TimeWorksPlus Knowledge Base

Accrual Scripting - Introductory Scripts

Last Updated: Jun 24, 2016 01:03PM MDT

Basic Accrue Scripts

These are some scripting examples for common and basic accrual policies. Each script example will be preceded with a "plain English" description of the policy. There will also be line comments (notes preceded by a “//”) within each script that explain the purpose of each line.

This article is designed to orient you to how Accrual scripts work. If you are looking for more detailed script examples for different policies, please see additional articles on accrual scripting in this topic. 

If you need more basic, background information on our accruals, please see Accruals - Getting Started.  

AccrueUp Scripting

Accruals are incremented with an accrueup script. This script uses the accrueup function and takes 5 pieces of data (or arguments) for defining the rules of the accrual.
This is how accrueup is scripted, with a label used to describe each argument.

accrueup("category name", accrual amount, accrual max, vesting date, expiration date);
Technically, only category name and accrual amount are required. The rest of the values could be left blank or have a "" put in as a placeholder.

Also, category name has to be surrounded in quotes.

Accrual max does not refer to an annual max, but rather, a cap that, once reached, turns off the accrual until the employee’s balance has dropped below the cap. So if an employee earns additional time due to a bonus or a carryover, the accrual max will prevent them from earning any additional time beyond the defined, max limit.

Vesting date generally applies to new hires who may earn time starting from the date of hire, but are not allowed to use paid leave until they reach a certain date. This can be set to a set number of days past the employee’s hire date as you will see in the examples below.

Expiration date applies if there is no carryover and the client has a “use it or lose it” policy.

 Annual AccrueUp Script

This script is an example of a script that runs once a year on January 1st for employees that earn their PTO in one lump sum. This script will:
  • Accrue PTO on the first of every year starting on January 1 of 2012
  • Don't let the employee accrue more than their annual amount
  • Expire any unused hours on the 31st of December
  • Accrue in the amount of:
    • 120 hours for employees with 5 years or more of service
    • 80 hours for employees with 2 years of more of service, but less than 5 years of service
    • 40 hours for employees with less than 2 years of service
if(reportingdate.date >= "2012-01-01"){     
//this means the script won’t run prior to Jan. 1 of 2012
   if(reportingdate.date == dateserial(reportingdate.year,1,1)){
   //this instructs to script to run on the 1st of January every year
       if(employee.yearsofservice >= 5){
       //start with employees with 5 or more years of service
           accrueup("PTO", 120, 120, "", dateserial(reportingdate.year,12,31));                  //accrue 120 hours of PTO with a limit of 120 hours that expires on 12/31 of the current year
       }else if(employee.yearsofservice >= 2){
           accrueup("PTO", 80, 80, "", dateserial(reportingdate.year,12,31));
       }else if (employee.yearsofservice >= 0){
           accrueup("PTO", 40, 40, "", dateserial(reportingdate.year,12,31));
       else{$donothing = 0;}

It would go in the AccrueUp Script bottom box because it runs once per time card line, regardless of whether there is punch activity on the day.

Accrue Highest to Lowest!
You’ll notice that the script starts with employees with more seniority (5 years)and works its way backwards to those with less (under 2 years). Since most companies provide different amounts of vacation based on tenure, this script can be easily modified to account for different threshold. Because it uses an “if…else if” method, the script will keep running through each threshold, from highest to lowest, until it finds one that matches the employee.

Allowing for Annual Carryover

If your client has an accrual policy that allows for a certain amount of unused paid leave to be carried over to the next year, you can use a script similar to this script that allows an employee to carry over up to 40 hours per year on December 31st.
In order for an accrual carryover like this to work:
  • The AccrueUp script cannot have an expiration date
  • The AccrueUp script must have an Accrual Max that allows for an employee to have more than 40 hours over their annual amount.
The policy this script will follow is:
  • If employees have unused Vacation time at the end of the calendar year, they can carryover up to 40 hours into the next year.

if(reportingdate.date = dateserial(reportingdate.year,1,1) and getbalance("Vacation") > 40){
//check to see if it is Jan. 1 of the current year and if the employee has more than 40 hours of Vacation left
            $subtract = getbalance("Vacation") - 40;
            //create a variable called $subtract that calculates the hours in excess of 40
            accruedown("Vacation", $subtract);
            //reduce the Vacation bucket by the amount of excess

First, you will note that the script runs on January 1st instead of December 31st. The reason is that this allows the employee to still use their balance on December 31st if desired. By putting this script in the AccrueUp bottom script box before the AccrueUp script , the sequence of events on January 1 will be:
  • reduce the employees hours if they are in excess of 40
  • add their annual vacation amount for the new year

Using the Accrual Factor Field from Employee Setup

In the Accruals category of the Processing Rules page is an option to turn on the AccrualFactor rule. This will turn on a field in Employee Setup that can be referenced when deciding how much time the employee earns. This can be a useful tool for employees that earn an amount outside of the general accrual policy.

AccrualFactor can also be used in addition to a standard accrual script, but it is important to make sure something in Employee Setup excludes the employee from the standard policy otherwise, they may double accrue.

This script will:
  • Implement a policy starting on Jan. 1 of 2012
  • Only apply this policy to employees with "Accrue" in their Home 3 field
  • Accrue PTO on the last day of the pay period
  • Use the value in the AccrualFactor field for the pay period amount

if (reportingdate.date >= "2012-01-01") {    
     if(employee.home3 = "Accrue"){
     //run script only on employees with Accrue in Home 3 
            if (reportingdate.date == reportingdate.payperiodend) {     
            //accrue only on the last day of the pay period
                   accrueup("PTO", employee.accrualfactor, (employee.accrualfactor * 26));
                  //accrues up by the amount in the accrual factor field of employee setup
                 //limits the accrual max to an annual amount that is 26 times the accrual factor

So instead of having an accrual amount defined in the script itself, your client has the option to set an amount per employee through Employee Setup. 

Basic AccrueDown Script

In addition to a script that increments an accrual bucket, you will also need a script that diminishes an accrual bucket when an employee uses time. The purpose of this script is to recognize a punch category on the time card that corresponds to an accrual bucket and diminish that bucket, i.e. 8 hours of Vacation on the time card decreases the Vacation accrual balance by 8 hours.
This script runs after the AccrueUp script, so if an employee earns time on the same day that they use time, it will be added to their available balance before the accrue down script deducts from the balance.
The accruedown function works with 3 arguments:
  • an accrual category name
  • an amount to reduce
  • a limit
This script will:
  • reduce a PTO balance starting on Jan. 1 of 2012
  • limit the balance deduction to 0 hours, the employee can't go negative
if (category = "PTO" and reportingdate.date >= "2012-01-01") {
//this makes sure the deduction is only made if the category on the time card is “PTO”
    AccrueDown("PTO",hours, 0);
    //this accrues down PTO in the amount of "hours" entered on the time card, with a limit of 0

In this case, the AccrueDown script diminishes the PTO bucket by how ever many hours are entered on the time card for that day, in the category of "PTO".

With the lower limit set to “0”, if the employee does not have enough PTO hours available, it will only deduct as many hours as it takes to reach 0. However, the employee will still be paid for those hours in excess of their balance. Most client would prefer to either
  • unpay any hours taken in excess of the employees balance
  • allow the employee to go negative on their balance and earn the time back through subsequent accruals. Below are examples of each.
The following script explains how to unpay hours in excess of the balance.

AccrueDown - Unpaid Hours

if(category = "PTO" and reportingdate.date >= "2012-01-01"){
    $shortfall = AccrueDown("PTO",hours, 0);

This script limits the reduction of the PTO bucket to a 0 balance, however, it also takes the remainder and adds it to a variable called $shortfall. That amount in $shortfall is then unpaid using the last line of the script.

AccrueDown - Allow Negative Balance

if(category = "PTO" and reportingdate.date >= "2012-01-01") {
            AccrueDown("PTO",hours, "");

In this script, we are allowing employees to go negative on their balance with the idea that future accruals will be used to return the balance to the plus side. In this case, we use a simple AccrueDown script, but instead of the third argument being "0", we leave it blank, which will allow employees to go infinitely negative. 
  • Get More in Support Center

    Swipeclock partners can submit cases to technical support and view additional articles in Support Center.

    Your accountant login to TimeWorksPlus is required to access Support Center.
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
Invalid characters found