<?php

include "head.php";
include "dbconfig.php";
require_once('pdf_demo/fpdf.php');
include 'phpmailer/PHPMailerAutoload.php';
error_reporting(0);
//include "css_header.php";
//Get the order data for this order.
$driver_id=$_REQUEST['driver_id'];
$booking_id=$_REQUEST['booking_id'];


$bid=$booking_id; 
//$sub_sql="select * from driver_substitute WHERE booking_id='$bid'";
$sub_sql="select * from driver_bookings WHERE booking_id='$bid'";
$sub_result=mysqli_query($con,$sub_sql);
$sub_driver=mysqli_num_rows($sub_result);


$cd_sql="SELECT * from employees WHERE id=".$driver_id;
$cd_res=mysqli_query($con,$cd_sql);
$debt_name=mysqli_fetch_assoc($cd_res);
$current_driver=$debt_name['first_name'];
$current_driver_email=$debt_name['email'];


$book_sql="SELECT * from bookings WHERE id=".$booking_id;
$book_res=mysqli_query($con,$book_sql);
$book=mysqli_fetch_assoc($book_res);
$start_date=date("d/m/Y", strtotime($book['start_date']));
$min_date=$book['start_date'];

$end_date=date("d/m/Y", strtotime($book['end_date']));
$max_date=$book['end_date'];

$day=$book['days'];
$parking=$book['parking'];
$transfer=$book['transfer'];
$supp_cost=$book['supp_cost'];




?>

<!docpayment_type html>
<html>
<head>
<head>
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    </head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.11/js/dataTables.bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"/>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<script payment_type="text/javascript">
	$(document).ready(function() {
    $('#example').DataTable();
} );
</script>
<meta charset="utf-8">
<title>Change Driver</title>
</head>

<body>
<form method="post">
<section id="main-content">
<section class="wrapper">
<!-- page start-->
<div class="row">
<div class="col-sm-12">
<section class="panel">

