I need a formula and/or a programmatic function (in any language) which will properly calculate a product discount so a customer can pay a price agreed upon at checkout, including tax, with multiple taxes applied to different amounts of the item price. The out-the-door price is not necessarily known until checkout and is kind of a bargaining tactic. For instance:
- Customer wishes to buy multiple items with a subtotal of \$6,000
- There is a 6% Sales Tax on all items
- There is an additional 1% on the first \$5,000 of all items.
| Item | Price | Quantity | Total | Amount Surtaxed | 0.01 Surtax Amount | Pctg of Order Total |
|---|---|---|---|---|---|---|
| Thing 1 | \$100.00 | 1 | \$100.00 | \$100.00 | \$1.00 | 1.56% |
| Thing 2 | \$5,500.00 | 1 | \$5,500.00 | \$5,000.00 | \$50.00 | 85.74% |
| Thing 3 | $400.00 | 1 | \$400.00 | \$400.00 | \$4.00 | 6.24% |
| Subtotal | \$6,000.00 | |||||
| Base Sales Tax (6%) | \$360.00 | |||||
| County Surtax (1%) | \$55.00 | |||||
| Total Tax | \$415.00 | |||||
| Order Total | \$6,415.00 |
The customer wants to only pay \$6,000 so we agree on that amount. Our store needs to ensure that sales taxes are paid on the order but, of course, we don't want to pay those taxes. So, we want to discount each item to get to a new subtotal which when the taxes are applied our new Order Total is exactly \$6,000. The customer ends up paying the tax on lower priced items. (Note that there’s multiple ways to adjust prices; you can come up with your own criteria.)
We've come up with a couple formulas for this and it works fine when we're only worried about a singular tax rate or just a single item. When we need to handle multiple tax rates and multiple items, we have a hard time getting the correct total.
I can post what we've tried but I'm afraid that will muddy the waters. We call this an "out the door" price.
\begin{align} Price1 && Price2 && Price3 && Order\ 100.00 && 5500.00 && 400.00 && 6415.00\ 98.01 && 5390.55 && 392.04 && 6288.34\ 97.03 && 5336.64 && 388.12 && 6225.95\ 96.06 && 5283.28 && 384.24 && 6164.19\ 95.10 && 5230.45 && 380.40 && 6103.05\ 94.15 && 5178.14 && 376.59 && 6042.52\ 93.21 && 5126.36 && 372.83 && 5982.60\ \end{align}
– Kurt G. Nov 11 '24 at 12:51