497 lines
16 KiB
PHP
497 lines
16 KiB
PHP
<?php
|
|
class Leave_model extends MY_Model {
|
|
|
|
public function get_leave_with_emp_name($business_id)
|
|
{
|
|
$this->db->select('A.* ,U1.name as emp_name, U2.name as ApproveBy, U3.name as DeclineBy, U4.name as Risedby');
|
|
$this->db->from('leave_list A');
|
|
$this->db->join('users U1', 'U1.id = A.emp_id', 'left');
|
|
$this->db->join('users U2', 'U2.id = A.approved_by', 'left');
|
|
$this->db->join('users U3', 'U3.id = A.declined_by', 'left');
|
|
$this->db->join('users U4', 'U4.id = A.risedby', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->order_by('A.id','DESC');
|
|
$this->db->where('A.is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
|
|
}
|
|
|
|
public function get_leave_data_using_leave_id($leave_id)
|
|
{
|
|
$this->db->select('A.* ,U1.name as emp_name, U1.email as emp_email, U2.name as ApproveBy, U3.name as DeclineBy, U4.name as Risedby, E.manager as ManagerId, LM.code as leave_code, LM.type as leave_type');
|
|
$this->db->from('leave_list A');
|
|
$this->db->join('users U1', 'U1.id = A.emp_id', 'left');
|
|
$this->db->join('users U2', 'U2.id = A.approved_by', 'left');
|
|
$this->db->join('users U3', 'U3.id = A.declined_by', 'left');
|
|
$this->db->join('users U4', 'U4.id = A.risedby', 'left');
|
|
$this->db->join('employees E', 'E.user_id = A.emp_id', 'left');
|
|
$this->db->join('leave_master LM', 'LM.id = A.type', 'left');
|
|
$this->db->where('A.id', $leave_id);
|
|
$this->db->order_by('A.id','DESC');
|
|
$this->db->where('A.is_active', 1);
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() > 0) {
|
|
return $row = $query->row();
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function get_template_data_using_code($code, $type){
|
|
$this->db->select('*');
|
|
$this->db->from('templates');
|
|
$this->db->where('templet_code', $code);
|
|
$this->db->where('templet_type', $type);
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->row();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
public function get_user_name($user_id){
|
|
|
|
$this->db->select('name');
|
|
$this->db->from('users');
|
|
$this->db->where('id', $user_id);
|
|
$query = $this->db->get();
|
|
// $query = $query->result();
|
|
if ($query->num_rows() > 0) {
|
|
$row = $query->row();
|
|
return $row->name;
|
|
} else {
|
|
return false;
|
|
}
|
|
// return $query;
|
|
|
|
}
|
|
|
|
public function get_all_leave_request_by_manager_id($business_id, $user_id)
|
|
{
|
|
$this->db->select('A.* ,U1.name as emp_name, U2.name as ApproveBy, U3.name as DeclineBy, U4.name as Risedby, E.manager as manager_id, LM.type as leave_type');
|
|
$this->db->from('leave_list A');
|
|
$this->db->join('users U1', 'U1.id = A.emp_id', 'left');
|
|
$this->db->join('users U2', 'U2.id = A.approved_by', 'left');
|
|
$this->db->join('users U3', 'U3.id = A.declined_by', 'left');
|
|
$this->db->join('users U4', 'U4.id = A.risedby', 'left');
|
|
$this->db->join('employees E', 'E.user_id = A.emp_id', 'left');
|
|
$this->db->join('leave_master LM', 'LM.id = A.type', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('E.manager', $user_id);
|
|
$this->db->order_by('A.id','DESC');
|
|
$this->db->where('A.is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
|
|
}
|
|
|
|
public function get_delegated_user_id($business_id, $user_id){
|
|
$this->db->select('emp_id');
|
|
$this->db->from('delegation');
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('delegated_to', $user_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$result_array = $query->result_array();
|
|
$emp_ids = array_column($result_array, 'emp_id');
|
|
return $emp_ids;
|
|
}
|
|
|
|
public function get_all_leave_request_by_manager_id_with_delegation($business_id, $loggeduserid)
|
|
{
|
|
|
|
$delegated_users_id_list = $this->get_delegated_user_id($business_id, $loggeduserid);
|
|
$count = count($delegated_users_id_list);
|
|
|
|
if($count > 0)
|
|
{
|
|
foreach ($delegated_users_id_list as $user_id) {
|
|
|
|
$this->db->select('A.* ,U1.name as emp_name, U2.name as ApproveBy, U3.name as DeclineBy, U4.name as Risedby, E.manager as manager_id, LM.type as leave_type, D.from_date as delegate_f_date, D.to_date as delegate_t_date, D.delegated_to, D.emp_id');
|
|
$this->db->from('leave_list A');
|
|
$this->db->join('users U1', 'U1.id = A.emp_id', 'left');
|
|
$this->db->join('users U2', 'U2.id = A.approved_by', 'left');
|
|
$this->db->join('users U3', 'U3.id = A.declined_by', 'left');
|
|
$this->db->join('users U4', 'U4.id = A.risedby', 'left');
|
|
$this->db->join('employees E', 'E.user_id = A.emp_id', 'left');
|
|
$this->db->join('delegation D', 'D.business_id = A.business_id', 'left');
|
|
$this->db->join('leave_master LM', 'LM.id = A.type', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('E.manager', $user_id); //User ID as Employee ID
|
|
// $this->db->where('D.emp_id', $user_id);
|
|
$this->db->order_by('A.id','DESC');
|
|
$this->db->where('A.is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function get_count($emp_id, $business_id, $type_id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('emp_leave_days');
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('emp_id', $emp_id);
|
|
$this->db->where('type', $type_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
|
|
}
|
|
|
|
public function remaining_days($emp_id, $business_id, $leave_year, $type)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('emp_leave_days');
|
|
$this->db->where('emp_id', $emp_id);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('year', $leave_year);
|
|
$this->db->where('type', $type);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
// public function remaining_days_2($emp_id, $business_id, $next_year, $type)
|
|
// {
|
|
// $this->db->select('*');
|
|
// $this->db->from('emp_leave_days');
|
|
// $this->db->where('emp_id', $emp_id);
|
|
// $this->db->where('business_id', $business_id);
|
|
// $this->db->where('year', $next_year);
|
|
// $this->db->where('type', $type);
|
|
// $this->db->where('is_active', 1);
|
|
// $query = $this->db->get();
|
|
// $query = $query->row();
|
|
// return $query;
|
|
// }
|
|
|
|
function get_id($id,$business_id,$table)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from($table);
|
|
$this->db->where('id', $id);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
function get_by_type($type,$business_id,$table)
|
|
{
|
|
$this->db->select();
|
|
$this->db->from($table);
|
|
$this->db->where('id', $type);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_employee($business_id)
|
|
{
|
|
|
|
$this->db->select('users.name, employees.user_id, employees.manager');
|
|
$this->db->from('users');
|
|
$this->db->join('employees', 'employees.user_id = users.id');
|
|
$this->db->where('users.business_id', $business_id);
|
|
$this->db->where('users.is_active', 1);
|
|
$this->db->where('employees.is_active', 1);
|
|
$query = $this->db->get();
|
|
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function get_leave($id , $business_id , $table, $leave_year, $type)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from($table);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('emp_id', $id);
|
|
$this->db->where('type', $type);
|
|
$this->db->where('year', $leave_year);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_leave_based_on_tpye($id , $type , $business_id , $table, $year)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from($table);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('emp_id', $id);
|
|
$this->db->where('type', $type);
|
|
$this->db->where('year', $year);
|
|
$this->db->order_by('id','DESC');
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_leave_by_md5_id($id,$business_id,$table)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from($table);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('md5(id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->row();
|
|
return $query;
|
|
}
|
|
|
|
function update_leave($action,$id,$table,$current_year,$type_id){
|
|
$this->db->where('emp_id',$id);
|
|
$this->db->where('type', $type_id);
|
|
$this->db->where('year', $current_year);
|
|
$this->db->update($table,$action);
|
|
return;
|
|
}
|
|
|
|
public function LeaveApprove($id, $data)
|
|
{
|
|
|
|
$this->db->where('id',$id);
|
|
$this->db->update('leave_list', $data);
|
|
return true;
|
|
|
|
}
|
|
|
|
public function LeaveDecline($id, $data)
|
|
{
|
|
$this->db->where('id',$id);
|
|
$this->db->where('status', 'pending');
|
|
$this->db->update('leave_list', $data);
|
|
return true;
|
|
}
|
|
|
|
public function Leavecancle($id, $data)
|
|
{
|
|
$this->db->where('md5(id)',$id);
|
|
$this->db->where('status', 'pending');
|
|
$this->db->update('leave_list', $data);
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
public function getLeaveType($business_id)
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('leave_master');
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('is_active', 1);
|
|
return $this->db->get()->result();
|
|
|
|
}
|
|
|
|
|
|
public function get_Leave_nodays($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('leave_list');
|
|
$this->db->where('id',$id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->row();
|
|
return $query;
|
|
}
|
|
|
|
public function emp_leave_days_update($id, $days, $current_year, $business_id, $type)
|
|
{
|
|
$this->db->where('emp_id',$id);
|
|
$this->db->where('year', $current_year);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('type', $type);
|
|
$this->db->update('emp_leave_days', $days);
|
|
}
|
|
|
|
// public function emp_leave_days_update_2($id, $days, $next_year, $business_id, $type)
|
|
// {
|
|
// $this->db->where('emp_id',$id);
|
|
// $this->db->where('year', $next_year);
|
|
// $this->db->where('business_id', $business_id);
|
|
// $this->db->where('type', $type);
|
|
// $this->db->update('emp_leave_days', $days);
|
|
// }
|
|
|
|
public function get_emp_id($id)
|
|
{
|
|
$this->db->select('emp_id');
|
|
$this->db->where('id', $id); // Assuming $leaveListId is the ID to match
|
|
$query = $this->db->get('leave_list');
|
|
|
|
if ($query->num_rows() > 0) {
|
|
$row = $query->row();
|
|
$empId = $row->emp_id;
|
|
return $empId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function under_emp_manager($user_id, $business_id)
|
|
{
|
|
$this->db->select('manager');
|
|
$this->db->from('employees');
|
|
$this->db->where('business_id', $business_id);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
}
|
|
|
|
|
|
public function editleave($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('leave_list');
|
|
$this->db->where('md5(id)', $id);
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function decline_dropdown($business_id)
|
|
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('enum');
|
|
$this->db->where('enum_type', 'decline');
|
|
$this->db->where('business_id', $business_id);
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
public function Get_delegation_id($business_id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('delegation');
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
}
|
|
|
|
public function get_emp_leave_count($type_id, $emp_id)
|
|
{
|
|
$this->db->select('remaining_days');
|
|
$this->db->from('emp_leave_days');
|
|
$this->db->where('emp_id', $emp_id);
|
|
$this->db->where('type', $type_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
public function get_leave_master($business_id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('leave_master');
|
|
$this->db->where('(business_id = 0 OR business_id = ' . $business_id . ')');
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$result = $query->result();
|
|
return $result;
|
|
|
|
}
|
|
|
|
public function get_leave_master_count($type_id, $business_id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('leave_master');
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('id', $type_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_emp_joing_year_month($emp_id, $business_id)
|
|
{
|
|
$this->db->select('A.*, name', 'users.name');
|
|
$this->db->from('employees A');
|
|
$this->db->join('users', 'users.id = A.user_id', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('A.user_id', $emp_id);
|
|
$this->db->where('A.is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_leave_type($business_id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('leave_master');
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_from_date($emp_id, $from_date, $to_date)
|
|
{
|
|
|
|
$this->db->select('*');
|
|
$this->db->from('leave_list');
|
|
$this->db->where('emp_id', $emp_id);
|
|
$this->db->where('from_date >=', $from_date);
|
|
$this->db->where('to_date <=', $to_date);
|
|
$query = $this->db->count_all_results();
|
|
return $query;
|
|
}
|
|
|
|
public function get_emp_join_date($emp_id, $from_date, $to_date)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('employees');
|
|
$this->db->where('user_id', $emp_id);
|
|
$this->db->where('j_date >', $from_date);
|
|
$query = $this->db->count_all_results();
|
|
return $query;
|
|
}
|
|
|
|
public function get_emp_data_by_emp_id($emp_id){
|
|
$this->db->select('*');
|
|
$this->db->from('employees');
|
|
$this->db->where('user_id', $emp_id);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
} |