diff --git a/src/XmlConverterCiiToUbl.php b/src/XmlConverterCiiToUbl.php index 98c786a..8f01690 100644 --- a/src/XmlConverterCiiToUbl.php +++ b/src/XmlConverterCiiToUbl.php @@ -409,6 +409,11 @@ function ($sellerTradePartyUniversalCommNode) { } ); + // Set the IDs of the seller + // ID's cardinallity + // CII - ID is 0..unbounded, GlobalID is 0..unbounded + // UBL - PartyIdentification is 0..unbounded + $this->source->queryAll('./ram:ID', $sellerTradePartyNode)->forEach( function ($sellerTradePartyIdNode) { $this->destination->startElement('cac:PartyIdentification'); @@ -430,9 +435,7 @@ function ($sellerTradePartyGlobalIdNode) { $invoiceHeaderSettlement, function ($DirectDebitMandateNode) { $this->destination->startElement('cac:PartyIdentification'); - $this->destination->startElement('cbc:ID', $DirectDebitMandateNode->nodeValue); - $this->destination->attribute('schemeID', 'SEPA'); - $this->destination->endElement(); + $this->destination->elementWithAttribute('cbc:ID', $DirectDebitMandateNode->nodeValue, 'schemeID', 'SEPA'); $this->destination->endElement(); } ); @@ -559,6 +562,11 @@ function ($buyerTradePartyUniversalCommNode) { } ); + // Set the IDs of the buyer + // ID's cardinallity + // CII - ID is 0..1, GlobalID is 0..1 + // UBL - PartyIdentification is 0..1 + $this->source->whenExists( './ram:GlobalID', $buyerTradePartyNode, @@ -702,6 +710,11 @@ function ($payeeTradePartyUniversalCommNode) { } ); + // Set the IDs of the payee + // ID's cardinallity + // CII - ID is 0..1, GlobalID is 0..1 + // UBL - PartyIdentification is 0..1 + $this->source->whenExists( './ram:GlobalID', $payeeTradePartyNode, @@ -835,16 +848,6 @@ private function convertTaxRepresentativeParty(): void function ($sellerTaxRepresentativePartyNode) { $this->destination->startElement('cac:TaxRepresentativeParty'); - $this->source->whenExists( - './ram:URIUniversalCommunication/ram:URIID', - $sellerTaxRepresentativePartyNode, - function ($sellerTaxRepresentativePartyUniversalCommNode) { - $this->destination->startElement('cbc:EndpointID', $sellerTaxRepresentativePartyUniversalCommNode->nodeValue); - $this->destination->attribute('schemeID', $this->source->queryValue('./@schemeID', $sellerTaxRepresentativePartyUniversalCommNode)); - $this->destination->endElement(); - } - ); - $this->source->whenExists( './ram:Name', $sellerTaxRepresentativePartyNode, @@ -945,6 +948,11 @@ function ($shipToTradePartyNode) use ($invoiceHeaderDelivery) { $this->destination->startElement('cac:DeliveryLocation'); + // Set the IDs of the ship to party + // ID's cardinallity + // CII - ID is 0..1, GlobalID is 0..1 + // UBL - PartyIdentification is 0..1 + $this->source->whenExists( './ram:GlobalID', $shipToTradePartyNode, diff --git a/src/XmlConverterUblToCii.php b/src/XmlConverterUblToCii.php index f0d04ff..f3da38b 100644 --- a/src/XmlConverterUblToCii.php +++ b/src/XmlConverterUblToCii.php @@ -385,16 +385,24 @@ private function convertApplicableHeaderTradeAgreement(): void $docRootElement, function ($invoiceAccountingSupplierPartyNode) { $this->destination->startElement('ram:SellerTradeParty'); + + // Set the IDs of the seller + // ID's cardinallity + // UBL - PartyIdentification is 0..unbounded + // CII - ID is 0..unbounded, GlobalID is 0..unbounded + $this->source->queryAll('./cac:PartyIdentification/cbc:ID[not(@schemeID)]', $invoiceAccountingSupplierPartyNode)->forEach( function ($invoiceAccountingSupplierPartyIdNode) { $this->destination->element('ram:ID', $invoiceAccountingSupplierPartyIdNode->nodeValue); } ); + $this->source->queryAll('./cac:PartyIdentification/cbc:ID[@schemeID != \'\' and @schemeID != \'SEPA\']', $invoiceAccountingSupplierPartyNode)->forEach( function ($invoiceAccountingSupplierPartyIdNode) { $this->destination->elementWithAttribute('ram:GlobalID', $invoiceAccountingSupplierPartyIdNode->nodeValue, 'schemeID', $invoiceAccountingSupplierPartyIdNode->getAttribute('schemeID')); } ); + $this->source->whenExists( './cac:PartyLegalEntity/cbc:RegistrationName', $invoiceAccountingSupplierPartyNode, @@ -402,6 +410,7 @@ function ($invoiceAccountingSupplierPartyNodeRegNameNode) { $this->destination->element('ram:Name', $invoiceAccountingSupplierPartyNodeRegNameNode->nodeValue); } ); + $this->source->whenExists( './cac:PartyLegalEntity/cbc:CompanyLegalForm', $invoiceAccountingSupplierPartyNode, @@ -409,6 +418,7 @@ function ($invoiceAccountingSupplierPartyLegalEntityNode) { $this->destination->element('ram:Description', $invoiceAccountingSupplierPartyLegalEntityNode->nodeValue); } ); + $this->source->whenOneExists( ['./cac:PartyLegalEntity/cbc:CompanyID', './cac:PartyName/cbc:Name'], [$invoiceAccountingSupplierPartyNode, $invoiceAccountingSupplierPartyNode], @@ -419,6 +429,7 @@ function () use ($invoiceAccountingSupplierPartyNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cac:Contact', $invoiceAccountingSupplierPartyNode, @@ -446,6 +457,7 @@ function ($invoiceAccountingSupplierPartyContactMailNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cac:PostalAddress', $invoiceAccountingSupplierPartyNode, @@ -460,6 +472,7 @@ function ($invoiceAccountingSupplierPartyPostalAddressNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cbc:EndpointID[@schemeID=\'EM\']', $invoiceAccountingSupplierPartyNode, @@ -469,6 +482,7 @@ function ($invoiceAccountingSupplierPartyEndpointNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'VAT\']', $invoiceAccountingSupplierPartyNode, @@ -478,6 +492,7 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'TAX\']', $invoiceAccountingSupplierPartyNode, @@ -487,6 +502,7 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'FC\']', $invoiceAccountingSupplierPartyNode, @@ -496,6 +512,7 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) { $this->destination->endElement(); } ); + $this->source->whenExists( './cac:PartyTaxScheme/cac:TaxScheme/cbc:ID[text() = \'???\']', $invoiceAccountingSupplierPartyNode, @@ -505,6 +522,7 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) { $this->destination->endElement(); } ); + $this->destination->endElement(); } ); @@ -515,6 +533,11 @@ function ($invoiceAccountingSupplierPartyTaxSchemeNode) { function ($invoiceAccountingCustomerPartyNode) { $this->destination->startElement('ram:BuyerTradeParty'); + // Set the IDs of the buyer + // ID's cardinallity + // UBL - PartyIdentification is 0..1 + // CII - ID is 0..1, GlobalID is 0..1 + $this->source->whenExists( './cac:PartyIdentification/cbc:ID[not(@schemeID)]', $invoiceAccountingCustomerPartyNode, @@ -809,6 +832,11 @@ private function convertApplicableHeaderTradeDelivery(): void function ($deliveryLocationNode, $deliveryNode) { $this->destination->startElement('ram:ShipToTradeParty'); + // Set the IDs of the ship to party + // ID's cardinallity + // UBL - PartyIdentification is 0..1 + // CII - ID is 0..1, GlobalID is 0..1 + $this->source->whenExists( './cbc:ID[not(@schemeID)]', $deliveryLocationNode, @@ -910,6 +938,11 @@ function ($documentCUrrencyNode) { function ($invoicePayeePartyNode) { $this->destination->startElement('ram:PayeeTradeParty'); + // Set the IDs of the payee + // ID's cardinallity + // UBL - PartyIdentification is 0..1 + // CII - ID is 0..1, GlobalID is 0..1 + $this->source->whenExists( './cac:PartyIdentification/cbc:ID[not(@schemeID)]', $invoicePayeePartyNode,