Uhrzeiten, Miete und Lieferkosten ergänzen; Server-Stand übernehmen
- bookings um optionale start_time/end_time sowie rent_cents und delivery_cents erweitert; Gesamtbetrag ist Miete + Lieferkosten (Migration 003, Schema und Doku nachgezogen) - Formular, Detailansicht, Panel, Kalender und Kopiertext zeigen Uhrzeiten und die getrennten Beträge - Live-Stand nachgezogen: Impressum/Datenschutz, Privacy-Cleanup im Cron-Lauf, Löschsperre für Buchungen mit Rechnung - Cache-Buster auf Version 10 erhöht
This commit is contained in:
parent
672df3d0a7
commit
d47a72820d
24 changed files with 1157 additions and 92 deletions
124
app/data.php
124
app/data.php
|
|
@ -118,13 +118,29 @@ function booking_conflicts(int $trailerId, string $start, string $end, int $excl
|
|||
function booking_input(array $source): array
|
||||
{
|
||||
$kind = (string) ($source['kind'] ?? 'pickup');
|
||||
if (array_key_exists('rent_cents', $source) || array_key_exists('delivery_cents', $source)) {
|
||||
$rent = max(0, (int) ($source['rent_cents'] ?? 0));
|
||||
$delivery = max(0, (int) ($source['delivery_cents'] ?? 0));
|
||||
} elseif (array_key_exists('rent', $source) || array_key_exists('delivery', $source)) {
|
||||
$rent = parse_money((string) ($source['rent'] ?? '0'));
|
||||
$delivery = parse_money((string) ($source['delivery'] ?? '0'));
|
||||
} else {
|
||||
// Aufrufer ohne getrennte Beträge: Gesamtbetrag gilt als Miete.
|
||||
$rent = parse_money((string) ($source['total'] ?? '0'));
|
||||
$delivery = 0;
|
||||
}
|
||||
|
||||
return [
|
||||
'trailer_id' => (int) ($source['trailer_id'] ?? 0),
|
||||
'employee_id' => (int) ($source['employee_id'] ?? 0),
|
||||
'start_date' => trim((string) ($source['start_date'] ?? '')),
|
||||
'end_date' => trim((string) ($source['end_date'] ?? '')),
|
||||
'start_time' => normalize_time($source['start_time'] ?? ''),
|
||||
'end_time' => normalize_time($source['end_time'] ?? ''),
|
||||
'deposit_cents' => parse_money((string) ($source['deposit'] ?? '0')),
|
||||
'total_cents' => parse_money((string) ($source['total'] ?? '0')),
|
||||
'rent_cents' => $rent,
|
||||
'delivery_cents' => $delivery,
|
||||
'total_cents' => $rent + $delivery,
|
||||
'invoice' => ((string) ($source['invoice'] ?? '0')) === '1' ? 1 : 0,
|
||||
'kind' => in_array($kind, ['pickup', 'delivery'], true) ? $kind : 'pickup',
|
||||
'customer_name' => trim((string) ($source['customer_name'] ?? '')),
|
||||
|
|
@ -135,6 +151,30 @@ function booking_input(array $source): array
|
|||
];
|
||||
}
|
||||
|
||||
/** Bestehende Buchung als Eingabedaten (Validierung, Verschieben, Wiederherstellen). */
|
||||
function booking_to_input(array $booking): array
|
||||
{
|
||||
return [
|
||||
'trailer_id' => (int) $booking['trailer_id'],
|
||||
'employee_id' => (int) $booking['employee_id'],
|
||||
'start_date' => (string) $booking['start_date'],
|
||||
'end_date' => (string) $booking['end_date'],
|
||||
'start_time' => normalize_time($booking['start_time'] ?? ''),
|
||||
'end_time' => normalize_time($booking['end_time'] ?? ''),
|
||||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'rent_cents' => (int) ($booking['rent_cents'] ?? $booking['total_cents']),
|
||||
'delivery_cents' => (int) ($booking['delivery_cents'] ?? 0),
|
||||
'total_cents' => (int) $booking['total_cents'],
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
'kind' => (string) $booking['kind'],
|
||||
'customer_name' => (string) $booking['customer_name'],
|
||||
'street' => (string) $booking['street'],
|
||||
'city' => (string) $booking['city'],
|
||||
'mobile' => (string) $booking['mobile'],
|
||||
'email' => (string) $booking['email'],
|
||||
];
|
||||
}
|
||||
|
||||
function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId = 0, int $allowEmployeeId = 0): array
|
||||
{
|
||||
$errors = [];
|
||||
|
|
@ -163,6 +203,20 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
|
|||
}
|
||||
}
|
||||
|
||||
foreach (['start_time' => 'Mietbeginn', 'end_time' => 'Mietende'] as $field => $label) {
|
||||
if (!valid_time((string) $data[$field])) {
|
||||
$errors[$field] = 'Bitte für ' . $label . ' eine gültige Uhrzeit angeben (HH:MM).';
|
||||
}
|
||||
}
|
||||
if (!isset($errors['start_time']) && !isset($errors['end_time'])
|
||||
&& !isset($errors['start_date']) && !isset($errors['end_date'])
|
||||
&& $data['start_date'] === $data['end_date']
|
||||
&& $data['start_time'] !== '' && $data['end_time'] !== ''
|
||||
&& $data['end_time'] <= $data['start_time']
|
||||
) {
|
||||
$errors['end_time'] = 'Am selben Tag muss das Mietende nach dem Mietbeginn liegen.';
|
||||
}
|
||||
|
||||
if ($data['customer_name'] === '') {
|
||||
$errors['customer_name'] = 'Bitte den Kundennamen angeben.';
|
||||
} elseif (mb_strlen($data['customer_name']) > 190) {
|
||||
|
|
@ -183,10 +237,10 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
|
|||
}
|
||||
|
||||
$maxAmount = 10000000; // 100.000,00 €
|
||||
if ($data['total_cents'] < 0 || $data['deposit_cents'] < 0) {
|
||||
$errors['total'] = 'Beträge dürfen nicht negativ sein.';
|
||||
} elseif ($data['total_cents'] > $maxAmount || $data['deposit_cents'] > $maxAmount) {
|
||||
$errors['total'] = 'Der Betrag ist unrealistisch hoch.';
|
||||
if ($data['rent_cents'] < 0 || $data['delivery_cents'] < 0 || $data['deposit_cents'] < 0) {
|
||||
$errors['rent'] = 'Beträge dürfen nicht negativ sein.';
|
||||
} elseif ($data['rent_cents'] > $maxAmount || $data['delivery_cents'] > $maxAmount || $data['deposit_cents'] > $maxAmount) {
|
||||
$errors['rent'] = 'Der Betrag ist unrealistisch hoch.';
|
||||
} elseif ($data['deposit_cents'] > $data['total_cents']) {
|
||||
$errors['deposit'] = 'Die Anzahlung darf den Gesamtbetrag nicht übersteigen.';
|
||||
}
|
||||
|
|
@ -234,13 +288,16 @@ function booking_create(array $data, int $userId): int
|
|||
}
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO bookings
|
||||
(trailer_id, employee_id, start_date, end_date, deposit_cents, total_cents, invoice, kind,
|
||||
(trailer_id, employee_id, start_date, end_date, start_time, end_time, deposit_cents,
|
||||
rent_cents, delivery_cents, total_cents, invoice, kind,
|
||||
customer_name, street, city, mobile, email, status, created_at, updated_at, created_by, updated_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['start_date'], $data['end_date'],
|
||||
$data['deposit_cents'], $data['total_cents'], $data['invoice'], $data['kind'],
|
||||
null_if_empty($data['start_time']), null_if_empty($data['end_time']),
|
||||
$data['deposit_cents'], $data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
utc_now(), utc_now(), $userId, $userId,
|
||||
]);
|
||||
|
|
@ -270,12 +327,15 @@ function booking_update(int $id, array $data, int $userId): void
|
|||
}
|
||||
$stmt = $pdo->prepare(
|
||||
'UPDATE bookings SET trailer_id = ?, employee_id = ?, start_date = ?, end_date = ?,
|
||||
deposit_cents = ?, total_cents = ?, invoice = ?, kind = ?, customer_name = ?, street = ?,
|
||||
start_time = ?, end_time = ?, deposit_cents = ?, rent_cents = ?, delivery_cents = ?,
|
||||
total_cents = ?, invoice = ?, kind = ?, customer_name = ?, street = ?,
|
||||
city = ?, mobile = ?, email = ?, updated_at = ?, updated_by = ? WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['start_date'], $data['end_date'],
|
||||
$data['deposit_cents'], $data['total_cents'], $data['invoice'], $data['kind'],
|
||||
null_if_empty($data['start_time']), null_if_empty($data['end_time']),
|
||||
$data['deposit_cents'], $data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
utc_now(), $userId, $id,
|
||||
]);
|
||||
|
|
@ -320,21 +380,12 @@ function booking_restore(int $id, int $userId): array
|
|||
if (!$booking) {
|
||||
throw new RuntimeException('not_found');
|
||||
}
|
||||
$errors = booking_validate([
|
||||
'trailer_id' => (int) $booking['trailer_id'],
|
||||
'employee_id' => (int) $booking['employee_id'],
|
||||
'start_date' => $booking['start_date'],
|
||||
'end_date' => $booking['end_date'],
|
||||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'total_cents' => (int) $booking['total_cents'],
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
'kind' => $booking['kind'],
|
||||
'customer_name' => $booking['customer_name'],
|
||||
'street' => $booking['street'],
|
||||
'city' => $booking['city'],
|
||||
'mobile' => $booking['mobile'],
|
||||
'email' => $booking['email'],
|
||||
], $id, (int) $booking['trailer_id'], (int) $booking['employee_id']);
|
||||
$errors = booking_validate(
|
||||
booking_to_input($booking),
|
||||
$id,
|
||||
(int) $booking['trailer_id'],
|
||||
(int) $booking['employee_id']
|
||||
);
|
||||
if ($errors) {
|
||||
return $errors;
|
||||
}
|
||||
|
|
@ -368,21 +419,10 @@ function booking_move(int $id, string $newStart, int $newTrailerId, int $userId)
|
|||
return ['error' => 'Bitte einen gültigen Kühlanhänger wählen.'];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'trailer_id' => $newTrailerId,
|
||||
'employee_id' => (int) $booking['employee_id'],
|
||||
'start_date' => $newStart,
|
||||
'end_date' => $newEnd,
|
||||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'total_cents' => (int) $booking['total_cents'],
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
'kind' => (string) $booking['kind'],
|
||||
'customer_name' => (string) $booking['customer_name'],
|
||||
'street' => (string) $booking['street'],
|
||||
'city' => (string) $booking['city'],
|
||||
'mobile' => (string) $booking['mobile'],
|
||||
'email' => (string) $booking['email'],
|
||||
];
|
||||
$data = booking_to_input($booking);
|
||||
$data['trailer_id'] = $newTrailerId;
|
||||
$data['start_date'] = $newStart;
|
||||
$data['end_date'] = $newEnd;
|
||||
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
|
|
@ -440,8 +480,8 @@ function booking_copy_text(array $booking): string
|
|||
'Gesamtbetrag: ' . fmt_money((int) $booking['total_cents']),
|
||||
'Noch zu zahlen: ' . fmt_money(due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents'])),
|
||||
'Rechnung: ' . booking_invoice_label($booking['invoice']),
|
||||
'Von: ' . fmt_date_short((string) $booking['start_date']),
|
||||
'Bis: ' . fmt_date_short((string) $booking['end_date']),
|
||||
'Von: ' . fmt_date_short_with_time((string) $booking['start_date'], $booking['start_time'] ?? null),
|
||||
'Bis: ' . fmt_date_short_with_time((string) $booking['end_date'], $booking['end_time'] ?? null),
|
||||
'Art: ' . booking_kind_label((string) $booking['kind']),
|
||||
'Name: ' . $booking['customer_name'],
|
||||
'Straße: ' . $booking['street'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue