(description) * @version GIT: $Id$ * @since Version 0.0.1 * @filesource * */ class Leave extends Admin_Controller { /** * [__construct description] * * @method __construct */ public function __construct() { // To inherit directly the attributes of the parent class. parent::__construct(); ### Syntax : $this->load->model('Model Path' , 'Alias name'); ### The second parameter (optional) is used to call the method. $this->load->model('MY_Model','MY_Model'); $this->load->model('Leave_model','Leave_model'); $this->load->model('Employee/Employee_model','Emp_model'); $this->load->model('Audit/Audit_model','audit_model'); $this->load->helper(array('form', 'url')); } public function index() { $this->layout->set('users', "gowtham"); $this->layout->buffer('main_content', 'Asset/index'); $this->layout->render('Employee_Layout'); } public function leaveList() { $business_id = user()->business_id; $leave_list = $this->Leave_model->get_leave_with_emp_name(user()->business_id); $leave_type = $this->Leave_model->get_leave_type($business_id); $decline_dropdown = $this->Leave_model->decline_dropdown($business_id); $this->layout->set('tableData', $leave_list); $this->layout->set('leave_type', $leave_type); $this->layout->set('dropdown', $decline_dropdown); $this->layout->buffer('main_content', 'Leave/leave_list'); $this->layout->render('Employee_Layout'); } public function leave_list_report() { $business_id = user()->business_id; $leave_list = $this->Leave_model->get_all_leave_data($business_id); $this->layout->set('leave_list', $leave_list); $this->layout->buffer('main_content', 'Leave/leave_list_report'); $this->layout->render('Employee_Layout'); } public function leave_list_report_exist() { $business_id = user()->business_id; $leave_list = $this->Leave_model->get_all_leave(user()->business_id); $resultArray = []; foreach ($leave_list as $entry) { $key = $entry->emp_id . '_' . $entry->type.'_'. date('m-Y', strtotime($entry->from_date_new)); if (!isset($resultArray[$key])) { if($entry->from_date_new != '') $entry->from_date_new = '( '.date('d-m-Y', strtotime($entry->from_date_new)).', '.date('d-m-Y', strtotime($entry->to_date_new)).' )'; $resultArray[$key] = $entry; } else { foreach ($entry as $field => $value) { if ($field == 'from_date_new' && $value != '') { $resultArray[$key]->$field .= '( '.date('d-m-Y', strtotime($entry->from_date_new)).', '.date('d-m-Y', strtotime($entry->to_date_new)).' )'; } if ($field == 'no_of_days') { $resultArray[$key]->$field += $value; } } } } $result = array_values($resultArray); // echo json_encode( $result, JSON_PRETTY_PRINT);die; $this->layout->set('leave_list', $result); $this->layout->buffer('main_content', 'Leave/leave_list_report'); $this->layout->render('Employee_Layout'); } public function applyLeave($update = null) { $business_id = user()->business_id; $user_id = user()->id; $emp = $this->Emp_model->get_employee(user()->business_id); $leave_master = $this->Leave_model->get_leave_master($business_id); $leavetype = $this->Leave_model->get_leave_master($business_id); $this->layout->set('emp', $emp); $this->layout->set('leave_master', $leave_master); $this->layout->set('leavetype', $leavetype); if($update == null) $this->session->set_flashdata('error', 0); $this->layout->buffer('main_content', 'Leave/apply_leave'); $this->layout->render('Employee_Layout'); } public function get_emp_leave_count() { $business_id = user()->business_id; $emp_id = $this->input->get('emp_id'); $type_id = $this->input->get('type_id'); $emp_leave_count = $this->Leave_model->get_count($emp_id, $business_id, $type_id); echo json_encode($emp_leave_count); } public function get_leave_master_count() { $business_id = user()->business_id; $type_id = $this->input->get('type_id'); // $year = $this->input->get('fromDate'); // $emp_id = $this->input->get('emp_id'); $emp_leave_count = $this->Leave_model->get_leave_master_count($type_id, $business_id); echo json_encode($emp_leave_count); } public function get_emp_name() { $emp = $this->Leave_model->get_employee(user()->business_id); $html = ''; foreach($emp as $val) { if($val->user_id != user()->id) { $html .=''; } } echo json_encode($html); } public function createLeave() { //permission type create part try { // echo base_url();die; // echo json_encode($this->input->post());die; if(!empty($this->input->post('from_time'))) { $perm_data = $this->input->post(); if(isset($perm_data['emp_id'])){ $emp_id =$this->input->post('emp_id'); }else{ $emp_id = user()->id; } $perm_data['emp_id'] = $emp_id; if($perm_data['manager']==""){ if(employee()->manager == null) { $manager = 0; } else { $manager = employee()->manager; } }else{ $manager = $this->input->post('manager'); } $perm_data['manager'] = $manager; $perm_data['business_id'] = user()->business_id; $perm_data['status'] = 'pending'; // $perm_data['created_date'] = date('d-m-Y'); $perm_data['created_date_new'] = date('Y-m-d'); $perm_data['created_time'] = date('h:i a'); unset($perm_data['from_date']); unset($perm_data['to_date']); unset($perm_data['from_date_new']); unset($perm_data['to_date_new']); $table="leave_list"; $perm_data['perm_date_new'] = date("Y-m-d", strtotime( $this->input->post('perm_date_new') )); $create_permission = $this->MY_Model->insert($perm_data,$table); // $create_permission = 221; //for notification if($create_permission){ $code = 'LEAVE_PERMISSION'; $type = 'Email'; $this->notification->sendNotification($create_permission, $code, $type); } $this->session->set_flashdata('Success', '1'); redirect('Leave/LeaveHistory'); } //end of permission //Leave create part $data = $this->input->post(); unset($data['perm_date']); unset($data['perm_date_new']); unset($data['from_time']); unset($data['to_time']); if(isset($data['emp_id'])){ $emp_id =$this->input->post('emp_id'); }else{ $emp_id = user()->id; } $data['emp_id'] = $emp_id; if($data['manager']==""){ if(employee()->manager == null) { $manager = 0; } else { $manager = employee()->manager; } }else{ $manager = $this->input->post('manager'); } $data['manager'] = $manager; $data['business_id'] = user()->business_id; $data['status'] = 'pending'; // $data['created_date'] = date('d-m-Y'); $data['created_date_new'] = date('Y-m-d'); $data['created_time'] = date('h:i a'); $leave_year = date('Y', strtotime($this->input->post('from_date_new'))); //get employee's leave count $emp_leave_count = $this->Leave_model->get_leave( $emp_id , user()->business_id , "emp_leave_days", $leave_year, $this->input->post('type')); $leave_master_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); // count number of days between two dates $days_between = ceil(abs(strtotime($this->input->post('to_date_new')) - strtotime($this->input->post('from_date_new'))) / 86400); $data['no_of_days'] = $days_between + 1; $noofdays = $days_between + 1; //this part is create and update leave data if (count($emp_leave_count) != 0) { if($noofdays > $emp_leave_count[0]->remaining_days) { $this->session->set_flashdata('error', '1'); redirect('Leave/applyLeave/'.'update'); } else { //this part is update if date inculeded in emp_leave_days table $data['leave_bal'] = $emp_leave_count[0]->remaining_days; $days['remaining_days'] = $emp_leave_count[0]->remaining_days; $this->Leave_model->update_leave($days, $emp_id , 'emp_leave_days', $leave_year, $this->input->post('type')); } } else { if($noofdays > $leave_master_count[0]->days) { $this->session->set_flashdata('error', '1'); redirect('Leave/applyLeave/'.'update'); } else { $all_leave_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); $data['leave_bal'] = $all_leave_count[0]->days; $days['remaining_days'] = $all_leave_count[0]->days; $days['business_id'] = user()->business_id; $days['emp_id'] = $emp_id; $days['total_days'] = $all_leave_count[0]->days; $days['type'] = $all_leave_count[0]->id; $days['year'] = $leave_year; $this->MY_Model->insert($days,'emp_leave_days'); } } $get_emp_data = $this->Leave_model->get_emp_data_by_emp_id($emp_id); // echo json_encode( $get_emp_data);die; // print_r($get_emp_data[0]->j_date); die; $from_date = new DateTime($this->input->post('from_date_new')); $j_date = new DateTime($get_emp_data[0]->j_date); $to_date = new DateTime($this->input->post('to_date_new')); if ($from_date >= $j_date && $from_date <= $to_date) { $table="leave_list"; $data['from_date_new'] = date("Y-m-d", strtotime( $this->input->post('from_date_new') )); $data['to_date_new'] = date("Y-m-d", strtotime( $this->input->post('to_date_new') )); // echo json_encode($data);die; $create_leave = $this->MY_Model->insert($data,$table); } else { $this->session->set_flashdata('error', '1'); redirect('Leave/applyLeave/'.'update'); } if($create_leave){ $code = 'APPLY_LEAVE'; $type = 'Email'; $mailres = $this->notification->sendNotification($create_leave, $code, $type); } //audit if($create_leave) { //set id $ table name for audit history $this->audit->set('id',$create_leave); $this->audit->set('table',$table); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $test = $this->audit->create_history('insert'); } $this->session->set_flashdata('Success', '1'); // $this->LeaveHistory(); redirect('Leave/LeaveHistory'); } catch (Exception $e) { echo "An error occurred: " . $e->getMessage(); } } public function edit_leave_function() { $id = $this->input->get('id'); $emp_leave_count = $this->Leave_model->get("emp_leave_days"); $emp = $this->Emp_model->get_employee(user()->business_id); $business_id = user()->business_id; $leavetype = $this->Leave_model->getLeaveType($business_id); $editleave = $this->Leave_model->editleave($id); // print_r($leavetype); // print_r($id); // print_r($editleave); // print_r($emp); // die; $this->layout->set('emp', $emp); $this->layout->set('editleave', $editleave); $this->layout->set('count', $emp_leave_count); $this->layout->set('leavetype', $leavetype); $this->layout->buffer('main_content', 'Leave/edit_leave'); $this->layout->render('Employee_Layout'); } public function editleave() { if($this->input->post('type') === '1') { $action = $this->input->post(); unset($action['from_date_new']); unset($action['to_date_new']); $id = $this->input->post('id'); if(isset($action['emp_id'])){ $emp_id =$this->input->post('emp_id'); }else{ $emp_id = user()->id; } $action['emp_id'] = $emp_id; if($action['manager']){ $manager = $this->input->post('manager'); }else{ $manager = employee()->manager; } $action['manager'] = $manager; $action['business_id'] = user()->business_id; $action['status'] = 'pending'; $action['perm_date_new'] = date('Y-m-d', strtotime($this->input->post('perm_date_new'))); $action['created_date'] = date('d-m-Y'); $action['created_time'] = date('h:i a'); $table="leave_list"; $create_permission = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('update', '0'); redirect('Leave/LeaveHistory'); } $action = $this->input->post(); $id = $this->input->post('id'); if(isset($action['emp_id'])){ $emp_id =$this->input->post('emp_id'); }else{ $emp_id = user()->id; } $action['emp_id'] = $emp_id; $action['business_id'] = user()->business_id; $action['status'] = 'pending'; $action['from_date_new'] = date('Y-m-d', strtotime($this->input->post('from_date_new'))); $action['to_date_new'] = date('Y-m-d', strtotime($this->input->post('to_date_new'))); $leave_year = date('Y', strtotime($this->input->post('from_date_new'))); $emp_leave_count = $this->Leave_model->get_leave( $emp_id , user()->business_id , "emp_leave_days", $leave_year, $this->input->post('type')); $leave_master_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); // count number of days between two dates $days_between = ceil(abs(strtotime(date('Y-m-d', strtotime($this->input->post('to_date_new')))) - strtotime(date('Y-m-d', strtotime($this->input->post('from_date_new'))))) / 86400); $action['no_of_days'] = $days_between + 1; $noofdays = $days_between + 1; $leave_id = $this->input->post('id'); if (count($emp_leave_count) != 0) { if($noofdays > $emp_leave_count[0]->remaining_days) { $this->session->set_flashdata('error', '1'); redirect('Leave/edit_leave_function?id='.md5($leave_id)); } else { //this part is update if date inculeded in emp_leave_days table $action['leave_bal'] = $emp_leave_count[0]->remaining_days; $days['remaining_days'] = $emp_leave_count[0]->remaining_days; $this->Leave_model->update_leave($days, $emp_id , 'emp_leave_days', $leave_year, $this->input->post('type')); } } else { if($noofdays > $leave_master_count[0]->days) { $this->session->set_flashdata('error', '1'); redirect('Leave/edit_leave_function?id='.md5($leave_id)); } else { $all_leave_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); $data['leave_bal'] = $all_leave_count[0]->days; $days['remaining_days'] = $all_leave_count[0]->days; $days['business_id'] = user()->business_id; $days['emp_id'] = $emp_id; $days['total_days'] = $all_leave_count[0]->days; $days['type'] = $all_leave_count[0]->id; $days['year'] = $leave_year; $this->MY_Model->insert($days,'emp_leave_days'); } } $get_from_date = $this->Leave_model->get_from_date($emp_id, $this->input->post('from_date_new'), $this->input->post('to_date_new')); if($get_from_date == 0) { $table="leave_list"; $update_leave = $this->MY_Model->edit_option($action,$id,$table); $this->session->set_flashdata('update', '0'); redirect('Leave/LeaveHistory'); } else { $this->session->set_flashdata('error', '1'); redirect('Leave/applyLeave/'.'update'); } } public function get_leave_count() { $id = $this->input->get('id'); $type_id = $this->input->get('type_id'); $year = date('Y'); $emp_leave_count = $this->Leave_model->get_leave_based_on_tpye($id, $type_id, user()->business_id, "emp_leave_days", $year); echo json_encode($emp_leave_count); } public function get_all_leave_count() { $id = $this->input->get('type_id'); $all_leave_count = $this->Leave_model->get_id( $id , user()->business_id , "leave_master"); echo json_encode($all_leave_count); } public function getDeleteConfirmationPopup() { $data = array(); $htmlPage = $this->load->view('confirmation_popup.php',$data,true); echo json_encode($htmlPage); } public function getDeclineConfirmationPopup() { $data = array(); $htmlPage = $this->load->view('confirmation_popup_2.php',$data,true); echo json_encode($htmlPage); } public function ApproveLeave() { $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_new)); $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); // print_r($leave_year); if($leave_type->leave_code !== 'permission') { $remaining_days = $this->Leave_model->remaining_days($emp_id,$business_id, $leave_year, $no_of_days->type); $balance_days = $remaining_days[0]->remaining_days - $no_of_days->no_of_days; // print_r($balance_days);die; $data['leave_bal'] = $balance_days; $days['remaining_days'] = $balance_days; $this->Leave_model->emp_leave_days_update($emp_id, $days, $leave_year, $business_id, $no_of_days->type); } $data['status'] = 'Approved'; $data['approved_by']= user()->id; $data['approved_at'] = date('d-m-Y H:i:s'); $leave_approve = $this->Leave_model->LeaveApprove($id, $data); if($leave_approve){ if($leave_type->leave_code === 'permission'){ $code = 'APPROVE_PERMISSION'; } else{ $code = 'APPROVE_LEAVE'; } $type = 'Email'; $this->notification->sendNotification($id, $code, $type); } redirect('Leave/leaveList'); } public function getManagerConfirmationPopup() { $data = array(); $htmlPage = $this->load->view('confirmation_popup.php',$data,true); echo json_encode($htmlPage); } public function ManagerLeaveApprove() { $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_new)); $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); $remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $no_of_days->type); $balance_days = $remaining_days[0]->remaining_days - $no_of_days->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, $business_id, $no_of_days->type); $data['status'] = 'Approved'; $data['approved_by']= user()->name; $data['approved_at'] = date('d-m-Y H:i:s'); $leave_approve = $this->Leave_model->LeaveApprove($id, $data); if($leave_approve){ if($leave_type->leave_code === 'permission'){ $code = 'APPROVE_PERMISSION'; } else{ $code = 'APPROVE_LEAVE'; } $type = 'Email'; $this->notification->sendNotification($id, $code, $type); } redirect('Leave/manager_approvel'); } public function Decline() { $id=$this->input->post('id'); $data['status'] = 'Declined'; $data['declined_by']= user()->name; $data['declined_at'] = date('d-m-Y H:i:s'); $data['DReason'] = $this->input->post('declinedata'); $leave_decline = $this->Leave_model->LeaveDecline($id, $data); $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); if($leave_decline){ if($leave_type->leave_code === 'permission'){ $code = 'DECLINE_PERMISSION'; } else{ $code = 'DECLINE_LEAVE'; } $type = 'Email'; $return = $this->notification->sendNotification($id, $code, $type); } redirect('Leave/leaveList'); } public function managerDecline() { $id=$this->input->post('id'); $data['status'] = 'Declined'; $data['declined_by']= user()->name; $data['declined_at'] = date('d-m-Y H:i:s'); $data['DReason'] = $this->input->post('declinedata'); $leave_decline = $this->Leave_model->LeaveDecline($id, $data); $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); if($leave_decline){ if($leave_type->leave_code === 'permission'){ $code = 'DECLINE_PERMISSION'; } else{ $code = 'DECLINE_LEAVE'; } $type = 'Email'; $return = $this->notification->sendNotification($id, $code, $type); } redirect('Leave/manager_approvel'); } public function cancled() { $id=$this->input->get('id'); $data['status'] = 'canceled'; $data['cancled_at'] = date('d-m-Y H:i:s'); $this->Leave_model->Leavecancle($id, $data); $this->session->set_flashdata('Success', 'Leave canceled Successfully'); 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() { $business_id = user()->business_id; $leave_list = $this->Leave_model->get_leave_with_emp_name(user()->business_id); $leave_type = $this->Leave_model->get_leave_type($business_id); $this->layout->set('tableData', $leave_list); $this->layout->set('leave_type', $leave_type); $this->layout->buffer('main_content', 'Leave/leavehistory'); $this->layout->render('Employee_Layout'); } public function manager_approvel() { $business_id = user()->business_id; $user_id = user()->id; $manager = $this->Leave_model->under_emp_manager($user_id, $business_id); $decline_dropdown = $this->Leave_model->decline_dropdown($business_id); $leave_list = $this->Leave_model->get_all_leave_request_by_manager_id(user()->business_id, user()->id); $leave_list_with_delegation = $this->Leave_model->get_all_leave_request_by_manager_id_with_delegation(user()->business_id, user()->id); if($leave_list_with_delegation == NULL){ $leave_list_with_delegation = []; } $mergedArray = array_merge($leave_list, $leave_list_with_delegation); $this->layout->set('tableData', $mergedArray); $this->layout->set('dropdown', $decline_dropdown); $this->layout->set('manager', $manager); $this->layout->buffer('main_content', 'Leave/manager_approvel'); $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_new)); $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_new)); $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); $data['weekApprovedData'] = $this->Leave_model->get_week_leave_approved_count($business_id); // echo print_r($data['weekData']);die; $this->layout->buffer('main_content', 'Leave/dashboard',$data); $this->layout->render('Employee_Layout'); } public function leavedashboard() { redirect('Leave/dashboard'); } }