<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php

$_SESSION['current_page'] = "store";
include ("../navigation/header.php");
$page_name = "Stores-main";

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

?>

<div class="main_frame">
 
<div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Outstanding orders</label></td>
            </tr>
        </table>
</div>

<?php
$today = date("Y-m-d");

$table_name = $_SESSION['db_prefix']."_permissions";
$permission_query = "SELECT access_id  FROM  $table_name  WHERE access_id ='". $_SESSION['access_id']."' AND page_name = 'Orders-edit delivery date' ";
$permission_result = $con->query($permission_query);
$permission_num = mysqli_num_rows($permission_result);
if ($permission_num>0) { 
		$edit = 'yes'; 
}
else {
	$edit = 'no'; 
}

$table_name2 = $_SESSION['db_prefix']."_orders";
$deliver_query = "SELECT order_no, order_reference,  cust_id, order_date, del_col, delivery_date, delivery_contact, delivery_phone, delivered, project_no, project_place FROM $table_name2 WHERE ordered = 'yes' AND  (delivered IS NULL or delivered = 'part') ORDER BY order_date DESC ";
$deliver_result = $con->query($deliver_query);
$deliver_num = mysqli_num_rows($deliver_result);	
?>
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "420px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"iDataSort": 8},
								{"bSortable": true},
								{"iDataSort": 6},
								{"iDataSort": 7},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}
								]
				} );
			} );
		</script>


<div class="page_inside_frame">

<div align="left">
            <label class="label_end"><img src="../images/round_orange.png" width="8" height="8" />: part delivered&nbsp;&nbsp;<img src="../images/round_red.png" width="8" height="8" />:on order</label>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          <label class="label_std">There are <?php echo $deliver_num ?> outstanding orders in this list.</label> </div>
          <table width="570" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th width="50" >Order no</th>
              <th width="61" >Deliver/<br>
                Collect</th>
              <th width="57" >Order Date</th>
              <th width="66" >Deliver Date</th>
              <th width="204" >Customer</th>
              <th width="23" >&nbsp;</th>
              <th width="23" >&nbsp;</th>
              <th width="23">&nbsp;</th>
              <th width="23">&nbsp;</th>
              </tr>
            </thead>
            <?php 

