There is an updated version of this article which uses a different scripting method TimeWorksPlus - Round Hours Instead of Punches
The following script rounds to total hours in a week to 40 and shows an alert on the time card to show how it rounded (PayRateScript Rule):
if(reportingdate.hourstodate >= 39.75 and reportingdate.hourstodate <= 40.25 and islasttoday){ $b = 40 - reportingdate.hourstodate; $c = hours + $b; if($b < 0){ addalert(cstr("Hours rounded from " + hours + " hours to " + $c + " hours to make the total hours 40.")); hours = $c; } else{ addalert(cstr("Hours rounded from " + hours + " hours to " + $c + " hours to make the total hours 40.")); hours = $c; } }
Here is a screen shot of how this looks on the time card:
Here is a script that rounds the hours at the end of the week to the nearest quarter hour (PayRateScript Rule):
if(reportingdate.islastpunchweek and islasttoday){ $decimal = reportingdate.weekhours - cint(reportingdate.weekhours); if($decimal < .125){ hours = hours - $decimal; } else if($decimal >= .125 and $decimal < .375){ $sub = .25 - $decimal; hours = hours + $sub; } else if($decimal >= .375 and $decimal < .625){ $sub = .5 - $decimal; hours = hours + $sub; } else if($decimal >= .625 and $decimal < .875){ $sub = .75 - $decimal; hours = hours + $sub; } else if($decimal >= .875){ $sub = 1 - $decimal; hours = hours + $sub; } }
Here is a script that rounds the hours at the end of the day to the nearest quarter hour (PayRateScript Rule):
if(islasttoday){ $decimal = reportingdate.totalhours - cint(reportingdate.totalhours); if($decimal < .125){ hours = hours - $decimal; } else if($decimal >= .125 and $decimal < .375){ $sub = .25 - $decimal; hours = hours + $sub; } else if($decimal >= .375 and $decimal < .625){ $sub = .5 - $decimal; hours = hours + $sub; } else if($decimal >= .625 and $decimal < .875){ $sub = .75 - $decimal; hours = hours + $sub; } else if($decimal >= .875){ $sub = 1 - $decimal; hours = hours + $sub; } }
Another example would be for rounding each punch to the nearest quarter hour (.25):
$decimal = hours - cint(hours);
if($decimal < .125){ hours = hours - $decimal; } else if($decimal >= .125 and $decimal < .375){ $sub = .25 - $decimal; hours = hours + $sub; } else if($decimal >= .375 and $decimal < .625){ $sub = .5 - $decimal; hours = hours + $sub; } else if($decimal >= .625 and $decimal < .875){ $sub = .75 - $decimal; hours = hours + $sub; } else if($decimal >= .875){ $sub = 1 - $decimal; hours = hours + $sub; } else { bob = 5; }
Another example rounds the hours on a punch by punch basis. the below rounds the hours of a punch to the nearest 10th so rounds it based on a 6 minute rule (60 / 6 = 10):
$mins = val(right(hours,3)) * 60; $dmins = val(right(hours,3));
if ($mins > 00 AND $mins <= 05) {hours = hours - ($dmins - .00);} if ($mins > 05 AND $mins <= 11) {hours = hours - ($dmins - .10);} if ($mins > 11 AND $mins <= 17) {hours = hours - ($dmins - .20);} if ($mins > 17 AND $mins <= 23) {hours = hours - ($dmins - .30);} if ($mins > 23 AND $mins <= 29) {hours = hours - ($dmins - .40);} if ($mins > 29 AND $mins <= 35) {hours = hours - ($dmins - .50);} if ($mins > 35 AND $mins <= 41) {hours = hours - ($dmins - .60);} if ($mins > 41 AND $mins <= 47) {hours = hours - ($dmins - .70);} if ($mins > 47 AND $mins <= 53) {hours = hours - ($dmins - .80);} if ($mins > 53 AND $mins <= 59) {hours = hours - ($dmins - .90);}
Note: This process disregards the seconds of a punch and does it strictly by the IN and OUT minutes.
| |