Пример #1
0
 private function _dash_index_messages_balancecheck()
 {
     $setup_company_list = new Beans_Setup_Company_List($this->_beans_data_auth());
     $setup_company_list_result = $setup_company_list->execute();
     $require_calibration = FALSE;
     $report_balancecheck_result = FALSE;
     if (isset($setup_company_list_result->data) && isset($setup_company_list_result->data->settings) && isset($setup_company_list_result->data->settings->calibrate_date_next) && $setup_company_list_result->data->settings->calibrate_date_next) {
         $require_calibration = TRUE;
     }
     if (!$require_calibration) {
         $customer_sale_calibrate_check = new Beans_Customer_Sale_Calibrate_Check($this->_beans_data_auth());
         $customer_sale_calibrate_check_result = $customer_sale_calibrate_check->execute();
         if (!$customer_sale_calibrate_check_result->success) {
             return array();
         }
         if (count($customer_sale_calibrate_check_result->data->ids)) {
             $require_calibration = TRUE;
         }
     }
     if (!$require_calibration) {
         $vendor_purchase_calibrate_check = new Beans_Vendor_Purchase_Calibrate_Check($this->_beans_data_auth());
         $vendor_purchase_calibrate_check_result = $vendor_purchase_calibrate_check->execute();
         if (!$vendor_purchase_calibrate_check_result->success) {
             return array();
         }
         if (count($vendor_purchase_calibrate_check_result->data->ids)) {
             $require_calibration = TRUE;
         }
     }
     if (!$require_calibration) {
         $account_calibrate_check = new Beans_Account_Calibrate_Check($this->_beans_data_auth());
         $account_calibrate_check_result = $account_calibrate_check->execute();
         if (!$account_calibrate_check_result->success) {
             return array();
         }
         if (count($account_calibrate_check_result->data->account_ids)) {
             $require_calibration = TRUE;
         }
     }
     if (!$require_calibration) {
         $report_balancecheck = new Beans_Report_Balancecheck($this->_beans_data_auth((object) array('date' => date("Y-m-d"))));
         $report_balancecheck_result = $report_balancecheck->execute();
         if (!$report_balancecheck_result->success) {
             return array();
         }
     }
     if ($require_calibration || $report_balancecheck_result && !$report_balancecheck_result->data->balanced) {
         return array((object) array('title' => "Calibration Required", 'text' => "Your books need to be calibrated due to an update\n\t\t\t\t\t\t\t\tin BeansBooks.  Your accounts will function correctly until then,\n\t\t\t\t\t\t\t\tbut may display an incorrect balance.", 'actions' => array((object) array('text' => "Calibrate Accounts", 'url' => "/setup/calibrate"))));
     }
     return array();
 }
