Add item search for category + suppliers (#328)

This commit is contained in:
jekkos
2016-03-07 23:21:57 +01:00
parent fe2787217f
commit dfbab194de
4 changed files with 16 additions and 36 deletions

View File

@@ -41,7 +41,7 @@ class Giftcards extends Secure_area implements iData_controller
*/
function suggest()
{
$suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term'), $this->input->post('limit'));
$suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term'));
echo json_encode($suggestions);
}

View File

@@ -120,7 +120,7 @@ class Items extends Secure_area implements iData_controller
$suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array(
'search_custom' => $this->input->post('search_custom'),
'is_deleted' => !empty($this->input->post('is_deleted'))),
FALSE, $this->input->post('limit'));
FALSE);
echo json_encode($suggestions);
}

View File

@@ -210,38 +210,6 @@ class Giftcard extends CI_Model
return $suggestions;
}
/*
Get search suggestions to find customers
*/
function get_person_search_suggestions($search,$limit=25)
{
$suggestions = array();
$this->db->select('person_id');
$this->db->from('people');
$this->db->like('person_id', $this->db->escape_like_str($search));
$this->db->or_like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('email', $this->db->escape_like_str($search));
$this->db->or_like('phone_number', $this->db->escape_like_str($search));
$this->db->order_by('person_id', 'asc');
$by_person_id = $this->db->get();
foreach($by_person_id->result() as $row)
{
$suggestions[]=array('label' => $row->person_id);
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
return $suggestions;
}
/*
Preform a search on giftcards
*/

View File

@@ -263,7 +263,7 @@ class Item extends CI_Model
return $this->db->update('items', array('deleted' => 1));
}
public function get_search_suggestions($search, $filters = array("is_deleted"), $unique = FALSE, $limit=25)
public function get_search_suggestions($search, $filters = array("is_deleted" => 0), $unique = FALSE, $limit=25)
{
$suggestions = array();
@@ -291,6 +291,18 @@ class Item extends CI_Model
if (!$unique)
{
$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');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = array('label' => $row->category);
}
$this->db->select('company_name');
$this->db->from('suppliers');
$this->db->like('company_name', $search);
@@ -301,7 +313,7 @@ class Item extends CI_Model
$by_company_name = $this->db->get();
foreach($by_company_name->result() as $row)
{
$suggestions[] = array('value' => $row->item_id, 'label' => $row->company_name);
$suggestions[] = array('label' => $row->company_name);
}
//Search by description