function filter($condition = FALSE)
 {
     $days_in_this_month = days_in_month(date('m'), date('Y'));
     $lastday_in_month = date('Y') . "-" . date('m') . "-" . $days_in_this_month;
     $firstday_in_month = date('Y') . "-" . date('m') . "-01";
     $this->view_data['estimates_paid_this_month'] = Invoice::count(array('conditions' => 'paid_date <= ' . $lastday_in_month . ' and paid_date >= ' . $firstday_in_month . ' AND estimate != 0'));
     $this->view_data['estimates_due_this_month'] = Invoice::count(array('conditions' => 'due_date <= ' . $lastday_in_month . ' and due_date >= ' . $firstday_in_month . ' AND estimate != 0'));
     switch ($condition) {
         case 'open':
             $this->view_data['estimates'] = Invoice::find('all', array('conditions' => array('estimate_status = ? and estimate != ?', 'Open', 0)));
             break;
         case 'sent':
             $this->view_data['estimates'] = Invoice::find('all', array('conditions' => array('estimate_status = ? and estimate != ?', 'Sent', 0)));
             break;
         case 'accepted':
             $this->view_data['estimates'] = Invoice::find('all', array('conditions' => array('estimate_status = ? and estimate != ?', 'Accepted', 0)));
             break;
         case 'declined':
             $this->view_data['estimates'] = Invoice::find('all', array('conditions' => array('estimate_status = ? and estimate != ?', 'Declined', 0)));
             break;
         case 'invoiced':
             $this->view_data['estimates'] = Invoice::find('all', array('conditions' => array('estimate_status = ? and estimate != ?', 'Invoiced', 0)));
             break;
         default:
             $this->view_data['estimates'] = Invoice::find('all', array('conditions' => array('estimate != ?', 0)));
             break;
     }
     $this->content_view = 'estimates/all';
 }
Exemple #2
0
 /**
  * @before _secure
  */
 public function affiliates()
 {
     $this->seo(array("title" => "Billing"));
     $view = $this->getActionView();
     $start = RM::get("start", date("Y-m-d", strtotime('-60 day')));
     $end = RM::get("end", date("Y-m-d", strtotime('now')));
     $query = ['utype' => 'publisher', 'org_id' => $this->org->_id];
     $payments = \Payment::all($query);
     $page = RM::get("page", 1);
     $limit = RM::get("limit", 10);
     $property = RM::get("property");
     $value = RM::get("value");
     if ($property) {
         $query["{$property} = ?"] = $value;
     } else {
         $query['created'] = Db::dateQuery($start, $end);
     }
     $invoices = \Invoice::all($query);
     $view->set('invoices', $invoices)->set('payments', $payments)->set('active', Invoice::count(['utype' => 'publisher', 'org_id' => $this->org->_id, "live = ?" => 1]))->set('inactive', Invoice::count(['utype' => 'publisher', 'org_id' => $this->org->_id, "live = ?" => 0]))->set('start', $start)->set('end', $end);
 }
 function filter($condition = FALSE)
 {
     $days_in_this_month = days_in_month(date('m'), date('Y'));
     $lastday_in_month = date('Y') . "-" . date('m') . "-" . $days_in_this_month;
     $firstday_in_month = date('Y') . "-" . date('m') . "-01";
     $this->view_data['invoices_paid_this_month'] = Invoice::count(array('conditions' => 'paid_date <= ' . $lastday_in_month . ' and paid_date >= ' . $firstday_in_month . ''));
     $this->view_data['invoices_due_this_month'] = Invoice::count(array('conditions' => 'due_date <= ' . $lastday_in_month . ' and due_date >= ' . $firstday_in_month . ''));
     switch ($condition) {
         case 'open':
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('status = ?', 'Open')));
             break;
         case 'sent':
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('status = ?', 'Sent')));
             break;
         case 'paid':
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('status = ?', 'Paid')));
             break;
         default:
             $this->view_data['invoices'] = Invoice::all();
             break;
     }
     $this->content_view = 'invoices/all';
 }
Exemple #4
0
<?php

