<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<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:template name="pickLayout">     
        <div class="section" id="mcpsLicenseShow">    
            <xsl:call-template name="helpLink" />     
            <xsl:call-template name="albumView" />
            <br />
            <xsl:call-template name="mcpsLicenseShow" />
            <br class="superBreak" />
            <br />
        </div>
        <xsl:call-template name="buttons" />
    </xsl:template>


    <xsl:template name="submitButton">
        <input type="button" value="Edit MCPS Product" onClick="location.href='uk_mech?c=edit_mcps_license&amp;ProductID={Form/Product/ProductID}'" />
    </xsl:template>


    <xsl:template name="cancelButton">
        <input type="button" value="Return to Album" onClick="location.href='catalog?c=show&amp;AlbumID={Form/Album/AlbumID}&amp;tab=ukLicenseTab'" />
    </xsl:template>


    <xsl:template name="mcpsLicenseShow">
        <fieldset>
            <legend>MCPS Data</legend>
            <div class="insideFieldset">                      
                <xsl:call-template name="column1" /> 
                <xsl:call-template name="column2" />
            </div>
            
            <xsl:call-template name="retentionsOverview" />
            
            <br />
            <br />
            
        </fieldset>
    </xsl:template>


    <xsl:template name="column1">

        <xsl:variable name="productTypeID" select="Form/Product/ProductTypeID" />
        <xsl:variable name="productType" select="Form/TypeList/Type[ProductTypeID = $productTypeID]/Description" />
    
        <div class="column1">
            <table>
                <tr>
                    <td class="leftCol">Product Type:</td>
                    <td>
                        <xsl:value-of select="$productType" />
                    </td>
                </tr>
                <tr>
                    <td class="leftCol">Product ID:</td>
                    <td>
                        <xsl:value-of select="Form/Product/ProductCode" />
                    </td>
                </tr>                           
                <tr>
                  <td class="leftCol">MCPS ID:</td>
                  <td>
                    <xsl:value-of select="Form/McpsLicense/McpsID" />
                  </td>
                </tr>
                
                <xsl:if test="$productType = 'DVD'">
                    <tr>
                        <td class="leftCol">DVD Category:</td>
                        <td>
                            <xsl:value-of select="Form/McpsLicense/DvdCategory" />
                        </td>
                    </tr>   
                </xsl:if>
                             
				<tr>
					<td class="leftCol">Product Status:</td>
					<td>
					    <xsl:variable name="productStatusID" select="Form/Product/ProductStatusID" />
                        <xsl:value-of select="Form/StatusList/Status[ProductStatusID = $productStatusID]/Description" />
					</td>
				</tr>   
                <tr>
                    <td class="leftCol">Release Date:</td>
                    <td>
                        <xsl:value-of select="Form/Product/ReleaseDate" />
                    </td>
                </tr>        				
				<tr>
					<td class="leftCol">Current Default Price:</td>
					<td>
					    <xsl:variable name="priceLevelID" select="Form/Product/DefaultPriceLevelID" />
                        <xsl:value-of select="Form/PriceLevelList/PriceLevel[PriceLevelID = $priceLevelID]/Name" />
					</td>
				</tr>  		       
				
				<xsl:variable name="payorID" select="Form/McpsLicense/PayorID" />
				
                <tr>
                    <td class="leftCol">Payor:</td>
                    <td>                    
                        <xsl:value-of select="Form/PayorList/Payor[PayorID = $payorID]/Name" />
                    </td>
                </tr>
                <tr>
                    <td class="leftCol">Supplier Code:</td>
                    <td>
                        <xsl:value-of select="Form/PayorList/Payor[PayorID = $payorID]/SupplierCode" />
                    </td>
                </tr>                 				
            </table>
        </div>
    
    </xsl:template>


    <xsl:template name="column2">
        <div class="column2">
            <table>    
                <tr>
                    <td class="leftCol">
                        TV Advertised:
                    </td>
                    <td>
                        <xsl:choose>
                            <xsl:when test="Form/McpsLicense/RetentionCategory = 'T'">
                                Yes
                            </xsl:when>
                            <xsl:otherwise>
                                No
                            </xsl:otherwise>
                        </xsl:choose>
    			    </td>   
                </tr>
                
                <xsl:variable name="initialPeriods">
                    <xsl:choose>
                        <xsl:when test="normalize-space(Form/McpsLicense/InitialPeriodsCompleted)">
                            <xsl:value-of select="Form/McpsLicense/InitialPeriodsCompleted" />
                        </xsl:when>
                        <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                
                <tr>
                    <td class="leftCol">
                        Initial Periods Completed:
                    </td>
                    <td>
                        <xsl:value-of select="$initialPeriods" /><xsl:if test="$initialPeriods = 5">+</xsl:if>
    			    </td>   
                </tr>
                      
                <xsl:if test="$initialPeriods &gt; 0 and $initialPeriods != 5">          
                    <tr>
                        <td class="leftCol">
                            Historical Retentions:
                        </td>
                        <td></td>
                    </tr>    
                    <tr>
                        <td colspan="2">
                        
                            <table id="historicalRetentions">
                                <tr>
                                    <th class="leftColumn">Period</th>
                                    <th>1</th>
                                    
                                    <xsl:if test="$initialPeriods &gt; 1">
                                        <th>2</th>
                                    </xsl:if>
                                    
                                    <xsl:if test="$initialPeriods &gt; 2">
                                        <th>3</th>
                                    </xsl:if>
                                    
                                    <xsl:if test="$initialPeriods &gt; 3">
                                        <th>4</th>
                                    </xsl:if>
                                    
                                </tr>
                                
                                <tr>
                                    <td class="leftColumn">#&#160;Held</td>
                                    <td>
                                        <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 1]/UnitsHeld" />
                                    </td>
                                    
                                    <xsl:if test="$initialPeriods &gt; 1">
                                        <td>
                                            <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 2]/UnitsHeld" />
                                        </td>
                                    </xsl:if> 
                                    
                                    <xsl:if test="$initialPeriods &gt; 2">  
                                        <td>
                                            <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 3]/UnitsHeld" />
                                        </td> 
                                    </xsl:if>
                                    
                                    <xsl:if test="$initialPeriods &gt; 3">                       
                                        <td>
                                            <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 4]/UnitsHeld" />
                                        </td>     
                                    </xsl:if>
                                                               
                                </tr>
                                <tr>
                                    <td class="leftColumn">Price&#160;Tier</td>
                                    <td>
                                        <xsl:call-template name="priceTierDisplay">
                                            <xsl:with-param name="period" select="'1'" />
                                        </xsl:call-template>                                    
                                    </td>
                                    
                                    <xsl:if test="$initialPeriods &gt; 1">
                                        <td>
                                            <xsl:call-template name="priceTierDisplay">
                                                <xsl:with-param name="period" select="'2'" />
                                            </xsl:call-template>   
                                        </td>
                                    </xsl:if>
                                    
                                    <xsl:if test="$initialPeriods &gt; 2">
                                        <td>
                                            <xsl:call-template name="priceTierDisplay">
                                                <xsl:with-param name="period" select="'3'" />
                                            </xsl:call-template>   
                                        </td>
                                    </xsl:if>    
                                       
                                    <xsl:if test="$initialPeriods &gt; 3">    
                                        <td>
                                            <xsl:call-template name="priceTierDisplay">
                                                <xsl:with-param name="period" select="'4'" />
                                            </xsl:call-template>   
                                        </td>
                                    </xsl:if>
                                    
                                </tr>                                                               
                            </table>      
                        </td>
                    </tr>
                </xsl:if>
                    
            </table>
        </div>
    </xsl:template>
    
    
    <xsl:template name="priceTierDisplay">
        <xsl:param name="period" />
                                    
        <xsl:variable name="priceLevelID" select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = $period]/PriceLevelID" />
        
        <xsl:variable name="priceID" select="/Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]/PriceID" />
        
        <xsl:variable name="priceTierPrice">            
            <xsl:choose>
                <xsl:when test="/Root/Form/McpsLicense/Committed = 0">
                    <xsl:value-of select="/Root/Form/PriceList/Price[PriceID = $priceID]/Retail" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="/Root/Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = $period]/Price" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>                                        
        
        <xsl:value-of select="Form/PriceLevelList/PriceLevel[PriceLevelID = $priceLevelID]/Name" /> <xsl:if test="Form/PriceLevelList/PriceLevel[PriceLevelID = $priceLevelID]/Name">/</xsl:if> <xsl:value-of select="$priceTierPrice" /> 
    </xsl:template>
    
    
    <xsl:template name="retentionsOverview">
        <fieldset id="retentionsOverview">
            <legend>Retentions Overview</legend>
            <div class="insideFieldset">
                <h4>Current Period: <xsl:value-of select="Form/McpsLicense/PeriodsCompleted + 1" /></h4>
                
                <xsl:choose>
                    <xsl:when test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionTotal != 0">
                        <xsl:call-template name="retentionsOverviewTable" />
                    </xsl:when>
                    <xsl:otherwise><br />No retentions have been taken for this product.</xsl:otherwise>
                </xsl:choose>
            </div>
        </fieldset>
    </xsl:template>
    
    
    <xsl:template name="retentionsOverviewTable">
        <table class="textChart">
            <tr>
                <th>Period</th>
                <th class="amount">1</th>
                <th class="amount">2</th>
                <th class="amount">3</th>
                <th class="amount">4</th>
                <th class="amount">Total</th>
            </tr>
            <xsl:for-each select="Form/McpsLicense/McpsLicenseRetentionList/PriceRows/PriceRow">
                <xsl:call-template name="priceRow" />
            </xsl:for-each>            
            <xsl:call-template name="retentionsOverviewTotals" />
            <tr>
                <td colspan="6" />
            </tr>
            <xsl:call-template name="retentionsOverviewRates" />
        </table>    
    </xsl:template>
    
    
    <xsl:template name="priceRow">
        <tr>
            <xsl:if test="position() = 1">
                <xsl:attribute name="class">total</xsl:attribute>
            </xsl:if>        
            <td>
                <xsl:value-of select="Price" />
            </td>
            <td class="amount">
                <xsl:value-of select="Period1" />
            </td>
            <td class="amount">
                <xsl:value-of select="Period2" />
            </td>
            <td class="amount">
                <xsl:value-of select="Period3" />
            </td>
            <td class="amount">
                <xsl:value-of select="Period4" />
            </td>   
            <td class="amount">
                <strong>
                    <xsl:value-of select="Total" />
                </strong>
            </td>                     
        </tr>
    </xsl:template>
        
    
    <xsl:template name="retentionsOverviewTotals">
        <tr class="total">
            <td>Total</td>
            <td class="amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod1Total" />
                </strong>
            </td>
            <td class="amount">
                <strong>                
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod2Total" />
                </strong>
            </td>
            <td class="amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod3Total" />
                </strong>
            </td>
            <td class="amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod4Total" />
                </strong>
            </td>
            <td class="amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionTotal" />
                </strong>            
            </td>
        </tr>
    </xsl:template>


    <xsl:template name="retentionsOverviewRates">
        <tr>
            <td>Rate</td>
            <td class="amount">
                <xsl:choose>
                    <xsl:when test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 1]">  
                        <xsl:choose>
                            <xsl:when test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 1]/RetentionCategory = 'T'">
                                25%
                            </xsl:when>
                            <xsl:otherwise>
                                10%
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test="Form/McpsLicense/RetentionCategory = 'T'">
                        25%
                    </xsl:when>
                    <xsl:otherwise>
                        10%
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="amount">
                <xsl:choose>
                    <xsl:when test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 2]">  
                        <xsl:choose>
                            <xsl:when test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 2]/RetentionCategory = 'T'">
                                25%
                            </xsl:when>
                            <xsl:otherwise>
                                10%
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test="Form/McpsLicense/RetentionCategory = 'T'">
                        25%
                    </xsl:when>
                    <xsl:otherwise>
                        10%
                    </xsl:otherwise>
                </xsl:choose>            
            </td>
            <td class="amount">10%</td>
            <td class="amount">10%</td>
            <td></td>
        </tr>    
    </xsl:template>    
        

</xsl:stylesheet>


