}
// 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';
$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;
}
// 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);
'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);
);
}
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',
$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']);
* @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];
}
/**
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.
*
}
/**
- * Check method getFinancialAccount()
+ * Check method retrieve()
*/
public function testRetrieve() {
list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount(
$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()
*/