<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('38','views','R');     
$_SESSION['cuPages']='payr_levaplist.php';   
$cuPage='payr_levaplist.php';    
$aid=$_SESSION['uid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='payroll';
$menuh='Payroll';
$phead='levaplist';
$page='Leave Record';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php 
if(isset($_POST['delalv'])){
$id=$_POST['delalv'];
if(delete_check('tbl_salarysheet','lapid',$id)>0){
save_msg('w','Leave Application Depend On Other Table!!!');
echo "<script>window.location='payr_levaplist.php'</script>";
return;    
}
$name= get_fild_data('tbl_employe',get_fild_data('tbl_leaverequest',$id,'empid'),'name');    
$sql="DELETE FROM tbl_leaverequest WHERE id='$id'";
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
$efid=mysqli_affected_rows($con);    
if($efid>0){
$act =remove_junk(escape('Employee name: '.$name));    
write_activity($aid,'ALV','Leave request has been deleted',$act);        
save_msg('s','Leave request Successfully Deleted!!!');
}else{
save_msg('w','Leave request Fail to Delete!!!');    
}
echo "<script>window.location='payr_levaplist.php'</script>";
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
    
<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Leave Record</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<div class="col-md-12 table-responsive">
<table class="table table-bordered table-striped" id="datarec">
<thead>
<tr>
<th rowspan="2" style="width:40px;">SN</th>   
<th rowspan="2">Date</th>
<th rowspan="2">Employee</th>
<th rowspan="2">Leave</th>
<th style="text-align:center;" colspan="3">Details</th>
<th rowspan="2" style="text-align:center;">Status</th>    
<th rowspan="2" style="width:40px; text-align:center;">Action</th>    
</tr>
<tr>
<th style="text-align:center;">From</th>  
<th style="text-align:center;">To</th>  
<th style="text-align:center;">Days</th>      
</tr>    
</thead>    
<tbody>
<?php
$sql="SELECT tbl_leaverequest.id,tbl_leaverequest.lid,tbl_leave.name AS ltype,tbl_leaverequest.empid,tbl_employe.name AS employ,tbl_leaverequest.lfrom,tbl_leaverequest.lto,tbl_leaverequest.ldays,tbl_leaverequest.uid,tbl_leaverequest.status,tbl_leaverequest.apdate,tbl_leaverequest.date FROM tbl_leaverequest LEFT JOIN tbl_leave ON tbl_leave.id=tbl_leaverequest.lid LEFT JOIN tbl_employe ON tbl_leave.id=tbl_leaverequest.empid ORDER BY tbl_leaverequest.apdate DESC";    
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($row=mysqli_fetch_array($query)){
$id=$row['id'];
?>
<tr>
<td class="center"><?php echo count_id();?></td>
<td style="text-align:left;"><?php echo date("d M Y", strtotime($row['apdate']));?></td>    
<td><?php echo $row['employ'];?></td> 
<td><?php echo $row['ltype'];?></td>     
<td style="text-align:center;"><?php echo date("d M Y", strtotime($row['lfrom']));?></td>
<td style="text-align:center;"><?php echo date("d M Y", strtotime($row['lto']));?></td>    
<td style="text-align:center;"><?php echo $row['ldays'];?></td>
<td style="text-align:center; background-color:<?php 
if($row['status']=='2'){echo 'honeydew';}elseif($row['status']=='1'){echo 'lightgreen';}else{echo 'orangered';}    
?>"><?php 
if($row['status']=='2'){echo 'Pending';}elseif($row['status']=='1'){echo 'Approve';}else{echo 'Disapprove';}    
?></td>    
<td nowrap="" style="text-align:center;">
<a class="btn btn-flat bg-purple" href="#" onclick="edit_item('ED_<?php echo $row['id'];?>')"><i class="fa fa-edit"></i>
</a> <a class="btn btn-flat bg-purple" href="#" onclick="remove_item('DL_<?php echo $row['id'];?>')"><i class="fa fa-trash"></i></a>
<form action="payr_levaplist.php" id="DL_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="delalv" value="<?php echo $row['id']; ?>" />
</form>
<form action="payr_levapedit.php" id="ED_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="editalv" value="<?php echo $row['id']; ?>" />
</form>     
</td>    
</tr>    
<?php } ?>    
</tbody>   
</table>
</div>
<div class="clearfix" ></div>  
<div class="row"style="margin-top: 15px" >
<div class="col-md-12 table-responsive">    
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<a href="payr_levapcreate.php" class="btn btn-flat bg-purple">Add Application</a>
</div>
</div>    
</div>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['access']=='1'){echo read_activity($aid,'ALV','A');}else{echo read_activity($aid,'ALV','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>     
</section>
<!-- /.main content -->    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function() {
$('#datarec').DataTable({stateSave: true});
} );
    
function edit_item(id) {
document.getElementById(id).submit(); 
}
    
function remove_item(id) {
bootbox.confirm({
title: "Confirm",
message: "Are you sure to delete ?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-flat bg-purple'
},
cancel: {
label: 'Cancel',
className: 'btn-flat bg-gray'
}
},
callback: function (result) {
if (result == true) {
document.getElementById(id).submit();
}
}
});
}
</script>    
<!-- /page script -->
</html>    