Skip to content

Commit

Permalink
Rework of serveral items
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Nov 7, 2024
1 parent 9b110fa commit 7fd55a4
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 117 deletions.
13 changes: 6 additions & 7 deletions src/XmlConverterCiiToUbl.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ function ($sellerTradePartyTaxRegNode) {
$this->destination->startElement('cac:PartyTaxScheme');
$this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue);
$this->destination->startElement('cac:TaxScheme');
$this->destination->element('cbc:ID', 'TAX');
$this->destination->element('cbc:ID', 'LOC');
$this->destination->endElement();
$this->destination->endElement();
}
Expand Down Expand Up @@ -650,7 +650,7 @@ function ($sellerTradePartyTaxRegNode) {
$this->destination->startElement('cac:PartyTaxScheme');
$this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue);
$this->destination->startElement('cac:TaxScheme');
$this->destination->element('cbc:ID', 'TAX');
$this->destination->element('cbc:ID', 'LOC');
$this->destination->endElement();
$this->destination->endElement();
}
Expand Down Expand Up @@ -798,7 +798,7 @@ function ($sellerTradePartyTaxRegNode) {
$this->destination->startElement('cac:PartyTaxScheme');
$this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue);
$this->destination->startElement('cac:TaxScheme');
$this->destination->element('cbc:ID', 'TAX');
$this->destination->element('cbc:ID', 'LOC');
$this->destination->endElement();
$this->destination->endElement();
}
Expand Down Expand Up @@ -910,7 +910,7 @@ function ($sellerTradePartyTaxRegNode) {
$this->destination->startElement('cac:PartyTaxScheme');
$this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue);
$this->destination->startElement('cac:TaxScheme');
$this->destination->element('cbc:ID', 'TAX');
$this->destination->element('cbc:ID', 'LOC');
$this->destination->endElement();
$this->destination->endElement();
}
Expand Down Expand Up @@ -1053,10 +1053,9 @@ private function convertPaymentMeans(): void
$invoiceSuppyChainTradeTransaction = $this->source->query('./rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0);
$invoiceHeaderSettlement = $this->source->query('./ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0);

$this->source->queryAll(
$this->source->whenExists(
'./ram:SpecifiedTradeSettlementPaymentMeans',
$invoiceHeaderSettlement
)->forEach(
$invoiceHeaderSettlement,
function ($paymentMeansNode) use ($invoiceHeaderSettlement) {
$this->destination->startElement('cac:PaymentMeans');

Expand Down
88 changes: 4 additions & 84 deletions src/XmlConverterUblToCii.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,27 +494,7 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) {
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'TAX\']',
$invoiceAccountingSupplierPartyNode,
function ($invoiceAccountingSupplierPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceAccountingSupplierPartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'FC\']',
$invoiceAccountingSupplierPartyNode,
function ($invoiceAccountingSupplierPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceAccountingSupplierPartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'???\']',
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'LOC\']',
$invoiceAccountingSupplierPartyNode,
function ($invoiceAccountingSupplierPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
Expand Down Expand Up @@ -645,27 +625,7 @@ function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'TAX\']',
$invoiceAccountingCustomerPartyNode,
function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceAccountingCustomerPartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'FC\']',
$invoiceAccountingCustomerPartyNode,
function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceAccountingCustomerPartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'???\']',
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'LOC\']',
$invoiceAccountingCustomerPartyNode,
function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
Expand Down Expand Up @@ -712,27 +672,7 @@ function ($invoiceTaxRepresentativePartyTaxSchemeNode) {
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'TAX\']',
$invoiceTaxRepresentativePartyNode,
function ($invoiceTaxRepresentativePartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceTaxRepresentativePartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'FC\']',
$invoiceTaxRepresentativePartyNode,
function ($invoiceTaxRepresentativePartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceTaxRepresentativePartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'???\']',
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'LOC\']',
$invoiceTaxRepresentativePartyNode,
function ($invoiceTaxRepresentativePartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
Expand Down Expand Up @@ -1035,27 +975,7 @@ function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'TAX\']',
$invoicePayeePartyNode,
function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceAccountingCustomerPartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'FC\']',
$invoicePayeePartyNode,
function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('../../cbc:CompanyID', $invoiceAccountingCustomerPartyTaxSchemeNode), 'schemeID', 'FC');
$this->destination->endElement();
}
);

$this->source->whenExists(
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'???\']',
'./cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'LOC\']',
$invoicePayeePartyNode,
function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$this->destination->startElement('ram:SpecifiedTaxRegistration');
Expand Down
14 changes: 9 additions & 5 deletions src/XmlDocumentReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,15 @@ public function whenNotEquals(string $expression, ?DOMNode $contextNode, $values

if ($equals === false) {
if (is_callable($callback)) {
call_user_func(
$callback,
$this->query($expression, $contextNode)->item(0),
$this->query($expression, $contextNode)->item(0)->parentNode
);
if ($this->query($expression, $contextNode)->item(0)) {
call_user_func(
$callback,
$this->query($expression, $contextNode)->item(0),
$this->query($expression, $contextNode)->item(0)->parentNode
);
} else {
call_user_func($callback);
}
}
} else {
if (is_callable($callbackElse)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/CiiToUblDiscountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testAccountingSupplierParty(): void
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 0, "DE123456789");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 0, "VAT");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 1, "201/113/40209");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 1, "TAX");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 1, "LOC");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName', 0, "Lieferant GmbH");
$this->assertXPathNotExists('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm');
$this->assertXPathNotExists('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID');
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/CiiToUblExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testAccountingSupplierParty(): void
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode', 0, "DE");
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cac:AddressLine/cbc:Line', 0);
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 0, "201/113/40209");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 0, "TAX");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 0, "LOC");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName', 0, "MUSTERLIEFERANT GMBH");
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm', 0);
$this->assertXPathNotExistsWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID', 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/CiiToUblSimplePayeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testAccountingSupplierParty(): void
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 0, "DE123456789");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 0, "VAT");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 1, "201/113/40209");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 1, "TAX");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 1, "LOC");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName', 0, "Lieferant GmbH");
$this->assertXPathNotExists('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm');
$this->assertXPathNotExists('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID');
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/CiiToUblSimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testAccountingSupplierParty(): void
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 0, "DE123456789");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 0, "VAT");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID', 1, "201/113/40209");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 1, "TAX");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', 1, "LOC");
$this->assertXPathValueWithIndex('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName', 0, "Lieferant GmbH");
$this->assertXPathNotExists('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm');
$this->assertXPathNotExists('/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID');
Expand Down
Loading

0 comments on commit 7fd55a4

Please sign in to comment.