Mitarbeiter ohne Buchungen löschbar machen
This commit is contained in:
parent
e3d328f55a
commit
672df3d0a7
7 changed files with 58 additions and 4 deletions
|
|
@ -33,6 +33,7 @@ Die Anforderungen stammen aus
|
|||
- **Buchungen verwalten**: anlegen, bearbeiten, per Drag & Drop verschieben,
|
||||
anderen Anhänger oder Mitarbeiter zuordnen, stornieren, wiederherstellen und
|
||||
nach Kundenname suchen.
|
||||
- **Mitarbeiter verwalten**: anlegen, umbenennen, sortieren, deaktivieren und löschen. Löschen ist nur ohne Buchungen möglich; sonst bleibt der Mitarbeiter deaktivierbar. Mindestens ein aktiver Mitarbeiter muss erhalten bleiben.
|
||||
- **Benutzerverwaltung** wie bei tippspiel2027: Konten werden ausschließlich
|
||||
vom Administrator angelegt. Anmeldung mit Vorname, Nachname und Passwort;
|
||||
keine Selbstregistrierung.
|
||||
|
|
|
|||
|
|
@ -251,6 +251,29 @@ function admin_employees(): void
|
|||
require_post();
|
||||
$action = post_string('action');
|
||||
$id = (int) post_string('id');
|
||||
|
||||
if ($action === 'delete') {
|
||||
$employee = employee_find($id);
|
||||
if (!$employee) {
|
||||
abort_page(404, 'Mitarbeiter nicht gefunden.');
|
||||
}
|
||||
$stmt = db()->prepare('SELECT COUNT(*) FROM bookings WHERE employee_id = ?');
|
||||
$stmt->execute([$id]);
|
||||
if ((int) $stmt->fetchColumn() > 0) {
|
||||
flash('error', 'Mitarbeiter ' . $employee['name'] . ' kann nicht gelöscht werden, weil Buchungen darauf verweisen. Der Mitarbeiter kann stattdessen deaktiviert werden.');
|
||||
redirect('/admin/employees');
|
||||
}
|
||||
if ((int) $employee['active'] === 1
|
||||
&& (int) db()->query('SELECT COUNT(*) FROM employees WHERE active = 1')->fetchColumn() <= 1
|
||||
) {
|
||||
flash('error', 'Mindestens ein aktiver Mitarbeiter muss bleiben, damit Buchungen zugeordnet werden können.');
|
||||
redirect('/admin/employees');
|
||||
}
|
||||
db()->prepare('DELETE FROM employees WHERE id = ?')->execute([$id]);
|
||||
flash('success', 'Mitarbeiter ' . $employee['name'] . ' wurde gelöscht.');
|
||||
redirect('/admin/employees');
|
||||
}
|
||||
|
||||
$values = [
|
||||
'name' => post_string('name'),
|
||||
'sort_order' => (int) post_string('sort_order'),
|
||||
|
|
@ -280,6 +303,8 @@ function admin_employees(): void
|
|||
$stmt->execute([$id, today_iso()]);
|
||||
if ((int) $stmt->fetchColumn() > 0) {
|
||||
$errors['active'] = 'Der Mitarbeiter hat noch aktive Buchungen und kann nicht deaktiviert werden. Bitte zuerst umbuchen.';
|
||||
} elseif ((int) db()->query('SELECT COUNT(*) FROM employees WHERE active = 1')->fetchColumn() <= 1) {
|
||||
$errors['active'] = 'Mindestens ein aktiver Mitarbeiter muss bleiben, damit Buchungen zugeordnet werden können.';
|
||||
}
|
||||
}
|
||||
if (!$errors) {
|
||||
|
|
@ -315,7 +340,8 @@ function admin_employees(): void
|
|||
|
||||
$rows = db()->query(
|
||||
'SELECT e.*, u.first_name, u.last_name,
|
||||
(SELECT COUNT(*) FROM bookings b WHERE b.employee_id = e.id AND b.status = "active" AND b.end_date >= CURDATE()) AS future_bookings
|
||||
(SELECT COUNT(*) FROM bookings b WHERE b.employee_id = e.id AND b.status = "active" AND b.end_date >= CURDATE()) AS future_bookings,
|
||||
(SELECT COUNT(*) FROM bookings b WHERE b.employee_id = e.id) AS booking_count
|
||||
FROM employees e LEFT JOIN users u ON u.employee_id = e.id
|
||||
ORDER BY e.sort_order, e.name'
|
||||
)->fetchAll();
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ function url(string $path = '/'): string
|
|||
}
|
||||
|
||||
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
|
||||
const DIC_ASSET_VERSION = '7';
|
||||
const DIC_ASSET_VERSION = '8';
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
|
|
|
|||
|
|
@ -80,6 +80,17 @@ Die Startausstattung aus der Anforderung wird vom Installer angelegt. Unter
|
|||
- Löschen ist nur ohne jede Buchung möglich; sonst bleibt der Anhänger
|
||||
stattdessen deaktivierbar. Mindestens ein Anhänger muss aktiv bleiben.
|
||||
|
||||
### Mitarbeiter
|
||||
|
||||
- Mitarbeiter werden unter **Verwaltung → Mitarbeiter** angelegt und bearbeitet.
|
||||
- Das Aktiv-Flag ist die normale „Löschung“: Inaktive Mitarbeiter stehen bei
|
||||
neuen Buchungen nicht mehr zur Auswahl, historische Buchungen bleiben aber
|
||||
erhalten. Deaktivieren ist gesperrt, solange aktive oder zukünftige Buchungen
|
||||
zugeordnet sind.
|
||||
- Endgültiges Löschen ist nur ohne jede Buchung möglich (Fremdschlüssel). Bei
|
||||
vorhandenen Buchungen bleibt nur Deaktivieren.
|
||||
- Mindestens ein aktiver Mitarbeiter muss erhalten bleiben.
|
||||
|
||||
## Erinnerungen
|
||||
|
||||
Die drei Erinnerungen werden **nicht** als Datensätze angelegt, sondern bei
|
||||
|
|
|
|||
|
|
@ -86,7 +86,21 @@ $fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
|||
<td><?= e($row['first_name'] ? $row['first_name'] . ' ' . $row['last_name'] : '–') ?></td>
|
||||
<td><?= (int) $row['future_bookings'] ?></td>
|
||||
<td><span class="pill <?= (int) $row['active'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= (int) $row['active'] === 1 ? 'aktiv' : 'inaktiv' ?></span></td>
|
||||
<td class="ta-right"><a class="btn small" href="<?= e(url('/admin/employees?edit=' . (int) $row['id'])) ?>">Bearbeiten</a></td>
|
||||
<td class="ta-right">
|
||||
<div class="table-actions">
|
||||
<a class="btn small" href="<?= e(url('/admin/employees?edit=' . (int) $row['id'])) ?>">Bearbeiten</a>
|
||||
<?php if ((int) $row['booking_count'] === 0): ?>
|
||||
<form method="post" action="<?= e(url('/admin/employees')) ?>" data-confirm="Mitarbeiter <?= e($row['name']) ?> endgültig löschen?">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="id" value="<?= (int) $row['id'] ?>">
|
||||
<button class="link-button small" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="muted small" title="<?= (int) $row['booking_count'] ?> Buchung(en) verweisen auf diesen Mitarbeiter"><?= (int) $row['booking_count'] ?> Buchung<?= (int) $row['booking_count'] === 1 ? '' : 'en' ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -721,6 +721,8 @@ a .ico, button .ico { pointer-events: none; }
|
|||
.admin-nav a.is-active { background: var(--ice-100); color: var(--brand-700); }
|
||||
.admin-nav .ico { width: 16px; height: 16px; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
|
||||
.table-actions form { margin: 0; }
|
||||
.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
|
||||
.data-table th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||||
.data-table td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
* zwischengespeichert, damit niemand veraltete Buchungen sieht.
|
||||
*/
|
||||
|
||||
const VERSION = 'dic-v7';
|
||||
const VERSION = 'dic-v8';
|
||||
const CACHE = VERSION;
|
||||
const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue