From 9c856c4ce7a3f3c1c2ee722198e4be5aab42f953 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Fri, 20 Sep 2024 05:45:25 +0200 Subject: [PATCH] Fix handling of names --- src/XmlConverterCiiToUbl.php | 30 ++++++------- src/XmlConverterUblToCii.php | 85 +++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/src/XmlConverterCiiToUbl.php b/src/XmlConverterCiiToUbl.php index d64cb10..c4fbc55 100644 --- a/src/XmlConverterCiiToUbl.php +++ b/src/XmlConverterCiiToUbl.php @@ -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(); } ); @@ -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)); @@ -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(); } ); @@ -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)); @@ -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(); } ); @@ -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(); diff --git a/src/XmlConverterUblToCii.php b/src/XmlConverterUblToCii.php index 3417872..b5bf6ea 100644 --- a/src/XmlConverterUblToCii.php +++ b/src/XmlConverterUblToCii.php @@ -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( @@ -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(); } ); @@ -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, @@ -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( @@ -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(); } ); @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,