From 264248b381bc3a50b7ed1b958a25e29c4ade9878 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Sat, 30 Nov 2013 19:02:31 +0100 Subject: [PATCH] Added autocompletion for the customer field in the sale editing screen --- application/controllers/sales.php | 8 +++++--- application/models/sale.php | 3 +++ application/views/sales/edit.php | 20 ++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 3e6ddd7f5..73f582e32 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -269,8 +269,10 @@ class Sales extends Secure_area $data['employees'][$employee->person_id] = $employee->first_name . ' '. $employee->last_name; } - $data['sale_info'] = $this->Sale->get_info($sale_id)->row_array(); - + $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['sale_info'] = $sale_info; $this->load->view('sales/edit', $data); } @@ -428,4 +430,4 @@ class Sales extends Secure_area $this->_reload(); } } -?> \ No newline at end of file +?> diff --git a/application/models/sale.php b/application/models/sale.php index 6867fc803..66af0a43c 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -3,7 +3,10 @@ class Sale extends CI_Model { public function get_info($sale_id) { + $this->db->select('sales.*', FALSE); + $this->db->select('people.*', FALSE); $this->db->from('sales'); + $this->db->join('people', 'people.person_id = sales.customer_id', 'LEFT'); $this->db->where('sale_id',$sale_id); return $this->db->get(); } diff --git a/application/views/sales/edit.php b/application/views/sales/edit.php index a93f7577f..5c67ec68e 100644 --- a/application/views/sales/edit.php +++ b/application/views/sales/edit.php @@ -22,7 +22,7 @@
lang->line('sales_customer').':', 'customer'); ?>
- + 'customer_id', 'value' => $selected_customer, 'id' => 'customer_id'));?>
@@ -75,16 +75,32 @@ $(document).ready(function() return false; } }); + + var formatItem = function(row) { + return [row[0], "|", row[1]].join(""); + }; + var autoCompleter = $("#customer_id").autocomplete('', { + minChars:0, + delay:15, + max:100, + cacheLength: 1, + formatItem: formatItem, + formatResult : formatItem + }); $('#sales_edit_form').validate({ submitHandler:function(form) { + var selectedCustomer = autoCompleter.val(); + var selectedCustomerId = selectedCustomer.replace(/(\w)\|.*/, "$1"); + selectedCustomerId && autoCompleter.val(selectedCustomerId); $(form).ajaxSubmit({ success:function(response) { if(response.success) { set_feedback(response.message,'success_message',false); + autoCompleter.val(selectedCustomer); } else { @@ -106,4 +122,4 @@ $(document).ready(function() } }); }); - \ No newline at end of file +