Add job history report

This commit is contained in:
Skylar Ittner 2018-01-06 21:44:00 -07:00
parent 5aae62ddb6
commit 044fcd987a
3 changed files with 56 additions and 5 deletions

View File

@ -295,19 +295,69 @@ function getJobsReport($showdeleted = true) {
return $out; return $out;
} }
function getJobHistoryReport($user = null, $start = null, $end = null) {
global $database;
global $allowed_users;
$where = [];
if ((bool) strtotime($start) == TRUE) {
$where["OR #start"] = [
"start[>=]" => date("Y-m-d", strtotime($start)),
"end[>=]" => date("Y-m-d", strtotime($start))
];
}
if ((bool) strtotime($end) == TRUE) {
// Make the date be the end of the day, not the start
$where["start[<=]"] = date("Y-m-d", strtotime($end)) . " 23:59:59";
}
if ($user != null && array_key_exists('uid', $user) && ($allowed_users === true || in_array($user['uid'], $allowed_users))) {
$where["uid"] = $user['uid'];
} else if ($user != null && array_key_exists('uid', $user) && $allowed_users !== true && !in_array($user['uid'], $allowed_users)) {
$where["uid"] = -1;
} else {
if ($allowed_users !== true) {
$where["uid"] = $allowed_users;
}
}
if (count($where) > 1) {
$where = ["AND" => $where];
}
$jobs = $database->select(
"job_tracking", [
"[>]jobs" => ["jobid" => "jobid"]
], [
"jobs.jobid", "uid", "start", "end", "jobname", "jobcode"
], $where
);
$header = [lang("name", false), lang("job", false), lang("code", false), lang("start", false), lang("end", false)];
$out = [$header];
$usercache = [];
for ($i = 0; $i < count($jobs); $i++) {
if (!array_key_exists($jobs[$i]["uid"], $usercache)) {
$usercache[$jobs[$i]["uid"]] = getUserByID($jobs[$i]["uid"]);
}
$out[] = [
$usercache[$jobs[$i]["uid"]]["name"] . " (" . $usercache[$jobs[$i]["uid"]]["username"] . ")",
$jobs[$i]['jobname'],
$jobs[$i]['jobcode'],
date(DATETIME_FORMAT, strtotime($jobs[$i]['start'])),
(is_null($jobs[$i]['end']) ? "" : date(DATETIME_FORMAT, strtotime($jobs[$i]['end']))),
];
}
return $out;
}
function getReportData($type, $user = null, $start = null, $end = null, $deleted = true) { function getReportData($type, $user = null, $start = null, $end = null, $deleted = true) {
switch ($type) { switch ($type) {
case "shifts": case "shifts":
return getShiftReport($user); return getShiftReport($user);
break;
case "punches": case "punches":
return getPunchReport($user, $start, $end); return getPunchReport($user, $start, $end);
break;
case "totals": case "totals":
return getTotalsReport($user, $start, $end); return getTotalsReport($user, $start, $end);
break;
case "alljobs": case "alljobs":
return getJobsReport($deleted); return getJobsReport($deleted);
case "jobs":
return getJobHistoryReport($user, $start, $end);
default: default:
return [["error"]]; return [["error"]];
} }

View File

@ -27,6 +27,7 @@ if (!account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE") && !accou
<option value="shifts"><?php lang("shifts") ?></option> <option value="shifts"><?php lang("shifts") ?></option>
<option value="punches"><?php lang("punches") ?></option> <option value="punches"><?php lang("punches") ?></option>
<option value="totals"><?php lang("totals") ?></option> <option value="totals"><?php lang("totals") ?></option>
<option value="jobs"><?php lang("jobs") ?></option>
<option value="alljobs"><?php lang("all jobs") ?></option> <option value="alljobs"><?php lang("all jobs") ?></option>
</select> </select>
</div> </div>

View File

@ -58,7 +58,7 @@ redirectifnotloggedin();
<th data-priority="1"><?php lang('actions'); ?></th> <th data-priority="1"><?php lang('actions'); ?></th>
<th data-priority="1"><i class="fa fa-fw fa-briefcase hidden-xs"></i> <?php lang('job'); ?></th> <th data-priority="1"><i class="fa fa-fw fa-briefcase hidden-xs"></i> <?php lang('job'); ?></th>
<th data-priority="2"><i class="fa fa-fw fa-play hidden-xs"></i> <?php lang('start'); ?></th> <th data-priority="2"><i class="fa fa-fw fa-play hidden-xs"></i> <?php lang('start'); ?></th>
<th data-priority="2"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('stop'); ?></th> <th data-priority="2"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('end'); ?></th>
<th data-priority="3"><i class="fa fa-fw fa-user hidden-xs"></i> <?php lang('user'); ?></th> <th data-priority="3"><i class="fa fa-fw fa-user hidden-xs"></i> <?php lang('user'); ?></th>
</tr> </tr>
</thead> </thead>
@ -71,7 +71,7 @@ redirectifnotloggedin();
<th data-priority="1"><?php lang('actions'); ?></th> <th data-priority="1"><?php lang('actions'); ?></th>
<th data-priority="1"><i class="fa fa-fw fa-briefcase hidden-xs"></i> <?php lang('job'); ?></th> <th data-priority="1"><i class="fa fa-fw fa-briefcase hidden-xs"></i> <?php lang('job'); ?></th>
<th data-priority="2"><i class="fa fa-fw fa-play hidden-xs"></i> <?php lang('start'); ?></th> <th data-priority="2"><i class="fa fa-fw fa-play hidden-xs"></i> <?php lang('start'); ?></th>
<th data-priority="2"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('stop'); ?></th> <th data-priority="2"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('end'); ?></th>
<th data-priority="3"><i class="fa fa-fw fa-user hidden-xs"></i> <?php lang('user'); ?></th> <th data-priority="3"><i class="fa fa-fw fa-user hidden-xs"></i> <?php lang('user'); ?></th>
</tr> </tr>
</tfoot> </tfoot>