Beispiel #1
0
 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();
     }
 }
Beispiel #2
0
 private function _dash_index_messages_closebooks($company_settings_result)
 {
     $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 || !$account_closebooks_check_result->data->ready || !$account_closebooks_check_result->data->fye_date) {
         return array();
     }
     $fye_date = $account_closebooks_check_result->data->fye_date;
     // This is a really ugly / special use case.
     $text = '';
     $text .= "You have now passed your fiscal year end. You close books\n\t\t\t\t\tafter completing tax preparation and entering end of year\n\t\t\t\t\tadjustments. Click Close Books when you're ready.\n\t\t\t\t";
     /*
     $text .= '<div class="text-bold bump-down-more">Closing Date</div>';
     $text .= '<div class="bump-down"><div class="select" style="width: 200px;"><select name="date">';
     
     for( $i = 1; $i < 13; $i++ ) {
     	$d = date("Y-m-t",strtotime($fye_date_next_day.' -'.$i.' Months'));
     	$text .= '<option value='.$d.'>'.$d.'</option>';
     }
     $text .= '</select></div></div>';
     */
     $account_search = new Beans_Account_Search($this->_beans_data_auth());
     $account_search_result = $account_search->execute();
     $text .= '<div class="clear"></div>';
     $text .= '<div class="text-bold bump-down-more float-left" style="width: 180px;">Fiscal Year End:</div>';
     $text .= '<div class="bump-down-more float-left" style="width: 215px;">' . $fye_date . '</div>';
     $text .= '<div class="clear"></div>';
     $text .= '<div class="text-bold bump-down-more float-left" style="width: 180px;">Equity Accounts to Close:</div>';
     $text .= '<div class="bump-down float-left dash-index-close-books-include_accounts" style="width: 215px;"><div class="select" style="width: 200px;"><select class="dash-index-close-books-include_account_ids">';
     $text .= '<option value="">&nbsp;</option>';
     foreach ($account_search_result->data->accounts as $account) {
         if (isset($account->type) and isset($account->type->type) and strtolower($account->type->type) == "equity") {
             $text .= '<option value="' . $account->id . '" ' . (stripos($account->name, 'owners distribution') !== FALSE ? 'selected="selected"' : '') . ' >' . $account->name . '</option>';
         }
     }
     $text .= '</select></div></div>';
     $text .= '<div class="clear"></div>';
     $text .= '<div class="text-bold bump-down-more float-left" style="width: 180px;">Closing Transfer Account:</div>';
     $text .= '<div class="bump-down float-left" style="width: 215px;"><div class="select" style="width: 200px;"><select name="transfer_account_id">';
     foreach ($account_search_result->data->accounts as $account) {
         if (isset($account->type) and isset($account->type->type) and strtolower($account->type->type) == "equity") {
             $text .= '<option value="' . $account->id . '" ' . (stripos($account->name, 'retained') !== FALSE ? 'selected="selected"' : '') . ' >' . $account->name . '</option>';
         }
     }
     $text .= '</select></div></div>';
     $text .= '<div class="clear"></div>';
     $text .= '<input type="hidden" name="date" value="' . $fye_date . '">';
     $text .= '<input type="hidden" name="include_account_ids" value="">';
     return array((object) array('title' => 'Year End - Close Books', 'text' => $text, 'actions' => array((object) array('text' => "Close Books", 'id' => "dash-index-close-books-submit"))));
 }