diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index e74a29f2f0c2..d9738cf359d5 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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); + } + }