From 5ab2fd4fe528c8928e93227bc16a8b1184f86718 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Fri, 20 Dec 2019 19:20:28 +0000 Subject: [PATCH] Return 0 if total amount is 0 instead of NULL. --- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Core/BAO/FinancialTrxn.php | 8 +++++--- CRM/Utils/Money.php | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 9d7873f245..21198fd752 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4165,7 +4165,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac return (float) CRM_Utils_Money::subtractCurrencies( $contributionTotal, - CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId, TRUE) ?: 0, + CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId, TRUE), CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'currency') ); } diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index f81fdf802d..6abb1bdb83 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -479,12 +479,14 @@ WHERE ceft.entity_id = %1"; } /** + * Get the total sum of all payments (and optionally refunds) for a contribution record + * * @param int $contributionID * @param bool $includeRefund * - * @return string + * @return float */ - public static function getTotalPayments($contributionID, $includeRefund = FALSE) { + public static function getTotalPayments($contributionID, $includeRefund = FALSE): float { $statusIDs = [CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')]; if ($includeRefund) { @@ -495,7 +497,7 @@ WHERE ceft.entity_id = %1"; INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution') WHERE eft.entity_id = %1 AND ft.is_payment = 1 AND ft.status_id IN (%2) "; - return CRM_Core_DAO::singleValueQuery($sql, [ + return (float) CRM_Core_DAO::singleValueQuery($sql, [ 1 => [$contributionID, 'Integer'], 2 => [implode(',', $statusIDs), 'CommaSeparatedIntegers'], ]); diff --git a/CRM/Utils/Money.php b/CRM/Utils/Money.php index a523fed925..0e8cd6d76c 100644 --- a/CRM/Utils/Money.php +++ b/CRM/Utils/Money.php @@ -122,6 +122,10 @@ class CRM_Utils_Money { /** * Subtract currencies using integers instead of floats, to preserve precision * + * @param string|float $leftOp + * @param string|float $rightOp + * @param string $currency + * * @return float * Result of subtracting $rightOp from $leftOp to the precision of $currency */ -- 2.25.1