From 230be83b47b0a1c4ba76ceef771374585c230d5d Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 16 Sep 2016 23:40:00 +1000 Subject: [PATCH] CRM-19149 Followup code cleanup as per pradpnayak --- CRM/Contribute/BAO/Contribution.php | 27 ++++----------------------- CRM/Core/BAO/FinancialTrxn.php | 1 - 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 9b700753f8..92498927df 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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); } } } diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index c3f63490c8..fb03325fa8 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -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)) { -- 2.25.1