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

class rawmaterialdetails_model extends CI_Model
{
    
	/**
     * This function is used to get the user listing count
     * @param string $searchText : This is optional search text
     * @param number $page : This is pagination offset
     * @param number $segment : This is pagination limit
     * @return array $result : This is result
     */
    function rawmaterialListing()
    {
        $this->db->select('*');
        $this->db->from('T_MaterialMaster');

		
        $query = $this->db->get();
        
        $result = $query->result();        
        return $result;
    }
	
	
	
	function getUOM($UOM = '')
    {
		$ConfigID = 'C001';
		$this->db->select('ConfigValue');
		$this->db->from('T_ConfigDetails');
        $this->db->where('Config_id ',$ConfigID );
		 if($UOM != '')
		{
			$this->db->where('ConfigValue !=',$UOM ); 
		}
       $query = $this->db->get();
       
       return $query->result();
    }
	
	function getmaterialType($MaterialType = '')
    {
		$Config_ID = 'C003';
		
		$this->db->select('Config_ID,ConfigValue');
        $this->db->from('T_ConfigDetails');
		$this->db->where('Config_id',$Config_ID ); 
		if($MaterialType != '')
		{
			$this->db->where('ConfigValue !=',$MaterialType ); 
		}
        $query = $this->db->get();
        
        return $query->result();
    }
	/**
     * This function used to get user information by id
     * @param number $userId : This is user id
     * @return array $result : This is user information
     */
   
function addNewRawMaterial($RawMaterial='')
    {
      
        $this->db->insert('T_MaterialMaster', $RawMaterial);
                    
        return TRUE;
    }
    
    /**
     * This function used to get user information by id
     * @param number $userId : This is user id
     * @return array $result : This is user information
     */
	 function getMaterialDetails($MaterialCode)
    {
        $this->db->select('*');
        $this->db->from('T_MaterialMaster');
       
        $this->db->where('MaterialCode', $MaterialCode);
        $query = $this->db->get();
        //sprint_r($this->db->last_query());
        return $query->result();
    }
	function editRawmaterial($RawMaterial, $MaterialCode)
    {
		
		
		
        $this->db->where('MaterialCode', $MaterialCode);
        $this->db->update('T_MaterialMaster', $RawMaterial);
        
        return TRUE;
    }
	
	function viewrawmaterial($RawMaterial, $MaterialCode)
    {
		echo $MaterialCode; //."and".$RawMaterial ;
		
		
        $this->db->where('MaterialCode', $MaterialCode);
        $this->db->update('T_MaterialMaster', $RawMaterial);
        
        return TRUE;
    }
	
	function export_excel(){
		
		$this->db->select('det.MaterialCode,det.MaterialName,det.MaterialType,det.UOM,emp.firstname,emp1.firstname as Updated_By,det.IsActive');
		$this->db->join('tbl_users as tbl',' det.createdby = tbl.userid','left');
		$this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid','left');
		$this->db->join('tbl_users as tbl1',' det.UpdatedBy = tbl1.userid','left');
		$this->db->join('T_Employee_Details as emp1', 'emp1.empid=tbl1.empid','left');
        return $this->db->get('T_MaterialMaster as det')->result_array();
	}
	/**
     * This function is used to delete the user information
     * @param number $userId : This is user id
     * @return boolean $result : TRUE / FALSE
     
    function deletePO($PO, $POinfo)
    {
        $this->db->where('PO', $PO);
        $this->db->update('T_PurchaseOrderDetails', $POInfo);
        
        return $this->db->affected_rows();
    }*/
}
?>