feat(booking): Kaution je Buchung, drei Vertragsunterschriften, Mails und Aufbewahrung nach Kundenwunsch
Kundenwunsch vom 04.12.2026 (docs/auftraege): - Kaution je Buchung (bookings.deposit_amount_cents, Standard 100 €, 0 = keine) statt globaler Konfiguration; Voreinstellungen im Formular angepasst. - Auftragsbestätigung rechnet Kaution nicht mehr in Gesamt/Restbetrag ein, zeigt sie als "in bar"-Hinweis unter dem Zahlungseingang, Verwendungszweck "#Buchungsnummer Name", Hinweis auf Anruf 8–10 Tage vor dem Termin. - Mietvertrag mit drei Unterschriften (Migration 021, document_signatures): Mitarbeiter bestätigt Zahlungseingang, Kunde Übernahme, Kunde Kautionsrückgabe; Zusatzvereinbarungen werden im Vertrag abgedruckt. - Zahlungserinnerung ebenfalls ohne Kaution im Betrag. - Mail-Fuß mit Signaturblock und Antwort-Sperrhinweis, Betreffzeilen mit Buchungsnummer und Mietgegenstand (ohne Anhängernummer), Wochentag in Datumsangaben. - Aufbewahrung: ohne Rechnung 30 Tage, mit Rechnung Mietvertrag 8 Jahre; Jahresarchiv der Mietverträge (app/export.php, Verwaltung → Sicherungen). - Automatische Bewertungsmail eine Woche nach Rückgabe (Migration 022). - Mehrfachvermietung: "Weiterer Anhänger für diesen Kunden" (/bookings/new?from=ID). Migrationen 020–022 sind lokal gelaufen; PDF-Erzeugung, Unterschrifts-Lebenszyklus und Jahresexport getestet.
This commit is contained in:
parent
606237dbda
commit
00b7b7f0e9
33 changed files with 1355 additions and 218 deletions
59
app/data.php
59
app/data.php
|
|
@ -180,6 +180,16 @@ function booking_input(array $source): array
|
|||
$invoiceNo = trim((string) ($source['invoice_no'] ?? ''));
|
||||
$invoice = $invoiceNo !== '' || ((string) ($source['invoice'] ?? '0')) === '1' ? 1 : 0;
|
||||
|
||||
// Kaution: eigener Betrag je Buchung, 0 = keine Kaution. Fehlt das Feld
|
||||
// ganz (Aufrufer ohne Kenntnis der Kaution), gilt weiter der Standard.
|
||||
if (array_key_exists('deposit_amount_cents', $source)) {
|
||||
$depositAmount = max(0, (int) $source['deposit_amount_cents']);
|
||||
} elseif (array_key_exists('deposit_amount', $source)) {
|
||||
$depositAmount = parse_money((string) $source['deposit_amount']);
|
||||
} else {
|
||||
$depositAmount = booking_deposit_default_cents();
|
||||
}
|
||||
|
||||
return [
|
||||
'trailer_id' => (int) ($source['trailer_id'] ?? 0),
|
||||
'employee_id' => (int) ($source['employee_id'] ?? 0),
|
||||
|
|
@ -191,6 +201,7 @@ function booking_input(array $source): array
|
|||
'deposit_cents' => $depositRequired ? parse_money((string) ($source['deposit'] ?? '0')) : 0,
|
||||
'deposit_required' => $depositRequired,
|
||||
'deposit_account_id' => (int) ($source['deposit_account_id'] ?? 0),
|
||||
'deposit_amount_cents' => $depositAmount,
|
||||
'balance_method' => (string) ($source['balance_method'] ?? 'cash') === 'transfer' ? 'transfer' : 'cash',
|
||||
'rent_cents' => $rent,
|
||||
'delivery_cents' => $delivery,
|
||||
|
|
@ -224,6 +235,7 @@ function booking_to_input(array $booking): array
|
|||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'deposit_required' => (int) ($booking['deposit_required'] ?? 0),
|
||||
'deposit_account_id' => (int) ($booking['deposit_account_id'] ?? 0),
|
||||
'deposit_amount_cents' => booking_deposit_amount($booking),
|
||||
'balance_method' => (string) ($booking['balance_method'] ?? 'cash') === 'transfer' ? 'transfer' : 'cash',
|
||||
'rent_cents' => (int) ($booking['rent_cents'] ?? $booking['total_cents']),
|
||||
'delivery_cents' => (int) ($booking['delivery_cents'] ?? 0),
|
||||
|
|
@ -333,9 +345,11 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
|
|||
}
|
||||
|
||||
$maxAmount = 10000000; // 100.000,00 €
|
||||
if ($data['rent_cents'] < 0 || $data['delivery_cents'] < 0 || $data['deposit_cents'] < 0) {
|
||||
if ($data['rent_cents'] < 0 || $data['delivery_cents'] < 0 || $data['deposit_cents'] < 0
|
||||
|| (int) ($data['deposit_amount_cents'] ?? 0) < 0) {
|
||||
$errors['rent'] = 'Beträge dürfen nicht negativ sein.';
|
||||
} elseif ($data['rent_cents'] > $maxAmount || $data['delivery_cents'] > $maxAmount || $data['deposit_cents'] > $maxAmount) {
|
||||
} elseif ($data['rent_cents'] > $maxAmount || $data['delivery_cents'] > $maxAmount
|
||||
|| $data['deposit_cents'] > $maxAmount || (int) ($data['deposit_amount_cents'] ?? 0) > $maxAmount) {
|
||||
$errors['rent'] = 'Der Betrag ist unrealistisch hoch.';
|
||||
} elseif ($data['deposit_cents'] > $data['total_cents']) {
|
||||
$errors['deposit'] = 'Die Anzahlung darf den Gesamtbetrag nicht übersteigen.';
|
||||
|
|
@ -545,7 +559,7 @@ function booking_create(array $data, int $userId): int
|
|||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO bookings
|
||||
(trailer_id, employee_id, return_employee_id, start_date, end_date, start_time, end_time, deposit_cents,
|
||||
deposit_required, deposit_account_id, balance_method,
|
||||
deposit_required, deposit_account_id, deposit_amount_cents, balance_method,
|
||||
rent_cents, delivery_cents, total_cents, invoice, invoice_no, kind,
|
||||
customer_name, street, city, delivery_street, delivery_city, mobile, email, note, agreements,
|
||||
status, created_at, updated_at, created_by, updated_by)
|
||||
|
|
@ -557,6 +571,7 @@ function booking_create(array $data, int $userId): int
|
|||
null_if_empty($data['start_time']), null_if_empty($data['end_time']),
|
||||
$data['deposit_cents'], (int) ($data['deposit_required'] ?? 0),
|
||||
((int) ($data['deposit_account_id'] ?? 0)) > 0 ? (int) $data['deposit_account_id'] : null,
|
||||
(int) ($data['deposit_amount_cents'] ?? 0),
|
||||
(string) ($data['balance_method'] ?? 'cash'),
|
||||
$data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
|
||||
|
|
@ -593,7 +608,7 @@ function booking_update(int $id, array $data, int $userId): void
|
|||
$stmt = $pdo->prepare(
|
||||
'UPDATE bookings SET trailer_id = ?, employee_id = ?, return_employee_id = ?, start_date = ?, end_date = ?,
|
||||
start_time = ?, end_time = ?, deposit_cents = ?, deposit_required = ?, deposit_account_id = ?,
|
||||
balance_method = ?,
|
||||
deposit_amount_cents = ?, balance_method = ?,
|
||||
rent_cents = ?, delivery_cents = ?, total_cents = ?, invoice = ?, invoice_no = ?, kind = ?,
|
||||
customer_name = ?, street = ?, city = ?, delivery_street = ?, delivery_city = ?,
|
||||
mobile = ?, email = ?, note = ?, agreements = ?, updated_at = ?,
|
||||
|
|
@ -605,6 +620,7 @@ function booking_update(int $id, array $data, int $userId): void
|
|||
null_if_empty($data['start_time']), null_if_empty($data['end_time']),
|
||||
$data['deposit_cents'], (int) ($data['deposit_required'] ?? 0),
|
||||
((int) ($data['deposit_account_id'] ?? 0)) > 0 ? (int) $data['deposit_account_id'] : null,
|
||||
(int) ($data['deposit_amount_cents'] ?? 0),
|
||||
(string) ($data['balance_method'] ?? 'cash'),
|
||||
$data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
|
||||
|
|
@ -744,6 +760,17 @@ function booking_kind_label(string $kind): string
|
|||
return $kind === 'delivery' ? 'Lieferung' : 'Abholer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Mietgegenstand in Kurzform für Mail-Betreff und -Text: „Kühlanhänger“ oder
|
||||
* „Truhe“ – bewusst ohne Anhänger-Nummer, damit der Kunde die Nummer nicht
|
||||
* mit seiner Buchung verwechselt (Kundenwunsch 04.12.2026).
|
||||
*/
|
||||
function booking_item_label(array $booking): string
|
||||
{
|
||||
$label = mb_strtolower((string) ($booking['trailer_label'] ?? ''));
|
||||
return str_contains($label, 'truhe') ? 'Truhe' : 'Kühlanhänger';
|
||||
}
|
||||
|
||||
/** Name des Mitarbeiters für die Abholung/Rücknahme (fällt auf die Übergabe zurück). */
|
||||
function booking_return_employee_name(array $booking): string
|
||||
{
|
||||
|
|
@ -885,15 +912,37 @@ function availability_level(int $free, int $total): string
|
|||
return $free <= 2 ? 'few' : 'free';
|
||||
}
|
||||
|
||||
/** Standard-Kaution in Cent (app.document_deposit_cents, Standard 100 €). */
|
||||
function booking_deposit_default_cents(): int
|
||||
{
|
||||
return max(0, (int) config('app.document_deposit_cents', 10000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kaution einer Buchung in Cent. 0 heißt „keine Kaution“ (z. B. Stammkunde) –
|
||||
* dann darf sie in den Unterlagen nirgends als Forderung auftauchen.
|
||||
* Fehlt die Spalte noch (Migration 020 ausstehend), gilt der Standard.
|
||||
*/
|
||||
function booking_deposit_amount(array $booking): int
|
||||
{
|
||||
if (array_key_exists('deposit_amount_cents', $booking) && $booking['deposit_amount_cents'] !== null) {
|
||||
return max(0, (int) $booking['deposit_amount_cents']);
|
||||
}
|
||||
return booking_deposit_default_cents();
|
||||
}
|
||||
|
||||
function booking_copy_text(array $booking): string
|
||||
{
|
||||
$depositAmount = booking_deposit_amount($booking);
|
||||
return implode("\n", [
|
||||
'Anzahlung: ' . fmt_money((int) $booking['deposit_cents'])
|
||||
. ((int) ($booking['deposit_required'] ?? 0) === 1 && (int) $booking['deposit_cents'] > 0
|
||||
? ' (fällig bis ' . fmt_date(deposit_due_date()) . ')'
|
||||
: ''),
|
||||
'Gesamtbetrag: ' . fmt_money((int) $booking['total_cents']),
|
||||
'Noch zu zahlen: ' . fmt_money(due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents'])),
|
||||
'Kaution: ' . ($depositAmount > 0
|
||||
? fmt_money($depositAmount) . ' (in bar bei der Übergabe)'
|
||||
: 'entfällt'), 'Noch zu zahlen: ' . fmt_money(due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents'])),
|
||||
'Restzahlung: ' . (booking_balance_transfer($booking)
|
||||
? 'Überweisung (bis ' . fmt_date(booking_balance_due_date($booking)) . ')'
|
||||
: 'bar bei der Übergabe'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue