<?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="row">
                  <?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)){
                         
                         $sql1 = "SELECT * FROM cars WHERE car_id='".$data['car_id']."'";
                                                       $result1 = mysqli_query($connect,$sql1);
                                                       $url="../admin/";
                                                       $row1 = mysqli_fetch_assoc($result1);
                                                       $car_img = $url.$row1['car_img'];
                     
                                                           $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"];
                     
                                                           $customer = $data["AppUser"];
                                                           $query = "SELECT * FROM app_users WHERE id = '$customer'";
                                                           $sql_1 = mysqli_query($connect,$query);
                                                           $data_1 = mysqli_fetch_assoc($sql_1);
                                                           ?>
                  <div class="col-xl-6 col-lg-6 col-md-6 d-flex">
                     <div class="card ctm-border-radius shadow-sm flex-fill">
                        <div class="card-header">
                           <table width="100%">
                                   <th colspan="2">
                                     <h4 class="card-title mb-0"><?php echo $data['BookingNumber'].' ::: '.date('d-m-Y H:i:s',strtotime($data['booking_date']));?></h4>
                                   </th>
                              <tr>
                                 <td width="35%">
                                    <img src="<?php echo $car_img ?>" alt="Car" class="img-fluid"></span>
                                 </td>
                                 <td width="65%">
                                     <?php 
                                       // echo '<br>'.$data["PaymentStatus"]; 
                                       if($_SESSION['driverid']>0)
                                       echo '<br> Customer: '.$data_1["Name"];
                                       else
                                       echo '<br>Captain: '.$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;" >';
                                       echo '('.$data["status"].')';
                                       echo ' - '.$data["PaymentStatus"]
                                       ?></a>
                                 </td>
                              </tr>
                           </table>
                           <?php //if ($data['status']=="Completed" && !$data['PaymentStatus']=="Un-paid") { 
                              if (!($data["PaymentStatus"]=="Un-paid")) { 
                                  echo '
                             <a href="./print2.php?id='.$data['BookingNumber'].'" class="btn btn-theme button-1 text-white ctm-border-radius lnr lnr-printer"style="background-color: green;  border-bottom: 0px;">Booking</a>
                            <a href="./print1.php?id='.$data["BookingNumber"].'" class="btn btn-theme button-1 text-white ctm-border-radius  lnr lnr-printer" style="background-color: red; border-bottom: 0px;">Invoice
                              <i class="fa fa-detail" style="font-size:24px;color:white" aria-hidden="true"></i></a> 
                              <a href="./print5.php?id='.$data["BookingNumber"].'" class="btn btn-theme button-1 text-white ctm-border-radius 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>
                              ';
                              }
                              ?>
                        </div>
                        <!--<div class="card-body">-->
                        <!--   <p class="card-text" align="center">-->
                        <?php
                           //  echo '<b>'
                           //  .$data["pickup"]
                           //  .'<br/>--- TO ---<br/>'
                           //  .$data["Destination"];
                            ?>
                        <!--</p>-->
                     </div>
                  </div>
<?php }?>
               </div>
            </div>
         </div>
      </div>
      <!--<div class="sidebar-overlay" id="sidebar_overlay"></div>-->
      <?php include("scripts.php");?>
   </body>
</html>