Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-19908

Fundamental Fixes for Tax Math Calculations.

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code
    • Verified?:
      No

      Description

      This is highly critical - as currently both 4.6 and 4.7 calculate incorrect Sales Tax Amounts - these are reported and filed w/ governments.

      When digging into these Tax Math issues for one of my clients (a National Engineering Association; they invoice lots; with/without pricesets/many lineItems, financial types, and sales tax rates) - I've discovered some fundamentally wrong math in two places in CiviCRM Core. I think this explains why there are a number of issues in JiRA re: Tax Math that get fixed/break again/get refixed/break again - etc.

      So I'm proposing to fix these fundamentally wrong math issues first - and then all critical/major Tax Math issues in JIRA should be re-visited. I'm not expecting this to fix every Tax Math issue out there - but firmly believe these fundamentals must be fixed first.

      The two fundamentally wrong operations are:

      • do math - do rounding - do math again
      • calculate tax rate using tax amount that was previously calculated using tax rate

      After really digging through these sections carefully over the past couple of weeks - I've been able to put together a 'negative' PR (+11 -27 lines) that will fix these two fundamentally wrong math issues for 4.6 [and I'll do the same for 4.7].

      Purpose of these edits - three fold: to make the minimal/safe edits required to:
      1) to make the sales Tax Amounts accurate [by moving premature rounding from the basic Utils function to -after- quantity has been taken into account] - right now they are not - and that's highly critical to organizations that are collecting GST.
      2) to remove/replace the backwards calculation of Tax Rate [do not calculate it based on the Tax Amount that used Tax Rate in the first place]
      3) to round close to output/display - and show three decimals (if needed); one of our provinces in Canada e.g. 9.975% - previously everything was always rounded to two decimals

      Note: I've not added a PHP Unit test for 1) to add a test would require edits to CiviCRM Core (contribution.php and confirm.php) itself [right now you can't test line_items w/ quantity within the TEST framework] - that in itself it not without risk. I strongly believe we need to get the fundamentals right first.

      To illustrate

      BEFORE: note Tax Rate is 5.01% and Tax Amount on that lineItem is $15.30 - both are incorrect.

      AFTER: note Tax Rate is 5% and Tax Amount on that lineItem is $15.26 - both are correct.

        Attachments

        1. 5.01taxb.png
          21 kB
          KarinG
        2. 5tax.png
          10 kB
          KarinG

          Issue Links

            Activity

              People

              • Assignee:
                KarinG KarinG
                Reporter:
                KarinG KarinG
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: