Merge pull request #20168 from larssandergreen/add-recurring-filter-to-contribution...
[civicrm-core.git] / CRM / Contribute / BAO / FinancialProcessor.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class for handling processing of financial records.
14 *
15 * This is a place to extract the financial record processing code to
16 * in order to clean it up.
17 *
18 * @internal core use only.
19 *
20 * @package CRM
21 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 */
23 class CRM_Contribute_BAO_FinancialProcessor {
24
25 /**
26 * Get the financial account for the item associated with the new transaction.
27 *
28 * @param array $params
29 * @param int $default
30 *
31 * @return int
32 */
33 public static function getFinancialAccountForStatusChangeTrxn($params, $default) {
34 if (!empty($params['financial_account_id'])) {
35 return $params['financial_account_id'];
36 }
37
38 $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($params['contribution_status_id'], 'name');
39 $preferredAccountsRelationships = [
40 'Refunded' => 'Credit/Contra Revenue Account is',
41 'Chargeback' => 'Chargeback Account is',
42 ];
43
44 if (array_key_exists($contributionStatus, $preferredAccountsRelationships)) {
45 $financialTypeID = !empty($params['financial_type_id']) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id;
46 return CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(
47 $financialTypeID,
48 $preferredAccountsRelationships[$contributionStatus]
49 );
50 }
51 return $default;
52 }
53
54 }