public function action_customersale() { $sale_id = $this->request->param('id'); $customer_sale_lookup = new Beans_Customer_Sale_Lookup($this->_beans_data_auth((object) array('id' => $sale_id))); $customer_sale_lookup_result = $customer_sale_lookup->execute(); if (!$customer_sale_lookup_result->success) { // V2Item - Clean up and output nicely. die("An error occurred: " . $customer_sale_lookup_result->error); } $customers_print_sale = new View_Customers_Print_Sale(); $customers_print_sale->sale = $customer_sale_lookup_result->data->sale; $customers_print_sale->setup_company_list_result = $this->_setup_company_list_result; die($customers_print_sale->render()); }
public function action_salesend() { $sale_id = $this->request->post('sale_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 (!$sale_id) { return $this->_return_error("ERROR: No sale ID provided."); } if (!$send_email and !$send_mail and !$send_done) { return $this->_return_error("ERROR: Please select at least one option."); } $customer_sale_lookup = new Beans_Customer_Sale_Lookup($this->_beans_data_auth((object) array('id' => $sale_id))); $customer_sale_lookup_result = $customer_sale_lookup->execute(); if (!$customer_sale_lookup_result->success) { return $this->_return_error("An error occurred retrieving that sale:<br>" . $this->_beans_result_get_error($customer_sale_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 . ' - ' . $customer_sale_lookup_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_lookup_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_lookup_result->data->sale->sent == "print" or $send_mail and $customer_sale_lookup_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(); }