# compound tax in php?

## Recommended Posts

hey guys can i get some help in putting this in php ?

i need to calculate taxes but in quebec...so 2 taxes

exapl

SUBTOTAL 3.99
TAX1: 18%
TAX2: 15%

Calculating when Compound tax is enabled:

Amount with Compound tax = (SUBTOTAL + TAX1) + TAX2

in digits:

(SUBTOTAL + TAX1) = 3.99 + 18% = 3.99 + 3.99 / 100 * 18 = 3.99 * 1.18 = 4.7082
(SUBTOTAL + TAX1) + TAX2 = 4.7082 + 15% = 4.7082 + 4.7082 / 100 * 15 = 4.7082 + 0.70623 = 4.7082 * 1.15 = 5.41443
Amount with Compound tax = 5.41443

##### Share on other sites

You already have the math worked out for applying the taxes (highlighted below)

(SUBTOTAL + TAX1) = 3.99 + 18% = 3.99 + 3.99 / 100 * 18 = 3.99 * 1.18 = 4.7082
(SUBTOTAL + TAX1) + TAX2 = 4.7082 + 15% = 4.7082 + 4.7082 / 100 * 15 = 4.7082 + 0.70623 = 4.7082 * 1.15 = 5.41443

The number in purple is the subtotal you're applying tax to. The green number is the subtotal with 1st tax. The number in blue will be sales price (subtotal, 1st and 2nd taxes added together).

So what is the problem. Are you unsure how covert it to PHP? All that is needed is for you to change the purple and green numbers to PHP variables.

Edited by Ch0cu3r
##### Share on other sites

As you've shown, compound tax is simply applying a tax to an already-taxed number. It can be simplified to just

`3.99 * 1.18 * 1.15 = 5.41443`
`\$price * \$tax1 * \$tax2`
##### Share on other sites

i got it going with this

```\$TAX1=5.00;\$TAX2 =9.974;///this is suppose to be 9.975 but i get a penny more..so i doped it a penny and im ok..
\$price1 = (\$price * \$TAX1/100) ;\$price2 = (\$price * \$TAX2/100) ;\$price3 =  \$price + \$price1 + \$price2; \$total1= round(\$price1, 2);\$total2= round(\$price2, 2);\$total= round(\$price3, 2);```
##### Share on other sites

is there a tutorial on how to make a form that when i scan it updates the field with the product info from database?im making a POS system for my body's store..

##### Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.