VAT calculation round not exact

Hi guys,

I think Invoice Ninja is having trouble rounding VAT amounts.

Suppose I want to sell a product for 10€ VAT included (21%)

Invoice Ninja only allows the following combinations:

  • 8,26 + 1,73 = 9,99€
  • 8,27 + 1,74 = 10,01€

This happens in both exclusive and inclusive tax methods.

In another accounting SAAS, the invoice is as follows:

  • Subtotal: 8,26€
  • VAT: 1,74€
  • Total: 10,00€

But right now, in Invoice Ninja there is no way to put a total of 10€ that contains 21% VAT.

Is there any way to solve it? It is probably because a rounding of 2 decimal places is being applied for the calculation of taxes. It could be corrected by increasing a decimal touch some .php file that controls the rounding of taxes. For example:

/tests/acceptance/TaxRatesCest.php

       $total = $itemCost;
       $total += round($itemCost * $invoiceTaxRate / 100, 2);

/app/Models/Invoice.php

       /**
            * @param $invoiceItem
            * @param $invoiceTotal
            *
            * @return float|int
            */
           public function getItemTaxable($invoiceItem, $invoiceTotal)
           {
               $total = $invoiceItem->qty * $invoiceItem->cost;
       
               if ($this->discount != 0) {
                   if ($this->is_amount_discount) {
                       if ($invoiceTotal + $this->discount != 0) {
                           $total -= $invoiceTotal ? ($total / ($invoiceTotal + $this->discount) * $this->discount) : 0;
                       }
                   } else {
                       $total *= (100 - $this->discount) / 100;
                   }
               }
       
               if ($invoiceItem->discount != 0) {
                   if ($this->is_amount_discount) {
                       $total -= $invoiceItem->discount;
                   } else {
                       $total -= $total * $invoiceItem->discount / 100;
                   }
               }
       
               return round($total, 2);
           }

Can it be fixed?

Thanks!

I think you’ve tagged the issue in v5, but it looks like from the code it is v4.

I can confirm V5 outputs the tax at 1.74

image

Hi @david

The version is
image

The code snippets are from v4 that you have included. I’m not sure why your calculations are appearing differently to mine, I don’t think this part of the app has changed in a long time

I just found that this rounding mismatch only occurs with the tax excluded mode. With the tax included mode it is calculated correctly.

@david Can you check if it also happens to you with taxes excluded?

@martinkbs

Can you provide an example where the amounts are not calculating correctly? Using exclusive taxes with a $10 amount still looks good to me.

image