darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.35k stars 453 forks source link

Apply multiple taxes #343

Open tongtian0925 opened 2 years ago

tongtian0925 commented 2 years ago

In Quebec Canada, we have two kinds of taxes GST 9.975%+ QST 5% but if I apply two conditions the calculation is wrong because it should be subtotal(1+ 0.0975+0.05), but the code is calculated as subtotal 1.0975*1.05 which means one tax is base on another tax result. do we have a way to calculate tax rate first then apply on the subtotal?

It is legal to get the tax separately, so I can't add them to one condition then apply it

Blum commented 2 years ago

First of all, as I read, it seems the opposite.. The QST is 9.975% and GST is 5%.

The only solution I see for this in the current functionality would be to add a conditions at once (*1,14975) and to break the result down into fractions after that, so you can show the taxes separately.

If the subtotal is S = 8,55, the both added taxes would be R = S1,14975 = 9,8303625, and GST+QST part would be = R - (R/1,14975) = 1,2803625. The ratio QST / GST = 9.975 / 5 , and after we know that GST = (1,2803625 - QST) turns out GST = 0,4275 and QST = 0,8528625. Quick check would confirms that if we extract the QST by (8,55 1,09975) - 8.55 we'll get exactly 0,8528625.

You can spare a lots of these calculations if you keep the original price as an attribute to the item, and get the QST and GST directly by it.

Cheers