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

class Employee_model extends CI_Model{
	
	  	public function employeemaster_all(){
		$this->db->select('comp_employee.*');
		$this->db->select('date_format(dateOfJoin , "%d-%m-%Y") as dateJoin', false);
		$this->db->where('is_delete', 0);
		$this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
		$query = $this->db->get('comp_employee');
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	public function employeemaster_insert($newuser){
		$sql = $this->db->insert_string('comp_employee', $newuser);
		$query = $this->db->query($sql);
		if($query === TRUE){
			return TRUE;
		} else {
			$last_query = $this->db->last_query();
			return $last_query;
		}
	}
	public function employeemaster_edit($updateuser, $ID){
		$this->db->where('ID', $ID);
		$query = $this->db->update('comp_employee', $updateuser); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}

	public function employeemaster_delete($deletuser, $ID){
		$this->db->where('ID', $ID);
		$query = $this->db->update('comp_employee', $deletuser); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	public function employeemaster_id($ID){
	    $this->db->where('ID', $ID);
		$query = $this->db->get('comp_employee', 1);		
		if($query->num_rows() == 1){
			return $query->result();
		}else{
			return false;
		}
	}
	
	//To check either employee code is exist or not	
 	public function check_empcode($employeecode){
		$this->db->select('employeeName');
		//$this->db->select('date_format ( dateOfJoin , "%d-%m-%Y" ) as dateJoin');
	    $this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
		$this->db->where('employeeCode' ,$employeecode);
		$this->db->where('is_delete', 0);
		$query = $this->db->get('comp_employee');
//    $query = $this->db->query("SELECT employeeCode FROM comp_employee WHERE employeeCode = '".$employeecode."'");
    if($query->num_rows() >0){
			return "true";
		}else{
			return "false";
		}
	}

		public function employeemaster_allopt(){
		$this->db->select('ID');
		$this->db->select('employeeName');
		//$this->db->select('date_format ( dateOfJoin , "%d-%m-%Y" ) as dateJoin');
	    $this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
		$this->db->where('is_delete', 0);
		$this->db->order_by('employeeName');
		$query = $this->db->get('comp_employee');
    	if($query->result()){
       		$result = $query->result();
        	return $result;
    	} 	
	}
}