bbone/application/modules/Leave/models/Leave_model.php
2023-06-29 11:36:03 +05:30

276 lines
7.8 KiB
PHP

<?php
class Leave_model extends MY_Model {
public function get_leave_with_emp_name($business_id)
{
$this->db->select('A.* , name', 'users.name');
$this->db->from('leave_list A');
$this->db->join('users', 'users.id = A.emp_id', 'left');
$this->db->where('A.business_id', $business_id);
$this->db->order_by('id','DESC');
$this->db->where('A.is_active', 1);
$query = $this->db->get();
$query = $query->result();
return $query;
}
public function get_with_emp_name($business_id, )
{
$this->db->select('A.* , name', 'users.name');
$this->db->from('leave_list A');
$this->db->join('users', 'users.id = A.emp_id', 'left');
$this->db->where('A.business_id', $business_id);
$this->db->order_by('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)
{
$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('is_active', 1);
$query = $this->db->get();
$query = $query->result();
return $query;
}
public function remaining_days($emp_id, $business_id)
{
$this->db->select('remaining_days');
$this->db->from('emp_leave_days');
$this->db->where('emp_id', $emp_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_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('type', $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)
{
$this->db->select('*');
$this->db->from($table);
$this->db->where('business_id', $business_id);
$this->db->where('emp_id', $id);
$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_based_on_tpye($id , $type , $business_id , $table)
{
$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->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($action,$id,$table){
$this->db->where('emp_id',$id);
$this->db->update($table,$action);
return;
}
public function LeaveApprove($id, $data)
{
$this->db->where('id',$id);
$this->db->update('leave_list', $data);
return;
}
public function LeaveDecline($id, $data)
{
$this->db->where('id',$id);
$this->db->where('status', 'pending');
$this->db->update('leave_list', $data);
return;
}
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('emp_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)
{
$this->db->where('emp_id',$id);
$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('delegated_to', $emp_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();
}
}