Tax Calculation

Background Information

WHMCS is a great software that we learned to master with over 10 years of experience as developers. We have no issue in achieving our goals but there's one problem that has always bugged us. The way WHMCS calculates taxes is wrong. We spent months trying to figure out how to "sanitize" amounts on invoices but all our solutions were impractical or impossible to use. We developed huge sections of code that almost did the job but in the end there was always one missing piece.

Sorry for being a bit cryptic but the argument we are discussing is immensely complex. From time to time you can read about some sides of this story directly on the forum of WHMCS (Problem VAT calculationWHMCS causing tax evasion) or in their feature requests area.

We won't even try to explain what's the problem in detail, what we did to overcome it and why our latest solution isn't perfect even if in the end it works. It's such tricky and messy story. So far no one managed to find the ideal solution therefore please trust us and accept the small downsides of our workaround.

The Problem

Actually there are multiple ways in which WHMCS causes invoicing issues due to inaccurate calculation of tax. Most of them are too complex to explain. It's about coding, hooks, missing data and decimal places. To make things easier to understand, let us report you a simple example we already posted on WHMCS forum.

Scenario:
  • Tax Type: Inclusive
  • Tax Rate: 22%
Let's create an invoice for an item that costs 14 € and focus on the calculation that WHMCS does:
  • Amount: 14 €
  • Subtotal: 11.48 €
  • 22% Tax: 2.52 €
  • Total Due: 14 €
We have 2.52 € of tax. Let's see if it's correct. 22% of 11.48 € is 2.5256 €. What is wrong with that?

According to the law of many countries, this value must be approximated to 2.53 €. It may seem not a serious question but this is an underpayment of tax. Most Revenue Agencies for an amount of 11.48 € expect a tax of 2.53 €. This is tax evasion. And if we sum 11.48 + 2.53 we get 14.01 that is wrong too.

Imagine how this problem can become gigantic if you generate thousand of invoices per year. Not to mention that the right combination of amounts, tax rates, coupuon codes, overpayments, credit usage (...) can be enough to cause this issue.

Workaround

This workaround is necessary when Taxation on credit is enabled in your system. Let's start from looking at the following example.
 


The customer applied 6 euro of credit on which he has already paid VAT at the moment of uploading funds to his account. We can't make him pay VAT twice therefore tax line should be recalculated to 0.80 euro (20% of subtotal minus credit). Sadly this can't be done at this stage for reasons we described earlier.

All the numbers on invoice will be corrected only at the moment the invoice becomes paid. This is the first downside that you have to accept. The second one is that the customer will still be asked to pay the wrong amount (6 euro) instead of the right one (4.8 euro) but don't panic. Billing Extension will automatically refund the amount that was not due (1.2 euro) directly on credit balance. Below you can see the corrected version of the invoice.


If you don't like this workaround keep in mind that there's no other possible solution other than not applying tax to add funds invoices. If the law of your country doesn't allow you to do so, then disable Add Funds entirely.

We understand that this workaround is bit limiting but we can't do anything without the help of WHMCS team. They should change core files or give us the ability to fix their calculations but at the moment they even refuse to recognize that there's a problem.