Skip to content

Commit

Permalink
Merge pull request #13 from josemmo/develop
Browse files Browse the repository at this point in the history
v0.1.5
  • Loading branch information
josemmo authored Nov 6, 2021
2 parents e938d70 + 30751aa commit 0853202
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 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
21 changes: 21 additions & 0 deletions src/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Party {
protected $tradingName = null;
protected $companyId = null;
protected $vatNumber = null;
protected $taxRegistrationId = null;
protected $contactName = null;
protected $contactPhone = null;
protected $contactEmail = null;
Expand Down Expand Up @@ -117,6 +118,26 @@ public function setVatNumber(?string $vatNumber): self {
}


/**
* Get tax registration ID
* @return Identifier|null Tax registration ID
*/
public function getTaxRegistrationId(): ?Identifier {
return $this->taxRegistrationId;
}


/**
* Set tax registration ID
* @param Identifier|null $taxRegistrationId Tax registration ID
* @return self Party instance
*/
public function setTaxRegistrationId(?Identifier $taxRegistrationId): self {
$this->taxRegistrationId = $taxRegistrationId;
return $this;
}


/**
* Get contact point name
* @return string|null Contact name
Expand Down
24 changes: 20 additions & 4 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 Expand Up @@ -338,10 +344,20 @@ private function parseSellerOrBuyerNode(UXML $xml): Party {
$this->parsePostalAddressFields($addressNode, $party);
}

// VAT number
$vatNumberNode = $xml->get("{{$cac}}PartyTaxScheme/{{$cbc}}CompanyID");
if ($vatNumberNode !== null) {
$party->setVatNumber($vatNumberNode->asText());
// VAT number and tax registration identifier
foreach ($xml->getAll("{{$cac}}PartyTaxScheme") as $taxNode) {
$companyIdNode = $taxNode->get("{{$cbc}}CompanyID");
if ($companyIdNode === null) continue;
$companyId = $companyIdNode->asText();

$taxSchemeNode = $taxNode->get("{{$cac}}TaxScheme/{{$cbc}}ID");
$taxScheme = ($taxSchemeNode === null) ? null : $taxSchemeNode->asText();

if ($taxScheme === "VAT") {
$party->setVatNumber($companyId);
} else {
$party->setTaxRegistrationId(new Identifier($companyId, $taxScheme));
}
}

// Legal name
Expand Down
17 changes: 17 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 Expand Up @@ -373,6 +379,17 @@ private function addSellerOrBuyerNode(UXML $parent, Party $party) {
$taxNode->add('cac:TaxScheme')->add('cbc:ID', 'VAT');
}

// Tax registration identifier
$taxRegistrationId = $party->getTaxRegistrationId();
if ($taxRegistrationId !== null) {
$taxRegistrationNode = $xml->add('cac:PartyTaxScheme');
$taxRegistrationNode->add('cbc:CompanyID', $taxRegistrationId->getValue());
$taxRegistrationScheme = $taxRegistrationId->getScheme();
if ($taxRegistrationScheme !== null) {
$taxRegistrationNode->add('cac:TaxScheme')->add('cbc:ID', $taxRegistrationScheme);
}
}

// Initial legal entity node
$legalEntityNode = $xml->add('cac:PartyLegalEntity');

Expand Down
6 changes: 6 additions & 0 deletions tests/Integration/peppol-allowance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyTaxScheme>
<cbc:CompanyID>SE555555555501</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID>TAX</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>SupplierOfficialName Ltd</cbc:RegistrationName>
<cbc:CompanyID>GB983294</cbc:CompanyID>
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 0853202

Please sign in to comment.