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

class Model_claim_others extends CI_Model {

	function fetchOtherClaim($user_id = null,$claim_id = null,$year = null,$month = null)
	{
		$this->db->select('a.*');
		if($user_id)$this->db->where('b.user_id',$user_id);
		if($claim_id)$this->db->where('a.claim_id',$claim_id);
		if($year)$this->db->where('b.year',$year);
		if($month)$this->db->where('b.month',$month);
		$this->db->where('a.is_delete',0);
		if($user_id || $year || $month) $this->db->join('hr__claim b','b.id = a.claim_id');

		$query = $this->db->get('hr__claim_others a');

		return ($query->result())?$query->result():null;
	}

	function fetchSingleClaim($user_id = null,$claim_id = null,$year = null,$month = null)
	{
		$dentals = $this->fetchOtherClaim($user_id,$claim_id,$year,$month);
		return ($dentals)?$dentals[0]:null;
	}

	function createClaim($input)
	{
		$this->db->insert('hr__claim_others',$input);
		return $this->db->insert_id();
	}

	function createAttachment($input)
	{
		return ($this->db->insert_batch('hr__claim_others_attachment',$input))?true:false;
	}

	function updateOtherClaim($input,$where = array())
	{
		$this->db->set($input);
		foreach ($where as $key => $wh) {
			$this->db->where($key,$wh);
		}

		$this->db->update('hr__claim_others');
	}

	function removeOtherClaim($id)
	{
		$data 	= array('is_delete' => 1);
		$where 	= array('id' => $id);
		$this->updateOtherClaim($data,$where);
	}

	function getAttachments($other_id)
	{
		$this->db->where('is_delete',0);
		$this->db->where('other_claim_id',$other_id);
		$query = $this->db->get('hr__claim_others_attachment');
		return ($query->num_rows() > 0)?$query->result():null;
	}

	function getAttachmentByUniqueid($unique_id)
	{
		$this->db->select('a.*');
		$this->db->where('a.unique_id',$unique_id);
		$query = $this->db->get('hr__claim_others_attachment a');
		return ($query->result())?$query->result():null;
	}
}
?>