<?php 
if ($_SESSION['order_no']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="store_no_return.php";
</script>
<?php
}
else {
$cust_id = $_SESSION['cust_id']; 
	
$table_name = $_SESSION['db_prefix']."_order_lines";
$line_query = "SELECT *  FROM $table_name WHERE order_no = '".$_SESSION['order_no']."'";
$line_result = $con->query($line_query);
$line_num = mysqli_num_rows($line_result);	


?>
</head>
<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<div class="wizard_page_middle_frame">
<div class="wizard_frame">
<?php 
	include ('../include/customer_block.php');
?><br>

<table width="650" id="table_display" >
  <tr>
    <td width="135">Delivery date:</td>
    <td width="125"><?php echo date("d-m-Y", strtotime($_SESSION['deliver_date'])) ?></td>
    <td width="98">Time:</td>
    <td width="272"><?php echo $_SESSION['hour'].':'.$_SESSION['min'] ?> </td>
  </tr>
  <tr>
    <td>Delivery address:</td>
    <td colspan="3"><?php echo $_SESSION['delivery_address'] ?></td>
    </tr>
  <tr>
    <td>Deliver vehicle reg:</td>
    <td><?php echo $_SESSION['vehicle'] ?></td>
    <td>Delivered by:</td>
    <td><?php echo $_SESSION['driver'] ?></td>
  </tr>
</table>

</div>

<form id="feedbackform" method="get" action="deliver_product_Wiz6.php" >
<div class="wizard_frame">
  <table width="650" id="table_display" >
    <tr>
      <td width="201" height="26" align="left" valign="top">Item</td>
      <td align="left" valign="top">Deliver&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Batch codes</td>
      <td align="center" valign="top">Unit price</td>
      <td align="center" valign="top">Line total</td>
      </tr>
    <?php
				$i=0;
				$a10_tot = '';
				 while($row = $line_result->fetch_assoc()) {
					$a0 = $row["order_line_id"];
					$a1 = $row["product_item_id"];
					$a6 = $row["quantity"];
					$a5 = $row["delivered"];
					$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);
						$row = mysqli_fetch_assoc($item_result);
						$a1a = $row['item_name'];
						$a3a = $row['unit'];
						$a4a = $row['subCategory'];
											
				
					$table_name = $_SESSION['db_prefix']."_deliver_product_lines_temp";
					$quantity_query = "SELECT quantity, batch_code  FROM $table_name WHERE order_reference = '".$_SESSION['order_reference']."' AND product_item_id = '".$a1."' AND user_name = '".$_SESSION['username']."'"; 
					$quantity_result = $con->query($quantity_query);
					$quantity_num = mysqli_num_rows($quantity_result);
					
					 
				 ?>
                 
<?php 
while($row = $quantity_result->fetch_assoc()) {
$a8 = $row['quantity'];
$a9 = $row['batch_code'];
$a10 = $a8 * $a7;
$a10_tot = $a10_tot + $a10; 
?>	                 
                 
    <tr>
      <td valign="middle"><?php echo $a1a ?>
        <input type="hidden" name="store_item_id<?php echo $i?>" id="store_item_id<?php echo $i?>" value="<?php echo $a1 ?>"></td>
      <td align="left" valign="middle"><input name="quantity_text<?php echo $i ?>" type="text" class="text60" id="quantity_text<?php echo $i ?>"  onkeypress="return numbersonly(this, event)" value="<?php echo $a8 ?>" style="width:30px; font-weight:bold; border:hidden; text-align:right" readonly  >
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="batch_code_text<?php echo $i ?>" type="text" style="width:170px; font-weight:bold; border:hidden;" readonly id="batch_code_text<?php echo $i ?>"   autocomplete="off"  onfocus = "this.select();" onKeyUp="ToUpper(this)" maxlength="4" value="<?php echo $a9 ?>" >							
  <br>
        
        
      </td>
      <td align="right" valign="middle"><?php echo number_format($a7, 2, '.', ',') ?></td>
      <td align="right" valign="middle"><?php echo number_format($a10, 2, '.', ',') ?></td>
      </tr>
 <?php } 
?>     
      
      
    <?php 
			   
				$i++;
				 }
				 ?>
    <?php 
	$table_name = $_SESSION['db_prefix']."_deliver_product_lines_temp";
					$quantity_query = "SELECT pallets, price  FROM $table_name WHERE order_reference = '".$_SESSION['order_reference']."' AND pallets > 0 AND user_name = '".$_SESSION['username']."'"; 
					$quantity_result = $con->query($quantity_query);
					$quantity_num = mysqli_num_rows($quantity_result);
					if ( $quantity_num> 0) {
							$row = mysqli_fetch_assoc($quantity_result);
							$a12 = $row['pallets'];
							$a13 = $row['price'];
					}
					else { 
					$a12 = '';
					$a13 = '';				
					}
					$a14 = $a12 * $a13;
					
					$a10_tot = $a10_tot + $a14;
	?>             
    <tr>
      <td height="29" align="left" valign="middle"> Pallets
        <input name="pallets_text" type="hidden" value="<?php echo $a12 ?>"> <input name="pallets_price" type="hidden" value="<?php echo $a13 ?>"></td>
      <td width="343" align="left" valign="middle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $a12 ?></td>
      <td width="90" align="right" valign="middle"><?php echo number_format($a13, 2, '.', ',') ?></td>
      <td width="90" align="right" valign="middle"><?php echo number_format($a14, 2, '.', ',') ?></td>
      </tr>
    <tr>
      <td height="38" colspan="3" align="right" valign="middle">Total: </td>
      <td align="right" valign="middle"><?php echo number_format($a10_tot, 2, '.', ',') ?></td>
    </tr>
  </table>
  <br>
    <br>
<br>
</div>
    <div class="wizard_frame">
      <input name="s" type="hidden" id="s" value="4" />
          <input name="p" type="hidden" id="p" value="4" />
          <label class="label_std">If you want to make changes use the 'Prev' button to go back. <br />
            Click 'New' to make a new entry or to finish the wizard click 'Finish'.</label>
        </div>
        <div class="wizard_frame">
      <table width="590" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;   MM_showHideLayers('wait','','show'); MM_goToURL('parent','deliver_product_Wizbase.php?s=&p=2');return document.MM_returnValue" /></td>
            <td width="115">&nbsp;</td>
            <td width="99"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="javascript:cancel_confirmation(1, '../store/store_main.php?date=0&product=salt'); needToConfirm = false;" value="Cancel" /></td>
            <td width="125"><input type="submit" name="new_button" class="imagebutton" id="new_button" value="New" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
            <td width="110"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
          </tr>
        </table>
        </div>
  
  
</form>
</div>


<?php
}
?>