<cfparam name="cart_grand_total" default="0">
<cfparam name="url.is_admin_view" default="0">

<cfquery name="get_order_info" datasource="#application.datasource#">
	SELECT	    O.OrderTypeID, O.OrderBusinessID, O.OrderRemarks
	FROM	    Orders O
	WHERE		O.OrderUUID = '#form.OrderUUID#'
</cfquery>

<cfquery name="get_parent_items_in_order" datasource="#application.datasource#">
SELECT	    O.OrderTypeID, O.OrderID, OL.OrderLineItemID, OL.OrderLineItemQuantity, OL.OrderLineItemRemark, I.ItemID, I.ItemName, I.ItemPrice, B.BusinessTaxRate, I.ItemCategoryID, ttO.tt_OrderTypeName<cfif get_order_info.OrderTypeID eq 3>, A.*</cfif><cfif url.is_admin_view EQ 0>, T.TaskAddedOn</cfif>
FROM	    Orders O, OrderLineItems OL, Items I, Businesses B, tt_OrderTypes ttO<cfif get_order_info.OrderTypeID eq 3>, Addresses A</cfif><cfif url.is_admin_view EQ 0>, Tasks T</cfif>
WHERE		O.OrderUUID = '#form.OrderUUID#'
				AND 
			OL.OrderLineItemParentOrderLineItemID = 0
				AND 
			OL.OrderLineItemItemID = I.ItemID
				<!--- AND 
			OL.OrderLineItemIsDeleted = 0 --->
				AND 
			OL.OrderLineItemOrderID = O.OrderID
				AND
			B.BusinessID = O.OrderBusinessID
				AND
			<cfif url.is_admin_view EQ 0>O.OrderID = T.TaskOrderID
				AND</cfif>
			<cfif get_order_info.OrderTypeID eq 3>A.AddressID = O.OrderAddressID
				AND </cfif>
			ttO.tt_OrderTypeID = O.OrderTypeID
ORDER BY 	OrderLineItemAddedOn DESC
</cfquery>

<cfoutput><cfif url.is_admin_view EQ 0>Ordered On #dateformat(get_parent_items_in_order.TaskAddedOn, "mm/dd/yy")# at #timeformat(get_parent_items_in_order.TaskAddedOn, "hh:mm tt")#<br></cfif>

#get_parent_items_in_order.tt_OrderTypeName#<cfif get_order_info.OrderTypeID eq 3> to #get_parent_items_in_order.AddressLine1#</cfif></cfoutput></br>
		
<cfif get_parent_items_in_order.OrderLineItemRemark gt "">
	<font color="FF0000"><cfoutput>#get_order_info.OrderRemarks#</cfoutput></font>
</cfif>

