<!--                                                                  -->
<!--  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="" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />

    <xsl:template name="pickLayout">
        <section class="LicenseView MainBaseSection" id="mcpsLicenseShow">
            <xsl:call-template name="helpLink" />
            <section class="PageShow-section">
                <xsl:call-template name="albumView" />
            </section>
            <section class="LicenseView-info-section">
                <xsl:call-template name="mcpsLicenseShow" />
            </section>
            <section class="LicenseView-info-section">
                <xsl:call-template name="retentionsOverview" />
            </section>
            <xsl:call-template name="buttons" />
        </section>
    </xsl:template>

    <xsl:template name="submitButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="type" select="'primary'" />
            <xsl:with-param name="className" select="'Form-button'" />
            <xsl:with-param name="content" select="'Edit MCPS Product'" />
            <xsl:with-param name="url">
                <xsl:text>uk_mech?c=edit_mcps_license&amp;ProductID=</xsl:text>
                <xsl:value-of select="Form/Product/ProductID" />
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Return to Album'" />
            <xsl:with-param name="className" select="'Form-button'" />
            <xsl:with-param name="url">
                <xsl:text>catalog?c=show&amp;AlbumID=</xsl:text>
                <xsl:value-of select="Form/Album/AlbumID" />
                <xsl:text>&amp;tab=ukLicenseTab</xsl:text>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="mcpsLicenseShow">
        <h2>MCPS Data</h2>
        <div class="LicenseView-info-wrapper InformationCols">
            <xsl:call-template name="column1" />
            <xsl:call-template name="column2" />
        </div>
    </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="LicenseView-info-column InformationCols-item">
            <div class="ValuePair">
                <div class="ValuePair-item">
                    <div class="ValuePair-label">Product Type</div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="$productType" />
                    </div>
                </div>
                <div class="ValuePair-item">
                    <div class="ValuePair-label">Product ID</div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="Form/Product/ProductCode" />
                    </div>
                </div>
                <div class="ValuePair-item">
                    <div class="ValuePair-label">MCPS ID</div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="Form/McpsLicense/McpsID" />
                    </div>
                </div>

                <xsl:if test="$productType = 'DVD'">
                    <div class="ValuePair-item">
                        <div class="ValuePair-label">DVD Category</div>
                        <div class="ValuePair-value">
                            <xsl:value-of select="Form/McpsLicense/DvdCategory" />
                        </div>
                    </div>
                </xsl:if>

                <div class="ValuePair-item">
                    <div class="ValuePair-label">Product Status</div>
                    <div class="ValuePair-value">
                        <xsl:variable name="productStatusID" select="Form/Product/ProductStatusID" />
                        <xsl:value-of select="Form/StatusList/Status[ProductStatusID = $productStatusID]/Description" />
                    </div>
                </div>
                <div class="ValuePair-item">
                    <div class="ValuePair-label">Release Date</div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="Form/Product/ReleaseDate" />
                    </div>
                </div>
                <div class="ValuePair-item">
                    <div class="ValuePair-label">Current Default Price</div>
                    <div class="ValuePair-value">
                        <xsl:variable name="priceLevelID" select="Form/Product/DefaultPriceLevelID" />
                        <xsl:value-of select="Form/PriceLevelList/PriceLevel[PriceLevelID = $priceLevelID]/Name" />
                    </div>
                </div>

                <xsl:variable name="payorID" select="Form/McpsLicense/PayorID" />

                <div class="ValuePair-item">
                    <div class="ValuePair-label">Payor</div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="Form/PayorList/Payor[PayorID = $payorID]/Name" />
                    </div>
                </div>
                <div class="ValuePair-item">
                    <div class="ValuePair-label">Supplier Code</div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="Form/PayorList/Payor[PayorID = $payorID]/SupplierCode" />
                    </div>
                </div>
            </div>
        </div>

    </xsl:template>


    <xsl:template name="column2">
        <div class="LicenseView-info-column InformationCols-item">
            <div class="ValuePair">
                <div class="ValuePair-item">
                    <div class="ValuePair-label">
                        TV Advertised
                    </div>
                    <div class="ValuePair-value">
                        <xsl:choose>
                            <xsl:when test="Form/McpsLicense/RetentionCategory = 'T'">
                                Yes
                            </xsl:when>
                            <xsl:otherwise>
                                No
                            </xsl:otherwise>
                        </xsl:choose>
                    </div>
                </div>

                <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>

                <div class="ValuePair-item">
                    <div class="ValuePair-label">
                        Initial Periods Completed
                    </div>
                    <div class="ValuePair-value">
                        <xsl:value-of select="$initialPeriods" /><xsl:if test="$initialPeriods = 5">+</xsl:if>
                    </div>
                </div>

                <xsl:if test="$initialPeriods &gt; 0 and $initialPeriods != 5">
                    <div class="ValuePair-item">
                        <div class="ValuePair-label">
                            Historical Retentions
                        </div>
                        <div class="ValuePair-value">
                            <table class="Table" id="historicalRetentions">
                                <thead>
                                    <tr class="Table-row Table-row-header">
                                        <th class="Table-col Table-col-header">Period</th>
                                        <th class="Table-col">1</th>

                                        <xsl:if test="$initialPeriods &gt; 1">
                                            <th class="Table-col">2</th>
                                        </xsl:if>

                                        <xsl:if test="$initialPeriods &gt; 2">
                                            <th class="Table-col">3</th>
                                        </xsl:if>

                                        <xsl:if test="$initialPeriods &gt; 3">
                                            <th class="Table-col">4</th>
                                        </xsl:if>

                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="Table-row Table-row-data">
                                        <td class="Table-col Table-col-header">#&#160;Held</td>
                                        <td class="Table-col">
                                            <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 1]/UnitsHeld" />
                                        </td>

                                        <xsl:if test="$initialPeriods &gt; 1">
                                            <td class="Table-col">
                                                <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 2]/UnitsHeld" />
                                            </td>
                                        </xsl:if>

                                        <xsl:if test="$initialPeriods &gt; 2">
                                            <td class="Table-col">
                                                <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 3]/UnitsHeld" />
                                            </td>
                                        </xsl:if>

                                        <xsl:if test="$initialPeriods &gt; 3">
                                            <td class="Table-col">
                                                <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 4]/UnitsHeld" />
                                            </td>
                                        </xsl:if>

                                    </tr>
                                    <tr>
                                        <td class="Table-col Table-col-header">Price&#160;Tier</td>
                                        <td class="Table-col">
                                            <xsl:call-template name="priceTierDisplay">
                                                <xsl:with-param name="period" select="'1'" />
                                            </xsl:call-template>
                                        </td>

                                        <xsl:if test="$initialPeriods &gt; 1">
                                            <td class="Table-col">
                                                <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 class="Table-col">
                                                <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 class="Table-col">
                                                <xsl:call-template name="priceTierDisplay">
                                                    <xsl:with-param name="period" select="'4'" />
                                                </xsl:call-template>
                                            </td>
                                        </xsl:if>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </xsl:if>
            </div>
        </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">
        <h2>Retentions Overview</h2>
        <h3>Current Period: <xsl:value-of select="Form/McpsLicense/PeriodsCompleted + 1" /></h3>

        <xsl:choose>
            <xsl:when test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionTotal != 0">
                <xsl:call-template name="retentionsOverviewTable" />
            </xsl:when>
            <xsl:otherwise>
                <div class="Table-empty-result">
                    No retentions have been taken for this product.
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="retentionsOverviewTable">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col">Period</th>
                    <th class="Table-col Table-col-amount">1</th>
                    <th class="Table-col Table-col-amount">2</th>
                    <th class="Table-col Table-col-amount">3</th>
                    <th class="Table-col Table-col-amount">4</th>
                    <th class="Table-col Table-col-amount">Total</th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Form/McpsLicense/McpsLicenseRetentionList/PriceRows/PriceRow">
                    <xsl:call-template name="priceRow" />
                </xsl:for-each>
                <xsl:call-template name="retentionsOverviewTotals" />
                <xsl:call-template name="retentionsOverviewRates" />
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="priceRow">
        <tr class="Table-row Table-row-data">
            <xsl:if test="position() = 1">
                <xsl:attribute name="class">Table-row Table-row-data Table-row-total</xsl:attribute>
            </xsl:if>
            <td class="Table-col">
                <xsl:value-of select="Price" />
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="Period1" />
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="Period2" />
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="Period3" />
            </td>
            <td class="Table-col Table-col-amount">
                <xsl:value-of select="Period4" />
            </td>
            <td class="Table-col Table-col-amount">
                <strong>
                    <xsl:value-of select="Total" />
                </strong>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="retentionsOverviewTotals">
        <tr class="Table-row Table-row-data Table-row-total">
            <td class="Table-col">Total</td>
            <td class="Table-col Table-col-amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod1Total" />
                </strong>
            </td>
            <td class="Table-col Table-col-amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod2Total" />
                </strong>
            </td>
            <td class="Table-col Table-col-amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod3Total" />
                </strong>
            </td>
            <td class="Table-col Table-col-amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionPeriod4Total" />
                </strong>
            </td>
            <td class="Table-col Table-col-amount">
                <strong>
                    <xsl:value-of select="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetentionTotal" />
                </strong>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="retentionsOverviewRates">
        <tr class="Table-row Table-row-data">
            <td class="Table-col">Rate</td>
            <td class="Table-col Table-col-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="Table-col Table-col-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="Table-col Table-col-amount">10%</td>
            <td class="Table-col Table-col-amount">10%</td>
            <td class="Table-col"></td>
        </tr>
    </xsl:template>

</xsl:stylesheet>


