Fixes #2922 feature request by adding the cash rounding type of half-five as a trigger for cash rounding and including the decimals as a factor in the round function.

This commit is contained in:
SteveIreland
2020-08-27 22:17:13 -04:00
committed by jekkos
parent bb309c2579
commit bf88f8fdae
5 changed files with 37 additions and 5 deletions

View File

@@ -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";

View File

@@ -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";

View File

@@ -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);
}

View File

@@ -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
{

View File

@@ -0,0 +1,31 @@
<?php
/**
* @backupGlobals disabled
*/
class Rounding_mode_test extends UnitTestCase
{
public function setUp()
{
$this->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));
}
}