Error with the XSLT Muenchian grouping and coding

76 views Asked by At

I'm having trouble with the syntax around the XSLT coding. There's clearly something wrong or missing, but I'm having trouble figuring it out.

The XML file is grabbing amounts from a series of earning, deduction and tax codes from a database. Most of the earning codes need to be grouped and summed when the few variables are the same (description, location and cost center), which is where Muenchian grouping comes into play.

John works for ABC location as a Technician and is being paid the following earnings: Regular, Holiday and Overtime. The amounts for these earnings need to show in the output as a summed value and grouped into a group called Gross Earnings. The deductions and taxes do not need to be summed up.

Below is the XML code and the XSLT coding below that. Any ideas on how to solve this one?

<?xml version="1.0" encoding="UTF-8"?>
<GLPayrollExportConfiguration>
  <definitions>
    <FileType Value="XML"/>
       <FileName>
            <Value Value="GL_Summary"/>
            <Value Value="_"/>
            <Value Value="paygroup_xref"/>
            <Value Value="_"/>
            <Value Value="payrun_payperiod_and_suffix"/>
            <Value Value="_"/>
            <Value Value="transaction_timestamp"/>
            <Value Value=".csv"/>
        </FileName>
    
    <Settings>
        <SplitMode Value="HOME_LOCATION_SPLIT"/>
        <ChartOfAccountXRefCode Value="GL"/>
        <RunOnPayRunCommit Value="True"/>
    </Settings>

    <Columns>
      <Column Name="ColA" DataType="string" Source="mapping"/>
      <Column Name="ColB" DataType="string" Source="data"/>
      <Column Name="ColC" DataType="string" Source="data"/>
      <Column Name="ColD" DataType="string" Source="data"/>
      <Column Name="PayDate" DataType="datetime" Source="data" Value="payrun_pay_date" Sort="true"/>
      <Column Name="PeriodEnd" DataType="datetime" Source="data" Value="payrun_pay_date" Sort="true"/>
      <Column Name="ColG" DataType="string" Source="data"/>
      <Column Name="AccountDesc" DataType="string" Source="data" Value="payrun_category_override_description" Sort="true" Function="group"/>
      <Column Name="PayrunCategoryName" DataType="string" Source="data" Value="payrun_category_name" Sort="true" Function="group"/>
      <Column Name="SiteName" DateType="string" Source="data" Value="charged_phys_loc_desc" Sort="true"/>
      <Column Name="Amount" DataType="number" Source="mapping" Value="payrun_amount" Function="sum" />
      <Column Name="GLAccount" DataType="string" Source="data" Value="override_segment_charged_position"/>
      <Column Name="ColL" DataType="string" Source="data"/>
      <Column Name="ColM" DataType="string" Source="data"/>
      <Column Name="ColN" DataType="string" Source="data"/>
    </Columns>
  </definitions>
  
    <MappingDefinitions>
  
    <definition>
      <criteriaset>
        <criteria item="payrun_category_override_journal_number" op="ne">EXCLUDE</criteria>
        <criteria item="payrun_category_override_journal_number" op="ne">Exclude</criteria>
        <criteria item="payrun_category_override_journal_number" op="ne">exclude</criteria>
        <criteria item="payrun_amount" op="ne" opDataType="number">0</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">ReliantRealtyServicesLLC</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">BronxParkPhaseI</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">BronxParkPhaseII</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">BronxParkPhaseIII</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">OmniNYLLC</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">OMPOfficeLLC</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">ReliantRealtyServicesLLC3rdParty</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">ReliantSafetyLLC</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">ReliantSafetyLLC3rdParty</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">RenewalConstructionServicesLLC</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">RMSPartnersLLC</criteria>
        <criteria item="charged_phys_loc_desc" op="ne">OMPParksideLP</criteria>
      </criteriaset>
      <mapping>
        <mapto columnname="ColA">
          <Value Value="J"/>
          </mapto>
        <mapto columnname="Amount">
          <Value Value="&#x0009;"/><Value Value="payrun_amount"/>
          
          </mapto>
      </mapping>
    </definition>

   </MappingDefinitions>
  <ColumnFormats>
    <ColumnFormat Name="ColA"/>
    <ColumnFormat Name="ColB"/>
    <ColumnFormat Name="ColC"/>
    <ColumnFormat Name="ColD"/>
    <ColumnFormat Name="PayDate" Format="MM/dd/yy"/>
    <ColumnFormat Name="PeriodEnd" Format="MM/dd/yy"/>
    <ColumnFormat Name="ColG"/>
    <ColumnFormat Name="AccountDesc"/>
    <ColumnFormat Name="SiteName"/>
    <ColumnFormat Name="Amount" Format="{0:##.00}"/>
    <ColumnFormat Name="GLAccount" WrapChar="&quot;"/>
    <ColumnFormat Name="ColL"/>
    <ColumnFormat Name="ColM"/>
    <ColumnFormat Name="ColN"/>

   </ColumnFormats>
   
