<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
include('../include/session.php');


include('../include/period_select_date.php');	 
 
$table_name = $_SESSION['db_prefix']."_direct_delivery";	 	
$display_query = "SELECT direct_delivery_id, direct_delivery_no, cust_id, issue_date FROM $table_name WHERE issue_date BETWEEN '".$start."' AND '".$end."' ";
	
	$display_result = execsql($display_query);
	$i = 0;
	$display_num = mysql_num_rows($display_result); 
		?> 

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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 


</head>


<body>
<?php
include ("../navigation/header.php");
include ("../navigation/store_sidebar.php");
$page_name = "Stores-main";
include ("../navigation/access.php");
if ($permission_num==1) {
?>
<div class="main_frame">
<div class="page_head_frame">
  <label class="label_page_head">Direct deliveries</label></div>

<div class="page_middle_frame">

<?php
$page='employee_supply_list.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
<div class="page_inside_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": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 2, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true}					
								 ]
				} );
			} );
		</script>    	
<table width="661" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="114">Date</th>
		  <th width="23">&nbsp;</th>
		  <th width="81">Delivery no</th>
          <th width="306" >Customer</th>
		  <th width="113" >&nbsp;</th>
		  </tr>
	</thead>
	<tbody>
  <?php
    $b9=0;
	$b4tot='0.00';
	$b5tot='0.00';
	while($i < $display_num){
		 $b0 = mysql_result($display_result, $i, "direct_delivery_id");
		 $b1 = mysql_result($display_result, $i, "issue_date");
		 $b4 = mysql_result($display_result, $i, "direct_delivery_no");
		   
		 $b2 = mysql_result($display_result, $i, "cust_id"); 
		 $table_name2 = $_SESSION['db_prefix']."_customer";
				$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$b2."' ";
				$customer_result = mySQL_query($customer_query);
				$customer_num = mysql_num_rows($customer_result);	
				$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$b2a = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$b2a = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
				
		  	$table_name = $_SESSION['db_prefix']."_direct_delivery_lines";
			$line_query = "SELECT store_item_id, quantity, price FROM $table_name WHERE direct_delivery_no = '".$b4."' ";
			$line_result = mySQL_query($line_query);
			$line_num = mysql_num_rows($line_result);
			$line_text='';
			$j=0;
			while ($j<$line_num) {
			 $store_item_id  = mysql_result($line_result, $j, "store_item_id");	
			if ($store_item_id!=0) {	
			  
			   		$table_name6 = $_SESSION['db_prefix']."_store_items";
		 			$item_query = "SELECT item_name FROM $table_name6 WHERE store_item_id = '".$store_item_id."' " ;
					$item_result = execsql($item_query);
					$item_num = mysql_num_rows($item_result);
					if ($item_num !=0) {
		   			       $item_name = mysql_result($item_result, 0, "item_name");
					}
					else {
						$item_name='';
					}
			}
			else {
				$item_name  = mysql_result($line_result, $j, "item_name");
			}
					
			   $line_quantity  = mysql_result($line_result, $j, "quantity");
			   $line_price  = mysql_result($line_result, $j, "price");
			   $line_text = $line_text.'<tr><td>'.$item_name."</td><td>".$line_quantity."</td><td>".$line_price."</td></tr>";
			   $j++;
			}
			   
			   	
		
		//$b8 = mysql_result($displayResult, $i, "reference");
		
				
		 $itemTT = 
		  "<b>Items on this supply:</b><br><table id=table_tool_tip width=300 border=1 ><tr><td>Item</td><td>Quantity</td><td>Price</td></tr>".$line_text."</table><br><b>Click for details</b>";
		
	   
		$custTT =
		   "<table id=table_tool_tip width=250 ><tr><td  width=75>Name:</td><td width=175>".$b2a."</td></tr></table><br><b>Click for details</b>";   
		
		?>
		<tr >
		  <td ><?php echo date("d-m-Y", strtotime($b1 ))?></td>
		  <td ><?php echo $b1 ?>&nbsp;</td>
		  <td align="left"><a href="direct_delivery.php?direct_delivery_no=<?php echo $b4 ?>" onMouseover="ddrivetip('<?php echo $itemTT ?>', 300)"; onMouseout="hideddrivetip()"><?php echo $b4 ?></a></td>
			<td align="left"><a href="../sales/customer_details.php?cust_id=<?php echo $b2 ?>" onMouseOver="ddrivetip('<?php echo $custTT ?>', 200)"; onMouseOut="hideddrivetip()"><?php echo $b2a?></a></td>
			<td align="right">&nbsp;</td>
	      </tr>
		       
		<?php
		$i++; 
	}
	?>
    </tbody>
    <tfoot>
    <tr >
		  <td >&nbsp;</td>
		  <td >&nbsp;</td>
		  <td align="left">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  </tr>
        </tfoot>
	
</table>
		
</div>	
</div>    
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>