<?php include("cn.php");?>
<?php $title = "All 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");?>


<?php

    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"));
        
    }
    else
    {
        $from = date('d-m-Y');
        $to = date('d-m-Y', strtotime($to."+24 hour -1 seconds"));
    }

?>

<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-drivers.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-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 class="text-center">Action</th>-->
						  <th class="text-center">Id</th>
						  <th class="text-center">Status</th>
						  <th class="text-center">Driver Id</th>
						  <th class="text-center">Booking #</th>
						  <th class="text-center">Driver</th>
						  <th class="text-center">Booking Date</th>
						  <th class="text-center">Amount</th> 
                          <th class="text-center">Additional Fare</th>
						  <th class="text-center">Car</th>
						  <th class="text-center">Vehicle Number</th>
						  <th class="text-center">Customer</th>
						  <th class="text-center">Pickup</th>
						  <th class="text-center">Destination</th>
						  <th class="text-center">Payment Status</th>
						  
						  <!--<th class="text-center">Payment</th>-->
						  <!--<th class="text-center">source</th>-->
						  
                          
						</tr>
						</thead>
                        <tbody>
										<?php

										
										$total = $totaladdifare = 0;
										$i= 1;
										
										$sql = "SELECT rentedcars.*, cars.car_name AS car_title, cars.car_nameplate AS car_nameplate, rentedcars.addifare as addifare, rentedcars.status as booking_status, rentedcars.hotel_name as hotel, rentedcars.PaymentStatus as PaymentStatus, driver.driver_name as driver_name FROM rentedcars 
										INNER JOIN cars ON cars.car_id = rentedcars.car_id 
										INNER JOIN driver
										LEFT JOIN users ON users.Id = rentedcars.User
										WHERE rentedcars.StartTime BETWEEN '$from' AND '$to' $hotel
										GROUP BY id
										ORDER BY rentedcars.id DESC
										";
										$sql = mysqli_query($connect, $sql);
										$rows = mysqli_num_rows($sql);
                                           
										while($data = mysqli_fetch_assoc($sql)){
                                            ?>
											<tr>
											    <!--<td class="text-center">-->
                                            <!--<a href="booking-detail.php?id=<?php echo $data["id"]?>" class="btn btn-theme button-1 ctm-border-radius text-white btn-sm float-center"><i class="fa fa-reply " aria-hidden="true"></i></a>-->
                                            <!--</td>-->
                                             <td class="text-center">
                                                <?php echo $i?>
                                            </td>
                                            
                                             <td class="text-center">
                                            <h4 class="card-title mb-0 mt-2"><?php { echo '
                                            <a href="./print2.php?id='.$data['BookingNumber'].'" class="btn btn-theme button-1 text-white ctm-border-radius lnr lnr-printer float-center ml-3"style="background-color: green;">Booking</a>
                                            <a href="./print1.php?id='.$data['BookingNumber'].'" class="btn btn-danger text-white ctm-border-radius lnr lnr-printer float-center">Invoice</a>             
                                            '; }?>
                                            </h4>                                             
                                            </td>
                                            <td class="text-center">
                                                <?php echo $data["driver_id"]?>
                                            </td>
                                             <td class="text-center">
                                                <!-- <h2 class="ml-2"><a href="details.php?id=<?php echo $data["id"]?>"><?php echo $data["BookingNumber"]?></a></h2> -->
                                                <h2 class="ml-2"><a href="#"><?php echo $data["BookingNumber"]?></a></h2>
                                            </td>
                                            
                                           <td class="text-center">
                                            <?php 
                                                
                                                $sql_1 = mysqli_query($connect,"select * from driver where
                                                driver_id = '".$data["driver_id"]."' ");
                                                $data_1 = mysqli_fetch_assoc($sql_1);
                                                echo $data_1["driver_name"];
                                            ?>
                                            <a
                                            <?php 
                                             if($data["booking_status"]=="Pending")
                                             echo 'style="color:red; font-weight:bold;"';
                                             else if ($data["booking_status"]=="assigned")
                                             echo 'style="color:blue; font-weight:bold;"';
                                             else
                                             echo 'style="color:green; font-weight: bold;"';
                                            ?>>
                                            (<?php echo $data["booking_status"]?>)</a>
                                                
                                            </td>
                                            
                                            <td class="text-center"> <?php echo date('d.m.Y', strtotime($data["rent_start_date"]));?>
                                            <?php echo date('h:i:sa', strtotime($data["rent_start_date"]));?>
                                            </td>
                                            
                                            <td class="text-center"> AED. <?php echo $data["total_amount"]?></td>
                                            <td>
                                            AED. <?php echo $data['addifare']; ?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php echo $data["car_title"]?>
                                            </td>
                                            <td class="text-center">
                                                <?php echo $data["car_nameplate"]?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php 

                                                $customer = $data["AppUser"];
                                                $query = "SELECT * FROM app_users WHERE id = '$customer'";
                                                $sql_1 = mysqli_query($connect,$query);
                                                $data_1 = mysqli_fetch_assoc($sql_1);

                                                echo $data_1["Name"];?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php echo $data["pickup"]?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php echo $data["Destination"]?>
                                            </td>
                                            <td class="text-center">
                                                <?php
                                                if ($data["PaymentStatus"] == "Hotel" || $data["PaymentStatus"] == "By Hotel"){
                                                echo $data["PaymentStatus"] . " ( ". $data["hotel"] ." )";
                                                }else{
                                                echo $data["PaymentStatus"];
                                                }?>
                                            </td>
                                            
                                            <!--<td class="text-center"> <?php echo $data["PaymentMethod"]?> (<?php echo $data["PaymentStatus"]?>)</td>-->
                                            <!--<td class="text-center"><?php echo $data["bookingsource"]?></td>-->
                                        </tr>
                                        <?php 
							$total += $data["total_amount"];
							$totaladdifare +=$data['addifare'];
							$i = $i + 1;
							}?>
							<tr>
							   <td class="text-center">TOTAL (<?php echo $rows;?>)</td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							   <td></td>
							   <td class="text-center"></td>
							   <td class="text-center">Total Amount</td>
							   <td class="text-center">AED. <?php echo $total ?></td>
							   <td>AED. <?php echo $totaladdifare; ?></td>
							   <td></td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							</tr>
<!--<td></td>										-->
                                    </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, 12, 13]
                    }
                    
                },
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
                    }
                },
                {
                extend: 'print',
                orientation: 'landscape',
                pageSize: 'LEGAL',
                exportOptions: {
                    columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
                }
                
            },
                {
                    extend: 'pdf',
                    orientation: 'landscape',
                    pageSize: 'LEGAL',
                    exportOptions: {
                       columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
                    }
                    
                },
                
               
            ],
           
            
        } )
</script>
</body>
</html>