291 lines
9.5 KiB
PHP
291 lines
9.5 KiB
PHP
<?php
|
|
class Expence_model extends MY_Model {
|
|
|
|
public function get_employee_name($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_expence_list($business_id)
|
|
{
|
|
$this->db->select('A.*, u1.name as requested_name, u2.name as created_name');
|
|
$this->db->from('expense A');
|
|
$this->db->join('users u1', 'u1.id = A.requested_for', 'left');
|
|
$this->db->join('users u2', 'u2.id = A.created_by', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('A.status', 'pending');
|
|
$this->db->or_where('A.status', 'Approved');
|
|
$this->db->or_where('A.status', 'Declined');
|
|
$this->db->or_where('A.status', 'Partially approved');
|
|
$this->db->order_by('A.id', 'DESC');
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
|
|
}
|
|
|
|
public function get_expence_list_all($business_id)
|
|
{
|
|
|
|
$this->db->select('A.*, u1.name as requested_name, u2.name as created_name');
|
|
$this->db->from('expense A');
|
|
$this->db->join('users u1', 'u1.id = A.requested_for', 'left');
|
|
$this->db->join('users u2', 'u2.id = A.created_by', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->order_by('A.id','DESC');
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
|
|
}
|
|
|
|
public function get_expense_data($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('expense');
|
|
$this->db->where('md5(id)', $id);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function get_expense_data_not_md5($id)
|
|
{
|
|
$this->db->select('A.*, u1.name as requested_name, u2.name as created_name');
|
|
$this->db->from('expense A');
|
|
$this->db->join('users u1', 'u1.id = A.requested_for', 'left');
|
|
$this->db->join('users u2', 'u2.id = A.created_by', 'left');
|
|
$this->db->where('A.id', $id);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function get_expense_child_data($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('expense_child');
|
|
$this->db->where('md5(expense_id)', $id);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_expense_child_data2($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('expense_child');
|
|
$this->db->where('expense_id', $id);
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
|
public function get_expence_child_list($expense_id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('expense_child');
|
|
$this->db->where('expense_id', $expense_id);
|
|
$this->db->order_by('id', 'DESC');
|
|
$query = $this->db->get();
|
|
return $query->result();
|
|
}
|
|
|
|
public function approve_child_expense($action, $id)
|
|
{
|
|
$this->db->where('expense_id', $id);
|
|
$this->db->where('status','pending');
|
|
$this->db->update('expense_child',$action);
|
|
}
|
|
|
|
public function approve_child_expense_2($action, $id)
|
|
{
|
|
$this->db->where('id', $id);
|
|
$this->db->where('status','pending');
|
|
return $this->db->update('expense_child',$action);
|
|
|
|
}
|
|
|
|
|
|
public function get_expence_list_by_id($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('expence_list');
|
|
$this->db->where('md5(id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
public function ExpenceDecline($id, $data)
|
|
{
|
|
$this->db->where('id',$id);
|
|
$this->db->where('status', 'pending');
|
|
$this->db->update('expense', $data);
|
|
return true;
|
|
}
|
|
|
|
public function Expence_Decline_Child($id, $data)
|
|
{
|
|
$this->db->where('expense_id',$id);
|
|
$this->db->where('status', 'pending');
|
|
$this->db->update('expense_child', $data);
|
|
return;
|
|
}
|
|
|
|
public function Expencecancle($id, $data)
|
|
{
|
|
$this->db->where('md5(id)',$id);
|
|
$this->db->where('status', 'Draft');
|
|
$this->db->update('expense', $data);
|
|
return $this->db->last_query();
|
|
}
|
|
|
|
public function Expencecancle_child($id, $data)
|
|
{
|
|
$this->db->where('md5(expense_id)',$id);
|
|
$this->db->where('status', 'Draft');
|
|
$this->db->update('expense_child', $data);
|
|
return $this->db->last_query();
|
|
}
|
|
|
|
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_manager_id($user_id)
|
|
{
|
|
$this->db->select('manager');
|
|
$this->db->from('employees');
|
|
$this->db->where('user_id', $user_id);
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() > 0) {
|
|
return $query->result();
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function remove_row($id)
|
|
{
|
|
$this->db->where("id", $id);
|
|
$this->db->delete("expense_child");
|
|
return true;
|
|
}
|
|
|
|
public function update_to_submit_all($id, $data)
|
|
{
|
|
$this->db->where('expense_id',$id);
|
|
$this->db->where('status', 'Draft');
|
|
$this->db->update('expense_child', $data);
|
|
return true;
|
|
}
|
|
|
|
|
|
// get the value from expense and expense_child sum of the value and count data
|
|
public function get_count_amount()
|
|
{
|
|
$query = $this->db->query('SELECT expense.id, (SELECT SUM(amount) FROM expense_child WHERE expense_child.expense_id = expense.id) as amount, (SELECT COUNT(expense_id) FROM expense_child WHERE expense_child.expense_id = expense.id) as count FROM expense');
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_status_update($id)
|
|
{
|
|
$query = $this->db->query('SELECT expense_id,
|
|
COUNT(CASE WHEN status = "Approved" THEN 1 ELSE NULL END) AS approve_count,
|
|
COUNT(CASE WHEN status = "Declined" THEN 1 ELSE NULL END) AS declined_count,
|
|
COUNT(CASE WHEN status = "pending" THEN 1 ELSE NULL END) AS pending_count
|
|
FROM expense_child
|
|
WHERE expense_id = ?
|
|
GROUP BY expense_id', $id);
|
|
|
|
$result = $query->row();
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |