From 040979d7e603396eda7db0e3b557e6fb6ae3c089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Sat, 3 Aug 2024 16:45:00 +0200 Subject: [PATCH] Added project reference (BT-11) - Updated Invoice class - Updated UBL reader and writer - Updated tests > Closes #60 --- src/Invoice.php | 21 +++++++++++++++++++++ src/Readers/UblReader.php | 6 ++++++ src/Writers/UblWriter.php | 6 ++++++ tests/Integration/peppol-base.xml | 3 +++ 4 files changed, 36 insertions(+) diff --git a/src/Invoice.php b/src/Invoice.php index c07df2f..e16a9c6 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -255,6 +255,7 @@ class Invoice { protected $salesOrderReference = null; protected $tenderOrLotReference = null; protected $contractReference = null; + protected $projectReference = null; protected $paidAmount = 0; protected $roundingAmount = 0; protected $customVatAmount = null; @@ -679,6 +680,26 @@ public function setContractReference(?string $contractReference): self { } + /** + * Get project reference + * @return string|null Project reference + */ + public function getProjectReference(): ?string { + return $this->projectReference; + } + + + /** + * Set project reference + * @param string|null $contractReference Project reference + * @return self Invoice instance + */ + public function setProjectReference(?string $projectReference): self { + $this->projectReference = $projectReference; + return $this; + } + + /** * Get invoice prepaid amount * @return float Invoice prepaid amount diff --git a/src/Readers/UblReader.php b/src/Readers/UblReader.php index 8078d46..ca74422 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -183,6 +183,12 @@ public function import(string $document): Invoice { $invoice->addAttachment($this->parseAttachmentNode($node)); } + // BT-11: Project reference + $projectReferenceNode = $xml->get("{{$cac}}ProjectReference/{{$cbc}}ID"); + if ($projectReferenceNode !== null) { + $invoice->setProjectReference($projectReferenceNode->asText()); + } + // Seller node $sellerNode = $xml->get("{{$cac}}AccountingSupplierParty/{{$cac}}Party"); if ($sellerNode !== null) { diff --git a/src/Writers/UblWriter.php b/src/Writers/UblWriter.php index 36f1fa5..bcb3737 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -141,6 +141,12 @@ public function export(Invoice $invoice): string { $this->addTenderOrLotReferenceNode($xml, $invoice); } + // BT-11: Project reference + $projectReference = $invoice->getProjectReference(); + if ($projectReference !== null) { + $xml->add('cac:ProjectReference')->add('cbc:ID', $projectReference); + } + // Seller node $seller = $invoice->getSeller(); if ($seller !== null) { diff --git a/tests/Integration/peppol-base.xml b/tests/Integration/peppol-base.xml index f4110b7..d7560ba 100644 --- a/tests/Integration/peppol-base.xml +++ b/tests/Integration/peppol-base.xml @@ -51,6 +51,9 @@ VGhlIGF0dGFjaG1lbnQgcmF3IGNvbnRlbnRz + + PROJ-1234 + 9482348239847239874