Skip to content

Commit

Permalink
Fix handling of names
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Sep 20, 2024
1 parent 88f18b2 commit 9c856c4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 42 deletions.
30 changes: 13 additions & 17 deletions src/XmlConverterCiiToUbl.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,6 @@ function ($sellerTradePartyLegalOrgNameNode) {
$this->destination->startElement('cac:PartyName');
$this->destination->element('cbc:Name', $sellerTradePartyLegalOrgNameNode->nodeValue);
$this->destination->endElement();
}, function () use ($sellerTradePartyNode) {
$this->destination->startElement('cac:PartyName');
$this->destination->element('cbc:Name', $this->source->queryValue('./ram:Name', $sellerTradePartyNode));
$this->destination->endElement();
}
);

Expand Down Expand Up @@ -507,7 +503,8 @@ function ($sellerTradePartyTaxRegNode) {
);

$this->destination->group(
'cac:PartyLegalEntity', function () use ($sellerTradePartyNode) {
'cac:PartyLegalEntity',
function () use ($sellerTradePartyNode) {
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $sellerTradePartyNode));
$this->destination->elementWithAttribute('cbc:CompanyID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID', $sellerTradePartyNode), 'schemeID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID/@schemeID', $sellerTradePartyNode));
$this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('./ram:Description', $sellerTradePartyNode));
Expand Down Expand Up @@ -587,10 +584,6 @@ function ($buyerTradePartyLegalOrgNameNode) {
$this->destination->startElement('cac:PartyName');
$this->destination->element('cbc:Name', $buyerTradePartyLegalOrgNameNode->nodeValue);
$this->destination->endElement();
}, function () use ($buyerTradePartyNode) {
$this->destination->startElement('cac:PartyName');
$this->destination->element('cbc:Name', $this->source->queryValue('./ram:Name', $buyerTradePartyNode));
$this->destination->endElement();
}
);

Expand Down Expand Up @@ -653,7 +646,8 @@ function ($sellerTradePartyTaxRegNode) {
);

$this->destination->group(
'cac:PartyLegalEntity', function () use ($buyerTradePartyNode) {
'cac:PartyLegalEntity',
function () use ($buyerTradePartyNode) {
$this->destination->element('cbc:RegistrationName', $this->source->queryValue('./ram:Name', $buyerTradePartyNode));
$this->destination->elementWithAttribute('cbc:CompanyID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID', $buyerTradePartyNode), 'schemeID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID/@schemeID', $buyerTradePartyNode));
$this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('./ram:Description', $buyerTradePartyNode));
Expand Down Expand Up @@ -795,12 +789,12 @@ function ($sellerTradePartyTaxRegNode) {
);

$this->source->whenExists(
'./ram:SpecifiedLegalOrganization/ram:ID', $payeeTradePartyNode, function () use ($payeeTradePartyNode) {
$this->destination->group(
'cac:PartyLegalEntity', function () use ($payeeTradePartyNode) {
$this->destination->elementWithAttribute('cbc:CompanyID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID', $payeeTradePartyNode), 'schemeID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID/@schemeID', $payeeTradePartyNode));
}
);
'./ram:SpecifiedLegalOrganization/ram:ID',
$payeeTradePartyNode,
function () use ($payeeTradePartyNode) {
$this->destination->startElement('cac:PartyLegalEntity');
$this->destination->elementWithAttribute('cbc:CompanyID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID', $payeeTradePartyNode), 'schemeID', $this->source->queryValue('./ram:SpecifiedLegalOrganization/ram:ID/@schemeID', $payeeTradePartyNode));
$this->destination->endElement();
}
);

