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

class Model_user_pcb extends CI_Model {

	public function fetchPCB($staff_id = null, $latest = false,$profiling_id = null, $pcb_id = null)
	{
		$this->db->select('a.*,
						b.name,b.ic_no,b.birthdate,b.occupation,b.oku_status,b.study_status,
						c.action_efective_date,
						d.type');
		$this->db->join('user__family_member b','b.id = a.family_id and b.is_delete = 0');
		$this->db->join('user__profiling c','c.id = a.profiling_id','left');
		$this->db->join('_ref__action_type d','d.id = c.action_type_id','left'); 

		$this->db->where('a.is_delete',0);

		if($staff_id) $this->db->where('a.user_id',$staff_id);
		if($profiling_id) $this->db->where('a.profiling_id',$profiling_id);
		if($pcb_id) $this->db->where('a.id',$pcb_id);

		$query = $this->db->get('user__pcb a');
		return ($query->num_rows() > 0)? $query->result() : null;
	}

	public function createPCB($input)
	{
		$this->db->insert('user__pcb',$input);
		return $this->db->insert_id();
	}

	public function editPCB($input,$id,$profiling_id = null)
	{
		if($profiling_id) $this->db->where('profiling_id',$profiling_id);

		$this->db->set($input);
		$this->db->where('id',$id);
		$this->db->update('user__pcb');

		return true;
	}
}
?>