<?php
class Travel_allowance_model extends CI_Model
{
  function __construct()
  {
    parent::__construct();
  }

  public function select_ta($columns="*",$data="",$distinct="",$entry_approval=1)
  {
    if(!empty($distinct)){
      $this->db->distinct();
    }
    $this->db->select($columns)->from('travel_allowance ta');
    $this->db->join('users u1','ta.created_by=u1.user_id');
    // $this->db->join('users u2','ta.user_id=u2.user_id','left');
    $this->db->join('employees e','ta.employee_id=e.employee_id');
    $this->db->join('travel_allowance_vehicles tv','tv.type=ta.vehicle_type','left');
    $this->db->join('vehicles v','ta.vehicle_id=v.id','left');
    $this->db->join('work_contracts wc','ta.project_id=wc.work_id','left');
    if(!empty($data)){
      $this->db->where($data);
    }
    if ($this->session->userdata('branch_id') != 0) {
      $this->db->where('e.branch_id', $this->session->userdata('branch_id'));
    }
    $this->db->where("ta.delete_status",0);
    if($entry_approval!='all'){
      $this->db->where("ta.entry_approval_status",$entry_approval);
    }
    $this->db->order_by("ta.ta_date",'asc');
    $this->db->order_by("ta.ta_id",'asc');
    $query = $this->db->get();
    return $query;
  }
  public function create_ta($data){
    $query=$this->db->insert('travel_allowance', $data);
    $result=array();
    $result['insert_id']=$this->db->insert_id();
    $result['status']=$query;
    return $result;
  }
  public function update_ta($data)
  {
    $this->db->where('ta_id', $data['ta_id']);
    $query=$this->db->update('travel_allowance', $data);
    return $query;
  }
  public function select_ta_vehicles($columns="*",$data="")
  {
    $this->db->select($columns)->from('travel_allowance_vehicles tv');
    if(!empty($data)){
      $this->db->where($data);
    }
    $query = $this->db->get();
    return $query;
  }
}
?>
