Skip to content

Commit

Permalink
WHF-174: Recalculates fee and net amount when a payment is recorded
Browse files Browse the repository at this point in the history
Included CiviCRM 5.38.0

PR: civicrm#20008
  • Loading branch information
olayiwola-compucorp committed Aug 9, 2021
1 parent 749b581 commit 93223ca
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ public static function updateRelatedContribution($params, $contributionID) {
$contributionDAO->id = $contributionID;
$contributionDAO->find(TRUE);

if (isset($params['fee_amount'])) {
// Update contribution.fee_amount to be be the total of all fees
// since the payment is already saved the total here will be right.
$payments = civicrm_api3('Payment', 'get', [
'contribution_id' => $contributionID,
'return' => 'fee_amount',
])['values'];
$totalFees = 0;
foreach ($payments as $payment) {
$totalFees += $payment['fee_amount'] ?? 0;
}
$contributionDAO->fee_amount = $totalFees;
$contributionDAO->net_amount = $contributionDAO->total_amount - $contributionDAO->fee_amount;
}

foreach (['trxn_id', 'check_number'] as $fieldName) {
if (!empty($params[$fieldName])) {
$values = [];
Expand Down

0 comments on commit 93223ca

Please sign in to comment.