<table border="0" cellspacing="2" cellpadding="2">
	<tr><td>Name</td><td>Quant</td><td>Price</td><td>Total</td><td>&nbsp;</td></tr>
	
	<cfset PaymentPayfritsCut = 0>

	<cfoutput query="get_parent_items_in_order">
	
		<cfif get_parent_items_in_order.ItemCategoryID neq 31>
		
			<cfset PaymentPayfritsCut = PaymentPayfritsCut + (get_parent_items_in_order.ItemPrice*get_parent_items_in_order.OrderLineItemQuantity*.05)>
		
		</cfif>				

		<tr><td>#get_parent_items_in_order.ItemName#</td><td align="middle">#get_parent_items_in_order.OrderLineItemQuantity#</td><td align="right">#dollarformat(get_parent_items_in_order.ItemPrice)#</td><td>#dollarformat(get_parent_items_in_order.ItemPrice * get_parent_items_in_order.OrderLineItemQuantity)#</td>
		
			<td>
			
				<!--- <script language="JavaScript">
					function submitformdelitem#get_parent_items_in_order.OrderLineItemID#()
					{
					document.myformdelitem#get_parent_items_in_order.OrderLineItemID#.submit();
					}
				</script>
				
				<form action="#request.cgiPath#" method="post" name="myformdelitem#get_parent_items_in_order.OrderLineItemID#" id="myformdelitem#get_parent_items_in_order.OrderLineItemID#" style="display:inline;">
					
					<a href="javascript: submitformdelitem#get_parent_items_in_order.OrderLineItemID#()">X</a>
					
					<input type="hidden" name="mode" value="delitem">
					<input type="hidden" name="OrderTypeID" value="#form.OrderTypeID#">
					<input type="hidden" name="BusinessID" value="#form.BusinessID#">
					<input type="hidden" name="OrderID" value="#form.OrderID#">
					<input type="hidden" name="OrderLineItemID" value="#get_parent_items_in_order.OrderLineItemID#">
					<input type="hidden" name="AddressID" value="#form.AddressID#">
				
				</form>	 --->		

			</td>
		
		</tr>
		<cfset cart_grand_total = cart_grand_total + get_parent_items_in_order.ItemPrice * get_parent_items_in_order.OrderLineItemQuantity>

		<cfquery name="get_child_line_items" datasource="#application.datasource#">
			SELECT	    I.ItemName, I.ItemID, I.ItemPrice, I.ItemParentItemID, OL.OrderLineItemID, OL.OrderLineItemParentOrderLineItemID
			FROM	    OrderLineItems OL, Items I, Orders O
			WHERE		O.OrderUUID = '#form.OrderUUID#'
							AND
						OL.OrderLineItemOrderID = O.OrderID
							AND 
						OL.OrderLineItemItemID = I.ItemID
							AND 
						OL.OrderLineItemParentOrderLineItemID = #get_parent_items_in_order.OrderLineItemID#
			ORDER BY 	OrderLineItemAddedOn DESC
		</cfquery>

		<cfif get_child_line_items.recordcount GT 0>
			<cfloop query="get_child_line_items">
				<cfquery name="get_parent_item_Name" datasource="#application.datasource#">
					SELECT 		ItemName
					FROM	    Items
					WHERE		ItemID = #get_child_line_items.ItemParentItemID#
				</cfquery>

				<tr><td colspan="3">&nbsp;&nbsp;#get_parent_item_Name.ItemName# : #get_child_line_items.ItemName# (#dollarformat(get_child_line_items.ItemPrice)#)</td><td align="right">#dollarformat(get_child_line_items.ItemPrice * get_parent_items_in_order.OrderLineItemQuantity)#</td>
				
					<td>&nbsp;</td>
				
				</tr>
				<cfset cart_grand_total = cart_grand_total + get_child_line_items.ItemPrice * get_parent_items_in_order.OrderLineItemQuantity>
			</cfloop>
		</cfif>
		
		<cfif get_parent_items_in_order.OrderLineItemRemark gt "">
			<tr><td colspan="4"><font color="FF0000">&nbsp; &nbsp; &nbsp; ^ ^ ^#get_parent_items_in_order.OrderLineItemRemark#^ ^ ^</font></td></tr>
		</cfif>

	</cfoutput>

</table>

Cart total: <cfoutput>#dollarFormat(cart_grand_total)#</cfoutput><br>

<cfset order_grand_total = cart_grand_total>

<cfif get_parent_items_in_order.BusinessTaxRate GT 0>
	<cfset tax_amount = round(cart_grand_total * get_parent_items_in_order.BusinessTaxRate*100)/10000>
	<cfset order_grand_total = order_grand_total + tax_amount>
<cfelse>
	<cfset tax_amount = 0>
</cfif>
Tax Amount = <cfoutput>#dollarformat(tax_amount)#</cfoutput><br>

Subtotal = <cfoutput>#dollarformat(tax_amount+cart_grand_total)#</cfoutput><br>

<!--- <cfset PaymentPayfritsCut = cart_grand_total*.05> --->
Payfrit's cut = <cfoutput>#dollarformat(PaymentPayfritsCut)#</cfoutput><br>

<cfset order_grand_total = order_grand_total + PaymentPayfritsCut>

<cfif get_parent_items_in_order.OrderTypeID eq 3> <!--- delivery --->

	<cfmodule template = "modules/get_delivery_fee.cfm" OrderID = "#get_parent_items_in_order.OrderID#">

	<cfset PaymentOrderDeliveryFee = #calculated_delivery_fee#>
	
	Delivery Fee = <cfoutput>#dollarformat(PaymentOrderDeliveryFee)#</cfoutput><br>
	<cfset order_grand_total = order_grand_total + PaymentOrderDeliveryFee>

<cfelse>

	<cfset PaymentOrderDeliveryFee = 0>

</cfif>

<h3>GRAND TOTAL: <cfoutput>#dollarformat(order_grand_total)#</cfoutput></h3>