<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <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_layouts/statements.xsl" />

	<!-- Currently, only Razor and Tie (Client ID 27) can download the Excel statement. -->
	
	<!--
	<xsl:variable name="showExcelDownload">
		<xsl:choose>
			<xsl:when test="/Root/User/ClientID = 27 and /Root/MechanicalRun/CanDownloadExcel = 1">1</xsl:when>
			<xsl:otherwise>0</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	-->

    <xsl:variable name="showExcelDownload">0</xsl:variable>

    <xsl:variable name="currencyCode" select="/Root/MechanicalRun/MechanicalStatementList/MechanicalStatement/AmountDue/@currency_code" />
    
    <xsl:variable name="areaPrefix">
        <xsl:choose>
            <xsl:when test="$area = 'ca_mechanical'">ca_</xsl:when>
            <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    

    <xsl:template name="pickLayout">
		<xsl:call-template name="mechanicalShowTop" />
        <div class="section" id="mechanicalShow">
			<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="publisherSummaryLink" />
    	<xsl:call-template name="mailingListLink" />
    	<br class="superBreak" />
			<xsl:if test="not(MechanicalRun/MechanicalStatementList/MechanicalStatement)">
				<p>
					No statements are available in this view.
				</p>
			</xsl:if>
    	    <xsl:if test="MechanicalRun/MechanicalStatementList/MechanicalStatement">
    		    <br />
    		    <xsl:call-template name="statementTable" />
            </xsl:if>
        </div>
		<xsl:call-template name="buttons" />
    </xsl:template>

    <xsl:template name="mechanicalShowTop">
  	    <xsl:choose>
  		    <xsl:when test="MechanicalRun/CanDownload = 1 or MechanicalRun/CanDownloadText = 1 or Mechanical/CanDownloadCMRRA = 1 or $showExcelDownload = 1 or MechanicalRun/CanDownloadExportText = 1 or MechanicalRun/CanDownloadExportExcel = 1">
  		        <div class="section" id="mechanicalShowTop">
  		            <xsl:call-template name="helpLink" />
                    <table class="landingPage">
                        <tr>
                            <td class="landingAdd">               
                                <xsl:call-template name="mechanicalReports" />
                            </td>
                            <td class="landingView">
    			  		        <xsl:call-template name="downloadAll" />
    			  		    </td>
                        </tr>
                    </table>  		
                </div>    
  		    </xsl:when>
  		    <xsl:otherwise>
  			    <div class="section" id="mechanicalShowTop">
  			        <xsl:call-template name="helpLink" />
  			        <div class="auditReportsWrapper">
  				        <xsl:call-template name="mechanicalReports" />
  				    </div>
  			    </div>
  		    </xsl:otherwise>
  	    </xsl:choose>
    </xsl:template>
  		
	<xsl:template name="mechanicalReports">		
	    <h2>Audit Reports</h2>
  		<table style="font-weight: normal;">
  		    <tr>
  			    <td style="padding: 0;">
      				<xsl:choose>
      					<xsl:when test="MechanicalRun/AccrualReportAvailable = 1">
      						<a href="report?c={$areaPrefix}license_accrual&amp;run_id={MechanicalRun/MechanicalRunID}&amp;payor_id={MechanicalRun/PayorID}">Unlicensed Accrual</a>
      					</xsl:when>
      					<xsl:otherwise>
      					    <a class="inactive">
      						Unlicensed Accrual
      						<xsl:call-template name="helpIcon">
      							<xsl:with-param name="tip">Not available for this royalty run</xsl:with-param>
      						</xsl:call-template>
      						</a>
      					</xsl:otherwise>
      				</xsl:choose>  					
      			</td>
      	    </tr>
  		    <tr>
  			    <td style="padding: 0;">
      				<xsl:choose>
      					<xsl:when test="MechanicalRun/PipelineReportAvailable = 1">
      						<a href="report?c={$areaPrefix}mechanical_reserve_pipeline&amp;run_id={MechanicalRun/MechanicalRunID}&amp;payor_id={MechanicalRun/PayorID}">Reserve Pipeline</a>
      					</xsl:when>
      					<xsl:otherwise>
      					    <a class="inactive">
      						Reserve Pipeline
      						<xsl:call-template name="helpIcon">
      							<xsl:with-param name="tip">Not available for this royalty run</xsl:with-param>
      						</xsl:call-template>
      						</a>
      					</xsl:otherwise>
      				</xsl:choose>  					
      			</td>
      	    </tr>
  		</table>
	</xsl:template>
		  	
	<xsl:template name="downloadAll">
		<div class="downloadWrapper">
			<h2>Download Statements</h2>
			<table style="font-weight: normal">
				<tr>
					<td>
						<xsl:if test="MechanicalRun/CanDownload = 1">
						    <xsl:if test="MechanicalRun/MechanicalStatementList/MechanicalStatement/Version = 4">
    							<div>
    								<a href="?c=label_pdf&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="All Label View PDF Statements" class="iconLink">
    								<img src="/production/images/icons/office/Harddisk-(Download)-(16x16.gif" height="16" width="16" />
    								</a> 
    								<a href="?c=label_pdf&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}">All Label View PDF Statements</a>
    							</div>		
						    </xsl:if>				
							<div>
								<a href="?c=pdf&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="All Publisher View PDF Statements" class="iconLink">
								<img src="/production/images/icons/office/Harddisk-(Download)-(16x16.gif" height="16" width="16" />
								</a> 
								<a href="?c=pdf&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}">All Publisher View PDF Statements</a>
							</div>
						</xsl:if>
						<xsl:if test="MechanicalRun/CanDownloadText = 1">
							<div>
								<a href="?c=text&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="All Electronic Format Statements" class="iconLink">
								<img src="/production/images/icons/office/Harddisk-(Download)-(16x16.gif" height="16" width="16" />
								</a> 
								<a href="?c=text&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}">All Electronic Format Statements</a>
							</div>
						</xsl:if>			
						<xsl:if test="MechanicalRun/CanDownloadCMRRA = 1">
							<div>
								<a href="?c=cmrra&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="All CMRRA Format Statements" class="iconLink">
								<img src="/production/images/icons/office/Harddisk-(Download)-(16x16.gif" height="16" width="16" />
								</a> 
								<a href="?c=cmrra&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}">All CMRRA Format Statements</a>
							</div>
						</xsl:if>										
						<xsl:if test="$showExcelDownload = 1">
							<div>
								<a href="?c=excel&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="Excel Statement" class="iconLink">
								<img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" />
								</a> 
								<a href="?c=excel&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}">Excel Statement</a>
							</div>
						</xsl:if>
						<xsl:choose>
							<xsl:when test="MechanicalRun/CanDownloadExportText = 1 or MechanicalRun/CanDownloadExportExcel = 1">
								<div>
									<a href="?c=export_text&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="Text" class="iconLink">
									<img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" />
									</a> 
									<a href="?c=export_excel&amp;MechanicalRunID={MechanicalRun/MechanicalRunID}" title="Excel" class="iconLink">
									<img src="/production/images/icons/excel16.gif" height="16" width="16" />
									</a> 
									Royalty Data Export
								</div>
							</xsl:when>			
							<xsl:otherwise>
      					    	<a class="inactive">
      							Royalty Data Export
      							<xsl:call-template name="helpIcon">
      								<xsl:with-param name="tip">Not available for this royalty run</xsl:with-param>
      							</xsl:call-template>
      							</a>
							</xsl:otherwise>


						</xsl:choose>
					</td>
				</tr>		
			</table>			
		</div>
    </xsl:template>
  
    <xsl:template name="mailingListLink">
		<xsl:if test="MechanicalRun/MechanicalStatementList/MechanicalStatement">
			<xsl:variable name="downloadLink">
				report?c=<xsl:value-of select="$areaPrefix" />publisher_mailing&amp;run_id=<xsl:value-of select="MechanicalRun/MechanicalRunID" />&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 Publisher Mailing List" class="iconLink"><img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" /></a> <a href="{$downloadLink}">Publisher Mailing List</a>
			</div>  
		</xsl:if>
    </xsl:template>
  
    <xsl:template name="publisherSummaryLink">
		<xsl:if test="MechanicalRun/MechanicalStatementList/MechanicalStatement">
			<xsl:variable name="downloadLink">
				?c=show&amp;PayorID=<xsl:value-of select="Payor/PayorID" />&amp;MechanicalRunID=<xsl:value-of select="MechanicalRun/MechanicalRunID" />&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="statementTable">
	    <xsl:variable name="pdfReady">
	        <xsl:choose>
	            <xsl:when test="normalize-space(MechanicalRun/CanDownload)">1</xsl:when>
	            <xsl:otherwise>0</xsl:otherwise>
	        </xsl:choose>
	    </xsl:variable>
	
        <table class="textChart hiOn">
            <tr>
                <th>Publisher</th>
                <th>Client&#160;#</th>
                <th class="amount">Previous Balance<br />(<xsl:value-of select="$currencyCode" />)</th>
                <th class="amount">Transaction Total<br />(<xsl:value-of select="$currencyCode" />)</th>
                <th class="amount">Period Royalties<br />(<xsl:value-of select="$currencyCode" />)</th>
                <th class="amount">Ending Balance<br />(<xsl:value-of select="$currencyCode" />)</th>
                <th class="amount">Minimum Payment<br />(<xsl:value-of select="$currencyCode" />)</th>
                <th class="amount">Amount Payable<br />(<xsl:value-of select="$currencyCode" />)</th>
            </tr>
            <xsl:for-each select="MechanicalRun/MechanicalStatementList/MechanicalStatement">
                <tr class="row{position() mod 2}">
                    <td>
                        <xsl:variable name="linkCommand">show_<xsl:value-of select="$areaPrefix" />mechanical<xsl:if test="Version = 4">_pdf</xsl:if></xsl:variable>
                    
                        <xsl:choose>
                            <xsl:when test="Version = 4 and $pdfReady != 1">
                                <xsl:value-of select="Publisher/PublisherName" />
                            </xsl:when>
                            <xsl:otherwise>
                                <a href="/rps/statement?c={$linkCommand}&amp;MechanicalStatementID={MechanicalStatementID}" onClick="pageLoading('/rps/statement?c=show_{$areaPrefix}mechanical&amp;MechanicalStatementID={MechanicalStatementID}')"><xsl:value-of select="Publisher/PublisherName" /></a>
                            </xsl:otherwise>
                        </xsl:choose>
                        
                        <xsl:if test="Publisher/IsAdmin = 1"> (Admin)</xsl:if><xsl:if test="Publisher/IsAgency = 1"> (Agency)</xsl:if>
                        
                        <!--
                        <xsl:if test="Publisher/IsAgency = 1">
                          &#160;<a href="statement?c=show_mechanical&amp;MechanicalStatementID={MechanicalStatementID}&amp;hfa=1" title="Download HFA version"><img src="/production/images/icons/mini/file.gif" /></a>
                        </xsl:if>
                        -->
                    </td>
                    <td>
          	            <xsl:value-of select="Publisher/ClientAccountID" />
                    </td>
                    <td class="amount">
                        <xsl:value-of select="PreviousBalance" />
                    </td>
                    <td class="amount">
                        <xsl:value-of select="TransactionSubtotal" />         
                    </td>
                    <td class="amount">
                        <xsl:value-of select="Subtotal" />
                    </td>
                    <td class="amount">
                        <xsl:value-of select="StatementTotal" />
                    </td>
                    <td class="amount">
                        <xsl:value-of select="MinimumPayment" />
                    </td>
                    <td class="amount">
          	            <xsl:choose>
          		            <xsl:when test="OnHold = 1">ON-HOLD</xsl:when>
          		            <xsl:otherwise>
              		            <xsl:value-of select="AmountDue" />
            	            </xsl:otherwise>
                        </xsl:choose>
                    </td>
                </tr>
            </xsl:for-each>
        </table>	
	</xsl:template>


    <xsl:template name="submitButton">
  	    <xsl:choose>
  		    <xsl:when test="$cmd = 'show' and MechanicalRun/Status = 2">
  			    <input type="button" value="Edit Payments" onClick="goToPayments('{$area}',{Params/PayorID},{Params/MechanicalRunID})" />
  		    </xsl:when>
  		    <xsl:otherwise>
    		    <xsl:attribute name="class" />
			</xsl:otherwise>
		</xsl:choose>
    </xsl:template>


    <xsl:template name="cancelButton">
        <input type="button" name="Back" value="Back to Royalty Runs" onClick="location.href='{$area}'" />
    </xsl:template>


</xsl:stylesheet>

