Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
78 changes: 78 additions & 0 deletions tests/Read/ItemAdditionalItemPropertyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace NumNum\UBL\Tests\Read;

use NumNum\UBL\AdditionalItemProperty;
use NumNum\UBL\Invoice;
use NumNum\UBL\Reader;
use PHPUnit\Framework\TestCase;

class ItemAdditionalItemPropertyTest extends TestCase
{
/** @test */
public function testAdditionalItemPropertiesAreHydratedAsObjects()
{
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<cbc:ID>12345</cbc:ID>
<cbc:IssueDate>2024-01-01</cbc:IssueDate>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PartyName>
<cbc:Name>Supplier</cbc:Name>
</cac:PartyName>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyName>
<cbc:Name>Customer</cbc:Name>
</cac:PartyName>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="EUR">21.00</cbc:TaxAmount>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:PayableAmount currencyID="EUR">121.00</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>1</cbc:ID>
<cbc:InvoicedQuantity unitCode="C62">1</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">100</cbc:LineExtensionAmount>
<cac:Item>
<cbc:Name>Test Product</cbc:Name>
<cac:AdditionalItemProperty>
<cbc:Name>Color</cbc:Name>
<cbc:Value>Blue</cbc:Value>
</cac:AdditionalItemProperty>
</cac:Item>
</cac:InvoiceLine>
</Invoice>
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());
}
}
2 changes: 1 addition & 1 deletion tests/Read/ItemOriginCountryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ public function testItemWithoutOriginCountryCanBeRead()
$originCountry = $item->getOriginCountry();
$this->assertNull($originCountry);
}
}

}