<?php
session_start();
require_once 'includes/config.php';

if (!isset($_SESSION['user_logged_in']) && $_SESSION['user_logged_in'] != TRUE) {
    header('Location:login.php');
}

$customers=mysqli_query($con,'SELECT * FROM orders  ORDER BY id DESC');


require_once 'includes/header.php';
?>
<div class="content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-12">
			<!--<a href="add_compliant.php" class="btn btn-primary btn-round">Add New Compliants<div class="ripple-container"></div></a>-->
              <div class="card">
                <div class="card-header card-header-primary">
                  <h4 class="card-title "> Orders</h4>
                  <p class="card-category"> </p>
                </div>
                <div class="card-body">
                  <div class="table-responsive">
                    <table class="table">
                      <thead class=" text-primary">
                        <th>Order ID</th>  
		  <th>
User Phone</th> 
		  <th>
Order Items</th> 
		  <th>
Amount</th> 	  
		  <th>
Transaction Id</th>
<th>
Used Cash</th>
<th>
Used Vouchers</th>
<th>
Address</th>
<th>
City</th>
<th>
State</th>

		  <th>Date</th>
                      </thead>
                      <tbody>
                        <?php
		if(mysqli_num_rows($customers)>0){	
		$i=1;
		while($customer=mysqli_fetch_array($customers)){?>
		<tr>
		<?php $cat=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM users WHERE id=".$customer['user_id']));
		$products=explode(",",$customer['product_id']);
			foreach($products as $key=>$p){
			$pro=mysqli_fetch_array(mysqli_query($con,"SELECT id,name FROM products WHERE id=".$p));
			$prod[]=$pro['name'];
			 
			}
			$prodname=implode(",",$prod);

		?>
		<td><?php  echo $customer['id'];?></td>
		<td><?php echo $cat['phone'];?></td>
		<td> <?php echo $prodname;?></td>
		<td><?php echo $customer['amount'];?></td>
		<td><?php echo $customer['transaction_id'];?></td>
		<td><?php echo $customer['used_cashpoints'];?></td>
		<td><?php echo $customer['use_voucherpoints'];?></td>
		<td><?php echo $customer['address'].'-'.$customer['pincode'];?></td>
		<td><?php echo $customer['city'];?></td>
		<td><?php echo $customer['state'];?></td>
		
		<td>
		<?php echo $customer['date'];?>
		</td>
		</tr>	
		<?php $i++;}
		}
		?>   
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>

<?php include_once 'includes/footer.php'; ?>

<script type="text/javascript">
    $(document).ready(function () {
        $('.delete_btn').click(function () {
            var r = confirm("Are you sure?")
            if (r == true) {
                return true;
            } else {
                return false;
            }
        });
    });
</script> 