<div class="panel-body">

      <form action="ajax/create_transaction.php" method="post" id="myform">
        <div class="form form-register dark form-horizontal col-sm-12 col-xs-12">
          <h4 class="head_back"> Driver Details </h4>
         
	
	
	  
			     
			       	 <div class="form-group col-sm-3">
					 <label>Driver : </label>
					  <?php echo $current_driver;?>
					  </div>
					   <div class="form-group col-sm-3">
					   <label>Start Date : </label>
					  <?php echo $start_date;?>
					  </div>
					   <div class="form-group col-sm-3">
					   <label>End Date : </label>
					  <?php echo $end_date;?>
					  </div>
					   <div class="form-group col-sm-3">
					   <label>Days : </label>
					  <?php echo $day;?>
					  </div>
					  </div>
					  
					   <div class="form form-register dark form-horizontal col-sm-12 col-xs-12">
					   
		  <div class="form-group col-sm-4">
					 
			       	   </div>
					   </div>
					    <!--div class="form form-register dark form-horizontal col-sm-12 col-xs-12">
					   
		  <div class="form-group">
      <label for="email" class="col-sm-4 col-xs-12 control-label">Select Driver<font class="red-alert">*</font></label>
      <div class="col-sm-4 col-xs-12">
      
			       	   <select name="select_driver_id" id="select_driver_id" required class="form-control">
			       	   	 <option style="padding:10px; background-color:#E7D91E; color:#F9F0F1; cursor:pointer;" value="">Select from List </option>
                               <?php 
							   /*
							      //  $customers_sql="SELECT * from employees where id!='$driver_id' order by first_name ASC";
$customers_sql="SELECT * from employees order by first_name ASC";
									$t_result=mysqli_query($con,$customers_sql);
									while($customer=mysqli_fetch_assoc($t_result))
									{
									
									?>
	<option style="padding:20px; background-color:#2977C9; color:#F9F0F1; cursor:pointer;" value="<?php echo $customer['id']; ?>">
	   <?php echo $customer['first_name']; ?>
    </option>
						<?php
						
						}*/
						?>
			       	   </select>
      </div>
    </div>
	
	<!--div class="form-group">
      <label for="email" class="col-sm-4 col-xs-12 control-label">Start Date<font class="red-alert">*</font></label>
      <div class="col-sm-4 col-xs-12">
         <input required type="text" style="width:100%;" value="<?php //echo $start_date;?>" class="form-control" required placeholder="Select a Date" name="start_date" id="start_date" onchange="cal()"  tabindex="7" >
      </div>
    </div>
	
	<div class="form-group">
      <label for="email" class="col-sm-4 col-xs-12 control-label">End Date<font class="red-alert">*</font></label>
      <div class="col-sm-4 col-xs-12">
       <input required type="text" style="width:100%;" value="<?php //echo $end_date;?>" class="form-control" required placeholder="Select a Date" name="end_date" id="end_date" onchange="cal()"  tabindex="7" >
      </div>
    </div>
	
	<div class="form-group">
      <label for="email" class="col-sm-4 col-xs-12 control-label">Days<font class="red-alert">*</font></label>
      <div class="col-sm-4 col-xs-12">
       <input name="days" type="text" id="days" value="<?php //echo $day;?>" class="form-control"  tabindex="4" >
      </div>
    </div-->
        
        
          
         
        </div>
        </section>
        </div>
        </div>
        <!-- page end-->
        </section>
        </section>
        </section>
		
		
		
  <div class="col-md-12">
             <fieldset class="well">
             <legend class="well-legend"><span class="glyphicon glyphicon-th-list">  </span>&nbsp;  Select Drivers </legend>	
            <div class="col-md-12">
							
                            <table id="new_invoice_table" class="table table-responsive list_jobs table-hover table-bordered table-striped table-info" cellspacing="0" border="1">

        <thead>
       
            <tr class="btn-primary">
                           <th class="col-md-1">Select Driver</th>
                           <th>Start Date</th>
                           <th class="col-md-1">End Date</th>
                           <th class="col-md-1">Days</th>
                          <th class="col-md-1">
                           <p style="background-color:#55CD01; cursor:pointer; font-size:16px; font-weight:bold;" id="add_row" class="btn btn-success btn-sm pull-right">+</p>
                           </th>
            </tr>

        </thead>

        <tfoot>

            <tr class="btn-primary">
                         <th class="col-md-3">Select Driver</th>
                           <th>Start Date</th>
                           <th class="col-md-3">End Date</th>
						    <th class="col-md-1">Days</th>
                           <th class="col-md-1"></th>
                          
                           
        </tfoot>

        <tbody>
      <?php 
	  		$srno=0;
