Compare commits

...

5 Commits

Author SHA1 Message Date
Jonny ca252fc5c8 Merge feature/tankfuellstand: Tankfuellstand bei Abgabe, kompakter Auftragskopf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 21:42:31 +01:00
Jonny c3c42313fb feat: Tankfuellstand-Auswahl im Auftrag, Kopf zeigt nur Name und Ort
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:12:34 +01:00
Jonny 132ce9606b feat: Tankfuellstand in Formularpruefung (Anlegen, Bearbeiten, Klonen)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:05:58 +01:00
Jonny 8ca964b3fb feat(db): Tankfuellstand bei Abgabe, nur Dispo/Admin aenderbar
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:01:10 +01:00
Jonny fe2aa04025 docs: Spec und Plan Tankfuellstand bei Abgabe
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:59:39 +01:00
16 changed files with 252 additions and 3 deletions

View File

@ -0,0 +1,17 @@
# Tankfüllstand Implementation Plan
**Spec:** docs/superpowers/specs/2026-11-08-tankfuellstand-design.md
1. Migration `20261108100000_auftraege_tankfuellstand.sql` mit Spalte, Check und Schutz-Trigger, dazu pgTAP `auftraege_tankfuellstand_test.sql`.
Tests: Check lehnt „2/3“ ab, Fahrer darf nicht ändern, Disponent darf.
2. `lib/auftraege/tankfuellstand.ts`: `TANKFUELLSTAENDE`, `parseTankfuellstand`, `tankfuellstandText`, mit Vitest.
3. In `validate-auftrag.ts` bekommen Anlegen und Klonen `tankfuellstand_abgabe`, Tests erweitern.
4. UI:
- `TankfuellstandFeld` in `AuftragStammFelder`.
- Bearbeiten und Klonen werden vorbelegt, `queries.ts` liest die Spalte.
- Detail bekommt Kopf mit `adresse_kurz` und das Tankfeld.
5. Abschluss:
- Tests, tsc, lint, build.
- Merge.
- Master-Stack neu bauen.
- Live prüfen.

View File

@ -0,0 +1,31 @@
# Tankfüllstand bei Abgabe + kompakter Auftragskopf
## Anlass
Der Disponent soll beim Anlegen eines Auftrags vorgeben können, mit welchem
Tankfüllstand das Fahrzeug am Ziel abgegeben wird. Der Kopf der
Auftragsansicht zeigt bisher die vollen Adressen, die weiter unten ohnehin
stehen.
## Entscheidungen (Nutzer)
- Auswahl zum Ankreuzen: 1/4, 1/2, 3/4, voll.
- Optional: ohne Auswahl gilt „keine Vorgabe“. Bestehende Aufträge bleiben unverändert.
- Kopf der Auftragsansicht: nur Name und Ort von Start und Ziel.
## Umsetzung
- Spalte `auftraege.tankfuellstand_abgabe text null`, Check auf die vier Werte.
- Nur Disponent/Admin dürfen den Wert ändern: eigener BEFORE-UPDATE-Trigger
(`auftrag_tankfuellstand_schuetzen`). Die Fahrer-Update-Policy erlaubt
sonst Änderungen am eigenen Auftrag.
- Formular (Anlegen, Bearbeiten, Klonen): Radio-Gruppe mit „keine Vorgabe“,
1/4, 1/2, 3/4, voll. Große Touch-Flächen.
- Unbekannte Werte aus dem Formular werden zu `null` (wie die
Zeitplanung-Fallbacks). Meine Entscheidung.
- Klonen übernimmt den Wert der Vorlage. Folgeauftrag startet ohne Vorgabe.
Meine Entscheidung.
- Detailansicht: Feld „Tankfüllstand bei Abgabe“ in den Stammdaten.
- Kopf: `abholort.adresse_kurz → zielort.adresse_kurz`. Der DB-Trigger
liefert dort schon „Name, Ort“ bzw. ohne Namen PLZ/Ort.
## Nicht enthalten
- Erfassung des tatsächlichen Tankstands durch den Fahrer und Ausgabe im
Übergabeprotokoll (PDF).

