Merge pull request #15338 from totten/master-poc-postcommit
[civicrm-core.git] / CRM / Financial / Page / FinancialType.php
CommitLineData
6a488035 1<?php
6a488035 2/*
bc77d7c0
TO
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 +--------------------------------------------------------------------+
006389de 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * Page for displaying list of financial types
20 */
21class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic {
96f50de2
CW
22
23 public $useLivePageJS = TRUE;
6a488035 24 /**
fe482240 25 * The action links that we need to display for the browse screen.
6a488035
TO
26 *
27 * @var array
6a488035 28 */
7b966967 29 public static $_links = NULL;
6a488035
TO
30
31 /**
fe482240 32 * Get BAO Name.
6a488035 33 *
a6c01b45
CW
34 * @return string
35 * Classname of BAO.
6a488035 36 */
00be9182 37 public function getBAOName() {
6a488035
TO
38 return 'CRM_Financial_BAO_FinancialType';
39 }
40
41 /**
fe482240 42 * Get action Links.
6a488035 43 *
a6c01b45
CW
44 * @return array
45 * (reference) of action links
6a488035 46 */
00be9182 47 public function &links() {
6a488035 48 if (!(self::$_links)) {
be2fb01f
CW
49 self::$_links = [
50 CRM_Core_Action::BROWSE => [
353ffa53
TO
51 'name' => ts('Accounts'),
52 'url' => 'civicrm/admin/financial/financialType/accounts',
53 'qs' => 'reset=1&action=browse&aid=%%id%%',
6a488035 54 'title' => ts('Accounts'),
be2fb01f
CW
55 ],
56 CRM_Core_Action::UPDATE => [
353ffa53
TO
57 'name' => ts('Edit'),
58 'url' => 'civicrm/admin/financial/financialType',
59 'qs' => 'action=update&id=%%id%%&reset=1',
6a488035 60 'title' => ts('Edit Financial Type'),
be2fb01f
CW
61 ],
62 CRM_Core_Action::DISABLE => [
353ffa53
TO
63 'name' => ts('Disable'),
64 'ref' => 'crm-enable-disable',
6a488035 65 'title' => ts('Disable Financial Type'),
be2fb01f
CW
66 ],
67 CRM_Core_Action::ENABLE => [
353ffa53
TO
68 'name' => ts('Enable'),
69 'ref' => 'crm-enable-disable',
6a488035 70 'title' => ts('Enable Financial Type'),
be2fb01f
CW
71 ],
72 CRM_Core_Action::DELETE => [
353ffa53
TO
73 'name' => ts('Delete'),
74 'url' => 'civicrm/admin/financial/financialType',
75 'qs' => 'action=delete&id=%%id%%',
6a488035 76 'title' => ts('Delete Financial Type'),
be2fb01f
CW
77 ],
78 ];
6a488035
TO
79 }
80 return self::$_links;
81 }
82
6a488035 83 /**
fe482240 84 * Browse all financial types.
6a488035 85 */
00be9182 86 public function browse() {
1ac87087
PN
87 // Check permission for Financial Type when ACL-FT is enabled
88 if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
89 && !CRM_Core_Permission::check('administer CiviCRM Financial Types')
90 ) {
beb414cc 91 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
1ac87087 92 }
6a488035 93 // get all financial types sorted by weight
be2fb01f 94 $financialType = [];
6a488035
TO
95 $dao = new CRM_Financial_DAO_FinancialType();
96 $dao->orderBy('name');
97 $dao->find();
98
99 while ($dao->fetch()) {
be2fb01f 100 $financialType[$dao->id] = [];
481a74f4 101 CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
be2fb01f 102 $defaults = $financialAccountId = [];
ecc1e0ef 103 $financialAccounts = CRM_Contribute_PseudoConstant::financialAccount();
be2fb01f 104 $financialAccountIds = [];
03e04002 105
ecc1e0ef
PN
106 $params['entity_id'] = $dao->id;
107 $params['entity_table'] = 'civicrm_financial_type';
db62d3a5
SL
108 $null = [];
109 CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $null, $financialAccountIds);
6a488035 110
9b873358 111 foreach ($financialAccountIds as $key => $values) {
a7488080 112 if (!empty($financialAccounts[$values['financial_account_id']])) {
6a488035 113 $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value(
481a74f4 114 $values['financial_account_id'], $financialAccounts);
6a488035
TO
115 }
116 }
117
118 if (!empty($financialAccountId)) {
481a74f4 119 $financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId);
6a488035
TO
120 }
121
122 // form all action links
123 $action = array_sum(array_keys($this->links()));
124
125 // update enable/disable links depending on if it is is_reserved or is_active
126 if ($dao->is_reserved) {
127 $action -= CRM_Core_Action::ENABLE;
128 $action -= CRM_Core_Action::DISABLE;
129 $action -= CRM_Core_Action::DELETE;
6a488035
TO
130 }
131 else {
132 if ($dao->is_active) {
133 $action -= CRM_Core_Action::ENABLE;
134 }
135 else {
136 $action -= CRM_Core_Action::DISABLE;
137 }
138 }
139
140 $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
be2fb01f 141 ['id' => $dao->id],
87dab4a4
AH
142 ts('more'),
143 FALSE,
144 'financialType.manage.action',
145 'FinancialType',
146 $dao->id
147 );
6a488035
TO
148 }
149 $this->assign('rows', $financialType);
150 }
151
152 /**
fe482240 153 * Get name of edit form.
6a488035 154 *
a6c01b45
CW
155 * @return string
156 * Classname of edit form.
6a488035 157 */
00be9182 158 public function editForm() {
6a488035
TO
159 return 'CRM_Financial_Form_FinancialType';
160 }
161
162 /**
fe482240 163 * Get edit form name.
6a488035 164 *
a6c01b45
CW
165 * @return string
166 * name of this page.
6a488035 167 */
00be9182 168 public function editName() {
6a488035
TO
169 return 'Financial Types';
170 }
171
172 /**
173 * Get user context.
174 *
fd31fa4c
EM
175 * @param null $mode
176 *
a6c01b45
CW
177 * @return string
178 * user context.
6a488035 179 */
045f52a3 180 public function userContext($mode = NULL) {
6a488035
TO
181 return 'civicrm/admin/financial/financialType';
182 }
96025800 183
6a488035 184}