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

<div class="tab-pane fade show active" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
    
<form action="reports-hotels.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-2">
<div class="form-group mb-xl-0 mb-md-2 mb-sm-2">
<select class="form-control select" id="hotels" name="hotels">
    <?php ($hotel=="all")? $status="selected":$status="";?>
<option vlaue="all" <?php echo $status ?>>Select Hotel</option>
    <?php 
    
    $bookings = $total = $totaladdifare = $i = 0;
    $from = $to = $hotel = $driver = $paymentstatus ="";
    
    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['hotels']!="Select Hotel")
            $hotel = "AND rentedcars.hotel_name='".$_POST['hotels']."'";
                                                // echo $data_1["driver_name"];
    }
    else
    {
        $from = date('d-m-Y');
        $to = date('d-m-Y', strtotime($to."+24 hour -1 seconds"));
    }
    
    $sql = "select FullName as hotel from users where Role = 'hotel'";
    
    $sql = mysqli_query($connect, $sql) or die(mysqli_error($connect));
    
    while($data = mysqli_fetch_assoc($sql)){
         ($data['hotel']==$driver)? $status="selected":$status="";
         
        echo '<option value="'.$data['hotel'].'" '.$status.'>'.$data['hotel'].'</option>';
    }
    ?>
</select>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-2">
<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 
    
    if($_POST)
    {
        
        if($_POST['drivers']!="Select Driver")
            $driver = "AND driver.driver_id='".$_POST['drivers']."'";
                                                // echo $data_1["driver_name"];
    }
    
    
    $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-2">
<div class="form-group mb-xl-0 mb-md-2 mb-sm-2">
<select class="form-control select" id="paymentstatus" name="paymentstatus">
    <?php ($_POST['paymentstatus']=="all")? $status="selected":$status="";?>
<option value="all" <?php echo $status ?>>Select Payment Method </option>
    <?php 
    if($_POST)
    {
        if($_POST['paymentstatus']!="all")
        $paymentstatus = "AND rentedcars.PaymentStatus='".$_POST['paymentstatus']."'";
    }
    ?>
    <option value="Cash"  <?php ($_POST['paymentstatus']=="Cash")? $status="selected":$status=""; echo $status;?>>Cash</option>
    <option value="Credit Card"  <?php ($_POST['paymentstatus']=="Credit Card")? $status="selected":$status=""; echo $status;?>>Credit Card</option>
    <option value="Room"  <?php ($_POST['paymentstatus']=="Room")? $status="selected":$status=""; echo $status;?>>Room</option>
</select>
</div>
</div>

<div class="col-sm-6 col-md-6 col-lg-6 col-xl-2">
<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-2">
<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-2">
<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>Id</th>
<th>Full Name</th>
<th>UserName</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, rentedcars.hotel_name as hotel, rentedcars.PaymentStatus as PaymentStatus, 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' $hotel $driver $paymentstatus
GROUP BY id
";
$sql = mysqli_query($connect, $sql) or die(mysqli_error($connect));

$rows = mysqli_num_rows($sql);

if ($rows>0) {
    $i = 1;
while($data = mysqli_fetch_assoc($sql)){
$data['image']="./users".$data['image'];
?>
    
    
<tr>
    <td><?php echo $i ?></td>
<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 'reportshotel.php?PaymentStatus='.$data["PaymentStatus"].'&hotel='.$data["hotel"].'&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 
$totaladdifare +=$data['addifare'];
$total +=$data['total'];
$i = $i + 1;
// $i = 0;
// $bookings = $total = $i = 0;
}
} else
{
    echo "NO Recored Found!";
}
?>
<tr>
<td>
TOTAL (<?php echo $rows;?>)
</td>
<td></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>
<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: ':visible'
                    }
                    
                },
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                extend: 'print',
                orientation: 'landscape',
                pageSize: 'LEGAL',
                exportOptions: {
                    columns: ':visible'
                }
                
            },
                {
                    extend: 'pdf',
                    orientation: 'landscape',
                    pageSize: 'LEGAL',
                    exportOptions: {
                        columns: ':visible'
                    }
                    
                },
                
               
            ],
           
            
        } );
</script>
</body>
</html>