///////////////
			  
			
			if($sub_driver<1)
			{
			
			
			//$sub_sql="select count(*) from driver_substitute";
			$sub_sql="select count(*) from driver_bookings";
$sub_result=mysqli_query($con,$sub_sql);
//$sub_driver=mysqli_num_rows($sub_result);

			}
			while($job_data=mysqli_fetch_assoc($sub_result))
			
                  {
 					 
					  ?>
                         <tr>
                           <td class="col-md-3">
                      
                             <select  name="order_detail[<?php echo $srno;?>][lorry_id]" id="lorry<?php echo $srno;?>"   class="form-control lorry" style="font-size:13px; cursor:pointer;">	
							 
							<option style="background-color:#2977C9; color:#F9F0F1; cursor:pointer;">
												Select Driver
											</option> 									     
									   <?php 
                             
							                 
										$customers_sql="SELECT first_name,id from employees order by first_name ASC";
										if(!$customers_sql){echo "error".mysqli_error($con);}
										$t_result=mysqli_query($con,$customers_sql);
										while($payment=mysqli_fetch_assoc($t_result))
										{?>                 
											
											<option style="background-color:#2977C9; color:#F9F0F1; cursor:pointer;" <?php if ($payment['id'] ==@$job_data['driver_id']) { echo 'selected'; } ?> value="<?php echo $payment['id']; ?>">
												<?php echo $payment['first_name']; ?>
											</option>
										<?php } ?>
									</select>  
							
							 
				
                            
                             </td>
                             <td class="col-md-3">
                      
                             <!--select name="order_detail[<?php// echo $srno;?>][slot_id]" id="slot0"  class="form-control" style="font-size:13px; cursor:pointer;">										     
									   <?php /*               
										$payment_sql="SELECT * from driver_substitute order by id ASC";
										$t_result=mysqli_query($con,$payment_sql);
										while($driver_d=mysqli_fetch_assoc($t_result))
										{?>                 
											<option style="background-color:#2977C9; color:#F9F0F1; cursor:pointer;" <?php if ($driver_d['start_date'] ==$job_data['start_date']) { echo 'selected'; } ?> value="<?php echo $driver_d['start_date']; ?>">
												<?php echo $driver_d['start_date']; ?>
											</option>
										<?php } */?>
									</select-->  
								
                            <input  type="date" style="width:100%;" value="<?php echo $job_data['start_date'];?>" min="<?php echo $min_date; ?>" max="<?php echo $max_date; ?>" class="form-control"  placeholder="Select a Date" name="order_detail[<?php echo $srno;?>][start_date]" id="start_date<?php echo $srno;?>" onChange="cal(this.value,<?php echo $srno;?>)"  tabindex="7" >
							</td>
							<td>
							
                            <input  type="date" style="width:100%;" value="<?php echo $job_data['end_date'];?>" min="<?php echo $min_date; ?>" max="<?php echo $max_date; ?>" class="form-control"  placeholder="Select a Date" name="order_detail[<?php echo $srno;?>][end_date]" id="end_date<?php echo $srno;?>" onChange="cal(this.value,<?php echo $srno;?>)"  tabindex="7" >
                             </td>
                              <td class="col-md-1"><!--input name="order_detail[<?php //echo $srno;?>][quantity]" id ="qty0" type="text" jas="0" value="<?php //echo $job_data['quantit'];?>" class="form-control quantity"-->
							   <input name="order_detail[<?php echo $srno;?>][days]" type="text" id="days<?php echo $srno;?>" value="<?php echo @$job_data['days'];?>" class="form-control days"  tabindex="4" >
							  </td>  
                            <td class="col-md-1"><p style="cursor:pointer; font-size:16px; font-weight:bold;" class="btn btn-danger btn-sm remove pull-right">x</p>
                           <input name="order_detail[<?php echo $srno;?>][arrival_time]" id ="arrival_time0" type="hidden" jas="0" value="<?php echo $job_data['arrival_time'];?>" class="form-control arrival_time">
                                 <input name="order_detail[<?php echo $srno;?>][status]" id ="status0" type="hidden" jas="0" value="<?php echo $job_data['status'];?>" class="form-control status">
                           <input name="order_detail[<?php echo $srno;?>][driver_id]" id ="driver_id0" type="hidden" jas="0" value="<?php echo $job_data['driver_id'];?>" class="form-control driver_id">
                    
                                     
                                      
                         				  
              </tr>
              <?php 
	 $srno++;
	}?>
	<input name="srno" id ="srno" type="hidden" jas="0" value="<?php echo $srno;?>" class="form-control">
    <!--input name="booking_id" id ="booking_id" type="hidden"  value="<?php //echo $booking_id;?>" class="form-control"-->                
   		 </tbody>
			   </table>
               <div class="col-sm-offset-4">
            <!--button type="button" class="btn btn-primary pull-right"><i class="fa fa-times"></i> Cancel</button-->
            <input type="submit" name="submit" value="Submit Details" class="btn btn-success pull-right" id="reAllocate">
         
        </div>
				</div>
            
            </div>

		

</form> 
<?php
if(isset($_POST['submit']))
{
//$booking_id=$_POST['booking_id'];
/*$sub_sqlm="select * from driver_bookings WHERE booking_id='$bid'";
$sub_resultm=mysqli_query($con,$sub_sqlm);
$sub_driverm=mysqli_num_rows($sub_resultm);
while($subm_data=mysqli_fetch_assoc($sub_resultm))
{



}
*/

$d_id="";
foreach($_POST['order_detail'] as $key=>$value)
		  {
		      $dsd =$value['lorry_id'];
			  $sd =$value['start_date'];
			  $ed =$value['end_date'];		
			  $d=$value['days'];
			  if($dsd=="" || $dsd=="Select Driver")
			  {
			  echo "<script>var url11 = 'list_bookings.php?'+new Date().getTime();window.location.replace(url11);</script>";  
			  exit;
			  
			  }
			}  
$sql="Delete from driver_bookings where booking_id=".$booking_id;
 if (!mysqli_query($con,$sql)) {//echo $sql_check;die('Update 3 INTO ORDER_Details -Error: ' . mysqli_error($con));
			}
foreach($_POST['order_detail'] as $key=>$value)
		  {
		      $dsd1 =$value['lorry_id'];
			  $sd1 =$value['start_date'];
			  $ed1 =$value['end_date'];		
			  $d1=$value['days'];
			  
			 $d_id=$dsd1;
			 $driver=$d_id;
			 $start_date=$sd1;
			 $end_date=$ed1;

			  	$sqlb="Select * from bookings where id=".$booking_id;
		//echo $sql;
		$resb=mysqli_query($con,$sqlb);
		$book=mysqli_fetch_assoc($resb);
		
		$supp_cost=$book['supp_cost'];
		$parking=$book['parking'];
		$days=$book['days'];
	
$days=$d1;
$total_fare=$supp_cost*$days+$parking+$transfer;
		$transfer=$book['transfer'];
		$total_fare=$supp_cost*$days+$parking+$transfer;
		// check if this booking already exist if yes then update otherwise insert record
	/*	$sql="Select booking_id from driver_bookings where booking_id='$booking_id' AND driver_id='$driver'";
		//echo $sql;
		$res=mysqli_query($con,$sql);
		$rowcount=mysqli_num_rows($res);
		$update_booking='';
		if($rowcount>0){
			
		//echo "Booking Found";
			$update_driver_booking="UPDATE driver_bookings SET
					  status=2,start_date=$start_date,end_date=$end_date,days=$days,total_fare=$total_fare WHERE booking_id=$booking_id AND driver_id=$driver";
					  if (!mysqli_query($con,$update_driver_booking)) {echo "Error. ".mysqli_error($con);}
					  $update_booking="UPDATE bookings SET
					  driver_id=$driver,job_status=2 WHERE id=$booking_id";
					 // echo $update_booking;
					  //exit;
					  if (!mysqli_query($con,$update_booking)) {echo "Error. ".mysqli_error($con);}
					  
					 // $update_driver_substitute="UPDATE driver_substitute SET driver_id=$driver WHERE booking_id=$booking_id";
					 // if (!mysqli_query($con,$update_driver_substitute)) {echo "Error. ".mysqli_error($con);}
			
			}else*/
			{
				
		//echo "nothing found";
				$update_driver_booking="INSERT INTO driver_bookings 
		(booking_id,driver_id,start_date,end_date,days,parking,transfer,total_fare,supp_cost)
		VALUES ('$booking_id','$driver','$start_date','$end_date','$days','$parking','$transfer','$total_fare','$supp_cost')";
		if (!mysqli_query($con,$update_driver_booking)) {mysqli_error($con);}
		$update_booking="UPDATE bookings SET
					  driver_id=$driver,job_status=2 WHERE id=$booking_id";
					  //echo $update_booking;
					  if (!mysqli_query($con,$update_booking)) {echo "Error. ".mysqli_error($con);}
					  
		}
		
		
		
		
	$cd_sqln="SELECT * from employees WHERE id=".$driver;
$cd_resn=mysqli_query($con,$cd_sqln);
$debt_namen=mysqli_fetch_assoc($cd_resn);
$new_driver=$debt_namen['first_name'];
$new_driver_email=$debt_namen['email'];	
		
		$sqlc="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 employees.id='$driver_id'";
		//echo $sql;
		if (!mysqli_query($con,$sqlc)) {mysqli_error($con);}
		$result=$con->query($sqlc);
		$driver=mysqli_fetch_assoc($result);
		$driver_email=$driver['email'];
	//	$driver_phone=$driver['phone'];
		//$driver_name=$driver['first_name'];
		$pco_number=$driver['pco_number'];
		$pco_expiry=$driver['pco_expiry'];
		//$driver_address=$driver['address'];
		$driver_post_code=$driver['post_code'];
		//$driver_photo=$driver['driver_photo'];
		$color=$driver['color'];
		$reg=$driver['reg'];
		$make=$driver['make'];
		/* $start3=date("d/m/y", strtotime($driver['start_date']));
							  $start4 = date("l", strtotime($driver['start_date']));
							  $startdate= $start4.' '.$start3;*/
		 $customers_sql1="select * from driver_bookings WHERE driver_id='$driver' AND booking_id='$booking_id'";
									$t_result1=mysqli_query($con,$customers_sql1);
									$sub=mysqli_fetch_assoc($t_result1);
							  
							   $start3=date("d/m/y", strtotime($sub['start_date']));
							  $start4 = date("l", strtotime($sub['start_date']));
							  $startdate= $start4.' '.$start3;
							  
							   $start5 = date("d/m/y", strtotime($sub['end_date']));
								$start6 = date("l", strtotime($sub['end_date']));
								$enddate= $start5.' '.$start6;
								
		//echo $driver_email;
		//exit;
		//Customer details for sending email
		
		//$passenger_email=$con->real_escape_string($_POST['email'][$index]);
		//$passenger_phone=$con->real_escape_string($_POST['passenger_phone'][$index]);
		$pickup_address=$driver['pickup_address'];
		$pickup_post_code=$driver['pickup_post_code'];
		//$pickup_date=$con->real_escape_string($_POST['pickup_date'][$index]);
		//$hours=$con->real_escape_string($_POST['hours'][$index]);
		//$mins=$con->real_escape_string($_POST['mins'][$index]);
		//$make=$con->real_escape_string($_POST['make'][$index]);
		$comments=$driver['comments'];
		//////// Now Select the Registration and Car Color of this Selectd Driver 
		//$pickup_time=$hours.":".$mins;
		//exit;
		$drop_address=$driver['drop_address'];
		$drop_post_code=$driver['drop_post_code'];
		//echo "Customer".$passenger;
		//$name=$passenger;
		// Now send email to Passenger///////////////////////////////////////////////////////////////
		 $passenger_message ='';
		 $driver_message1='';
         $to = "dashraja65@gmail.com";//$passenger_email;
		 //$No=$No+1; 
					  
			 $driver_message1 .= '    
				 <p>'.$comments.'</p>
		 
		
		 
		 <p style="color:#E3060A"><strong>Booking Ref: </strong>'.$booking_id.'</p>
		 
	     <p><strong>Start Date: </strong>'.$startdate.'</p>
		  <p><strong>End Date: </strong>'.$enddate.'</p>
		 
		 
		     
		 <p><strong>Pickup From: </strong>'.$pickup_address.','.$pickup_post_code.'</p>
         <p><strong>Drop To: </strong>'.$drop_address.','.$drop_post_code.'</p>
		
		<p><strong>Driver PCO Number: </strong>'.$pco_number.'</p>
		  <p><strong>PCO Expiry Date: </strong>'.date("d/m/Y",strtotime($pco_expiry)).'</p>
		 <p><strong>Car: </strong>'.strtoupper($make).'</p>
		 <p><strong>Car Color: </strong>'.strtoupper($color).'</p>
		 <p><strong>Car Reg: </strong>'.strtoupper($reg).'</p>
		
		 <hr>
		<b><p><strong>Terms and Conditions:</strong></p></b>
		

<b> 
Driver are responsible for the safety of vehicles.</b> 
<hr>
</p>
		
		 ';		
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	 
		  
		 //  $driver_email="dashraja65@gmail.com";//$to;
		/*   $message="hello Your Booking ".$booking_id." Is Cancelled";
		   $driver_message=$message;
		  $driver_name=$current_driver;
		$mail2 = new PHPMailer;
		$mail2->SMTPAuth   = true;
		$mail2->setFrom('info@limochauffeurs.com', 'Wings Chauffeurs Ltd.');
		$mail2->IsHTML(true);
		$mail2->addAddress($current_driver_email, $driver_name);
		$mail2->Subject  = 'Booking Updated';
		$mail2->Body     = $driver_message;
		if(!$mail2->send()) {
		   
		   
			  echo '<script>alert("Email Was not Sent To Driver");</script>';
		   }else {
			  /* echo '<script>alert("Email Sent To Driver");</script>';*/
		 //  }
		   
////////////////////////////////////////////////////////////////////////////////////////

	     $driver_email1=$new_driver_email;
		 $message1="hello new driver";
		   //$driver_message1=$message1;
		  $driver_name1=$new_driver;
		$mail21 = new PHPMailer;
		$mail21->SMTPAuth   = true;
		$mail21->setFrom('info@wingschauffeurs.com', 'Wings Chauffeurs Ltd.');
		$mail21->IsHTML(true);
		$mail21->addAddress($driver_email1, $driver_name1);
		$mail21->Subject  = 'Booking Updated';
		$mail21->Body     = $driver_message1;
		if(!$mail21->send()) {
		   
		   
			  echo '<script>alert("Email Was not Sent To New Driver");</script>';
		   }else {
			  /* echo '<script>alert("Email Sent To Driver");</script>';*/
		   }
			  
			  
			}  
			
			


		
					
					echo "<script>alert('successfull');var url11 = 'list_bookings.php?'+new Date().getTime();window.location.replace(url11);</script>";  

}
?>
<script type="text/javascript">
	
	
	

 var jas =  <?php echo $srno;?>;
