<?php


include('../conn.php');
$page='Print Order Reciept';
include('../common/head.php');




if (isset($_GET['item'])) {

    $orderid=$_GET['item'];


    $sql7 = "SELECT * FROM `orders_details` WHERE orderid='$orderid'";
    $result7 = mysqli_query($conn,$sql7)or die( mysqli_error($conn));
    $row7=mysqli_fetch_array($result7) ;
    $data=$row7['orderid'];
    $customer_name=$row7['costomer_name'];
    $amount=$row7['amount'];
    $contact=$row7['contact'];
    $payment_method=$row7['payment_method'];
    $date=$row7['date'];
    $time=$row7['time'];
 
    $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];
 
 }

 
$sql1="SELECT * FROM currency ";
$result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
$row1=mysqli_fetch_array($result1) ;
$currency=$row1['curency'];


?>

   <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">

<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;
font-family: 'Roboto', sans-serif ! 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:18px;
  color:black !important;
    }

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

        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                <div class="invoice-title">
                        <div class="mb-1">
                           <h2  class="mb-1 ">GATPRO RESTAURANT</h2>
                        </div>
                        <div class="">
                            <p class="mb-1">Madina Fire stone</p>
                            <p><i class="uil uil-phone me-1"></i>0534648926 / 0540948579</p>
                            <p>Email: gatpros@gmail.com</p>
                            <p> www.gatpros.com</p>
                        </div>
                    </div>
                    <hr class="my-2">

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="">
                                <h5 style="font-size: 12px;" class=" mb-1">Billed To: <?php echo $name ?></h5>
                                <input type="hidden" name="name" value="<?php echo $name ?>">
                                <p style="font-size: 12px;">Phone number: <?php echo $number ?></p>
                                <input type="hidden" name="contact" value="<?php echo $number ?>">
                            </div>
                        </div>
                        <!-- end col -->
                        <div class="col-sm-12">
                            <div class=" text-sm-end">
                                <div class="mt-2">
                                    <h5 style="font-size: 12px;" class=" mb-1">Invoice Date:</h5>
                                    <p style="font-size: 12px;"><?php echo $date." ".$time ?></p>
                                    <p style="font-size: 12px;">Payment method: <?php echo $payment ?></p>
                                    <input type="hidden" name="time" value="<?php echo $time ?>">
                                    <input type="hidden" name="date" value="<?php echo $date ?>">
                                    <input type="hidden" name="by" value="<?php echo $by ?>">
                                </div>
                                <div class="mt-4">
                                    <h5 style="font-size: 12px;" class=" mb-1">Order No:</h5>
                                    <p>#<?php echo $ord?></p>
                                    <input type="hidden" name="order_id" value="<?php echo $order_id ?>">
                                    <input type="hidden" name="payment" value="<?php echo $payment ?>">
                                </div>
                            </div>
                        </div>
                        <!-- end col -->
                    </div>
                    <!-- end row -->
                    
                    <div class="py-2">
                        <h5 style="font-size: 12px;" class="">Order Summary</h5>
                        <div class="table-responsive">
                            <table  style="width:350px;font-size: 12px;" class="table align-middle table-nowrap table-centered mb-0">
                                <thead>
                                    <tr>
                                        <th >Item </th>
                                        <th>Qty</th>
                                        <th>Price</th>
                                        <th>Total</th>
                                    </tr>
                                </thead><!-- end thead -->
                                <tbody>
                                <?php


                     
$sql="select * from orders where orderid='$orderid'";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
    $data=$row['orderid'];
    $itme_name=$row['item_name'];
    $quantity=$row['quantity'];
    $price=$row['price'];
    $status=$row['status'];
    
    $total_item_price=$quantity* $price;   
    $real_id=substr($data,-2);
 $ord = sprintf('%03d',$real_id);

?>    
                                    <tr style="display:;">
                                        <td ><?php echo $itme_name ?></td>
                                        <td><b><?php echo $quantity ?></b></td>
                                        <td><b><?php echo $currency ?><?php echo number_format($price,2)?></b></td>
                                        <td><b><?php echo $currency ?><?php echo number_format($total_item_price,2)?></b></td>
                                    </tr>

                                    
                                    <?php }?>
                               
                                    <!-- 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];
                                 
                                      
                                 
                                 $dicount=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,2)?></b>
                                    </td>
                                    </tr>
                                    <!-- end tr -->
                                </tbody><!-- end tbody -->
                            </table><!-- end table -->
                            <?php include('recipt_footer.php') ?>
                        </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="../orders" class="btn btn-primary btn-sm">Back Home</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            </form>
        </div><!-- end col -->
     
    </div>
</div>
<script>
function myFunction() {
  var x = document.getElementById("mySelect").value;
  document.getElementById("demo").innerHTML = "Bill to: " + x;
}
</script> 
    