Forum Moderators: open

Message Too Old, No Replies

Calculate subtotals according to date difference/adobe/javascript

Many thanks in advance

         

madona33

4:23 pm on Feb 22, 2021 (gmt 0)

5+ Year Member



Hi everyone,

I would need help to create a date and total calculation in an order form, I am really very 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 date field -in date format - called "event start date " in DD/MM/YYYY format and another one called "today's date"- also date format -. so If the order has been filled in within 20 days prior to the event start date (event start date - today's date <= 20), then 20% surcharge of the total will be calculated (there is a field called "surcharge" ) and added to the total charges , if the event start date > 20 days then the form should work as it is (no surcharge )

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.

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.

Any help, would be much appreciated

Many thanks

Madona33

lammert

4:48 pm on Feb 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should do this server side, not in JavaScript. If a bad person discovers that discounts and surcharges are calculated in the browser, it is very easy for them to manipulate the price.

NickMNS

5:16 pm on Feb 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello Madona33 welcome to WW

Let me start with the post title:
adobe/javascript

I'm not sure why you refer to adobe, but if you mean adobe Flash, then you should know that there is no longer any support for Flash in modern browsers, nor from Adobe itself. You should not use it all even in legacy code, it is a big security risk and most users will not be able use it.

What you are asking for is not a simple script and to be done correctly requires both client side (javascript) and server side code. I can provide you with a few pointers to get you started but
I would need help to create a date and total calculation in an order form, I am really very new in this field

Being that you are beginner this may be challenging for you.

1- This is relatively straight forward. Use the JS Date() API , convet both inputs into "Date" objects and then subtract the value to get the number of days. See this link for more details and examples:
[developer.mozilla.org...]

Note once you have the number of days difference the rest because simple math.

2- Again this is straight forward, add <div> on your page with the notification, eg "20% Surcharge in Effect" give it an id say "notification" and class of say "hide-notification" and using CSS set the style for that class to display:none, then set a style for a second class called "show-notification" with the style display:block. This will hide the div by default. Then use an if statement in your JS code, if the days calculated in 1 is greater 20 days change the class name to "show-notification".


// change class to show-notification
document.querySelector('#notification').className = "show-notification"


4 - To stop the script from running

I'm not sure what you mean by this. If this is a web page, then the script runs when the user access the page, and/or when the user submits the form. It is for all intents and purposes instant, there shouldn't be a time lag (network latency and other such things are negligible in this case). When the form is submitted, it should simply have a boolean (yes/no) field "apply surcharge" yes or no. As to how you handle the form once you receive on your end, that is a completely different issue. There must be two separate mechanism in place one for the user (described above) and another for you to manage. Handling the management side is a completely different thing. It can also work with "client-side" Javascript but now the client is you. Regardless this will require that your server receive the user's form, process it and then delegate it to next step, put it in a queue, send it by email, whatever. This process is outside of the scope of a Javascript script, it will need to be run on the server in whatever code your server is running (PHP, Python, NodeJS etc...)

I hope this helps.

NickMNS

5:22 pm on Feb 22, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What Lammert said is true. When the page is requested by the user the server should determine if the the surcharge applies and then respond with the appropriate page, surcharge page or no surcharge page.

madona33

11:32 am on Feb 23, 2021 (gmt 0)

5+ Year Member



Dear all,

Many thanks for all you help and suggestions, that's very kind of you all, brilliant.

We don't prefer to do it complicated (server). I do understand the security risks.

Simply, we have an order form, which we created in adobe acrobat pro, it is working fine in terms of calculations of the total, subtotal, VAT, etc....
It's a secure document, which is protected with a very strong password to prevent anyone from editing it, so it's just an adobe acrobat document and we send it to our clients, that's all.

As mentioned, it has all fields we need and it does the job brilliantly but we need to add the surcharge depending on the date and the notification message (point 1 and 2 in my first post), please ignore last point :

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

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.
We would love to write a script(s) to do the above in adobe acrobat (no FormCalc please).

Many thanks to you all

madnona

NickMNS

1:24 pm on Feb 23, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Unfortunately I have no experience with coding for Adobe Acrobat.

madona33

4:42 pm on Feb 23, 2021 (gmt 0)

5+ Year Member



No worries NickMNS, Many thanks anyway, hope someone else would be able to help