<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Alert_model extends Ci_Model
{

    public function __construct()
    {
        parent::__construct();
    }
    
    function getclaims($company_id) {
        $sql = "SET SQL_BIG_SELECTS=1";
		$this->db->query($sql);

		$where = array(
            'admin_id'		=> $company_id,
        );
        

		$query = $this->db
            ->select("distinct c.claim_id, c.refno,c.name,c.date_added, 
                        (SELECT type FROM `claim_types` WHERE `ct_id` = c.ct_id) as claim_type, 
                        c.admin_id, 
                        c.status, 
                        (SELECT description FROM `status` WHERE `status_id` = c.status LIMIT 1) as status_desc
					",FALSE)
			->from("claims c")
			->where($where)
			->order_by('c.date_added DESC')
			->get();
			//echo $this->db->last_query();
			if(!$query) return false;
			if($query->num_rows()>0) return $query->result();
			else return false;
    }

    function getdocus($refno) {
        $sql = "SET SQL_BIG_SELECTS=1";
		$this->db->query($sql);

		$where = array(
            'refno'		=> $refno,
        );
        

		$query = $this->db
            ->select("cd_id as id, dt.type as doc
					",FALSE)
            ->from("claim_docus cd")
            ->join("doc_types AS dt","cd.doc_id=dt.id","left")
			->where($where)
			->order_by('dt.id ASC')
			->get();
			//echo $this->db->last_query();
			if(!$query) return false;
			if($query->num_rows()>0) return $query->result();
			else return false;
    }

}
