-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ready for core team review] CRM-20677, used generalized function to retrieve financial account id #10463
[ready for core team review] CRM-20677, used generalized function to retrieve financial account id #10463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,12 +39,6 @@ public function __construct() { | |
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Financial account. | ||
* @var array | ||
*/ | ||
private static $financialAccount; | ||
|
||
/** | ||
* Fetch object based on array of properties. | ||
* | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pradpnayak this is what is causing the test to fail would there be a reason why there is 2 payment_instruments with the same option value? Maybe its a test problem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seamuslee001 you are right and I have fixed that test failure. Thanks for bringing that glitch into notice :) |
||
'return' => array("id"), | ||
'value' => $paymentInstrumentValue, | ||
'option_group_id' => "payment_instrument", | ||
)); | ||
$financialAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount( | ||
$paymentInstrument['id'], | ||
NULL, | ||
'civicrm_option_value' | ||
); | ||
return $financialAccountId; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small note -- this was technically a change in the function signature (dropping the
NULL
default). Not a huge deal because it's an internal function, but there was a stale reference insql/GenerateData.php
(which is used forregen.sh
) where it calls:To work around it, I grepped for
getInstrumentFinancialAccount
and saw a test written with the hard-coded valuegetInstrumentFinancialAccount(4)
. Not sure if it's the right thing, but using4
does seem to getregen.sh
running.