<?php include("cn.php");?>
<?php $title = "Drivers Reports";?>
<!DOCTYPE html>
<html lang="en">
<?php include("head-tag.php");?>

<?php 
date_default_timezone_set('Asia/Dubai');

       $sql_1 = mysqli_query($connect,"select * from users where
        Id = '".$_SESSION["userid"]."' ");
        $data_1 = mysqli_fetch_assoc($sql_1);
?>
<body>

<div class="inner-wrapper">

<?php include("pre-loader.php");?>

<?php include("header.php");?>


<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xl-3 col-lg-4 col-md-12 theiaStickySidebar">
<aside class="sidebar sidebar-user">
<div class="card ctm-border-radius shadow-sm">
            <div class="card-body py-4">
                <div class="row">
                    <div class="col-md-12 mr-auto text-left">
                        <div class="custom-search input-group">
                            <div class="custom-breadcrumb">
                                <ol class="breadcrumb no-bg-color d-inline-block p-0 m-0 mb-2">
                                    <li class="breadcrumb-item d-inline-block"><a href="index.php" class="text-dark">Home</a></li>
                                    <li class="breadcrumb-item d-inline-block active"><?php echo $title?></li>
                                </ol>
                                <h4 class="text-dark">Admin Dashboard</h4>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
<div class="card ctm-border-radius shadow-sm">
<div class="card-body">
<!--<a href="javascript:void(0)" class="btn btn-theme button-1 ctm-border-radius text-white btn-block" data-toggle="modal" data-target="#add_report"><span><i class="fe fe-plus"></i></span> Create Reports</a>-->
</div>
</div>
</aside>
</div>
<div class="col-xl-9 col-lg-8  col-md-12">

<?php include("tabs.php") ?>

<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 = $totaladdifare = 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>Additional Fare</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,  rentedcars.addifare as addifare, 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'] + $data['addifare'];
    $bookings +=  $data['total'] + $data['addifare'];
?>
</td>
<td>
AED. <?php echo $data['total'];?>
</td>
<td>
AED. <?php echo $data['addifare']; ?>
</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 
$total +=$data['total'];
$totaladdifare +=$data['addifare'];
// $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>
AED. <?php echo $totaladdifare;?>
</td>
<td></td>
</tr>

</tbody>

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


<!--<div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
<div class="employee-office-table">
<div class="table-responsive">
<table class="table custom-table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Salary Current</th>
<th>Date Of Birth</th>
<th>Phone Number</th>
<th>Address</th>
<th>Bank Name</th>
<th>Account Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="employment.html" class="avatar"><img alt="avatar image" src="assets/img/profiles/img-5.jpg" class="img-fluid"></a>
<h2><a href="employment.html">Danny Ward</a></h2>
</td>
<td>
Male
</td>
<td>$3000</td>
<td>25 Jun 1984</td>
<td>9876543231</td>
<td>201 Lunetta Street,Plant City,<br> Florida(FL), 33566</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987652</td>
</tr>
<tr>
<td>
<a href="employment.html" class="avatar"><img class="img-fluid" alt="avatar image" src="assets/img/profiles/img-4.jpg"></a>
<h2><a href="employment.html"> Linda Craver</a></h2>
</td>
<td>
Female
 </td>
<td>$2000</td>
<td>14 Feb 1984</td>
<td>9876543221</td>
<td>683 Longview Avenue,New York, <br> New York(NY), 10011</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987662</td>
</tr>
<tr>
<td>
<a href="employment.html" class="avatar"><img class="img-fluid" alt="avatar image" src="assets/img/profiles/img-3.jpg"></a>
<h2><a href="employment.html">Jenni Sims</a></h2>
</td>
<td>
Female
</td>
<td>$4000</td>
<td>20 Jan 1984</td>
<td>9876534214</td>
<td> 4923 Front Street,Detroit,<br> Michigan(MI), 48226</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987653</td>
</tr>
<tr>
<td>
<a href="employment.html" class="avatar"><img alt="avatar image" src="assets/img/profiles/img-6.jpg" class="img-fluid"></a>
<h2><a href="employment.html"> Maria Cotton</a></h2>
</td>
<td>
Female
</td>
<td>$5000</td>
<td>15 Jul 1984</td>
<td>9876541123</td>
<td>1246 Parkway Street, Brawley, <br>California(CA), 92227</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987654</td>
</tr>
<tr>
<td>
<a href="employment.html" class="avatar"><img class="img-fluid" alt="avatar image" src="assets/img/profiles/img-2.jpg"></a>
<h2><a href="employment.html"> John Gibbs</a></h2>
</td>
<td>
Male
</td>
<td>$4500</td>
<td>05 Dec 1984</td>
<td>9876541132</td>
<td>4604 Fairfax Drive,Rochelle Park,<br> New Jersey(NJ), 07662</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987655</td>
</tr>
<tr>
<td>
<a href="employment.html" class="avatar"><img class="img-fluid" alt="avatar image" src="assets/img/profiles/img-10.jpg"></a>
<h2><a href="employment.html"> Richard Wilson</a></h2>
</td>
<td>
Male
</td>
<td>$4600</td>
<td>25 Apr 1984</td>
<td>9876541321</td>
<td>3088 Gordon Street, Los Angeles,<br> California(CA), 90017</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987656</td>
</tr>
<tr>
<td>
<a href="employment.html" class="avatar"><img class="img-fluid" alt="avatar image" src="assets/img/profiles/img-8.jpg"></a>
<h2><a href="employment.html">Stacey Linville</a></h2>
</td>
<td>
Female
</td>
<td>$4700</td>
<td>23 Jan 1984</td>
<td>9876542312</td>
<td>835 Sarah Drive,Lafayette,<br> Louisiana(LA), 70506</td>
<td>Life Essence Banks, Inc.</td>
<td>112300987657</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>-->

</div>
<div class="text-center mt-3">
<!--<a href="javascript:void(0)" class="btn btn-theme button-1 ctm-border-radius text-white">Download Report</a>-->
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div>


<!--<div class="modal fade" id="add_report">-->
<!--<div class="modal-dialog modal-dialog-centered">-->
<!--<div class="modal-content">-->

<!--<div class="modal-body">-->
<!--<button type="button" class="close" data-dismiss="modal">&times;</button>-->
<!--<h4 class="modal-title mb-3">Create Report</h4>-->
<!--<form>-->
<!--<p class="mb-2">Select Report Type</p>-->
<!--<div class="custom-control custom-radio custom-control-inline">-->
<!--<input type="radio" class="custom-control-input" id="customRadio" name="example" value="customEx">-->
<!--<label class="custom-control-label" for="customRadio">Team Member</label>-->
<!--</div>-->
<!--<div class="custom-control custom-radio custom-control-inline">-->
<!--<input type="radio" class="custom-control-input" id="customRadio2" name="example" value="customEx">-->
<!--<label class="custom-control-label" for="customRadio2">Time Off</label>-->
<!--</div>-->
<!--<div class="form-group">-->
<!--<label class="mt-3">What data would you like to include?</label>-->

<!--<select multiple class="select w-100 form-control">-->
<!--<option>Full Name</option>-->
<!--<option>Working Days Off</option>-->
<!--<option>Booked By</option>-->
<!--<option>Start Date</option>-->
<!--<option>End Date</option>-->
<!--<option>Team Name</option>-->
<!--<option>First Name</option>-->
<!--<option>Last Name</option>-->
<!--<option>Email</option>-->
<!--<option>Date Of Birth</option>-->
<!--<option>Phone Number</option>-->
<!--</select>-->
<!--</div>-->
<!--</form>-->
<!--<button type="button" class="btn btn-danger text-white ctm-border-radius float-right ml-3" data-dismiss="modal">Cancel</button>-->
<!--<button type="button" class="btn btn-theme button-1 text-white ctm-border-radius float-right">Add</button>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->


<div class="sidebar-overlay" id="sidebar_overlay"></div>

<?php include("scripts.php");?>
<script>
     $('#Booking').DataTable( {
            dom: 'B<clear>frtip',
            "bFilter": true,
            "bSort": true,
            "bPaginate": true,
             paging: true,
             info: false,
            "lengthMenu": [ [10, 50, 100, -1], [10, 50, 100, "All"] ],
            buttons: [
                {
                    extend: 'copy',
                    exportOptions: {
                        columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
                    }
                    
                },
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
                    }
                },
                {
                extend: 'print',
                orientation: 'landscape',
                pageSize: 'LEGAL',
                exportOptions: {
                    columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
                }
                
            },
                {
                    extend: 'pdf',
                    orientation: 'landscape',
                    pageSize: 'LEGAL',
                    exportOptions: {
                       columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
                    }
                    
                },
                
               
            ],
           
            
        } )
</script>
</body>
</html>