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')
);
}
}
/**
+ * 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) {
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'],
]);
/**
* 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
*/