diff --git a/composer.json b/composer.json index 691ceae..ee5182c 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ ], "require": { "php": "^7.4 || ^8.0", + "ext-libxml": "*", "sabre/xml": "^4.0", "nesbot/carbon": "^2.72 || ^3.11", "doctrine/collections": "^1.8 || ^2.0" diff --git a/src/Invoice.php b/src/Invoice.php index c4aede7..28c614e 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -902,10 +902,7 @@ public function xmlSerialize(Writer $writer): void } if (!empty($this->additionalDocumentReferences)) { - foreach ( - $this->additionalDocumentReferences - as $additionalDocumentReference - ) { + foreach ($this->additionalDocumentReferences as $additionalDocumentReference) { $writer->write([ Schema::CAC . "AdditionalDocumentReference" => $additionalDocumentReference, diff --git a/src/Reader.php b/src/Reader.php index 54e1d56..37c9084 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -28,6 +28,7 @@ public static function ubl($currencyId = 'EUR'): Service Schema::CAC. 'AccountingCustomerParty' => fn ($reader) => AccountingParty::xmlDeserialize($reader), Schema::CAC. 'AccountingSupplierParty' => fn ($reader) => AccountingParty::xmlDeserialize($reader), Schema::CAC. 'AdditionalDocumentReference' => fn ($reader) => AdditionalDocumentReference::xmlDeserialize($reader), + Schema::CAC. 'AdditionalItemProperty' => fn ($reader) => AdditionalItemProperty::xmlDeserialize($reader), Schema::CAC. 'Address' => fn ($reader) => Address::xmlDeserialize($reader), Schema::CAC. 'AddressLine' => fn ($reader) => AddressLine::xmlDeserialize($reader), Schema::CAC. 'AllowanceCharge' => fn ($reader) => AllowanceCharge::xmlDeserialize($reader), diff --git a/tests/Read/ItemAdditionalItemPropertyTest.php b/tests/Read/ItemAdditionalItemPropertyTest.php new file mode 100644 index 0000000..1e162e6 --- /dev/null +++ b/tests/Read/ItemAdditionalItemPropertyTest.php @@ -0,0 +1,78 @@ + + + 12345 + 2024-01-01 + + + + Supplier + + + + + + + Customer + + + + + 21.00 + + + 121.00 + + + 1 + 1 + 100 + + Test Product + + Color + Blue + + + + +XML; + + $ublReader = Reader::ubl(); + $invoice = $ublReader->parse($xml); + + $this->assertNotNull($invoice); + $this->assertInstanceOf(Invoice::class, $invoice); + + $invoiceLines = $invoice->getInvoiceLines(); + $this->assertNotEmpty($invoiceLines); + + $firstLine = array_values($invoiceLines)[0]; + $item = $firstLine->getItem(); + $this->assertNotNull($item); + + $additionalItemProperties = $item->getAdditionalItemProperties(); + $this->assertIsArray($additionalItemProperties); + $this->assertCount(1, $additionalItemProperties); + $firstAdditionalItemProperty = reset($additionalItemProperties); + $this->assertInstanceOf(AdditionalItemProperty::class, $firstAdditionalItemProperty); + $this->assertEquals('Color', $firstAdditionalItemProperty->getName()); + $this->assertEquals('Blue', $firstAdditionalItemProperty->getValue()); + } +} diff --git a/tests/Read/ItemOriginCountryTest.php b/tests/Read/ItemOriginCountryTest.php index 7f0d19a..95a2ad1 100644 --- a/tests/Read/ItemOriginCountryTest.php +++ b/tests/Read/ItemOriginCountryTest.php @@ -132,5 +132,5 @@ public function testItemWithoutOriginCountryCanBeRead() $originCountry = $item->getOriginCountry(); $this->assertNull($originCountry); } -} +}