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

if (!isset($_SESSION['user_logged_in']) && $_SESSION['user_logged_in'] != TRUE) {
    header('Location:login.php');
}
if (isset($_POST['search'])) {
	$start_date=$_POST['start_date'];
	$end_date=$_POST['end_date'];
	
	$customers=mysqli_query($con,"SELECT * FROM vouchers_logs WHERE DATE(created_at) >= '".$start_date."' AND DATE(created_at)<= '".$end_date."' ORDER BY id DESC");
	
	
}

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


require_once 'includes/header.php';
?>
<style>
.modal{
	z-index: 9999;
	max-height: 55%;
	
}
.modal-content{
	border:none;
}
</style>
<div class="content">
        <div class="container-fluid">
		
		<div class="container mt-5">
  <!--Grid row-->
  <form action="" method="POST">
  <div class="row">
	
    <!--Grid column-->
    <div class="col-md-4 mb-4">

      <div class="md-form">
        <!--The "from" Date Picker -->
        <input name="start_date" placeholder="Selected starting date datepicker" type="text" id="startingDate" class="form-control datepicker">
       <!-- <label for="startingDate">start</label>-->
      </div>

    </div>
    <!--Grid column-->

    <!--Grid column-->
    <div class="col-md-4 mb-4">

      <div class="md-form">
        <!--The "to" Date Picker -->
        <input name="end_date" placeholder="Selected ending date datepicker" type="text" id="endingDate" class="form-control datepicker">
       <!-- <label for="endingDate">end</label>-->
      </div>

    </div>
    <!--Grid column-->
	 <div class="col-md-2 mb-4">
<button name="search" type="submit" class="btn btn-primary">Go</button>
</div>

  </div>
  <!--Grid row-->
  </form>
</div>
		
		<?php if($customers){ ?>
          <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 Voucher 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>名稱  <br>
Name</th> 
		  <th>每日優惠券  <br>
Daily Voucher</th> 
		  <th>可用優惠券<br>
Available Vouchers</th> 
		 
		  
		  <th>类型  <br>
Type</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'])); ?>
		<td><?php  echo $cat['phone'];?></td>
		<td><?php echo $cat['first_name'];?></td>
		<td> + <?php echo $customer['difference'];?></td>
		<td><?php echo $customer['voucher'];?></td>
		<td>RLS</td>
		
		<td>
		<?php echo $customer['created_at'];?>
		</td>
		</tr>	
		<?php $i++;}
		}
		?>   
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
            
          </div>
		  <?php } ?>
        </div>
      </div>

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

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