Home      Ask a Question      My Stuff      Help   
  
Scripting - Auto Lunches
Question
ID
522
Category
<Unassigned>
Date Created
2/16/2011 8:08:15 AM
Date Updated
5/3/2022 9:35:43 AM
Is there way to do auto deductions for things like breaks and lunches using a script?
Answer
Yes there is. BUT you are still under the same limitations as the feature "Auto-Lunch" which are:

==TimeWorks==

1. It has to be calculated against a CONTINUOUS amount of hours worked.
2. It will remove the time off of the total hours for the punch. It will not adjust in/out times.
3. You will still need to specify the deduction amount and at what amount of hours worked they will have to do before the deduction takes place.

An additional draw back of using the script is it will do the deduction but will not have any default indicators of it doing such besides the times and total hours not matching up unless told to do so which we will go over also with our example script.

Some of the pluses of using this is:

1. It will work with the rest of the scripting keywords and processes we have so for example:

2. You can have it work only on certain days or have it change depending on the day as opposed to the Auto-Lunch feature which is a either on/off regardless of the day.

3. You can also have the script react in different ways depending on the amount of hours worked. For example if they got a 15 minute break after 2 hours of work but also got an additional 30 minutes break if they worked at or over 4 hours. We can make the script at the 2 hours mark do a 15 minute deduction then at the 4 hour mark we can have another script overwrite the earlier script and give them a 45 minute (a 15 minute at the 2 hours mark + a 30 minute break at the 4 hour mark) deduction instead.

4. It is retro, meaning it will affect all punches with the exclusion of punches that have been frozen.

Below is an example of a basic script for doing this. In the example if the system sees that a punch spans to or over 5 hours deduct 30 minutes or .5 hours off of the total hours worked for that punch:

if (hours >= 5)
{
hours = hours - .50;
}

A screen shot of this is below working on a 6 hour punch:




Another example below does have an indicator built in but it does requires a variable (in our example that is "a") and a job code prompt to display the indicator for the deduction.

This still uses the above example of a 30 minute deduction at or after 5 hours of continuous work but using a job code prompt and variable (a) we can script a message to the effect of if the employee worked say 6 hours "30 Minute Break / Actual Hours Worked = 6.0" and his hours total will say 5.5.

if (hours >= 5)
{
a = hours;
y = hours - .50;
x = ("30 Minute Break / " + "Actual Hours Worked = ") + a;
hours = y;
y = "";
}

An example screen shot of this is below:




==TimeWorks Plus==

In TimeWorks Plus we can also adjust the Break column to reflect the deduction in addition to deducting from their hours worked.

Here is an example of this using the threshold of (greater than) 5 hours and deducting 30 minutes for the break which you put under Settings Menu > Processing Rules > PayRateScript:

if(istimes and category = "Regular" and hours > 5){
breakseconds = 1800;
hours = hours - .50;
}

One of the advantages of using this instead of the "Auto-Lunch" Processing Rule is that the script will run AFTER any rounding of the employees time. Without this the employee could be rounded back to before the threshold but the rule would look at the actual unrounded time and still trigger.

Here is one that accounts for different lengths of breaks based on how many hours the employee works. If more than 6 hours but less than 7 then it is it a 30 minute break. If worked hours are more than or equal to 7 hours then it is a 1-hour break. If they work less than 6 hours no time is deducted:


if(reportingdate.totalhours > 6 and reportingdate.totalday("breakseconds") <= 0){

if(reportingdate.totalhours >= 7){
breakseconds = 3600;
hours = hours - (breakseconds / 3600);
}

if (reportingdate.totalhours < 7){
breakseconds = 1800;
hours = hours - (breakseconds / 3600);
}

}

Scripting (Main Page) > Scripting - Breaks & Lunches (Main Page)
Back to Search Results