<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
include ("../navigation/header.php");

$page_name = "Orders-main";
include ("../navigation/access.php");

if ($permission_num==1) {

include ("../navigation/orders_sidebar.php");
	
include('../include/period_select_date.php');

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

$table_name2 = $_SESSION['db_prefix']."_orders";
$order_query = "SELECT order_no, order_reference,  cust_id, del_col, order_date, delivery_date, delivered, project_no, project_place  FROM $table_name2 WHERE order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."' AND ordered = 'yes' AND (delivered = 'part' OR delivered IS NULL) ORDER BY order_date DESC ";
$order_result = mySQL_query($order_query);
$order_num = mysql_num_rows($order_result);	
?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
       
</head>

<body>

<div class="main_frame">
 
  <div class="page_head_frame">
    <label class="label_page_head">Outstanding orders</label></div>
<div class="page_middle_frame">
<?php
$page='outstanding_order_list.php';
$reference_name='';
$reference='';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block_2.php');
?>      
<br>
<br>  

<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": [[ 1, "desc" ]],
					"aoColumns": [
								{"iDataSort": 8},
								{"iDataSort": 6},
								{"bSortable": true},
								{"iDataSort": 7},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>

<div class="page_inside_frame">
            <label class="label_end"><img src="../images/round_green.png" width="8" height="8" />: Delivered&nbsp;&nbsp;<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&nbsp;&nbsp;</label> 
            There are <?php echo $order_num ?> outstanding orders in this list. 
</div>

<div class="page_inside_frame">
          
<table width="617" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th width="58" >Order no</th>
              <th width="59" >Order Date</th>
              <th width="67" >Deliver/<br>Collect</th>
              <th width="87" >Del/Col Date</th>
              <th >Customer</th>
              <th >&nbsp;</th>
              <th width="23" >&nbsp;</th>
              <th width="23">&nbsp;</th>
              <th width="23">&nbsp;</th>
              <th width="23">&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;

$a7tot=0;
$price=0;
while ($i<$order_num) {
	$a1 = mysql_result($order_result, $i, "order_no");
	$a1a = mysql_result($order_result, $i, "order_reference");
		
	     $a2 = mysql_result($order_result, $i, "cust_id");
	     $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 = mySQL_query($customer_query);
		 $customer_num = mysql_num_rows($customer_result);
		 if ($customer_num!=0) {
         $a2a = mysql_result($customer_result, 0, "comp_name");
		 $a2b = mysql_result($customer_result, 0, "bag_box");
		 $a2c = mysql_result($customer_result, 0, "box_no");
		 $a2d = mysql_result($customer_result, 0, "postal_place");
		 $a2e = mysql_result($customer_result, 0, "phone");
		 $a2f = mysql_result($customer_result, 0, "contact_1");
		 $a3 = mysql_result($customer_result, 0, "status");
		 
		 }
	
	$a4 = mysql_result($order_result, $i, "del_col");
	$a5 = mysql_result($order_result, $i, "order_date");
	$a6 = mysql_result($order_result, $i, "delivery_date");
	$a7 = '';
	$a11 = mysql_result($order_result, $i, "delivered");
	$a14 = mysql_result($order_result, $i, "project_no");
	$a15 = mysql_result($order_result, $i, "project_place");
	
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$line_query = "SELECT  store_item_id, quantity, delivered FROM $table_name WHERE order_no = '".$a1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
		
	$l=0;
	$total=0;
	$order_line_text="";
	$deliver_line_text="";
	$products=mysql_result($line_result, 0, "store_item_id");
		
	while($l<$line_num) {
		$store_item_id = mysql_result($line_result, $l, "store_item_id");
		$quantity = mysql_result($line_result, $l, "quantity");
		$delivered = mysql_result($line_result, $l, "delivered");
		$balance = $quantity-$delivered;		
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
		$name_result = mySQL_query($name_query);
		$store_item_name = mysql_result($name_result, 0, "item_name");
		
			  
	   	$order_line_text = $order_line_text."<tr><td>".$store_item_name."</td><td>".$quantity."</td><td>".$delivered."</td><td>".$balance."</td></tr>";
		$deliver_line_text = "<tr><td>".$a14."</td></tr><tr><td>".$a15."</td></tr>";
	   $l++;
	}
	
	$orderTT ="<table id=table_tool_tip width=350 ><tr><td>Item</td><td>Quantity</td><td>Delivered</td><td>Balance</td></tr>".$order_line_text."</table><br><b>Click for details</b>";
	
	$deliverTT ="<b>Deliver to:</b><table id=table_tool_tip width=200 >".$deliver_line_text."</table><br><b>Click for details</b>";

	
	$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>";
		
	?>
            <tr>
              <td align="left"  style="padding-left:0px;"><a href="../store/order.php?order_reference=<?php echo $a1a ?> " onmouseover="ddrivetip('<?php echo $orderTT?>', 350)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td align="left"><?php if($a4=='deliver') { ?><a href="" onMouseover="ddrivetip('<?php echo $deliverTT ?>', 200)"; onMouseout="hideddrivetip()"><?php echo $a4 ?></a> <?php } else { echo $a4; } ?></td>
              <td align="left"><?php if ($a6!='0000-00-00') { if ($a6<$today){ ?><font color="#FF3300"> <?php echo date("d-m-Y", strtotime($a6)); ?> </font> <?php } else { echo date("d-m-Y", strtotime($a6));} }?></td>
              <td width="187" 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 width="23" align="center"><?php if ($a11=="yes") { ?>
                <img src="../images/round_green.png" width="12" height="12"  />
                <?php } ?>
                <?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>
              <td align="left"><?php echo $a7 ?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td align="right" valign="bottom">&nbsp;</td>
                <td align="right" valign="bottom">&nbsp;</td>
                <td align="right" valign="bottom">&nbsp;</td>
                <td align="right" valign="bottom">&nbsp;</td>
                <td align="right" valign="bottom">&nbsp;</td>
                <td align="right" valign="bottom">&nbsp;</td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
              </tr>
            </tfoot>
          </table>
</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=";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>

