So, we have a table, called timePunches:
CREATE TABLE `timePunches` (
`punchID` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'The unique ID of the punch',
`employeeID` VARCHAR(50) NOT NULL COMMENT 'Who did the punch',
`punchDATETIME` DATETIME NOT NULL COMMENT 'The time of the punch',
`punchDTC_LINK` DATETIME NULL DEFAULT NULL COMMENT 'The previous start time for the OUT punch',
`punchDATECRC` INT(100) NOT NULL COMMENT 'The punch CRC, to prevent hacking',
`punchDIRECTION` TINYTEXT NOT NULL COMMENT 'What the punch did',
`punchTOTAL` INT(11) NULL DEFAULT NULL,
`fullName` TEXT NULL,
PRIMARY KEY (`punchID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
ROW_FORMAT=DYNAMIC
AUTO_INCREMENT=15825
This table is used for tracking punch times from our employees. Meaning, we track when they punch in and punch out. This table is an audit compliance table, meaning that we do not SELECT/UPDATE records, instead, we SELECT/INSERT them only.
So, this is what happens when a user punches the clock:
-
PUNCH IN: Application sends
employeeID(string),punchDATETIME(DateTime),punchDATECRC(int) andpunchDTC_LINK(DateTime [null]) to the database via a stored procedure. This stored procedure adds the necessary information to the database, to include triggering an internal function to pull the full name of the user into the same table. -
PUNCH OUT: Application sends
employeeID(string),punchDATETIME(DateTime),punchDATECRC(int) andpunchDTC_LINK(DateTime) to the database. The stored procedure adds the necessary information, including the trigger to do the math between bothDateTimeelements, and fill out the legal name.
As we can see from the above, when the user punches IN, the query looks kind of like this:
INSERT INTO
timePunches(punchID,employeeID,punchDATETIME,punchDTC_LINK,punchDATECRC,punchDIRECTION,punchTOTAL) VALUES (15797, ‘prumple’, ‘2012-01-11 17:35:10’, NULL, -2011509138, ‘IN’, NULL);
And, when the user punches out, it sends something like this:
INSERT INTO
timePunches(punchID,employeeID,punchDATETIME,punchDTC_LINK,punchDATECRC,punchDIRECTION,punchTOTAL) VALUES (15797, ‘prumple’, ‘2012-01-11 19:39:52’, ‘2012-01-11 17:35:10’, -2011509138, ‘OUT’, NULL);
So, as we can see, there are 2 elements in the DataTable for this user. One IN and one OUT.
What I need to do, is find out if the user has forgotten to punch OUT. So, let’s say that a user punches IN, works all the day long, closes their punch clock w/o clocking out, and then the next day punches IN again. HE then works his full shift, and remembers to punch out this time.
Now, for that situation, we have 2 IN punches, and only 1 OUT punch. I need a way to detect this.
If I understand correctly, an ‘IN’ record’s corresponding ‘OUT’ record will match on
employeeID(the punch is for the same employee) and the ‘IN’DATETIMEwill match the ‘OUT’DTC_LINK.