Пример #2
0
 public function action_calibratestartdate()
 {
     set_time_limit(60 * 10);
     ini_set('memory_limit', '256M');
     // Get First Transaction and Last Transaction
     // then simple bisection...
     $date_start = NULL;
     $date_end = NULL;
     $account_transaction_search = new Beans_Account_Transaction_Search($this->_beans_data_auth((object) array('sort_by' => 'oldest', 'page_size' => 1)));
     $account_transaction_search_result = $account_transaction_search->execute();
     if (!$account_transaction_search_result->success || !count($account_transaction_search_result->data->transactions)) {
         return $this->_return_error('Error getting starting transaction: ' . $account_transaction_search_result->error);
     }
     $date_start = $account_transaction_search_result->data->transactions[0]->date;
     $account_transaction_search = new Beans_Account_Transaction_Search($this->_beans_data_auth((object) array('sort_by' => 'newest', 'page_size' => 1)));
     $account_transaction_search_result = $account_transaction_search->execute();
     if (!$account_transaction_search_result->success || !count($account_transaction_search_result->data->transactions)) {
         return $this->_return_error('Error getting ending transaction: ' . $account_transaction_search_result->error);
     }
     $date_end = $account_transaction_search_result->data->transactions[0]->date;
     // First check if books are balanced as of yesterday - if so, just return yesterday.
     $report_balancecheck = new Beans_Report_Balancecheck($this->_beans_data_auth((object) array('date' => date("Y-m-d", strtotime("-1 Day")))));
     $report_balancecheck_result = $report_balancecheck->execute();
     if (!$report_balancecheck_result->success) {
         return $this->_return_error('Error finding first good date: ' . $report_balancecheck_result->error);
     }
     if ($report_balancecheck_result->data->balanced) {
         $date_start = $report_balancecheck_result->data->date;
     } else {
         $date_end = $report_balancecheck_result->data->date;
     }
     // By default we calibrate the last two days - forces a smooth JS experience.
     while ($date_start != $date_end && strtotime($date_end) - strtotime($date_start) > 60 * 60 * 24 * 2) {
         $report_balancecheck = new Beans_Report_Balancecheck($this->_beans_data_auth((object) array('date' => date("Y-m-d", strtotime($date_start) + floor((strtotime($date_end) - strtotime($date_start)) / 2)))));
         $report_balancecheck_result = $report_balancecheck->execute();
         if (!$report_balancecheck_result->success) {
             return $this->_return_error('Error finding first good date: ' . $report_balancecheck_result->error);
         }
         if ($report_balancecheck_result->data->balanced) {
             $date_start = $report_balancecheck_result->data->date;
         } else {
             $date_end = $report_balancecheck_result->data->date;
         }
     }
     $this->_return_object->data->date = $date_start;
     $setup_company_list = new Beans_Setup_Company_List($this->_beans_data_auth());
     $setup_company_list_result = $setup_company_list->execute();
     if (isset($setup_company_list_result->data->settings) && isset($setup_company_list_result->data->settings->calibrate_date_next) && $setup_company_list_result->data->settings->calibrate_date_next && strtotime($setup_company_list_result->data->settings->calibrate_date_next) < strtotime($this->_return_object->data->date)) {
         $this->_return_object->data->date = $setup_company_list_result->data->settings->calibrate_date_next;
     }
 }
Пример #3
0
 public function action_calibrate()
 {
     $account_calibrate_check = new Beans_Account_Calibrate_Check($this->_beans_data_auth());
     $account_calibrate_check_result = $account_calibrate_check->execute();
     if ($this->_beans_result_check($account_calibrate_check_result)) {
         $this->_view->account_calibrate_check_result = $account_calibrate_check_result;
     }
     $report_balancecheck = new Beans_Report_Balancecheck($this->_beans_data_auth((object) array('date' => date("Y-m-d"))));
     $report_balancecheck_result = $report_balancecheck->execute();
     if ($this->_beans_result_check($report_balancecheck_result)) {
         $this->_view->report_balancecheck_result = $report_balancecheck_result;
     }
     $customer_sale_calibrate_check = new Beans_Customer_Sale_Calibrate_Check($this->_beans_data_auth());
     $customer_sale_calibrate_check_result = $customer_sale_calibrate_check->execute();
     if ($this->_beans_result_check($customer_sale_calibrate_check_result)) {
         $this->_view->customer_sale_calibrate_check_result = $customer_sale_calibrate_check_result;
     }
     $vendor_purchase_calibrate_check = new Beans_Vendor_Purchase_Calibrate_Check($this->_beans_data_auth());
     $vendor_purchase_calibrate_check_result = $vendor_purchase_calibrate_check->execute();
     if ($this->_beans_result_check($vendor_purchase_calibrate_check_result)) {
         $this->_view->vendor_purchase_calibrate_check_result = $vendor_purchase_calibrate_check_result;
     }
     $setup_company_list = new Beans_Setup_Company_List($this->_beans_data_auth());
     $setup_company_list_result = $setup_company_list->execute();
     if ($this->_beans_result_check($setup_company_list_result)) {
         $this->_view->setup_company_list_result = $setup_company_list_result;
     }
 }