<?php


		if(empty($search)){
			$where = 'a.no_sale = 0 AND b.loc_code = '. "'".LOCATION_CODE."'";
		}else{
			$where = "a.no_sale = 0 AND b.loc_code = '".LOCATION_CODE."' 
					 AND (a.description LIKE '".  mysql_real_escape_string($search)."%' 
					 	 OR  CONCAT(a.description,' - ',p.size) LIKE '".  mysql_real_escape_string($search)."%' 
					 	 OR  CONCAT(a.description,p.size) LIKE '".  mysql_real_escape_string($search)."%' 
					 	 OR  p.size LIKE '".  mysql_real_escape_string($search)."%' 
					 	 OR a.stock_id LIKE '".mysql_real_escape_string($search)."%')";
		}


		$query = $this->db->query("
                    SELECT a.stock_id AS item_id, IF(a.item_size_id> 0, CONCAT(a.description,' - ',p.size), a.description) AS name, b.lot_no, SUM(b.qty) qty, a.stock_id AS item_number
                    FROM stock_master a
					INNER JOIN stock_moves b ON a.stock_id =b.stock_id
					LEFT JOIN pos_item_sizes AS p ON a.item_size_id=p.id
                    WHERE $where
                    GROUP BY b.stock_id, b.lot_no
					ORDER BY name ASC, LENGTH(p.size), p.size");

		foreach ($query->result() as $row) {
			if($row->qty > 0){
				//                $suggestions[] = $row->item_id . '|' . $row->name . ' ('.$row->item_number.$row->lot_no.')';
				$suggestions[] = $row->item_id.'@'.$row->lot_no . '|' . $row->name . ' ('.$row->item_number.$row->lot_no.')';
			}
		}


		
		
		
		$query = $this->db->query("
                    SELECT tax_types.rate as percent
                    FROM stock_master 
					LEFT JOIN item_tax_type_exemptions ON item_tax_type_exemptions.item_tax_type_id = stock_master.tax_type_id
					LEFT JOIN tax_types ON item_tax_type_exemptions.tax_type_id = tax_types.id
                    WHERE stock_master.stock_id ='".mysql_real_escape_string($item_id)."'");

		return $query->row();


?>