Skip to content

Commit

Permalink
Fix Bug where Payment Balance is sometimes miscalculated
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Mar 16, 2020
1 parent ffdf4f9 commit 4924bfe
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4087,13 +4087,15 @@ public static function addActivityForPayment($targetCid, $activityType, $title,
* 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');
Expand All @@ -4115,19 +4117,15 @@ public static function getPaymentInfo($id, $component = 'contribution', $getTrxn
$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);

Expand Down

0 comments on commit 4924bfe

Please sign in to comment.