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
|
|
@ -63,6 +63,10 @@ function agb_sections(): array
|
|||
. 'Die Kaution wird bei ordnungsgemäßer Rückgabe selbstverständlich vollständig erstattet.'],
|
||||
['p' => 'Nach Absprache kann auch per Überweisung bezahlt werden – dann jedoch so, dass das '
|
||||
. 'Geld spätestens am Montag der Terminwoche auf dem Konto des Vermieters eingegangen ist.'],
|
||||
['p' => 'Ist in der Auftragsbestätigung eine Anzahlung ausgewiesen, ist diese innerhalb von '
|
||||
. '7 Werktagen nach Erhalt der Auftragsbestätigung auf das dort genannte Konto zu überweisen. '
|
||||
. 'Erst mit Eingang der Anzahlung ist der Termin verbindlich reserviert; bei nicht '
|
||||
. 'fristgerechtem Eingang kann der Termin anderweitig vergeben werden.'],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -55,6 +55,17 @@ return [
|
|||
'backup_keep' => 14,
|
||||
// Maximale Größe einer hochgeladenen Sicherung (MB).
|
||||
'backup_max_mb' => 200,
|
||||
// Anzahlung in der Auftragsbestätigung: Frist in Werktagen (Mo–Sa ohne
|
||||
// gesetzliche Feiertage). Die Konten stehen als Standard in
|
||||
// app/documents.php (deposit_accounts()) und lassen sich hier
|
||||
// überschreiben: Schlüssel => ['label', 'holder', 'bank', 'iban'].
|
||||
'deposit_due_working_days' => 7,
|
||||
// 'deposit_accounts' => [
|
||||
// 'postbank' => ['label' => 'Postbank – Michael Schmitz', 'holder' => 'Michael Schmitz',
|
||||
// 'bank' => 'Postbank', 'iban' => 'DE…'],
|
||||
// 'sparkasse' => ['label' => 'Sparkasse – Drink it cold', 'holder' => '…',
|
||||
// 'bank' => '…', 'iban' => 'DE…'],
|
||||
// ],
|
||||
],
|
||||
// Optional: Angaben für Impressum und Datenschutz überschreiben. Die
|
||||
// Standardwerte stehen in app/legal.php. Hinweis: tools/deploy.sh erzeugt
|
||||
|
|
|
|||
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),
|
||||
|
|
|
|||
|
|
@ -418,6 +418,91 @@ function document_pdf_rows(PdfDoc $pdf, float $top, array $rows, float $valueX =
|
|||
return $y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Konten, auf die eine Anzahlung überwiesen werden kann.
|
||||
*
|
||||
* Standard steht in dieser Funktion, damit sie auch dann greift, wenn die
|
||||
* app/config.local.php beim Deployment neu erzeugt wird (dort wird kein
|
||||
* `app.deposit_accounts` geschrieben). Weitere Konten lassen sich hier
|
||||
* ergänzen oder per `app.deposit_accounts` in der lokalen Konfiguration
|
||||
* überschreiben (Schlüssel => label/holder/bank/iban).
|
||||
*
|
||||
* @return array<string, array{label: string, holder: string, bank: string, iban: string}>
|
||||
*/
|
||||
function deposit_accounts(): array
|
||||
{
|
||||
$defaults = [
|
||||
'postbank' => [
|
||||
'label' => 'Postbank – Michael Schmitz',
|
||||
'holder' => 'Michael Schmitz',
|
||||
'bank' => 'Postbank',
|
||||
'iban' => 'DE12 1001 0010 0464 1261 30',
|
||||
],
|
||||
];
|
||||
|
||||
$configured = config('app.deposit_accounts', null);
|
||||
if (!is_array($configured) || $configured === []) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
$accounts = [];
|
||||
foreach ($configured as $key => $account) {
|
||||
if (!is_array($account)) {
|
||||
continue;
|
||||
}
|
||||
$accounts[(string) $key] = [
|
||||
'label' => (string) ($account['label'] ?? $key),
|
||||
'holder' => (string) ($account['holder'] ?? ''),
|
||||
'bank' => (string) ($account['bank'] ?? ''),
|
||||
'iban' => (string) ($account['iban'] ?? ''),
|
||||
];
|
||||
}
|
||||
return $accounts !== [] ? $accounts : $defaults;
|
||||
}
|
||||
|
||||
/** Konto zur Kennung; ohne gültige Kennung das erste Konto (oder null). */
|
||||
function deposit_account(string $key): ?array
|
||||
{
|
||||
$accounts = deposit_accounts();
|
||||
if ($key !== '' && isset($accounts[$key])) {
|
||||
return $accounts[$key];
|
||||
}
|
||||
$first = reset($accounts);
|
||||
return $first === false ? null : $first;
|
||||
}
|
||||
|
||||
/** Frist für die Anzahlung in Werktagen (Mo–Sa, ohne gesetzliche Feiertage). */
|
||||
function deposit_due_working_days(): int
|
||||
{
|
||||
return max(1, min(60, (int) config('app.deposit_due_working_days', 7)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fälligkeitsdatum der Anzahlung: n Werktage ab heute (Mo–Sa, NRW-Feiertage
|
||||
* zählen nicht mit).
|
||||
*/
|
||||
function deposit_due_date(?string $fromIso = null): string
|
||||
{
|
||||
$date = $fromIso !== null && valid_date($fromIso) ? $fromIso : today_iso();
|
||||
$remaining = deposit_due_working_days();
|
||||
$guard = 0;
|
||||
$cursor = date_obj($date);
|
||||
while ($remaining > 0 && $guard < 400) {
|
||||
$cursor = $cursor->modify('+1 day');
|
||||
$guard++;
|
||||
$iso = $cursor->format('Y-m-d');
|
||||
$weekday = $cursor->format('N');
|
||||
if ($weekday === '7') {
|
||||
continue; // Sonntag ist kein Werktag
|
||||
}
|
||||
if (holiday_name($iso) !== null) {
|
||||
continue;
|
||||
}
|
||||
$remaining--;
|
||||
}
|
||||
return $cursor->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bezeichnung des Mietgegenstandes, ohne doppelte Wörter
|
||||
* ("Kühlanhänger 1", "Kühltruhe 1", "Kühlanhänger: WM Meyer").
|
||||
|
|
@ -663,26 +748,59 @@ function document_confirmation_pdf(array $booking, string $variant): string
|
|||
if ($deposit > 0) {
|
||||
$priceRows[] = ['Kaution', fmt_money($deposit) . ' (Rückgabe: volle Erstattung)'];
|
||||
}
|
||||
// Anzahlung: vereinbart (Häkchen in der Buchung) und Betrag > 0.
|
||||
$depositRequired = (int) ($booking['deposit_required'] ?? 0) === 1;
|
||||
$account = $depositRequired && $paid > 0 ? deposit_account((string) ($booking['deposit_account'] ?? '')) : null;
|
||||
$dueDate = $account !== null ? deposit_due_date() : null;
|
||||
$workingDays = deposit_due_working_days();
|
||||
if ($paid > 0) {
|
||||
$priceRows[] = ['Anzahlung', '− ' . fmt_money($paid)];
|
||||
$priceRows[] = [
|
||||
$depositRequired ? 'Anzahlung (bis ' . fmt_date((string) $dueDate) . ')' : 'Anzahlung',
|
||||
'− ' . fmt_money($paid),
|
||||
];
|
||||
}
|
||||
$priceRows[] = ['Gesamtbetrag', fmt_money($grand), true];
|
||||
$priceRows[] = ['Bei Übergabe zu zahlen', fmt_money(max(0, $grand - $paid)), true];
|
||||
$priceRows[] = ['Rechnung', booking_invoice_display($booking)];
|
||||
$y = document_pdf_rows($pdf, $y, $priceRows);
|
||||
|
||||
$note = 'Der Gesamtbetrag ist bei der Übergabe in bar zu zahlen. Nach Absprache ist auch eine '
|
||||
. 'Überweisung möglich – das Geld muss dann spätestens am Montag der Terminwoche eingegangen sein. '
|
||||
. 'Die Kaution wird bei ordnungsgemäßer Rückgabe vollständig erstattet.';
|
||||
$y = document_pdf_note($pdf, $y + 8, 'Zahlung', $note);
|
||||
if ($account !== null) {
|
||||
$y = document_pdf_heading($pdf, $y + 6, 'Anzahlung und verbindliche Reservierung');
|
||||
$intro = 'Zur verbindlichen Reservierung ist eine Anzahlung in Höhe von ' . fmt_money($paid)
|
||||
. ' innerhalb von ' . $workingDays . ' Werktagen nach Erhalt dieser Auftragsbestätigung – also bis '
|
||||
. 'spätestens ' . fmt_date((string) $dueDate) . ' – auf folgendes Konto zu überweisen:';
|
||||
$y = $pdf->paragraph(50, $y + 2, $pdf->pageWidth() - 100, 9.5, $intro, false, 13);
|
||||
$y = document_pdf_rows($pdf, $y + 4, [
|
||||
['Kontoinhaber', $account['holder']],
|
||||
['Bank', $account['bank']],
|
||||
['IBAN', $account['iban']],
|
||||
['Verwendungszweck', 'Kühlanhänger ' . fmt_date((string) $booking['start_date']) . ' · '
|
||||
. (string) $booking['customer_name']],
|
||||
], 150.0);
|
||||
$warning = 'Bitte beachten: Erst nach Eingang der Anzahlung auf dem genannten Konto ist der Termin '
|
||||
. 'verbindlich reserviert. Erfolgt innerhalb der Frist kein Zahlungseingang, behalten wir uns vor, '
|
||||
. 'den Termin wieder freizugeben.';
|
||||
$y = $pdf->paragraph(50, $y + 4, $pdf->pageWidth() - 100, 9.5, $warning, false, 13);
|
||||
}
|
||||
|
||||
// Mit Anzahlung steht das Wichtigste schon oben – dann nur noch der Restbetrag.
|
||||
$note = $account !== null
|
||||
? 'Der Restbetrag von ' . fmt_money(max(0, $grand - $paid)) . ' ist bei der Übergabe in bar zu zahlen; '
|
||||
. 'nach Absprache auch per Überweisung. Die Kaution wird bei ordnungsgemäßer Rückgabe vollständig erstattet.'
|
||||
: 'Der Gesamtbetrag ist bei der Übergabe in bar zu zahlen. Nach Absprache ist auch eine '
|
||||
. 'Überweisung möglich – das Geld muss dann spätestens am Montag der Terminwoche eingegangen sein. '
|
||||
. 'Die Kaution wird bei ordnungsgemäßer Rückgabe vollständig erstattet.';
|
||||
$y = document_pdf_note($pdf, $y + 6, 'Zahlung', $note);
|
||||
|
||||
$closing = 'Vielen Dank für die Buchung. Diese Auftragsbestätigung bestätigt den vereinbarten Termin und '
|
||||
. 'die genannten Beträge. Es gelten die Allgemeinen Geschäftsbedingungen des Vermieters. '
|
||||
. 'Bitte prüfen Sie die Angaben und melden Sie sich bei Abweichungen.';
|
||||
$y = $pdf->paragraph(50, $y + 4, $pdf->pageWidth() - 100, 9, $closing, false, 12.5);
|
||||
|
||||
$signatureTop = $y + 50;
|
||||
if ($signatureTop > 720) {
|
||||
// Unterschrift nur dann auf eine neue Seite, wenn sie sonst in den Fußbereich
|
||||
// rutschen würde – mit Anzahlungsblock ist Seite 1 sonst schnell „voll".
|
||||
$signatureTop = $y + 34;
|
||||
if ($signatureTop > 770) {
|
||||
document_pdf_footer($pdf, 'Auftragsbestätigung · Buchung #' . (int) $booking['id']);
|
||||
$pdf->newPage();
|
||||
$signatureTop = 150;
|
||||
|
|
|
|||
|
|
@ -806,6 +806,8 @@ function booking_form_context(array $user, ?array $booking = null, array $values
|
|||
'user' => $user,
|
||||
'isEdit' => $booking !== null,
|
||||
'canEditBilling' => auth_can_manage($user),
|
||||
'depositAccounts' => deposit_accounts(),
|
||||
'depositDueDays' => deposit_due_working_days(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -820,6 +822,8 @@ function form_values_from_input(array $data): array
|
|||
'start_time' => (string) ($data['start_time'] ?? ''),
|
||||
'end_time' => (string) ($data['end_time'] ?? ''),
|
||||
'deposit' => number_format($data['deposit_cents'] / 100, 2, ',', ''),
|
||||
'deposit_required' => (int) ($data['deposit_required'] ?? 0),
|
||||
'deposit_account' => (string) ($data['deposit_account'] ?? ''),
|
||||
'rent' => number_format($data['rent_cents'] / 100, 2, ',', ''),
|
||||
'delivery' => number_format($data['delivery_cents'] / 100, 2, ',', ''),
|
||||
'invoice' => (int) $data['invoice'],
|
||||
|
|
@ -872,6 +876,8 @@ function page_booking_new(array $user, string $method): void
|
|||
'start_time' => '',
|
||||
'end_time' => '',
|
||||
'deposit' => '',
|
||||
'deposit_required' => 0,
|
||||
'deposit_account' => '',
|
||||
'rent' => '',
|
||||
'delivery' => '',
|
||||
'invoice' => 0,
|
||||
|
|
@ -926,6 +932,8 @@ function page_booking_edit(array $user, int $id, string $method): void
|
|||
'start_time' => (string) ($booking['start_time'] ?? ''),
|
||||
'end_time' => (string) ($booking['end_time'] ?? ''),
|
||||
'deposit' => number_format((int) $booking['deposit_cents'] / 100, 2, ',', ''),
|
||||
'deposit_required' => (int) ($booking['deposit_required'] ?? 0),
|
||||
'deposit_account' => (string) ($booking['deposit_account'] ?? ''),
|
||||
'rent' => number_format((int) $booking['rent_cents'] / 100, 2, ',', ''),
|
||||
'delivery' => number_format((int) $booking['delivery_cents'] / 100, 2, ',', ''),
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
|
|
@ -950,6 +958,8 @@ function page_booking_edit(array $user, int $id, string $method): void
|
|||
$data = booking_input($_POST);
|
||||
if (!$canEditBilling) {
|
||||
$data['deposit_cents'] = (int) $booking['deposit_cents'];
|
||||
$data['deposit_required'] = (int) ($booking['deposit_required'] ?? 0);
|
||||
$data['deposit_account'] = (string) ($booking['deposit_account'] ?? '');
|
||||
$data['rent_cents'] = (int) $booking['rent_cents'];
|
||||
$data['delivery_cents'] = (int) $booking['delivery_cents'];
|
||||
$data['total_cents'] = (int) $booking['total_cents'];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue