From 74015822757615b1cd49baef4ed455ebb875a9f9 Mon Sep 17 00:00:00 2001 From: Christian Vermeulen Date: Mon, 13 Sep 2021 12:12:34 +0200 Subject: [PATCH 1/5] Include a billing document reference for credit notes --- src/Invoice.php | 21 +++++++++++++++++++++ src/Readers/UblReader.php | 6 ++++++ src/Writers/UblWriter.php | 9 +++++++++ tests/Readers/UblReaderTest.php | 1 + tests/Readers/peppol-example.xml | 5 +++++ tests/Writers/UblWriterTest.php | 1 + 6 files changed, 43 insertions(+) diff --git a/src/Invoice.php b/src/Invoice.php index cee62cb..efdf5ab 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -34,6 +34,7 @@ class Invoice { protected $buyerReference = null; protected $purchaseOrderReference = null; protected $salesOrderReference = null; + protected $billingReference = null; protected $paidAmount = 0; protected $roundingAmount = 0; protected $seller = null; @@ -331,6 +332,26 @@ public function setSalesOrderReference(?string $salesOrderReference): self { } + /** + * Get billing reference + * @return string|null Billing reference + */ + public function getBillingReference(): ?string { + return $this->billingReference; + } + + + /** + * Set sales order reference + * @param string|null $billingReference Billing reference + * @return self Invoice instance + */ + public function setBillingReference(?string $billingReference): self { + $this->billingReference = $billingReference; + 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 0ec0df5..def06d1 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -142,6 +142,12 @@ public function import(string $document): Invoice { $invoice->setSalesOrderReference($salesOrderReferenceNode->asText()); } + // BG-3: Billing Reference + $billingReference = $xml->get("{{$cac}}BillingReference/{{$cac}}InvoiceDocumentReference/{{$cbc}}ID"); + if ($billingReference !== null) { + $invoice->setBillingReference($billingReference->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 8ee3db4..9cd02a6 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -96,6 +96,15 @@ public function export(Invoice $invoice): string { // Order reference node $this->addOrderReferenceNode($xml, $invoice); + // BG-3: Billing reference + if ($invoice->getBillingReference()) { + $xml + ->add('cac:BillingReference') + ->add('cac:InvoiceDocumentReference') + ->add('cbc:ID', $invoice->getBillingReference()) + ; + } + // BG-24: Attachments node foreach ($invoice->getAttachments() as $attachment) { $this->addAttachmentNode($xml, $attachment); diff --git a/tests/Readers/UblReaderTest.php b/tests/Readers/UblReaderTest.php index 38435c6..480d155 100644 --- a/tests/Readers/UblReaderTest.php +++ b/tests/Readers/UblReaderTest.php @@ -27,6 +27,7 @@ public function testCanReadInvoice(): void { $this->assertEquals(1656.25, $totals->payableAmount); $this->assertEquals('S', $totals->vatBreakdown[0]->category); $this->assertEquals(25, $totals->vatBreakdown[0]->rate); + $this->assertEquals('INV-123', $invoice->getBillingReference()); $this->assertEquals('This is a sample string', $invoice->getAttachments()[0]->getContents()); } } diff --git a/tests/Readers/peppol-example.xml b/tests/Readers/peppol-example.xml index e9de3c0..d56efac 100644 --- a/tests/Readers/peppol-example.xml +++ b/tests/Readers/peppol-example.xml @@ -12,6 +12,11 @@ EUR 4025:123:4343 0150abc + + + INV-123 + + ABC-123 Invoice ABC-123 diff --git a/tests/Writers/UblWriterTest.php b/tests/Writers/UblWriterTest.php index 14783f7..6db9f23 100644 --- a/tests/Writers/UblWriterTest.php +++ b/tests/Writers/UblWriterTest.php @@ -70,6 +70,7 @@ private function getSampleInvoice(): Invoice { ->setIssueDate(new DateTime('-3 days')) ->setDueDate(new DateTime('+30 days')) ->setBuyerReference('REF-0172637') + ->setBillingReference('INV-123') ->setSeller($seller) ->setBuyer($buyer) ->addLine($complexLine) From 4d2bca1a7a8775296b77cdb9dc1ac8e7f661f2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Tue, 21 Sep 2021 18:34:29 +0200 Subject: [PATCH 2/5] Replaced single billing reference with preceding invoice references - Renamed field to match naming in EN16931 - Created InvoiceReference class - Updated UblReader and UblWriter - Updated unit tests - Updated peppol-base.xml --- src/Invoice.php | 23 +------- src/InvoiceReference.php | 59 +++++++++++++++++++ src/Readers/UblReader.php | 17 ++++-- .../PrecedingInvoiceReferencesTrait.php | 53 +++++++++++++++++ src/Writers/UblWriter.php | 15 ++--- tests/Integration/peppol-base.xml | 11 ++++ tests/Readers/UblReaderTest.php | 2 +- tests/Writers/UblWriterTest.php | 3 +- 8 files changed, 149 insertions(+), 34 deletions(-) create mode 100644 src/InvoiceReference.php create mode 100644 src/Traits/PrecedingInvoiceReferencesTrait.php diff --git a/src/Invoice.php b/src/Invoice.php index efdf5ab..9a89c3d 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -10,6 +10,7 @@ use Einvoicing\Traits\BuyerAccountingReferenceTrait; use Einvoicing\Traits\InvoiceValidationTrait; use Einvoicing\Traits\PeriodTrait; +use Einvoicing\Traits\PrecedingInvoiceReferencesTrait; use InvalidArgumentException; use OutOfBoundsException; use function array_splice; @@ -34,7 +35,6 @@ class Invoice { protected $buyerReference = null; protected $purchaseOrderReference = null; protected $salesOrderReference = null; - protected $billingReference = null; protected $paidAmount = 0; protected $roundingAmount = 0; protected $seller = null; @@ -49,6 +49,7 @@ class Invoice { use BuyerAccountingReferenceTrait; use PeriodTrait; use InvoiceValidationTrait; + use PrecedingInvoiceReferencesTrait; /** * Invoice constructor @@ -332,26 +333,6 @@ public function setSalesOrderReference(?string $salesOrderReference): self { } - /** - * Get billing reference - * @return string|null Billing reference - */ - public function getBillingReference(): ?string { - return $this->billingReference; - } - - - /** - * Set sales order reference - * @param string|null $billingReference Billing reference - * @return self Invoice instance - */ - public function setBillingReference(?string $billingReference): self { - $this->billingReference = $billingReference; - return $this; - } - - /** * Get invoice prepaid amount * NOTE: may be rounded according to the CIUS specification diff --git a/src/InvoiceReference.php b/src/InvoiceReference.php new file mode 100644 index 0000000..782df4b --- /dev/null +++ b/src/InvoiceReference.php @@ -0,0 +1,59 @@ +setValue($value); + $this->setIssueDate($issueDate); + } + + + /** + * Get value + * @return string Value + */ + public function getValue(): string { + return $this->value; + } + + + /** + * Set value + * @param string $value Value + * @return self Invoice reference instance + */ + public function setValue(string $value): self { + $this->value = $value; + return $this; + } + + + /** + * Get issue date + * @return DateTime|null Issue date + */ + public function getIssueDate(): ?DateTime { + return $this->issueDate; + } + + + /** + * Set issue date + * @param DateTime|null $issueDate Issue date + * @return self Invoice reference instance + */ + public function setIssueDate(?DateTime $issueDate): self { + $this->issueDate = $issueDate; + return $this; + } +} diff --git a/src/Readers/UblReader.php b/src/Readers/UblReader.php index def06d1..4e1df7b 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -9,6 +9,7 @@ use Einvoicing\Identifier; use Einvoicing\Invoice; use Einvoicing\InvoiceLine; +use Einvoicing\InvoiceReference; use Einvoicing\Party; use Einvoicing\Payments\Card; use Einvoicing\Payments\Mandate; @@ -142,10 +143,18 @@ public function import(string $document): Invoice { $invoice->setSalesOrderReference($salesOrderReferenceNode->asText()); } - // BG-3: Billing Reference - $billingReference = $xml->get("{{$cac}}BillingReference/{{$cac}}InvoiceDocumentReference/{{$cbc}}ID"); - if ($billingReference !== null) { - $invoice->setBillingReference($billingReference->asText()); + // BG-3: Preceding invoice references + foreach ($xml->getAll("{{$cac}}BillingReference/{{$cac}}InvoiceDocumentReference") as $node) { + $invoiceReferenceValueNode = $node->get("{{$cbc}}ID"); + if ($invoiceReferenceValueNode === null) { + continue; + } + $invoiceReference = new InvoiceReference($invoiceReferenceValueNode->asText()); + $invoiceReferenceIssueDateNode = $node->get("{{$cbc}}IssueDate"); + if ($invoiceReferenceIssueDateNode !== null) { + $invoiceReference->setIssueDate(new DateTime($invoiceReferenceIssueDateNode->asText())); + } + $invoice->addPrecedingInvoiceReference($invoiceReference); } // BG-24: Attachment nodes diff --git a/src/Traits/PrecedingInvoiceReferencesTrait.php b/src/Traits/PrecedingInvoiceReferencesTrait.php new file mode 100644 index 0000000..3f17cb6 --- /dev/null +++ b/src/Traits/PrecedingInvoiceReferencesTrait.php @@ -0,0 +1,53 @@ +precedingInvoiceReferences; + } + + + /** + * Add preceding invoice reference + * @param InvoiceReference $reference Preceding invoice reference + * @return self This instance + */ + public function addPrecedingInvoiceReference(InvoiceReference $reference): self { + $this->precedingInvoiceReferences[] = $reference; + return $this; + } + + + /** + * Remove preceding invoice reference + * @param int $index Preceding invoice reference index + * @return self This instance + * @throws OutOfBoundsException if preceding invoice reference index is out of bounds + */ + public function removePrecedingInvoiceReference(int $index): self { + if ($index < 0 || $index >= count($this->precedingInvoiceReferences)) { + throw new OutOfBoundsException('Could not find preceding invoice reference by index'); + } + array_splice($this->precedingInvoiceReferences, $index, 1); + return $this; + } + + + /** + * Clear all preceding invoice references + * @return self This instance + */ + public function clearPrecedingInvoiceReferences(): self { + $this->precedingInvoiceReferences = []; + return $this; + } +} diff --git a/src/Writers/UblWriter.php b/src/Writers/UblWriter.php index 9cd02a6..546a60e 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -96,13 +96,14 @@ public function export(Invoice $invoice): string { // Order reference node $this->addOrderReferenceNode($xml, $invoice); - // BG-3: Billing reference - if ($invoice->getBillingReference()) { - $xml - ->add('cac:BillingReference') - ->add('cac:InvoiceDocumentReference') - ->add('cbc:ID', $invoice->getBillingReference()) - ; + // BG-3: Preceding invoice reference + foreach ($invoice->getPrecedingInvoiceReferences() as $invoiceReference) { + $invoiceDocumentReferenceNode = $xml->add('cac:BillingReference')->add('cac:InvoiceDocumentReference'); + $invoiceDocumentReferenceNode->add('cbc:ID', $invoiceReference->getValue()); + $invoiceReferenceIssueDate = $invoiceReference->getIssueDate(); + if ($invoiceReferenceIssueDate !== null) { + $invoiceDocumentReferenceNode->add('cbc:IssueDate', $invoiceReferenceIssueDate->format('Y-m-d')); + } } // BG-24: Attachments node diff --git a/tests/Integration/peppol-base.xml b/tests/Integration/peppol-base.xml index c52bf23..87de012 100644 --- a/tests/Integration/peppol-base.xml +++ b/tests/Integration/peppol-base.xml @@ -15,6 +15,17 @@ 854777 + + + INV-122 + 2021-09-21 + + + + + INV-123 + + INV-123 130 diff --git a/tests/Readers/UblReaderTest.php b/tests/Readers/UblReaderTest.php index 480d155..e97de37 100644 --- a/tests/Readers/UblReaderTest.php +++ b/tests/Readers/UblReaderTest.php @@ -27,7 +27,7 @@ public function testCanReadInvoice(): void { $this->assertEquals(1656.25, $totals->payableAmount); $this->assertEquals('S', $totals->vatBreakdown[0]->category); $this->assertEquals(25, $totals->vatBreakdown[0]->rate); - $this->assertEquals('INV-123', $invoice->getBillingReference()); + $this->assertEquals('INV-123', $invoice->getPrecedingInvoiceReferences()[0]->getValue()); $this->assertEquals('This is a sample string', $invoice->getAttachments()[0]->getContents()); } } diff --git a/tests/Writers/UblWriterTest.php b/tests/Writers/UblWriterTest.php index 6db9f23..eec4077 100644 --- a/tests/Writers/UblWriterTest.php +++ b/tests/Writers/UblWriterTest.php @@ -7,6 +7,7 @@ use Einvoicing\Identifier; use Einvoicing\Invoice; use Einvoicing\InvoiceLine; +use Einvoicing\InvoiceReference; use Einvoicing\Party; use Einvoicing\Presets\Peppol; use Einvoicing\Writers\UblWriter; @@ -70,7 +71,7 @@ private function getSampleInvoice(): Invoice { ->setIssueDate(new DateTime('-3 days')) ->setDueDate(new DateTime('+30 days')) ->setBuyerReference('REF-0172637') - ->setBillingReference('INV-123') + ->addPrecedingInvoiceReference(new InvoiceReference('INV-123')) ->setSeller($seller) ->setBuyer($buyer) ->addLine($complexLine) From c78981a82dabc09fd3abaf33db6213f0e5b703d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Tue, 21 Sep 2021 19:26:10 +0200 Subject: [PATCH 3/5] Created CONTRIBUTING.md - Created CONTRIBUTING.md file --- CONTRIBUTING.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..05214d8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,38 @@ +# Contributing +Thanks for taking your time to contribute to this project! +This document will get you on the right track to help improve eInvoicing. + +## How to Get Started +Use the following sites to get more information about the European electronic invocing specification: + +- [EU e-Invoicing core concepts](https://josemmo.github.io/einvoicing/getting-started/eu-einvoicing-concepts/) +- [Compliance with the European standard on eInvoicing](https://ec.europa.eu/cefdigital/wiki/x/ggTvB) +- [Obtaining a copy of the European standard on eInvoicing](https://ec.europa.eu/cefdigital/wiki/x/kgLvB) +- [UBL Invoice fields](https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/tree/) +- [CEF eInvoicing Validator](https://www.itb.ec.europa.eu/invoice/upload) + +## PR Requirements +Before opening a Pull Request, please make sure your code meets the following requirements: + +### 1. Uses `develop` as the base branch +The main repository branch is only for stable releases. + +### 2. Passes static analysis inspection +``` +vendor/bin/phan --testdox +``` + +### 3. Passes all tests +``` +vendor/bin/simple-phpunit +``` + +### 4. Complies with EN 16931 +Although the most popular European Invoicing CIUS is [PEPPOL BIS Billing 3.0](https://docs.peppol.eu/poacc/billing/3.0/), +the real deal is the "European Standard for Electronic invocing" or EN 16931. + +This means that, while most users will use the [Peppol](src/Presets/Peppol.php) preset for reading and writing invoices, +there are other CIUS/extensions from various member states and business sectors which might not be an exact match to PEPPOL. + +Because the one thing all these specifications have in common is EN 16931, fields and methods you add to the library +must have the same names as they do in the European Standard. From 7b855d9100bc375e3784e644f7f3d8ed3747a0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20H=C3=B6gberg?= Date: Mon, 20 Sep 2021 16:04:40 +0200 Subject: [PATCH 4/5] Add support for OriginatorDocumentReference See reference at https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-OriginatorDocumentReference/ --- src/Invoice.php | 23 +++++++++++++++++++++++ src/Readers/UblReader.php | 6 ++++++ src/Writers/UblWriter.php | 7 +++++++ tests/Readers/peppol-example.xml | 3 +++ tests/Writers/UblWriterTest.php | 1 + 5 files changed, 40 insertions(+) diff --git a/src/Invoice.php b/src/Invoice.php index 9a89c3d..c0f196b 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -35,6 +35,7 @@ class Invoice { protected $buyerReference = null; protected $purchaseOrderReference = null; protected $salesOrderReference = null; + protected $originatorDocumentReference = null; protected $paidAmount = 0; protected $roundingAmount = 0; protected $seller = null; @@ -333,6 +334,28 @@ public function setSalesOrderReference(?string $salesOrderReference): self { } + /** + * Get originator document reference + * @return string|null + */ + public function getOriginatorDocumentReference(): ?string + { + return $this->originatorDocumentReference; + } + + + /** + * Set originator document reference + * @param string|null $originatorDocumentReference + * @return Invoice + * @see https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-OriginatorDocumentReference/ + */ + public function setOriginatorDocumentReference(?string $originatorDocumentReference): self { + $this->originatorDocumentReference = $originatorDocumentReference; + 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 4e1df7b..a2d4926 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -157,6 +157,12 @@ public function import(string $document): Invoice { $invoice->addPrecedingInvoiceReference($invoiceReference); } + // Originator Document Reference + $originatorDocumentReference = $xml->get("{{$cac}}OriginatorDocumentReference/{{$cbc}}ID"); + if ($originatorDocumentReference !== null) { + $invoice->setOriginatorDocumentReference($originatorDocumentReference->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 546a60e..8647e48 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -106,6 +106,13 @@ public function export(Invoice $invoice): string { } } + $originatorDocumentReference = $invoice->getOriginatorDocumentReference(); + if ($originatorDocumentReference) { + $xml + ->add('cac:OriginatorDocumentReference') + ->add('cbc:ID', $originatorDocumentReference); + } + // BG-24: Attachments node foreach ($invoice->getAttachments() as $attachment) { $this->addAttachmentNode($xml, $attachment); diff --git a/tests/Readers/peppol-example.xml b/tests/Readers/peppol-example.xml index d56efac..0100a56 100644 --- a/tests/Readers/peppol-example.xml +++ b/tests/Readers/peppol-example.xml @@ -17,6 +17,9 @@ INV-123 + + PPID-123 + ABC-123 Invoice ABC-123 diff --git a/tests/Writers/UblWriterTest.php b/tests/Writers/UblWriterTest.php index eec4077..7cd189c 100644 --- a/tests/Writers/UblWriterTest.php +++ b/tests/Writers/UblWriterTest.php @@ -72,6 +72,7 @@ private function getSampleInvoice(): Invoice { ->setDueDate(new DateTime('+30 days')) ->setBuyerReference('REF-0172637') ->addPrecedingInvoiceReference(new InvoiceReference('INV-123')) + ->setOriginatorDocumentReference('PPID-123') ->setSeller($seller) ->setBuyer($buyer) ->addLine($complexLine) From 15f2dc5ce5d475b81a2b3a6b76bfd4f069f7e023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Fri, 24 Sep 2021 19:43:53 +0200 Subject: [PATCH 5/5] Renamed BT-17 (tender or lot reference) - Renamed originator document reference to tender or lot reference to match EN16931 --- src/Invoice.php | 22 ++++++++++------------ src/Readers/UblReader.php | 8 ++++---- src/Writers/UblWriter.php | 9 ++++----- tests/Integration/peppol-base.xml | 3 +++ tests/Readers/peppol-example.xml | 3 --- tests/Writers/UblWriterTest.php | 2 +- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/Invoice.php b/src/Invoice.php index c0f196b..d83da5f 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -35,7 +35,7 @@ class Invoice { protected $buyerReference = null; protected $purchaseOrderReference = null; protected $salesOrderReference = null; - protected $originatorDocumentReference = null; + protected $tenderOrLotReference = null; protected $paidAmount = 0; protected $roundingAmount = 0; protected $seller = null; @@ -335,23 +335,21 @@ public function setSalesOrderReference(?string $salesOrderReference): self { /** - * Get originator document reference - * @return string|null + * Get tender or lot reference + * @return string|null Tender or lot reference */ - public function getOriginatorDocumentReference(): ?string - { - return $this->originatorDocumentReference; + public function getTenderOrLotReference(): ?string { + return $this->tenderOrLotReference; } /** - * Set originator document reference - * @param string|null $originatorDocumentReference - * @return Invoice - * @see https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-OriginatorDocumentReference/ + * Set tender or lot reference + * @param string|null $tenderOrLotReference Tender or lot reference + * @return self Invoice instance */ - public function setOriginatorDocumentReference(?string $originatorDocumentReference): self { - $this->originatorDocumentReference = $originatorDocumentReference; + public function setTenderOrLotReference(?string $tenderOrLotReference): self { + $this->tenderOrLotReference = $tenderOrLotReference; return $this; } diff --git a/src/Readers/UblReader.php b/src/Readers/UblReader.php index a2d4926..ce33d32 100644 --- a/src/Readers/UblReader.php +++ b/src/Readers/UblReader.php @@ -157,10 +157,10 @@ public function import(string $document): Invoice { $invoice->addPrecedingInvoiceReference($invoiceReference); } - // Originator Document Reference - $originatorDocumentReference = $xml->get("{{$cac}}OriginatorDocumentReference/{{$cbc}}ID"); - if ($originatorDocumentReference !== null) { - $invoice->setOriginatorDocumentReference($originatorDocumentReference->asText()); + // BT-17: Tender or lot reference + $tenderOrLotReferenceNode = $xml->get("{{$cac}}OriginatorDocumentReference/{{$cbc}}ID"); + if ($tenderOrLotReferenceNode !== null) { + $invoice->setTenderOrLotReference($tenderOrLotReferenceNode->asText()); } // BG-24: Attachment nodes diff --git a/src/Writers/UblWriter.php b/src/Writers/UblWriter.php index 8647e48..fb31768 100644 --- a/src/Writers/UblWriter.php +++ b/src/Writers/UblWriter.php @@ -106,11 +106,10 @@ public function export(Invoice $invoice): string { } } - $originatorDocumentReference = $invoice->getOriginatorDocumentReference(); - if ($originatorDocumentReference) { - $xml - ->add('cac:OriginatorDocumentReference') - ->add('cbc:ID', $originatorDocumentReference); + // BT-17: Tender or lot reference + $tenderOrLotReference = $invoice->getTenderOrLotReference(); + if ($tenderOrLotReference !== null) { + $xml->add('cac:OriginatorDocumentReference')->add('cbc:ID', $tenderOrLotReference); } // BG-24: Attachments node diff --git a/tests/Integration/peppol-base.xml b/tests/Integration/peppol-base.xml index 87de012..14a6ed0 100644 --- a/tests/Integration/peppol-base.xml +++ b/tests/Integration/peppol-base.xml @@ -26,6 +26,9 @@ INV-123 + + PPID-123 + INV-123 130 diff --git a/tests/Readers/peppol-example.xml b/tests/Readers/peppol-example.xml index 0100a56..d56efac 100644 --- a/tests/Readers/peppol-example.xml +++ b/tests/Readers/peppol-example.xml @@ -17,9 +17,6 @@ INV-123 - - PPID-123 - ABC-123 Invoice ABC-123 diff --git a/tests/Writers/UblWriterTest.php b/tests/Writers/UblWriterTest.php index 7cd189c..31a73ee 100644 --- a/tests/Writers/UblWriterTest.php +++ b/tests/Writers/UblWriterTest.php @@ -72,7 +72,7 @@ private function getSampleInvoice(): Invoice { ->setDueDate(new DateTime('+30 days')) ->setBuyerReference('REF-0172637') ->addPrecedingInvoiceReference(new InvoiceReference('INV-123')) - ->setOriginatorDocumentReference('PPID-123') + ->setTenderOrLotReference('PPID-123') ->setSeller($seller) ->setBuyer($buyer) ->addLine($complexLine)