<?php
include('../include/session.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$vehicle_id = $_GET['vehicle_id_text'];


$service_date = $_GET['service_date'];
$service = $_GET['service_select'];
$mileage = $_GET['km_reading_text'];
$spares_cost = $_GET['spares_text'];
$labour_cost = $_GET['labour_text'];
$garage = $_GET['provider_select'];
$order_no = $_GET['reference_text'];
$work_done = $_GET['work_text'];
$advice = $_GET['advice_text'];


$table_name = $_SESSION['db_prefix']."_vehicle_service";
$fuel_query = "INSERT INTO $table_name (service_date, vehicle_id, service, mileage, spares_cost, labour_cost, garage, order_no, work_done, advice) VALUES ('".$service_date."', '".$vehicle_id."', '".$service."', '".$mileage."', '".$spares_cost."', '".$labour_cost."', '".$garage."', '".$order_no."', '".$work_done."', '".$advice."' ) ";
execsql($fuel_query);

echo '<br>'.$service;
if ( ($service=='General service') OR ($service=='Major service') ) {
$table_name = $_SESSION['db_prefix']."_vehicle";
$service_query = "UPDATE $table_name SET last_service_date = '".$service_date."', last_service_mileage = '".$mileage."' WHERE vehicle_id = '".$vehicle_id."' ";
execsql($service_query);
}



$table_name = $_SESSION['db_prefix']."_mileage";
$rec_mileage_query = "INSERT INTO $table_name (vehicle_id, rec_date, rec_mileage, service_done) VALUES ('".$vehicle_id."', '".$service_date."', '".$mileage."', '".$service."') ";
execsql($rec_mileage_query);



$table_name = $_SESSION['db_prefix']."_tracking_transport";
   $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '43', '".$vehicle_id."' ,'".$service_date."','".$service."','".$mileage."' )";
   $trackingResult = mySQL_query($trackingQuery);



if (isset($_GET['save_close_button']) )
	   { ?>
       <script>
	 		 window.location="../transport/transport_main.php?date=0";
		</script>
        <?php		 
	   }
	   
	if (isset($_GET['save_button']) )
	   {  ?>
       <script>
	        window.location="service_rec.php?vehicle_id="
	   </script>
        <?php		 
	   }
	   ?>

