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

  public function insert_client($data)
  {
    if($this->session->userdata('branch_id')!=0){
      $data['branch_id'] = $this->session->userdata('branch_id');
    }
    $query=$this->db->insert('clients', $data);
    $result=array();
    $result['insert_id']=$this->db->insert_id();
    $result['status']=$query;
    return $result;
  }
  public function update_client($data)
  {
    if($this->session->userdata('branch_id')!=0){
      $this->db->where("branch_id",$this->session->userdata('branch_id'));
    }
    $this->db->where('client_id', $data['client_id']);
    $query=$this->db->update('clients', $data);
    return $query;
  }
  public function select_client($columns="*",$data="")
  {
    $this->db->select($columns)->from('clients c');
    $this->db->join('tax_state_codes tsc','tsc.state_id=c.tax_state_id','left');
    if(!empty($data)){
      $this->db->where($data);
    }
    $this->db->where("c.delete_status",0);
    if ($this->session->userdata('branch_id') != 0) {
      $this->db->where('c.branch_id', $this->session->userdata('branch_id'));
    }
    $query = $this->db->get();
    return $query;
  }
}
?>
