Skip to content

Commit

Permalink
CRM-20677, updated getInstrumentFinancialAccount() to use api
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-20677: Use generalised function to retrieve financial account
  https://issues.civicrm.org/jira/browse/CRM-20677
  • Loading branch information
pradpnayak committed Jun 3, 2017
1 parent d71572c commit d9d02bb
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions CRM/Financial/BAO/FinancialTypeAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public function __construct() {
parent::__construct();
}

/**
* Financial account.
* @var array
*/
private static $financialAccount;

/**
* Fetch object based on array of properties.
*
Expand Down Expand Up @@ -157,30 +151,20 @@ public static function del($financialTypeAccountId, $accountId = NULL) {
* @param int $paymentInstrumentValue
* Payment instrument value.
*
* @return array|null|string
* @return null|int
*/
public static function getInstrumentFinancialAccount($paymentInstrumentValue = NULL) {
if (!self::$financialAccount) {
$query = "SELECT ceft.financial_account_id, cov.value
FROM civicrm_entity_financial_account ceft
INNER JOIN civicrm_option_value cov ON cov.id = ceft.entity_id AND ceft.entity_table = 'civicrm_option_value'
INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id
WHERE cog.name = 'payment_instrument' ";

if ($paymentInstrumentValue) {
$query .= " AND cov.value = '{$paymentInstrumentValue}' ";
return CRM_Core_DAO::singleValueQuery($query);
}
else {
$result = CRM_Core_DAO::executeQuery($query);
while ($result->fetch()) {
self::$financialAccount[$result->value] = $result->financial_account_id;
}
return self::$financialAccount;
}
}

return $paymentInstrumentValue ? self::$financialAccount[$paymentInstrumentValue] : self::$financialAccount;
public static function getInstrumentFinancialAccount($paymentInstrumentValue) {
$paymentInstrument = civicrm_api3('OptionValue', 'getsingle', array(
'return' => array("id"),
'value' => $paymentInstrumentValue,
'option_group_id' => "payment_instrument",
));
$financialAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount(
$paymentInstrument['id'],
NULL,
'civicrm_option_value'
);
return $financialAccountId;
}

/**
Expand Down

0 comments on commit d9d02bb

Please sign in to comment.