Skip to content
Snippets Groups Projects
Commit 8da4799e authored by Eileen McNaughton's avatar Eileen McNaughton
Browse files

Move the tested but crazy tax calc to the contribution api

parent fe619cf4
Branches
Tags
No related merge requests found
......@@ -192,7 +192,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
if (!isset($params['tax_amount']) && $setPrevContribution && (isset($params['total_amount']) ||
isset($params['financial_type_id']))) {
$params['tax_amount'] = $taxAmount;
$params['total_amount'] = $taxAmount + $lineTotal;
}
if (isset($params['tax_amount']) && empty($params['skipLineItem'])
&& !CRM_Utils_Money::equals($params['tax_amount'], $taxAmount, ($params['currency'] ?? Civi::settings()->get('defaultCurrency')))
......
......@@ -70,6 +70,18 @@ function civicrm_api3_contribution_create($params) {
throw new API_Exception($error['financial_type_id']);
}
}
if (!isset($params['tax_amount']) && empty($params['line_item'])
&& empty($params['skipLineItem'])
&& empty($params['id'])
) {
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
$taxRate = $taxRates[$params['financial_type_id']] ?? 0;
if ($taxRate) {
// Be afraid - historically if a contribution was tax then the passed in amount is EXCLUSIVE
$params['tax_amount'] = $params['total_amount'] * ($taxRate / 100);
$params['total_amount'] += $params['tax_amount'];
}
}
_civicrm_api3_contribution_create_legacy_support_45($params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment