199 lines
5.0 KiB
PHP
199 lines
5.0 KiB
PHP
<?php
|
|
session_start();
|
|
require_once('./../admin/tcpdf/tcpdf.php');
|
|
require_once("inc/config.inc.php");
|
|
require_once("inc/functions.inc.php");
|
|
|
|
// Überprüfen, ob eine Benutzer-ID in der Session vorhanden ist
|
|
if (!isset($_SESSION['userid'])) {
|
|
die("Kein Benutzer angemeldet.");
|
|
}
|
|
|
|
$user_id = $_SESSION['userid'];
|
|
$user = check_user();
|
|
|
|
if (!is_admin_user()) {
|
|
die("Keine Rechte fuer diese Ansicht.");
|
|
}
|
|
|
|
?>
|
|
|
|
<?php include 'header.php'; ?>
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
|
<h2 class="mb-4">Zeitbuchungsfehler Auswertung</h2>
|
|
|
|
<?php if (!empty($_SESSION['time_error_close_result'])): ?>
|
|
<?php $closeResult = $_SESSION['time_error_close_result']; unset($_SESSION['time_error_close_result']); ?>
|
|
<div class="alert alert-<?php echo htmlspecialchars($closeResult['type'], ENT_QUOTES, 'UTF-8'); ?>" role="alert">
|
|
<?php echo htmlspecialchars($closeResult['message'], ENT_QUOTES, 'UTF-8'); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
|
|
// Benutzer aus der Datenbank erhalten
|
|
try {
|
|
$users_stmt = $pdo->prepare("SELECT id,vorname, nachname FROM users WHERE zeiterfassung='1' ORDER BY nachname ASC");
|
|
$users_stmt->execute();
|
|
$users = $users_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
|
|
|
|
foreach($users AS $user){
|
|
|
|
|
|
try {
|
|
// Holen Sie die fehlerhaften Zeitbuchungen des Mitarbeiters aus der Datenbank
|
|
$query = "
|
|
SELECT
|
|
DATE(timestamp_datetime) as datum,
|
|
SUM(CASE WHEN timestamp_type = 'KOMMEN' THEN 1 ELSE 0 END) as kommen_count,
|
|
SUM(CASE WHEN timestamp_type = 'GEHEN' THEN 1 ELSE 0 END) as gehen_count
|
|
FROM
|
|
timestamps
|
|
WHERE
|
|
employee_id = :employee_id
|
|
GROUP BY
|
|
DATE(timestamp_datetime)
|
|
HAVING
|
|
kommen_count != gehen_count";
|
|
|
|
$stmt = $pdo->prepare($query);
|
|
$stmt->bindParam(':employee_id', $user["id"], PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$fehlerhafteTage = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
|
|
|
|
try {
|
|
$query2 = "
|
|
SELECT
|
|
DATE(timestamp_datetime) AS datum,
|
|
GROUP_CONCAT(timestamp_type ORDER BY timestamp_datetime) AS day_sequence
|
|
FROM
|
|
timestamps
|
|
WHERE
|
|
employee_id = :employee_id
|
|
GROUP BY
|
|
DATE(timestamp_datetime);";
|
|
|
|
$stmt = $pdo->prepare($query2);
|
|
$stmt->bindParam(':employee_id', $user["id"], PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$result = $stmt->fetchAll();
|
|
|
|
$invalidDates = [];
|
|
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
|
|
|
|
try {
|
|
$query1 = "
|
|
SELECT
|
|
vorname,
|
|
nachname
|
|
FROM
|
|
users
|
|
WHERE
|
|
id = :employee_id
|
|
ORDER BY
|
|
nachname
|
|
";
|
|
|
|
$stmt = $pdo->prepare($query1);
|
|
$stmt->bindParam(':employee_id', $user["id"], PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$userdaten = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch(PDOException $e) {
|
|
echo "Datenbankfehler: " . $e->getMessage();
|
|
}
|
|
|
|
|
|
foreach ($userdaten as $usertag){
|
|
echo "<h5>" . $usertag["vorname"] . " " . $usertag["nachname"] . "</h5>";
|
|
|
|
}
|
|
|
|
|
|
foreach ($result as $row) {
|
|
if (!isValidSequence($row["day_sequence"])) {
|
|
$invalidDates[] = $row["datum"];
|
|
}
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?php if (!empty($invalidDates)): ?>
|
|
<form action="closeEmployeeTimeErrors.php" method="post" class="form-inline mb-3">
|
|
<input type="hidden" name="employee_id" value="<?php echo (int)$user['id']; ?>">
|
|
<label class="mr-2" for="hours_to_close_<?php echo (int)$user['id']; ?>">Fehlbuchungen automatisch schliessen mit</label>
|
|
<input
|
|
type="number"
|
|
step="0.25"
|
|
min="0.25"
|
|
class="form-control mr-2"
|
|
id="hours_to_close_<?php echo (int)$user['id']; ?>"
|
|
name="hours_to_close"
|
|
value="8"
|
|
required
|
|
>
|
|
<span class="mr-2">Stunden</span>
|
|
<button type="submit" class="btn btn-primary">Alle schliessen</button>
|
|
</form>
|
|
|
|
<table class="table table-striped">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Datum</th>
|
|
<th>Fehler</th>
|
|
<th>Aktionen</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($invalidDates as $date): ?>
|
|
<tr>
|
|
<td><?php echo date('d.m.Y', strtotime($date)); ?></td>
|
|
<td>Fehlerhafte Daten</td>
|
|
<td>
|
|
<a href="editDayEntries.php?employee_id=<?php echo $user['id']; ?>&datum=<?php echo $date; ?>" class="btn btn-warning">Anpassen</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php else: ?>
|
|
<div class="alert alert-info" role="alert">
|
|
Keine Zeitbuchungsfehler gefunden.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
|
|
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include 'footer.php'; ?>
|