withdraw and employ list

This commit is contained in:
heama 2024-01-30 15:19:40 +05:30
parent 2f8556de64
commit 4c331afa21
6 changed files with 562 additions and 92 deletions

View File

@ -90,7 +90,7 @@
<li><a><i class="fa fa-calendar-times-o"></i> Leaves <span class="fa fa-chevron-down"></span></a> <li><a><i class="fa fa-calendar-times-o"></i> Leaves <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu"> <ul class="nav child_menu">
<li><a href="<?php echo base_url();?>Leave/leavedashboard">Dashboard</a></li>
<li><a href="<?php echo base_url();?>Leave/leavehistory">My Leaves</a></li> <li><a href="<?php echo base_url();?>Leave/leavehistory">My Leaves</a></li>
<li><a href="<?php echo base_url();?>Leave/applyLeave">Apply Leave</a></li> <li><a href="<?php echo base_url();?>Leave/applyLeave">Apply Leave</a></li>
@ -188,4 +188,3 @@
<!-- /menu footer buttons --> <!-- /menu footer buttons -->
</div> </div>

View File

@ -596,6 +596,15 @@ public function cancled()
$this->session->set_flashdata('Success', 'Leave canceled Successfully'); $this->session->set_flashdata('Success', 'Leave canceled Successfully');
redirect('Leave/LeaveHistory'); redirect('Leave/LeaveHistory');
} }
public function withdraw()
{
$id=$this->input->get('id');
$data['status'] = 'withdraw-pending';
$data['cancled_at'] = date('d-m-Y H:i:s');
$this->Leave_model->Leavecanceaprove($id, $data);
$this->session->set_flashdata('Success', 'Leave canceled Successfully');
redirect('Leave/LeaveHistory');
}
public function LeaveHistory() public function LeaveHistory()
{ {
@ -629,6 +638,110 @@ public function manager_approvel()
$this->layout->render('Employee_Layout'); $this->layout->render('Employee_Layout');
} }
public function DeclinewithdrawLeave()
{
$id=$this->input->post('id');
$business_id = user()->business_id;
$emp_id = $this->Leave_model->get_emp_id($id);
$no_of_days = $this->Leave_model->get_Leave_nodays($id,);
$leave_year = date('Y', strtotime($no_of_days->from_date));
$leave_type = $this->Leave_model->get_leave_data_using_leave_id($id);
if($leave_type->leave_code !== 'permission')
$data['status'] = 'Withdraw-declined';
$data['declined_by']= user()->id;
$data['declined_at'] = date('d-m-Y H:i:s');
$data['DReason'] = $this->input->post('declinedata');
$leave_approve = $this->Leave_model->LeavewithdrawDecline($id, $data);
$emp_id = $this->Leave_model->get_emp_id($id);
$this->Leave_model->emp_leave_days_update($emp_id, $days, $leave_year, user()->business_id, $leave_data->type);
if($leave_approve){
if($leave_type->leave_code === 'permission'){
$code = 'APPROVE_Withdraw';
}
else{
$code = 'DECLINE_WITHDRAW_LEAVE';
}
$type = 'Email';
$this->notification->sendNotification($id, $code, $type);
}
redirect('Leave/leaveList');
}
public function ApprovewithdrawLeave()
{
$id = $this->input->post('id');
$leave_data = $this->Leave_model->get_Leave_nodays($id);
$data['status'] = 'Withdraw-Approved';
$data['approved_by'] = user()->name;
$data['approved_at'] = date('d-m-Y H:i:s');
// Update leave balance
$emp_id = $this->Leave_model->get_emp_id($id);
$leave_year = date('Y', strtotime($leave_data->from_date));
$remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $leave_data->type);
$balance_days = $remaining_days[0]->remaining_days + $leave_data->no_of_days;
$data['leave_bal'] = $balance_days;
$days['remaining_days'] = $balance_days;
$this->Leave_model->emp_leave_days_update($emp_id, $days, $leave_year, user()->business_id, $leave_data->type);
// Approve the leave withdrawal
$leave_approve = $this->Leave_model->LeavewithdrawApproved($id, $data);
// Send notification
$leave_type = $this->Leave_model->get_leave_data_using_leave_id($id);
if ($leave_approve) {
if ($leave_type->leave_code === 'permission') {
$code = 'APPROVE_Withdraw';
} else {
$code = 'APPROVE_WITHDRAW_LEAVE';
}
$type = 'Email';
$this->notification->sendNotification($id, $code, $type);
}
redirect('Leave/leaveList');
}
// public function dashboard()
// {
// $business_id = user()->business_id;
// // Replace 123 with the actual business_id
// // $this->load->view('Leave/dashboard', $data);
// $data['leaveData'] = $this->Leave_model->get_all_leave_data($business_id);
// $this->layout->buffer('main_content', 'Leave/dashboard',$data);
// $this->layout->render('Employee_Layout');
// }
// public function leavedashboard()
// {
// redirect('Leave/dashboard');
// }
public function dashboard()
{
$business_id = user()->business_id;
// Replace 123 with the actual business_id
// $this->load->view('Leave/dashboard', $data);
$data['weekData'] = $this->Leave_model->get_approved_leaves_cur_week($business_id);
$this->layout->buffer('main_content', 'Leave/dashboard',$data);
$this->layout->render('Employee_Layout');
}
public function leavedashboard()
{
redirect('Leave/dashboard');
}
} }

