<!--                                                                  -->
<!--  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="currencyCode">
        <xsl:choose>
            <xsl:when test="$cmd = 'ca_license_accrual'">CAD</xsl:when>
            <xsl:otherwise>USD</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:variable name="countryCode">
        <xsl:choose>
            <xsl:when test="$cmd = 'ca_license_accrual'">CA</xsl:when>
            <xsl:otherwise>US</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="formCommand">
        <xsl:choose>
            <xsl:when test="$cmd = 'ca_license_accrual'">ca_license_accrual</xsl:when>
            <xsl:otherwise>license_accrual</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="licenseAccrualLayout">
        <div class="AuditReport" id="auditReport">
            <xsl:choose>
                <xsl:when test="Report/Track">
                    <h2 class="AuditReport-header">
                        Unlicensed Accrual

                        <xsl:choose>
                            <xsl:when test="$cmd = 'ca_license_accrual'">
                                <xsl:value-of select="Report/MechanicalRun/StartDate" /> - <xsl:value-of select="Report/MechanicalRun/EndDate" />
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="Report/MechanicalRun/Label" />
                            </xsl:otherwise>
                        </xsl:choose>

                        <xsl:call-template name="helpIcon">
                            <xsl:with-param name="tip">
                                Lists unlicensed portion of tracks with associated accruals by product.
                                &lt;ul&gt;
                                &lt;li&gt;Uses full stat rate if song timing is available, min stat rate otherwise;&lt;/li&gt;
                                &lt;li&gt;Uses stat rate associated with the date of the sale;&lt;/li&gt;
                                &lt;li&gt;Accounts for <xsl:value-of select="$countryCode" /> sales only.&lt;/li&gt;
                                &lt;/ul&gt;
                            </xsl:with-param>
                        </xsl:call-template>
                    </h2>

                    <div class="Table-controls Table-controls-top">
                        <xsl:if test="count(Report/LabelList/Label) &gt; 1">
                            <div class="Table-controls-item AuditReport-controls-mech">
                                <form method="get" action="/rps/report">
                                    <input type="hidden" name="c" value="{$formCommand}" />
                                    <input type="hidden" name="run_id" value="{Params/run_id}" />
                                    <input type="hidden" name="payor_id" value="{Params/payor_id}" />

                                    <div class="Form-group Form-group-horizontal">
                                        <div class="Form-item">
                                            <label class="Form-label">
                                                <span class="Form-label-caption">Now Viewing</span>
                                                <span class="Form-input-wrapper">
                                                    <xsl:variable name="auditReportRegionListItems">
                                                        <map>
                                                            <mapEntry>
                                                                <name>All Labels</name>
                                                                <value></value>
                                                            </mapEntry>
                                                            <xsl:for-each select="Report/LabelList/Label">
                                                                <mapEntry>
                                                                    <name><xsl:value-of select="LabelName" /></name>
                                                                    <value>
                                                                        <xsl:value-of select="LabelID" />
                                                                    </value>
                                                                </mapEntry>
                                                            </xsl:for-each>
                                                        </map>
                                                    </xsl:variable>
                                                    <xsl:call-template name="uiDropdown">
                                                        <xsl:with-param name="items" select="$auditReportRegionListItems"/>
                                                        <xsl:with-param name="name" select="'label_id'"/>
                                                        <xsl:with-param name="id" select="'labelID'"/>
                                                        <xsl:with-param name="active" select="/Root/Params/label_id"/>
                                                        <xsl:with-param name="className" select="'AuditReport-mech-select'"/>
                                                    </xsl:call-template>
                                                </span>
                                            </label>
                                        </div>
                                        <div class="Form-item">
                                            <div class="Form-input-wrapper">
                                                <xsl:call-template name="uiButton">
                                                    <xsl:with-param name="content" select="'Update'" />
                                                    <xsl:with-param name="elemType" select="'submit'" />
                                                </xsl:call-template>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </xsl:if>
                        <div class="Table-controls-item AuditReport-controls-download">
                            <xsl:call-template name="reportDownloadLink" />
                        </div>
                        <div class="Table-controls-item Table-controls-item-pagination">
                            <xsl:call-template name="reportNav" />
                        </div>
                    </div>
                    <xsl:call-template name="licenseAccrualTable" />
                    <xsl:call-template name="reportFooter" />
                </xsl:when>
                <xsl:otherwise>
                    <section class="Table-empty-results">
                        <p>No tracks with missing licenses were found.</p>
                    </section>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
                <xsl:when test="$cmd = 'ca_license_accrual'">
                    <xsl:call-template name="backToCAMechRun" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="backToMechRun" />
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>


    <xsl:template name="licenseAccrualTable">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col">Label</th>
                    <th class="Table-col">Album Title</th>
                    <th class="Table-col">Catalog&#160;#</th>
                    <th class="Table-col">Artist</th>
                    <th class="Table-col">Track Title</th>
                    <th class="Table-col Table-col-amount">Share</th>
                    <th class="Table-col">Config</th>
                    <th class="Table-col">Year</th>
                    <th class="Table-col">Rate</th>
                    <th class="Table-col">Units</th>
                    <th class="Table-col Table-col-amount">Cumulative Accrual (<xsl:value-of select="$currencyCode" />)</th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Report/Track">
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><xsl:value-of select="LabelName" /></td>
                        <td class="Table-col">
                            <a href="/rps/catalog?c=show&amp;AlbumID={AlbumID}">
                                <xsl:value-of select="AlbumTitle" />
                            </a>
                        </td>
                        <td class="Table-col"><xsl:value-of select="CatalogNumber" /></td>
                        <td class="Table-col"><xsl:value-of select="TrackArtist" /></td>
                        <td class="Table-col">
                            <a href="/rps/track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="TrackTitle" /></a>
                        </td>
                        <td class="Table-col Table-col-amount"><xsl:value-of select="UnlicensedShare" />%</td>
                        <td class="Table-col">
                            <xsl:value-of select="ProductType" />
                        </td>
                        <td class="Table-col">
                            <xsl:value-of select="Year" />
                        </td>
                        <td class="Table-col">
                            <xsl:value-of select="Rate" />
                        </td>
                        <td class="Table-col">
                            <xsl:value-of select="Units" />
                        </td>
                        <td class="Table-col Table-col-amount">
                            $<xsl:value-of select="Accrual" />
                        </td>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>


</xsl:stylesheet>
