craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
226 stars 170 forks source link

Get wrong calculation for "Taxes include" #1108

Closed PopaWeb closed 4 years ago

PopaWeb commented 5 years ago

Description

I'm in Canada (Quebec) and we have 2 taxes: GST: 5% and QST: 9.975% If my settings are correct... When i add a product with taxes include, i got wrong amounts in the cart.

EX: Taxes not include (it works fine) 86.97 $ 0.05 (GST) = 4.35 $ 86.97 $ 0.975 (QST) = 8.68 $ Total: 86.97 + 4.35 + 8.68 = 100 $

EX: Taxes include (wrong amounts) "Is this tax is already included in the taxable subject?" -> Checked For a selling amount of 100 $ i got: GST (5%) = 4.76 $ QST (9.975%) = 9.07 $ Amount without taxes : 86.17 $ (instead of 86.97 $)

Here is a formula i found when 2 taxes are added to the selling price:

Example 100 $ / 1.14975 = 86.97 $ 86.97 $ 0.05 = 4.35 $ 86.97 $ 0.0975 = 8.68

Explanation Amount with taxes / 1.(GST+QST) = Amount without taxes Amount without taxes GST = amount of the GST Amount without taxes QST = amount of the QST

Am i doing this right ?

Steps to reproduce

  1. Add a tax category name "Taxes included" and check the product type
  2. Add first tax with "Is this tax is already included in the taxable subject?" -> Checked
  3. Taxable Subject: Line item price
  4. Rate: 5%
  5. Tax category: select "Taxes included"
  6. Repeat steps 2 to 5 to add the second tax with a rate of 9.975%

Additional info

stenvdb commented 4 years ago

I have a very similar question. In @PopaWeb's example, shouldn't 5% of 100$ be simply 5$? Instead in his example it's:

GST (5%) = 4.76 $

Where is 4.76 coming from?

PopaWeb commented 4 years ago

Hi @stenvdb If your adding 5% to $ 100, it is $5 But in reverse, the 5% came from the $ 86.97

So if you want $ 100 tax-in you have to do: $ 86.97 + 5% = $ 4.35 AND $86.97 + 9.975% = $ 8.68 Total $86.97 + $4.76 + $8.68 = $100

The temporary correction i made: commerce > src > adjusters > Tax.php : Line 272

+ $beforeTaxes = $taxableAmount / 1.14975; // Added by me 5% + 9.75%
+ $amount = $beforeTaxes * $taxRate->rate; // Added by me
- // $amount = $taxableAmount - ($taxableAmount / (1 + $taxRate->rate));
$itemTax = Currency::round($amount);
nfourtythree commented 4 years ago

Hi @PopaWeb

We made some significant updates around tax calculation and rounding in 3.1.

With that version does your issue still persist?

Thanks.

PopaWeb commented 4 years ago

Hi,

Thanks for the update but the issue is still there.

Here the modification i have to made to make it work:

In Tax.php:Line 299 -> Function _getTaxAmount

/ Before $exTax = $taxableAmount / (1 + $rate); $exTax = Currency::round($exTax); $tax = $taxableAmount - $exTax; / Before - Result for 100 $ TPS=4,76 $ TVQ=9,07 $

/ After / $exTax = $taxableAmount / 1.14975; // 1 + (5% + 9.975%) We have to include the 2 tax $exTax = $exTax * $rate; $tax = Currency::round($exTax);

After - Result for 100 $ TPS=4,35 $ TVQ=8,68 $

Here’s a link to calculate the taxes included in Canada: http://www.calculconversion.com/reverse-sales-tax-calculator-gst-qst.html http://www.calculconversion.com/reverse-sales-tax-calculator-gst-qst.html The formula is also on this page.

It will be nice to have a "Tax calculation formula" like the “Zip Code Condition Formula”.

Have a nice day! Richard St-Pierre

On Apr 3, 2020, at 06:00, Nathaniel Hammond notifications@github.com wrote:

Hi @PopaWeb https://github.com/PopaWeb We made some significant updates around tax calculation and rounding in 3.1.

With that version does your issue still persist?

Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/craftcms/commerce/issues/1108#issuecomment-608346869, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG3VB5MB6ROW3XHWG6KBBT3RKWXSZANCNFSM4JIE3YWQ.

ishandudeja commented 4 years ago

In Tax.php:Line 299 -> Function _getTaxAmount

private function _getTaxAmount($taxableAmount, $rate, $included)
    {
        if (!$included) {
            $incTax = $taxableAmount * (1 + $rate);
            $incTax = Currency::round($incTax);
            $tax = $incTax - $taxableAmount;
        } else {
            $exTax = $taxableAmount *(1 + $rate);
            $exTax = Currency::round($exTax);
            $tax =   $exTax -$taxableAmount;

        }

        return $tax;
    }
nfourtythree commented 4 years ago

Hi @PopaWeb

Currently, we do not support grouped tax rates. We have created an issue for this for us to look into to see how we can add it. You can follow along here: #1380

For the moment, you can get the taxes calculating correctly by using a single rate of 14.975% which will give you the right amount. You can then show that on the front end/emails as two separate taxes using your own calculations.

Thanks.