Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viksingh/b97cba3dc8b7bde3b26fcae9b5e62931 to your computer and use it in GitHub Desktop.
Save viksingh/b97cba3dc8b7bde3b26fcae9b5e62931 to your computer and use it in GitHub Desktop.
Example #XSLT #PI #mapping working with a SAP #Invoice message
<?xml version="1.0" encoding="UTF-8"?>
<!--
Name: ProCon Invoice Mapping
Author: Chris Mills
Details: Mapping implemented as an XSL as single SAP Invoice message needs to be split to mutliple ProCon messages, 1 per PO
and financials calculated by unique PO. i.e. if invoice has 3 line items which relate to two PO's then need to split to
two output messages and calculate the tax and net amounts by PO, recursion much easier in XSL
NOTE: This will only send items from the invoice that relate to a contract, the business rules are meant to be no multi-contract
invoices and no mix of 1 item against a contract and another not but if it happens ProCon will only see parts of the invoice
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge"
xmlns:ns1="http://8over8.com/servicecontracts/09/09">
<xsl:output indent="yes"/>
<xsl:template match="/">
<ns0:Messages>
<ns0:Message1>
<xsl:for-each select="//Invoice/Item[PurchasingContractReference/ID]">
<xsl:variable name="purchaseOrder"><xsl:value-of select="PurchaseOrderReference/ID"></xsl:value-of></xsl:variable>
<!-- Only process the item if we haven't processed a line with the same Purchase Order number previously -->
<xsl:if test="count(preceding-sibling::Item[PurchaseOrderReference/ID = $purchaseOrder]) = 0">
<!-- xsl is base 1 so year runs from pos 1 to pos 5 -->
<xsl:variable name="invoice"><xsl:value-of select="substring(../BillToID,5)"></xsl:value-of></xsl:variable>
<xsl:variable name="invoiceYear"><xsl:value-of select="substring(../BillToID,1,4)"></xsl:value-of></xsl:variable>
<ns1:ActivityMessage>
<ns1:Activity>
<ns1:ContractReference><xsl:value-of select="PurchasingContractReference/ID"/></ns1:ContractReference>
<ns1:ActivityTypeAbbreviation>INV</ns1:ActivityTypeAbbreviation>
<ns1:ActivityReference><xsl:value-of select="$invoice"/></ns1:ActivityReference>
<ns1:Title><xsl:value-of select="concat($invoiceYear,'-',$invoice)" /></ns1:Title>
<xsl:choose>
<xsl:when test="../CancellationInvoiceIndicator = 'true'">
<ns1:State>Cancelled</ns1:State>
</xsl:when>
<xsl:when test="../PaymentForm/GrossAmountClearedIndicator = 'true'">
<ns1:State>Agreed</ns1:State>
</xsl:when>
<xsl:otherwise>
<ns1:State>ApprovedAndWaitingResponse</ns1:State>
</xsl:otherwise>
</xsl:choose>
<ns1:OwnedFrom><xsl:value-of select="../TransactionDate" /></ns1:OwnedFrom> <!-- was previously: ../DateTime -->
<ns1:OriginatedOn><xsl:value-of select="../TransactionDate" /></ns1:OriginatedOn>
<ns1:Description><xsl:value-of select="../Description"/></ns1:Description>
<ns1:CustomFields>
<ns1:CustomField>
<ns1:Name>SAP Purchase Order Number</ns1:Name>
<ns1:Value><xsl:value-of select="$purchaseOrder"/></ns1:Value>
</ns1:CustomField>
<!-- <xsl:if test="../ID"> -->
<ns1:CustomField>
<ns1:Name>Contractor Invoice Number</ns1:Name>
<ns1:Value><xsl:value-of select="../ReferenceDocumentID"/></ns1:Value>
</ns1:CustomField>
<!-- </xsl:if> -->
<ns1:CustomField>
<ns1:Name>Tax Amount</ns1:Name>
<ns1:Value><xsl:value-of select="sum(//Invoice/Item/ProductTax/Amount[../../PurchaseOrderReference/ID=$purchaseOrder])"/></ns1:Value>
</ns1:CustomField>
</ns1:CustomFields>
<ns1:FinancialValues>
<ns1:FinancialValue>
<ns1:Title>Total</ns1:Title>
<ns1:Value><xsl:value-of select="sum(//Invoice/Item/Price/NetAmount[../../PurchaseOrderReference/ID=$purchaseOrder])"/></ns1:Value>
</ns1:FinancialValue>
</ns1:FinancialValues>
</ns1:Activity>
</ns1:ActivityMessage>
</xsl:if>
</xsl:for-each>
</ns0:Message1>
</ns0:Messages>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<ns3:InvoiceReplication_V01 xmlns:ns3="urn:std:inpex.com.au:cmm:Invoice">
<MessageHeader>
<ID>0050568201851EE381A7EF2083A626D2</ID>
<CreationDateTime>2013-08-15T00:13:18Z</CreationDateTime>
<SenderBusinessSystemID>ERD030_D</SenderBusinessSystemID>
</MessageHeader>
<Invoice>
<ReferenceDocumentID>909001563</ReferenceDocumentID>
<BillFromParty>
<InternalID>0000400100</InternalID>
<Address>
<PhysicalAddress>
<CountryCode>AU</CountryCode>
<StreetPostalCode>6000</StreetPostalCode>
<CityName>Perth</CityName>
<POBoxRegionName>WA</POBoxRegionName>
<StreetName>13 Pentrich</StreetName>
</PhysicalAddress>
</Address>
</BillFromParty>
<BillToID>20135105600556</BillToID>
<CashDiscountTerms>
<PaymentBaselineDate>2013-04-29</PaymentBaselineDate>
</CashDiscountTerms>
<Item>
<ID>000001</ID>
<BillToID>000001</BillToID>
<TypeCode>002</TypeCode>
<ProcessingTypeCode>B</ProcessingTypeCode>
<AccountingCodingBlockAssignment>
<OrdinalNumberValue>1</OrdinalNumberValue>
<Amount currencyCode="USD">10.0</Amount>
<Quantity unitCode="EA">10.0</Quantity>
<AlternativeQuantity unitCode="EA">10.0</AlternativeQuantity>
<CompanyID>2100</CompanyID>
<ProfitCentreID>200020012</ProfitCentreID>
<SegmentID>0000000000</SegmentID>
<SalesOrderReference>
<ID/>
<ItemID>000000</ItemID>
</SalesOrderReference>
<AccountDeterminationExpenseGroupCode>5035000</AccountDeterminationExpenseGroupCode>
</AccountingCodingBlockAssignment>
<DeliveryReference>
<ID>5000001902</ID>
<ItemID>0001</ItemID>
</DeliveryReference>
<Price>
<NetAmount currencyCode="USD">10.0</NetAmount>
</Price>
<ProductTax>
<TypeCode listID=" ">P1</TypeCode>
<Amount currencyCode="USD">1.0</Amount>
</ProductTax>
<PurchaseOrderReference>
<ID>4500000505</ID>
<ItemID>00010</ItemID>
</PurchaseOrderReference>
<PurchasingContractReference>
<ID>820063USD</ID>
<ItemID>00010</ItemID>
</PurchasingContractReference>
</Item>
<PaymentForm>
<PaymentFormCode>U </PaymentFormCode>
<GrossAmountClearedIndicator>true</GrossAmountClearedIndicator>
</PaymentForm>
<Price>
<GrossAmount currencyCode="USD">10.0</GrossAmount>
</Price>
<ProductTax>
<TypeCode listID=" ">P1</TypeCode>
<Amount currencyCode="USD">1.0</Amount>
</ProductTax>
<TransactionDate>2013-06-14</TransactionDate>
<TypeCode>004</TypeCode>
</Invoice>
</ns3:InvoiceReplication_V01>
</ns0:Message1>
</ns0:Messages>
<?xml version="1.0"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge" xmlns:ns1="http://8over8.com/servicecontracts/09/09">
<ns0:Message1>
<ns1:ActivityMessage>
<ns1:Activity>
<ns1:ContractReference>820063USD</ns1:ContractReference>
<ns1:ActivityTypeAbbreviation>INV</ns1:ActivityTypeAbbreviation>
<ns1:ActivityReference>5105600556</ns1:ActivityReference>
<ns1:Title>2013-5105600556</ns1:Title>
<ns1:State>Agreed</ns1:State>
<ns1:OwnedFrom>2013-06-14</ns1:OwnedFrom>
<ns1:OriginatedOn>2013-06-14</ns1:OriginatedOn>
<ns1:Description/>
<ns1:CustomFields>
<ns1:CustomField>
<ns1:Name>SAP Purchase Order Number</ns1:Name>
<ns1:Value>4500000505</ns1:Value>
</ns1:CustomField>
<ns1:CustomField>
<ns1:Name>Contractor Invoice Number</ns1:Name>
<ns1:Value>909001563</ns1:Value>
</ns1:CustomField>
<ns1:CustomField>
<ns1:Name>Tax Amount</ns1:Name>
<ns1:Value>1</ns1:Value>
</ns1:CustomField>
</ns1:CustomFields>
<ns1:FinancialValues>
<ns1:FinancialValue>
<ns1:Title>Total</ns1:Title>
<ns1:Value>10</ns1:Value>
</ns1:FinancialValue>
</ns1:FinancialValues>
</ns1:Activity>
</ns1:ActivityMessage>
</ns0:Message1>
</ns0:Messages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment