Files
api/services/nginx/app/tests/Unit/Invoicing/EconomicLegacyDraftPayloadWiringTest.php
T
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

37 lines
1.7 KiB
PHP

<?php
it('wires legacy draft creation payload with customer e-conomic metadata and EAN delivery settings', function (): void {
$content = file_get_contents(app_path('modules/economic/invoices/draft/economic_invoice_draft_mo.php'));
expect($content)->not->toBeFalse();
$content = (string)$content;
expect($content)
->toContain('$customer = $this->economic->getCustomer((int)$this->customer_number);')
->toContain("\$recipient['nemHandelType'] = 'ean';")
->toContain("\$recipient['attention']")
->toContain("\$references['customerContact']")
->toContain("\$references['salesPerson']")
->toContain("\$references['vendorReference']")
->toContain("\$data['deliveryLocation']")
->toContain("'paymentTermsNumber' => (int)\$customer->getPaymentTermsNumber()")
->toContain("'vatZoneNumber' => (int)\$customer->getVatZoneNumber()")
->toContain("'currency' => \$customer->getCurrency() ?? 'DKK'");
});
it('selects the discount layout in legacy draft creation when lines carry itemized discount percentages', function (): void {
$content = file_get_contents(app_path('modules/economic/invoices/draft/economic_invoice_draft_mo.php'));
expect($content)->not->toBeFalse();
$content = (string)$content;
expect($content)
->toContain('private function resolveLayoutNumber(): int')
->toContain('if (!$this->hasDiscountedItemizedLines())')
->toContain('invoice_discount_layout')
->toContain('Discount invoice layout is not configured')
->toContain('private function hasDiscountedItemizedLines(): bool')
->toContain("\$line['discountPercentage']")
->toContain('return true;');
});