diff --git a/src/XmlConverterBase.php b/src/XmlConverterBase.php index d132d0d..2984c49 100644 --- a/src/XmlConverterBase.php +++ b/src/XmlConverterBase.php @@ -29,29 +29,29 @@ abstract class XmlConverterBase * * @var XmlDocumentReader */ - protected $in = null; + protected $source = null; /** * The output document * * @var XmlDocumentWriter */ - protected $out = null; + protected $destination = null; /** * Constructor */ protected final function __construct() { - $this->in = (new XmlDocumentReader()); - $this->out = (new XmlDocumentWriter($this->getDestinationRoot())); + $this->source = (new XmlDocumentReader()); + $this->destination = (new XmlDocumentWriter($this->getDestinationRoot())); foreach ($this->getSourceNamespaces() as $namespace => $namespaceUri) { - $this->in->addNamespace($namespace, $namespaceUri); + $this->source->addNamespace($namespace, $namespaceUri); } foreach ($this->getDestinationNamespaces() as $namespace => $namespaceUri) { - $this->out->addNamespace($namespace, $namespaceUri); + $this->destination->addNamespace($namespace, $namespaceUri); } } @@ -63,7 +63,7 @@ protected final function __construct() */ public function loadFromXmlString(string $source): XmlConverterCiiToUbl { - $this->in->loadFromXmlString($source); + $this->source->loadFromXmlString($source); return $this; } @@ -81,7 +81,7 @@ public function loadFromXmlFile(string $filename): XmlConverterCiiToUbl throw new RuntimeException("File $filename does not exists"); } - $this->in->loadFromXmlFile($filename); + $this->source->loadFromXmlFile($filename); return $this; } @@ -93,7 +93,7 @@ public function loadFromXmlFile(string $filename): XmlConverterCiiToUbl */ public function saveXmlString(): string { - return $this->out->saveXmlString(); + return $this->destination->saveXmlString(); } /** @@ -104,7 +104,7 @@ public function saveXmlString(): string */ public function saveXmlFile(string $filename) { - return $this->out->saveXmlFile($filename); + return $this->destination->saveXmlFile($filename); } /** diff --git a/src/XmlConverterCiiToUbl.php b/src/XmlConverterCiiToUbl.php index 6c1460a..05074b0 100644 --- a/src/XmlConverterCiiToUbl.php +++ b/src/XmlConverterCiiToUbl.php @@ -118,6 +118,7 @@ protected function getDestinationNamespaces(): array public function convert() { $this->checkValidSource(); + $this->convertGeneral(); $this->convertSellerTradeParty(); $this->convertBuyerTradeParty(); @@ -165,10 +166,10 @@ public function enableAmountFormatDisabled(): XmlConverterCiiToUbl */ private function checkValidSource(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceExchangeDocumentContext = $this->in->query('//rsm:ExchangedDocumentContext', $invoiceElement)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceExchangeDocumentContext = $this->source->query('//rsm:ExchangedDocumentContext', $invoiceElement)->item(0); - $submittedProfile = $this->in->queryValue('.//ram:GuidelineSpecifiedDocumentContextParameter/ram:ID', $invoiceExchangeDocumentContext); + $submittedProfile = $this->source->queryValue('.//ram:GuidelineSpecifiedDocumentContextParameter/ram:ID', $invoiceExchangeDocumentContext); if (!in_array($submittedProfile, static::SUPPORTED_PROFILES)) { throw new \RuntimeException(sprintf('The submitted profile %s is not supported', $submittedProfile)); @@ -182,190 +183,190 @@ private function checkValidSource(): void */ private function convertGeneral(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceExchangeDocumentContext = $this->in->query('//rsm:ExchangedDocumentContext', $invoiceElement)->item(0); - $invoiceExchangeDocument = $this->in->query('//rsm:ExchangedDocument', $invoiceElement)->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $invoiceHeaderAgreement = $this->in->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); - $invoiceHeaderDelivery = $this->in->query('//ram:ApplicableHeaderTradeDelivery', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceExchangeDocumentContext = $this->source->query('//rsm:ExchangedDocumentContext', $invoiceElement)->item(0); + $invoiceExchangeDocument = $this->source->query('//rsm:ExchangedDocument', $invoiceElement)->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceHeaderAgreement = $this->source->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceHeaderDelivery = $this->source->query('//ram:ApplicableHeaderTradeDelivery', $invoiceSuppyChainTradeTransaction)->item(0); - $this->out->element('cbc:CustomizationID', $this->in->queryValue('.//ram:GuidelineSpecifiedDocumentContextParameter/ram:ID', $invoiceExchangeDocumentContext)); - $this->out->element('cbc:ProfileID', 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0'); + $this->destination->element('cbc:CustomizationID', $this->source->queryValue('.//ram:GuidelineSpecifiedDocumentContextParameter/ram:ID', $invoiceExchangeDocumentContext)); + $this->destination->element('cbc:ProfileID', 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:ID', $invoiceExchangeDocument)); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:ID', $invoiceExchangeDocument)); - $this->out->element( + $this->destination->element( 'cbc:IssueDate', $this->convertDateTime( - $this->in->queryValue('.//ram:IssueDateTime/udt:DateTimeString', $invoiceExchangeDocument), - $this->in->queryValue('.//ram:IssueDateTime/udt:DateTimeString/@format', $invoiceExchangeDocument) + $this->source->queryValue('.//ram:IssueDateTime/udt:DateTimeString', $invoiceExchangeDocument), + $this->source->queryValue('.//ram:IssueDateTime/udt:DateTimeString/@format', $invoiceExchangeDocument) ) ); - $this->out->element( + $this->destination->element( 'cbc:DueDate', $this->convertDateTime( - $this->in->queryValue('.//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString', $invoiceHeaderSettlement), - $this->in->queryValue('.//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString/@format', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString', $invoiceHeaderSettlement), + $this->source->queryValue('.//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString/@format', $invoiceHeaderSettlement) ) ); - $this->out->element('cbc:InvoiceTypeCode', $this->in->queryValue('.//ram:TypeCode', $invoiceExchangeDocument)); + $this->destination->element('cbc:InvoiceTypeCode', $this->source->queryValue('.//ram:TypeCode', $invoiceExchangeDocument)); - $this->in->queryValues('.//ram:IncludedNote', $invoiceExchangeDocument)->forEach( + $this->source->queryValues('.//ram:IncludedNote', $invoiceExchangeDocument)->forEach( function ($includedNoteNode) { - $note = $this->in->queryValue('.//ram:Content', $includedNoteNode); - if ($this->in->queryValue('.//ram:SubjectCode', $includedNoteNode)) { - $note = sprintf('#%s#%s', $this->in->queryValue('.//ram:SubjectCode'), $note); + $note = $this->source->queryValue('.//ram:Content', $includedNoteNode); + if ($this->source->queryValue('.//ram:SubjectCode', $includedNoteNode)) { + $note = sprintf('#%s#%s', $this->source->queryValue('.//ram:SubjectCode'), $note); } - $this->out->element('cbc:Note', $note); + $this->destination->element('cbc:Note', $note); } ); - $this->out->element( + $this->destination->element( 'cbc:TaxPointDate', $this->convertDateTime( - $this->in->queryValue('.//ram:ApplicableTradeTax/ram:TaxPointDate/udt:DateString', $invoiceHeaderSettlement), - $this->in->queryValue('.//ram:ApplicableTradeTax/ram:TaxPointDate/udt:DateString/@format', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:ApplicableTradeTax/ram:TaxPointDate/udt:DateString', $invoiceHeaderSettlement), + $this->source->queryValue('.//ram:ApplicableTradeTax/ram:TaxPointDate/udt:DateString/@format', $invoiceHeaderSettlement) ) ); - $this->out->element('cbc:DocumentCurrencyCode', $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); + $this->destination->element('cbc:DocumentCurrencyCode', $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); - $this->out->element('cbc:TaxCurrencyCode', $this->in->queryValue('.//ram:TaxCurrencyCode', $invoiceHeaderSettlement)); + $this->destination->element('cbc:TaxCurrencyCode', $this->source->queryValue('.//ram:TaxCurrencyCode', $invoiceHeaderSettlement)); - $this->out->element('cbc:AccountingCost', $this->in->queryValue('.//ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', $invoiceHeaderSettlement)); + $this->destination->element('cbc:AccountingCost', $this->source->queryValue('.//ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', $invoiceHeaderSettlement)); - $this->out->element('cbc:BuyerReference', $this->in->queryValue('.//ram:BuyerReference', $invoiceHeaderAgreement)); + $this->destination->element('cbc:BuyerReference', $this->source->queryValue('.//ram:BuyerReference', $invoiceHeaderAgreement)); - $this->in->whenExists( + $this->source->whenExists( './/ram:BillingSpecifiedPeriod', $invoiceHeaderSettlement, function ($nodeFound) { - $this->out->startElement('cac:InvoicePeriod'); - $this->out->element( + $this->destination->startElement('cac:InvoicePeriod'); + $this->destination->element( 'cbc:StartDate', $this->convertDateTime( - $this->in->queryValue('.//ram:StartDateTime/udt:DateTimeString', $nodeFound), - $this->in->queryValue('.//ram:StartDateTime/udt:DateTimeString/@format', $nodeFound) + $this->source->queryValue('.//ram:StartDateTime/udt:DateTimeString', $nodeFound), + $this->source->queryValue('.//ram:StartDateTime/udt:DateTimeString/@format', $nodeFound) ) ); - $this->out->element( + $this->destination->element( 'cbc:EndDate', $this->convertDateTime( - $this->in->queryValue('.//ram:EndDateTime/udt:DateTimeString', $nodeFound), - $this->in->queryValue('.//ram:EndDateTime/udt:DateTimeString/@format', $nodeFound) + $this->source->queryValue('.//ram:EndDateTime/udt:DateTimeString', $nodeFound), + $this->source->queryValue('.//ram:EndDateTime/udt:DateTimeString/@format', $nodeFound) ) ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:BuyerOrderReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderAgreement, function ($nodeFound) use ($invoiceHeaderAgreement) { - $this->out->startElement('cac:OrderReference'); - $this->out->element('cbc:ID', $nodeFound->nodeValue); - $this->out->element('cbc:SalesOrderID', $this->in->queryValue('.//ram:SellerOrderReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderAgreement)); - $this->out->endElement(); + $this->destination->startElement('cac:OrderReference'); + $this->destination->element('cbc:ID', $nodeFound->nodeValue); + $this->destination->element('cbc:SalesOrderID', $this->source->queryValue('.//ram:SellerOrderReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderAgreement)); + $this->destination->endElement(); }, function () use ($invoiceHeaderAgreement) { - $this->in->whenExists( + $this->source->whenExists( './/ram:SellerOrderReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderAgreement, function ($sellerOrderReferencedDocumentNode) { - $this->out->startElement('cac:OrderReference'); - $this->out->element('cbc:SalesOrderID', $sellerOrderReferencedDocumentNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:OrderReference'); + $this->destination->element('cbc:SalesOrderID', $sellerOrderReferencedDocumentNode->nodeValue); + $this->destination->endElement(); } ); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:InvoiceReferencedDocument', $invoiceHeaderSettlement, function ($nodeFound) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:BillingReference'); - $this->out->startElement('cac:InvoiceDocumentReference'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:IssuerAssignedID', $nodeFound)); - $this->out->element( + $this->destination->startElement('cac:BillingReference'); + $this->destination->startElement('cac:InvoiceDocumentReference'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:IssuerAssignedID', $nodeFound)); + $this->destination->element( 'cbc:IssueDate', $this->convertDateTime( - $this->in->queryValue('.//ram:FormattedIssueDateTime/qdt:DateTimeString', $nodeFound), - $this->in->queryValue('.//ram:FormattedIssueDateTime/qdt:DateTimeString/@format', $nodeFound) + $this->source->queryValue('.//ram:FormattedIssueDateTime/qdt:DateTimeString', $nodeFound), + $this->source->queryValue('.//ram:FormattedIssueDateTime/qdt:DateTimeString/@format', $nodeFound) ) ); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->queryValues('.//ram:DespatchAdviceReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderDelivery)->forEach( + $this->source->queryValues('.//ram:DespatchAdviceReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderDelivery)->forEach( function ($nodeFound) { - $this->out->startElement('cac:DespatchDocumentReference'); - $this->out->element('cbc:ID', $nodeFound->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:DespatchDocumentReference'); + $this->destination->element('cbc:ID', $nodeFound->nodeValue); + $this->destination->endElement(); } ); - $this->in->queryValues('.//ram:ReceivingAdviceReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderDelivery)->forEach( + $this->source->queryValues('.//ram:ReceivingAdviceReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderDelivery)->forEach( function ($nodeFound) { - $this->out->startElement('cac:ReceiptDocumentReference'); - $this->out->element('cbc:ID', $nodeFound->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:ReceiptDocumentReference'); + $this->destination->element('cbc:ID', $nodeFound->nodeValue); + $this->destination->endElement(); } ); - $this->in->queryValues('.//ram:AdditionalReferencedDocument', $invoiceHeaderAgreement)->forEach( + $this->source->queryValues('.//ram:AdditionalReferencedDocument', $invoiceHeaderAgreement)->forEach( function ($nodeFound) { - $this->in->whenEquals( + $this->source->whenEquals( './/ram:TypeCode', $nodeFound, '50', function () use ($nodeFound) { - $this->out->startElement('cac:OriginatorDocumentReference'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:IssuerAssignedID', $nodeFound)); - $this->out->endElement(); + $this->destination->startElement('cac:OriginatorDocumentReference'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:IssuerAssignedID', $nodeFound)); + $this->destination->endElement(); } ); } ); - $this->in->queryValues('.//ram:ContractReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderAgreement)->forEach( + $this->source->queryValues('.//ram:ContractReferencedDocument/ram:IssuerAssignedID', $invoiceHeaderAgreement)->forEach( function ($nodeFound) { - $this->out->startElement('cac:ContractDocumentReference'); - $this->out->element('cbc:ID', $nodeFound->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:ContractDocumentReference'); + $this->destination->element('cbc:ID', $nodeFound->nodeValue); + $this->destination->endElement(); } ); - $this->in->queryValues('.//ram:AdditionalReferencedDocument', $invoiceHeaderAgreement)->forEach( + $this->source->queryValues('.//ram:AdditionalReferencedDocument', $invoiceHeaderAgreement)->forEach( function ($additionalReferencedDocumentNode) { - $this->in->whenNotEquals( + $this->source->whenNotEquals( './/ram:TypeCode', $additionalReferencedDocumentNode, '50', function () use ($additionalReferencedDocumentNode) { - $this->out->startElement('cac:AdditionalDocumentReference'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:IssuerAssignedID', $additionalReferencedDocumentNode)); - $this->in->whenEquals( + $this->destination->startElement('cac:AdditionalDocumentReference'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:IssuerAssignedID', $additionalReferencedDocumentNode)); + $this->source->whenEquals( './/ram:TypeCode', $additionalReferencedDocumentNode, '130', function () use ($additionalReferencedDocumentNode) { - $this->out->element('cbc:DocumentTypeCode', $this->in->queryValue('.//ram:TypeCode', $additionalReferencedDocumentNode)); + $this->destination->element('cbc:DocumentTypeCode', $this->source->queryValue('.//ram:TypeCode', $additionalReferencedDocumentNode)); } ); - $this->out->element('cbc:DocumentDescription', $this->in->queryValue('.//ram:Name', $additionalReferencedDocumentNode)); - $this->in->whenExists( + $this->destination->element('cbc:DocumentDescription', $this->source->queryValue('.//ram:Name', $additionalReferencedDocumentNode)); + $this->source->whenExists( './/ram:AttachmentBinaryObject', $additionalReferencedDocumentNode, function ($attachmentBinaryObjectNode, $additionalReferencedDocumentNode) { - $this->out->startElement('cac:Attachment'); - $this->out->elementWithMultipleAttributes( + $this->destination->startElement('cac:Attachment'); + $this->destination->elementWithMultipleAttributes( 'cbc:EmbeddedDocumentBinaryObject', $attachmentBinaryObjectNode->nodeValue, [ @@ -373,19 +374,19 @@ function ($attachmentBinaryObjectNode, $additionalReferencedDocumentNode) { 'filename' => $attachmentBinaryObjectNode->getAttribute('filename'), ] ); - $this->in->whenExists( + $this->source->whenExists( './/ram:URIID', $additionalReferencedDocumentNode, function ($uriIdNode) { - $this->out->startElement('cac:ExternalReference'); - $this->out->element('cbc:URI', $uriIdNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:ExternalReference'); + $this->destination->element('cbc:URI', $uriIdNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -394,11 +395,11 @@ function ($uriIdNode) { //TODO: See Mapping lines 42..45 //TODO: See Mapping lines 47..51 - $this->in->queryValues('.//ram:SpecifiedProcuringProject/ram:ID', $invoiceHeaderAgreement)->forEach( + $this->source->queryValues('.//ram:SpecifiedProcuringProject/ram:ID', $invoiceHeaderAgreement)->forEach( function ($nodeFound) { - $this->out->startElement('cac:ProjectReference'); - $this->out->element('cbc:ID', $nodeFound->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:ProjectReference'); + $this->destination->element('cbc:ID', $nodeFound->nodeValue); + $this->destination->endElement(); } ); } @@ -410,160 +411,160 @@ function ($nodeFound) { */ private function convertSellerTradeParty(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $invoiceHeaderAgreement = $this->in->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceHeaderAgreement = $this->source->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:SellerTradeParty', $invoiceHeaderAgreement, function ($sellerTradePartyNode) use ($invoiceHeaderAgreement, $invoiceHeaderSettlement) { - $this->out->startElement('cac:AccountingSupplierParty'); - $this->out->startElement('cac:Party'); - $this->in->whenExists( + $this->destination->startElement('cac:AccountingSupplierParty'); + $this->destination->startElement('cac:Party'); + $this->source->whenExists( './/ram:URIUniversalCommunication/ram:URIID', $sellerTradePartyNode, function ($sellerTradePartyUniversalCommNode) { - $this->out->startElement('cbc:EndpointID', $sellerTradePartyUniversalCommNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('./@schemeID', $sellerTradePartyUniversalCommNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:EndpointID', $sellerTradePartyUniversalCommNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('./@schemeID', $sellerTradePartyUniversalCommNode)); + $this->destination->endElement(); } ); - $this->in->queryValues('./ram:ID', $sellerTradePartyNode)->forEach( + $this->source->queryValues('./ram:ID', $sellerTradePartyNode)->forEach( function ($sellerTradePartyIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $sellerTradePartyIdNode->nodeValue, 'schemeID', $sellerTradePartyIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $sellerTradePartyIdNode->nodeValue, 'schemeID', $sellerTradePartyIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:GlobalID', $sellerTradePartyNode, function ($sellerTradePartyGlobalIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $sellerTradePartyGlobalIdNode->nodeValue, 'schemeID', $sellerTradePartyGlobalIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $sellerTradePartyGlobalIdNode->nodeValue, 'schemeID', $sellerTradePartyGlobalIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:CreditorReferenceID', $invoiceHeaderSettlement, function ($DirectDebitMandateNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->startElement('cbc:ID', $DirectDebitMandateNode->nodeValue); - $this->out->attribute('schemeID', 'SEPA'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->startElement('cbc:ID', $DirectDebitMandateNode->nodeValue); + $this->destination->attribute('schemeID', 'SEPA'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:Name', $sellerTradePartyNode, function ($sellerTradePartyNameNode) { - $this->out->startElement('cac:PartyName'); - $this->out->element('cbc:Name', $sellerTradePartyNameNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:PartyName'); + $this->destination->element('cbc:Name', $sellerTradePartyNameNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:PostalTradeAddress', $sellerTradePartyNode, function ($sellerTradePartyPostalAddressNode) { - $this->out->startElement('cac:PostalAddress'); - $this->out->element('cbc:StreetName', $this->in->queryValue('.//ram:LineOne', $sellerTradePartyPostalAddressNode)); - $this->out->element('cbc:AdditionalStreetName', $this->in->queryValue('.//ram:LineTwo', $sellerTradePartyPostalAddressNode)); - $this->out->element('cbc:CityName', $this->in->queryValue('.//ram:CityName', $sellerTradePartyPostalAddressNode)); - $this->out->element('cbc:PostalZone', $this->in->queryValue('.//ram:PostcodeCode', $sellerTradePartyPostalAddressNode)); - $this->out->element('cbc:CountrySubentity', $this->in->queryValue('.//ram:CountrySubDivisionName', $sellerTradePartyPostalAddressNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PostalAddress'); + $this->destination->element('cbc:StreetName', $this->source->queryValue('.//ram:LineOne', $sellerTradePartyPostalAddressNode)); + $this->destination->element('cbc:AdditionalStreetName', $this->source->queryValue('.//ram:LineTwo', $sellerTradePartyPostalAddressNode)); + $this->destination->element('cbc:CityName', $this->source->queryValue('.//ram:CityName', $sellerTradePartyPostalAddressNode)); + $this->destination->element('cbc:PostalZone', $this->source->queryValue('.//ram:PostcodeCode', $sellerTradePartyPostalAddressNode)); + $this->destination->element('cbc:CountrySubentity', $this->source->queryValue('.//ram:CountrySubDivisionName', $sellerTradePartyPostalAddressNode)); + $this->source->whenExists( './/ram:LineThree', $sellerTradePartyPostalAddressNode, function ($sellerTradePartyPostalAddressNode) { - $this->out->startElement('cac:AddressLine'); - $this->out->element('cbc:Line', $sellerTradePartyPostalAddressNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:AddressLine'); + $this->destination->element('cbc:Line', $sellerTradePartyPostalAddressNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:CountryID', $sellerTradePartyPostalAddressNode, function ($sellerTradePartyPostalAddressCountryNode) { - $this->out->startElement('cac:Country'); - $this->out->element('cbc:IdentificationCode', $sellerTradePartyPostalAddressCountryNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:Country'); + $this->destination->element('cbc:IdentificationCode', $sellerTradePartyPostalAddressCountryNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'VA\']', $sellerTradePartyNode, function ($sellerTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'VAT'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'VAT'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'FC\']', $sellerTradePartyNode, function ($sellerTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'FC'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'FC'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLegalOrganization', $sellerTradePartyNode, function ($sellerTradePartyLegalOrgNode) use ($sellerTradePartyNode) { - $this->out->startElement('cac:PartyLegalEntity'); - $this->out->element('cbc:RegistrationName', $this->in->queryValue('.//ram:Name', $sellerTradePartyNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PartyLegalEntity'); + $this->destination->element('cbc:RegistrationName', $this->source->queryValue('.//ram:Name', $sellerTradePartyNode)); + $this->source->whenExists( './/ram:ID', $sellerTradePartyLegalOrgNode, function ($sellerTradePartyLegalOrgIdNode) { - $this->out->startElement('cbc:CompanyID', $sellerTradePartyLegalOrgIdNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('.//@schemeID', $sellerTradePartyLegalOrgIdNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:CompanyID', $sellerTradePartyLegalOrgIdNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('.//@schemeID', $sellerTradePartyLegalOrgIdNode)); + $this->destination->endElement(); } ); - $this->out->element('cbc:CompanyLegalForm', $this->in->queryValue('.//ram:Description', $sellerTradePartyNode)); - $this->out->endElement(); + $this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('.//ram:Description', $sellerTradePartyNode)); + $this->destination->endElement(); }, function () use ($sellerTradePartyNode) { - $this->in->whenExists( + $this->source->whenExists( './/ram:Name', $sellerTradePartyNode, function ($sellerTradePartyNameNode) { - $this->out->startElement('cac:PartyLegalEntity'); - $this->out->element('cbc:RegistrationName', $sellerTradePartyNameNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:PartyLegalEntity'); + $this->destination->element('cbc:RegistrationName', $sellerTradePartyNameNode->nodeValue); + $this->destination->endElement(); } ); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:DefinedTradeContact', $sellerTradePartyNode, function ($sellerTradePartyContactNode) { - $this->out->startElement('cac:Contact'); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:PersonName', $sellerTradePartyContactNode)); - $this->out->element('cbc:Telephone', $this->in->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $sellerTradePartyContactNode)); - $this->out->element('cbc:ElectronicMail', $this->in->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $sellerTradePartyContactNode)); - $this->out->endElement(); + $this->destination->startElement('cac:Contact'); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:PersonName', $sellerTradePartyContactNode)); + $this->destination->element('cbc:Telephone', $this->source->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $sellerTradePartyContactNode)); + $this->destination->element('cbc:ElectronicMail', $this->source->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $sellerTradePartyContactNode)); + $this->destination->endElement(); } ); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->endElement(); + $this->destination->endElement(); } ); } @@ -575,148 +576,148 @@ function ($sellerTradePartyContactNode) { */ private function convertBuyerTradeParty(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderAgreement = $this->in->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderAgreement = $this->source->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:BuyerTradeParty', $invoiceHeaderAgreement, function ($buyerTradePartyNode) use ($invoiceHeaderAgreement) { - $this->out->startElement('cac:AccountingCustomerParty'); - $this->out->startElement('cac:Party'); - $this->in->whenExists( + $this->destination->startElement('cac:AccountingCustomerParty'); + $this->destination->startElement('cac:Party'); + $this->source->whenExists( './/ram:URIUniversalCommunication/ram:URIID', $buyerTradePartyNode, function ($buyerTradePartyUniversalCommNode) { - $this->out->startElement('cbc:EndpointID', $buyerTradePartyUniversalCommNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('./@schemeID', $buyerTradePartyUniversalCommNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:EndpointID', $buyerTradePartyUniversalCommNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('./@schemeID', $buyerTradePartyUniversalCommNode)); + $this->destination->endElement(); } ); - $this->in->queryValues('./ram:ID', $buyerTradePartyNode)->forEach( + $this->source->queryValues('./ram:ID', $buyerTradePartyNode)->forEach( function ($buyerTradePartyIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $buyerTradePartyIdNode->nodeValue, 'schemeID', $buyerTradePartyIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $buyerTradePartyIdNode->nodeValue, 'schemeID', $buyerTradePartyIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:GlobalID', $buyerTradePartyNode, function ($buyerTradePartyGlobalIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $buyerTradePartyGlobalIdNode->nodeValue, 'schemeID', $buyerTradePartyGlobalIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $buyerTradePartyGlobalIdNode->nodeValue, 'schemeID', $buyerTradePartyGlobalIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:Name', $buyerTradePartyNode, function ($buyerTradePartyNameNode) { - $this->out->startElement('cac:PartyName'); - $this->out->element('cbc:Name', $buyerTradePartyNameNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:PartyName'); + $this->destination->element('cbc:Name', $buyerTradePartyNameNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:PostalTradeAddress', $buyerTradePartyNode, function ($buyerTradePartyPostalAddressNode) { - $this->out->startElement('cac:PostalAddress'); - $this->out->element('cbc:StreetName', $this->in->queryValue('.//ram:LineOne', $buyerTradePartyPostalAddressNode)); - $this->out->element('cbc:AdditionalStreetName', $this->in->queryValue('.//ram:LineTwo', $buyerTradePartyPostalAddressNode)); - $this->out->element('cbc:CityName', $this->in->queryValue('.//ram:CityName', $buyerTradePartyPostalAddressNode)); - $this->out->element('cbc:PostalZone', $this->in->queryValue('.//ram:PostcodeCode', $buyerTradePartyPostalAddressNode)); - $this->out->element('cbc:CountrySubentity', $this->in->queryValue('.//ram:CountrySubDivisionName', $buyerTradePartyPostalAddressNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PostalAddress'); + $this->destination->element('cbc:StreetName', $this->source->queryValue('.//ram:LineOne', $buyerTradePartyPostalAddressNode)); + $this->destination->element('cbc:AdditionalStreetName', $this->source->queryValue('.//ram:LineTwo', $buyerTradePartyPostalAddressNode)); + $this->destination->element('cbc:CityName', $this->source->queryValue('.//ram:CityName', $buyerTradePartyPostalAddressNode)); + $this->destination->element('cbc:PostalZone', $this->source->queryValue('.//ram:PostcodeCode', $buyerTradePartyPostalAddressNode)); + $this->destination->element('cbc:CountrySubentity', $this->source->queryValue('.//ram:CountrySubDivisionName', $buyerTradePartyPostalAddressNode)); + $this->source->whenExists( './/ram:LineThree', $buyerTradePartyPostalAddressNode, function ($buyerTradePartyPostalAddressNode) { - $this->out->startElement('cac:AddressLine'); - $this->out->element('cbc:Line', $buyerTradePartyPostalAddressNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:AddressLine'); + $this->destination->element('cbc:Line', $buyerTradePartyPostalAddressNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:CountryID', $buyerTradePartyPostalAddressNode, function ($buyerTradePartyPostalAddressCountryNode) { - $this->out->startElement('cac:Country'); - $this->out->element('cbc:IdentificationCode', $buyerTradePartyPostalAddressCountryNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:Country'); + $this->destination->element('cbc:IdentificationCode', $buyerTradePartyPostalAddressCountryNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'VA\']', $buyerTradePartyNode, function ($buyerTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $buyerTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'VAT'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $buyerTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'VAT'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'FC\']', $buyerTradePartyNode, function ($sellerTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'FC'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'FC'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLegalOrganization', $buyerTradePartyNode, function ($buyerTradePartyLegalOrgNode) use ($buyerTradePartyNode) { - $this->out->startElement('cac:PartyLegalEntity'); - $this->out->element('cbc:RegistrationName', $this->in->queryValue('.//ram:Name', $buyerTradePartyNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PartyLegalEntity'); + $this->destination->element('cbc:RegistrationName', $this->source->queryValue('.//ram:Name', $buyerTradePartyNode)); + $this->source->whenExists( './/ram:ID', $buyerTradePartyLegalOrgNode, function ($buyerTradePartyLegalOrgIdNode) { - $this->out->startElement('cbc:CompanyID', $buyerTradePartyLegalOrgIdNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('.//@schemeID', $buyerTradePartyLegalOrgIdNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:CompanyID', $buyerTradePartyLegalOrgIdNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('.//@schemeID', $buyerTradePartyLegalOrgIdNode)); + $this->destination->endElement(); } ); - $this->out->element('cbc:CompanyLegalForm', $this->in->queryValue('.//ram:Description', $buyerTradePartyNode)); - $this->out->endElement(); + $this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('.//ram:Description', $buyerTradePartyNode)); + $this->destination->endElement(); }, function () use ($buyerTradePartyNode) { - $this->in->whenExists( + $this->source->whenExists( './/ram:Name', $buyerTradePartyNode, function ($buyerTradePartyNameNode) { - $this->out->startElement('cac:PartyLegalEntity'); - $this->out->element('cbc:RegistrationName', $buyerTradePartyNameNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:PartyLegalEntity'); + $this->destination->element('cbc:RegistrationName', $buyerTradePartyNameNode->nodeValue); + $this->destination->endElement(); } ); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:DefinedTradeContact', $buyerTradePartyNode, function ($buyerTradePartyContactNode) { - $this->out->startElement('cac:Contact'); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:PersonName', $buyerTradePartyContactNode)); - $this->out->element('cbc:Telephone', $this->in->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $buyerTradePartyContactNode)); - $this->out->element('cbc:ElectronicMail', $this->in->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $buyerTradePartyContactNode)); - $this->out->endElement(); + $this->destination->startElement('cac:Contact'); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:PersonName', $buyerTradePartyContactNode)); + $this->destination->element('cbc:Telephone', $this->source->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $buyerTradePartyContactNode)); + $this->destination->element('cbc:ElectronicMail', $this->source->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $buyerTradePartyContactNode)); + $this->destination->endElement(); } ); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->endElement(); + $this->destination->endElement(); } ); } @@ -728,135 +729,135 @@ function ($buyerTradePartyContactNode) { */ private function convertPayeeTradeParty(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:PayeeTradeParty', $invoiceHeaderSettlement, function ($payeeTradePartyNode) { - $this->out->startElement('cac:PayeeParty'); - $this->in->whenExists( + $this->destination->startElement('cac:PayeeParty'); + $this->source->whenExists( './/ram:URIUniversalCommunication/ram:URIID', $payeeTradePartyNode, function ($payeeTradePartyUniversalCommNode) { - $this->out->startElement('cbc:EndpointID', $payeeTradePartyUniversalCommNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('./@schemeID', $payeeTradePartyUniversalCommNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:EndpointID', $payeeTradePartyUniversalCommNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('./@schemeID', $payeeTradePartyUniversalCommNode)); + $this->destination->endElement(); } ); - $this->in->queryValues('./ram:ID', $payeeTradePartyNode)->forEach( + $this->source->queryValues('./ram:ID', $payeeTradePartyNode)->forEach( function ($payeeTradePartyIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $payeeTradePartyIdNode->nodeValue, 'schemeID', $payeeTradePartyIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $payeeTradePartyIdNode->nodeValue, 'schemeID', $payeeTradePartyIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:GlobalID', $payeeTradePartyNode, function ($payeeTradePartyGlobalIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $payeeTradePartyGlobalIdNode->nodeValue, 'schemeID', $payeeTradePartyGlobalIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $payeeTradePartyGlobalIdNode->nodeValue, 'schemeID', $payeeTradePartyGlobalIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:Name', $payeeTradePartyNode, function ($payeeTradePartyNameNode) { - $this->out->startElement('cac:PartyName'); - $this->out->element('cbc:Name', $payeeTradePartyNameNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:PartyName'); + $this->destination->element('cbc:Name', $payeeTradePartyNameNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:PostalTradeAddress', $payeeTradePartyNode, function ($payeeTradePartyPostalAddressNode) { - $this->out->startElement('cac:PostalAddress'); - $this->out->element('cbc:StreetName', $this->in->queryValue('.//ram:LineOne', $payeeTradePartyPostalAddressNode)); - $this->out->element('cbc:AdditionalStreetName', $this->in->queryValue('.//ram:LineTwo', $payeeTradePartyPostalAddressNode)); - $this->out->element('cbc:CityName', $this->in->queryValue('.//ram:CityName', $payeeTradePartyPostalAddressNode)); - $this->out->element('cbc:PostalZone', $this->in->queryValue('.//ram:PostcodeCode', $payeeTradePartyPostalAddressNode)); - $this->out->element('cbc:CountrySubentity', $this->in->queryValue('.//ram:CountrySubDivisionName', $payeeTradePartyPostalAddressNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PostalAddress'); + $this->destination->element('cbc:StreetName', $this->source->queryValue('.//ram:LineOne', $payeeTradePartyPostalAddressNode)); + $this->destination->element('cbc:AdditionalStreetName', $this->source->queryValue('.//ram:LineTwo', $payeeTradePartyPostalAddressNode)); + $this->destination->element('cbc:CityName', $this->source->queryValue('.//ram:CityName', $payeeTradePartyPostalAddressNode)); + $this->destination->element('cbc:PostalZone', $this->source->queryValue('.//ram:PostcodeCode', $payeeTradePartyPostalAddressNode)); + $this->destination->element('cbc:CountrySubentity', $this->source->queryValue('.//ram:CountrySubDivisionName', $payeeTradePartyPostalAddressNode)); + $this->source->whenExists( './/ram:LineThree', $payeeTradePartyPostalAddressNode, function ($payeeTradePartyPostalAddressNode) { - $this->out->startElement('cac:AddressLine'); - $this->out->element('cbc:Line', $payeeTradePartyPostalAddressNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:AddressLine'); + $this->destination->element('cbc:Line', $payeeTradePartyPostalAddressNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:CountryID', $payeeTradePartyPostalAddressNode, function ($payeeTradePartyPostalAddressCountryNode) { - $this->out->startElement('cac:Country'); - $this->out->element('cbc:IdentificationCode', $payeeTradePartyPostalAddressCountryNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:Country'); + $this->destination->element('cbc:IdentificationCode', $payeeTradePartyPostalAddressCountryNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'VA\']', $payeeTradePartyNode, function ($payeeTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $payeeTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'VAT'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $payeeTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'VAT'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'FC\']', $payeeTradePartyNode, function ($sellerTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'FC'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'FC'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLegalOrganization', $payeeTradePartyNode, function ($payeeTradePartyLegalOrgNode) use ($payeeTradePartyNode) { - $this->out->startElement('cac:PartyLegalEntity'); - $this->out->element('cbc:RegistrationName', $this->in->queryValue('.//ram:Name', $payeeTradePartyNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PartyLegalEntity'); + $this->destination->element('cbc:RegistrationName', $this->source->queryValue('.//ram:Name', $payeeTradePartyNode)); + $this->source->whenExists( './/ram:ID', $payeeTradePartyLegalOrgNode, function ($payeeTradePartyLegalOrgIdNode) { - $this->out->startElement('cbc:CompanyID', $payeeTradePartyLegalOrgIdNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('.//@schemeID', $payeeTradePartyLegalOrgIdNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:CompanyID', $payeeTradePartyLegalOrgIdNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('.//@schemeID', $payeeTradePartyLegalOrgIdNode)); + $this->destination->endElement(); } ); - $this->out->element('cbc:CompanyLegalForm', $this->in->queryValue('.//ram:Description', $payeeTradePartyNode)); - $this->out->endElement(); + $this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('.//ram:Description', $payeeTradePartyNode)); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:DefinedTradeContact', $payeeTradePartyNode, function ($payeeTradePartyContactNode) { - $this->out->startElement('cac:Contact'); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:PersonName', $payeeTradePartyContactNode)); - $this->out->element('cbc:Telephone', $this->in->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $payeeTradePartyContactNode)); - $this->out->element('cbc:ElectronicMail', $this->in->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $payeeTradePartyContactNode)); - $this->out->endElement(); + $this->destination->startElement('cac:Contact'); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:PersonName', $payeeTradePartyContactNode)); + $this->destination->element('cbc:Telephone', $this->source->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $payeeTradePartyContactNode)); + $this->destination->element('cbc:ElectronicMail', $this->source->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $payeeTradePartyContactNode)); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -868,135 +869,135 @@ function ($payeeTradePartyContactNode) { */ private function convertTaxRepresentativeParty(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderAgreement = $this->in->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderAgreement = $this->source->query('//ram:ApplicableHeaderTradeAgreement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:SellerTaxRepresentativeTradeParty', $invoiceHeaderAgreement, function ($sellerTaxRepresentativePartyNode) { - $this->out->startElement('cac:TaxRepresentativeParty'); - $this->in->whenExists( + $this->destination->startElement('cac:TaxRepresentativeParty'); + $this->source->whenExists( './/ram:URIUniversalCommunication/ram:URIID', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyUniversalCommNode) { - $this->out->startElement('cbc:EndpointID', $sellerTaxRepresentativePartyUniversalCommNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('./@schemeID', $sellerTaxRepresentativePartyUniversalCommNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:EndpointID', $sellerTaxRepresentativePartyUniversalCommNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('./@schemeID', $sellerTaxRepresentativePartyUniversalCommNode)); + $this->destination->endElement(); } ); - $this->in->queryValues('./ram:ID', $sellerTaxRepresentativePartyNode)->forEach( + $this->source->queryValues('./ram:ID', $sellerTaxRepresentativePartyNode)->forEach( function ($sellerTaxRepresentativePartyIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $sellerTaxRepresentativePartyIdNode->nodeValue, 'schemeID', $sellerTaxRepresentativePartyIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $sellerTaxRepresentativePartyIdNode->nodeValue, 'schemeID', $sellerTaxRepresentativePartyIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:GlobalID', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyGlobalIdNode) { - $this->out->startElement('cac:PartyIdentification'); - $this->out->elementWithAttribute('cbc:ID', $sellerTaxRepresentativePartyGlobalIdNode->nodeValue, 'schemeID', $sellerTaxRepresentativePartyGlobalIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:PartyIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $sellerTaxRepresentativePartyGlobalIdNode->nodeValue, 'schemeID', $sellerTaxRepresentativePartyGlobalIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:Name', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyNameNode) { - $this->out->startElement('cac:PartyName'); - $this->out->element('cbc:Name', $sellerTaxRepresentativePartyNameNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:PartyName'); + $this->destination->element('cbc:Name', $sellerTaxRepresentativePartyNameNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:PostalTradeAddress', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyPostalAddressNode) { - $this->out->startElement('cac:PostalAddress'); - $this->out->element('cbc:StreetName', $this->in->queryValue('.//ram:LineOne', $sellerTaxRepresentativePartyPostalAddressNode)); - $this->out->element('cbc:AdditionalStreetName', $this->in->queryValue('.//ram:LineTwo', $sellerTaxRepresentativePartyPostalAddressNode)); - $this->out->element('cbc:CityName', $this->in->queryValue('.//ram:CityName', $sellerTaxRepresentativePartyPostalAddressNode)); - $this->out->element('cbc:PostalZone', $this->in->queryValue('.//ram:PostcodeCode', $sellerTaxRepresentativePartyPostalAddressNode)); - $this->out->element('cbc:CountrySubentity', $this->in->queryValue('.//ram:CountrySubDivisionName', $sellerTaxRepresentativePartyPostalAddressNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PostalAddress'); + $this->destination->element('cbc:StreetName', $this->source->queryValue('.//ram:LineOne', $sellerTaxRepresentativePartyPostalAddressNode)); + $this->destination->element('cbc:AdditionalStreetName', $this->source->queryValue('.//ram:LineTwo', $sellerTaxRepresentativePartyPostalAddressNode)); + $this->destination->element('cbc:CityName', $this->source->queryValue('.//ram:CityName', $sellerTaxRepresentativePartyPostalAddressNode)); + $this->destination->element('cbc:PostalZone', $this->source->queryValue('.//ram:PostcodeCode', $sellerTaxRepresentativePartyPostalAddressNode)); + $this->destination->element('cbc:CountrySubentity', $this->source->queryValue('.//ram:CountrySubDivisionName', $sellerTaxRepresentativePartyPostalAddressNode)); + $this->source->whenExists( './/ram:LineThree', $sellerTaxRepresentativePartyPostalAddressNode, function ($sellerTaxRepresentativePartyPostalAddressNode) { - $this->out->startElement('cac:AddressLine'); - $this->out->element('cbc:Line', $sellerTaxRepresentativePartyPostalAddressNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:AddressLine'); + $this->destination->element('cbc:Line', $sellerTaxRepresentativePartyPostalAddressNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:CountryID', $sellerTaxRepresentativePartyPostalAddressNode, function ($sellerTaxRepresentativePartyPostalAddressCountryNode) { - $this->out->startElement('cac:Country'); - $this->out->element('cbc:IdentificationCode', $sellerTaxRepresentativePartyPostalAddressCountryNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:Country'); + $this->destination->element('cbc:IdentificationCode', $sellerTaxRepresentativePartyPostalAddressCountryNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'VA\']', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $sellerTaxRepresentativePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'VAT'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $sellerTaxRepresentativePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'VAT'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTaxRegistration/ram:ID[@schemeID=\'FC\']', $sellerTaxRepresentativePartyNode, function ($sellerTradePartyTaxRegNode) { - $this->out->startElement('cac:PartyTaxScheme'); - $this->out->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', 'FC'); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:PartyTaxScheme'); + $this->destination->element('cbc:CompanyID', $sellerTradePartyTaxRegNode->nodeValue); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', 'FC'); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLegalOrganization', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyLegalOrgNode) use ($sellerTaxRepresentativePartyNode) { - $this->out->startElement('cac:PartyLegalEntity'); - $this->out->element('cbc:RegistrationName', $this->in->queryValue('.//ram:Name', $sellerTaxRepresentativePartyNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PartyLegalEntity'); + $this->destination->element('cbc:RegistrationName', $this->source->queryValue('.//ram:Name', $sellerTaxRepresentativePartyNode)); + $this->source->whenExists( './/ram:ID', $sellerTaxRepresentativePartyLegalOrgNode, function ($sellerTaxRepresentativePartyLegalOrgIdNode) { - $this->out->startElement('cbc:CompanyID', $sellerTaxRepresentativePartyLegalOrgIdNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('.//@schemeID', $sellerTaxRepresentativePartyLegalOrgIdNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:CompanyID', $sellerTaxRepresentativePartyLegalOrgIdNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('.//@schemeID', $sellerTaxRepresentativePartyLegalOrgIdNode)); + $this->destination->endElement(); } ); - $this->out->element('cbc:CompanyLegalForm', $this->in->queryValue('.//ram:Description', $sellerTaxRepresentativePartyNode)); - $this->out->endElement(); + $this->destination->element('cbc:CompanyLegalForm', $this->source->queryValue('.//ram:Description', $sellerTaxRepresentativePartyNode)); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:DefinedTradeContact', $sellerTaxRepresentativePartyNode, function ($sellerTaxRepresentativePartyContactNode) { - $this->out->startElement('cac:Contact'); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:PersonName', $sellerTaxRepresentativePartyContactNode)); - $this->out->element('cbc:Telephone', $this->in->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $sellerTaxRepresentativePartyContactNode)); - $this->out->element('cbc:ElectronicMail', $this->in->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $sellerTaxRepresentativePartyContactNode)); - $this->out->endElement(); + $this->destination->startElement('cac:Contact'); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:PersonName', $sellerTaxRepresentativePartyContactNode)); + $this->destination->element('cbc:Telephone', $this->source->queryValue('.//ram:TelephoneUniversalCommunication/ram:CompleteNumber', $sellerTaxRepresentativePartyContactNode)); + $this->destination->element('cbc:ElectronicMail', $this->source->queryValue('.//ram:EmailURIUniversalCommunication/ram:URIID', $sellerTaxRepresentativePartyContactNode)); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -1008,91 +1009,91 @@ function ($sellerTaxRepresentativePartyContactNode) { */ private function convertShipToTradeParty(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderDelivery = $this->in->query('//ram:ApplicableHeaderTradeDelivery', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderDelivery = $this->source->query('//ram:ApplicableHeaderTradeDelivery', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:ShipToTradeParty', $invoiceHeaderDelivery, function ($shipToTradePartyNode) use ($invoiceHeaderDelivery) { - $this->out->startElement('cac:Delivery'); - $this->out->element( + $this->destination->startElement('cac:Delivery'); + $this->destination->element( 'cbc:ActualDeliveryDate', $this->convertDateTime( - $this->in->queryValue('.//ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString', $invoiceHeaderDelivery), - $this->in->queryValue('.//ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString/@format', $invoiceHeaderDelivery) + $this->source->queryValue('.//ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString', $invoiceHeaderDelivery), + $this->source->queryValue('.//ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString/@format', $invoiceHeaderDelivery) ) ); - $this->out->startElement('cac:DeliveryLocation'); - $this->in->whenExists( + $this->destination->startElement('cac:DeliveryLocation'); + $this->source->whenExists( './/ram:ID', $shipToTradePartyNode, function ($shipToTradePartyIdNode) use ($invoiceHeaderDelivery) { - $this->out->startElement('cbc:ID', $shipToTradePartyIdNode->nodeValue); - $this->out->attribute('schemeID', $this->in->queryValue('.//ram:ShipToTradeParty/ram:GlobalID/@schemeID', $invoiceHeaderDelivery)); - $this->out->endElement(); + $this->destination->startElement('cbc:ID', $shipToTradePartyIdNode->nodeValue); + $this->destination->attribute('schemeID', $this->source->queryValue('.//ram:ShipToTradeParty/ram:GlobalID/@schemeID', $invoiceHeaderDelivery)); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:PostalTradeAddress', $shipToTradePartyNode, function ($shipToTradePartyPostalAddressNode) { - $this->out->startElement('cac:Address'); - $this->out->element('cbc:StreetName', $this->in->queryValue('.//ram:LineOne', $shipToTradePartyPostalAddressNode)); - $this->out->element('cbc:AdditionalStreetName', $this->in->queryValue('.//ram:LineTwo', $shipToTradePartyPostalAddressNode)); - $this->in->whenExists( + $this->destination->startElement('cac:Address'); + $this->destination->element('cbc:StreetName', $this->source->queryValue('.//ram:LineOne', $shipToTradePartyPostalAddressNode)); + $this->destination->element('cbc:AdditionalStreetName', $this->source->queryValue('.//ram:LineTwo', $shipToTradePartyPostalAddressNode)); + $this->source->whenExists( './/ram:LineThree', $shipToTradePartyPostalAddressNode, function ($shipToTradePartyPostalAddressNode) { - $this->out->startElement('cac:AddressLine'); - $this->out->element('cbc:Line', $shipToTradePartyPostalAddressNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:AddressLine'); + $this->destination->element('cbc:Line', $shipToTradePartyPostalAddressNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->element('cbc:CityName', $this->in->queryValue('.//ram:CityName', $shipToTradePartyPostalAddressNode)); - $this->out->element('cbc:PostalZone', $this->in->queryValue('.//ram:PostcodeCode', $shipToTradePartyPostalAddressNode)); - $this->out->element('cbc:CountrySubentity', $this->in->queryValue('.//ram:CountrySubDivisionName', $shipToTradePartyPostalAddressNode)); - $this->in->whenExists( + $this->destination->element('cbc:CityName', $this->source->queryValue('.//ram:CityName', $shipToTradePartyPostalAddressNode)); + $this->destination->element('cbc:PostalZone', $this->source->queryValue('.//ram:PostcodeCode', $shipToTradePartyPostalAddressNode)); + $this->destination->element('cbc:CountrySubentity', $this->source->queryValue('.//ram:CountrySubDivisionName', $shipToTradePartyPostalAddressNode)); + $this->source->whenExists( './/ram:CountryID', $shipToTradePartyPostalAddressNode, function ($shipToTradePartyPostalAddressCountryNode) { - $this->out->startElement('cac:Country'); - $this->out->element('cbc:IdentificationCode', $shipToTradePartyPostalAddressCountryNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:Country'); + $this->destination->element('cbc:IdentificationCode', $shipToTradePartyPostalAddressCountryNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); - $this->in->whenExists( + $this->destination->endElement(); + $this->source->whenExists( './/ram:Name', $shipToTradePartyNode, function ($shipToTradePartyNameNode) { - $this->out->startElement('cac:DeliveryParty'); - $this->out->startElement('cac:PartyName'); - $this->out->element('cbc:Name', $shipToTradePartyNameNode->nodeValue); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:DeliveryParty'); + $this->destination->startElement('cac:PartyName'); + $this->destination->element('cbc:Name', $shipToTradePartyNameNode->nodeValue); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); }, function () use ($invoiceHeaderDelivery) { - $this->in->whenExists( + $this->source->whenExists( './/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString', $invoiceHeaderDelivery, function ($actualDeliverySupplyChainEventNode) { - $this->out->startElement('cac:Delivery'); - $this->out->element( + $this->destination->startElement('cac:Delivery'); + $this->destination->element( 'cbc:ActualDeliveryDate', $this->convertDateTime( $actualDeliverySupplyChainEventNode->nodeValue, $actualDeliverySupplyChainEventNode->getAttribute('format') ) ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -1106,73 +1107,73 @@ function ($actualDeliverySupplyChainEventNode) { */ private function convertPaymentMeans(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTradeSettlementPaymentMeans', $invoiceHeaderSettlement, function ($peymentMeansNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:PaymentMeans'); - $this->in->whenExists( + $this->destination->startElement('cac:PaymentMeans'); + $this->source->whenExists( './/ram:TypeCode', $peymentMeansNode, function ($paymentMeansTypeCodeNode) use ($peymentMeansNode) { - $this->out->startElement('cbc:PaymentMeansCode', $paymentMeansTypeCodeNode->nodeValue); - $this->out->attribute('name', $this->in->queryValue('.//ram:Information', $peymentMeansNode)); - $this->out->endElement(); + $this->destination->startElement('cbc:PaymentMeansCode', $paymentMeansTypeCodeNode->nodeValue); + $this->destination->attribute('name', $this->source->queryValue('.//ram:Information', $peymentMeansNode)); + $this->destination->endElement(); } ); - $this->out->element('cbc:PaymentID', $this->in->queryValue('.//ram:PaymentReference', $invoiceHeaderSettlement)); - $this->in->whenExists( + $this->destination->element('cbc:PaymentID', $this->source->queryValue('.//ram:PaymentReference', $invoiceHeaderSettlement)); + $this->source->whenExists( './/ram:ApplicableTradeSettlementFinancialCard', $peymentMeansNode, function ($paymentMeansFinancialCardNode) { - $this->out->startElement('cac:CardAccount'); - $this->out->element('cbc:PrimaryAccountNumberID', $this->in->queryValue('.//ram:ID', $paymentMeansFinancialCardNode)); - $this->out->element('cbc:HolderName', $this->in->queryValue('.//ram:CardholderName', $paymentMeansFinancialCardNode)); - $this->out->endElement(); + $this->destination->startElement('cac:CardAccount'); + $this->destination->element('cbc:PrimaryAccountNumberID', $this->source->queryValue('.//ram:ID', $paymentMeansFinancialCardNode)); + $this->destination->element('cbc:HolderName', $this->source->queryValue('.//ram:CardholderName', $paymentMeansFinancialCardNode)); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:PayeePartyCreditorFinancialAccount', $peymentMeansNode, function ($paymentMeansCreditorFinancialAccountNode) use ($peymentMeansNode) { - $this->out->startElement('cac:PayeeFinancialAccount'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:IBANID', $paymentMeansCreditorFinancialAccountNode)); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:AccountName', $paymentMeansCreditorFinancialAccountNode)); - $this->in->whenExists( + $this->destination->startElement('cac:PayeeFinancialAccount'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:IBANID', $paymentMeansCreditorFinancialAccountNode)); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:AccountName', $paymentMeansCreditorFinancialAccountNode)); + $this->source->whenExists( './/ram:PayeeSpecifiedCreditorFinancialInstitution', $peymentMeansNode, function ($paymentMeansCreditorFinancialInstNode) { - $this->out->startElement('cac:FinancialInstitutionBranch'); - $this->out->element('cbc:ID', $paymentMeansCreditorFinancialInstNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:FinancialInstitutionBranch'); + $this->destination->element('cbc:ID', $paymentMeansCreditorFinancialInstNode->nodeValue); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTradePaymentTerms/ram:DirectDebitMandateID', $invoiceHeaderSettlement, function ($DirectDebitMandateNode) use ($invoiceHeaderSettlement, $peymentMeansNode) { - $this->out->startElement('cac:PaymentMandate'); - $this->out->element('cbc:ID', $DirectDebitMandateNode->nodeValue); - $this->in->whenExists( + $this->destination->startElement('cac:PaymentMandate'); + $this->destination->element('cbc:ID', $DirectDebitMandateNode->nodeValue); + $this->source->whenExists( './/ram:PayerPartyDebtorFinancialAccount', $peymentMeansNode, function ($paymentMeansDebtorFinancialAccountNode) { - $this->out->startElement('cac:PayerFinancialAccount'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:IBANID', $paymentMeansDebtorFinancialAccountNode)); - $this->out->endElement(); + $this->destination->startElement('cac:PayerFinancialAccount'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:IBANID', $paymentMeansDebtorFinancialAccountNode)); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -1184,17 +1185,17 @@ function ($paymentMeansDebtorFinancialAccountNode) { */ private function convertPaymentTerms(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTradePaymentTerms', $invoiceHeaderSettlement, function ($peymentTermsNode) { - $this->out->startElement('cac:PaymentTerms'); - $this->out->element('cbc:Note', $this->in->queryValue('.//ram:Description', $peymentTermsNode)); - $this->out->endElement(); + $this->destination->startElement('cac:PaymentTerms'); + $this->destination->element('cbc:Note', $this->source->queryValue('.//ram:Description', $peymentTermsNode)); + $this->destination->endElement(); } ); } @@ -1206,33 +1207,33 @@ function ($peymentTermsNode) { */ private function convertDocumentLevelAllowanceCharge(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->queryValues('.//ram:SpecifiedTradeAllowanceCharge', $invoiceHeaderSettlement)->forEach( + $this->source->queryValues('.//ram:SpecifiedTradeAllowanceCharge', $invoiceHeaderSettlement)->forEach( function ($tradeAllowanceChargeNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:AllowanceCharge'); - $this->out->element('cbc:ChargeIndicator', $this->in->queryValue('.//ram:ChargeIndicator/udt:Indicator', $tradeAllowanceChargeNode)); - $this->out->element('cbc:AllowanceChargeReasonCode', $this->in->queryValue('.//ram:ReasonCode', $tradeAllowanceChargeNode)); - $this->out->element('cbc:AllowanceChargeReason', $this->in->queryValue('.//ram:Reason', $tradeAllowanceChargeNode)); - $this->out->element('cbc:MultiplierFactorNumeric', $this->in->queryValue('.//ram:CalculationPercent', $tradeAllowanceChargeNode)); - $this->out->elementWithAttribute('cbc:Amount', $this->formatAmount($this->in->queryValue('.//ram:ActualAmount', $tradeAllowanceChargeNode)), 'currencyID', $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); - $this->out->elementWithAttribute('cbc:BaseAmount', $this->formatAmount($this->in->queryValue('.//ram:BasisAmount', $tradeAllowanceChargeNode)), 'currencyID', $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); - $this->in->whenExists( + $this->destination->startElement('cac:AllowanceCharge'); + $this->destination->element('cbc:ChargeIndicator', $this->source->queryValue('.//ram:ChargeIndicator/udt:Indicator', $tradeAllowanceChargeNode)); + $this->destination->element('cbc:AllowanceChargeReasonCode', $this->source->queryValue('.//ram:ReasonCode', $tradeAllowanceChargeNode)); + $this->destination->element('cbc:AllowanceChargeReason', $this->source->queryValue('.//ram:Reason', $tradeAllowanceChargeNode)); + $this->destination->element('cbc:MultiplierFactorNumeric', $this->source->queryValue('.//ram:CalculationPercent', $tradeAllowanceChargeNode)); + $this->destination->elementWithAttribute('cbc:Amount', $this->formatAmount($this->source->queryValue('.//ram:ActualAmount', $tradeAllowanceChargeNode)), 'currencyID', $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); + $this->destination->elementWithAttribute('cbc:BaseAmount', $this->formatAmount($this->source->queryValue('.//ram:BasisAmount', $tradeAllowanceChargeNode)), 'currencyID', $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); + $this->source->whenExists( './/ram:CategoryTradeTax', $tradeAllowanceChargeNode, function ($tradeAllowanceChargeTaxNode) { - $this->out->startElement('cac:TaxCategory'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:CategoryCode', $tradeAllowanceChargeTaxNode)); - $this->out->element('cbc:Percent', $this->in->queryValue('.//ram:RateApplicablePercent', $tradeAllowanceChargeTaxNode)); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:TypeCode', $tradeAllowanceChargeTaxNode)); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:TaxCategory'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:CategoryCode', $tradeAllowanceChargeTaxNode)); + $this->destination->element('cbc:Percent', $this->source->queryValue('.//ram:RateApplicablePercent', $tradeAllowanceChargeTaxNode)); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:TypeCode', $tradeAllowanceChargeTaxNode)); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -1244,23 +1245,23 @@ function ($tradeAllowanceChargeTaxNode) { */ private function convertDocumentLevelTax(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $invoiceCurrencyCode = $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement); - $taxCurrencyCode = $this->in->queryValue('.//ram:TaxCurrencyCode', $invoiceHeaderSettlement); + $invoiceCurrencyCode = $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement); + $taxCurrencyCode = $this->source->queryValue('.//ram:TaxCurrencyCode', $invoiceHeaderSettlement); - $this->in->whenExists( + $this->source->whenExists( './/ram:ApplicableTradeTax', $invoiceHeaderSettlement, function () use ($invoiceHeaderSettlement, $invoiceCurrencyCode, $taxCurrencyCode) { - $this->out->startElement('cac:TaxTotal'); - $this->in->whenExists( + $this->destination->startElement('cac:TaxTotal'); + $this->source->whenExists( sprintf('.//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount[@currencyID=\'%s\']', $invoiceCurrencyCode), $invoiceHeaderSettlement, function ($taxTotalAmountNode) { - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:TaxAmount', $this->formatAmount($taxTotalAmountNode->nodeValue), 'currencyID', @@ -1268,48 +1269,48 @@ function ($taxTotalAmountNode) { ); } ); - $this->in->queryValues('.//ram:ApplicableTradeTax', $invoiceHeaderSettlement)->forEach( + $this->source->queryValues('.//ram:ApplicableTradeTax', $invoiceHeaderSettlement)->forEach( function ($tradeTaxNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:TaxSubtotal'); - $this->out->elementWithAttribute( + $this->destination->startElement('cac:TaxSubtotal'); + $this->destination->elementWithAttribute( 'cbc:TaxableAmount', - $this->formatAmount($this->in->queryValue('.//ram:BasisAmount', $tradeTaxNode)), + $this->formatAmount($this->source->queryValue('.//ram:BasisAmount', $tradeTaxNode)), 'currencyID', - $this->in->queryValue('.//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount/@currencyID', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount/@currencyID', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:TaxAmount', - $this->formatAmount($this->in->queryValue('.//ram:CalculatedAmount', $tradeTaxNode)), + $this->formatAmount($this->source->queryValue('.//ram:CalculatedAmount', $tradeTaxNode)), 'currencyID', - $this->in->queryValue('.//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount/@currencyID', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount/@currencyID', $invoiceHeaderSettlement) ); - $this->out->startElement('cac:TaxCategory'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:CategoryCode', $tradeTaxNode)); - $this->out->element('cbc:Percent', $this->in->queryValue('.//ram:RateApplicablePercent', $tradeTaxNode)); - $this->out->element('cbc:TaxExemptionReasonCode', $this->in->queryValue('.//ram:ExemptionReasonCode', $tradeTaxNode)); - $this->out->element('cbc:TaxExemptionReason', $this->in->queryValue('.//ram:ExemptionReason', $tradeTaxNode)); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:TypeCode', $tradeTaxNode)); - $this->out->endElement(); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:TaxCategory'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:CategoryCode', $tradeTaxNode)); + $this->destination->element('cbc:Percent', $this->source->queryValue('.//ram:RateApplicablePercent', $tradeTaxNode)); + $this->destination->element('cbc:TaxExemptionReasonCode', $this->source->queryValue('.//ram:ExemptionReasonCode', $tradeTaxNode)); + $this->destination->element('cbc:TaxExemptionReason', $this->source->queryValue('.//ram:ExemptionReason', $tradeTaxNode)); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:TypeCode', $tradeTaxNode)); + $this->destination->endElement(); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); if ($invoiceCurrencyCode && $taxCurrencyCode && ($invoiceCurrencyCode != $taxCurrencyCode)) { - $this->in->whenExists( + $this->source->whenExists( sprintf('.//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount[@currencyID=\'%s\']', $taxCurrencyCode), $invoiceHeaderSettlement, function ($taxTotalAmountNode) { - $this->out->startElement('cac:TaxTotal'); - $this->out->elementWithAttribute( + $this->destination->startElement('cac:TaxTotal'); + $this->destination->elementWithAttribute( 'cbc:TaxAmount', $this->formatAmount($taxTotalAmountNode->nodeValue), 'currencyID', $taxTotalAmountNode->getAttribute('currencyID') ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -1324,64 +1325,64 @@ function ($taxTotalAmountNode) { */ private function convertDocumentSummation(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTradeSettlementHeaderMonetarySummation', $invoiceHeaderSettlement, function ($monetarySummationNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:LegalMonetaryTotal'); - $this->out->elementWithAttribute( + $this->destination->startElement('cac:LegalMonetaryTotal'); + $this->destination->elementWithAttribute( 'cbc:LineExtensionAmount', - $this->formatAmount($this->in->queryValue('.//ram:LineTotalAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:LineTotalAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:TaxExclusiveAmount', - $this->formatAmount($this->in->queryValue('.//ram:TaxBasisTotalAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:TaxBasisTotalAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:TaxInclusiveAmount', - $this->formatAmount($this->in->queryValue('.//ram:GrandTotalAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:GrandTotalAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:AllowanceTotalAmount', - $this->formatAmount($this->in->queryValue('.//ram:AllowanceTotalAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:AllowanceTotalAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:ChargeTotalAmount', - $this->formatAmount($this->in->queryValue('.//ram:ChargeTotalAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:ChargeTotalAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:PrepaidAmount', - $this->formatAmount($this->in->queryValue('.//ram:TotalPrepaidAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:TotalPrepaidAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:PayableRoundingAmount', - $this->formatAmount($this->in->queryValue('.//ram:RoundingAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:RoundingAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:PayableAmount', - $this->formatAmount($this->in->queryValue('.//ram:DuePayableAmount', $monetarySummationNode)), + $this->formatAmount($this->source->queryValue('.//ram:DuePayableAmount', $monetarySummationNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->endElement(); + $this->destination->endElement(); } ); } @@ -1393,202 +1394,202 @@ function ($monetarySummationNode) use ($invoiceHeaderSettlement) { */ private function convertLines(): void { - $invoiceElement = $this->in->query('//rsm:CrossIndustryInvoice')->item(0); - $invoiceSuppyChainTradeTransaction = $this->in->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); - $invoiceHeaderSettlement = $this->in->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); + $invoiceElement = $this->source->query('//rsm:CrossIndustryInvoice')->item(0); + $invoiceSuppyChainTradeTransaction = $this->source->query('//rsm:SupplyChainTradeTransaction', $invoiceElement)->item(0); + $invoiceHeaderSettlement = $this->source->query('//ram:ApplicableHeaderTradeSettlement', $invoiceSuppyChainTradeTransaction)->item(0); - $this->in->whenExists( + $this->source->whenExists( './/ram:IncludedSupplyChainTradeLineItem', $invoiceSuppyChainTradeTransaction, function () use ($invoiceSuppyChainTradeTransaction, $invoiceHeaderSettlement) { - $this->in->queryValues( + $this->source->queryValues( './/ram:IncludedSupplyChainTradeLineItem', $invoiceSuppyChainTradeTransaction )->forEach( function ($tradeLineItemNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:InvoiceLine'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:AssociatedDocumentLineDocument/ram:LineID', $tradeLineItemNode)); - $this->out->element('cbc:Note', $this->in->queryValue('.//ram:AssociatedDocumentLineDocument/ram:IncludedNote/ram:Content', $tradeLineItemNode)); - $this->out->elementWithAttribute( + $this->destination->startElement('cac:InvoiceLine'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:AssociatedDocumentLineDocument/ram:LineID', $tradeLineItemNode)); + $this->destination->element('cbc:Note', $this->source->queryValue('.//ram:AssociatedDocumentLineDocument/ram:IncludedNote/ram:Content', $tradeLineItemNode)); + $this->destination->elementWithAttribute( 'cbc:InvoicedQuantity', - $this->in->queryValue('.//ram:SpecifiedLineTradeDelivery/ram:BilledQuantity', $tradeLineItemNode), + $this->source->queryValue('.//ram:SpecifiedLineTradeDelivery/ram:BilledQuantity', $tradeLineItemNode), 'unitCode', - $this->in->queryValue('.//ram:SpecifiedLineTradeDelivery/ram:BilledQuantity/@unitCode', $tradeLineItemNode) + $this->source->queryValue('.//ram:SpecifiedLineTradeDelivery/ram:BilledQuantity/@unitCode', $tradeLineItemNode) ); - $this->out->elementWithAttribute( + $this->destination->elementWithAttribute( 'cbc:LineExtensionAmount', - $this->formatAmount($this->in->queryValue('.//ram:LineTotalAmount', $tradeLineItemNode)), + $this->formatAmount($this->source->queryValue('.//ram:LineTotalAmount', $tradeLineItemNode)), 'currencyID', - $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) + $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement) ); - $this->out->element('cbc:AccountingCost', $this->in->queryValue('.//ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', $tradeLineItemNode)); - $this->in->whenExists( + $this->destination->element('cbc:AccountingCost', $this->source->queryValue('.//ram:SpecifiedLineTradeSettlement/ram:ReceivableSpecifiedTradeAccountingAccount/ram:ID', $tradeLineItemNode)); + $this->source->whenExists( './/ram:SpecifiedLineTradeSettlement/ram:BillingSpecifiedPeriod', $tradeLineItemNode, function ($billingSpecifiedPeriodNode) { - $this->out->startElement('cac:InvoicePeriod'); - $this->out->element( + $this->destination->startElement('cac:InvoicePeriod'); + $this->destination->element( 'cbc:StartDate', $this->convertDateTime( - $this->in->queryValue('.//ram:StartDateTime/udt:DateTimeString', $billingSpecifiedPeriodNode), - $this->in->queryValue('.//ram:StartDateTime/udt:DateTimeString/@format', $billingSpecifiedPeriodNode) + $this->source->queryValue('.//ram:StartDateTime/udt:DateTimeString', $billingSpecifiedPeriodNode), + $this->source->queryValue('.//ram:StartDateTime/udt:DateTimeString/@format', $billingSpecifiedPeriodNode) ) ); - $this->out->element( + $this->destination->element( 'cbc:EndDate', $this->convertDateTime( - $this->in->queryValue('.//ram:EndDateTime/udt:DateTimeString', $billingSpecifiedPeriodNode), - $this->in->queryValue('.//ram:EndDateTime/udt:DateTimeString/@format', $billingSpecifiedPeriodNode) + $this->source->queryValue('.//ram:EndDateTime/udt:DateTimeString', $billingSpecifiedPeriodNode), + $this->source->queryValue('.//ram:EndDateTime/udt:DateTimeString/@format', $billingSpecifiedPeriodNode) ) ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLineTradeAgreement/ram:BuyerOrderReferencedDocument/ram:LineID', $tradeLineItemNode, function ($buyerOrderReferencedDocumentNode) { - $this->out->startElement('cac:OrderLineReference'); - $this->out->element('cbc:LineID', $buyerOrderReferencedDocumentNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:OrderLineReference'); + $this->destination->element('cbc:LineID', $buyerOrderReferencedDocumentNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLineTradeSettlement/ram:AdditionalReferencedDocument/ram:IssuerAssignedID', $tradeLineItemNode, function ($additionalReferencedDocumentNode) { - $this->out->startElement('cac:DocumentReference'); - $this->out->element('cbc:ID', $additionalReferencedDocumentNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:DocumentReference'); + $this->destination->element('cbc:ID', $additionalReferencedDocumentNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->queryValues('.//ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeAllowanceCharge', $tradeLineItemNode)->forEach( + $this->source->queryValues('.//ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeAllowanceCharge', $tradeLineItemNode)->forEach( function ($tradeLineItemAllowanceChargeNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:AllowanceCharge'); - $this->out->element('cbc:ChargeIndicator', $this->in->queryValue('.//ram:ChargeIndicator/udt:Indicator', $tradeLineItemAllowanceChargeNode)); - $this->out->element('cbc:AllowanceChargeReasonCode', $this->in->queryValue('.//ram:ReasonCode', $tradeLineItemAllowanceChargeNode)); - $this->out->element('cbc:AllowanceChargeReason', $this->in->queryValue('.//ram:Reason', $tradeLineItemAllowanceChargeNode)); - $this->out->element('cbc:MultiplierFactorNumeric', $this->in->queryValue('.//ram:CalculationPercent', $tradeLineItemAllowanceChargeNode)); - $this->out->element('cbc:Amount', $this->in->queryValue('.//ram:ActualAmount', $tradeLineItemAllowanceChargeNode)); - $this->out->elementWithAttribute('cbc:Amount', $this->formatAmount($this->in->queryValue('.//ram:ActualAmount', $tradeLineItemAllowanceChargeNode)), 'currencyID', $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); - $this->out->elementWithAttribute('cbc:BaseAmount', $this->formatAmount($this->in->queryValue('.//ram:BasisAmount', $tradeLineItemAllowanceChargeNode)), 'currencyID', $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); - $this->in->whenExists( + $this->destination->startElement('cac:AllowanceCharge'); + $this->destination->element('cbc:ChargeIndicator', $this->source->queryValue('.//ram:ChargeIndicator/udt:Indicator', $tradeLineItemAllowanceChargeNode)); + $this->destination->element('cbc:AllowanceChargeReasonCode', $this->source->queryValue('.//ram:ReasonCode', $tradeLineItemAllowanceChargeNode)); + $this->destination->element('cbc:AllowanceChargeReason', $this->source->queryValue('.//ram:Reason', $tradeLineItemAllowanceChargeNode)); + $this->destination->element('cbc:MultiplierFactorNumeric', $this->source->queryValue('.//ram:CalculationPercent', $tradeLineItemAllowanceChargeNode)); + $this->destination->element('cbc:Amount', $this->source->queryValue('.//ram:ActualAmount', $tradeLineItemAllowanceChargeNode)); + $this->destination->elementWithAttribute('cbc:Amount', $this->formatAmount($this->source->queryValue('.//ram:ActualAmount', $tradeLineItemAllowanceChargeNode)), 'currencyID', $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); + $this->destination->elementWithAttribute('cbc:BaseAmount', $this->formatAmount($this->source->queryValue('.//ram:BasisAmount', $tradeLineItemAllowanceChargeNode)), 'currencyID', $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); + $this->source->whenExists( './/ram:CategoryTradeTax', $tradeLineItemAllowanceChargeNode, function ($tradeLineItemAllowanceChargeTaxNode) { - $this->out->startElement('cac:TaxCategory'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:CategoryCode', $tradeLineItemAllowanceChargeTaxNode)); - $this->out->element('cbc:Percent', $this->in->queryValue('.//ram:RateApplicablePercent', $tradeLineItemAllowanceChargeTaxNode)); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', $this->in->queryValue('.//ram:TypeCode', $tradeLineItemAllowanceChargeTaxNode)); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:TaxCategory'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:CategoryCode', $tradeLineItemAllowanceChargeTaxNode)); + $this->destination->element('cbc:Percent', $this->source->queryValue('.//ram:RateApplicablePercent', $tradeLineItemAllowanceChargeTaxNode)); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', $this->source->queryValue('.//ram:TypeCode', $tradeLineItemAllowanceChargeTaxNode)); + $this->destination->endElement(); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTradeProduct', $tradeLineItemNode, function ($tradeLineItemProductNode) use ($tradeLineItemNode) { - $this->out->startElement('cac:Item'); - $this->out->element('cbc:Description', $this->in->queryValue('.//ram:Description', $tradeLineItemProductNode)); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:Name', $tradeLineItemProductNode)); - $this->in->whenExists( + $this->destination->startElement('cac:Item'); + $this->destination->element('cbc:Description', $this->source->queryValue('.//ram:Description', $tradeLineItemProductNode)); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:Name', $tradeLineItemProductNode)); + $this->source->whenExists( './/ram:BuyerAssignedID', $tradeLineItemProductNode, function ($tradeLineItemProductIdNode) { - $this->out->startElement('cac:BuyersItemIdentification'); - $this->out->element('cbc:ID', $tradeLineItemProductIdNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:BuyersItemIdentification'); + $this->destination->element('cbc:ID', $tradeLineItemProductIdNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SellerAssignedID', $tradeLineItemProductNode, function ($tradeLineItemProductIdNode) { - $this->out->startElement('cac:SellersItemIdentification'); - $this->out->element('cbc:ID', $tradeLineItemProductIdNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:SellersItemIdentification'); + $this->destination->element('cbc:ID', $tradeLineItemProductIdNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:GlobalID', $tradeLineItemProductNode, function ($tradeLineItemProductGlobalIdNode) { - $this->out->startElement('cac:StandardItemIdentification'); - $this->out->elementWithAttribute('cbc:ID', $tradeLineItemProductGlobalIdNode->nodeValue, 'schemeID', $tradeLineItemProductGlobalIdNode->getAttribute('schemeID')); - $this->out->endElement(); + $this->destination->startElement('cac:StandardItemIdentification'); + $this->destination->elementWithAttribute('cbc:ID', $tradeLineItemProductGlobalIdNode->nodeValue, 'schemeID', $tradeLineItemProductGlobalIdNode->getAttribute('schemeID')); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:OriginTradeCountry/ram:ID', $tradeLineItemProductNode, function ($tradeLineItemProductOriginTradeCountryNode) { - $this->out->startElement('cac:OriginCountry'); - $this->out->element('cbc:IdentificationCode', $tradeLineItemProductOriginTradeCountryNode->nodeValue); - $this->out->endElement(); + $this->destination->startElement('cac:OriginCountry'); + $this->destination->element('cbc:IdentificationCode', $tradeLineItemProductOriginTradeCountryNode->nodeValue); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:DesignatedProductClassification/ram:ClassCode', $tradeLineItemProductNode, function ($tradeLineItemProductClassificationNode) { - $this->out->startElement('cac:CommodityClassification'); - $this->out->elementWithMultipleAttributes('cbc:ItemClassificationCode', $tradeLineItemProductClassificationNode->nodeValue, ['listID' => $tradeLineItemProductClassificationNode->getAttribute('listID'), 'listVersionID' => $tradeLineItemProductClassificationNode->getAttribute('listVersionID')]); - $this->out->endElement(); + $this->destination->startElement('cac:CommodityClassification'); + $this->destination->elementWithMultipleAttributes('cbc:ItemClassificationCode', $tradeLineItemProductClassificationNode->nodeValue, ['listID' => $tradeLineItemProductClassificationNode->getAttribute('listID'), 'listVersionID' => $tradeLineItemProductClassificationNode->getAttribute('listVersionID')]); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLineTradeSettlement', $tradeLineItemNode, function ($tradeLineItemSettlementNode) { - $this->in->whenExists( + $this->source->whenExists( './/ram:ApplicableTradeTax', $tradeLineItemSettlementNode, function ($tradeLineItemSettlementTaxNode) { - $this->out->startElement('cac:ClassifiedTaxCategory'); - $this->out->element('cbc:ID', $this->in->queryValue('ram:CategoryCode', $tradeLineItemSettlementTaxNode)); - $this->out->element('cbc:Percent', $this->in->queryValue('ram:RateApplicablePercent', $tradeLineItemSettlementTaxNode)); - $this->out->startElement('cac:TaxScheme'); - $this->out->element('cbc:ID', $this->in->queryValue('ram:TypeCode', $tradeLineItemSettlementTaxNode)); - $this->out->endElement(); - $this->out->endElement(); + $this->destination->startElement('cac:ClassifiedTaxCategory'); + $this->destination->element('cbc:ID', $this->source->queryValue('ram:CategoryCode', $tradeLineItemSettlementTaxNode)); + $this->destination->element('cbc:Percent', $this->source->queryValue('ram:RateApplicablePercent', $tradeLineItemSettlementTaxNode)); + $this->destination->startElement('cac:TaxScheme'); + $this->destination->element('cbc:ID', $this->source->queryValue('ram:TypeCode', $tradeLineItemSettlementTaxNode)); + $this->destination->endElement(); + $this->destination->endElement(); } ); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedTradeProduct', $tradeLineItemNode, function ($tradeLineItemProductNode) { - $this->in->whenExists( + $this->source->whenExists( './/ram:ApplicableProductCharacteristic', $tradeLineItemProductNode, function ($tradeLineProductCharacteristicNode) { - $this->out->startElement('cac:AdditionalItemProperty'); - $this->out->element('cbc:Name', $this->in->queryValue('.//ram:Description', $tradeLineProductCharacteristicNode)); - $this->out->element('cbc:Value', $this->in->queryValue('.//ram:Value', $tradeLineProductCharacteristicNode)); - $this->out->endElement(); + $this->destination->startElement('cac:AdditionalItemProperty'); + $this->destination->element('cbc:Name', $this->source->queryValue('.//ram:Description', $tradeLineProductCharacteristicNode)); + $this->destination->element('cbc:Value', $this->source->queryValue('.//ram:Value', $tradeLineProductCharacteristicNode)); + $this->destination->endElement(); } ); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); - $this->in->whenExists( + $this->source->whenExists( './/ram:SpecifiedLineTradeAgreement', $tradeLineItemNode, function ($tradeLineItemAgreementNode) use ($invoiceHeaderSettlement) { - $this->out->startElement('cac:Price'); - $this->out->elementWithAttribute('cbc:PriceAmount', $this->formatAmount($this->in->queryValue('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', $tradeLineItemAgreementNode)), 'currencyID', $this->in->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); - $this->out->elementWithAttribute('cbc:BaseQuantity', $this->in->queryValue('.//ram:NetPriceProductTradePrice/ram:BasisQuantity', $tradeLineItemAgreementNode), 'unitCode', $this->in->queryValue('.//ram:NetPriceProductTradePrice/ram:BasisQuantity/@unitCode', $tradeLineItemAgreementNode)); - $this->out->endElement(); + $this->destination->startElement('cac:Price'); + $this->destination->elementWithAttribute('cbc:PriceAmount', $this->formatAmount($this->source->queryValue('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', $tradeLineItemAgreementNode)), 'currencyID', $this->source->queryValue('.//ram:InvoiceCurrencyCode', $invoiceHeaderSettlement)); + $this->destination->elementWithAttribute('cbc:BaseQuantity', $this->source->queryValue('.//ram:NetPriceProductTradePrice/ram:BasisQuantity', $tradeLineItemAgreementNode), 'unitCode', $this->source->queryValue('.//ram:NetPriceProductTradePrice/ram:BasisQuantity/@unitCode', $tradeLineItemAgreementNode)); + $this->destination->endElement(); } ); - $this->out->endElement(); + $this->destination->endElement(); } ); } diff --git a/src/XmlDocumentWriter.php b/src/XmlDocumentWriter.php index bba884f..012e1de 100644 --- a/src/XmlDocumentWriter.php +++ b/src/XmlDocumentWriter.php @@ -9,7 +9,6 @@ namespace horstoeko\zugferdublbridge; -use Closure; use DOMElement; use DOMDocument; use horstoeko\zugferdublbridge\XmlDocumentBase;