<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />
    <xsl:include href="shared.xsl" />

    <xsl:variable name="showLabelTable">
        <xsl:choose>
            <xsl:when test="Statement/LabelStatement/LabelStatementLabelList/LabelStatementLabel">
                <xsl:text>true</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>false</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="pickLayout">
        <div class="StatementsDocuments">
            <section class="MainBaseSection" id="labelStatement">
                <xsl:call-template name="labelSummary" />

            </section>
            <section class="MainBaseSection">
                <a name="top" />
                <xsl:call-template name="transactionTable">
                    <xsl:with-param name="statement" select="Statement/LabelStatement" />
                    <xsl:with-param name="transactions" select="Statement/LabelStatement/LabelStatementTransactionList/LabelStatementTransaction" />
                </xsl:call-template>
                <xsl:if test="$showLabelTable != 'true'">
                    <xsl:call-template name="buttons" />
                </xsl:if>
            </section>

            <xsl:if test="$showLabelTable = 'true'">
                <section class="MainBaseSection">
                    <div class="Table-wrapper Table-wrapper-srollleft">
                        <table class="Table">
                            <thead>
                                <xsl:call-template name="labelStatementHeader" />
                            </thead>
                            <tbody>
                                <xsl:for-each select="Statement/LabelStatement/LabelStatementLabelList/LabelStatementLabel">
                                    <xsl:call-template name="labelStatementRow" />
                                </xsl:for-each>
                                <xsl:call-template name="labelStatementTotals" />
                            </tbody>
                        </table>
                    </div>
                    <xsl:call-template name="buttons" />
                </section>
            </xsl:if>
        </div>
    </xsl:template>

    <xsl:template name="labelSummary">
        <div id="statementSummary">

            <h2><xsl:value-of select="Statement/LabelRoyaltyRun/Label" /></h2>
            <section class="StatementsDocuments-publisher">
                <xsl:call-template name="labelPayeeInfo">
                    <xsl:with-param name="payee" select="Statement/LabelStatement/LabelPayee" />
                </xsl:call-template>
            </section>

            <xsl:if test="Statement/LabelRoyaltyRun/CanDownload = 1">
                <ul class="StatementsDocuments-download ControlsList">
                    <li class="ControlsList-item">
                        <xsl:call-template name="downloadLabelPDF" />
                    </li>
                    <li class="ControlsList-item">
                        <xsl:call-template name="downloadSalesFile" />
                    </li>
                </ul>
            </xsl:if>

        </div>
    </xsl:template>

    <xsl:template name="labelPayeeInfo">
        <xsl:param name="payee" />
        <a href="/rps/label_payee?LabelPayeeID={$payee/LabelPayeeID}&amp;c=show">
            <xsl:value-of select="$payee/Name" />
        </a>
        <xsl:if test="normalize-space($payee/StreetAddress)">
            <p><xsl:value-of select="$payee/StreetAddress" /></p>
        </xsl:if>
        <xsl:if test="normalize-space($payee/StreetAddress2)">
            <p><xsl:value-of select="$payee/StreetAddress2" /></p>
        </xsl:if>
        <xsl:if test="normalize-space($payee/StreetAddress3)">
            <p><xsl:value-of select="$payee/StreetAddress3" /></p>
        </xsl:if>
        <xsl:if test="normalize-space($payee/City) or normalize-space($payee/StateProvince)">
            <p><xsl:if test="normalize-space($payee/City)"><xsl:value-of select="$payee/City" /><xsl:if test="normalize-space($payee/StateProvince)">, </xsl:if></xsl:if><xsl:value-of select="$payee/StateProvince" />&#160;<xsl:value-of select="$payee/PostalCode" /></p>
        </xsl:if>
        <xsl:if test="normalize-space($payee/CountryCode)">
            <p><xsl:value-of select="$payee/CountryCode" /></p>
        </xsl:if>
    </xsl:template>

    <xsl:template name="downloadLabelPDF">
        <xsl:call-template name="uiDownloadLink">
            <xsl:with-param name="text" select="'Summary View'" />
            <xsl:with-param name="url">
                <xsl:text>?c=pdf_label&amp;LabelStatementID=</xsl:text>
                <xsl:value-of select="Statement/LabelStatement/LabelRoyaltyStatementID" />
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="downloadSalesFile">
        <xsl:call-template name="uiDownloadLink">
            <xsl:with-param name="text" select="'Sales Detail'" />
            <xsl:with-param name="url">
                <xsl:text>/rps/statement?c=report_label&amp;LabelStatementID=</xsl:text>
                <xsl:value-of select="Statement/LabelStatement/LabelRoyaltyStatementID" />
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="labelStatementHeader">
        <tr class="Table-row Table-row-header">
            <th class="Table-col">Label</th>
            <th class="Table-col">Service</th>
            <th class="Table-col">Country</th>
            <th class="Table-col">Distribution Rate</th>
            <th class="Table-col Table-col-amount">Gross Sales</th>
            <th class="Table-col Table-col-amount">Distribution Fee</th>
            <th class="Table-col Table-col-amount">Net Sales</th>
        </tr>
    </xsl:template>

    <xsl:template name="labelStatementRow">
        <tr class="Table-row Table-row-data">
            <xsl:attribute name="class">
                <xsl:text>Table-row Table-row-data</xsl:text>
                <xsl:if test="position() = 1">
                    <xsl:text> Table-row-total</xsl:text>
                </xsl:if>
            </xsl:attribute>
            <td class="Table-col">
                <xsl:if test="LabelContractID &gt; 0">
                    <a href="/rps/label_contract?LabelContractID={LabelContractID}&amp;c=show" title="View Contract">
                        <img src="/production/images/icons/mini/briefcase.gif" width="10" height="10" />
                    </a>&#160;
                </xsl:if>
                <xsl:value-of select="Label/LabelName" />
            </td>
            <td class="Table-col">
                <xsl:value-of select="ServiceName" />
            </td>
            <td class="Table-col">
                <xsl:value-of select="CountryName" />
            </td>
            <td class="Table-col">
                <xsl:value-of select="DistributionFee" />%
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="GrossSales" />
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="Fee" />
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="NetSales" />
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="labelStatementTotals">
        <tr class="Table-row Table-row-header">
            <td colspan="2" class="Table-col Table-col-total">Total:</td>
            <td colspan="3" class="Table-col Table-col-total Table-col-amount">
                <xsl:value-of select="Statement/LabelStatement/GrossSalesTotal" />
            </td>
            <td class="Table-col Table-col-total Table-col-amount">
                <xsl:value-of select="Statement/LabelStatement/FeeTotal" />
            </td>
            <td class="Table-col Table-col-total Table-col-amount">
                <xsl:value-of select="Statement/LabelStatement/Total" />
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="submitButton">
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Back to Statements'" />
            <xsl:with-param name="className" select="'Form-button'" />
            <xsl:with-param name="name" select="'Back'" />
            <xsl:with-param name="url">
                <xsl:text>label_royalty?LabelRoyaltyRunID=</xsl:text>
                <xsl:value-of select="Statement/LabelRoyaltyRun/LabelRoyaltyRunID" />
                <xsl:text>&amp;c=show&amp;PayorID=</xsl:text>
                <xsl:value-of select="Statement/LabelStatement/PayorID" />
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>

