From 9ce6375b3329e62b78cb0447737a4eeb87ca3da2 Mon Sep 17 00:00:00 2001 From: Andrei Laas Date: Tue, 1 Dec 2026 12:12:59 +0100 Subject: [PATCH] FL statt VL, Stufen 1 bis 7 Die Angabe heisst ueberall "FL" (Einstellung, Wiedereintritt, Daten aendern, Akte, Zusammenfassung, Export, Austauschdatei). Gespeichert bleibt sie in vl, in Historie und Feldkarte als "VL"; anzeige() zeigt dort "FL". Migration 20261201120000: chk_vl auf 1 bis 7. Bestand mit 8 wird geleert und je Person im Protokoll vermerkt ("FL geleert"). Geplante Aenderungen auf 8 verlieren diese Angabe in Vormerkung und Historienzeile; bleibt nichts uebrig, entfaellt der Vorgang samt Zeile. Jeweils Protokolleintrag. Geprueft: lint, tsc, types:check, npm test (1123), waechter; Migrationen auf leerer Datenbank zweimal (Nichts anzuwenden), rauchtest.sql, vertragsangaben.sql (FL 8 abgewiesen, Wiedereintritt mit FL 6); Bestand mit FL 8, geplanter Aenderung FL 8 plus Bonus und geplanter Aenderung nur FL 8: geleert, Bonus bleibt vorgemerkt, Vorgang entfaellt. --- app/api/export/employees/route.ts | 2 +- .../employees/VertragsangabenFields.tsx | 4 +- components/employees/tabs/VertragTab.tsx | 2 +- components/hire/StepSummary.tsx | 2 +- components/hire/types.ts | 2 +- .../20261201120000_fl_ohne_stufe_8.sql | 78 +++++++++++++++++++ db/tests/vertragsangaben.sql | 12 +-- lib/anzeige.ts | 2 + lib/austausch/format.ts | 2 +- lib/austausch/katalog.ts | 2 +- lib/types.ts | 2 +- lib/vertragsangaben.ts | 9 ++- .../components/VertragsangabenFields.test.tsx | 10 +-- tests/unit/vertragsangaben.test.ts | 18 ++++- 14 files changed, 119 insertions(+), 28 deletions(-) create mode 100644 db/migrations/20261201120000_fl_ohne_stufe_8.sql diff --git a/app/api/export/employees/route.ts b/app/api/export/employees/route.ts index a83c2f2..32a0bdc 100644 --- a/app/api/export/employees/route.ts +++ b/app/api/export/employees/route.ts @@ -115,7 +115,7 @@ function employeeExportColumns( // weiterverarbeiten, die Bezeichnung das, was ein Mensch liest. { header: "C-Level", get: (e) => e.c_level }, { header: "Hay-Grade", get: (e) => e.paygrade }, - { header: "VL", get: (e) => e.vl }, + { header: "FL", get: (e) => e.vl }, { header: "Bonusanspruch", get: (e) => e.has_bonusanspruch }, { header: "Bonusregelung", get: (e) => e.bonusanspruch_art }, { header: "Herkunft", get: (e) => e.source }, diff --git a/components/employees/VertragsangabenFields.tsx b/components/employees/VertragsangabenFields.tsx index e798493..fb7c2e8 100644 --- a/components/employees/VertragsangabenFields.tsx +++ b/components/employees/VertragsangabenFields.tsx @@ -3,7 +3,7 @@ import { SelectField } from "@/components/ui/Field"; import { BONUSREGELUNGEN, VL_STUFEN } from "@/lib/vertragsangaben"; -// VL und Bonusanspruch — dieselben Felder im Einstellungsassistenten, im +// FL und Bonusanspruch — dieselben Felder im Einstellungsassistenten, im // Wiedereintritt und in „Daten ändern". Eine Komponente statt drei Kopien, // wie bei „Anstellungsart": drei Kopien laufen auseinander, und dann // bietet eine Stelle eine Bonusregelung an, die eine andere nicht kennt. @@ -28,7 +28,7 @@ export function VertragsangabenFields({ return ( <> onChange({ vl })} diff --git a/components/employees/tabs/VertragTab.tsx b/components/employees/tabs/VertragTab.tsx index 0cff082..69a006e 100644 --- a/components/employees/tabs/VertragTab.tsx +++ b/components/employees/tabs/VertragTab.tsx @@ -87,7 +87,7 @@ export function VertragTab({ // Kollektivvertrag und wird hier nicht geführt. Eine feste Zahl für alle // wäre erfunden, und eine erfundene Zahl ist schlechter als keine. ["Hay-Grade", hayGradeLabel(employee.paygrade)], - ["VL", vlLabel(employee.vl)], + ["FL", vlLabel(employee.vl)], // Wie beim Dienstwagen: statt eines blossen „Ja" gleich die Regelung. ["Bonusanspruch", ohneVorgabe(employee, ["has_bonusanspruch"], bonusanspruchLabel(employee.has_bonusanspruch, employee.bonusanspruch_art))], ["Beschäftigtengruppe", ohneVorgabe(employee, ["worker_type"], anzeige(employee.worker_type) ?? "–")], diff --git a/components/hire/StepSummary.tsx b/components/hire/StepSummary.tsx index 197de3a..ad59955 100644 --- a/components/hire/StepSummary.tsx +++ b/components/hire/StepSummary.tsx @@ -80,7 +80,7 @@ export function StepSummary({ draft, selectedPosition, locations, extern = false ["Vertragsart", draft.contractType === "befristet" ? `befristet bis ${fmtDate(draft.contractEndDate)}` : "unbefristet"], ["Beschäftigungsausmaß", `${draft.employmentType} (${draft.weeklyHours} h)`], ["Hay-Grade", hayGradeLabel(draft.paygrade)], - ["VL", draft.vl || "–"], + ["FL", draft.vl || "–"], ["Bonusanspruch", bonusanspruchLabel(draft.hasBonusanspruch, draft.bonusanspruchArt)], ["Beschäftigtengruppe", anzeige(draft.workerType)], ...(draft.workerType === "Lehrling" diff --git a/components/hire/types.ts b/components/hire/types.ts index f0a3be3..ff97b0a 100644 --- a/components/hire/types.ts +++ b/components/hire/types.ts @@ -84,7 +84,7 @@ export type HireDraftData = { teilzeitBis: string; /** Leer heisst „noch nicht bewertet" und ist der Normalfall beim Anlegen. */ paygrade: PaygradeType | ""; - /** VL 1–8 als Text; "" heisst nicht erfasst. */ + /** FL 1–7 als Text; "" heisst nicht erfasst. */ vl: string; hasBonusanspruch: boolean; /** Nur ausgewertet, wenn hasBonusanspruch gesetzt ist — so will es der CHECK. */ diff --git a/db/migrations/20261201120000_fl_ohne_stufe_8.sql b/db/migrations/20261201120000_fl_ohne_stufe_8.sql new file mode 100644 index 0000000..61a9827 --- /dev/null +++ b/db/migrations/20261201120000_fl_ohne_stufe_8.sql @@ -0,0 +1,78 @@ +-- FL: Stufen 1 bis 7 +-- +-- Die Angabe heisst fachlich „FL" und kennt die Stufen 1 bis 7. Gespeichert +-- bleibt sie in der Spalte vl, und in der Historie und der Feldkarte heisst +-- das Feld weiter „VL": daran hängen Berichtigen und Zurücksetzen bestehender +-- Einträge. Die Oberfläche zeigt „FL" (lib/anzeige.ts). +-- +-- Bestand mit Stufe 8: welche Stufe stattdessen gilt, geht aus den Daten +-- nicht hervor. Die Angabe wird geleert und je Person im Protokoll vermerkt; +-- ein geratener Wert sähe aus wie ein erfasster. Geplante Änderungen auf +-- Stufe 8 verlieren diese eine Angabe, in der Vormerkung und in ihrer +-- Historienzeile; der Rest des Vorgangs bleibt. Bleibt nichts übrig, entfällt +-- der Vorgang samt Zeile, wie beim Abbrechen in der Historie. + +do $geplant$ +declare + v_plan record; + v_payload jsonb; +begin + for v_plan in + select * from pending_org_changes + where status = 'pending' and payload->'contract'->>'vl' = '8' + loop + v_payload := jsonb_set(v_plan.payload, '{contract}', (v_plan.payload->'contract') - 'vl'); + + insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details) + select null, 'Wartung', 'Geplante Änderung angepasst', e.first_name || ' ' || e.last_name, e.id, + 'Zum ' || v_plan.effective_date || ' war FL 8 vorgemerkt. Die Stufe 8 gibt es nicht mehr; ' + || 'diese Angabe entfällt aus dem Vorgang.' + from employees e where e.id = v_plan.employee_id; + + if coalesce(v_payload->'person', '{}'::jsonb) = '{}'::jsonb + and coalesce(v_payload->'contract', '{}'::jsonb) = '{}'::jsonb + and coalesce(v_payload->'role', '{}'::jsonb) = '{}'::jsonb then + update pending_org_changes set status = 'cancelled' where id = v_plan.id; + delete from employee_history where pending_id = v_plan.id; + else + update pending_org_changes set payload = v_payload where id = v_plan.id; + -- In der Beschreibung steht die Liste der Felder, jedes gefolgt von + -- einem Komma („Geänderte Felder: VL, Bonusanspruch, wirksam ab …"). + update employee_history h + set changes = (select coalesce(jsonb_agg(a), '[]'::jsonb) + from jsonb_array_elements(h.changes) a + where a->>'feld' <> 'VL'), + description = replace(h.description, 'VL, ', '') + where h.pending_id = v_plan.id; + end if; + end loop; +end +$geplant$; + +insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details) +select null, 'Wartung', 'FL geleert', e.first_name || ' ' || e.last_name, e.id, + 'Die Stufe 8 gibt es nicht mehr; FL war 8 und ist jetzt leer. Bitte die zutreffende Stufe (1 bis 7) nachtragen.' + from employees e + where e.vl = 8; + +update employees set vl = null where vl = 8; + +alter table employees drop constraint if exists chk_vl; +alter table employees add constraint chk_vl check (vl is null or vl between 1 and 7); + +comment on column employees.vl is 'FL, Stufe 1 bis 7; leer heisst nicht erfasst. In Historie und Feldkarte als „VL" geführt.'; + +do $pruefung$ +begin + if exists (select 1 from employees where vl not between 1 and 7) then + raise exception 'Es gibt noch FL-Werte ausserhalb von 1 bis 7.'; + end if; + if exists (select 1 from pending_org_changes where status = 'pending' and payload->'contract'->>'vl' = '8') then + raise exception 'Es gibt noch geplante Änderungen auf FL 8.'; + end if; + if pg_get_constraintdef((select oid from pg_constraint where conname = 'chk_vl' and conrelid = 'public.employees'::regclass)) + not like '%vl >= 1%vl <= 7%' then + raise exception 'chk_vl erlaubt nicht genau 1 bis 7.'; + end if; +end +$pruefung$; diff --git a/db/tests/vertragsangaben.sql b/db/tests/vertragsangaben.sql index 352d6db..31b0bf3 100644 --- a/db/tests/vertragsangaben.sql +++ b/db/tests/vertragsangaben.sql @@ -149,14 +149,14 @@ begin perform hire_employee(jsonb_build_object( 'personnel_number', v_nr + 2, 'first_name', 'X', 'last_name', 'Y', 'gender', 'm', 'birth_date', '1980-01-01', 'location_id', v_ort, 'position_id', v_p3, - 'entry_date', current_date::text, 'vl', 9)); + 'entry_date', current_date::text, 'vl', 8)); v_ging := true; exception when others then v_ging := false; end; if v_ging then - raise exception '3: VL 9 wurde angenommen.'; + raise exception '3: FL 8 wurde angenommen.'; end if; - raise notice '3/9 Abgewiesen: Bonus ohne Regelung, abgeschaltete HR, „Süßwaren", VL 9'; + raise notice '3/9 Abgewiesen: Bonus ohne Regelung, abgeschaltete HR, „Süßwaren", FL 8'; -- ── 4. Daten ändern, sofort ──────────────────────────────────── perform change_employee_data(jsonb_build_object( @@ -271,16 +271,16 @@ begin 'employee_id', v_a, 'rehire_date', current_date::text, 'position_id', v_p3, 'first_name', 'Vertrag', 'last_name', 'Test-A', 'gender', 'w', 'birth_date', '1990-01-01', 'nationality', 'Österreich', 'location_id', v_ort, - 'vl', 8, 'has_bonusanspruch', false, 'zustaendige_hr_id', v_hr1, + 'vl', 6, 'has_bonusanspruch', false, 'zustaendige_hr_id', v_hr1, 'collective_agreement', 'Süßware Angestellter', 'erlernter_beruf', 'Bäckerin')); select * into v_e from employees where id = v_a; - if v_e.vl <> 8 or v_e.has_bonusanspruch or v_e.bonusanspruch_art is not null + if v_e.vl <> 6 or v_e.has_bonusanspruch or v_e.bonusanspruch_art is not null or v_e.zustaendige_hr_id <> v_hr1 or v_e.collective_agreement::text <> 'Süßware Angestellter' or v_e.erlernter_beruf is distinct from 'Bäckerin' then raise exception '9: Wiedereintritt hat VL/Bonus/HR/KV nicht übernommen: % % % % %', v_e.vl, v_e.has_bonusanspruch, v_e.bonusanspruch_art, v_e.zustaendige_hr_id, v_e.collective_agreement; end if; - raise notice '9/9 Wiedereintritt übernimmt VL 8, Bonus Nein, HR und Süßware Angestellter'; + raise notice '9/9 Wiedereintritt übernimmt FL 6, Bonus Nein, HR und Süßware Angestellter'; raise notice 'Vertragsangaben-Rauchtest bestanden. Alles Angelegte wird gleich verworfen.'; end diff --git a/lib/anzeige.ts b/lib/anzeige.ts index 7fcfe76..09c67f1 100644 --- a/lib/anzeige.ts +++ b/lib/anzeige.ts @@ -41,6 +41,8 @@ const REGELN: readonly (readonly [RegExp, string])[] = [ // Ganze Wörter, die fachlich anders heissen als gespeichert. const UMBENANNT: readonly (readonly [RegExp, string])[] = [ [new RegExp(`(? { expect(screen.getByLabelText(/Bonusregelung/)).toBeTruthy(); }); - it("steht bei Nein, ohne VL", () => { + it("steht bei Nein, ohne FL", () => { render( {}} />); expect((screen.getByLabelText("Bonusanspruch") as HTMLSelectElement).value).toBe("nein"); - expect((screen.getByLabelText("VL") as HTMLSelectElement).value).toBe(""); + expect((screen.getByLabelText("FL") as HTMLSelectElement).value).toBe(""); }); - it("bietet VL 1 bis 8 und leer an", () => { + it("bietet FL 1 bis 7 und leer an", () => { render( {}} />); - const werte = [...(screen.getByLabelText("VL") as HTMLSelectElement).options].map((o) => o.value); - expect(werte).toEqual(["", "1", "2", "3", "4", "5", "6", "7", "8"]); + const werte = [...(screen.getByLabelText("FL") as HTMLSelectElement).options].map((o) => o.value); + expect(werte).toEqual(["", "1", "2", "3", "4", "5", "6", "7"]); }); it("belegt bei Ja keine Regelung vor", () => { diff --git a/tests/unit/vertragsangaben.test.ts b/tests/unit/vertragsangaben.test.ts index af1f4d7..3d52d3b 100644 --- a/tests/unit/vertragsangaben.test.ts +++ b/tests/unit/vertragsangaben.test.ts @@ -1,6 +1,7 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; +import { anzeige } from "@/lib/anzeige"; import { KOLLEKTIVVERTRAEGE } from "@/lib/kollektivvertrag"; import { BONUSREGELUNGEN, @@ -19,6 +20,7 @@ import { const migration = (datei: string) => readFileSync(join(process.cwd(), "db/migrations", datei), "utf8"); const VERTRAG = migration("20261007100000_vl_bonus_zustaendige_hr.sql"); const KV = migration("20261007090000_kollektivvertraege.sql"); +const FL = migration("20261201120000_fl_ohne_stufe_8.sql"); function werteDerBedingung(sql: string, name: string): string[] { const block = sql.match(new RegExp(`${name}\\s+check[\\s\\S]*?\\);`))?.[0]; @@ -49,10 +51,18 @@ describe("Bonusregelungen", () => { }); }); -describe("VL", () => { - it("geht von 1 bis 8, wie in der Datenbank", () => { - expect([...VL_STUFEN]).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - expect(VERTRAG).toContain("vl is null or vl between 1 and 8"); +describe("FL", () => { + it("geht von 1 bis 7, wie in der Datenbank", () => { + expect([...VL_STUFEN]).toEqual([1, 2, 3, 4, 5, 6, 7]); + expect(FL).toContain("vl is null or vl between 1 and 7"); + }); + + it("heisst in der Anzeige FL, auch als Feld der Historie", () => { + expect(anzeige("VL")).toBe("FL"); + expect(anzeige("Geänderte Felder: VL, Bonusanspruch, wirksam ab 2026-12-01")).toBe( + "Geänderte Felder: FL, Bonusanspruch, wirksam ab 01.12.2026" + ); + expect(anzeige("VLB")).toBe("VLB"); }); it("zeigt „–“, wenn nichts erfasst ist", () => {