From: Joe Hunt Date: Wed, 4 Jan 2012 13:25:12 +0000 (+0100) Subject: Improved float compare in certain files (AR/AP ledger) X-Git-Tag: 2.3-final~511 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;ds=inline;h=ab5bb181d749dae6f681ee44cba86c9ef2d26c06;p=fa-stable.git Improved float compare in certain files (AR/AP ledger) --- diff --git a/includes/current_user.inc b/includes/current_user.inc index 7c99f233..51c03ee6 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -210,6 +210,20 @@ function number_format2($number, $decimals=0) return $decimals==='max' ? rtrim($num, '0') : $num; } + +/* price/float comparision helper to be used in any suspicious place for zero values? +usage: +if (!floatcmp($value1, $value2)) + compare value is 0 +*/ + +define('FLOAT_COMP_DELTA', 0.0000001); + +function floatcmp($a, $b) +{ + return $a - $b > FLOAT_COMP_DELTA ? 1 : $b - $a > FLOAT_COMP_DELTA ? -1 : 0; +} + // // Current ui mode. // diff --git a/reporting/rep101.php b/reporting/rep101.php index 3f1ece78..0ff78c8b 100644 --- a/reporting/rep101.php +++ b/reporting/rep101.php @@ -189,7 +189,7 @@ function print_customer_balances() $rep->Line($rep->row + 4); while ($trans = db_fetch($res)) { - if ($no_zeros && $trans['TotalAmount'] == 0 && $trans['Allocated'] == 0) continue; + if ($no_zeros && floatcmp($trans['TotalAmount'], $trans['Allocated']) == 0) continue; $rep->NewLine(1, 2); $rep->TextCol(0, 1, $systypes_array[$trans['type']]); $rep->TextCol(1, 2, $trans['reference']); diff --git a/reporting/rep102.php b/reporting/rep102.php index 18fab24d..07847070 100644 --- a/reporting/rep102.php +++ b/reporting/rep102.php @@ -168,7 +168,7 @@ function print_aged_customer_analysis() $custrec["Overdue1"]-$custrec["Overdue2"], $custrec["Overdue2"], $custrec["Balance"]); - if ($no_zeros && array_sum($str) == 0) continue; + if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue; $rep->fontSize += 2; $rep->TextCol(0, 2, $myrow['name']); diff --git a/reporting/rep201.php b/reporting/rep201.php index 79cd401f..4004c8a2 100644 --- a/reporting/rep201.php +++ b/reporting/rep201.php @@ -175,7 +175,7 @@ function print_supplier_balances() $rep->Line($rep->row + 4); while ($trans=db_fetch($res)) { - if ($no_zeros && $trans['TotalAmount'] == 0 && $trans['Allocated'] == 0) continue; + if ($no_zeros && floatcmp(abs($trans['TotalAmount']), $trans['Allocated']) == 0) continue; $rep->NewLine(1, 2); $rep->TextCol(0, 1, $systypes_array[$trans['type']]); $rep->TextCol(1, 2, $trans['reference']); diff --git a/reporting/rep202.php b/reporting/rep202.php index f18abaec..32f7bed3 100644 --- a/reporting/rep202.php +++ b/reporting/rep202.php @@ -182,7 +182,7 @@ function print_aged_supplier_analysis() $supprec["Overdue2"], $supprec["Balance"]); - if ($no_zeros && array_sum($str) == 0) continue; + if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue; $rep->fontSize += 2; $rep->TextCol(0, 2, $myrow['name']); diff --git a/sales/inquiry/customer_inquiry.php b/sales/inquiry/customer_inquiry.php index 4508b2f2..3ebc84b5 100644 --- a/sales/inquiry/customer_inquiry.php +++ b/sales/inquiry/customer_inquiry.php @@ -212,7 +212,7 @@ function prt_link($row) function check_overdue($row) { return $row['OverDue'] == 1 - && (abs($row["TotalAmount"]) - $row["Allocated"] != 0); + && floatcmp($row["TotalAmount"], $row["Allocated"]) != 0; } //------------------------------------------------------------------------------------------------ $sql = get_sql_for_customer_inquiry();