From e66512af91ce90e3c46539470cee6fc189d31cb6 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 15 Jun 2016 16:19:00 +0530 Subject: [PATCH] CRM-16189, added code to get financial account on the basis of account relationship ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- CRM/Financial/BAO/FinancialAccount.php | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 24516f1330..d30a72903a 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -246,4 +246,43 @@ WHERE cft.id = %1 return Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId]; } + /** + * Get Financial Account type relations + * + * @param $flip bool + * + * @return array + * + */ + public static function getfinancialAccountRelations($flip = FALSE, $id = NULL) { + $params = array('labelColumn' => 'name'); + $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params); + $accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params); + $Links = array( + 'Expense Account is' => 'Expenses', + 'Accounts Receivable Account is' => 'Asset', + 'Income Account is' => 'Revenue', + 'Asset Account is' => 'Asset', + 'Cost of Sales Account is' => 'Cost of Sales', + 'Premiums Inventory Account is' => 'Asset', + 'Discounts Account is' => 'Revenue', + 'Sales Tax Account is' => 'Liability', + 'Deferred Revenue Account is' => 'Liability', + ); + if (!$flip) { + foreach ($Links as $accountRelation => $accountType) { + $financialAccountLinks[array_search($accountRelation, $accountRelationships)] = array_search($accountType, $financialAccountType); + } + } + else { + foreach ($Links as $accountRelation => $accountType) { + $financialAccountLinks[array_search($accountType, $financialAccountType)][] = array_search($accountRelation, $accountRelationships); + } + } + if ($id) { + return CRM_Utils_Array::value($id, $financialAccountLinks); + } + return $financialAccountLinks; + } + } -- 2.25.1