<?php include("cn.php");?>
<?php $title = "Bookings";?>
<!DOCTYPE html>
<html lang="en">
<?php include("head-tag.php");
$sql = mysqli_query($connect, "select count(*) as total from rentedcars
where User = '".$_SESSION['userid']."'");
$data = mysqli_fetch_assoc($sql);
$user_id = $_SESSION['userid'];

?>
<body>

<div class="inner-wrapper">
<?php include("pre-loader.php");?>

<?php include("header.php");?>
<div class="page-wrapper">
    <div class="container-fluid">
        <div class="col-xl-12 col-lg-12 col-md-12">

<div class="row">
<div class="col-xl-3 col-lg-3 col-sm-6 col-12">
<div class="card dash-widget ctm-border-radius shadow-sm">
<div class="card-body" style="padding: 0.65rem;">
<div class="card-icon bg-info" style="width: 40px;
    height: 40px;">
<i class="fa fa-calendar" aria-hidden="true"></i>
</div>
<?php 
$sql = mysqli_query($connect, "select count(id) as total from rentedcars WHERE User = '".$_SESSION['userid']."'");
$data = mysqli_fetch_assoc($sql);
?>
<div class="card-right">
<h4 class="card-title"><a style="color: #4ab9cf; font-weight: bold;">Total Bookings</a></h4>
<p class="card-text"><?php echo $data['total']?></p>
</div>
</div>
</div>
</div>
<?php 
$sql = mysqli_query($connect, "SELECT count(id) as total from rentedcars WHERE User = '".$_SESSION['userid']."' and Status = 'Pending'");
$data = mysqli_fetch_assoc($sql);
?>
<div class="col-xl-3 col-lg-3 col-sm-6 col-12">
    <div class="card dash-widget ctm-border-radius shadow-sm">
        <div class="card-body" style="padding: 0.65rem;">
            <div class="card-icon bg-danger" style="width: 40px;
    height: 40px;">
                <i class="fa fa-calendar-times-o" aria-hidden="true"></i>
            </div>
            <div class="card-right">
                <h4 class="card-title"><a style="color: #4ab9cf; font-weight: bold;">Pending</a></h4>
                <p class="card-text"><?php echo $data['total']?></p>
            </div>
        </div>
    </div>
</div>
<?php 
$sql = mysqli_query($connect, "SELECT count(id) as total from rentedcars WHERE User = '".$_SESSION['userid']."' and Status = 'assigned'");
$data = mysqli_fetch_assoc($sql);
?>
<div class="col-xl-3 col-lg-3 col-sm-6 col-12">
    <div class="card dash-widget ctm-border-radius shadow-sm">
        <div class="card-body" style="padding: 0.65rem;">
            <div class="card-icon bg-warning" style="width: 40px;
    height: 40px;">
                <i class="fa fa-calendar-plus-o"></i>
            </div>
            <div class="card-right">
                <h4 class="card-title"><a style="color: #4ab9cf; font-weight: bold;">Assigned</a></h4>
                <p class="card-text"><?php echo $data['total']?></p>
            </div>
        </div>
    </div>
</div>
<?php 
$sql = mysqli_query($connect, "SELECT count(id) as total from rentedcars WHERE User = '".$_SESSION['userid']."' and Status = 'Completed'");
$data = mysqli_fetch_assoc($sql);
?>
<div class="col-xl-3 col-lg-3 col-sm-6 col-12">
    <div class="card dash-widget ctm-border-radius shadow-sm">
        <div class="card-body" style="padding: 0.65rem;">
            <div class="card-icon bg-success" style="width: 40px;
    height: 40px;">
                <i class="fa fa-calendar-check-o" aria-hidden="true"></i>
            </div>
            <div class="card-right">
                <h4 class="card-title"><a style="color: #4ab9cf; font-weight: bold;">Complete</a></h4>
                <p class="card-text"><?php echo $data['total']?></p>
            </div>
        </div>
    </div>
</div>


</div>
</div>

        <div class="row">
           
            <div class="col-xl-12 col-lg-12 col-md-12">
                
                
                <div class="ctm-border-radius shadow-sm card">
                    <div class="card-body">
                        <div class="table-responsive table-togglable table-hover" style="white-space: normal;">
                            <input type="button" class="dt-button" onclick="location.href='new-booking.php';" value="&#10133;Booking"/>
                            <table id="Booking" class="table table-striped table-bordered ">
    
        <!--<i class="fa fa-plus"></i>-->
        <!--<input type="button" class="float-right dt-button" onclick="location.href='new-booking.php';" value="&#10133;Booking"/>-->
    
                        
						<thead>
						<tr>
						  <!--<th class="text-center">Action</th>-->
						  <th class="text-center">Status</th>
						  <th class="text-center">Booking #</th>
						  <th class="text-center">Driver</th>
						  <th class="text-center">Booking Made on</th>
						  <th class="text-center">Booking Date</th>
						  <th class="text-center">Car</th>
						  <th class="text-center">Pickup</th>
						  <th class="text-center">Destination</th>
						  <th class="text-center">Customer</th>
						  <th class="text-center">Amount</th>
						  <th class="text-center">Payment</th>
						  <th class="text-center">Voucher Number</th>
						  <th class="text-center">Payment Reference</th>
						  <th class="text-center">Hotel Name</th>
						  <th class="text-center">Source</th>
						  
                          
						</tr>
						</thead>
						<tbody>
										<?php
										$sql = mysqli_query($connect, "SELECT rentedcars.*, cars.car_name AS car_title, 
                                        driver.driver_name as driver_name 
										FROM rentedcars 
										INNER JOIN cars ON cars.car_id = rentedcars.car_id
										LEFT JOIN driver ON driver.driver_id = rentedcars.driver_id
										WHERE rentedcars.user_id = $user_id
										ORDER BY rentedcars.booking_date DESC");
                                           
										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">-->
                                            <!--<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">
                                                <!-- <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["status"]=="Pending")
                                             echo 'style="color:red; font-weight:bold;">';
                                             else if ($data["status"]=="assigned")
                                             echo 'style="color:blue; font-weight:bold;" >';
                                             else
                                             echo 'style="color:green; font-weight: bold;" >';
                                            ?>
                                            (<?php
                                                echo $data["status"]
                                                ?>)</a>
                                                
                                            </td>
                                            
                                            <td class="text-center"> <?php echo date('d.m.Y H:i a', strtotime($data["booking_date"]));?>
                                            </td>
                                            
                                            <td class="text-center"> <?php echo date('d.m.Y H:i a', strtotime($data["rent_start_date"]));?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php echo $data["car_title"]?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php echo $data["pickup"]?>
                                            </td>
                                            
                                            <td class="text-center">
                                                <?php echo $data["Destination"]?>
                                            </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["total_amount"]?> AED</td>
                                            
                                            <td class="text-center"> <?php echo $data["PaymentMethod"]?> (<?php echo $data["PaymentStatus"]?>)</td>
                                            <td class="text-center"> <?php echo $data["voucher_number"]?></td>
                                            <td class="text-center"> <?php echo $data["PaymentReference"]?></td>
                                            <td class="text-center"> <?php echo $data["hotel_name"]?></td>
                                            <td class="text-center">
                                            <?php
                                            if($data["bookingsource"] == "User"){
                                                $sql_user = mysqli_query($connect,"select * from users where
                                                Id = '".$data["user_id"]."' ");
                                                $data_user = mysqli_fetch_assoc($sql_user);
                                                echo $data_user["Username"];?> (<?php echo $data["bookingsource"]?>)<?php } ?>
                                                </td>
                                        </tr>
										<?php }?>
										
                                    </tbody>
						</table>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
</div>


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

<?php include("scripts.php");?>
</body>
<script>
    $(document).ready(function() {
        
    });
</script>
</html>