<?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 points_logs    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 "> Daily Points Earning Transaction </h4>
                  <p class="card-category"> </p>
                </div>
                <div class="card-body">
                  <div class="table-responsive">
                    <table class="table">
                      <thead class=" text-primary">
                        <th>UID</th>  
		  <th>
Name</th> 
		  <th>
Level</th> 
		  <th>
Available Points</th>
 <th>
Earning Amount</th> 
		 
		  <th>
Type</th>
		  <th>Date</th>
                      </thead>
                      <tbody>
                        <?php
		if(mysqli_num_rows($customers)>0){	
		$i=1;
		while($customer=mysqli_fetch_array($customers)){
			$level=0;
	$credits=$customer['credits'];
	if($credits<=1000){
		$level=1;
	}elseif($credits<=50000 && $credits>1000){
		$level=2;
	}elseif($credits<=100000 && $credits>50000){
		$level=3;
	}elseif($credits<=1000000 && $credits>100000){
		$level=4;
	}
			?>
		<tr>
		
		<?php $cat=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM users WHERE id=".$customer['user_id'])); ?>
		<td><?php  echo $cat['phone'];?></td>
		<td><?php echo $cat['first_name'];?></td>
		<td>Level <?php echo $level;?></td>
		<td><?php echo $customer['points'];?></td>
		<td>- <?php echo $customer['difference'];?></td>
		
		<td>
		<?php echo $customer['created_at'];?>
		</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> 