<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class pro_capacity_model extends CI_Model {

    private $tableName = 'pro_capacity';

    function __construct()
    {
        /* Call the Model constructor */
        parent::__construct();
    }

    function save_department(&$department_data,$department_id=false)
    {
        if (!$department_id)
        {
          //  $this->db->insert($this->tableName,$department_data);
            return true;
        }else {
            $this->db->where('pro_capacity_id', $department_id);
            return $this->db->update($this->tableName,$department_data);
        }
    }
    
    
    function get_max_type_id(){
        $this->db->select_max('p_id');
	//$this->db->where('warehouse_id', $warehouse_id);
	$query = $this->db->get('mstr_pro_type');
     if($query->num_rows() >0)
     {
       $g = $query->result();
       $u = $g[0]->p_id+1;
       return $u;
     }
     else
     {
       return false;
     }
        
	  //$this->db->select_max('ptype_id');
	 // return $this->db->get('mstr_pro_type');
  }
  
    
    function save_type(&$department_data,$department_id=false)
    {
        if (!$department_id)
        {
            $this->db->insert('mstr_pro_type',$department_data);
            return true;
        }else {
           // $this->db->where('department_id', $department_id);
            //return $this->db->update($this->tableName,$department_data);
        }
    }
    
    
    function get_all_department_list() {
        $this->db->select($this->tableName.'.*');
        $this->db->order_by("pro_model_id", "desc");
        //$this->db->where("department_id IS NOT NULL");//("id !=",$id);
        $query = $this->db->get($this->tableName);
        return $query->result();
    }
    
    function get_all_type_list() {
        $this->db->select('mstr_pro_type'.'.*');
        $this->db->order_by("ptype_name", "asc");
        //$this->db->where("department_id IS NOT NULL");//("id !=",$id);
        $query = $this->db->get('mstr_pro_type');
        return $query->result();
    }
    
    function get_all_department() {
        $this->db->select($this->tableName.'.*');
        $this->db->order_by("pro_capacity_id", "desc");
       // $this->db->where("department_id IS NOT NULL");//("id !=",$id);
        $query = $this->db->get($this->tableName);
        return $query->result_array();
    }

    public function get_department_info($id)
    {
        $this->db->select('*');
        $this->db->from($this->tableName);
        $this->db->where("pro_capacity_id", $id);
        //$this->db->order_by("department_id", "desc");
        $query = $this->db->get();

        return $query->row_array();
    }

    public function delete_department($department_id)
    {
        $this->db->where('department_id', $department_id);
        $this->db->delete($this->tableName);

    }

    public function disable_department($department_id)
    {
        $data = array(
            'ptype_status' => 0
        );
        $this->db->where('ptype_id', $department_id);
        $this->db->update($this->tableName, $data);
    }

    public function enable_department($department_id)
    {
        $data = array(
            'ptype_status' => 1
        );
        $this->db->where('ptype_id', $department_id);
        $this->db->update($this->tableName, $data);
    }
}