diff --git a/application/language/en-GB/config_lang.php b/application/language/en-GB/config_lang.php index 9b55225c2..95a049254 100644 --- a/application/language/en-GB/config_lang.php +++ b/application/language/en-GB/config_lang.php @@ -32,7 +32,7 @@ $lang["config_barcode_type"] = "Barcode Type"; $lang["config_barcode_width"] = "Width (px)"; $lang["config_bottom"] = "Bottom"; $lang["config_cash_decimals"] = "Cash Decimals"; -$lang["config_cash_decimals_tooltip"] = "If cash decimals and currency decimals are the same then no cash rounding will take place."; +$lang["config_cash_decimals_tooltip"] = "If Cash Decimals and Currency Decimals are the same then no cash triggered rounding will take place, unless Cash Rounding is set to Half Five."; $lang["config_cash_rounding"] = "Cash Rounding"; $lang["config_category_dropdown"] = "Show Category as a dropdown"; $lang["config_center"] = "Centre"; diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index e5a72caef..67f9cddf7 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -32,7 +32,7 @@ $lang["config_barcode_type"] = "Barcode Type"; $lang["config_barcode_width"] = "Width (px)"; $lang["config_bottom"] = "Bottom"; $lang["config_cash_decimals"] = "Cash Decimals"; -$lang["config_cash_decimals_tooltip"] = "If Cash Decimals and Currency Decimals are the same then no cash rounding will take place."; +$lang["config_cash_decimals_tooltip"] = "If Cash Decimals and Currency Decimals are the same then no cash triggered rounding will take place, unless Cash Rounding is set to Half Five."; $lang["config_cash_rounding"] = "Cash Rounding"; $lang["config_category_dropdown"] = "Show Category as a dropdown"; $lang["config_center"] = "Center"; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 542a2dd37..5530113be 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -1070,7 +1070,9 @@ class Sale_lib } $this->CI->session->set_userdata('cash_mode', $cash_mode); - if(cash_decimals() < totals_decimals()) + $cash_rounding_code = $this->CI->config->item('cash_rounding_code'); + + if(cash_decimals() < totals_decimals() || $cash_rounding_code == Rounding_mode::HALF_FIVE) { $cash_rounding = 1; } @@ -1271,7 +1273,6 @@ class Sale_lib { $cash_decimals = cash_decimals(); $cash_rounding_code = $this->CI->config->item('cash_rounding_code'); - $rounded_total = $total; return Rounding_mode::round_number($cash_rounding_code, $total, $cash_decimals); } diff --git a/application/models/enums/Rounding_mode.php b/application/models/enums/Rounding_mode.php index 51ca6e13e..65fe7414c 100644 --- a/application/models/enums/Rounding_mode.php +++ b/application/models/enums/Rounding_mode.php @@ -66,7 +66,7 @@ class Rounding_mode } elseif($rounding_mode == Rounding_mode::HALF_FIVE) { - $rounded_total = round($amount / 5) * 5; + $rounded_total = round($amount / 5, $decimals, Rounding_mode::HALF_EVEN) * 5; } else { diff --git a/application/tests/models/Rounding_mode_test.php b/application/tests/models/Rounding_mode_test.php new file mode 100644 index 000000000..c64cdd5c3 --- /dev/null +++ b/application/tests/models/Rounding_mode_test.php @@ -0,0 +1,31 @@ +resetInstance(); + $this->CI->load->model('enums/Rounding_mode'); + } + + public function test_rounding() + { + // $this->assertEquals(5.20, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.20, 2)); + $this->assertEquals(5.20, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.20, 2)); + $this->assertEquals(5.20, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.21, 2)); + $this->assertEquals(5.20, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.22, 2)); + $this->assertEquals(5.25, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.23, 2)); + $this->assertEquals(5.25, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.24, 2)); + $this->assertEquals(5.25, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.25, 2)); + $this->assertEquals(5.25, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.26, 2)); + $this->assertEquals(5.25, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.27, 2)); + $this->assertEquals(5.30, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.28, 2)); + $this->assertEquals(5.30, Rounding_mode::round_number(Rounding_mode::HALF_FIVE, 5.29, 2)); + } +} +