diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index d8ac76d1a..6fa642474 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -6,22 +6,22 @@ function currency_side() { - $CI =& get_instance(); - $fmt = new \NumberFormatter($CI->config->item('number_locale'), \NumberFormatter::CURRENCY); - $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $CI->config->item('currency_symbol')); + $config = get_instance()->config; + $fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::CURRENCY); + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); return !preg_match('/^ยค/', $fmt->getPattern()); } function quantity_decimals() { - $CI =& get_instance(); - return $CI->config->item('quantity_decimals') ? $CI->config->item('quantity_decimals') : 0; + $config = get_instance()->config; + return $config->item('quantity_decimals') ? $config->item('quantity_decimals') : 0; } function totals_decimals() { - $CI =& get_instance(); - return $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 0; + $config = get_instance()->config; + return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0; } function to_currency($number, $escape = FALSE) @@ -36,10 +36,6 @@ function to_currency_no_money($number) function to_tax_decimals($number) { - if (empty($number)) - { - return $number; - } return to_decimals($number, 'tax_decimals'); } @@ -50,25 +46,32 @@ function to_quantity_decimals($number) function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL) { - $CI =& get_instance(); - $fmt = new \NumberFormatter($CI->config->item('number_locale'), $type); - $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')); + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter($config->item('number_locale'), $type); + $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals)); + $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals)); + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); return $fmt->format($number); } function parse_decimals($number) { - // ignore empty strings as they are just for empty input - if (empty($number)) + // ignore empty strings and return + if(empty($number)) { return $number; } - $CI =& get_instance(); - $fmt = new \NumberFormatter( $CI->config->item('number_locale'), \NumberFormatter::DECIMAL ); - $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $CI->config->item('quantity_decimals')); - $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $CI->config->item('quantity_decimals')); + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item('quantity_decimals')); + $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item('quantity_decimals')); return $fmt->parse($number); } diff --git a/database/database.sql b/database/database.sql index 837f7b70d..531e475c8 100644 --- a/database/database.sql +++ b/database/database.sql @@ -60,6 +60,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('dateformat', 'm/d/Y'), ('timeformat', 'H:i:s'), ('currency_symbol', '$'), +('number_locale', 'en_US'), ('currency_decimals', '2'), ('tax_decimals', '2'), ('quantity_decimals', '0'), diff --git a/database/migrate_phppos_dist.sql b/database/migrate_phppos_dist.sql index a21821db4..149b5d0f8 100644 --- a/database/migrate_phppos_dist.sql +++ b/database/migrate_phppos_dist.sql @@ -60,7 +60,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('dateformat', 'm/d/Y'), ('timeformat', 'H:i:s'), ('currency_symbol', '$'), -('decimal_point', '.'), +('number_locale', 'en_US'), ('currency_decimals', '2'), ('tax_decimals', '2'), ('quantity_decimals', '0'),