<?php 
	include ('includes/db1config.php');
	include ('../includes/mysql_connect.php');

	
	if( isset($_GET['id']) ){
		$customer  = "SELECT orders.*,orderItem.qty,menuItem.itemName,menuItem.itemPrice,guestLogin.FirstName,guestLogin.LastName,guestLogin.Address1,guestLogin.City,guestLogin.State,guestLogin.Zip,guestLogin.Phone,guestLogin.pickup,guestLogin.paymethod,guestLogin.delivery_zone from orders 
		INNER JOIN orderItem  ON orderItem.orderNumber=orders.orderNumber
		INNER JOIN menuItem   ON menuItem.itemKey=orderItem.itemNumber
		INNER JOIN guestLogin ON guestLogin.UserKey=orders.UserKey
		WHERE orders.recordKey=".$_GET['id'];
		$custArray = mysql_query($customer);  // query executed
		echo mysql_error(); 

		$str = '<center>
			<style type="text/css" media="screen">
    			.orders td{
                    font-size:12px;
                }.orderItems td{
    				font-size:12px;
    			}
                #OrderViewTop{
                    border-collapse: collapse;
                    margin-left: -372px;
                    margin-top: 27px;
                    text-align: center;
                    width: 46%;
                }
                #header {
                    background: black none repeat scroll 0 0;
                    margin-right: -3px !important;
                    color:white;
                }
                #header > td {
                    border-right: 2px solid white;
                }
                .orders > td {
                    border: 1px solid black;
                }
    		</style>
            <table width=100% cellpadding=5 cellspacing=5 id="OrderViewTop" >
            <tr class="orders" id="header" >
                <td>
                    <strong>Order #</strong>
                </td>
                <td style="width:51%" >
                    <strong>Time of order</strong>
                </td>
                <td style="width:45%" >
                    <strong>Del/PU</strong>
                </td>
                
            </tr>';
			
            while ( $row = mysql_fetch_array($custArray)) {
                $str .='<tr class="orders">
                        <td width=10%>' . $row['orderNumber'] . '</td>
                        <td width=10%>' . date('H:i',strtotime($row['orderTime'])) . '<br>'.date('l',strtotime($row['orderTime'])).' '.date('F',strtotime($row['orderTime'])).' '.date('d',strtotime($row['orderTime'])).',</br>'.date('Y',strtotime($row['orderTime'])).'</td>
                        <td width=10%><span style="color:red;">Delivery <br>to:</span><br> ' . $row['FirstName'] . ' ' . $row['LastName'] . '<br>'.$row['Address1'].'<br>'.$row['City'].','.$row['State'].'<br>'.$row['Zip'].'<br>'.$row['Phone'].'</td>
                    </tr>';
                    break;
            }

            $str .= '<table width=100% cellpadding=5 cellspacing=5 id="OrderView" >
            <tr class="orderItems" >
                <td style="width:65%">
                    <strong>Qty</strong>
                </td>
                <td>
                    <strong>Item</strong>
                </td>
                <td>
                    <strong>Price</strong>
                </td>
                <td>
                    <strong>Extended Total</strong>
                </td>
            </tr>
            <tr class="appendInvoice">
                <td colspan="4"><hr/></td>
            </tr>';
            $grandTotal = 0;
            while ( $row = mysql_fetch_array($custArray)) {
                $str .='<tr class="orderItems">
                        <td>' . $row['qty'] . '</td>
                        <td>' . $row['itemName'] .'</td>
                        <td>' . ($row['itemPrice'] != NULL ? '$'.$row['itemPrice'] : '-' ) .'</td>
                        <td>$' . $row['orderTotal'] .'</td>
                    </tr><tr class="appendInvoice">
                <td colspan="4"><hr/></td>
            </tr>';
            $grandTotal += $row['orderTotal'];
            } 

            if($grandTotal != 0){

                $str.='<tr>
                    <td colspan="4"><b style="float:right;">Total (including tax/delivery) $'.$grandTotal.'</b></td>
                </tr>';
            }

            $str.='</table>
        	</table>
    		</center>';
			echo $str;
	} else {
		echo "<h1>Something Went wrong please try again after some time</h1>";
	}
	
?>