 					</cfloop>
 					<th>Total</th>
 				</tr>
-				<cfset currProd = 0>
-				<cfset totCount = 0>
-				<cfset block = {}>
-				<cfset totals = {}>
-				<cfloop query="QItemAnalysis">
-					<cfif currProd neq 0 AND currProd neq prodID>
-						<tr>
-							<td>#catTitle#</td>
-							<td>#prodTitle#</td>
-							<td>#siUnitSize#</td>
-							<cfloop from="#startHour#" to="#endHour#" index="i">
-								<cfif StructKeyExists(block,i)>
-									<cfset theValue = StructFind(block,i)>
+				
+				<cfloop array="#productArray#" index="prodrec">
+					<cfset theProduct = StructFind(products,prodrec)>
+					<tr>
+						<td>#theProduct.groupTitle#</td>
+						<td>#theProduct.catTitle#</td>
+						<td>#theProduct.prodTitle#</td>
+						<td>#theProduct.siUnitSize#</td>
+						<cfset lineTotal = 0>
+						<cfloop from="#startHour#" to="#endHour#" index="i">
+							<cfif StructKeyExists(theProduct,i)>
+								<cfset theValue = StructFind(theProduct,i)>
+								<cfset lineTotal += theValue>
 									<cfif StructKeyExists(totals,i)>
 										<cfset oldValue = StructFind(totals,i)>
 										<cfset StructUpdate(totals,i,oldValue + theValue)>
 									<cfelse>
 										<cfset StructInsert(totals,i,theValue)>
 									</cfif>
-									<td align="center">#theValue#</td>
-								<cfelse>
-									<td></td>
-								</cfif>
-							</cfloop>
-							<td align="center">#totCount#</td>
-						</tr>
-						<cfset block = {}>
-						<cfset totCount = 0>
-					</cfif>
-					<cfset currProd = prodID>
-					<cfset totCount += recCount>
-					<cfset StructInsert(block,hh,recCount)>
+								<td align="center">#theValue#</td>
+							<cfelse>
+								<td></td>
+							</cfif>
+						</cfloop>
+						<td align="center">#lineTotal#</td>
+					</tr>
 				</cfloop>
+
 				<cfset grandTotal = 0>
 				<tr>
-					<th colspan="3">Totals</th>
+					<th colspan="4">Totals</th>
 					<cfloop from="#startHour#" to="#endHour#" index="i">
 						<cfif StructKeyExists(totals,i)>
 							<cfset hourTotal = StructFind(totals,i)>

					</cfloop>
					<th>#grandTotal#</th>
				</tr>
			</table>
		</cfoutput>
	</cfif>

		WHERE DATE(ehTimeStamp) >= '#parm.reportDateFrom#'
		AND DATE(ehTimeStamp) <= '#parm.reportDateTo#'
		AND eiClass = 'sale'
        GROUP BY groupTitle, catTitle, prodTitle, siUnitSize, hh
	</cfquery>
</cfif>
<body>
