<?php 
require_once('includes/check-login.php');
require_once('includes/header.php'); 
require_once('includes/menu.php'); 
require_once('includes/config.php'); 
$tablename="save_order";	
$addurl="service-view.php";
if($_SESSION['role_id']==1){
$sql = "SELECT * from ".$tablename." WHERE 1=1";
$order_date=isset($_GET['order_date']) ? $_GET['order_date'] : '';
$job_date=isset($_GET['job_date']) ? $_GET['job_date'] : '';
$job_status=isset($_GET['job_status']) ? $_GET['job_status'] : ''; 
if(!empty($order_date)){
  $sql .=" and order_date='$order_date'";  
}else{
 $sql .=" and order_date='empty'";     
}
if(!empty($job_date)){
  $sql .=" and job_date='$job_date'";  
}
if($job_status!=""){
  $sql .=" and job_status='$job_status'";  
}
}else{
$sql = "SELECT * from ".$tablename." WHERE vendor_id = '".$_SESSION['userid']."'";    
$order_date=isset($_GET['order_date']) ? $_GET['order_date'] : '';
$job_date=isset($_GET['job_date']) ? $_GET['job_date'] : '';
$job_status=isset($_GET['job_status']) ? $_GET['job_status'] : ''; 
if(!empty($order_date)){
  $sql .=" and order_date='$order_date'";  
}else{
 $sql .=" and order_date='empty'";     
}
if(!empty($job_date)){
  $sql .=" and job_date='$job_date'";  
}
if($job_status!=""){
  $sql .=" and job_status='$job_status'";  
}
}
$result = $con->query($sql);
?>
<style>.ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year {color: #000;}</style>
<!-- Datatable CSS -->
<link href='data_tables/datatables.min.css' rel='stylesheet' type='text/css' />
<link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel= "stylesheet">
<!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">                                
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>                    
                        <li class="active"><a href="#">Job Request Report</a></li>           
                    </ol>                
            </section>

            <!-- Main content -->
            <section class="content">                
                <!-- Default box -->
                <div class="box box-form">
                    <div class="box-header with-border">
                        <h3 class="box-title">Job Request Report</h3>
                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                                <i class="fa fa-minus"></i></button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                                <i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <div class="box-body">    
                    <div class="container">
  <form method="get">
    <div class="form-group row">
      <div class="col-xs-3">
        <label for="ex1">Order Date</label>
        <input class="form-control datepicker" type="text" name="order_date" value="<?php echo $order_date;?>" readonly>
      </div>
      <div class="col-xs-3">
        <label for="ex2">Job Date</label>
        <input class="form-control datepicker" type="text" name="job_date" value="<?php echo $job_date;?>" readonly>
      </div>
      <div class="col-xs-3">
        <label for="ex3">status</label>
        <select class="form-control" name="job_status">
        <option Value="" selected> Choose status</option>
        <option value="0" <?php if($job_status=='0'){ echo "selected";}?> >Pending</option>
        <option value="1" <?php if($job_status=='1'){ echo "selected";}?>>Approved</option>
        <option value="2" <?php if($job_status=='2'){ echo "selected";}?>>Completed</option>
        <option value="3" <?php if($job_status=='3'){ echo "selected";}?>>Canceled</option>
        </select>
      </div>
      <div class="col-xs-2">
        <label for="ex3"></label>
        <input class="form-control btn btn-success" type="submit" value="Search">
      </div>
    </div>
  </form>
</div>
                        <!-- Table -->
                        <table id='workapp' class='display dataTable table table-bordered table-hover'>
                            <thead>
                            <tr>
                                <th>Order ID</th>                    
                                <th>Name</th>  
                                <th>Phone</th> 
                                <th>Email</th>
                                <th>Job Date & Time</th>
                                <th>Status</th>
                            </tr>
                            </thead> 
                              <tbody>
							<?php $i=1;
							if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                            $status=$row['job_status'];
                            if($status==0){
                               $stacom="Pending"; 
                            }else if($status==1){
                               $stacom="Approved";  
                            }else if($status==2){
                               $stacom="Completed";  
                            }else{
                               $stacom="Canceled";  
                            }?>
						   <tr>
						   <td><?php echo $row['id'];?></td>
						   <td><?php echo $row['name'];?></td>
						   <td><?php echo $row['phone'];?></td>
						   <td><?php echo $row['email'];?></td>
						   <td><?php echo $row['job_date'];?> & <?php echo $row['job_time'];?></td>
						   <td><?php echo $stacom;?></td>
						    </tr>								  
							 <?php $i++;}}?>
                           </tbody>							
                        </table>

                    </div>
                    
                    <!-- /.box-footer-->                    
                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->                                        
        </div>
        <!-- /.content-wrapper -->        
<script src="js/common.js"></script>  
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
         $(function() {
            $(".datepicker" ).datepicker({
           changeMonth: true,
           changeYear: true,
           dateFormat:'yy-mm-dd',
           showButtonPanel: true,
           closeText:'Clear',
	beforeShow: function( input ) {
		setTimeout(function() {
		var clearButton = $(input )
			.datepicker( "widget" )
			.find( ".ui-datepicker-close" );
		clearButton.unbind("click").bind("click",function(){$.datepicker._clearDate( input );});
		}, 1 );
	}
          });
         });
</script>
<script src="js/datatables-report.js"></script> 
<script src="https://cdn.datatables.net/buttons/1.6.0/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.0/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.0/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.0/js/buttons.print.min.js"></script>
<?php require_once('includes/footer.php'); ?>