// setup
$Invoice = new Invoice();
$total = $Invoice->count();
$items_per_page = 10;
if (!isset($page) || $page < 0) {
    $page = 1;
}
$number_of_pages = ceil($total / $items_per_page);
if ($number_of_pages == 0) {
    $number_of_pages = 1;
}
$start = ($page - 1) * $items_per_page;
?>
<div class="actions">
    <a href="xhtml.php/invoices/*/enumerate">List Invoices</a>
    <a href="xhtml.php/invoices/*/create">New Invoice</a>
</div>
<table>
    <tr>
        <th>#</th><th>Date</th><th>Client</th><th>Project</th><th>Status</th><th>Amount</th><th> </th>
    </tr>
    <?php 
$list = $Invoice->get_list($start, $items_per_page);
if (!$list) {
    echo '<tr><td colspan="6">No Invoices Found</td></tr>';
} else {
    foreach ($list as $invoice) {
        include Configuration::get('base_dir') . DS . 'templates' . DS . 'invoice-list-item-view.php';
    }
Exemple #5
0
    function filter($year = FALSE)
    {
        if (!$year) {
            $year = date('Y', time());
        }
        $tax = $this->view_data['core_settings']->tax;
        $this->load->database();
        $sql = "select invoices.paid_date, ROUND(sum(invoice_has_items.value*invoice_has_items.amount)-if(SUBSTR(invoices.discount,-1)='%',(sum(invoice_has_items.value*invoice_has_items.amount)/100*(SUBSTRING(invoices.discount, 1, CHAR_LENGTH(invoices.discount) - 1))), invoices.discount)+(sum(invoice_has_items.value*invoice_has_items.amount)-if(SUBSTR(invoices.discount,-1)='%',(sum(invoice_has_items.value*invoice_has_items.amount)/100*(SUBSTRING(invoices.discount, 1, CHAR_LENGTH(invoices.discount) - 1))), invoices.discount))/100*{$tax},0) as summary FROM invoices, invoice_has_items where invoices.id = invoice_has_items.invoice_id AND invoices.`status` = 'Paid' AND paid_date between '{$year}-01-01'\nAND '{$year}-12-31' GROUP BY SUBSTR(invoices.paid_date,1,7)";
        $query = $this->db->query($sql);
        $this->view_data["stats"] = $query->result();
        $this->view_data["year"] = $year;
        //Projects
        //open
        $this->view_data["projects_open"] = Project::count(array('conditions' => array('progress < ?', 100)));
        //all
        $this->view_data["projects_all"] = Project::count();
        //invoices
        //open
        $this->view_data["invoices_open"] = Invoice::count(array('conditions' => array('status != ?', 'Paid')));
        //all
        $this->view_data["invoices_all"] = Invoice::count();
        //payments open
        $thismonth = date('m');
        $this->view_data["month"] = date('M');
        $sql = "select invoices.paid_date, ROUND(sum(invoice_has_items.value*invoice_has_items.amount)-if(SUBSTR(invoices.discount,-1)='%',(sum(invoice_has_items.value*invoice_has_items.amount)/100*(SUBSTRING(invoices.discount, 1, CHAR_LENGTH(invoices.discount) - 1))), invoices.discount)+(sum(invoice_has_items.value*invoice_has_items.amount)-if(SUBSTR(invoices.discount,-1)='%',(sum(invoice_has_items.value*invoice_has_items.amount)/100*(SUBSTRING(invoices.discount, 1, CHAR_LENGTH(invoices.discount) - 1))), invoices.discount))/100*{$tax},0) as summary FROM invoices, invoice_has_items where invoices.id = invoice_has_items.invoice_id AND invoices.`status` = 'Paid' AND paid_date between '{$year}-{$thismonth}-01'\nAND '{$year}-{$thismonth}-31' ";
        $query = $this->db->query($sql);
        $this->view_data["payments"] = $query->result();
        //payments outstanding
        $thismonth = date('m');
        $this->view_data["month"] = date('M');
        $sql = "select invoices.paid_date, ROUND(sum(invoice_has_items.value*invoice_has_items.amount)-if(SUBSTR(invoices.discount,-1)='%',(sum(invoice_has_items.value*invoice_has_items.amount)/100*(SUBSTRING(invoices.discount, 1, CHAR_LENGTH(invoices.discount) - 1))), invoices.discount)+(sum(invoice_has_items.value*invoice_has_items.amount)-if(SUBSTR(invoices.discount,-1)='%',(sum(invoice_has_items.value*invoice_has_items.amount)/100*(SUBSTRING(invoices.discount, 1, CHAR_LENGTH(invoices.discount) - 1))), invoices.discount))/100*{$tax},0) as summary FROM invoices, invoice_has_items where invoices.id = invoice_has_items.invoice_id AND invoices.`status` != 'Paid' ";
        $query = $this->db->query($sql);
        $this->view_data["paymentsoutstanding"] = $query->result();
        //Events
        $events = array();
        $date = date('Y-m-d', time());
        $eventcount = 0;
        foreach ($this->view_data['menu'] as $key => $value) {
            if ($value->link == "invoices") {
                $sql = 'SELECT * FROM invoices WHERE status != "Paid" AND due_date < "' . $date . '" ORDER BY due_date';
                $res = $this->db->query($sql);
                $res = $res->result();
                foreach ($res as $key2 => $value2) {
                    $eventline = str_replace("{invoice_number}", '<a href="' . base_url() . 'invoices/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_invoice_overdue'));
                    $events[$value2->due_date . "." . $value2->id] = $eventline;
                    $eventcount = $eventcount + 1;
                }
            }
            if ($value->link == "projects") {
                $sql = 'SELECT * FROM projects WHERE progress != "100" AND end < "' . $date . '" ORDER BY end';
                $res = $this->db->query($sql);
                $res = $res->result();
                foreach ($res as $key2 => $value2) {
                    if ($this->user->admin == 0) {
                        $sql = "SELECT id FROM `project_has_workers` WHERE project_id = " . $value->id . " AND user_id = " . $this->user->id;
                        $query = $this->db->query($sql);
                        $res = $query->result();
                        if ($res) {
                            $eventline = str_replace("{project_number}", '<a href="' . base_url() . 'projects/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_project_overdue'));
                            $events[$value2->end . "." . $value2->id] = $eventline;
                            $eventcount = $eventcount + 1;
                        }
                    } else {
                        $eventline = str_replace("{project_number}", '<a href="' . base_url() . 'projects/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_project_overdue'));
                        $events[$value2->end . "." . $value2->id] = $eventline;
                        $eventcount = $eventcount + 1;
                    }
                }
            }
            if ($value->link == "subscriptions") {
                $sql = 'SELECT * FROM subscriptions WHERE status != "Inactive" AND end_date > "' . $date . '" AND next_payment <= "' . $date . '" ORDER BY next_payment';
                $res = $this->db->query($sql);
                $res = $res->result();
                foreach ($res as $key2 => $value2) {
                    $eventline = str_replace("{subscription_number}", '<a href="' . base_url() . 'subscriptions/view/' . $value2->id . '">#' . $value2->reference . '</a>', $this->lang->line('event_subscription_new_invoice'));
                    $events[$value2->next_payment . "." . $value2->id] = $eventline;
                    $eventcount = $eventcount + 1;
                }
            }
            if ($value->link == "messages") {
                $sql = 'SELECT privatemessages.id, privatemessages.`status`, privatemessages.subject, privatemessages.message, privatemessages.`time`, privatemessages.`recipient`, clients.`userpic` as userpic_c, users.`userpic` as userpic_u  , users.`email` as email_u , clients.`email` as email_c , CONCAT(users.firstname," ", users.lastname) as sender_u, CONCAT(clients.firstname," ", clients.lastname) as sender_c
							FROM privatemessages
							LEFT JOIN clients ON CONCAT("c",clients.id) = privatemessages.sender
							LEFT JOIN users ON CONCAT("u",users.id) = privatemessages.sender 
							GROUP by privatemessages.id HAVING privatemessages.recipient = "u' . $this->user->id . '"AND privatemessages.status != "deleted" ORDER BY privatemessages.`time` DESC LIMIT 6';
                $query = $this->db->query($sql);
                $this->view_data["message"] = array_filter($query->result());
            }
            if ($value->link == "projects") {
                $sql = 'SELECT * FROM project_has_tasks WHERE status != "done" AND user_id = "' . $this->user->id . '" ORDER BY project_id';
                $taskquery = $this->db->query($sql);
                $this->view_data["tasks"] = $taskquery->result();
            }
        }
        krsort($events);
        $this->view_data["events"] = $events;
        $this->view_data["eventcount"] = $eventcount;
        $this->content_view = 'dashboard/dashboard';
    }
