<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");

$order_reference = $_GET['order_reference'];

	
$table_name2 = $_SESSION['db_prefix']."_orders";
$order_query = "SELECT * FROM $table_name2 WHERE order_reference ='".$order_reference."' ";
$order_result = $con->query($order_query);
$order_num = mysqli_num_rows($order_result);
while($row = $order_result->fetch_assoc()) {
$order_no = $row["order_no"];
$cust_id = $row["cust_id"];
$order_no  = $row["order_no"];
$cust_id  = $row["cust_id"];
$order_date  = $row["order_date"];
$delivery_date  = $row["delivery_date"];
$delivery_contact  = $row["delivery_contact"];
$delivery_phone  = $row["delivery_phone"];
$project_no  = $row["project_no"];
$project_place  = $row["project_place"];
$pallets  = $row["pallets"];
$pallets_price  = $row["pallets_price"];
$del_col  = $row["del_col"];
$additional_info  = $row["additional_info"];
$ordered  = $row["ordered"];
}

$table_name3 = $_SESSION['db_prefix']."_customer";
$account_query = "SELECT cust_id, comp_name, bag_box, box_no, postal_place, phone, contact_1, email_1, cell_1 FROM $table_name3 WHERE cust_id = '".$cust_id."' ";
$account_result = $con->query($account_query);
while($row = $account_result->fetch_assoc()) {
$c1 = $row["comp_name"];
$c2 = $row["bag_box"];
$c3 = $row["box_no"];
$c4 = $row["postal_place"];
$c5 = $row["phone"];
$c6 = $row["contact_1"];
}

$accountTT = "<label class=tip_text_label>".$c1."<br>".$c2."<br>".$c4."<br>".$c5."<br>".$c6."<br><label class=tip_click_label>Click for details</label>";


?>

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>


</head>

<body  onload="<?php if ($ordered=='no') { ?>alertMessage(1, '', 'This ordered is cancelled.');<?php } ?>">
<div class="main_frame" style="height:auto; min-height:555px;">
<div class="page_head_frame">
          <table width="690" border="0" cellspacing="0" cellpadding="0">
          
            <tr>
              <td width="493">
              <label class="label_page_head">Order</label>&nbsp;&nbsp;&nbsp;<label style="font-size:18px; "><b><?php echo $c1 ?></b></label>
              </td>
              <td width="197"><label style="font-size:18px; ">No:&nbsp;&nbsp;<b><?php echo $order_no ?></b></label></td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
<br />
<br />

      <div class="page_middle_frame">
      <?php if ($ordered=='no') { ?><div class="page_inside_frame"><img src="../images/exclamation_mark_red_small.png" width="20" height="32" />&nbsp;&nbsp;This order is canceled.</div><?php } ?>
       <div class="page_inside_frame"> Order for:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order date:&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($order_date)) ?>  
              <?php 
		include ('../include/customer_block.php');
		echo' <br>';
		?>
       
      
        
          <table width="642" id="table_display" >
            <tr>
              <td width="155" valign="top"><?php if ($del_col=='deliver') {echo 'Delivery date:'; } else { echo 'Collection date:';} ?> </td>
              <td colspan="3" valign="top"><?php if ($delivery_date!='2000-01-01') { echo date("d-m-Y", strtotime($delivery_date));} else { echo 't.b.a.'; } ?></td>
            </tr>
            
            <tr>
              <td><?php if ($del_col=='deliver') {echo 'Delivery address:'; } ?></td>
              <td colspan="3"><?php if ($del_col=='deliver') { echo $project_no.' '.$project_place ;} ?></td>
            </tr>
            <tr>
              <td>Contact:</td>
              <td width="149"><?php echo $delivery_contact ?></td>
              <td width="76">Cell/phone:</td>
              <td width="242" align="left" valign="top"><?php echo $delivery_phone ?></td>
            </tr>
            <tr>
              <td>Notes:</td>
              <td colspan="3"><?php echo $additional_info ?></td>
            </tr>
         </table>
          <br />
          Order details:<br />
            
            <?php

