2 Replies Latest reply on Aug 30, 2015 5:11 PM by John Frederick Chionglo

# Help creating an Arcobat timesheet using javascript

Hello awesome people of the Adobe community,

I'm trying to create a timsheet that calculates regular hours and over-time hours.

I currently am using javascript to calculate time into total hours.

Example: from 9 am to 12pm is 3hours

Then, for each day I'm using javascript to determine if the total time for the day is +/- 8hrs. I split into two cells, one cell shows under or equal to 8 hrs and the other cell shows total over 8 hrs.

Example: If the total time worked in a day is 9 hours, regular hrs = 8, overtime hrs =1.

After the daily totals, I have a cell that totals all the regular hours in a week (Sunday - Saturday).

I have 2 separate cells that determine if the total of regular hours in a week is +/- 40 hrs.  One cell displays under or equal to 40hrs, and the other cell show the total over 40 hrs.

Finally, I have a cell that adds both daily overtime (any hrs over 8) and weekly overtime (any hrs over 40) to total the entire week of overtime.

So for example at the end the week I want totals to display, hypothetically, 39 total regular hours and 6 total overtime hours.

The cells I use for calculations would be hidden cells, but have javascript.

Some of the problems I am having is sometimes my cells javascript disappears or there seems to be a delay in the chain to calculating the totals.  Like if I fill out the times from Sunday to Wed, my timesheet will not total Sun - Wed until I start putting time in on Thurs?

I do not know how to write javascript, so the javascript that I am using in my timesheet is script that I've actually found here on the forums and so I am asking for help to see if there is a way to consolidate the javascript into fewer cells?

Or is there a script possible to calculate reg and ot hours accurately?

I don't know how (or if I even could) upload my pdf, but here's a screenshot with my "calculation cells" visible:

I have come up with the following situations and one of them the where my current timesheet fails and I was wondering if there's some sort of method or javascript that could solve this-

SunMonTuesWedThursFriSat
0888888

Total Regular hours = 40

Total Overtime hours = 8

SunMonTuesWedThursFriSat
0988880

Total Regular hours = 40

Total Overtime hours = 1

SunMonTuesWedThursFriSat
0988888

Total Regular hours = 40

Total Overtime hours = 9

My timesheet would fail in this scenario-

SunMonTuesWedThursFriSat
0978880

Total Regular hours = 39

Total Overtime hours = 1

My timesheet would calculate this as 40 regular hours and 1 overtime hours because, yes the grand total hrs worked is 40, but 1 of those hrs is considered overtime and not a reg hour.

I hope all this makes sense.

The question I would definitely liked answered is; is there way to consolidate the javascript into fewer cells?

If I can't get the reg and ot hr totals due to complexity, its ok, that can be figured out manually.

Any help and recommendations that could be provided would be very much appreciated.

Thank you.

• ###### 1. Re: Help creating an Arcobat timesheet using javascript

I see you have the dates for the line entry, why are you not using this field?

If you work shifts will cover the from 1:00am to 3:00am and your locality recognizes Daylight Savings Time (U.S.) or Summer Time (UK & Europe) you will need to have the dates so the scripts will properly handle the time shift for the spring and fall.

All the coding that needs to be done will be custom JavaScript and if a responders makes assumptions as to the field names you are using, do you know enough to modify the scripts to work with your field names.

I would use functions to preform the date time string conversions and summing the time periods. Another technique to consider is to record the time worked in minutes for the even values and use a custom format script to format the display the elapsed time. This script could also be a function since this custom formatting will be used about 24 times.

• ###### 2. Re: Help creating an Arcobat timesheet using javascript

You might find the following references useful for learning JavaScript and Acrobat/JavaScript:

1. David Flanagan’s book “JavaScript: The Definitive Guide, Fifth Edition”.
1. JavaScript for Acrobat API Reference and
2. Developing Acrobat Applications Using JavaScript

You should consider the following:

1. For more control over the occurrences of computations for fields, design your own computation process and trigger the process based on field events.

2. It is possible to consolidate the definition of every computation needed in your form at the document level. Codes attached to field-level events are function calls whose definitions are found at the document-level.

Regards,

John