<!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('../include/session.php');
include('../include/period_select_date.php');


?>
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="javascript" src="../jscript/calendar.js"></script>

</head>
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body onLoad="document.getElementById('fuel_div').hidden=true; document.getElementById('service_div').hidden=true; document.getElementById('admin_div').hidden=true">
<?php
include ("../navigation/header.php");
$page_name = "Transport-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/transport_sidebar.php");
    include ('../include/tooltip.php');
	
$date = $_GET['date'];
$vehicle_id = $_GET['vehicle_id'];

$table_name2 = $_SESSION['db_prefix']."_fuel_supply";
$fuel_query = "SELECT * FROM $table_name2 WHERE vehicle_id = '".$vehicle_id."' AND supply_date >= '".$start."' AND supply_date <= '".$end."' ORDER BY supply_date ASC";
$fuel_result = mySQL_query($fuel_query);
$fuel_num = mysql_num_rows($fuel_result);

$table_name2 = $_SESSION['db_prefix']."_vehicle_service";
$service_query = "SELECT * FROM $table_name2 WHERE vehicle_id = '".$vehicle_id."' AND service_date >= '".$start."' AND service_date <= '".$end."' ORDER BY service_date ASC";
$service_result = mySQL_query($service_query);
$service_num = mysql_num_rows($service_result);


$table_name2 = $_SESSION['db_prefix']."_vehicle_admin";
$admin_query = "SELECT * FROM $table_name2 WHERE vehicle_id = '".$vehicle_id."' AND admin_date >= '".$start."' AND admin_date <= '".$end."' ORDER BY admin_date ASC";
$admin_result = mySQL_query($admin_query);
$admin_num = mysql_num_rows($admin_result);

$table_name = $_SESSION['db_prefix']."_vehicle";
$vehicle_query = "SELECT registration_no, make, model, department, clock_reading FROM $table_name WHERE vehicle_id = '".$vehicle_id."' ";
$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");
$clock_reading = number_format(mysql_result($vehicle_result, 0, "clock_reading"), 0, '.', ',');

$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$make.' '.$model."</td></tr><tr><td>Department:</td><td>".$department."</td></tr><tr><td>Km reading:</td><td>".$clock_reading."km</td></tr></table><br><b>Click for details</b>"; 

//$table_name2 = $_SESSION['db_prefix']."_vehicle_service";
//$service_query = "SELECT * FROM $table_name2 WHERE service_date >= '".$start."' AND service_date <= '".$end."' ";
//$service_result = mySQL_query($service_query);
//$service_num = mysql_num_rows($service_result);

//$table_name2 = $_SESSION['db_prefix']."_vehicle_admin";
//$admin_query = "SELECT * FROM $table_name2 WHERE admin_date >= '".$start."' AND admin_date <= '".$end."' ";
//$admin_result = mySQL_query($admin_query);
//$admin_num = mysql_num_rows($admin_result);
	?>

<div class="main_frame">

  <div class="page_head_frame">
      <table width="650" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td ><label class="label_page_head">Vehicle expense</label><label class="label_page_head_2"><?php echo $registration_no.' '.$make.' '.$model?></label></td>
         </tr>
        </table>
      </div>
<div class="page_middle_frame">
<?php
$page='vehicle_expense_list.php';
$reference_name='vehicle_id';
$reference=$vehicle_id;
include('../include/period_select_block.php');
?>
<div class="page_inside_frame">

