Skip to main content
Participant
September 17, 2017
Question

Very Simple Overtime Calculation (based on a varied hour work week)

  • September 17, 2017
  • 1 reply
  • 748 views

I have a timesheet form that adds and populates based on a varied work week.  Normal work week hours can vary by each employee.  I want to auto-populate three boxes "Total Hours", "Regular Hours" and "Overtime Hours" based on whatever is entered in the "Normal Hours" field.

ex: if "Normal Hours" = 37  and "Total Hours" = 55, "Regular Hours" should read 37, "Overtime Hours" should read 15.

ex: if "Normal Hours" = 37  and "Total Hours" = 35, "Regular Hours" should read 35, "Overtime Hours" should read 0.

This reply was spot on, except my sheet is not based on a standard 40 hour work week. It could be 35, 37 etc.

Basically, "Regular Hours" should be <= Total Hours but cannot exceed Normal Hours.

I would greatly appreciate any assistance with this.

Thanks!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 17, 2017

Sounds like Regular Hours = Normal Hours, and Overtime Hours = Total Hours - Normal Hours, or zero if the result is negative. Is that correct?

joijoyAuthor
Participant
September 17, 2017

Hi

Very close. Actually...

Regular Hours = Total Hours or Normal Hours, whichever is smaller.

Overtime Hours = Total Hours - Regular Hours, or zero if the result is negative.  OT is over 40 hours per week.

try67
Community Expert
Community Expert
September 17, 2017

I think I understand... Use this code as the custom calculation script of Regular Hours:

var normalHours = Number(this.getField("NormalHours").value);

var totalHours = Number(this.getField("TotalHours").value);

event.value = Math.min(regularHours, totalHours);

And this one for Overtime Hours:

var regularHours = Number(this.getField("RegularHours").value);

var totalHours = Number(this.getField("TotalHours").value);

event.value = (totalHours>40) ? Math.max(totalHours-regularHours, 0) : 0;