From c3f2f41888a5e568f74a10c362f3d18157219880 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 9 May 2016 17:59:53 +0200 Subject: [PATCH] Fix barcode generation in items and item_kits (#537, #538) Enable sorting in takings (with static row below the table) (#293, #507) --- application/controllers/Giftcards.php | 4 ++- application/controllers/Sales.php | 4 ++- application/helpers/table_helper.php | 43 +++++++++++++++----------- application/models/Giftcard.php | 4 +-- application/models/Sale.php | 4 +-- application/views/giftcards/manage.php | 1 + application/views/item_kits/manage.php | 1 + application/views/items/manage.php | 1 + application/views/people/manage.php | 1 + application/views/receivings/form.php | 36 +++------------------ application/views/sales/form.php | 2 +- application/views/sales/manage.php | 1 + js/manage_tables.js | 8 ++--- 13 files changed, 49 insertions(+), 61 deletions(-) diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index b1539cbe0..f5d7bfbb3 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -26,8 +26,10 @@ class Giftcards extends Secure_area implements iData_controller $search = $this->input->get('search'); $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); - $giftcards = $this->Giftcard->search($search, $limit, $offset); + $giftcards = $this->Giftcard->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Giftcard->get_found_rows($search); $data_rows = array(); diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index d158722ec..0bf6f395a 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -60,6 +60,8 @@ class Sales extends Secure_area $search = $this->input->get('search'); $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); $is_valid_receipt = isset($search) ? $this->sale_lib->is_valid_receipt($search) : FALSE; @@ -75,7 +77,7 @@ class Sales extends Secure_area $filledup = array_fill_keys($this->input->get('filters'), TRUE); $filters = array_merge($filters, $filledup); - $sales = $this->Sale->search($search, $filters, $limit, $offset); + $sales = $this->Sale->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->Sale->get_found_rows($search, $filters); $payments = $this->Sale->get_payments_summary($search, $filters); $payment_summary = get_sales_manage_payments_summary($payments, $sales, $this); diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 8ef3fa4ca..0866171f2 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -6,9 +6,8 @@ function get_sales_manage_table_headers() $headers = array( array('sale_id' => $CI->lang->line('common_id')), - array('receipt_number' => $CI->lang->line('sales_receipt_number')), array('sale_time' => $CI->lang->line('sales_sale_time')), - array('customer' => $CI->lang->line('customers_customer')), + array('customer_name' => $CI->lang->line('customers_customer')), array('amount_tendered' => $CI->lang->line('sales_amount_tendered')), array('amount_due' => $CI->lang->line('sales_amount_due')), array('change_due' => $CI->lang->line('sales_change_due')), @@ -18,10 +17,10 @@ function get_sales_manage_table_headers() if($CI->config->item('invoice_enable') == TRUE) { $headers[] = array('invoice_number' => $CI->lang->line('sales_invoice_number')); - $headers[] = array('invoice' => ' '); + $headers[] = array('invoice' => ' ', 'sortable' => FALSE); } - return transform_headers(array_merge($headers, array(array( 'receipt' => ' ' )))); + return transform_headers(array_merge($headers, array(array( 'receipt' => ' ', 'sortable' => FALSE )))); } /* @@ -44,7 +43,7 @@ function get_sale_data_last_row($sales, $controller) return array( 'sale_id' => '-', - 'receipt_number' => ''.$CI->lang->line('sales_total').'', + 'sale_time' => ''.$CI->lang->line('sales_total').'', 'amount_tendered' => ''. to_currency($sum_amount_tendered).'', 'amount_due' => ''.to_currency($sum_change_due).'' ); @@ -57,9 +56,8 @@ function get_sale_data_row($sale, $controller) $row = array ( 'sale_id' => $sale->sale_id, - 'receipt_number' => 'POS ' . $sale->sale_id, 'sale_time' => date( $CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($sale->sale_time) ), - 'customer' => character_limiter( $sale->customer_name, 25), + 'customer_name' => character_limiter( $sale->customer_name, 25), 'amount_tendered' => to_currency( $sale->amount_tendered ), 'amount_due' => to_currency($sale->amount_due), 'change_due' => to_currency($sale->change_due), @@ -124,10 +122,19 @@ function transform_headers_readonly($array) function transform_headers($array) { - return json_encode(array_map(function($v) { - return array('field' => key($v), 'title' => current($v), 'checkbox' => (key($v) == 'checkbox'), 'sortable' => current($v) != '' - && current($v) != 'select' && key($v) != 'item_pic' && current($v) != ' '); - }, array_merge(array(array('checkbox' => 'select')), $array, array(array('edit' => ''))))); + $result = array(); + $array = array_merge(array(array('checkbox' => 'select', 'sortable' => FALSE)), + $array, array(array('edit' => ''))); + foreach($array as $element) + { + $result[] = array('field' => key($element), + 'title' => current($element), + 'sortable' => isset($element['sortable']) ? + $element['sortable'] : current($element) != '', + 'checkbox' => isset($element['checkbox']) ? + $element['checkbox'] : FALSE); + } + return json_encode($result); } function get_people_manage_table_headers() @@ -144,7 +151,7 @@ function get_people_manage_table_headers() if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id'))) { - $headers[] = array('messages' => ''); + $headers[] = array('messages' => '', 'sortable' => FALSE); } return transform_headers($headers); @@ -223,8 +230,8 @@ function get_items_manage_table_headers() array('cost_price' => $CI->lang->line('items_cost_price')), array('unit_price' => $CI->lang->line('items_unit_price')), array('quantity' => $CI->lang->line('items_quantity')), - array('tax_percents' => $CI->lang->line('items_tax_percents')), - array('item_pic' => $CI->lang->line('items_image')), + array('tax_percents' => $CI->lang->line('items_tax_percents'), 'sortable' => FALSE), + array('item_pic' => $CI->lang->line('items_image'), 'sortable' => FALSE), array('inventory' => ''), array('stock' => '') ); @@ -286,7 +293,7 @@ function get_giftcards_manage_table_headers() array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('giftcard_number' => $CI->lang->line('giftcards_giftcard_number')), - array('giftcard_value' => $CI->lang->line('giftcards_card_value')) + array('value' => $CI->lang->line('giftcards_card_value')) ); return transform_headers($headers); @@ -302,7 +309,7 @@ function get_giftcard_data_row($giftcard, $controller) 'last_name' => character_limiter($giftcard->last_name,13), 'first_name' => character_limiter($giftcard->first_name,13), 'giftcard_number' => $giftcard->giftcard_number, - 'giftcard_value' => to_currency($giftcard->value), + 'value' => to_currency($giftcard->value), 'edit' => anchor($controller_name."/view/$giftcard->giftcard_id", '', array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update')) )); @@ -316,8 +323,8 @@ function get_item_kits_manage_table_headers() array('item_kit_id' => $CI->lang->line('item_kits_kit')), array('name' => $CI->lang->line('item_kits_name')), array('description' => $CI->lang->line('item_kits_description')), - array('cost_price' => $CI->lang->line('items_cost_price')), - array('unit_price' => $CI->lang->line('items_unit_price')) + array('cost_price' => $CI->lang->line('items_cost_price'), 'sortable' => FALSE), + array('unit_price' => $CI->lang->line('items_unit_price'), 'sortable' => FALSE) ); return transform_headers($headers); diff --git a/application/models/Giftcard.php b/application/models/Giftcard.php index 35c0d6b2a..77dfc303d 100644 --- a/application/models/Giftcard.php +++ b/application/models/Giftcard.php @@ -195,7 +195,7 @@ class Giftcard extends CI_Model /* Preform a search on giftcards */ - function search($search, $rows = 0, $limit_from = 0) + function search($search, $rows = 0, $limit_from = 0, $sort = 'giftcard_number', $order = 'asc') { $this->db->from('giftcards'); $this->db->join('people', 'giftcards.person_id=people.person_id', 'left'); @@ -207,7 +207,7 @@ class Giftcard extends CI_Model $this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search)); $this->db->group_end(); $this->db->where('giftcards.deleted', 0); - $this->db->order_by('giftcard_number', 'asc'); + $this->db->order_by($sort, $order); if ($rows > 0) { diff --git a/application/models/Sale.php b/application/models/Sale.php index 44e4aff9b..21e0fd4d4 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -28,7 +28,7 @@ class Sale extends CI_Model /* Get the sales data for the takings (sales/manage) view */ - public function search($search, $filters, $rows=0, $limit_from=0) + public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'sale_date', $order = 'desc') { $this->db->select('sale_id, sale_date, sale_time, SUM(quantity_purchased) AS items_purchased, CONCAT(customer.first_name, " ", customer.last_name) AS customer_name, @@ -83,7 +83,7 @@ class Sale extends CI_Model } $this->db->group_by('sale_id'); - $this->db->order_by('sale_date', 'desc'); + $this->db->order_by($sort, $order); if ($rows > 0) { diff --git a/application/views/giftcards/manage.php b/application/views/giftcards/manage.php index 13004a1e2..b94b36df6 100644 --- a/application/views/giftcards/manage.php +++ b/application/views/giftcards/manage.php @@ -7,6 +7,7 @@ $(document).ready(function() resource: '', headers: , pageSize: config->item('lines_per_page'); ?>, + uniqueId: 'id', confirmDeleteMessage : 'lang->line($controller_name."_confirm_delete")?>' }); }); diff --git a/application/views/item_kits/manage.php b/application/views/item_kits/manage.php index 1d2399b45..75f5b1efc 100644 --- a/application/views/item_kits/manage.php +++ b/application/views/item_kits/manage.php @@ -9,6 +9,7 @@ $(document).ready(function() resource: '', headers: , pageSize: config->item('lines_per_page'); ?>, + uniqueId: 'item_kit_id', confirmDeleteMessage: 'lang->line($controller_name."_confirm_delete")?>' }); diff --git a/application/views/items/manage.php b/application/views/items/manage.php index 3c3a3e6bf..673524251 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -37,6 +37,7 @@ $(document).ready(function() resource: '', headers: , pageSize: config->item('lines_per_page'); ?>, + uniqueId: 'items.item_id', confirmDeleteMessage : 'lang->line($controller_name."_confirm_delete")?>', queryParams: function() { return $.extend(arguments[0], { diff --git a/application/views/people/manage.php b/application/views/people/manage.php index 4e20d2feb..f6538fbe6 100644 --- a/application/views/people/manage.php +++ b/application/views/people/manage.php @@ -9,6 +9,7 @@ $(document).ready(function() resource: '', headers: , pageSize: config->item('lines_per_page'); ?>, + uniqueId: 'person_id', confirmDeleteMessage : 'lang->line($controller_name."_confirm_delete")?>', enableActions: function() { diff --git a/application/views/receivings/form.php b/application/views/receivings/form.php index 22ea57690..a2bc23293 100755 --- a/application/views/receivings/form.php +++ b/application/views/receivings/form.php @@ -54,10 +54,6 @@ -'recvs_delete_form')); ?> - - - diff --git a/application/views/sales/form.php b/application/views/sales/form.php index 3fe3bcaf4..92e4c9c46 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -158,7 +158,7 @@ $(document).ready(function() $('button#delete').click(function() { dialog_support.hide(); - table_support.do_delete(); + table_support.do_delete('', ); }); var submit_form = function() diff --git a/application/views/sales/manage.php b/application/views/sales/manage.php index 2fe2d6fa1..d2901bc90 100755 --- a/application/views/sales/manage.php +++ b/application/views/sales/manage.php @@ -22,6 +22,7 @@ $(document).ready(function() resource: '', headers: , pageSize: config->item('lines_per_page'); ?>, + uniqueId: 'sale_id', confirmDeleteMessage : 'lang->line($controller_name."_confirm_delete")?>', onLoadSuccess: function(response) { $("#payment_summary").html(response.payment_summary); diff --git a/js/manage_tables.js b/js/manage_tables.js index 81ae5e1f6..867e40122 100644 --- a/js/manage_tables.js +++ b/js/manage_tables.js @@ -118,7 +118,7 @@ var selected_ids = function () { return $.map(table().getSelections(), function (element) { - return element.id; + return element[options.uniqueId]; }); }; @@ -146,9 +146,9 @@ .animate({backgroundColor: original}, "slow", "linear"); }; - var do_delete = function () { + var do_delete = function (url, ids) { if (confirm(options.confirmDeleteMessage)) { - $.post(options.resource + '/delete', {'ids[]': selected_ids()}, function (response) { + $.post((url || options.resource) + '/delete', {'ids[]': ids || selected_ids()}, function (response) { //delete was successful, remove checkbox rows if (response.success) { $(selected_rows()).each(function (index, element) { @@ -196,7 +196,7 @@ showColumns: true, clickToSelect: true, toolbar: '#toolbar', - uniqueId: 'id', + uniqueId: options.uniqueId || 'id', onCheck: enable_actions, onUncheck: enable_actions, onCheckAll: enable_actions,