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

  public function select_customer($columns="*",$data="")
  {
    $this->db->select($columns)->from('customers c');
    $this->db->join('tax_state_codes tsc','tsc.state_id=c.customer_tax_state','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'));
    }
      $this->db->order_by("customer_id",'desc');
    $query = $this->db->get();
    return $query;
  }
  public function update_customer($data)
  {
    if($this->session->userdata('branch_id')!=0){
      $this->db->where("branch_id",$this->session->userdata('branch_id'));
    }
    $this->db->where('customer_id', $data['customer_id']);
    $query=$this->db->update('customers', $data);
    return $query;
  }
  public function create_customer($data){
    if ($this->session->userdata('branch_id') != 0) {
      $data['branch_id'] = $this->session->userdata('branch_id');
    }
    $query = $this->db->insert('customers', $data);
    $result=array();
    $result['insert_id']=$this->db->insert_id();
    $result['status']=$query;
    return $result;
  }
}
?>
