diff --git a/application/language/en-GB/config_lang.php b/application/language/en-GB/config_lang.php index 1457f97a7..6c3b896a8 100644 --- a/application/language/en-GB/config_lang.php +++ b/application/language/en-GB/config_lang.php @@ -233,6 +233,10 @@ $lang["config_stock_location"] = "Stock location"; $lang["config_stock_location_duplicate"] = "Please use an unique location name"; $lang["config_stock_location_invalid_chars"] = "The stock location name cannot contain '_'"; $lang["config_stock_location_required"] = "Stock location is a required field"; +$lang["config_suggestions_first_column"] = "Column 1"; +$lang["config_suggestions_layout"] = "Search Suggestions Layout"; +$lang["config_suggestions_second_column"] = "Column 2"; +$lang["config_suggestions_third_column"] = "Column 3"; $lang["config_table"] = "Table"; $lang["config_table_configuration"] = "Table Configuration"; $lang["config_takings_printer"] = "Takings Printer"; diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index 15d996f81..718770fbe 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -234,6 +234,10 @@ $lang["config_stock_location"] = "Stock location"; $lang["config_stock_location_duplicate"] = "Stock Location must be unique."; $lang["config_stock_location_invalid_chars"] = "Stock Location can not contain '_'."; $lang["config_stock_location_required"] = "Stock location is a required field."; +$lang["config_suggestions_first_column"] = "Column 1"; +$lang["config_suggestions_layout"] = "Search Suggestions Layout"; +$lang["config_suggestions_second_column"] = "Column 2"; +$lang["config_suggestions_third_column"] = "Column 3"; $lang["config_table"] = "Table"; $lang["config_table_configuration"] = "Table Configuration"; $lang["config_takings_printer"] = "Receipt Printer"; diff --git a/application/models/Item.php b/application/models/Item.php index f8eb442a7..231d4af4c 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -428,11 +428,49 @@ class Item extends CI_Model return $success; } + function get_search_suggestion_format(string $seed = NULL) + { + $seed .= ','.$this->config->item('suggestions_first_column'); + + if($this->config->item('suggestions_second_column') !== '') + { + $seed .= ','.$this->config->item('suggestions_second_column'); + } + + if($this->config->item('suggestions_third_column') !== '') + { + $seed .= ','.$this->config->item('suggestions_third_column'); + } + + return $seed; + } + + function get_search_suggestion_label($result_row) + { + $label1 = $this->config->item('suggestions_first_column'); + $label2 = $this->config->item('suggestions_second_column'); + $label3 = $this->config->item('suggestions_third_column'); + + $label = $result_row->$label1; + + if($label2 !== '') + { + $label .= ' | '. $result_row->$label2; + } + + if($label3 !== '') + { + $label .= ' | '. $result_row->$label3; + } + + return $label; + } + public function get_search_suggestions($search, $filters = array('is_deleted' => FALSE, 'search_custom' => FALSE), $unique = FALSE, $limit = 25) { $suggestions = array(); - $this->db->select('item_id, name'); + $this->db->select($this->get_search_suggestion_format('item_id,name')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later @@ -440,10 +478,10 @@ class Item extends CI_Model $this->db->order_by('name', 'asc'); foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); } - $this->db->select('item_id, item_number'); + $this->db->select($this->get_search_suggestion_format('item_id,item_number')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later @@ -451,7 +489,7 @@ class Item extends CI_Model $this->db->order_by('item_number', 'asc'); foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->item_number); + $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); } if(!$unique) @@ -484,7 +522,7 @@ class Item extends CI_Model } //Search by description - $this->db->select('item_id, name, description'); + $this->db->select($this->get_search_suggestion_format('item_id, name, description')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later @@ -492,7 +530,7 @@ class Item extends CI_Model $this->db->order_by('description', 'asc'); foreach($this->db->get()->result() as $row) { - $entry = array('value' => $row->item_id, 'label' => $row->name); + $entry = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } )) { $suggestions[] = $entry; @@ -519,7 +557,7 @@ class Item extends CI_Model $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + $suggestions[] = array('value' => $row->item_id, 'label' => get_search_suggestion_label($row)); } } } @@ -539,7 +577,7 @@ class Item extends CI_Model { $suggestions = array(); - $this->db->select('item_id, name'); + $this->db->select($this->get_search_suggestion_format('item_id, name')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later @@ -548,10 +586,10 @@ class Item extends CI_Model $this->db->order_by('name', 'asc'); foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); } - $this->db->select('item_id, item_number'); + $this->db->select($this->get_search_suggestion_format('item_id, item_number')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later @@ -560,7 +598,7 @@ class Item extends CI_Model $this->db->order_by('item_number', 'asc'); foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->item_number); + $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); } if(!$unique) @@ -593,7 +631,7 @@ class Item extends CI_Model } //Search by description - $this->db->select('item_id, name, description'); + $this->db->select($this->get_search_suggestion_format('item_id, name, description')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later @@ -602,7 +640,7 @@ class Item extends CI_Model $this->db->order_by('description', 'asc'); foreach($this->db->get()->result() as $row) { - $entry = array('value' => $row->item_id, 'label' => $row->name); + $entry = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } )) { $suggestions[] = $entry; @@ -630,7 +668,7 @@ class Item extends CI_Model $this->db->where('deleted', $filters['is_deleted']); foreach($this->db->get()->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)); } } } diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 86bc5a8c0..4e5ddd043 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -115,6 +115,43 @@ +