<!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");

$cash_sale_no = $_GET['cash_sale_no'];

   
		$table_name = $_SESSION['db_prefix']."_cash_deliver_product";
		$quote_query = "SELECT *  FROM $table_name WHERE cash_sale_no = '".$cash_sale_no."'";
		$quote_result = $con->query($quote_query);
		$row = mysqli_fetch_assoc($quote_result);
		$cash_receipt_no = $row["cash_receipt_no"];
		$sale_date=$row["sale_date"];
		$pallets=$row["pallets"];
		$pallets_price=$row["pallets_price"];
		$cust_name=$row["cust_name"];			 
		$cust_address=$row["cust_address"];
		$cust_place=$row["cust_place"];	
		$cust_phone=$row["cust_phone"];	
		$cust_vat_number=$row["cust_vat_number"];
		$additional_info=$row["additional_info"];	
		
				
		$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines";
		$line_query = "SELECT *  FROM $table_name WHERE cash_sale_no = '".$cash_sale_no."' AND quantity > 0 ";
		$line_result = $con->query($line_query);
		
	
?>

<!--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">Cash sale delivery note</label></td>
            <td width="167" align="right"><label class="label_page_head_2">Delivery no <?php echo $cash_sale_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">Cash sale no <?php echo $cash_sale_no ?> delivered to:</td>
    <td width="169">Delivery date: <?php echo date("d-m-Y", strtotime($sale_date)) ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Receipt no: <?php echo $cash_receipt_no ?></td>
  </tr>
         </table>

        
    </div><br>
    <table width="650" id="table_display" >
  <tr>
    <td width="118">Customer:</td>
    <td colspan="3"><?php echo $cust_name ?></td>
    </tr>
  <tr>
    <td>Address:</td>
    <td><?php echo $cust_address ?></td>
    <td>Tel::</td>
    <td><?php echo $cust_phone ?></td>
    </tr>
  <tr>
    <td>Place:</td>
    <td width="156"><?php echo $cust_place ?></td>
    <td width="116">VAT reg_no::</td>
    <td width="240"><?php echo $cust_vat_number ?></td>
  </tr>
  <tr>
    <td>Notes:</td>
    <td colspan="3"><?php echo $additional_info ?></td>
    </tr>
    </table>

<br>
<div class="wizard_frame">
Items delivered:
         <table width="650" id="table_display" >
           <tr>
             <td width="193" height="26" align="left" valign="top">Item</td>
             <td width="171" align="left" valign="top">Batch codes</td>
             <td width="71" align="left" valign="top">Quantity</td>
             <td align="left" valign="top">Unit price</td>
             <td align="left" valign="top">Line total</td>
           </tr>
           <?php
				$sub_tot=0;
				$a6_total=0;
				while($row = $line_result->fetch_assoc()) {
					$a0 = $row["cash_delivery_line_id"];
					$a1 = $row["product_item_id"];
					$a2 = $row["quantity"];
					$a3 = $row["price"];
					$a5 = $row["batch_code"];
					
					$a6 = $a2 * $a3;
					$a6_total = $a6_total + $a6;
				 	 
					$table_name = $_SESSION['db_prefix']."_product_store";
						$item_query = "SELECT item_name 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"];
											 
					 
			?>
           <tr>
             <td valign="top"><?php echo $a1a ?></td>
             <td valign="top"><?php echo $a5 ?></td>
             <td valign="top"><?php echo $a2 ?></td>
             <td width="91" align="right" valign="top"><?php echo number_format($a3, 2, '.', ',') ?></td>
             <td width="100" align="right" valign="top"><?php echo number_format($a6, 2, '.', ',') ?></td>
           </tr>
           <?php 
			 }
			 $pallets_line = $pallets * $pallets_price;
			 $a6_total = $a6_total + $pallets_line;
				 ?>
          
           <tr>
             <td valign="top">Pallets</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_line, 2, '.', ',') ?></td>
           </tr>
           <tr>
             <td colspan="4" align="right" valign="top">Total:&nbsp;&nbsp;</td>
             <td align="right" valign="top"><?php echo number_format($a6_total, 2, '.', ',') ?></td>
           </tr>       
         </table>
         </div>
         <br>
<br>


    <table width="642" height="50" align="left" id="table_button_bar">
        <tr>
          <td><form action="cash_deliver_print.php?" method="get" target="_blank">
            <input name="cash_sale_no" type="hidden" value="<?php echo $cash_sale_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="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'); ?>