function record_hours($tc)
{
    // Insert records of computed hours into temp database table.
    // Helper function for Timecard::walk().
    if ($tc->in_or_out == 1) {
        // Don't record records between the beginning of the work week and the report's begin date.
        if ($tc->end_time < $GLOBALS['tc_begin_local_timestamp']) {
            return;
        }
        if ($tc->start_time < $GLOBALS['tc_begin_local_timestamp']) {
            // Person punched in before start time of report and punched out after.
            // Adjust hours to be just those from the beginning of day.
            $start_time = $GLOBALS['tc_begin_local_timestamp'];
            $begin_hours = compute_hours($start_time, $tc->end_time);
            if ($begin_hours < $tc->overtime) {
                $overtime = $tc->overtime - $begin_hours;
                $hours = $tc->hours;
            } else {
                $overtime = 0;
                $hours - $tc->hours - ($begin_hours - $tc->overtime);
            }
        } else {
            // Normal case.
            $start_time = $tc->start_time;
            $hours = $tc->hours;
            $overtime = $tc->overtime;
        }
        if (round($hours, 3) > 0) {
            $reg_ot = 'R';
            $q_inout = mysql_real_escape_string($tc->row['inout']);
            $q_color = mysql_real_escape_string($tc->row['color']);
            $q_employee = mysql_real_escape_string($tc->row['fullname']);
            $q_name = mysql_real_escape_string($tc->row['displayname']);
            $q_group = mysql_real_escape_string($tc->row['groups']);
            $q_office = mysql_real_escape_string($tc->row['office']);
            #$date        = date('Y-m-d H:i',$start_time); ## debug
            $date = date('Y-m-d', $start_time);
            $sql = <<<End_Of_SQL
insert into t_computed_hours (hours,reg_ot,`inout`,color,hours_date,empfullname,displayname,groups,office)
values ({$hours},'{$reg_ot}','{$q_inout}','{$q_color}','{$date}','{$q_employee}','{$q_name}','{$q_group}','{$q_office}')
End_Of_SQL;
            mysql_query($sql) or trigger_error("export_display: Cannot insert regular hours into temp table. " . mysql_error(), E_USER_WARNING);
        }
        if (round($overtime, 3) > 0) {
            $reg_ot = 'O';
            $q_inout = mysql_real_escape_string($tc->row['inout']);
            $q_color = mysql_real_escape_string($tc->row['color']);
            $q_employee = mysql_real_escape_string($tc->row['fullname']);
            $q_name = mysql_real_escape_string($tc->row['displayname']);
            $q_group = mysql_real_escape_string($tc->row['groups']);
            $q_office = mysql_real_escape_string($tc->row['office']);
            #$date        = date('Y-m-d H:i',$start_time); ## debug
            $date = date('Y-m-d', $start_time);
            $sql = <<<End_Of_SQL
insert into t_computed_hours (hours,reg_ot,`inout`,color,hours_date,empfullname,displayname,groups,office)
values ({$overtime},'{$reg_ot}','{$q_inout}','{$q_color}','{$date}','{$q_employee}','{$q_name}','{$q_group}','{$q_office}')
End_Of_SQL;
            mysql_query($sql) or trigger_error("export_display: Cannot insert overtime hours into temp table. " . mysql_error(), E_USER_WARNING);
        }
    }
}
Example #2
0
function compute_day_hours($date, $start_time, $end_time)
{
    // Compute number of hours that fall within the given date.
    global $one_day;
    $start_date = date('Ymd', $start_time);
    $end_date = date('Ymd', $end_time);
    if ($start_date == $date && $end_date == $date) {
        return compute_hours($start_time, $end_time);
    }
    if ($start_date == $date) {
        $end_time = day_timestamp($start_time + $one_day) - 1;
        return compute_hours($start_time, $end_time);
    }
    if ($end_date == $date) {
        $start_time = day_timestamp($end_time);
        return compute_hours($start_time, $end_time);
    }
    return 0;
}
Example #3
0
/**
 * Current employee punch-in/out status for entry.php
 */
if (!isset($_SESSION['application'])) {
    header('Location:entry.php');
    exit;
}
require_once 'config.inc.php';
require_once 'lib.common.php';
// Configuration variables.
global $timefmt, $datefmt, $timecard_display_hours_minutes;
// Get status
list($in_or_out, $color, $inout, $timestamp, $notes) = get_employee_status($empfullname);
// Compute hours
$punch_time = local_timestamp($timestamp);
$hours = compute_hours($punch_time, local_timestamp());
$h_color = htmlentities($color);
$h_inout = htmlentities($inout);
$h_time = date($timefmt, $punch_time);
$h_date = date($datefmt, $punch_time);
if ($in_or_out == 1) {
    if ($timecard_display_hours_minutes == "yes") {
        $h_hours = hrs_min($hours);
    } else {
        $h_hours = sprintf("%01.02f", $hours);
    }
} else {
    $h_hours = '';
}
$h_notes = htmlentities($notes);
?>