<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--style sheets--> 
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<!--jscript-->

<?php
include ("../navigation/header.php");
include('../include/period_select_date.php');

$date = $_GET['date'];
$comp = $_GET['comp'];

?>

<script language="javascript" src="../jscript/calendar.js"></script>
</head>
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");

$table_name2 = $_SESSION['db_prefix']."_fuel_supply";	
if ($comp=='All') { 	
$comp_query = "SELECT * FROM $table_name2 WHERE rec_no <> 'Ext' AND supply_date >= '".$start."' AND supply_date <= '".$end."' ";
}
else {
$comp_query = "SELECT * FROM $table_name2 WHERE rec_no <> 'Ext' AND department = '".$comp."' AND supply_date >= '".$start."' AND supply_date <= '".$end."' ";
}
$comp_result = mySQL_query($comp_query);
$comp_num = mysql_num_rows($comp_result);

 $table_name = $_SESSION['db_prefix']."_list_company";
$vehicleQuery = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$vehicleResult = execsql($vehicleQuery);
	$vehicleNum = mysql_num_rows($vehicleResult);
	$w = 0;
	$arrId3 = array ();
	$arrName3 = array ();
	while ($w < $vehicleNum) {
		$arrId3[$w] = mysql_result($vehicleResult, $w, "item_name");
		$arrName3[$w] = mysql_result($vehicleResult, $w, "item_name");
		$w++;
	}   
	?>

<div class="main_frame">

  <div class="page_head_frame">
      <label class="label_page_head">Company fuel supply</label>&nbsp;&nbsp;&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $comp ?></label>
      </div>
<div class="page_middle_frame">
<?php
$page='company_fuel_list.php';
$reference_name='comp';
$reference=$comp;
$reference_name_2='';
$reference_2='';
include('../include/period_select_block.php');
?>
<div class="page_inside_frame">
<!--jscript-->
<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": [[ 0, "desc" ]],
					"aoColumns": [
					     		{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}								
								 ]
				} );
			} );
		</script>
<form action="" method="get">
Filter on company:&nbsp;&nbsp;
<select name="supply_to_select" id="supply_to_select" class="select160" onchange="window.location.href= this.form.supply_to_select.options[this.form.supply_to_select.selectedIndex].value" >
  <option value="" disabled selected hidden>Select company</option>
  <option value="company_fuel_list.php?comp=All&date=3&start_date=<?php echo $start ?>&end_date=<?php echo $end ?>">All</option>
  <?php 
    	for ($w = 0; $w < count($arrId3); $w++) {
		echo "<option value=company_fuel_list.php?comp=".urlencode($arrId3[$w])."&date=3&start_date=".$start."&end_date=".$end.">" . $arrName3[$w] . "</option>";	
	    }
     ?>
</select>
</form>        
<table width="679" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th align="center">No</th>
    <th align="center">Date</th>
    <th align="center">Company</th>
    <th align="center">Vehicle</th>
    <th align="center">Registration</th>
    <th align="center">Ltrs</th>
    <th align="center">Ltr<br>
      Price</th>
    <th align="center">Delivery<br>
      price</th>
    </tr>
    </thead>
<?php 

$i=0;
$a5_total=0;
$a7_total=0;
while ($i<$comp_num) {

	$a0 = mysql_result($comp_result, $i, "fuel_id");
	$a1 = mysql_result($comp_result, $i, "supply_date");
			
	$a3 = mysql_result($comp_result, $i, "vehicle_id");
	$a4 = mysql_result($comp_result, $i, "fuel");
	$a5 = mysql_result($comp_result, $i, "qty_supplied");
	$a6 = mysql_result($comp_result, $i, "price");
	$a7 = $a5 * $a6;
	$clock_reading = number_format(mysql_result($comp_result, $i, "mileage"), 0, '.', ',');
		
	$table_name = $_SESSION['db_prefix']."_vehicle";
	$vehicle_query = "SELECT registration_no, make, model, department FROM $table_name WHERE vehicle_id = '".$a3."' ";
	$vehicle_result = mySQL_query($vehicle_query);
	$vehicle_num = mysql_num_rows($vehicle_result);
	$registration_no = mysql_result($vehicle_result, 0, "registration_no");
	$make = mysql_result($vehicle_result, 0, "make");
	$model = mysql_result($vehicle_result, 0, "model");
	$department = mysql_result($vehicle_result, 0, "department");
	

$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$make.' '.$model."</td></tr><tr><td>Company:</td><td>".$department."</td></tr><tr><td>Km reading:</td><td>".$clock_reading."km</td></tr></table><br><b>Click for details</b>"; 
	
	
	
	//$a7 = mysql_result($fuel_result, $i, "rec_no");
	
	$a9 = mysql_result($comp_result, $i, "department");
		
	$a5_total = $a5_total + $a5;
	$a7_total = $a7_total + $a7; 	
	
	
	
	?>
<tr>
    <td align="left"><a href="fuel_rec_display.php?fuel_id=<?php echo $a0 ?>" onMouseover="ddrivetip('Click for fuel receipt.', 150)"; onMouseout="hideddrivetip()"><?php echo $a0 ?></a>&nbsp;</td>
    <td align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
    <td align="left"><?php echo $a9 ?></td>
    <td align="left"><a href="vehicle_details.php?vehicle_id=<?php echo $a3 ?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $make.' '.$model ?></a></td>
    <td align="center"><?php echo $registration_no ?>  </a></td>
    <td align="right"><?php echo $a5;?></td>
    <td align="right"><?php echo number_format($a6, 2, '.', ',') ?></td>
    <td align="right"><?php echo number_format($a7, 2, '.', ',') ?></td>
    </tr> 
  
  <?php
  $i++;
}
?>
<tfoot>
<tr>
  <td align="right">Totals:</td>
  <td align="right">&nbsp;</td>
  <td align="right">&nbsp;</td>
  <td align="right">&nbsp;</td>
  <td align="right">&nbsp;</td>
  <td align="right"><?php echo number_format($a5_total, 2, '.', ',') ?></td>
    <td align="left">&nbsp;</td>
    <td align="right"><?php echo number_format($a7_total, 2, '.', ',') ?></td>
    </tr>
  </tfoot>
</table>
</div>
</div>
</div>

<?php } else {
$_SESSION['denied_return'] = "transport/transport_main.php?date=";	
include ("../navigation/transport_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>


</body>
</html>