<?php include("cn.php");
include("info.php");?>
<?php $title = "Booking Details";
$id = $_REQUEST["id"];
$sql = mysqli_query($connect, "SELECT rentedcars.*, /*cars.*,*/ cars.car_name AS car_title 
									from rentedcars 
										inner join cars ON cars.car_id = rentedcars.car_id
										where rentedcars.id = '$id'");
$data = mysqli_fetch_assoc($sql);
?>
<!DOCTYPE html>
<html lang="en">

<?php include("head-tag.php");?>

<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-blue"><span class="lnr lnr-home mr-3"></span>Home</a></li>
<li class="breadcrumb-item d-inline-block active">Booking Detail</li>
</ol>
<h4 class="text-dark">Booking Detail</h4>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="user-card card shadow-sm bg-white text-center ctm-border-radius">
<div class="user-info card-body">
<!--<div class="user-avatar mb-4">-->
<!--<img src="<?php echo $data["Image"];?>" alt="User Avatar" class="img-fluid" width="200">-->
<!--</div>-->
<div class="user-details">
<p class="text-left">Car: <span class="text-primary"><?php echo $data["car_title"];?></span></p>
<p class="text-left">Booking No. <span class="text-primary"><?php echo $data["BookingNumber"];?></span></p>
<p class="text-left">Status: <b class="<?php if($data['PaymentStatus']=="Un-paid"){ echo "text-danger";}else{ echo "text-success";}?>"><?php echo $data["PaymentStatus"];?> (<?php echo $data["status"];?>)</b></p>
<p class="text-left">Request Date: <span class="text-primary"><?php echo date("d.m.Y H:i",strtotime($data["booking_date"]));?></span></p>
<!--<p class="text-left">Request Date: <span class="text-primary"><?php echo date("d.m.Y",strtotime($data["booking_date"]));?> </span></p>-->
<?php if($data['driver_id']==0){
    ?>
    


<!-- End Assign Car Button -->

<!-- Assign Driver Button -->

<button class="btn btn-primary btn-block" type="button" data-toggle="modal" data-target="#add-driver">Assign Driver</button>

<!-- End Assign Driver Button -->



<?php
} 
if($data['PaymentStatus']=="Un-paid" || $data['PaymentStatus']=="By Hotel" || $data['PaymentStatus']=="By Cash" || $data['PaymentStatus']=="By Credit Card" || $data['PaymentStatus']=="By Room")
{?>
    <a class="btn btn-success btn-block" href="ajax/confirm-booking.php?id=<?php echo $id?>">Mark as Paid / Confirmed</a>
    <a class="btn btn-danger btn-block" href="ajax/cancel-booking.php?id=<?php echo $id?>">Cancel Booking</a>
<?php }?>
<!-- Cancel/ Paid Booking Button -->

<?php if($data['ConfirmDate']!=""){?>
<p class="text-left"><?php echo $data['status']?> on: <span class="text-primary"><?php echo date("d.m.Y H:i",strtotime($data["ConfirmDate"]));?></span></p>
<?php }?>

</div>
</div>
</div>
</aside>
</div>
<div class="col-xl-9 col-lg-8  col-md-12">
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12 d-flex">
<div class="card flex-fill ctm-border-radius shadow-sm">
<div class="card-header">
<h4 class="card-title mb-0 mt-2">  Booking Detail <?php { echo '
<a href="./print2.php?id='.$data['BookingNumber'].'" class="btn btn-theme button-1 text-white ctm-border-radius lnr lnr-printer float-right ml-3"style="background-color: green;">Booking</a>
<a href="./print5.php?id='.$data['BookingNumber'].'" class="btn btn-theme button-1 text-white ctm-border-radius  lnr lnr-printer float-right ml-3">Receipt</a>
<a href="./print1.php?id='.$data['BookingNumber'].'" class="btn btn-danger text-white ctm-border-radius lnr lnr-printer float-right">Invoice</a>             
'; }?>

</h4>    

</div>
<div class="card-body ">
    <div class="row">
    <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Car: </span><br>
            <?php echo $data["car_title"];?></p>
        </div>
        
         <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Booking Charges: </span><br>
            <?php echo $data["fare"];?> AED/<?php echo $data["charge_type"];?></p>
            <!--<?php echo $data["Amount"];?> AED</p>-->
            <?php if($data["bookingsource"] == "Guest"){ ?>
                
                    <button class="btn btn-primary" style="background-color: #898f96;" type="button" data-toggle="modal" data-target="#edit-amount">Edit</button>
                    
            <?php } ?>
        </div>

        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Booking Date: </span><br><?php echo date("d.m.Y",strtotime($data["rent_start_date"]));?> (<?php echo date('h:i:sa', strtotime($data["rent_start_date"]));?>)
            </p>
        </div>
        
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Payment Method: </span><br>CASH<?php echo $data["PaymentMethod"];?></p>
        </div>
        
        <?php //if($data['Type']=="route"){?>
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Pick-up: </span><br>
            <?php 
                // $p_sql = mysqli_query($connect,"select * from emirates where Id = '".$data['PickUp']."'");
                // $p_data = mysqli_fetch_assoc($p_sql);
                // $pickup_name = $p_data["Title"];
                
                $pickup_name = $data["pickup"];

                echo $pickup_name;?></p>
        </div>
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Destination: </span><br>
             <?php 
            //  $d_sql = mysqli_query($connect,"select * from emirates where Id = '".$data['Destination']."'");
            //  $d_data = mysqli_fetch_assoc($d_sql);
            //  $destination_name = $d_data["Title"];
             
             $destination_name = $data["Destination"];
             
            echo $destination_name;?>
            </p>
        </div>
        <!--<?php //} else {?>-->
        <!--<div class="col-md-6 col-sm-12 col-xs-12">-->
        <!--    <p class="card-text mb-1"><span class="text-primary">No. of Days: </span><br><?php echo $data["Days"];?></p>-->
        <!--</div>-->
        <?php //}?>
        
      
    </div>
</div>
</div>
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-xs-12 d-flex">
<div class="card flex-fill  ctm-border-radius shadow-sm">
<div class="card-header">
<h4 class="card-title mb-0">Customer Detail
</h4>
</div>

<?php
$customer = $data["AppUser"];
$query = "SELECT * FROM app_users WHERE id = '$customer'";
$sql_customer = mysqli_query($connect,$query);
$data_customer = mysqli_fetch_assoc($sql_customer);
?>
<div class="card-body">
<div class="row">
     <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Name: </span><br><?php echo $data_customer["Name"];?></p>
        </div>
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Email Address: </span><br><?php echo $data_customer["Email"];?></p>
        </div>
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Mobile Contact: </span><br><?php echo $data_customer["Phone"];?></p>
        </div>
        <!--<div class="col-md-12 col-sm-12 col-xs-12">-->
        <!--    <p class="card-text mb-1"><span class="text-primary">Customer Notes: </span><br><?php echo $data["Notes"];?></p>-->
        <!--</div>-->
    </div>
</div>
</div>
</div>

<?php if($data['driver_id']!=0){

$sql_driver = mysqli_query($connect,"SELECT driver.*, app_users.*, app_users.email AS email  from driver left join app_users on driver.driver_id = app_users.driverid
WHERE driver.driver_id='".$data["driver_id"]."'");
$data_driver = mysqli_fetch_assoc($sql_driver);
?>
  <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-xs-12 d-flex">
<div class="card flex-fill  ctm-border-radius shadow-sm">
<div class="card-header">
    
<h4 class="card-title mb-0">Driver
</h4>
</div>
<div class="card-body">
<div class="row">
     <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Name: </span><br><?php echo $data_driver["driver_name"];?></p>
        </div>
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Mobile Contact: </span><br><?php echo $data_driver["driver_phone"];?></p>
        </div>
        <div class="col-md-6 col-sm-12 col-xs-12">
            <p class="card-text mb-1"><span class="text-primary">Email Address: </span><br><?php echo $data_driver["email"];?></p>
        </div>
    </div>
</div>
</div>
</div>  
<?php }?>

</div>
</div>
</div>
</div>
</div>

</div>
<div class="modal fade" id="edit-amount">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body">
                <form method = "post" action="ajax/edit-amount.php" enctype='multipart/form-data'>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title mb-3">Edit Amount</h4>
                <div class="row">
                    <input type="hidden" name="booking" value="<?php echo $id?>">
                    
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <div class="input-group mb-3">
                                <input type="text" name="amount" placeholder="Amount" class="form-control" aria-label="Default">
                            </div>
                        </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">Change</button>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="add-driver">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body">
                <form method = "post" action="ajax/assign-driver.php" enctype='multipart/form-data'>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title mb-3">Assign Driver</h4>
                <div class="row">
                    <input type="hidden" name="booking" value="<?php echo $id?>">
                    
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <select class="form-control select" name="driver">
                                <option value="">-- Select Driver --</option>
                                <?php if($driveravailcheck==1){
                                $sql = mysqli_query($connect, "select driver.* 
								from driver WHERE `driver_availability` = 'yes'");
                                }
                                else{
                                    $sql = mysqli_query($connect, "select driver.* 
								from driver");
                                    
                                }
								
								while($data_m = mysqli_fetch_assoc($sql)){?>
									<option value="<?php echo $data_m["driver_id"]?>"><?php echo $data_m['driver_name'];?></option>
								<?php }?>
                            </select>
                        </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">Assign</button>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="sidebar-overlay" id="sidebar_overlay"></div>

<?php include("scripts.php");?>

</body>

</html>