Expand my Community achievements bar.

SOLVED

order form with automatically calculation

Avatar

Level 2

Hi everyone,

 

I would need help to create a date and total calculation in an order form, I am really new in this field, I would appreciate any help, thanks

Basically, we are a small event organisation, we offer some products to our clients, the order form works brilliantly as it's but because we receive often  orders very late,we would like to add a script to do the following:

 

1- There is a field called "event start date " in DD/MM/YYYY format, so If the order has been filled in within 20 days prior to the event start date (event start date <= 20), then 20% surcharge will be added to the total (there is a field called "surcharge" before the total and will be added to the total charges) , if the event start date > 20 days then the form should work as it is

 

2- In case that the difference is <=20 then a notification should appear to notify the client that 20% surcharge will be added to the total due to the late order.

 

3- If possible, we don't prefer to add a field called " today's date" (we need only "event start date" ), so the script should compare the actual date with the event start date without entering the actual date.

 

4 - To stop the script from running , in case we receive and open the form within the 20 days (in case clients send it before the 20 days deadline), is it possible to lock the form after the client saved it , so the form doesn't pick up today's date and recalculate the total if we open it later  within the 20 days before the event.

 

Many thanks in advanced

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Dear radzmar,

 

I am really sorry, I accepted the answer by mistake, please see below

 

Many thanks for your reply and sorry for the delay in responding. I tried the code provided but it doesn't work.Basically, if the Date2-Date1<20 then surcharge (field called sur) should be 20% of the total (I have a field for total, called Total ). Both dates fields are in form DD/MM/YYY. Any suggestions please? Many thanks

View solution in original post

5 Replies

Avatar

Level 10

Hi,

 

for date calculations you can use FormCalc, which is much easier than JavaScript. 

The surcharge can be calculated in this way for example: 

 

var nSurcharge = 0

if (Date2Num(EventStartDateField.formattedValue, "DD/MM/YYYY") - Date() le 20) then

    nSurcharge = 20

endif

$ = nSurcharge

 

To protect a form, you can either lock the uppermost element in your form or every single field.

There are plenty of examples in this forum available about this.

Avatar

Level 2
Dear Radzmar, Many thanks for your reply and sorry for the delay in responding. I tried the code provided but it doesn't work.Basically, if the Date2-Date1<20 then surcharge (field called sur) should be 20% of the total (I have a field for total, called Total ). Both dates fields are in form DD/MM/YYY. Any suggestions please? Many thanks

Avatar

Correct answer by
Level 2

Dear radzmar,

 

I am really sorry, I accepted the answer by mistake, please see below

 

Many thanks for your reply and sorry for the delay in responding. I tried the code provided but it doesn't work.Basically, if the Date2-Date1<20 then surcharge (field called sur) should be 20% of the total (I have a field for total, called Total ). Both dates fields are in form DD/MM/YYY. Any suggestions please? Many thanks

Avatar

Level 10

I would have to know the hierachy of your form to give a more suitable answer. Please provide some screenshots.