<?php
	include("my_functions.php");
	$pagetitle = "Job search using barcode or client's Name";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";
	
	$startdatevalid = false;
	
 
?>
			<!-- 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 id="servererrormessage">
							</div>
							
							<?php
								if($err!="")
								{
							?>
							<div class="alert alert-danger alert-dismissable">
								<i class="fa fa-ban"></i>
								<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><br>
								<?php 
									echo $err; 
								?>
							</div>
							<?php
								}
								$jobs = array();
								if(isset($_POST['theclient'])){
                                  $search = trim($_POST['theclient']);
								$jobs = 	notcleared( $from = false , 50 , $search  );
									
								} 
									
							?>
							
							<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">
                  
                  
                 
                    <label for="to">Search customer or job</label>
											<div class="input-group">
												<input type="text"   name='theclient' placeholder='Enter client name or Barcode' 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><!-- form-group -->
               
				</form>
				<br /><br />
             
              
								 
								<?php
                                 
                               
									 
                                        

                                  

                                    if(!empty($jobs)){
                                        $count = 0;
 
								?>
								<table class="table table-striped table-bordered"   id="example2">
									<thead>
										<tr>
											<th>Bar code</th>
											<th class="text-center">Item</th>
											<th class="text-right">Date</th>
                                            <th class="text-center">Client</th>
											<th class="text-right">Contact</th>
                                            <th class="text-center">Bill</th>
											<th class="text-right">Balance</th>
                                            <th class="text-center">type</th>
											<th class="text-right">Owner</th>
                                            <th class="text-center">Status</th>
                                            <th class="text-center">Dipatch date</th> 
										</tr>
									</thead>
									<tbody>

                                    <?php
                                     foreach($jobs as $row){
                                        $bar_code = $row['parent_bar_code'];
                                        $topups = topups($bar_code  );
                                        if(!empty($topups)){
                                             $topups = $topups[0]['topup'];

                                        }
                                           //$amount = amount_to_be_not_cleared($bar_code);
                                          

                                        echo '<tr> <td colspan="6"> #'.( $count +=1).' Bar Code: <b>'.$bar_code.' </b> </td>
                                        
                                        <td colspan ="2"> <a class="btn btn-info" href="'.$GLOBALS['base_url'].'dothetopups/'.$bar_code.'"  >  Top up </a></td>
                                        <td colspan ="2"> <a class="btn btn-primary" href="'.$GLOBALS['base_url'].'thebarcodes/'.$bar_code.'" target="blank">  Print bar codes </a></td>
                                        <td colspan ="2"> <a class="btn btn-info" href="'.$GLOBALS['base_url'].'customreceipt/'.$bar_code.'" target="blank">  Get a receipt </a> </td>
                                        
                                        </tr>';
                                        echo barcode_jobs($bar_code);

                                     }
                                        

                                        ?>
										 
									</tbody>
								</table>
								<?php
                                    }else echo 'No data found';
								 
								?>
								 
							</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')?>
		<!-- InputMask -->
		<script src="plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
		<script src="plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
		<script src="plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>
		<!-- AdminLTE App -->
	 
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		
		
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
		<script>
			$(function() 
			{
				//Datemask2 mm/dd/yyyy
				$("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "mm/dd/yyyy"});
				//Money Euro
				$("[data-mask]").inputmask();
			});
		</script>
		
		<script>
  $(function () {
    $("#example11").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>
	</body>
</html>