From 2727e91c96649110e78a8cb879e09962b97ed04b Mon Sep 17 00:00:00 2001 From: jekkos Date: Sat, 26 Nov 2016 11:38:43 +0100 Subject: [PATCH] Fix currency sorting in tabular_details (#1003) --- application/controllers/Reports.php | 47 ++++++++++++++++--- application/helpers/table_helper.php | 14 ++++-- .../models/reports/Detailed_receivings.php | 19 ++++---- application/models/reports/Detailed_sales.php | 29 ++++++------ .../models/reports/Specific_customer.php | 22 ++++----- .../models/reports/Specific_discount.php | 20 ++++---- .../models/reports/Specific_employee.php | 22 ++++----- application/views/reports/tabular_details.php | 15 +++++- 8 files changed, 119 insertions(+), 69 deletions(-) diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 9c9615511..682a9ce9d 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -723,7 +723,18 @@ class Reports extends Secure_Controller foreach($report_data['summary'] as $key => $row) { - $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['employee_name'], to_currency($row['subtotal']), to_currency($row['tax']), to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); + $summary_data[] = $this->xss_clean(array( + 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'sale_date' => $row['sale_date'], + 'quantity' => to_quantity_decimals($row['items_purchased']), + 'employee_name' => $row['employee_name'], + 'subtotal' => to_currency($row['subtotal']), + 'tax' => to_currency($row['tax']), + 'total' => to_currency($row['total']), + 'cost' => to_currency($row['cost']), + 'profit' => to_currency($row['profit']), + 'payment_type' => $row['payment_type'], + 'comment' => $row['comment'])); foreach($report_data['details'][$key] as $drow) { @@ -776,7 +787,18 @@ class Reports extends Secure_Controller foreach($report_data['summary'] as $key => $row) { - $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['customer_name'], to_currency($row['subtotal']), to_currency($row['tax']), to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); + $summary_data[] = $this->xss_clean(array( + 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'sale_date' => $row['sale_date'], + 'quantity' => to_quantity_decimals($row['items_purchased']), + 'customer_name' => $row['customer_name'], + 'subtotal' => to_currency($row['subtotal']), + 'tax' => to_currency($row['tax']), + 'total' => to_currency($row['total']), + 'cost' => to_currency($row['cost']), + 'profit' => to_currency($row['profit']), + 'payment_type' => $row['payment_type'], + 'comment' => $row['comment'])); foreach($report_data['details'][$key] as $drow) { @@ -831,7 +853,18 @@ class Reports extends Secure_Controller foreach($report_data['summary'] as $key => $row) { - $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['customer_name'], to_currency($row['subtotal']), to_currency($row['tax']), to_currency($row['total']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); + $summary_data[] = $this->xss_clean(array( + 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'sale_date' => $row['sale_date'], + 'quantity' => to_quantity_decimals($row['items_purchased']), + 'customer_name' => $row['customer_name'], + 'subtotal' => to_currency($row['subtotal']), + 'tax' => to_currency($row['tax']), + 'total' => to_currency($row['total']), + 'profit' => to_currency($row['profit']), + 'payment_type' => $row['payment_type'], + 'comment' => $row['comment'] + )); foreach($report_data['details'][$key] as $drow) { @@ -906,8 +939,8 @@ class Reports extends Secure_Controller 'id' => $row['sale_id'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), - 'employee' => $row['employee_name'], - 'customer' => $row['customer_name'], + 'employee_name' => $row['employee_name'], + 'customer_name' => $row['customer_name'], 'subtotal' => to_currency($row['subtotal']), 'tax' => to_currency($row['tax']), 'total' => to_currency($row['total']), @@ -996,8 +1029,8 @@ class Reports extends Secure_Controller 'id' => $row['receiving_id'], 'receiving_date' => $row['receiving_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), - 'employee' => $row['employee_name'], - 'supplier' => $row['supplier_name'], + 'employee_name' => $row['employee_name'], + 'supplier_name' => $row['supplier_name'], 'total' => to_currency($row['total']), 'payment_type' => $row['payment_type'], 'reference' => $row['reference'], diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 93dd86221..731b636f2 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -124,8 +124,14 @@ function transform_headers_readonly($array) function transform_headers($array) { $result = array(); - $array = array_merge(array(array('checkbox' => 'select', 'sortable' => FALSE)), - $array, array(array('edit' => ''))); + + if (!readonly) + { + $array = array_merge(array(array('checkbox' => 'select', 'sortable' => FALSE)), $array); + } + + $array[] = array('edit' => ''); + foreach($array as $element) { $result[] = array('field' => key($element), @@ -137,7 +143,9 @@ function transform_headers($array) 'checkbox' => isset($element['checkbox']) ? $element['checkbox'] : FALSE, 'class' => isset($element['checkbox']) || preg_match('(^$| )', current($element)) ? - 'print_hide' : ''); + 'print_hide' : '', + 'sorter' => isset($element['sorter']) ? + $element ['sorter'] : ''); } return json_encode($result); } diff --git a/application/models/reports/Detailed_receivings.php b/application/models/reports/Detailed_receivings.php index a1d4e7064..48c8eb9a4 100644 --- a/application/models/reports/Detailed_receivings.php +++ b/application/models/reports/Detailed_receivings.php @@ -19,16 +19,15 @@ class Detailed_receivings extends Report { $columns = array( 'summary' => array( - 'id' => $this->lang->line('reports_receiving_id'), - 'receiving_date' => $this->lang->line('reports_date'), - 'quantity' => $this->lang->line('reports_quantity'), - 'employee' => $this->lang->line('reports_received_by'), - 'supplier' => $this->lang->line('reports_supplied_by'), - 'total' => $this->lang->line('reports_total'), - 'payment_type' => $this->lang->line('reports_payment_type'), - 'reference' => $this->lang->line('receivings_reference'), - 'comment' => $this->lang->line('reports_comments'), - 'edit' => ''), + array('id' => $this->lang->line('reports_receiving_id')), + array('receiving_date' => $this->lang->line('reports_date')), + array('quantity' => $this->lang->line('reports_quantity')), + array('employee_name' => $this->lang->line('reports_received_by')), + array('supplier' => $this->lang->line('reports_supplied_by')), + array('total' => $this->lang->line('reports_total'), 'sorter' => 'currency_sorter'), + array('payment_type' => $this->lang->line('reports_payment_type')), + array('reference' => $this->lang->line('receivings_reference')), + array('comment' => $this->lang->line('reports_comments'))), 'details' => array( $this->lang->line('reports_item_number'), $this->lang->line('reports_name'), diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index c4beef861..fa1109312 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -19,19 +19,18 @@ class Detailed_sales extends Report { return array( 'summary' => array( - 'id' => $this->lang->line('reports_sale_id'), - 'sale_date' => $this->lang->line('reports_date'), - 'quantity' => $this->lang->line('reports_quantity'), - 'employee' => $this->lang->line('reports_sold_by'), - 'customer' => $this->lang->line('reports_sold_to'), - 'subtotal' => $this->lang->line('reports_subtotal'), - 'tax' => $this->lang->line('reports_tax'), - 'total' => $this->lang->line('reports_total'), - 'cost' => $this->lang->line('reports_cost'), - 'profit' => $this->lang->line('reports_profit'), - 'payment_type' => $this->lang->line('sales_amount_tendered'), - 'comment' => $this->lang->line('reports_comments'), - 'edit' => ''), + array('id' => $this->lang->line('reports_sale_id')), + array('sale_date' => $this->lang->line('reports_date')), + array('quantity' => $this->lang->line('reports_quantity')), + array('employee_name' => $this->lang->line('reports_sold_by')), + array('customer_name' => $this->lang->line('reports_sold_to')), + array('subtotal' => $this->lang->line('reports_subtotal'), 'sorter' => 'currency_sorter'), + array('total' => $this->lang->line('reports_total'), 'sorter' => 'currency_sorter'), + array('tax' => $this->lang->line('reports_tax'), 'sorter' => 'currency_sorter'), + array('cost' => $this->lang->line('reports_cost'), 'sorter' => 'currency_sorter'), + array('profit' => $this->lang->line('reports_profit'), 'sorter' => 'currency_sorter'), + array('payment_type' => $this->lang->line('sales_amount_tendered')), + array('comment' => $this->lang->line('reports_comments'))), 'details' => array( $this->lang->line('reports_name'), $this->lang->line('reports_category'), @@ -44,7 +43,7 @@ class Detailed_sales extends Report $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) - ); + ); } public function getDataBySaleId($sale_id) @@ -100,7 +99,7 @@ class Detailed_sales extends Report if($inputs['location_id'] != 'all') { - $this->db->where('item_location', $inputs['location_id']); + $this->db->where('item_location', $inputs['location_id']); } if($inputs['sale_type'] == 'sales') diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 0371eecdf..83b2d2f50 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -19,17 +19,17 @@ class Specific_customer extends Report { return array( 'summary' => array( - $this->lang->line('reports_sale_id'), - $this->lang->line('reports_date'), - $this->lang->line('reports_quantity'), - $this->lang->line('reports_sold_by'), - $this->lang->line('reports_subtotal'), - $this->lang->line('reports_tax'), - $this->lang->line('reports_total'), - $this->lang->line('reports_cost'), - $this->lang->line('reports_profit'), - $this->lang->line('reports_payment_type'), - $this->lang->line('reports_comments')), + array('id' => $this->lang->line('reports_sale_id')), + array('sale_date' => $this->lang->line('reports_date')), + array('quantity' => $this->lang->line('reports_quantity')), + array('sold_by' => $this->lang->line('reports_sold_by')), + array('subtotal' => $this->lang->line('reports_subtotal'), 'sorter' => 'currency_sorter'), + array('tax' => $this->lang->line('reports_tax'), 'sorter' => 'currency_sorter'), + array('total' => $this->lang->line('reports_total'), 'sorter' => 'currency_sorter'), + array('cost' => $this->lang->line('reports_cost'), 'sorter' => 'currency_sorter'), + array('profit' => $this->lang->line('reports_profit'), 'sorter' => 'currency_sorter'), + array('payment_type' => $this->lang->line('reports_payment_type')), + array('comments' => $this->lang->line('reports_comments'))), 'details' => array( $this->lang->line('reports_name'), $this->lang->line('reports_category'), diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index c57c36fc6..900083016 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -19,16 +19,16 @@ class Specific_discount extends Report { return array( 'summary' => array( - $this->lang->line('reports_sale_id'), - $this->lang->line('reports_date'), - $this->lang->line('reports_quantity'), - $this->lang->line('reports_sold_to'), - $this->lang->line('reports_subtotal'), - $this->lang->line('reports_tax'), - $this->lang->line('reports_total'), - $this->lang->line('reports_profit'), - $this->lang->line('reports_payment_type'), - $this->lang->line('reports_comments')), + array('id' => $this->lang->line('reports_sale_id')), + array('sale_date' => $this->lang->line('reports_date')), + array('quantity' => $this->lang->line('reports_quantity')), + array('customer_name' => $this->lang->line('reports_sold_to')), + array('subtotal' => $this->lang->line('reports_subtotal'), 'sorter' => 'currency_sorter'), + array('tax' => $this->lang->line('reports_tax'), 'sorter' => 'currency_sorter'), + array('total' => $this->lang->line('reports_total'), 'sorter' => 'currency_sorter'), + array('profit' => $this->lang->line('reports_profit'), 'sorter' => 'currency_sorter'), + array('payment_type' => $this->lang->line('reports_payment_type')), + array('comments' => $this->lang->line('reports_comments'))), 'details' => array( $this->lang->line('reports_name'), $this->lang->line('reports_category'), diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 3b9c8bbf5..1366352db 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -19,17 +19,17 @@ class Specific_employee extends Report { return array( 'summary' => array( - $this->lang->line('reports_sale_id'), - $this->lang->line('reports_date'), - $this->lang->line('reports_quantity'), - $this->lang->line('reports_sold_to'), - $this->lang->line('reports_subtotal'), - $this->lang->line('reports_tax'), - $this->lang->line('reports_total'), - $this->lang->line('reports_cost'), - $this->lang->line('reports_profit'), - $this->lang->line('reports_payment_type'), - $this->lang->line('reports_comments')), + array('id' => $this->lang->line('reports_sale_id')), + array('sale_date' => $this->lang->line('reports_date')), + array('quantity' => $this->lang->line('reports_quantity')), + array('customer_name' => $this->lang->line('reports_sold_to')), + array('subtotal' => $this->lang->line('reports_subtotal'), 'sorter' => 'currency_sorter'), + array('tax' => $this->lang->line('reports_tax'), 'sorter' => 'currency_sorter'), + array('total' => $this->lang->line('reports_total'), 'sorter' => 'currency_sorter'), + array('cost' => $this->lang->line('reports_cost'), 'sorter' => 'currency_sorter'), + array('profit' => $this->lang->line('reports_profit'), 'sorter' => 'currency_sorter'), + array('payment_type' => $this->lang->line('reports_payment_type')), + array('comments' => $this->lang->line('reports_comments'))), 'details' => array( $this->lang->line('reports_name'), $this->lang->line('reports_category'), diff --git a/application/views/reports/tabular_details.php b/application/views/reports/tabular_details.php index fbd1cb677..3f1dd4815 100644 --- a/application/views/reports/tabular_details.php +++ b/application/views/reports/tabular_details.php @@ -20,6 +20,16 @@