Exemple #6
0
 function filter($condition = FALSE)
 {
     $days_in_this_month = days_in_month(date('m'), date('Y'));
     $lastday_in_month = date('Y') . "-" . date('m') . "-" . $days_in_this_month;
     $firstday_in_month = date('Y') . "-" . date('m') . "-01";
     $this->view_data['invoices_paid_this_month'] = Invoice::count(array('conditions' => 'paid_date <= ' . $lastday_in_month . ' and paid_date >= ' . $firstday_in_month . ' AND estimate != 1'));
     $this->view_data['invoices_due_this_month'] = Invoice::count(array('conditions' => 'due_date <= ' . $lastday_in_month . ' and due_date >= ' . $firstday_in_month . ' AND estimate != 1'));
     //statistic
     $now = time();
     $beginning_of_week = strtotime('last Monday', $now);
     // BEGINNING of the week
     $end_of_week = strtotime('next Sunday', $now) + 86400;
     // END of the last day of the week
     $this->view_data['invoices_due_this_month_graph'] = Invoice::find_by_sql('select count(id) AS "amount", DATE_FORMAT(`due_date`, "%w") AS "date_day", DATE_FORMAT(`due_date`, "%Y-%m-%d") AS "date_formatted" from invoices where UNIX_TIMESTAMP(`due_date`) >= "' . $beginning_of_week . '" AND UNIX_TIMESTAMP(`due_date`) <= "' . $end_of_week . '" AND estimate != 1');
     $this->view_data['invoices_paid_this_month_graph'] = Invoice::find_by_sql('select count(id) AS "amount", DATE_FORMAT(`paid_date`, "%w") AS "date_day", DATE_FORMAT(`paid_date`, "%Y-%m-%d") AS "date_formatted" from invoices where UNIX_TIMESTAMP(`paid_date`) >= "' . $beginning_of_week . '" AND UNIX_TIMESTAMP(`paid_date`) <= "' . $end_of_week . '" AND estimate != 1');
     switch ($condition) {
         case 'open':
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('status = ? and estimate != ?', 'Open', 1)));
             break;
         case 'sent':
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('status = ? and estimate != ?', 'Sent', 1)));
             break;
         case 'paid':
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('status = ? and estimate != ?', 'Paid', 1)));
             break;
         default:
             $this->view_data['invoices'] = Invoice::find('all', array('conditions' => array('estimate != ?', 1)));
             break;
     }
     $this->content_view = 'invoices/all';
 }
Exemple #7
0
 public function index($offset = 0)
 {
     $columns = $this->_search_columns();
     $configs = array('admin', $this->get_class(), '%s');
     $conditions = conditions($columns, $configs);
     Invoice::addConditions($conditions, 'destroy_user_id IS NULL');
     $limit = 25;
     $total = Invoice::count(array('conditions' => $conditions));
     $offset = $offset < $total ? $offset : 0;
     $this->load->library('pagination');
     $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links();
     $invoices = Invoice::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('pictures', 'user', 'tag'), 'conditions' => $conditions));
     return $this->set_tab_index(1)->set_subtitle('帳務列表')->add_hidden(array('id' => 'is_finished_url', 'value' => base_url('admin', $this->get_class(), 'is_finished')))->load_view(array('invoices' => $invoices, 'pagination' => $pagination, 'columns' => $columns));
 }