Skip to content

Commit

Permalink
Merge pull request #15489 from eileenmcnaughton/credit_dep
Browse files Browse the repository at this point in the history
[REF] Replace deprecated function call with a more readable alternative
  • Loading branch information
mattwire authored Oct 13, 2019
2 parents 5a30440 + 07376a0 commit 620bacc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 1 addition & 4 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3784,10 +3784,7 @@ public static function updateFinancialAccounts(&$params, $context = NULL) {
$itemParams['amount'] = self::getMultiplier($params['contribution']->contribution_status_id, $context) * $taxAmount;
$itemParams['description'] = $taxTerm;
if ($lineItemDetails['financial_type_id']) {
$itemParams['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount(
$lineItemDetails['financial_type_id'],
'Sales Tax Account is'
);
$itemParams['financial_account_id'] = CRM_Financial_BAO_FinancialAccount::getSalesTaxFinancialAccount($lineItemDetails['financial_type_id']);
}
CRM_Financial_BAO_FinancialItem::create($itemParams, NULL, $trxnIds);
}
Expand Down
13 changes: 13 additions & 0 deletions CRM/Financial/BAO/FinancialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ public static function getFinancialAccountForFinancialTypeByRelationship($financ
return Civi::$statics[__CLASS__]['entity_financial_account'][$financialTypeID][$relationTypeId];
}

/**
* Get the sales tax financial account id for the financial type id.
*
* This is a helper wrapper to make the function name more readable.
*
* @param int $financialAccountID
*
* @return int
*/
public static function getSalesTaxFinancialAccount($financialAccountID) {
return self::getFinancialAccountForFinancialTypeByRelationship($financialAccountID, 'Sales Tax Account is');
}

/**
* Get Financial Account type relations.
*
Expand Down
1 change: 1 addition & 0 deletions CRM/Financial/Form/FinancialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public static function formRule($values, $files, $self) {
}
if ($self->_action & CRM_Core_Action::UPDATE) {
if (!(isset($values['is_tax']))) {
// @todo replace with call to CRM_Financial_BAO_FinancialAccount getSalesTaxFinancialAccount
$relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
$params = [
'financial_account_id' => $self->_id,
Expand Down
1 change: 1 addition & 0 deletions CRM/Financial/Form/FinancialTypeAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public static function formRule($values, $files, $self) {
];
$defaults = [];
if ($self->_action == CRM_Core_Action::ADD) {
// @todo replace with call to CRM_Financial_BAO_FinancialAccount getSalesTaxFinancialAccount
$relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
$isTax = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $values['financial_account_id'], 'is_tax');
if ($values['account_relationship'] == $relationshipId) {
Expand Down

0 comments on commit 620bacc

Please sign in to comment.