
<meta charset="utf-8">

<title>List of Bookings</title>
<!doctype html>

<html>
<?php 

include "head.php";

?>

   <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>

  <?php

include "dbconfig.php";
//include "css_header.php";

$today= date('Y-m-d');
$from="";
	$to="";
	
if (!empty($_POST['from']))
	{
	  $from=$con->real_escape_string($_POST['from']);
	  $from = str_replace("/","-",$from);
	  $from = date("Y-m-d", strtotime($from));
	}
	if (!empty($_POST['to']))
	{
	  $to=$con->real_escape_string($_POST['to']);
	  $to = str_replace("/","-",$to);
	  $to = date("Y-m-d", strtotime($to));
	}
	
$sql="SELECT bookings.pickup_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,
customers.id AS customer_id, customers.name AS customer_name,customers.address1,customers.post_code,customers.city, customers.mobile, payment_type.name AS payment_type, employees.first_name AS driver,employees.id as driver_id, vehicles.make as vehicle, company_contact.name as company_contact,company_contact.email
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 vehicles ON bookings.vehicle_id = vehicles.id 
LEFT JOIN company_contact ON bookings.passenger_id = company_contact.id 
WHERE bookings.job_status=2 
AND bookings.pickup_date BETWEEN '$from' AND '$to'
ORDER BY bookings.id DESC
";
// $customer_id=$_GET['company_id'];
//WHERE customers.id=$customer_id GROUP BY bookings.id
$res=mysqli_query($con,$sql);
$rowcount=mysqli_num_rows($res);

//echo $sql;


?>

 </head>

<body style="font-family:Montserrat; font-size:16px;">
<div class="container-fluid">
  <div class="col-md-12" style="text-align:center;color:#0000; padding:5px; font-size:18px;">
   <div class="col-md-4" style="margin-top:10px;">
   <p style="text-align:center;color:#0000; padding:10px; font-size:16px;">Filter Jobs as Your Requirement</p>
   </div>
       
      
      </div>
   

    <form action="" method="post">
    <input type="hidden" name="filter_search" value="yes">
     <div class="col-md-12" style="text-align:center;">

        <center>
        <div class="col-md-2">
         <div class="form-group">
                      
 <input type="text" name="from" class="from form-control" placeholder="Date From" id="from">
             
         </div>
        </div>
       <div class="col-md-2">
         <div class="form-group">
                      
 <input type="text"  name="to" class="to form-control" placeholder="Date To" id="to">
             
         </div>
        </div>
     <div class="col-md-1">
            <div class="form-group">
                  <input type="text" name="job_id" id="job_id" class="job_id form-control" placeholder="Job ID">
            </div>      
    
         </div>
         
         <div class="col-md-1">
            <div class="form-group">
                  <input type="text" name="driver" id="driver" class="driver form-control" placeholder="Driver">
            </div>      
    
         </div>
     
      <div class="col-md-1">
         <div class="form-group">
          <input type="text" name="paid" id="paid" class="paid job_type form-control" placeholder="Type N or P">
         </div>
      </div>
      <div class="col-md-1">
          <div class="form-group">
            <input type="text" name="post_code" id="post_code" class="post_code form-control" placeholder="Post Code">
          </div> 
      </div>
      <div class="col-md-2">
          <div class="form-group">
            <input type="text" name="name" 
id="name" class="name form-control" placeholder="Customer Name">
          </div> 
      </div>
        </div>
</center>
      </form>
      
   
<hr>
  
  <div class="row">
      <div class="col-md-12" id="filter_results">
        
           <?php include "ajax/finished_jobs_data.inc.php";?>

        
		    </div>
	    </div>
</div>



<script type="text/javascript">
$('body').delegate('.post_code,.name,.driver,.paid,.from,.to,.job_id','keyup',function()  
{
		
  var from=$('#from').val();
  var to=$('#to').val();
  //alert(from);
  var filter_search="filter_search";
  var post_code=$('#post_code').val();
  var name=$('#name').val();
  var driver=$('#driver').val();
   var paid=$('#paid').val();
    var search = $(this).val();
  var booking_id=$('#job_id').val();
	
  if (search.length > 0) {
	

   var dataString ='filter_search=' + filter_search+'&from=' + from+'&post_code=' + post_code+'&name=' + name+'&driver=' + driver+'&paid=' + paid +'&to=' + to+ '&booking_id=' + booking_id;

	
	} else {
		var dataString ='filter_search=' + filter_search+'&from=' + from +'&post_code=' + post_code+'&name=' + name+'&driver=' + driver+'&paid=' + paid +'&to=' + to+ '&booking_id=' + booking_id;
	}
	//alert(dataString);
  $.ajax({
                    type: "POST",
                    url: "search_finished_jobs.inc.php",
                    data: dataString,
                    success: function(data) {
                     //console.log(data); 
          // $('#gross').hide();
           $('#filter_results').html(data); 
           
                }
            });
        });
		
//When user click on Start_date execute the filter
  $('.to').datepicker({
	
    	onSelect: function() {
			
			$( ".to" ).datepicker( "option", "dateFormat","dd/mm/yy");
		var to=$('#to').val();
                $( ".from" ).datepicker( "option", "dateFormat","dd/mm/yy");
		var from=$('#from').val();
		//alert(to);
  		var filter_search="filter_search";
    
  		//alert(amount);
  		 var dataString ='filter_search=' + filter_search+'&to=' + to+'&from=' + from;
			//alert(dataString);
  //return false;
  $.ajax({
                    type: "POST",
                    url: "search_finished_jobs.inc.php",
                    data: dataString,
                    success: function(data) {
                     //console.log(data); 
          // $('#gross').hide();
           $('#filter_results').html(data); 
           
                }
            });
			
    }
  
  });

	$('#name').keyup(function(){
	
});	
$('.from').datepicker({
	
    	onSelect: function() {
			
                $( ".from" ).datepicker( "option", "dateFormat","dd/mm/yy");
		var from=$('#from').val();
		//alert(to);
  		var filter_search="filter_search";
    
  		//alert(amount);
  		 var dataString ='filter_search=' + filter_search+'&from=' + from;
			//alert(dataString);
        }
        });
</script>
</body>
</html>