MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/crm_cafsindia_com/application/models/Item.php
<?php
class Item extends CI_Model
{

  /*
	Perform a search on items
	*/
	public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'items.product_id', $order = 'asc')
	{
    $this->db->from('items');
		$this->db->join('category', 'category.cat_id = items.category_id');
		$this->db->join('vendor', 'vendor.vendor_id = items.vendorcompanyname');
    $this->db->where('items.deleted', 0);
    $this->db->group_start();
    $this->db->like('product_name', $search);
    $this->db->or_like('cat_name', $search);
    $this->db->or_like('vendor.vendorcompanyname', $search);
    $this->db->or_like('weight_credit', $search);

    // $this->db->or_like('CONCAT(first_name, " ", last_name)', $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 item
  */
  public function get_info($item_id)
  {

    $this->db->from('items');
      $this->db->where('product_id', $item_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('items') as $field)
      {
        $item_obj->$field = '';
      }

      return $item_obj;
    }
  }

  /*
  Gets Company
  */

 public function get_company($id){

      $this->db->from('vendor');
      $this->db->order_by('vendorcompanyname', 'asc');
      $this->db->where('deleted', 0);
      $this->db->where('category_id', $id);

       return $this->db->get()->result_array();

}

public function exists($item_id, $ignore_deleted = FALSE, $deleted = FALSE)
{
	$this->db->from('items');

	$this->db->where('product_id',$item_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(&$item_data, $item_id = FALSE){
		if(!$item_id || !$this->exists($item_id, TRUE))
		{
			if($this->db->insert('items', $item_data))
			{
				$item_data['product_id'] = $this->db->insert_id();

				return TRUE;
			}

			return FALSE;
		}

		$this->db->where('product_id', $item_id);

		return $this->db->update('items', $item_data);
	}

	/*
	Deletes a list of items
	*/
	public function delete_list($item_ids)
	{
		//Run these queries as a transaction, we want to make sure we do all or nothing
		$this->db->trans_start();

		// set to 0 quantities

		$this->db->where_in('product_id', $item_ids);
		$success = $this->db->update('items', array('deleted'=>1));

		$this->db->trans_complete();

		$success &= $this->db->trans_status();

		return $success;
 	}

	/*
	Get an item id given an item number
	*/
	public function get_item_id($item_id)
	{
		$this->db->from('items');

		$this->db->where('product_id', $item_id);
		$this->db->where('items.deleted', 0);

		$query = $this->db->get();

		if($query->num_rows() == 1)
		{
			return $query->row()->product_id;
		}

		return FALSE;
	}

	/*
	Gets information about multiple items
	*/
	public function get_multiple_info($item_ids)
	{
		$this->db->from('items');

		$this->db->where_in('items.product_id', $item_ids);

		return $this->db->get();
	}
}
?>