<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<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="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />
    <xsl:include href="shared.xsl" />
 
    <xsl:variable name="allContracts" select="/Root/Statement/ArtistStatement/ArtistStatementContractList/ArtistStatementContract" />

	<xsl:variable name="allAlbums" select="/Root/Statement/ArtistStatement/ArtistStatementAlbumList/ArtistStatementAlbum" />

    <!--
        If you add/remove columns from the income lines, you'll have to adjust artistColumns
        in order to get the summary lines to line up properly.
    -->
    <xsl:variable name="artistColumns">21</xsl:variable>


    <xsl:template name="pickLayout">
        <div id="artistStatement">
    	    <xsl:if test="Statement/ArtistStatement/ArtistStatementAlbumList/ArtistStatementAlbum/IncomeItemList/IncomeItem">
    	        <xsl:call-template name="statementLegend" />
    	    </xsl:if>
    	
            <xsl:call-template name="artistSummary" />
			<xsl:call-template name="transactionTable">
				<xsl:with-param name="statement" select="Statement/ArtistStatement" />
				<xsl:with-param name="transactions" select="Statement/ArtistStatement/ArtistStatementTransactionList/ArtistStatementTransaction" />
			</xsl:call-template>
			<a name="top" />
			<xsl:if test="$allAlbums or Statement/ArtistStatement/ArtistStatementLicenseIncomeItemList/LicenseIncomeItem">
      	        <xsl:call-template name="albumSummary" />
            </xsl:if>
	        <div class="section">
				<table class="statementTable">
					<xsl:for-each select="$allAlbums">
						<xsl:call-template name="albumDetails" />
					</xsl:for-each>
					<xsl:if test="Statement/ArtistStatement/ArtistStatementLicenseIncomeItemList/LicenseIncomeItem">
						<xsl:call-template name="contractLicenseIncomeSection" />
					</xsl:if>
				</table>
			</div>
        </div>
		<xsl:call-template name="buttons" />
    </xsl:template>
  
  
	<xsl:template name="statementLegend">  	 
		<div class="statementLegend"> 	 
			<h3>Source Abbreviations</h3> 	 
			<dl> 	 		
				<xsl:for-each select="Statement/IncomeSourceList/IncomeSource">
					<xsl:sort select="Name" />
					<xsl:variable name="sourceID" select="IncomeSourceID" />
					<xsl:if test="/Root/Statement/ArtistStatement/ArtistStatementIncomeSourceList/IncomeSource = $sourceID">
                		<dt><xsl:value-of select="Name" /></dt>
                		<dd>
                			<xsl:choose>
                				<xsl:when test="Name = 'DA'">Digital Album Permanent Download</xsl:when>
                				<xsl:when test="Name = 'DA-P'">Premium Digital Album Download</xsl:when>
                				<xsl:when test="Name = 'DA-U'">Digital Album Download Upgrade</xsl:when>
                				<xsl:when test="Name = 'DT'">Digital Track Permanent Download</xsl:when>
                				<xsl:when test="Name = 'DT-P'">Premium Digital Track Download</xsl:when>
                				<xsl:when test="Name = 'DT-U'">Digital Track Download Upgrade</xsl:when>
                				<xsl:when test="Name = 'DTETH'">Digital Tethered Download</xsl:when>
                				<xsl:when test="Name = 'VPD'">Variable Priced Download</xsl:when>
                				<xsl:otherwise>
                					<xsl:value-of select="Description" />
                				</xsl:otherwise>
                			</xsl:choose>
                		</dd>
                	</xsl:if>
                </xsl:for-each>			
			</dl> 	 
		</div> 	 
	</xsl:template>


    <xsl:template name="artistSummary">
		<div id="statementSummary">
			<div class="statementInfo">
				<xsl:call-template name="payeeInfo">
                    <xsl:with-param name="payee" select="Statement/ArtistStatement/ArtistPayee" />
                </xsl:call-template>
                <br /><br />
				<strong><xsl:value-of select="Statement/ArtistRoyaltyRun/Label" /></strong>
				<xsl:if test="Statement/ArtistRoyaltyRun/CanDownload = 1">
					<br /><br />
        	        <a href="?c=pdf_artist&amp;ArtistStatementID={Statement/ArtistStatement/ArtistRoyaltyStatementID}" title="Download PDF">
        		        <img src="/production/images/pdficon_small.gif" height="17" width="17" class="pdfIcon" />
					</a>
        	        <a href="?c=pdf_artist&amp;ArtistStatementID={Statement/ArtistStatement/ArtistRoyaltyStatementID}">Artist/Producer View</a>
				</xsl:if>
				<xsl:if test="Statement/ArtistRoyaltyRun/CanDownloadExcel = 1">
					<br /><br />
        	        <a href="?c=excel_artist&amp;ArtistStatementID={Statement/ArtistStatement/ArtistRoyaltyStatementID}" title="Download Excel">
                    <img src="/production/images/icons/excel16.gif" height="16" width="16" />
					</a>&#160; <a href="?c=excel_artist&amp;ArtistStatementID={Statement/ArtistStatement/ArtistRoyaltyStatementID}">Artist/Producer View</a>
				</xsl:if>
            </div>
        </div>
        <br />
    </xsl:template>


	<xsl:template name="albumSummary">
		<div class="section" id="albumSummary">
			<table>
				<tr>
					<th></th>
					<th>Type</th>
					<th>Album</th>
					<th class="amount">Sales</th>
					<th class="amount">License Income</th>
					<th class="amount">Expenses</th>
					<th class="amount">Previous Balance</th>
					<th class="amount">Total</th>
				</tr>
				<xsl:if test="//IsCrossCollateralized = 1 or Statement/ArtistStatement/ArtistStatementLicenseIncomeItemList/LicenseIncomeItem">
					<xsl:for-each select="$allAlbums[IsCrossCollateralized = 1]">
						<xsl:call-template name="artistAlbumSummaryRow" />
					</xsl:for-each>
					<xsl:if test="Statement/ArtistStatement/ArtistStatementLicenseIncomeItemList/LicenseIncomeItem or translate(Statement/ArtistStatement/ContractLevelLicenseIncomeSubtotal, translate(Statement/ArtistStatement/ContractLevelLicenseIncomeSubtotal, '0123456789', ''), '') != 0 or translate(Statement/ArtistStatement/ContractLevelLicenseIncomePreviousBalance, translate(Statement/ArtistStatement/ContractLevelLicenseIncomePreviousBalance, '0123456789', ''), '') != 0">
						<xsl:call-template name="licenseIncomeSummaryRow">
							<xsl:with-param name="crossedAlbumCount" select="count($allAlbums[IsCrossCollateralized = 1])" />
						</xsl:call-template>
					</xsl:if>
					<xsl:call-template name="crossCollateralizedTotal" />
				</xsl:if>
        <xsl:if test="//IsCrossCollateralized = 0">
	        <xsl:for-each select="$allAlbums[IsCrossCollateralized = 0]">
  	        <xsl:call-template name="artistAlbumSummaryRow" />
    	    </xsl:for-each>
					<tr>
						<td class="statementLabel total">Total:</td>
						<td colspan="7" class="total amount">
							<xsl:value-of select="Statement/ArtistStatement/Total" />				
						</td>
					</tr>
				</xsl:if>
			</table>
		</div>
	</xsl:template>


  <xsl:template name="crossCollateralizedTotal">
		<tr class="totalRow">
			<td></td>
			<td class="total">Total:</td>
			<td class="total"></td>
	    <td class="amount total">
	      <xsl:value-of select="Statement/ArtistStatement/CrossCollateralizedIncomeSubTotal" />
			</td>
	    <td class="amount total">
	      <xsl:value-of select="Statement/ArtistStatement/LicenseIncomeSubtotal" />
			</td>						
	    <td class="amount total">
	      <xsl:value-of select="Statement/ArtistStatement/CrossCollateralizedExpenseSubTotal" />
	    </td>
	    <td class="amount total">
	      <xsl:value-of select="Statement/ArtistStatement/CrossCollateralizedPreviousBalance" />
	    </td>
	    <td class="amount total">
	      <xsl:value-of select="Statement/ArtistStatement/CrossCollateralizedSubTotal" />
	    </td>
		</tr>  
  </xsl:template>


	<xsl:template name="artistAlbumSummaryRow">
		<tr>
			<td class="statementLabel">
				<xsl:if test="position() = 1">
					<xsl:if test="IsCrossCollateralized = 1">Crossed Totals</xsl:if>
	        <xsl:if test="IsCrossCollateralized = 0">Uncrossed Totals</xsl:if>
				</xsl:if>
			</td>
			<td>
				Product Sales
			</td>
			<td>
				<a href="#{Album/AlbumID}">
					<xsl:value-of select="Album/Title" />
				</a>
			</td>
			<td class="amount">
				<xsl:value-of select="TotalIncome" />
			</td>
			<td class="amount">
				<xsl:value-of select="LicenseIncomeSubtotal" />
			</td>			
			<td class="amount">
				<xsl:value-of select="TotalExpenses" />
			</td>
			<td class="amount">
				<xsl:value-of select="PreviousBalance" />
			</td>
			<td class="amount">
				<xsl:value-of select="Total" />
			</td>
		</tr>
	</xsl:template>


	<xsl:template name="licenseIncomeSummaryRow">
		<xsl:param name="crossedAlbumCount" />
		<tr>
			<td class="statementLabel">
				<xsl:if test="$crossedAlbumCount = 0">
					Crossed Totals
				</xsl:if>
			</td>
			<td>
				Contract License Income
			</td>
			<td></td>
			<td></td>
			<td class="amount">
				<xsl:value-of select="Statement/ArtistStatement/ContractLevelLicenseIncomeSubtotal" />
			</td>
			<td class="amount">		
			</td>
			<td class="amount">		
				<xsl:value-of select="Statement/ArtistStatement/ContractLevelLicenseIncomePreviousBalance" />
			</td>
			<td class="amount">
				<xsl:value-of select="Statement/ArtistStatement/ContractLevelLicenseIncomeTotal" />
			</td>
		</tr>
	</xsl:template>


  <xsl:template name="payeeInfo">
		<xsl:param name="payee" />
		<a href="/rps/artist_payee?ArtistPayeeID={$payee/ArtistPayeeID}&amp;c=show">
      <xsl:value-of select="$payee/Name" />
    </a>
    <xsl:if test="normalize-space($payee/ClientAccountID)">
      <br />
      Client #: <xsl:value-of select="$payee/ClientAccountID" />
    </xsl:if>
    <xsl:if test="normalize-space($payee/StreetAddress)">
      <br />
      <xsl:value-of select="$payee/StreetAddress" />
    </xsl:if>
    <xsl:if test="normalize-space($payee/StreetAddress2)">
      <br />
      <xsl:value-of select="$payee/StreetAddress2" />
    </xsl:if>    
    <xsl:if test="normalize-space($payee/StreetAddress3)">
      <br />
      <xsl:value-of select="$payee/StreetAddress3" />
    </xsl:if>    
    <xsl:if test="normalize-space($payee/City) or normalize-space($payee/StateProvince)">
      <br />
      <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" />
    </xsl:if>
    <xsl:if test="normalize-space($payee/CountryCode)">
      <br />
      <xsl:value-of select="$payee/CountryCode" />
    </xsl:if>
    <xsl:if test="normalize-space($payee/ArtistName)">
      <br /><br />
      Artist Name: <xsl:value-of select="$payee/ArtistName" />
    </xsl:if>
  </xsl:template>


    <xsl:template name="albumDetails">
		<tr>
			<td colspan="{$artistColumns}" class="albumDetailsTitle">
                <a name="{Album/AlbumID}" href="/rps/catalog?AlbumID={Album/AlbumID}&amp;c=show">
		            <xsl:value-of select="Album/Title" /> (<xsl:value-of select="Album/CatalogNumber" />)
    		    </a>
		        <a href="#top" title="back to top"><img src="/production/images/icons/mini/arrow_up.gif" /></a>
                <a href="/rps/artist_contract?ArtistContractID={ArtistContractID}&amp;c=show">
		            <xsl:value-of select="ContractName" />
    		    </a>
                <xsl:if test="IsCrossCollaterallized = 1">Cross Collaterallized</xsl:if>
			</td>
		</tr>
		
		<xsl:variable name="showUnitRoyalties">
			<xsl:for-each select="IncomeItemList/IncomeItem">
      	        <xsl:if test="ContractRateTypeID != 5 and ContractRateTypeID != 9">1</xsl:if>
			</xsl:for-each>
		</xsl:variable>
		
		<xsl:if test="$showUnitRoyalties > 0">
  		    <xsl:call-template name="unitRoyaltiesSection" />
		</xsl:if>
		
        <xsl:variable name="showNetRoyalties">
            <xsl:for-each select="IncomeItemList/IncomeItem">
                <xsl:if test="ContractRateTypeID = 5">1</xsl:if>
            </xsl:for-each>
        </xsl:variable>
        
        <xsl:if test="$showNetRoyalties > 0">
            <xsl:call-template name="netRoyaltiesSection" />
        </xsl:if>
        
        <xsl:variable name="showNonPayableRoyalties">
            <xsl:for-each select="IncomeItemList/IncomeItem">
                <xsl:if test="ContractRateTypeID = 9">1</xsl:if>
            </xsl:for-each>
        </xsl:variable>
        
        <xsl:if test="$showNonPayableRoyalties > 0">
            <xsl:call-template name="nonPayableRoyaltiesSection" />
        </xsl:if>        
        
		<xsl:if test="LicenseIncomeItemList/LicenseIncomeItem">
  		    <xsl:call-template name="licenseIncomeSection" />
		</xsl:if>
				    
        <xsl:variable name="showNetExpenses">
            <xsl:for-each select="ExpenseItemList/ExpenseItem">
                <xsl:if test="UsesDefaultNetRate = 1">1</xsl:if>
            </xsl:for-each>
        </xsl:variable>
        
        <xsl:if test="$showNetExpenses > 0">
            <xsl:call-template name="netExpensesSection" />
        </xsl:if>
        
        <xsl:variable name="showRecoupExpenses">
		    <xsl:for-each select="ExpenseItemList/ExpenseItem">
                <xsl:if test="UsesDefaultNetRate = 0">1</xsl:if>
		    </xsl:for-each>
        </xsl:variable>
        
		<xsl:if test="$showRecoupExpenses > 0">
            <xsl:call-template name="recoupExpensesSection" />
		</xsl:if>
		
		<xsl:call-template name="albumTotalRow" />
		
	</xsl:template>


    <xsl:template name="unitRoyaltiesSection">
		<tr>
			<td colspan="{$artistColumns}" class="heading statementLabel">Unit Royalties</td>
		</tr>
        <xsl:call-template name="unitRoyaltiesHeader" />
        <xsl:for-each select="IncomeItemList/IncomeItem[ContractRateTypeID != 5 and ContractRateTypeID != 9]">
            <xsl:call-template name="incomeItemRow" />
        </xsl:for-each>
		<xsl:call-template name="unitRevenueTotalRow" />
        <tr>
            <td colspan="{$artistColumns}" class="total"></td>
        </tr>
    </xsl:template>
  
  
    <xsl:template name="unitRoyaltiesHeader">
        <tr class="statementHeader">
            <th>Track Title</th>
            <th>Source</th>
            <th>Region</th>
            <th>Channel</th>
			<th>Price Tier</th>
			<th>Sales Price</th>
			<th>Rate Type</th>
			<th class="percent">Base Rate</th>
			<th class="amount">Proration</th>
            <th class="percent">Prorated Rate</th>
            <th class="percent">Rate Reduction</th>
  	        <th class="percent">Packaging</th>
			<th class="amount">Effective Rate</th>
			<th class="amount">Gross Units</th>
			<th class="percent">% of Sales</th>
	        <th class="percent">Free Goods</th>
	        <th class="amount">Reserves</th>
            <th class="amount">Liquidations</th>
			<th class="amount">Returns</th>
            <th class="amount">Net Units</th>
            <th class="amount">Total</th>
        </tr>
    </xsl:template>  


    <xsl:template name="netRoyaltiesSection">
        <tr>
  	        <td colspan="{$artistColumns}" class="heading statementLabel">Net Revenue Royalties</td>
        </tr>
        <xsl:call-template name="netRoyaltiesHeader" />
        <xsl:for-each select="IncomeItemList/IncomeItem[ContractRateTypeID = 5]">
	        <xsl:call-template name="incomeItemRow" />
 		</xsl:for-each>
        <xsl:call-template name="netRevenueTotalRow" />
   	    <tr>
     	    <td colspan="{$artistColumns}" class="total"></td>
        </tr>
    </xsl:template>


    <xsl:template name="netRoyaltiesHeader">
        <tr class="statementHeader">
            <th colspan="3">
				Track Title
			</th>
            <th>Source</th>
            <th>Region</th>
            <th>Channel</th>
            <th>Rate Type</th>
			<th class="percent">Base Rate</th>
			<th class="amount">Proration</th>
            <th class="percent">Prorated Rate</th>
            <th class="percent">Rate Reduction</th>
	        <th class="percent">Packaging</th>
    	    <th class="percent">Effective Rate</th>
    	    <th class="amount">Gross Sales</th>
            <th class="percent">% of Sales</th>
			<th class="percent">Free Goods</th>
  	        <th class="amount">Reserves</th>
    	    <th class="amount">Liquidations</th>
			<th class="amount">Net Units</th>
            <th class="amount">Net Sales</th>
            <th class="amount">Total</th>
        </tr>
    </xsl:template>


    <xsl:template name="nonPayableRoyaltiesSection">
        <tr>
  	        <td colspan="{$artistColumns}" class="heading statementLabel">Non-Payable Royalties</td>
        </tr>
        <xsl:call-template name="nonPayableRoyaltiesHeader" />
        <xsl:for-each select="IncomeItemList/IncomeItem[ContractRateTypeID = 9]">
	        <xsl:call-template name="nonPayableItemRow" />
 		</xsl:for-each>
        <xsl:call-template name="nonPayableRevenueTotalRow" />
   	    <tr>
     	    <td colspan="{$artistColumns}" class="total"></td>
        </tr>
    </xsl:template>


    <xsl:template name="nonPayableRoyaltiesHeader">
        <tr class="statementHeader">
            <th colspan="3">
				Track Title
			</th>
            <th colspan="2">Source</th>
            <th colspan="2">Region</th>
            <th colspan="2">Channel</th>
            <th colspan="2">Rate Type</th>
    	    <th class="percent" colspan="2">Effective Rate</th>
    	    <th class="amount" colspan="2">Gross Units</th>
    	    <th class="amount" colspan="2">Gross Sales</th>
            <th class="amount" colspan="2">Total</th>
        </tr>
    </xsl:template>
    
    
    <xsl:template name="nonPayableItemRow">
        <tr>
            <td colspan="3">
                <a href="track?c=show&amp;TrackID={TrackID}">
                    <xsl:value-of select="TrackName" />
				</a>
            </td>
            <xsl:variable name="sourceID" select="IncomeSourceID" />
            <xsl:variable name="sourceName" select="/Root/Statement/IncomeSourceList/IncomeSource[IncomeSourceID = $sourceID]/Name" />
            <td colspan="2">
				<xsl:value-of select="$sourceName" />
			</td>
            <td colspan="2">
                <xsl:variable name="regionID" select="RegionID" />
                <xsl:variable name="regionName" select="/Root/Statement/RegionList/Region[RegionID = $regionID]/Name" />
				<xsl:choose>
					<xsl:when test="$regionID = 0 and UsesDefaultNetRate = 1">All</xsl:when>
					<xsl:when test="substring($regionName,21)">
						<xsl:value-of select="substring($regionName,1,18)" />...
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$regionName" />
					</xsl:otherwise>
				</xsl:choose>
			</td>
            <td colspan="2">
                <xsl:variable name="channelID" select="ChannelID" />
                <xsl:value-of select="/Root/Statement/ChannelList/Channel[ChannelID = $channelID]/Name" />
			</td>
			<xsl:variable name="rateID" select="ContractRateTypeID" />
   	        <td colspan="2">
 	            <xsl:value-of select="/Root/Statement/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateID]/Name" />
			</td>
			<td class="percent" colspan="2">
	            0%
			</td>
			<td class="amount" colspan="2">
                <xsl:value-of select="Sales" />
			</td>
			<td class="amount" colspan="2">
                <xsl:value-of select="Revenue" />
			</td>			
            <td class="amount" colspan="2">
                <xsl:value-of select="Total" />
            </td>
        </tr>
    </xsl:template>    


    <xsl:template name="incomeItemRow">
        <tr>
            <td>
                <xsl:if test="ContractRateTypeID = 5">
					<xsl:attribute name="colspan">3</xsl:attribute>
				</xsl:if>
                <a href="track?c=show&amp;TrackID={TrackID}">
                    <xsl:value-of select="TrackName" />
				</a>
            </td>
            <xsl:variable name="sourceID" select="IncomeSourceID" />
            <xsl:variable name="sourceName" select="/Root/Statement/IncomeSourceList/IncomeSource[IncomeSourceID = $sourceID]/Name" />
            <td>
				<xsl:value-of select="$sourceName" />
			</td>
            <td>
                <xsl:variable name="regionID" select="RegionID" />
                <xsl:variable name="regionName" select="/Root/Statement/RegionList/Region[RegionID = $regionID]/Name" />
				<xsl:choose>
					<xsl:when test="$regionID = 0 and UsesDefaultNetRate = 1">All</xsl:when>
					<xsl:when test="substring($regionName,21)">
						<xsl:value-of select="substring($regionName,1,18)" />...
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$regionName" />
					</xsl:otherwise>
				</xsl:choose>
			</td>
            <td>
                <xsl:variable name="channelID" select="ChannelID" />
                <xsl:value-of select="/Root/Statement/ChannelList/Channel[ChannelID = $channelID]/Name" />
			</td>
			<xsl:variable name="rateID" select="ContractRateTypeID" />
			<xsl:if test="ContractRateTypeID != 5">
				<td>
					<xsl:if test="/Root/Statement/IncomeSourceList/IncomeSource[IncomeSourceID = $sourceID]/Format = 1">
  			            <xsl:variable name="priceID" select="PriceLevelID" />
						<xsl:value-of select="/Root/Statement/PriceLevelList/PriceLevel[PriceLevelID = $priceID]/Name" />
					</xsl:if>
	    	    </td>
				<td>
					<xsl:if test="/Root/Statement/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateID]/Name != 'Fixed'">
	  	                <xsl:value-of select="Price" />
					</xsl:if>
				</td>
			</xsl:if>
   	        <td>
 	            <xsl:value-of select="/Root/Statement/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateID]/Name" />
			</td>

			<!-- FB113: Update Rate (now Base Rate) cell -->
			<td class="amount">
	            <xsl:choose>
					<xsl:when test="/Root/Statement/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateID]/Fixed = 1"> 
	    	            <xsl:value-of select="BaseRate" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="class">percent</xsl:attribute>
  		  	            <xsl:value-of select="BaseRate" />%
					</xsl:otherwise>
				</xsl:choose>
			</td>

			<!-- FB113: Add Proration cell (tracks only) -->
			<td class="center">
	          <xsl:choose>
			    <xsl:when test = "TrackID = '0'">
				  &#160;
				</xsl:when>
				<xsl:otherwise>
                  <!--
                     Until we get the proration baked into the contract reserves, any income
                     items due to liquidations won't have any proration information.  Displaying
                     a "1" gets confusing if the effective rate is less than the base rate, so
                     just display a blank space for now. -ES
                  -->
				  <xsl:choose>
				    <!--xsl:when test="ProrateTrackCount = 0">1</xsl:when-->
				    <xsl:when test="ProrateTrackCount = 0"> </xsl:when>
                    <xsl:otherwise>
				      <xsl:value-of select="ProrateTrackCount" />
                    </xsl:otherwise>
				  </xsl:choose>

				</xsl:otherwise>
	          </xsl:choose>
			</td>

			<!-- FB113: Add Prorated Rate cell (tracks only) -->
			<td class="amount">
	          <xsl:choose>
			    <xsl:when test = "TrackID = '0'">
				  &#160;
				</xsl:when>
				<xsl:otherwise>
	              <xsl:choose>
					  <xsl:when test="/Root/Statement/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateID]/Fixed = 1"> 
	    	              <xsl:value-of select="Rate" />
					  </xsl:when>
					  <xsl:otherwise>
						  <xsl:attribute name="class">percent</xsl:attribute>
  		  	              <xsl:value-of select="Rate" />%
					  </xsl:otherwise>
				  </xsl:choose>
				</xsl:otherwise>
	          </xsl:choose>
			</td>

			<td class="percent">
  	            <xsl:value-of select="RateReduction" />%
			</td>
            <td class="percent">
                <xsl:value-of select="PackagingDeduction" />%
            </td>
            <td class="percent">
                <xsl:choose>
                    <xsl:when test="ContractRateTypeID = 5">
                        <xsl:value-of select="NetRate" />%
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">amount</xsl:attribute>
                        <xsl:value-of select="NetRate" />
                    </xsl:otherwise>
                </xsl:choose>
            </td>
			<td class="amount">
                <xsl:choose>
                    <xsl:when test="ContractRateTypeID = 5">
                        <xsl:value-of select="Revenue" />
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="Sales" />
                    </xsl:otherwise>
                </xsl:choose>
			</td>
  	        <td class="percent">
	            <xsl:value-of select="PercentageOfSales" />%
            </td>
  	        <td class="percent">
      	        <xsl:value-of select="FreeGoodsDeduction" />%
	        </td>
			<td class="amount">
				<xsl:choose>
					<xsl:when test="ContractRateTypeID = 5">
    		  	        <xsl:value-of select="RevenueReserved" />
					</xsl:when>
					<xsl:otherwise>
      	                <xsl:value-of select="UnitsReserved" />
					</xsl:otherwise>
				</xsl:choose>
			</td>
            <td class="amount">
	            <xsl:choose>
  	                <xsl:when test="ContractRateTypeID = 5">
      	                <xsl:value-of select="RevenueLiquidated" />
                    </xsl:when>
	                <xsl:otherwise>
    	                <xsl:value-of select="UnitsLiquidated" />
        	        </xsl:otherwise>
                </xsl:choose>
	        </td>
	        <xsl:if test="ContractRateTypeID != 5">
      	        <td class="amount">
         	        <xsl:value-of select="Returns" />
      	        </td>
            </xsl:if>
			<xsl:if test="ContractRateTypeID = 5">
				<td class="amount">
  		            <xsl:value-of select="NetUnits" />				
				</td>
			</xsl:if>
			<td class="amount">
				<xsl:choose>
					<xsl:when test="ContractRateTypeID = 5">
  	                    <xsl:value-of select="NetRevenue" />
					</xsl:when>
					<xsl:otherwise>
  		                <xsl:value-of select="NetUnits" />
					</xsl:otherwise>
				</xsl:choose>
			</td>
            <td class="amount">
                <xsl:value-of select="Total" />
            </td>
        </tr>
    </xsl:template>


    <xsl:template name="unitRevenueTotalRow">
		<xsl:call-template name="totalRow">
			<xsl:with-param name="title">Unit Level Income</xsl:with-param>
			<xsl:with-param name="total" select="UnitLevelIncome" />
		</xsl:call-template>
    </xsl:template>


    <xsl:template name="netRevenueTotalRow">
        <xsl:call-template name="totalRow">
            <xsl:with-param name="title">Net Revenue Total</xsl:with-param>
            <xsl:with-param name="total" select="NetRevenueIncome" />
        </xsl:call-template>
    </xsl:template>
    

    <xsl:template name="nonPayableRevenueTotalRow">
        <xsl:call-template name="totalRow">
            <xsl:with-param name="title">Non-Payable Royalties Total</xsl:with-param>
            <xsl:with-param name="total"><xsl:value-of select="/Root/Client/Locale/CurrencyFormat/Symbol" />0<xsl:value-of select="/Root/Client/Locale/NumericFormat/Decimal" />00</xsl:with-param>
        </xsl:call-template>
    </xsl:template>    


  <xsl:template name="albumTotalRow">
    <tr>
      <td colspan="{$artistColumns - 5}" class="emptyCell"></td>
      <td colspan="4" class="amount"><strong>Album Previous Balance:</strong></td>
      <td class="amount">
        <xsl:value-of select="PreviousBalance" />
      </td>
    </tr>
    <xsl:call-template name="totalRow">
      <xsl:with-param name="title">Album Total</xsl:with-param>
      <xsl:with-param name="total" select="Total" />
    </xsl:call-template>
  </xsl:template>


  <xsl:template name="netExpensesSection">
    <tr>
      <td colspan="{$artistColumns}" class="statementLabel heading">Net Expenses</td>
    </tr>
    <xsl:call-template name="expenseHeaderRow" />
    <xsl:for-each select="ExpenseItemList/ExpenseItem[UsesDefaultNetRate = 1]">
      <xsl:call-template name="expenseItemRow" />
    </xsl:for-each>
    <xsl:call-template name="netExpensesTotalRow" />
    <tr>
      <td colspan="{$artistColumns}" class="total"></td>
    </tr>
  </xsl:template>


  <xsl:template name="recoupExpensesSection">
    <tr>
      <td colspan="{$artistColumns}" class="statementLabel heading">Recoupable Expenses</td>
    </tr>
    <xsl:call-template name="expenseHeaderRow" />
    <xsl:for-each select="ExpenseItemList/ExpenseItem[UsesDefaultNetRate = 0]">
      <xsl:call-template name="expenseItemRow" />
    </xsl:for-each>
		<xsl:call-template name="recoupExpensesTotalRow" />
    <tr>
      <td colspan="{$artistColumns}" class="total"></td>
    </tr>
	</xsl:template>
	

  <xsl:template name="expenseHeaderRow">
		<tr>
			<th colspan="{$artistColumns - 8}"></th>
			<th colspan="3" class="heading">Description</th>
			<th colspan="2" class="heading">Memo</th>
			<th class="amount heading">Cost</th>
      <th class="percent heading">Rate</th>
      <th class="amount heading">Total</th>
		</tr>
	</xsl:template>
	
	
	<xsl:template name="expenseItemRow">
    <tr>
      <td colspan="{$artistColumns - 8}"></td>
      <td colspan="3"><xsl:value-of select="ExpenseName" /></td>
      <td colspan="2"><xsl:value-of select="Memo" /></td>
      <td class="amount">
        <xsl:value-of select="Cost" />
      </td>
      <td class="percent">
        <xsl:value-of select="Rate" />%
      </td>
      <td class="amount">
        <xsl:value-of select="Total" />
      </td>
    </tr>
	</xsl:template>	


  <xsl:template name="netExpensesTotalRow">
    <xsl:call-template name="totalRow">
      <xsl:with-param name="title">Net Expenses Total</xsl:with-param>
      <xsl:with-param name="total" select="NetRevenueExpenses" />
    </xsl:call-template>
    <tr>
      <td colspan="{$artistColumns - 5}" class="emptyCell"></td>
      <td colspan="4" class="amount"><strong>Net Rate:</strong></td>
      <td class="amount">
        <xsl:value-of select="DefaultNetRevenueRate" />%
      </td>
    </tr>
    <xsl:call-template name="totalRow">
      <xsl:with-param name="title">Net Expenses Adjusted Total</xsl:with-param>
      <xsl:with-param name="total" select="NetRevenueExpensesSubTotal" />
    </xsl:call-template>
  </xsl:template>


  <xsl:template name="recoupExpensesTotalRow">
    <xsl:call-template name="totalRow">
      <xsl:with-param name="title">Recoupable Expenses Total</xsl:with-param>
      <xsl:with-param name="total" select="RecoupableExpenses" />
    </xsl:call-template>
  </xsl:template>
 
 
  <xsl:template name="licenseIncomeSection">
    <tr>
      <td colspan="{$artistColumns}" class="statementLabel heading">License Income Royalties</td>
    </tr>
    <xsl:call-template name="licenseIncomeHeaderRow" />
    <xsl:for-each select="LicenseIncomeItemList/LicenseIncomeItem">
      <xsl:call-template name="licenseIncomeItemRow" />
    </xsl:for-each>
		<xsl:call-template name="licenseIncomeTotalRow" />
    <tr>
      <td colspan="{$artistColumns}" class="total"></td>
    </tr>
	</xsl:template>  	


  <xsl:template name="contractLicenseIncomeSection">
    <tr>
      <td colspan="{$artistColumns}" class="heading contractDetailsTitle">Contract Level License Income Royalties</td>
    </tr>
    <xsl:call-template name="licenseIncomeHeaderRow">
    	<xsl:with-param name="contractLevel" select="'1'" />
    </xsl:call-template>
    <xsl:for-each select="Statement/ArtistStatement/ArtistStatementLicenseIncomeItemList/LicenseIncomeItem">
      <xsl:call-template name="licenseIncomeItemRow">
    	<xsl:with-param name="contractLevel" select="'1'" />
    </xsl:call-template>      
    </xsl:for-each>
		<xsl:call-template name="contractLicenseIncomeTotalRow" />
	</xsl:template>  
	
	
  <xsl:template name="contractLicenseIncomeTotalRow">
    <xsl:call-template name="totalRow">
      <xsl:with-param name="title">License Income Total</xsl:with-param>
      <xsl:with-param name="total" select="Statement/ArtistStatement/ContractLevelLicenseIncomeSubtotal" />
    </xsl:call-template>
  </xsl:template>			
	

  <xsl:template name="licenseIncomeHeaderRow">
  	<xsl:param name="contractLevel" select="'0'" />
		<tr class="statementHeader">
			<th colspan="{$artistColumns - 14}">
				<xsl:choose>
				  <xsl:when test="$contractLevel = 1">Contract Title</xsl:when>
				  <xsl:otherwise>Track Title</xsl:otherwise>			
				</xsl:choose>
			</th>
			<th colspan="3">Income Type</th>
			<th colspan="5">Memo</th>
			<th colspan="2">Rate Type</th>
			<th class="percent">Base Rate</th>   
      <th class="amount">Units</th>
      <th class="amount">Sales</th>
      <th class="amount">Total</th>
		</tr>
	</xsl:template>


  <xsl:template name="licenseIncomeItemRow">
  	<xsl:param name="contractLevel" select="'0'" />
		<tr>
			<td colspan="{$artistColumns - 14}">
				<xsl:choose>
				  <xsl:when test="$contractLevel = 1">
				    <a href="/rps/artist_contract?c=show&amp;ArtistContractID={ArtistContractID}"><xsl:value-of select="ContractTitle" /></a>
				  </xsl:when>
				  <xsl:otherwise>
				    <a href="/rps/track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="TrackName" /></a>
				  </xsl:otherwise>
			  </xsl:choose>   
			</td>
			<td colspan="3">
				<xsl:variable name="typeID" select="LicenseIncomeTypeID" />
			  <xsl:value-of select="/Root/Statement/LicenseIncomeTypeList/LicenseIncomeType[LicenseIncomeTypeID = $typeID]/Name" />
			</td>
      <td colspan="5">
        <xsl:value-of select="Memo" />
      </td>			
			<td colspan="2">
			  % Net Revenue
			</td>
			<td class="percent">
			  <xsl:value-of select="Rate" />%   
			</td>
      <td class="amount">
        <xsl:value-of select="Units" />
      </td>
      <td class="amount">
        <xsl:value-of select="Revenue" />
      </td>
      <td class="amount">
        <xsl:value-of select="NetRevenue" />
      </td>
		</tr>
	</xsl:template>


  <xsl:template name="licenseIncomeTotalRow">
    <xsl:call-template name="totalRow">
      <xsl:with-param name="title">License Income Total</xsl:with-param>
      <xsl:with-param name="total" select="LicenseIncomeSubtotal" />
    </xsl:call-template>
  </xsl:template>


  <xsl:template name="totalRow">
		<xsl:param name="title" />
		<xsl:param name="total" />
    <tr class="totalRowInline">
      <td colspan="{$artistColumns - 5}" class="emptyCell"></td>
      <td colspan="4" class="amount"><strong><xsl:value-of select="$title" />:</strong></td>
      <td class="amount total">
        <xsl:value-of select="$total" />
      </td>
    </tr>
  </xsl:template>


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

    <xsl:template name="cancelButton">
        <input type="button" name="Back" value="Back to Statements" onClick="location.href='artist_royalty?RoyaltyRunID={Statement/ArtistRoyaltyRun/ArtistRoyaltyRunID}&amp;c=show&amp;PayorID={Statement/ArtistStatement/PayorID}'" />
    </xsl:template>
  

</xsl:stylesheet>

