CRM-16189, added condition to create account receivable entry for completed contribution
authorPradeep Nayak <pradpnayak@gmail.com>
Thu, 25 Aug 2016 22:07:53 +0000 (03:37 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Sun, 25 Sep 2016 21:22:30 +0000 (02:52 +0530)
----------------------------------------
* CRM-16189:
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM/Contribute/BAO/Contribution.php

index 8cf69fa347d12f61038bfba71c5ddc9439cacf25..8da6c326feb9444af5ca1b9ea84c7b0c274b8881 100644 (file)
@@ -5323,10 +5323,16 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     $statusId = $contributionParams['contribution']->contribution_status_id;
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $contributionStatus = empty($statusId) ? NULL : $contributionStatuses[$statusId];
+    $previousContributionStatus = empty($contributionParams['prevContribution']) ? NULL : $contributionStatuses[$contributionParams['prevContribution']->contribution_status_id];
     // Return if contribution status is not completed.
-    if ($contributionStatus != 'Completed') {
+    if (!($contributionStatus == 'Completed' && (empty($previousContributionStatus)
+      || (!empty($previousContributionStatus) && $previousContributionStatus == 'Pending'
+        && $contributionParams['prevContribution']->is_pay_later == 0
+      )))
+    ) {
       return NULL;
     }
+
     $params = $trxnParams;
     $financialTypeID = CRM_Utils_Array::value('financial_type_id', $contributionParams) ? $contributionParams['financial_type_id'] : $contributionParams['prevContribution']->financial_type_id;
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));