From 5586f109f8a3ea907c28cb7ef64b6f0de888a65d Mon Sep 17 00:00:00 2001 From: Jasper Briers Date: Fri, 9 Jan 2026 20:23:53 +0100 Subject: [PATCH 1/3] Read all TaxSubtotals Until now, only one cac:TaxSubtotal was read from cac:TaxTotal, this patch fixes this behavior. --- src/TaxTotal.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/TaxTotal.php b/src/TaxTotal.php index 4f6d1ab..2ac087e 100644 --- a/src/TaxTotal.php +++ b/src/TaxTotal.php @@ -4,8 +4,9 @@ use InvalidArgumentException; -use function Sabre\Xml\Deserializer\keyValue; +use function Sabre\Xml\Deserializer\mixedContent; +use Doctrine\Common\Collections\ArrayCollection; use Sabre\Xml\Reader; use Sabre\Xml\Writer; use Sabre\Xml\XmlDeserializable; @@ -101,23 +102,18 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { - $keyValues = keyValue($reader); + $mixedContent = mixedContent($reader); + $collection = new ArrayCollection($mixedContent); - $taxSubTotals = array_values( - array_filter( - $keyValues, - fn ($value, $key) => $key === Schema::CAC . 'TaxSubtotal', ARRAY_FILTER_USE_BOTH - ) - ); + $taxSubTotals = ReaderHelper::getArrayValue(Schema::CAC . 'TaxSubtotal', $collection); return (new static()) ->setTaxAmount(isset($keyValues[Schema::CBC.'TaxAmount']) ? floatval($keyValues[Schema::CBC.'TaxAmount']) : null) ->setTaxSubTotals($taxSubTotals); - ; } } From a189fed2feb82d6d992ae02f6c135f6259a38b5d Mon Sep 17 00:00:00 2001 From: Jasper Briers Date: Fri, 9 Jan 2026 23:19:32 +0100 Subject: [PATCH 2/3] Fix TaxTotalTest The first element in the array apparently has key '1' instead of '0', switched to using reset() just to be sure that we get the first element of the array. --- tests/Read/TaxTotalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Read/TaxTotalTest.php b/tests/Read/TaxTotalTest.php index 34d0807..93791f7 100644 --- a/tests/Read/TaxTotalTest.php +++ b/tests/Read/TaxTotalTest.php @@ -115,7 +115,7 @@ public function testSingleTaxTotalDeserializes() $this->assertCount(1, $taxSubtotals); - $firstSubtotal = $taxSubtotals[0]; + $firstSubtotal = reset($taxSubtotals); $this->assertInstanceOf(TaxSubTotal::class, $firstSubtotal); From 7f3ee39e5a4d5c680e348ff4dc4cc13757027a6f Mon Sep 17 00:00:00 2001 From: Jasper Briers Date: Sat, 10 Jan 2026 14:27:05 +0100 Subject: [PATCH 3/3] Fix reading TaxAmount The previous change broke reading the cacTaxTotal/cbc:TaxAmount tag, this commit fixes this. --- src/TaxTotal.php | 3 ++- tests/Read/TaxTotalTest.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/TaxTotal.php b/src/TaxTotal.php index 2ac087e..3abf236 100644 --- a/src/TaxTotal.php +++ b/src/TaxTotal.php @@ -110,10 +110,11 @@ public static function xmlDeserialize(Reader $reader) $mixedContent = mixedContent($reader); $collection = new ArrayCollection($mixedContent); + $taxAmount = ReaderHelper::getTag(Schema::CBC . 'TaxAmount', $collection); $taxSubTotals = ReaderHelper::getArrayValue(Schema::CAC . 'TaxSubtotal', $collection); return (new static()) - ->setTaxAmount(isset($keyValues[Schema::CBC.'TaxAmount']) ? floatval($keyValues[Schema::CBC.'TaxAmount']) : null) + ->setTaxAmount(isset($taxAmount) ? floatval($taxAmount['value']) : null) ->setTaxSubTotals($taxSubTotals); } } diff --git a/tests/Read/TaxTotalTest.php b/tests/Read/TaxTotalTest.php index 93791f7..1e1fb79 100644 --- a/tests/Read/TaxTotalTest.php +++ b/tests/Read/TaxTotalTest.php @@ -111,6 +111,8 @@ public function testSingleTaxTotalDeserializes() $this->assertInstanceOf(TaxTotal::class, $taxTotal); + $this->assertEquals(20.79, $taxTotal->getTaxAmount()); + $taxSubtotals = $taxTotal->getTaxSubTotals(); $this->assertCount(1, $taxSubtotals);