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

Calculating Sum - Adding Fee to Most of the Items

Community Beginner ,
Feb 27, 2024 Feb 27, 2024

Calculating Sum - additional fee variable

I want to calculate the sum of 29 fields.

There is a $30 base fee that gets added to the sum of the fields.

However, there are two items in the list that do not get charged that additional 'base fee' of $30 (highlighted in the image)

Right now, I am using this simplified field notation:

(Cost1+Cost2+Cost3+Cost4+Cost5+Cost6+Cost7+Cost8+Cost9+Cost10+Cost11+Cost12+Cost13+Cost14+Cost15+Cost16+Cost17+Cost18+Cost19+Cost20+Cost21+Cost22+Cost23+Cost24+Cost25+Cost26+Cost27+Cost28+Cost29+Cost30+30)

 

Screenshot 2024-02-27 121322.png

What's the best way for me get the correct calculation? 

 

TOPICS
Create PDFs , Modern Acrobat , PDF , PDF forms
1.0K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 27, 2024 Feb 27, 2024

Try this code as the custom calculation script of the total field:

 

var total = 0;
var addFee = false;
for (var i=1; i<=30; i++) {
	var cost = Number(this.getField("Cost"+i).valueAsString);
	total+=cost;
	if (cost>0 && i!=1 && i!=24) addFee = true;
}
if (addFee) total+=30;
event.value = total;

View solution in original post

Translate
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 ,
Feb 27, 2024 Feb 27, 2024

So you want to add the fee if any of the other fields are selected, basically? Do all of these fields have a value, or does the user enter one into them? Does it not also rely on the quantity fields (Cost*Quantity)?

Translate
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 ,
Feb 27, 2024 Feb 27, 2024

The fee only gets added to the sum, not to the items indivuidually. When the user enters a value, the cost for that item is set to calculate. Then the sum of all of the individual fields is calculated. Right now, the "Total Permit Fee" field also adds $30 to the calculation (that's for the 'base fee' charged by the department. Hoever, there are two items in the list that should not be assessed that additional $30 fee.

Screenshot 2024-02-27 120822.png

Translate
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 ,
Feb 27, 2024 Feb 27, 2024

I'm trying to understand how it should work practically, though. Say the user entered qty 1 for Gas Safety only. Then the cost for that field is calculated to be 50 (for example). So the total is just 50. That's clear.

But if they enter "1" for Boiler then the cost for that field becomes 30, say. So what's the total now? Isn't it 50+30+30 (the fee because of Boiler) = 110?

There's no way not to apply the fee to these two items, too, unless they are the only ones that are selected...

Translate
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 ,
Feb 27, 2024 Feb 27, 2024

"There's no way not to apply the fee to these two items, too, unless they are the only ones that are selected..."

 

That's the part that I want to fix. If the user only selects one (or both) of the highlighted items, how can I prevent the base fee of $30 from being added to the Total Permit Fee field?

Translate
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 ,
Feb 27, 2024 Feb 27, 2024

Try this code as the custom calculation script of the total field:

 

var total = 0;
var addFee = false;
for (var i=1; i<=30; i++) {
	var cost = Number(this.getField("Cost"+i).valueAsString);
	total+=cost;
	if (cost>0 && i!=1 && i!=24) addFee = true;
}
if (addFee) total+=30;
event.value = total;
Translate
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 ,
Feb 27, 2024 Feb 27, 2024
LATEST

Thank you! It's perfect!

I appreciate your time to provide this solution. I'm definitely a novice when it comes to using java script for calculations. 

Translate
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