<!--                                                                  -->
<!--  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="artistRoyaltyShowTop" />
    <div class="section" id="artistRoyaltyShow">
			<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" />
    	<xsl:call-template name="mailingListLink" />
    	<br class="superBreak" />
    	<xsl:choose>
    		<xsl:when test="ArtistRoyaltyRun/ArtistRoyaltyStatementList/ArtistStatement">
	 	    	<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="artistRoyaltyShowTop">
		<xsl:choose>
			<xsl:when test="ArtistRoyaltyRun/CanDownload = 1">
				<div class="twoSections" id="artistShowTop">
			  	<div class="sectionLeft">			
			  		<xsl:call-template name="artistRoyaltyReports" />
			  	</div>	
			  	<div class="sectionRight">
			  		<xsl:call-template name="downloadAll" />
			  	</div>
			  </div>
			</xsl:when>
			<xsl:otherwise>
				<div class="section" id="artistShowTop">
					<xsl:call-template name="artistRoyaltyReports" />
				</div>
  		</xsl:otherwise>
  	</xsl:choose>
  </xsl:template>	
  
	<xsl:template name="artistRoyaltyReports">
		<div class="auditReportsWrapper">
  		<h2>Audit Reports</h2>
  		<ul>
  			<li><a href="report?c=missed_sales&amp;run_id={ArtistRoyaltyRun/ArtistRoyaltyRunID}">Unallocated Sales</a></li>
  			<li>
  				<xsl:choose>
  					<xsl:when test="ArtistRoyaltyRun/PipelineReportAvailable = 1">
  						<a href="report?c=artist_reserve_pipeline&amp;run_id={ArtistRoyaltyRun/ArtistRoyaltyRunID}">Reserve Pipeline</a>
  					</xsl:when>
  					<xsl:otherwise>
  						<span class="subtle">Reserve Pipeline</span>
  						<xsl:call-template name="helpIcon">
  							<xsl:with-param name="tip">Not available for this royalty run</xsl:with-param>
  						</xsl:call-template>
  					</xsl:otherwise>
  				</xsl:choose>
  			</li>
  		</ul>
  	</div>
	</xsl:template>		  

	<xsl:template name="downloadAll">	  	
		<!--div class="downloadWrapper"-->
		<div class="auditReportsWrapper">
  		<h2>Download Statements</h2>
			<table style="font-weight: normal">
				<tr>
					<td>
						<a href="?c=pdf&amp;RoyaltyRunID={ArtistRoyaltyRun/ArtistRoyaltyRunID}" title="Download All Statements With Activity" class="iconLink">
							<img src="/production/images/icons/office/Harddisk-(Download)-(16x16.gif" height="16" width="16" />
						</a> 
						<a href="?c=pdf&amp;RoyaltyRunID={ArtistRoyaltyRun/ArtistRoyaltyRunID}">Download All Statements With Activity</a>

						<!-- Add links for Current Period and/or Album Balance report if they're ready -->

						<xsl:choose>
							<xsl:when test="ArtistRoyaltyRun/CanDownloadCPExcel = 1 and ArtistRoyaltyRun/CanDownloadCPText = 1">
								<div>
									<a href="?c=cp_text&amp;RoyaltyRunID={ArtistRoyaltyRun/ArtistRoyaltyRunID}" title="Text" class="iconLink">
										<img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" />
										</a>
									<a href="?c=cp_excel&amp;RoyaltyRunID={ArtistRoyaltyRun/ArtistRoyaltyRunID}" title="Excel" class="iconLink">
										<img src="/production/images/icons/excel16.gif" height="16" width="16" />
									</a>
  								Current Period Royalties
								</div>
							</xsl:when>
							<xsl:otherwise>
								<div>
  								<span class="subtle">Current Period Royalties</span>
  								<xsl:call-template name="helpIcon">
  									<xsl:with-param name="tip">Not available for this royalty run</xsl:with-param>
  								</xsl:call-template>
								</div>
							</xsl:otherwise>
  					</xsl:choose>

						<xsl:choose>
							<xsl:when test="ArtistRoyaltyRun/CanDownloadABExcel = 1 and ArtistRoyaltyRun/CanDownloadABText = 1">
								<div>
									<a href="?c=ab_text&amp;RoyaltyRunID={ArtistRoyaltyRun/ArtistRoyaltyRunID}" title="Text" class="iconLink">
										<img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" />
										</a>
									<a href="?c=ab_excel&amp;RoyaltyRunID={ArtistRoyaltyRun/ArtistRoyaltyRunID}" title="Excel" class="iconLink">
										<img src="/production/images/icons/excel16.gif" height="16" width="16" />
									</a>
  								Album Balances
								</div>
							</xsl:when>
							<xsl:otherwise>
								<div>
  								<span class="subtle">Album Balances</span>
  								<xsl:call-template name="helpIcon">
  									<xsl:with-param name="tip">Not available for this royalty run</xsl:with-param>
  								</xsl:call-template>
								</div>
							</xsl:otherwise>
  					</xsl:choose>

					</td>
				</tr>
			</table>
		</div>
  </xsl:template>
  
  <xsl:template name="payeeSummaryLink">
		<xsl:if test="ArtistRoyaltyRun/ArtistRoyaltyStatementList/ArtistStatement">
			<xsl:variable name="downloadLink">
				?c=show&amp;PayorID=<xsl:value-of select="Payor/PayorID" />&amp;RoyaltyRunID=<xsl:value-of select="ArtistRoyaltyRun/ArtistRoyaltyRunID" />&amp;download=1<xsl:if test="Params/filterBy">&amp;filterBy=<xsl:value-of select="Params/filterBy" /></xsl:if>
			</xsl:variable>
			<div class="downloadFiltered">
				<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}">Royalty Run Statement Summary</a>
			</div>  
		</xsl:if>
  </xsl:template>
  
  <xsl:template name="mailingListLink">
		<xsl:if test="ArtistRoyaltyRun/ArtistRoyaltyStatementList/ArtistStatement">
			<xsl:variable name="downloadLink">
				report?c=payee_mailing&amp;run_id=<xsl:value-of select="ArtistRoyaltyRun/ArtistRoyaltyRunID" />&amp;download=1<xsl:if test="Params/filterBy">&amp;filter_by=<xsl:value-of select="Params/filterBy" /></xsl:if>
			</xsl:variable>
			<div class="downloadFiltered">
				<a href="{$downloadLink}" title="Download Payee Mailing List" class="iconLink"><img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" /></a> <a href="{$downloadLink}">Payee Mailing List</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">Unrecouped Crossed Album Total</th>
        <th class="amount">Payable Crossed Album Royalties</th>
        <th class="amount">Unrecouped Uncrossed Album Total</th>
        <th class="amount">Payable Uncrossed Album Royalties</th>

        <th class="amount">Payable Period Royalties</th>
        <th class="amount">Ending Balance</th>
        <th class="amount">Minimum Payment</th>
        <th class="amount">Total Amount Payable</th>
      </tr>
      <xsl:for-each select="ArtistRoyaltyRun/ArtistRoyaltyStatementList/ArtistStatement">
        <tr class="row{position() mod 2}">
          <td>
            <a href="/rps/statement?c=show_artist&amp;ArtistStatementID={ArtistRoyaltyStatementID}" onclick="pageLoading('/rps/statement?c=show_artist&amp;ArtistStatementID={ArtistRoyaltyStatementID}')"><xsl:value-of select="ArtistPayee/Name" /></a>
          </td>
          <td>
          	<xsl:value-of select="ArtistPayee/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">
			<!-- unrecouped crossed album total -->
           	<xsl:call-template name="formatDollars">
				<xsl:with-param name="dollarAmount" select="UnrecoupedCrossedSubTotal" />
           	</xsl:call-template>            
          </td>

          <td class="amount">
			<!-- payable crossed album royalties -->
           	<xsl:call-template name="formatDollars">
				<xsl:with-param name="dollarAmount" select="PayableCrossedSubTotal" />
           	</xsl:call-template>            
          </td>

          <td class="amount">
			<!-- unrecouped uncrossed album total -->
           	<xsl:call-template name="formatDollars">
       			<xsl:with-param name="dollarAmount" select="UnrecoupedUncrossedSubTotal" />
           	</xsl:call-template>            
          </td>

          <td class="amount">
			<!-- payable uncrossed album royalties -->
           	<xsl:call-template name="formatDollars">
       			<xsl:with-param name="dollarAmount" select="PayableUncrossedSubTotal" />
           	</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="translate(Balance, translate(Balance,'0123456789', ''), '') = 0 and translate(AmountDue, translate(AmountDue,'0123456789', ''), '') &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>

