Changeset 3496827
- Timestamp:
- 04/01/2026 04:43:32 PM (4 days ago)
- Location:
- flowdino/trunk
- Files:
-
- 4 edited
-
changelog.txt (modified) (1 diff)
-
flowdino.php (modified) (2 diffs)
-
includes/tabs/class-flowdino-wc-sales-tab.php (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
flowdino/trunk/changelog.txt
r3493443 r3496827 1 1 *** FlowDino Changelog *** 2 3 2026-04-01 - version 1.1.11 4 * Sales - Orders are now imported with status "Processing" instead of "Pending" 5 * Sales - Order lines are matched against WooCommerce products via FlowDino sync table, externalKey, SKU and title 6 * Sales - Stock levels are automatically decremented when a new order is imported 7 * Sales - Shipping label URL (urlEtiquette) is saved on the order and displayed as a download button in the WC order admin page 8 * Sales - Tax handling: TTC amounts are split into HT + VAT when WooCommerce taxes are enabled 9 * Sales - Added resync feature: reset sync date from a chosen date and re-import all orders 2 10 3 11 2026-03-28 - version 1.0.9 -
flowdino/trunk/flowdino.php
r3496763 r3496827 4 4 * Plugin URI: https://www.flowdino.com 5 5 * Description: Automatically synchronize your WooCommerce catalog with the FlowDino platform for centralized product management. 6 * Version: 1. 0.96 * Version: 1.1.11 7 7 * Author: Jeremy DUMONT 8 8 * License: GPL v2 or later … … 28 28 } 29 29 if (!defined('FLOWDINO_VERSION')) { 30 define('FLOWDINO_VERSION', '1. 0.9');30 define('FLOWDINO_VERSION', '1.1.11'); 31 31 } 32 32 -
flowdino/trunk/includes/tabs/class-flowdino-wc-sales-tab.php
r3496763 r3496827 380 380 381 381 // --- Order lines --- 382 $order_lines = $order_data['orderLines'] ?? array(); 383 $total_lines = 0.0; 382 $order_lines = $order_data['orderLines'] ?? array(); 383 $total_lines_ht = 0.0; 384 $billing_country = $order->get_billing_country(); 384 385 385 386 if (!empty($order_lines)) { 386 387 foreach ($order_lines as $line) { 387 388 $product_id = $this->get_wc_product_id_from_line($line); 388 $line_total = (float) ($line['amountLines'] ?? 0); 389 $total_lines += $line_total; 389 $line_ttc = (float) ($line['amountLines'] ?? 0); 390 391 $product = $product_id ? wc_get_product($product_id) : null; 392 $tax_class = $product ? $product->get_tax_class() : ''; 393 $amounts = $this->split_ttc_amount($line_ttc, $billing_country, $tax_class); 394 $total_lines_ht += $amounts['ht']; 390 395 391 396 $item = new WC_Order_Item_Product(); 392 397 $item->set_name(sanitize_text_field($line['title'] ?? __('Produit FlowDino', 'flowdino'))); 393 398 $item->set_quantity(1); 394 $item->set_ total($line_total);395 $item->set_ subtotal($line_total);399 $item->set_subtotal($amounts['ht']); 400 $item->set_total($amounts['ht']); 396 401 397 402 if ($product_id) { 398 403 $item->set_product_id($product_id); 399 $product = wc_get_product($product_id); 400 if ($product && $product->get_type() === 'variable') { 401 // Leave variation_id at 0 – enough for line creation 402 } 404 } 405 406 if (!empty($amounts['rates']) && $amounts['tax'] > 0.0) { 407 $taxes = WC_Tax::calc_tax($amounts['ht'], $amounts['rates'], false); 408 $item->set_taxes(array('total' => $taxes, 'subtotal' => $taxes)); 403 409 } 404 410 … … 409 415 $amount_order = (float) ($order_data['amountOrder'] ?? 0); 410 416 $fees_order = (float) ($order_data['feesOrder'] ?? 0); 411 $total_lines = $amount_order - $fees_order; 417 $line_ttc = $amount_order - $fees_order; 418 419 $amounts = $this->split_ttc_amount($line_ttc, $billing_country, ''); 420 $total_lines_ht = $amounts['ht']; 412 421 413 422 $item = new WC_Order_Item_Product(); … … 418 427 )); 419 428 $item->set_quantity(1); 420 $item->set_total($total_lines); 421 $item->set_subtotal($total_lines); 429 $item->set_subtotal($amounts['ht']); 430 $item->set_total($amounts['ht']); 431 432 if (!empty($amounts['rates']) && $amounts['tax'] > 0.0) { 433 $taxes = WC_Tax::calc_tax($amounts['ht'], $amounts['rates'], false); 434 $item->set_taxes(array('total' => $taxes, 'subtotal' => $taxes)); 435 } 436 422 437 $order->add_item($item); 423 438 } 424 439 425 // Totals 426 $order->set_total((float) ($order_data['amountOrder'] ?? $total_lines)); 440 // Aggregate tax line items from per-item taxes 441 if (wc_tax_enabled()) { 442 $order->calculate_taxes(); 443 } 444 445 // Grand total = TTC amount from FlowDino 446 $grand_total_ttc = (float) ($order_data['amountOrder'] ?? 0); 447 $order->set_total($grand_total_ttc > 0 ? $grand_total_ttc : $total_lines_ht); 427 448 428 449 // FlowDino order reference as meta … … 584 605 private function clean_field($value) { 585 606 return sanitize_text_field(wp_strip_all_tags($value)); 607 } 608 609 /** 610 * Split a TTC (tax-included) amount into HT (ex-tax) and tax portions. 611 * 612 * If WooCommerce taxes are disabled, returns the full amount as HT with no tax. 613 * Uses WC_Tax::find_rates() with the billing country and product tax class. 614 * 615 * @param float $ttc Amount including tax. 616 * @param string $country Billing country ISO code (e.g. 'FR'). 617 * @param string $tax_class WooCommerce tax class ('' = standard). 618 * @return array { ht: float, tax: float, rates: array } 619 */ 620 private function split_ttc_amount(float $ttc, string $country, string $tax_class = ''): array { 621 $empty = array('ht' => $ttc, 'tax' => 0.0, 'rates' => array()); 622 623 if (!wc_tax_enabled() || $ttc <= 0) { 624 return $empty; 625 } 626 627 $rates = WC_Tax::find_rates(array( 628 'country' => $country, 629 'tax_class' => $tax_class, 630 )); 631 632 if (empty($rates)) { 633 $rates = WC_Tax::get_rates($tax_class); 634 } 635 636 if (empty($rates)) { 637 return $empty; 638 } 639 640 $total_rate = array_sum(array_column($rates, 'rate')); 641 if ($total_rate <= 0) { 642 return array('ht' => $ttc, 'tax' => 0.0, 'rates' => $rates); 643 } 644 645 $ht = (float) wc_format_decimal($ttc / (1.0 + $total_rate / 100.0), wc_get_price_decimals()); 646 $tax = (float) wc_format_decimal($ttc - $ht, wc_get_price_decimals()); 647 648 return array('ht' => $ht, 'tax' => $tax, 'rates' => $rates); 586 649 } 587 650 -
flowdino/trunk/readme.txt
r3493443 r3496827 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1. 0.97 Stable tag: 1.1.11 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.