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

class ZakatCenter extends CI_Model{
	
	public function group_all(){
		$this->db->select('a.*');
		$this->db->order_by('a.shortName');
		$this->db->from('zakat_center a');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
        
        
        public function getSaleAmountForWakaf($year, $from, $to, $acct){
            
             $this->db->select("companyID, year, SUM(amount_cr) as saleAmount");
            $this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
            $this->db->where('year', $year);
            $this->db->where('sequence >=', $from);
            $this->db->where('sequence <=', $to);
            $this->db->where('acctCode', $acct);
            
            $this->db->group_by("companyID, year");
            
            $query = $this->db->get("comp_journal_detail");
            
            if($query->num_rows() >= 1){
                    $return = $query->result();
                    $som = 0;
                    foreach ($return as $row){
                        $som = $row->saleAmount;
                    }
                    return $som;
		}else{
			return FALSE;
		}
            
        }

                public function ZakatCenter_Insert(){
		$newData = array(
			'shortName' => $this->input->post('shortName'),
			'name' => $this->input->post('name'),
			'line1' => $this->input->post('line1'),
			'line2' => $this->input->post('line2'),
			'line3' => $this->input->post('line3'),
			'city' => $this->input->post('city'),
			'postCode' => $this->input->post('postCode'),
			'stateID' => $this->input->post('state'),
			'countryID' => $this->input->post('country'),
			'noTel' => $this->input->post('noTel'),
			'noFax' => $this->input->post('noFax'),
			'email' => $this->input->post('email'),
			'website' => $this->input->post('website'),
			'createdBy' => element('role', $this->session->userdata('logged_in'))
		);
		$query = $this->db->insert('zakat_center', $newData);
		if($query){
			return $this->db->insert_id();
		}else{
			return FALSE;
		}
	}
	public function ZakatCenter_Update($ID, $data){
		$this->db->where('ID', $ID);
		$query = $this->db->update('zakat_center', $data); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
        
        public function UpdateByTname($tname,$ID, $data){
		$this->db->where('ID', $ID);
		$query = $this->db->update($taname, $data); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function ZakatCenter_Delete($ID){
		$this->db->where('ID', $ID);
		$query = $this->db->delete('zakat_center'); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
        
	public function ZakatCenter_ID($ID){
		$this->db->where('ID', $ID);
		$this->db->from('zakat_center');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	public function ZakatCenter_search($where){
		$this->db->where($where);
		$this->db->from('zakat_center');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
}

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