I have a function on my site that allows users to clock in and clock out. I then have a report function that prints out like a timecard for them. I have an issue though, I need a way to manually enter a timestamp in case the employee misses a punch. The way I have been calculating time work is on every clock "Out" I would calculate the number of minutes since last clock "In" and put that total number of minutes in the database. Then on the report I just totalled the minutes in that row between the 2 dates the user selects. But I can't do this when you enter a manual timestamp, and I can't think of how to accomplish this task. Was wondering if someone had any suggestions.

My table example...

ID Employee Timestamp In/Out

1 Jerry 12345678 In
1 Jerry 12345679 Out
1 Jerry 12345680 In
1 Jerry 12345681 Out

Here is the current code I use to calculate the timecard, but using precalculated minutes in the database, since I calculate them on every clock Out right now...

<?php
if($_POST['report'] == "time")

   {
	   ?>
       <table border="1">
<tr><th>Date/Time</th><th>Punched</th></tr>
<?php
  				$date1 = mysql_escape_string($_POST['Date1']);
				$date2 = mysql_escape_string($_POST['Date2']);
				$date1 = strtotime($date1);
				$date2 = strtotime($date2);
				$newdate1= date('Y-m-d', $date1);
				$newdate2= date('Y-m-d', $date2);
				$time2 = " 00:00:01";
				$time = " 23:59:59";
				$date3 = $newdate2 . $time;
				$date4 = $newdate1 . $time2;
				$employee = $_SESSION['SESS_MEMBER_ID'];

		$query="SELECT Clock, Time FROM timeclock WHERE Employee = '$employee' AND Time BETWEEN '$date4' AND '$date3'";
		$result = mysql_query($query);
	while($myrow = mysql_fetch_assoc($result)) 
         { 
		 $convertime = strtotime($myrow['Time']);
		 $convertime = date("l, m/d/Y, g:i a ", $convertime)
?>
<tr><td><?php echo $convertime; ?></td><td><?php echo $myrow['Clock']; ?></td></tr>
<?php
			 }
			 $fquery="SELECT SUM(MinutesClock) AS MinutesClock FROM timeclock WHERE Employee = '$employee' AND Clock = 'Out' AND Time BETWEEN '$date4' AND '$date3' ";
			$fresult = mysql_query($fquery);
	while($myfrow = mysql_fetch_assoc($fresult))
	{

$min2hours=$myfrow['MinutesClock'];
$printhours = m2h($min2hours);
$finalhours = explode('.', $printhours);
?>
<tr><th>Total Time Worked: <?php echo $finalhours[0];?> Hours <?php echo $finalhours[1];?> Minutes</th></tr>
</table>
<a class="button" target="_blank" href="fpdftest.php?ID=<?php echo $employee;?>&Date=<?php echo $date4;?>&Date2=<?php echo $date3;?>" onClick="this.blur();"><span>Export to PDF</span></a><br /><br /><br />
		<?php
	}
?>
    Write a Reply...