<!--                                                                  -->
<!--  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">
        <xsl:call-template name="distributorRoyaltyShowTop" />
        <div class="section" id="distributorRoyaltyShow">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Payments successfully updated!</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="statementFilter" />
            <xsl:call-template name="payeeSummaryLink" />
            <br class="superBreak" />
            <xsl:choose>
                <xsl:when test="DistributorRoyaltyRun/DistributorRoyaltyStatementList/DistributorStatement">
                    <br />
                    <xsl:call-template name="statementTable" />
                </xsl:when>
                <xsl:otherwise>
                    <p>
                        No statements are available in this view.
                    </p>
                </xsl:otherwise>
            </xsl:choose>
        </div>
        <xsl:call-template name="buttons" />
    </xsl:template>

    <xsl:template name="distributorRoyaltyShowTop">
        <xsl:if test="DistributorRoyaltyRun/CanDownload = 1">
            <div class="section" id="distributorShowTop">
                <xsl:call-template name="downloadAll" />
                <br />
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="downloadAll">
        <div class="downloadWrapper">
            <a href="?c=pdf&amp;DistributorRoyaltyRunID={DistributorRoyaltyRun/DistributorRoyaltyRunID}" title="Download All Statements" class="iconLink">
                <img src="/production/images/icons/office/Harddisk-(Download)-(16x16.gif" height="16" width="16" />
            </a>
            <a href="?c=pdf&amp;DistributorRoyaltyRunID={DistributorRoyaltyRun/DistributorRoyaltyRunID}">Download All Statements</a>
        </div>
    </xsl:template>

    <xsl:template name="payeeSummaryLink">
        <xsl:if test="DistributorRoyaltyRun/DistributorRoyaltyStatementList/DistributorStatement">
            <xsl:variable name="downloadLink">
                ?c=show&amp;PayorID=<xsl:value-of select="Payor/PayorID" />&amp;DistributorRoyaltyRunID=<xsl:value-of select="DistributorRoyaltyRun/DistributorRoyaltyRunID" />&amp;download=1<xsl:if test="Params/filterBy">&amp;filterBy=<xsl:value-of select="Params/filterBy" /></xsl:if>
            </xsl:variable>
            <div class="downloadText">
                <a href="{$downloadLink}" title="Contains summary information for statements in the current filtered view below" class="iconLink"><img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" /></a> <a href="{$downloadLink}">Download Text File</a>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="statementTable">
        <table class="textChart hiOn">
            <tr>
                <th>Payee</th>
                <th>Client&#160;#</th>
                <th class="amount">Previous Balance</th>
                <th class="amount">Transaction Total</th>
                <th class="amount">Period Royalties</th>
                <th class="amount">Ending Balance</th>
                <th class="amount">Minimum Payment</th>
                <th class="amount">Amount Payable</th>
            </tr>
            <xsl:for-each select="DistributorRoyaltyRun/DistributorRoyaltyStatementList/DistributorStatement">
                <tr class="row{position() mod 2}">
                    <td>
                        <a href="javascript:pageLoading('/rps/statement?c=show_distributor&amp;DistributorStatementID={DistributorRoyaltyStatementID}')"><xsl:value-of select="DistributorPayee/Name" /></a>
                    </td>
                    <td>
                        <xsl:value-of select="DistributorPayee/ClientAccountID" />
                    </td>
                    <td class="amount">
                        <xsl:call-template name="formatDollars">
                            <xsl:with-param name="dollarAmount" select="PreviousBalance" />
                        </xsl:call-template>
                    </td>
                    <td class="amount">
                        <xsl:call-template name="formatDollars">
                            <xsl:with-param name="dollarAmount" select="TransactionSubtotal" />
                        </xsl:call-template>
                    </td>
                    <td class="amount">
                        <xsl:call-template name="formatDollars">
                            <xsl:with-param name="dollarAmount" select="Total" />
                        </xsl:call-template>
                    </td>
                    <td class="amount">
                        <xsl:choose>
                            <xsl:when test="Balance = 0 and AmountDue &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="amount">
                        <xsl:call-template name="formatDollars">
                            <xsl:with-param name="dollarAmount" select="MinPayment" />
                        </xsl:call-template>
                    </td>
                    <td class="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>
        </table>
    </xsl:template>

</xsl:stylesheet>

