Fixed CRM_Core_PseudoConstant::accountOptionValues hardcoded values, breaking multili...
authorMattias Michaux <mattias.michaux@gmail.com>
Mon, 2 Nov 2015 14:34:31 +0000 (15:34 +0100)
committerMattias Michaux <mattias.michaux@gmail.com>
Mon, 2 Nov 2015 14:34:31 +0000 (15:34 +0100)
CRM/Core/BAO/FinancialTrxn.php
CRM/Financial/BAO/FinancialAccount.php
CRM/Financial/Form/FinancialAccount.php

index 282f382790f5a0bc371f7843ebad59ec8d6bdc71..1c7ba25e602c38c46cd81e2d71b3c4137c9407f8 100644 (file)
@@ -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);
index 9d866799ca58a84eaf4e93420efd1805eb2a2824..2a5dd5a73d873ac84fc42e8a264e170257f60350 100644 (file)
@@ -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;";
index 4fa43aa970605dae33650a989f1e14d44dba2899..cdda52dc9241fa276c22f9387710f087ac238f66 100644 (file)
@@ -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) {