I have an order that contains two items, item A and item B. They have different net (before tax) prices and they have different tax rates applied. There is one of each product on the order.
Lets say item A is $100 with 5% tax and item B is $50 with 10% tax
A = 100, B = 50
The order total is taken as (A + A * 5%) + (B + B * 10%)
So the order total is 105 + 55 = $160 including tax.
$10 of the total is therefore tax.
What I need is a formula so that given the total tax on the order ($10), and knowing there are two products on the order, and knowing their net price and tax rate, how can I calculate the amount of tax per item.
I need to reverse calculate the tax payable on each individual item from the total tax on the order. I cannot in this scenario just use the item price and tax rate as I used in the example when forward calculating the tax, this has to be worked from total tax back to individual tax. The reason for this is to overcome rounding errors that creep in due to money only being worked with at 4dps. With rounding errors calculating tax forward can give different results to calculating it backwards - hence I need to be able to work from total tax value back to individual item tax value.
Note the solution will form part of an algorithm so a multi step solution woudl be fine.