diff --git a/README.md b/README.md index 59edb1780..6c15d30f2 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,14 @@ Please also make sure you have updated all the files from latest master. Bug reports must follow this schema: -1. OS name and version running your Web Server (e.g. Linux Ubuntu 15.0) -2. Web Server name and version (e.g. Apache 2.4) -3. Database name and version (e.g. MySQL 5.6) -3. PHP version (e.g. PHP 5.5) -4. Language selected in OSPOS (e.g. English, Spanish) -5. Any configuration of OSPOS that you changed -6. Exact steps to reproduce the issue (test case) +1. OSPOS **version string with git commit hash** (see footer) +2. OS name and version running your Web Server (e.g. Linux Ubuntu 15.0) +3. Web Server name and version (e.g. Apache 2.4) +4. Database name and version (e.g. MySQL 5.6) +5. PHP version (e.g. PHP 5.5) +6. Language selected in OSPOS (e.g. English, Spanish) +7. Any configuration of OSPOS that you changed +8. Exact steps to reproduce the issue (test case) If above information is not provided in full, your issue will be tagged as pending. If missing information is not provided within a week we will close your issue. diff --git a/application/config/theme.php b/application/config/theme.php new file mode 100644 index 000000000..807e85503 --- /dev/null +++ b/application/config/theme.php @@ -0,0 +1,15 @@ + $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'))); } + function check_number_locale() + { + $number_locale = $this->input->post('number_locale'); + $fmt = new \NumberFormatter($number_locale, \NumberFormatter::CURRENCY); + $currency_symbol = empty($this->input->post('currency_symbol')) ? $fmt->getSymbol(\NumberFormatter::CURRENCY_SYMBOL) : $this->input->post('currency_symbol'); + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $currency_symbol); + $number_local_example = $fmt->format(1234567890.12300); + echo json_encode(array('success' => $number_local_example != FALSE, 'number_locale_example' => $number_local_example, 'currency_symbol' => $currency_symbol)); + } + function save_locale() { - $batch_save_data = array( + $batch_save_data = array( 'currency_symbol' => $this->input->post('currency_symbol'), - 'currency_side' => $this->input->post('currency_side') != NULL, 'language' => $this->input->post('language'), 'timezone' => $this->input->post('timezone'), 'dateformat' => $this->input->post('dateformat'), 'timeformat' => $this->input->post('timeformat'), - 'thousands_separator' => $this->input->post('thousands_separator'), - 'decimal_point' => $this->input->post('decimal_point'), + 'number_locale' => $this->input->post('number_locale'), 'currency_decimals' => $this->input->post('currency_decimals'), 'tax_decimals' => $this->input->post('tax_decimals'), 'quantity_decimals' => $this->input->post('quantity_decimals'), diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 361886bfc..624fae30e 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -322,8 +322,8 @@ class Items extends Secure_Controller 'category' => $this->input->post('category'), 'supplier_id' => $this->input->post('supplier_id') == '' ? NULL : $this->input->post('supplier_id'), 'item_number' => $this->input->post('item_number') == '' ? NULL : $this->input->post('item_number'), - 'cost_price' => $this->input->post('cost_price'), - 'unit_price' => $this->input->post('unit_price'), + 'cost_price' => parse_decimals($this->input->post('cost_price')), + 'unit_price' => parse_decimals($this->input->post('unit_price')), 'reorder_level' => $this->input->post('reorder_level'), 'receiving_quantity' => $this->input->post('receiving_quantity'), 'allow_alt_description' => $this->input->post('allow_alt_description') != NULL, diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 5e92f4df4..737659202 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -99,19 +99,24 @@ class Receivings extends Secure_Controller $this->_reload($data); } + function numeric($str) + { + return (bool) preg_match('/^[\-+]?[0-9]*[\.,]?[0-9]+$/', $str); + } + public function edit_item($item_id) { $data = array(); - $this->form_validation->set_rules('price', 'lang:items_price', 'required|numeric'); - $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|numeric'); - $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|numeric'); + $this->form_validation->set_rules('price', 'lang:items_price', 'required|callback_numeric'); + $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|callback_numeric'); + $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|callback_numeric'); $description = $this->input->post('description'); $serialnumber = $this->input->post('serialnumber'); - $price = $this->input->post('price'); - $quantity = $this->input->post('quantity'); - $discount = $this->input->post('discount'); + $price = parse_decimals($this->input->post('price')); + $quantity = parse_decimals($this->input->post('quantity')); + $discount = parse_decimals($this->input->post('discount')); $item_location = $this->input->post('location'); if($this->form_validation->run() != FALSE) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 8957b51e6..6e3da6bb5 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -183,7 +183,7 @@ class Sales extends Secure_Controller $this->form_validation->set_rules('amount_tendered', 'lang:sales_amount_tendered', 'trim|required|numeric'); $payment_type = $this->input->post('payment_type'); - $amount_tendered = $this->input->post('amount_tendered'); + $amount_tendered = parse_decimals($this->input->post('amount_tendered')); if($this->form_validation->run() == FALSE) { @@ -280,19 +280,24 @@ class Sales extends Secure_Controller $this->_reload($data); } + function numeric($str) + { + return (bool) preg_match('/^[\-+]?[0-9]*[\.,]?[0-9]+$/', $str); + } + public function edit_item($item_id) { $data = array(); - $this->form_validation->set_rules('price', 'lang:items_price', 'required|numeric'); - $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|numeric'); - $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|numeric'); + $this->form_validation->set_rules('price', 'lang:items_price', 'required|callback_numeric'); + $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|callback_numeric'); + $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|callback_numeric'); $description = $this->input->post('description'); $serialnumber = $this->input->post('serialnumber'); - $price = $this->input->post('price'); - $quantity = $this->input->post('quantity'); - $discount = $this->input->post('discount'); + $price = parse_decimals($this->input->post('price')); + $quantity = parse_decimals($this->input->post('quantity')); + $discount = parse_decimals($this->input->post('discount')); $item_location = $this->input->post('location'); if($this->form_validation->run() != FALSE) diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index e31f45e37..fd20ebbef 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -4,113 +4,65 @@ * Currency locale */ -function to_currency($number, $escape = FALSE) +function currency_side() { - $CI =& get_instance(); - - $currency_symbol = $CI->config->item('currency_symbol') ? $CI->config->item('currency_symbol') : '$'; - $currency_symbol = $currency_symbol == '$' && $escape ? '\$' : $currency_symbol; - $thousands_separator = $CI->config->item('thousands_separator') ? $CI->config->item('thousands_separator') : ''; - $decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.'; - $decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 0; - - // the conversion function needs a non null var, so if the number is null set it to 0 - if(empty($number)) - { - $number = 0; - } - - if($number >= 0) - { - if(!$CI->config->item('currency_side')) - { - return $currency_symbol.number_format($number, $decimals, $decimal_point, $thousands_separator); - } - else - { - return number_format($number, $decimals, $decimal_point, $thousands_separator).$currency_symbol; - } - } - else - { - if(!$CI->config->item('currency_side')) - { - return '-'.$currency_symbol.number_format(abs($number), $decimals, $decimal_point, $thousands_separator); - } - else - { - return '-'.number_format(abs($number), $decimals, $decimal_point, $thousands_separator).$currency_symbol; - } - } -} - -function to_currency_no_money($number) -{ - // ignore empty strings as they are just for empty input - if(empty($number)) - { - return $number; - } - - $CI =& get_instance(); - - $decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 0; - - return number_format($number, $decimals, '.', ''); + $CI =& get_instance(); + $fmt = new \NumberFormatter($CI->config->item('number_locale'), \NumberFormatter::CURRENCY); + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $CI->config->item('currency_symbol')); + return !preg_match('/^¤/', $fmt->getPattern()); } function totals_decimals() { $CI =& get_instance(); - $decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 0; return $decimals; } +function to_currency($number, $escape = FALSE) +{ + return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY); +} -/* - * Tax locale - */ +function to_currency_no_money($number) +{ + return to_decimals($number, 'currency_decimals'); +} function to_tax_decimals($number) { - // ignore empty strings as they are just for empty input - if( empty($number) ) - { - return $number; - } - - $CI =& get_instance(); - - $decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.'; - $decimals = $CI->config->item('tax_decimals') ? $CI->config->item('tax_decimals') : 0; - - return number_format($number, $decimals, $decimal_point, ''); + return to_decimals($number, 'tax_decimals'); } - -/* - * Quantity decimals - */ - function to_quantity_decimals($number) { - $CI =& get_instance(); - - $decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.'; - $decimals = $CI->config->item('quantity_decimals') ? $CI->config->item('quantity_decimals') : 0; - - return number_format($number, $decimals, $decimal_point, ''); + return to_decimals($number, 'quantity_decimals'); } -function quantity_decimals() +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL) { - $CI =& get_instance(); - - return $CI->config->item('quantity_decimals') ? $CI->config->item('quantity_decimals') : 0; + $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')); + return $fmt->format(floatval($number)); } +function parse_decimals($number) +{ + // ignore empty strings as they are just for empty input + 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')); + return $fmt->parse($number); +} /* * Time locale conversion utility diff --git a/application/language/de-CH/config_lang.php b/application/language/de-CH/config_lang.php index ea5050efc..e0bdde8c5 100644 --- a/application/language/de-CH/config_lang.php +++ b/application/language/de-CH/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Tausendertrennzeichen"; $lang["config_timezone"] = "Zeitzone"; $lang["config_top"] = "Top"; $lang["config_website"] = "Website"; +$lang["config_number_locale"] = "Länderkonfiguration"; +$lang["config_return_policy_required"] = "Rücknahmepolitik erforderlich"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/en/config_lang.php b/application/language/en/config_lang.php index 4ec41aa5d..4a55e7a3a 100644 --- a/application/language/en/config_lang.php +++ b/application/language/en/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "Timezone"; $lang["config_top"] = "Top"; $lang["config_website"] = "Website"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "Return policy is a required field"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/es/config_lang.php b/application/language/es/config_lang.php index bf4a060db..a56acc421 100644 --- a/application/language/es/config_lang.php +++ b/application/language/es/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Separador de miles"; $lang["config_timezone"] = "Zona Horaria"; $lang["config_top"] = "Top"; $lang["config_website"] = "Sitio Web"; +$lang["config_number_locale"] = "Ubicación"; +$lang["config_return_policy_required"] = "Política de Devolución es requerida"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/fr/config_lang.php b/application/language/fr/config_lang.php index cb5d60151..874e0118e 100644 --- a/application/language/fr/config_lang.php +++ b/application/language/fr/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "Fuseau Horaire"; $lang["config_top"] = "Top"; $lang["config_website"] = "Site-web"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "Le Message est un champ requis"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/hr-HR/config_lang.php b/application/language/hr-HR/config_lang.php index 59c43499b..537d59008 100644 --- a/application/language/hr-HR/config_lang.php +++ b/application/language/hr-HR/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Razdjelnik za tisućice"; $lang["config_timezone"] = "Vremenska zona"; $lang["config_top"] = "Top"; $lang["config_website"] = "web strana"; +$lang["config_number_locale"] = "Lokalnoj"; +$lang["config_return_policy_required"] = "Polje za povratne obavijesti je potrebno"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/hu-HU/config_lang.php b/application/language/hu-HU/config_lang.php index 130f4c910..4de18c9a3 100644 --- a/application/language/hu-HU/config_lang.php +++ b/application/language/hu-HU/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Ezres elválasztó"; $lang["config_timezone"] = "Időzóna"; $lang["config_top"] = "Top"; $lang["config_website"] = "Weboldal"; +$lang["config_number_locale"] = "Lokalizációs"; +$lang["config_return_policy_required"] = "Return policy is a required field"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/id/config_lang.php b/application/language/id/config_lang.php index f7b67c07d..ec5346461 100644 --- a/application/language/id/config_lang.php +++ b/application/language/id/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Pemisah Ribuan"; $lang["config_timezone"] = "Zona Waktu"; $lang["config_top"] = "Top"; $lang["config_website"] = "Situs Perusahaan"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "Kebijakan retur wajib diisi"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/nl-BE/config_lang.php b/application/language/nl-BE/config_lang.php index 98f2f6c06..e484cafda 100755 --- a/application/language/nl-BE/config_lang.php +++ b/application/language/nl-BE/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "Tijdzone"; $lang["config_top"] = "Top"; $lang["config_website"] = "Website"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "De retourvoorwaarden moeten ingevuld worden"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/pt-BR/config_lang.php b/application/language/pt-BR/config_lang.php index eb466f4c4..86b7ac948 100644 --- a/application/language/pt-BR/config_lang.php +++ b/application/language/pt-BR/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Separador de milhar"; $lang["config_timezone"] = "Fuso horário"; $lang["config_top"] = "Topo"; $lang["config_website"] = "Site da internet"; +$lang["config_number_locale"] = "Localização"; +$lang["config_return_policy_required"] = "A política de devolução é um campo obrigatório"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/ru/config_lang.php b/application/language/ru/config_lang.php index 42330695e..8273f1674 100644 --- a/application/language/ru/config_lang.php +++ b/application/language/ru/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "Часовой пояс"; $lang["config_top"] = "Top"; $lang["config_website"] = "Веб-сайт"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "Возвратний полис обязательный пробел"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/th/config_lang.php b/application/language/th/config_lang.php index 97cf627ab..2a8e8fac3 100644 --- a/application/language/th/config_lang.php +++ b/application/language/th/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "ตัวคั่นหลักพั $lang["config_timezone"] = "โซนเวลา"; $lang["config_top"] = "Top"; $lang["config_website"] = "เว็บไซต์"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "ต้องกรอกเงื่อนไขการคืนสินค้า"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/tr/config_lang.php b/application/language/tr/config_lang.php index 7ecc777c5..d4f4da00e 100644 --- a/application/language/tr/config_lang.php +++ b/application/language/tr/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "Saat Dilimi"; $lang["config_top"] = "Top"; $lang["config_website"] = "Website"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "İade Politikası zorunlu alandır"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/language/zh/config_lang.php b/application/language/zh/config_lang.php index 8c4304ddb..e8363489f 100755 --- a/application/language/zh/config_lang.php +++ b/application/language/zh/config_lang.php @@ -173,3 +173,8 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "時區"; $lang["config_top"] = "Top"; $lang["config_website"] = "網站"; +$lang["config_number_locale"] = "Localisation"; +$lang["config_return_policy_required"] = "退換貨政策為必填"; +$lang["config_number_locale_required"] = "Number Locale is a required field"; +$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value"; +$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link"; diff --git a/application/views/configs/locale_config.php b/application/views/configs/locale_config.php index a926b636f..80d9e023d 100644 --- a/application/views/configs/locale_config.php +++ b/application/views/configs/locale_config.php @@ -10,18 +10,27 @@ 'currency_symbol', 'id' => 'currency_symbol', - 'class' => 'form-control input-sm', + 'class' => 'form-control input-sm number_locale', 'value'=>$this->config->item('currency_symbol'))); ?> -