Rechnungsnummer zur Buchung ergänzen (Feld „Rechnung" der Vorlage)

Die Vorlage Neuanlage enthält bei „Rechnung" eine Rechnungsnummer
(RE2026054), nicht nur Ja/Nein. Neu:

- bookings.invoice_no (VARCHAR 40, Migration 004)
- Formularfeld „Rechnungsnummer": eine eingetragene Nummer setzt
  „Rechnung" automatisch auf JA (auch serverseitig)
- Detail, Panel und Kopiertext zeigen die Nummer („Rechnung: JA (RE…)")
- Validierung: max. 40 Zeichen, nur Buchstaben, Ziffern und . / - sowie
  Leerzeichen
- Cache-Buster auf Version 11
This commit is contained in:
torsten 2026-11-18 21:27:50 +01:00
parent 25830560bc
commit 7fd77d58d7
11 changed files with 64 additions and 12 deletions

View file

@ -130,6 +130,9 @@ function booking_input(array $source): array
$delivery = 0;
}
$invoiceNo = trim((string) ($source['invoice_no'] ?? ''));
$invoice = $invoiceNo !== '' || ((string) ($source['invoice'] ?? '0')) === '1' ? 1 : 0;
return [
'trailer_id' => (int) ($source['trailer_id'] ?? 0),
'employee_id' => (int) ($source['employee_id'] ?? 0),
@ -141,7 +144,8 @@ function booking_input(array $source): array
'rent_cents' => $rent,
'delivery_cents' => $delivery,
'total_cents' => $rent + $delivery,
'invoice' => ((string) ($source['invoice'] ?? '0')) === '1' ? 1 : 0,
'invoice' => $invoice,
'invoice_no' => $invoiceNo,
'kind' => in_array($kind, ['pickup', 'delivery'], true) ? $kind : 'pickup',
'customer_name' => trim((string) ($source['customer_name'] ?? '')),
'street' => trim((string) ($source['street'] ?? '')),
@ -166,6 +170,7 @@ function booking_to_input(array $booking): array
'delivery_cents' => (int) ($booking['delivery_cents'] ?? 0),
'total_cents' => (int) $booking['total_cents'],
'invoice' => (int) $booking['invoice'],
'invoice_no' => (string) ($booking['invoice_no'] ?? ''),
'kind' => (string) $booking['kind'],
'customer_name' => (string) $booking['customer_name'],
'street' => (string) $booking['street'],
@ -236,6 +241,14 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
}
}
if ($data['invoice_no'] !== '') {
if (mb_strlen($data['invoice_no']) > 40) {
$errors['invoice_no'] = 'Die Rechnungsnummer ist zu lang (max. 40 Zeichen).';
} elseif (preg_match('/^[A-Za-z0-9._\/\- ]+$/', $data['invoice_no']) !== 1) {
$errors['invoice_no'] = 'Die Rechnungsnummer darf nur Buchstaben, Ziffern, Punkt, Schrägstrich, Bindestrich und Leerzeichen enthalten.';
}
}
$maxAmount = 10000000; // 100.000,00 €
if ($data['rent_cents'] < 0 || $data['delivery_cents'] < 0 || $data['deposit_cents'] < 0) {
$errors['rent'] = 'Beträge dürfen nicht negativ sein.';
@ -289,15 +302,15 @@ function booking_create(array $data, int $userId): int
$stmt = $pdo->prepare(
'INSERT INTO bookings
(trailer_id, employee_id, start_date, end_date, start_time, end_time, deposit_cents,
rent_cents, delivery_cents, total_cents, invoice, kind,
rent_cents, delivery_cents, total_cents, invoice, invoice_no, 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'],
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['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
utc_now(), utc_now(), $userId, $userId,
]);
@ -328,14 +341,14 @@ function booking_update(int $id, array $data, int $userId): void
$stmt = $pdo->prepare(
'UPDATE bookings SET 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 = ?,
total_cents = ?, invoice = ?, invoice_no = ?, 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'],
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['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
utc_now(), $userId, $id,
]);
@ -472,6 +485,14 @@ function booking_invoice_label(int|string $invoice): string
return (int) $invoice === 1 ? 'JA' : 'NEIN';
}
/** Rechnung inklusive Nummer, z. B. "JA (RE2026054)". */
function booking_invoice_display(array $booking): string
{
$label = booking_invoice_label($booking['invoice']);
$number = trim((string) ($booking['invoice_no'] ?? ''));
return $number === '' ? $label : $label . ' (' . $number . ')';
}
/** Exakt der Text aus der Anforderung, Zeile für Zeile. */
function booking_copy_text(array $booking): string
{
@ -479,7 +500,7 @@ function booking_copy_text(array $booking): string
'Anzahlung: ' . fmt_money((int) $booking['deposit_cents']),
'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']),
'Rechnung: ' . booking_invoice_display($booking),
'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']),

View file

@ -479,6 +479,7 @@ function form_values_from_input(array $data): array
'rent' => number_format($data['rent_cents'] / 100, 2, ',', ''),
'delivery' => number_format($data['delivery_cents'] / 100, 2, ',', ''),
'invoice' => (int) $data['invoice'],
'invoice_no' => (string) ($data['invoice_no'] ?? ''),
'kind' => (string) $data['kind'],
'customer_name' => (string) $data['customer_name'],
'street' => (string) $data['street'],
@ -524,6 +525,7 @@ function page_booking_new(array $user, string $method): void
'rent' => '',
'delivery' => '',
'invoice' => 0,
'invoice_no' => '',
'kind' => 'pickup',
'customer_name' => '',
'street' => '',
@ -571,6 +573,7 @@ function page_booking_edit(array $user, int $id, string $method): void
'rent' => number_format((int) $booking['rent_cents'] / 100, 2, ',', ''),
'delivery' => number_format((int) $booking['delivery_cents'] / 100, 2, ',', ''),
'invoice' => (int) $booking['invoice'],
'invoice_no' => (string) ($booking['invoice_no'] ?? ''),
'kind' => (string) $booking['kind'],
'customer_name' => (string) $booking['customer_name'],
'street' => (string) $booking['street'],

View file

@ -89,7 +89,7 @@ function url(string $path = '/'): string
}
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
const DIC_ASSET_VERSION = '10';
const DIC_ASSET_VERSION = '11';
function asset(string $path): string
{