Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of financial types | |
38 | */ | |
39 | class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic { | |
96f50de2 CW |
40 | |
41 | public $useLivePageJS = TRUE; | |
6a488035 | 42 | /** |
fe482240 | 43 | * The action links that we need to display for the browse screen. |
6a488035 TO |
44 | * |
45 | * @var array | |
6a488035 | 46 | */ |
045f52a3 | 47 | static $_links = NULL; |
6a488035 TO |
48 | |
49 | /** | |
fe482240 | 50 | * Get BAO Name. |
6a488035 | 51 | * |
a6c01b45 CW |
52 | * @return string |
53 | * Classname of BAO. | |
6a488035 | 54 | */ |
00be9182 | 55 | public function getBAOName() { |
6a488035 TO |
56 | return 'CRM_Financial_BAO_FinancialType'; |
57 | } | |
58 | ||
59 | /** | |
fe482240 | 60 | * Get action Links. |
6a488035 | 61 | * |
a6c01b45 CW |
62 | * @return array |
63 | * (reference) of action links | |
6a488035 | 64 | */ |
00be9182 | 65 | public function &links() { |
6a488035 TO |
66 | if (!(self::$_links)) { |
67 | self::$_links = array( | |
353ffa53 TO |
68 | CRM_Core_Action::BROWSE => array( |
69 | 'name' => ts('Accounts'), | |
70 | 'url' => 'civicrm/admin/financial/financialType/accounts', | |
71 | 'qs' => 'reset=1&action=browse&aid=%%id%%', | |
6a488035 TO |
72 | 'title' => ts('Accounts'), |
73 | ), | |
353ffa53 TO |
74 | CRM_Core_Action::UPDATE => array( |
75 | 'name' => ts('Edit'), | |
76 | 'url' => 'civicrm/admin/financial/financialType', | |
77 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
6a488035 TO |
78 | 'title' => ts('Edit Financial Type'), |
79 | ), | |
80 | CRM_Core_Action::DISABLE => array( | |
353ffa53 TO |
81 | 'name' => ts('Disable'), |
82 | 'ref' => 'crm-enable-disable', | |
6a488035 TO |
83 | 'title' => ts('Disable Financial Type'), |
84 | ), | |
353ffa53 TO |
85 | CRM_Core_Action::ENABLE => array( |
86 | 'name' => ts('Enable'), | |
87 | 'ref' => 'crm-enable-disable', | |
6a488035 TO |
88 | 'title' => ts('Enable Financial Type'), |
89 | ), | |
353ffa53 TO |
90 | CRM_Core_Action::DELETE => array( |
91 | 'name' => ts('Delete'), | |
92 | 'url' => 'civicrm/admin/financial/financialType', | |
93 | 'qs' => 'action=delete&id=%%id%%', | |
6a488035 TO |
94 | 'title' => ts('Delete Financial Type'), |
95 | ), | |
96 | ); | |
97 | } | |
98 | return self::$_links; | |
99 | } | |
100 | ||
101 | /** | |
102 | * Run the page. | |
103 | * | |
104 | * This method is called after the page is created. It checks for the | |
105 | * type of action and executes that action. | |
106 | * Finally it calls the parent's run method. | |
107 | * | |
108 | * @return void | |
6a488035 | 109 | */ |
00be9182 | 110 | public function run() { |
6a488035 | 111 | // get the requested action |
045f52a3 | 112 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // default to 'browse' |
6a488035 TO |
113 | |
114 | // assign vars to templates | |
115 | $this->assign('action', $action); | |
045f52a3 | 116 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); |
6a488035 TO |
117 | |
118 | // what action to take ? | |
119 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
045f52a3 | 120 | $this->edit($action, $id); |
6a488035 TO |
121 | } |
122 | ||
123 | // parent run | |
124 | return parent::run(); | |
125 | } | |
126 | ||
127 | /** | |
fe482240 | 128 | * Browse all financial types. |
6a488035 TO |
129 | * |
130 | * | |
131 | * @return void | |
6a488035 | 132 | */ |
00be9182 | 133 | public function browse() { |
6a488035 TO |
134 | // get all financial types sorted by weight |
135 | $financialType = array(); | |
136 | $dao = new CRM_Financial_DAO_FinancialType(); | |
137 | $dao->orderBy('name'); | |
138 | $dao->find(); | |
139 | ||
140 | while ($dao->fetch()) { | |
141 | $financialType[$dao->id] = array(); | |
481a74f4 | 142 | CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]); |
6a488035 | 143 | $defaults = $financialAccountId = array(); |
ecc1e0ef PN |
144 | $financialAccounts = CRM_Contribute_PseudoConstant::financialAccount(); |
145 | $financialAccountIds = array(); | |
03e04002 | 146 | |
ecc1e0ef PN |
147 | $params['entity_id'] = $dao->id; |
148 | $params['entity_table'] = 'civicrm_financial_type'; | |
149 | CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds); | |
6a488035 | 150 | |
9b873358 | 151 | foreach ($financialAccountIds as $key => $values) { |
a7488080 | 152 | if (!empty($financialAccounts[$values['financial_account_id']])) { |
6a488035 | 153 | $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value( |
481a74f4 | 154 | $values['financial_account_id'], $financialAccounts); |
6a488035 TO |
155 | } |
156 | } | |
157 | ||
158 | if (!empty($financialAccountId)) { | |
481a74f4 | 159 | $financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId); |
6a488035 TO |
160 | } |
161 | ||
162 | // form all action links | |
163 | $action = array_sum(array_keys($this->links())); | |
164 | ||
165 | // update enable/disable links depending on if it is is_reserved or is_active | |
166 | if ($dao->is_reserved) { | |
167 | $action -= CRM_Core_Action::ENABLE; | |
168 | $action -= CRM_Core_Action::DISABLE; | |
169 | $action -= CRM_Core_Action::DELETE; | |
170 | //continue; | |
171 | } | |
172 | else { | |
173 | if ($dao->is_active) { | |
174 | $action -= CRM_Core_Action::ENABLE; | |
175 | } | |
176 | else { | |
177 | $action -= CRM_Core_Action::DISABLE; | |
178 | } | |
179 | } | |
180 | ||
181 | $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
87dab4a4 AH |
182 | array('id' => $dao->id), |
183 | ts('more'), | |
184 | FALSE, | |
185 | 'financialType.manage.action', | |
186 | 'FinancialType', | |
187 | $dao->id | |
188 | ); | |
6a488035 TO |
189 | } |
190 | $this->assign('rows', $financialType); | |
191 | } | |
192 | ||
193 | /** | |
fe482240 | 194 | * Get name of edit form. |
6a488035 | 195 | * |
a6c01b45 CW |
196 | * @return string |
197 | * Classname of edit form. | |
6a488035 | 198 | */ |
00be9182 | 199 | public function editForm() { |
6a488035 TO |
200 | return 'CRM_Financial_Form_FinancialType'; |
201 | } | |
202 | ||
203 | /** | |
fe482240 | 204 | * Get edit form name. |
6a488035 | 205 | * |
a6c01b45 CW |
206 | * @return string |
207 | * name of this page. | |
6a488035 | 208 | */ |
00be9182 | 209 | public function editName() { |
6a488035 TO |
210 | return 'Financial Types'; |
211 | } | |
212 | ||
213 | /** | |
214 | * Get user context. | |
215 | * | |
fd31fa4c EM |
216 | * @param null $mode |
217 | * | |
a6c01b45 CW |
218 | * @return string |
219 | * user context. | |
6a488035 | 220 | */ |
045f52a3 | 221 | public function userContext($mode = NULL) { |
6a488035 TO |
222 | return 'civicrm/admin/financial/financialType'; |
223 | } | |
96025800 | 224 | |
6a488035 | 225 | } |