<?php
class Barcode_model extends CI_Model {
	
	public $db_tabel    = 'customers';
	 
    function customer_search($search)
    {
        $sql="SELECT *
              FROM customers A 
              WHERE A.customer_code like '%$search%' OR  A.customer_name like '%$search%' AND isactive='Y'";
        $query = $this->db->query($sql);

        if($query->num_rows()>0)
        {
            return $query->result();  
        }
        else
        {
            return null;
        }
    }

    function product_search($search)
    {
        $sql="SELECT *
              FROM products A 
              WHERE A.product_code like '%$search%' OR  A.product_name like '%$search%' AND isactive='Y'";
        $query = $this->db->query($sql);

        if($query->num_rows()>0)
        {
            return $query->result();  
        }
        else
        {
            return null;
        }
    }
    
    function customer_search_lap($search)
    {
        $sql="SELECT *
              FROM customers A 
              WHERE A.customer_code like '%$search%' OR  A.customer_name like '%$search%'";
        $query = $this->db->query($sql);

        if($query->num_rows()>0)
        {
            return $query->result();  
        }
        else
        {
            return null;
        }
    }

    function product_search_lap($search)
    {
        $sql="SELECT *
              FROM products A 
              WHERE A.product_code like '%$search%' OR  A.product_name like '%$search%'";
        $query = $this->db->query($sql);

        if($query->num_rows()>0)
        {
            return $query->result();  
        }
        else
        {
            return null;
        }
    }

    public function InsertCustomer($data)
    {
        $result = $this->db->insert('customers', $data);
        return $result;
    }
  
    public function UpdateCustomer($id, $data)
    {
        $this->db->where('id',$id);
        $result = $this->db->update('customers', $data);
        return $result;
    }
	
    public function InsertBarcode($data){
        $result = $this->db->insert('barcode', $data);
        return $result;
    }

}