Skip to content

Commit

Permalink
Added missing conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Nov 9, 2024
1 parent 18c751f commit b331c3b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/XmlConverterCiiToUbl.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function ($additionalReferencedDocumentNode) {
function () use ($additionalReferencedDocumentNode) {
$this->destination->startElement('cac:AdditionalDocumentReference');
$this->destination->element('cbc:ID', $this->source->queryValue('./ram:IssuerAssignedID', $additionalReferencedDocumentNode));
if ($this->source->queryValue('./ram:TypeCode', $additionalReferencedDocumentNode) === "50" || $this->source->queryValue('./ram:TypeCode', $additionalReferencedDocumentNode) === "130") {
if ($this->source->queryValue('./ram:TypeCode', $additionalReferencedDocumentNode) === "130") {
$this->destination->element('cbc:DocumentTypeCode', $this->source->queryValue('./ram:TypeCode', $additionalReferencedDocumentNode));
}
$this->destination->element('cbc:DocumentDescription', $this->source->queryValue('./ram:Name', $additionalReferencedDocumentNode));
Expand Down Expand Up @@ -1389,7 +1389,13 @@ function ($tradeLineItemNode) use ($invoiceHeaderSettlement) {
$this->source->queryValue('./ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)
);

$this->destination->element('cbc:AccountingCost', $this->source->queryValue('./ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', $tradeLineItemNode));
$this->source->whenExists(
'./ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID',
$tradeLineItemNode,
function ($accountingCostNode) {
$this->destination->element('cbc:AccountingCost', $accountingCostNode->nodeValue);
}
);

$this->source->whenExists(
'./ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod',
Expand Down
56 changes: 55 additions & 1 deletion src/XmlConverterUblToCii.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected function getSourceNamespaces(): array
protected function getDestinationNamespaces(): array
{
return [
'a' => 'urn:un:unece:uncefact:data:standard:QualifiedDataType:100',
'rsm' => 'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100',
'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100',
'qdt' => 'urn:un:unece:uncefact:data:Standard:QualifiedDataType:100',
Expand Down Expand Up @@ -360,6 +361,16 @@ function ($invoiceLineInvoicePeriodEndNode) {
$this->destination->startElement('ram:SpecifiedTradeSettlementLineMonetarySummation');
$this->destination->element('ram:LineTotalAmount', $this->source->queryValue('cbc:LineExtensionAmount', $invoiceLineNode));
$this->destination->endElement();
$this->source->whenExists(
'./cbc:AccountingCost',
$invoiceLineNode,
function ($invoiceLineAccountingCostNode) {
$this->destination->startElement('ram:ReceivableSpecifiedTradeAccountingAccount');
$this->destination->element('ram:ID', $invoiceLineAccountingCostNode->nodeValue);
$this->destination->endElement();
}
);

$this->destination->endElement();

$this->destination->endElement();
Expand Down Expand Up @@ -721,7 +732,9 @@ function ($additionalDocumentReferenceNode) {
'./cbc:DocumentTypeCode',
$additionalDocumentReferenceNode,
function ($docTypeCodeNode) {
$this->destination->element('ram:TypeCode', $docTypeCodeNode->nodeValue);
if ($docTypeCodeNode->nodeValue == "50" || $docTypeCodeNode->nodeValue == "130" || $docTypeCodeNode->nodeValue == "916") {
$this->destination->element('ram:TypeCode', $docTypeCodeNode->nodeValue);
}
},
function () {
$this->destination->element('ram:TypeCode', '916');
Expand Down Expand Up @@ -835,6 +848,26 @@ function ($actualDeliveryDateNode) {
}
);

$this->source->whenExists(
'./cac:DespatchDocumentReference/cbc:ID',
$docRootElement,
function ($despatchDocumentReferenceNode) {
$this->destination->startElement('ram:DespatchAdviceReferencedDocument');
$this->destination->element('ram:IssuerAssignedID', $despatchDocumentReferenceNode->nodeValue);
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:ReceiptDocumentReference/cbc:ID',
$docRootElement,
function ($receiptDocumentReferenceNode) {
$this->destination->startElement('ram:ReceivingAdviceReferencedDocument');
$this->destination->element('ram:IssuerAssignedID', $receiptDocumentReferenceNode->nodeValue);
$this->destination->endElement();
}
);

$this->destination->endElement();
}

Expand Down Expand Up @@ -1210,6 +1243,27 @@ function () {
}
);

$this->source->queryAll('./cac:BillingReference/cac:InvoiceDocumentReference', $docRootElement)->foreach(
function ($billingReferenceNode) {
$this->destination->startElement('ram:InvoiceReferencedDocument');
$this->destination->element('ram:IssuerAssignedID', $this->source->queryValue('./cbc:ID', $billingReferenceNode));
$this->destination->startElement('ram:FormattedIssueDateTime');
$this->destination->elementWithAttribute('a:DateTimeString', $this->convertDateTime($this->source->queryValue('./cbc:IssueDate', $billingReferenceNode)), 'format', '102');
$this->destination->endElement();
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cbc:AccountingCost',
$docRootElement,
function ($accountingCostNode) {
$this->destination->startElement('ram:ReceivableSpecifiedTradeAccountingAccount');
$this->destination->element('ram:ID', $accountingCostNode->nodeValue);
$this->destination->endElement();
}
);

$this->destination->endElement();
}

Expand Down
12 changes: 12 additions & 0 deletions tests/assets/cii/1_cii_simple.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount>198.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:ReceivableSpecifiedTradeAccountingAccount>
<ram:ID>0815</ram:ID>
</ram:ReceivableSpecifiedTradeAccountingAccount>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:IncludedSupplyChainTradeLineItem>
Expand Down Expand Up @@ -123,6 +126,12 @@
<udt:DateTimeString format="102">20180305</udt:DateTimeString>
</ram:OccurrenceDateTime>
</ram:ActualDeliverySupplyChainEvent>
<ram:DespatchAdviceReferencedDocument>
<ram:IssuerAssignedID>5433</ram:IssuerAssignedID>
</ram:DespatchAdviceReferencedDocument>
<ram:ReceivingAdviceReferencedDocument>
<ram:IssuerAssignedID>3544</ram:IssuerAssignedID>
</ram:ReceivingAdviceReferencedDocument>
</ram:ApplicableHeaderTradeDelivery>
<ram:ApplicableHeaderTradeSettlement>
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
Expand Down Expand Up @@ -153,6 +162,9 @@
<ram:TotalPrepaidAmount>0.00</ram:TotalPrepaidAmount>
<ram:DuePayableAmount>529.87</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
<ram:ReceivableSpecifiedTradeAccountingAccount>
<ram:ID>4025:123:4343</ram:ID>
</ram:ReceivableSpecifiedTradeAccountingAccount>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>
12 changes: 8 additions & 4 deletions tests/testcases/CiiToUblSimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ public function testDocumentGeneral(): void
$this->assertXPathNotExists('/ubl:Invoice/cbc:TaxPointDate');
$this->assertXPathValue('/ubl:Invoice/cbc:DocumentCurrencyCode', "EUR");
$this->assertXPathNotExists('/ubl:Invoice/cbc:TaxCurrencyCode');
$this->assertXPathNotExists('/ubl:Invoice/cbc:AccountingCost');
$this->assertXPathValueWithIndex('/ubl:Invoice/cbc:AccountingCost', 0, '4025:123:4343');
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cbc:AccountingCost', 1);
$this->assertXPathNotExists('/ubl:Invoice/cbc:BuyerReference');
$this->assertXPathNotExists('/ubl:Invoice/cbc:StartDate');
$this->assertXPathNotExists('/ubl:Invoice/cbc:EndDate');
$this->assertXPathNotExists('/ubl:Invoice/cac:OrderReference/cbc:ID');
$this->assertXPathNotExists('/ubl:Invoice/cac:OrderReference/cbc:SalesOrderID');
$this->assertXPathNotExists('/ubl:Invoice/cac:BillingReference/cac:InvoiceDocumentReference/cbc:ID');
$this->assertXPathNotExists('/ubl:Invoice/cac:BillingReference/cac:InvoiceDocumentReference/cbc:IssueDate');
$this->assertXPathNotExists('/ubl:Invoice/cac:DespatchDocumentReference/cbc:ID');
$this->assertXPathNotExists('/ubl:Invoice/cac:ReceiptDocumentReference/cbc:ID');
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:DespatchDocumentReference/cbc:ID', 0, '5433');
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:DespatchDocumentReference/cbc:ID', 1);
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:ReceiptDocumentReference/cbc:ID', 0, '3544');
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:ReceiptDocumentReference/cbc:ID', 1);
$this->assertXPathNotExists('/ubl:Invoice/cac:AdditionalDocumentReference/cbc:ID');
$this->assertXPathNotExists('/ubl:Invoice/cac:AdditionalDocumentReference/cbc:DocumentTypeCode');
$this->assertXPathNotExists('/ubl:Invoice/cac:AdditionalDocumentReference/cbc:DocumentDescription');
Expand Down Expand Up @@ -218,7 +221,8 @@ public function testInvoiceLine(): void
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:InvoiceLine/cbc:Note', 0);
$this->assertXPathValueWithIndexAndAttribute('/ubl:Invoice/cac:InvoiceLine/cbc:InvoicedQuantity', 0, "20.0000", "unitCode", "H87");
$this->assertXPathValueWithIndexAndAttribute('/ubl:Invoice/cac:InvoiceLine/cbc:LineExtensionAmount', 0, "198.00", "currencyID", "EUR");
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:InvoiceLine/cbc:AccountingCost', 0);
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:InvoiceLine/cbc:AccountingCost', 0, '0815');
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:InvoiceLine/cbc:AccountingCost', 1);
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:InvoiceLine/cac:InvoicePeriod', 0);
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:InvoiceLine/cac:InvoicePeriod/cbc:StartDate', 0);
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:InvoiceLine/cac:InvoicePeriod/cbc:EndDate', 0);
Expand Down
22 changes: 22 additions & 0 deletions tests/testcases/UblToCiiSimple2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testTradeLineItem(): void
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount', 0, '1000.00');
$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod/ram:StartDateTime/udt:DateTimeString', 0, '20130310', 'format', '102');
$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod/ram:EndDateTime/udt:DateTimeString', 0, '20130410', 'format', '102');
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', 0, 'ACC7654');

$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:AssociatedDocumentLineDocument/ram:LineID', 1, '2');
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:AssociatedDocumentLineDocument/ram:IncludedNote/ram:Content', 1, 'second line');
Expand All @@ -72,6 +73,7 @@ public function testTradeLineItem(): void
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount', 1, '500.00');
$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod/ram:StartDateTime/udt:DateTimeString', 1, '20130310', 'format', '102');
$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod/ram:EndDateTime/udt:DateTimeString', 1, '20130410', 'format', '102');
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', 1, 'ACC7654');

$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:AssociatedDocumentLineDocument/ram:LineID', 2, '3');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:AssociatedDocumentLineDocument/ram:IncludedNote/ram:Content', 2);
Expand All @@ -88,6 +90,7 @@ public function testTradeLineItem(): void
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent', 2, '12.0');
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount', 2, '2500.00');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod', 2);
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', 2);

$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem', 3);
}
Expand Down Expand Up @@ -193,6 +196,11 @@ public function testShipToTradeParty(): void
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty', 1);

$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString', 0, '20130415', 'format', '102');

$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:DespatchAdviceReferencedDocument/ram:IssuerAssignedID', 0, '5433');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:DespatchAdviceReferencedDocument/ram:IssuerAssignedID', 1);
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ReceivingAdviceReferencedDocument/ram:IssuerAssignedID', 0, '3544');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ReceivingAdviceReferencedDocument/ram:IssuerAssignedID', 1);
}

public function testPayeeTradeParty(): void
Expand Down Expand Up @@ -363,4 +371,18 @@ public function testDocumentSummation(): void

$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation', 1);
}

public function testInvoiceReferencedDocument(): void
{
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceReferencedDocument/ram:IssuerAssignedID', 0, 'TOSL109');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceReferencedDocument/ram:IssuerAssignedID', 1);
$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceReferencedDocument/ram:FormattedIssueDateTime/a:DateTimeString', 0, '20130310', 'format', '102');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceReferencedDocument/ram:FormattedIssueDateTime/a:DateTimeString', 1);
}

public function testDocumentAccountingAccount(): void
{
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', 0, '67543');
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', 1);
}
}
Loading

0 comments on commit b331c3b

Please sign in to comment.