Home      Ask a Question      My Stuff      Help   
  
Scripting - Triggering a Change based on a Day in the Pay Period
Please note, bi-weekly or 2 weeks, and weekly or 7 days are the only pay frequencies that will work with this rule.

Other pay cycles like monthly or semi-monthly may work in certain cases but due to months not having a fixed end day (28,29,30,31) which the script needs it may fail depending on what is required. With that the examples used in this article will use a fixed pay period of 14 days or a bi-weekly cycle.

Through scripting you can adjust things like pay rates, clock prompts, or job codes/categories based on the day worked in a pay period.

To do so we would first pick a variable or a name to call our process. This can be anything but in our example we will use "daynumber".

Next we pick a start date. This can be any date but should be something in the past and must be a date that starts on the first day of your pay period for example if you were on a weekly cycle with Sunday as the the start day you use a date in the past that would fall on a Sunday.

This is handled on line 1 of our example:

daynumber = DateSerial(Year,Month,Day)

So if we use Sunday as our day one example we would use a Sunday date, like January 2, 2011 or:

daynumber = DateSerial(2011,1,2)

Next we adjust our "daynumber" variable to do the counting calculation and script the amount of days we want the system to count up to based on our pay period set in "Accountant Menu > Change Pay Period / OT Rules" (weekly).

daynumber = (((daynumber \ Amount of Days) * Amount of days) - 1);)

So if we were doing a weekly period (7 days) we would do the below:

daynumber = (((daynumber \ 7) * 7) - 1);)

With the below two lines you would just need to script your "if" statements based on our variable we created "daynumber":

daynumber = punchdate - DateSerial (2011,1,2);
daynumber = daynumber - (((daynumber \ 7) * 7) - 1);

An example it says if the numbered day or in other words our variable "daynumber" equals or exceeds 5 into your pay period apply an alternate rate of the payrate in effect times 1.5:

daynumber = punchdate - DateSerial (2011,1,2);
daynumber = daynumber - (((daynumber \ 7) * 7) - 1);

if (daynumber >= 5)
{
payrate = payrate * 1.5;
}

Another example is changing the pay category/job code/pay code. In the example we still use Sunday as day 1 in a bi-weekly schedule and we make days 1-7 category "Week 1" and any days higher "Week 2".

daynumber = punchdate - DateSerial (2011,1,2);
daynumber = daynumber - (((daynumber \ 14) * 14) - 1);

if (daynumber <= 7)
{
category = "Week 1";
}
else
{
category = "Week 2";
}

So in our example if the day number is 7 or less change the pay code/job code/category to "Week 1". "Else", meaning if it is more or day number 8-14 then change it to "Week 2".

Now for a more complex example. We will do three things based on a bi-weekly pay periode again starting on Sunday (14 days):

1. Change the category like the above example (Week 1, Week 2)
2. And if it is "Week 2" change the pay rate like in our first example to payrate times 1.5.
3. And lastly we will have the x prompt display the day number to verify it is working.

daynumber = punchdate - DateSerial (2011,1,2);
daynumber = daynumber - (((daynumber \ 14) * 14) - 1);

if (daynumber <= 7)
{
category = "Week 1";
}
else
{
category = "Week 2";
payrate = payrate * 1.5;
}

x = daynumber;

To review our example we first have our two line script to count from Sunday up to 2 weeks or 14 days.

Next we have the script look for days 1-7 to change the category to "Week 1". "Else" if this is false (days 8-14) to change the category to "Week 2" and change the payrate to payrate times 1.5.

Lastly we have it put the day number in the x prompt to verify if the script is working correctly.

Below is a screen shot of all of this working on a time card with the default payrate at $10.




ID
335
Category
Training
  FAQ's
Date Created
12/11/2008 12:46:15 PM
Date Updated
9/20/2011 7:50:04 AM
Back to Search Results