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

$userId = $_SESSION['username'];
date_default_timezone_set('Africa/Gaborone');
$entryDate = date("Y-m-d H:i:s"); 


$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$update_query = "UPDATE $table_name SET  installed='yes'  WHERE job_card_no = '".$_SESSION['job_card_no']."' ";
execsql($update_query);
	

$table_name = $_SESSION['db_prefix']."_install_jobs";
$install_query = "INSERT INTO $table_name (job_card_no, cust_id, install_date, confirmed, forman, site_contact, site_no, route_description, vehicle ) VALUES ('".$_SESSION['job_card_no']."', '".$_SESSION['cust_id']."', '".$_SESSION['deliver_date']."', '".$_SESSION['confirm']."', '".$_SESSION['forman']."', '".$_SESSION['site_contact']."', '".$_SESSION['site_no']."', '".$_SESSION['route']."', '".$_SESSION['vehicle_id']."' ) ";
execsql($install_query);



$table_name = $_SESSION['db_prefix']."_vehicle";
$mileage_query = "SELECT clock_reading FROM $table_name WHERE vehicle_id = '".$_SESSION['vehicle_id']."' ";
$mileage_result = mySQL_query($mileage_query);
$mileage = mysql_result($mileage_result, 0, "clock_reading");

$table_name = $_SESSION['db_prefix']."_vehicle_project";
$vehicle_query = "INSERT INTO $table_name (job_card_no, vehicle_id, use_date, mileage) VALUES ('".$_SESSION['job_card_no']."', '".$_SESSION['vehicle_id']."', '".$_SESSION['deliver_date']."', '".$mileage."'  ) ";
execsql($vehicle_query);


$table_name6 = $_SESSION['db_prefix']."_order_history";
    $history_query = "INSERT INTO $table_name6 (job_card_number, note_date, note_text, user_name ) VALUES ('".$_SESSION['job_card_no']."', '".$entryDate."', 'Job installed.', '".$_SESSION['username']."' ) ";
	execsql($history_query);

$table_name = $_SESSION['db_prefix']."_tracking_orders";
$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '91', '".$_SESSION['job_card_no']."', '".$_SESSION['project']."' ,'','' )";
$trackingResult = mySQL_query($trackingQuery);
	
	
$job_card_no=$_SESSION['job_card_no'];
	 	 
	 $_SESSION['job_card_no']="";
	 $_SESSION['name']="";
	 $_SESSION['deliver_date']=date("Y-m-d");
	 $_SESSION['cust_id']='';
			
		$_SESSION['cust_id']='';
		$_SESSION['order_date']='';
		$_SESSION['project_description']="";
		$_SESSION['project_no']="";
		$_SESSION['project_place']="";
		$_SESSION['project_area']="";
		$_SESSION['deliver_date']="";
		$_SESSION['work_days']="";
		$_SESSION['value']="";
		

        $_SESSION['forman']="";
		$_SESSION['forman_name']='';
	 	
		$_SESSION['forman_new']='';
		$_SESSION['install_date']='';
		$_SESSION['confirm']='';
		$_SESSION['site_contact']='';
		$_SESSION['site_no']='';
		$_SESSION['route']='';
		$_SESSION['vehicle_id']='';
		$_SESSION['vehicle_name']='';
				
			
		$table_name = $_SESSION['db_prefix']."_order_job_lines_supply_temp";
		$delete2_query = "DELETE FROM $table_name WHERE  user_name =  '".$_SESSION['username']."' "; 
		execsql($delete2_query);
	 
?>

<script language="javascript" type="text/javascript">
        
		  window.location="install_job.php?job_card_no=<?php echo $job_card_no ?>" ;
        
       </script>

