3 Replies Latest reply on Feb 3, 2017 12:10 PM by try67

# Conditional Sales Tax Calculation

I need some java script help creating a PDF form/field named "Sales Tax" that does the following:

Calculates the amount of tax from the "Search Fee" field based on "Zip" and "State" fields.

Conditions are that if the "State" field is not "NY" the sales tax rate would be zero and thus the "Sales Tax" field would read \$0.00.

i.e. State: CA, Search Fee: \$150.00, Sales Tax: \$0.00

IF the "State" field is "NY" then it would calculate the rate based off of the "Zip" field.

i.e. State: NY, Zip: 10005, Search Fee: \$150.00, Sales Tax: \$13.31 (8.875% of \$150)

i.e. State: NY, Zip: 10005, Search Fee: \$150.00, Sales Tax: \$12.94 (8.625% of \$150)

Ideally the calculation would read an excel sheet with 2 columns (one for zip and for tax rate) but I would also be interested in the code that 'manually' covers the 11 sales tax rates of NY.

Any help would be great.

Thanks!

• ###### 1. Re: Conditional Sales Tax Calculation

This is a complex task, especially if you want to use an external data source. It would require the development of a custom-made script.

If you're interested I could explain what would be involved in developing this script, or I could just create it for you (for a fee). If you're interested in the latter you can contact me at try6767 at gmail.com to discuss it further.

• ###### 2. Re: Conditional Sales Tax Calculation

At this point I'd rather not incur any costs and figure it out myself, with some help of course I would be interested in the steps involved. I don't think reading from an external source is necessary and in fact would prefer manually coding everything to contain in a single file.

• ###### 3. Re: Conditional Sales Tax Calculation

OK. In that case you can use something like this to calculate the value of the Sales Tax Percentage field. You can then multiply that value by your Search Fee to get the actual Sales Tax:

```var state = this.getField("State").valueAsString;
if (state!="NY") event.value = 0;
else {
var zip = this.getField("Zip").valueAsString;
if (zip=="10005") event.value = 0.08875;
else if (zip=="10006") event.value = 0.08625;
// etc.
}
```