feat(booking): Anzahlung mit Konto und Frist in der Auftragsbestätigung
- Migration 015_booking_deposit.sql: bookings.deposit_required + bookings.deposit_account (bestehende Buchungen mit Betrag > 0 werden auf JA gesetzt), schema.sql nachgezogen - Buchungsformular: „Anzahlung fällig: JA/NEIN“ und Kontoauswahl neben dem Betrag (nur Verwaltung; Nicht-Admins behalten die gespeicherten Werte), Pflichtbetrag bei JA, Hinweis in der Zusammenfassung - app/documents.php: deposit_accounts() (Standard Postbank/Michael Schmitz, überschreibbar per app.deposit_accounts) und deposit_due_date() (7 Werktage Mo–Sa ohne NRW-Feiertage, app.deposit_due_working_days) - Auftragsbestätigung: Block „Anzahlung und verbindliche Reservierung“ mit Betrag, Datum, Kontoinhaber, Bank, IBAN, Verwendungszweck und Hinweis, dass der Termin erst nach Zahlungseingang reserviert ist; kompaktere Beträge/ Signatur, damit alles auf eine Seite passt - Buchungsdetail, Kopiertext, AGB (Zahlungsabschnitt), Anleitung, README, config.example.php und ROADMAP (Feature 24) ergänzt
This commit is contained in:
parent
8f0d3d9191
commit
bf85a64a79
12 changed files with 243 additions and 17 deletions
34
app/data.php
34
app/data.php
|
|
@ -163,6 +163,8 @@ function booking_note_clean(string $note): string
|
|||
function booking_input(array $source): array
|
||||
{
|
||||
$kind = (string) ($source['kind'] ?? 'pickup');
|
||||
// Anzahlung: Häkchen „Anzahlung vereinbart“ entscheidet, ob der Betrag gilt.
|
||||
$depositRequired = (string) ($source['deposit_required'] ?? '0') === '1' ? 1 : 0;
|
||||
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));
|
||||
|
|
@ -186,7 +188,9 @@ function booking_input(array $source): array
|
|||
'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')),
|
||||
'deposit_cents' => $depositRequired ? parse_money((string) ($source['deposit'] ?? '0')) : 0,
|
||||
'deposit_required' => $depositRequired,
|
||||
'deposit_account' => trim((string) ($source['deposit_account'] ?? '')),
|
||||
'rent_cents' => $rent,
|
||||
'delivery_cents' => $delivery,
|
||||
'total_cents' => $rent + $delivery,
|
||||
|
|
@ -214,6 +218,8 @@ function booking_to_input(array $booking): array
|
|||
'start_time' => normalize_time($booking['start_time'] ?? ''),
|
||||
'end_time' => normalize_time($booking['end_time'] ?? ''),
|
||||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'deposit_required' => (int) ($booking['deposit_required'] ?? 0),
|
||||
'deposit_account' => (string) ($booking['deposit_account'] ?? ''),
|
||||
'rent_cents' => (int) ($booking['rent_cents'] ?? $booking['total_cents']),
|
||||
'delivery_cents' => (int) ($booking['delivery_cents'] ?? 0),
|
||||
'total_cents' => (int) $booking['total_cents'],
|
||||
|
|
@ -317,6 +323,11 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
|
|||
$errors['rent'] = 'Der Betrag ist unrealistisch hoch.';
|
||||
} elseif ($data['deposit_cents'] > $data['total_cents']) {
|
||||
$errors['deposit'] = 'Die Anzahlung darf den Gesamtbetrag nicht übersteigen.';
|
||||
} elseif ((int) ($data['deposit_required'] ?? 0) === 1 && $data['deposit_cents'] <= 0) {
|
||||
$errors['deposit'] = 'Bitte den Betrag der Anzahlung angeben oder „Anzahlung: NEIN“ wählen.';
|
||||
}
|
||||
if ((int) ($data['deposit_required'] ?? 0) === 1 && !deposit_account((string) ($data['deposit_account'] ?? ''))) {
|
||||
$errors['deposit_account'] = 'Bitte das Konto für die Anzahlung auswählen.';
|
||||
}
|
||||
|
||||
if (!$errors && $trailer) {
|
||||
|
|
@ -514,15 +525,17 @@ 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,
|
||||
rent_cents, delivery_cents, total_cents, invoice, invoice_no, kind,
|
||||
customer_name, street, city, mobile, email, note, status, created_at, updated_at, created_by, updated_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['return_employee_id'] ?: null,
|
||||
$data['start_date'], $data['end_date'],
|
||||
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['deposit_cents'], (int) ($data['deposit_required'] ?? 0), (string) ($data['deposit_account'] ?? ''),
|
||||
$data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
(string) ($data['note'] ?? ''),
|
||||
|
|
@ -554,15 +567,17 @@ 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 = ?, rent_cents = ?, delivery_cents = ?,
|
||||
total_cents = ?, invoice = ?, invoice_no = ?, kind = ?, customer_name = ?, street = ?,
|
||||
city = ?, mobile = ?, email = ?, note = ?, updated_at = ?, updated_by = ? WHERE id = ?'
|
||||
start_time = ?, end_time = ?, deposit_cents = ?, deposit_required = ?, deposit_account = ?,
|
||||
rent_cents = ?, delivery_cents = ?, total_cents = ?, invoice = ?, invoice_no = ?, kind = ?,
|
||||
customer_name = ?, street = ?, city = ?, mobile = ?, email = ?, note = ?, updated_at = ?,
|
||||
updated_by = ? WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['return_employee_id'] ?: null,
|
||||
$data['start_date'], $data['end_date'],
|
||||
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['deposit_cents'], (int) ($data['deposit_required'] ?? 0), (string) ($data['deposit_account'] ?? ''),
|
||||
$data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
(string) ($data['note'] ?? ''),
|
||||
|
|
@ -760,7 +775,10 @@ function booking_invoice_display(array $booking): string
|
|||
function booking_copy_text(array $booking): string
|
||||
{
|
||||
return implode("\n", [
|
||||
'Anzahlung: ' . fmt_money((int) $booking['deposit_cents']),
|
||||
'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'])),
|
||||
'Rechnung: ' . booking_invoice_display($booking),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue