<?php


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




if(isset($_POST['submit'])){
 
    $name=addslashes($_POST['name']);
    $number=$_POST['contact'];
    $facility=$_POST['facility'];
    $orderid=$_POST['orderid'];
    $start=$_POST['start'];
    $day=$_POST['day'];
    $amount=$_POST['amount'];
    $total=$_POST['total'];
    $purpose=$_POST['purpose'];
    $date=$_POST['datein'];
    $event_date=$_POST['event_date'];
    $payment=$_POST['payment'];
    $time=$_POST['time'];
    $by=$_POST['by'];

echo $total;
echo $amount;
echo $day;


    if ($payment=='nun') {
        echo"<script>alert('Please Select payment method'); window.location.href='../facility'</script>";
       }
       else {
    $sql = "SELECT `number` FROM `customers` WHERE `number`='".$number."'";
    $result = $conn->query($sql);
    
    if($result->num_rows >= 1) {
     
    } else {
       // Image db insert sql
       $sql = "INSERT INTO `customers`(`fname`, `number`, `date`,`by`) VALUES ('$name','$number','$date','$by')";
       if(mysqli_query($conn,$sql)){


       }
       else{
         echo 'Error: '.mysqli_error($conn);
       }

    }
 

   
$sql = "SELECT `orderid` FROM `facility_rental` WHERE `orderid`='".$orderid."'";
$result = $conn->query($sql);

if($result->num_rows >= 1) {
    echo"<script>alert('You can not Submit one order times'); window.location.href='../facility'</script>";
 
} else {


    $sql1 = "INSERT INTO `facility_rental`(  `orderid`, `customer_name`, `number`, `name`, `days`, `amount`,`payment_method`, `purpose`, `date`, `event_date`, `time`, `by` ) VALUES ('$orderid','$name','$number','$facility','$day','$amount','$payment','$purpose','$date','$event_date','$time' ,'$by')";
    if(mysqli_query($conn,$sql1)){ 
        echo"<script>alert('Print reciept'); window.location.href='../print/facility_print.php?item=$orderid'</script>";
} 
else{
   echo 'Error: '.mysqli_error($conn);
 }
}

       }
}

$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">

        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <div class="invoice-title">
                     
                        <div class="">
                            <p class="mb-1">The Kamb  Restaurant 189, Accra awoshi</p>
                            <p><i class="uil uil-phone me-1"></i> 012-345-6789</p>
                        </div>
                    </div>

                    <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>
                                <p><?php echo $number ?></p>
                                <h5 class="font-size-15 mb-1">Payment method: <?php echo $payment ?></h5>
                            </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>
                                </div>
                                <div class="mt-4">
                                    <h5 class="font-size-15 mb-1">Order No:</h5>
                                    <p>#<?php echo $ord?></p>
                                </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 >Facility </th>
                                        <th>Days</th>
                                        <th>Price</th>
                                    </tr>
                                </thead><!-- end thead -->
                                <tbody>
                                <tr style="display:;">
                                        <td ><?php echo $facility?></td>
                                        <td><?php echo $days?></td>
                                        <td><?php echo $currency ?><?php echo number_format($amount,2)?></td>
                                        <input type="hidden" name="facility" value="<?php echo $facility ?>">
                                        <input type="hidden" name="day" value="<?php echo $days ?>">
                                        <input type="hidden" name="purpose" value="<?php echo $purpose ?>">
                                        <input type="hidden" name="event_date" value="<?php echo $event_date ?>">
                                      
                                    </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>
                                    </tr>
                                    <!-- end tr -->
                                </tbody><!-- end tbody -->
                            </table><!-- end table -->
                            <div class="reciept-title ">
                       <p class="" style="font-size: 12px;">Thank you for Visiting TheKamb  Restaurant <br> Visit thekambhotel.com/restaurant to place online orders</p>
                   </div>
                        </div>
                        <!-- end table responsive -->
                        <div class="d-print-none mt-4">
                        <div class="pament-button text-center">
              
                            <div class="float-end">
                                <a href="javascript:window.print()" class="btn btn-success me-1"><i class="fa fa-print"></i></a>
                                <a href="#" class="btn btn-primary btn-sm">Back Home</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            

        </div><!-- end col -->
     
    </div>
</div>
