header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename=' . $filename); //$headers = "Department,Last Name,First Name,Email,Earnings,Max Term Earnings,Remaining \n"; $headers = "DET,DETCode,ID,Hours,Amount,Budget,Department,Last Name,First Name,Max Term Earnings,Remaining \n"; echo $headers; $courses = get_courses($catid, 'fullname ASC', 'c.id, c.shortname'); foreach ($courses as $course) { 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;
function get_earnings_this_term($userid, $courseid) { $boundaries = get_term_boundaries($courseid); $units = get_split_units($boundaries['termstart'], $boundaries['termend'], $userid, $courseid); if (!$units) { return 0; } $round = get_rounding_config($courseid); $earnings = 0; foreach ($units as $unit) { $hours = round_time($unit->timeout - $unit->timein); $hours = round($hours / 3600, 3); $earnings += $hours * $unit->payrate; } return round($earnings, 2); }