-- CRM-14853, change payment instrument id when contribution status is changed from...
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Tue, 2 Sep 2014 20:35:03 +0000 (02:05 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Tue, 2 Sep 2014 20:35:03 +0000 (02:05 +0530)
----------------------------------------
* CRM-14853: Bookkeeping report represents payment type incorrectly
  https://issues.civicrm.org/jira/browse/CRM-14853

CRM/Contribute/BAO/Contribution.php
CRM/Upgrade/Incremental/sql/4.5.beta9.mysql.tpl

index eee3a4d96aee6f9bad40706301de758e2b381dc0..90e05757fdcae570163af2fb980b36ed1bd21db0 100644 (file)
@@ -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) {
index e17299ebe6c86a8f7657b7330f68dd9d64c358eb..dc34c88a3b23cfa4ee4223b6a8392d55cb020a7d 100644 (file)
@@ -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