$table_name = $_SESSION['db_prefix']."_order_lines";
$line_query = "SELECT *  FROM $table_name WHERE  order_reference =  '".$order_reference."'";
$line_result = $con->query($line_query);
$line_num = mysqli_num_rows($line_result);

				  ?>
            
            <input name="order_reference" type="hidden" value="<?php echo $order_reference ?>" />   
          </p>
          <table width="670" id="table_display" >
            <tr>
                  <td width="213" height="26" align="left" valign="top">Item</td>
                  <td width="41" align="center" valign="top">Unit</td>
                  <td width="76" align="center" valign="top">Ordered</td>
                  <td width="61" align="center" valign="top">Unit price</td>
                  <td width="106" align="center" valign="top">Line total</td>
                  <td width="76" align="center" valign="top" style="background-color:#CCC;">Delivered</td>
                  <td width="65" align="center" valign="top" style="background-color:#CCC;">Balance</td>
            </tr>
                <?php
				$a8_tot=0;
				while($row = $line_result->fetch_assoc()) {
					$a0 = $row["order_line_id"];
					$a1 = $row["product_item_id"];
					$a2 = $row["quantity"];
					$a3 = $row["delivered"];
					$a5 = $row["returned"];
					$a7 = $row["price"];
				
					$table_name = $_SESSION['db_prefix']."_product_store";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE product_item_id = '".$a1."' ";
						$item_result = $con->query($item_query);
						while($row = $item_result->fetch_assoc()) {
							$a1a = $row["item_name"];
							$a3a = $row["unit"];
							$a4a = $row["subCategory"];
						}
			      $a6 = $a2 - $a3;
				  
				  $a8 = $a2 * $a7;
				  
				  $a8_tot = $a8_tot + $a8;
								 
				 ?>
                <tr>
                  <td valign="top"><?php echo $a1a ?></td>
                  <td valign="top"><?php echo $a3a ?></td>
                  <td align="right" valign="top"><?php echo number_format($a2, 0, '.', ','); ?></td>
                  <td align="right" valign="top"><?php echo number_format($a7, 2, '.', ','); ?></td>
                  <td align="right" valign="top"><?php echo number_format($a8, 2, '.', ','); ?></td>
                  <td align="right" valign="top" style="background-color:#CCC;"><?php echo number_format($a3, 0, '.', ','); ?></td>
                  <td align="right" valign="top" style="background-color:#CCC;"><?php echo number_format($a6, 0, '.', ','); ?></td>
                </tr>
                <?php 
			     }
				 $a9 = $pallets * $pallets_price;
				 $a8_tot = $a8_tot + $a9;
				 
				 if ($pallets>0) {?>
                <tr>
                  <td> Pallets</td>
                  <td>&nbsp;</td>
                  <td align="right" valign="top"><?php echo $pallets ?></td>
                  <td align="right" valign="top"><?php echo number_format($pallets_price, 2, '.', ','); ?></td>
                  <td align="right" valign="top"><?php echo number_format($a9, 2, '.', ','); ?></td>
                  <td align="right" valign="top" style="background-color:#CCC;">&nbsp;</td>
                  <td align="right" valign="top" style="background-color:#CCC;">&nbsp;</td>
                </tr>
                <?php } ?>
                <tfoot>
                <tr>
                  <td colspan="4" align="right">Total:&nbsp;&nbsp;</td>
                  <td align="right" valign="top"><?php echo number_format($a8_tot, 2, '.', ','); ?></td>
                  <td colspan="2" align="right" valign="top">&nbsp;</td>
                  </tr>
                </tfoot>
         </table>
         <br />
              <!--<div style="float:left;">
				<a href="order_print.php?order_reference=<?php echo $order_reference ?>" target="_blank"><input name="print_button" id="print_button" type="button" value="Print" class="imagebutton" /></a>
		 </div>-->
  
 <br />
<br />
<br />
</div>

<div class="page_inside_frame">

<?php
$a7='';
		 	$table_name = $_SESSION['db_prefix']."_deliver_product";
			$deliver_query = "SELECT delivery_no FROM $table_name WHERE order_no = '".$order_no."' ";
			$deliver_result = $con->query($deliver_query);
			$deliver_num = mysqli_num_rows($deliver_result);
			
			while($row = $deliver_result->fetch_assoc()) {
				$delivery_no = $row["delivery_no"];
				
			
			$table_name = $_SESSION['db_prefix']."_deliver_product_lines";
			$item_query = "SELECT product_item_id, quantity FROM $table_name WHERE delivery_no = '".$delivery_no."' ";
			$item_result = $con->query($item_query);
			$item_num = mysqli_num_rows($item_result);
			
			$deliveryTT_lines='';
			while($row = $item_result->fetch_assoc()) {
				$product_item_id = $row["product_item_id"];
				$quantity = $row["quantity"];
			
			$table_name = $_SESSION['db_prefix']."_product_store";
			$item_name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$product_item_id."' ";
			$item_name_result = $con->query($item_name_query);
			while($row = $item_name_result->fetch_assoc()) {
					$item_name = $row["item_name"];
				}
						
			$deliveryTT_lines = $deliveryTT_lines."<tr><td width=150px;>".$item_name."</td><td width=50px;>".$quantity."</td></tr>";
			
			}
			
			
			 $deliveryTT = " 'Delivery no: ".$delivery_no."<br><table width=200px;>".$deliveryTT_lines." </table><br>Click for details'";;
			 $a7 = $a7.' <a href="../store/deliver_product_display.php?delivery_no='.$delivery_no.'" onMouseover="ddrivetip('.$deliveryTT.', 200)"; onMouseout="hideddrivetip()">'.$delivery_no.'</a>&nbsp;&nbsp;&nbsp;';
			 
			}
?>

Deliveries on this order:&nbsp;&nbsp;&nbsp;<?php echo $a7 ?>
</div>
  </div>
  
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "orders/orders_main.php?date=";	
include ("../navigation/orders_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>