diff --git a/actions/employees.ts b/actions/employees.ts index c12354c..7b6a3b4 100644 --- a/actions/employees.ts +++ b/actions/employees.ts @@ -276,8 +276,31 @@ export async function transferEmployee(payload: { effective_date: string; /** Die Zielplanstelle; Bereich, Abteilung und Team ergeben sich aus ihrer Einheit. */ target_position_id: string; + /** + * Ein neuer Standort, wenn er mit der Versetzung wechselt — fachlich + * vorgegeben. Leer oder unverändert heisst: der Standort bleibt. + */ + location_id?: string; }): Promise { - return callRpc("transfer_employee", payload, [`/employees/${payload.employee_id}`, "/employees"]); + const { location_id, ...versetzung } = payload; + try { + // In einer Transaktion: eine Versetzung ohne den mitbeschlossenen + // Standortwechsel wäre eine halbe. + await withUser(await currentUserId(), async (tx) => { + await callFunction(tx, "transfer_employee", versetzung); + if (location_id) { + await callFunction(tx, "change_employee_data", { + employee_id: payload.employee_id, + effective_date: payload.effective_date, + role: { location_id }, + }); + } + }); + } catch (err) { + return { success: false, error: err instanceof Error ? err.message : "Unbekannter Fehler." }; + } + for (const path of [`/employees/${payload.employee_id}`, "/employees"]) revalidatePath(path); + return { success: true }; } export async function promoteEmployee(payload: { diff --git a/app/(app)/layout.tsx b/app/(app)/layout.tsx index f867a48..8031345 100644 --- a/app/(app)/layout.tsx +++ b/app/(app)/layout.tsx @@ -1,3 +1,4 @@ +import { StandorteProvider } from "@/components/shell/StandorteContext"; import { redirect } from "next/navigation"; import type { ReactNode } from "react"; import { HireWizardProvider } from "@/components/hire/HireWizardContext"; @@ -37,11 +38,13 @@ export default async function AppLayout({ children }: { children: ReactNode }) { return ( + ({ id: l.id, name: l.name }))}> {children} + ); } diff --git a/components/employees/EmployeeDetail.tsx b/components/employees/EmployeeDetail.tsx index 46411db..7b481f3 100644 --- a/components/employees/EmployeeDetail.tsx +++ b/components/employees/EmployeeDetail.tsx @@ -299,6 +299,7 @@ export function EmployeeDetail(props: EmployeeDetailProps) { onClose={() => setPanel(null)} employee={employee} openPositions={openPositions} + locations={locations} /> { if (feld === ZUSTAENDIGE_HR_FELD) return hrOptionen(hrBenutzer, werte[feld] ?? "").slice(1); + if (feld === STANDORT_FELD) return standorte.map((s) => ({ value: s.id, label: s.name })); // Was in der Zeile steht, gehört in die Auswahl, auch wenn es nicht in // der Liste vorkommt — ein frei eingetragenes Verhältnis zum // Notfallkontakt, ein Wert, den die Liste heute nicht führt. @@ -197,6 +200,8 @@ export function HistorieBearbeiten({ {c.vorher === null || c.vorher === "" ? ( leer + ) : c.feld === STANDORT_FELD ? ( + standortName(standorte, c.vorher) ) : c.feld === ZUSTAENDIGE_HR_FELD ? ( hrName(hrBenutzer, c.vorher) ) : ( diff --git a/components/employees/panels/TransferPanel.tsx b/components/employees/panels/TransferPanel.tsx index f96947f..c30881e 100644 --- a/components/employees/panels/TransferPanel.tsx +++ b/components/employees/panels/TransferPanel.tsx @@ -5,7 +5,7 @@ import { useMemo, useState } from "react"; import { geplantenVorgangErsetzen, transferEmployee } from "@/actions/employees"; import { Button } from "@/components/ui/Button"; import { PlanstellenAuswahl } from "@/components/positions/PlanstellenAuswahl"; -import { DateField } from "@/components/ui/Field"; +import { DateField, SelectField } from "@/components/ui/Field"; import { SlideOver } from "@/components/ui/SlideOver"; import { useToast } from "@/components/ui/Toast"; import { mitBisherigerStelle, type GeplanterVorgang } from "@/lib/geplanter-vorgang"; @@ -22,6 +22,8 @@ type TransferPanelProps = { openPositions: OpenPositionResolved[]; /** Eine geplante Versetzung, die geändert wird (lib/geplanter-vorgang.ts). */ ersetzt?: GeplanterVorgang | null; + /** Die Standorte zur Auswahl — mit der Versetzung kann auch der Standort wechseln. */ + locations?: { id: string; name: string }[]; }; // Eine Versetzung ist der Wechsel auf eine andere Planstelle — nicht die @@ -29,13 +31,15 @@ type TransferPanelProps = { // Team ergeben sich aus der Einheit der Zielplanstelle, die neue Tätigkeit aus // ihrem Job. Damit kann eine Versetzung gar nicht erst irgendwo landen, wo es // keine Stelle gibt. -export function TransferPanel({ open, onClose, employee, openPositions, ersetzt }: TransferPanelProps) { +export function TransferPanel({ open, onClose, employee, openPositions, ersetzt, locations = [] }: TransferPanelProps) { const { showToast } = useToast(); const router = useRouter(); // Ein Stichtag in der Vergangenheit gehört zu einer liegengebliebenen // Vormerkung; ihn vorzubelegen schlüge eine sofort wirksame Versetzung vor. const [effectiveDate, setEffectiveDate] = useState(ersetzt && ersetzt.datum > todayIso() ? ersetzt.datum : ""); const [positionId, setPositionId] = useState(ersetzt?.vorgemerkt.target_position_id ?? ""); + // Vorbelegt mit dem bisherigen Standort; geschickt wird er nur, wenn er wechselt. + const [standort, setStandort] = useState(employee.location_id); const [pending, setPending] = useState(false); // Die bisher vorgemerkte Zielplanstelle steht nicht unter den offenen — @@ -67,6 +71,7 @@ export function TransferPanel({ open, onClose, employee, openPositions, ersetzt employee_id: employee.id, effective_date: effectiveDate, target_position_id: positionId, + location_id: standort !== employee.location_id ? standort : undefined, }); setPending(false); if (result.success) { @@ -117,6 +122,17 @@ export function TransferPanel({ open, onClose, employee, openPositions, ersetzt onChange={setPositionId} /> )} + {/* Nur bei einer neuen Versetzung: an einer geplanten werden + Planstelle und Datum geändert. */} + {!ersetzt && locations.length > 0 && ( + ({ value: l.id, label: l.name }))} + hint="Wechselt mit der Versetzung zum selben Tag; sonst bleibt der bisherige." + /> + )} ); diff --git a/components/shell/StandorteContext.tsx b/components/shell/StandorteContext.tsx new file mode 100644 index 0000000..a1eda0e --- /dev/null +++ b/components/shell/StandorteContext.tsx @@ -0,0 +1,28 @@ +"use client"; + +import { createContext, useContext, type ReactNode } from "react"; + +// Die Standorte, einmal mit der Hülle geladen. Die Historie speichert beim +// Feld „Standort" die Kennung; angezeigt und gewählt wird der Name — wie bei +// der zuständigen HR (HrBenutzerContext). + +export type StandortEintrag = { id: string; name: string }; + +/** Die Bezeichnung des Feldes in app_feld_karte und in der Historie. */ +export const STANDORT_FELD = "Standort"; + +const StandorteContext = createContext([]); + +export function StandorteProvider({ standorte, children }: { standorte: StandortEintrag[]; children: ReactNode }) { + return {children}; +} + +export function useStandorte(): StandortEintrag[] { + return useContext(StandorteContext); +} + +/** Der Name zu einer Kennung; die Kennung selbst, wenn der Standort nicht mehr existiert. */ +export function standortName(liste: StandortEintrag[], id: string | null | undefined): string { + if (!id) return "–"; + return liste.find((s) => s.id === id)?.name ?? id; +} diff --git a/components/ui/AenderungsTabelle.tsx b/components/ui/AenderungsTabelle.tsx index 488330d..9b10c40 100644 --- a/components/ui/AenderungsTabelle.tsx +++ b/components/ui/AenderungsTabelle.tsx @@ -1,6 +1,7 @@ "use client"; import { hrName, useHrBenutzer } from "@/components/shell/HrBenutzerContext"; +import { STANDORT_FELD, standortName, useStandorte } from "@/components/shell/StandorteContext"; import { ZUSTAENDIGE_HR_FELD } from "@/lib/historie-felder"; import { anzeige } from "@/lib/anzeige"; import type { AuditChange } from "@/lib/types"; @@ -21,8 +22,14 @@ export function AenderungsTabelle({ changes }: { changes: AuditChange[] }) { // Die zuständige HR steht als Kennung im Protokoll — sie ist es, die sich // zurücksetzen lässt. Gezeigt wird der Name. const hrBenutzer = useHrBenutzer(); + // Ebenso der Standort: gespeichert ist die Kennung, gezeigt der Name. + const standorte = useStandorte(); const wert = (feld: string, text: string | null) => - feld === ZUSTAENDIGE_HR_FELD && text ? hrName(hrBenutzer, text) : anzeige(text); + feld === ZUSTAENDIGE_HR_FELD && text + ? hrName(hrBenutzer, text) + : feld === STANDORT_FELD && text + ? standortName(standorte, text) + : anzeige(text); return (
diff --git a/db/migrations/20261022110000_standort_aenderbar.sql b/db/migrations/20261022110000_standort_aenderbar.sql new file mode 100644 index 0000000..6694094 --- /dev/null +++ b/db/migrations/20261022110000_standort_aenderbar.sql @@ -0,0 +1,84 @@ +-- Der Standort einer Person lässt sich ändern. +-- +-- Fachlich vorgegeben: mit einer Versetzung kann auch der Standort wechseln. +-- Geändert wird er über change_employee_data (Gruppe `role`), mit Stichtag: +-- sofort wirksam oder vorgemerkt wie jede andere Vertragsänderung, mit Zeile +-- in der Historie, berichtigbar und zurücknehmbar. Gespeichert wird in der +-- Historie die Kennung des Standorts; die Oberfläche zeigt den Namen. +-- +-- Ein leer geschickter Standort ändert nichts — die Spalte ist Pflicht. +-- +-- Ergänzt wird an der laufenden Definition, an den Zeilen der Lehrzeit +-- (20261021100000), an genau einem Anker je Stelle. +do $migration$ +declare + v_ziele text[][] := array[ + array['change_employee_data', + $a$if v_role ? 'lehrzeit_bis' then v_contract_changes := app_aenderung(v_contract_changes, 'Lehrzeit bis', v_old.lehrzeit_bis::text, (nullif(v_role->>'lehrzeit_bis', '')::date)::text); end if;$a$, + $a$if v_role ? 'lehrzeit_bis' then v_contract_changes := app_aenderung(v_contract_changes, 'Lehrzeit bis', v_old.lehrzeit_bis::text, (nullif(v_role->>'lehrzeit_bis', '')::date)::text); end if; + if nullif(v_role->>'location_id', '') is not null then v_contract_changes := app_aenderung(v_contract_changes, 'Standort', v_old.location_id::text, (v_role->>'location_id')::uuid::text); end if;$a$], + array['change_employee_data', + $a$lehrzeit_bis = case when v_role ? 'lehrzeit_bis' then nullif(v_role->>'lehrzeit_bis', '')::date else lehrzeit_bis end,$a$, + $a$lehrzeit_bis = case when v_role ? 'lehrzeit_bis' then nullif(v_role->>'lehrzeit_bis', '')::date else lehrzeit_bis end, + location_id = coalesce(nullif(v_role->>'location_id', '')::uuid, location_id),$a$], + array['apply_due_pending_changes', + $a$lehrzeit_bis = case when v_role ? 'lehrzeit_bis' then nullif(v_role->>'lehrzeit_bis', '')::date else lehrzeit_bis end,$a$, + $a$lehrzeit_bis = case when v_role ? 'lehrzeit_bis' then nullif(v_role->>'lehrzeit_bis', '')::date else lehrzeit_bis end, + location_id = coalesce(nullif(v_role->>'location_id', '')::uuid, location_id),$a$], + array['app_feld_karte', + $a$'Lehrzeit bis', jsonb_build_array('lehrzeit_bis', 'date', 'role'),$a$, + $a$'Lehrzeit bis', jsonb_build_array('lehrzeit_bis', 'date', 'role'), + 'Standort', jsonb_build_array('location_id', 'uuid', 'role'),$a$] + ]; + v_fn text; + v_def text; + v_treffer integer; + i integer; +begin + foreach v_fn in array array['change_employee_data', 'apply_due_pending_changes', 'app_feld_karte'] loop + select pg_get_functiondef(p.oid) into v_def + from pg_proc p join pg_namespace n on n.oid = p.pronamespace + where n.nspname = 'public' and p.prokind = 'f' and p.proname = v_fn; + if v_def is null then + raise exception '% ist nicht vorhanden.', v_fn; + end if; + if position('location_id = coalesce(nullif(v_role' in v_def) > 0 or position('''Standort''' in v_def) > 0 then + raise notice '% kennt den Standort bereits — nichts zu tun.', v_fn; + continue; + end if; + for i in 1 .. array_length(v_ziele, 1) loop + continue when v_ziele[i][1] <> v_fn; + v_treffer := (length(v_def) - length(replace(v_def, v_ziele[i][2], ''))) / length(v_ziele[i][2]); + if v_treffer <> 1 then + raise exception '%: Anker % kommt % mal vor, erwartet genau einmal.', v_fn, i, v_treffer; + end if; + v_def := replace(v_def, v_ziele[i][2], v_ziele[i][3]); + end loop; + execute v_def; + end loop; +end +$migration$; + +do $pruefung$ +declare + v_def text; +begin + select pg_get_functiondef(p.oid) into v_def + from pg_proc p join pg_namespace n on n.oid = p.pronamespace + where n.nspname = 'public' and p.prokind = 'f' and p.proname = 'change_employee_data'; + if position('''Standort''' in v_def) = 0 or position('location_id = coalesce(nullif(v_role' in v_def) = 0 + or position('lehrzeit_von' in v_def) = 0 or position('require_hr_admin()' in v_def) = 0 + or position('v_pending_vertrag' in v_def) = 0 then + raise exception 'change_employee_data ist nicht wie erwartet angepasst.'; + end if; + select pg_get_functiondef(p.oid) into v_def + from pg_proc p join pg_namespace n on n.oid = p.pronamespace + where n.nspname = 'public' and p.prokind = 'f' and p.proname = 'apply_due_pending_changes'; + if position('location_id = coalesce(nullif(v_role' in v_def) = 0 then + raise exception 'Der Nachtlauf setzt den Standort nicht.'; + end if; + if not (app_feld_karte() ? 'Standort' and app_feld_karte() ? 'Lehrzeit bis') then + raise exception 'Die Feldkarte kennt den Standort nicht.'; + end if; +end +$pruefung$; diff --git a/db/tests/rauchtest.sql b/db/tests/rauchtest.sql index eac01cd..92cc78b 100644 --- a/db/tests/rauchtest.sql +++ b/db/tests/rauchtest.sql @@ -77,14 +77,14 @@ begin 'job_title', 'Rauchtest Drei', 'is_chief', false, 'valid_from', (current_date - 30)::text)); v_p4 := create_position(jsonb_build_object('org_unit_id', v_einheit, 'job_title', 'Rauchtest Vier', 'is_chief', false, 'valid_from', (current_date - 30)::text)); - raise notice '1/29 Einheit und vier Planstellen angelegt'; + raise notice '1/30 Einheit und vier Planstellen angelegt'; -- ── Einstellung ───────────────────────────────────────────────── v_a := hire_employee(jsonb_build_object( 'personnel_number', v_nr, 'first_name', 'Rauch', 'last_name', 'Test-A', 'gender', 'w', 'birth_date', '1990-01-01', 'location_id', v_ort, 'position_id', v_p1, 'entry_date', current_date::text)); - raise notice '2/29 Einstellung auf Planstelle 1'; + raise notice '2/30 Einstellung auf Planstelle 1'; -- ── Versetzung am selben Tag (20260929180000) ─────────────────── -- Die Besetzung begann heute; sie auf heute zu schliessen wäre ein @@ -97,7 +97,7 @@ begin if v_stelle is distinct from v_p2 then raise exception 'Nach der Versetzung sitzt die Person nicht auf Planstelle 2.'; end if; - raise notice '3/29 Versetzung am selben Tag'; + raise notice '3/30 Versetzung am selben Tag'; -- ── Beförderung mit Planstellenwechsel, ebenfalls heute ───────── perform promote_employee(jsonb_build_object( @@ -122,7 +122,7 @@ begin if v_titel <> 'Rauchtest Leitung' then raise exception 'Die Zielplanstelle heisst nach der Beförderung „%", erwartet „Rauchtest Leitung".', v_titel; end if; - raise notice '4/29 Beförderung am selben Tag: Hay-Grade und Planstellenbezeichnung'; + raise notice '4/30 Beförderung am selben Tag: Hay-Grade und Planstellenbezeichnung'; -- Dieselbe Planstelle, nur ein neuer Name. perform promote_employee(jsonb_build_object( @@ -140,7 +140,7 @@ begin if not exists (select 1 from jobs where title = 'Rauchtest Leitung') then raise exception 'Der alte Katalogeintrag wurde umbenannt statt die Planstelle umgehängt.'; end if; - raise notice '4b/29 Beförderung ohne Stellenwechsel benennt dieselbe Planstelle um'; + raise notice '4b/30 Beförderung ohne Stellenwechsel benennt dieselbe Planstelle um'; -- ── Vorgemerkte Planstelle (20260929200000) ───────────────────── -- Eine Versetzung in die Zukunft belegt die Zielstelle, obwohl dort noch @@ -171,13 +171,13 @@ begin if v_meldung not like '%bereits eine Versetzung vorgemerkt%' then raise exception 'Erwartet wurde die Meldung zur Vormerkung, kam aber: %', v_meldung; end if; - raise notice '5/29 Vorgemerkte Planstelle wird abgewiesen'; + raise notice '5/30 Vorgemerkte Planstelle wird abgewiesen'; -- Die eigene Vormerkung darf nicht im Weg stehen: dieselbe Versetzung noch -- einmal zu erfassen ist eine Berichtigung. perform transfer_employee(jsonb_build_object( 'employee_id', v_a, 'target_position_id', v_p4, 'effective_date', (current_date + 20)::text)); - raise notice '6/29 Die eigene Vormerkung steht nicht im Weg'; + raise notice '6/30 Die eigene Vormerkung steht nicht im Weg'; -- ── Austritt am selben Tag (20260929220000) ───────────────────── perform terminate_employee(jsonb_build_object( @@ -189,7 +189,7 @@ begin if v_offen <> 0 then raise exception 'Nach dem Austritt ist die Planstelle nicht frei.'; end if; - raise notice '7/29 Austritt am selben Tag, Planstelle frei'; + raise notice '7/30 Austritt am selben Tag, Planstelle frei'; -- ── Wiedereintritt (20260929160000) ───────────────────────────── perform rehire_employee(jsonb_build_object( @@ -206,7 +206,7 @@ begin if v_stelle is distinct from v_p1 then raise exception 'Nach dem Wiedereintritt sitzt die Person nicht auf Planstelle 1.'; end if; - raise notice '8/29 Wiedereintritt'; + raise notice '8/30 Wiedereintritt'; -- ── Rückdatierte Versetzung (20261013140000) ──────────────────── -- @@ -241,7 +241,7 @@ begin if v_stelle is distinct from v_p2 then raise exception 'Nach der rückdatierten Versetzung sitzt die Person nicht auf Planstelle 2.'; end if; - raise notice '9/29 Rückdatierte Versetzung lässt keine zweite Besetzung stehen'; + raise notice '9/30 Rückdatierte Versetzung lässt keine zweite Besetzung stehen'; -- ── Versetzung bei datiertem Austritt (20261013140000) ────────── -- @@ -275,7 +275,7 @@ begin if v_offen <> 1 then raise exception 'Die neue Besetzung endet nicht am Austrittstag.'; end if; - raise notice '10/29 Versetzung bei datiertem Austritt: kein Überlappen, kein Überleben'; + raise notice '10/30 Versetzung bei datiertem Austritt: kein Überlappen, kein Überleben'; -- ── Änderung vor dem Eintritt (20261018100000) ────────────────── -- @@ -314,7 +314,7 @@ begin and event_date = current_date + 40) then raise exception 'Mit dem Eintritt ist die Änderung davor nicht mitgewandert.'; end if; - raise notice '11/29 Änderung vor dem Eintritt wirkt sofort und wandert mit dem Eintritt'; + raise notice '11/30 Änderung vor dem Eintritt wirkt sofort und wandert mit dem Eintritt'; -- ── Abwesenheit mit geplanter Rückkehr löschen (20261019100000) ─ -- @@ -352,7 +352,7 @@ begin if v_status <> 'Aktiv' then raise exception 'Nach dem Löschen der Abwesenheit steht der Status auf %, erwartet Aktiv.', v_status; end if; - raise notice '12/29 Abwesenheit mit geplanter Rückkehr lässt sich löschen'; + raise notice '12/30 Abwesenheit mit geplanter Rückkehr lässt sich löschen'; -- ── Zweite Versetzung zum selben Tag (20261019110000) ─────────── -- @@ -392,7 +392,7 @@ begin if exists (select 1 from pending_org_changes where employee_id = v_d and status = 'pending') then raise exception 'Nach dem Abbrechen ist die Versetzung weiter vorgemerkt.'; end if; - raise notice '13/29 Zweite Versetzung zum selben Tag abgewiesen, die erste lässt sich abbrechen'; + raise notice '13/30 Zweite Versetzung zum selben Tag abgewiesen, die erste lässt sich abbrechen'; -- ── Notiz löschen (20261019130000) ────────────────────────────── -- Die eigene lässt sich löschen; das Protokoll behält den Text. @@ -405,7 +405,7 @@ begin if not exists (select 1 from audit_log where action = 'HR-Notiz gelöscht' and details like '%Rauchtest-Notiz%') then raise exception 'Das Löschen der Notiz steht nicht im Protokoll.'; end if; - raise notice '14/29 Eigene Notiz lässt sich löschen, das Protokoll behält sie'; + raise notice '14/30 Eigene Notiz lässt sich löschen, das Protokoll behält sie'; -- ── Austritt zurücknehmen (20261019140000) ────────────────────── -- v_b hat seit Schritt 10 einen datierten Austritt; die Besetzung auf @@ -420,7 +420,7 @@ begin if exists (select 1 from employee_history where employee_id = v_b and event_type = 'Austritt') then raise exception 'Nach der Rücknahme steht der Austritt noch in der Historie.'; end if; - raise notice '15/29 Austritt zurückgenommen, Besetzung läuft wieder'; + raise notice '15/30 Austritt zurückgenommen, Besetzung läuft wieder'; -- ── Letzte Versetzung zurücknehmen (20261019140000) ───────────── v_p8 := create_position(jsonb_build_object('org_unit_id', v_einheit, @@ -443,7 +443,7 @@ begin if exists (select 1 from position_assignments where position_id = v_p9) then raise exception 'Nach der Rücknahme steht auf der Zielplanstelle noch eine Besetzung.'; end if; - raise notice '16/29 Letzte Versetzung zurückgenommen, vorherige Planstelle wieder besetzt'; + raise notice '16/30 Letzte Versetzung zurückgenommen, vorherige Planstelle wieder besetzt'; -- ── Planstelle beim Eintritt berichtigen (20261019140000) ─────── -- v_c (Schritt 11) ist noch nicht eingetreten und nie versetzt worden. @@ -457,7 +457,7 @@ begin if exists (select 1 from employee_history where employee_id = v_c and event_type = 'Versetzung') then raise exception 'Die Berichtigung hat eine Versetzung hinterlassen.'; end if; - raise notice '17/29 Planstelle beim Eintritt berichtigt, ohne Versetzung'; + raise notice '17/30 Planstelle beim Eintritt berichtigt, ohne Versetzung'; -- ── Planstelle nicht vor ihrer Einheit (20261019150000) ───────── v_spaet := create_org_unit(jsonb_build_object( @@ -477,7 +477,7 @@ begin if v_meldung not like '%besteht erst ab%' then raise exception 'Erwartet wurde die Meldung zur Einheit, kam aber: %', v_meldung; end if; - raise notice '18/29 Planstelle vor ihrer Einheit wird abgewiesen'; + raise notice '18/30 Planstelle vor ihrer Einheit wird abgewiesen'; -- ── Anschliessende Abwesenheit (20261019220000) ───────────────── -- v_e (Schritt 16) geht in Wochenhilfe; eine Elternkarenz wird @@ -517,7 +517,7 @@ begin where employee_id = v_e and status = 'pending' and change_type = 'karenz_return') <> 2 then raise exception 'Erwartet wurden zwei vorgemerkte Rückkehren, eine je Abwesenheit.'; end if; - raise notice '19/29 Anschliessende Abwesenheit frühestens am Ende der laufenden'; + raise notice '19/30 Anschliessende Abwesenheit frühestens am Ende der laufenden'; -- ── Rückkehr anpassen ─────────────────────────────────────────── -- Über den Beginn der anschliessenden hinaus geht nicht; früher schon. Die @@ -558,7 +558,7 @@ begin and change_type = 'karenz_return' and payload ? 'teilzeit_art') then raise exception 'Die Rückkehr ohne Reduktion merkt eine Teilzeitvariante vor.'; end if; - raise notice '20/29 Rückkehr angepasst, die der anschliessenden Abwesenheit bleibt'; + raise notice '20/30 Rückkehr angepasst, die der anschliessenden Abwesenheit bleibt'; -- ── Sofortige Rückkehr ────────────────────────────────────────── perform rueckkehr_anpassen(jsonb_build_object( @@ -574,7 +574,7 @@ begin and change_type = 'karenz_start' and effective_date = current_date + 60) then raise exception 'Die anschliessend geplante Abwesenheit ist mit der Rückkehr verschwunden.'; end if; - raise notice '21/29 Rückkehr heute wird sofort verbucht, die geplante Abwesenheit bleibt'; + raise notice '21/30 Rückkehr heute wird sofort verbucht, die geplante Abwesenheit bleibt'; -- ── Checklisten (20261019230000) ──────────────────────────────── -- Eine Liste lässt sich abschliessen und sperrt dann; eine neue zur @@ -608,7 +608,7 @@ begin where checkliste_id = app_aktuelle_checkliste(v_e, 'onboarding') and erledigt) is distinct from 'b' then raise exception 'Der Haken steht nicht in der neuen Liste.'; end if; - raise notice '22/29 Checkliste abschliessen sperrt, neue Liste zur Rückkehr beginnt leer'; + raise notice '22/30 Checkliste abschliessen sperrt, neue Liste zur Rückkehr beginnt leer'; -- ── Kostenstelle anlegen (20261020110000) ─────────────────────── -- Neu angelegt lässt sie sich einer Planstelle zuordnen; dieselbe Nummer @@ -630,7 +630,7 @@ begin if v_ging or v_meldung not like '%gibt es bereits%' then raise exception 'Eine doppelte Kostenstellennummer wurde angenommen (%).', v_meldung; end if; - raise notice '23/29 Kostenstelle angelegt und zugeordnet, doppelte Nummer abgewiesen'; + raise notice '23/30 Kostenstelle angelegt und zugeordnet, doppelte Nummer abgewiesen'; -- ── Geplante Abwesenheit berichtigen (20261020120000) ─────────── -- Über „Eintrag berichtigen": der Beginn wandert, die geplante Rückkehr @@ -671,7 +671,7 @@ begin if not exists (select 1 from employee_dependents where employee_id = v_d and relationship = 'Onkel') then raise exception 'Ein frei eingetragenes Verhältnis wurde nicht gespeichert.'; end if; - raise notice '24/29 Geplante Abwesenheit berichtigt, freies Verhältnis bei Angehörigen'; + raise notice '24/30 Geplante Abwesenheit berichtigt, freies Verhältnis bei Angehörigen'; -- ── Wochenhilfe ohne Ende (20261020130000) ────────────────────── -- Ohne Ende keine vorgemerkte Rückkehr; eine anschliessende Abwesenheit @@ -698,7 +698,7 @@ begin if v_ging or v_meldung not like '%keine Rückkehr geplant%' then raise exception 'Eine anschliessende Abwesenheit liess sich ohne Ende der Wochenhilfe planen (%).', v_meldung; end if; - raise notice '25/29 Wochenhilfe ohne Ende, anschliessende Abwesenheit erst mit Ende'; + raise notice '25/30 Wochenhilfe ohne Ende, anschliessende Abwesenheit erst mit Ende'; -- ── Berichtigte Rückkehr wandert mit (20261020140000) ─────────── -- v_a geht in eine Abwesenheit mit Rückkehr in 30 Tagen. Über „Eintrag @@ -726,7 +726,7 @@ begin and h.event_date = current_date + 70) then raise exception 'Die vorgemerkte Rückkehr ist der Berichtigung nicht gefolgt.'; end if; - raise notice '26/29 Berichtigte Rückkehr: Vormerkung und Historie folgen'; + raise notice '26/30 Berichtigte Rückkehr: Vormerkung und Historie folgen'; -- ── Lehrzeit (20261021100000) ─────────────────────────────────── -- Ein Lehrling bekommt Beginn und Ende; ein Ende vor dem Beginn wird @@ -761,7 +761,7 @@ begin if (select lehrzeit_von from employees where id = v_e) is not null then raise exception 'Nach dem Wechsel der Gruppe steht noch eine Lehrzeit.'; end if; - raise notice '27/29 Lehrzeit beim Lehrling, sonst leer'; + raise notice '27/30 Lehrzeit beim Lehrling, sonst leer'; -- ── Einstellung ohne Geburtsdatum (20261021120000) ────────────── v_p6 := create_position(jsonb_build_object('org_unit_id', v_einheit, @@ -773,7 +773,7 @@ begin if (select birth_date from employees where id = v_d) is not null then raise exception 'Ein leeres Geburtsdatum wurde nicht als leer gespeichert.'; end if; - raise notice '28/29 Einstellung ohne Geburtsdatum'; + raise notice '28/30 Einstellung ohne Geburtsdatum'; -- ── Organisationseinheit umbenennen (20261022100000) ──────────── perform rename_org_unit(jsonb_build_object('org_unit_id', v_einheit, 'name', 'Rauchtest umbenannt')); @@ -784,7 +784,25 @@ begin and target_label like '%Rauchtest umbenannt') then raise exception 'Die Umbenennung steht nicht im Protokoll.'; end if; - raise notice '29/29 Organisationseinheit umbenannt, im Protokoll'; + raise notice '29/30 Organisationseinheit umbenannt, im Protokoll'; + + -- ── Standort ändern (20261022110000) ──────────────────────────── + -- Gebraucht wird ein zweiter Standort; der Rauchtest legt ihn an und + -- verwirft ihn mit allem anderen. + insert into locations (name, country) + select 'Rauchtest-Standort', country from locations where id = v_ort + returning id into v_stelle; + perform change_employee_data(jsonb_build_object( + 'employee_id', v_d, 'effective_date', current_date::text, + 'role', jsonb_build_object('location_id', v_stelle::text))); + if (select location_id from employees where id = v_d) <> v_stelle then + raise exception 'Der Standort wurde nicht geändert.'; + end if; + if not exists (select 1 from employee_history where employee_id = v_d and event_type = 'Vertragsänderung' + and changes @> '[{"feld": "Standort"}]') then + raise exception 'Der Standortwechsel steht nicht in der Historie.'; + end if; + raise notice '30/30 Standort geändert, in der Historie'; raise notice ''; raise notice 'Rauchtest bestanden. Alles Angelegte wird gleich verworfen.';