View File

@ -277,6 +277,23 @@ public function LeaveApprove($id, $data)
$this->db->update('leave_list', $data); $this->db->update('leave_list', $data);
return true; return true;
}
public function LeavewithdrawDecline($id, $data)
{
$this->db->where('id',$id);
// $this->db->update('emp_leave_days', $data);
$this->db->update('leave_list', $data);
return true;
}
public function LeavewithdrawApproved($id, $data)
{
$this->db->where('id',$id);
$this->db->update('leave_list', $data);
return true;
} }
public function LeaveDecline($id, $data) public function LeaveDecline($id, $data)
@ -294,7 +311,13 @@ public function Leavecancle($id, $data)
$this->db->update('leave_list', $data); $this->db->update('leave_list', $data);
return; return;
} }
public function Leavecanceaprove($id, $data)
{
$this->db->where('md5(id)',$id);
$this->db->where('status', 'Approved');
$this->db->update('leave_list', $data);
return;
}
public function getLeaveType($business_id) public function getLeaveType($business_id)
@ -494,4 +517,102 @@ public function get_emp_data_by_emp_id($emp_id){
$query = $query->result(); $query = $query->result();
return $query; return $query;
} }
public function get_approved_leaves_cur_week()
{
$currentWeekStart = date('Y-m-d', strtotime('monday this week'));
$currentWeekEnd = date('Y-m-d', strtotime('sunday this week'));
$this->db->select('leave_list.*, users.name as emp_name');
$this->db->from('leave_list');
$this->db->join('users', 'users.id = leave_list.emp_id', 'left');
$this->db->group_start();
$this->db->where("STR_TO_DATE(from_date, '%d-%m-%Y') <= '$currentWeekEnd'");
$this->db->where("STR_TO_DATE(to_date, '%d-%m-%Y') >= '$currentWeekStart'");
$this->db->or_where("STR_TO_DATE(perm_date, '%d-%m-%Y') <= '$currentWeekEnd'");
$this->db->or_where("STR_TO_DATE(perm_date, '%d-%m-%Y') >= '$currentWeekStart'");
$this->db->group_end();
$this->db->where('leave_list.status', 'approved');
$query = $this->db->get();
$approvedLeaveRecords = $query->result();
// Organize approved leave records into columns based on days of the week
$weekData = [];
foreach ($approvedLeaveRecords as $leave) {
$leaveStartDate = ($leave->from_date) ? date('Y-m-d', strtotime($leave->from_date)) : date('Y-m-d', strtotime($leave->perm_date));
$leaveEndDate = ($leave->to_date) ? date('Y-m-d', strtotime($leave->to_date)) : date('Y-m-d', strtotime($leave->perm_date));
// Use from_time and to_time if available
$fromTime = ($leave->from_time) ? ' ' . $leave->from_time : '';
$toTime = ($leave->to_time) ? ' ' . $leave->to_time : '';
// Iterate over each day in the leave period
$currentDate = $leaveStartDate;
while ($currentDate <= $leaveEndDate) {
$dayOfWeek = date('l', strtotime($currentDate));
$weekData[$dayOfWeek][] = [
'emp_id' => $leave->emp_id,
'emp_name' => $leave->emp_name,
'from_time' => $fromTime,
'to_time' => $toTime,
];
$currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
}
}
// print_r($weekData);
return $weekData;
}
// public function get_all_leave_data($business_id){
// $this->db->select('leave_list.*, employees.*, users.*, leave_master.*, (SELECT MAX(remaining_days) FROM emp_leave_days WHERE emp_id = leave_list.emp_id) as leave_balance');
// $this->db->from('leave_list');
// $this->db->join('users', 'leave_list.emp_id = users.id', 'left');
// $this->db->join('employees', 'leave_list.emp_id = employees.user_id', 'left');
// $this->db->join('leave_master', 'leave_list.type = leave_master.id', 'left');
// $this->db->select_sum('leave_list.no_of_days', 'total_leave_days');
// $this->db->select('SUM(CASE WHEN leave_master.type = "permission" THEN 1 ELSE 0 END) as permission_count');
// $this->db->group_by('leave_list.emp_id');
// $query = $this->db->get();
// print_r($this->db->last_query());
// return $query->result();
// }
// public function get_all_leave_data($business_id) {
// $this->db->select('leave_list.*, employees.*, users.*, leave_master.*, leave_list.leave_bal');
// $this->db->from('leave_list');
// $this->db->join('users', 'leave_list.emp_id = users.id', 'left');
// $this->db->join('employees', 'leave_list.emp_id = employees.user_id', 'left');
// $this->db->join('leave_master', 'leave_list.type = leave_master.id', 'left');
// // Subquery to get the last inserted leave balance for each employee
// $subquery = $this->db->select('MAX(id) as max_id')
// ->from('leave_list ll')
// ->where('ll.emp_id = leave_list.emp_id', null, false)
// ->get_compiled_select();
// $this->db->join("($subquery) as latest_leave", 'leave_list.id = latest_leave.max_id', 'left');
// $this->db->group_by('leave_list.emp_id');
// $query = $this->db->get();
// print_r($this->db->last_query());
// return $query->result();
// }
} }

