<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class statue_vendor_model extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->vendor = TBL_VENDOR;
        $this->statue = TBL_STATUE_BOOK;
    }
    
    public function list_all() {
        $this->db->where('status !=', 2);
        return $this->db->get($this->vendor)->result();
    }
   
    public  function insert($data){  
        $this->db->insert($this->vendor, $data);  
        return $this->db->insert_id();
    }   
    
    public function update($data, $id){
        $this->db->where('id', $id);
        $this->db->update($this->vendor, $data);
        return $this->db->affected_rows();
    }
    
    public function get_by_id($id) {
        $this->db->where('id', $id);
        return $this->db->get($this->vendor)->row();
    }
   
    public function vendor_name_exists($id = '',$name = '') {
        if($id != '')
            $this->db->where('id !=', $id);
        
        $this->db->where('name', $name);
        $this->db->where('status !=', 2);
        if($this->db->get($this->vendor)->num_rows())
            return 1;
        else 
            return 0;
    }
   
    public function get_last_insert_id() {
        $this->db->select('id,code');
        $this->db->where('status !=',2);
        $this->db->limit(1);
        $this->db->order_by('id','desc');
        return $this->db->get($this->vendor)->row();
    }
    
    public function vendor_exists($id) {
        $this->db->where('vendor_id',$id);
        $this->db->where('status !=',2);
        $getData = $this->db->get($this->statue);
        if($getData->num_rows() > 0)
            return 1;
        
        else 
            return 0;
    }
}
?>