Skip to content

Commit

Permalink
Added support for tax registration identifier (BT-32)
Browse files Browse the repository at this point in the history
- Added Party::$taxRegistrationId attribute
- Updated UblReader and UblWriter
- Updated integration test
  • Loading branch information
josemmo committed Oct 27, 2021
1 parent 0609b9c commit 30751aa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
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
18 changes: 14 additions & 4 deletions src/Readers/UblReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,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
11 changes: 11 additions & 0 deletions src/Writers/UblWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,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

0 comments on commit 30751aa

Please sign in to comment.