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

    $actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$parts = explode('shortsummaries' , $actual_link);
		
    $fromdate = false;
    $selector = false;
	
	$startdatevalid = false;
	
	if(isset($_POST['getreceiptsbtn']))
	{
		if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"] < 5)
		{
			
			if($_POST['shop']=="")
			{
				$err = $err."Shop Selection Required!<br>";
			}
			else
			{
				if($_SESSION["connectedusergroup"] == 3 && $_POST['shop'] != $_SESSION["connecteduserbranch"])
					$err = $err."You Are Not Authorised To Access Receipts From Other Shops!<br>";
			}
			
			if(trim($_POST['from'])=="")
			{
				$err = $err."Start Date Required!<br>";
			}
			else
			{
				 
					if(date("Y-m-d", strtotime(trim($_POST['from']))) > date("Y-m-d"))
					{
						$err = $err."Future Start Date Not Supported.<br>";
					}
					else
					{
						$startdatevalid = true;
					}
				 
			}
			
			if(trim($_POST['to'])=="")
			{
				$err = $err."End Date Required!<br>";
			}
			 
		}
		else
		{
			$err = $err."Limited Access!<br>";
		}
	}else{

        $end = $parts[1];
		 $parts = explode('/' , $end);

        $command =  $parts[1];
        $command2 =  $parts[2]; 
        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");

        
								 
								  
 
    }
?>
			<!-- 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"] < 5)
							{
						?>
						<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">

                <div class="col-4">
                  <label for="shop">Job Status</label>
											<select  class="form-control" name="shop" id="shop" data-placeholder="Choose One">
												<option value="0">Type</option> 
                                                <option value="3">Dispatch</option>
                                                <option value="5">Waiting</option>
                                                <option value="6">Ready for pickup</option>
												 
											</select>
                  </div>

                  <div class="col-4">
                  <label for="shop">Select Shop</label>
											<select  class="form-control" name="shop" id="shop" data-placeholder="Choose One">
												<option value="x">All Shops</option>
												<?php
													$shopsdata = DB::query("SELECT id, full_name FROM shop ");
													
													foreach ($shopsdata as $shoprow)
													{
												?>
												<option <?php if(isset($_POST['shop']) && $shoprow['id']==$_POST['shop']) echo "selected=\"selected\""; ?> value="<?php echo $shoprow['id']; ?>"><?php echo $shoprow['full_name']; ?></option>
												<?php
													}
												?>
											</select>
                  </div>
                  
                  <div class="col-4">
                    <label for="to">From Date</label>
											<div class="input-group">
											
											 
											
												<input type="text" 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>
						
							 
								<?php
									if($err=="" )
									{
								?>
								  
								  <br /><br />
								
								 <h6> Job summary from <?php echo $fromdate; ?>  </h6>
								 
								  
								  
								  
								  
								 
								 
								 
												 <table class="table table-striped table-boardered  table-hover" id="ziana">
												<thead>
												
												<tr class ='info'>
												<th> #</th><th>Job Description </th> <th>Date </th>    <th>Client</th><th>Phone</th> <th>Charges</th><th>Job type </th> <th>Owner  </th>  	<th>Status </th> 	<th>Pick up date </th> 
												</tr>
												</thead>
								 
								<?php
								
								  
							 

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

                             
									 
								?>
								
								</table>

								<?php 	} ?>
									 
								
								   
								 
										 
								</div>
              </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 -->
		
		<div class="modal" id="waitdialogmodal"  data-backdrop="static">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-body">
					<div class="text-center">
						<img src="<?php echo $base_url . $ajax_loading_image; ?>" />
					</div>
				  </div>
              </div>
            </div>
        </div>

		 
	
	
	
	
 <?php include ('includes/general_footer.php')?> 
<script src="js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="tableExport.js"></script>
<script type="text/javascript" src="jquery.base64.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript" src="jspdf/libs/sprintf.js"></script>
<script type="text/javascript" src="jspdf/jspdf.js"></script>
<script type="text/javascript" src="jspdf/libs/base64.js"></script> 
 <link href="css/datepicker.css" rel="stylesheet">
 
<script>
 
		$(function(){
			 
			$('#from').datepicker();
			$('#to').datepicker();
			 
			 
		});
	</script>

	 
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/store.js" type="text/javascript"></script>
	</body>
</html>