<?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>All Points</h1>
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<?php
						if($_SESSION["connectedusergroup"] == 1)
						{
					?>
					<div class="row">
						<div class="col-md-12">
							<div id="servererrormessage">
							</div>
						</div>
					</div>
					
					<div class="card card-info">
						  <div class="card-header">
							<h3 class="card-title">All Points</h3>
						  </div>
					  <div class="card-body">
					 
						
						<div class="row">
						  <div class="col-3"> From <br />
							<input type="text" class="form-control" name="start_date" placeholder="YYYY-MM-DD" id="start_date" >
													
						  </div>
						  <div class="col-3">
							To<br />
															<input type="text" class="form-control" name="end_date" placeholder="YYYY-MM-DD" id="end_date" >
														
						  </div>
						  <div class="col-3">
							&nbsp;<br />
															<input type="submit" class="form-control btn-info" value="Search" />
						  </div>
						</div>
					  </div>
              <!-- /.card-body -->
            </div>
			
			 <div class="card">
             
            <!-- /.card-header -->
            <div class="card-body" id="customerclaims">
             <table id="stockitemstable" class="table  table-bordered table-striped  ">
                <thead>
                <tr>
                  <th style="display:none;"></th>
														<th>Shop</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['start_date'])){
															$start_date = $_GET['start_date'];
													}else{
														$start_date = date('Y-m-d');
													}
													
													if(isset($_GET['end_date'])){
															$end_date = $_GET['end_date'];
													}else{
														$end_date = date('Y-m-d');
													}
													
														$items = DB::query("SELECT id, shop, customer_name, value_date, bill, claim, customer_id FROM cash_receipt where value_date between '{$start_date}' and '{$end_date}'");
														
														$total_bills = 0;
														$total_claims = 0;
														
														foreach ($items as $item)
														{
													?>
													<tr>
														<td style="display:none;"></td>
														<td>
														<?php 
															$shop_id = $item['shop'];
	$shops = DB::query("SELECT id, full_name FROM shop WHERE id = '{$shop_id}'");
	foreach ($shops as $shop)
	{
		echo $shop['full_name'];
	}
														?>
														</td>
														<td><a href="individualcustomerclaims.php?customer_id=<?php echo $item['customer_id']; ?>&start_date=<?php echo $start_date; ?>&end_date=<?php echo $end_date; ?>"><?php echo $item['customer_name']; ?></a></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>
				</table>
				</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>
	</body>
</html>