public function before() { parent::before(); $this->_return_object = new stdClass(); $this->_return_object->success = TRUE; $this->_return_object->error = ""; $this->_return_object->data = new stdClass(); // Only if logged in. if (!strlen(Session::instance()->get('auth_uid')) or !strlen(Session::instance()->get('auth_key')) or !strlen(Session::instance()->get('auth_expiration'))) { return; } $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->_setup_company_list_result = $setup_company_list_result; } }
protected function beans_settings() { if ($this->_beans_settings) { return $this->_beans_settings; } $company_settings = new Beans_Setup_Company_List($this->_beans_data_auth()); $company_settings_result = $company_settings->execute(); if (!$company_settings_result->success) { $this->_beans_settings = new stdClass(); $this->_beans_settings->company_currency = "\$"; return $this->_beans_settings; } $this->_beans_settings = $company_settings_result->data->settings; // Default if (!isset($this->_beans_settings->company_currency) or !strlen($this->_beans_settings->company_currency)) { $this->_beans_settings->company_currency = "\$"; } return $this->_beans_settings; }
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; } }
public function action_purchasesend() { $purchase_id = $this->request->post('purchase_id'); $send_email = $this->request->post('send-email') ? TRUE : FALSE; $email = $this->request->post('email'); $send_mail = $this->request->post('send-mail') ? TRUE : FALSE; $send_done = $this->request->post('send-done') ? TRUE : FALSE; if (!$purchase_id) { return $this->_return_error("ERROR: No purchase ID provided."); } if (!$send_email and !$send_mail and !$send_done) { return $this->_return_error("ERROR: Please select at least one option."); } $vendor_purchase_lookup = new Beans_Vendor_Purchase_Lookup($this->_beans_data_auth((object) array('id' => $purchase_id))); $vendor_purchase_lookup_result = $vendor_purchase_lookup->execute(); if (!$vendor_purchase_lookup_result->success) { return $this->_return_error("An error occurred retrieving that purchase:<br>" . $this->_beans_result_get_error($vendor_purchase_lookup_result)); } if ($send_email) { if (!$email or !filter_var($email, FILTER_VALIDATE_EMAIL)) { return $this->_return_error("Please provide a valid email address."); } $company_settings = new Beans_Setup_Company_List($this->_beans_data_auth()); $company_settings_result = $company_settings->execute(); if (!$company_settings_result->success) { return $this->_return_error($this->_beans_result_get_error($company_settings_result)); } // Shorten for sanity's sake... $settings = $company_settings_result->data->settings; if (!isset($settings->company_email) or !strlen($settings->company_email)) { return $this->_return_error("Email cannot be sent until you set an email address for your company within 'Setup'."); } $message = Swift_Message::newInstance(); $message->setSubject($settings->company_name . ' - Purchase ' . $vendor_purchase_lookup_result->data->purchase->purchase_number)->setFrom(array($settings->company_email))->setTo(array($email)); $vendors_print_purchase = new View_Vendors_Print_Purchase(); $vendors_print_purchase->setup_company_list_result = $company_settings_result; $vendors_print_purchase->purchase = $vendor_purchase_lookup_result->data->purchase; $vendors_print_purchase->swift_email_message = $message; $message = $vendors_print_purchase->render(); try { if (!Email::connect()) { return $this->_return_error("Could not send email. Does your config have correct email settings?"); } if (!Email::sendMessage($message)) { return $this->_return_error("Could not send email. Does your config have correct email settings?"); } } catch (Exception $e) { return $this->_return_error("An error occurred when sending the email: " . $e->getMessage() . "<br><br>Have you setup email properly in config.php?"); } } $vendor_purchase_update_sent_data = new stdClass(); $vendor_purchase_update_sent_data->id = $purchase_id; if ($send_done or $send_email and $send_mail or $send_email and $vendor_purchase_lookup_result->data->purchase->sent == "print" or $send_mail and $vendor_purchase_lookup_result->data->purchase->sent == "email") { $vendor_purchase_update_sent_data->sent = 'both'; } else { if ($send_email) { $vendor_purchase_update_sent_data->sent = 'email'; } else { if ($send_mail) { $vendor_purchase_update_sent_data->sent = 'print'; } } } $vendor_purchase_update_sent = new Beans_Vendor_Purchase_Update_Sent($this->_beans_data_auth($vendor_purchase_update_sent_data)); $vendor_purchase_update_sent_result = $vendor_purchase_update_sent->execute(); if (!$vendor_purchase_update_sent_result->success) { return $this->_return_error("An error occurred when updating that purchase:<br>" . $this->_beans_result_get_error($vendor_purchase_update_sent_result)); } $html = new View_Partials_Vendors_Purchases_Purchase(); $html->purchase = $vendor_purchase_update_sent_result->data->purchase; $this->_return_object->data->purchase = $vendor_purchase_update_sent_result->data->purchase; $this->_return_object->data->purchase->html = $html->render(); }
/** * Adds a few Beans_ calls to each view ( such as company settings ). */ protected function _beans_default_calls() { // Get Version $b = new Beans(); $this->_view->beansbooks_version = $b->get_version(); // Only if logged in. if (!strlen(Session::instance()->get('auth_uid')) or !strlen(Session::instance()->get('auth_key')) or !strlen(Session::instance()->get('auth_expiration'))) { return FALSE; } $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; } $account_chart = new Beans_Account_Chart($this->_beans_data_auth()); $account_chart_result = $account_chart->execute(); if ($this->_beans_result_check($account_chart_result)) { $this->_view->account_chart_result = $account_chart_result; } $account_type_search = new Beans_Account_Type_Search($this->_beans_data_auth()); $account_type_search_result = $account_type_search->execute(); if ($this->_beans_result_check($account_type_search_result)) { $this->_view->account_type_search_result = $account_type_search_result; } // We don't want to override something set elsewhere - like in Controller_View_Setup -> action_taxes() if (!isset($this->_view->tax_search_result)) { $tax_search = new Beans_Tax_Search($this->_beans_data_auth((object) array('search_include_hidden' => TRUE))); $tax_search_result = $tax_search->execute(); if ($this->_beans_result_check($tax_search_result)) { $this->_view->tax_search_result = $tax_search_result; } } }
public function action_saleinvoice() { $sale_id = $this->request->post('sale_id'); $send_none = $this->request->post('send-none') ? TRUE : FALSE; $send_email = $this->request->post('send-email') ? TRUE : FALSE; $email = $this->request->post('email'); $send_mail = $this->request->post('send-mail') ? TRUE : FALSE; $send_done = $this->request->post('send-done') ? TRUE : FALSE; if (!$sale_id) { return $this->_return_error("ERROR: No sale ID provided."); } if (!$send_none and !$send_email and !$send_mail and !$send_done) { return $this->_return_error("ERROR: Please select at least one option."); } // Invoice $customer_sale_invoice = new Beans_Customer_Sale_Invoice($this->_beans_data_auth((object) array('id' => $sale_id))); $customer_sale_invoice_result = $customer_sale_invoice->execute(); if (!$customer_sale_invoice_result->success) { return $this->_return_error("An error occurred when converting that sale to an invoice:<br>" . $this->_beans_result_get_error($customer_sale_invoice_result)); } if ($send_none) { $html = new View_Partials_Customers_Sales_Sale(); $html->sale = $customer_sale_invoice_result->data->sale; $html->invoice_view = $this->request->post('invoice_view'); $this->_return_object->data->sale = $customer_sale_invoice_result->data->sale; $this->_return_object->data->sale->html = $html->render(); return; } if ($send_done) { $customer_sale_update_sent = new Beans_Customer_Sale_Update_Sent($this->_beans_data_auth((object) array('id' => $customer_sale_invoice_result->data->sale->id, 'sent' => 'both'))); $customer_sale_update_sent_result = $customer_sale_update_sent->execute(); $html = new View_Partials_Customers_Sales_Sale(); $html->sale = $customer_sale_update_sent_result->data->sale; $html->invoice_view = $this->request->post('invoice_view'); $this->_return_object->data->sale = $customer_sale_update_sent_result->data->sale; $this->_return_object->data->sale->html = $html->render(); return; } if ($send_email) { if (!$email or !filter_var($email, FILTER_VALIDATE_EMAIL)) { return $this->_return_error("Please provide a valid email address."); } $company_settings = new Beans_Setup_Company_List($this->_beans_data_auth()); $company_settings_result = $company_settings->execute(); if (!$company_settings_result->success) { return $this->_return_error($this->_beans_result_get_error($company_settings_result)); } // Shorten for sanity's sake... $settings = $company_settings_result->data->settings; if (!isset($settings->company_email) or !strlen($settings->company_email)) { return $this->_return_error("Email cannot be sent until you set an email address for your company within 'Setup'."); } $message = Swift_Message::newInstance(); $message->setSubject($settings->company_name . ' - ' . $customer_sale_invoice_result->data->sale->title)->setFrom(array($settings->company_email))->setTo(array($email)); $customers_print_sale = new View_Customers_Print_Sale(); $customers_print_sale->setup_company_list_result = $company_settings_result; $customers_print_sale->sale = $customer_sale_invoice_result->data->sale; $customers_print_sale->swift_email_message = $message; $message = $customers_print_sale->render(); try { if (!Email::connect()) { return $this->_return_error("Could not send email. Does your config have correct email settings?"); } if (!Email::sendMessage($message)) { return $this->_return_error("Could not send email. Does your config have correct email settings?"); } } catch (Exception $e) { return $this->_return_error("An error occurred when sending the email: " . $e->getMessage() . "<br><br>Have you setup email properly in config.php?"); } } // Update sale attributes only. $customer_sale_update_sent_data = new stdClass(); $customer_sale_update_sent_data->id = $sale_id; if ($send_done or $send_email and $send_mail or $send_email and $customer_sale_invoice_result->data->sale->sent == "print" or $send_mail and $customer_sale_invoice_result->data->sale->sent == "email") { $customer_sale_update_sent_data->sent = 'both'; } else { if ($send_email) { $customer_sale_update_sent_data->sent = 'email'; } else { if ($send_mail) { $customer_sale_update_sent_data->sent = 'print'; } } } $customer_sale_update_sent = new Beans_Customer_Sale_Update_Sent($this->_beans_data_auth($customer_sale_update_sent_data)); $customer_sale_update_sent_result = $customer_sale_update_sent->execute(); if (!$customer_sale_update_sent_result->success) { return $this->_return_error("An error occurred when updating that sale:<br>" . $this->_beans_result_get_error($customer_sale_update_sent_result)); } $html = new View_Partials_Customers_Sales_Sale(); $html->sale = $customer_sale_update_sent_result->data->sale; $html->invoice_view = $this->request->post('invoice_view'); $this->_return_object->data->sale = $customer_sale_update_sent_result->data->sale; $this->_return_object->data->sale->html = $html->render(); }
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_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; } }
/** * Adds a few Beans_ calls to each view ( such as company settings ). */ protected function _beans_default_calls() { // Only if logged in. if (!strlen(Session::instance()->get('auth_uid')) or !strlen(Session::instance()->get('auth_key')) or !strlen(Session::instance()->get('auth_expiration'))) { return FALSE; } $setup_company_list = new Beans_Setup_Company_List($this->_beans_data_auth()); $this->_setup_company_list_result = $setup_company_list->execute(); }