<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
    <script src="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.min.js"></script>
	

  <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		          var salaryid = $(this).data('salaryid');
		  $("#salaryid").val(salaryid); 
		   
        });
		

 	$(this).ready( function() {  
            $("#mysuppliers").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
 
 

	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/searchleaves";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/searchleaves";

		    // document.body.innerHTML = originalContents;

	}
	
		
    </script>  


	
   	<div class="col-md-12">
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				View leaves submitted by other staffs for my approval		
				                  <span class="pull-right">   <a  class="btn btn-primary" href="<?php echo base_url();?>user/applyleave"> Apply leave  </a></span> 
				     <a data-toggle='modal' data-target='#viewleaves' class="btn btn-primary">Leave Report </a>

			 <a href="<?php echo base_url();?>user/viewleaves" class="btn btn-info">  Go back</a>	
			 <a href="<?php echo base_url();?>user/allleaves" class="btn btn-info">  Refresh</a>	


				 <form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="Print!" />
</form>
		  
				</div>
            </div>
			<div class="panel-body">

			
										
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
					<div class="table-responsive3">

									
									
							
<table id="example"  cellspacing="1" border="1" class="table-striped" width="100%">
             <thead>
         <tr>
		 <th>Name</th> 
		 	 <th>Date applied</th> 
	 <th>Days</th> 
		 	  <th>Leave type</th>
		  <th>From</th>
    		  <th>To</th>
			    <th>Employee</th>
					    <th>Supervisor</th>
  <th>Reasons</th>
  <th>Message</th>
 <th>Status</th>  	
 <th>More</th>  




                 </tr>
             </thead>
<?php


 echo $this->session->flashdata('deletemsg'); 
 
				echo $this->session->flashdata('msg'); 
   $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];










 if(!is_array($report)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='11'>";
    
       echo '<div class="alert alert-warning text-center">You dont have any application submited by now.</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
  	foreach ($report as $c): 

		 

             ?>



             <tr>
                
            <?php 
$id=$c->id;
$createdat=$c->postedtime;



?>

 <td><?php 
	
								 
 
					// $branch="";
					 $userid=$c->userid;

					 $myenployee= $this->usermodel->populateall('people','id',$userid);



if(is_array($myenployee)) {

   foreach($myenployee as $myenployeerow){

   echo $myenployeerow->surname." ".$myenployeerow->firstname."(".$myenployeerow->number.")"; 
 
 
}} else {
    echo 'No Employee';
}
	
?>
	
	
</td>
 <td><?php echo $c->postedtime	; ?></td> 				   
 <td><?php echo $c->duration	; ?></td> 				   


  <td><?php 
	
								 
 
					// $branch="";
					 $mytype=$c->type;

					 $leavetype= $this->usermodel->populateall('leavegroup','id',$mytype);



if(is_array($leavetype)) {

   foreach($leavetype as $leavetyperow){

   echo $leavetyperow->name;
 
 
}} else {
    echo 'No type';
}
	
?>
	
	
</td>



 

 <td><?php echo $c->startdate	; ?></td> 	
               <td><?php echo $c->enddate; ?></td> 	

 
		   <td><?php 
	
								 
 
					// $branch="";
					 $myincharge=$c->incharge;

					 $myenployee= $this->usermodel->populateall('people','id',$myincharge);



if(is_array($myenployee)) {

   foreach($myenployee as $myenployeerow){

   echo $myenployeerow->surname." ".$myenployeerow->firstname."(".$myenployeerow->number.")"; 
 
 
}} else {
    echo 'No Employee';
}
	
?>
	
</td>
        <td><?php  
		$manager=$c->manager; 
		   
						   	  $myconfiguration = $this->usermodel->populateallarray('people','id',$manager);
echo $firstname=$myconfiguration[0]["firstname"];
		   

		?></td> 

          <td><?php echo $c->description; ?></td> 

          <td><?php echo $c->comments; ?></td> 

        
   
				<td><?php 
	
								 
 
					// $branch="";
					 $mystatuse=$c->status;

					 $leavestatus= $this->usermodel->populateall('status','id',$mystatuse);



if(is_array($leavestatus)) {

   foreach($leavestatus as $leavestatusrow){

   echo $leavestatusrow->name;
 
 
}} else {
    //echo 'No Status';
}
	
?>
	
	
</td>
	 
     				 
		

<td id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
									
				
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
									  
                                   <li> 
								   
								    <a  id="more" class="btn btn-warning" href="<?php echo base_url();?>user/manageleave?randomitemidentifier=<?php   {echo  $id;}  ?>"> More </a>

					
                                 </li>
																			        <li class="divider"></li>
	
											<?php
											
										if($usertype=="admin"){
											
											?>
                                        
                                    
										

											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#deleteModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel Leave
                                                </a>
                                                        </li>
														
									
										<?php
										}
										?>
                                  			
									
								
									
											
														
														
														
                                        
                                    </ul>
										
                                </div>
</td>
                  











	 </td>			 
           
					 
					 
          
             </tr>

             <?php endforeach; ?>

              <?php }?>

        </table>

									
		
