Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Critical
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.6.24, 4.7.15
-
Component/s: CiviContribute
-
Labels:
-
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
Issue Links
- is blocked by
-
CRM-16656 [only confirmed for 4.6] Total tax amount on invoice PDF should not depend on calculation producing incorrect results.
- Done/Fixed
- links to