<!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');
	
$table_name2 = $_SESSION['db_prefix']."_fuel_supply";
$fuel_query = "SELECT * FROM $table_name2 WHERE supply_date >= '".$start."' AND supply_date <= '".$end."' ";
$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 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="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Transport expense</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
<div class="page_middle_frame">
<?php
$page='transport_expense_list.php';
$reference_name='';
$reference='';
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": [[ 6, "desc" ]],
					"aoColumns": [
								{"iDataSort": 8},
								{"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>Date</th>
        <th>Vehicle</th>
        <th>Mileage</th>
        <th>Fuel</th>
        <th>Qty</th>
        <th>Cost</th>
        <th>Ref</th>
        <th>Supplier</th>
        <th>&nbsp;</th>
      </tr>
    </thead>
    <?php 

$i=0;

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

	$a1 = mysql_result($fuel_result, $i, "supply_date");
	$a2 = mysql_result($fuel_result, $i, "vehicle_id");
	   	$table_name = $_SESSION['db_prefix']."_vehicle";
    	$vehicle_query = "SELECT registration_no, make, model, department, clock_reading  FROM $table_name WHERE vehicle_id = $a2 ";
		$vehicle_result = mySQL_query($vehicle_query);
		$a2a = mysql_result($vehicle_result, 0, "registration_no");
        $a2b = mysql_result($vehicle_result, 0, "make")." ".mysql_result($vehicle_result, 0, "model");
		$a10 = mysql_result($vehicle_result, 0, "department");
		$a11 =number_format(mysql_result($vehicle_result, 0, "clock_reading"), 0, '.', ',') ;
		
	$a3 = number_format(mysql_result($fuel_result, $i, "mileage"), 0, '.', ',');
	$a4 = mysql_result($fuel_result, $i, "fuel");
	$a5 = mysql_result($fuel_result, $i, "qty_supplied");
	$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"); 
	
	
	$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$a2b."</td></tr><tr><td>Department:</td><td>".$a10."</td></tr><tr><td>Km reading:</td><td>".$a11."km</td></tr></table><br><b>Click for details</b>"; 
	
	?>
    <tr>
      <td width="66" align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
      <td width="101" align="left"><a href="vehicle_details.php?vehicle_id=<?php echo $a2?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"><?php echo $a2a ?></a><br>
        <?php echo $a2b ?></td>
      <td width="71" align="left"><?php echo $a3 ?></a></td>
      <td width="69" align="left"><?php echo $a4 ?></td>
      <td width="58" align="right"><?php echo $a5 ?> </a></td>
      <td width="71" align="right"><?php echo number_format($a6a, 2, '.', ',') ?></td>
      <td width="56" align="left"><?php echo $a7 ?></td>
      <td width="100" align="left"><?php echo $a8 ?></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="655" id="scroll_table3" class="data_display"  >
  <thead>
  <tr>
    <th>Date</th>
    <th>Vehicle</th>
    <th>Mileage</th>
    <th>Service</th>
    <th>Labour<br>
      cost</th>
    <th>Spares<br>
      cost</th>
    <th>Garage</th>
    <th>Order/<br>
      invoice no</th>
    <th>&nbsp;</th>
    </tr>
    </thead>
<?php 

$i=0;
$labour_total=0;
$spares_total=0;
while ($i<$service_num) {

	
	$a1 = mysql_result($service_result, $i, "service_date");
		
	$a2 = mysql_result($service_result, $i, "vehicle_id");
	   	$table_name = $_SESSION['db_prefix']."_vehicle";
    	$vehicle_query = "SELECT registration_no, make, model, department, clock_reading  FROM $table_name WHERE vehicle_id = $a2 ";
		$vehicle_result = mySQL_query($vehicle_query);
		$a2a = mysql_result($vehicle_result, 0, "registration_no");
        $a2b = mysql_result($vehicle_result, 0, "make")." ".mysql_result($vehicle_result, 0, "model");
		$a10 = mysql_result($vehicle_result, 0, "department");
		$a11 = number_format(mysql_result($vehicle_result, 0, "clock_reading"), 0, '.', ',');
		
	$a3 = number_format(mysql_result($service_result, $i, "mileage"), 0, '.', ',');
	$a4 = mysql_result($service_result, $i, "service");
	$a5 = mysql_result($service_result, $i, "labour_cost");
	$a6 = mysql_result($service_result, $i, "spares_cost");
	$labour_total=$labour_total+$a5;
	$spares_total=$spares_total+$a6;
	
	$a8 = mysql_result($service_result, $i, "garage");
	$a9 = mysql_result($service_result, $i, "order_no");
	
	
	$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$a2b."</td></tr><tr><td>Department:</td><td>".$a10."</td></tr><tr><td>Km reading:</td><td>".$a11."km</td></tr></table><br><b>Click for details</b>"; 
	?>

  <tr>
    <td width="61" align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
    <td width="106" align="left"><a href="vehicle_details.php?vehicle_id=<?php echo $a2?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"><?php echo $a2a ?></a><br><?php echo $a2b ?></td>
    <td width="71" align="left"><?php echo $a3 ?></td>
    <td width="71" align="left"><?php echo $a4 ?></td>
    <td width="71" align="right"><?php echo number_format($a5, 2, '.', ',') ?></td>
    <td width="56" align="right"><?php echo number_format($a6, 2, '.', ',') ?></td>
    <td width="86" align="left"><?php echo $a8 ?> </td>
    <td width="70" align="left"><?php echo $a9 ?> </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": 8},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>        
<table width="655" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>Date</th>
    <th>Vehicle</th>
    <th>Mileage</th>
    <th>Admin</th>
    <th>
      Cost</th>
    <th>Document no</th>
    <th>Provider</th>
    <th>Notes</th>
    <th>&nbsp;</th>
    </tr>
    </thead>
<?php 

$i=0;
$admin_total=0;

while ($i<$admin_num) {
	$a1 = mysql_result($admin_result, $i, "admin_date");
	$a2 = mysql_result($admin_result, $i, "vehicle_id");
	   	$table_name = $_SESSION['db_prefix']."_vehicle";
    	$vehicle_query = "SELECT registration_no, make, model  FROM $table_name WHERE vehicle_id = $a2 ";
		$vehicle_result = mySQL_query($vehicle_query);
		$a2a = mysql_result($vehicle_result, 0, "registration_no");
        $a2b = mysql_result($vehicle_result, 0, "make")." ".mysql_result($vehicle_result, 0, "model");
	$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;
		
	//$a4 = mysql_result($fuel_result, $i, "issued_by");
//	$a3_total = $a3_total + $a3;
//	$a6_total = $a6_total + $a6;
//	$employeeTT = "<label class=tip_text_label>".$a1."</label><br><label class=tip_click_label>Click for details</label>";  
	
	?>

  <tr>
    <td width="66" align="left"><?php echo date("d-m-Y", strtotime($a1 )) ?></td>
    <td width="96" align="left"><?php echo $a2a ?><br><?php echo $a2b ?></td>
    <td width="76" align="left"><?php echo $a3 ?></td>
    <td width="71" align="left"><?php echo $a4 ?></td>
    <td width="65" align="right"><?php echo number_format($a5, 2, '.', ',') ?></td>
    <td width="75" align="left">&nbsp;</td>
    <td width="62" align="left">&nbsp;</td>
    <td width="81" align="left">&nbsp;</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>