<commit_before><?php
class Item extends CI_Model
{
	/*
	Determines if a given item_id is an item
	*/
	public function exists($item_id)
	{
		$this->db->from('items');
		$this->db->where('item_id', $item_id);
		$query = $this->db->get();

		return ($query->num_rows() == 1);
	}
	
	public function item_number_exists($item_number, $item_id='')
	{
		$this->db->from('items');
		$this->db->where('item_number', $item_number);
		if (!empty($item_id))
		{
			$this->db->where('item_id !=', $item_id);
		}
		$query=$this->db->get();

		return ($query->num_rows() == 1);
	}
	
	public function get_total_rows()
	{
		$this->db->from('items');
		$this->db->where('deleted', 0);

		return $this->db->count_all_results();
	}

	/*
	 Get number of rows
	*/
	public function get_found_rows($search, $filters)
	{
		return $this->search($search, $filters)->num_rows();
	}

	/*
	 Perform a search on items
	*/
	public function search($search, $filters, $rows=0, $limit_from=0)
	{
		$this->db->from('items');
		$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');
		$this->db->join('inventory', 'inventory.trans_items = items.item_id');

		if ($filters['stock_location_id'] > -1)
		{
			$this->db->join('item_quantities', 'item_quantities.item_id = items.item_id');
			$this->db->where('location_id', $filters['stock_location_id']);
		}

		if (empty($search))
		{
			$this->db->where('DATE_FORMAT(trans_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
		}
		else
		{
			if ($filters['search_custom'] == FALSE)
			{
				$this->db->where("(name LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"item_number LIKE '" . $this->db->escape_like_str($search) . "%' OR " .
								$this->db->dbprefix('items').".item_id LIKE '" . $this->db->escape_like_str($search) . "%' OR " .
								"company_name LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"category LIKE '%" . $this->db->escape_like_str($search) . "%')");
			}
			else
			{
				$this->db->where("(custom1 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom2 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom3 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom4 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom5 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom6 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom7 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom8 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom9 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom10 LIKE '%" . $this->db->escape_like_str($search) . "%')");
			}
		}

		$this->db->where('items.deleted', $filters['is_deleted']);

		if ($filters['empty_upc'] != FALSE)
		{
			$this->db->where('item_number', null);
		}
		if ($filters['low_inventory'] != FALSE)
		{
			$this->db->where('quantity <=', 'reorder_level');
		}
		if ($filters['is_serialized'] != FALSE)
		{
			$this->db->where('is_serialized', 1);
		}
		if ($filters['no_description'] != FALSE)
		{
			$this->db->where('items.description', '');
		}

		// avoid duplicate entry with same name because of inventory reporting multiple changes on the same item in the same date range
		//$this->db->group_by('items.name');
		
		// order by name of item
		$this->db->order_by('items.name', 'asc');

		if ($rows > 0) 
		{	
			$this->db->limit($rows, $limit_from);
		}

		return $this->db->get();
	}
	
	/*
	 Returns all the items
	*/
	public function get_all($stock_location_id=-1, $rows=0, $limit_from=0)
	{
		$this->db->from('items');
		$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');

		if ($stock_location_id > -1)
		{
			$this->db->join('item_quantities', 'item_quantities.item_id=items.item_id');
			$this->db->where('location_id', $stock_location_id);
		}

		$this->db->where('items.deleted', 0);
		
		// order by name of item
		$this->db->order_by('items.name', 'asc');<commit_msg>Properly fix for item search bug (remove duplicated rows due to left outer join)<commit_after><?php
class Item extends CI_Model
{
	/*
	Determines if a given item_id is an item
	*/
	public function exists($item_id)
	{
		$this->db->from('items');
		$this->db->where('item_id', $item_id);
		$query = $this->db->get();

		return ($query->num_rows() == 1);
	}
	
	public function item_number_exists($item_number, $item_id='')
	{
		$this->db->from('items');
		$this->db->where('item_number', $item_number);
		if (!empty($item_id))
		{
			$this->db->where('item_id !=', $item_id);
		}
		$query=$this->db->get();

		return ($query->num_rows() == 1);
	}
	
	public function get_total_rows()
	{
		$this->db->from('items');
		$this->db->where('deleted', 0);

		return $this->db->count_all_results();
	}

	/*
	 Get number of rows
	*/
	public function get_found_rows($search, $filters)
	{
		return $this->search($search, $filters)->num_rows();
	}

	/*
	 Perform a search on items
	*/
	public function search($search, $filters, $rows=0, $limit_from=0)
	{
		$this->db->from('items');
		$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');
		$this->db->join('inventory', 'inventory.trans_items = items.item_id');

		if ($filters['stock_location_id'] > -1)
		{
			$this->db->join('item_quantities', 'item_quantities.item_id = items.item_id');
			$this->db->where('location_id', $filters['stock_location_id']);
		}

		if (empty($search))
		{
			$this->db->where('DATE_FORMAT(trans_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
		}
		else
		{
			if ($filters['search_custom'] == FALSE)
			{
				$this->db->where("(name LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"item_number LIKE '" . $this->db->escape_like_str($search) . "%' OR " .
								$this->db->dbprefix('items').".item_id LIKE '" . $this->db->escape_like_str($search) . "%' OR " .
								"company_name LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"category LIKE '%" . $this->db->escape_like_str($search) . "%')");
			}
			else
			{
				$this->db->where("(custom1 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom2 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom3 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom4 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom5 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom6 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom7 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom8 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom9 LIKE '%" . $this->db->escape_like_str($search) . "%' OR " .
								"custom10 LIKE '%" . $this->db->escape_like_str($search) . "%')");
			}
		}

		$this->db->where('items.deleted', $filters['is_deleted']);

		if ($filters['empty_upc'] != FALSE)
		{
			$this->db->where('item_number', null);
		}
		if ($filters['low_inventory'] != FALSE)
		{
			$this->db->where('quantity <=', 'reorder_level');
		}
		if ($filters['is_serialized'] != FALSE)
		{
			$this->db->where('is_serialized', 1);
		}
		if ($filters['no_description'] != FALSE)
		{
			$this->db->where('items.description', '');
		}

		// avoid duplicate entry with same name because of inventory reporting multiple changes on the same item in the same date range
		$this->db->group_by('items.item_id');
		
		// order by name of item
		$this->db->order_by('items.name', 'asc');

		if ($rows > 0) 
		{	
			$this->db->limit($rows, $limit_from);
		}

		return $this->db->get();
	}
	
	/*
	 Returns all the items
	*/
	public function get_all($stock_location_id=-1, $rows=0, $limit_from=0)
	{
		$this->db->from('items');
		$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');

		if ($stock_location_id > -1)
		{
			$this->db->join('item_quantities', 'item_quantities.item_id=items.item_id');
			$this->db->where('location_id', $stock_location_id);
		}

		$this->db->where('items.deleted', 0);
		
		// order by name of item
		$this->db->order_by('items.name', 'asc');
{'fraction_non_alphanumeric': 0.2276967232719445, 'fraction_numerical': 0.005740253527864147, 'mean_word_length': 3.49140708915145, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 221, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1653692', 'n_tokens_mistral': 3548, 'n_tokens_neox': 3071, 'n_words': 498}