<!--- 
  Filename:     OrderHistory.cfm
  Created by:   Nate Weiss (NMW)
  Date Created: 3/5/2001
--->

<!--- Retrieve user's orders, based on ContactID --->
<CFQUERY NAME="GetOrders" DATASOURCE="#DataSource#">
  SELECT OrderID, OrderDate, 
    (SELECT Count(*) 
     FROM MerchandiseOrdersItems oi
     WHERE oi.OrderID = o.OrderID) AS ItemCount
  FROM MerchandiseOrders o
  WHERE ContactID = #SESSION.Auth.ContactID#
  ORDER BY OrderDate DESC
</CFQUERY>

<HTML>
<HEAD>
  <TITLE>Your Order History</TITLE>
</HEAD>
<BODY>

<!--- Personalized message at top of page--->
<CFOUTPUT>
  <h2>Your Order History</h2>
  <P><B>Welcome back, #SESSION.Auth.FirstName#</B>!<BR>
  You have placed <B>#GetOrders.RecordCount#</B> 
  orders with us to date.</P>
</CFOUTPUT>


<!--- Display orders in a simple HTML table --->
<TABLE BORDER="1" WIDTH="300" CELLPADDING="5" CELLSPACING="2">
  <!--- Column headers --->
  <TR>
    <TH>Date Ordered</TH>
    <TH>Items</TH>
  </TR>

  <!--- Display each order as a table row --->
  <CFOUTPUT QUERY="GetOrders">
    <TR>
      <TD>
        <A HREF="OrderHistory.cfm?OrderID=#OrderID#">
          #DateFormat(OrderDate, "mmmm d, yyyy")#
        </A>
      </TD>
      <TD>
        <B>#ItemCount#</B>
      </TD>
    </TR>
  </CFOUTPUT>
</TABLE>

</BODY>
</HTML>