<div id="viewleaves" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Leaves Report</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');

 $finalendate=date("Y-m-d 23:59:59");
  $finalstartdate=date("Y-m-d 00:00:00");
  
  
  


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/searchleaves' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

		


  
  
  
 <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Branch</label>
    <div class="col-sm-10">
				
				
				<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter --</option>
	<option value="all"  selected="selected"  >-All Branches/Counters--</option>

									
								
<?php
	     $mybranch=$this->usermodel->populateall('branch','id',$branchid);


if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){

   ?>
					<option  value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
	
	
	
	
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
				
		</div>
  </div>
				
  
  
  
  

  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$finalendate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  

  
	
  		  <div class="form-group" id="mysupplier">
    <label for="inputsupplier" class="col-sm-2 control-label"> Employee name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier" id="mysuppliers" autofocus value="<?php echo set_value('supplier',"all"); ?>" class="form-control"  placeholder="Enter Customer or supplier name ">
		 
				
		<span class="text-danger"> Enter "all" or enter Employee name<?php echo form_error('supplier'); ?>
		
		</span>
	</div>
	</div>
    

  
  			<div class="form-group">
    <label for="inputdepartment" class="col-sm-2 control-label">Department</label>
    <div class="col-sm-10">
	<select class="form-control" name="department" required>
		<option value="all"  >All</option>

	<option value=""  >---Select department---</option>

	<?php 	 
	
						$myemployee = $this->usermodel->populateall('department', 'id > ',1);


if(is_array($myemployee)) {

   foreach($myemployee as $myemployee){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $myemployee->id;   ?>"><?= $myemployee->firstname ." ".$myemployee->surname; ?></option>



	<?php

}} else {
    echo 'No  Employee.';
}
	
?>
	
			
				
				</select>
		
						<span class="text-danger"><?php echo form_error('status'); ?>

	</div>
  </div>
   
  
    
  <div class="form-group" >
    <label for="inputdownload" class="col-sm-2 control-label">Date Type </label>
    <div class="col-sm-10">
	<select class="form-control" name="category"   required>
	<option value="posteddate" selected="selected"   >Search By posted date</option>
	<option value="LeaveDate"  >	Search By Leave date</option>

	

</select>
		

		
	</div>
  </div>
  
  
  
  
  <div class="form-group" style="display:none">
    <label for="inputdownload" class="col-sm-2 control-label">Download messagees </label>
    <div class="col-sm-10">
	<select class="form-control" name="download"   required>
	<option value="no" selected="selected"   >No(Just Viewing)</option>
	<option value="yes"  >	Yes(Download Now) </option>

	

</select>
		

		
	</div>
  </div>
  
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="leave" name="btn_leavesforall" class="btn btn-primary"> View SMS  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>	

	
					
					
					
	
	<div id="deleteModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Delete</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to cancel this leave? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('adminlogged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="leaves">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/allleaves">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
  <input type="hidden" id="salaryid"name="salaryid" class="salaryid" placeholder="salaryid" value=""><br>

 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>			
	
	
	
	
	
				
									
									
							</div>
						</div>
				

			
			</div>
		</div>
  
  </div>
			
			
			
		
		
  

 
</div>


















