<!--- 
  Filename:     NextN3.cfm
  Created by:   Nate Weiss (NMW)
  Purpose:      Displays Next N record-navigation interface
  Please Note:  Includes NextNIncludeBackNext.cfm and NextNIncludePageLinks
--->

<!--- Retrieve expense records from database --->
<cfquery name="getExp" datasource="#APPLICATION.DataSource#">
  SELECT 
    f.FilmID, f.MovieTitle, 
    e.Description, e.ExpenseAmount, e.ExpenseDate
  FROM 
    Expenses e INNER JOIN Films f
    ON e.FilmID = f.FilmID
  ORDER BY 
    e.ExpenseDate DESC
</cfquery>


<!--- Number of rows to display per Next/Back page  --->
<cfset rowsPerPage = 10>

<!--- What row to start at? Assume first by default --->
<cfparam name="URL.startRow" default="1" type="numeric">

<!--- We know the total number of rows from query   --->
<cfset totalRows = getExp.recordCount>

<!--- Last row is 10 rows past the starting row, or --->
<!--- total number of query rows, whichever is less --->
<cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>

<!--- Next button goes to 1 past current end row  --->
<cfset startRowNext = endRow + 1>

<!--- Back button goes back N rows from start row --->
<cfset startRowBack = URL.startRow - rowsPerPage>

<html>
<head><title>Expense Browser</title></head>
<body>
<cfoutput><h2>#APPLICATION.CompanyName# Expense Report</h2></cfoutput>

<!--- Simple Style Sheet for formatting --->
<style>
  th       {font-family:sans-serif;font-size:smaller;
            background:navy;color:white}
  td       {font-family:sans-serif;font-size:smaller}
  td.DataA {background:silver;color:black}
  td.DataB {background:lightgrey;color:black}
</style>

<table width="600" border="0" cellSpacing="0" cellPadding="1">
  <!--- Row at top of table, above column headers --->
  <tr>
    <td width="500" colSpan="3">
      <!--- Message about which rows are being displayed --->
      <cfoutput>
        Displaying <b>#URL.startRow#</b> to <b>#endRow#</b>
        of <b>#TotalRows#</b> Records<br>
      </cfoutput>
    </td>
    <td width="100" align="right">
      <!--- Provide Next/Back links --->
      <cfinclude template="NextNIncludeBackNext.cfm">
    </td>
  </tr>

  <!--- Row for column headers --->
  <tr>
    <th width="100">Date</th>
    <th width="250">Film</th>
    <th width="150">Expense</th>
    <th width="100">Amount</th>
  </tr>
  
  <!--- For each query row that should be shown now --->
  <cfloop query="getExp" startRow="#URL.startRow#" endRow="#endRow#">
    <!--- Use class "DataA" or "DataB" for alternate rows --->
    <cfset class = iif(getExp.currentRow mod 2 eq 0, "'DataA'", "'DataB'")>
  
    <cfoutput>
      <tr valign="baseline">
        <td class="#class#" width="100">#lsDateFormat(ExpenseDate)#</td>
        <td class="#class#" width="250">#MovieTitle#</td>
        <td class="#class#" width="150"><i>#Description#</i></td>
        <td class="#class#" width="100">#lsCurrencyFormat(ExpenseAmount)#</td>
      </tr>
    </cfoutput>
  </cfloop>
  
  <!--- Row at bottom of table, after rows of data --->
  <tr>
    <td width="500" colSpan="3">
      <!--- Shortcut links for "Pages" of search results --->
      Page <cfinclude template="NextNIncludePageLinks.cfm">
    </td>
    <td width="100" align="right">
      <!--- Provide Next/Back links --->
      <cfinclude template="NextNIncludeBackNext.cfm">
    </td>
  </tr>
</table>


</body>
</html>
