From ec04cb127aabe14fe794a37c3ac9b992ce073b97 Mon Sep 17 00:00:00 2001 From: Guanhuan Chen Date: Thu, 10 Sep 2015 15:31:45 +0100 Subject: [PATCH] Correct CRM-17183 financial entry for cancelling a pending payment --- CRM/Contribute/BAO/Contribution.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0305ee83c2..964f3e971b 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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']; } -- 2.25.1