Expand my Community achievements bar.

SOLVED

Calculate subtotals according to date difference

Avatar

Level 2

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

 

Madona33

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

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

 

Avatar

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