I have an invoice with a total of 0.28, a first tax of 5% and second tax of 7.5% applied on the total plus the 5%. Generally, my clients' accountants expect this:
- Subtotal: 0.28
- Tax 1: 0.01
- Tax 2: 0.02
- Total: 0.31
In the above example, the total is the sum of the subtotal and the rounded tax amounts (.28+.01+.02)
Storm uses the sum of the unrounded amounts (.28+0.014+0.02205) and then rounds the total (in this case, 0.31605 is rounded to 0.32). (see first enclosed image)
It might be a good idea to give users the option of calculating this differently (see the second enclosed image). This has a few implications:
- To my knowledge, all currencies have a 2 decimal point cutoff point, but perhaps this shouldn't be hard-coded (the storm attribute system could be used to associate different currencies to different decimal cutoff points, with 2 being the default)
- Because storm invoice shows the tax amounts for each line of the invoice, the totals and tax amounts per line will be approximative: the difference between approximate vs. real values should be made clear, as in the second enclosed image. (one might suggest that we stop calculating taxes and totals per line, but I kind of like the idea)
It should be noted that in Quebec where I do business, most accounts have a policy of letting slide an inconsistency of a few cents, but it has suggested to me that using rounded values would seem more in line with generally accepted accounted standards.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 686362-13-storm-rounding.diff | 48.08 KB | alberto56 |
| #3 | 686362-3-rounding.diff | 13.7 KB | alberto56 |
| Screen shot 2010-01-15 at 9.15.03 PM.png | 48.5 KB | alberto56 | |
| Screen shot 2010-01-15 at 9.10.03 PM.png | 49.85 KB | alberto56 |
Comments
Comment #1
alberto56 commentedOK, it was western-centric of me to assume that all currencies have a two decimal point cutoff point. The rupee and yen seem to work differently. Here are some random links (ok, maybe I am getting too much into this):
- an analogous bug report for another software product
- Some european rounding rules
- Some yen rounding rules
- Some rupee rounding rules
(By the way, I would be curious to hear from anyone in India, Sri Lanka, Japan or other countries which use diverse rounding systems.)
Perhaps we could introduce the concept of a 'currency pack' which defines some callback functions. Third-party modules could then define these currency packs as needed via hooks.
For example, when it comes time to calculate totals on the invoice, in line with the attached images in the issue description, we could do something like:
now, it will be quite easy to create a patch, or for a third party module to do something like:
Anyhow, your comments are welcome.
Albert.
Comment #2
Magnity commentedTo keep it simple, would a setting "Round currency calculations to XX decimals" or something similar work?
So if "unlimited" were selected, it could work as is. If 2, as you suggest, etc.
Comment #3
alberto56 commentedHi, after pondering this, I don't think a simple setting would work, because there are several settings:
- *when* to calculate taxes (at the very end or at every line)?
- round at every step or not?
- how many decimal points?
- whether or not to allow different tax settings on different lines and how to deal with this if taxes have to be calculated at the end.
All of these settings can be packaged into a rounding mechanism. My suggestion is to package storm with two rounding mechanisms: default (as always) and a new setting: something like "apply taxes at the end and round every step of the way".
Further, it is impossible to predict every single possibility for these settings, so my solution would be to provide a hook allowing modules to define other rounding mechanisms if they are required.
Here is a patch that does this that I've used without side effects. I am including some simpletests as well. Comments welcome.
Comment #4
alberto56 commentedComment #5
juliangb commentedI'm not convinced that it needs to be this complicated.
What would be wrong with having two settings / variables:
- storminvoice_rounding_method
- storminvoice_rounding_digits
The first being a select from:
- No rounding
- Each line rounded
- Rounded pretax
etc
The second being numerical, only active if the former is not set to "No rounding".
Happy to be convinced otherwise if there is a strong argument - but I'm in favour of simplicity if possible.
Comment #6
alberto56 commentedI have found in the past that when it is hard to implement all possibilities, the best thing is to provide a hook to avoid to try to be all things to all people in the main module. Hooks after all are what make Drupal so scalable.
Let's say in the future someone in Quebec wants to start selling insurance alongside banking services alongside computer services, and all are taxed differently. It is likely that this will never happen, so we don't want to implement it now; If it does happen, I like the idea of that person having the option to have a module for that rather than submitting a patch with yet more options to click.
This being said, I too am open to be convinced, but for now I'm still not sure :)
What do you think?
Cheers,
Albert.
Comment #7
alberto56 commentedIn fact, there being a hook opens the possibility of a lot more than rounding.
What do you think if the following scenario, which corresponds to my case? In addition to rounding and using a unique tax system per invoice, I also would like to:
- make sure my client's Organization has a billing address and recognized province and country.
- make sure only one tax is used if selling to Canada outside Quebec and that its rate is correct.
- make sure two taxes are used if selling to Quebec and that their rates are correct.
- make sure not taxes are used if selling outside Canada.
- provide a warning if the total before taxes exceeds my client's credit limit, which is fetched from a cck field.
- make sure the second tax rate is correct according to the date of the invoice: in my jurisdiction, 2 changes to tax rates have been announced in the last 2 years, and I got a few complaints from clients because I forgot to lower the tax rate on the right date. Two more changes have just been announced in the coming years.
All this processing exceeds the concept of rounding, which is why I am changing the title of this issue slightly.
What do you think: is it better to provide a simple setting for rounding, and have users such as myself use hooks such as hook_form_alter to set this up all this stuff? Or to provide a hook as in comment #3, above (which might be easier to use for beginner programmers because they can be inspired by the rounding example)? I would have penchant for the latter.
Cheers,
A.
Comment #8
juliangb commentedYes, I think the validation bits you mention are highly custom, so a hook_form_alter with a validation handler will be best.
With the rounding, I see this more as an accounting standard rather than per taxation system - so still think the simple setting would be better. I feel with that, we could still achieve the scenarios most people would want, but without the complexity of a hook that many people wouldn't know how to implement.
Comment #9
alberto56 commentedSounds right.
In the module, though, we would need to have the option of forcing each line to have the same taxation scheme. This is important where taxes are added to the subtotal.
However, this raises the question of how to deal with invoices which already contain multiple taxation rates per line. If you create one of those invoices, then check the box that states, for example "single tax rate per invoice, rounded at end", what happens when you try to view an invoice which has already been created with multiple taxation rates?
Food for thought...
Albert.
Comment #10
juliangb commentedThat is indeed food for thought.
How about - if rounding is done at the end we hide the totals per item, then we can sum item amounts, tax1 amounts, tax2 amounts, and the overall total can be the sum of those three.
This seems more a question of accountancy though.
Comment #11
alberto56 commentedActually, we can't do the sum of tax1 and then the sum of tax2, because the requirement in many jurisdictions is that the total without tax be the basis for applying tax 1, then tax 2 is applied to the rounded sum of tax 1 and the subtotal, then tax 2 is rounded -- and finally the total is calculated... Therefore, tax2 can't be calculated per line.
I think there really should be an option to calculate taxes at the very end of the process and not per-line.
I'm sure there is an elegant solution to this :)
Comment #12
tchurch commented+1
Comment #13
alberto56 commentedThe patch in comment #3 doesn't work with storm 6.x-1.33. I've created an updated version of the patch, with no new functionality, that works with 6.x-1.33.
Albert.
Comment #14
alberto56 commentedRelated: #2365799: Total should be sum of price + rounded tax not rounded sum of price + tax
Comment #15
juliangb commentedMoving to Drupal PM project.
Comment #16
d34dman commentedFor some reason, D.O is not allowing me to assign this issue to a particular branch. Could we close this issue and continue discussion in #2365799: Total should be sum of price + rounded tax not rounded sum of price + tax ?
Also it is my understanding that this issue has become "closed won't fix" in storm (6.x version) by moving it to Project Management. Correct me if i am wrong. In case it is, then i suggest it be marked as "closed won't fix under storm itself" and we just reference this issue to #2365799: Total should be sum of price + rounded tax not rounded sum of price + tax.
Comment #17
alberto56 commentedI have no objection.
Comment #18
juliangb commentedI had assigned it to the wrong project. Now fixed.
Comment #19
d34dman commentedMoving To PM Invoice module issue queue where it would be fixed.