diff --git a/src/Invoice.php b/src/Invoice.php index d83da5f..db624b1 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -36,6 +36,7 @@ class Invoice { protected $purchaseOrderReference = null; protected $salesOrderReference = null; protected $tenderOrLotReference = null; + protected $contractReference = null; protected $paidAmount = 0; protected $roundingAmount = 0; protected $seller = null; @@ -354,6 +355,26 @@ public function setTenderOrLotReference(?string $tenderOrLotReference): self { } + /** + * Get contract reference + * @return string|null Contract reference + */ + public function getContractReference(): ?string { + return $this->contractReference; + } + + + /** + * Set contract reference + * @param string|null $contractReference Contract reference + * @return self Invoice instance + */ + public function setContractReference(?string $contractReference): self { + $this->contractReference = $contractReference; + return $this; + } + + /** * Get invoice prepaid amount * NOTE: may be rounded according to the CIUS specification diff --git a/src/Readers/UblReader.php b/src/Readers/UblReader.php index ce33d32..7f543fb 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -163,6 +163,12 @@ public function import(string $document): Invoice { $invoice->setTenderOrLotReference($tenderOrLotReferenceNode->asText()); } + // BT-12: Contract reference + $contractReferenceNode = $xml->get("{{$cac}}ContractDocumentReference/{{$cbc}}ID"); + if ($contractReferenceNode !== null) { + $invoice->setContractReference($contractReferenceNode->asText()); + } + // BG-24: Attachment nodes foreach ($xml->getAll("{{$cac}}AdditionalDocumentReference") as $node) { $invoice->addAttachment($this->parseAttachmentNode($node)); diff --git a/src/Writers/UblWriter.php b/src/Writers/UblWriter.php index fb31768..13f26f4 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -112,6 +112,12 @@ public function export(Invoice $invoice): string { $xml->add('cac:OriginatorDocumentReference')->add('cbc:ID', $tenderOrLotReference); } + // BT-12: Contract reference + $contractReference = $invoice->getContractReference(); + if ($contractReference !== null) { + $xml->add('cac:ContractDocumentReference')->add('cbc:ID', $contractReference); + } + // BG-24: Attachments node foreach ($invoice->getAttachments() as $attachment) { $this->addAttachmentNode($xml, $attachment); diff --git a/tests/Integration/peppol-base.xml b/tests/Integration/peppol-base.xml index 14a6ed0..f4110b7 100644 --- a/tests/Integration/peppol-base.xml +++ b/tests/Integration/peppol-base.xml @@ -29,6 +29,9 @@ PPID-123 + + 123Contractref + INV-123 130 diff --git a/tests/Writers/UblWriterTest.php b/tests/Writers/UblWriterTest.php index 31a73ee..b3190e6 100644 --- a/tests/Writers/UblWriterTest.php +++ b/tests/Writers/UblWriterTest.php @@ -73,6 +73,7 @@ private function getSampleInvoice(): Invoice { ->setBuyerReference('REF-0172637') ->addPrecedingInvoiceReference(new InvoiceReference('INV-123')) ->setTenderOrLotReference('PPID-123') + ->setContractReference('123Contractref') ->setSeller($seller) ->setBuyer($buyer) ->addLine($complexLine)