From cfcccb2d0ba090c3a6f45e49b8325c7f30d7bcc5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 29 Oct 2024 21:40:21 +1100 Subject: [PATCH] Minor fixes --- src/EInvoice.php | 18 ++++++++++++++++++ src/Models/Peppol/AllowanceCharge.php | 7 ++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/EInvoice.php b/src/EInvoice.php index d475bc0..dc4ea53 100644 --- a/src/EInvoice.php +++ b/src/EInvoice.php @@ -178,12 +178,30 @@ public function encode(mixed $object, string $type): string $object = $serializer->normalize($object, null, [\Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::SKIP_NULL_VALUES => true]); + $object = $this->removeEmptyValues($object); + $data = $serializer->encode($object, $type, $context); return $type == 'xml' ? $this->decorateXml($data) : $data; } + private function removeEmptyValues(array $array): array + { + foreach ($array as $key => $value) { + if (is_array($value)) { + $array[$key] = $this->removeEmptyValues($value); + if (empty($array[$key])) { + unset($array[$key]); + } + } elseif ($value === null || $value === '') { + unset($array[$key]); + } + } + + return $array; + } + /** * DecorateXml * diff --git a/src/Models/Peppol/AllowanceCharge.php b/src/Models/Peppol/AllowanceCharge.php index 612f4ad..c0b0283 100644 --- a/src/Models/Peppol/AllowanceCharge.php +++ b/src/Models/Peppol/AllowanceCharge.php @@ -28,12 +28,9 @@ class AllowanceCharge #[SerializedName('cbc:ID')] public $ID; - /** @var bool */ - #[NotNull] - #[NotBlank] - #[Valid] + /** @var string */ #[SerializedName('cbc:ChargeIndicator')] - public bool $ChargeIndicator; + public string $ChargeIndicator; /** @var AllowanceChargeReasonCode */ #[SerializedName('cbc:AllowanceChargeReasonCode')]