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

CRM-20677. more changes

----------------------------------------
* CRM-20677: Use generalised function to retrieve financial account
  https://issues.civicrm.org/jira/browse/CRM-20677
  • Loading branch information
pradpnayak authored and monishdeb committed Jul 4, 2017
1 parent 77aec2e commit 81a7f7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
10 changes: 8 additions & 2 deletions CRM/Event/BAO/Participant.php
Expand Up @@ -1973,7 +1973,10 @@ public static function changeFeeSelections($params, $participantId, $contributio
$updateFinancialItemInfoValues['tax']['amount'] = -($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']);
$updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
if ($updateFinancialItemInfoValues['financial_type_id']) {
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateFinancialItemInfoValues['financial_type_id']);
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount(
$updateFinancialItemInfoValues['financial_type_id'],
'Sales Tax Account is'
);
}
}
// INSERT negative financial_items for tax amount
Expand All @@ -1989,7 +1992,10 @@ public static function changeFeeSelections($params, $participantId, $contributio
$updateFinancialItemInfoValues['tax']['amount'] = $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'];
$updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
if ($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']) {
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']);
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount(
$updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id'],
'Sales Tax Account is'
);
}
}
$financialItemsArray[] = $updateFinancialItemInfoValues;
Expand Down
42 changes: 13 additions & 29 deletions CRM/Financial/BAO/FinancialTypeAccount.php
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 81a7f7b

Please sign in to comment.