From: unknown Date: Fri, 30 Oct 2015 19:44:06 +0000 (-0600) Subject: CRM-17469 - update pledge payments with actual amount paid X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a5d8acb900a154d88442dca48590ac9307e305ed;p=civicrm-core.git CRM-17469 - update pledge payments with actual amount paid --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index e0a9f95279..9cb68a2075 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -896,6 +896,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if ($pledgeID) { //when user doing pledge payments. //update the schedule when payment(s) are made + $amount = $params['amount']; + $pledgePaymentParams = array(); foreach ($params['pledge_amount'] as $paymentId => $dontCare) { $scheduledAmount = CRM_Core_DAO::getFieldValue( 'CRM_Pledge_DAO_PledgePayment', @@ -904,14 +906,22 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'id' ); - $pledgePaymentParams = array( - 'id' => $paymentId, - 'contribution_id' => $contribution->id, - 'status_id' => $contribution->contribution_status_id, - 'actual_amount' => $scheduledAmount, - ); - - CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams); + $pledgePayment = ($amount >= $scheduledAmount) ? $scheduledAmount : $amount; + if ($pledgePayment > 0) { + $pledgePaymentParams[] = array( + 'id' => $paymentId, + 'contribution_id' => $contribution->id, + 'status_id' => $contribution->contribution_status_id, + 'actual_amount' => $pledgePayment, + ); + $amount -= $pledgePayment; + } + } + if ($amount > 0 && count($pledgePaymentParams)) { + $pledgePaymentParams[count($pledgePaymentParams) - 1]['actual_amount'] += $amount; + } + foreach ($pledgePaymentParams as $p) { + CRM_Pledge_BAO_PledgePayment::add($p); } //update pledge status according to the new payment statuses