## Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.

• Daily Time Sheet

# Daily Time Sheet

New Here ,
Feb 27, 2018 Feb 27, 2018

Copied

Hi, I have created a daily time sheet, The column with the time entered for each task is totaled at the bottom in box A (Total Hours). We are now required to pay overtime if the person works over their daily shift hours. Sometimes the shift may be 10 hours or 8 hours.

Is there a way to create a box with the daily hours (target hours). When the entered time totals less than the target, put total in box A, if the total exceeds the target hours, those hours over the target are put in box B (Overtime hours). Example would be: John's shift is 10 hours today, he enters 10 in the target box. He works through the day and at the end of his shift the total amount of hours he worked is 12 hours. Box A shows 10 Hours and Box B shows 2 hours.

Any help would be appreciated. Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

283

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Adobe Community Professional , Feb 27, 2018 Feb 27, 2018
That said, a simple solution requires calculation scripts in three fieldsFirst add a hidden total field and add a calculation to total the hours. You need that because both of the other fields rely on a total. This puts it in one place.On the regularhours calculation.var nTotal = this.getField("TotalHours").value;var nShift = this.getField("ShiftHours").value;if(nTotal > nShift)   event.value =  nShift;else   event.value = nTotal;Script for OvertimeHours calculationvar nTotal = this.getField("To...

Likes

8 Replies 8
Feb 27, 2018 Feb 27, 2018

Copied

Absolutely this is possible to do. You just need to get familiar with time and date calculations.

Here are some old articles on the topic:

I've written more about it on this subscription site, which also includes a time sheet example with overtime calculations.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 27, 2018 Feb 27, 2018

Copied

Thanks for your reply Thom. I don't have a lot of experience with

JavaScript, just a novice. The time that the person enters is just basic

math, the hour is divided into 4, 15 minute units so if they worked on a

project for 2 hours and 45 minutes they would enter 2.75 hours for that

project. They aren't required to enter the start and finish time. Thanks.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 27, 2018 Feb 27, 2018

Copied

That's quite easily done.

Let's say the fields are named TotalHours, NormalHours and Overtime.

As the custom calculation script of NormalHours enter this:

`var v = Number(this.getField("TotalHours").valueAsString);event.value = Math.min(10, v);`

And as the custom calculation script of Overtime enter this:

`var v = Number(this.getField("TotalHours").valueAsString);event.value = Math.max(0, v-10);`

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 27, 2018 Feb 27, 2018

Copied

Hi,

My form, as it is right now, has 16 boxes for time entry with a box at the

bottom saying Total Hours.

What I would like is a box at the top, ShiftHours, that the person working

will enter at the beginning of their shift. This could be any quantity

between 0 hours to 12 hour. 0 hours would relate to the whole day being

overtime.

I think this is what I need translated to JavaScript.

If the sum of boxes T1, T2, T3, â€¦. T16 is less than ShiftHours then put the

sum in RegularHours.

If the sum of boxes T1, T2, T3, â€¦. T16 is greater than ShiftHours then put

the sum, minus ShiftHours, in OvertimeHours and the quantity in ShiftHours

in RegularHours.

Thanks.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 27, 2018 Feb 27, 2018

Copied

That's quite a lot of ask for in a single question. We can help you with specific scripting/form issues, but we can't provide you with a complete solution to you form, unless of course you'd like to hire us to do that.

So, please break your project down into specific, single task issues, then we'll be able to provide some help. And to do this, you will of course need to learn some scripting.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 27, 2018 Feb 27, 2018

Copied

That said, a simple solution requires calculation scripts in three fields

First add a hidden total field and add a calculation to total the hours. You need that because both of the other fields rely on a total. This puts it in one place.

On the regularhours calculation.

var nTotal = this.getField("TotalHours").value;

var nShift = this.getField("ShiftHours").value;

if(nTotal > nShift)

event.value =  nShift;

else

event.value = nTotal;

Script for OvertimeHours calculation

var nTotal = this.getField("TotalHours").value;

var nShift = this.getField("ShiftHours").value;

if(nTotal > nShift)

event.value =  nTotal - nShift;

else

event.value = 0;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 27, 2018 Feb 27, 2018

Copied

I appreciate the help, now Iâ€™ll see if I can get it to work. I do have a

work around, I can just create a second column for overtime hours, itâ€™s not

as elegant but should work. Thanks for your help.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Feb 27, 2018 Feb 27, 2018

Copied

LATEST

Works perfect, just what I wanted. Thank you very much.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more