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

  public function select($columns="*",$data="")
  {
    $this->db->select($columns)->from('daily_tasks dt');
    $this->db->join('work_contracts wc','dt.work_id=wc.work_id');
    $this->db->join('users u1','dt.user_id=u1.user_id','left');
    $this->db->join('users u2','dt.created_by=u2.user_id','left');
    if(!empty($data)){
      $this->db->where($data);
    }
    $this->db->where("dt.delete_status",0);
    $this->db->where("wc.delete_status",0);
    if ($this->session->userdata('branch_id') != 0) {
      $this->db->where('u1.branch_id', $this->session->userdata('branch_id'));
    }
    $this->db->order_by("dt.task_due_date",'desc');
    $query = $this->db->get();
    return $query;
  }
  public function create ($data){
    $query=$this->db->insert('daily_tasks', $data);
    $result=array();
    $result['insert_id']=$this->db->insert_id();
    $result['status']=$query;
    return $result;
  }
  public function update($data)
  {
    $this->db->where('task_id', $data['task_id']);
    $query=$this->db->update('daily_tasks', $data);
    return $query;
  }
}
?>
