Correct CRM-17183 financial entry for cancelling a pending payment
authorGuanhuan Chen <oooomic@gmail.com>
Thu, 10 Sep 2015 14:31:45 +0000 (15:31 +0100)
committerGuanhuan Chen <oooomic@gmail.com>
Thu, 10 Sep 2015 14:31:45 +0000 (15:31 +0100)
CRM/Contribute/BAO/Contribution.php

index 0305ee83c250dd0c9b145a79cddbc721d49dfbe2..964f3e971bfd175d8e00b046e5f60bc9b6cbae68 100644 (file)
@@ -3001,13 +3001,16 @@ WHERE  contribution_id = %1 ";
           && $params['prevContribution']->is_pay_later) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)
       ) {
         $financialTypeID = CRM_Utils_Array::value('financial_type_id', $params) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id;
+        $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
+        $arAccountId = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeID, $relationTypeId);
+
         if ($params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus)) {
-          $params['trxnParams']['to_financial_account_id'] = NULL;
+          $params['trxnParams']['to_financial_account_id'] = $arAccountId;
           $params['trxnParams']['total_amount'] = -$params['total_amount'];
         }
-        $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
-        $params['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType(
-          $financialTypeID, $relationTypeId);
+        else {
+          $params['trxnParams']['from_financial_account_id'] = $arAccountId;
+        }
       }
       $itemAmount = $params['trxnParams']['total_amount'];
     }