We are importing Peppol vendor invoices into our ERP-system by converting then into to another xml format using xslt. An example of a such an invoice is here:Github: OpenPEPPOL / peppol-bis-invoice-3
I want to give my accountant full freedom regarding which fields to be populated in each ERP-vendor invoice journal field. I want to give them a choice from a predefined set of nodes to use, for example:
/Invoice/ID /Invoice/IssueDate
/Invoice/AccountingSupplierParty/Party/PartyName/Name
/Invoice/InvoiceLine/InvoicedQuantity
/Invoice/InvoiceLine/Item/Name
I import specific vendor information from the ERP-system to use in the transformation process, for example to look up the vendor account:
<vendors>
<vendor>
<administration>YIT</administration>
<FISCALCODE>04705810150</FISCALCODE>
<accountNumber>20003</accountNumber>
<Offset_LedgerAccount>67123</Offset_LedgerAccount>
<name>A.Manzoni&C. Spa</name>
</vendor>
<vendors>
I lookup this information in the vendor xml table using the xslt below:
<xsl:variable name="LegalEntity">
<xsl:choose>
<xsl:when test="contains(cac:AccountingCustomerParty/cac:Party/cac:PartyName/cbc:Name, 'Italia')">YIT</xsl:when>
<xsl:otherwise>'UNKNOWN LegalEntity'</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="current-vendor-name" select="cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name"/>
<xsl:variable name="vendor-data" select="document('Vendors.xml')/vendors/vendor[name=$current-vendor-name and administration=$LegalEntity]"/>
The output of the transformation (when applied to the example input file in the link) is currently like below:
<?xml version="1.0" encoding="utf-8"?>
<PurchaseInvoices_version_1.0>
<PurchaseInvoice>
<LegalEntity>YIT</LegalEntity>
<SupplierAccountNum>20202</SupplierAccountNum>
<SupplierBankAccount>IBAN32423940</SupplierBankAccount>
<SupplierName>SupplierTradingName Ltd.</SupplierName>
<SupplierCity>London</SupplierCity>
<CurrencyCode>EUR</CurrencyCode>
<AmountExclTax>1325</AmountExclTax>
<AmountInclTax>1656.25</AmountInclTax>
<TaxAmount>331.25</TaxAmount>
<InvoiceId>Snippet1</InvoiceId>
<InvoiceDate>13-11-2017</InvoiceDate>
<PaymentNote>Payment within 10 days, 2% discount</PaymentNote>
<TaxCode>S</TaxCode>
<Lines>
<Line>
<Item>|Description of item</Item>
<Quantity>7</Quantity>
<UnitPrice>400</UnitPrice>
<LineAmount>2800</LineAmount>
<AmountIncl>3500</AmountIncl>
<AmountExcl>2800</AmountExcl>
<TaxAmount>700</TaxAmount>
<TaxCode>S</TaxCode>
<Description>Description of item|2017-11-13</Description>
<Unit>pcs</Unit>
</Line>
<Line>
<Item>|Description 2</Item>
<Quantity>-3</Quantity>
<UnitPrice>500</UnitPrice>
<LineAmount>-1500</LineAmount>
<AmountIncl>-1875</AmountIncl>
<AmountExcl>-1500</AmountExcl>
<TaxAmount>-375</TaxAmount>
<TaxCode>S</TaxCode>
<Description>Description 2|2017-11-13</Description>
<Unit>pcs</Unit>
</Line>
</Lines>
</PurchaseInvoice>
</PurchaseInvoices_version_1.0>
I want to create more freedom regarding which text (nodes) from the input xml to use in the Description field as well as the order in which to show them. This should be defined per vendor on the vendor card and imported into the vendors.xml file of which a sample is shown above.
For example for vendor A the description could be a concatenation of all nodes:
/Invoice/ID /Invoice/IssueDate
/Invoice/InvoiceLine/Item/Name
/Invoice/InvoiceLine/InvoicedQuantity
/Invoice/AccountingSupplierParty/Party/PartyName/Name
While for vendor B the description could be only:
/Invoice/InvoiceLine/Item/Name
The question is how to proceed from here.
My current idea is to create a description based on fixed number of variables:
<Description><xsl:value-of select="$A"/><xsl:value-of select="$B"/><xsl:value-of select="$C"/><xsl:value-of select="$D"/></Description>
And put the correct nodes in each variable based on some kind of input on Vendor card which is imported into the vendors.xml file and used in the xslt script.