From 6c29faeba105c42d618c96ce09d2a737ed82377d Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 7 Mar 2016 07:56:41 +0100 Subject: [PATCH 1/2] Remove old jquery autocomplete Remove id|name format in giftcards customer selection Cleanup duplicated custom field suggestion in Items Migrate table search suggestion to jQuery UI Add jquery UI bootstrap theme --- application/controllers/Customers.php | 10 +- application/controllers/Employees.php | 4 +- application/controllers/Giftcards.php | 16 +- application/controllers/Item_kits.php | 4 +- application/controllers/Items.php | 124 +-- application/controllers/Receivings.php | 10 +- application/controllers/Sales.php | 26 +- application/controllers/Suppliers.php | 2 +- application/models/Customer.php | 107 +-- application/models/Employee.php | 8 +- application/models/Giftcard.php | 88 +-- application/models/Item.php | 332 +------- application/models/Item_kit.php | 47 +- application/models/Person.php | 40 +- application/models/Sale.php | 2 +- application/models/Supplier.php | 18 +- application/views/giftcards/form.php | 32 +- application/views/item_kits/form.php | 51 +- application/views/items/form.php | 21 +- application/views/items/manage.php | 2 +- application/views/partial/header.php | 7 +- application/views/sales/form.php | 22 +- bower.json | 3 +- css/autocomplete.css | 54 -- css/ospos.css | 2 +- dist/opensourcepos.js | 833 ++------------------ dist/opensourcepos.min.css | 21 +- dist/opensourcepos.min.js | 8 +- js/jquery.autocomplete.js | 764 ------------------ js/manage_tables.js | 35 +- js/nominatim.autocomplete.js | 35 +- templates/spacelab/views/partial/header.php | 6 +- 32 files changed, 406 insertions(+), 2328 deletions(-) delete mode 100644 css/autocomplete.css delete mode 100644 js/jquery.autocomplete.js diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 473325e6d..1b3647e32 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -40,8 +40,14 @@ class Customers extends Person_controller */ function suggest() { - $suggestions = $this->Customer->get_search_suggestions($this->input->post('q'),$this->input->post('limit')); - echo implode("\n",$suggestions); + $suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), TRUE); + echo json_encode($suggestions); + } + + function suggest_search() + { + $suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), FALSE); + echo json_encode($suggestions); } /* diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index 942234cba..6d6a5a70a 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -40,8 +40,8 @@ class Employees extends Person_controller */ function suggest() { - $suggestions = $this->Employee->get_search_suggestions($this->input->post('q'),$this->input->post('limit')); - echo implode("\n",$suggestions); + $suggestions = $this->Employee->get_search_suggestions($this->input->post('term')); + echo json_encode($suggestions); } /* diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index 4e3c0a123..7750466b8 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -41,17 +41,8 @@ class Giftcards extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Giftcard->get_search_suggestions($this->input->post('q'), $this->input->post('limit')); - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions for person_id based on what is being searched for - */ - function person_search() - { - $suggestions = $this->Customer->get_customer_search_suggestions($this->input->post('q'), $this->input->post('limit')); - echo implode("\n",$suggestions); + $suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term'), $this->input->post('limit')); + echo json_encode($suggestions); } function get_row() @@ -65,7 +56,8 @@ class Giftcards extends Secure_area implements iData_controller { $giftcard_info = $this->Giftcard->get_info($giftcard_id); $person_name=$giftcard_id > 0? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : ''; - $data['selected_person'] = $giftcard_id > 0 && isset($giftcard_info->person_id) ? $giftcard_info->person_id . "|" . $person_name : ""; + $data['selected_person_name'] = $giftcard_id > 0 && isset($giftcard_info->person_id) ? $person_name : ''; + $data['selected_person_id'] = $giftcard_info->person_id; $data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $this->Giftcard->get_max_number()->giftcard_number + 1; $data['giftcard_info'] = $giftcard_info; $this->load->view("giftcards/form",$data); diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 3caa72aa5..ad652ed41 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -73,9 +73,9 @@ class Item_kits extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('q'), $this->input->post('limit')); + $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), $this->input->post('limit')); - echo implode("\n", $suggestions); + echo json_encode($suggestions); } function get_row() diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 4975bcd06..53abe45d5 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -117,17 +117,17 @@ class Items extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('q'), $this->input->post('limit'), - $this->input->post('search_custom'), $this->input->post('is_deleted') != null); - - echo implode("\n",$suggestions); + $suggestions = $this->Item->get_search_suggestions($this->input->post('term'), array( + 'search_custom' => $this->input->post('search_custom'), + 'is_deleted' => $this->input->post('is_deleted') != "0"), + FALSE, $this->input->post('limit')); + echo json_encode($suggestions); } - - function item_search() - { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'), $this->input->post('limit')); - echo implode("\n",$suggestions); + function suggest_search() + { + $suggestions = $this->Item->get_search_suggestions($this->input->post('term'), TRUE); + echo json_encode($suggestions); } /* @@ -135,9 +135,9 @@ class Items extends Secure_area implements iData_controller */ function suggest_category() { - $suggestions = $this->Item->get_category_suggestions($this->input->post('q')); + $suggestions = $this->Item->get_category_suggestions($this->input->post('term')); - echo implode("\n",$suggestions); + echo json_encode($suggestions); } /* @@ -145,111 +145,19 @@ class Items extends Secure_area implements iData_controller */ function suggest_location() { - $suggestions = $this->Item->get_location_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); + $suggestions = $this->Item->get_location_suggestions($this->input->post('term')); + echo json_encode($suggestions); } /* Gives search suggestions based on what is being searched for */ - function suggest_custom1() + function suggest_custom() { - $suggestions = $this->Item->get_custom1_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); + $suggestions = $this->Item->get_custom_suggestions($this->input->post('term'), $this->input->post('field_no')); + echo json_encode($suggestions); } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom2() - { - $suggestions = $this->Item->get_custom2_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom3() - { - $suggestions = $this->Item->get_custom3_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom4() - { - $suggestions = $this->Item->get_custom4_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom5() - { - $suggestions = $this->Item->get_custom5_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom6() - { - $suggestions = $this->Item->get_custom6_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom7() - { - $suggestions = $this->Item->get_custom7_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom8() - { - $suggestions = $this->Item->get_custom8_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom9() - { - $suggestions = $this->Item->get_custom9_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom10() - { - $suggestions = $this->Item->get_custom10_suggestions($this->input->post('q')); - - echo implode("\n",$suggestions); - } - function get_row() { $item_id = $this->input->post('row_id'); diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index b7971d08b..0e5aca336 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -16,15 +16,15 @@ class Receivings extends Secure_area function item_search() { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit')); - $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($this->input->post('q'),$this->input->post('limit'))); - echo implode("\n",$suggestions); + $suggestions = $this->Item->get_search_suggestions($this->input->post('term')); + $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($this->input->post('term'))); + echo json_encode($suggestions); } function supplier_search() { - $suggestions = $this->Supplier->get_suppliers_search_suggestions($this->input->post('q'),$this->input->post('limit')); - echo implode("\n",$suggestions); + $suggestions = $this->Supplier->get_suppliers_search_suggestions($this->input->post('term'),$this->input->post('limit')); + echo json_encode($suggestions); } function select_supplier() diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 76cb33b61..dcd588582 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -126,36 +126,22 @@ class Sales extends Secure_area function item_search() { $suggestions = array(); - $search = $this->input->post('q'); - $limit = $this->input->post('limit'); + $search = $this->input->post('term'); if ($this->sale_lib->get_mode() == 'return' && $this->sale_lib->is_valid_receipt($search) ) { $suggestions[] = $search; } - $suggestions = array_merge($suggestions, $this->Item->get_item_search_suggestions($search , $limit)); - $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($search, $limit)); + $suggestions = array_merge($suggestions, $this->Item->get_search_suggestions($search)); + $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($search)); - echo implode("\n", $suggestions); - } - - function customer_search() - { - $search = $this->input->post('q'); - $limit = $this->input->post('limit'); - - $suggestions = $this->Customer->get_customer_search_suggestions($search, $limit); - - echo implode("\n", $suggestions); + echo json_encode($suggestions); } function suggest() { - $search = $this->input->post('q'); - $limit = $this->input->post('limit'); - $suggestions = $this->Sale->get_search_suggestions($search, $limit); - - echo implode("\n", $suggestions); + $suggestions = $this->Sale->get_search_suggestions($this->input->post('term')); + echo json_encode($suggestions); } function select_customer() diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index 48b4cac98..5f032ba61 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -42,7 +42,7 @@ class Suppliers extends Person_controller function suggest() { $suggestions = $this->Supplier->get_search_suggestions($this->input->post('q'),$this->input->post('limit')); - echo implode("\n",$suggestions); + echo json_encode($suggestions); } /* diff --git a/application/models/Customer.php b/application/models/Customer.php index 2c6b2e9ef..edbf2619e 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -141,7 +141,7 @@ class Customer extends Person /* Get search suggestions to find customers */ - function get_search_suggestions($search,$limit=25) + function get_search_suggestions($search, $unique=TRUE, $limit=25) { $suggestions = array(); @@ -154,41 +154,45 @@ class Customer extends Person $by_name = $this->db->get(); foreach($by_name->result() as $row) { - $suggestions[]=$row->first_name.' '.$row->last_name; - } - - $this->db->from('customers'); - $this->db->join('people','customers.person_id=people.person_id'); - $this->db->where('deleted',0); - $this->db->like("email",$search); - $this->db->order_by("email", "asc"); - $by_email = $this->db->get(); - foreach($by_email->result() as $row) - { - $suggestions[]=$row->email; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name); } - $this->db->from('customers'); - $this->db->join('people','customers.person_id=people.person_id'); - $this->db->where('deleted',0); - $this->db->like("phone_number",$search); - $this->db->order_by("phone_number", "asc"); - $by_phone = $this->db->get(); - foreach($by_phone->result() as $row) + if (!$unique) { - $suggestions[]=$row->phone_number; - } - - $this->db->from('customers'); - $this->db->join('people','customers.person_id=people.person_id'); - $this->db->where('deleted',0); - $this->db->like("account_number",$search); - $this->db->order_by("account_number", "asc"); - $by_account_number = $this->db->get(); - foreach($by_account_number->result() as $row) - { - $suggestions[]=$row->account_number; + $this->db->from('customers'); + $this->db->join('people','customers.person_id=people.person_id'); + $this->db->where('deleted',0); + $this->db->like("email",$search); + $this->db->order_by("email", "asc"); + $by_email = $this->db->get(); + foreach($by_email->result() as $row) + { + $suggestions[]=array('value' => $row->person_id, 'label' => $row->email); + } + + $this->db->from('customers'); + $this->db->join('people','customers.person_id=people.person_id'); + $this->db->where('deleted',0); + $this->db->like("phone_number",$search); + $this->db->order_by("phone_number", "asc"); + $by_phone = $this->db->get(); + foreach($by_phone->result() as $row) + { + $suggestions[]=array('value' => $row->person_id, 'label' => $row->phone_number); + } + + $this->db->from('customers'); + $this->db->join('people','customers.person_id=people.person_id'); + $this->db->where('deleted',0); + $this->db->like("account_number",$search); + $this->db->order_by("account_number", "asc"); + $by_account_number = $this->db->get(); + foreach($by_account_number->result() as $row) + { + $suggestions[]= array('value' => $row->person_id, 'label' => $row->account_number); + } } + //only return $limit suggestions if(count($suggestions > $limit)) @@ -197,46 +201,7 @@ class Customer extends Person } return $suggestions; } - - /* - Get search suggestions to find customers - */ - function get_customer_search_suggestions($search,$limit=25) - { - $suggestions = array(); - - $this->db->from('customers'); - $this->db->join('people','customers.person_id=people.person_id'); - $this->db->where("(first_name LIKE '%".$this->db->escape_like_str($search)."%' or - last_name LIKE '%".$this->db->escape_like_str($search)."%' or - CONCAT(`first_name`,' ',`last_name`) LIKE '%".$this->db->escape_like_str($search)."%') and deleted=0"); - $this->db->order_by("last_name", "asc"); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[]=$row->person_id.'|'.$row->first_name.' '.$row->last_name; - } - - $this->db->from('customers'); - $this->db->join('people','customers.person_id=people.person_id'); - $this->db->where('deleted',0); - $this->db->like("account_number",$search); - $this->db->order_by("account_number", "asc"); - $by_account_number = $this->db->get(); - foreach($by_account_number->result() as $row) - { - $suggestions[]=$row->person_id.'|'.$row->account_number; - } - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0,$limit); - } - return $suggestions; - - } - function get_found_rows($search) { $this->db->from('customers'); diff --git a/application/models/Employee.php b/application/models/Employee.php index 6b49c0ac4..fcd914452 100644 --- a/application/models/Employee.php +++ b/application/models/Employee.php @@ -192,7 +192,7 @@ class Employee extends Person $by_name = $this->db->get(); foreach($by_name->result() as $row) { - $suggestions[]=$row->first_name.' '.$row->last_name; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name); } $this->db->from('employees'); @@ -203,7 +203,7 @@ class Employee extends Person $by_email = $this->db->get(); foreach($by_email->result() as $row) { - $suggestions[]=$row->email; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->email); } $this->db->from('employees'); @@ -214,7 +214,7 @@ class Employee extends Person $by_username = $this->db->get(); foreach($by_username->result() as $row) { - $suggestions[]=$row->username; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->username); } @@ -226,7 +226,7 @@ class Employee extends Person $by_phone = $this->db->get(); foreach($by_phone->result() as $row) { - $suggestions[]=$row->phone_number; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->phone_number); } diff --git a/application/models/Giftcard.php b/application/models/Giftcard.php index 879f53cd2..0ab2acc47 100644 --- a/application/models/Giftcard.php +++ b/application/models/Giftcard.php @@ -184,21 +184,21 @@ class Giftcard extends CI_Model foreach($by_number->result() as $row) { - $suggestions[]=$row->giftcard_number; + $suggestions[]=array('label' => $row->giftcard_number); } - $this->db->from('customers'); - $this->db->join('people', 'customers.person_id=people.person_id', 'left'); + $this->db->from('customers'); + $this->db->join('people', 'customers.person_id=people.person_id', 'left'); $this->db->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->where('deleted', 0); - $this->db->order_by('last_name', 'asc'); - $by_name = $this->db->get(); + $this->db->where('deleted', 0); + $this->db->order_by('last_name', 'asc'); + $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[]=$row->first_name.' '.$row->last_name; + foreach($by_name->result() as $row) + { + $suggestions[]=array('label' => $row->first_name.' '.$row->last_name); } //only return $limit suggestions @@ -209,49 +209,49 @@ 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'); + + /* + 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[]=$row->person_id; - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0,$limit); + $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); } - - return $suggestions; + + //only return $limit suggestions + if(count($suggestions > $limit)) + { + $suggestions = array_slice($suggestions, 0,$limit); + } + + return $suggestions; } /* Preform a search on giftcards */ function search($search, $rows = 0, $limit_from = 0) - { - $this->db->from('giftcards'); + { + $this->db->from('giftcards'); $this->db->join('people', 'giftcards.person_id=people.person_id', 'left'); - $this->db->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->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('giftcard_number', $this->db->escape_like_str($search)); $this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search)); $this->db->where('deleted', 0); @@ -261,7 +261,7 @@ class Giftcard extends CI_Model { $this->db->limit($rows, $limit_from); } - + return $this->db->get(); } diff --git a/application/models/Item.php b/application/models/Item.php index 8aa5ecb70..901a76ba0 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -263,156 +263,67 @@ class Item extends CI_Model return $this->db->update('items', array('deleted' => 1)); } - /* - Get search suggestions to find items - */ - public function get_search_suggestions($search, $limit=25, $search_custom=0, $is_deleted=0) + public function get_search_suggestions($search, $filters, $unique = FALSE, $limit=25) { $suggestions = array(); - $this->db->select('category'); + $this->db->select('item_id, name'); $this->db->from('items'); - $this->db->where('deleted', $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) + $this->db->where('deleted', $filters['is_deleted']); + $this->db->like('name', $search); + $this->db->order_by('name', 'asc'); + $by_name = $this->db->get(); + foreach($by_name->result() as $row) { - $suggestions[] = $row->category; + $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'); + $by_item_number = $this->db->get(); + foreach($by_item_number->result() as $row) + { + $suggestions[] = array('value' => $row->item_id, 'label' => $row->item_number); } $this->db->select('company_name'); $this->db->from('suppliers'); $this->db->like('company_name', $search); // restrict to non deleted companies only if is_deleted if false - if( $is_deleted == 0 ) - { - $this->db->where('deleted', $is_deleted); - } + $this->db->where('deleted', $filters['is_deleted']); $this->db->distinct(); $this->db->order_by('company_name', 'asc'); $by_company_name = $this->db->get(); foreach($by_company_name->result() as $row) { - $suggestions[] = $row->company_name; - } - - $this->db->select('name'); - $this->db->from('items'); - $this->db->like('name', $search); - $this->db->where('deleted', $is_deleted); - $this->db->order_by('name', 'asc'); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[] = $row->name; - } - - $this->db->select('item_number'); - $this->db->from('items'); - $this->db->like('item_number', $search); - $this->db->where('deleted', $is_deleted); - $this->db->order_by('item_number', 'asc'); - $by_item_number = $this->db->get(); - foreach($by_item_number->result() as $row) - { - $suggestions[] = $row->item_number; - } - - //Search by description - $this->db->select('name, description'); - $this->db->from('items'); - $this->db->like('description', $search); - $this->db->where('deleted', $is_deleted); - $this->db->order_by('description', 'asc'); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - if (!in_array($row->name, $suggestions)) - { - $suggestions[] = $row->name; - } - } - - //Search by custom fields - if ($search_custom != 0) - { - $this->db->from('items'); - $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->where('deleted', $is_deleted); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[] = $row->name; - } - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0, $limit); - } - - return $suggestions; - } - - public function get_item_search_suggestions($search, $limit=25, $search_custom=0, $is_deleted=0) - { - $suggestions = array(); - - $this->db->select('item_id, name'); - $this->db->from('items'); - $this->db->where('deleted', $is_deleted); - $this->db->like('name', $search); - $this->db->order_by('name', 'asc'); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[] = $row->item_id.'|'.$row->name; - } - - $this->db->select('item_id, item_number'); - $this->db->from('items'); - $this->db->where('deleted', $is_deleted); - $this->db->like('item_number', $search); - $this->db->order_by('item_number', 'asc'); - $by_item_number = $this->db->get(); - foreach($by_item_number->result() as $row) - { - $suggestions[] = $row->item_id.'|'.$row->item_number; + $suggestions[] = array('value' => $row->item_id, 'label' => $row->company_name); } //Search by description $this->db->select('item_id, name, description'); $this->db->from('items'); - $this->db->where('deleted', $is_deleted); + $this->db->where('deleted', $filters['is_deleted']); $this->db->like('description', $search); $this->db->order_by('description', 'asc'); $by_description = $this->db->get(); foreach($by_description->result() as $row) { - $entry = $row->item_id.'|'.$row->name; - if (!in_array($entry, $suggestions)) - { + $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 ($search_custom != 0) + if ($filters['search_custom'] != 0) { $this->db->from('items'); - $this->db->where('deleted', $is_deleted); + $this->db->where('deleted', $filters['is_deleted']); $this->db->like('custom1', $search); $this->db->or_like('custom2', $search); $this->db->or_like('custom3', $search); @@ -426,7 +337,7 @@ class Item extends CI_Model $by_description = $this->db->get(); foreach($by_description->result() as $row) { - $suggestions[] = $row->item_id.'|'.$row->name; + $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); } } @@ -451,7 +362,7 @@ class Item extends CI_Model $by_category = $this->db->get(); foreach($by_category->result() as $row) { - $suggestions[] = $row->category; + $suggestions[] = array('label' => $row->category); } return $suggestions; @@ -469,187 +380,26 @@ class Item extends CI_Model $by_category = $this->db->get(); foreach($by_category->result() as $row) { - $suggestions[] = $row->location; + $suggestions[] = array('label' => $row->location); } return $suggestions; } - public function get_custom1_suggestions($search) + public function get_custom_suggestions($search, $field_no) { $suggestions = array(); $this->db->distinct(); - $this->db->select('custom1'); + $this->db->select('custom'.$field_no); $this->db->from('items'); - $this->db->like('custom1', $search); + $this->db->like('custom'.$field_no, $search); $this->db->where('deleted', 0); - $this->db->order_by('custom1', 'asc'); + $this->db->order_by('custom'.$field_no, 'asc'); $by_category = $this->db->get(); foreach($by_category->result() as $row) { - $suggestions[] = $row->custom1; - } - - return $suggestions; - } - - public function get_custom2_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom2'); - $this->db->from('items'); - $this->db->like('custom2', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom2', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom2; - } - - return $suggestions; - } - - public function get_custom3_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom3'); - $this->db->from('items'); - $this->db->like('custom3', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom3', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom3; - } - - return $suggestions; - } - - public function get_custom4_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom4'); - $this->db->from('items'); - $this->db->like('custom4', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom4', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom4; - } - - return $suggestions; - } - - public function get_custom5_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom5'); - $this->db->from('items'); - $this->db->like('custom5', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom5', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom5; - } - - return $suggestions; - } - - public function get_custom6_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom6'); - $this->db->from('items'); - $this->db->like('custom6', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom6', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom6; - } - - return $suggestions; - } - - public function get_custom7_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom7'); - $this->db->from('items'); - $this->db->like('custom7', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom7', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom7; - } - - return $suggestions; - } - - public function get_custom8_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom8'); - $this->db->from('items'); - $this->db->like('custom8', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom8', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom8; - } - - return $suggestions; - } - - public function get_custom9_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom9'); - $this->db->from('items'); - $this->db->like('custom9', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom9', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom9; - } - - return $suggestions; - } - - public function get_custom10_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom10'); - $this->db->from('items'); - $this->db->like('custom10', $search); - $this->db->where('deleted', 0); - $this->db->order_by('custom10', 'asc'); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[] = $row->custom10; + $row_array = (array) $row; + $suggestions[] = array('label' => $row_array['custom'.$field_no]); } return $suggestions; @@ -665,7 +415,7 @@ class Item extends CI_Model return $this->db->get(); } - + /* * changes the cost price of a given item * calculates the average price between received items and items on stock @@ -673,10 +423,10 @@ class Item extends CI_Model * $items_received : the amount of new items received * $new_price : the cost-price for the newly received items * $old_price (optional) : the current-cost-price - * + * * used in receiving-process to update cost-price if changed * caution: must be used there before item_quantities gets updated, otherwise average price is wrong! - * + * */ public function change_cost_price($item_id, $items_received, $new_price, $old_price = null) { @@ -697,7 +447,7 @@ class Item extends CI_Model $average_price = bcdiv(bcadd(bcmul($items_received, $new_price), bcmul($old_total_quantity, $old_price)), $total_quantity); $data = array('cost_price' => $average_price); - + return $this->save($data, $item_id); } } diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 04b64e00e..7ab243ec2 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -118,54 +118,10 @@ class Item_kit extends CI_Model return $this->db->delete('item_kits'); } - /* - Get search suggestions to find kits - */ function get_search_suggestions($search, $limit=25) { $suggestions = array(); - $this->db->from('item_kits'); - - //KIT # - if (stripos($search, 'KIT ') !== false) - { - $this->db->like('item_kit_id', str_ireplace('KIT ', '', $search)); - - $this->db->order_by('item_kit_id', 'asc'); - $by_name = $this->db->get(); - - foreach($by_name->result() as $row) - { - $suggestions[] = 'KIT ' . $row->item_kit_id; - } - } - else - { - $this->db->like('name', $search); - - $this->db->order_by('name', 'asc'); - $by_name = $this->db->get(); - - foreach($by_name->result() as $row) - { - $suggestions[] = $row->name; - } - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0, $limit); - } - - return $suggestions; - } - - function get_item_kit_search_suggestions($search, $limit=25) - { - $suggestions = array(); - $this->db->from('item_kits'); $this->db->like('name', $search); $this->db->order_by('name', 'asc'); @@ -173,8 +129,7 @@ class Item_kit extends CI_Model foreach($by_name->result() as $row) { - // do not touch the '|' otherwise the sale search will not fetch the kit - $suggestions[] = 'KIT ' . $row->item_kit_id . '|' . $row->name; + $suggestions[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name); } //only return $limit suggestions diff --git a/application/models/Person.php b/application/models/Person.php index 787bc6106..20f39e73c 100644 --- a/application/models/Person.php +++ b/application/models/Person.php @@ -85,15 +85,15 @@ class Person extends CI_Model return $this->db->update('people',$person_data); } - /* - Get search suggestions to find customers - */ - function get_search_suggestions($search,$limit=25) - { - $suggestions = array(); - + /* + Get search suggestions to find customers + */ + function get_search_suggestions($search,$limit=25) + { + $suggestions = array(); + // $this->db->select("person_id"); -// $this->db->from('people'); +// $this->db->from('people'); // $this->db->where('deleted',0); // $this->db->where('person_id',$this->db->escape($search)); // $this->db->like('first_name',$this->db->escape_like_str($search)); @@ -101,20 +101,20 @@ class Person extends CI_Model // $this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search)); // $this->db->or_like('email',$search); // $this->db->or_like('phone_number',$search); -// $this->db->order_by('last_name', "asc"); - $by_person_id = $this->db->get(); +// $this->db->order_by('last_name', "asc"); + $by_person_id = $this->db->get(); - foreach($by_person_id->result() as $row) - { - $suggestions[]=$row->person_id; - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0,$limit); + 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; } diff --git a/application/models/Sale.php b/application/models/Sale.php index 0062e290a..40a2f542c 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -194,7 +194,7 @@ class Sale extends CI_Model foreach($this->db->get()->result_array() as $result) { - $suggestions[] = $result[ 'first_name' ].' '.$result[ 'last_name' ]; + $suggestions[] = array('label' => $result[ 'first_name' ].' '.$result[ 'last_name' ]); } } else diff --git a/application/models/Supplier.php b/application/models/Supplier.php index aaefeb416..04862c3a4 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -148,7 +148,7 @@ class Supplier extends Person $by_company_name = $this->db->get(); foreach($by_company_name->result() as $row) { - $suggestions[]=$row->company_name; + $suggestions[]=array('label' => $row->company_name); } $this->db->from('suppliers'); @@ -160,7 +160,7 @@ class Supplier extends Person $by_agency_name = $this->db->get(); foreach($by_agency_name->result() as $row) { - $suggestions[]=$row->agency_name; + $suggestions[]=array('label' => $row->agency_name); } $this->db->from('suppliers'); @@ -172,7 +172,7 @@ class Supplier extends Person $by_name = $this->db->get(); foreach($by_name->result() as $row) { - $suggestions[]=$row->first_name.' '.$row->last_name; + $suggestions[]=array('label' => $row->first_name.' '.$row->last_name); } $this->db->from('suppliers'); @@ -183,7 +183,7 @@ class Supplier extends Person $by_email = $this->db->get(); foreach($by_email->result() as $row) { - $suggestions[]=$row->email; + $suggestions[]=array('label' => $row->email); } $this->db->from('suppliers'); @@ -194,7 +194,7 @@ class Supplier extends Person $by_phone = $this->db->get(); foreach($by_phone->result() as $row) { - $suggestions[]=$row->phone_number; + $suggestions[]=array('label' => $row->phone_number); } $this->db->from('suppliers'); @@ -205,7 +205,7 @@ class Supplier extends Person $by_account_number = $this->db->get(); foreach($by_account_number->result() as $row) { - $suggestions[]=$row->account_number; + $suggestions[]=array('label' => $row->account_number); } //only return $limit suggestions @@ -232,7 +232,7 @@ class Supplier extends Person $by_company_name = $this->db->get(); foreach($by_company_name->result() as $row) { - $suggestions[]=$row->person_id.'|'.$row->company_name; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->company_name); } @@ -245,7 +245,7 @@ class Supplier extends Person $by_agency_name = $this->db->get(); foreach($by_agency_name->result() as $row) { - $suggestions[]=$row->person_id.'|'.$row->agency_name; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->agency_name); } @@ -258,7 +258,7 @@ class Supplier extends Person $by_name = $this->db->get(); foreach($by_name->result() as $row) { - $suggestions[]=$row->person_id.'|'.$row->first_name.' '.$row->last_name; + $suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name); } //only return $limit suggestions diff --git a/application/views/giftcards/form.php b/application/views/giftcards/form.php index bfa7a4741..e49be6bbe 100644 --- a/application/views/giftcards/form.php +++ b/application/views/giftcards/form.php @@ -8,11 +8,12 @@ lang->line('giftcards_person_id'), 'name', array('class'=>'control-label col-xs-3')); ?>
'person_id', - 'id'=>'person_id', + 'name'=>'person_name', + 'id'=>'person_name', 'class'=>'form-control input-sm', - 'value'=>$selected_person) + 'value'=>$selected_person_name) );?> +
@@ -46,22 +47,25 @@ //validation and submit handling $(document).ready(function() { - var format_item = function(row) - { - return [row[0], "|", row[1]].join(""); + var fill_value = function(event, ui) { + event.preventDefault(); + $("input[name='person_id']").val(ui.item.value); + $("input[name='person_name']").val(ui.item.label); }; - var autocompleter = $("#person_id").autocomplete('', + + var autocompleter = $("#person_name").autocomplete( { + source: '', minChars:0, delay:15, - max:100, cacheLength: 1, - formatItem: format_item, - formatResult : format_item + appendTo: '.modal-content', + select: fill_value, + focus: fill_value }); // declare submitHandler as an object.. will be reused - var submit_form = function(selected_person) + var submit_form = function() { $(this).ajaxSubmit( { @@ -72,7 +76,6 @@ $(document).ready(function() }, error: function(jqXHR, textStatus, errorThrown) { - selected_customer && autocompleter.val(selected_person); post_giftcard_form_submit({message: errorThrown}); }, dataType:'json' @@ -82,10 +85,7 @@ $(document).ready(function() $('#giftcard_form').validate($.extend({ submitHandler:function(form) { - var selected_person = autocompleter.val(); - var selected_person_id = selected_person && selected_person.replace(/(\w)\|.*/, "$1"); - selected_person_id && autocompleter.val(selected_person_id); - submit_form.call(form, selected_person); + submit_form.call(form) }, rules: { diff --git a/application/views/item_kits/form.php b/application/views/item_kits/form.php index 09006ff4c..20b78b8b1 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -54,7 +54,7 @@ ?> Item->get_info($item_kit_item['item_id']); ?> - + name; ?> ' name=item_kit_item[] value=''/> @@ -67,39 +67,33 @@ \ No newline at end of file diff --git a/application/views/items/form.php b/application/views/items/form.php index 226c9a2a8..7caad3d96 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -295,12 +295,29 @@ }); var no_op = function(event, data, formatted){}; - $("#category").autocomplete("",{max:100,minChars:0,delay:10}).result(no_op).search(); + $("#category").autocomplete({source: "",delay:10,appendTo: '.modal-content'}); - $("#custom"+).autocomplete("",{max:100,minChars:0,delay:10}).result(no_op).search(); + $("#custom"+).autocomplete({ + source:function (request, response) { + $.ajax({ + type: "POST", + url: "", + dataType: "json", + data: $.extend(request, {field_no: }), + success: function(data) { + response($.map(data, function(item) { + return { + value: item.label + }; + })) + } + }); + }, + delay:10, + appendTo: '.modal-content'}); diff --git a/application/views/items/manage.php b/application/views/items/manage.php index 2c87663f8..7934a9f24 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -177,7 +177,7 @@ function post_bulk_form_submit(response) -'search_form')); ?> +'search_form', 'class'=>'form-horizontal')); ?>