From d94b1d921e4501c96028661683d2a03fae7451f2 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 9 May 2016 08:35:09 +0200 Subject: [PATCH] Enable sorting for items, customers, suppliers, employees and item_kits module (#293, #507) --- application/controllers/Customers.php | 4 +- application/controllers/Item_kits.php | 7 +-- application/controllers/Items.php | 4 +- application/helpers/table_helper.php | 43 ++++++++++--------- application/models/Customer.php | 4 +- application/models/Item.php | 4 +- application/models/Item_kit.php | 4 +- application/views/reports/tabular.php | 1 + application/views/reports/tabular_details.php | 1 + 9 files changed, 40 insertions(+), 32 deletions(-) diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 3df05c9f8..8d48add67 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -23,8 +23,10 @@ class Customers extends Person_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'); - $customers = $this->Customer->search($search, $limit, $offset); + $customers = $this->Customer->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Customer->get_found_rows($search); $data_rows = array(); diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 115c06362..5ec15e2a0 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -42,11 +42,12 @@ class Item_kits extends Secure_area implements iData_controller $search = $this->input->get('search'); $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); - $lines_per_page = $this->Appconfig->get('lines_per_page'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); - $item_kits = $this->Item_kit->search($search, $limit, $offset); + $item_kits = $this->Item_kit->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Item_kit->get_found_rows($search); - //$links = $this->_initialize_pagination($this->Item_kit, $lines_per_page, $limit, $total_rows, 'search'); + $data_rows = array(); foreach($item_kits->result() as $item_kit) { diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 99ec61d4c..2ed3d255c 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -40,6 +40,8 @@ class Items 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'); $this->item_lib->set_item_location($this->input->get('stock_location')); @@ -57,7 +59,7 @@ class Items extends Secure_area implements iData_controller $filledup = array_fill_keys($this->input->get('filters'), true); $filters = array_merge($filters, $filledup); - $items = $this->Item->search($search, $filters, $limit, $offset); + $items = $this->Item->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->Item->get_found_rows($search, $filters); $data_rows = array(); diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 7ac356c0b..8ef3fa4ca 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -5,7 +5,7 @@ function get_sales_manage_table_headers() $CI =& get_instance(); $headers = array( - array('id' => $CI->lang->line('common_id')), + 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')), @@ -43,7 +43,7 @@ function get_sale_data_last_row($sales, $controller) } return array( - 'id' => '-', + 'sale_id' => '-', 'receipt_number' => ''.$CI->lang->line('sales_total').'', 'amount_tendered' => ''. to_currency($sum_amount_tendered).'', 'amount_due' => ''.to_currency($sum_change_due).'' @@ -56,7 +56,7 @@ function get_sale_data_row($sale, $controller) $controller_name = $CI->uri->segment(1); $row = array ( - 'id' => $sale->sale_id, + '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), @@ -116,7 +116,7 @@ function transform_headers_readonly($array) $result = array(); foreach($array as $key => $value) { - $result[] = array('field' => $key, 'title' => $value); + $result[] = array('field' => $key, 'title' => $value, 'sortable' => $value != ''); } return json_encode($result); @@ -125,7 +125,8 @@ 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')); + 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' => ''))))); } @@ -134,7 +135,7 @@ function get_people_manage_table_headers() $CI =& get_instance(); $headers = array( - array('id' => $CI->lang->line('common_id')), + array('people.person_id' => $CI->lang->line('common_id')), array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('email' => $CI->lang->line('common_email')), @@ -155,7 +156,7 @@ function get_person_data_row($person, $controller) $controller_name=strtolower(get_class($CI)); return array ( - 'id' => $person->person_id, + 'people.person_id' => $person->person_id, 'last_name' => character_limiter($person->last_name,13), 'first_name' => character_limiter($person->first_name,13), 'email' => empty($person->email) ? '' : mailto($person->email,character_limiter($person->email,22)), @@ -172,7 +173,7 @@ function get_suppliers_manage_table_headers() $CI =& get_instance(); $headers = array( - array('id' => $CI->lang->line('common_id')), + array('people.person_id' => $CI->lang->line('common_id')), array('company_name' => $CI->lang->line('suppliers_company_name')), array('agency_name' => $CI->lang->line('suppliers_agency_name')), array('last_name' => $CI->lang->line('common_last_name')), @@ -195,7 +196,7 @@ function get_supplier_data_row($supplier, $controller) $controller_name=strtolower(get_class($CI)); return array ( - 'id' => $supplier->person_id, + 'people.person_id' => $supplier->person_id, 'company_name' => character_limiter($supplier->company_name,13), 'agency_name' => character_limiter($supplier->agency_name,13), 'last_name' => character_limiter($supplier->last_name,13), @@ -214,10 +215,10 @@ function get_items_manage_table_headers() $CI =& get_instance(); $headers = array( - array('id' => $CI->lang->line('common_id')), + array('items.item_id' => $CI->lang->line('common_id')), array('item_number' => $CI->lang->line('items_item_number')), - array('item_name' => $CI->lang->line('items_name')), - array('item_category' => $CI->lang->line('items_category')), + array('name' => $CI->lang->line('items_name')), + array('category' => $CI->lang->line('items_category')), array('company_name' => $CI->lang->line('suppliers_company_name')), array('cost_price' => $CI->lang->line('items_cost_price')), array('unit_price' => $CI->lang->line('items_unit_price')), @@ -255,10 +256,10 @@ function get_item_data_row($item, $controller) } return array ( - 'id' => $item->item_id, + 'items.item_id' => $item->item_id, 'item_number' => $item->item_number, - 'item_name' => character_limiter($item->name,13), - 'item_category' => character_limiter($item->category,13), + 'name' => character_limiter($item->name,13), + 'category' => character_limiter($item->category,13), 'company_name' => character_limiter($item->company_name,20), 'cost_price' => to_currency($item->cost_price), 'unit_price' => to_currency($item->unit_price), @@ -312,9 +313,9 @@ function get_item_kits_manage_table_headers() $CI =& get_instance(); $headers = array( - array('id' => $CI->lang->line('item_kits_kit')), - array('kit_name' => $CI->lang->line('item_kits_name')), - array('kit_description' => $CI->lang->line('item_kits_description')), + 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')) ); @@ -328,9 +329,9 @@ function get_item_kit_data_row($item_kit, $controller) $controller_name=strtolower(get_class($CI)); return array ( - 'id' => $item_kit->item_kit_id, - 'kit_name' => character_limiter($item_kit->name,13), - 'kit_description' => character_limiter($item_kit->description,13), + 'item_kit_id' => $item_kit->item_kit_id, + 'name' => character_limiter($item_kit->name), + 'description' => character_limiter($item_kit->description,13), 'cost_price' => to_currency($item_kit->total_cost_price), 'unit_price' => to_currency($item_kit->total_unit_price), 'edit' => anchor($controller_name."/view/$item_kit->item_kit_id", '', diff --git a/application/models/Customer.php b/application/models/Customer.php index e0288295a..c05b88ac0 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -241,7 +241,7 @@ class Customer extends Person /* Perform a search on customers */ - function search($search, $rows = 0, $limit_from = 0) + function search($search, $rows = 0, $limit_from = 0, $sort = 'last_name', $order = 'asc') { $this->db->from('customers'); $this->db->join('people', 'customers.person_id = people.person_id'); @@ -252,7 +252,7 @@ class Customer extends Person account_number 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"); + $this->db->order_by($sort, $order); if ($rows > 0) { $this->db->limit($rows, $limit_from); diff --git a/application/models/Item.php b/application/models/Item.php index c4303d4ba..38830b764 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -45,7 +45,7 @@ class Item extends CI_Model /* Perform a search on items */ - public function search($search, $filters, $rows=0, $limit_from=0) + public function search($search, $filters, $rows=0, $limit_from=0, $sort='items.name', $order='asc') { $this->db->from('items'); $this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left'); @@ -108,7 +108,7 @@ class Item extends CI_Model $this->db->group_by('items.item_id'); // order by name of item - $this->db->order_by('items.name', 'asc'); + $this->db->order_by($sort, $order); if ($rows > 0) { diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 13b94cd5e..91edef9b2 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -146,7 +146,7 @@ class Item_kit extends CI_Model /* Perform a search on items */ - function search($search, $rows=0, $limit_from=0) + function search($search, $rows=0, $limit_from=0, $sort='name', $order='asc') { $this->db->from('item_kits'); $this->db->like('name', $search); @@ -158,7 +158,7 @@ class Item_kit extends CI_Model $this->db->or_like('item_kit_id', str_ireplace('KIT ', '', $search)); } - $this->db->order_by('name', 'asc'); + $this->db->order_by($sort, $order); if ($rows > 0) { diff --git a/application/views/reports/tabular.php b/application/views/reports/tabular.php index 9b6f4012d..f395295f4 100644 --- a/application/views/reports/tabular.php +++ b/application/views/reports/tabular.php @@ -57,6 +57,7 @@ else columns: , pageSize: config->item('lines_per_page'); ?>, striped: true, + sortable: true, pagination: true, showColumns: true, data: , diff --git a/application/views/reports/tabular_details.php b/application/views/reports/tabular_details.php index b04c6c3ad..1ec58c12f 100644 --- a/application/views/reports/tabular_details.php +++ b/application/views/reports/tabular_details.php @@ -58,6 +58,7 @@ else pageSize: config->item('lines_per_page'); ?>, striped: true, pagination: true, + sortable: true, showColumns: true, uniqueId: 'id', data: ,