if ($active) {
        //find all active workers
        $workers = $DB->get_records('block_timetracker_workerinfo', array('active' => 1, 'courseid' => $course->id));
    } else {
        //find all workers
        $workers = $DB->get_records('block_timetracker_workerinfo', array('courseid' => $course->id));
    }
    foreach ($workers as $worker) {
        $units = get_split_units($start, $end, $worker->id, $course->id);
        //don't include the ones that aren't between $start and $end
        foreach ($units as $key => $unit) {
            if (!($unit->timein >= $start && $unit->timeout <= $end)) {
                unset($units[$key]);
            }
        }
        $info = break_down_earnings($units);
        $remaining = $worker->maxtermearnings - $info['earnings'];
        if ($remaining < 0) {
            $remaining = 0;
        }
        //print_object($info);
        if ($info['regearnings'] > 0) {
            $contents = "E,Reg,{$worker->idnum}," . $info['reghours'] . ',' . $info['regearnings'] . ',' . "{$worker->budget},{$course->shortname},{$worker->lastname},{$worker->firstname}," . "{$worker->maxtermearnings},{$remaining}\n";
            echo $contents;
        }
        if ($info['ovtearnings'] > 0) {
            $contents = "E,OT,{$worker->idnum}," . $info['ovthours'] . ',' . $info['ovtearnings'] . ',' . "{$worker->budget},{$course->shortname},{$worker->lastname},{$worker->firstname}," . "{$worker->maxtermearnings},{$remaining}\n";
            echo $contents;
        }
    }
}
Example #2
0
 } else {
     if ($formdata = $mform->get_data()) {
         /*
              Look for units that straddle the pay period boundary
              TODO Check for course conflicts against submitted work units
              Create timesheet entry
              Assign all of the work units the timesheet id
              Set all of the work units canedit=0
         */
         $numunits = $DB->count_records_select('block_timetracker_workunit', 'timein BETWEEN ' . $start . ' AND ' . $end . ' OR timeout BETWEEN ' . $start . ' AND ' . $end, array('userid' => $userid, 'courseid' => $courseid, 'timesheetid' => 0));
         if ($numunits) {
             split_boundary_units($start, $end, $userid, $courseid);
             $sql = 'SELECT * FROM ' . $CFG->prefix . 'block_timetracker_workunit WHERE timein BETWEEN ' . $start . ' AND ' . $end . ' AND timeout BETWEEN ' . $start . ' AND ' . $end . ' AND userid=' . $userid . ' AND courseid=' . $courseid . ' AND timesheetid=0';
             $units = $DB->get_records_sql($sql);
             if ($units) {
                 $earnings = break_down_earnings($units);
                 if ($earnings['regearnings'] + $earnings['ovtearnings'] > 0) {
                     //Create entry in timesheet table
                     $newtimesheet = new stdClass();
                     $newtimesheet->userid = $userid;
                     $newtimesheet->courseid = $courseid;
                     $newtimesheet->submitted = 0;
                     $newtimesheet->workersignature = time();
                     $newtimesheet->reghours = $earnings['reghours'];
                     $newtimesheet->regpay = $earnings['regearnings'];
                     $newtimesheet->othours = $earnings['ovthours'];
                     $newtimesheet->otpay = $earnings['ovtearnings'];
                     $timesheetid = $DB->insert_record('block_timetracker_timesheet', $newtimesheet);
                     foreach ($units as $unit) {
                         $unit->timesheetid = $timesheetid;
                         $unit->canedit = 0;
Example #3
0
/**
* Also calculates overtime (Weeks > 40 hours Mon-Sun)
* @return earnings (in dollars) for this time period
*
*/
function get_earnings($userid, $courseid, $start, $end, $processovt = 1)
{
    global $DB;
    $units = get_split_units($start, $end, $userid, $courseid);
    if (!$units) {
        return 0;
    }
    $info = break_down_earnings($units, $processovt);
    return $info['earnings'];
}