Пример #1
0
 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();
 }
Пример #2
0
 public function action_vendorpurchase()
 {
     $purchase_id = $this->request->param('id');
     $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) {
         // V2Item - Clean up and output nicely.
         die("An error occurred: " . $vendor_purchase_lookup_result->error);
     }
     $vendors_print_purchase = new View_Vendors_Print_Purchase();
     $vendors_print_purchase->purchase = $vendor_purchase_lookup_result->data->purchase;
     $vendors_print_purchase->setup_company_list_result = $this->_setup_company_list_result;
     die($vendors_print_purchase->render());
 }