<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template name="statementList">
        <div class="LabelRoyaltyShow-section MainBaseSection" id="labelRoyaltyShow">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Payments successfully updated!</xsl:with-param>
            </xsl:call-template>

            <xsl:call-template name="labelRoyaltyShowTop" />

            <h2>Label Royalty Statements</h2>
            <div class="Table-controls Table-controls-top">
                <div class="Table-controls-item StatementsShow-filter">
                    <xsl:call-template name="statementFilter" />
                </div>
                <div class="Table-controls-item StatementsShow-filter-links">
                    <xsl:call-template name="payeeSummaryLink" />
                </div>
            </div>
            <xsl:choose>
                <xsl:when test="LabelRoyaltyRun/LabelRoyaltyStatementList/LabelStatement">
                    <xsl:call-template name="statementTable" />
                </xsl:when>
                <xsl:otherwise>
                    <div class="Table-empty-reults">
                        No statements are available in this view.
                    </div>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:call-template name="buttons" />
        </div>
    </xsl:template>

    <xsl:template name="labelRoyaltyShowTop">
        <div class="StatementsShow-general">
            <xsl:if test="LabelRoyaltyRun/CanDownload = 1">
                <div class="InformationCols">
                    <div class="InformationCols-item InformationCols-item-double" id="labelShowTop">
                        <xsl:call-template name="downloadAll" />
                    </div>
                </div>
            </xsl:if>
        </div>
    </xsl:template>

    <xsl:template name="downloadAll">
        <ul class="ControlsList StatementsShow-list StatementsShow-list-distributed">
            <li class="ControlsList-item StatementsShow-list-item">
                <xsl:call-template name="uiDownloadLink">
                    <xsl:with-param name="text" select="'Download All Statements'"/>
                    <xsl:with-param name="url">
                        <xsl:text>?c=pdf&amp;LabelRoyaltyRunID=</xsl:text>
                        <xsl:value-of select="LabelRoyaltyRun/LabelRoyaltyRunID" />
                    </xsl:with-param>
                </xsl:call-template>
            </li>
        </ul>
    </xsl:template>

    <xsl:template name="payeeSummaryLink">
        <xsl:if test="LabelRoyaltyRun/LabelRoyaltyStatementList/LabelStatement">
            <xsl:variable name="downloadLink">
                ?c=show&amp;PayorID=<xsl:value-of select="Payor/PayorID" />&amp;LabelRoyaltyRunID=<xsl:value-of select="LabelRoyaltyRun/LabelRoyaltyRunID" />&amp;download=1<xsl:if test="Params/filterBy">&amp;filterBy=<xsl:value-of select="Params/filterBy" /></xsl:if>
            </xsl:variable>

            <xsl:call-template name="uiDownloadLink">
                <xsl:with-param name="text" select="'Royalty Run Statement Summary'"/>
                <xsl:with-param name="className" select="'StatementsShow-filter-link'"/>
                <xsl:with-param name="url" select="$downloadLink" />
                <xsl:with-param name="title" select="'Contains summary information for statements in the current filtered view below'" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <xsl:template name="statementTable">
        <xsl:variable name="pdfReady" select="normalize-space(LabelRoyaltyRun/CanDownload)" />
        <div class="Table-wrapper">
            <table class="Table Table-with-highlight">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Payee</th>
                        <th class="Table-col">Client&#160;#</th>
                        <th class="Table-col Table-col-amount">Previous Balance</th>
                        <th class="Table-col Table-col-amount">Transaction Total</th>
                        <th class="Table-col Table-col-amount">Period Royalties</th>
                        <th class="Table-col Table-col-amount">Ending Balance</th>
                        <th class="Table-col Table-col-amount">Minimum Payment</th>
                        <th class="Table-col Table-col-amount">Amount Payable</th>
                    </tr>
                </thead>
                <tbody>
                    <xsl:for-each select="LabelRoyaltyRun/LabelRoyaltyStatementList/LabelStatement">
                        <tr class="Table-row Table-row-data">
                            <xsl:variable name="linkCommand">show_label_pdf</xsl:variable>

                            <td class="Table-col">
                                <xsl:choose>
                                    <xsl:when test="not($pdfReady)">
                                        <xsl:value-of select="LabelPayee/Name" />
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <a href="/rps/statement?c={$linkCommand}&amp;LabelStatementID={LabelRoyaltyStatementID}" onClick="pageLoading('/rps/statement?c=show_label&amp;LabelStatementID={LabelRoyaltyStatementID}')"><xsl:value-of select="LabelPayee/Name" /></a>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                            <td class="Table-col StatementsShow-client-id-col">
                                <xsl:value-of select="LabelPayee/ClientAccountID" />
                            </td>
                            <td class="Table-col Table-col-amount">
                                <xsl:call-template name="formatDollars">
                                    <xsl:with-param name="dollarAmount" select="PreviousBalance" />
                                </xsl:call-template>
                            </td>
                            <td class="Table-col Table-col-amount">
                                <xsl:call-template name="formatDollars">
                                    <xsl:with-param name="dollarAmount" select="TransactionSubtotal" />
                                </xsl:call-template>
                            </td>
                            <td class="Table-col Table-col-amount">
                                <xsl:call-template name="formatDollars">
                                    <xsl:with-param name="dollarAmount" select="Total" />
                                </xsl:call-template>
                            </td>
                            <td class="Table-col Table-col-amount">
                                <xsl:choose>
                                    <xsl:when test="translate(Balance, translate(Balance,'0123456789', ''), '') = 0 and translate(AmountDue, translate(AmountDue,'0123456789', ''), '') &gt; 0">
                                        <xsl:call-template name="formatDollars">
                                            <xsl:with-param name="dollarAmount" select="AmountDue" />
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:call-template name="formatDollars">
                                            <xsl:with-param name="dollarAmount" select="Balance" />
                                        </xsl:call-template>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                            <td class="Table-col Table-col-amount">
                                <xsl:call-template name="formatDollars">
                                    <xsl:with-param name="dollarAmount" select="MinPayment" />
                                </xsl:call-template>
                            </td>
                            <td class="Table-col Table-col-amount">
                                <xsl:choose>
                                    <xsl:when test="OnHold = 1">ON-HOLD</xsl:when>
                                    <xsl:otherwise>
                                        <xsl:call-template name="formatDollars">
                                            <xsl:with-param name="dollarAmount" select="AmountDue" />
                                        </xsl:call-template>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                        </tr>
                    </xsl:for-each>
                </tbody>
            </table>
            <xsl:call-template name="paymentsPagination">
                <xsl:with-param name="pagination" select="LabelRoyaltyRun/LabelRoyaltyStatementList/Pagination" />
            </xsl:call-template>
        </div>
    </xsl:template>

</xsl:stylesheet>

