<!--                                                                  -->
<!--  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:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:include href="/app/tools/bookpub/templates/global.xsl" />
    <xsl:include href="/app/tools/bookpub/templates/tracker/messages.xsl" />

    <xsl:variable name="displayPriceExceptions" select="/Root/Access/bookpub/tracker/price_exceptions" />

    <xsl:template name="pickLayout">
        <script type="text/javascript" src="/production/javascript/bookpub/tracker.js"></script>
        <div class="Tracker-edit-page-container FinishLayout">

            <xsl:if test="Messages/Message/Type = 'error'">
                <xsl:call-template name="trackerErrorMessages" />
            </xsl:if>

            <xsl:choose>
                <xsl:when test="File/FileStatus = 5">
                    <xsl:call-template name="fileFinishedMessage" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="fileFinishLayout" />
                </xsl:otherwise>
            </xsl:choose>

        </div>
    </xsl:template>

    <xsl:template name="fileFinishedMessage">
        <xsl:choose>
            <xsl:when test="normalize-space(NewFile/FileID)">
                <p class="FinishLayout-status-text">
                    <span class="FileName">
                        <xsl:choose>
                            <xsl:when test="normalize-space(File/ParentFileID)">
                                <xsl:value-of select="File/PrettyFileName" />
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="translate(File/OrigFileName,'_',' ')" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </span> split successfully!
                </p>
                <p><span class="FileName"><xsl:value-of select="File/PrettyFileName" /></span> contains the clean sales records.</p>
                <p><span class="FileName"><xsl:value-of select="NewFile/PrettyFileName" /></span> contains the faulty sales records.</p>
            </xsl:when>
            <xsl:otherwise>
                <p><span class="FileName"><xsl:value-of select="File/PrettyFileName" /></span> imported and processed successfully!</p>
            </xsl:otherwise>
        </xsl:choose>
        <p><a class="ReturnToLink" href="/bookpub/tracker?page={Params/page}#file{File/FileID}">Return to Revenue File Tracker</a></p>
    </xsl:template>

    <xsl:template name="fileFinishLayout">
        <xsl:call-template name="helpLink">
            <xsl:with-param name="extraParams">
                <xsl:if test="/Root/ClientTypes/ClientType[ClientTypeID = 9]/IsClientTypeFlag = 1">&amp;price_validation=1</xsl:if>
            </xsl:with-param>
        </xsl:call-template>
        <xsl:call-template name="messages" />
        <xsl:call-template name="fileStats" />
        <xsl:call-template name="fileFinishForm" />
    </xsl:template>

    <xsl:template name="fileStats">
        <ul class="ValuePair ValuePair-line-view">
            <li class="ValuePair-item">
                <span class="ValuePair-label">File Name</span>
                <div class="ValuePair-value">
                    <xsl:value-of select="File/PrettyFileName" />
                </div>
            </li>
            <li class="ValuePair-item">
                <span class="ValuePair-label">Service</span>
                <div class="ValuePair-value"><xsl:value-of select="File/ServiceName" /></div>
            </li>
            <li class="ValuePair-item">
                <span class="ValuePair-label">Received</span>
                <div class="ValuePair-value"><xsl:value-of select="File/DateCreated" /></div>
            </li>
            <li class="ValuePair-item">
                <span class="ValuePair-label">Units</span>
                <div class="ValuePair-value"><xsl:value-of select="File/Units" /></div>
            </li>
            <li class="ValuePair-item">
                <span class="ValuePair-label">Revenue</span>
                <div class="ValuePair-value">
                    <xsl:choose>
                        <xsl:when test="normalize-space(File/RevenueBase)">
                            <xsl:value-of select="File/RevenueBase" />
                        </xsl:when>
                        <xsl:when test="normalize-space(File/Revenue)">
                            <xsl:value-of select="File/Revenue" />
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="/Root/Client/Locale/CurrencyFormat/Symbol" />0<xsl:value-of select="/Root/Client/Locale/NumericFormat/Decimal" />00
                        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="File/CurrencyCode != /Root/Client/Locale/CurrencyFormat/CurrencyCode">
                        (<xsl:value-of select="File/Revenue" />&#160;<xsl:value-of select="File/CurrencyCode" />)&#160;
                    </xsl:if>
                </div>
            </li>
            <xsl:choose>
                <xsl:when test="$displayPriceExceptions">
                    <li class="ValuePair-item">
                        <span class="ValuePair-label">Catalog Exceptions</span>
                        <div class="ValuePair-value"><xsl:value-of select="File/RemainingExceptions" /></div>
                    </li>
                    <li class="ValuePair-item">
                        <span class="ValuePair-label">Price Exceptions</span>
                        <div class="ValuePair-value">
                            <xsl:choose>
                                <xsl:when test="normalize-space(File/PriceExceptionsUnapproved)">
                                    <xsl:value-of select="File/PriceExceptionsUnapproved" />
                                </xsl:when>
                                <xsl:otherwise>0</xsl:otherwise>
                            </xsl:choose>
                        </div>
                    </li>
                    <li class="ValuePair-item">
                        <span class="ValuePair-label">Total Exceptions</span>
                        <div class="ValuePair-value"><xsl:value-of select="File/TotalRemainingExceptions" /></div>
                    </li>
                </xsl:when>
                <xsl:otherwise>
                    <li class="ValuePair-item">
                        <span class="ValuePair-label">Exceptions</span>
                       <div class="ValuePair-value"><xsl:value-of select="File/RemainingExceptions" /></div>
                    </li>
                </xsl:otherwise>
            </xsl:choose>
        </ul>
    </xsl:template>

    <xsl:template name="fileFinishForm">
        <xsl:variable name="exceptionTotal">
            <xsl:choose>
                <xsl:when test="$displayPriceExceptions">
                    <xsl:value-of select="File/RemainingExceptions/@raw + File/PriceExceptionsUnapproved/@raw" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="File/RemainingExceptions/@raw" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <form id="confirmBoxOpener" action="/bookpub/tracker">
            <input type="hidden" name="file" value="{File/FileID}" />
            <input type="hidden" name="page" value="{Params/page}" />
            <input type="hidden" name="submit" value="1" />
            <input type="hidden" name="c" value="finish" />
            <fieldset class="Form-fieldset Form-fieldset-buttons">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Cancel'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="url" select="'/bookpub/tracker'" />
                </xsl:call-template>

                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="elemType" select="'submit'" />

                    <xsl:with-param name="content">
                        <xsl:choose>
                            <xsl:when test="$exceptionTotal > 0">
                                <xsl:text>Split File</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:text>Finish Import</xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>

                    <xsl:with-param name="onClick">
                        <xsl:if test="$exceptionTotal > 0">
                            <xsl:text>confirmSplitFile('</xsl:text>
                            <xsl:value-of select="File/PrettyFileName" />
                            <xsl:text>',</xsl:text>
                            <xsl:value-of select="File/FileID" />
                            <xsl:text>,</xsl:text>
                            <xsl:value-of select="Params/page" />
                            <xsl:text>); return false;</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </fieldset>
            <span id="ERRORstreamRevenue" class="Form-error"></span>
        </form>
    </xsl:template>

</xsl:stylesheet>