$a7tot=0;
$price=0;
while($row = $deliver_result->fetch_assoc()) {
			$a1 = $row["order_no"];
			$a1a = $row["order_reference"];
			$a2 = $row["cust_id"];
			$a4 = $row["del_col"];
			$a5 = $row["order_date"];
			$a6 = $row["delivery_date"];
			$a7 = $row["delivery_contact"];
			$a8 = $row["delivery_phone"];
			$a11 = $row["delivered"];
			$a14 = $row["project_no"];
			$a15 = $row["project_place"];
	
		
	     
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 $customer_result = $con->query($customer_query);
		 $customer_num = mysqli_num_rows($customer_result);
		 if ($customer_num!=0) {
		 $row = mysqli_fetch_assoc($customer_result);
			$a2a = $row["comp_name"];
	  		$a2b = $row["bag_box"];
		 	$a2c = $row["box_no"];
		 	$a2d = $row["postal_place"];
		 	$a2e = $row["phone"];
		 	$a2f = $row["contact_1"];
		 	$a3 = $row["status"];
		 }
	
	
	
	$deliver_line_text = "<tr><td>Plot:</td><td>".$a14."</td></tr><tr><td>Place:</td><td>".$a15."</td></tr><tr><td>Contact:</td><td>".$a7."</td></tr><tr><td>Cell/phone:</td><td>".$a8."</td></tr>";
	
	$collect_line_text = "<tr><td>Contact:</td><td>".$a7."</td></tr><tr><td>Cell/phone:</td><td>".$a8."</td></tr>";
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$line_query = "SELECT  product_item_id, quantity, delivered FROM $table_name WHERE order_reference = '".$a1a."' ";
	$line_result = $con->query($line_query);
	$line_num = mysqli_num_rows($line_result);
	
	$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";


	$deliverTT ="<b>To be delivered</b><table id=table_tool_tip width=200 >".$deliver_line_text."</table>";
	
	$collectTT ="<b>To be collected</b><table id=table_tool_tip width=200 >".$collect_line_text."</table>";
	
	
	$total=0;
	
	$line_text2="";
	//$products=mysql_result($line_result, 0, "store_item_id");
		
	while($row = $line_result->fetch_assoc()) {
		$product_item_id = $row["product_item_id"];
		$quantity = $row["quantity"];
		$delivered = $row["delivered"];
		
		$table_name = $_SESSION['db_prefix']."_product_store";
		$name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$product_item_id."'  ";
		$name_result = $con->query($name_query);
		$row = mysqli_fetch_assoc($name_result);
			$store_item_name = $row['item_name'];

		$balance = $quantity - $delivered;
					  
	   	$line_text2 = $line_text2."<tr><td>".$store_item_name."</td><td align=right>".$quantity."</td><td align=right>".$delivered."</td><td align=right>".$balance."</td></tr>";
	}


$orderTT ="<b>".'---'."</b><br><table id=table_tool_tip width=400 ><tr><td>Item</td><td align=center>Ordered</td><td align=center>Delivered</td><td align=center>Balance</td></tr>".$line_text2."</table><br><table><tr><td>Notes:</td><td></td></tr>".'---'."</table>";



	
	?>
            <tr>
              <td align="left"  style="padding-left:0px;"><a href="order.php?order_reference=<?php echo $a1a ?> " onmouseover="ddrivetip('<?php echo $orderTT?>', 450)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td ><?php if($a4=='deliver') { ?>
                <a href="" onMouseover="ddrivetip('<?php echo $deliverTT ?>', 200)"; onMouseout="hideddrivetip()"><?php echo $a4 ?></a>
              <?php } else { ?>
			  <a href="" onMouseover="ddrivetip('<?php echo $collectTT ?>', 200)"; onMouseout="hideddrivetip()"><?php echo $a4 ?></a>
              <?php } ?></td>
              <td align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td align="left"><?php if ($edit=='yes') { ?>
			  <a href="" onMouseOver="ddrivetip('Click to change delivery date.', 250)"; onMouseOut="hideddrivetip()" onClick=
    "editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/change_delivery_date.php?order_reference=<?php echo $a1a ?>', 'Change delivery date.', 'width=450px,height=250px,center=1,resize=0,scrolling=0');
needToConfirm = false;
editwindow.onclose=function(){return window}; return false;">
<?php 
if ($a6!='2000-01-01') {
if ($a6!='2000-01-01') { if ($a6<$today){ ?><font color="#FF3300"> <?php echo date("d-m-Y", strtotime($a6)); ?> </font> <?php } else { echo date("d-m-Y", strtotime($a6));} }?></a><?php } else { if ($a6!='2000-01-01') { if ($a6<$today){ ?><font color="#FF3300"> <?php echo date("d-m-Y", strtotime($a6)); ?> </font> <?php } else { echo date("d-m-Y", strtotime($a6));} } }?>
<?php } ?>
<?php if ($a6=='2000-01-01') { echo 't.b.a.'; } ?>			  
              
              </td>
              <td align="left"><a href="../store/account_details.php?cust_id=<?php echo $a2 ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a ?></a>
</td>
              <td align="center"><?php if ($a11=="part") { ?>
                <img src="../images/round_orange.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="") { ?>
                <img src="../images/round_red.png" width="12" height="12"   />
              <?php } ?></td>
              <td align="left"><?php echo $a5 ?></td>
              <td  align="left"><?php echo $a6 ?></td>
              <td  align="left"><?php echo $a1 ?></td>
            </tr>
            <?php
}
?>
          </table>
 
 </div>
</div>



<?php include ('../navigation/side_bar.php'); ?>

</body>

<?php } else {
	
$_SESSION['denied_return'] = $_SESSION['location'];	
include ("../navigation/store_sidebar.php");
include ('../navigation/side_bar.php');
?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>


</html>