Expand Down Expand Up @@ -858,7 +852,9 @@ function ($sellerTaxRepresentativePartyGlobalIdNode) {
},
function () use ($sellerTaxRepresentativePartyNode) {
$this->source->whenExists(
'./ram:ID', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyIdNode) {
'./ram:ID',
$sellerTaxRepresentativePartyNode,
function ($sellerTaxRepresentativePartyIdNode) {
$this->destination->startElement('cac:PartyIdentification');
$this->destination->elementWithAttribute('cbc:ID', $sellerTaxRepresentativePartyIdNode->nodeValue, 'schemeID', $sellerTaxRepresentativePartyIdNode->getAttribute('schemeID'));
$this->destination->endElement();
Expand Down
85 changes: 60 additions & 25 deletions src/XmlConverterUblToCii.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,10 @@ function ($invoiceAccountingSupplierPartyIdNode) {
}
);
$this->source->whenExists(
'./cac:PartyName/cbc:Name',
'./cac:PartyLegalEntity/cbc:RegistrationName',
$invoiceAccountingSupplierPartyNode,
function ($invoiceAccountingSupplierPartyNameNode) {
$this->destination->element('ram:Name', $invoiceAccountingSupplierPartyNameNode->nodeValue);
},
function () use ($invoiceAccountingSupplierPartyNode) {
$this->destination->element('ram:Name', $this->source->queryValue('./cac:PartyLegalEntity/cbc:RegistrationName', $invoiceAccountingSupplierPartyNode));
function ($invoiceAccountingSupplierPartyNodeRegNameNode) {
$this->destination->element('ram:Name', $invoiceAccountingSupplierPartyNodeRegNameNode->nodeValue);
}
);
$this->source->whenExists(
Expand All @@ -397,13 +394,11 @@ function ($invoiceAccountingSupplierPartyLegalEntityNode) {
$this->destination->element('ram:Description', $invoiceAccountingSupplierPartyLegalEntityNode->nodeValue);
}
);
$this->source->whenExists(
'./cac:PartyLegalEntity',
$invoiceAccountingSupplierPartyNode,
function ($invoiceAccountingSupplierPartyLegalEntityNode) {
$this->source->whenOneExists(
['./cac:PartyLegalEntity/cbc:CompanyID', './cac:PartyName/cbc:Name'], [$invoiceAccountingSupplierPartyNode, $invoiceAccountingSupplierPartyNode], function () use ($invoiceAccountingSupplierPartyNode) {
$this->destination->startElement('ram:SpecifiedLegalOrganization');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('./cbc:CompanyID', $invoiceAccountingSupplierPartyLegalEntityNode), 'schemeID', $this->source->queryValue('./cbc:CompanyID/@schemeID', $invoiceAccountingSupplierPartyLegalEntityNode));
$this->destination->element('ram:TradingBusinessName', $this->source->queryValue('./cbc:RegistrationName', $invoiceAccountingSupplierPartyLegalEntityNode));
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('./cac:PartyLegalEntity/cbc:CompanyID', $invoiceAccountingSupplierPartyNode), 'schemeID', $this->source->queryValue('./cac:PartyLegalEntity/cbc:CompanyID/@schemeID', $invoiceAccountingSupplierPartyNode));
$this->destination->element('ram:TradingBusinessName', $this->source->queryValue('./cac:PartyName/cbc:Name', $invoiceAccountingSupplierPartyNode));
$this->destination->endElement();
}
);
Expand Down Expand Up @@ -475,6 +470,15 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) {
$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() = \'???\']',
$invoiceAccountingSupplierPartyNode,
Expand All @@ -500,13 +504,10 @@ function ($invoiceAccountingCustomerPartyIdNode) {
}
);
$this->source->whenExists(
'./cac:PartyName/cbc:Name',
'./cac:PartyLegalEntity/cbc:RegistrationName',
$invoiceAccountingCustomerPartyNode,
function ($invoiceAccountingCustomerPartyNameNode) {
$this->destination->element('ram:Name', $invoiceAccountingCustomerPartyNameNode->nodeValue);
},
function () use ($invoiceAccountingCustomerPartyNode) {
$this->destination->element('ram:Name', $this->source->queryValue('./cac:PartyLegalEntity/cbc:RegistrationName', $invoiceAccountingCustomerPartyNode));
function ($invoiceAccountingCustomerPartyNodeRegNameNode) {
$this->destination->element('ram:Name', $invoiceAccountingCustomerPartyNodeRegNameNode->nodeValue);
}
);
$this->source->whenExists(
Expand All @@ -516,13 +517,11 @@ function ($invoiceAccountingCustomerPartyLegalEntityNode) {
$this->destination->element('ram:Description', $invoiceAccountingCustomerPartyLegalEntityNode->nodeValue);
}
);
$this->source->whenExists(
'./cac:PartyLegalEntity',
$invoiceAccountingCustomerPartyNode,
function ($invoiceAccountingCustomerPartyLegalEntityNode) {
$this->source->whenOneExists(
['./cac:PartyLegalEntity/cbc:CompanyID', './cac:PartyName/cbc:Name'], [$invoiceAccountingCustomerPartyNode, $invoiceAccountingCustomerPartyNode], function () use ($invoiceAccountingCustomerPartyNode) {
$this->destination->startElement('ram:SpecifiedLegalOrganization');
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('./cbc:CompanyID', $invoiceAccountingCustomerPartyLegalEntityNode), 'schemeID', $this->source->queryValue('./cbc:CompanyID/@schemeID', $invoiceAccountingCustomerPartyLegalEntityNode));
$this->destination->element('ram:TradingBusinessName', $this->source->queryValue('./cbc:RegistrationName', $invoiceAccountingCustomerPartyLegalEntityNode));
$this->destination->elementWithAttribute('ram:ID', $this->source->queryValue('./cac:PartyLegalEntity/cbc:CompanyID', $invoiceAccountingCustomerPartyNode), 'schemeID', $this->source->queryValue('./cac:PartyLegalEntity/cbc:CompanyID/@schemeID', $invoiceAccountingCustomerPartyNode));
$this->destination->element('ram:TradingBusinessName', $this->source->queryValue('./cac:PartyName/cbc:Name', $invoiceAccountingCustomerPartyNode));
$this->destination->endElement();
}
);
Expand Down Expand Up @@ -594,6 +593,15 @@ function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$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() = \'???\']',
$invoiceAccountingCustomerPartyNode,
Expand Down Expand Up @@ -651,6 +659,15 @@ function ($invoiceTaxRepresentativePartyTaxSchemeNode) {
$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() = \'???\']',
$invoiceTaxRepresentativePartyNode,
Expand Down Expand Up @@ -846,6 +863,15 @@ function ($invoiceAccountingCustomerPartyIdNode) {
}
);
$this->destination->element('ram:Name', $this->source->queryValue('./cac:PartyName/cbc:Name', $invoicePayeePartyNode));
$this->source->whenExists(
'./cac:PartyLegalEntity/cbc:CompanyID',
$invoicePayeePartyNode,
function ($invoiceAccountingSupplierPartyLegalEntityCompanyIdNode) {
$this->destination->startElement('ram:SpecifiedLegalOrganization');
$this->destination->elementWithAttribute('ram:ID', $invoiceAccountingSupplierPartyLegalEntityCompanyIdNode->nodeValue, 'schemeID', $this->source->queryValue('./@schemeID', $invoiceAccountingSupplierPartyLegalEntityCompanyIdNode));
$this->destination->endElement();
}
);
$this->source->whenExists(
'./cac:Contact',
$invoicePayeePartyNode,
Expand Down Expand Up @@ -914,6 +940,15 @@ function ($invoiceAccountingCustomerPartyTaxSchemeNode) {
$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() = \'???\']',
$invoicePayeePartyNode,
Expand Down Expand Up @@ -981,7 +1016,7 @@ function ($taxSubtotalNode) use ($docRootElement) {
$this->destination->element('ram:TypeCode', $this->source->queryValue('./cac:TaxCategory/cac:TaxScheme/cbc:ID', $taxSubtotalNode));
$this->destination->element('ram:BasisAmount', $this->source->queryValue('./cbc:TaxableAmount', $taxSubtotalNode));
$this->destination->element('ram:CategoryCode', $this->source->queryValue('./cac:TaxCategory/cbc:ID', $taxSubtotalNode));
if ($this->source->queryValue('./cac:TaxCategory/cbc:ID', $taxSubtotalNode) == "E") {
if ($this->source->queryValue('./cac:TaxCategory/cbc:ID', $taxSubtotalNode) != "E") {
$this->source->whenExists(
'./cbc:TaxPointDate',
$docRootElement,
Expand Down

0 comments on commit 9c856c4

Please sign in to comment.