<?php include("cn.php");?>
<?php $title = "Bookings";?>
<!DOCTYPE html>
<html lang="en">
<?php include("head-tag.php");
$customer = $_SESSION['userid'];

$driver = $query = $query1= "";
if($_SESSION['driverid']>0){
    $driver = $_SESSION['driverid'];
    $query = ' `driver_id`='.$driver;
    $query1 = ' rentedcars.driver_id=\''.$driver.'\'';
} else
{
    $query = ' `AppUser`='.$customer;
    $query1 = ' rentedcars.AppUser=\''.$customer.'\'';
}
$sql = 'SELECT count(*) as total from rentedcars WHERE '.$query;
$sql = mysqli_query($connect, $sql);
$data = mysqli_fetch_assoc($sql);

?>
<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 = 'SELECT count(id) as total from rentedcars WHERE '.$query;
$sql = mysqli_query($connect, $sql);
// $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 = 'SELECT count(id) as total from rentedcars  WHERE Status = '."'Pending' AND" .$query;
$sql = mysqli_query($connect, $sql);
$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 = 'SELECT count(id) as total from rentedcars  WHERE Status = '."'assigned' AND" .$query;
$sql = mysqli_query($connect, $sql);
$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 = 'SELECT count(id) as total from rentedcars  WHERE Status = '."'Completed' AND" .$query;
$sql = mysqli_query($connect, $sql);
$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="card shadow-sm ctm-border-radius">
                    <div class="card-body">
                        <h4 class="card-title mb-0 mt-2"><?php echo $data["total"]?> Bookings
                        </h4>
                    </div>
                </div>-->
                
                <div class="ctm-border-radius shadow-sm card">
                    <div class="card-body">
                         <div class="table-responsive table-togglable table-hover" style="white-space: normal;">
                            <table id="Booking" class="table table-striped table-bordered ">
						<thead>
						<tr>
						  <!--<th class="text-center">Action</th>-->
						  <th class="text-center">Action</th>
						  <th class="text-center">Booking #</th>
						  <th class="text-center">Driver</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">source</th>
						  
                          
						</tr>
						</thead>
						<tbody>
										<?php
										
										$sql = '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 '.$query1.'
										ORDER BY rentedcars.rent_start_date';
										
										$sql = mysqli_query($connect, $sql);
                                           
										while($data = mysqli_fetch_assoc($sql)){
                                            ?>
											<tr>
                                             <td class="text-center">
                                             <!--<a href="<?php echo $companyweb;?>/booking/payonline/PayTabs.php?id=<?php echo $data["BookingNumber"]?>&amount=<?php echo $data["total_amount"]?>" 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>-->
                                             <!--<a href="PayOnline/ex_1_verify_info.php" 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>-->
                            <?php //if ($data['status']=="Completed" && !$data['PaymentStatus']=="Un-paid") { 
                            if (!($data["PaymentStatus"]=="Un-paid")) { 
                                echo '
                            <a href="./print1.php?id='.$data["BookingNumber"].'" class="btn btn-theme button-1 text-white ctm-border-radius mt-4 lnr lnr-printer" style="background-color: green; border-bottom: 0px;">Invoice
                            <i class="fa fa-detail" style="font-size:24px;color:white" aria-hidden="true"></i></a><br/>
                            <a href="./print5.php?id='.$data["BookingNumber"].'" class="btn btn-theme button-1 text-white ctm-border-radius mt-4 lnr lnr-printer" style="background-color: blue; border-bottom: 0px;">Receipt
                            <i class="fa fa-detail" style="font-size:24px;color:white" aria-hidden="true"></i></a>
                            ';
                            } 
                            else {
                            if (!($_SESSION['driverid']>0) && $data["PaymentStatus"]=="Un-paid" && $data["status"]=="Completed" )
                            {
                            echo '
                            <a href="checkout.php?id='.$data["BookingNumber"].'" class="btn  text-white btn-sm float-center" style="background-color: green; border-bottom: 0px;">Pay Now 
                            <i class="fa fa-credit-card" style="font-size:24px;color:white" aria-hidden="true"></i></a>
                            <br/>';
                            }
                            echo '
                            <a href="./bookingdetail.php?id='.$data['BookingNumber'].'" class="btn btn-theme button-1 text-white ctm-border-radius mt-4 lnr lnr-eye" style="background-color: red; border-bottom: 0px;"> Booking Detail
                            </a>
                            ';
                            }
                            ?>
                                             </td>
                                             
                                             <td class="text-center">
                                                <h2 class="ml-2"><a bookingdetail.php?id="<?php echo $data['BookingNumber']?>"><?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', strtotime($data["rent_start_date"]));?>
                                            <?php echo date('h:i:sa', 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">AED. <?php echo $data["total_amount"]?>.00</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 }?>
										
                                    </tbody>
						</table>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
</div>


</div>
<div class="modal fade" id="add-car">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body">
                <form method = "post" action="ajax/save-car.php" enctype='multipart/form-data'>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title mb-3">Add Car</h4>
                <div class="row">
                    <div class="col-md-6 col-sm-12 col-xs-12">
						<div class="form-group">
							<input type="file" name="photo" id="photo" class="dropify" data-height="220"
							data-allowed-file-extensions='["jpg", "png", "jpeg"]'/>
						</div>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                         <input type="text" class="form-control " placeholder="Name of Car"  name="title" value="<?php echo $data['Title']?>" required/>
                        </div>
                        <div class="form-group">
                            <select class="form-control select" name="brand">
                                <option value="">-- Select Brand --</option>
                                <?php $sql = mysqli_query($connect, "select brands.* 
								from brands");
								while($data_m = mysqli_fetch_assoc($sql)){?>
									<option value="<?php echo $data_m["Id"]?>"><?php echo $data_m['Title'];?></option>
								<?php }?>
                            </select>
                        </div>
                        
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Model" name="model" value="<?php echo $data['Model']?>" />
                        </div>
                        <div class="form-group">
                            <input class="form-control" name="rate" type="text" placeholder="Rate Per Day" value="<?php echo $data['Rate']?>" />
                        </div>
                    </div>
                    
                </div>
                <button type="button" class="btn btn-danger float-right ml-3 ctm-border-radius" data-dismiss="modal">Cancel</button>
                <button type="submit" class="btn btn-theme  button-1 text-white ctm-border-radius float-right">Save</button>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="sidebar-overlay" id="sidebar_overlay"></div>

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