<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include('../include/session.php');
$cash_sale_no = $_GET['cash_sale_no'];
if (isset($_GET['print_checkbox'])) { $p=1; } else { $p=0; } ;
   
		$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);
		
$report_name = 'Cash sale delivery';
$report_no = $cash_sale_no;
?>

<!--style sheets-->
<link href="../css/print.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico">
<title>Cash delivery <?php echo $cash_sale_no ?></title>

</head>

<body  onload="window.print(); window.close();" >
<?php include('../include/print_header.php'); ?>
<div class="print_main_frame" style="height:auto; margin-left:50px;">
<br>
<br>

<div class="print_standard_frame">

</div>
<br>

  <div class="print_standard_frame">
        <table width="600" 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 class="print_standard_frame">
  <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>
<br>

<label class="print_header_label_std">Items delivered:</label>
<br>
<br>
         <table width="650" id="table_display" >
           <tr>
             <td width="208" height="26" align="left" valign="top">Item</td>
             <td width="206" align="left" valign="top">Batch codes</td>
             <td width="66" align="left" valign="top">Quantity</td>
             <?php if ($p==1) { ?>
             <td width="81" align="left" valign="top">Unit price</td>
             <td width="98" align="left" valign="top">Line total</td>
             <?php } ?>
           </tr>
           <?php
				$i=0;
				$sub_tot=0;
				$a7_total=0;
				 while($row = $line_result->fetch_assoc()) {
					$a0 = $row["cash_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 = $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 align="left" valign="top"><?php echo $a5 ?></td>
             <td align="center" valign="top"><?php echo $a2 ?></td>
             <?php if ($p==1) { ?>
             <td align="right" valign="top"><?php echo number_format($a6, 2, '.', ',') ?></td>
             <td align="right" valign="top"><?php echo number_format($a7, 2, '.', ',') ?></td>
             <?php } ?>
           </tr>
           <?php 
			   $i++;
				 }
				 
			$pallets_total =$pallets * $pallets_price; 
			$a7_total = $a7_total + $pallets_total;
				 ?>
           <tr>
             <td valign="top">Pallets</td>
             <td align="left" valign="top">&nbsp;</td>
             <td align="center" valign="top"><?php echo $pallets ?></td>
             <?php if ($p==1) { ?>
             <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>
             <?php } ?>
           </tr>
           <?php if ($p==1) { ?>
           <tr>
             <td colspan="4" align="right" valign="top">Total:&nbsp;&nbsp;</td>
             <td align="right" valign="top"><?php echo number_format($a7_total, 2, '.', ',') ?></td>
           </tr> 
           <?php } ?>      
         </table>
	<div align="left">
<img src="../images/info_blue.png" width="16" height="16">
<label class="label_info">Pallets to be refunded on return.</label>
	</div>
<br>
<br>

<table width="597" id="table_display">
  <tr>
    <td width="114" height="36">Received by:</td>
    <td width="471">&nbsp;</td>
    </tr>
  <tr>
    <td height="30">Date:</td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td height="30">Customer sign:</td>
    <td>&nbsp;</td>
    </tr>
</table>

</div>         
<br>
</div>
 
  



</body>