$('#add_row').click(function(){
	$('#new_invoice_table').append('<tr><td><select name="order_detail['+jas+'][lorry_id]" jas='+jas+' id="lorry'+jas+'" class="form-control lorry"></select> </td><td><input required type="date" style="width:100%;" min="<?php echo $min_date; ?>" max="<?php echo $max_date; ?>" class="form-control"  placeholder="Select a Date" name="order_detail['+jas+'][start_date]" id="start_date'+jas+'" onchange="cal(this.value,'+jas+')" ></td><td><input required type="date" style="width:100%;" min="<?php echo $min_date; ?>" max="<?php echo $max_date; ?>" class="form-control"  placeholder="Select a Date" name="order_detail['+jas+'][end_date]" id="end_date'+jas+'" onchange="cal(this.value,'+jas+')" ></td><td><input name="order_detail['+jas+'][days]" type="text" id="days'+jas+'" class="form-control days"  tabindex="4" ></td><td><p style="cursor:pointer; font-size:20px; font-weight:bold;" class="btn btn-danger btn-sm remove pull-right">x</p></td><input type="hidden" name="order_detail[<?php echo $srno;?>][arrival_time]" id ="arrival_time'+jas+'" jas='+jas+' value="<?php echo $job_data['arrival_time'];?>" class="form-control arrival_time"><input type="hidden" name="order_detail[<?php echo $srno;?>][status]" id ="status'+jas+'" jas='+jas+' value="2" class="form-control status"><input type="hidden" name="order_detail[<?php echo $srno;?>][driver_id]" id ="driver_id'+jas+'" jas='+jas+' value="<?php echo $job_data['driver_id'];?>" class="form-control driver_id"></tr>');
	var i = 1;
	$('.row-num').each(function(){
		$(this).html(i+1);
		i++;
	});
	$('#lorry0 option').clone().appendTo('#lorry'+jas);
	//$('#start_date0').clone().appendTo('#start_date'+jas);
	jas = jas + 1;
});