<div align="left">Fuel expense&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/down_arrow.png" width="16" height="10" onClick="document.getElementById('fuel_div').hidden=false"><img src="../images/up_arrow.png" width="16" height="10" onClick="document.getElementById('fuel_div').hidden=true"></div> 
<div id="fuel_div" style="width:660px; height:260px;" >
<!--jscript-->
  <script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
  <script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				
				$('#scroll_table2').dataTable( {
					"sScrollY": "225px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 10},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
  <table width="655" id="scroll_table2" class="data_display"  >
    <thead>
      <tr>
        <th align="center">Date</th>
        <th align="center">Km</th>
        <th align="center">Fuel</th>
        <th align="center">Qty</th>
        <th align="center">Covered</th>
        <th align="center">Consumption</th>
        <th align="center">Cost</th>
        <th align="center">Reference</th>
        <th align="center">Supplier</th>
        <th align="center">Fill up by</th>
        <th align="center">&nbsp;</th>
      </tr>
    </thead>
    <?php 

$i=0;
$pre_mileage=0;
$a5_total=0;
$fuel_total=0;
$a10_total=0;
while ($i<$fuel_num) {

	
	$a1 = mysql_result($fuel_result, $i, "supply_date");
			
	$a3 = mysql_result($fuel_result, $i, "mileage");
	$a3a = $pre_mileage; 
	$a10 = $a3-$a3a;
	
	
	$a4 = mysql_result($fuel_result, $i, "fuel");
	$a5 = mysql_result($fuel_result, $i, "qty_supplied");
	
	if ($pre_mileage!=0) {
	$average = number_format($a10/$a5, 2, '.', ',');
	}
	else {
		$a10='';
		$average='';
	}
	$a5_total=$a5_total+$a5;
	$a10_total=$a10_total+$a10;;
	
	$a6 = mysql_result($fuel_result, $i, "price");
	$a6a = $a5*$a6;
	
	$fuel_total=$fuel_total+$a6a;
	$a7 = mysql_result($fuel_result, $i, "reference");
	$a8 = mysql_result($fuel_result, $i, "supplier");
	$a9 = mysql_result($fuel_result, $i, "driver");
			$table_name2 = $_SESSION['db_prefix']."_employee";
			$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$a9."' ";
			$employee_result = mySQL_query($employee_query);
			$employee_num = mysql_num_rows($employee_result);	
			$a9a = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
	
	
	
	$pre_mileage = mysql_result($fuel_result, $i, "mileage");
	
	
	?>
    <tr>
      <td width="51" align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
      <td width="41" align="left"><?php echo $a3 ?></a></td>
      <td width="56" align="left"><?php echo $a4 ?></td>
      <td width="56" align="center"><?php echo $a5 ?> </a></td>
      <td width="67" align="center"><?php echo $a10 ?></td>
      <td width="90" align="center">1 : <?php echo $average ?></td>
      <td width="55" align="right"><?php echo number_format($a6a, 2, '.', ',') ?></td>
      <td width="72" align="left"><?php echo $a7 ?></td>
      <td width="71" align="center"><?php echo $a8 ?></td>
      <td width="50" align="left"><a href="..hr_module/employee_details.php?emp_id=<?php echo $a1 ?>" onMouseover="ddrivetip('<?php echo $a9a ?><br><b>Click for details</b>', 150)"; onMouseout="hideddrivetip()"><?php echo $a9a ?></a></td>
      <td width="23" align="left"><?php echo $a1 ?></td>
    </tr>
    <?php
  $i++;
}
?>
</table>
</div>
<table width="655" border="0">
  <tr>
    <td height="30" colspan="4" align="right" valign="bottom">Total fuel expense:</td>
        <td width="155" align="right" valign="bottom" ><?php echo number_format($fuel_total, 2, '.', ',') ?>&nbsp;</td>
        <td width="53" align="right" valign="bottom">&nbsp;</td>
        <td width="65" align="left" valign="bottom">&nbsp;</td>
        <td width="62" align="left" valign="bottom">&nbsp;</td>
        </tr>
</table>

</div>


<div class="page_inside_frame">

Service and maintenance&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/down_arrow.png" width="16" height="10" onClick="document.getElementById('service_div').hidden=false"><img src="../images/up_arrow.png" width="16" height="10" onClick="document.getElementById('service_div').hidden=true">
<div  id="service_div" style="width:660px; height:260px;"> 
  <!--jscript-->
  <script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table3').dataTable( {
					"sScrollY": "200px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
					     		
								{"iDataSort": 8},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
<table width="670" id="scroll_table3" class="data_display"  >
  <thead>
    <tr>
      <th align="center">Date</th>
      <th align="center">Km</th>
      <th align="center">Service</th>
      <th align="center">Covered</th>
      <th align="center">Labour cost</th>
      <th align="center">Spares Cost</th>
      <th align="center">Garage</th>
      <th align="center">Order/<br>
        invoice no</th>
      <th align="center">&nbsp;</th>
    </tr>
  </thead>
  <?php 

$i=0;
$pre_mileage=0;
$labour_total=0;
$spares_total=0;
$a10_total=0;
while ($i<$service_num) {
	$a1 = mysql_result($service_result, $i, "service_date");
			
	$a3 = number_format(mysql_result($service_result, $i, "mileage"), 0, '.', ',');
	$a3a = $pre_mileage; 
	if ($pre_mileage!=0) {
	       $a10 = $a3-$a3a;
	}
	else { 
	$a10='';
	}
	
	
	$a4 = mysql_result($service_result, $i, "service");
	$a5 = mysql_result($service_result, $i, "labour_cost");
	$labour_total=$labour_total+$a5;
	$a6 = mysql_result($service_result, $i, "spares_cost");
	$spares_total=$spares_total+$a6;
	$a7 = mysql_result($service_result, $i, "order_no");
	$a8 = mysql_result($service_result, $i, "garage");
	
	
	$pre_mileage = mysql_result($service_result, $i, "mileage");
	
	
	?>
  <tr>
    <td width="46" align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
    <td width="61" align="right"><?php echo $a3 ?></a></td>
    <td width="97" align="left"><?php echo $a4 ?></td>
    <td width="60" align="center"></a><?php echo $a10 ?></td>
    <td width="56" align="right"><?php echo number_format($a5, 2, '.', ',') ?></td>
    <td width="71" align="right"><?php echo number_format($a6, 2, '.', ',') ?></td>
    <td width="131" align="left"><?php echo $a8 ?></td>
    <td width="85" align="left"><?php echo $a7 ?></td>
    <td width="23" align="left"><?php echo $a1 ?></td>
  </tr>
  <?php
  $i++;
}
?>
</table>
</div>
<table width="655" border="0">
  <tr>
    <td height="20" colspan="4" align="right" valign="bottom">Total service labour expense:</td>
    <td align="right" valign="bottom" ><?php echo number_format($labour_total, 2, '.', ',') ?></td>
    <td align="right" valign="bottom">&nbsp;</td>
    <td align="left" valign="bottom">&nbsp;</td>
    <td align="left" valign="bottom">&nbsp;</td>
  </tr>
  <tr>
    <td height="20" colspan="4" align="right" valign="bottom">Total service spares expense:</td>
    <td width="155" align="right" valign="bottom" ><?php echo number_format($spares_total, 2, '.', ',') ?></td>
    <td width="53" align="right" valign="bottom">&nbsp;</td>
    <td width="65" align="left" valign="bottom">&nbsp;</td>
    <td width="62" align="left" valign="bottom">&nbsp;</td>
  </tr>
</table>
</div>



<div class="page_inside_frame">
Admin expense&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/down_arrow.png" width="16" height="10" onClick="document.getElementById('admin_div').hidden=false"><img src="../images/up_arrow.png" width="16" height="10" onClick="document.getElementById('admin_div').hidden=true"> 
<div  id="admin_div" style="width:660px; height:260px;">   
<!--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": "220px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
					     		
								{"iDataSort": 7},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
<table width="670" id="scroll_table" class="data_display"  >
  <thead>
    <tr>
      <th align="center">Date</th>
      <th align="center">Km</th>
      <th align="center">Admin</th>
      <th align="center">Cost</th>
      <th align="center">Document<br>
        no</th>
      <th align="center">Provider</th>
      <th align="center">Notes</th>
      <th align="center">&nbsp;</th>
    </tr>
  </thead>
  <?php 

$i=0;

$admin_total=0;

$a10_total=0;
while ($i<$admin_num) {

	
	$a1 = mysql_result($admin_result, $i, "admin_date");
	
	$a3 = mysql_result($admin_result, $i, "mileage");
		
	$a4 = mysql_result($admin_result, $i, "admin_type");
	$a5 = mysql_result($admin_result, $i, "admin_cost");
	$admin_total=$admin_total+$a5;
	$a6 = mysql_result($admin_result, $i, "document_no");
	
	$a8 = mysql_result($admin_result, $i, "provider");
	$a9 = mysql_result($admin_result, $i, "notes");

	?>
  <tr>
    <td width="51" align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
    <td width="41" align="right"><?php echo $a3 ?></a></td>
    <td width="101" align="left"><?php echo $a4 ?></td>
    <td width="56" align="right"><?php echo number_format($a5, 2, '.', ',') ?></td>
    <td width="71" align="left"><?php echo $a6 ?></td>
    <td width="131" align="left"><?php echo $a8 ?></td>
    <td width="160" align="left">&nbsp;<?php echo $a9 ?></td>
    <td width="23" align="left"><?php echo $a1 ?></td>
  </tr>
  <?php
  $i++;
}
?>
</table>
</div>
<table width="614" border="0">
  <tr>
    <td height="40" colspan="4" align="right" valign="bottom">Total admin expense:</td>
    <td width="155" align="right" valign="bottom" ><?php echo number_format($admin_total, 2, '.', ',') ?>&nbsp;</td>
    <td width="53" align="right" valign="bottom">&nbsp;</td>
    <td width="65" align="left" valign="bottom">&nbsp;</td>
    <td width="21" align="left" valign="bottom">&nbsp;</td>
  </tr>
</table>
</div>

<div class="page_inside_frame" style="background:#C7DECA;">
<?php 
$all_total = $fuel_total + $spares_total + $labour_total + $admin_total;
?>
  <table width="614" border="0">
    <tr>
      <td height="40" colspan="4" align="right">All total transport expense:</td>
      <td width="155" align="right" ><?php echo number_format($all_total, 2, '.', ',') ?>&nbsp;</td>
      <td width="53" align="right">&nbsp;</td>
      <td width="65" align="left">&nbsp;</td>
      <td width="21" align="left">&nbsp;</td>
    </tr>
  </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>