Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * Page for displaying list of financial type accounts | |
39 | */ | |
40 | class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page { | |
41 | /** | |
42 | * The action links that we need to display for the browse screen | |
43 | * | |
44 | * @var array | |
45 | * @static | |
46 | */ | |
47 | static $_links = null; | |
48 | ||
49 | /** | |
50 | * The account id that we need to display for the browse screen | |
51 | * | |
52 | * @var array | |
53 | * @static | |
54 | */ | |
55 | static $_aid = null; | |
56 | ||
57 | /** | |
58 | * Get BAO Name | |
59 | * | |
60 | * @return string Classname of BAO. | |
61 | */ | |
62 | function getBAOName() { | |
63 | return 'CRM_Financial_BAO_FinancialTypeAccount'; | |
64 | } | |
65 | ||
66 | /** | |
67 | * Get action Links | |
68 | * | |
69 | * @return array (reference) of action links | |
70 | */ | |
71 | function &links() { | |
72 | if (!(self::$_links)) { | |
73 | self::$_links = array( | |
74 | CRM_Core_Action::UPDATE => array( | |
75 | 'name' => ts('Edit'), | |
76 | 'url' => 'civicrm/admin/financial/financialType/accounts', | |
77 | 'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1', | |
78 | 'title' => ts('Edit Financial Type Account'), | |
79 | ), | |
80 | CRM_Core_Action::DELETE => array( | |
81 | 'name' => ts('Delete'), | |
82 | 'url' => 'civicrm/admin/financial/financialType/accounts', | |
83 | 'qs' => 'action=delete&id=%%id%%&aid=%%aid%%', | |
84 | 'title' => ts('Delete Financial Type Account'), | |
85 | ), | |
86 | ); | |
87 | } | |
88 | return self::$_links; | |
89 | } | |
90 | ||
91 | /** | |
92 | * Run the page. | |
93 | * | |
94 | * This method is called after the page is created. It checks for the | |
95 | * type of action and executes that action. | |
96 | * Finally it calls the parent's run method. | |
97 | * | |
98 | * @return void | |
99 | * @access public | |
100 | * | |
101 | */ | |
102 | function run() { | |
103 | // get the requested action | |
104 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse' | |
105 | ||
106 | // assign vars to templates | |
107 | $this->assign('action', $action); | |
108 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); | |
109 | $this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this, false, 0); | |
110 | ||
111 | // what action to take ? | |
112 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
113 | $this->edit($action, $id) ; | |
114 | } | |
115 | else { | |
116 | $this->browse($action, $id); | |
117 | } | |
118 | ||
119 | // parent run | |
120 | return parent::run(); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Browse all Financial Type Account data | |
125 | * | |
126 | * @return void | |
127 | * @access public | |
128 | * @static | |
129 | */ | |
130 | function browse() { | |
131 | // get all Financial Type Account data sorted by weight | |
132 | $financialType = array(); | |
133 | $params = array(); | |
134 | $dao = new CRM_Financial_DAO_EntityFinancialAccount(); | |
135 | $params['entity_id'] = $this->_aid; | |
136 | $params['entity_table'] = 'civicrm_financial_type'; | |
137 | if ($this->_aid) { | |
138 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name'); | |
139 | CRM_Utils_System::setTitle($this->_title .' - '.ts( 'Assigned Financial Accounts')); | |
140 | $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); | |
141 | $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); | |
142 | $dao->copyValues($params); | |
143 | $dao->find(); | |
144 | while ($dao->fetch()) { | |
145 | $financialType[$dao->id] = array(); | |
146 | CRM_Core_DAO::storeValues( $dao, $financialType[$dao->id] ); | |
147 | ||
148 | $params = array( 'id' => $dao->financial_account_id ); | |
149 | $defaults = array(); | |
150 | $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); | |
151 | if (!empty($financialAccount)) { | |
152 | $financialType[$dao->id]['financial_account'] = $financialAccount->name; | |
153 | $financialType[$dao->id]['accounting_code'] = $financialAccount->accounting_code; | |
154 | $financialType[$dao->id]['account_type_code'] = $financialAccount->account_type_code; | |
155 | $financialType[$dao->id]['is_active'] = $financialAccount->is_active; | |
156 | if (!empty($financialAccount->contact_id)) { | |
157 | $financialType[$dao->id]['owned_by'] = CRM_Contact_BAO_Contact::displayName($financialAccount->contact_id); | |
158 | } | |
159 | if (!empty($financialAccount->financial_account_type_id)) { | |
160 | $optionGroupName = 'financial_account_type'; | |
161 | $financialType[$dao->id]['financial_account_type'] = CRM_Utils_Array::value($financialAccount->financial_account_type_id, $financialAccountType); | |
162 | ||
163 | } | |
164 | if (!empty($dao->account_relationship)) { | |
165 | $optionGroupName = 'account_relationship'; | |
166 | $financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship); | |
167 | } | |
168 | } | |
169 | ||
170 | // form all action links | |
171 | $action = array_sum(array_keys($this->links())); | |
172 | $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
173 | array( | |
174 | 'id' => $dao->id, | |
175 | 'aid'=> $dao->entity_id, | |
176 | ) | |
177 | ); | |
178 | } | |
179 | $this->assign('rows', $financialType); | |
180 | $this->assign( 'aid', $this->_aid ); | |
181 | $this->assign('financialTypeTitle', $this->_title); | |
182 | } | |
183 | else { | |
184 | CRM_Core_Error::fatal( ); | |
185 | return null; | |
186 | } | |
187 | } | |
188 | ||
189 | /** | |
190 | * edit CiviCRM Financial Type Account data. | |
191 | * | |
192 | * editing would involved modifying existing financial Account Type + adding data | |
193 | * to new financial Account Type. | |
194 | * | |
195 | * @param string $action the action to be invoked | |
196 | * | |
197 | * @return void | |
198 | * @access public | |
199 | */ | |
200 | function edit( $action ) { | |
201 | // create a simple controller for editing CiviCRM Profile data | |
202 | $controller = new CRM_Core_Controller_Simple( 'CRM_Financial_Form_FinancialTypeAccount', ts('Financial Account Types'), $action ); | |
203 | ||
204 | // set the userContext stack | |
205 | $session = CRM_Core_Session::singleton(); | |
206 | $session->pushUserContext( CRM_Utils_System::url( 'civicrm/admin/financial/financialType/accounts', | |
207 | 'reset=1&action=browse&aid=' . $this->_aid ) ); | |
208 | $controller->set( 'aid', $this->_aid ); | |
209 | ||
210 | $controller->setEmbedded( true ); | |
211 | $controller->process(); | |
212 | $controller->run(); | |
213 | } | |
214 | } | |
215 | ||
216 |