Used generalized function, removed unused function
authorPradeep Nayak <pradpnayak@gmail.com>
Fri, 7 Apr 2017 22:34:27 +0000 (04:04 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 17 Apr 2017 22:00:38 +0000 (03:30 +0530)
CRM/Admin/Form/Options.php
CRM/Admin/Form/PaymentProcessor.php
CRM/Admin/Page/Options.php
CRM/Admin/Page/PaymentProcessor.php
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/PseudoConstant.php
CRM/Financial/BAO/FinancialTypeAccount.php
tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php

index 670a21688a3c503f6ceb2d010b4e7c60b2c58519..7dc2560376b1916639b5524e0695394cc9af6258 100644 (file)
@@ -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';
index e444eea37a23fa0b34bf384ac44a6782d5ee8dde..64fd697ea88a225d50f71076085d884fbfa558c7 100644 (file)
@@ -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;
   }
index 71d826feb05950dfc698fb65c47f98a44ce7bafd..1a5fdb8671ef5c7771de63f9864aadd7cff64fc4 100644 (file)
@@ -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);
index 40e5683a54470a5282f3fb0f6c0a72518101510e..63c9e1917607fe96b04aee7a428b3db6f1bbdc6e 100644 (file)
@@ -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);
index a196c7c53bcbd09c53bf147e6a0d209e1e371b31..4cf3637cecdf55d56d7668494d33970ef42a2053 100644 (file)
@@ -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']);
index f71c2905d75b9dc241bb62706057e9bf7f1a9bc4..1cc6cd9859b1a1825844695164305d717aac32bb 100644 (file)
@@ -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];
   }
 
   /**
index a023d233cd1966dc549aafa23b0e736db9dba9c5..92b8aa8d6199e39f2ca84770126e0e5c122222e9 100644 (file)
@@ -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.
    *
index 099aff6789586bb4e73841bcce498cf0db9901f8..88172853d05d21f4af7d1cd58d3df536c20261cb 100644 (file)
@@ -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()
    */