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

class ZakatNisab extends CI_Model{
	
	public function group_all(){
		$this->db->select('a.*');
		$this->db->select('b.name as centerName');
		$this->db->order_by('a.centerID');
		$this->db->order_by('a.year desc');
		$this->db->from('zakat_nisab a');
		$this->db->join('zakat_center b', 'b.ID = a.centerID','left outer');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	public function ZakatNisab_Insert(){
		$newData = array(
			'companyID' => element('compID', $this->session->userdata('logged_in')),
			'centerID' => $this->input->post('centerID'),
			'year' => $this->input->post('add_year'),
			'nisab' => $this->input->post('nisab'),
			'createdBy' => element('role', $this->session->userdata('logged_in'))
		);
		$query = $this->db->insert('zakat_nisab', $newData);
		if($query){
			return $this->db->insert_id();
		}else{
			return FALSE;
		}
	}
	public function ZakatNisab_save($ID, $data){
		$this->db->where('ID', $ID);
		$query = $this->db->update('zakat_nisab', $data); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function ZakatNisab_Delete($ID){
		$this->db->where('ID', $ID);
		$query = $this->db->delete('zakat_nisab'); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function ZakatNisab_ID($ID){
		$this->db->where('ID', $ID);
		$this->db->from('zakat_nisab');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	public function ZakatNisab_search($where){
		$this->db->where($where);
		$this->db->from('zakat_nisab');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
}

/* End of file ZakatNisab.php */
/* Location: ./application/models/ZakatNisab.php */
/* Created By : Yahaya Abdollah */
