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:
parent
25830560bc
commit
7fd77d58d7
11 changed files with 64 additions and 12 deletions
|
|
@ -14,7 +14,8 @@ Die Anforderungen stammen aus
|
|||
durchgehender, farbiger Balken in der Farbe des Anhängers.
|
||||
- **Buchungen** mit Anfangs- und Endtermin (Datum, Uhrzeit optional), Miete,
|
||||
Lieferkosten, automatisch berechnetem Gesamtbetrag und Restbetrag, Anzahlung,
|
||||
Rechnung JA/NEIN, Abholung/Lieferung und vollständigen Kundendaten.
|
||||
Rechnung JA/NEIN samt Rechnungsnummer, Abholung/Lieferung und vollständigen
|
||||
Kundendaten.
|
||||
- **Buchungstext kopieren** mit einem Klick – exakt in der geforderten
|
||||
Reihenfolge und mit erhaltenen Zeilenumbrüchen.
|
||||
- **Doppelbelegungsschutz**: Ein Anhänger kann im gleichen Zeitraum nicht
|
||||
|
|
|
|||
35
app/data.php
35
app/data.php
|
|
@ -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']),
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ Browser
|
|||
| `trailers` | Anhänger mit Bezeichnung, Farbname, Hex-Farbe, Sortierung und Aktiv-Status (Start-Anhänger aus der Anforderung vorinstalliert, weitere im Admin anlegbar) |
|
||||
| `employees` | Mitarbeiter (M. Krücken, N. Jorns, M. Schmitz), aktiv/inaktiv |
|
||||
| `users` | Login-Konten (Vorname, Nachname, Passwort-Hash, Rolle, optional E-Mail, optional Mitarbeiter-Link) |
|
||||
| `bookings` | Buchung inkl. Zeitraum (Datum + optionale Uhrzeit), Miete/Lieferkosten mit Gesamtbetrag, Anzahlung, Rechnungsflag, Art, Kundendaten, Status |
|
||||
| `bookings` | Buchung inkl. Zeitraum (Datum + optionale Uhrzeit), Miete/Lieferkosten mit Gesamtbetrag, Anzahlung, Rechnungsflag und Rechnungsnummer, Art, Kundendaten, Status |
|
||||
| `reminder_done` | Abgehakte Erinnerung, Schlüssel `(booking_id, kind, due_date)` |
|
||||
| `reminder_mail_log` | Versandprotokoll, verhindert doppelte E-Mails |
|
||||
| `push_subscriptions` | Web-Push-Abos pro Gerät (Endpoint-Hash, p256dh, auth, letzter Erfolg/Fehler) |
|
||||
|
|
@ -144,7 +144,7 @@ sind die primäre Anzeige und funktionieren ohne Mailversand.
|
|||
| 4. Felder in fester Reihenfolge | Formular und Kopiervorlage in exakt der vorgegebenen Reihenfolge; Uhrzeit optional |
|
||||
| Restbetrag automatisch | `total_cents − deposit_cents`, live im Formular und serverseitig berechnet |
|
||||
| Miete + Lieferkosten | `rent_cents` + `delivery_cents` = `total_cents`, live im Formular mitgerechnet |
|
||||
| Rechnung JA/NEIN, Art Abholer/Lieferung | Radio-Auswahl, Labels wie gefordert |
|
||||
| Rechnung JA/NEIN, Art Abholer/Lieferung | Radio-Auswahl, Labels wie gefordert; Rechnungsnummer optional, setzt JA automatisch |
|
||||
| Komplett kopieren | Button nutzt Clipboard-API, Fallback `execCommand`; Text enthält Zeilenumbrüche |
|
||||
| 5. Mitarbeiterzuordnung | `bookings.employee_id`, Auswahl im Formular, änderbar |
|
||||
| 6. Drei automatische Erinnerungen | serverseitig aus den Daten berechnet, an den Mitarbeiter gebunden |
|
||||
|
|
|
|||
9
sql/migrations/004_booking_invoice_no.sql
Normal file
9
sql/migrations/004_booking_invoice_no.sql
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-- Rechnungsnummer als eigenes Feld (Vorlage „Neuanlage", Feld „Rechnung").
|
||||
--
|
||||
-- Die Vorlage trägt dort keine Ja/Nein-Markierung, sondern die Nummer der
|
||||
-- Rechnung (z. B. RE2026054). Das bisherige Flag `invoice` bleibt als
|
||||
-- Auswertung erhalten: Es ist gesetzt, sobald eine Nummer hinterlegt ist
|
||||
-- oder „Rechnung = JA" gewählt wurde.
|
||||
|
||||
ALTER TABLE bookings
|
||||
ADD COLUMN invoice_no VARCHAR(40) NULL DEFAULT NULL AFTER invoice;
|
||||
|
|
@ -68,6 +68,7 @@ CREATE TABLE IF NOT EXISTS bookings (
|
|||
delivery_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
total_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
invoice TINYINT(1) NOT NULL DEFAULT 0,
|
||||
invoice_no VARCHAR(40) NULL DEFAULT NULL,
|
||||
kind ENUM('pickup', 'delivery') NOT NULL DEFAULT 'pickup',
|
||||
customer_name VARCHAR(190) NOT NULL,
|
||||
street VARCHAR(190) NOT NULL DEFAULT '',
|
||||
|
|
@ -168,6 +169,7 @@ INSERT IGNORE INTO employees (name, sort_order, created_at) VALUES
|
|||
INSERT IGNORE INTO schema_migrations (version, applied_at) VALUES (1, UTC_TIMESTAMP());
|
||||
INSERT IGNORE INTO schema_migrations (version, applied_at) VALUES (2, UTC_TIMESTAMP());
|
||||
INSERT IGNORE INTO schema_migrations (version, applied_at) VALUES (3, UTC_TIMESTAMP());
|
||||
INSERT IGNORE INTO schema_migrations (version, applied_at) VALUES (4, UTC_TIMESTAMP());
|
||||
|
||||
-- Web-Push-Abos (VAPID) und Versandprotokoll für Erinnerungen.
|
||||
CREATE TABLE IF NOT EXISTS push_subscriptions (
|
||||
|
|
|
|||
|
|
@ -153,6 +153,9 @@ $returnTo = '/bookings/' . (int) $booking['id'];
|
|||
<div><dt>Bis</dt><dd><?= e(fmt_date_long($booking['end_date'])) ?><?php if (fmt_time($booking['end_time'] ?? null) !== ''): ?> · <?= e(fmt_time($booking['end_time'])) ?> Uhr<?php endif; ?></dd></div>
|
||||
<div><dt>Art</dt><dd><span class="pill pill--blue"><?= e(booking_kind_label((string) $booking['kind'])) ?></span></dd></div>
|
||||
<div><dt>Rechnung</dt><dd><span class="pill <?= (int) $booking['invoice'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= e(booking_invoice_label($booking['invoice'])) ?></span></dd></div>
|
||||
<?php if (trim((string) ($booking['invoice_no'] ?? '')) !== ''): ?>
|
||||
<div><dt>Rechnungsnummer</dt><dd><?= e((string) $booking['invoice_no']) ?></dd></div>
|
||||
<?php endif; ?>
|
||||
</dl>
|
||||
<hr>
|
||||
<dl class="money-list">
|
||||
|
|
|
|||
|
|
@ -172,6 +172,12 @@ $backUrl = $isEdit ? '/bookings/' . (int) $booking['id'] : '/calendar';
|
|||
<label><input type="radio" name="invoice" value="1"<?= (int) $values['invoice'] === 1 ? ' checked' : '' ?>><span>JA</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<label class="field<?= $fieldError('invoice_no') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Rechnungsnummer</span>
|
||||
<input type="text" name="invoice_no" value="<?= e($values['invoice_no']) ?>" maxlength="40" placeholder="z. B. RE2026054" data-invoice-no>
|
||||
<?php if ($fieldError('invoice_no')): ?><em class="field-error"><?= e($fieldError('invoice_no')) ?></em><?php endif; ?>
|
||||
<em class="muted small">Wird eine Nummer eingetragen, gilt die Buchung automatisch als „Rechnung: JA".</em>
|
||||
</label>
|
||||
<div class="field">
|
||||
<span>Art</span>
|
||||
<div class="segmented-radio">
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ foreach ($reminders as $reminder) {
|
|||
<div><dt>Anhänger</dt><dd><?= e($booking['trailer_label'] . ' · ' . $booking['trailer_color_name']) ?></dd></div>
|
||||
<div><dt>Mitarbeiter</dt><dd><?= e($booking['employee_name']) ?></dd></div>
|
||||
<div><dt>Art</dt><dd><?= e(booking_kind_label((string) $booking['kind'])) ?></dd></div>
|
||||
<div><dt>Rechnung</dt><dd><?= e(booking_invoice_label($booking['invoice'])) ?></dd></div>
|
||||
<div><dt>Rechnung</dt><dd><?= e(booking_invoice_display($booking)) ?></dd></div>
|
||||
<div><dt>Miete</dt><dd><?= e(fmt_money((int) $booking['rent_cents'])) ?></dd></div>
|
||||
<div><dt>Lieferkosten</dt><dd><?= e(fmt_money((int) $booking['delivery_cents'])) ?></dd></div>
|
||||
<div><dt>Gesamt</dt><dd><?= e(fmt_money((int) $booking['total_cents'])) ?></dd></div>
|
||||
|
|
|
|||
|
|
@ -362,6 +362,13 @@
|
|||
startTimeInput?.addEventListener('input', updateSummary);
|
||||
endTimeInput?.addEventListener('input', updateSummary);
|
||||
|
||||
// Rechnungsnummer gesetzt -> "Rechnung: JA" mitziehen.
|
||||
const invoiceNoInput = bookingForm.querySelector('[data-invoice-no]');
|
||||
const invoiceYes = bookingForm.querySelector('input[name="invoice"][value="1"]');
|
||||
invoiceNoInput?.addEventListener('input', () => {
|
||||
if (invoiceNoInput.value.trim() !== '' && invoiceYes) invoiceYes.checked = true;
|
||||
});
|
||||
|
||||
updateTrailer();
|
||||
updateTotals();
|
||||
updateSummary();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue