<?php
include "dbconfig.php";
 $bid=$_POST['job_id']; 
 
 
 
 
 
													  
							  
 
 
 
 $cdays=0;
 $sub_sql1="select * from driver_substitute WHERE booking_id='$bid'";
									$sub_result1=mysqli_query($con,$sub_sql1);
							  	while($sub_driver1=mysqli_fetch_assoc($sub_result1))
									{
									
									$cdays=$cdays+$sub_driver1['days'];
									
									}
 
 
 $sql1="SELECT bookings.start_date,bookings.id AS booking_id,bookings.comments, bookings.parking,bookings.driver_id, bookings.drop_address,bookings.drop_post_code,bookings.pickup_address,bookings.pickup_post_code, bookings.waiting_charges,bookings.fare,bookings.total_fare,bookings.waiting_time, bookings.hours,bookings.mins,bookings.other,bookings.job_status,bookings.passengers,job_status.name,bookings.comments,
bookings.start_date,bookings.end_date,bookings.days,bookings.rate AS rate,bookings.supp_cost AS supp_cost,bookings.substitute,
customers.id AS customer_id, customers.name AS customer_name,customers.address1,customers.post_code,customers.city, customers.phone as customer_phone, 
employees.first_name AS driver,vehicles.color as color,vehicles.reg as reg, vehicle_make.make as make,
company_contact.name as company_contact,company_contact.email,company_contact.mobile as passenger_phone

FROM bookings 
LEFT JOIN customers ON bookings.customer_id = customers.id 
LEFT JOIN payment_type ON bookings.payment_type = payment_type.id 
LEFT JOIN employees ON bookings.driver_id = employees.id 
LEFT JOIN company_contact ON bookings.passenger_id = company_contact.id 
LEFT JOIN vehicle_make ON bookings.vehicle_id = vehicle_make.id 
LEFT JOIN vehicles on vehicles.driver_id=employees.id
LEFT JOIN job_status ON bookings.job_status = job_status.id 
WHERE 
		bookings.id='$bid'
";
$res1=mysqli_query($con,$sql1);
								$job1=mysqli_fetch_assoc($res1);
 
   echo "<p>".$job1['driver']." ".$job1["reg"]." ".$job1["make"]." ".$job1["color"]." &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
							 
							   $start3j=date("d/m/y", strtotime($job1['start_date']));
							  $start4j = date("l", strtotime($job1['start_date']));
							  echo $start4j.' '.$start3j."  -  ";
							  // $end3j=date("d/m/y", strtotime($job1['end_date']));
							  $rd=$job1['days']-$cdays;
							   $end3j= date('d/m/y', strtotime($job1['end_date']. ' - '.$cdays.' days'));
							 // $end4j = date("l", strtotime($job1['end_date']));
							   $end4j = date("l", strtotime($end3j));
							  echo $end4j.' '.$end3j."  &nbsp; &nbsp; &nbsp; ";
							//  $cdays=$cdays+1;
							  echo $job1['days']-$cdays." days </p>";
									  
                              
							   $sub_sql="select * from driver_substitute WHERE booking_id='$bid'";
									$sub_result=mysqli_query($con,$sub_sql);
							  	while($sub_driver=mysqli_fetch_assoc($sub_result))
									{
									$sid=$sub_driver['substitute_id'];
							    $customers_sql1="select * from employees WHERE employees.id='$sid'";
									$t_result1=mysqli_query($con,$customers_sql1);
									$sub=mysqli_fetch_assoc($t_result1);
									
									$sql="SELECT bookings.start_date,bookings.id AS booking_id,bookings.comments, bookings.parking,bookings.driver_id, bookings.drop_address,bookings.drop_post_code,bookings.pickup_address,bookings.pickup_post_code, bookings.waiting_charges,bookings.fare,bookings.total_fare,bookings.waiting_time, bookings.hours,bookings.mins,bookings.other,bookings.job_status,bookings.passengers,job_status.name,bookings.comments,
bookings.start_date,bookings.end_date,bookings.days,bookings.rate AS rate,bookings.supp_cost AS supp_cost,bookings.substitute,
customers.id AS customer_id, customers.name AS customer_name,customers.address1,customers.post_code,customers.city, customers.phone as customer_phone, 
employees.first_name AS driver,vehicles.color as color,vehicles.reg as reg, vehicle_make.make as make,
company_contact.name as company_contact,company_contact.email,company_contact.mobile as passenger_phone

FROM bookings 
LEFT JOIN customers ON bookings.customer_id = customers.id 
LEFT JOIN payment_type ON bookings.payment_type = payment_type.id 
LEFT JOIN employees ON bookings.driver_id = employees.id 
LEFT JOIN company_contact ON bookings.passenger_id = company_contact.id 
LEFT JOIN vehicle_make ON bookings.vehicle_id = vehicle_make.id 
LEFT JOIN vehicles on vehicles.driver_id=employees.id
LEFT JOIN job_status ON bookings.job_status = job_status.id 
WHERE 
		bookings.id='$bid'
";
$res=mysqli_query($con,$sql);
								$job=mysqli_fetch_assoc($res);
								
							  echo "<p>".$sub['first_name']." ".$job["reg"]." ".$job["make"]." ".$job["color"]." &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;";
							 
							   $start3=date("d/m/y", strtotime($sub_driver['start_date']));
							  $start4 = date("l", strtotime($sub_driver['start_date']));
							  echo $start4.' '.$start3."  -  ";
							   $end3=date("d/m/y", strtotime($sub_driver['end_date']));
							  $end4 = date("l", strtotime($sub_driver['end_date']));
							  echo $end4.' '.$end3."  &nbsp; &nbsp; &nbsp; ";
							  
							  echo $sub_driver['days']." days </p>";
							
							 
							  }
							  
							  
	

?>