Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
006389de | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * Page for displaying list of financial types | |
36 | */ | |
37 | class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic { | |
96f50de2 CW |
38 | |
39 | public $useLivePageJS = TRUE; | |
6a488035 | 40 | /** |
fe482240 | 41 | * The action links that we need to display for the browse screen. |
6a488035 TO |
42 | * |
43 | * @var array | |
6a488035 | 44 | */ |
045f52a3 | 45 | static $_links = NULL; |
6a488035 TO |
46 | |
47 | /** | |
fe482240 | 48 | * Get BAO Name. |
6a488035 | 49 | * |
a6c01b45 CW |
50 | * @return string |
51 | * Classname of BAO. | |
6a488035 | 52 | */ |
00be9182 | 53 | public function getBAOName() { |
6a488035 TO |
54 | return 'CRM_Financial_BAO_FinancialType'; |
55 | } | |
56 | ||
57 | /** | |
fe482240 | 58 | * Get action Links. |
6a488035 | 59 | * |
a6c01b45 CW |
60 | * @return array |
61 | * (reference) of action links | |
6a488035 | 62 | */ |
00be9182 | 63 | public function &links() { |
6a488035 TO |
64 | if (!(self::$_links)) { |
65 | self::$_links = array( | |
353ffa53 TO |
66 | CRM_Core_Action::BROWSE => array( |
67 | 'name' => ts('Accounts'), | |
68 | 'url' => 'civicrm/admin/financial/financialType/accounts', | |
69 | 'qs' => 'reset=1&action=browse&aid=%%id%%', | |
6a488035 TO |
70 | 'title' => ts('Accounts'), |
71 | ), | |
353ffa53 TO |
72 | CRM_Core_Action::UPDATE => array( |
73 | 'name' => ts('Edit'), | |
74 | 'url' => 'civicrm/admin/financial/financialType', | |
75 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
6a488035 TO |
76 | 'title' => ts('Edit Financial Type'), |
77 | ), | |
78 | CRM_Core_Action::DISABLE => array( | |
353ffa53 TO |
79 | 'name' => ts('Disable'), |
80 | 'ref' => 'crm-enable-disable', | |
6a488035 TO |
81 | 'title' => ts('Disable Financial Type'), |
82 | ), | |
353ffa53 TO |
83 | CRM_Core_Action::ENABLE => array( |
84 | 'name' => ts('Enable'), | |
85 | 'ref' => 'crm-enable-disable', | |
6a488035 TO |
86 | 'title' => ts('Enable Financial Type'), |
87 | ), | |
353ffa53 TO |
88 | CRM_Core_Action::DELETE => array( |
89 | 'name' => ts('Delete'), | |
90 | 'url' => 'civicrm/admin/financial/financialType', | |
91 | 'qs' => 'action=delete&id=%%id%%', | |
6a488035 TO |
92 | 'title' => ts('Delete Financial Type'), |
93 | ), | |
94 | ); | |
95 | } | |
96 | return self::$_links; | |
97 | } | |
98 | ||
23cb875c | 99 | /** |
100 | * Run the page. | |
101 | * | |
102 | * This method is called after the page is created. It checks for the | |
103 | * type of action and executes that action. | |
104 | * Finally it calls the parent's run method. | |
105 | */ | |
106 | public function run() { | |
107 | // get the requested action | |
108 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse' | |
109 | ||
110 | // assign vars to templates | |
111 | $this->assign('action', $action); | |
112 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); | |
113 | ||
114 | // what action to take ? | |
115 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
116 | $this->edit($action, $id); | |
117 | } | |
118 | ||
119 | // parent run | |
120 | return parent::run(); | |
121 | } | |
122 | ||
6a488035 | 123 | /** |
fe482240 | 124 | * Browse all financial types. |
6a488035 | 125 | */ |
00be9182 | 126 | public function browse() { |
1ac87087 PN |
127 | // Check permission for Financial Type when ACL-FT is enabled |
128 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() | |
129 | && !CRM_Core_Permission::check('administer CiviCRM Financial Types') | |
130 | ) { | |
131 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); | |
132 | } | |
6a488035 TO |
133 | // get all financial types sorted by weight |
134 | $financialType = array(); | |
135 | $dao = new CRM_Financial_DAO_FinancialType(); | |
136 | $dao->orderBy('name'); | |
137 | $dao->find(); | |
138 | ||
139 | while ($dao->fetch()) { | |
140 | $financialType[$dao->id] = array(); | |
481a74f4 | 141 | CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]); |
6a488035 | 142 | $defaults = $financialAccountId = array(); |
ecc1e0ef PN |
143 | $financialAccounts = CRM_Contribute_PseudoConstant::financialAccount(); |
144 | $financialAccountIds = array(); | |
03e04002 | 145 | |
ecc1e0ef PN |
146 | $params['entity_id'] = $dao->id; |
147 | $params['entity_table'] = 'civicrm_financial_type'; | |
148 | CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds); | |
6a488035 | 149 | |
9b873358 | 150 | foreach ($financialAccountIds as $key => $values) { |
a7488080 | 151 | if (!empty($financialAccounts[$values['financial_account_id']])) { |
6a488035 | 152 | $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value( |
481a74f4 | 153 | $values['financial_account_id'], $financialAccounts); |
6a488035 TO |
154 | } |
155 | } | |
156 | ||
157 | if (!empty($financialAccountId)) { | |
481a74f4 | 158 | $financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId); |
6a488035 TO |
159 | } |
160 | ||
161 | // form all action links | |
162 | $action = array_sum(array_keys($this->links())); | |
163 | ||
164 | // update enable/disable links depending on if it is is_reserved or is_active | |
165 | if ($dao->is_reserved) { | |
166 | $action -= CRM_Core_Action::ENABLE; | |
167 | $action -= CRM_Core_Action::DISABLE; | |
168 | $action -= CRM_Core_Action::DELETE; | |
6a488035 TO |
169 | } |
170 | else { | |
171 | if ($dao->is_active) { | |
172 | $action -= CRM_Core_Action::ENABLE; | |
173 | } | |
174 | else { | |
175 | $action -= CRM_Core_Action::DISABLE; | |
176 | } | |
177 | } | |
178 | ||
179 | $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
87dab4a4 AH |
180 | array('id' => $dao->id), |
181 | ts('more'), | |
182 | FALSE, | |
183 | 'financialType.manage.action', | |
184 | 'FinancialType', | |
185 | $dao->id | |
186 | ); | |
6a488035 TO |
187 | } |
188 | $this->assign('rows', $financialType); | |
189 | } | |
190 | ||
191 | /** | |
fe482240 | 192 | * Get name of edit form. |
6a488035 | 193 | * |
a6c01b45 CW |
194 | * @return string |
195 | * Classname of edit form. | |
6a488035 | 196 | */ |
00be9182 | 197 | public function editForm() { |
6a488035 TO |
198 | return 'CRM_Financial_Form_FinancialType'; |
199 | } | |
200 | ||
201 | /** | |
fe482240 | 202 | * Get edit form name. |
6a488035 | 203 | * |
a6c01b45 CW |
204 | * @return string |
205 | * name of this page. | |
6a488035 | 206 | */ |
00be9182 | 207 | public function editName() { |
6a488035 TO |
208 | return 'Financial Types'; |
209 | } | |
210 | ||
211 | /** | |
212 | * Get user context. | |
213 | * | |
fd31fa4c EM |
214 | * @param null $mode |
215 | * | |
a6c01b45 CW |
216 | * @return string |
217 | * user context. | |
6a488035 | 218 | */ |
045f52a3 | 219 | public function userContext($mode = NULL) { |
6a488035 TO |
220 | return 'civicrm/admin/financial/financialType'; |
221 | } | |
96025800 | 222 | |
6a488035 | 223 | } |