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

class Agent_Model extends CI_Model{
	
	public function agent_all(){
		//$this->db->where('is_delete',0);
		$this->db->order_by('agentName');
		$this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
		$query = $this->db->get('comp_sales_agent');		
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}
	
	public function agent_id($ID){
	    $this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
	    $this->db->where('ID', $ID);
		$query = $this->db->get('comp_sales_agent', 1);		
		if($query->num_rows() == 1){
			return $query->result();
		}else{
			return false;
		}
	}
    public function agent_insert($newagent){
		$sql = $this->db->insert_string('comp_sales_agent', $newagent);
		$query = $this->db->query($sql);
		if($query === TRUE){
			return TRUE;
		} else {
			$last_query = $this->db->last_query();
			return $last_query;
		}
	}
	public function agent_edit($updateuser, $ID){
		$this->db->where('ID', $ID);
		$query = $this->db->update('comp_sales_agent', $updateuser); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}

	public function agent_delete($deletuser, $ID){
		$this->db->where('ID', $ID);
		$query = $this->db->update('comp_sales_agent', $ID); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	
}