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

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


<table width="600" border="0" cellSpacing="0" cellPadding="1" cols="3">
 <!--- Row at top of table, above column headers --->
 <tr>
 <td colSpan="2">
 <!--- 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></td>
 <td 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#">
 <cfoutput>
 <tr valign="baseline">
 <td width="100">#lsDateFormat(ExpenseDate)#</td>
 <td width="250">#MovieTitle#</td>
 <td width="150"><em>#Description#</em></td>
 <td width="100">#lsCurrencyFormat(ExpenseAmount)#</td>
 </tr>
 </cfoutput>
 </cfloop>
 
 <!--- Row at bottom of table, after rows of data --->
 <tr>
 <td colSpan="4" align="right">
 <!--- Provide Next/Back links --->
 <cfinclude template="NextNIncludeBackNext.cfm">
 </td>
 </tr>
</table>


</body>
</html>
