From 182228d5d016685d41dd5438c733e26694e9816c Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 3 Sep 2014 02:05:03 +0530 Subject: [PATCH] -- CRM-14853, change payment instrument id when contribution status is changed from In-progress/Pending to Completed ---------------------------------------- * CRM-14853: Bookkeeping report represents payment type incorrectly https://issues.civicrm.org/jira/browse/CRM-14853 --- CRM/Contribute/BAO/Contribution.php | 10 ++++++++-- CRM/Upgrade/Incremental/sql/4.5.beta9.mysql.tpl | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index eee3a4d96a..90e05757fd 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2718,9 +2718,15 @@ WHERE contribution_id = %1 "; $params['trxnParams']['net_amount'] = $params['prevContribution']->net_amount; $params['trxnParams']['trxn_id'] = $params['prevContribution']->trxn_id; $params['trxnParams']['status_id'] = $params['prevContribution']->contribution_status_id; - $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id; - $params['trxnParams']['check_number'] = $params['prevContribution']->check_number; + + if (!(($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses) + || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatuses)) + && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses))) { + $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id; + $params['trxnParams']['check_number'] = $params['prevContribution']->check_number; + } + //if financial type is changed if (!empty($params['financial_type_id']) && $params['contribution']->financial_type_id != $params['prevContribution']->financial_type_id) { diff --git a/CRM/Upgrade/Incremental/sql/4.5.beta9.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.5.beta9.mysql.tpl index e17299ebe6..dc34c88a3b 100644 --- a/CRM/Upgrade/Incremental/sql/4.5.beta9.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.5.beta9.mysql.tpl @@ -14,3 +14,14 @@ INSERT INTO civicrm_navigation ( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight ) VALUES ( {$domainID}, 'civicrm/admin/options/grant_status?reset=1', '{ts escape="sql" skip="true"}Grant Status{/ts}', 'Grant Status', 'access CiviGrant,administer CiviCRM', 'AND', @parent_id, '1', NULL, 2 ); + +-- CRM-14853 +UPDATE civicrm_financial_trxn cft +INNER JOIN ( SELECT max(cft.id) trxn_id, ceft.entity_id contribution_id +FROM civicrm_financial_trxn cft +LEFT JOIN civicrm_entity_financial_trxn ceft ON ceft.financial_trxn_id = cft.id +WHERE ceft.entity_table = 'civicrm_contribution' +GROUP BY ceft.entity_id ) as temp ON temp.trxn_id = cft.id +INNER JOIN civicrm_contribution cc ON cc.id = temp.contribution_id +AND cc.payment_instrument_id <> cft.payment_instrument_id +SET cft.payment_instrument_id = cc.payment_instrument_id; \ No newline at end of file -- 2.25.1