<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:include href="/app/tools/common/production/templates/list_nav.xsl" />

  <xsl:template name="posFileSection" >
    <fieldset>
      <legend>Daily POS Feeds</legend>
      <xsl:call-template name="posMessaging" />      
      <xsl:call-template name="posFileList" />
    </fieldset>
  </xsl:template>


  <xsl:template name="posMessaging">
    <xsl:if test="Messages/Message/Type = 'error'">
      <p class="errorGeneral messageBox">
        <xsl:if test="Messages/Message/Code = 'download_unavailable'">
          File cannot be downloaded at this time.
        </xsl:if>
      </p>
    </xsl:if>
  </xsl:template>
  

  <xsl:template name="posFileList" >

    <xsl:choose>

      <xsl:when test="PosFileList/PosFile">
          <xsl:call-template name="posFileListBody" />
      </xsl:when>

      <xsl:otherwise>
        <xsl:call-template name="collectionListEmpty" />
      </xsl:otherwise>

    </xsl:choose>

  </xsl:template>


  <xsl:template name="posFileListBody" >

    <div style="margin: 0 auto; text-align: center;">
      <form method="get" action="/support/bookpub" id="posFilesPerPage">
        <input type="hidden" name="c" value="pos_feed" />
        <select name="pageSize" id="pageSize">
          <option value="25">
            25
          </option>
          <option value="50">
            <xsl:if test="PosFileList/Pagination/PageSize = 50">
              <xsl:attribute name="selected">selected</xsl:attribute>
            </xsl:if>
            50
          </option>
          <option value="100">
            <xsl:if test="PosFileList/Pagination/PageSize = 100">
              <xsl:attribute name="selected">selected</xsl:attribute>
            </xsl:if>
            100
          </option>
        </select>
         files per page
        <input type="submit" value="Update" />
      </form>

      <b><xsl:value-of select="PosFileList/TotalRecords" /></b> files<xsl:if test="PosFileList/TotalRecords > 0"> - Page <b><xsl:value-of select="PosFileList/Pagination/Page" /></b> of <b><xsl:value-of select="PosFileList/Pagination/NumPages" /></b></xsl:if>

      <br />

      <xsl:call-template name="numericListNav">
        <xsl:with-param name="pagination">/Root/PosFileList/Pagination</xsl:with-param>
        <xsl:with-param name="extraParams" />
      </xsl:call-template>

    </div>

    <table class="dataset">
      <tbody>
        <tr class="header">
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'date_start'" />
            <xsl:with-param name="displayName" select="'Date'" />
          </xsl:call-template>
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'service_name'" />
            <xsl:with-param name="displayName" select="'Service'" />
          </xsl:call-template>
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'orig_file_name'" />
            <xsl:with-param name="displayName" select="'File Name'" />
          </xsl:call-template>
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'units'" />
            <xsl:with-param name="displayName" select="'Units'" />
          </xsl:call-template>
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'revenue'" />
            <xsl:with-param name="displayName" select="'Revenue'" />
          </xsl:call-template>
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'remaining_exceptions'" />
            <xsl:with-param name="displayName" select="'Exceptions'" />
          </xsl:call-template>
          <xsl:call-template name="posFileHeaderCell">
            <xsl:with-param name="sortBy" select="'file_status'" />
            <xsl:with-param name="displayName" select="'Status'" />
          </xsl:call-template>
        </tr>

        <xsl:for-each select="PosFileList/PosFile" >
          <xsl:call-template name="displayPosFileRow" />
        </xsl:for-each>
      </tbody>
    </table>
  </xsl:template>


  <xsl:template name="posFileHeaderCell">
    <xsl:param name="sortBy" />
    <xsl:param name="displayName" />
    <xsl:param name="class" />
    <th nowrap="nowrap" class="{$class}">
        <a>
            <xsl:attribute name="href">?c=pos_feed&amp;sortBy=<xsl:value-of select="$sortBy" /></xsl:attribute>
            <xsl:value-of select="$displayName" /><xsl:text> </xsl:text>
            <xsl:if test="/Root/PosFileList/SortBy = $sortBy">
        	    <xsl:choose>
        		    <xsl:when test="/Root/PosFileList/ReverseSort = 1"><img src="/production/images/asc.gif" class="sortImage" /></xsl:when>
        		    <xsl:otherwise><img src="/production/images/desc.gif" class="sortImage" /></xsl:otherwise>
        	    </xsl:choose>
            </xsl:if>
        </a>
    </th>
  </xsl:template>


  <xsl:template name="displayPosFileRow" >
    <tr class="row{position() mod 2}">
      <td>
        <xsl:value-of select="DateStart" />
      </td>
      <td>
        <xsl:variable name="serviceID" select="ServiceID" />
        <xsl:value-of select="/Root/ServiceList/Service[ServiceID = $serviceID]/ServiceName" />
      </td>
      <td>
        <a href="?c=saveas&amp;POSFileID={POSFileID}">
          <xsl:value-of select="OrigFileName" />
        </a>
      </td>
      <td>
        <xsl:value-of select="Units" />
      </td>
      <td>
        <xsl:value-of select="Revenue" />
      </td>
      <td>
        <xsl:choose>
          <xsl:when test="Status = 'Error'">--</xsl:when>
          <xsl:when test="RemainingExceptions = 0">0</xsl:when>
          <xsl:otherwise>
            <a href="/bookpub/matcher?c=sale_pos&amp;file={POSFileID}">
              <xsl:value-of select="RemainingExceptions" />
            </a>
          </xsl:otherwise>
        </xsl:choose>
      </td>
      <td>
        <xsl:choose>
          <!-- Status is error or invalid then allow a retry -->
          <xsl:when test="FileStatus = 8 or FileStatus = 3">
            <xsl:value-of select="FileStatusText" />
            (<a href="?c=retry_pos&amp;posFileID={POSFileID}">retry</a>)
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="FileStatusText" />
          </xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>
