Level 1

0% to

Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

## Calculate subtotals according to date difference

Level 1

Likes

0 likes

Total Posts

6 posts

1 solution
View profile

Level 1

Likes

0 likes

Total Posts

6 posts

1 solution
View profile
Level 1

14-01-2021

Dear all,

I need help with a task I need to achieve;

I Created a purchase order form, where clients could order items.

they are about 10 products, each product has 3 fields : price, quantity and total price. the total amount will be calculated at the bottom of the page. the document works brilliantly.

I would need ta java script to do the following (I am straggling to do it):

I have 2 dates fields, one for actual date (will call it: date1) and the second is for "chosen delivery date (will call it: date2)", so I would like the document to be able to pick the actual date automatically as soon as the PDF has been opened and should be locked (uneditable).

Now, the calculation should depend on the date difference (date2 -date1), if the difference is less than 21 days then the calculation of the price for each product should be increased by 20% for each product  and the client should see a warning message that 20% surcharge will be added due to e.g. late order

Is that possible ? could anyone help?

Many thanks

#### Accepted Solutions (1)

MVP

Likes

397 likes

Total Posts

2,687 posts

492 solutions
View profile

MVP

Likes

397 likes

Total Posts

2,687 posts

492 solutions
View profile
MVP

14-01-2021

In FormCalc this is quite easy. The calculation script for the total price could look this way:

``````var factor = 1
if (not datefield2.isNull and not datefield1.isNull) then
if (Date2Num(datefield2.formattedValue, "MM/DD/YYYY") - Date2Num(datefield1.formattedValue, "MM/DD/YYYY") lt 21) then
factor = 1.2
endif
endif
var totalPrice = quantity * price * factor
\$ = totalPrice``````

Many thanks radzmar, will give it a try and let you know, Thanks again