Merge pull request #1111 from RuleDomain/fix-kit-item-selection

Change kit item selection from the Item Kit maintenance to only selec…
This commit is contained in:
FrancescoUK
2017-02-01 20:07:48 +00:00
committed by GitHub
3 changed files with 110 additions and 1 deletions

View File

@@ -57,6 +57,7 @@ class Items extends Secure_Controller
$filters = array_merge($filters, $filledup);
$items = $this->Item->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->Item->get_found_rows($search, $filters);
$data_rows = array();
@@ -120,6 +121,14 @@ class Items extends Secure_Controller
echo json_encode($suggestions);
}
public function suggest_kits()
{
$suggestions = $this->xss_clean($this->Item->get_kit_search_suggestions($this->input->post_get('term'),
array('search_custom' => FALSE, 'is_deleted' => FALSE), TRUE));
echo json_encode($suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/

View File

@@ -496,6 +496,106 @@ class Item extends CI_Model
return $suggestions;
}
public function get_kit_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->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->where("item_type = '1'"); // standard, exclude kit items since kits will be picked up later
$this->db->like('name', $search);
$this->db->order_by('name', 'asc');
foreach($this->db->get()->result() as $row)
{
$suggestions[] = array('value' => $row->item_id, 'label' => $row->name);
}
$this->db->select('item_id, item_number');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->like('item_number', $search);
$this->db->order_by('item_number', 'asc');
foreach($this->db->get()->result() as $row)
{
$suggestions[] = array('value' => $row->item_id, 'label' => $row->item_number);
}
if(!$unique)
{
//Search by category
$this->db->select('category');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->distinct();
$this->db->like('category', $search);
$this->db->order_by('category', 'asc');
foreach($this->db->get()->result() as $row)
{
$suggestions[] = array('label' => $row->category);
}
//Search by supplier
$this->db->select('company_name');
$this->db->from('suppliers');
$this->db->like('company_name', $search);
// restrict to non deleted companies only if is_deleted is FALSE
$this->db->where('deleted', $filters['is_deleted']);
$this->db->distinct();
$this->db->order_by('company_name', 'asc');
foreach($this->db->get()->result() as $row)
{
$suggestions[] = array('label' => $row->company_name);
}
//Search by description
$this->db->select('item_id, name, description');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->like('description', $search);
$this->db->order_by('description', 'asc');
foreach($this->db->get()->result() as $row)
{
$entry = array('value' => $row->item_id, 'label' => $row->name);
if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } ))
{
$suggestions[] = $entry;
}
}
//Search by custom fields
if($filters['search_custom'] != FALSE)
{
$this->db->from('items');
$this->db->group_start();
$this->db->like('custom1', $search);
$this->db->or_like('custom2', $search);
$this->db->or_like('custom3', $search);
$this->db->or_like('custom4', $search);
$this->db->or_like('custom5', $search);
$this->db->or_like('custom6', $search);
$this->db->or_like('custom7', $search);
$this->db->or_like('custom8', $search);
$this->db->or_like('custom9', $search);
$this->db->or_like('custom10', $search);
$this->db->group_end();
$this->db->where('deleted', $filters['is_deleted']);
foreach($this->db->get()->result() as $row)
{
$suggestions[] = array('value' => $row->item_id, 'label' => $row->name);
}
}
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
return $suggestions;
}
public function get_category_suggestions($search)
{
$suggestions = array();

View File

@@ -216,7 +216,7 @@ $(document).ready(function()
$("#item_name").autocomplete({
source: '<?php echo site_url("items/suggest"); ?>',
source: '<?php echo site_url("items/suggest_kits"); ?>',
minChars: 0,
delay: 15,
cacheLength: 1,