<!--                                                                  -->
<!--  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:variable name="statusDescriptions">
		Waiting to Run:
		&lt;br&gt;
		In queue and ready to run
		&lt;br&gt;&lt;br&gt;
		Running:
		&lt;br&gt;
		In progress
		&lt;br&gt;&lt;br&gt;
		Complete:
		&lt;br&gt;
		Preliminary royalty run
		&lt;br&gt;&lt;br&gt;
		Committed:
		&lt;br&gt;
		Royalty period closed, statements committed<xsl:if test="$area != 'uk_mech'">, payments open</xsl:if>
		&lt;br&gt;&lt;br&gt;
		Closed:
		&lt;br&gt;
		Royalty period closed, statements closed<xsl:if test="$area != 'uk_mech'">, payments closed</xsl:if>
	</xsl:variable>


    <xsl:template name="statementSuccessMessages">
		<xsl:call-template name="successMessageGeneral">
			<xsl:with-param name="successMessage">
			    <xsl:if test="Messages/Message/Code = 'form_submit_success'">Royalty run has been created successfully!</xsl:if>
			    <xsl:if test="Messages/Message/Code = 'delete_success'">Royalty run has been queued for deletion!</xsl:if>
			    <xsl:if test="Messages/Message/Code = 'commit_success'">Royalty run has been queued for committal!</xsl:if>
			    <xsl:if test="Messages/Message/Code = 'invalidate_success'">Royalty run has been invalidated successfully!</xsl:if>
			</xsl:with-param>
		</xsl:call-template>
    </xsl:template>


	<xsl:template name="statusCodeToName">
      	<xsl:choose>
            <xsl:when test="Status = 0">Running</xsl:when>
            <xsl:when test="Status = 1">Complete</xsl:when>
            <xsl:when test="Status = 2">Committed</xsl:when>
            <xsl:when test="Status = 3">Aborted</xsl:when>
            <xsl:when test="Status = 4">Error</xsl:when>
            <xsl:when test="Status = 5">Closed</xsl:when>
            <xsl:when test="Status = 6">Waiting to Run</xsl:when>
            <xsl:when test="Status = 7">Committing</xsl:when>
            <xsl:when test="Status = 8">Deleting</xsl:when>
            <xsl:when test="Status = 9">Invalid</xsl:when>
        </xsl:choose>
	</xsl:template>


	<xsl:template name="runActions">
		<xsl:variable name="runParam">
			<xsl:choose>
				<xsl:when test="$area = 'artist_royalty'">RoyaltyRunID=<xsl:value-of select="ArtistRoyaltyRunID" /></xsl:when>
				<xsl:when test="$area = 'label_royalty'">LabelRoyaltyRunID=<xsl:value-of select="LabelRoyaltyRunID" /></xsl:when>
				<xsl:when test="$area = 'uk_mech'">UKMechanicalRunID=<xsl:value-of select="UKMechanicalRunID" /></xsl:when>
				<xsl:otherwise>MechanicalRunID=<xsl:value-of select="MechanicalRunID" /></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="commitAccess">/Root/Access/rps/<xsl:value-of select="$area" />/commit</xsl:variable>
		<xsl:variable name="deleteAccess">/Root/Access/rps/<xsl:value-of select="$area" />/delete</xsl:variable>
		<xsl:variable name="invalidateAccess">/Root/Access/rps/<xsl:value-of select="$area" />/invalidate</xsl:variable>
		<xsl:variable name="editPayAccess">/Root/Access/rps/<xsl:value-of select="$area" />/editpay</xsl:variable>
		<xsl:if test="Status = 1">
			<xsl:if test="dyn:evaluate($commitAccess) = 1">
				<xsl:call-template name="commitRunLink">
					<xsl:with-param name="runParam" select="$runParam" />
				</xsl:call-template>
			</xsl:if>
			<xsl:if test="dyn:evaluate($deleteAccess) = 1 and dyn:evaluate($commitAccess) = 1">, </xsl:if>
			<xsl:if test="dyn:evaluate($deleteAccess) = 1">
				<xsl:call-template name="deleteRunLink">
					<xsl:with-param name="runParam" select="$runParam" />
				</xsl:call-template>
			</xsl:if>
			<xsl:if test="dyn:evaluate($deleteAccess) = 1 and dyn:evaluate($invalidateAccess) = 1">, </xsl:if>
			<xsl:if test="dyn:evaluate($invalidateAccess) = 1">
				<xsl:call-template name="invalidateRunLink">
					<xsl:with-param name="runParam" select="$runParam" />
				</xsl:call-template>
			</xsl:if>
		</xsl:if>
		<xsl:if test="Status = 2 and dyn:evaluate($editPayAccess) = 1">
			<xsl:call-template name="editPaymentsLink">
				<xsl:with-param name="runParam" select="$runParam" />
			</xsl:call-template>
		</xsl:if>
		<xsl:if test="Status = 3 or Status = 9">
			<xsl:if test="dyn:evaluate($deleteAccess) = 1">
				<xsl:call-template name="deleteRunLink">
					<xsl:with-param name="runParam" select="$runParam" />
				</xsl:call-template>
			</xsl:if>
		</xsl:if>
	</xsl:template>


	<xsl:template name="editPaymentsLink">
		<xsl:param name="runParam" />
		<xsl:choose>
			<xsl:when test="$area = 'label_royalty'">
				<a href="?c=editpay&amp;{$runParam}&amp;Payments=1&amp;PayorID={PayorID}">Edit Payments</a>
  		</xsl:when>
  		<xsl:otherwise>
				<a href="?c=payors&amp;{$runParam}&amp;Payments=1">Edit Payments</a>
  		</xsl:otherwise>
  	</xsl:choose>
	</xsl:template>


	<xsl:template name="commitRunLink">
		<xsl:param name="runParam" />
		<a href="javascript:confirmCommitRun('{$runParam}')">Commit</a>
	</xsl:template>


	<xsl:template name="deleteRunLink">
		<xsl:param name="runParam" />
		<a href="javascript:confirmDeleteRun('{$runParam}')">Delete</a>
	</xsl:template>


	<xsl:template name="invalidateRunLink">
		<xsl:param name="runParam" />
		<xsl:choose>
			<xsl:when test="RoyaltyRunStatus/InvalidatedRuns &gt; 7">
         		<a href="javascript:confirmInvalidateRun('{$runParam}', 'invalid')">Invalidate</a>
			</xsl:when>
			<xsl:otherwise>
         		<a href="javascript:confirmInvalidateRun('{$runParam}')">Invalidate</a>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template name="statementCount">
		<xsl:variable name="numStatements"><xsl:value-of select="NumStatements" /><xsl:value-of select="NumberOfStatements" /></xsl:variable>
		<xsl:variable name="runParam">
			<xsl:choose>
				<xsl:when test="$area = 'artist_royalty'">RoyaltyRunID=<xsl:value-of select="ArtistRoyaltyRunID" /></xsl:when>
				<xsl:when test="$area = 'label_royalty'">LabelRoyaltyRunID=<xsl:value-of select="LabelRoyaltyRunID" /></xsl:when>
				<xsl:when test="$area = 'uk_mech'">UKMechanicalRunID=<xsl:value-of select="UKMechanicalRunID" /></xsl:when>
				<xsl:otherwise>MechanicalRunID=<xsl:value-of select="MechanicalRunID" /></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
  	<xsl:choose>
  		<xsl:when test="$numStatements = 0"></xsl:when>
    	<xsl:when test="Status = 1 or Status = 2 or Status = 5 or Status = 9">
    		<xsl:choose>
    			<xsl:when test="$area = 'label_royalty'">
		      	    <a href="?c=show&amp;{$runParam}&amp;PayorID={PayorID}">
		        	    <xsl:value-of select="$numStatements" />
			 	    </a>
	 	  		</xsl:when>
    			<xsl:when test="$area = 'uk_mech'">
		      	    <a href="?c=show&amp;{$runParam}">
		        	    <xsl:value-of select="$numStatements" />
			 	    </a>
	 	  		</xsl:when>
	 	  		<xsl:otherwise>
		      	    <a href="?c=payors&amp;{$runParam}">
		        	    <xsl:value-of select="$numStatements" />
			 	    </a>
	 	  		</xsl:otherwise>
	 	  	</xsl:choose>
			</xsl:when>
    	<xsl:otherwise>
				<xsl:value-of select="$numStatements" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template name="runDate">
		<xsl:param name="runDate" select="substring(StartTime,1,10)" />
		<xsl:variable name="dateSeparator" select="/Root/Client/Locale/DateTimeFormat/DateSeparator" />
		<xsl:if test="translate($runDate, $dateSeparator, '') != 0">
			<xsl:value-of select="$runDate" />
		</xsl:if>
	</xsl:template>

	<xsl:template name="endingSalesDate">
		<xsl:param name="endingSaleDate" select="substring(StartTime,1,10)" />
		<xsl:variable name="dateSeparator" select="/Root/Client/Locale/DateTimeFormat/DateSeparator" />
		<xsl:if test="translate($endingSaleDate, $dateSeparator, '') != 0">
			<xsl:value-of select="$endingSaleDate" />
		</xsl:if>
	</xsl:template>


	<xsl:template name="payorName">
      	<xsl:variable name="payorID" select="PayorID" />
      	<xsl:choose>
      		<xsl:when test="PayorID = 0">Various</xsl:when>
      		<xsl:otherwise><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></xsl:otherwise>
      	</xsl:choose>
	</xsl:template>


	<xsl:template name="createRunLink">
		<xsl:variable name="createAccess">Access/rps/<xsl:value-of select="$area" />/create</xsl:variable>
		<xsl:choose>
		    <xsl:when test="dyn:evaluate($createAccess) = 1">
            	<p class="addLink">
          			<a href="?c=create" title="Create New Royalty Run"><img src="/production/images/icons/office/Add-(16x16).gif" height="16" width="16" /></a> <a href="?c=create">Create New Royalty Run</a>
           		</p>
   	        </xsl:when>
   	        <xsl:otherwise>
   	            <br />
   	        </xsl:otherwise>
   	    </xsl:choose>
	</xsl:template>


	<xsl:template name="statementFill">
	    <xsl:param name="disabled" />
		<xsl:variable name="runID">
			<xsl:value-of select="Params/MechanicalRunID" /><xsl:value-of select="Params/RoyaltyRunID" /><xsl:value-of select="Params/LabelRoyaltyRunID" />
		</xsl:variable>
		<div class="statementFill">
			<label for="quickFill">Quick Fill:</label>&#160;<select name="quickFill" id="quickFill">
				<xsl:if test="$disabled = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				</xsl:if>
				<option value="full">
					<xsl:if test="Params/fullPayments = 1">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					Full Payment - All
				</option>
				<option value="clear">
					<xsl:if test="Params/clearPayments = 1">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					No Payment - All
				</option>
			</select>&#160;<input type="button" value="Update" onClick="fillStatementsConfirm()">
				<xsl:if test="$disabled = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				</xsl:if>
			</input>
		</div>
	</xsl:template>


	<xsl:template name="statementFilter">
		<xsl:variable name="runID">
			<xsl:value-of select="Params/MechanicalRunID" /><xsl:value-of select="Params/RoyaltyRunID" /><xsl:value-of select="Params/LabelRoyaltyRunID" /><xsl:value-of select="Params/UKMechanicalRunID" />
		</xsl:variable>
		<div class="statementFilter">
			<label for="filterBy">Now Viewing:</label>&#160;<select name="filterBy" id="filterBy">
                <xsl:choose>
                    <xsl:when test="/Root/Area = 'label_royalty'">
				        <option value="">All Statements</option>
                    </xsl:when>
                    <xsl:otherwise>
				        <option value="">All Statements With Activity</option>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="/Root/Area != 'label_royalty'">
				    <option value="5">
					    <xsl:if test="Params/filterBy = 5">
						    <xsl:attribute name="selected">selected</xsl:attribute>
					    </xsl:if>
				        All Statements	
				    </option>
                </xsl:if>
				<option value="1">
					<xsl:if test="Params/filterBy = 1">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					Ending Total &lt;= 0
				</option>
				<option value="2">
					<xsl:if test="Params/filterBy = 2">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					Ending Total &gt; 0
				</option>
				<option value="3">
					<xsl:if test="Params/filterBy = 3">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					Ending Total &gt;= Min Payment
				</option>
				<option value="4">
					<xsl:if test="Params/filterBy = 4">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					On-hold
				</option>
			</select>&#160;<input type="button" value="Update" onClick="filterStatements('{$area}','{$cmd}',{$runID},{Params/PayorID})" />
		</div>
	</xsl:template>


  <xsl:template name="paymentFields">
		<xsl:param name="disabled" />
		<xsl:param name="paymentCount" />
		<xsl:param name="paymentIndex" />
		<xsl:param name="paymentPrefix" />
		<xsl:param name="statementIndex" />
		<td>
			<xsl:if test="Amount[@e]">
				<xsl:attribute name="class">errorInput</xsl:attribute>
			</xsl:if>
			<input type="hidden" name="{$paymentPrefix}{$paymentIndex}_TypeCode" value="4" />
			<input type="text" name="{$paymentPrefix}{$paymentIndex}_Amount" id="{$paymentPrefix}{$paymentIndex}_Amount" class="dollarField" value="{Amount}">
				<xsl:if test="$disabled = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				</xsl:if>
			</input>
		</td>
		<td>
			<xsl:if test="CheckNumber[@e]">
				<xsl:attribute name="class">errorInput</xsl:attribute>
			</xsl:if>
			<input type="text" name="{$paymentPrefix}{$paymentIndex}_CheckNumber" id="{$paymentPrefix}{$paymentIndex}_CheckNumber" class="dollarField" value="{CheckNumber}">
				<xsl:if test="$disabled = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				</xsl:if>
			</input>
		</td>
		<td>
			<input type="text" name="{$paymentPrefix}{$paymentIndex}_Memo" id="{$paymentPrefix}{$paymentIndex}_Memo" class="memoField" value="{Memo}">
				<xsl:if test="$disabled = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				</xsl:if>
			</input>&#160;
			<xsl:if test="($paymentCount = 0 or position() = last()) and $disabled != 1">
				<a href="javascript:addPayment('{$area}',{$statementIndex},{$paymentIndex})" title="Add Another Payment" id="{$statementIndex}_{$paymentIndex}_Add"><img src="/production/images/icons/office/Add-(16x16).gif" height="16" width="16" /></a>
			</xsl:if>
		</td>
		<td class="icon">
			<input type="checkbox" name="{$paymentPrefix}{$paymentIndex}_Delete" id="{$paymentPrefix}{$paymentIndex}_Delete" value="1">
				<xsl:if test="$disabled = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				</xsl:if>
			</input>
		</td>
  </xsl:template>


  <xsl:template name="paymentErrors">
    <div class="error">
      <xsl:if test="//Amount[@e = 'field_blank']">Amount cannot be blank.<br /></xsl:if>
      <xsl:if test="//Amount[@e = 'field_out_of_range']">Amount must be a positive number.<br /></xsl:if>
      <xsl:if test="//CheckNumber[@e]">Check # is invalid.<br /></xsl:if>
      <br />
    </div>
  </xsl:template>


  <!-- we only want to allow royaltyshare folks to see this. -->
  <xsl:template name="logLevelRow">

        <xsl:if test="/Root/User/AccessLevel = 1 or /Root/User/AccessLevel = 2">

    		<tr>
    			<td class="leftCol"><label for="Form_LogLevel">Log Level:</label></td>
    			<td>
    				<xsl:call-template name="inlineError">
    					<xsl:with-param name="path">Form/LogLevel</xsl:with-param>
    					<xsl:with-param name="displayName">Log Level</xsl:with-param>
    				</xsl:call-template>
    				<select name="Form_LogLevel" id="Form_LogLevel">

    					<option value="1">
    						<xsl:if test="Form/LogLevel = 1">
    							<xsl:attribute name="selected">selected</xsl:attribute>
    						</xsl:if>
    						1
    					</option>
    					<option value="2">
    						<xsl:if test="Form/LogLevel = 2">
    							<xsl:attribute name="selected">selected</xsl:attribute>
    						</xsl:if>
    						2
    					</option>
    					<option value="3">
    						<xsl:if test="Form/LogLevel = 3">
    							<xsl:attribute name="selected">selected</xsl:attribute>
    						</xsl:if>
    						3
    					</option>
    					<option value="4">
    						<xsl:if test="Form/LogLevel = 4">
    							<xsl:attribute name="selected">selected</xsl:attribute>
    						</xsl:if>
    						4
    					</option>

    				</select>

    				<xsl:call-template name="helpIcon">
    					<xsl:with-param name="tip">Changing this value will affect the amount of logging that is done&lt;br&gt;for this run.  Please do not modify unless necessary.</xsl:with-param>
    				</xsl:call-template>
    			</td>
    		</tr>

	    </xsl:if>

	</xsl:template>


</xsl:stylesheet>