View File

@ -0,0 +1,175 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css'>
<style>
.alert-success {
background-color: #dff0d8;
color: #3c763d;
border-color: #d6e9c6;
}
.flash-message {
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
margin-left: 650px;
}
div.dataTables_wrapper div.dataTables_filter {
margin-top: -30px !important;
}
/* Add a CSS class for highlighting the current date */
table#datatables th {
background-color: #C8E4E7;
}
/* Set the background color of the current date heading */
table#datatables th.current-date {
background-color: #A8E7CF;
}
/* table#datatables th:not(.current-date):first-child,
table#datatables td:first-child:not(.current-date) {
background-color: #BEEEE6;
} */
</style>
</head>
<body>
<div class="col-md-12 col-sm-12 ">
<div class="x_panel">
<div class="x_title">
<button hidden id="button" class="btn btn-secondary source" onclick="new PNotify({
text: '<html><h2>Submited for Approval.<h2></html>',
type: 'success',
styling: 'bootstrap3'
});">Success</button>
<input type="hidden" id="error" value="<?php echo $this->session->userdata('Success'); ?>">
<?php $this->session->unset_userdata('Success'); ?>
<script>
$(document).ready(function () {
if ($('#error').val() == 1) {
$('#button').click();
}
})
</script>
<ul class="nav navbar-right panel_toolbox"></ul>
<h1>Employ Leave List</h1>
<div class="clearfix"></div>
</div>
<div class="x_content">
<div class="row">
<div class="col-sm-12">
<table id="datatables" class="table table-striped table-bordered" width="100%">
<tr>
<?php
// Get the start date of the current week
$currentDate = date('Y-m-d', strtotime('monday this week'));
// Iterate over the days of the current week
for ($i = 0; $i < 7; $i++) {
$dayOfWeek = date('l', strtotime($currentDate));
$formattedDate = date('d-m-Y', strtotime($currentDate));
// Add a CSS class for the current date
$class = ($currentDate == date('Y-m-d')) ? ' class="current-date"' : '';
// Display the date and day, but skip Sunday
if ($dayOfWeek !== 'Sunday') {
echo '<th' . $class . '><h2>' . $dayOfWeek . '</h2><span>(' . $formattedDate . ')</span></th>';
}
// Move to the next day
$currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
}
?>
</tr>
<tr>
<?php
// Reset the current date to the start date of the current week
$currentDate = date('Y-m-d', strtotime('monday this week'));
// Iterate over the days of the current week
for ($i = 0; $i < 7; $i++) {
$dayOfWeek = date('l', strtotime($currentDate));
// Skip Sunday
if ($dayOfWeek !== 'Sunday') {
echo '<td>';
// Check if there are leave records for the current day
if (array_key_exists($dayOfWeek, $weekData)) {
foreach ($weekData[$dayOfWeek] as $leaveRecord) {
if (empty($leaveRecord['from_time']) && empty($leaveRecord['to_time'])) {
// Display leave records for the day
echo $leaveRecord['emp_name'] . '<br>' . $leaveRecord['from_time'] . $leaveRecord['to_time'] . '<br>';
}
}
} else {
// No leave records for the day
}
echo '</td>';
}
// Move to the next day
$currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
}
?>
</tr>
<tr>
<?php
// Reset the current date to the start date of the current week
$currentDate = date('Y-m-d', strtotime('monday this week'));
// Iterate over the days of the current week
for ($i = 0; $i < 7; $i++) {
$dayOfWeek = date('l', strtotime($currentDate));
// Skip Sunday
if ($dayOfWeek !== 'Sunday') {
echo '<td>';
// Check if there are leave records for the current day
if (array_key_exists($dayOfWeek, $weekData)) {
foreach ($weekData[$dayOfWeek] as $leaveRecord) {
if (!empty($leaveRecord['from_time']) && !empty($leaveRecord['to_time'])) {
echo $leaveRecord['emp_name'] . '<br>' . $leaveRecord['from_time'] . $leaveRecord['to_time'] . '<br>';
}
}
} else {
// No leave records for the day
// echo 'No Leave';
}
echo '</td>';
}
// Move to the next day
$currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
}
?>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<br />
<!-- Large modal -->
<div class="modal fade bs-example-modal-lg" id="ItemModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
<div class="modal bs-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true" id="popup"> </div>
<div style="display:none" id="sub-value"></div>
</body>
</html>

