Skip to content

Commit

Permalink
Add support for ContractDocumentReference (BT-12)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmazter committed Oct 25, 2021
1 parent 15f2dc5 commit 1ce251a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Readers/UblReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions src/Writers/UblWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/peppol-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<cac:OriginatorDocumentReference>
<cbc:ID>PPID-123</cbc:ID>
</cac:OriginatorDocumentReference>
<cac:ContractDocumentReference>
<cbc:ID>123Contractref</cbc:ID>
</cac:ContractDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>INV-123</cbc:ID>
<cbc:DocumentTypeCode>130</cbc:DocumentTypeCode>
Expand Down
1 change: 1 addition & 0 deletions tests/Writers/UblWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ce251a

Please sign in to comment.