<!--                                                                  -->
<!--  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:template name="licenseAccrualLayout">
        <div class="section" id="auditReport">
    	    <xsl:choose>
    		    <xsl:when test="Report/Track">
    			    <div class="reportNavWrapper">
    				    <h2>
    					    Unlicensed Accrual
    					    <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> 
							<br />
							<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>
							
    				    </h2>
    				
    				    <xsl:if test="count(Report/LabelList/Label) &gt; 1">
	    				    <form method="get" action="/rps/report">
    	    					<input type="hidden" name="c" value="license_accrual" />
    	    					<input type="hidden" name="run_id" value="{Params/run_id}" />
    		    				<label for="label_id">Now Viewing: </label>
		    				    <select name="label_id" id="labelID">
    		    					<option value="">All Labels</option>
    		    					<xsl:for-each select="Report/LabelList/Label">
    		    						<option value="{LabelID}">
    		    							<xsl:if test="LabelID = /Root/Params/label_id">
    		    								<xsl:attribute name="selected">selected</xsl:attribute>
    		    							</xsl:if>
    		    							<xsl:value-of select="LabelName" />
    		    						</option>
    		    					</xsl:for-each>
		    				    </select>&#160;<input type="submit" value="Update" />
		    				    <br />
		    			    </form>
	    			    </xsl:if>    				   				
        				<xsl:call-template name="reportHeading" />
    	    			<xsl:call-template name="reportNav" />
					</div>
    		  		<xsl:call-template name="licenseAccrualTable" />
    		  		<xsl:call-template name="reportNav" />
					<br class="superBreak" />
					<br />
				</xsl:when>
				<xsl:otherwise>
					<p>No tracks with missing licenses were found.</p>
				</xsl:otherwise>
			</xsl:choose>
		</div>			
		<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>	
	</xsl:template>


	<xsl:template name="licenseAccrualTable">
        <table class="textChart hiOn">
            <tr>
              	<th>Label</th>
              	<th>Album Title</th>
              	<th>Catalog&#160;#</th>
              	<th>Artist</th>
              	<th>Track Title</th>
                <th class="amount">Share</th>
                <th>Config</th>
                <th>Year</th>
                <th>Rate</th>
                <th>Units</th>
                <th class="amount">Cumulative Accrual (<xsl:value-of select="$currencyCode" />)</th>
            </tr>
            <xsl:for-each select="Report/Track">
                <tr class="row{position() mod 2}">
        	        <td><xsl:value-of select="LabelName" /></td>
					<td>
					    <xsl:choose>
					        <xsl:when test="normalize-space(ProductTitle)">
						        <a href="/rps/product?c=show&amp;ProductID={ProductID}">
						            <xsl:value-of select="ProductTitle" />
						        </a>					            
					        </xsl:when>
					        <xsl:otherwise>
						        <a href="/rps/catalog?c=show&amp;AlbumID={AlbumID}">
						            <xsl:value-of select="AlbumTitle" />
						        </a>
						    </xsl:otherwise>
						</xsl:choose>
					</td>        	
                     <td><xsl:value-of select="CatalogNumber" /></td>
					<td><xsl:value-of select="TrackArtistName" /></td>
					<td>
						<a href="/rps/track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="TrackTitle" /></a>
					</td>
					<td class="amount"><xsl:value-of select="UnlicensedShare" />%</td>
					<td>
						<xsl:value-of select="ProductType" />
					</td>
					<td>
						<xsl:value-of select="Year" />
					</td>
					<td>
						<xsl:value-of select="Rate" />
					</td>
					<td>
						<xsl:value-of select="Units" />
					</td>
					<td class="amount">
						$<xsl:value-of select="Accrual" />
					</td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
    

</xsl:stylesheet>
