Return 0 if total amount is 0 instead of NULL.
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Fri, 20 Dec 2019 19:20:28 +0000 (19:20 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Thu, 23 Jan 2020 21:28:31 +0000 (21:28 +0000)
CRM/Contribute/BAO/Contribution.php
CRM/Core/BAO/FinancialTrxn.php
CRM/Utils/Money.php

index 9d7873f2457f15ce55e4f3c8629db21fcb5401c1..21198fd7520574edd821b6f456b6077485db218f 100644 (file)
@@ -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')
     );
   }
index f81fdf802d19eda7a58a2c25a57db87004e709aa..6abb1bdb83d80abf42e8a82c02e15e332cb31bea 100644 (file)
@@ -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'],
     ]);
index a523fed925b924dd1d31419020e0b63b5d7c7261..0e8cd6d76cc9497462ee6eaf066d9ae67f8176a7 100644 (file)
@@ -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
    */