241 lines
7.1 KiB
PHP
241 lines
7.1 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->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');
|
|
$this->db->update('expense_child',$action);
|
|
}
|
|
|
|
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_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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
// 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;
|
|
}
|
|
|
|
} |