View File

@ -0,0 +1,29 @@
-- Tankfuellstand, mit dem das Fahrzeug am Ziel abgegeben werden soll.
-- Vorgabe des Disponenten, optional (null = keine Vorgabe).
alter table public.auftraege
add column tankfuellstand_abgabe text
constraint auftraege_tankfuellstand_abgabe_check
check (tankfuellstand_abgabe in ('1/4', '1/2', '3/4', 'voll'));
-- Die Fahrer-Update-Policy erlaubt Aenderungen am eigenen Auftrag; die
-- Vorgabe gehoert aber dem Disponenten.
create or replace function public.auftrag_tankfuellstand_schuetzen()
returns trigger
language plpgsql
security definer
set search_path = public
as $$
begin
if new.tankfuellstand_abgabe is distinct from old.tankfuellstand_abgabe
and coalesce(public.user_role()::text, '') not in ('admin', 'disponent')
and auth.uid() is not null
then
raise exception 'Nur Disponent/Admin duerfen den Tankfuellstand aendern';
end if;
return new;
end;
$$;
create trigger auftrag_tankfuellstand_schuetzen
before update on public.auftraege
for each row execute function public.auftrag_tankfuellstand_schuetzen();

View File

@ -0,0 +1,57 @@
begin;
select plan(5);
insert into auth.users (id, email) values
('a1111111-1111-1111-1111-111111111111', 'admin@tank.test.local'),
('b2222222-2222-2222-2222-222222222222', 'fahrer@tank.test.local');
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f001' where firma_id is null;
update public.profiles set role = 'admin' where id = 'a1111111-1111-1111-1111-111111111111';
update public.profiles set role = 'fahrer' where id = 'b2222222-2222-2222-2222-222222222222';
insert into public.orte (id, adresse, ansprechpartner, firma_id) values
('01111111-1111-1111-1111-111111111111', 'Hauptstr. 1, Musterstadt', 'Frau Muster', '00000000-0000-0000-0000-00000000f001'),
('02222222-2222-2222-2222-222222222222', 'Nebenweg 2, Musterstadt', 'Herr Beispiel', '00000000-0000-0000-0000-00000000f001');
insert into public.fahrzeuge (id, kennzeichen, firma_id) values
('f0000000-0000-0000-0000-000000000001', 'M-AB 123', '00000000-0000-0000-0000-00000000f001');
insert into public.auftraege (id, abholort_id, zielort_id, fahrzeug_id, erstellt_von, status, zugewiesen_an, tankfuellstand_abgabe, firma_id) values
('40000000-0000-0000-0000-000000000001', '01111111-1111-1111-1111-111111111111', '02222222-2222-2222-2222-222222222222',
'f0000000-0000-0000-0000-000000000001', 'a1111111-1111-1111-1111-111111111111', 'zugewiesen',
'b2222222-2222-2222-2222-222222222222', '1/2', '00000000-0000-0000-0000-00000000f001');
select throws_ok(
$$ update public.auftraege set tankfuellstand_abgabe = '2/3' where id = '40000000-0000-0000-0000-000000000001' $$,
'23514', null,
'Unbekannter Tankfuellstand wird vom Check abgelehnt'
);
select lives_ok(
$$ update public.auftraege set tankfuellstand_abgabe = null where id = '40000000-0000-0000-0000-000000000001' $$,
'Ohne Vorgabe (null) ist erlaubt'
);
update public.auftraege set tankfuellstand_abgabe = '1/2' where id = '40000000-0000-0000-0000-000000000001';
set local role authenticated;
set local request.jwt.claims to '{"sub": "b2222222-2222-2222-2222-222222222222", "role": "authenticated"}';
select throws_ok(
$$ update public.auftraege set tankfuellstand_abgabe = 'voll' where id = '40000000-0000-0000-0000-000000000001' $$,
'P0001', 'Nur Disponent/Admin duerfen den Tankfuellstand aendern',
'Fahrer darf die Tank-Vorgabe nicht aendern'
);
set local request.jwt.claims to '{"sub": "a1111111-1111-1111-1111-111111111111", "role": "authenticated"}';
select lives_ok(
$$ update public.auftraege set tankfuellstand_abgabe = 'voll' where id = '40000000-0000-0000-0000-000000000001' $$,
'Admin darf die Tank-Vorgabe aendern'
);
reset role;
select is(
(select tankfuellstand_abgabe from public.auftraege where id = '40000000-0000-0000-0000-000000000001'),
'voll',
'Wert des Admins ist gespeichert'
);
select * from finish();
rollback;

