Skip to content

Commit

Permalink
Return 0 if total amount is 0 instead of NULL.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Dec 20, 2019
1 parent a43ea4b commit 5ce8232
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CRM/Core/BAO/FinancialTrxn.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,14 @@ public static function getPartialPaymentWithType($entityId, $entityName = 'parti
}

/**
* 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) {
Expand All @@ -495,10 +497,14 @@ public static function getTotalPayments($contributionID, $includeRefund = FALSE)
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, [
$totalAmount = CRM_Core_DAO::singleValueQuery($sql, [
1 => [$contributionID, 'Integer'],
2 => [implode(',', $statusIDs), 'CommaSeparatedIntegers'],
]);
if (!$totalAmount) {
$totalAmount = 0;
}
return $totalAmount;
}

/**
Expand Down

0 comments on commit 5ce8232

Please sign in to comment.