Fix line item calculation from exclusive to inclusive
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 22 Aug 2021 00:16:12 +0000 (12:16 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 24 Aug 2021 04:24:10 +0000 (16:24 +1200)
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

index 618765423840dc42a909fd4183371dc08e418f27..2591f632e82ff0dee388415a8903b95ce3b7825a 100644 (file)
@@ -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;
       }