CRM-12595 fix formatting in remaing files
[civicrm-core.git] / CRM / Financial / Page / FinancialTypeAccount.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
31 * @copyright CiviCRM LLC (c) 2004-2013
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 */
54 static $_aid = null;
55
56 /**
57 * Get BAO Name
58 *
59 * @return string Classname of BAO.
60 */
61 function getBAOName() {
62 return 'CRM_Financial_BAO_FinancialTypeAccount';
63 }
64
65 /**
66 * Get action Links
67 *
68 * @return array (reference) of action links
69 */
70 function &links() {
71 if (!(self::$_links)) {
72 self::$_links = array(
73 CRM_Core_Action::UPDATE => array(
74 'name' => ts('Edit'),
75 'url' => 'civicrm/admin/financial/financialType/accounts',
76 'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
77 'title' => ts('Edit Financial Type Account'),
78 ),
79 CRM_Core_Action::DELETE => array(
80 'name' => ts('Delete'),
81 'url' => 'civicrm/admin/financial/financialType/accounts',
82 'qs' => 'action=delete&id=%%id%%&aid=%%aid%%',
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
98 * @access public
99 *
100 */
101 function run() {
102 // get the requested action
103 $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse'
104
105 // assign vars to templates
106 $this->assign('action', $action);
107 $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0);
108 $this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this, false, 0);
109
110 // what action to take ?
111 if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
112 $this->edit($action, $id) ;
113 }
114 else {
115 $this->browse($action, $id);
116 }
117
118 // parent run
119 return parent::run();
120 }
121
122 /**
123 * Browse all Financial Type Account data
124 *
125 * @return void
126 * @access public
127 * @static
128 */
129 function browse() {
130 // get all Financial Type Account data sorted by weight
131 $financialType = array();
132 $params = array();
133 $dao = new CRM_Financial_DAO_EntityFinancialAccount();
134 $params['entity_id'] = $this->_aid;
135 $params['entity_table'] = 'civicrm_financial_type';
136 if ($this->_aid) {
137 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name');
138 CRM_Utils_System::setTitle($this->_title .' - '.ts( 'Assigned Financial Accounts'));
139 $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type');
140 $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship');
141 $dao->copyValues($params);
142 $dao->find();
143 while ($dao->fetch()) {
144 $financialType[$dao->id] = array();
145 CRM_Core_DAO::storeValues( $dao, $financialType[$dao->id] );
146
147 $params = array( 'id' => $dao->financial_account_id );
148 $defaults = array();
149 $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
150 if (!empty($financialAccount)) {
151 $financialType[$dao->id]['financial_account'] = $financialAccount->name;
152 $financialType[$dao->id]['accounting_code'] = $financialAccount->accounting_code;
153 $financialType[$dao->id]['account_type_code'] = $financialAccount->account_type_code;
154 $financialType[$dao->id]['is_active'] = $financialAccount->is_active;
155 if (!empty($financialAccount->contact_id)) {
156 $financialType[$dao->id]['owned_by'] = CRM_Contact_BAO_Contact::displayName($financialAccount->contact_id);
157 }
158 if (!empty($financialAccount->financial_account_type_id)) {
159 $optionGroupName = 'financial_account_type';
160 $financialType[$dao->id]['financial_account_type'] = CRM_Utils_Array::value($financialAccount->financial_account_type_id, $financialAccountType);
161
162 }
163 if (!empty($dao->account_relationship)) {
164 $optionGroupName = 'account_relationship';
165 $financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship);
166 }
167 }
168
169 // form all action links
170 $action = array_sum(array_keys($this->links()));
171 $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
172 array(
173 'id' => $dao->id,
174 'aid'=> $dao->entity_id,
175 )
176 );
177 }
178 $this->assign('rows', $financialType);
179 $this->assign( 'aid', $this->_aid );
180 $this->assign('financialTypeTitle', $this->_title);
181 }
182 else {
183 CRM_Core_Error::fatal( );
184 return null;
185 }
186 }
187
188 /**
189 * edit CiviCRM Financial Type Account data.
190 *
191 * editing would involved modifying existing financial Account Type + adding data
192 * to new financial Account Type.
193 *
194 * @param string $action the action to be invoked
195 *
196 * @return void
197 * @access public
198 */
199 function edit( $action ) {
200 // create a simple controller for editing CiviCRM Profile data
201 $controller = new CRM_Core_Controller_Simple( 'CRM_Financial_Form_FinancialTypeAccount', ts('Financial Account Types'), $action );
202
203 // set the userContext stack
204 $session = CRM_Core_Session::singleton();
205 $session->pushUserContext( CRM_Utils_System::url( 'civicrm/admin/financial/financialType/accounts',
206 'reset=1&action=browse&aid=' . $this->_aid ) );
207 $controller->set( 'aid', $this->_aid );
208
209 $controller->setEmbedded( true );
210 $controller->process();
211 $controller->run();
212 }
213 }
214
215