From 580e86605c6766d682e94579d7e2b52179024e0b Mon Sep 17 00:00:00 2001 From: Jasper Briers Date: Thu, 25 Sep 2025 13:16:27 +0200 Subject: [PATCH] Improve LegalMonetaryTotal cbc:AllowanceTotalAmount and cbc:ChargeTotalAmount shouldn't be required. --- src/LegalMonetaryTotal.php | 42 +++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/LegalMonetaryTotal.php b/src/LegalMonetaryTotal.php index 0baecd8..4abcd76 100644 --- a/src/LegalMonetaryTotal.php +++ b/src/LegalMonetaryTotal.php @@ -14,8 +14,8 @@ class LegalMonetaryTotal implements XmlSerializable, XmlDeserializable private $lineExtensionAmount = 0; private $taxExclusiveAmount = 0; private $taxInclusiveAmount = 0; - private $allowanceTotalAmount = 0; - private $chargeTotalAmount = 0; + private $allowanceTotalAmount; + private $chargeTotalAmount; private $prepaidAmount; private $payableAmount = 0; private $payableRoundingAmount; @@ -193,24 +193,32 @@ public function xmlSerialize(Writer $writer): void 'currencyID' => Generator::$currencyID ] - ], - [ - 'name' => Schema::CBC . 'AllowanceTotalAmount', - 'value' => NumberFormatter::format($this->allowanceTotalAmount,2), - 'attributes' => [ - 'currencyID' => Generator::$currencyID - ] + ] + ]); - ], - [ - 'name' => Schema::CBC . 'ChargeTotalAmount', - 'value' => NumberFormatter::format($this->chargeTotalAmount, 2), - 'attributes' => [ - 'currencyID' => Generator::$currencyID + if ($this->allowanceTotalAmount !== null) { + $writer->write([ + [ + 'name' => Schema::CBC . 'AllowanceTotalAmount', + 'value' => NumberFormatter::format($this->allowanceTotalAmount, 2), + 'attributes' => [ + 'currencyID' => Generator::$currencyID + ] ] + ]); + } - ] - ]); + if ($this->chargeTotalAmount !== null) { + $writer->write([ + [ + 'name' => Schema::CBC . 'ChargeTotalAmount', + 'value' => NumberFormatter::format($this->chargeTotalAmount, 2), + 'attributes' => [ + 'currencyID' => Generator::$currencyID + ] + ] + ]); + } if ($this->prepaidAmount !== null) { $writer->write([