View File

@ -62,6 +62,7 @@ export default async function AuftragBearbeitenPage({
fahrzeugId: auftrag.fahrzeug.id,
auftragsnummer: auftrag.auftragsnummer,
zeitplanungTyp: auftrag.zeitplanung_typ,
tankfuellstand: auftrag.tankfuellstand_abgabe,
zeitplanungZeitpunkt: auftrag.zeitplanung_zeitpunkt
? alsDatetimeLocal(auftrag.zeitplanung_zeitpunkt)
: undefined,

View File

@ -59,6 +59,7 @@ export default async function AuftragKlonenPage({
abholortId: auftrag.abholort.id,
zielortId: auftrag.zielort.id,
zeitplanungTyp: auftrag.zeitplanung_typ,
tankfuellstand: auftrag.tankfuellstand_abgabe,
zeitplanungZeitpunkt: auftrag.zeitplanung_zeitpunkt
? alsDatetimeLocal(auftrag.zeitplanung_zeitpunkt)
: undefined,

View File

@ -2,6 +2,7 @@ import { notFound } from "next/navigation";
import Link from "next/link";
import { loadAuftrag, findeFolgeauftrag } from "@/lib/auftraege/queries";
import { formatZeitplanung } from "@/lib/auftraege/zeitplanung";
import { tankfuellstandText } from "@/lib/auftraege/tankfuellstand";
import { folgeauftragUrl } from "@/lib/auftraege/klonen";
import { loadProfile } from "@/lib/auth/profile";
import { istEinsatzrolle, kannAuftraegeVerwalten, personBezeichnung } from "@/lib/auth/roles";
@ -81,7 +82,7 @@ export default async function AuftragDetailPage({
</Link>
)}
<h1 className="text-xl font-semibold text-asphalt-grey">
{auftrag.abholort.adresse} → {auftrag.zielort.adresse}
{auftrag.abholort.adresse_kurz} → {auftrag.zielort.adresse_kurz}
</h1>
</Card>
@ -176,6 +177,10 @@ export default async function AuftragDetailPage({
{formatZeitplanung(auftrag.zeitplanung_typ, auftrag.zeitplanung_zeitpunkt)}
</dd>
</div>
<div>
<dt className="text-sm text-asphalt-grey/70">Tankfüllstand bei Abgabe</dt>
<dd className="text-asphalt-grey">{tankfuellstandText(auftrag.tankfuellstand_abgabe)}</dd>
</div>
<div>
<dt className="text-sm text-asphalt-grey/70">Zugewiesen an</dt>
<dd className="text-asphalt-grey">

View File

@ -1,7 +1,9 @@
import type { Fahrzeug, Ort } from "@/lib/auftraege/queries";
import type { ZeitplanungTyp } from "@/lib/auftraege/zeitplanung";
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
import type { Tankfuellstand } from "@/lib/auftraege/tankfuellstand";
import { ZeitplanungFeld } from "@/components/auftraege/ZeitplanungFeld";
import { TankfuellstandFeld } from "@/components/auftraege/TankfuellstandFeld";
import { AuftragAuswahlFelder } from "@/components/auswahl/AuftragAuswahlFelder";
export type AuftragStammWerte = {
@ -11,6 +13,7 @@ export type AuftragStammWerte = {
auftragsnummer?: string;
zeitplanungTyp?: ZeitplanungTyp;
zeitplanungZeitpunkt?: string;
tankfuellstand?: Tankfuellstand | null;
};
// Gemeinsame Felder fuer "Auftrag anlegen", "bearbeiten" und "klonen". Formular
@ -50,6 +53,8 @@ export function AuftragStammFelder({
startZeitpunkt={werte.zeitplanungZeitpunkt}
/>
<TankfuellstandFeld startWert={werte.tankfuellstand} />
{!ohneFahrzeugUndNummer && (
<FormField label={nummerLabel} htmlFor="auftragsnummer">
<input

View File

@ -0,0 +1,33 @@
import { TANKFUELLSTAENDE, tankfuellstandText, type Tankfuellstand } from "@/lib/auftraege/tankfuellstand";
const OPTIONEN: { wert: string; text: string }[] = [
{ wert: "", text: tankfuellstandText(null) },
...TANKFUELLSTAENDE.map((wert) => ({ wert, text: tankfuellstandText(wert) })),
];
// Vorgabe des Disponenten, mit welchem Tankstand das Fahrzeug am Ziel
// abgegeben wird. "Keine Vorgabe" sendet einen leeren Wert (= null).
export function TankfuellstandFeld({ startWert }: { startWert?: Tankfuellstand | null }) {
return (
<fieldset className="mb-4">
<legend className="mb-1 text-sm font-medium text-asphalt-grey">Tankfüllstand bei Abgabe (optional)</legend>
<div className="grid grid-cols-2 gap-2 sm:grid-cols-5">
{OPTIONEN.map(({ wert, text }) => (
<label
key={wert || "keine"}
className="flex min-h-11 cursor-pointer items-center justify-center gap-2 rounded-md border border-aluminium-grey px-3 py-2 text-sm text-asphalt-grey has-[:checked]:border-performance-blue has-[:checked]:bg-blue-50 has-[:checked]:font-medium has-[:focus-visible]:outline has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-performance-blue"
>
<input
type="radio"
name="tankfuellstand_abgabe"
value={wert}
defaultChecked={(startWert ?? "") === wert}
className="h-4 w-4 accent-performance-blue"
/>
{text}
</label>
))}
</div>
</fieldset>
);
}

View File

@ -8,6 +8,7 @@ function makeAuftrag(overrides: Partial<Auftrag> = {}): Auftrag {
auftragsnummer: "A-2026-0001",
zeitplanung_typ: "ab_sofort",
zeitplanung_zeitpunkt: null,
tankfuellstand_abgabe: null,
status: "abgeschlossen",
abholort: { id: "o1", adresse: "Hauptstr. 1, Musterstadt", adresse_kurz: "Hauptstr. 1, Musterstadt", name: null, strasse: "Hauptstr. 1, Musterstadt", hausnummer: null, plz: null, ort: null, ansprechpartner: "Frau Muster", telefon: null, email: null },
zielort: { id: "o2", adresse: "Nebenweg 2, Musterstadt", adresse_kurz: "Nebenweg 2, Musterstadt", name: null, strasse: "Nebenweg 2, Musterstadt", hausnummer: null, plz: null, ort: null, ansprechpartner: "Herr Beispiel", telefon: null, email: null },

View File

@ -1,3 +1,4 @@
import type { Tankfuellstand } from "./tankfuellstand";
import type { SupabaseClient } from "@supabase/supabase-js";
import { createClient } from "@/lib/supabase/server";
import type { Role } from "@/lib/auth/roles";
@ -37,6 +38,7 @@ export type Auftrag = {
auftragsnummer: string;
zeitplanung_typ: ZeitplanungTyp;
zeitplanung_zeitpunkt: string | null;
tankfuellstand_abgabe: Tankfuellstand | null;
status: AuftragStatus;
abholort: Ort;
zielort: Ort;
@ -58,7 +60,7 @@ export type Auftrag = {
};
const AUFTRAG_SELECT =
`id, auftragsnummer, zeitplanung_typ, zeitplanung_zeitpunkt, status, zugewiesen_an, start_zeit, fahrt_beginn_at, start_km, end_km, start_fin, start_fin_status, uebergabe_bestaetigt_at, empfaenger_name, unterschrift_storage_path, vorgaenger_auftrag_id, created_at, abholort:orte!auftraege_abholort_id_fkey(${ORT_SPALTEN}), zielort:orte!auftraege_zielort_id_fkey(${ORT_SPALTEN}), fahrzeug:fahrzeuge(id, kennzeichen, fin, marke, modell), erstellt_von:profiles!auftraege_erstellt_von_fkey(id, name), zugewiesen_an_profil:profiles!auftraege_zugewiesen_an_fkey(id, name)`;
`id, auftragsnummer, zeitplanung_typ, zeitplanung_zeitpunkt, tankfuellstand_abgabe, status, zugewiesen_an, start_zeit, fahrt_beginn_at, start_km, end_km, start_fin, start_fin_status, uebergabe_bestaetigt_at, empfaenger_name, unterschrift_storage_path, vorgaenger_auftrag_id, created_at, abholort:orte!auftraege_abholort_id_fkey(${ORT_SPALTEN}), zielort:orte!auftraege_zielort_id_fkey(${ORT_SPALTEN}), fahrzeug:fahrzeuge(id, kennzeichen, fin, marke, modell), erstellt_von:profiles!auftraege_erstellt_von_fkey(id, name), zugewiesen_an_profil:profiles!auftraege_zugewiesen_an_fkey(id, name)`;
export async function listOrte(): Promise<Ort[]> {
const supabase = await createClient();

View File

@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { parseTankfuellstand, tankfuellstandText, TANKFUELLSTAENDE } from "./tankfuellstand";
describe("tankfuellstand", () => {
it("kennt die vier Stufen in Reihenfolge", () => {
expect(TANKFUELLSTAENDE).toEqual(["1/4", "1/2", "3/4", "voll"]);
});
it("uebernimmt gueltige Werte", () => {
expect(parseTankfuellstand("3/4")).toBe("3/4");
expect(parseTankfuellstand("voll")).toBe("voll");
});
it("macht leere, fehlende und unbekannte Werte zu null", () => {
expect(parseTankfuellstand("")).toBeNull();
expect(parseTankfuellstand(null)).toBeNull();
expect(parseTankfuellstand("2/3")).toBeNull();
});
it("beschriftet Werte fuer die Anzeige", () => {
expect(tankfuellstandText("1/4")).toBe("1/4");
expect(tankfuellstandText("voll")).toBe("Voll");
expect(tankfuellstandText(null)).toBe("Keine Vorgabe");
});
});

View File

@ -0,0 +1,16 @@
// Tankfuellstand, mit dem das Fahrzeug am Ziel abgegeben werden soll
// (Vorgabe des Disponenten, optional).
export const TANKFUELLSTAENDE = ["1/4", "1/2", "3/4", "voll"] as const;
export type Tankfuellstand = (typeof TANKFUELLSTAENDE)[number];
export function parseTankfuellstand(wert: FormDataEntryValue | null): Tankfuellstand | null {
return typeof wert === "string" && (TANKFUELLSTAENDE as readonly string[]).includes(wert)
? (wert as Tankfuellstand)
: null;
}
export function tankfuellstandText(wert: Tankfuellstand | null): string {
if (wert === null) return "Keine Vorgabe";
return wert === "voll" ? "Voll" : wert;
}

View File

@ -21,6 +21,7 @@ describe("validateAuftragEingaben", () => {
auftragsnummer: "24-A",
zeitplanung_typ: "ab_sofort",
zeitplanung_zeitpunkt: null,
tankfuellstand_abgabe: null,
},
});
});
@ -98,6 +99,7 @@ describe("validateKlonEingaben", () => {
fahrzeug_ids: ["f1", "f2"],
zeitplanung_typ: "ab_sofort",
zeitplanung_zeitpunkt: null,
tankfuellstand_abgabe: null,
},
});
});
@ -131,3 +133,22 @@ describe("validateKlonEingaben", () => {
});
});
});
describe("Tankfuellstand bei Abgabe", () => {
it("uebernimmt den Wert beim Anlegen", () => {
const ergebnis = validateAuftragEingaben(formular({ ...GUELTIG, tankfuellstand_abgabe: "1/2" }));
expect(ergebnis.valid && ergebnis.werte.tankfuellstand_abgabe).toBe("1/2");
});
it("ist ohne Auswahl null", () => {
const ergebnis = validateAuftragEingaben(formular(GUELTIG));
expect(ergebnis.valid && ergebnis.werte.tankfuellstand_abgabe).toBeNull();
});
it("uebernimmt den Wert beim Klonen", () => {
const fd = formular({ abholort_id: "o1", zielort_id: "o2", zeitplanung_typ: "ab_sofort", tankfuellstand_abgabe: "voll" });
fd.append("fahrzeug_ids", "f1");
const ergebnis = validateKlonEingaben(fd);
expect(ergebnis.valid && ergebnis.werte.tankfuellstand_abgabe).toBe("voll");
});
});

View File

@ -1,3 +1,4 @@
import { parseTankfuellstand, type Tankfuellstand } from "./tankfuellstand";
import { ZEITPLANUNG_TYPEN, type ZeitplanungTyp, parseZeitplanungZeitpunkt } from "./zeitplanung";
export type AuftragWerte = {
@ -7,6 +8,7 @@ export type AuftragWerte = {
auftragsnummer: string | null;
zeitplanung_typ: ZeitplanungTyp;
zeitplanung_zeitpunkt: string | null;
tankfuellstand_abgabe: Tankfuellstand | null;
};
export type AuftragValidierung = { valid: true; werte: AuftragWerte } | { valid: false; error: string };
@ -15,7 +17,7 @@ function textOderLeer(wert: FormDataEntryValue | null): string {
return typeof wert === "string" ? wert : "";
}
type StreckeUndZeit = Pick<AuftragWerte, "abholort_id" | "zielort_id" | "zeitplanung_typ" | "zeitplanung_zeitpunkt">;
type StreckeUndZeit = Pick<AuftragWerte, "abholort_id" | "zielort_id" | "zeitplanung_typ" | "zeitplanung_zeitpunkt" | "tankfuellstand_abgabe">;
export type KlonWerte = StreckeUndZeit & { fahrzeug_ids: string[] };
@ -49,6 +51,7 @@ function pruefeStreckeUndZeit(formData: FormData): { valid: true; werte: Strecke
zielort_id: zielortId,
zeitplanung_typ: zeitplanungTyp,
zeitplanung_zeitpunkt: zeitplanungZeitpunkt,
tankfuellstand_abgabe: parseTankfuellstand(formData.get("tankfuellstand_abgabe")),
},
};
}
@ -72,6 +75,7 @@ export function validateAuftragEingaben(formData: FormData): AuftragValidierung
auftragsnummer: nummer || null,
zeitplanung_typ: basis.werte.zeitplanung_typ,
zeitplanung_zeitpunkt: basis.werte.zeitplanung_zeitpunkt,
tankfuellstand_abgabe: basis.werte.tankfuellstand_abgabe,
},
};
}

View File

@ -11,6 +11,7 @@ function makeAuftrag(overrides: Partial<Auftrag> = {}): Auftrag {
auftragsnummer: "26-09-01-0001",
zeitplanung_typ: "ab_sofort",
zeitplanung_zeitpunkt: null,
tankfuellstand_abgabe: null,
status: "abgeschlossen",
abholort: { id: "o1", adresse: "Hauptstr. 1, Musterstadt", adresse_kurz: "Hauptstr. 1, Musterstadt", name: null, strasse: "Hauptstr. 1, Musterstadt", hausnummer: null, plz: null, ort: null, ansprechpartner: "Frau Muster", telefon: null, email: null },
zielort: { id: "o2", adresse: "Nebenweg 2, Musterstadt", adresse_kurz: "Nebenweg 2, Musterstadt", name: null, strasse: "Nebenweg 2, Musterstadt", hausnummer: null, plz: null, ort: null, ansprechpartner: "Herr Beispiel", telefon: null, email: null },