From 74afdc4091830215f2b6e9a19af8f894af860ccd Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sat, 8 Apr 2017 04:04:27 +0530 Subject: [PATCH] Used generalized function, removed unused function --- CRM/Admin/Form/Options.php | 2 +- CRM/Admin/Form/PaymentProcessor.php | 2 +- CRM/Admin/Page/Options.php | 2 +- CRM/Admin/Page/PaymentProcessor.php | 2 +- CRM/Contribute/BAO/Contribution.php | 4 +-- CRM/Contribute/PseudoConstant.php | 16 +++++++---- CRM/Financial/BAO/FinancialTypeAccount.php | 28 ------------------- .../BAO/FinancialTypeAccountTest.php | 25 +---------------- 8 files changed, 17 insertions(+), 64 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index 670a21688a..7dc2560376 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -132,7 +132,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { } // CRM-11516 if ($this->_gName == 'payment_instrument' && $this->_id) { - $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($this->_id, 'civicrm_option_value', 'financial_account_id'); + $defaults['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($this->_id, NULL, 'civicrm_option_value'); } if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'color')) { $defaults['color'] = '#ffffff'; diff --git a/CRM/Admin/Form/PaymentProcessor.php b/CRM/Admin/Form/PaymentProcessor.php index e444eea37a..64fd697ea8 100644 --- a/CRM/Admin/Form/PaymentProcessor.php +++ b/CRM/Admin/Form/PaymentProcessor.php @@ -359,7 +359,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { $defaults[$testName] = $testDAO->{$field['name']}; } } - $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor', 'financial_account_id'); + $defaults['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($dao->id, NULL, 'civicrm_payment_processor'); return $defaults; } diff --git a/CRM/Admin/Page/Options.php b/CRM/Admin/Page/Options.php index 71d826feb0..1a5fdb8671 100644 --- a/CRM/Admin/Page/Options.php +++ b/CRM/Admin/Page/Options.php @@ -245,7 +245,7 @@ class CRM_Admin_Page_Options extends CRM_Core_Page_Basic { // retrieve financial account name for the payment method page if ($gName = "payment_instrument") { foreach ($optionValue as $key => $option) { - $optionValue[$key]['financial_account'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($key, 'civicrm_option_value'); + $optionValue[$key]['financial_account'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($key, NULL, 'civicrm_option_value', 'financial_account_id.name'); } } $this->assign('rows', $optionValue); diff --git a/CRM/Admin/Page/PaymentProcessor.php b/CRM/Admin/Page/PaymentProcessor.php index 40e5683a54..63c9e19176 100644 --- a/CRM/Admin/Page/PaymentProcessor.php +++ b/CRM/Admin/Page/PaymentProcessor.php @@ -156,7 +156,7 @@ class CRM_Admin_Page_PaymentProcessor extends CRM_Core_Page_Basic { 'PaymentProcessor', $dao->id ); - $paymentProcessor[$dao->id]['financialAccount'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor'); + $paymentProcessor[$dao->id]['financialAccount'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($dao->id, NULL, 'civicrm_payment_processor', 'financial_account_id.name'); } $this->assign('rows', $paymentProcessor); diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index a196c7c53b..4cf3637cec 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3167,7 +3167,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac ); } elseif (!empty($params['payment_processor'])) { - $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id'); + $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($params['payment_processor'], NULL, 'civicrm_payment_processor'); $params['payment_instrument_id'] = civicrm_api3('PaymentProcessor', 'getvalue', array( 'id' => $params['payment_processor'], 'return' => 'payment_instrument_id', @@ -4856,7 +4856,7 @@ LIMIT 1;"; $balanceTrxnParams['to_financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['financial_type_id'], 'Accounts Receivable Account is'); } elseif (!empty($params['payment_processor'])) { - $balanceTrxnParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($contribution['payment_processor'], 'civicrm_payment_processor', 'financial_account_id'); + $balanceTrxnParams['to_financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['payment_processor'], NULL, 'civicrm_payment_processor'); } elseif (!empty($params['payment_instrument_id'])) { $balanceTrxnParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contribution['payment_instrument_id']); diff --git a/CRM/Contribute/PseudoConstant.php b/CRM/Contribute/PseudoConstant.php index f71c2905d7..1cc6cd9859 100644 --- a/CRM/Contribute/PseudoConstant.php +++ b/CRM/Contribute/PseudoConstant.php @@ -378,19 +378,23 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant { * @param int $entityId * @param string $accountRelationType * @param string $entityTable + * @param string $returnField * @return int */ - public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type') { - $result = civicrm_api3('EntityFinancialAccount', 'get', array( - 'return' => array("financial_account_id"), - 'account_relationship.name' => $accountRelationType, + public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type', $returnField = 'financial_account_id') { + $params = array( + 'return' => array($returnField), 'entity_table' => $entityTable, 'entity_id' => $entityId, - )); + ); + if ($accountRelationType) { + $params['account_relationship.name'] = $accountRelationType; + } + $result = civicrm_api3('EntityFinancialAccount', 'get', $params); if (!$result['count']) { return NULL; } - return $result['values'][$result['id']]['financial_account_id']; + return $result['values'][$result['id']][$returnField]; } /** diff --git a/CRM/Financial/BAO/FinancialTypeAccount.php b/CRM/Financial/BAO/FinancialTypeAccount.php index a023d233cd..92b8aa8d61 100644 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@ -151,34 +151,6 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete the account of type: %1.', array(1 => $relationValues[$financialType->account_relationship]))); } - /** - * Get Financial Account Name. - * - * @param int $entityId - * - * @param string $entityTable - * - * @param string $columnName - * Column to fetch. - * - * @return null|string - */ - public static function getFinancialAccount($entityId, $entityTable, $columnName = 'name') { - $join = $columnName == 'name' ? 'LEFT JOIN civicrm_financial_account ON civicrm_entity_financial_account.financial_account_id = civicrm_financial_account.id' : NULL; - $query = " -SELECT {$columnName} -FROM civicrm_entity_financial_account -{$join} -WHERE entity_table = %1 -AND entity_id = %2"; - - $params = array( - 1 => array($entityTable, 'String'), - 2 => array($entityId, 'Integer'), - ); - return CRM_Core_DAO::singleValueQuery($query, $params); - } - /** * Financial Account for payment instrument. * diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php index 099aff6789..88172853d0 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php @@ -70,7 +70,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { } /** - * Check method getFinancialAccount() + * Check method retrieve() */ public function testRetrieve() { list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount( @@ -91,29 +91,6 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $this->assertEquals($financialAccountType['financial_account_id'], $financialAccount->id, 'Verify Financial Account Id.'); } - /** - * Check method getFinancialAccount() - */ - public function testGetFinancialAccount() { - list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount( - 'Asset' - ); - $params = array( - 'financial_account_id' => $financialAccount->id, - 'payment_processor_type_id' => 1, - 'domain_id' => 1, - 'billing_mode' => 1, - 'name' => 'paymentProcessor', - ); - $processor = CRM_Financial_BAO_PaymentProcessor::create($params); - - $account = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount( - $processor->id, - 'civicrm_payment_processor' - ); - $this->assertEquals($account, $financialAccount->name, 'Verify Financial Account Name'); - } - /** * Check method getInstrumentFinancialAccount() */ -- 2.25.1