From ab295276194b67a50be0dbbaf9b2bd0afbf7d4cb Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 2 Jul 2017 21:07:55 +0100 Subject: [PATCH] Fix (yet again) registry "complete" issue with rounding --- application/libraries/Sale_lib.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 74fc959cb..0e13b3be7 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -410,13 +410,16 @@ class Sale_lib $current_due = $amount_due; } + // 0 decimal -> 1 / 2 = 0.5, 1 decimals -> 0.1 / 2 = 0.05, 2 decimals -> 0.01 / 2 = 0.005 + $threshold = bcpow(10, -$this->CI->config->item('currency_decimals')) / 2; + if($this->get_mode() == 'return') { - $totals['payments_cover_total'] = $current_due >= 0; + $totals['payments_cover_total'] = $current_due > -$threshold; } else { - $totals['payments_cover_total'] = $current_due <= 0; + $totals['payments_cover_total'] = $current_due < $threshold; } return $totals; @@ -436,19 +439,6 @@ class Sale_lib return $rounded_due == 0 ? 0 : $amount_due; } - public function is_payment_covering_total() - { - - if($this->get_mode() == 'return') - { - return $this->get_amount_due() >= 0; - } - else - { - return $this->get_amount_due() <= 0; - } - } - public function get_customer() { if(!$this->CI->session->userdata('sales_customer'))