Skip to content

Commit

Permalink
Added project reference (BT-11)
Browse files Browse the repository at this point in the history
- Updated Invoice class
- Updated UBL reader and writer
- Updated tests

> Closes #60
  • Loading branch information
josemmo committed Aug 3, 2024
1 parent 8399f13 commit 040979d
Show file tree
Hide file tree
Showing 4 changed files with 36 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 @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Readers/UblReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Writers/UblWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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 @@ -51,6 +51,9 @@
<cbc:EmbeddedDocumentBinaryObject mimeCode="application/pdf" filename="ATT-1234.pdf">VGhlIGF0dGFjaG1lbnQgcmF3IGNvbnRlbnRz</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
<cac:ProjectReference>
<cbc:ID>PROJ-1234</cbc:ID>
</cac:ProjectReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cbc:EndpointID schemeID="0088">9482348239847239874</cbc:EndpointID>
Expand Down

0 comments on commit 040979d

Please sign in to comment.