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

include('../include/period_select_date.php');

$table_name2 = $_SESSION['db_prefix']."_cash_deliver_product";
$deliver_query = "SELECT cash_sale_no, cash_receipt_no, cust_name, cust_address, cust_place, cust_phone, cust_vat_number, sale_date FROM $table_name2 WHERE  sale_date BETWEEN '".$start."' AND '".$end."'  ORDER BY sale_date DESC ";
$deliver_result = $con->query($deliver_query);
$deliver_num = mysqli_num_rows($deliver_result);	

?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

       
</head>

<body>

<div class="main_frame">
 
  <div class="page_head_frame">
    <label class="label_page_head">Cash deliveries</label></div>

<div class="page_middle_frame">   

<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
								{"bSortable": true},
								{"iDataSort": 6},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false}
							 ]
				} );
			} );
		</script>
       
        
<?php
$page='cash_delivered_list.php';
$reference_name='';
$reference='';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block_2.php');
?>

<div class="page_inside_frame">            
          <table width="650" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th align="center" >Cash sale<br />no</th>
              <th >Delivery date</th>
              <th >Customer</th>
              <th >Receipt no</th>
              <th >Delivered products</th>
              <th width="23">&nbsp;</th>
              <th width="23">&nbsp;</th>
              </tr>
            </thead>
            <?php 

$a7tot=0;
$price=0;
$all_total = 0;

while($row = $deliver_result->fetch_assoc()) {
		$a1 = $row["cash_sale_no"];
		$a2 = $row["sale_date"];
		$a3 = $row["cust_name"];
		$a3a = $row["cust_address"];
		$a3b = $row["cust_place"];
		$a3c = $row["cust_phone"];
		$a3d = $row["cust_vat_number"];
		$a4 = $row["cash_receipt_no"];
		
				
	$table_name = $_SESSION['db_prefix']."_cash_deliver_product_lines";
	$line_query = "SELECT  product_item_id, quantity, batch_code FROM $table_name WHERE cash_sale_no = '".$a1."' ";
	$line_result = $con->query($line_query);
	$line_num = mysqli_num_rows($line_result);
		
	$total=0;
	$line_text="";
	$line_text2="";
			
	while($row = $line_result->fetch_assoc()) {
		$product_item_id = $row["product_item_id"];
		$quantity = $row["quantity"];
						
		$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);
		$product_item_name = $row['item_name'];
					  
	   	$line_text = $line_text."<tr><td>".$product_item_name."</td><td>".$quantity."</td></tr>";
		$line_text2 = $line_text2.$product_item_name." / ";
		//$line_text2 = substr($line_text2, 0, 40) . '...';
		//$line_text2 = mb_strimwidth($line_text2, 0, 50, "...");
	}
			
	
	$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Customer:</td><td width=175>".$a3."</td></tr><tr><td>Address:</td><td>".$a3a."<br>".$a3b."</td></tr><tr><td>Phone:</td><td>".$a3c."</td></tr><tr><td>VAT reg number:</td><td>".$a3d."</td></tr></table>";
	
	$deliverTT ="<table id=table_tool_tip width=250 ><tr><td>Item</td><td>Quantity</td></tr>".$line_text."<tr><td>&nbsp;</td><td>&nbsp;</td></tr></table><br><b>Click for details</b>";
	

	?>
            <tr>               
              <td width="65"align="left"  style="padding-left:0px;"><a href="cash_deliver_product_display.php?cash_sale_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $deliverTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="91" align="left"><?php echo date("d-m-Y", strtotime($a2))?></td>
              <td width="98" align="left"><a href="#" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a3 ?></a></td>
              <td width="84" align="left"><?php echo $a4 ?></td>
              <td width="234" align="left"><a href="cash_deliver_product_display.php?cash_sale_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $deliverTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $line_text2 ?></a></td>
              <td align="left"><?php echo $a1 ?></td>
              <td align="left"><?php echo $a3 ?></td>
            </tr>
            <?php
}
?>
            <tfoot>
            </tfoot>
          </table>
 
 </div>
</div>

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

