File: /home/cafsindia/crm_cafsindia_com/application/models/Vendor_model.php
<?php
class vendor_model extends CI_Model
{
/*
Perform a search on items
*/
public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'vendor.vendor_id', $order = 'asc')
{
$this->db->from('vendor');
$this->db->join('category', 'category.cat_id = vendor.category_id');
$this->db->where('vendor.deleted', 0);
$this->db->group_start();
$this->db->like('vendorcompanyname', $search);
$this->db->or_like('cat_name', $search);
$this->db->or_like('vendordesc', $search);
$this->db->group_end();
$this->db->order_by($sort, $order);
if($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
/*
Get number of rows
*/
public function get_found_rows($search, $filters)
{
return $this->search($search, $filters)->num_rows();
}
/*
Gets information about a particular Company
*/
public function get_info($vendor_id)
{
// echo "SAT : $vendor_id"; die;
$this->db->from('vendor');
$this->db->where('vendor_id', $vendor_id);
$query = $this->db->get();
if($query->num_rows() == 1)
{
return $query->row();
}
else
{
//Get empty base parent object, as $item_id is NOT an item
$item_obj = new stdClass();
//Get all the fields from items table
foreach($this->db->list_fields('vendor') as $field)
{
$item_obj->$field = '';
}
return $item_obj;
}
}
/*
Gets information about multiple items
*/
public function get_multiple_info($vendor_ids, $location_id)
{
$this->db->from('vendor');
$this->db->where_in('vendor_id', $vendor_ids);
return $this->db->get()->result_array();
}
public function exists($vendor_id, $ignore_deleted = FALSE, $deleted = FALSE)
{
$this->db->from('vendor');
$this->db->where('vendor_id',$vendor_id);
if($ignore_deleted == FALSE)
{
$this->db->where('deleted', $deleted);
}
return ($this->db->get()->num_rows() == 1);
}
/*
Gets total of rows
*/
public function get_total_rows()
{
$this->db->from('items');
$this->db->where('deleted', 0);
// $this->db->where('shop_id',$this->session->userdata('shop_id'));
return $this->db->count_all_results();
}
/*
Inserts or updates a item
*/
public function save(&$company_data, $vendor_id = FALSE){
if(!$vendor_id || !$this->exists($vendor_id, TRUE))
{
if($this->db->insert('vendor', $company_data))
{
$company_data['vendor_id'] = $this->db->insert_id();
return TRUE;
}
return FALSE;
}
$this->db->where('vendor_id', $vendor_id);
return $this->db->update('vendor', $company_data);
}
// /*
// Deletes one item
// */
// public function delete($vendor_id)
// {
//
// // echo "SAT :: $vendor_id"; die;
// //Run these queries as a transaction, we want to make sure we do all or nothing
// $this->db->trans_start();
//
// $this->db->where('vendor_id', $vendor_id);
// $success = $this->db->update('vendor', array('deleted'=>1));
//
// $this->db->trans_complete();
//
// $success &= $this->db->trans_status();
//
// return $success;
// }
/*
Deletes a list of items
*/
public function delete_list($vendor_id)
{
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
$this->db->where_in('vendor_id', $vendor_id);
$success = $this->db->update('vendor', array('deleted'=>1));
$this->db->trans_complete();
$success &= $this->db->trans_status();
return $success;
}
public function get_category()
{
$this->db->from('category');
$this->db->order_by('cat_name', 'asc');
return $this->db->get();
}
}
?>