From 538e521c7e8482d3945c0ff792d36e7d9aebbf88 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 16 Jul 2021 18:15:14 +1200 Subject: [PATCH] Start the process of moving financial processing to own class This starts the process of moving the functions used to process financial records to their own class Once we have moved them over (& unwravelled all the 'self' references) it will be easier to clean them up and use methods rather than param passing --- CRM/Contribute/BAO/Contribution.php | 33 +------------- CRM/Contribute/BAO/FinancialProcessor.php | 54 +++++++++++++++++++++++ 2 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 CRM/Contribute/BAO/FinancialProcessor.php diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 7dab1582be..e814d2c14d 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1141,7 +1141,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $receiveDate = CRM_Utils_Date::isoToMysql($params['contribution']->receive_date); } - $financialAccount = self::getFinancialAccountForStatusChangeTrxn($params, CRM_Utils_Array::value('financial_account_id', $prevFinancialItem)); + $financialAccount = CRM_Contribute_BAO_FinancialProcessor::getFinancialAccountForStatusChangeTrxn($params, CRM_Utils_Array::value('financial_account_id', $prevFinancialItem)); $currency = $params['prevContribution']->currency; if ($params['contribution']->currency) { @@ -4385,37 +4385,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac } } - /** - * Get the financial account for the item associated with the new transaction. - * - * @param array $params - * @param int $default - * - * @return int - */ - public static function getFinancialAccountForStatusChangeTrxn($params, $default) { - - if (!empty($params['financial_account_id'])) { - return $params['financial_account_id']; - } - - $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($params['contribution_status_id'], 'name'); - $preferredAccountsRelationships = [ - 'Refunded' => 'Credit/Contra Revenue Account is', - 'Chargeback' => 'Chargeback Account is', - ]; - - if (array_key_exists($contributionStatus, $preferredAccountsRelationships)) { - $financialTypeID = !empty($params['financial_type_id']) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id; - return CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship( - $financialTypeID, - $preferredAccountsRelationships[$contributionStatus] - ); - } - - return $default; - } - /** * ContributionPage values were being imposed onto values. * diff --git a/CRM/Contribute/BAO/FinancialProcessor.php b/CRM/Contribute/BAO/FinancialProcessor.php new file mode 100644 index 0000000000..06a9e82438 --- /dev/null +++ b/CRM/Contribute/BAO/FinancialProcessor.php @@ -0,0 +1,54 @@ + 'Credit/Contra Revenue Account is', + 'Chargeback' => 'Chargeback Account is', + ]; + + if (array_key_exists($contributionStatus, $preferredAccountsRelationships)) { + $financialTypeID = !empty($params['financial_type_id']) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id; + return CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship( + $financialTypeID, + $preferredAccountsRelationships[$contributionStatus] + ); + } + return $default; + } + +} -- 2.25.1