<!DOCTYPE html>
<html lang = "en">
<head>
<?php   include('conn.php');
$page='Track Orders';
include 'common/head_online.php'; ?>
 
</head>





<body>
<div  class="container p-0 ">
<!---side nav bar end-->
<?php include("common/tittle_online.php")?>

 <div class="card container m-0 ">
      <h4 class="text-center p-2">Order History</h4>
      <hr>
        <div class="row py-2">

        <div class="col-sm-12">
            <div class="orders">
            <div class="row">
 
            
            <?php


    # code...



$sql2="SELECT * FROM currency ";
$result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
$row2=mysqli_fetch_array($result2) ;
$currency=$row2['curency'];


if (!isset($_SESSION['number'])) {
    $number= '0000'; 
}
else {
    $number= $_SESSION['number'];
    
  
}

$sql="select * from orders_details where contact='$number' order by id desc";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
 $i=0;
while ($row=mysqli_fetch_array($result)) {
 $data=$row['orderid'];
   $customer_name=$row['costomer_name'];
   $total=$row['amount'];
   $status=$row['status'];
   $order_type=$row['order_type'];
   $date=$row['date'];
   $time=$row['time'];
   $payment_status=$row['payment_status'];
   $delivery_status=$row['delivery_status'];
if ($order_type==1) {
 $order_type='Online Order';
}
else{
  $order_type='In Store Order';
}

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

 
 $dat=$data;

          

          
 $text='';
 $text_payment='';


 if ($payment_status==='1') {
    $text_payment='Payment Confirmed';
    $read_payment='badge-success';
  }
  else{
    $text_payment='Confirming payment';
    $read_payment='badge-secondary';
  }

 if ($status==1 && $delivery_status==0) {
   $text='Ready for delivery';
   $read='badge-info';
   $de='deactivate';
   $sta=0;
 }
elseif ($status==0 && $delivery_status==0) {
    $text='Cocking';
    $read='badge-primary';
}
elseif ($status==2 && $delivery_status==0) {
    $text='Cancelled';
    $read='badge-warning';
}
elseif ($status==='1'&& $delivery_status=1) {
  $text='Delivery Completed';
  $read='badge-success';
}
$link="print/order_print.php?item=$data";

$payment_link="online_payment?item=".urlencode(base64_encode($data));
$i++;
?>
  <div class="col-xl-6 mb-4">
    <div class="card">
      <div class="card-body">
        <div class="d-flex justify-content-between align-items-center">
          <div class="d-flex align-items-center">
       
            <div class="ms-3">
              <p class="fw-bold mb-1">#<?php echo $ord?></p>
              <p class="text-muted mb-0"><?php echo $date ." ". date('h:i A', strtotime($time))?></p>
            </div>
          </div>
        </div>

        <div class="info m-2 d-flex justify-content-between">
        <span class="badge rounded-pill <?php echo $read_payment?> p-2"
            ><a class="text-light" href="<?=$payment_link?>"> <?php echo $text_payment?></span
          ></a><span class="badge rounded-pill <?php echo $read?> p-2"
            ><?php echo $text?> 
            
            </span
          >
        </div>

        <ol class="list-group list-group-light list-group-numbered">
            <?php
             $sql3 = "SELECT * FROM orders WHERE orderid ='$data'";  
             $result3 = mysqli_query($conn, $sql3);  
             while ($row3=mysqli_fetch_array($result3)){
               $data=$row3['orderid'];
               $itme_name=$row3['item_name'];
               $itme_id=$row3['item_id'];
               $quantity=$row3['quantity'];
               $price=$row3['price'];
               $status=$row3['status'];
            ?>
  <li class="list-group-item d-flex justify-content-between align-items-start">
    <div class="ms-2  text-muted me-auto">
      <?php echo $itme_name ." ". 'X' ." ". $quantity?>
    </div>
    <span class="badge badge-secondary rounded-pill p-2"><?php echo $currency ."". number_format($price,2) ?></span>
  </li>
<?php }?>
<div class="b d-flex justify-content-between align-items-end m-2">
  <a href="feedback?i=<?php echo base64_encode($data);?>" class="btn btn-outline-info" >Feedback</a>
<span class="badge badge-info rounded-pill p-2 mt-2"><?php echo $currency ."". number_format($total,2) ?></span>
</div>
</ol>
      </div>

    </div>
  </div>
<?php }?>
<?php
if($i==0){
    echo "  <h4> You have no orders !!!</h4>";
}

