<?php
class Inventory_Settings_Model extends CI_Model {
    public function __construct(){
        parent::__construct();
        $this->inventory_settings 		= TBL_SETTINGS_INVENTORY;
        $this->statue_settings 			= TBL_SETTINGS_STATUE;
		$this->expenses_settings 		= TBL_SETTINGS_EXPENSES;
		$this->inventory_tem_settings 	= TBL_SETTINGS_TEM_INVENTORY;
    }
    
    public function list_all() {
        $resource = $this->db->get($this->inventory_settings);
        return $resource->result();
    }
    
    public function statue_list() {
        $resource = $this->db->get($this->statue_settings);
        return $resource->result();
    }
	
	public function expenses_list() {
        $resource = $this->db->get($this->expenses_settings);
        return $resource->result();
    }
	
	public function inventory_list() {
        $resource = $this->db->get($this->inventory_tem_settings);
        return $resource->result();
    }
    
    public function get_data($ids = '') {
        $this->db->select('id');
        if (!empty($ids)) {
            $this->db->where_not_in('id', $ids);
        }
        $resource = $this->db->get($this->inventory_settings);
        return $resource->result();
    }
    public function get_data_statue($ids = '') {
        $this->db->select('id');
        if (!empty($ids)) {
            $this->db->where_not_in('id', $ids);
        }
        $resource = $this->db->get($this->statue_settings);
        return $resource->result();
    }
	
	public function get_data_expenses($ids = '') {
        $this->db->select('id');
        if (!empty($ids)) {
            $this->db->where_not_in('id', $ids);
        }
        $resource = $this->db->get($this->expenses_settings);
        return $resource->result();
    }
	
	public function get_data_inventory($ids = '') {
        $this->db->select('id');
        if (!empty($ids)) {
            $this->db->where_not_in('id', $ids);
        }
        $resource = $this->db->get($this->inventory_tem_settings);
        return $resource->result();
    }
    
    public function list_active() {
        $this->db->select('id, inventory_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->inventory_settings)->result();
    }
    
    public function controller_name_str() {
        $this->db->select('GROUP_CONCAT(controller_name SEPARATOR ",") as controller_name', FALSE);
        $this->db->where('status', 1);
        return $this->db->get($this->inventory_settings)->row()->controller_name;
    }
    
    public function statue_list_active() {
        $this->db->select('id, menu_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->statue_settings)->result();
    }
    
    public function statue_controller_name_str() {
        $this->db->select('GROUP_CONCAT(controller_name SEPARATOR ",") as controller_name', FALSE);
        $this->db->where('status', 1);
        return $this->db->get($this->statue_settings)->row()->controller_name;
    }
	
	public function expenses_list_active() {
        $this->db->select('id, menu_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->expenses_settings)->result();
    }
    
    public function expenses_controller_name_str() {
        $this->db->select('GROUP_CONCAT(controller_name SEPARATOR ",") as controller_name', FALSE);
        $this->db->where('status', 1);
        return $this->db->get($this->expenses_settings)->row()->controller_name;
    }
	
	public function inventory_list_active() {
        $this->db->select('id, menu_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->inventory_tem_settings)->result();
    }
    
    public function inventory_controller_name_str() {
        $this->db->select('GROUP_CONCAT(controller_name SEPARATOR ",") as controller_name', FALSE);
        $this->db->where('status', 1);
        return $this->db->get($this->inventory_tem_settings)->row()->controller_name;
    }
    
    public function permissions_by_controller($controller_name_arr) {
        
        if(!empty($controller_name_arr)) :
            $this->db->select('id, inventory_name, controller_name, menu_name, menu_icon');
            $this->db->where_in('controller_name', $controller_name_arr);
        
            $this->db->where('status', 1);
            $this->db->order_by('seq_number');
            return $this->db->get($this->inventory_settings)->result_array();
        endif;
        
        return array();
    }
    
    public function statue_permissions_by_controller($controller_name_arr) {
        
        if(!empty($controller_name_arr)) :
            $this->db->select('id, menu_name, controller_name, menu_icon');
            $this->db->where_in('controller_name', $controller_name_arr);
        
            $this->db->where('status', 1);
            $this->db->order_by('seq_number');
            return $this->db->get($this->statue_settings)->result_array();
        endif;
        
        return array();
    }
	
	public function expenses_permissions_by_controller($controller_name_arr) {
        
        if(!empty($controller_name_arr)) :
            $this->db->select('id, menu_name, controller_name, menu_icon');
            $this->db->where_in('controller_name', $controller_name_arr);
        
            $this->db->where('status', 1);
            $this->db->order_by('seq_number');
            return $this->db->get($this->expenses_settings)->result_array();
        endif;
        
        return array();
    }
	
	public function inventory_permissions_by_controller($controller_name_arr) {
        
        if(!empty($controller_name_arr)) :
            $this->db->select('id, menu_name, controller_name, menu_icon');
            $this->db->where_in('controller_name', $controller_name_arr);
        
            $this->db->where('status', 1);
            $this->db->order_by('seq_number');
            return $this->db->get($this->inventory_tem_settings)->result_array();
        endif;
        
        return array();
    }
    
    public function update($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->inventory_settings, $data);
        return $this->db->affected_rows();
    }
	
    public function update_statue($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->statue_settings, $data);
        return $this->db->affected_rows();
    }
	
	public function update_expenses($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->expenses_settings, $data);
        return $this->db->affected_rows();
    }
	
	public function update_inventory($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->inventory_tem_settings, $data);
        return $this->db->affected_rows();
    }
}
?>
