<?php header("Cache-Control: no-cache, must-revalidate");
include "head_without_jquery.php";
include "dynamic_table.php";
?>

<?php

include "dbconfig.php";
$today= date('Y-m-d');
$sql="SELECT employees.*,employees.id as id
FROM employees
"; // this is main big SQL Query to fetch data

if(isset($_POST['filter_search'])){
    
	$name='';
	$from="";
	$to="";
	$sql="SELECT employees.*,employees.id as id
FROM employees 
 INNER JOIN debtors ON employees.id=debtors.source_id WHERE 1=1";
//$sql_sub="SELECT * FROM driver_bookings WHERE 1=1";
	
	if (!empty($_POST['from']) && !empty($_POST['to']))
	{
	  $from=$con->real_escape_string($_POST['from']);
	  $from = str_replace("/","-",$from);
	  $from = date("Y-m-d", strtotime($from));
	
	  $to=$con->real_escape_string($_POST['to']);
	  $to = str_replace("/","-",$to);
	  $to = date("Y-m-d", strtotime($to));
	$sql.=" AND 
    debtors.created BETWEEN '$from' AND '$to'"; 
	//$sql_sub.=" AND start_date BETWEEN '$from' AND '$to'"; 
	}
	
	if (!empty($_POST['driver_id']))
	{
	  $driver_id=$con->real_escape_string($_POST['driver_id']);
	$sql.=" AND employees.id='$driver_id'";
	
	}
	



}
$res=mysqli_query($con,$sql);
$rowcount=mysqli_num_rows($res);


?>

<?php 
$count_sql="SELECT * from employees";
$count_res=mysqli_query($con,$count_sql);
$total_jobs=mysqli_num_rows($count_res);
;
?>
<!DOCTYPE html>

<html lang="en">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.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>
   <body>

      

      <div class="container-fluid">
<div class="col-md-12" style="text-align:center;color:#0000; padding:5px; font-size:18px;">
   <h2> List of All Debtors</h2>
     
</div>
      <div class="col-md-12" id="filter_results">
        
        <?php include "ajax/list_driver_debtor.php";?>
        
		    </div>
	    </div>
<!-- Delete Modal -->

   <script>
   
  $(document).ready(function() {
	 
    $('#drivers').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5',
			'print'
			        ]
    } );
} );
 </script>
 <script>
 $('.from').datepicker({
	
    	onSelect: function() {
			
                $( ".from" ).datepicker( "option", "dateFormat","dd/mm/yy");
		var from=$('#from').val();
		
        }
        });
$('.to').datepicker({
	
    	onSelect: function() {
		$( ".from" ).datepicker( "option", "dateFormat","dd/mm/yy");
		var from=$('#from').val();	
	    $( ".to" ).datepicker( "option", "dateFormat","dd/mm/yy");
		var to=$(this).val();
		
        if(from>to){alert("Date From is Greater than Date To");return false;
		
		}        
		var date='from='+from+'&to='+to;
		var url11 = 'ajax/find_drivers_transcations.php?'+new Date().getTime();
		$.ajax
        ({
              type: "Post",
              url: url11,
              data: date,
              success: function(data)
              {
                 $('#jobs_data').html(data);
              }
		});
			
    }
  
  });

 $('#driver_id').select2({width: '100%'});
 </script>   
   </body>
</html>
