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


$direct_delivery_no = $_GET['direct_delivery_no'];

$table_name = $_SESSION['db_prefix']."_direct_delivery";
$cash_query = "SELECT cust_id  FROM $table_name WHERE direct_delivery_no = '".$direct_delivery_no."' ";
$cash_result = mySQL_query($cash_query);
$cash_num = mysql_num_rows($cash_result);
$cust_id = mysql_result($cash_result, 0, "cust_id");

$quote='no';

$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
			
$table_name = $_SESSION['db_prefix']."_direct_delivery";
$supply_id_query = "SELECT direct_delivery_id, direct_delivery_no, issue_date FROM $table_name WHERE  direct_delivery_no = '".$direct_delivery_no."' ";
$supply_id_result = mySQL_query($supply_id_query);
$supply_id_num = mysql_num_rows($supply_id_result);
$direct_delivery_id = mysql_result($supply_id_result, 0, "direct_delivery_id");
$supply_date = mysql_result($supply_id_result, 0, "issue_date");
	
			
$table_name = $_SESSION['db_prefix']."_direct_delivery_lines";
$item_query = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE  direct_delivery_no = '".$direct_delivery_no."' ";
$item_result = mySQL_query($item_query);
$item_num = mysql_num_rows($item_result);

?>

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

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

</head>
<body>
<?php
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" style="height:auto;">
 <div class="page_head_frame">
     <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Direct delivery</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2">&nbsp;&nbsp;&nbsp; <?php echo $name ?></label></td>
            <td width="208">&nbsp;</td>
            </tr>
        </table>
      </div>
 <div class="page_middle_frame">
 
<div class="page_inside_frame"> 
<?php 
		include ('../include/customer_block.php');
		echo '<br>';
		
		?>
</div>

<div class="page_inside_frame"><br>
  Direct delivery no: <?php echo $direct_delivery_no ?>&nbsp;&nbsp;&nbsp;&nbsp;Delivery date: <?php echo date("d-m-Y", strtotime($supply_date)) ?>
   <table width="650" id="table_details_display">
  <tr>
    <td width="448">Item</td>
    <td width="89" align="center">Supply</td>
    <td width="92" align="center">unit</td>
  </tr>
  <?php
  $i=0;
  while ($i<$item_num) {
	  $store_item_id = mysql_result($item_result, $i, "store_item_id");
	  $spec_name = mysql_result($item_result, $i, "item_name");
	  
	  		if (($store_item_id!=0) AND ($store_item_id<100000)) {
	       		$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, register, unit 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");
				$register = mysql_result($name_result, 0, "register");
				$unit = mysql_result($name_result, 0, "unit");
			}
			
					 
			if ($register=='yes') {
				  	$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number FROM $table_name WHERE job_card = '".$direct_delivery_no."' AND store_item_id = '".$store_item_id."'  ";
					$register_result = mySQL_query($register_query);
					$serial = mysql_result($register_result, 0, "serial_number");
			}
			
	  $delivered = mysql_result($item_result, $i, "quantity");
	  ?>
  <tr>
    <td><?php echo $store_item_name ?> <?php if ($register=='yes') { echo 'serial no: '.$serial ; }?> </td>
    <td align="center"><?php if ($unit!='no') {echo number_format($delivered, 2, '.', ',');} else { echo number_format($delivered, 0, '.', ','); } ?></td>
    <td align="center"><?php echo $unit ?>&nbsp;</td>
  </tr>
  <?php
  $i++;
  }
  ?>
</table>

</div>

<div class="page_inside_frame">
<a href="direct_delivery_print.php?direct_delivery_no=<?php echo $direct_delivery_no  ?>" target="_blank"><input name="print_button" type="button" class="imagebutton" value="Print delivery note"></a>
</div>

</div>
</div>

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

</body>
<?php } else {
$_SESSION['denied_return'] = "store/store_main.php";	
include ("../navigation/store_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>
</html>