diff --git a/.gitignore b/.gitignore index 59c3fb532..cfed0a7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules bower_components -dist/*_bower.* +dist/ application/config/email.php application/config/database.php *.patch diff --git a/Gruntfile.js b/Gruntfile.js index 83d2032c6..849882418 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,7 @@ module.exports = function(grunt) { destPrefix: 'dist' }, files: { + 'jquery-ui.css': 'jquery-ui/themes/smoothness/jquery-ui.css', 'bootstrap.min.css': 'bootswatch-dist/css/bootstrap.min.css' } } @@ -99,7 +100,7 @@ module.exports = function(grunt) { closeTag: '', absolutePath: true }, - src: [ 'dist/*min.css' ], + src: [ 'dist/*.css' ], dest: 'application/views/partial/header.php' }, css_login: { @@ -109,7 +110,7 @@ module.exports = function(grunt) { closeTag: '', absolutePath: true }, - src: [ 'dist/bootstrap.min.css', 'css/login.css' ], + src: [ 'dist/jquery-ui.min.css', 'dist/bootstrap.min.css', 'css/login.css' ], dest: 'application/views/login.php' }, js: { diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 473325e6d..db409ef38 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->get('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..130dc629d 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -38,10 +38,10 @@ class Employees extends Person_controller /* Gives search suggestions based on what is being searched for */ - function suggest() + function suggest_search() { - $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..7645058e1 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -73,9 +73,8 @@ 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')); - - echo implode("\n", $suggestions); + $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), TRUE); + echo json_encode($suggestions); } function get_row() diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 4975bcd06..cb5351aa6 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -115,19 +115,21 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ + function suggest_search() + { + $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')); + echo json_encode($suggestions); + } + 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); - } - - function item_search() - { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'), $this->input->post('limit')); - - echo implode("\n",$suggestions); + $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array( + 'search_custom' => FALSE, + 'is_deleted' => FALSE), TRUE); + echo json_encode($suggestions); } /* @@ -135,9 +137,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 +147,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..5cd66f78c 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -16,15 +16,10 @@ 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); - } - - function supplier_search() - { - $suggestions = $this->Supplier->get_suppliers_search_suggestions($this->input->post('q'),$this->input->post('limit')); - echo implode("\n",$suggestions); + $suggestions = $this->Item->get_search_suggestions($this->input->get('term'), + array('is_deleted' => FALSE, 'search_custom' => FALSE), FALSE); + $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($this->input->get('term'))); + echo json_encode($suggestions); } function select_supplier() @@ -141,7 +136,8 @@ class Receivings extends Secure_area $receiving_info = $this->Receiving->get_info($receiving_id)->row_array(); $person_name = $receiving_info['first_name'] . " " . $receiving_info['last_name']; - $data['selected_supplier'] = !empty($receiving_info['supplier_id']) ? $receiving_info['supplier_id'] . "|" . $person_name : ""; + $data['selected_supplier_name'] = !empty($receiving_info['supplier_id']) ? $person_name : ""; + $data['selected_supplier_id'] = $receiving_info['supplier_id']; $data['receiving_info'] = $receiving_info; $this->load->view('receivings/form', $data); @@ -367,7 +363,7 @@ class Receivings extends Secure_area $receiving_data = array( 'receiving_time' => $date_formatter->format('Y-m-d H:i:s'), - 'supplier_id' => $this->input->post('supplier_id'), + 'supplier_id' => $this->input->post('supplier_id', TRUE) ? $this->input->post('supplier_id') : null, 'employee_id' => $this->input->post('employee_id'), 'comment' => $this->input->post('comment'), 'invoice_number' => $this->input->post('invoice_number') diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 76cb33b61..901ba3483 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -126,36 +126,23 @@ class Sales extends Secure_area function item_search() { $suggestions = array(); - $search = $this->input->post('q'); - $limit = $this->input->post('limit'); + $search = $this->input->get('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, + array('is_deleted' => FALSE, 'search_custom' => FALSE), FALSE)); + $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($search)); - echo implode("\n", $suggestions); + echo json_encode($suggestions); } - function customer_search() + function suggest_search() { - $search = $this->input->post('q'); - $limit = $this->input->post('limit'); - - $suggestions = $this->Customer->get_customer_search_suggestions($search, $limit); - - echo implode("\n", $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() @@ -642,7 +629,8 @@ class Sales extends Secure_area $sale_info = $this->Sale->get_info($sale_id)->row_array(); $person_name = $sale_info['first_name'] . " " . $sale_info['last_name']; - $data['selected_customer'] = !empty($sale_info['customer_id']) ? $sale_info['customer_id'] . "|" . $person_name : ""; + $data['selected_customer_name'] = !empty($sale_info['customer_id']) ? $person_name : ''; + $data['selected_customer_id'] = $sale_info['customer_id']; $data['sale_info'] = $sale_info; $this->load->view('sales/form', $data); diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index 48b4cac98..58d3c492d 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -41,8 +41,14 @@ 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); + $suggestions = $this->Supplier->get_search_suggestions($this->input->get('term'), TRUE); + echo json_encode($suggestions); + } + + function suggest_search() + { + $suggestions = $this->Supplier->get_search_suggestions($this->input->post('term'), FALSE); + 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..5e8dd9d03 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -263,170 +263,84 @@ 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) - { - $suggestions = array(); - - $this->db->select('category'); - $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) - { - $suggestions[] = $row->category; - } - - $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->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) + public function get_search_suggestions($search, $filters = array("is_deleted"), $unique = FALSE, $limit=25) { $suggestions = array(); $this->db->select('item_id, name'); $this->db->from('items'); - $this->db->where('deleted', $is_deleted); + $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->item_id.'|'.$row->name; + $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); } $this->db->select('item_id, item_number'); $this->db->from('items'); - $this->db->where('deleted', $is_deleted); + $this->db->where('deleted', $filters['is_deleted'] != null); $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->item_number); } - //Search by description - $this->db->select('item_id, name, description'); - $this->db->from('items'); - $this->db->where('deleted', $is_deleted); - $this->db->like('description', $search); - $this->db->order_by('description', 'asc'); - $by_description = $this->db->get(); - foreach($by_description->result() as $row) + if (!$unique) { - $entry = $row->item_id.'|'.$row->name; - if (!in_array($entry, $suggestions)) + $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 + $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[] = $entry; + $suggestions[] = array('value' => $row->item_id, 'label' => $row->company_name); } - } - //Search by custom fields - if ($search_custom != 0) - { + //Search by description + $this->db->select('item_id, name, description'); $this->db->from('items'); - $this->db->where('deleted', $is_deleted); - $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', $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) { - $suggestions[] = $row->item_id.'|'.$row->name; + $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'] != 0) + { + $this->db->from('items'); + $this->db->where('deleted', $filters['is_deleted']); + $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); + $by_description = $this->db->get(); + foreach($by_description->result() as $row) + { + $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + } } } @@ -451,7 +365,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 +383,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 +418,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 +426,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 +450,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..bb11ad8af 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -118,9 +118,6 @@ 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(); @@ -131,25 +128,25 @@ class Item_kit extends CI_Model 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; - } + $suggestions[] = array('value' => 'KIT '. $row->item_kit_id, 'label' => '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; + $suggestions[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name); } } @@ -161,30 +158,6 @@ class Item_kit extends CI_Model 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'); - $by_name = $this->db->get(); - - 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; - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0, $limit); - } - - return $suggestions; - } /* Perform a search on items 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..cb437d55b 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -194,12 +194,12 @@ 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 { - $suggestions[] = $search; + $suggestions[] = array('label' => $search); } return $suggestions; diff --git a/application/models/Supplier.php b/application/models/Supplier.php index aaefeb416..562d49db1 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -136,78 +136,79 @@ class Supplier extends Person /* Get search suggestions to find suppliers */ - function get_search_suggestions($search,$limit=25) + function get_search_suggestions($search, $unique = FALSE, $limit = 25) { $suggestions = array(); - + $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->join('people', 'suppliers.person_id=people.person_id'); $this->db->where('deleted', 0); - $this->db->like("company_name",$search); - $this->db->order_by("company_name", "asc"); + $this->db->like("company_name", $search); + $this->db->order_by("company_name", "asc"); $by_company_name = $this->db->get(); - foreach($by_company_name->result() as $row) - { - $suggestions[]=$row->company_name; + foreach ($by_company_name->result() as $row) { + $suggestions[] = array('value' => $row->person_id, 'label' => $row->company_name); } $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->join('people', 'suppliers.person_id=people.person_id'); $this->db->where('deleted', 0); $this->db->distinct(); - $this->db->like("agency_name",$search); - $this->db->order_by("agency_name", "asc"); + $this->db->like("agency_name", $search); + $this->db->where("agency_name", "<> null"); + $this->db->order_by("agency_name", "asc"); $by_agency_name = $this->db->get(); - foreach($by_agency_name->result() as $row) - { - $suggestions[]=$row->agency_name; - } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.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->first_name.' '.$row->last_name; - } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.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; + foreach ($by_agency_name->result() as $row) { + $suggestions[] = array('value' => $row->person_id, 'label' => $row->agency_name); } $this->db->from('suppliers'); - $this->db->join('people','suppliers.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[]=$row->phone_number; + $this->db->join('people', 'suppliers.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[] = array('value' => $row->person_id, 'label' => $row->first_name . ' ' . $row->last_name); } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.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) + + if (!$unique) { - $suggestions[]=$row->account_number; + $this->db->from('suppliers'); + $this->db->join('people','suppliers.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('suppliers'); + $this->db->join('people','suppliers.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('suppliers'); + $this->db->join('people','suppliers.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)) { @@ -216,60 +217,7 @@ class Supplier extends Person return $suggestions; } - - /* - Get search suggestions to find suppliers - */ - function get_suppliers_search_suggestions($search,$limit=25) - { - $suggestions = array(); - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->like("company_name",$search); - $this->db->order_by("company_name", "asc"); - $by_company_name = $this->db->get(); - foreach($by_company_name->result() as $row) - { - $suggestions[]=$row->person_id.'|'.$row->company_name; - } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->distinct(); - $this->db->like("agency_name",$search); - $this->db->order_by("agency_name", "asc"); - $by_agency_name = $this->db->get(); - foreach($by_agency_name->result() as $row) - { - $suggestions[]=$row->person_id.'|'.$row->agency_name; - } - - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.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; - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0,$limit); - } - return $suggestions; - - } - function get_found_rows($search) { $this->db->from('suppliers'); 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')); ?>