Rounding VAT on invoice total

Hello, I’ve just noticed an issue with the rounding of VAT, where it seems to round it per line, rather than total. I’m based in Germany (19% VAT) and the problem usually occurs when using decimals in line items. We use two decimals.

If we change to three decimals, the total VAT is correct, but we have too many decimals for PDF outputs to look nice.

If you have three items:

€97.50
€65
€32.50

And VAT is 19%, you would get VAT:

€18.525
€12.35
€6.175

Which adds up to:

Price: €195
VAT: €37.05
Total: €232.05

But with “Currency Significant” set to 2, it rounds each line item, so VAT becomes:

€18.53
€12.35
€6.18

Total VAT: €37.06

The VAT amount is off by €0.01. Is there anywhere in the admin to define rounding on totals rather than line items? Or can we set 3 decimals in the admin, but two decimals in the invoice PDFs?

I can’t find so much in the forum. A similar question was asked a couple of years ago https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/2233-difficulties-rounding-vat-correctly#9052, but the answer was to start changing the code - is there a different way today?

I had someone help me with this, so I’m documenting what solved it for us, in case it might help someone else.

In the file /modules/AOS_Products_Quotes/line_items.js we disabled line #722:

document.getElementById(key + 'vat_amt' + ln).value = format2Number(totalvat);

and replaced it with:

document.getElementById(key + 'vat_amt' + ln).value = parseFloat(totalvat).toFixed(3);
document.getElementById(key + 'vat_amt' + ln).value = document.getElementById(key + 'vat_amt' + ln).value.toString().replace(".", ",");

Then on line #793 we disabled:

product_vat_amt = unformat2Number(input[j].value);

and replaced it with:

var vat_custom = input[j].value;
var vat_custom_new =  vat_custom.replace(",", ".");
product_vat_amt =  parseFloat(vat_custom_new);

We then saved this file as an override in /custom/modules/AOS_Products_Quotes/line_items.js

This works for us with invoices, which is mainly what we use SuiteCRM for. It shows 3 decimals for line item VAT, then rounds the total VAT, giving us correct VAT and grand total.

Is this a fix that should be put into SuiteCRM for everyone? You could contribute it on Github.

The developer seemed to think it’s a bug. But I don’t know if this fix is general enough to be contributed the way it is now. Essentially it forces three decimals on line item VAT, although two decimals is set in admin - this so that rounding on line item VAT can be properly rounded and then we still just use two decimals for totals, invoices etc.

For this to be incorporated into core, I think it would probably need to be written so that line item VAT is rounded on full amount (in our case three decimals was enough), but in the admin you still only see the number of decimals set in the configuration.

I found this

https://github.com/salesagility/SuiteCRM/issues/4460

It looks like the exact same thing.

Sorry, forgot to reply to this. Yes, that’s the same issue, it was me making the comment at the end.