<!--	
 	Copyright 2006 Intuit Inc. All rights reserved. Unauthorized reproduction
 	is a violation of applicable law. This material contains certain
 	confidential or proprietary information and trade secrets of Intuit Inc.
-->

<!-- This XSL file transforms QBXML like responses (The responses are not pure
	 SDK responses since we embed some proprietary elements/attributes in them) into
	 QBXML like Add and Mod requests. A proprietary <AFXInfo> element is used to embed
	 any non-SDK Add/Mod request information.
	 Most of the transformation is handled using XSL templates and copying
	 of elements where necessary.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- Match the element QBXML/QBXMLMsgsRs. There will be one of each of these
  	   elements for every Add and Mod responses. -->
  <xsl:template match="QBXML/QBXMLMsgsRq">
    <QBXML>
      <QBXMLMsgsRq onError="continueOnError">
        <xsl:apply-templates/>
      </QBXMLMsgsRq>
    </QBXML>
  </xsl:template>
  <xsl:template match ="ReceivePaymentModRq/ReceivePaymentMod">
    <ReceivePaymentAddRq>
      <xsl:attribute name="requestID">
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ReceivePaymentAdd>
	    <!-- TxnID is not part of the ReceivePayment Add request but needed while
			 importing accountant changes on the client side. -->
        <AFXInfo>
          <xsl:copy-of select="TxnID"/>
          <xsl:copy-of select="TotalAmount"/>
        </AFXInfo>
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="ARAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="TotalAmount"/>
        <xsl:copy-of select="PaymentMethodRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="DepositToAccountRef"/>
        <xsl:choose>
          <xsl:when test="AppliedToTxnMod">
            <xsl:apply-templates select="AppliedToTxnMod"/>
          </xsl:when>
          <xsl:otherwise>
            <IsAutoApply>false</IsAutoApply>
          </xsl:otherwise>
        </xsl:choose>
      </ReceivePaymentAdd>
    </ReceivePaymentAddRq>
  </xsl:template>
  <xsl:template match="DepositModRq/DepositMod">
    <DepositAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent DepositRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <DepositAdd>
	    <!-- TxnID is not part of the Deposit Add request but needed while
			 importing accountant changes on the client side. -->
        <AFXInfo>
          <xsl:copy-of select="TxnID"/>
          <xsl:copy-of select="DepositTotal"/>
        </AFXInfo>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="DepositToAccountRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:if test="CashBackInfoMod">
          <CashBackInfoAdd>
            <xsl:copy-of select="AccountRef"/>
            <xsl:copy-of select="Memo"/>
            <xsl:copy-of select="Amount"/>
          </CashBackInfoAdd>
        </xsl:if>
        <xsl:apply-templates select="DepositLineMod"/>
      </DepositAdd>
    </DepositAddRq>
  </xsl:template>
  <xsl:template match="AppliedToTxnMod">
    <AppliedToTxnAdd>
      <xsl:copy-of select="TxnID"/>
      <xsl:copy-of select="PaymentAmount"/>
      <xsl:copy-of select="DiscountAmount"/>
      <xsl:copy-of select="DiscountAccountRef"/>
      <xsl:copy-of select="AFXInfo"/>
    </AppliedToTxnAdd>
  </xsl:template>
  <xsl:template match="DepositLineMod">
    <DepositLineAdd>
      <xsl:choose>
        <xsl:when test="TxnType = 'ReceivePayment' or TxnType = 'SalesReceipt'">
           <xsl:copy-of select="PaymentTxnID"/>
          <xsl:copy-of select="AFXInfo"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="AFXInfo"/>
          <xsl:copy-of select="EntityRef"/>
          <xsl:copy-of select="AccountRef"/>
          <xsl:copy-of select="Memo"/>
          <xsl:copy-of select="CheckNumber"/>
          <xsl:copy-of select="PaymentMethodRef"/>
          <xsl:copy-of select="ClassRef"/>
          <xsl:copy-of select="Amount"/>
        </xsl:otherwise>
      </xsl:choose>
    </DepositLineAdd>
  </xsl:template>
</xsl:stylesheet>