Skip to content

Commit

Permalink
Merge pull request #15641 from eileenmcnaughton/cont_clean
Browse files Browse the repository at this point in the history
[REF] Move calls to CRM_Core_BAO_FinancialTrxn::createDeferredTrxn back to the calling functions.
  • Loading branch information
mattwire authored Nov 1, 2019
2 parents 5dced02 + 901094e commit 1244e13
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3667,10 +3667,18 @@ public static function recordFinancialAccounts(&$params, $financialTrxnValues =
}
}
self::updateFinancialAccounts($params, 'changeFinancialType');
$params['skipLineItem'] = FALSE;
foreach ($params['line_item'] as &$lineItems) {
foreach ($lineItems as &$line) {
$line['financial_type_id'] = $params['financial_type_id'];
}
}
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changeFinancialType');
/* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */
$params['financial_account_id'] = $newFinancialAccount;
$params['total_amount'] = $params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $trxnParams['total_amount'];
self::updateFinancialAccounts($params);
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE);
$params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id'];
$updated = TRUE;
$params['deferred_financial_account_id'] = $newFinancialAccount;
Expand All @@ -3692,6 +3700,7 @@ public static function recordFinancialAccounts(&$params, $financialTrxnValues =
$callUpdateFinancialAccounts = self::updateFinancialAccountsOnContributionStatusChange($params);
if ($callUpdateFinancialAccounts) {
self::updateFinancialAccounts($params, 'changedStatus');
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changedStatus');
}
$updated = TRUE;
}
Expand Down Expand Up @@ -3720,6 +3729,7 @@ public static function recordFinancialAccounts(&$params, $financialTrxnValues =
//Update Financial Records
$params['trxnParams']['from_financial_account_id'] = NULL;
self::updateFinancialAccounts($params, 'changedAmount');
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, 'changedAmount');
$updated = TRUE;
}

Expand Down Expand Up @@ -3824,18 +3834,6 @@ public static function updateFinancialAccounts(&$params, $context = NULL) {
foreach ($params['line_item'] as $fieldId => $fields) {
$params = self::createFinancialItemsForLine($params, $context, $fields, $previousLineItems, $inputParams, $isARefund, $trxnIds, $fieldId);
}

if ($context == 'changeFinancialType') {
// @todo we should stop passing $params by reference - splitting this out would be a step towards that.
$params['skipLineItem'] = FALSE;
foreach ($params['line_item'] as &$lineItems) {
foreach ($lineItems as &$line) {
$line['financial_type_id'] = $params['financial_type_id'];
}
}
}

CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, $context);
}

/**
Expand Down

0 comments on commit 1244e13

Please sign in to comment.