
<?php 
include('../conn.php');
include('../common/head.php');




if(isset($_POST['submit'])){
 
    $name=addslashes($_POST['name']);
     $number=$_POST['number'];
     $id_number=$_POST['id_number'];
     $e_number=$_POST['e_number'];
    $checkin=$_POST['checkin'];
     $checkout=$_POST['checkout'];
     $room=$_POST['room'];
     $date=$_POST['date'];
     $orderid=$_POST['orderid'];
     $by=$_POST['by'];
     $time=date("h:ia");
     $cat  = $room;
     $explode_cat = explode(" ", $cat);
$room_cat=$explode_cat[1];
      // piece1

     $charge=0;
     $deluxe='Deluxe';
     $normal='Normal';
     $executive='Executive';
     $standard='Standard';


     $string = str_replace(' ','',$room_cat);
    




if ($string==$deluxe) {
    $charge=350;
}
elseif ($string==$normal) {
    $charge=200;
}
elseif ($string==$executive) {
    $charge=400;
}
elseif ($string==$standard) {
    $charge=300;
}


$diff = abs(strtotime($checkout) - strtotime($checkin));

$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

if ($days==0) {
    $days=1;
 }
$amount=$charge*$days;



$real_id=substr($orderid,-2);
$ord = sprintf('%03d',$real_id);  


$sql="select * from tax where status='1'";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
$data=$row['id'];
$tax=$row['tax'];
$percent=$row['percent']; 
}
$sql7="SELECT  sum(percent) FROM tax  WHERE status='1'";
  $result7 = mysqli_query($conn,$sql7)or die( mysqli_error($conn));
  $row7=mysqli_fetch_array($result7) ;
  
      $total_tax= $row7[0];

$total_tax_payable=$amount*$total_tax/100;
$amount_payable=$amount+$total_tax_payable;
   
}
$sql1="SELECT * FROM currency ";
$result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
$row1=mysqli_fetch_array($result1) ;
$currency=$row1['curency'];
?>
      
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.1/css/all.min.css" integrity="sha256-2XFplPlrFClt0bIdPgpz8H7ojnk10H69xRqd9+uTShA=" crossorigin="anonymous" />
<style>
    body{margin-top:20px;
background-color:#eee;
color:black !important;
}

.card {
    box-shadow: 0 20px 27px 0 rgb(0 0 0 / 5%);
}
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    word-wrap: break-word;
    background-color: #fff;
    background-clip: border-box;
    border: 0 solid rgba(0,0,0,.125);
    border-radius: 1rem;}



        
        table, th, td {

  border-collapse: collapse;
  font-size:16px;
  color:black !important;
    }

 
</style>
<div class="container">
<div class="row">
        <form action="hotel_booking_confirmed.php" method="post">

        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                  

                    <hr class="my-4">

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="">
                                <h5 class="font-size-16 mb-1">Billed To:</h5>
                                <h5 class="font-size-15 mb-1"><?php echo $name ?></h5>
                                <input type="hidden" name="name" value="<?php echo $name ?>">
                                <p><?php echo $number ?></p>
                                <input type="hidden" name="number" value="<?php echo $number ?>">
                            </div>
                        </div>
                        <!-- end col -->
                        <div class="col-sm-12">
                            <div class=" text-sm-end">
                                <div class="mt-4">
                                    <h5 class="font-size-15 mb-1">Invoice Date:</h5>
                                    <p><?php echo $date." ".$time ?></p>
                                    <input type="hidden" name="time" value="<?php echo $time ?>">
                                    <input type="hidden" name="datein" value="<?php echo $date ?>">
                                    <input type="hidden" name="by" value="<?php echo $by ?>">
                                    
                                </div>
                                <div class="mt-4">
                                    <h5 class="font-size-15 mb-1">Order No:</h5>
                                    <p>#<?php echo $ord?></p>
                                    <input type="hidden" name="orderid" value="<?php echo $orderid ?>">
                                </div>
                            </div>
                        </div>
                        <!-- end col -->
                    </div>
                    <!-- end row -->
                    
                    <div class="py-2">
                        <h5 class="font-size-15">Order Summary</h5>
                        <div class="table-responsive">
                            <table  style="width:300px" class="table align-middle table-nowrap table-centered mb-0">
                                <thead>
                                    <tr>
                                        <th >No.</th>
                                        <th >Room </th>
                                        <th>Days</th>
                                        <th>Cost</th>
                                    </tr>
                                </thead><!-- end thead -->
                                <tbody>
                                    <tr style="display:;">
                                        <td  scope="row">01</td>
                                        <td ><?php echo $room?></td>
                                        <td><?php echo $days?></td>
                                        <td><?php echo $currency ?><?php echo number_format($amount,2)?></td>
                                        <input type="hidden" name="room" value="<?php echo $room ?>">
                                        <input type="hidden" name="days" value="<?php echo $days ?>">
                                        <input type="hidden" name="id_number" value="<?php echo $id_number ?>">
                                        <input type="hidden" name="e_number" value="<?php echo $e_number ?>">
                                        <input type="hidden" name="checkin" value="<?php echo $checkin ?>">
                                        <input type="hidden" name="checkout" value="<?php echo $checkout ?>">
                                        <input type="hidden" name="orderid" value="<?php echo $orderid ?>">
                                        <input type="hidden" name="amount" value="<?php echo $amount ?>">
                                    </tr>
                                  
                                    <!-- end tr -->

                                    <!-- end tr -->
                                    <?php
                                 
                                 $sql12="select * from tax where status='1'";
                                 $result12 = mysqli_query($conn,$sql12)or die( mysqli_error($conn));
                                 while ($row12=mysqli_fetch_array($result12)) {
                                 $data=$row12['id'];
                                 $tax=$row12['tax'];
                                 $percent=$row12['percent']; 
                                 
                                 $sql10="SELECT  sum(percent) FROM tax  WHERE status='1'";
                                   $result10 = mysqli_query($conn,$sql10)or die( mysqli_error($conn));
                                   $row10=mysqli_fetch_array($result10) ;
                                   
                                       $total_tax= $row10[0];
                                 
                                
                                 
                                 
                                 
                                 
                                   ?>
                                                     
                                                     
                                                        
                                 
                                                      
                                                              
                                                                     <!-- end tr -->
                                                                     <tr>
                                                                         <th scope="row" colspan="2" class="border-0 ">
                                                                         <?php  echo $tax?> </th>
                                                                         <td class="border-0 "><?php echo  $percent ?>%</td>
                                                                     </tr>
                                 
                                                                     <?php }?>
                                    <!-- end tr -->
                                    <tr>
                                        <th scope="row" colspan="2" class="border-0 ">Total</th>
                                        <td class="border-0 "><b class="m-0 fw-semibold"><?php echo $currency ?><?php echo number_format($amount_payable,2)?></b></td>
                                        <input type="hidden" name="total" value="<?php echo $amount_payable;?>" >
                                    </tr>
                                    <!-- end tr -->
                                </tbody><!-- end tbody -->
                            </table><!-- end table -->
                        </div><!-- end table responsive -->
                        <div class="d-print-none mt-4">
                        <div class="pament-button text-center">
              
              <select class="form-control m-2 " name="payment"  id="mySelect1" onchange="myFunction1()">
                 <option value="nan">Select Payment Method</option>
                 <option value="Cash">Cash</option>
                 <option value="Momo">Momo</option>
            </select>
                            <div class="float-end">
                                
                                <button class="btn btn-success btn-sm "  name="submit">Confirm payment</button>
                                <a href="../hotel" class="btn btn-primary btn-sm">Back Home</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            </form>
        </div><!-- end col -->
     
    </div>
</div>

    