//remove a row
	$('body').delegate('.remove','click',function()  
	{  
	$(this).parent().parent().remove();
	
	}); 
</script>
<script type="text/javascript">


        function cal(a,i){
		//alert(document.getElementById("end_date"+i).value);
		//alert(document.getElementById("start_date"+i).value);
        if(document.getElementById("end_date"+i)){
		 var sdate = document.getElementById("start_date"+i).value;
 //alert(sdate);
//var sdatearray = sdate.split("-");

//var snewdate = sdatearray[1] + '-' + sdatearray[0] + '-' + sdatearray[2];
//alert(snewdate);

var edate = document.getElementById("end_date"+i).value;
//var edatearray = edate.split("-");

//var enewdate = edatearray[1] + '-' + edatearray[0] + '-' + edatearray[2];
 
 
               
				 var dropdt = new Date(edate);//document.getElementById("end_date").value);
                var pickdt = new Date(sdate);//document.getElementById("start_date").value);
               var ndays= parseInt(((dropdt - pickdt) / (24 * 3600 * 1000))+1);
			//   ndays=ndays+1;
			  // alert(ndays);
		if(ndays<1)
		{
		alert("Select proper date");
		}
		else
		{
            document.getElementById("days"+i).value=ndays;
		}
			
        }  
		}
 $(document).ready(
      function () {
      $('#pickup_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	  
	   $('#start_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	  
	  $('#end_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	  
	     $('.start_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	  
	  $('.end_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
      }
    
    );
	
</script>   
  
</body>
</html>