Bug #11: For customer 35131752 ('kd'), the 15% e-conomic discount was configured on the customer but never applied to the draft invoice line items. The customer discount was only used in the flag/preview service for expected price calculations, not when actually building the draft invoice. Changes: - economicCustomers.php: log swallowed missing-currency-price errors so silently-missing discounts (like customer 35131752) become visible in the application log instead of vanishing. - economic_invoice_draft.php: thread the customer discount percentage through addOrderItemLines/addOrderItemLine and apply it at the line level (e-conomic's draft invoice line API requires per-line discountPercentage; an aggregate TotDiscount line is ignored when the customer has a per-line discount configured). - economic_invoices_draft_endpoint.php: forward the customer discount percentage to the draft builder. - collected_order_invoices_o.php: resolve the customer discount via Redis cache + e-conomicCustomers, then pass it to add_orders. - Tests: new EconomicInvoiceDraftCustomerDiscountTest covering the customer 35131752 15% case, plus updates to the existing wiring tests to account for the new parameter and the customer-discount guard on the aggregate TotDiscount line.
24 lines
1.1 KiB
PHP
24 lines
1.1 KiB
PHP
<?php
|
|
|
|
it('only adds TotDiscount aggregate line when itemized discounts are disabled and no customer discount is set', function (): void {
|
|
$content = file_get_contents(app_path('modules/economic/helpers/economic_invoice_draft.php'));
|
|
|
|
expect($content)->not->toBeFalse();
|
|
$content = (string)$content;
|
|
|
|
$start = strpos($content, 'public function addOrderItemLines');
|
|
$end = strpos($content, 'public function addOrderItemLine(', (int)$start + 1);
|
|
expect($start)->not->toBeFalse();
|
|
expect($end)->not->toBeFalse();
|
|
expect($end)->toBeGreaterThan($start);
|
|
|
|
$block = substr($content, (int)$start, (int)$end - (int)$start);
|
|
// The aggregate TotDiscount line is only added when neither itemized discounts
|
|
// nor a customer-level e-conomic discount is in effect. The customer discount
|
|
// (e.g. bug #11 customer 35131752 "kd" 15%) is applied at the line level instead.
|
|
expect($block)
|
|
->toContain('if (!$use_itemized_discounts && $customer_discount_percentage === 0 && $total_discount > 0)')
|
|
->toContain('self::addProductDiscountLine($total_discount');
|
|
});
|
|
|