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

class ZakatSummary extends CI_Model{
	
	public function group_all(){
		$this->db->select('a.*');
		$this->db->select('b.name as centerName');
		$this->db->from('zakat_summary 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 ZakatSummary_Insert(){
		$newData = array(
			'companyID' => element('compID', $this->session->userdata('logged_in')),
			'centerID' => $this->input->post('centerID'),
			'year' => $this->input->post('nisabYear'),
			'totalAmount' => $this->input->post('zakatPerniagaan'),
			'totalZakatPaid' => $this->input->post('zakatPay'),
			'createdBy' => element('role', $this->session->userdata('logged_in'))
		);
		$query = $this->db->insert('zakat_summary', $newData);
		if($query){
			return $this->db->insert_id();
		}else{
			return FALSE;
		}
	}
	public function ZakatSummary_save($ID, $data){
		$this->db->where('ID', $ID);
		$query = $this->db->update('zakat_summary', $data); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function ZakatSummary_Delete($ID){
		$this->db->where('ID', $ID);
		$query = $this->db->delete('zakat_summary'); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function ZakatSummary_ID($ID){
		$this->db->where('ID', $ID);
		$this->db->from('zakat_summary');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	public function ZakatSummary_search($where){
		$this->db->where($where);
		$this->db->from('zakat_summary');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
}

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