From 48a29690958cf8d5e5bca800ffbe9e4e6eea74d9 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Thu, 16 Jun 2016 01:47:28 +0530 Subject: [PATCH] --CRM-16189, generalized code, removed hardcoded values, used function --- CRM/Financial/Form/FinancialTypeAccount.php | 27 ++++---------------- CRM/Financial/Page/AJAX.php | 28 +++++---------------- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/CRM/Financial/Form/FinancialTypeAccount.php b/CRM/Financial/Form/FinancialTypeAccount.php index 281193f586..d8825eb61b 100644 --- a/CRM/Financial/Form/FinancialTypeAccount.php +++ b/CRM/Financial/Form/FinancialTypeAccount.php @@ -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); diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index ac133abba8..49ef45a058 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -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 -'), -- 2.25.1