?>
</div>
            </div>

        
          
        </div>
          
        </div>
    </div>

 
<!-- Ads Start -->

<div class="container-fluid py-0 mb-4 wow fadeInUp" data-wow-delay="0.1s">
        <div class="container py-0">
            <div class="row">

            <div class="  wow col-sm-12 text-center fadeInUp" data-wow-delay="0.6s">
              <a href="#">
                <div class="ads-item  my-0">
                <img class="img-fluid" src="logo/restaurant_delivery.jpg" alt="banner">
                
                </div>
             </a>

            </div>
            </div>
           
        </div>
    </div>
<!---ads end--->

<!--item added to added to cart notification--->
<div class="bg-success text-white rounded  w-25" id="popUp" style="display: none;"> Item added to cart <i class="fa fa-check-square-o" aria-hidden="true"></i></div>
<!--item added to added to cart notification end--->
    <div class="pad p-4">

    </div>
 <!-- Ads End -->
 <?php include('online_button_nav.php')?>

</div>




<script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>
<script src="js/script.js"></script>
    <!-- JavaScript Libraries -->
    <script src="lib/owlcarousel/owl.carousel.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() { /// Wait till page is loaded
setInterval(timingLoad, 3000);
function timingLoad() {
$('#main').load('property-detailed.php #main', function() {
/// can add another function here
});
}
}); //// End of Wait till page is loaded
</script>
<script>


   $(document).ready(function(){
setInterval(function(){
      $(".refreeshmes").load(window.location.href + " .refreeshmes" );
}, 3000);
});

 function reply_click(obj)
  {

    var id = obj.id;
    document.getElementById(id).style.visibility = "hidden";
      $( "#popUp" ).show(); 
   setTimeout(function() {
      $( "#popUp" ).hide();
      $( id ).hide();
    }, 2000);
  }






// quick search regex
var qsRegex;
var buttonFilter;

// init Isotope
var $grid = $('.grid').isotope({
  itemSelector: '.element-item',
  layoutMode: 'fitRows',
  filter: function() {
    var $this = $(this);
    var searchResult = qsRegex ? $this.text().match( qsRegex ) : true;
    var buttonResult = buttonFilter ? $this.is( buttonFilter ) : true;
    return searchResult && buttonResult;
  }
});

$('#filters').on( 'click', 'button', function() {
  buttonFilter = $( this ).attr('data-filter');
  $grid.isotope();
});

// use value of search field to filter
var $quicksearch = $('#quicksearch').keyup( debounce( function() {
  qsRegex = new RegExp( $quicksearch.val(), 'gi' );
  $grid.isotope();
}) );


  // change is-checked class on buttons
$('.button-group').each( function( i, buttonGroup ) {
  var $buttonGroup = $( buttonGroup );
  $buttonGroup.on( 'click', 'button', function() {
    $buttonGroup.find('.is-checked').removeClass('is-checked');
    $( this ).addClass('is-checked');
  });
});
  

// debounce so filtering doesn't happen every millisecond
function debounce( fn, threshold ) {
  var timeout;
  threshold = threshold || 100;
  return function debounced() {
    clearTimeout( timeout );
    var args = arguments;
    var _this = this;
    function delayed() {
      fn.apply( _this, args );
    }
    timeout = setTimeout( delayed, threshold );
  };
}




</script>
</body>
</html>
