Sum values depending on values in other fields

New Here ,
Jan 31, 2020 Jan 31, 2020

Copy link to clipboard

Copied

Hi! I am trying to create an invoice form that will hold varying VAT tax percentages. Each row has both a total price before tax (Field A), and a number indicating the VAT % of that row (Field 1).

I would like to show the total sums for three different tax levels on the bottom of my form, where each field would preferably autopopulate with the sums for that tax %.

 

For example: Fields A, B, D, and G should be summed because fields 1, 2, 4, and 7 show the same number, while fields C, E, and F sum because fields 3, 5, and 6 show the same number.

 

I am not super familiar with javascript but assume I will need to use a hefty amount of if statements.

I've looked at this thread to try to figure it out but need some help figuring out how to code it for acrobat: https://stackoverflow.com/questions/50879417/sum-field-values-based-on-condition-in-another-field-in...

 

I'm working directly in Acrobat, right clicking fields > properties > custom calculation script.

 

Would love to hear if anyone has tips!

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

52

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Jan 31, 2020 Jan 31, 2020

Copy link to clipboard

Copied

Your description is not very clear, I'm afraid. Are you trying to match the fields names with the numbers that correspond with the order in the alphabet? What does that have to do with taxes? Please clarify.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Thank you for checking in! The template I'm working on can be viewed here.

I want the numbers entered into the column titled "Belopp (SEK)" to sum automatically into the four bottom-left fields ("Moms 25%", "Moms 12%", "Moms 6%", and "Momsfritt") depending on the numbers entered into the column titled "Moms %".

 

Example:

The columns show these numbers

Belopp     Moms

100           25

100           12

100           25

 

The fields on the bottom left should then show this calculation

Moms 25% 200

Moms 12% 100

Moms 6% 0

Momsfritt 0

 

Thank you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Ok, and what exactly is the calculation? 

How was the number 200 calculated?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2020 Feb 04, 2020

Copy link to clipboard

Copied

The number 200 is the sum of every field in the "Belopp" column that is followed by a field filled with '25' in the "Moms" column.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 04, 2020 Feb 04, 2020

Copy link to clipboard

Copied

LATEST

So how then are the fields named. The naming is critical to developing the script. The field names create the relationship between the data in the rows and colums. 

For this scenerio it would be best to name everything in the Belopp column with the Belopp prefix, and the same for the Moms column. So "Belopp.Row1" "Belopp.Row2" etc. and "Moms.Row1" Moms.Row2", etc.

 

The script should loop over the fields in the Moms column, using an object to track Moms values and the related sums from the "Belopp" column.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines