## Context Queue job **#3572** failed in `COLLECTED_INVOICE_EXPORT` with e-conomic HTTP 400 (`Validation failed. 2 errors found.`) while creating draft for customer `35131752`. ## Fix - align draft payload optional references to e-conomic object references (not id-only fragments): - `recipient.attention` - `references.customerContact` - `references.salesPerson` - `references.vendorReference` (legacy path) - `deliveryLocation` - include upstream `self` links when available from customer payload - keep both collected and legacy draft creation paths consistent - improve e-conomic error formatting so nested annotated validation errors and `developerHint` are included in thrown messages ## Tests - `vendor/bin/pest tests/Unit/Invoicing/EconomicCustomerEanHelperTest.php tests/Unit/Invoicing/EconomicInvoiceDraftRecipientEanWiringTest.php tests/Unit/Invoicing/EconomicLegacyDraftPayloadWiringTest.php tests/Unit/Invoicing/EconomicUpstreamErrorFormattingTest.php tests/Unit/Invoicing/EconomicLegacyDraftDiscountWiringTest.php tests/Unit/Invoicing/EconomicInvoiceDraftDiscountLineModeWiringTest.php tests/Unit/Invoicing/CollectedInvoiceEconomicBatchTransferWiringTest.php tests/Unit/Invoicing/EconomicInvoiceDraftItemizedDiscountTest.php --colors=never` Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
42 lines
2.0 KiB
PHP
42 lines
2.0 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('$customer->getAttentionReference()')
|
|
->toContain("\$recipient['attention']")
|
|
->toContain('$customer->getReferenceCustomerContact()')
|
|
->toContain("\$references['customerContact']")
|
|
->toContain('$customer->getSalesPersonReference()')
|
|
->toContain("\$references['salesPerson']")
|
|
->toContain('$customer->getVendorReferenceReference()')
|
|
->toContain("\$references['vendorReference']")
|
|
->toContain('$customer->getDefaultDeliveryLocationReference()')
|
|
->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;');
|
|
});
|