From fe619cf4b6bc9f8f2102f9b4817aabd06d4c05a4 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 22 Aug 2021 12:16:12 +1200 Subject: [PATCH] Fix line item calculation from exclusive to inclusive This was added https://github.com/civicrm/civicrm-core/commit/e967ce8fe2b58b94e2163dde395542e55599da13#diff-a16d4d7449cf5f3a0616d1d282a32f27ab6d3f7d2726d076c02ad1d4d655af41R512 but incorrectly assumes the totalAmount is exclusive at this point - but it is inclusive --- CRM/Price/BAO/LineItem.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 6187654238..2591f632e8 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -516,17 +516,20 @@ WHERE li.contribution_id = %1"; } $financialType = $values['financial_type_id']; } + $taxRates = CRM_Core_PseudoConstant::getTaxRates(); + $taxRate = $taxRates[$financialType] ?? 0; + $taxAmount = ($taxRate / 100) * $totalAmount / (1 + ($taxRate / 100)); $lineItem = [ 'price_field_id' => $values['priceFieldID'], 'price_field_value_id' => $values['priceFieldValueID'], 'label' => $values['label'], 'qty' => 1, - 'unit_price' => $totalAmount, - 'line_total' => $totalAmount, + 'unit_price' => $totalAmount - $taxAmount, + 'line_total' => $totalAmount - $taxAmount, 'financial_type_id' => $financialType, 'membership_type_id' => $values['membership_type_id'], + 'tax_amount' => $taxAmount, ]; - $lineItem['tax_amount'] = self::getTaxAmountForLineItem($lineItem); $params['line_item'][$values['setID']][$values['priceFieldID']] = $lineItem; break; } -- 2.25.1