public function __construct($data = NULL) { parent::__construct($data); $this->_transactions = ORM::Factory('transaction')->distinct(TRUE)->join('entities', 'LEFT')->on('entities.id', '=', 'transaction.entity_id'); $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0; $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50; $this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest"; $this->_form_id = isset($data->form_id) ? $data->form_id : FALSE; // Re-declare $this->_transactions to use proper joins for a form search. $this->_transactions = ORM::Factory('transaction')->DISTINCT(TRUE)->join('account_transactions', 'RIGHT')->on('account_transactions.transaction_id', '=', 'transaction.id')->join('account_transaction_forms', 'RIGHT')->on('account_transaction_forms.account_transaction_id', '=', 'account_transactions.id'); }
public function __construct($data = NULL) { parent::__construct($data); $this->_transactions = ORM::Factory('transaction')->distinct(TRUE)->join('entities', 'LEFT')->on('entities.id', '=', 'transaction.entity_id'); $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0; $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50; $this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest"; // Check for search fields. $this->_search_vendor_keywords = isset($data->vendor_keywords) ? $data->vendor_keywords : FALSE; $this->_search_customer_keywords = isset($data->customer_keywords) ? $data->customer_keywords : FALSE; $this->_search_date = isset($data->date) ? $data->date : FALSE; $this->_search_check_number = isset($data->check_number) ? $data->check_number : FALSE; }
public function __construct($data = NULL) { parent::__construct($data); $this->_transactions = ORM::Factory('transaction')->distinct(TRUE); $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0; $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50; $this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest"; // Check for search fields. $this->_search_vendor_id = isset($data->vendor_id) ? $data->vendor_id : FALSE; $this->_search_keywords = isset($data->search_keywords) ? $data->search_keywords : FALSE; $this->_search_date = isset($data->date) ? $data->date : FALSE; $this->_search_check_number = isset($data->check_number) ? $data->check_number : FALSE; $this->_search_and = isset($data->search_and) ? $data->search_and ? TRUE : FALSE : TRUE; }
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_reconcile() { $account_id = $this->request->param('id'); $account_lookup = new Beans_Account_Lookup($this->_beans_data_auth((object) array('id' => $account_id))); $account_lookup_result = $account_lookup->execute(); if ($this->_beans_result_check($account_lookup_result)) { $this->_action_tab_name = $account_lookup_result->data->account->name; $this->_view->force_current_uri = '/accounts/view/' . $account_id; if (!$account_lookup_result->data->account->reconcilable) { $this->_view->send_error_message("This account cannot be reconciled."); } else { $this->_view->account_lookup_result = $account_lookup_result; // Look up last reconcile... $account_reconcile = new Beans_Account_Reconcile_Search($this->_beans_data_auth((object) array('account_id' => $account_lookup_result->data->account->id, 'page' => 0, 'page_size' => 1, 'sort_by' => 'newest'))); $account_reconcile_result = $account_reconcile->execute(); if ($this->_beans_result_check($account_reconcile_result)) { $this->_view->account_reconcile_result = $account_reconcile_result; } $account_transactions = new Beans_Account_Transaction_Search($this->_beans_data_auth((object) array('account_id' => $account_lookup_result->data->account->id, 'page_size' => 50000, 'page' => 0, 'reconciled' => FALSE, 'sort_by' => 'oldest'))); $account_transactions_result = $account_transactions->execute(); if ($this->_beans_result_check($account_transactions_result)) { $this->_view->account_transactions_result = $account_transactions_result; } } $this->_action_tab_name = $account_lookup_result->data->account->name; $this->_action_tab_uri = '/accounts/view/' . $account_lookup_result->data->account->id; } }
private function _dash_index_messages_startingbalance() { $account_transaction_search = new Beans_Account_Transaction_Search($this->_beans_data_auth((object) array('search_code' => "STARTINGBAL"))); $account_transaction_search_result = $account_transaction_search->execute(); // V2Item - Consider error'ing this. if (!$account_transaction_search_result->success) { return array(); } if ($account_transaction_search_result->data->total_results == 0) { return array((object) array('title' => "Starting Balance", 'text' => "Finally, add starting balances to your accounts. \n\t\t\t\t\t\t\t\tStarting balances are copied from an existing accounting \n\t\t\t\t\t\t\t\tprogram or entered for the first time if you're starting \n\t\t\t\t\t\t\t\ta new business.", 'actions' => array((object) array('text' => "Enter Starting Balance", 'url' => "/accounts/startingbalance")))); } return array(); }
public function action_transactionsloadmore() { $account_id = $this->request->post('account_id'); $last_transaction_id = $this->request->post('last_transaction_id'); $last_transaction_date = $this->request->post('last_transaction_date'); $count = $this->request->post('count'); if (!$account_id) { return $this->_return_error("An error occurred: no account ID was provided."); } if (!$last_transaction_id) { return $this->_return_error("An error occurred: no last transaction ID was provided."); } if (!$count) { $count = 50; } $this->_return_object->data->transactions = array(); $account_lookup = new Beans_Account_Lookup($this->_beans_data_auth((object) array('id' => $account_id))); $account_lookup_result = $account_lookup->execute(); $account_transactions_search = new Beans_Account_Transaction_Search($this->_beans_data_auth((object) array('account_id' => $account_id, 'sort_by' => 'newest', 'before_transaction_id' => $last_transaction_id, 'page_size' => $count))); $account_transactions_search_result = $account_transactions_search->execute(); if (!$account_transactions_search_result->success) { return $this->_return_error("An unexpected error occurred: " . $this->_beans_result_get_error($account_transactions_search_result)); } foreach ($account_transactions_search_result->data->transactions as $transaction) { $html = new View_Partials_Accounts_View_Transaction(); $html->setup_company_list_result = $this->_setup_company_list_result; $html->account_lookup_result = $account_lookup_result; $html->transaction = $transaction; $html->account_id = $account_id; $transaction->html = $html->render(); $this->_return_object->data->transactions[] = $transaction; } }