Add jobs export

master
Skylar Ittner 6 years ago
parent 7e3246c6c0
commit 5aae62ddb6

@ -146,4 +146,9 @@ define("STRINGS", [
"job added" => "Job added.",
"job deleted" => "Job deleted.",
"show all" => "Show all",
"id" => "ID",
"deleted" => "Deleted",
"groups" => "Groups",
"all jobs" => "All Jobs (export)",
"include deleted" => "Include Deleted"
]);

@ -64,7 +64,7 @@ if (LOADED) {
$user = getUserByUsername($VARS['user']);
}
if (isset($VARS['type']) && isset($VARS['format'])) {
generateReport($VARS['type'], $VARS['format'], $user, $VARS['startdate'], $VARS['enddate']);
generateReport($VARS['type'], $VARS['format'], $user, $VARS['startdate'], $VARS['enddate'], $VARS['deleted'] == "1");
die();
} else {
lang("invalid parameters");
@ -241,7 +241,61 @@ function getTotalsReport($user = null, $start = null, $end = null) {
return $out;
}
function getReportData($type, $user = null, $start = null, $end = null) {
function getJobsReport($showdeleted = true) {
global $database;
$jobs = $database->select('jobs', ['jobid (id)', 'jobname (name)', 'jobcode (code)', 'color', 'deleted']);
$all_groups = [];
$client = new GuzzleHttp\Client();
$response = $client
->request('POST', PORTAL_API, [
'form_params' => [
'key' => PORTAL_KEY,
'action' => "getgroups"
]
]);
if ($response->getStatusCode() > 299) {
sendError($response->getBody());
}
$resp = json_decode($response->getBody(), TRUE);
if ($resp['status'] == "OK") {
foreach ($resp['groups'] as $g) {
$all_groups[$g['id']] = $g['name'];
}
}
$header = [lang("id", false), lang("name", false), lang("code", false), lang("groups", false)];
if ($showdeleted) {
$header[] = lang('deleted', false);
}
$out = [$header];
for ($i = 0; $i < count($jobs); $i++) {
if ($jobs[$i]["deleted"] == 1 && !$showdeleted) {
continue;
}
$groups = $database->select("job_groups", 'groupid', ['jobid' => $jobs[$i]["id"]]);
$groupnames = [];
foreach ($groups as $g) {
if ($g == -1) {
$groupnames[] = lang("all groups", false);
} else {
$groupnames[] = $all_groups[$g];
}
}
$row = [
$jobs[$i]["id"],
$jobs[$i]["name"],
$jobs[$i]["code"],
implode("|", $groupnames)
];
if ($showdeleted) {
$row[] = $jobs[$i]["deleted"] == 1 ? "X" : "";
}
$out[] = $row;
}
return $out;
}
function getReportData($type, $user = null, $start = null, $end = null, $deleted = true) {
switch ($type) {
case "shifts":
return getShiftReport($user);
@ -252,6 +306,8 @@ function getReportData($type, $user = null, $start = null, $end = null) {
case "totals":
return getTotalsReport($user, $start, $end);
break;
case "alljobs":
return getJobsReport($deleted);
default:
return [["error"]];
}
@ -388,8 +444,8 @@ STYLE
echo $out;
}
function generateReport($type, $format, $user = null, $start = null, $end = null) {
$data = getReportData($type, $user, $start, $end);
function generateReport($type, $format, $user = null, $start = null, $end = null, $deleted = true) {
$data = getReportData($type, $user, $start, $end, $deleted);
switch ($format) {
case "ods":
dataToODS($data, $type, $user, $start, $end);

@ -1,5 +1,4 @@
<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -24,10 +23,11 @@ if (!account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE") && !accou
<h3 class="panel-title"><label for="type"><i class="fa fa-list"></i> <?php lang("report type"); ?></label></h3>
</div>
<div class="panel-body">
<select name="type" class="form-control" required>
<select name="type" id="type" class="form-control" required>
<option value="shifts"><?php lang("shifts") ?></option>
<option value="punches"><?php lang("punches") ?></option>
<option value="totals"><?php lang("totals") ?></option>
<option value="alljobs"><?php lang("all jobs") ?></option>
</select>
</div>
</div>
@ -54,28 +54,39 @@ if (!account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE") && !accou
<h3 class="panel-title"><label><i class="fa fa-filter"></i> <?php lang("filter"); ?></label></h3>
</div>
<div class="panel-body">
<div class="radio">
<label>
<input name="users" value="all" checked="" type="radio"> <i class="fa fa-users fa-fw"></i>
<?php lang("all managed users") ?>
</label>
<div id="user-filter">
<div class="radio">
<label>
<input name="users" value="all" checked="" type="radio"> <i class="fa fa-users fa-fw"></i>
<?php lang("all managed users") ?>
</label>
</div>
<div class="radio">
<label>
<input name="users" value="one" type="radio"> <i class="fa fa-user fa-fw"></i>
<?php lang("one user") ?>
<div class="form-group" id="user-selection">
<input type="text" name="user" class="form-control" id="user-box" placeholder="<?php lang("choose user") ?>" />
<label class="control-label" id="user-not-managed-text" for="user-box"><i class="fa fa-warning"></i> <?php lang("not a managed user") ?></label>
</div>
</label>
</div>
</div>
<div class="radio">
<label>
<input name="users" value="one" type="radio"> <i class="fa fa-user fa-fw"></i>
<?php lang("one user") ?>
<div class="form-group" id="user-selection">
<input type="text" name="user" class="form-control" id="user-box" placeholder="<?php lang("choose user") ?>" />
<label class="control-label" id="user-not-managed-text" for="user-box"><i class="fa fa-warning"></i> <?php lang("not a managed user") ?></label>
</div>
</label>
<div id="date-filter">
<label><i class="fa fa-calendar"></i> <?php lang("date range") ?></label><br />
<div class="input-group">
<input type="text" id="startdate" name="startdate" class="form-control" />
<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
<input type="text" id="enddate" name="enddate" class="form-control" />
</div>
</div>
<hr />
<label><i class="fa fa-calendar"></i> <?php lang("date range") ?></label><br />
<div class="input-group">
<input type="text" id="startdate" name="startdate" class="form-control" />
<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
<input type="text" id="enddate" name="enddate" class="form-control" />
<div id="deleted-filter">
<div class="checkbox">
<label>
<input name="deleted" value="1" checked="1" type="checkbox"> <i class="fa fa-trash fa-fw"></i>
<?php lang("include deleted") ?>
</label>
</div>
</div>
</div>
</div>

@ -61,4 +61,27 @@ $(function () {
});
});
$('#user-not-managed-text').css('visibility', 'hidden');
$('#user-not-managed-text').css('visibility', 'hidden');
$("#type").change(function () {
switch ($("#type").val()) {
case "shifts":
$('#date-filter').hide('fast');
$('#user-filter').show('fast');
$('#deleted-filter').hide('fast');
break;
case "alljobs":
$('#date-filter').hide('fast');
$('#user-filter').hide('fast');
$('#deleted-filter').show('fast');
break;
default:
$('#date-filter').show('fast');
$('#user-filter').show('fast');
$('#deleted-filter').hide('fast');
break;
}
});
$('#date-filter').hide();
$('#deleted-filter').hide();
Loading…
Cancel
Save