Commit Graph
2 Commits
Author SHA1 Message Date
MiniMax M3 Subagent 8972b8f2ae fix(api): apply e-conomic discount percentage at line level for customer 35131752
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.
2026-08-10 16:23:05 +02:00
59107a6bb2 Enforce e-conomic discount template + EAN draft metadata (#349)
## What changed
- enforce EAN draft delivery wiring by setting
`recipient.nemHandelType=ean` when customer EAN is present
- copy existing e-conomic customer metadata into draft payload:
`recipient.attention`, `references.customerContact`,
`references.salesPerson`, and `deliveryLocation`
- keep `references.other` external-id mapping intact
- remove legacy explicit `Rabat:` text-line injection and use line-level
`discountPercentage` instead
- add/update unit tests for helper extraction and discount/EAN wiring

## Tests
- `vendor/bin/pest
tests/Unit/Invoicing/EconomicCustomerEanHelperTest.php
tests/Unit/Invoicing/EconomicInvoiceDraftRecipientEanWiringTest.php
tests/Unit/Invoicing/EconomicLegacyDraftDiscountWiringTest.php
tests/Unit/Invoicing/EconomicInvoiceDraftDiscountLineModeWiringTest.php
tests/Unit/Invoicing/CollectedInvoiceEconomicBatchTransferWiringTest.php
tests/Unit/Invoicing/EconomicInvoiceDraftItemizedDiscountTest.php
--colors=never`

## Notes
- full unit suite in this environment still has an unrelated
pre-existing failure in
`Tests\\Unit\\Bird\\BirdControlPlaneActivationTest` requiring
`PLENO_REPO_ROOT_FOR_TESTS`.
- live manual verification against customer `12345679` remains
environment-blocked due missing e-conomic credentials.

---------

Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-05 14:44:40 +02:00