<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:variable name="pagination" select="/Root/Form/LabelRoyaltyStatementList/Pagination" />

    <xsl:template name="statementEditPay">
        <xsl:variable name="totalInRunCount">
            <xsl:if test="$pagination/TotalPages > 1">
                <xsl:value-of select="$pagination/Total - Form/OnHoldCount" />
            </xsl:if>
        </xsl:variable>

        <div class="js-edit-payments-table" data-all-in-run="{$totalInRunCount}">
            <script src="/production/javascript/validatePayments.js?t={$now}" type="text/javascript"></script>
            <form action="/rps/label_royalty" method="post" name="editPayments" id="editPayments">
                <input type="hidden" name="c" value="editpay" />
                <input type="hidden" name="PayorID" value="{Params/PayorID}" />
                <input type="hidden" name="LabelRoyaltyRunID" value="{Params/LabelRoyaltyRunID}" />
                <input type="hidden" name="page" value="{Params/page}" />
                <input type="hidden" name="formSubmit" id="formSubmit" value="1" />
                <input type="hidden" name="clearAll" id="clearAll" value="0"/>
                <input type="hidden" name="fillAll" id="fillAll" value="0"/>

                <div class="MainBaseSection StatementsEdit">
                    <h2><xsl:value-of select="/Root/Form/Payor/Name" /> — <xsl:value-of select="/Root/Form/LabelRoyaltyRun/Label" /></h2>
                    <xsl:if test="Form/LabelRoyaltyStatementList/LabelStatement">
                        <xsl:call-template name="editPaymentsList" />
                        <xsl:call-template name="buttons" />
                    </xsl:if>
                    <xsl:if test="not(Form/LabelRoyaltyStatementList/LabelStatement)">
                        <div>
                            <div class="StatementsEdit-filter-wrapper">
                                <xsl:call-template name="statementFilter" />
                            </div>
                            <div class="Table-empty-results">
                                No statements are available in this view.
                            </div>
                        </div>
                        <xsl:call-template name="buttons" />
                    </xsl:if>
                </div>
            </form>
        </div>
    </xsl:template>

    <xsl:template name="editPaymentsList">
        <xsl:call-template name="openRunStatusMessage" />

        <div class="StatementsEdit-filter-wrapper">
            <xsl:call-template name="statementFilter">
                <xsl:with-param name="showLabel" select="'true'" />
            </xsl:call-template>
        </div>

        <xsl:if test="//*[@e]">
            <xsl:call-template name="errorMessageGeneral" />
        </xsl:if>
        <xsl:call-template name="successMessageGeneral">
            <xsl:with-param name="successMessage">Payments successfully updated!</xsl:with-param>
        </xsl:call-template>
        <div class="Form-header">
            <p>
                Enter payment information for payees in this run.
            </p>
        </div>
        <div class="Statement-editpay">

            <xsl:call-template name="statementFill">
                <xsl:with-param name="disabled" select="$openRuns" />
                <xsl:with-param name="showLabel" select="'true'" />
            </xsl:call-template>

            <table class="Table js-rs-html-content js-edit-payments-table-node" id="paymentTable">
                <thead>
                    <xsl:call-template name="edidPaymentHeader" />
                </thead>
                <tbody>
                    <xsl:for-each select="Form/LabelRoyaltyStatementList/LabelStatement">
                        <xsl:call-template name="edidPaymentBodyRow">
                            <xsl:with-param name="pendingTransaction" select="LabelPayeeAccount/FinanceAccount/PendingTransactionList/PendingTransaction" />
                            <xsl:with-param name="name" select="LabelPayee/Name" />
                            <xsl:with-param name="accountId" select="LabelPayee/ClientAccountID" />
                            <xsl:with-param name="endingBalance">
                                <xsl:choose>
                                    <xsl:when test="translate(Balance, translate(Balance,'0123456789', ''), '') = 0 and translate(AmountDue, translate(AmountDue,'0123456789', ''), '') &gt; 0">
                                        <xsl:value-of select="AmountDue" />
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="Balance" />
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:with-param>
                            <xsl:with-param name="paymentPrefix">
                                <xsl:text>Form_LabelRoyaltyStatementList_LabelStatement_</xsl:text>
                                <xsl:value-of select="@i" />
                                <xsl:text>_LabelPayeeAccount_FinanceAccount_PendingTransactionList_PendingTransaction_</xsl:text>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:for-each>
                </tbody>
            </table>
            <xsl:call-template name="paymentsPagination">
                <xsl:with-param name="pagination" select="$pagination" />
            </xsl:call-template>
        </div>
    </xsl:template>

</xsl:stylesheet>

