<?php include("cn.php");?>
<?php $title = "Driver Report";?>
<!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="reports.php"  Style="color:blue;">Reports</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-12 col-lg-12  col-md-12">
<div class="card shadow-sm ctm-border-radius">
<div class="card-body align-center">
<ul class="nav nav-pills" id="pills-tab" role="tablist">
<li class="nav-item mr-md-1">
<a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Driver wise Reports</a>
</li>
<!--<li class="nav-item">-->
<!--<a class="nav-link" id="pills-profile-tab" data-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Booking wise Reports</a>-->
<!--</li>-->
</ul>
</div>
</div>

<?php 
    $id = $from = $to = $driver="";
    if($_GET)
    {
        $_SESSION['driver'] = $_GET['driver'];
        $id=$_GET['driver'];
        $from = $_GET['from'];
        $to = $_GET['too'];
        $driver = "AND driver.driver_id=".$_GET['driver'];
    }
        
    else
    {
        $id=$_SESSION['driver'];
        $from = $_POST['from'];
        $to = $_POST['to'];
        $to = date('Y-m-d H:i:s', strtotime($to."+24 hour -1 seconds"));
        $driver = "AND driver.driver_id=".$id;
    }
    
    $sql_1 = "select * from driver where driver_id = '".$id."' ";
    
    $sql_1 = mysqli_query($connect,$sql_1);
    $data_1 = mysqli_fetch_assoc($sql_1);
                                                // echo $data_1["driver_name"];
    ?>

<form action="reportsdriver.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">
<!--<input type="text" name="driver" id = "driver" value="<?php echo $data_1['driver_id'];?>" disabled hidden="yes"/>-->
<input type="text" class="form-control" placeholder="<?php echo $data_1['driver_name'];?>" name="drivers" value="<?php $data_1['driver_name'];?>" disabled/>
</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="<?php echo $from;?>" name="from" value="<?php echo date('d-m-Y',strtotime($from));?>" disabled/>
</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" name="to" placeholder="<?php echo $to;?>" value="<?php echo date('d-m-Y',strtotime($to));?>" disabled>
</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" disabled/>
</div>-->
</div>
</div>
</div>
</form>

<div class="card shadow-sm ctm-border-radius">
<div class="card-body align-center">
<div class="tab-content" id="pills-tabContent">

<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
<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">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">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

										
								// 		if($_POST)
								// 		{
								// 		    $from = $_POST['from'];
								// 		    $to = $_POST['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"));
										    
								// 		    $driver = "AND driver.driver_id='".$_POST['drivers']."'";
								// 		}
										
										$total = 0;
										$i= 1;
										
										$sql = "SELECT rentedcars.*, cars.car_name AS car_title, cars.car_nameplate AS car_nameplate, 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 ON driver.driver_id = rentedcars.driver_id 
										LEFT JOIN users ON users.Id = rentedcars.User
										WHERE rentedcars.StartTime BETWEEN '$from' AND '$to' $hotel $driver $payStatus
										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">
                                                <!-- <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 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"];
							$i = $i + 1;
							}?>
							<tr>
							   <td class="text-center">TOTAL (<?php echo $rows;?>)</td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							   <td class="text-center"></td>
							   <td class="text-center">Total Amount</td>
							   <td class="text-center">AED. <?php echo $total ?></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>
							   <td class="text-center"></td>
							</tr>
<!--<td></td>										-->
                                    </tbody>
                  </table>
						<!--Total Amount = AED. <?php echo $total ?>-->

</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="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>