From 4924bfe960e6f65edda8ad514e02e62ab497eb2f Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 15 Feb 2020 11:03:08 +1300 Subject: [PATCH] Fix Bug where Payment Balance is sometimes miscalculated I observed that when this function is called without the mystical the paymentBalance is miscalculated The payment balance is calculated as the Contribution Total less the amount paid (for less queries the total is passed into getContributionBalance & used if passed in). We were passing in the Balance as the total causing the balance to be calculated as the Balance less any amount paid. From what I can tell this function has been honed & cleaned up but because the parameter never made much sense the impact of different variants was not really tested. This removes & fixes --- CRM/Contribute/BAO/Contribution.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6a39286c51..845f9c8631 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4087,13 +4087,15 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * Get list of payments displayed by Contribute_Page_PaymentInfo. * * @param int $id - * @param $component + * @param string $component * @param bool $getTrxnInfo - * @param bool $usingLineTotal * * @return mixed + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ - public static function getPaymentInfo($id, $component = 'contribution', $getTrxnInfo = FALSE, $usingLineTotal = FALSE) { + public static function getPaymentInfo($id, $component = 'contribution', $getTrxnInfo = FALSE) { // @todo deprecate passing in component - always call with contribution. if ($component == 'event') { $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id'); @@ -4115,19 +4117,15 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $contributionId = $id; } - $total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); - $baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL; + // The balance used to be calculated this way - we really want to remove this 'oldCalculation' + // but need to unpick the whole trxn_id it's returning first. + $oldCalculation = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); + $baseTrxnId = !empty($oldCalculation['trxn_id']) ? $oldCalculation['trxn_id'] : NULL; if (!$baseTrxnId) { $baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId); $baseTrxnId = $baseTrxnId['financialTrxnId']; } - if (empty($total['total_amount']) || $usingLineTotal) { - $total = CRM_Price_BAO_LineItem::getLineTotal($contributionId); - } - else { - $baseTrxnId = $total['trxn_id']; - $total = $total['total_amount']; - } + $total = CRM_Price_BAO_LineItem::getLineTotal($contributionId); $paymentBalance = CRM_Contribute_BAO_Contribution::getContributionBalance($contributionId, $total); -- 2.25.1