Skip to content

Commit

Permalink
CRM-19585, Fixed tax calculation when multiple attribute are changed …
Browse files Browse the repository at this point in the history
…for contribution like Amount, FT, PI

----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585
  • Loading branch information
pradpnayak committed Jan 16, 2017
1 parent f47e577 commit 24ce181
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3265,9 +3265,13 @@ public static function recordFinancialAccounts(&$params, $financialTrxnValues =
}
self::updateFinancialAccounts($params, 'changeFinancialType');
$params['financial_account_id'] = $newFinancialAccount;
list($changeFTAmount, $ignoreChangeAmount) = self::calcluateFTChangeAmount($params, $trxnParams['total_amount']);
list($changeFTAmount, $ignoreChangeAmount, $taxAmounts) = self::calculateFTChangeAmount($params, $trxnParams['total_amount'], $totalAmount);
$params['total_amount'] = $params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $changeFTAmount;
self::updateFinancialAccounts($params);
if (isset($taxAmounts['new_tax_amount'])) {
$params['tax_amount'] = $taxAmounts['new_tax_amount'];
$params['prevContribution']->tax_amount = CRM_Utils_Array::value('previous_tax_amount', $taxAmounts);
}
$params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id'];
$updated = TRUE;
$params['deferred_financial_account_id'] = $newFinancialAccount;
Expand Down Expand Up @@ -3445,7 +3449,8 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
}
if ($context == 'changedAmount' || $context == 'changeFinancialType') {
$itemAmount = $params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $params['total_amount'] - $params['prevContribution']->total_amount;
if (isset($params['tax_amount'])) {

if (isset($params['prevContribution']->tax_amount) && $context != 'changeFinancialType') {
$itemAmount -= CRM_Utils_Array::value('tax_amount', $params, 0);
}
if (isset($params['tax_amount'])) {
Expand Down Expand Up @@ -3584,7 +3589,7 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
'previous_line_total' => CRM_Utils_Array::value('line_total', CRM_Utils_Array::value($fieldValues['id'], $previousLineItem)),
'item_amount' => $itemAmount,
);
$amount = self::calcluateFinancialItemAmount($params, $amountParams, $context);
$amount = self::calcluateFinancialItemAmount($params, $amountParams, $context, $fieldValues);
$itemParams = array(
'transaction_date' => $receiveDate,
'contact_id' => $params['prevContribution']->contact_id,
Expand Down Expand Up @@ -5339,12 +5344,16 @@ public static function recordAlwaysAccountsReceivable(&$trxnParams, $contributio
* @param array $amountParams
*
* @param string $context
* @param array $fieldValues
*
* @return float
*/
public static function calculateFinancialItemAmount($params, $amountParams, $context) {
public static function calculateFinancialItemAmount($params, $amountParams, $context, &$fieldValues) {
if (!empty($params['is_quick_config'])) {
$amount = $amountParams['item_amount'];
if (!empty($params['tax_amount']) && !CRM_Utils_System::isNull($params['tax_amount'])) {
$fieldValues['tax_amount'] = $params['tax_amount'];
}
if (!$amount) {
$amount = $params['total_amount'];
if ($context === NULL) {
Expand Down

0 comments on commit 24ce181

Please sign in to comment.