From 7d45c236b164e2c8fdc9447acfa786be8bf3cf09 Mon Sep 17 00:00:00 2001 From: Mattias Michaux Date: Mon, 2 Nov 2015 15:34:31 +0100 Subject: [PATCH] Fixed CRM_Core_PseudoConstant::accountOptionValues hardcoded values, breaking multilingual installs. --- CRM/Core/BAO/FinancialTrxn.php | 2 +- CRM/Financial/BAO/FinancialAccount.php | 3 +-- CRM/Financial/Form/FinancialAccount.php | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index 282f382790..1c7ba25e60 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -330,7 +330,7 @@ WHERE ceft.entity_id = %1"; if (!empty($params['cost'])) { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $financialAccountType = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id']); - $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND label IN ('Premiums Inventory Account is', 'Cost of Sales Account is')"); + $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name IN ('Premiums Inventory Account is', 'Cost of Sales Account is')"); $toFinancialAccount = !empty($params['isDeleted']) ? 'Premiums Inventory Account is' : 'Cost of Sales Account is'; $fromFinancialAccount = !empty($params['isDeleted']) ? 'Cost of Sales Account is' : 'Premiums Inventory Account is'; $accountRelationship = array_flip($accountRelationship); diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 9d866799ca..2a5dd5a73d 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -188,8 +188,7 @@ WHERE cft.id = %1 */ public static function getARAccounts($financialAccountId, $financialAccountTypeId = NULL, $accountTypeCode = 'ar') { if (!$financialAccountTypeId) { - $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); - $financialAccountTypeId = array_search('Asset', $financialAccountType); + $financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' ")); } $query = "SELECT count(id) FROM civicrm_financial_account WHERE financial_account_type_id = %1 AND LCASE(account_type_code) = %2 AND id != %3 AND is_active = 1;"; diff --git a/CRM/Financial/Form/FinancialAccount.php b/CRM/Financial/Form/FinancialAccount.php index 4fa43aa970..cdda52dc92 100644 --- a/CRM/Financial/Form/FinancialAccount.php +++ b/CRM/Financial/Form/FinancialAccount.php @@ -55,10 +55,10 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { 'id' => $this->_id, ); $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, CRM_Core_DAO::$_nullArray); - $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); - if ($financialAccount->financial_account_type_id == array_search('Asset', $financialAccountType) + $financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' ")); + if ($financialAccount->financial_account_type_id == $financialAccountTypeId && strtolower($financialAccount->account_type_code) == 'ar' - && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, array_search('Asset', $financialAccountType)) + && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, $financialAccountTypeId) ) { $this->_isARFlag = TRUE; if ($this->_action & CRM_Core_Action::DELETE) { -- 2.25.1