<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Core_Production_Estimate_Model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->db->query("SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));");
    }
    protected function saveMaster($pd)
    {
        if ($this->db->insert('production_cost_estimation_master', $pd)) {
            $lst = $this->db->insert_id();
            return $lst;
        } else {
            return false;
        }
    }
    protected function saveItems($pd)
    {
        if ($this->db->insert('production_cost_estimation_item', $pd)) {
            $lst = $this->db->insert_id();
            return $lst;
        } else {
            return false;
        }
    }
   
    protected function updateMaster($id,$data){
        if($id>0){
            $this->db->where('pcem_id', $id);
            return $this->db->update('production_cost_estimation_master',$data);  
        }else{
            return false;
        }
    }
    protected function updateItems($id,$data){
        if($id>0){
            $this->db->where('pcei_id', $id);
            return $this->db->update('production_cost_estimation_item',$data);  
        }else{
            return false;
        }
    }
     protected function updateSubItems($id,$data){
        if($id>0){
            $this->db->where('pcesi_id', $id);
            return $this->db->update('production_cost_estimation_sub_item',$data);  
        }else{
            return false;
        }
    }
    protected function deleteItems($id,$data){
        if($id>0){
            $this->db->where('pcei_id', $id);
            return $this->db->delete('production_cost_estimation_item',$data);  
        }else{
            return false;
        }
    }
     protected function deleteSubItemsWithItem($id,$data){
        if($id>0){
            $this->db->where('pcei_id', $id);
            return $this->db->delete('production_cost_estimation_sub_item',$data);  
        }else{
            return false;
        }
    }
     protected function updateSubItems($id,$data){
        if($id>0){
            $this->db->where('pcesi_id', $id);
            return $this->db->update('production_cost_estimation_sub_item',$data);  
        }else{
            return false;
        }
    }
    protected function getBasicMaster($id){
        $this->db->select('p.* ');
        $this->db->from('production_cost_estimation_master p');
        //$this->db->join('master_brand b', 'p.mat_brand_id = b.brand_id', 'left');
        $this->db->where('p.pcem_id',$id);
         $query = $this->db->get();
          if ($query->num_rows() > 0) {
            return $query->row_array();
        } else {
            return false;
        }
    }
    protected function getBasicItem($id){
        $this->db->select('p.* ');
        $this->db->from('production_cost_estimation_item p');
        //$this->db->join('master_brand b', 'p.mat_brand_id = b.brand_id', 'left');
        $this->db->where('p.pcei_id',$id);
         $query = $this->db->get();
          if ($query->num_rows() > 0) {
            return $query->row_array();
        } else {
            return false;
        }
    }
    
   
    
    

  
}