Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 | 32 | */ |
6a488035 TO |
33 | class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAccount { |
34 | ||
6a488035 | 35 | /** |
fe482240 | 36 | * Class constructor. |
6a488035 | 37 | */ |
00be9182 | 38 | public function __construct() { |
ac7514c2 | 39 | parent::__construct(); |
6a488035 | 40 | } |
0e6e8724 | 41 | |
6a488035 | 42 | /** |
fe482240 | 43 | * Fetch object based on array of properties. |
6a488035 | 44 | * |
ed5dd492 TO |
45 | * @param array $params |
46 | * (reference ) an assoc array of name/value pairs. | |
47 | * @param array $defaults | |
48 | * (reference ) an assoc array to hold the flattened values. | |
6a488035 | 49 | * |
72b3a70c | 50 | * @return CRM_Financial_BAO_FinancialAccount |
6a488035 | 51 | */ |
00be9182 | 52 | public static function retrieve(&$params, &$defaults) { |
ac7514c2 PN |
53 | $financialAccount = new CRM_Financial_DAO_FinancialAccount(); |
54 | $financialAccount->copyValues($params); | |
55 | if ($financialAccount->find(TRUE)) { | |
6a488035 TO |
56 | CRM_Core_DAO::storeValues($financialAccount, $defaults); |
57 | return $financialAccount; | |
58 | } | |
ac7514c2 | 59 | return NULL; |
6a488035 TO |
60 | } |
61 | ||
62 | /** | |
fe482240 | 63 | * Update the is_active flag in the db. |
6a488035 | 64 | * |
ed5dd492 TO |
65 | * @param int $id |
66 | * Id of the database record. | |
67 | * @param bool $is_active | |
68 | * Value we want to set the is_active field. | |
6a488035 | 69 | * |
8a4fede3 | 70 | * @return bool |
71 | * true if we found and updated the object, else false | |
6a488035 | 72 | */ |
00be9182 | 73 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
74 | return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $id, 'is_active', $is_active); |
75 | } | |
76 | ||
77 | /** | |
fe482240 | 78 | * Add the financial types. |
6a488035 | 79 | * |
ed5dd492 TO |
80 | * @param array $params |
81 | * Reference array contains the values submitted by the form. | |
0e6e8724 | 82 | * |
72b3a70c | 83 | * @return CRM_Financial_DAO_FinancialAccount |
6a488035 | 84 | */ |
235929d0 | 85 | public static function add(&$params) { |
22e263ad | 86 | if (empty($params['id'])) { |
bc2bc079 | 87 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); |
88 | $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE); | |
89 | $params['is_tax'] = CRM_Utils_Array::value('is_tax', $params, FALSE); | |
90 | $params['is_header_account'] = CRM_Utils_Array::value('is_header_account', $params, FALSE); | |
91 | $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); | |
92 | } | |
235929d0 PN |
93 | if (!empty($params['id']) |
94 | && !empty($params['financial_account_type_id']) | |
95 | && CRM_Financial_BAO_FinancialAccount::validateFinancialAccount( | |
96 | $params['id'], | |
97 | $params['financial_account_type_id'] | |
98 | ) | |
99 | ) { | |
100 | throw new CRM_Core_Exception(ts('You cannot change the account type since this financial account refers to a financial item having an account type of Revenue/Liability.')); | |
101 | } | |
a7488080 | 102 | if (!empty($params['is_default'])) { |
ac7514c2 PN |
103 | $query = 'UPDATE civicrm_financial_account SET is_default = 0 WHERE financial_account_type_id = %1'; |
104 | $queryParams = array(1 => array($params['financial_account_type_id'], 'Integer')); | |
105 | CRM_Core_DAO::executeQuery($query, $queryParams); | |
0e6e8724 DL |
106 | } |
107 | ||
6a488035 | 108 | // action is taken depending upon the mode |
ac7514c2 | 109 | $financialAccount = new CRM_Financial_DAO_FinancialAccount(); |
afa09af7 PN |
110 | |
111 | // invoke pre hook | |
112 | $op = 'create'; | |
113 | if (!empty($params['id'])) { | |
114 | $op = 'edit'; | |
115 | } | |
116 | CRM_Utils_Hook::pre($op, 'FinancialAccount', CRM_Utils_Array::value('id', $params), $params); | |
117 | ||
235929d0 PN |
118 | if (!empty($params['id'])) { |
119 | $financialAccount->id = $params['id']; | |
120 | $financialAccount->find(TRUE); | |
121 | } | |
122 | ||
6a488035 | 123 | $financialAccount->copyValues($params); |
ac7514c2 | 124 | $financialAccount->save(); |
afa09af7 PN |
125 | |
126 | // invoke post hook | |
127 | $op = 'create'; | |
128 | if (!empty($params['id'])) { | |
129 | $op = 'edit'; | |
130 | } | |
131 | CRM_Utils_Hook::post($op, 'FinancialAccount', $financialAccount->id, $financialAccount); | |
132 | ||
6a488035 TO |
133 | return $financialAccount; |
134 | } | |
0e6e8724 | 135 | |
6a488035 | 136 | /** |
fe482240 | 137 | * Delete financial Types. |
0e6e8724 | 138 | * |
6a488035 | 139 | * @param int $financialAccountId |
6a488035 | 140 | */ |
00be9182 | 141 | public static function del($financialAccountId) { |
cded2ebf | 142 | // checking if financial type is present |
ac7514c2 | 143 | $check = FALSE; |
0e6e8724 | 144 | |
6a488035 | 145 | //check dependencies |
b44e3f84 | 146 | $dependency = array( |
0e6e8724 DL |
147 | array('Core', 'FinancialTrxn', 'to_financial_account_id'), |
148 | array('Financial', 'FinancialTypeAccount', 'financial_account_id'), | |
f0d6e4c5 | 149 | array('Financial', 'FinancialItem', 'financial_account_id'), |
353ffa53 | 150 | ); |
b44e3f84 | 151 | foreach ($dependency as $name) { |
045f52a3 | 152 | require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_" . $name[0] . "_BAO_" . $name[1]) . ".php"; |
0e6e8724 DL |
153 | $className = "CRM_{$name[0]}_BAO_{$name[1]}"; |
154 | $bao = new $className(); | |
6ef04c72 | 155 | $bao->{$name[2]} = $financialAccountId; |
ac7514c2 PN |
156 | if ($bao->find(TRUE)) { |
157 | $check = TRUE; | |
6a488035 TO |
158 | } |
159 | } | |
0e6e8724 | 160 | |
6a488035 | 161 | if ($check) { |
ac7514c2 | 162 | CRM_Core_Session::setStatus(ts('This financial account cannot be deleted since it is being used as a header account. Please remove it from being a header account before trying to delete it again.')); |
05b9ff02 | 163 | return FALSE; |
6a488035 | 164 | } |
0e6e8724 | 165 | |
cded2ebf | 166 | // delete from financial Type table |
ac7514c2 | 167 | $financialAccount = new CRM_Financial_DAO_FinancialAccount(); |
6a488035 TO |
168 | $financialAccount->id = $financialAccountId; |
169 | $financialAccount->delete(); | |
05b9ff02 | 170 | return TRUE; |
6a488035 | 171 | } |
0e6e8724 | 172 | |
6a488035 | 173 | /** |
fe482240 | 174 | * Get accounting code for a financial type with account relation Income Account is. |
6a488035 | 175 | * |
100fef9d | 176 | * @param int $financialTypeId |
da6b46f4 | 177 | * |
72b3a70c CW |
178 | * @return int |
179 | * accounting code | |
6a488035 | 180 | */ |
00be9182 | 181 | public static function getAccountingCode($financialTypeId) { |
f743a6eb | 182 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); |
6a488035 TO |
183 | $query = "SELECT cfa.accounting_code |
184 | FROM civicrm_financial_type cft | |
185 | LEFT JOIN civicrm_entity_financial_account cefa ON cefa.entity_id = cft.id AND cefa.entity_table = 'civicrm_financial_type' | |
186 | LEFT JOIN civicrm_financial_account cfa ON cefa.financial_account_id = cfa.id | |
187 | WHERE cft.id = %1 | |
188 | AND account_relationship = %2"; | |
189 | $params = array( | |
190 | 1 => array($financialTypeId, 'Integer'), | |
191 | 2 => array($relationTypeId, 'Integer'), | |
192 | ); | |
193 | return CRM_Core_DAO::singleValueQuery($query, $params); | |
194 | } | |
0e6e8724 | 195 | |
7d289724 | 196 | /** |
fe482240 | 197 | * Get AR account. |
7d289724 | 198 | * |
ed5dd492 TO |
199 | * @param $financialAccountId |
200 | * Financial account id. | |
7d289724 | 201 | * |
ed5dd492 TO |
202 | * @param $financialAccountTypeId |
203 | * Financial account type id. | |
7d289724 | 204 | * |
72b3a70c CW |
205 | * @param string $accountTypeCode |
206 | * account type code | |
7d289724 | 207 | * |
df8d3074 | 208 | * @return int |
a6c01b45 | 209 | * count |
7d289724 | 210 | */ |
00be9182 | 211 | public static function getARAccounts($financialAccountId, $financialAccountTypeId = NULL, $accountTypeCode = 'ar') { |
ddaa8ef1 | 212 | if (!$financialAccountTypeId) { |
7d45c236 | 213 | $financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' ")); |
ddaa8ef1 | 214 | } |
7d289724 | 215 | $query = "SELECT count(id) FROM civicrm_financial_account WHERE financial_account_type_id = %1 AND LCASE(account_type_code) = %2 |
ddaa8ef1 | 216 | AND id != %3 AND is_active = 1;"; |
7d289724 PN |
217 | $params = array( |
218 | 1 => array($financialAccountTypeId, 'Integer'), | |
219 | 2 => array(strtolower($accountTypeCode), 'String'), | |
220 | 3 => array($financialAccountId, 'Integer'), | |
221 | ); | |
045f52a3 | 222 | return CRM_Core_DAO::singleValueQuery($query, $params); |
7d289724 | 223 | } |
96025800 | 224 | |
bf2cf926 | 225 | /** |
226 | * Get the Financial Account for a Financial Type Relationship Combo. | |
227 | * | |
228 | * Note that some relationships are optionally configured - so far | |
229 | * Chargeback and Credit / Contra. Since these are the only 2 currently Income | |
230 | * is an appropriate fallback. In future it might make sense to extend the logic. | |
231 | * | |
232 | * Note that we avoid the CRM_Core_PseudoConstant function as it stores one | |
233 | * account per financial type and is unreliable. | |
234 | * | |
235 | * @param int $financialTypeID | |
236 | * | |
237 | * @param string $relationshipType | |
238 | * | |
239 | * @return int | |
240 | */ | |
241 | public static function getFinancialAccountForFinancialTypeByRelationship($financialTypeID, $relationshipType) { | |
242 | $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE '{$relationshipType}' ")); | |
243 | ||
244 | if (!isset(Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId])) { | |
245 | $accounts = civicrm_api3('EntityFinancialAccount', 'get', array( | |
246 | 'entity_id' => $financialTypeID, | |
247 | 'entity_table' => 'civicrm_financial_type', | |
248 | )); | |
249 | ||
250 | foreach ($accounts['values'] as $account) { | |
251 | Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$account['account_relationship']] = $account['financial_account_id']; | |
252 | } | |
253 | ||
254 | $accountRelationships = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL); | |
255 | ||
256 | $incomeAccountRelationshipID = array_search('Income Account is', $accountRelationships); | |
257 | $incomeAccountFinancialAccountID = Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$incomeAccountRelationshipID]; | |
258 | ||
259 | foreach (array('Chargeback Account is', 'Credit/Contra Revenue Account is') as $optionalAccountRelationship) { | |
260 | ||
261 | $accountRelationshipID = array_search($optionalAccountRelationship, $accountRelationships); | |
262 | if (empty(Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$accountRelationshipID])) { | |
52da5b1e | 263 | Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$accountRelationshipID] = $incomeAccountFinancialAccountID; |
bf2cf926 | 264 | } |
265 | } | |
928a340b | 266 | if (!isset(Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId])) { |
267 | Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId] = NULL; | |
268 | } | |
bf2cf926 | 269 | } |
270 | return Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId]; | |
271 | } | |
272 | ||
e66512af | 273 | /** |
871de167 | 274 | * Get Financial Account type relations. |
e66512af PN |
275 | * |
276 | * @param $flip bool | |
277 | * | |
278 | * @return array | |
279 | * | |
280 | */ | |
eac838e9 | 281 | public static function getfinancialAccountRelations($flip = FALSE) { |
e66512af PN |
282 | $params = array('labelColumn' => 'name'); |
283 | $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params); | |
284 | $accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params); | |
285 | $Links = array( | |
286 | 'Expense Account is' => 'Expenses', | |
287 | 'Accounts Receivable Account is' => 'Asset', | |
288 | 'Income Account is' => 'Revenue', | |
289 | 'Asset Account is' => 'Asset', | |
290 | 'Cost of Sales Account is' => 'Cost of Sales', | |
291 | 'Premiums Inventory Account is' => 'Asset', | |
292 | 'Discounts Account is' => 'Revenue', | |
293 | 'Sales Tax Account is' => 'Liability', | |
294 | 'Deferred Revenue Account is' => 'Liability', | |
295 | ); | |
296 | if (!$flip) { | |
297 | foreach ($Links as $accountRelation => $accountType) { | |
298 | $financialAccountLinks[array_search($accountRelation, $accountRelationships)] = array_search($accountType, $financialAccountType); | |
299 | } | |
300 | } | |
301 | else { | |
302 | foreach ($Links as $accountRelation => $accountType) { | |
303 | $financialAccountLinks[array_search($accountType, $financialAccountType)][] = array_search($accountRelation, $accountRelationships); | |
304 | } | |
305 | } | |
e66512af PN |
306 | return $financialAccountLinks; |
307 | } | |
308 | ||
d9eeb0f4 | 309 | /** |
871de167 | 310 | * Get Deferred Financial type. |
d9eeb0f4 PN |
311 | * |
312 | * @return array | |
313 | * | |
314 | */ | |
315 | public static function getDeferredFinancialType() { | |
316 | $deferredFinancialType = array(); | |
317 | $query = "SELECT ce.entity_id, cft.name FROM civicrm_entity_financial_account ce | |
d9eeb0f4 | 318 | INNER JOIN civicrm_financial_type cft ON ce.entity_id = cft.id |
c5d6e9b5 PN |
319 | WHERE ce.entity_table = 'civicrm_financial_type' AND ce.account_relationship = %1 AND cft.is_active = 1"; |
320 | $deferredAccountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' ")); | |
321 | $queryParams = array(1 => array($deferredAccountRel, 'Integer')); | |
322 | $dao = CRM_Core_DAO::executeQuery($query, $queryParams); | |
d9eeb0f4 PN |
323 | while ($dao->fetch()) { |
324 | $deferredFinancialType[$dao->entity_id] = $dao->name; | |
325 | } | |
326 | return $deferredFinancialType; | |
327 | } | |
328 | ||
e805833b | 329 | /** |
b1b5303b | 330 | * Check if financial account is referenced by financial item. |
e805833b | 331 | * |
b1b5303b | 332 | * @param int $financialAccountId |
e805833b | 333 | * |
b1b5303b | 334 | * @param int $financialAccountTypeID |
ea996660 | 335 | * |
e805833b | 336 | * @return bool |
ea996660 PN |
337 | * |
338 | */ | |
339 | public static function validateFinancialAccount($financialAccountId, $financialAccountTypeID = NULL) { | |
e805833b | 340 | $sql = "SELECT f.financial_account_type_id FROM civicrm_financial_account f |
fed4d93d | 341 | INNER JOIN civicrm_financial_item fi ON fi.financial_account_id = f.id |
b1b5303b | 342 | WHERE f.id = %1 AND f.financial_account_type_id IN (%2) |
e805833b | 343 | LIMIT 1"; |
b1b5303b PN |
344 | $params = array('labelColumn' => 'name'); |
345 | $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params); | |
346 | $params = array( | |
347 | 1 => array($financialAccountId, 'Integer'), | |
348 | 2 => array( | |
349 | implode(',', | |
350 | array( | |
351 | array_search('Revenue', $financialAccountType), | |
352 | array_search('Liability', $financialAccountType), | |
353 | ) | |
354 | ), | |
7d68b2a3 | 355 | 'Text', |
b1b5303b PN |
356 | ), |
357 | ); | |
e805833b | 358 | $result = CRM_Core_DAO::singleValueQuery($sql, $params); |
fed4d93d | 359 | if ($result && $result != $financialAccountTypeID) { |
e805833b PN |
360 | return TRUE; |
361 | } | |
362 | return FALSE; | |
363 | } | |
364 | ||
b2ffc3e1 PN |
365 | /** |
366 | * Validate Financial Type has Deferred Revenue account relationship | |
ab6c306d | 367 | * with Financial Account. |
b2ffc3e1 PN |
368 | * |
369 | * @param array $params | |
ab6c306d | 370 | * Holds submitted formvalues and params from api for updating/adding contribution. |
b2ffc3e1 PN |
371 | * |
372 | * @param int $contributionID | |
c849d761 | 373 | * Contribution ID |
b2ffc3e1 | 374 | * |
ab6c306d PN |
375 | * @param array $priceSetFields |
376 | * Array of price fields of a price set. | |
b2ffc3e1 | 377 | * |
52d479ee | 378 | * @return bool |
b2ffc3e1 PN |
379 | * |
380 | */ | |
ab6c306d | 381 | public static function checkFinancialTypeHasDeferred($params, $contributionID = NULL, $priceSetFields = NULL) { |
b2ffc3e1 PN |
382 | if (!CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) { |
383 | return FALSE; | |
384 | } | |
385 | $recognitionDate = CRM_Utils_Array::value('revenue_recognition_date', $params); | |
386 | if (!(!CRM_Utils_System::isNull($recognitionDate) | |
17d83f50 | 387 | || ($contributionID && isset($params['prevContribution']) |
388 | && !CRM_Utils_System::isNull($params['prevContribution']->revenue_recognition_date))) | |
b2ffc3e1 PN |
389 | ) { |
390 | return FALSE; | |
391 | } | |
392 | ||
b2ffc3e1 PN |
393 | $lineItems = CRM_Utils_Array::value('line_item', $params); |
394 | $financialTypeID = CRM_Utils_Array::value('financial_type_id', $params); | |
395 | if (!$financialTypeID) { | |
396 | $financialTypeID = $params['prevContribution']->financial_type_id; | |
397 | } | |
398 | if (($contributionID || !empty($params['price_set_id'])) && empty($lineItems)) { | |
399 | if (!$contributionID) { | |
ab6c306d | 400 | CRM_Price_BAO_PriceSet::processAmount($priceSetFields, |
b2ffc3e1 PN |
401 | $params, $items); |
402 | } | |
403 | else { | |
404 | $items = CRM_Price_BAO_LineItem::getLineItems($contributionID, 'contribution', TRUE, TRUE, TRUE); | |
405 | } | |
406 | if (!empty($items)) { | |
407 | $lineItems[] = $items; | |
408 | } | |
409 | } | |
410 | $deferredFinancialType = self::getDeferredFinancialType(); | |
96039749 | 411 | $isError = FALSE; |
b2ffc3e1 PN |
412 | if (!empty($lineItems)) { |
413 | foreach ($lineItems as $lineItem) { | |
414 | foreach ($lineItem as $items) { | |
415 | if (!array_key_exists($items['financial_type_id'], $deferredFinancialType)) { | |
96039749 | 416 | $isError = TRUE; |
b2ffc3e1 PN |
417 | } |
418 | } | |
419 | } | |
420 | } | |
421 | elseif (!array_key_exists($financialTypeID, $deferredFinancialType)) { | |
96039749 | 422 | $isError = TRUE; |
b2ffc3e1 | 423 | } |
96039749 PN |
424 | |
425 | if ($isError) { | |
cebff547 | 426 | $error = ts('Revenue Recognition Date cannot be processed unless there is a Deferred Revenue account setup for the Financial Type. Please remove Revenue Recognition Date, select a different Financial Type with a Deferred Revenue account setup for it, or setup a Deferred Revenue account for this Financial Type.'); |
96039749 PN |
427 | throw new CRM_Core_Exception($error); |
428 | } | |
429 | return $isError; | |
b2ffc3e1 PN |
430 | } |
431 | ||
fd633b30 PN |
432 | /** |
433 | * Retrieve all Deferred Financial Accounts. | |
434 | * | |
435 | * | |
436 | * @return array of Deferred Financial Account | |
437 | * | |
438 | */ | |
439 | public static function getAllDeferredFinancialAccount() { | |
fd633b30 | 440 | $financialAccount = array(); |
da345655 E |
441 | $result = civicrm_api3('EntityFinancialAccount', 'get', array( |
442 | 'sequential' => 1, | |
443 | 'return' => array("financial_account_id.id", "financial_account_id.name", "financial_account_id.accounting_code"), | |
444 | 'entity_table' => "civicrm_financial_type", | |
445 | 'account_relationship' => "Deferred Revenue Account is", | |
446 | )); | |
447 | if ($result['count'] > 0) { | |
448 | foreach ($result['values'] as $key => $value) { | |
449 | $financialAccount[$value['financial_account_id.id']] = $value['financial_account_id.name'] . ' (' . $value['financial_account_id.accounting_code'] . ')'; | |
450 | } | |
fd633b30 PN |
451 | } |
452 | return $financialAccount; | |
453 | } | |
454 | ||
16e4c0a3 PN |
455 | /** |
456 | * Get Organization Name associated with Financial Account. | |
457 | * | |
458 | * @param bool $checkPermissions | |
459 | * | |
460 | * @return array | |
461 | * | |
462 | */ | |
463 | public static function getOrganizationNames($checkPermissions = TRUE) { | |
464 | $result = civicrm_api3('FinancialAccount', 'get', array( | |
465 | 'return' => array("contact_id.organization_name", "contact_id"), | |
466 | 'contact_id.is_deleted' => 0, | |
467 | 'options' => array('limit' => 0), | |
468 | 'check_permissions' => $checkPermissions, | |
469 | )); | |
470 | $organizationNames = array(); | |
471 | foreach ($result['values'] as $values) { | |
472 | $organizationNames[$values['contact_id']] = $values['contact_id.organization_name']; | |
473 | } | |
474 | return $organizationNames; | |
475 | } | |
476 | ||
6a488035 | 477 | } |