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

Community Beginner ,
Sep 17, 2017

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

138

Likes

Translate

Translate

Report

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

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

Community Beginner ,
Sep 17, 2017

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

139

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 17, 2017 0
Most Valuable Participant ,
Sep 17, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2017 0
Community Beginner ,
Sep 17, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2017 0
Most Valuable Participant ,
Sep 17, 2017

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2017 2
Community Beginner ,
Sep 17, 2017

Copy link to clipboard

Copied

Thank you! The Regular Hours code worked. The Overtime code keeps giving the entire value of TotalHours - RegularHours instead of just the OT hours over 40.

So I used the code you recommended to another user and it gives me what I need.

event.value = +this.getField("TotalHours").value > 40 ? (+this.getField("TotalHours").value - 40) : 0;

I've tried multiple scenarios to make sure it works and it does, so thanks again. I really appreciate your help!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2017 0