Fix currency sorting in tabular_details (#1003)

This commit is contained in:
jekkos
2016-11-26 11:38:43 +01:00
parent 4304f5ceea
commit 2727e91c96
8 changed files with 119 additions and 69 deletions

View File

@@ -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'],

View File

@@ -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('(^$|&nbsp)', current($element)) ?
'print_hide' : '');
'print_hide' : '',
'sorter' => isset($element['sorter']) ?
$element ['sorter'] : '');
}
return json_encode($result);
}

View File

@@ -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'),

View File

@@ -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')

View File

@@ -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'),

View File

@@ -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'),

View File

@@ -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'),

View File

@@ -20,6 +20,16 @@
</div>
<script type="text/javascript">
function currency_sorter(a, b)
{
a = +a.replace(/[^0-9\.]+/g,"");
b = +b.replace(/[^0-9\.]+/g,"");
if (a > b) return 1;
if (a < b) return -1;
return 0;
}
$(document).ready(function()
{
<?php $this->load->view('partial/bootstrap_tables_locale'); ?>
@@ -28,6 +38,7 @@
var init_dialog = function()
{
<?php if (isset($editable)): ?>
table_support.submit_handler('<?php echo site_url("reports/get_detailed_" . $editable . "_row")?>');
dialog_support.init("a.modal-dlg");
@@ -35,7 +46,7 @@
};
$('#table').bootstrapTable({
columns: <?php echo transform_headers_readonly($headers['summary']); ?>,
columns: <?php echo transform_headers($headers['summary'], TRUE); ?>,
pageSize: <?php echo $this->config->item('lines_per_page'); ?>,
striped: true,
pagination: true,
@@ -56,7 +67,7 @@
onExpandRow: function (index, row, $detail) {
$detail.html('<table></table>').find("table").bootstrapTable({
columns: <?php echo transform_headers_readonly($headers['details']); ?>,
data: detail_data[row.id || $(row[0]).text().replace(/(POS|RECV)\s*/g, '')]
data: detail_data[(!isNaN(row.id) && row.id) || $(row[0] || row.id).text().replace(/(POS|RECV)\s*/g, '')]
});
}
});