• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trying to make automated calculations for an invoice .pdf in acrobat

Community Beginner ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied

Hi! 

 

I've been spending the last couple of days trying to understand javascrip in acrobat. There's a lot of good posts on here and a lot of good answers for difficult problems. However I've tried a lot of different scripts and I still haven't quite come up with a solution for my form. 

 

It looks like this: Capture (Invoice Form).PNG

1. What I have right now is a Subtotal (named Subtotal) that just simply adds all the total rows (named TotalRow1 etc.) together using simplified field notations.

 

2. Then I have a discount (named Discount) which is just a number with an added custom format script (if (event.value) event.value += " %";).

 

3. Then I have VAT (named VAT) which is multiplying the subtotal with 25 in a simplified field notation (Subtotal*0.25).

 

4. Lastly my total (named Total) is just the Subtotal with the VAT added in simplified field notations. 

 

What I'm trying to achieve: 

I would like for it to be possible to enter a discount percentage (e.g.  10%) as just a round number and then for that dicount percentage to be subtracted from the total. I've tried multiple things, but unfortunatly nothing seems to work. (This is a little different from the posts I've seen cause I have VAT added)

 

As an extra thing, but not as important:

It would be nice if the hours and costs could be multiplied in the total, but that if they are left blank it will be possible to just enter a total in e.g. 'TotalRow1'.

 

Any ideas, questions and suggestions are welcome!

TOPICS
JavaScript

Views

517

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

correct answers 2 Correct answers

Community Expert , Mar 02, 2021 Mar 02, 2021

#1. So is the discount calculated from the sub-total (ie. before adding VAT)? In other words, Total should be (Subtotal * Discount) + VAT?

 

#2. This is a bit tricky. In order to do it you would need to look at the name of the field that triggered the calculation event (via event.source.name). For example, for TotalRow1 you need to check whether it's HoursRow1 or CostRow1 and if so perform the automatic calculation. Otherwise do nothing. That will allow the user to enter a custom value into the

...

Votes

Translate

Translate
Community Expert , Mar 02, 2021 Mar 02, 2021

@Lennart_ wrote:

Any ideas, questions and suggestions are welcome!


 

 

Sometimes it works to create additional fields and format them to "Hidden" so they can be used for calculations but do not show on the form.

 

~ Jane

Votes

Translate

Translate
Community Expert ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied

#1. So is the discount calculated from the sub-total (ie. before adding VAT)? In other words, Total should be (Subtotal * Discount) + VAT?

 

#2. This is a bit tricky. In order to do it you would need to look at the name of the field that triggered the calculation event (via event.source.name). For example, for TotalRow1 you need to check whether it's HoursRow1 or CostRow1 and if so perform the automatic calculation. Otherwise do nothing. That will allow the user to enter a custom value into the field without it being overwritten, unless they change the value in one of those two fields.

Votes

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
Community Beginner ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Thanks for the quick reply! 

 

#1 It doens't seem to work with that calculation (maybe because my 'discountfield' is not a percentage but a number). I've gotten it to work using a hidden calculation though, which first calculates the percentage from the subtotal and then subtracts that number from the total (using a calculating in the total). I think you pose a good question about the VAT. I'm pretty sure I would want the discount to be subtracted before VAT is added, but I'll look into that and make a desicion. 

 

#2 Thank you! That sound complicated for my level of Javascript, but I'll look into it.

 

All in all i really appreciate the help!  

Votes

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
Community Expert ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

If the discount field is set as a number (but represents a percentage) then you calculate its use it like this (under the Simple Field Notation option in the Calculate tab of Total):

 

(Subtotal * ((100-Discount)/100)) + VAT


Or if the discount should apply to the VAT as well, then this:

 

(Subtotal + VAT) * ((100-Discount) / 100)

Votes

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
Community Expert ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied


@Lennart_ wrote:

Any ideas, questions and suggestions are welcome!


 

 

Sometimes it works to create additional fields and format them to "Hidden" so they can be used for calculations but do not show on the form.

 

~ Jane

Votes

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
Community Beginner ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi Jane,

 

Thanks! Using a hidden calculation really helped solve this whole thing. 

 

Much appreciated!

Votes

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
Community Expert ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

LATEST

You're welcome, @Lennart_ 😊

~ Jane

Votes

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