From 21f5e4648860601d8d150fa93b1e7f3852db659a Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 8 Jul 2016 08:38:05 +0200 Subject: [PATCH] Fix tax percentage parsing (#458, #727) Add tabindexes to price, discount field in register --- application/controllers/Config.php | 4 ++-- application/controllers/Items.php | 5 +++-- application/controllers/Receivings.php | 2 +- application/controllers/Sales.php | 2 +- application/helpers/locale_helper.php | 6 +++++- application/views/configs/locale_config.php | 2 +- application/views/sales/register.php | 20 ++++++++++---------- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 4398ce711..8c003f4d6 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -58,9 +58,9 @@ class Config extends Secure_Controller { $batch_save_data = array( 'default_tax_1_rate' => parse_decimals($this->input->post('default_tax_1_rate')), - 'default_tax_1_name' => parse_decimals($this->input->post('default_tax_1_name')), + 'default_tax_1_name' => $this->input->post('default_tax_1_name'), 'default_tax_2_rate' => parse_decimals($this->input->post('default_tax_2_rate')), - 'default_tax_2_name' => parse_decimals($this->input->post('default_tax_2_name')), + 'default_tax_2_name' => $this->input->post('default_tax_2_name'), 'tax_included' => $this->input->post('tax_included') != NULL, 'receiving_calculate_average_price' => $this->input->post('receiving_calculate_average_price') != NULL, 'lines_per_page' => $this->input->post('lines_per_page'), diff --git a/application/controllers/Items.php b/application/controllers/Items.php index f0c9d8b25..f2ab2f9d7 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -370,9 +370,10 @@ class Items extends Secure_Controller $count = count($tax_percents); for ($k = 0; $k < $count; ++$k) { - if(is_numeric($tax_percents[$k])) + $tax_percentage = parse_decimals($tax_percents[$k]); + if(is_numeric($tax_percentage)) { - $items_taxes_data[] = array('name' => $tax_names[$k], 'percent' => parse_decimals($tax_percents[$k])); + $items_taxes_data[] = array('name' => $tax_names[$k], 'percent' => $tax_percentage); } } $success &= $this->Item_taxes->save($items_taxes_data, $item_id); diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 427d17694..c24935ab3 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -101,7 +101,7 @@ class Receivings extends Secure_Controller function numeric($str) { - return (bool) preg_match('/^[\-+]?([0-9]*[\.,])*?[0-9]+$/', $str); + return parse_decimals($str, 2); } public function edit_item($item_id) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 099fa9ea4..daf301988 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -282,7 +282,7 @@ class Sales extends Secure_Controller function numeric($str) { - return (bool) preg_match('/^[\-+]?([0-9]*[\.,])*?[0-9]+$/', $str); + return parse_decimals($str, 2); } public function edit_item($item_id) diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index 04132c793..d8ac76d1a 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -36,6 +36,10 @@ function to_currency_no_money($number) function to_tax_decimals($number) { + if (empty($number)) + { + return $number; + } return to_decimals($number, 'tax_decimals'); } @@ -51,7 +55,7 @@ function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL) $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $CI->config->item($decimals)); $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $CI->config->item($decimals)); $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $CI->config->item('currency_symbol')); - return $fmt->format(floatval($number)); + return $fmt->format($number); } function parse_decimals($number) diff --git a/application/views/configs/locale_config.php b/application/views/configs/locale_config.php index 80d9e023d..6fc5697ff 100644 --- a/application/views/configs/locale_config.php +++ b/application/views/configs/locale_config.php @@ -17,7 +17,7 @@
lang->line('config_number_locale'), 'number_locale', array('class' => 'control-label col-xs-2')); ?> -
+
config->item('number_locale'), array('class' => 'form-control input-sm', 'id' => 'number_locale')); ?>
diff --git a/application/views/sales/register.php b/application/views/sales/register.php index aaaf34418..992b632c6 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -67,6 +67,8 @@ if (isset($success))
+ + 'add_item_form', 'class'=>'form-horizontal panel panel-default')); ?>
    @@ -74,7 +76,7 @@ if (isset($success))
  • - 'item', 'id'=>'item', 'class'=>'form-control input-sm', 'size'=>'50', 'tabindex'=>'1')); ?> + 'item', 'id'=>'item', 'class'=>'form-control input-sm', 'size'=>'50', 'tabindex'=>++$tabindex)); ?>
  • @@ -118,7 +120,6 @@ if (isset($success)) } else { - $tabindex = 2; foreach(array_reverse($cart, true) as $line=>$item) { ?> @@ -135,7 +136,7 @@ if (isset($success)) if ($items_module_allowed) { ?> - 'price', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['price'])));?> + 'price', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['price']), 'tabindex'=>++$tabindex));?> 'quantity', 'class'=>'form-control input-sm', 'value'=>to_quantity_decimals($item['quantity']), 'tabindex'=>$tabindex)); + echo form_input(array('name'=>'quantity', 'class'=>'form-control input-sm', 'value'=>to_quantity_decimals($item['quantity']), 'tabindex'=>++$tabindex)); } ?> - 'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0)));?> + 'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex));?> lang->line('sales_update')?> > @@ -222,7 +223,6 @@ if (isset($success)) @@ -366,13 +366,13 @@ if (isset($success)) lang->line('sales_amount_tendered'); ?> - 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm disabled', 'disabled'=>'disabled', 'value'=>'0', 'size'=>'5', 'tabindex'=>$tabindex)); ?> + 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm disabled', 'disabled'=>'disabled', 'value'=>'0', 'size'=>'5', 'tabindex'=>++$tabindex)); ?> -
     lang->line('sales_complete_sale'); ?>
    +
     lang->line('sales_complete_sale'); ?>
    lang->line('sales_amount_tendered'); ?> - 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($amount_due), 'size'=>'5', 'tabindex'=>5)); ?> + 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($amount_due), 'size'=>'5', 'tabindex'=>++$tabindex)); ?> -
     lang->line('sales_add_payment'); ?>
    +
     lang->line('sales_add_payment'); ?>