</GLPayrollExportConfiguration>

And this is my XSLT-1.0 code:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:cs="urn:cs" exclude-result-prefixes="xs">
  <msxsl:script language="C#" implements-prefix="cs">
    <msxsl:using namespace="System.IO"/>
    <![CDATA[
            
        public static int DayDifference(string rehiredate,string termdate)
        {       
            String rehire=rehiredate;
            String term=termdate;
            if (string.IsNullOrEmpty(rehiredate)==true || string.IsNullOrEmpty(termdate)==true) return 0;
                DateTime d1 = DateTime.Parse(rehire.Substring(6,4) + '-' + rehire.Substring(0,2) + '-' + rehire.Substring(3,2) );
                DateTime d2 = DateTime.Parse(term.Substring(6,4) + '-' + term.Substring(0,2) + '-' + term.Substring(3,2) );
            return (d1 - d2).Days; 
        }   
        
        public static int DayDifferenceSys(string rehiredate)
        {       
            String rehire=rehiredate;
            DateTime CurrentDate= DateTime.Now;
            if (string.IsNullOrEmpty(rehiredate)==true) return 0;
            DateTime d1 = DateTime.Parse(rehire.Substring(6,4) + '-' + rehire.Substring(0,2) + '-' + rehire.Substring(3,2));
            return CurrentDate.Subtract(d1).Days;
        }   
        
        public string DateAdd(string s1,int i){
            DateTime d1= DateTime.Parse(s1.Substring(6,4) + '-' + s1.Substring(0,2) + '-' + s1.Substring(3,2));
            
            return d1.AddDays(i).ToString("yyyy-MM-dd");
            
            }
            
       ]]>
  </msxsl:script>

  <xsl:output method="text"/>
  
  <xsl:key name="GrossEarnings" match="PayrunCategoryName" use="AccountDesc"/>

  <xsl:template match="PayrunCategoryName">
  
  <xsl:apply-templates select="key(GrossEarnings, AccountDesc)" />
  
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:for-each select="Export/Record[Amount!=0 and group(.|key('key_GrossEarnings', concat(PayrunCategoryName))[1])=1]">
      
            <xsl:value-of select="ColA"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColB"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColC"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColD"/><xsl:text>,</xsl:text>
            <xsl:value-of select="PayDate"/><xsl:text>,</xsl:text>
            <xsl:value-of select="PeriodEnd"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColG"/><xsl:text>,</xsl:text>
            <xsl:value-of select="AccountDesc"/><xsl:text>,</xsl:text>
            <xsl:value-of select="GrossEarnings"/><xsl:text>,</xsl:text>
            <xsl:value-of select="SiteName"/><xsl:text>,</xsl:text>
            <xsl:value-of select="Amount"/><xsl:text>,</xsl:text>
            
                <xsl:choose>
                <xsl:when test="GrossEarnings">
                    <xsl:value-of select="sum(Amount)" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="Amount"/>
                </xsl:otherwise>
                    <xsl:text>,</xsl:text>
                
            </xsl:choose>
            <xsl:text>,</xsl:text>
            
            <xsl:value-of select="GLAccount"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColL"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColM"/><xsl:text>,</xsl:text>
            <xsl:value-of select="ColN"/><xsl:text>,</xsl:text>
        <xsl:text>&#xD;&#xA;</xsl:text>
    </xsl:for-each>
    
  </xsl:template>

</xsl:stylesheet>

Edit: Thanks @zx485. If George has earnings of Regular, Sick and Vacation, works at ABC site and the earnings are allocated to Cost Ctr 12345, I'm looking for the earnings to be summed up into one transaction called Gross Earnings with the resulting sum value.

0

There are 0 answers