<head>

<script language="JavaScript" src="../jscript/format.min.js"  type="text/javascript"></script>
<?php
$pallets = $_GET['pallets_text'];

	
$table_name = $_SESSION['db_prefix']."_store_items";
$pallet_price_query = "SELECT  price FROM $table_name WHERE store_item_id = '10000'  ";
$pallet_price_result = $con->query($pallet_price_query);
$row = mysqli_fetch_assoc($pallet_price_result);
$pallet_price = $row['price'];

$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$check_query = "SELECT delivery_line_id FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND pallets > 0  ";
$check_result = $con->query($check_query);
$check_num = mysqli_num_rows($check_result);
$row = mysqli_fetch_assoc($check_result);
$delivery_line_id = $row["delivery_line_id"];


if ($check_num>0) {
$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$pallets_query = "UPDATE $table_name SET pallets = '".$pallets."' WHERE delivery_line_id = '".$delivery_line_id."' ";
$pallets_result = $con->query($pallets_query);
}
else {
$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$pallets_query = "INSERT INTO $table_name ( cash_sale_no, pallets, price, user_name) VALUES ('".$_SESSION['cash_sale_no']."', '".$pallets."', '".$pallet_price."', '".$_SESSION['username']."' ) ";
$pallets_result = $con->query($pallets_query);
}
	
$_SESSION['pallets'] = $pallets;




$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$deliver_query = "SELECT product_item_id, quantity, price, batch_code FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND quantity > 0";
$deliver_result = $con->query($deliver_query);

$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines_temp";
$pallets_query = "SELECT pallets, price  FROM $table_name WHERE cash_sale_no = '".$_SESSION['cash_sale_no']."' AND pallets > 0 ";
$pallets_result = $con->query($pallets_query);
$row = mysqli_fetch_assoc($pallets_result);
$pallets = $row["pallets"];
$pallets_price = $row["price"];



?>

</head>
<?php include('../include/wait.php') ?>
<body onLoad="MM_showHideLayers('wait','','hide'); " onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<div class="page_middle_frame">
<form id="feedbackform" method="get" action="newCashWiz6.php" >
  <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
     <tr>
            <td width="525" >
             Cash sale delivery
               <table width="670" id="table_details_display">
                <tr>
                  <td>Cash sale no:</td>
                  <td><?php echo $_SESSION['cash_sale_no'] ?></td>
                  <td>Delivery date:</td>
                  <td><?php  echo date("d-m-Y", strtotime($_SESSION['sale_date'])); ?></td>
                </tr>
                <tr>
                  <td width="123">Receipt no</td>
                  <td width="205"><?php echo $_SESSION['receipt_no'] ?></td>
                  <td width="109">&nbsp;</td>
                  <td width="213"></td>
                </tr>
              </table>
            
            <br />
            <table width="670" id="table_details_display">
              <tr>
                  <td width="123">Name:</td>
                  <td colspan="3"><?php echo  $_SESSION['cust_name'] ?></td>
                </tr>
                <tr>
                  <td>Address:</td>
                  <td width="205"><?php echo $_SESSION['cust_address'] ?></td>
                  <td width="109">Phone/cell:</td>
                  <td width="213"><?php echo $_SESSION['phone_no'] ?></td>
                </tr><br />


                <tr>
                  <td>Place:</td>
                  <td colspan="3"><?php echo $_SESSION['cust_place'] ?></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>VAT reg no:</td>
                  <td><?php echo $_SESSION['cust_vat_number'] ?></td>
                </tr>
              </table>
            
<br />
               Deliver details:
                
              
              <br>
              
              <table width="658" id="table_display" >
                <tr>
                  <td width="189" height="26" align="left" valign="middle">Item</td>
                  <td width="181" align="left" valign="middle">Batch no</td>
                  <td width="106" align="left" valign="middle">Quantity</td>
                  <td width="76" align="left" valign="middle">Unit price</td>
                  <td width="82" align="left" valign="middle">Line total</td>
                </tr>
                <?php
				$all_total=0;
				while($row = $deliver_result->fetch_assoc()) {
				$product_item_id = $row["product_item_id"];
				$quantity = $row["quantity"];
				$price = $row["price"];
				$batch_code = $row["batch_code"];
				
				$line_total = $quantity * $price;
				$all_total = $all_total + $line_total;
				
				$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);
				$item_name = $row['item_name'];

				?>
                <tr>
                  <td valign="middle"><?php echo $item_name ?></td>
                  <td valign="middle"><?php echo $batch_code ?></td>
                  <td valign="middle"><?php echo $quantity ?></td>
                  <td align="right" valign="middle"><?php echo number_format($price, 2, '.', ',') ?></td>
                  <td align="right" valign="middle"><?php echo number_format($line_total, 2, '.', ',') ?></td>
                </tr>
                <?php
				}
				$pallet_line = $pallets * $pallet_price;
				$all_total = $all_total + $pallet_line;
				?>
                <?php if ($_SESSION['pallets']>0) { ?>
			    <tr>
                  <td align="left" valign="middle">Pallets <input name="pallets_text" type="hidden" value="<?php echo $pallets ?>"> <input name="pallets_price" type="hidden" value="<?php echo $pallets_price ?>"></td>
                  <td align="left" valign="middle">&nbsp;</td>
                  <td align="left" valign="middle"><?php echo $_SESSION['pallets'] ?></td>
                  <td align="right" valign="middle"><?php echo number_format($pallets_price, 2, '.', ',') ?></td>
                  <td align="right" valign="middle"><?php echo number_format($pallet_line, 2, '.', ',') ?></td>
                </tr>
                <?php } ?>
			    <tr>
			      <td colspan="4" align="right" valign="middle">Total:&nbsp;&nbsp;</td>
			      <td align="right" valign="middle"><?php echo number_format($all_total, 2, '.', ',') ?></td>
		        </tr>
              </table>
              <br />
<br />

            <div class="wizard_frame">
              <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>
       </td>
           
    </tr>
    <tr>
    <td>
          
              <table width="675" height="50" align="center" id="table_button_bar">
                <tr>
                  <td width="117" valign="top"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','newCashWizbase.php?s=&amp;p=3');return document.MM_returnValue" /></td>
                  <td width="115" valign="top">
                    <input name="s" type="hidden" id="s" value="5" />
                    <input name="p" type="hidden" id="p" value="5" />
                  </td>
                  <td width="99" valign="top"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../store/store_main.php?date='); " value="Cancel" /></td>
                  <td width="255" align="right" valign="top"><input type="submit" name="new_button" class="imagebutton" id="new_button" value="New" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" onMouseDown="MM_showHideLayers('wait','','show');"  />
                      <td width="65" align="right" valign="top"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false;MM_showHideLayers('wait','','show')"  />                                        
              </table></td>
          </tr>
  </table>
 
  
</form>

</div>
</body>

