Skip to content

Commit

Permalink
CRM-19585, added function to Calculate amounts when Financial type fo…
Browse files Browse the repository at this point in the history
…r contribution is changed.

----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585
  • Loading branch information
pradpnayak committed Jan 16, 2017
1 parent 4a4051a commit b09cbff
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5457,4 +5457,37 @@ public static function createProportionalFinancialEntries($entityParams, $lineIt
}
}

/**
* Calculate amounts when Financial type for contribution is changed.
*
* @param array $params
* contribution params
* @param float $trxnAmount
* financial trxn total amount
* @param float $totalAmount
* Contribution total amount
*
* @return array
*/
public static function calculateFTChangeAmount(&$params, $trxnAmount, &$totalAmount) {
$changeFTAmount = $trxnAmount;
$ignoreChangeAmount = FALSE;
$taxAmounts = array(
'new_tax_amount' => NULL,
);
if (isset($params['prevContribution']->total_amount) || isset($params['tax_amount'])) {
$taxAmount = CRM_Utils_Array::value('tax_amount', $params, 0);
$changesinTaxAmount = $totalAmount - $params['prevContribution']->total_amount + $params['prevContribution']->tax_amount - $taxAmount;
$taxAmounts['new_tax_amount'] = $taxAmount;
if ($changesinTaxAmount == 0) {
$ignoreChangeAmount = TRUE;
$changeFTAmount = $totalAmount;
}
elseif ($taxAmount) {
self::calculateTaxForChangeInFinancialType($params, $totalAmount, $taxAmounts, $changeFTAmount);
}
}
return array($changeFTAmount, $ignoreChangeAmount, $taxAmounts);
}

}

0 comments on commit b09cbff

Please sign in to comment.