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

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

if ($permission_num==1) {

include ("../navigation/store_sidebar.php");

$delivery_no = $_GET['delivery_no'];

   
		$table_name = $_SESSION['db_prefix']."_deliver_product";
		$quote_query = "SELECT *  FROM $table_name WHERE delivery_no = '".$delivery_no."'";
		$quote_result = $con->query($quote_query);
		$row = mysqli_fetch_assoc($quote_result);
		$cust_id = $row["cust_id"];
		$deliver_date=$row["deliver_date"];
		$del_col=$row["del_col"];
		$order_no=$row["order_no"];
		$pallets=$row["pallets"];
		$pallets_price=$row["pallets_price"];
		$delivery_address=$row["delivery_address"];			 
		$delivered_by=$row["delivered_by"];
		$delivery_time=$row["delivery_time"];	
		$vehicle_reg=$row["vehicle_reg"];	
		
		
				
		$table_name = $_SESSION['db_prefix']."_deliver_product_lines";
		$line_query = "SELECT *  FROM $table_name WHERE delivery_no = '".$delivery_no."' AND quantity > 0 ";
		$line_result = $con->query($line_query);
		$line_num = mysqli_num_rows($line_result);
	
	//$quote_no = $order_no;
	
?>

<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>
<script type="text/javascript">
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
</head>

<body>

<div class="main_frame" >
  <div class="page_head_frame">
        <table width="650" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="483"><label class="label_page_head">Delivery note</label></td>
            <td width="167" align="right"><label class="label_page_head_2">Delivery no <?php echo $delivery_no?>
</label></td>
          </tr>
        </table>
  </div><br />
<div class="page_middle_frame">
<div class="wizard_frame">

</div>
<br>

         <div class="wizard_frame">
         <table width="652" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="483">Order no <?php echo $order_no ?> delivered to:</td>
    <td width="169">Delivery date: <?php echo date("d-m-Y", strtotime($deliver_date)) ?></td>
  </tr>
</table>

        <?php 
		include ('../include/customer_block.php');
		?>
         </div><br>
         Delivery address:
         <table width="650" id="table_display" >
  <tr>
    <td width="118">Delivery addres:</td>
    <td colspan="3"><?php echo $delivery_address ?></td>
    </tr>
  <tr>
    <td>Delivery made by:</td>
    <td><?php echo $delivered_by ?></td>
    <td>Delivery time:</td>
    <td><?php echo $delivery_time ?></td>
    </tr>
  <tr>
    <td>Driver:</td>
    <td width="156"><?php echo $delivered_by ?></td>
    <td width="116">Vehicle reg:</td>
    <td width="240"><?php echo $vehicle_reg ?></td>
  </tr>
    </table>

<br>
<div class="wizard_frame">
Items delivered:
         <table width="600" id="table_display" >
           <tr>
             <td width="238" height="26" align="left" valign="top">Item</td>
             <td width="111" align="left" valign="top">Batch codes</td>
             <td width="31" align="left" valign="top">Unit</td>
             <td width="56" align="left" valign="top">Quantity</td>
             <td align="left" valign="top">Unit price</td>
             <td align="left" valign="top">Line total</td>
           </tr>
           <?php
				$a7_total=0;
				while($row = $line_result->fetch_assoc()) {
					$a0 = $row["delivery_line_id"];
					$a1 = $row["product_item_id"];
					$a2 = $row["quantity"];
					$a5 = $row["batch_code"];
					$a6 = $row["price"];
					
					$a7 = $a6 * $a2;
				 	
					$a7_total = $a7_total + $a7;
					
					 
					 $table_name = $_SESSION['db_prefix']."_product_store";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE product_item_id = '".$a1."' ";
						$item_result = $_result = $con->query($item_query);
						$row = mysqli_fetch_assoc($item_result);
						$a1a = $row["item_name"];
						$a3a = $row["unit"];
						$a4a = $row["subCategory"];
					 
					 
			?>
           <tr>
             <td valign="top"><?php echo $a1a ?></td>
             <td valign="top"><?php echo $a5 ?></td>
             <td valign="top"><?php echo $a3a ?></td>
             <td valign="top"><?php echo $a2 ?></td>
             <td width="140" align="right" valign="top"><?php echo number_format($a6, 2, '.', ',') ?></td>
             <td width="140" align="right" valign="top"><?php echo number_format($a7, 2, '.', ',') ?></td>
           </tr>
           <?php 
			 }
		$pallets_total =$pallets * $pallets_price; 
		$a7_total = $a7_total + $pallets_total;
				 ?>
          
           <tr>
             <td valign="top">Pallets</td>
             <td valign="top">&nbsp;</td>
             <td valign="top">&nbsp;</td>
             <td 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($pallets_total, 2, '.', ',') ?></td>
           </tr>
           <tr>
             <td height="38" colspan="5" align="right" valign="middle">Total:&nbsp;&nbsp;</td>
             <td align="right" valign="middle"><?php echo number_format($a7_total, 2, '.', ',') ?></td>
           </tr>       
         </table>
         </div>
         <br>
<br>


    <table width="642" height="50" align="left" id="table_button_bar">
        <tr>
          <td>
          <form action="product_deliver_print.php?" method="get" target="_blank">
          <input name="delivery_no" type="hidden" value="<?php echo $delivery_no ?>">
          <input type="submit" name="print_button" id="print_button" value="Print" class="imagebutton"></a>
          &nbsp;&nbsp;&nbsp;
          <input type="checkbox" name="print_checkbox" id="print_checkbox">&nbsp;&nbsp;print prices on delivery note
          </form>
          </td>
          
          <td width="66" align="right">&nbsp;</td>
          <td width="162" align="right"><input type="button" name="close_button" id="close_button" value="Close" class="imagebutton" onClick="MM_goToURL('parent','store_main.php?date=&subCatSelect=Tiles');return document.MM_returnValue" ></td>
        </tr>
      </table>

</div>
</div>    
  
</div>


</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/store_main.php?date=0&subCatSelect=Tiles";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>