--CRM-16189, generalized code, removed hardcoded values, used function
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 15 Jun 2016 20:17:28 +0000 (01:47 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Sun, 26 Jun 2016 23:02:47 +0000 (04:32 +0530)
CRM/Financial/Form/FinancialTypeAccount.php
CRM/Financial/Page/AJAX.php

index 281193f586b2615dcc41545ecf5a66cdebef2986..d8825eb61b028d1aca4b22ac4e3015deaa298e9a 100644 (file)
@@ -141,12 +141,13 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form {
       // hidden field to catch the field id in profile
       $this->add('hidden', 'account_type_id', $this->_id);
     }
-    $AccountTypeRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
+    $params['orderColumn'] = 'label';
+    $AccountTypeRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params); 
     if (!empty($AccountTypeRelationship)) {
       $element = $this->add('select',
         'account_relationship',
         ts('Financial Account Relationship'),
-        array('select' => '- select -') + $AccountTypeRelationship,
+        array('select' => '- Select Financial Account Relationship -') + $AccountTypeRelationship,
         TRUE
       );
     }
@@ -157,16 +158,7 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form {
 
     if ($this->_action == CRM_Core_Action::ADD) {
       if (!empty($this->_submitValues['account_relationship']) || !empty($this->_submitValues['financial_account_id'])) {
-        $financialAccountType = array(
-          '5' => 5, //expense
-          '3' => 1, //AR relation
-          '1' => 3, //revenue
-          '6' => 1, //Asset
-          '7' => 4, //cost of sales
-          '8' => 1, //premium inventory
-          '9' => 3, //discount account is,
-        );
-
+        $financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
         $financialAccountType = CRM_Utils_Array::value($this->_submitValues['account_relationship'], $financialAccountType);
         $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
 
@@ -179,16 +171,7 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form {
       }
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
-      $financialAccountType = array(
-        '5' => 5, //expense
-        '3' => 1, //AR relation
-        '1' => 3, //revenue
-        '6' => 1, //Asset
-        '7' => 4, //cost of sales
-        '8' => 1, //premium inventory
-        '9' => 3, //discount account is,
-      );
-
+      $financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
       $financialAccountType = $financialAccountType[$this->_defaultValues['account_relationship']];
       $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
 
index ac133abba897f18531322f7191879a5df15390fe..49ef45a0585b0bb08a05e0071b872ff7d4a0ff72 100644 (file)
@@ -53,16 +53,7 @@ class CRM_Financial_Page_AJAX {
       $result = CRM_Contribute_PseudoConstant::financialAccount();
     }
     else {
-      $financialAccountType = array(
-        '5' => 5, // expense
-        '3' => 1, // AR relation
-        '1' => 3, // revenue
-        '6' => 1, // asset
-        '7' => 4, // cost of sales
-        '8' => 1, // premium inventory
-        '9' => 3, // discount account is
-        '10' => 2, // sales tax liability
-      );
+      $financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
       $financialAccountType = CRM_Utils_Array::value($_GET['_value'], $financialAccountType);
       $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
       if ($financialAccountType) {
@@ -101,21 +92,14 @@ class CRM_Financial_Page_AJAX {
       CRM_Utils_System::civiExit();
     }
 
-    if ($_GET['_value'] == 'select') {
-      $result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
-    }
-    else {
-      $financialAccountType = array(
-        '5' => array(5), //expense
-        '1' => array(3, 6, 8), //Asset
-        '3' => array(1, 9), //revenue
-        '4' => array(7), //cost of sales
-      );
+    if ($_GET['_value'] != 'select') {
+      $financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations(TRUE);
       $financialAccountId = CRM_Utils_Request::retrieve('_value', 'Positive', CRM_Core_DAO::$_nullObject);
       $financialAccountTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountId, 'financial_account_type_id');
-      $result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
     }
-
+    $params['orderColumn'] = 'label';
+    $result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
     $elements = array(
       array(
         'name' => ts('- Select Financial Account Relationship -'),