added shiftcount

This commit is contained in:
2019-07-02 12:37:21 +02:00
parent e78aad9db7
commit 9cb38e0f00

View File

@@ -36,7 +36,8 @@ uasort($worklists, function($a, $b) {
return $a[1] > $b[1] ? -1 : 1;
});
$all_names = [];
$nameCount = [];
$nameHours = [];
$totalShifted = 0;
$total = 0;
$checkedLists = [];
@@ -80,10 +81,15 @@ if (isset($_GET['worklist']) || count($checkedLists) > 0) {
preg_match_all('/<span.*?>(.*?)<\/span>/s', $blockNames[1][0], $names);
foreach ($names[1] as $name) {
if (!array_key_exists($name, $all_names)) {
$all_names[$name] = $diff;
if (!array_key_exists($name, $nameCount)) {
$nameCount[$name] = 1;
} else {
$all_names[$name] += $diff;
$nameCount[$name] += 1;
}
if (!array_key_exists($name, $nameHours)) {
$nameHours[$name] = $diff;
} else {
$nameHours[$name] += $diff;
}
$totalShifted += $diff;
}
@@ -93,8 +99,8 @@ if (isset($_GET['worklist']) || count($checkedLists) > 0) {
}
$avg = 0;
if ($totalShifted !== 0 & count($all_names) !== 0)
$avg = $totalShifted / count($all_names);
if ($totalShifted !== 0 & count($nameHours) !== 0)
$avg = $totalShifted / count($nameHours);
?>
@@ -119,7 +125,7 @@ if ($totalShifted !== 0 & count($all_names) !== 0)
<div class="text-center">
<h1>Wina shift counter</h1>
<form class="mb-2" method="get">
<select name="worklist[]" class="selectpicker" data-style="btn-primary" data-live-search="true" multiple>
<select name="worklist[]" class="selectpicker" data-style="btn-primary" data-live-search="true" multiple>
<?php
foreach($worklists as $key => $list) {
echo "<option " . (in_array($key, $checkedLists) ? "selected " : '') . "value='$key'>" . $list[0] . ' ' . $list[1]->format('d/m/Y') . "</option>";
@@ -154,12 +160,13 @@ if ($totalShifted !== 0 & count($all_names) !== 0)
<tr>
<th scope="col">Naam</th>
<th scope="col">Uren</th>
<th scope="col">Shiften</th>
</tr>
</thead>
<tbody>
<?php
foreach ($all_names as $name => $val) {
echo "<tr><td data-order='$name'>$name</td><td data-order='$val'>" . floor($val) . 'h ' . ($val - floor($val)) * 60 . 'min' . "</td></tr>";
foreach ($nameHours as $name => $val) {
echo "<tr><td data-order='$name'>$name</td><td data-order='$val'>" . floor($val) . 'h ' . ($val - floor($val)) * 60 . 'min' . "</td><td>" . $nameCount[$name] . "</td></tr>";
}
?>
@@ -183,7 +190,7 @@ if ($totalShifted !== 0 & count($all_names) !== 0)
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript">
$(document).ready( function () {
$(document).ready(function() {
let table = $('#table').DataTable({
buttons: [
'copy', 'csv', 'excel'
@@ -197,8 +204,7 @@ if ($totalShifted !== 0 & count($all_names) !== 0)
$('form').submit();
});
$('.input-daterange').datepicker({
});
$('.input-daterange').datepicker();
</script>
</body>
</html>