Changeset 2583681
- Timestamp:
- 08/16/2021 05:35:11 PM (5 years ago)
- Location:
- smartaccounts/trunk
- Files:
-
- 4 edited
-
SmartAccountsApi.php (modified) (3 diffs)
-
SmartAccountsClass.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
-
smartaccounts.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smartaccounts/trunk/SmartAccountsApi.php
r2001667 r2583681 1 1 <?php 2 2 3 if ( !defined('ABSPATH')) {3 if (!defined('ABSPATH')) { 4 4 exit; 5 5 } // Exit if accessed directly … … 10 10 public function sendRequest($body, $apiUrl, $extraParams = null) 11 11 { 12 error_log("Sending SA call to $apiUrl"); 12 13 if ($body == null) { 13 14 $body = new stdClass(); … … 38 39 $decodedResponse = json_decode($saResponse, true); 39 40 40 if ( ! in_array($response_code, [200, 201]) || is_wp_error($saResponse)) { 41 42 if (!in_array($response_code, [200, 201]) || is_wp_error($saResponse)) { 43 error_log("SmartAccounts call failed url=$url: $response_code" . print_r($response, true)); 41 44 throw new Exception("SmartAccounts call failed url=$url: $response_code" . print_r($response, true)); 45 } 46 47 if (!$decodedResponse) { 48 return $saResponse; // Needed for getting raw PDF bytes 42 49 } 43 50 -
smartaccounts/trunk/SmartAccountsClass.php
r2465911 r2583681 13 13 class SmartAccountsClass 14 14 { 15 public static function attachPdf($attachments, $email_id, WC_Order $order, $email) 16 { 17 $settings = self::getSettings(); 18 // IF PDF attaching disabled then skip 19 // If no real_id found the skip 20 // If not order completed then skip 21 $invoiceId = get_post_meta($order->get_id(), 'smartaccounts_invoice_real_id', true); 22 $invoiceNumber = get_post_meta($order->get_id(), 'smartaccounts_invoice_id', true); 23 if ($email_id !== "customer_completed_order" || !$invoiceId || !$settings->attachPdf) { 24 return $attachments; 25 } 26 27 $api = new SmartAccountsApi(); 28 try { 29 $response = $api->sendRequest(null, 'purchasesales/clientinvoices:getpdf', "id=$invoiceId"); 30 } catch (Exception $exception) { 31 error_log("PDF not received to attach to the invoice"); 32 return $attachments; 33 } 34 35 $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "invoice_$invoiceNumber.pdf"; 36 file_put_contents($fileName, $response); 37 $attachments[] = $fileName; 38 error_log("Attachments are now: $email_id " . json_encode($attachments)); 39 40 return $attachments; 41 } 42 15 43 public static function orderOfferStatusProcessing($order_id) 16 44 { … … 22 50 || strlen(get_post_meta($order_id, 'smartaccounts_offer_id', true)) > 0) { 23 51 error_log("SmartAccounts order $order_id already sent as offer or invoice, not sending OFFER again, SA id=" 24 . get_post_meta($order_id, 'smartaccounts_invoice_id', true) . " offer_id="25 . get_post_meta($order_id, 'smartaccounts_offer_id', true));52 . get_post_meta($order_id, 'smartaccounts_invoice_id', true) . " offer_id=" 53 . get_post_meta($order_id, 'smartaccounts_offer_id', true)); 26 54 27 55 return; //Smartaccounts offer is already created … … 75 103 if (strlen(get_post_meta($order_id, 'smartaccounts_invoice_id', true)) > 0) { 76 104 error_log("SmartAccounts order $order_id already sent, not sending again, SA id=" 77 . get_post_meta($order_id, 'smartaccounts_invoice_id', true));105 . get_post_meta($order_id, 'smartaccounts_invoice_id', true)); 78 106 79 107 return; //Smartaccounts order is already created … … 88 116 $saPayment->createPayment(); 89 117 update_post_meta($order_id, 'smartaccounts_invoice_id', $invoice['invoice']['invoiceNumber']); 118 update_post_meta($order_id, 'smartaccounts_invoice_real_id', $invoice['invoice']['invoiceId']); 90 119 error_log("SmartAccounts sales invoice created for order $order_id - " . $invoice['invoice']['invoiceNumber']); 91 120 $order->add_order_note("Invoice sent to SmartAccounts: " . $invoice['invoice']['invoiceNumber']); … … 194 223 $settings->importProducts = isset($unSanitized->importProducts) && $unSanitized->importProducts === true; 195 224 $settings->importInventory = isset($unSanitized->importInventory) && $unSanitized->importInventory === true; 225 $settings->attachPdf = isset($unSanitized->attachPdf) && $unSanitized->attachPdf === true; 196 226 $settings->inventoryFilter = sanitize_text_field($unSanitized->inventoryFilter); 197 227 $objectId = sanitize_text_field($unSanitized->objectId); … … 280 310 if (!isset($currentSettings->importInventory)) { 281 311 $currentSettings->importInventory = true; 312 } 313 if (!isset($currentSettings->attachPdf)) { 314 $currentSettings->attachPdf = false; 282 315 } 283 316 if (!isset($currentSettings->inventoryFilter)) { … … 493 526 <td> 494 527 <input type="text" v-model="settings.inventoryFilter"><br> 495 <small>Comma separate list of Inventory account (Laokonto) to use when synching product stock quantities from eg 10710,10741. If not empty then overrides filters above.</small> 528 <small>Comma separate list of Inventory account (Laokonto) to use when synching product 529 stock quantities from eg 10710,10741. If not empty then overrides filters 530 above.</small> 496 531 </td> 497 532 </tr> … … 500 535 <td> 501 536 <input type="text" v-model="settings.warehouseId"><br> 502 <small>Leave empty if not not relevant</small> 537 <small>Leave empty if not relevant. Usually empty</small> 538 </td> 539 </tr> 540 <tr> 541 <th>Attach SmartAccounts PDF invoice customer e-mail</th> 542 <td> 543 <input type="checkbox" v-model="settings.attachPdf"> 544 <small></small> 503 545 </td> 504 546 </tr> -
smartaccounts/trunk/readme.txt
r2561842 r2583681 59 59 == Changelog == 60 60 61 = 3.7 = 62 Option to include SmartAccounts invoice when sending order completed message to the customer. 63 61 64 = 3.6 = 62 65 Price update improvements and more detailed logging for existing customer matching. -
smartaccounts/trunk/smartaccounts.php
r2561842 r2583681 4 4 * Plugin URI: https://github.com/smartman/woocommerce_smartaccounts 5 5 * Description: This plugin creates sales invoices in the smartaccounts.ee Online Accounting Software after Woocommerce order creation 6 * Version: 3. 66 * Version: 3.7 7 7 * Author: Margus Pala 8 8 * Author URI: https://marguspala.com … … 10 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 * Requires at least: 4.8.0 12 * Tested up to: 5. 7.212 * Tested up to: 5.8 13 13 */ 14 14 … … 55 55 } 56 56 57 add_filter('woocommerce_email_attachments', 'SmartAccountsClass::attachPdf', 10, 4); 58 57 59 add_action('sa_retry_failed_job', 'SmartAccountsClass::retryFailedOrders'); 58 60
Note: See TracChangeset
for help on using the changeset viewer.