From 1aca1f1e5bdbca8e01214219aa28e40a8536cfcb Mon Sep 17 00:00:00 2001 From: Brian Shaughnessy Date: Tue, 21 Feb 2017 16:06:25 -0500 Subject: [PATCH] CRM-20145 move to utility function --- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Contribute/BAO/Contribution/Utils.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index da03b77f87..70b850c46a 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5419,7 +5419,7 @@ LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co $paid = $entityParams['line_item_amount'] * ($entityParams['trxn_total_amount'] / $entityParams['contribution_total_amount']); // Record Entity Financial Trxn // CRM-20145 - $eftParams['amount'] = number_format((float)round($paid, 2), 2, '.', ''); + $eftParams['amount'] = CRM_Contribute_BAO_Contribution_Utils::formatAmount($paid); civicrm_api3('EntityFinancialTrxn', 'create', $eftParams); } diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 5b650a10a0..05074209c8 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -481,4 +481,19 @@ LIMIT 1 return $taxAmount; } + /* + * Format monetary amount: round and return to desired decimal place + * CRM-20145 + * + * @param float $amount + * Monetary amount + * @param integer $decimals + * How many decimal places to round to and return + * + * @return float + * Amount rounded and returned with the desired decimal places + */ + public static function formatAmount($amount, $decimals = 2) { + return number_format((float) round($amount, (int) $decimals), (int) $decimals, '.', ''); + } } -- 2.25.1