Skip to content

Commit

Permalink
Added the possibillity to force a customization (profile) in the dest…
Browse files Browse the repository at this point in the history
…ination UBL-Document (XmlConverterCiiToUbl)
  • Loading branch information
ruff committed Jul 25, 2024
1 parent bcc37fb commit 2403545
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 13 deletions.
78 changes: 67 additions & 11 deletions src/XmlConverterCiiToUbl.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class XmlConverterCiiToUbl extends XmlConverterBase
*/
private $automaticModeDisabled = true;

/**
* Internal Flag to force a profile in destination
*
* @var string
*/
private $forceDestinationProfile = "";

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -196,6 +203,35 @@ public function enableAutomaticMode(): XmlConverterCiiToUbl
return $this;
}

/**
* Set the profile to force in the destination (UBL) document
*
* @param string $forceDestinationProfile
* @return XmlConverterCiiToUbl
*/
public function setForceDestinationProfile(string $forceDestinationProfile): XmlConverterCiiToUbl
{
if (!in_array($forceDestinationProfile, static::SUPPORTED_PROFILES)) {
return $this;
}

$this->forceDestinationProfile = $forceDestinationProfile;

return $this;
}

/**
* Unsert the profile to force in the destination (UBL) document
*
* @return XmlConverterCiiToUbl
*/
public function clearForceDestinationProfile(): XmlConverterCiiToUbl
{
$this->forceDestinationProfile = "";

return $this;
}

/**
* Returns true if source is a credit note, otherwise false
*
Expand Down Expand Up @@ -243,7 +279,13 @@ private function convertGeneral(): void
$invoiceHeaderAgreement = $this->source->query('./ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0);
$invoiceHeaderDelivery = $this->source->query('./ram:ApplicableHeaderTradeDelivery', $invoiceSuppyChainTradeTransaction)->item(0);

$this->destination->element('cbc:CustomizationID', $this->source->queryValue('./ram:GuidelineSpecifiedDocumentContextParameter/ram:ID', $invoiceExchangeDocumentContext));
$customizationId = $this->source->queryValue('./ram:GuidelineSpecifiedDocumentContextParameter/ram:ID', $invoiceExchangeDocumentContext);

if ($this->forceDestinationProfile) {
$customizationId = $this->forceDestinationProfile;
}

$this->destination->element('cbc:CustomizationID', $customizationId);
$this->destination->element('cbc:ProfileID', 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0');

$this->destination->element('cbc:ID', $this->source->queryValue('./ram:ID', $invoiceExchangeDocument));
Expand Down Expand Up @@ -593,16 +635,20 @@ function ($sellerTradePartyTaxRegNode) {
function ($sellerTradePartyLegalOrgNode) use ($sellerTradePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->source->whenExists(
'./ram:TradingBusinessName', $sellerTradePartyLegalOrgNode, function ($sellerTradePartyTradingBusinessName) {
'./ram:TradingBusinessName',
$sellerTradePartyLegalOrgNode,
function ($sellerTradePartyTradingBusinessName) {
$this->destination->element('cbc:RegistrationName', $sellerTradePartyTradingBusinessName->nodeValue);
}, function () use ($sellerTradePartyNode) {
},
function () use ($sellerTradePartyNode) {
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $sellerTradePartyNode));
}
);
$this->destination->elementWithAttribute('cbc:CompanyID', $this->source->queryValue('./ram:ID', $sellerTradePartyLegalOrgNode), 'schemeID', $this->source->queryValue('./ram:ID/@schemeID', $sellerTradePartyLegalOrgNode));
$this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('./ram:Description', $sellerTradePartyNode));
$this->destination->endElement();
}, function () use ($sellerTradePartyNode) {
},
function () use ($sellerTradePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $sellerTradePartyNode));
$this->destination->endElement();
Expand Down Expand Up @@ -737,16 +783,20 @@ function ($sellerTradePartyTaxRegNode) {
function ($buyerTradePartyLegalOrgNode) use ($buyerTradePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->source->whenExists(
'./ram:TradingBusinessName', $buyerTradePartyLegalOrgNode, function ($tradingBusinessName) {
'./ram:TradingBusinessName',
$buyerTradePartyLegalOrgNode,
function ($tradingBusinessName) {
$this->destination->element('cbc:RegistrationName', $tradingBusinessName->nodeValue);
}, function () use ($buyerTradePartyNode) {
},
function () use ($buyerTradePartyNode) {
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $buyerTradePartyNode));
}
);
$this->destination->elementWithAttribute('cbc:CompanyID', $this->source->queryValue('./ram:ID', $buyerTradePartyLegalOrgNode), 'schemeID', $this->source->queryValue('./ram:ID/@schemeID', $buyerTradePartyLegalOrgNode));
$this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('./ram:Description', $buyerTradePartyNode));
$this->destination->endElement();
}, function () use ($buyerTradePartyNode) {
},
function () use ($buyerTradePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $buyerTradePartyNode));
$this->destination->endElement();
Expand Down Expand Up @@ -880,9 +930,12 @@ function ($sellerTradePartyTaxRegNode) {
function ($buyerTradePartyLegalOrgNode) use ($payeeTradePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->source->whenExists(
'./ram:TradingBusinessName', $buyerTradePartyLegalOrgNode, function ($tradingBusinessName) {
'./ram:TradingBusinessName',
$buyerTradePartyLegalOrgNode,
function ($tradingBusinessName) {
$this->destination->element('cbc:RegistrationName', $tradingBusinessName->nodeValue);
}, function () use ($payeeTradePartyNode) {
},
function () use ($payeeTradePartyNode) {
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $payeeTradePartyNode));
}
);
Expand Down Expand Up @@ -1018,9 +1071,12 @@ function ($sellerTradePartyTaxRegNode) {
function ($buyerTradePartyLegalOrgNode) use ($sellerTaxRepresentativePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->source->whenExists(
'./ram:TradingBusinessName', $buyerTradePartyLegalOrgNode, function ($tradingBusinessName) {
'./ram:TradingBusinessName',
$buyerTradePartyLegalOrgNode,
function ($tradingBusinessName) {
$this->destination->element('cbc:RegistrationName', $tradingBusinessName->nodeValue);
}, function () use ($sellerTaxRepresentativePartyNode) {
},
function () use ($sellerTaxRepresentativePartyNode) {
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $sellerTaxRepresentativePartyNode));
}
);
Expand Down
4 changes: 2 additions & 2 deletions tests/testcases/CiiToUblExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class CiiToUblExtendedTest extends TestCase

public function testLoadAndConvert(): void
{
self::$document = XmlConverterCiiToUbl::fromFile(dirname(__FILE__) . "/../assets/cii/2_cii_extended.xml")->enableAutomaticMode()->convert();
self::$document = XmlConverterCiiToUbl::fromFile(dirname(__FILE__) . "/../assets/cii/2_cii_extended.xml")->enableAutomaticMode()->setForceDestinationProfile('urn:cen.eu:en16931:2017')->convert();
$this->assertNotNull(self::$document);
}

public function testDocumentGeneral(): void
{
$this->assertXPathValue('/ubl:Invoice/cbc:CustomizationID', "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended");
$this->assertXPathValue('/ubl:Invoice/cbc:CustomizationID', "urn:cen.eu:en16931:2017");
$this->assertXPathValue('/ubl:Invoice/cbc:ProfileID', "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0");
$this->assertXPathValue('/ubl:Invoice/cbc:ID', "KR87654321012");
$this->assertXPathValue('/ubl:Invoice/cbc:IssueDate', "2018-10-06");
Expand Down

0 comments on commit 2403545

Please sign in to comment.