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

	$actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$parts = explode('jobsearch' , $actual_link);
	
		$fromdate = false;
		$command = false;

		$startdatevalid = false;


		
	
 
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				 

				<!-- 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
								}
							?>
							
							<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 Job using name or bar code</label>
											<div class="input-group">
												<input type="text"   name="barcode" id="barcode" class="form-control" value='<?php  if(isset($_POST['barcode'])) { echo  $_POST['barcode'] ; } ?>'   />
												<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>
              </div>
              <!-- /.card-body -->
            </div>
							
							<div class="card-body table-responsive  ">
								 
								
								<div class="col-md-12" style="margin-top: 25px"></div>
								 
								<?php
                                 
                                $jobs = array();
									if(  isset($_POST['barcode']))
									{
                                        $code =  $_POST['barcode']; 
                                        //$jobs = search_barcode($code);
										$jobs = 	notcleared( $from = false , 50 , $code  );

                                         
                                         

                                      

                                    }else{

									     

											$end = $parts[1];
											 $parts = explode('/' , $end);
											 $selector =  false;
											 $fromdate = date('Y-m-d');
											 if(sizeof($parts) > 0){
												$fromdate = date('Y-m-d');

											 }else  {
											 
											 
									
											$command =  $parts[1]; 
											if($command =='today'){  $fromdate = date('Y-m-d');  $selector = false; } else if($command =='waiting'){  $fromdate = false; $selector = $command2;  }
									
											$shop =  $command;
									     }
											$fromdate =  date("Y-m-d");
									
											
																	 
																	  
									 
										 

                                        $jobs = distcinct_jobs($selector , $fromdate);

                                    }

                                    if(!empty($jobs)){
                                        $count = 0;
 
								?>
								<table class="table table-striped table-bordered" id="receiptstable">
									<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">Dispatch date</th> 
										</tr>
									</thead>
									<tbody>

                                    <?php
									 
                                     foreach($jobs as $row){
                                        $bar_code = $row['parent_bar_code'];

                                        echo '<tr> <td colspan="6"> #'.( $count +=1).' Bar Code: <b>'.$bar_code.' </b> </td>
                                        
										<td colspan ="2"> <a class="btn btn-primary" href="'.$GLOBALS['base_url'].'deleteajob.php/'.$bar_code.'"  >  Delete </a></td>
										<td colspan ="2"> <a class="btn btn-primary" href="'.$GLOBALS['base_url'].'thebarcodes.php/'.$bar_code.'" target="blank">  Print bar codes </a></td>
                                        <td colspan ="2"> <a class="btn btn-info" href="'.$GLOBALS['base_url'].'customreceipt.php/'.$bar_code.'" target="blank">  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')?> 
		 
	</body>
</html>