<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
    
    <form action="reports.php" method="POST">
<div class="card shadow-sm ctm-border-radius">
<div class="card-body align-center">
<div class="row filter-row">
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-3">
<div class="form-group mb-xl-0 mb-md-2 mb-sm-2">
<select class="form-control select" id="drivers" name="drivers">
    <?php ($driver=="all")? $status="selected":$status="";?>
<option vlaue="all" <?php echo $status ?>>Select Driver</option>
    <?php 
    
    $bookings = $total = $i = 0;
    $from = $to = $driver="";
    
    if($_POST)
    {
        $from = $_POST['from'];
        $to = $_POST['to'];
        // if($from == $to)
        $from = date('Y-m-d H:i:s', strtotime($from));
        $to = date('Y-m-d H:i:s', strtotime($to."+24 hour -1 seconds"));
        
        if($_POST['drivers']!="Select Driver")
            $driver = "AND driver.driver_id='".$_POST['drivers']."'";
                                                // echo $data_1["driver_name"];
    }
    else
    {
        $from = date('d-m-Y');
        $to = date('d-m-Y', strtotime($to."+24 hour -1 seconds"));
    }
    
    $sql = "select driver.driver_id as id, driver.driver_name as driver from driver";
    
    $sql = mysqli_query($connect, $sql) or die(mysqli_error($connect));
    
    while($data = mysqli_fetch_assoc($sql)){
         ($data['id']==$driver)? $status="selected":$status="";
         
        echo '<option value="'.$data['id'].'" '.$status.'>'.$data['driver'].'</option>';
    }
    ?>
</select>
</div>
</div>

<div class="col-sm-6 col-md-6 col-lg-6 col-xl-3">
<div class="form-group mb-lg-0 mb-md-2 mb-sm-2">
<input type="text" class="form-control datetimepicker" placeholder="From" name="from" value="<?php if($_POST){echo date('d-m-Y', strtotime($from));}  ?>" required/>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-3">
<div class="form-group mb-lg-0 mb-md-0 mb-sm-0">
<input type="text" class="form-control datetimepicker" placeholder="To" name="to" value="<?php if($_POST){echo date('d-m-Y', strtotime($to));} ?>" required/>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-3">
<input type="submit" class="btn btn-theme button-1 text-white btn-block p-2 mb-md-0 mb-sm-0 mb-lg-0 mb-0" value="Apply Filter"/>
</div>
</div>
</div>
</div>
</form>

    
    
    
<div class="employee-office-table">
<div class="table-responsive">
<table  id="Booking" class="table custom-table table-hover">
    
<thead>
    <tr>
        <td  colspan="6">
            From <?php echo date('d-m-Y',strtotime($from));?> to <?php echo date('d-m-Y',strtotime($to));?>
        </td>
        
    </tr>
<tr>
<th>Name</th>
<th>License No.</th>
<th>Email</th>
<!--<th>Booking No.</th>-->
<!--<th>Date</th>-->
<th>Total Amount</th>
<th>Amount Received</th>
<th>Action</th>
<!--<th>Company Name</th>-->
</tr>
</thead>
<tbody>
    
    
<?php 

// count(rentedcars.id) as bookings,
// echo $driver;
$sql = "select driver.driver_id as id, driver.Image as image, driver.driver_name as driver, driver.dl_number as dlnumber, app_users.Email as Email,
 sum(rentedcars.total_amount) as total
from rentedcars
LEFT JOIN driver on driver.driver_id = rentedcars.driver_id
RIGHT JOIN app_users on driver.driver_id = app_users.DriverId
WHERE rentedcars.StartTime BETWEEN '$from' AND '$to' $driver
GROUP BY id
";
$sql = mysqli_query($connect, $sql) or die(mysqli_error($connect));

$rows = mysqli_num_rows($sql);

if ($rows>0) {
while($data = mysqli_fetch_assoc($sql)){
$data['image']="./drivers".$data['image'];
?>
    
    
<tr>
<td>

<a href="employment.html" class="avatar"><img alt="avatar image" src="<?php echo $data['image'];?>" class="img-fluid">
</a>
<?php echo $data['driver'];?>
</td>
<td>
<?php echo $data['dlnumber'];?>
</td>
<td><?php echo $data['Email'];?></td>
<td>
AED. <?php echo $data['total'];?>
</td>
<td>
AED. <?php echo $data['total'];?>
</td>
<td>
    <a href="<?php echo 'reportsdriver.php?driver='.$data["id"].'&from='.$from.'&too='.$to;?>"><span class="btn btn-outline-success text-dark btn-sm">View Detail</span></a></td>
<!--<td><span class="btn btn-outline-warning text-dark btn-sm">Designing</span></td>-->
<!--<td>05 Jan 2019</td>-->
<!--<td>Focus Technologies</td>-->
</tr>

<?php 
$bookings +=$data['total'];
$total +=$data['total'];
// $i = 0;
// $bookings = $total = $i = 0;
}
} else
{
    echo "NO Recored Found!";
}
?>
<tr>
<td>
TOTAL (<?php echo $rows;?>)
</td>
<td></td>
<td></td>
<td>
AED. <?php echo $bookings;?>
</td>
<td>
AED. <?php echo $total;?>
</td>
<td></td>
</tr>

</tbody>

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