CRM-19149 Followup code cleanup as per pradpnayak
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 16 Sep 2016 13:40:00 +0000 (23:40 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 16 Sep 2016 13:40:00 +0000 (23:40 +1000)
CRM/Contribute/BAO/Contribution.php
CRM/Core/BAO/FinancialTrxn.php

index 9b700753f8862ce107d755525e2a40e493b82b14..92498927df17c11c00e8df6ce261c5902842ec80 100644 (file)
@@ -3469,22 +3469,10 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
         $deferredFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId);
       }
       $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC', FALSE, NULL, $deferredFinancialAccount);
-      if ($params['trxnParams']['total_amount'] < 0) {
-        if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
-          if ($params['total_amount'] > 0) {
-            $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
-            $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
-          }
-          else {
-            $params['trxnParams']['to_financial_account_id'] = $params['to_financial_account_id'];
-            $params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
-          }
-        }
-      }
-      else {
-        if ($params['total_amount'] < 0) {
-          $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
+      if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
+        if ($params['total_amount'] != $params['trxnParams']['total_amount']) {
           $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
+          $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
         }
         else {
           $params['trxnParams']['to_financial_account_id'] = $params['to_financial_account_id'];
@@ -3608,21 +3596,14 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
       foreach ($params['line_item'] as $lineitems) {
         foreach ($lineitems as $fieldValueId => $fieldValues) {
           $prevFinancialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($fieldValues['id']);
-          if (!CRM_Utils_Rule::currencyCode($trxn->currency)) {
-            $trxn->currency = CRM_Core_Config::singleton()->defaultCurrency;
-          }
-
           // save to entity_financial_trxn table
           $entityFinancialTrxnParams = array(
             'entity_table' => "civicrm_financial_item",
             'entity_id' => $prevFinancialItem->id,
             'financial_trxn_id' => $trxn->id,
             'amount' => $trxn->total_amount,
-            'currency' => $trxn->currency,
           );
-          $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
-          $entityTrxn->copyValues($entityFinancialTrxnParams);
-          $entityTrxn->save();
+          civicrm_api3('entityFinancialTrxn', 'create', $entityFinancialTrxnParams);
         }
       }
     }
index c3f63490c881f17bfff2ed8c8982a4d6720d9dee..fb03325fa89e2623fb76f82231543ce15db0f32d 100644 (file)
@@ -71,7 +71,6 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
         'entity_table' => "civicrm_contribution",
         'financial_trxn_id' => $trxn->id,
         'amount' => $params['total_amount'],
-        'currency' => $trxn->currency,
       );
 
     if (!empty($trxnEntityTable)) {