## 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>
95 lines
4.0 KiB
PHP
95 lines
4.0 KiB
PHP
<?php
|
|
|
|
app_require('modules/economic/helpers/economic_customer.php');
|
|
|
|
use helpers\economic_customer;
|
|
|
|
function economic_customer_helper_from_payload(object $payload): economic_customer
|
|
{
|
|
$reflection = new ReflectionClass(economic_customer::class);
|
|
/** @var economic_customer $customer */
|
|
$customer = $reflection->newInstanceWithoutConstructor();
|
|
|
|
$property = $reflection->getProperty('customer_data_object');
|
|
$property->setValue($customer, $payload);
|
|
|
|
return $customer;
|
|
}
|
|
|
|
it('exposes optional EAN and public entry number from fetched e-conomic customer data', function (): void {
|
|
$customer = economic_customer_helper_from_payload((object)[
|
|
'customerNumber' => 42331123,
|
|
'ean' => ' 5790001234567 ',
|
|
'publicEntryNumber' => ' DK123456789 ',
|
|
'attention' => (object)[
|
|
'customerContactNumber' => 9,
|
|
'self' => 'https://restapi.e-conomic.com/customers/42331123/contacts/9',
|
|
],
|
|
'customerContact' => (object)[
|
|
'customerContactNumber' => 10,
|
|
'self' => 'https://restapi.e-conomic.com/customers/42331123/contacts/10',
|
|
],
|
|
'salesPerson' => (object)[
|
|
'employeeNumber' => 12,
|
|
'self' => 'https://restapi.e-conomic.com/employees/12',
|
|
],
|
|
'vendorReference' => (object)[
|
|
'employeeNumber' => 14,
|
|
'self' => 'https://restapi.e-conomic.com/employees/14',
|
|
],
|
|
'defaultDeliveryLocation' => (object)[
|
|
'deliveryLocationNumber' => 7,
|
|
'self' => 'https://restapi.e-conomic.com/customers/42331123/delivery-locations/7',
|
|
],
|
|
]);
|
|
|
|
expect($customer->getEan())->toBe('5790001234567');
|
|
expect($customer->getPublicEntryNumber())->toBe('DK123456789');
|
|
expect($customer->getAttentionReference())->toBe([
|
|
'customerContactNumber' => 9,
|
|
'self' => 'https://restapi.e-conomic.com/customers/42331123/contacts/9',
|
|
]);
|
|
expect($customer->getReferenceCustomerContact())->toBe([
|
|
'customerContactNumber' => 10,
|
|
'self' => 'https://restapi.e-conomic.com/customers/42331123/contacts/10',
|
|
]);
|
|
expect($customer->getSalesPersonReference())->toBe([
|
|
'employeeNumber' => 12,
|
|
'self' => 'https://restapi.e-conomic.com/employees/12',
|
|
]);
|
|
expect($customer->getVendorReferenceReference())->toBe([
|
|
'employeeNumber' => 14,
|
|
'self' => 'https://restapi.e-conomic.com/employees/14',
|
|
]);
|
|
expect($customer->getDefaultDeliveryLocationReference())->toBe([
|
|
'deliveryLocationNumber' => 7,
|
|
'self' => 'https://restapi.e-conomic.com/customers/42331123/delivery-locations/7',
|
|
]);
|
|
expect($customer->getAttentionCustomerContactNumber())->toBe(9);
|
|
expect($customer->getReferenceCustomerContactNumber())->toBe(10);
|
|
expect($customer->getSalesPersonEmployeeNumber())->toBe(12);
|
|
expect($customer->getVendorReferenceEmployeeNumber())->toBe(14);
|
|
expect($customer->getDefaultDeliveryLocationNumber())->toBe(7);
|
|
});
|
|
|
|
it('returns null for blank optional e-conomic customer recipient identifiers', function (): void {
|
|
$customer = economic_customer_helper_from_payload((object)[
|
|
'customerNumber' => 42331123,
|
|
'ean' => ' ',
|
|
'publicEntryNumber' => '',
|
|
]);
|
|
|
|
expect($customer->getEan())->toBeNull();
|
|
expect($customer->getPublicEntryNumber())->toBeNull();
|
|
expect($customer->getAttentionReference())->toBeNull();
|
|
expect($customer->getReferenceCustomerContact())->toBeNull();
|
|
expect($customer->getSalesPersonReference())->toBeNull();
|
|
expect($customer->getVendorReferenceReference())->toBeNull();
|
|
expect($customer->getDefaultDeliveryLocationReference())->toBeNull();
|
|
expect($customer->getAttentionCustomerContactNumber())->toBeNull();
|
|
expect($customer->getReferenceCustomerContactNumber())->toBeNull();
|
|
expect($customer->getSalesPersonEmployeeNumber())->toBeNull();
|
|
expect($customer->getVendorReferenceEmployeeNumber())->toBeNull();
|
|
expect($customer->getDefaultDeliveryLocationNumber())->toBeNull();
|
|
});
|