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

class Model_claim_trainer extends CI_Model 
{
   
    public function fetchTrainer($claim_id)
    {
        $this->db->select('a.*');
        $this->db->where('a.claim_id',$claim_id);
        $this->db->where('a.is_delete',0);

        $result = $this->db->get('hr__claim_trainer a')->result();

        if($result)
        {
            foreach($result as $key => $value)
            {
                $result[$key]->attachments = $this->fetchTrainerAttachment($value->id);
            }

            return $result;
        }else{
            return null;
        }
    }

    public function fetchTrainerAttachment($claim_trainer_id)
    {
        $this->db->select('a.*');
        $this->db->where('a.claim_trainer_id',$claim_trainer_id);
        $result = $this->db->get('hr__claim_trainer_attachment a')->result();
        return $result;
    }
    
    /*
    public function fetchTollMovement($claim_toll_id)
    {
        $this->db->select('a.*,b.date,b.description,b.destination,c.movementType as type');
        $this->db->where('a.claim_toll_id',$claim_toll_id);
        $this->db->join('hr__movement_group b','b.id = a.movement_id');
        $this->db->join('hr__movement_type c','c.id = b.movementType');
        $query = $this->db->get(' hr__claim_toll_movement a');
        return ($query->result())?$query->result():null;
    }

    public function fetchTollAttachment($claim_toll_id)
    {
        $this->db->select('a.*');
        $this->db->where('a.claim_toll_id',$claim_toll_id);
        $query = $this->db->get('hr__claim_toll_attachment a');
        return ($query->result() > 0)?$query->result():null;   
    }
    */

    public function create($data)
    {
        $this->db->insert('hr__claim_trainer',$data);
        return $this->db->insert_id();
    }
    
    public function createAttachment($data)
    {
        $this->db->insert('hr__claim_trainer_attachment',$data);
        return true;
    }

    /*
    public function updateTrainer($input,$where)
    {
        $this->db->set($input);
		foreach ($where as $key => $wh) {
			$this->db->where($key,$wh);
		}
        $this->db->update('hr__claim_toll');
    }
    */

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

    public function updateClaim($input,$where)
    {
		$this->db->set($input);
		foreach ($where as $key => $wh) {
			$this->db->where($key,$wh);
		}
        $this->db->update('hr__claim_trainer');
        
    }
}
?>