<?php session_start();
?>
<?php   include('conn.php');
$page='Dashboard Management';
include 'common/head.php'; ?>
<div id="main">

 <form class=" " method="post"action="submit_order.php">
 <?php
 
 $sql2="SELECT * FROM currency ";
 $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
 $row2=mysqli_fetch_array($result2) ;
$currency=$row2['curency'];
 $order_id='T'.date('ymdhi').mt_rand(10,100);
 $real_id=substr($order_id,-2);
 $ord = sprintf('%03d',$real_id);  
$total=0;
$discount=0;
$total_price=0;
if (!empty($_SESSION['cart'])) {
    foreach($_SESSION['cart'] as$key => $value) {
      $arr=count($_SESSION['cart']);
         $total=   $total + ($value['new_price'] * $value['quantity']);
         $total_price=  $total_price + ($value['price'] * $value['quantity']);

         $discount=$total_price-$total;
       $real_id= $value['orderid'];
$ord = sprintf('%03d',$real_id);
?>
 <div style="background-color: white; border-radius:20px;" class="cart-details   my-2">
 <div class="row  rounded-3 p-2 m-1 border-0 ">
                   <div class="col-5 p-0 col-sm-2">
                       <div class="blog-img position-relative overflow-hidden">
                           <img style="width: 40px;" class="img-cart " src="image/<?php echo $value['image'] ?>" alt="">
                          </div>
                   </div>
                   <div class="col-5  col-sm-8">
                       <p style="font-size: 12px;" class="tittle" class="mb-1"><?php echo $value['name']?>   </p>
               <h3 class="my-2">
                   <small  id="" class="align-top " style="font-size:15px; line-height: 1px; "><b><?php echo $currency?><?php echo number_format($value['price'])?></b> <span class="" style="font-size:small;">x</span><?php echo $value['quantity']?></small>
               </h3>
         

               <input type="hidden" name="food_name[]" value="<?php echo $value['name']?>">
                           <input type="hidden" name="quantity[]" value="<?php echo $value['quantity']?>">
                           <input type="hidden" name="item_total[]" value="<?php echo $pay_item?>">
                           <input type="hidden" name="price[]" value="<?php echo $value['price']?>">
                           <input type="hidden" name="new_price[]" value="<?php echo $value['new_price']?>">
                           <input type="hidden" name="item_id[]" value="<?php echo $value['id']?>">
                           <input type="hidden" name="location[]" value="<?php echo $value['location']?>">
                           <input type="hidden" name="dates[]" value="<?php echo $value['date']?>">
                           <input type="hidden" name="orderid[]" value="<?php echo $order_id?>">
                           <input  type="hidden" name="note[]" value="<?php echo $value['note']?>  ">

                   </div>
                   <div class="col-2 col-sm-2 text-center">
                       <a class=""  style="font-size: 30px;" href="index.php?action=remove&id=<?=$value['id']?>"><i class="bi bi-trash text-danger   "></i></a>
                   </div>
               </div>
 </div>
 <?php }}?>



 <div style="background-color: white; border-radius:20px;" class="p-2 text-dark ">
               <p class="my-1">Items Total:  <span style="float: right;font-size:20px; line-height: 2px;"><b><?php echo $currency?><?php echo number_format($total)?></b></span></p>
               <p class="my-1">Discount:  <span style="float: right;font-size:20px; line-height: 2px;"><b><?php echo number_format($discount)?></b></span></p>
               <p class="my-1">Subtotal:  <span style="float: right;font-size:20px; line-height: 2px;"><b><?php echo $currency?><?php echo number_format($total)?></b></span></p>
               <input type="hidden" name="total" value="<?php echo $total?>">
                       <input type="hidden" name="discount" value="<?php echo $discount?>">
                      <input type="hidden" name="order_id" value="<?php echo $order_id?>">
                      <input type="hidden" name="order_type" value="0">
                      <input type="hidden" name="by" value="<?php echo $id_user?>">
                      <input type="hidden" name="time" value="<?php echo date("G:i")?>">
           </div>
           <a  href="carts" style="background-color:#982BAD;" id="payBtn"  class="btn  btn-block  text-white my-2">Complete Order</a>
           </form>
 </div>
</div>