CRM-13224 fix
authormonishdeb <monish.deb@webaccess.co.in>
Fri, 23 Aug 2013 13:54:44 +0000 (19:24 +0530)
committermonishdeb <monish.deb@webaccess.co.in>
Fri, 23 Aug 2013 13:54:44 +0000 (19:24 +0530)
----------------------------------------
* CRM-13224: Contribution entries are not being created while recording 'adjusted payment' for installments of a pledge
  http://issues.civicrm.org/jira/browse/CRM-13224

CRM/Pledge/BAO/PledgePayment.php

index cdd5a1168fd9cce9392abd5301367ca49832afc8..f1690ff2e5e7b312d6559ea66ee14031f5118036 100644 (file)
@@ -776,8 +776,18 @@ WHERE civicrm_pledge_payment.contribution_id = {$paymentContributionId}
           $oldScheduledAmount = $oldestPayment['amount'];
           $newScheduledAmount = $oldScheduledAmount + ($pledgeScheduledAmount - $actualAmount);
           //store new amount in oldest pending payment record.
-          CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'scheduled_amount', $newScheduledAmount);
-          CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'contribution_id', $paymentContributionId);
+          CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment',
+            $oldestPayment['id'],
+            'scheduled_amount',
+            $newScheduledAmount
+          );
+          if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'contribution_id', 'id')) {
+            CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment',
+              $oldestPayment['id'],
+              'contribution_id',
+              $paymentContributionId
+            );
+          }
         }
         elseif (($actualAmount > $pledgeScheduledAmount) && (($actualAmount - $pledgeScheduledAmount) >= $oldestPayment['amount'])) {
           // here the actual amount is greater than expected and also greater than the next installment amount, so update the next installment as complete and again add it to next subsequent pending payment