<?php
	include("my_functions.php");
	$pagetitle = "Report";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";

    $actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 
	$parts = explode('jobstatuscheck' , $actual_link);
		 
		
    $fromdate = false;
    $selector = false;
    $cat = $shop = false;
	
	$startdatevalid = false;
	$jobs = array();
	
	if(isset($_POST['getreceiptsbtn']))
	{
		 
     $fromdate =  date('Y-m-d', strtotime($_POST['to']));
		   
		  
           
		   
		   	$jobs = distcinct_jobs_status_by_customer( $fromdate );
          
			 
		 
	} else {
           
		                             	$jobs = distcinct_jobs_status_by_customer( ); 
										 

	}
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				 

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<div class="card card-primary">
						<?php
							if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"]> 2)
							{
						?>
						<div class="card-body">
							 
							 
							
							<div class="card card-info">
              <div class="card-header">
                <h6 class="card-title"><?= $pagetitle ?></h6>
              </div>
              <div class="card-body">
			  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
									
                <div class="row">

                

                   
                  
                  <div class="col-6">
                    <label for="to">From Date</label>
											<div class="input-group">
											
											 
											
												<input type="date" value="<?php echo isset($_POST['to']) ?  $_POST['to'] : "" ?>" name="to" id="to"  data-date-format="dd-mm-yyyy"  class="form-control"   />
												<span class="input-group-btn">
													<button class="btn btn-primary btn-flat" type="submit" name="getreceiptsbtn" id="getreceiptsbtn">Go!</button>
												</span>
											</div>
                  </div>
                </div>
				</form>
				</div>
            
							
							 
								<?php
									if($err=="" )
									{
										//print_r($jobs);
 
								 
 	 
								if(!empty($jobs)){
									$count = 0;

							?>
							<table class="table table-striped table-bordered" id="receiptstable">
								<thead>
									<tr>
										<th>Bar code</th>
										<th class="text-center">Customer</th>
										<th class="text-right">Received By</th>
										<th class="text-center">Jobs</th>
										<th  >Job Data</th> 
									</tr>
								</thead>
								<tbody>
								

								<?php
								function Sum_jobs($person , $time){//
									$name = 'N/A';
									 
									 DB::query(' SELECT id    FROM job_receipt WHERE customer_id  ='.$person.'  and pickon = "'.$time.'"     ');
									 //$categorydata = DB::query("SELECT sum(quantity) as quantity FROM item_stock_level WHERE item=%i AND shop =%i LIMIT 1"  , $item , $shop);
		
									 return DB::count();
										 
								}
								
								 //<td>'.barcode_jobs_mini($row['customer_id'], $row['pickon']).' </td>
								 //<td>'.Sum_jobs($row['customer_id'] , $row['pickon']).' </td>
								 foreach($jobs as $row){
									$bar_code = $row['parent_bar_code'];
									//customer_id //Personel_name(

									echo '<tr> 
									<td  > #'.( $count +=1).' Bar Code: <b>'.$bar_code.' </b> </td>
									<td>'.$row['customer_name'].' </td> 
									<td>'.Personel_name($row['attendant']).' </td> 
									<td>'.Sum_jobs($row['customer_id'] , $row['pickon']).' </td>
									<td>'.barcode_jobs_mini($row['customer_id'], $row['pickon']).' </td>
									
									 
									
									
								 
									
									
									 
									</tr>';
									 

								 }
									

									?>
									 
								</tbody>
							</table>
							<?php
								}else echo 'No data found';
							 
							?>
								
							 

                                <?php }   ?>
									 
								
								   
								 
										 
								
								</div>
              <!-- /.card-body -->
            </div>
								
								</div>
							</div>
						</div><!-- /.card-body -->
						<?php
						
							}
							else
							{
						?>
						<div class="alert alert-danger alert-dismissable">
							<i class="fa fa-ban-circle"></i><br>
							Limited Access
						</div>
						<?php
							}
						?>
					</div><!-- /.card -->
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->
 
		</div><!-- ./wrapper -->
		
		 

		 
	
	
	
	
 <?php include ('includes/general_footer.php')?> 
 
 
	</body>
</html>