<?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 Shop</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="row">
						<div class="col-md-12">
							<div class="card card-primary" id="customerclaims" style="">
								<div class="card-body">
									 
											 <table id="example2" class="table table-bordered table-hover">
												<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>
													 
													<form class="form" method="get" action="customerclaimspershop.php">
													
													<div class="row">
														<div class="col-lg-3">
														Shop<br />
														
														<select  class="form-control" name="shop_id" id="">
															<?php
																$shops = DB::query("SELECT id, full_name FROM shop");
																
																foreach ($shops as $shop)
																{
															?>
															<option value="<?php echo $shop['id']; ?>"><?php echo $shop['full_name']; ?></option>
															<?php
																}
															?>
														</select>
										
														</div>
														<div class="col-lg-3">
															From<br />
															<input type="text" class="form-control" name="start_date" placeholder="YYYY-MM-DD" id="start_date" >
														</div>
														<div class="col-lg-3">
															To<br />
															<input type="text" class="form-control" name="end_date" placeholder="YYYY-MM-DD" id="end_date" >
														</div>
														<div class="col-lg-3">
															&nbsp;<br />
															<input type="submit" class="form-control" value="Search" />
														</div>
													</div>
														  
													</form>
													
													<?php
													if(isset($_GET['shop_id'])){
															$shop_id = $_GET['shop_id'];
													}else{
														$shop_id = 1;
													}
													
													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 FROM cash_receipt where shop = {$shop_id}  and 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><?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>
										 
								</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>
	</body>
</html>