Changeset 2465911
- Timestamp:
- 01/31/2021 01:26:52 PM (5 years ago)
- Location:
- smartaccounts/trunk
- Files:
-
- 5 edited
-
SmartAccountsArticleAsync.php (modified) (4 diffs)
-
SmartAccountsClass.php (modified) (4 diffs)
-
SmartAccountsSalesInvoice.php (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
-
smartaccounts.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smartaccounts/trunk/SmartAccountsArticleAsync.php
r2298313 r2465911 21 21 $syncCount = 0; 22 22 $noSyncCount = 0; 23 24 $settings = SmartAccountsClass::getSettings(); 25 if (strlen($settings->inventoryFilter) === 0) { 26 $filter = []; 27 } else { 28 $filter = explode(',', $settings->inventoryFilter); 29 } 30 23 31 do { 24 32 $result = $api->sendRequest(null, "purchasesales/articles:get", "pageNumber=$page"); 25 33 if (isset($result['articles']) && is_array($result['articles'])) { 26 34 foreach ($result['articles'] as $article) { 27 if ($article['activeSales'] && ($article['type'] == 'PRODUCT' || $article['type'] == 'WH')) { 28 if (count($products) == 20) { 29 $productsBatches[] = $products; 30 $products = []; 31 } 32 $products[$article['code']] = [ 33 'code' => $article['code'], 34 'price' => $article['priceSales'], 35 'description' => $article['description'], 36 'quantity' => 0 37 ]; 38 $syncCount++; 39 } else { 40 error_log("Not active sales and not product nor WH item " . $article['code']); 35 if (!$article['activeSales']) { 36 continue; 37 } 38 39 if (count($filter) > 0 && !in_array($article['accountWarehouse'], $filter)) { 40 error_log('Item filtered from sync ' . $article['code']); 41 41 $noSyncCount++; 42 continue; 42 43 } 44 45 if ($article['type'] === 'PRODUCT' && !$settings->importProducts) { 46 error_log('not importing PRODUCT ' . $article['code']); 47 $noSyncCount++; 48 continue; 49 } elseif ($article['type'] === 'SERVICE' && !$settings->importServices) { 50 error_log('not importing SERVICE ' . $article['code']); 51 $noSyncCount++; 52 continue; 53 } elseif ($article['type'] === 'WH' && !$settings->importInventory) { 54 error_log('not importing WH ' . $article['code']); 55 $noSyncCount++; 56 continue; 57 } 58 59 if (count($products) == 20) { 60 $productsBatches[] = $products; 61 $products = []; 62 } 63 64 $products[$article['code']] = [ 65 'code' => $article['code'], 66 'price' => $article['priceSales'], 67 'description' => $article['description'], 68 'quantity' => 0 69 ]; 70 $syncCount++; 43 71 } 44 72 } … … 64 92 function task($products) 65 93 { 66 if ( !is_array($products)) {94 if (!is_array($products)) { 67 95 error_log('Not an array, something is wrong, removing from sync list: ' . print_r($products, true)); 68 96 … … 104 132 foreach ($products as $code => $product) { 105 133 $productId = wc_get_product_id_by_sku($code); 106 if ( !$productId) {134 if (!$productId) { 107 135 error_log("Inserting product $code"); 108 136 $this->insertProduct($code, $product); … … 145 173 $finalPrice = get_post_meta($post_id, '_price', true); 146 174 $salePrice = get_post_meta($post_id, '_sale_price', true); 147 if ( ! $regularPrice || !$finalPrice) {175 if (!$regularPrice || !$finalPrice) { 148 176 // No price set at all yet, set one now. 149 177 update_post_meta($post_id, '_regular_price', $data['price']); -
smartaccounts/trunk/SmartAccountsClass.php
r2328274 r2465911 1 1 <?php 2 3 if (!defined('ABSPATH')) { 4 exit; 5 } // Exit if accessed directly 2 6 3 7 include_once('SmartAccountsClient.php'); … … 186 190 $settings->defaultPayment = sanitize_text_field($unSanitized->defaultPayment); 187 191 $settings->vat_number_meta = sanitize_text_field($unSanitized->vat_number_meta); 192 $settings->warehouseId = sanitize_text_field($unSanitized->warehouseId); 193 $settings->importServices = isset($unSanitized->importServices) && $unSanitized->importServices === true; 194 $settings->importProducts = isset($unSanitized->importProducts) && $unSanitized->importProducts === true; 195 $settings->importInventory = isset($unSanitized->importInventory) && $unSanitized->importInventory === true; 196 $settings->inventoryFilter = sanitize_text_field($unSanitized->inventoryFilter); 188 197 $objectId = sanitize_text_field($unSanitized->objectId); 198 189 199 if (preg_match("/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/", $objectId)) { 190 200 $settings->objectId = $objectId; … … 258 268 if (!isset($currentSettings->vat_number_meta)) { 259 269 $currentSettings->vat_number_meta = "vat_number"; 270 } 271 if (!isset($currentSettings->warehouseId)) { 272 $currentSettings->warehouseId = null; 273 } 274 if (!isset($currentSettings->importServices)) { 275 $currentSettings->importServices = false; 276 } 277 if (!isset($currentSettings->importProducts)) { 278 $currentSettings->importProducts = true; 279 } 280 if (!isset($currentSettings->importInventory)) { 281 $currentSettings->importInventory = true; 282 } 283 if (!isset($currentSettings->inventoryFilter)) { 284 $currentSettings->inventoryFilter = ""; 260 285 } 261 286 if (!isset($currentSettings->paymentMethods) || !is_object($currentSettings->paymentMethods)) { … … 442 467 </table> 443 468 469 <h2>Warehouse and import config</h2> 470 <small>What type of articles to sync from SmartAccounts and what warehouses to use 471 </small> 472 <table class="form-table"> 473 <tr valign="top"> 474 <th>Import Services</th> 475 <td> 476 <input type="checkbox" v-model="settings.importServices"> 477 </td> 478 </tr> 479 <tr valign="top"> 480 <th>Import Products</th> 481 <td> 482 <input type="checkbox" v-model="settings.importProducts"> 483 </td> 484 </tr> 485 <tr valign="top"> 486 <th>Import Warehouse Inventory</th> 487 <td> 488 <input type="checkbox" v-model="settings.importInventory"> 489 </td> 490 </tr> 491 <tr valign="top"> 492 <th>Warehouse filter (Overrides others)</th> 493 <td> 494 <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> 496 </td> 497 </tr> 498 <tr valign="top"> 499 <th>What warehouse to use when sending sales invoice.</th> 500 <td> 501 <input type="text" v-model="settings.warehouseId"><br> 502 <small>Leave empty if not not relevant</small> 503 </td> 504 </tr> 505 </table> 506 444 507 <br> 445 508 <br> -
smartaccounts/trunk/SmartAccountsSalesInvoice.php
r2369311 r2465911 13 13 { 14 14 $this->client = $client; 15 $this->order = $order;16 $this->api = new SmartAccountsApi();15 $this->order = $order; 16 $this->api = new SmartAccountsApi(); 17 17 } 18 18 … … 21 21 $apiUrl = "purchasesales/clientoffers:add"; 22 22 23 $body = new stdClass();24 $body->clientId = $this->client["id"];25 $body->date = $this->order->get_date_created()->date("d.m.Y");26 $body->currency = $this->order->get_currency();27 $body->rows = $this->getOrderRows();23 $body = new stdClass(); 24 $body->clientId = $this->client["id"]; 25 $body->date = $this->order->get_date_created()->date("d.m.Y"); 26 $body->currency = $this->order->get_currency(); 27 $body->rows = $this->getOrderRows(); 28 28 $body->roundAmount = $this->getRoundingAmount($body->rows); 29 $body->amount = $this->order->get_total();30 $body->offerNote = "WooCommerce order #" . $this->order->get_id() . ". " . $this->order->get_customer_note();29 $body->amount = $this->order->get_total(); 30 $body->offerNote = "WooCommerce order #" . $this->order->get_id() . ". " . $this->order->get_customer_note(); 31 31 32 32 $settings = json_decode(get_option("sa_settings")); … … 47 47 $apiUrl = "purchasesales/clientinvoices:add"; 48 48 49 $body = new stdClass();50 $body->clientId = $this->client["id"];51 $body->date = $this->order->get_date_created()->date("d.m.Y");52 $body->currency = $this->order->get_currency();53 $body->rows = $this->getOrderRows();49 $body = new stdClass(); 50 $body->clientId = $this->client["id"]; 51 $body->date = $this->order->get_date_created()->date("d.m.Y"); 52 $body->currency = $this->order->get_currency(); 53 $body->rows = $this->getOrderRows(); 54 54 $body->roundAmount = $this->getRoundingAmount($body->rows); 55 $body->amount = $this->order->get_total();55 $body->amount = $this->order->get_total(); 56 56 $body->invoiceNote = "WooCommerce order #" . $this->order->get_id() . ". " . $this->order->get_customer_note(); 57 57 … … 64 64 if ($settings && $settings->objectId) { 65 65 $body->objectId = $settings->objectId; 66 } 67 68 if ($settings && $settings->warehouseId) { 69 $body->warehouseId = $settings->warehouseId; 66 70 } 67 71 … … 101 105 private function getOrderRows() 102 106 { 103 $rows = [];107 $rows = []; 104 108 $totalTax = $this->getTotalTax(); 105 109 $subTotal = $this->getOrderTotal(); 106 $vatPc = round($totalTax * 100 / $subTotal);110 $vatPc = round($totalTax * 100 / $subTotal); 107 111 foreach ($this->order->get_items() as $item) { 108 112 $product = $item->get_product(); 109 $row = new stdClass();113 $row = new stdClass(); 110 114 if ($product == null) { 111 115 error_log("SA Product not found for order item " . $item->get_id()); 112 116 $row->description = $item->get_name(); 113 $code = "wc_missing_product_" . $item->get_id();117 $code = "wc_missing_product_" . $item->get_id(); 114 118 } else { 115 119 $code = $product->get_sku(); … … 118 122 } 119 123 120 //in case 124 //in case 121 125 $codeSplit = explode(",", $code); 122 126 if (count($codeSplit) > 1) { … … 132 136 $row->description = preg_replace('/[\xF0-\xF7].../s', '_', $row->description); 133 137 134 $row->code = $code;138 $row->code = $code; 135 139 $row->quantity = $item->get_quantity(); 136 140 137 141 $rowPrice = $item->get_total() / $item->get_quantity(); 138 142 139 $row->price = number_format($rowPrice, 2, ".", "");140 $row->vatPc = $vatPc;143 $row->price = number_format($rowPrice, 2, ".", ""); 144 $row->vatPc = $vatPc; 141 145 $row->totalCents = intval(round(floatval($row->price) * $row->quantity * 100)); 142 $row->taxCents = intval(round($row->totalCents * $vatPc / 100));146 $row->taxCents = intval(round($row->totalCents * $vatPc / 100)); 143 147 144 148 $settings = json_decode(get_option("sa_settings")); … … 151 155 152 156 if ($this->order->get_shipping_total() > 0) { 153 $settings = json_decode(get_option("sa_settings"));154 $row = new stdClass();155 $row->code = isset($settings->defaultShipping) ? $settings->defaultShipping : "shipping";157 $settings = json_decode(get_option("sa_settings")); 158 $row = new stdClass(); 159 $row->code = isset($settings->defaultShipping) ? $settings->defaultShipping : "shipping"; 156 160 $row->description = "Woocommerce Shipping"; 157 $row->price = $this->order->get_shipping_total();158 $row->quantity = 1;159 $row->vatPc = $vatPc;160 $row->totalCents = intval(round(floatval($row->price) * $row->quantity * 100));161 $row->taxCents = intval(round($row->totalCents * $vatPc / 100));161 $row->price = $this->order->get_shipping_total(); 162 $row->quantity = 1; 163 $row->vatPc = $vatPc; 164 $row->totalCents = intval(round(floatval($row->price) * $row->quantity * 100)); 165 $row->taxCents = intval(round($row->totalCents * $vatPc / 100)); 162 166 163 167 $settings = json_decode(get_option("sa_settings")); -
smartaccounts/trunk/readme.txt
r2369311 r2465911 2 2 Tags: SmartAccounts, smartaccounts, WooCommerce 3 3 Requires at least: 4.8 4 Tested up to: 5. 44 Tested up to: 5.6 5 5 License: GPLv2 or later 6 6 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 59 59 == Changelog == 60 60 61 = 3.4 = 62 Product import filters and Warehouse setting for new invoices. 63 61 64 = 3.2 = 62 65 Strip unsupported characters when creating invoices. -
smartaccounts/trunk/smartaccounts.php
r2369311 r2465911 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. 26 * Version: 3.4 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. 512 * Tested up to: 5.6 13 13 */ 14 14 15 if ( !defined('ABSPATH')) {15 if (!defined('ABSPATH')) { 16 16 exit; 17 17 } // Exit if accessed directly 18 18 19 include_once( ABSPATH . 'wp-admin/includes/plugin.php');19 include_once(ABSPATH . 'wp-admin/includes/plugin.php'); 20 20 21 21 function smartaccounts_missing_wc_admin_notice()
Note: See TracChangeset
for help on using the changeset viewer.