Copy link to clipboard
Copied
I am currently trying to modify our mileage sheet to do calculations automatically. Originally we were using simplified field notation of: (Miles1*0.67)+(Hours1*1.5)+(Misc1) to calculate the subtotal of each line.
Recently there has been a change though,
The Hourly rate needs to be $17.00
The milage rates are .70 if they travel less than 99 miles and .44 if they travel 100 miles or more.
I've attached a screenshot naming each of the fields
Copy link to clipboard
Copied
You can try this as custom calculation script:
var miles = Number(this.getField("Miles1").valueAsString);
var hours = Number(this.getField("Hours1").valueAsString);
var misc = Number(this.getField("Misc1").valueAsString);
var mileRate = (miles > 0 && miles < 100) ? 0.70 : (miles >= 100 ? 0.44 : 0);
event.value = (miles * mileRate) + (hours * 17) + misc;
If those are all calculations you are using for subtotal, you may consider using a loop to calculate all rows with one script and grand total instead of using a script in each row.
EDIT:
Script for loop, use it in "GRAND TOTAL" field as custom calculation script:
var grandTotal = 0;
for(var i=1; i<=10; i++) {
var miles = +this.getField("Miles"+i).valueAsString;
var hours = +this.getField("Hours"+i).valueAsString;
var misc = +this.getField("Misc"+i).valueAsString;
var sub = this.getField("Subtotal"+i);
var mileRate = (miles > 0 && miles < 100) ? 0.70 : (miles >= 100 ? 0.44 : 0);
var total = (miles * mileRate) + (hours * 17) + misc;
sub.value = total;
grandTotal += total;}
event.value = grandTotal;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now