<?php
	include("includes/dbconfig.php");
	$pagetitle = "Customers";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					<h1>Points Per Person</h1>
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<?php
						if($_SESSION["connectedusergroup"] == 3 || $_SESSION["connectedusergroup"] == 4 || $_SESSION["connectedusergroup"] == 1)
						{
					?>
					<div class="row">
						<div class="col-md-12">
							<div id="servererrormessage">
							</div>
						</div>
					</div>
				
					<div class="row">
						<div class="col-md-12">
							<div class="card card-primary" id="customerclaims" style="">
								<div class="card-body">
									
									<div>
										<div id="">
										<form class="form" method="get" action="individualcustomerclaims.php">
													
													<div class="row">
														<div class="col-lg-6">
													  
										 
											<input type="text" id="search-card" placeholder="Search a customer here" />
										 
										 
										<select class="form-control  " style="width: 100%;"  name="customer_id" id="customer_id">
										  
										  <option value="1" selected="selected" >No Name</option>
										   
										</select>
										
											</div>
														 
														<div class="col-lg-3">
															&nbsp;<br />
															<input type="submit" class="form-control btn-info" value="Search" />
														</div>
													</div>
														  
													</form>
													<br />
													<?php 	if(isset($_GET['customer_id'])){ ?>
											 <table id="example1" class="table table-bordered table-hover">
												<thead>
													<tr>
														<th style="display:none;"></th>
														<th>#</th>
														<th>Customer Name</th>
														<th class="text-right">Bill</th>
														<th class="text-right">Points</th>
														<th>Date</th>
													</tr>
												</thead>
												<tbody>
													 
													
													
													<?php
												
													if(isset($_GET['customer_id'])){
															$customer_id = $_GET['customer_id'];
													}else{
														$customer_id = 0;
													}
													
													if(isset($_GET['start_date'])){
															$start_date = $_GET['start_date'];
													}else{
														/* $today = date('Y-m-d');
														$start_date = date('Y-m-d', strtotime($today. ' - 1 days')); */

														$start_date = date('Y-m-d');
													}
													
													if(isset($_GET['end_date'])){
															$end_date = $_GET['end_date'];
													}else{
														/* $today = date('Y-m-d');
														$end_date = date('Y-m-d', strtotime($today. ' + 1 days')); */

														$end_date = date('Y-m-d');
													}
														$items = DB::query("SELECT id, customer_name, value_date, bill, claim FROM cash_receipt where customer_id = '{$customer_id}' LIMIT 10");
														
														$total_bills = 0;
														$total_claims = 0;
														
														foreach ($items as $item)
														{
													?>
													<tr>
														<td style="display:none;"></td>
														<td><?php echo $customer_id; ?></td>
														<td><?php echo $item['customer_name']; ?></td>
														<td class="text-right"><?php $total_bills = $total_bills + $item['bill']; echo $item['bill']; ?></td>
														<td class="text-right"><?php $total_claims = $total_claims + ($item['claim']/100)*($item['bill']); echo ($item['claim']/100)*($item['bill']); ?></td>
														<td><?php echo $item['value_date']; ?></td>
													</tr>
													<?php
														}
													?>
													<tr style="background-color: #ccc;">
														<td style="display:none;"></td>
														<td></td>
														<td></td>
														<td class="text-right"><b><?php echo $total_bills; ?></b></td>
														<td class="text-right"><b><?php echo $total_claims; ?></b></td>
														<td></td>
													</tr>
												</tbody>
											</table>
													<?php  } ?>
										</div>
									</div>
								</div><!-- /.card-body -->
							</div><!-- /.card -->
						</div>
						
						
					</div>
					<?php
						}
						else
						{
					?>
					<div class="alert alert-danger alert-dismissable">
						<i class="fa fa-ban-circle"></i>
						Limited Access
					</div>
					<?php
						}
					?>
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->

			 
		</div><!-- ./wrapper -->
		
		
		
		<?php include ('includes/general_footer.php')?> 
		
		<script src="plugins/bert/jquery.price_format.min.js" type="text/javascript"></script>
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/cashsalesregister.js" type="text/javascript"></script>
		
				<!-- bootstrap datepicker -->
		<script src="<?php echo $base_url; ?>plugins/datepicker/bootstrap-datepicker.js"></script>

		<script type="text/javascript">
		//Date picker
    $('#start_date').datepicker({
      autoclose: true, 
	  format: 'yyyy-mm-dd'
    });
	
	$('#end_date').datepicker({
      autoclose: true, 
	  format: 'yyyy-mm-dd'
    });
		</script>
	<script src="plugins/js/select2.full.min.js" type="text/javascript"></script>
	<script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2();

	 
	 
	 
 
  })
  
  // AJAX call for autocomplete 
$(document).ready(function(){
	$("#search-card").css("background","#ffe6e6");
	
	$("#search-card").keyup(function(){
		 
		$.ajax({
		type: "POST",
		url: "get_customers.php",
		data:'keyword='+$(this).val(),
		beforeSend: function(){
			 
			$("#customer_id").css("background","#f39c12");
		},
		success: function(data){ 
			$("#customer_id").html(data); 
			 
			$("#customer_id").css("background","#FFFF00");
			$("#search-card").css("background","#ffffff");
		}
		});
	});
});
//To select country name
 
</script>
	</body>
</html>