Skip to content

Commit

Permalink
CRM-19585, fixed code for entries in civicrm_financial_item when cont…
Browse files Browse the repository at this point in the history
…ribution amount is changed having tax

----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585
  • Loading branch information
pradpnayak committed Nov 1, 2016
1 parent f53a29b commit 17443f8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3447,7 +3447,8 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
return;
}
if ($context == 'changedAmount' || $context == 'changeFinancialType') {
$itemAmount = $params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $params['total_amount'] - $params['prevContribution']->total_amount;
$params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $params['total_amount'] - $params['prevContribution']->total_amount;
$itemAmount = $params['total_amount'] - $params['prevContribution']->total_amount - $params['tax_amount'] + $params['prevContribution']->tax_amount;
}
if ($context == 'changedStatus') {
//get all the statuses
Expand Down Expand Up @@ -3550,6 +3551,7 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
}
}
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$previousLineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['id']);
$params['entity_id'] = $trxn->id;
if ($context != 'changePaymentInstrument') {
$itemParams['entity_table'] = 'civicrm_line_item';
Expand Down Expand Up @@ -3579,7 +3581,12 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
}
}
else {
$amount = $diff * $fieldValues['line_total'];
if ($context == 'changedAmount') {
$itemParams['amount'] = $diff * ($fieldValues['line_total'] - $previousLineItem[$fieldValues['id']]['line_total']);
}
else {
$amount = $diff * $fieldValues['line_total'];
}
}

$itemParams = array(
Expand All @@ -3600,7 +3607,12 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
if ($fieldValues['tax_amount']) {
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$itemParams['amount'] = $diff * $fieldValues['tax_amount'];
if ($context == 'changedAmount') {
$itemParams['amount'] = $diff * ($fieldValues['tax_amount'] - $previousLineItem[$fieldValues['id']]['tax_amount']);
}
else {
$itemParams['amount'] = $diff * $fieldValues['tax_amount'];
}
$itemParams['description'] = $taxTerm;
if ($fieldValues['financial_type_id']) {
$itemParams['financial_account_id'] = self::getFinancialAccountId($fieldValues['financial_type_id']);
Expand Down

0 comments on commit 17443f8

Please sign in to comment.