Exemple #1
0
 public function action_incomedaterange()
 {
     $date_start = $this->request->post('date_start');
     $date_end = $this->request->post('date_end');
     if (!$date_start) {
         if (Session::instance()->get('dash_income_date_start')) {
             $date_start = Session::instance()->get('dash_income_date_start');
         } else {
             $date_start = date("Y-m", strtotime("-11 Months")) . '-01';
         }
     }
     if (!$date_end) {
         if (Session::instance()->get('dash_income_date_end')) {
             $date_end = Session::instance()->get('dash_income_date_end');
         } else {
             $date_end = date("Y-m-d");
         }
     }
     if (strtotime($date_end) < strtotime($date_start)) {
         $date_start = date("Y-m", strtotime("-11 Months")) . '-01';
         $date_end = date("Y-m-d");
     }
     Session::instance()->set('dash_income_date_start', $date_start);
     Session::instance()->set('dash_income_date_end', $date_end);
     $date_counter = $date_start;
     $this->_return_object->data->date_ranges = array();
     $this->_return_object->data->income = array();
     $this->_return_object->data->gross_income = array();
     $this->_return_object->data->expenses = array();
     $this->_return_object->data->net_income = array();
     while (strtotime($date_counter) < strtotime($date_end)) {
         $report_date_start = date("Y-m", strtotime($date_counter)) . "-01";
         $report_date_end = date("Y-m-t", strtotime($date_counter));
         if (strtotime($report_date_end) > strtotime($date_end)) {
             $report_date_end = $date_end;
         }
         $report_income = new Beans_Report_Income($this->_beans_data_auth((object) array('date_start' => $report_date_start, 'date_end' => $report_date_end)));
         $report_income_result = $report_income->execute();
         if (!$report_income_result->success) {
             return $this->_return_error($this->_beans_result_get_error($report_income_result));
         }
         $this->_return_object->data->date_ranges[] = date("M", strtotime($report_date_start));
         $this->_return_object->data->income[] = $report_income_result->data->account_types['income']->balance;
         $this->_return_object->data->gross_income[] = $report_income_result->data->account_types['gross']->balance;
         $this->_return_object->data->expense[] = $report_income_result->data->account_types['expense']->balance;
         $this->_return_object->data->net_income[] = $report_income_result->data->account_types['net']->balance;
         $date_counter = date("Y-m", strtotime($date_counter . " +1 Month")) . "-01";
     }
     if (count($this->_return_object->data->date_ranges) == 1) {
         $this->_return_object->data->date_ranges[] = $this->_return_object->data->date_ranges[0];
         $this->_return_object->data->income[] = $this->_return_object->data->income[0];
         $this->_return_object->data->gross_income[] = $this->_return_object->data->gross_income[0];
         $this->_return_object->data->expense[] = $this->_return_object->data->expense[0];
         $this->_return_object->data->net_income[] = $this->_return_object->data->net_income[0];
     }
 }
Exemple #2
0
 protected function _execute()
 {
     if (!$this->_date) {
         throw new Exception("Invalid report date: none provided.");
     }
     if ($this->_date != date("Y-m-d", strtotime($this->_date))) {
         throw new Exception("Invalid report date: must be in format YYYY-MM-DD.");
     }
     // T2 Accounts ( just below top level )
     $t2_accounts = array();
     foreach (ORM::Factory('account')->where('parent_account_id', 'IS', NULL)->find_all() as $top_level_account) {
         foreach ($top_level_account->child_accounts->find_all() as $t2_account) {
             $t2_accounts[] = $t2_account;
         }
     }
     //
     // Query for our accounts - we're interested in
     //
     $account_types = array();
     $account_types['asset'] = new stdClass();
     $account_types['asset']->name = "Assets";
     $account_types['asset']->balance = 0.0;
     $account_types['asset']->accounts = array();
     $account_types['liability'] = new stdClass();
     $account_types['liability']->name = "Liabilities";
     $account_types['liability']->balance = 0.0;
     $account_types['liability']->accounts = array();
     $account_types['equity'] = new stdClass();
     $account_types['equity']->name = "Equity";
     $account_types['equity']->balance = 0.0;
     $account_types['equity']->accounts = array();
     // $array is blank - fill it in.
     foreach ($account_types as $type => $array) {
         foreach ($t2_accounts as $t2_account) {
             $t2_result = $this->_build_type_chart($t2_account, $type);
             if ($t2_result) {
                 $account_types[$type]->accounts[] = $t2_result;
             }
         }
     }
     foreach ($account_types as $type_key => $type) {
         foreach ($type->accounts as $key => $account) {
             $account_types[$type_key]->accounts[$key] = $this->_generate_account_balance($account, $this->_date, FALSE, $type_key == 'equity' ? TRUE : FALSE);
         }
     }
     foreach ($account_types as $type_key => $type) {
         $bal = $this->_generate_account_balance_total($type->accounts);
         $account_types[$type_key]->balance = $bal;
     }
     // Net Income Year = Last un-closed year.
     $fye_transaction = ORM::Factory('transaction')->where('close_books', 'IS NOT', NULL)->where('date', '<', $this->_date)->order_by('close_books', 'DESC')->find();
     $income_year = date("Y", 1);
     if ($fye_transaction->loaded()) {
         $income_year = intval(substr($fye_transaction->close_books, 0, 4)) + 1;
     }
     // Get Net Income
     $income_report = new Beans_Report_Income($this->_beans_data_auth((object) array('date_start' => $income_year . '-01-01', 'date_end' => $this->_date)));
     $income_report_result = $income_report->execute();
     if (!$income_report_result->success) {
         throw new Exception("Unexpected error: could not get net income: " . $income_report_result->error . $income_report_result->auth_error . $income_report_result->config_error);
     }
     $net_income = $income_report_result->data->account_types['net']->balance;
     $account_types['equity']->balance = $this->_beans_round($account_types['equity']->balance + $net_income);
     $account_types['equity']->accounts[] = (object) array('name' => "Net Income", 'id' => NULL, 'type' => 'equity', 'table_sign' => 1, 'balance' => $net_income);
     $total_liabilities_equity = $this->_beans_round($account_types['liability']->balance + $account_types['equity']->balance);
     $account_types['net'] = new stdClass();
     $account_types['net']->name = "Total Liabilities and Equity";
     $account_types['net']->balance = $total_liabilities_equity;
     $account_types['net']->accounts = array();
     $return_array[] = array('name' => '', 'balance_formatted' => ($total_liabilities_equity < 0 ? '<span class="text-red">-' : '') . number_format(abs($total_liabilities_equity), 2, '.', ',') . ($total_liabilities_equity < 0 ? '</span>' : ''));
     return (object) array('date' => $this->_date, 'account_types' => $account_types);
 }
Exemple #3
0
 public function action_income()
 {
     $date_start = date("Y") . "-01-01";
     $date_end = date("Y-m-d");
     if ($this->request->post('date_start')) {
         $date_start = $this->request->post('date_start');
     }
     if ($this->request->post('date_end')) {
         $date_end = $this->request->post('date_end');
     }
     $report_income = new Beans_Report_Income($this->_beans_data_auth((object) array('date_start' => $date_start, 'date_end' => $date_end)));
     $report_income_result = $report_income->execute();
     if ($this->_beans_result_check($report_income_result)) {
         $this->_view->report_income_result = $report_income_result;
     }
     if ($this->request->post('report-balance-zero-toggle')) {
         $this->_view->show_zero = TRUE;
     }
     $this->_action_tab_name = "Income Statement";
     $this->_action_tab_uri = '/' . $this->request->uri();
 }