Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Payroll formula that selects lunch punches Post Reply Post New Topic
Author Message
sparkypine
Newbie
Newbie


Joined: 27 Jan 2009
Online Status: Offline
Posts: 2
Quote sparkypine Replybullet Topic: Payroll formula that selects lunch punches
     Posted: 27 Jan 2009 at 9:06am
I wrote a report that displays employees' punch details for each day of the week of a given pay period.  I need to calculate how long they took for their lunch, if they took a lunch, not everyone does.  I figured out how to determine if someone took a lunch but now I'm stuck on how to isolate the "out" punch for lunch and then the "in" punch from lunch. 

There are two tables involved:
{V_TA_PREPOST.START_TIME} and
{V_TA_PREPOST.END_TIME}

If someone takes a lunch their punches for the day would look like so:

   in                                out
7:00 am                      11:30 am
12:00 pm                     3:00 pm

I need to subtract 11:30 am from 12:00 pm and show the minutes taken for lunch.  I'm stuck because I can not figure out how to say, "Take the first out punch and subtract it from the second in punch."

I've looked at arrays, count, etc., but this is out of my league.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 28 Jan 2009 at 7:21am
Since they are in different data rows, I would use shared variables in a formula.  There would be a couple formulae.  1 would reset the variable at the change of a group (probably an employee's id and date) and 1 to calculate the time difference.
 
The calculate formula would look something like:
shared numbervar timeOut;
local numbervar lunch := 0;
 
if timeOut = 0 then
  timeOut := {timeout field}
else
  lunch := {timein field} - timeOut;
 
if lunch > 0 then
  lunch
else
  0
 
 
You should be able to sum this, if not, it is just another shared variable to calculate the total lunch times...there is much that can be done, but this is the basis.
 
Hope it helps
 
 
 
IP IP Logged
sparkypine
Newbie
Newbie


Joined: 27 Jan 2009
Online Status: Offline
Posts: 2
Quote sparkypine Replybullet Posted: 28 Jan 2009 at 10:04am
Thanks for the reply lockwelle.

These punch times are already in a subreport.  I have a subreport for each day of the week, grouped by employee.  The times that populate the "in" and "out" punch are sequenced based on when the employee hits the clock.

I was hoping to find a way to answer the business rule of: "if there are 4 punches in that group, subtract the two middle ones from each other"  Which would effectively give me the amount of time I'm after.  I figured out how to "count" the number of punches to determine if someone took a lunch.  I just need to figure out how to tell Crystal to subtract the middle two punches.  This formula flags the condition where there are 4 punches for that person for that day:

If DistinctCount ({V_TA_PREPOST.START_TIME})= 2 and DistinctCount ({V_TA_PREPOST.END_TIME})= 2 then "1"

Else ""

Is it possible to use that string in formula called something like "lunchflag" and then create another formula that says something like:

If @lunchflag = 1 then  "subtract the middle two punches"

It's the "subtract the middle two punches" part that I'm not certain about as far as how to syntax a formula.  

Edited by sparkypine - 28 Jan 2009 at 10:15am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum