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(); }
public function action_calibratedate() { $date = $this->request->post('date'); $manual = $this->request->post('manual'); if (!$date or $date != date("Y-m-d", strtotime($date))) { return $this->_return_error('Invalid date provided: ' . $date . ' expected YYYY-MM-DD'); } // If manual, we don;t want them trying to calibrate pre-fye if ($manual == "1") { $account_closebooks_check = new Beans_Account_Closebooks_Check($this->_beans_data_auth()); $account_closebooks_check_result = $account_closebooks_check->execute(); if (!$account_closebooks_check_result->success) { return $this->_return_error("An unexpected error occurred when trying to validate the date: " . $account_closebooks_check_result->error); } if ($account_closebooks_check_result->data->previous_date && strtotime($date) <= strtotime($account_closebooks_check_result->data->previous_date)) { return $this->_return_error("The books were closed most recently on " . $account_closebooks_check_result->data->previous_date . ". " . "Please choose a date after that to begin manual calibration."); } } // This can take a while. set_time_limit(60 * 10); ini_set('memory_limit', '256M'); // Recalibrate Customer Invoices / Cancellations $customer_sale_calibrate = new Beans_Customer_Sale_Calibrate($this->_beans_data_auth((object) array('date_after' => $date, 'date_before' => $date))); $customer_sale_calibrate_result = $customer_sale_calibrate->execute(); if (!$customer_sale_calibrate_result->success) { return $this->_return_error('Error updating customer sales: ' . $customer_sale_calibrate_result->error); } // Recalibrate any payments tied to these sales AFTER this transaction date. $customer_payment_calibrate = new Beans_Customer_Payment_Calibrate($this->_beans_data_auth((object) array('date_after' => $date, 'date_before' => $date))); $customer_payment_calibrate_result = $customer_payment_calibrate->execute(); if (!$customer_payment_calibrate_result->success) { return $this->_return_error('Error updating customer payments: ' . $customer_payment_calibrate_result->error); } // Recalibrate Vendor Invoices / Cancellations $vendor_purchase_calibrate = new Beans_Vendor_Purchase_Calibrate($this->_beans_data_auth((object) array('date_after' => $date, 'date_before' => $date))); $vendor_purchase_calibrate_result = $vendor_purchase_calibrate->execute(); if (!$vendor_purchase_calibrate_result->success) { return $this->_return_error('Error updating vendor purchases: ' . $vendor_purchase_calibrate_result->error); } // Recalibrate any payments tied to these purchases AFTER this transaction date. $vendor_payment_calibrate = new Beans_Vendor_Payment_Calibrate($this->_beans_data_auth((object) array('date_after' => $date, 'date_before' => $date))); $vendor_payment_calibrate_result = $vendor_payment_calibrate->execute(); if (!$vendor_payment_calibrate_result->success) { return $this->_return_error('Error updating vendor payments: ' . $vendor_payment_calibrate_result->error); } $this->_return_object->data->date_next = date("Y-m-d", strtotime($date . " +1 Day")); $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; // This gets run on the very last iteration of calibration. if (strtotime($date_end) < strtotime($this->_return_object->data->date_next)) { $this->_return_object->data->date_next = FALSE; $account_calibrate = new Beans_Account_Calibrate($this->_beans_data_auth()); $account_calibrate_result = $account_calibrate->execute(); if (!$account_calibrate_result->success) { return $this->_return_error('Error calibrating individual account balances: ' . $account_calibrate_result->error); } $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 $this->_return_error('Error calibrating customer sales: ' . $customer_sale_calibrate_check_result->error); } if (count($customer_sale_calibrate_check_result->data->ids)) { $customer_sale_calibrate = new Beans_Customer_Sale_Calibrate($this->_beans_data_auth((object) array('ids' => $customer_sale_calibrate_check_result->data->ids))); $customer_sale_calibrate_result = $customer_sale_calibrate->execute(); if (!$customer_sale_calibrate_result->success) { return $this->_return_error('Error calibrating customer sales: ' . $customer_sale_calibrate_result->error); } } $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 $this->_return_error('Error calibrating vendor purchases: ' . $vendor_purchase_calibrate_check_result->error); } if (count($vendor_purchase_calibrate_check_result->data->ids)) { $vendor_purchase_calibrate = new Beans_Vendor_Purchase_Calibrate($this->_beans_data_auth((object) array('ids' => $vendor_purchase_calibrate_check_result->data->ids))); $vendor_purchase_calibrate_result = $vendor_purchase_calibrate->execute(); if (!$vendor_purchase_calibrate_result->success) { return $this->_return_error('Error calibrating vendor purchases: ' . $vendor_purchase_calibrate_result->error); } } } // Update our latest date in case user pauses and comes back later. // We only do this if the user isn't manually recalibrating books. if ($manual !== "1") { $setup_company_update = new Beans_Setup_Company_Update($this->_beans_data_auth((object) array('settings' => array('calibrate_date_next' => $this->_return_object->data->date_next)))); $setup_company_update_result = $setup_company_update->execute(); } }
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; } }