3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Page for displaying list of financial types
21 class CRM_Financial_Page_FinancialType
extends CRM_Core_Page_Basic
{
23 public $useLivePageJS = TRUE;
25 * The action links that we need to display for the browse screen.
29 public static $_links = NULL;
37 public function getBAOName() {
38 return 'CRM_Financial_BAO_FinancialType';
45 * (reference) of action links
47 public function &links() {
48 if (!(self
::$_links)) {
50 CRM_Core_Action
::BROWSE
=> [
51 'name' => ts('Accounts'),
52 'url' => 'civicrm/admin/financial/financialType/accounts',
53 'qs' => 'reset=1&action=browse&aid=%%id%%',
54 'title' => ts('Accounts'),
56 CRM_Core_Action
::UPDATE
=> [
58 'url' => 'civicrm/admin/financial/financialType',
59 'qs' => 'action=update&id=%%id%%&reset=1',
60 'title' => ts('Edit Financial Type'),
62 CRM_Core_Action
::DISABLE
=> [
63 'name' => ts('Disable'),
64 'ref' => 'crm-enable-disable',
65 'title' => ts('Disable Financial Type'),
67 CRM_Core_Action
::ENABLE
=> [
68 'name' => ts('Enable'),
69 'ref' => 'crm-enable-disable',
70 'title' => ts('Enable Financial Type'),
72 CRM_Core_Action
::DELETE
=> [
73 'name' => ts('Delete'),
74 'url' => 'civicrm/admin/financial/financialType',
75 'qs' => 'action=delete&id=%%id%%',
76 'title' => ts('Delete Financial Type'),
84 * Browse all financial types.
86 public function browse() {
87 // get all financial types sorted by weight
89 $dao = new CRM_Financial_DAO_FinancialType();
90 $dao->orderBy('name');
93 while ($dao->fetch()) {
94 $financialType[$dao->id
] = [];
95 CRM_Core_DAO
::storeValues($dao, $financialType[$dao->id
]);
96 $defaults = $financialAccountId = [];
97 $financialAccounts = CRM_Contribute_PseudoConstant
::financialAccount();
98 $financialAccountIds = [];
100 $params['entity_id'] = $dao->id
;
101 $params['entity_table'] = 'civicrm_financial_type';
103 CRM_Financial_BAO_FinancialTypeAccount
::retrieve($params, $null, $financialAccountIds);
105 foreach ($financialAccountIds as $key => $values) {
106 if (!empty($financialAccounts[$values['financial_account_id']])) {
107 $financialAccountId[$values['financial_account_id']] = $financialAccounts[$values['financial_account_id']] ??
NULL;
111 if (!empty($financialAccountId)) {
112 $financialType[$dao->id
]['financial_account'] = implode(',', $financialAccountId);
115 // form all action links
116 $action = array_sum(array_keys($this->links()));
118 // update enable/disable links depending on if it is is_reserved or is_active
119 if ($dao->is_reserved
) {
120 $action -= CRM_Core_Action
::ENABLE
;
121 $action -= CRM_Core_Action
::DISABLE
;
122 $action -= CRM_Core_Action
::DELETE
;
125 if ($dao->is_active
) {
126 $action -= CRM_Core_Action
::ENABLE
;
129 $action -= CRM_Core_Action
::DISABLE
;
133 $financialType[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
137 'financialType.manage.action',
142 $this->assign('rows', $financialType);
146 * Get name of edit form.
149 * Classname of edit form.
151 public function editForm() {
152 return 'CRM_Financial_Form_FinancialType';
156 * Get edit form name.
161 public function editName() {
162 return 'Financial Types';
173 public function userContext($mode = NULL) {
174 return 'civicrm/admin/financial/financialType';