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

    <xsl:variable name="lockedRecord">
        <xsl:choose>
            <xsl:when test="/Root/Form/ArtistContract/Status = 2">1</xsl:when>
            <xsl:when test="/Root/Form/ArtistContract/Status = 3">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="contractShowLayout">
        <xsl:call-template name="contractShow"/>
        <xsl:call-template name="buttons"/>
    </xsl:template>

    <xsl:template name="contractShow">
        <div id="contractShow">
            <xsl:call-template name="helpLink"/>
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Contract successfully updated!</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="contractView"/>
            <xsl:call-template name="termView"/>
            <fieldset class="Form-fieldset">
                <div class="Artist-contract-two-columns">
                    <xsl:call-template name="sourceList"/>
                    <xsl:call-template name="expenseList"/>
                </div>
            </fieldset>
            <fieldset class="Form-fieldset">
                <xsl:call-template name="ccompView">
                    <xsl:with-param name="ccomp" select="Form/ArtistContract/ControlledComposition"/>
                </xsl:call-template>
            </fieldset>
            <xsl:call-template name="albumList"/>
            <xsl:call-template name="trackList"/>
        </div>
    </xsl:template>

    <xsl:template name="termView">
        <fieldset class="Form-fieldset contractTerms">
            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">Contract Terms</h3>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'editTerms'" />
                    <xsl:with-param name="content" select="'Edit Terms'" />
                    <xsl:with-param name="url">
                        <xsl:text>?c=edit&amp;ArtistContractID=</xsl:text>
                        <xsl:value-of select="Form/ArtistContract/ArtistContractID" />
                        <xsl:text>#terms</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
            <xsl:if test="Form/ArtistContract/TermList/Term/ArtistContractTermID or normalize-space(Form/ArtistContract/DefaultTerm/Rate)">
                <table class="Table Table-with-highlight" id="termTable">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col rowLeft">Priority</th>
                            <th class="Table-col">Source</th>
                            <th class="Table-col">Region</th>
                            <th class="Table-col">Channel</th>
                            <th class="Table-col">Price</th>
                            <th class="Table-col">Rate Type</th>
                            <th class="Table-col">Rate</th>
                            <th class="Table-col">
                                <span class="Table-col-wrapper">Rate</span>
                                <xsl:call-template name="helpIcon">
                                    <xsl:with-param name="tip">% of Rate Payable (more or less than 100%)</xsl:with-param>
                                </xsl:call-template>
                                <div>Reduction</div>
                            </th>
                            <th class="Table-col">% of Sales</th>
                            <th class="Table-col">Packaging</th>
                            <th class="Table-col">Free Goods</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="Form/ArtistContract/TermList/Term">
                            <xsl:call-template name="termRowView"/>
                        </xsl:for-each>
                        <xsl:if test="normalize-space(Form/ArtistContract/DefaultTerm/Rate)">
                            <xsl:call-template name="defaultTermRowView"/>
                        </xsl:if>
                    </tbody>
                </table>
            </xsl:if>
            <xsl:if
                test="not(Form/ArtistContract/TermList/Term/ArtistContractTermID) and not(normalize-space(Form/ArtistContract/DefaultTerm/ArtistContractTermID))">
                <section class="Table-empty-results">
                    <p>No terms have been set for this contract.</p>
                </section>
            </xsl:if>
        </fieldset>
        <fieldset class="Form-fieldset liquidationScheduleHolder">
            <xsl:call-template name="liquidationScheduleView">
                <xsl:with-param name="liquidationSchedule" select="Form/ArtistContract/ReserveLiquidationList/ReserveLiquidation"/>
                <xsl:with-param name="reserveRate" select="Form/ArtistContract/ReserveRate"/>
            </xsl:call-template>
            <xsl:variable name="unitBasedScheduleTest">
                <xsl:for-each select="Form/ArtistContract/ReserveLiquidationList/ReserveLiquidation">
                    <xsl:if test="normalize-space(Percent)">
                        <xsl:value-of select="Percent"/>
                    </xsl:if>
                </xsl:for-each>
            </xsl:variable>
            <xsl:if test="normalize-space($unitBasedScheduleTest)">
                <div class="Form-input-annotation Reserve-types">
                    <xsl:choose>
                        <xsl:when test="Form/ArtistContract/DigitalReservesEnabled = 1">Physical and Digital</xsl:when>
                        <xsl:otherwise>Physical Only</xsl:otherwise>
                    </xsl:choose>
                </div>
            </xsl:if>
        </fieldset>
    </xsl:template>

    <xsl:template name="termRowView">
        <xsl:variable name="termPosition" select="position() - 1"/>
        <tr class="Table-row Table-row-data" id="contractTerm{position()}">
            <td class="Table-col rowLeft">
                <xsl:value-of select="Priority"/>
            </td>
            <td class="Table-col">
                <xsl:variable name="sourceID">
                    <xsl:value-of select="ContractTermSourceID"/>
                </xsl:variable>
                <xsl:value-of select="/Root/Form/ContractTermSourceList/ContractTermSource[ContractTermSourceID = $sourceID]/Name"/>
            </td>
            <td class="Table-col">
                <xsl:variable name="regionID">
                    <xsl:value-of select="RegionID"/>
                </xsl:variable>
                <xsl:value-of select="/Root/Form/RegionList/Region[RegionID = $regionID]/Name"/>
            </td>
            <td class="Table-col">
                <xsl:if test="ChannelID > 0">
                    <xsl:variable name="channelID">
                        <xsl:value-of select="ChannelID"/>
                    </xsl:variable>
                    <xsl:value-of select="/Root/Form/ChannelList/Channel[ChannelID = $channelID]/Name"/>
                </xsl:if>
                <xsl:if test="ChannelID = 0">
                    All
                </xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="PriceLevelID > 0">
                    <xsl:variable name="priceID">
                        <xsl:value-of select="PriceLevelID"/>
                    </xsl:variable>
                    <xsl:value-of select="/Root/Form/PriceLevelList/PriceLevel[PriceLevelID = $priceID]/Name"/>
                </xsl:if>
                <xsl:if test="PriceLevelID = 0">
                    All
                </xsl:if>
            </td>
            <td class="Table-col">
                <xsl:variable name="rateTypeID">
                    <xsl:value-of select="ContractRateTypeID"/>
                </xsl:variable>
                <xsl:value-of select="/Root/Form/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateTypeID]/Name"/>
            </td>
            <td class="Table-col">
                <xsl:if test="ContractRateTypeID = 6">
                    <xsl:value-of select="/Root/Client/Locale/CurrencyFormat/Symbol"/>
                </xsl:if>
                <xsl:value-of select="Rate"/>
                <xsl:if test="ContractRateTypeID != 6">%</xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="normalize-space(RateReduction)"><xsl:value-of select="RateReduction"/>%</xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="normalize-space(PercentageOfSales)"><xsl:value-of select="PercentageOfSales"/>%</xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="normalize-space(PackagingDeduction)"><xsl:value-of select="PackagingDeduction"/>%</xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="normalize-space(FreeGoodsDeduction)"><xsl:value-of select="FreeGoodsDeduction"/>%</xsl:if>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="defaultTermRowView">
        <tr class="Table-row Table-row-data defaultRow{count(Form/ArtistContract/TermList/Term) mod 2}" id="contractTermDefault">
            <td class="Table-col rowLeft">Default</td>
            <xsl:choose>
                <xsl:when test="Form/ArtistContract/DefaultTerm/Inactive = 1">
                    <td class="Table-col" colspan="10">The default term is currently inactive.</td>
                </xsl:when>
                <xsl:otherwise>
                    <td class="Table-col">All</td>
                    <td class="Table-col">All</td>
                    <td class="Table-col">All</td>
                    <td class="Table-col">All</td>
                    <td class="Table-col">% Net Revenue</td>
                    <td class="Table-col">
                        <xsl:value-of select="Form/ArtistContract/DefaultTerm/Rate"/>%
                    </td>
                    <td class="Table-col">
                        <xsl:value-of select="Form/ArtistContract/DefaultTerm/RateReduction"/>%
                    </td>
                    <td class="Table-col">
                        <xsl:value-of select="Form/ArtistContract/DefaultTerm/PercentageOfSales"/>%
                    </td>
                    <td class="Table-col">
                        <xsl:value-of select="Form/ArtistContract/DefaultTerm/PackagingDeduction"/>%
                    </td>
                    <td class="Table-col">
                        <xsl:value-of select="Form/ArtistContract/DefaultTerm/FreeGoodsDeduction"/>%
                    </td>
                </xsl:otherwise>
            </xsl:choose>
        </tr>
    </xsl:template>

    <xsl:template name="expenseList">
        <fieldset class="Artist-contract-column expenseList">
            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">Recoupable Expenses</h3>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'editExpenses'" />
                    <xsl:with-param name="content" select="'Edit'" />
                    <xsl:with-param name="url">
                        <xsl:text>artist_contract?c=expense&amp;ArtistContractID=</xsl:text>
                        <xsl:value-of select="Form/ArtistContract/ArtistContractID" />
                    </xsl:with-param>
                </xsl:call-template>
            </div>
            <xsl:if test="Form/ExpenseTypeList/ExpenseType/ExpenseTypeID">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Expense Type</th>
                            <th class="Table-col">Recoupable</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="Form/ExpenseTypeList/ExpenseType[Inactive = 0]">
                            <tr class="Table-row Table-row-data">
                                <td class="Table-col">
                                    <xsl:value-of select="ExpenseName"/>
                                </td>
                                <td class="Table-col">
                                    <xsl:value-of select="Percent"/>%
                                </td>
                            </tr>
                        </xsl:for-each>
                    </tbody>
                </table>
            </xsl:if>
            <xsl:if test="not(Form/ExpenseTypeList/ExpenseType/ExpenseTypeID)">
                <section class="Table-empty-results">
                    <p>No active recoupable expenses are associated with this contract.</p>
                </section>
            </xsl:if>
        </fieldset>
    </xsl:template>

    <xsl:template name="sourceList">
        <fieldset class="Artist-contract-column sourceList">
            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">License Income Sources</h3>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'editSources'" />
                    <xsl:with-param name="content" select="'Edit'" />
                    <xsl:with-param name="url">
                        <xsl:text>artist_contract?c=license_income&amp;ArtistContractID=</xsl:text>
                        <xsl:value-of select="Form/ArtistContract/ArtistContractID" />
                    </xsl:with-param>
                </xsl:call-template>
            </div>
            <xsl:variable name="activeSources" select="Form/ArtistContractLicenseIncomeList/ArtistContractLicenseIncome[Inactive = 0]"/>
            <xsl:if test="$activeSources">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Income Type</th>
                            <th class="Table-col">Net Revenue Rate</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="$activeSources">
                            <tr class="Table-row Table-row-data">
                                <td class="Table-col">
                                    <xsl:value-of select="LicenseIncomeType"/>
                                </td>
                                <td class="Table-col"><xsl:value-of select="Percent"/>%
                                </td>
                            </tr>
                        </xsl:for-each>
                    </tbody>
                </table>
            </xsl:if>
            <xsl:if test="not($activeSources)">
                <section class="Table-empty-results">
                    <p>No license income sources are associated with this contract.</p>
                </section>
            </xsl:if>
        </fieldset>
    </xsl:template>

    <xsl:template name="albumList">
        <fieldset class="Form-fieldset">
            <h3>Albums</h3>
            <xsl:if test="Form/AlbumContractList/AlbumContract/Album/AlbumID">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Title</th>
                            <th class="Table-col">Catalog #</th>
                            <xsl:if test="Form/LabelList/Label">
                                <th class="Table-col">Label</th>
                            </xsl:if>
                            <th class="Table-col">Artist</th>
                            <th class="Table-col">Contract Status</th>
                            <th class="Table-col">Expenses</th>
                            <th class="Table-col">
                                <span class="Table-col-wrapper">XC</span>
                                <xsl:call-template name="helpIcon">
                                    <xsl:with-param name="tip">Cross Collateralize</xsl:with-param>
                                </xsl:call-template>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="Form/AlbumContractList/AlbumContract/Album">
                            <xsl:sort select="translate(Title,$lcletters,$ucletters)"/>
                            <xsl:call-template name="albumListRow"/>
                        </xsl:for-each>
                    </tbody>
                </table>
            </xsl:if>
            <xsl:if test="not(Form/AlbumContractList/AlbumContract/Album)">
                <section class="Table-empty-results">
                    <p>No albums are currently associated with this contract.</p>
                </section>
            </xsl:if>
        </fieldset>
    </xsl:template>

    <xsl:template name="albumListRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col">
                <a href="catalog?AlbumID={AlbumID}&amp;c=show">
                    <xsl:value-of select="Title"/>
                    <xsl:if test="TitleVersion != ''">(<xsl:value-of select="TitleVersion"/>)
                    </xsl:if>
                </a>
            </td>
            <td class="Table-col">
                <xsl:value-of select="CatalogNumber"/>
            </td>
            <xsl:if test="/Root/Form/LabelList/Label">
                <td class="Table-col">
                    <xsl:variable name="albumLabelID">
                        <xsl:value-of select="LabelID"/>
                    </xsl:variable>
                    <xsl:value-of select="/Root/Form/LabelList/Label[LabelID = $albumLabelID]/LabelName"/>
                </td>
            </xsl:if>
            <td class="Table-col">
                <xsl:value-of select="ArtistName"/>
            </td>
            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="../Status = 1">Active</xsl:when>
                    <xsl:when test="../Status = 2">Inactive</xsl:when>
                </xsl:choose>
            </td>
            <td class="Table-col">
                <a href="/rps/catalog?c=expense&amp;AlbumContractID={../AlbumContractID}">View</a>
            </td>
            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="$openRuns &gt; 0">
                        <xsl:if test="../CrossCollateralized = 0">No</xsl:if>
                        <xsl:if test="../CrossCollateralized = 1">Yes</xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <a href="catalog?c=cc&amp;ArtistContractID={../ContractID}&amp;AlbumContractID={../AlbumContractID}">
                            <xsl:if test="../CrossCollateralized = 0">No</xsl:if>
                            <xsl:if test="../CrossCollateralized = 1">Yes</xsl:if>
                        </a>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="trackList">
        <fieldset class="Form-fieldset">
            <h3>Tracks</h3>
            <xsl:if test="Form/TrackContractList/TrackContract/Track/TrackID">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Title</th>
                            <th class="Table-col">Artist</th>
                            <th class="Table-col">Album</th>
                            <th class="Table-col">Length</th>
                            <th class="Table-col">Proration</th>
                            <th class="Table-col">Contract Status</th>
                            <th class="Table-col">Expenses</th>
                            <th class="Table-col">
                                <span class="Table-col-wrapper">XC</span>
                                <xsl:call-template name="helpIcon">
                                    <xsl:with-param name="tip">Cross Collateralize</xsl:with-param>
                                </xsl:call-template>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="Form/TrackContractList/TrackContract/Track">
                            <xsl:sort select="translate(Title,$lcletters,$ucletters)"/>
                            <xsl:call-template name="trackListRow"/>
                        </xsl:for-each>
                    </tbody>
                </table>
            </xsl:if>
            <xsl:if test="not(Form/TrackContractList/TrackContract/Track)">
                <section class="Table-empty-results">
                    <p>No tracks are currently associated with this contract.</p>
                </section>
            </xsl:if>
        </fieldset>
    </xsl:template>

    <xsl:template name="trackListRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col">
                <a href="track?TrackID={TrackID}&amp;c=show">
                    <xsl:value-of select="Title"/>
                </a>
            </td>
            <td class="Table-col">
                <xsl:value-of select="ArtistName"/>
            </td>
            <td class="Table-col">
                <xsl:value-of select="../AlbumTitle"/>
            </td>
            <td class="Table-col">
                <xsl:value-of select="Duration"/>
            </td>
            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="$openRuns &gt; 0">
                        <xsl:value-of select="../ProrateTrackCount"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <a href="javascript:void(0);" onClick="ContractPage.editProration({../ContractID},{../TrackContractID},{../ProrateTrackCount}, event);">
                            <xsl:value-of select="../ProrateTrackCount"/>
                        </a>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="../Status = 1">Active</xsl:when>
                    <xsl:when test="../Status = 2">Inactive</xsl:when>
                </xsl:choose>
            </td>
            <td class="Table-col">
                <a href="/rps/track?c=expense&amp;TrackContractID={../TrackContractID}">View</a>
            </td>
            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="$openRuns &gt; 0">
                        <xsl:if test="../CrossCollateralized = 0">No</xsl:if>
                        <xsl:if test="../CrossCollateralized = 1">Yes</xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <a href="track?c=cc&amp;ArtistContractID={../ContractID}&amp;TrackContractID={../TrackContractID}">
                            <xsl:if test="../CrossCollateralized = 0">No</xsl:if>
                            <xsl:if test="../CrossCollateralized = 1">Yes</xsl:if>
                        </a>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="termList">
        <div class="termList">
            <h3>Physical Terms:</h3>
            <hr/>
            <div class="contractDetailList">
                <xsl:if test="not($terms/Term)">
                    No terms have been created.
                    <br/>
                </xsl:if>
                <xsl:for-each select="$terms/*">
                    <xsl:call-template name="termListRow">
                        <xsl:with-param name="mode" select="$mode"/>
                    </xsl:call-template>
                </xsl:for-each>
            </div>
            <input type="button" name="editTerms" value="Edit"
                   onClick="location.href='?c=term&amp;ArtistContractID={Form/ArtistContract/ArtistContractID}&amp;Mode={$mode}'"
                   class="editSectionButton"/>
        </div>
    </xsl:template>

    <xsl:template name="productFormatOption">
        <option value="{ProductFormatID}">
            <xsl:if test="ParentID != 0">-</xsl:if>
            <xsl:value-of select="Name"/>
        </option>
    </xsl:template>

    <xsl:template name="termListRow">
        <xsl:variable name="channelID" select="ChannelID"/>
        <xsl:variable name="priceLevelID" select="PriceLevelID"/>
        <xsl:value-of select="Percent"/>% of
        <xsl:if test="$mode = 1">
            <xsl:if test="$priceLevelID != 0">
                <xsl:value-of select="/Root/Form/PriceLevelList/PriceLevel[PriceLevelID = $priceLevelID]/Name"/> Priced
            </xsl:if>
            <xsl:if test="$channelID != 0">
                <xsl:value-of select="/Root/Form/ChannelList/Channel[ChannelID = $channelID]/Name"/> Channel
            </xsl:if>
        </xsl:if>
        <xsl:if test="ProductFormat/Name != 'All Physical'"><xsl:value-of select="ProductFormat/Name"/>&#160;
        </xsl:if>
        sales
        <br/>
    </xsl:template>

    <xsl:template name="deductionList">
        <div class="deductionList">
            <h3>
                <xsl:if test="$mode = 1">Physical</xsl:if>
                <xsl:if test="$mode != 1">Digital</xsl:if>
                Deductions:
            </h3>
            <hr/>
            <div class="contractDetailList">
                <xsl:if test="not($deductions/Deduction)">
                    No deductions have been created.
                    <br/>
                </xsl:if>
                <xsl:for-each select="$deductions/Deduction">
                    <xsl:value-of select="Percent"/>% for
                    <xsl:value-of select="DeductionType/Name"/>
                    <br/>
                </xsl:for-each>
            </div>
            <input type="button" name="EditDeductions" value="Edit"
                   onClick="location.href='?c=deduction&amp;ArtistContractID={Form/ArtistContract/ArtistContractID}&amp;Mode={$mode}'"
                   class="editSectionButton"/>
        </div>
    </xsl:template>

    <xsl:template name="escalationList">
        <div class="escalationList escalationMode{$mode}">
            <h3>
                <xsl:if test="$mode = 1">Physical</xsl:if>
                <xsl:if test="$mode = 3">Digital Album</xsl:if>
                <xsl:if test="$mode = 4">Digital Single</xsl:if>
                Escalations:
            </h3>
            <hr/>
            <div class="contractDetailList">
                <xsl:if test="not($escalations/UnitEscalation)">
                    No escalations have been created.
                    <br/>
                </xsl:if>
                <xsl:for-each select="$escalations/UnitEscalation">
                    <xsl:if test="PennyBased = 1">
                        <xsl:value-of select="/Root/Client/Locale/CurrencyFormat/Symbol"/>
                    </xsl:if>
                    <xsl:value-of select="Amount"/>
                    <xsl:if test="PennyBased = 0">%</xsl:if>
                    at
                    <xsl:value-of select="Units"/> units
                    <br/>
                </xsl:for-each>
            </div>
            <input type="button" name="EditEscalations" value="Edit"
                   onClick="location.href='?c=unit_escalation&amp;ArtistContractID={Form/ArtistContract/ArtistContractID}&amp;Mode={$mode}'"
                   class="editSectionButton"/>
        </div>
    </xsl:template>
</xsl:stylesheet>
