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 1b3647e32..db409ef38 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -40,7 +40,7 @@ class Customers extends Person_controller */ function suggest() { - $suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), TRUE); + $suggestions = $this->Customer->get_search_suggestions($this->input->get('term'), TRUE); echo json_encode($suggestions); } diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index 6d6a5a70a..130dc629d 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -38,7 +38,7 @@ 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('term')); echo json_encode($suggestions); diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index ad652ed41..7645058e1 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -73,8 +73,7 @@ class Item_kits extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), $this->input->post('limit')); - + $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), TRUE); echo json_encode($suggestions); } diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 53abe45d5..cb5351aa6 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -115,18 +115,20 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ - function suggest() + function suggest_search() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('term'), array( + $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array( 'search_custom' => $this->input->post('search_custom'), - 'is_deleted' => $this->input->post('is_deleted') != "0"), + 'is_deleted' => !empty($this->input->post('is_deleted'))), FALSE, $this->input->post('limit')); echo json_encode($suggestions); } - function suggest_search() + function suggest() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('term'), TRUE); + $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array( + 'search_custom' => FALSE, + 'is_deleted' => FALSE), TRUE); echo json_encode($suggestions); } diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 0e5aca336..5cd66f78c 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -16,14 +16,9 @@ class Receivings extends Secure_area function item_search() { - $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('term'),$this->input->post('limit')); + $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); } @@ -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 dcd588582..901ba3483 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -126,19 +126,20 @@ class Sales extends Secure_area function item_search() { $suggestions = array(); - $search = $this->input->post('term'); + $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_search_suggestions($search)); - $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($search)); + $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 json_encode($suggestions); } - function suggest() + function suggest_search() { $suggestions = $this->Sale->get_search_suggestions($this->input->post('term')); echo json_encode($suggestions); @@ -628,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 5f032ba61..58d3c492d 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -41,7 +41,13 @@ class Suppliers extends Person_controller */ function suggest() { - $suggestions = $this->Supplier->get_search_suggestions($this->input->post('q'),$this->input->post('limit')); + $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/Item.php b/application/models/Item.php index 901a76ba0..5e8dd9d03 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -263,7 +263,7 @@ class Item extends CI_Model return $this->db->update('items', array('deleted' => 1)); } - public function get_search_suggestions($search, $filters, $unique = FALSE, $limit=25) + public function get_search_suggestions($search, $filters = array("is_deleted"), $unique = FALSE, $limit=25) { $suggestions = array(); @@ -280,7 +280,7 @@ class Item extends CI_Model $this->db->select('item_id, item_number'); $this->db->from('items'); - $this->db->where('deleted', $filters['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(); @@ -289,55 +289,58 @@ class Item extends CI_Model $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 - $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) + if (!$unique) { - $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', $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 = array('value' => $row->item_id, 'label' => $row->name); - if (!array_walk($suggestions, function($value, $label) use ($entry) { - return $entry['label'] != $label; - })) { - $suggestions[] = $entry; + $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[] = array('value' => $row->item_id, 'label' => $row->company_name); } - } - //Search by custom fields - if ($filters['search_custom'] != 0) - { + //Search by description + $this->db->select('item_id, name, description'); $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); + $this->db->like('description', $search); + $this->db->order_by('description', 'asc'); $by_description = $this->db->get(); foreach($by_description->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $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); + } } } diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 7ab243ec2..bb11ad8af 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -123,13 +123,31 @@ class Item_kit extends CI_Model $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) + //KIT # + if (stripos($search, 'KIT ') !== false) { - $suggestions[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name); + $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[] = 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[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name); + } } //only return $limit suggestions diff --git a/application/models/Sale.php b/application/models/Sale.php index 40a2f542c..cb437d55b 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -199,7 +199,7 @@ class Sale extends CI_Model } else { - $suggestions[] = $search; + $suggestions[] = array('label' => $search); } return $suggestions; diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 04862c3a4..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[]=array('label' => $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[]=array('label' => $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[]=array('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("email",$search); - $this->db->order_by("email", "asc"); - $by_email = $this->db->get(); - foreach($by_email->result() as $row) - { - $suggestions[]=array('label' => $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[]=array('label' => $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[]=array('label' => $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[]=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->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[]=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("(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); - } - - //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/item_kits/form.php b/application/views/item_kits/form.php index 20b78b8b1..d2bab0d62 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -72,7 +72,7 @@ $(document).ready(function() { $("#item").autocomplete({ - source: '', + source: '', minChars:0, autoFocus: false, delay:10, @@ -87,6 +87,7 @@ $(document).ready(function() $("#item_kit_items").append("