Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of financial type accounts | |
38 | */ | |
39 | class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page { | |
40 | /** | |
41 | * The action links that we need to display for the browse screen | |
42 | * | |
43 | * @var array | |
44 | * @static | |
45 | */ | |
46 | static $_links = null; | |
47 | ||
48 | /** | |
49 | * The account id that we need to display for the browse screen | |
50 | * | |
51 | * @var array | |
52 | * @static | |
53 | */ | |
1ba0ac21 | 54 | protected $_aid = null; |
6a488035 TO |
55 | |
56 | /** | |
57 | * Get BAO Name | |
58 | * | |
59 | * @return string Classname of BAO. | |
60 | */ | |
00be9182 | 61 | public function getBAOName() { |
6a488035 TO |
62 | return 'CRM_Financial_BAO_FinancialTypeAccount'; |
63 | } | |
64 | ||
65 | /** | |
66 | * Get action Links | |
67 | * | |
68 | * @return array (reference) of action links | |
69 | */ | |
00be9182 | 70 | public function &links() { |
6a488035 TO |
71 | if (!(self::$_links)) { |
72 | self::$_links = array( | |
73 | CRM_Core_Action::UPDATE => array( | |
7d289724 PN |
74 | 'name' => ts('Edit'), |
75 | 'url' => 'civicrm/admin/financial/financialType/accounts', | |
76 | 'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1', | |
6a488035 TO |
77 | 'title' => ts('Edit Financial Type Account'), |
78 | ), | |
79 | CRM_Core_Action::DELETE => array( | |
7d289724 PN |
80 | 'name' => ts('Delete'), |
81 | 'url' => 'civicrm/admin/financial/financialType/accounts', | |
82 | 'qs' => 'action=delete&id=%%id%%&aid=%%aid%%', | |
6a488035 TO |
83 | 'title' => ts('Delete Financial Type Account'), |
84 | ), | |
85 | ); | |
86 | } | |
87 | return self::$_links; | |
88 | } | |
89 | ||
90 | /** | |
91 | * Run the page. | |
92 | * | |
93 | * This method is called after the page is created. It checks for the | |
94 | * type of action and executes that action. | |
95 | * Finally it calls the parent's run method. | |
96 | * | |
97 | * @return void | |
6a488035 TO |
98 | * |
99 | */ | |
00be9182 | 100 | public function run() { |
6a488035 TO |
101 | // get the requested action |
102 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse' | |
103 | ||
104 | // assign vars to templates | |
105 | $this->assign('action', $action); | |
106 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); | |
107 | $this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this, false, 0); | |
108 | ||
109 | // what action to take ? | |
110 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
111 | $this->edit($action, $id) ; | |
112 | } | |
113 | else { | |
114 | $this->browse($action, $id); | |
115 | } | |
116 | ||
117 | // parent run | |
118 | return parent::run(); | |
119 | } | |
120 | ||
121 | /** | |
122 | * Browse all Financial Type Account data | |
123 | * | |
124 | * @return void | |
6a488035 TO |
125 | * @static |
126 | */ | |
00be9182 | 127 | public function browse() { |
6a488035 TO |
128 | // get all Financial Type Account data sorted by weight |
129 | $financialType = array(); | |
130 | $params = array(); | |
131 | $dao = new CRM_Financial_DAO_EntityFinancialAccount(); | |
132 | $params['entity_id'] = $this->_aid; | |
133 | $params['entity_table'] = 'civicrm_financial_type'; | |
134 | if ($this->_aid) { | |
7d289724 | 135 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); |
6a488035 TO |
136 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name'); |
137 | CRM_Utils_System::setTitle($this->_title .' - '.ts( 'Assigned Financial Accounts')); | |
7611ae71 AS |
138 | $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id'); |
139 | $accountRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); | |
6a488035 TO |
140 | $dao->copyValues($params); |
141 | $dao->find(); | |
142 | while ($dao->fetch()) { | |
143 | $financialType[$dao->id] = array(); | |
7d289724 | 144 | CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]); |
6a488035 | 145 | |
7d289724 | 146 | $params = array('id' => $dao->financial_account_id); |
6a488035 TO |
147 | $defaults = array(); |
148 | $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); | |
149 | if (!empty($financialAccount)) { | |
150 | $financialType[$dao->id]['financial_account'] = $financialAccount->name; | |
151 | $financialType[$dao->id]['accounting_code'] = $financialAccount->accounting_code; | |
152 | $financialType[$dao->id]['account_type_code'] = $financialAccount->account_type_code; | |
153 | $financialType[$dao->id]['is_active'] = $financialAccount->is_active; | |
154 | if (!empty($financialAccount->contact_id)) { | |
155 | $financialType[$dao->id]['owned_by'] = CRM_Contact_BAO_Contact::displayName($financialAccount->contact_id); | |
156 | } | |
157 | if (!empty($financialAccount->financial_account_type_id)) { | |
158 | $optionGroupName = 'financial_account_type'; | |
159 | $financialType[$dao->id]['financial_account_type'] = CRM_Utils_Array::value($financialAccount->financial_account_type_id, $financialAccountType); | |
03e04002 | 160 | |
6a488035 TO |
161 | } |
162 | if (!empty($dao->account_relationship)) { | |
163 | $optionGroupName = 'account_relationship'; | |
164 | $financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship); | |
165 | } | |
166 | } | |
6a488035 TO |
167 | // form all action links |
168 | $action = array_sum(array_keys($this->links())); | |
7d289724 | 169 | $links = self::links(); |
8ef12e64 | 170 | |
7d289724 PN |
171 | //CRM-12492 |
172 | if ($dao->account_relationship == $relationTypeId) { | |
173 | unset($links[CRM_Core_Action::DELETE]); | |
174 | } | |
175 | $financialType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, | |
6a488035 TO |
176 | array( |
177 | 'id' => $dao->id, | |
178 | 'aid'=> $dao->entity_id, | |
87dab4a4 AH |
179 | ), |
180 | ts('more'), | |
181 | FALSE, | |
182 | 'financialTypeAccount.manage.action', | |
183 | 'FinancialTypeAccount', | |
184 | $dao->id | |
6a488035 TO |
185 | ); |
186 | } | |
187 | $this->assign('rows', $financialType); | |
188 | $this->assign( 'aid', $this->_aid ); | |
189 | $this->assign('financialTypeTitle', $this->_title); | |
190 | } | |
191 | else { | |
192 | CRM_Core_Error::fatal( ); | |
193 | return null; | |
194 | } | |
195 | } | |
196 | ||
197 | /** | |
100fef9d | 198 | * Edit CiviCRM Financial Type Account data. |
6a488035 TO |
199 | * |
200 | * editing would involved modifying existing financial Account Type + adding data | |
201 | * to new financial Account Type. | |
202 | * | |
203 | * @param string $action the action to be invoked | |
204 | * | |
205 | * @return void | |
6a488035 | 206 | */ |
00be9182 | 207 | public function edit( $action ) { |
6a488035 TO |
208 | // create a simple controller for editing CiviCRM Profile data |
209 | $controller = new CRM_Core_Controller_Simple( 'CRM_Financial_Form_FinancialTypeAccount', ts('Financial Account Types'), $action ); | |
210 | ||
211 | // set the userContext stack | |
212 | $session = CRM_Core_Session::singleton(); | |
213 | $session->pushUserContext( CRM_Utils_System::url( 'civicrm/admin/financial/financialType/accounts', | |
214 | 'reset=1&action=browse&aid=' . $this->_aid ) ); | |
215 | $controller->set( 'aid', $this->_aid ); | |
216 | ||
217 | $controller->setEmbedded( true ); | |
218 | $controller->process(); | |
219 | $controller->run(); | |
220 | } | |
221 | } |