View File

@ -110,6 +110,18 @@
<?php } <?php }
else if($value->status == 'canceled'){ ?> else if($value->status == 'canceled'){ ?>
<td style="color:darkcyan;"><?php echo $value->status; ?></td> <td style="color:darkcyan;"><?php echo $value->status; ?></td>
<?php }
else if($value->status == 'withdraw-pending'){ ?>
<td style="color:#e68a00"><?php echo $value->status; ?></td>
<?php }
else if($value->status == 'Withdraw-declined'){ ?>
<td style="color:red;"><?php echo $value->status; ?> By
<?php echo $value->declined_by; ?> <br>" <?php echo $value->DReason; ?> "</td></td>
<?php }
else if($value->status == 'Withdraw-Approved'){ ?>
<td style="color:green"><?php echo $value->status; ?> By
<?php echo $value->ApproveBy; ?><br><?php echo $value->approved_at; ?></td>
<?php } <?php }
else{ else{
}?> }?>
@ -120,7 +132,13 @@
<a><i class="fa fa-check approveleave" data-toggle="modal" data-target=".bs-example-modal-sm" title="Approve" id="<?php echo $value->id;?>"></i></a>&nbsp; <a><i class="fa fa-check approveleave" data-toggle="modal" data-target=".bs-example-modal-sm" title="Approve" id="<?php echo $value->id;?>"></i></a>&nbsp;
<a><i class="fa fa-times test" data-toggle="modal" data-target=".bs-example-modal-sm" title="Decline" id="<?php echo $value->id;?>"></i></a>&nbsp; <a><i class="fa fa-times test" data-toggle="modal" data-target=".bs-example-modal-sm" title="Decline" id="<?php echo $value->id;?>"></i></a>&nbsp;
<!-- <a href="#"><i class="fa fa-times test" aria-hidden="true" title="Decline" onclick="showCustomPrompt()" id="<?php echo $value->id; ?>"></i></a>&nbsp; --> <!-- <a href="#"><i class="fa fa-times test" aria-hidden="true" title="Decline" onclick="showCustomPrompt()" id="<?php echo $value->id; ?>"></i></a>&nbsp; -->
<?php } ?>
<?php } else if ($value->status == 'withdraw-pending') { ?>
<a><i class="fa fa-check approveleave1" data-toggle="modal" data-target=".bs-example-modal-sm" title="Approve" id="<?php echo $value->id;?>"></i></a>&nbsp;
<a><i class="fa fa-times test1" data-toggle="modal" data-target=".bs-example-modal-sm" title="Decline" id="<?php echo $value->id;?>"></i></a>&nbsp;
<?php } ?>
</td> </td>
</tr> </tr>
<?php } } } ?> <?php } } } ?>
@ -173,6 +191,21 @@
} }
}); });
}); });
$('.approveleave1').click(function() {
var id = $(this).attr('id');
var url = "<?php echo base_url()?>Leave/ApprovewithdrawLeave";
$.ajax({
url: "<?php echo base_url()?>Leave/getDeleteConfirmationPopup",
type: "GET",
success: function(data) {
$('#popup').html(JSON.parse(data));
$('.delete_id').attr('value', id);
$('.delete_url').attr('action', url);
}
});
});
$('.test').click(function() { $('.test').click(function() {
var id = $(this).attr('id'); var id = $(this).attr('id');
@ -188,6 +221,20 @@
} }
}); });
}); });
$('.test1').click(function() {
var id = $(this).attr('id');
var url = "<?php echo base_url()?>Leave/DeclinewithdrawLeave";
$.ajax({
url: "<?php echo base_url()?>Leave/getDeclineConfirmationPopup",
type: "GET",
success: function(data) {
$('#popup').html(JSON.parse(data));
$('.delete_id').attr('value', id);
$('.delete_url').attr('action', url);
}
});
});
$(document).on('click', '.bi-card-list', function() { $(document).on('click', '.bi-card-list', function() {

View File

@ -112,6 +112,17 @@
else if($value->status == 'canceled'){ ?> else if($value->status == 'canceled'){ ?>
<td style="color:darkcyan;"><?php echo $value->status; ?></td> <td style="color:darkcyan;"><?php echo $value->status; ?></td>
<?php } <?php }
else if($value->status == 'withdraw-pending'){ ?>
<td style="color:#e68a00"><?php echo $value->status; ?></td>
<?php }
else if($value->status == 'Withdraw-declined'){ ?>
<td style="color:red"><?php echo $value->status; ?> By <?php echo $value->DeclineBy; ?> <br> <?php echo $value->DReason; ?></td>
<?php }
else if($value->status == 'Withdraw-Approved'){ ?>
<td style="color:green;"><?php echo $value->status; ?></td>
<?php }
else{ else{
}?> }?>
@ -122,8 +133,12 @@
<a href="<?php echo base_url('Leave/edit_leave_function')?>?id=<?php echo md5($value->id);?> "><i class="fa fa-edit" aria-hidden="true"title="Edit"></i></a> &nbsp; <a href="<?php echo base_url('Leave/edit_leave_function')?>?id=<?php echo md5($value->id);?> "><i class="fa fa-edit" aria-hidden="true"title="Edit"></i></a> &nbsp;
<a href="<?php echo base_url('Leave/cancled')?>?id=<?php echo md5($value->id);?> "><i class="fa fa-ban" aria-hidden="true"title="Cancel"></i></a> &nbsp; <a href="<?php echo base_url('Leave/cancled')?>?id=<?php echo md5($value->id);?> "><i class="fa fa-ban" aria-hidden="true"title="Cancel"></i></a> &nbsp;
<?php } else if ($value->status == 'Approved') { ?>
<a href="<?php echo base_url('Leave/withdraw')?>?id=<?php echo md5($value->id);?> "><i class="fa fa-ban" aria-hidden="true"title="Cancel"></i></a> &nbsp;
<?php } ?>
<?php } ?>
</td> </td>