Checklisten mit Anlass, neue Liste zur Rueckkehr, abschliessen
Eine Person kann mehrere Onboarding- und Offboarding-Listen haben (Tabelle checklisten), jede mit Anlass: Eintritt, Rueckkehr, Wiedereintritt, Austritt. Bearbeitet wird die juengste; fruehere bleiben mit ihren Haken lesbar. - Nach einer Rueckkehr aus einer Langzeitabwesenheit laesst sich eine neue Onboarding-Liste anlegen. - Wiedereintritt und jeder Austritt legen eine neue Liste an statt die alte zu ergaenzen. - "Checkliste abschliessen" sperrt die Liste und haelt Datum und Namen fest; "Wieder oeffnen" hebt das auf. Beides steht im Protokoll. - Austritt zuruecknehmen loescht nur die Liste dieses Austritts. - Der Ausdruck zeigt die juengste Liste. Bestand: je Person und Art wird aus den vorhandenen Punkten eine Liste. Rauchtest: Schritt 22. Geprueft: lint, tsc, types:check, 928 Tests, Uebergabe-Waechter
This commit is contained in:
@@ -0,0 +1,394 @@
|
||||
-- Checklisten: mehrere je Person, jede mit Anlass, abschliessbar.
|
||||
--
|
||||
-- Eine Person kann mehrmals ins Onboarding kommen — nach dem Eintritt, nach
|
||||
-- der Rückkehr aus einer Langzeitabwesenheit, nach einem Wiedereintritt —
|
||||
-- und mehrmals ins Offboarding. Jede dieser Listen ist ein eigener Vorgang:
|
||||
-- die neue beginnt leer, die alte bleibt mit ihren Haken lesbar.
|
||||
--
|
||||
-- Abschliessen sperrt eine Liste gegen Änderungen und hält fest, wann und von
|
||||
-- wem. Wieder öffnen ist möglich und steht im Protokoll; ein versehentlicher
|
||||
-- Abschluss liesse sich sonst nicht beheben.
|
||||
--
|
||||
-- Bearbeitet wird immer die jüngste Liste einer Art. Ältere sind Akte.
|
||||
|
||||
create table if not exists checklisten (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
employee_id uuid not null references employees(id) on delete cascade,
|
||||
art text not null check (art in ('onboarding', 'offboarding')),
|
||||
-- Eintritt, Rückkehr, Wiedereintritt, Austritt.
|
||||
anlass text not null,
|
||||
created_at timestamptz not null default now(),
|
||||
abgeschlossen_am timestamptz,
|
||||
abgeschlossen_von uuid references profiles(id) on delete set null,
|
||||
-- Der Name mitgeschrieben, wie bei den Punkten: lesbar auch dann, wenn die
|
||||
-- Person nicht mehr im Verzeichnis steht.
|
||||
abgeschlossen_von_name text,
|
||||
constraint chk_checkliste_abschluss check ((abgeschlossen_am is null) = (abgeschlossen_von_name is null))
|
||||
);
|
||||
|
||||
create index if not exists checklisten_person_idx on checklisten (employee_id, art, created_at desc);
|
||||
|
||||
alter table checklisten enable row level security;
|
||||
drop policy if exists checklisten_hr_all on checklisten;
|
||||
create policy checklisten_hr_all on checklisten
|
||||
for all using ((select is_hr_user())) with check ((select is_hr_user()));
|
||||
|
||||
-- ── Bestand: je Person und Art eine Liste ───────────────────────────────
|
||||
alter table onboarding_tasks add column if not exists checkliste_id uuid references checklisten(id) on delete cascade;
|
||||
alter table offboarding_tasks add column if not exists checkliste_id uuid references checklisten(id) on delete cascade;
|
||||
|
||||
insert into checklisten (employee_id, art, anlass, created_at)
|
||||
select t.employee_id, 'onboarding', 'Eintritt', min(t.created_at)
|
||||
from onboarding_tasks t
|
||||
where t.checkliste_id is null
|
||||
group by t.employee_id;
|
||||
|
||||
insert into checklisten (employee_id, art, anlass, created_at)
|
||||
select t.employee_id, 'offboarding', 'Austritt', min(t.created_at)
|
||||
from offboarding_tasks t
|
||||
where t.checkliste_id is null
|
||||
group by t.employee_id;
|
||||
|
||||
update onboarding_tasks t set checkliste_id = c.id
|
||||
from checklisten c
|
||||
where t.checkliste_id is null and c.employee_id = t.employee_id and c.art = 'onboarding';
|
||||
|
||||
update offboarding_tasks t set checkliste_id = c.id
|
||||
from checklisten c
|
||||
where t.checkliste_id is null and c.employee_id = t.employee_id and c.art = 'offboarding';
|
||||
|
||||
alter table onboarding_tasks alter column checkliste_id set not null;
|
||||
alter table offboarding_tasks alter column checkliste_id set not null;
|
||||
|
||||
alter table onboarding_tasks drop constraint if exists onboarding_tasks_eine_zeile;
|
||||
alter table offboarding_tasks drop constraint if exists offboarding_tasks_eine_zeile;
|
||||
alter table onboarding_tasks drop constraint if exists onboarding_tasks_je_liste;
|
||||
alter table offboarding_tasks drop constraint if exists offboarding_tasks_je_liste;
|
||||
alter table onboarding_tasks add constraint onboarding_tasks_je_liste unique (checkliste_id, item_key);
|
||||
alter table offboarding_tasks add constraint offboarding_tasks_je_liste unique (checkliste_id, item_key);
|
||||
|
||||
-- ── Die jüngste Liste einer Art ─────────────────────────────────────────
|
||||
create or replace function public.app_aktuelle_checkliste(p_employee_id uuid, p_art text)
|
||||
returns uuid
|
||||
language sql
|
||||
stable
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
select id from checklisten
|
||||
where employee_id = p_employee_id and art = p_art
|
||||
order by created_at desc
|
||||
limit 1
|
||||
$$;
|
||||
|
||||
grant execute on function public.app_aktuelle_checkliste(uuid, text) to alpenwerk_app;
|
||||
|
||||
-- ── Liste anlegen ───────────────────────────────────────────────────────
|
||||
--
|
||||
-- Ohne `neu` wird die jüngste Liste ergänzt (oder, wo keine ist, eine
|
||||
-- angelegt) — der Nachtrag für Personen von vor dieser Liste. Mit `neu`
|
||||
-- entsteht eine weitere Liste für den angegebenen Anlass.
|
||||
create or replace function public.app_checkliste_anlegen(p_art text, payload jsonb)
|
||||
returns integer
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_employee_id uuid := (payload->>'employee_id')::uuid;
|
||||
v_keys jsonb := coalesce(payload->'item_keys', '[]'::jsonb);
|
||||
v_neu boolean := coalesce((payload->>'neu')::boolean, false);
|
||||
v_anlass text := coalesce(nullif(payload->>'anlass', ''),
|
||||
case p_art when 'onboarding' then 'Eintritt' else 'Austritt' end);
|
||||
v_name text;
|
||||
v_liste uuid;
|
||||
v_angelegt integer;
|
||||
begin
|
||||
select first_name || ' ' || last_name into v_name from employees where id = v_employee_id;
|
||||
if v_name is null then
|
||||
raise exception 'Die Person existiert nicht.';
|
||||
end if;
|
||||
if jsonb_array_length(v_keys) = 0 then
|
||||
raise exception 'Es wurden keine Punkte übergeben.';
|
||||
end if;
|
||||
|
||||
v_liste := case when v_neu then null else app_aktuelle_checkliste(v_employee_id, p_art) end;
|
||||
if v_liste is null then
|
||||
insert into checklisten (employee_id, art, anlass) values (v_employee_id, p_art, v_anlass)
|
||||
returning id into v_liste;
|
||||
end if;
|
||||
|
||||
if p_art = 'onboarding' then
|
||||
insert into onboarding_tasks (checkliste_id, employee_id, item_key, updated_by, updated_by_name)
|
||||
select v_liste, v_employee_id, k, app_current_user_id(), current_actor_name()
|
||||
from jsonb_array_elements_text(v_keys) k
|
||||
on conflict (checkliste_id, item_key) do nothing;
|
||||
else
|
||||
insert into offboarding_tasks (checkliste_id, employee_id, item_key, updated_by, updated_by_name)
|
||||
select v_liste, v_employee_id, k, app_current_user_id(), current_actor_name()
|
||||
from jsonb_array_elements_text(v_keys) k
|
||||
on conflict (checkliste_id, item_key) do nothing;
|
||||
end if;
|
||||
|
||||
get diagnostics v_angelegt = row_count;
|
||||
|
||||
if v_angelegt > 0 then
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
|
||||
values (app_current_user_id(), current_actor_name(),
|
||||
case p_art when 'onboarding' then 'Onboarding-Checkliste angelegt' else 'Offboarding-Checkliste angelegt' end,
|
||||
v_name, v_employee_id, v_angelegt || ' Punkte, Anlass: ' || v_anlass);
|
||||
end if;
|
||||
|
||||
return v_angelegt;
|
||||
end;
|
||||
$$;
|
||||
|
||||
revoke execute on function public.app_checkliste_anlegen(text, jsonb) from public;
|
||||
|
||||
create or replace function public.start_onboarding(payload jsonb)
|
||||
returns integer
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
return app_checkliste_anlegen('onboarding', payload);
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace function public.start_offboarding(payload jsonb)
|
||||
returns integer
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
return app_checkliste_anlegen('offboarding', payload);
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.start_onboarding(jsonb) to alpenwerk_app;
|
||||
grant execute on function public.start_offboarding(jsonb) to alpenwerk_app;
|
||||
|
||||
-- ── Einen Punkt festhalten ──────────────────────────────────────────────
|
||||
--
|
||||
-- Immer in der jüngsten Liste. Gesetzt wird, was mitkommt: wer nur den
|
||||
-- Kommentar ändert, schickt nur den Kommentar — sonst würde ein Tippfehler
|
||||
-- im Kommentarfeld den Haken mitlöschen.
|
||||
create or replace function public.app_checklistenpunkt_setzen(p_art text, payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_employee_id uuid := (payload->>'employee_id')::uuid;
|
||||
v_item_key text := nullif(trim(payload->>'item_key'), '');
|
||||
v_name text;
|
||||
v_liste checklisten%rowtype;
|
||||
v_erledigt boolean;
|
||||
v_wert text;
|
||||
v_kommentar text;
|
||||
v_vorher_erledigt boolean;
|
||||
v_vorher_wert text;
|
||||
v_vorher_kommentar text;
|
||||
begin
|
||||
if v_item_key is null then
|
||||
raise exception 'Es wurde kein Punkt angegeben.';
|
||||
end if;
|
||||
|
||||
select first_name || ' ' || last_name into v_name from employees where id = v_employee_id;
|
||||
if v_name is null then
|
||||
raise exception 'Die Person existiert nicht.';
|
||||
end if;
|
||||
|
||||
select * into v_liste from checklisten where id = app_aktuelle_checkliste(v_employee_id, p_art) for update;
|
||||
if not found then
|
||||
raise exception 'Für diese Person gibt es keine Checkliste.';
|
||||
end if;
|
||||
if v_liste.abgeschlossen_am is not null then
|
||||
raise exception 'Die Checkliste ist abgeschlossen. Zum Ändern bitte zuerst wieder öffnen.';
|
||||
end if;
|
||||
|
||||
if p_art = 'onboarding' then
|
||||
select erledigt, wert, kommentar into v_vorher_erledigt, v_vorher_wert, v_vorher_kommentar
|
||||
from onboarding_tasks where checkliste_id = v_liste.id and item_key = v_item_key for update;
|
||||
else
|
||||
select erledigt, wert, kommentar into v_vorher_erledigt, v_vorher_wert, v_vorher_kommentar
|
||||
from offboarding_tasks where checkliste_id = v_liste.id and item_key = v_item_key for update;
|
||||
end if;
|
||||
|
||||
-- Weggelassen heisst „unverändert", nicht „leeren": eine ausdrückliche
|
||||
-- null muss löschen können, deshalb `payload ? 'feld'` statt coalesce.
|
||||
v_erledigt := case when payload ? 'erledigt' then (payload->>'erledigt')::boolean
|
||||
else coalesce(v_vorher_erledigt, false) end;
|
||||
v_wert := case when payload ? 'wert' then nullif(trim(payload->>'wert'), '') else v_vorher_wert end;
|
||||
v_kommentar := case when payload ? 'kommentar' then nullif(trim(payload->>'kommentar'), '')
|
||||
else v_vorher_kommentar end;
|
||||
|
||||
if p_art = 'onboarding' then
|
||||
insert into onboarding_tasks (checkliste_id, employee_id, item_key, erledigt, wert, kommentar, updated_by, updated_by_name)
|
||||
values (v_liste.id, v_employee_id, v_item_key, v_erledigt, v_wert, v_kommentar,
|
||||
app_current_user_id(), current_actor_name())
|
||||
on conflict (checkliste_id, item_key) do update
|
||||
set erledigt = excluded.erledigt, wert = excluded.wert, kommentar = excluded.kommentar,
|
||||
updated_at = now(), updated_by = excluded.updated_by, updated_by_name = excluded.updated_by_name;
|
||||
else
|
||||
insert into offboarding_tasks (checkliste_id, employee_id, item_key, erledigt, wert, kommentar, updated_by, updated_by_name)
|
||||
values (v_liste.id, v_employee_id, v_item_key, v_erledigt, v_wert, v_kommentar,
|
||||
app_current_user_id(), current_actor_name())
|
||||
on conflict (checkliste_id, item_key) do update
|
||||
set erledigt = excluded.erledigt, wert = excluded.wert, kommentar = excluded.kommentar,
|
||||
updated_at = now(), updated_by = excluded.updated_by, updated_by_name = excluded.updated_by_name;
|
||||
end if;
|
||||
|
||||
-- Kein Eintrag in employee_history: das ist der Stand einer Aufgabe, keine
|
||||
-- Änderung an der Person. Ins Protokoll gehört es — es ist eine Handlung
|
||||
-- mit Urheber.
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
|
||||
values (app_current_user_id(), current_actor_name(),
|
||||
case p_art when 'onboarding' then 'Onboarding-Punkt' else 'Offboarding-Punkt' end, v_name, v_employee_id,
|
||||
v_item_key || ': ' ||
|
||||
case when v_wert is not null then v_wert
|
||||
when v_erledigt then 'erledigt'
|
||||
else 'offen' end ||
|
||||
coalesce(' — ' || v_kommentar, ''));
|
||||
end;
|
||||
$$;
|
||||
|
||||
revoke execute on function public.app_checklistenpunkt_setzen(text, jsonb) from public;
|
||||
|
||||
create or replace function public.set_onboarding_task(payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
perform app_checklistenpunkt_setzen('onboarding', payload);
|
||||
end;
|
||||
$$;
|
||||
|
||||
create or replace function public.set_offboarding_task(payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
perform app_checklistenpunkt_setzen('offboarding', payload);
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.set_onboarding_task(jsonb) to alpenwerk_app;
|
||||
grant execute on function public.set_offboarding_task(jsonb) to alpenwerk_app;
|
||||
|
||||
-- ── Abschliessen und wieder öffnen ──────────────────────────────────────
|
||||
create or replace function public.checkliste_abschliessen(payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
security definer
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_id uuid := (payload->>'checkliste_id')::uuid;
|
||||
v_oeffnen boolean := coalesce((payload->>'wieder_oeffnen')::boolean, false);
|
||||
v_liste checklisten%rowtype;
|
||||
v_name text;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
select * into v_liste from checklisten where id = v_id for update;
|
||||
if not found then
|
||||
raise exception 'Die Checkliste existiert nicht.';
|
||||
end if;
|
||||
select first_name || ' ' || last_name into v_name from employees where id = v_liste.employee_id;
|
||||
|
||||
if v_oeffnen then
|
||||
if v_liste.abgeschlossen_am is null then
|
||||
raise exception 'Die Checkliste ist nicht abgeschlossen.';
|
||||
end if;
|
||||
update checklisten set abgeschlossen_am = null, abgeschlossen_von = null, abgeschlossen_von_name = null
|
||||
where id = v_id;
|
||||
else
|
||||
if v_liste.abgeschlossen_am is not null then
|
||||
raise exception 'Die Checkliste ist bereits abgeschlossen.';
|
||||
end if;
|
||||
update checklisten set abgeschlossen_am = now(), abgeschlossen_von = app_current_user_id(),
|
||||
abgeschlossen_von_name = current_actor_name()
|
||||
where id = v_id;
|
||||
end if;
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
|
||||
values (app_current_user_id(), current_actor_name(),
|
||||
case v_liste.art when 'onboarding' then 'Onboarding-Checkliste' else 'Offboarding-Checkliste' end
|
||||
|| case when v_oeffnen then ' wieder geöffnet' else ' abgeschlossen' end,
|
||||
v_name, v_liste.employee_id,
|
||||
'Anlass: ' || v_liste.anlass || ', angelegt am ' || to_char(v_liste.created_at, 'DD.MM.YYYY'));
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.checkliste_abschliessen(jsonb) to alpenwerk_app;
|
||||
|
||||
-- ── austritt_zuruecknehmen: die Liste dieses Austritts fällt ganz ───────
|
||||
do $migration$
|
||||
declare
|
||||
v_def text;
|
||||
v_treffer integer;
|
||||
v_anker constant text := E' delete from offboarding_tasks where employee_id = v_employee_id;\n';
|
||||
v_neu constant text :=
|
||||
E' -- Die Liste dieses Austritts, nicht die eines früheren.\n'
|
||||
|| E' delete from checklisten where id = app_aktuelle_checkliste(v_employee_id, ''offboarding'');\n';
|
||||
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 = 'austritt_zuruecknehmen';
|
||||
|
||||
if position('app_aktuelle_checkliste' in v_def) > 0 then
|
||||
raise notice 'austritt_zuruecknehmen ist bereits angepasst — nichts zu tun.';
|
||||
else
|
||||
v_treffer := (length(v_def) - length(replace(v_def, v_anker, ''))) / length(v_anker);
|
||||
if v_treffer <> 1 then
|
||||
raise exception 'Der Anker in austritt_zuruecknehmen kommt % mal vor, erwartet genau einmal.', v_treffer;
|
||||
end if;
|
||||
execute replace(v_def, v_anker, v_neu);
|
||||
end if;
|
||||
end
|
||||
$migration$;
|
||||
|
||||
-- ── Selbstprüfung ─────────────────────────────────────────────────────────
|
||||
do $pruefung$
|
||||
declare
|
||||
v_fn text;
|
||||
v_def text;
|
||||
v_definer boolean;
|
||||
begin
|
||||
foreach v_fn in array array['start_onboarding', 'start_offboarding', 'set_onboarding_task',
|
||||
'set_offboarding_task', 'checkliste_abschliessen', 'austritt_zuruecknehmen'] loop
|
||||
select pg_get_functiondef(p.oid), p.prosecdef into v_def, v_definer
|
||||
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 not v_definer then
|
||||
raise exception '% ist nicht security definer.', v_fn;
|
||||
end if;
|
||||
if position(E'begin\n perform require_hr_admin();' in v_def) = 0 then
|
||||
raise exception '% prüft die Rechte nicht in der ersten Zeile.', v_fn;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
if exists (select 1 from onboarding_tasks where checkliste_id is null)
|
||||
or exists (select 1 from offboarding_tasks where checkliste_id is null) then
|
||||
raise exception 'Es gibt Checklistenpunkte ohne Liste.';
|
||||
end if;
|
||||
if exists (select 1 from onboarding_tasks t join checklisten c on c.id = t.checkliste_id
|
||||
where c.art <> 'onboarding' or c.employee_id <> t.employee_id)
|
||||
or exists (select 1 from offboarding_tasks t join checklisten c on c.id = t.checkliste_id
|
||||
where c.art <> 'offboarding' or c.employee_id <> t.employee_id) then
|
||||
raise exception 'Checklistenpunkte hängen an der falschen Liste.';
|
||||
end if;
|
||||
if not (select relrowsecurity from pg_class where oid = 'public.checklisten'::regclass) then
|
||||
raise exception 'checklisten ist ohne Zugriffsschutz.';
|
||||
end if;
|
||||
end
|
||||
$pruefung$;
|
||||
@@ -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/21 Einheit und vier Planstellen angelegt';
|
||||
raise notice '1/22 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/21 Einstellung auf Planstelle 1';
|
||||
raise notice '2/22 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/21 Versetzung am selben Tag';
|
||||
raise notice '3/22 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/21 Beförderung am selben Tag: Hay-Grade und Planstellenbezeichnung';
|
||||
raise notice '4/22 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/21 Beförderung ohne Stellenwechsel benennt dieselbe Planstelle um';
|
||||
raise notice '4b/22 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/21 Vorgemerkte Planstelle wird abgewiesen';
|
||||
raise notice '5/22 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/21 Die eigene Vormerkung steht nicht im Weg';
|
||||
raise notice '6/22 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/21 Austritt am selben Tag, Planstelle frei';
|
||||
raise notice '7/22 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/21 Wiedereintritt';
|
||||
raise notice '8/22 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/21 Rückdatierte Versetzung lässt keine zweite Besetzung stehen';
|
||||
raise notice '9/22 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/21 Versetzung bei datiertem Austritt: kein Überlappen, kein Überleben';
|
||||
raise notice '10/22 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/21 Änderung vor dem Eintritt wirkt sofort und wandert mit dem Eintritt';
|
||||
raise notice '11/22 Ä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/21 Abwesenheit mit geplanter Rückkehr lässt sich löschen';
|
||||
raise notice '12/22 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/21 Zweite Versetzung zum selben Tag abgewiesen, die erste lässt sich abbrechen';
|
||||
raise notice '13/22 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/21 Eigene Notiz lässt sich löschen, das Protokoll behält sie';
|
||||
raise notice '14/22 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/21 Austritt zurückgenommen, Besetzung läuft wieder';
|
||||
raise notice '15/22 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/21 Letzte Versetzung zurückgenommen, vorherige Planstelle wieder besetzt';
|
||||
raise notice '16/22 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/21 Planstelle beim Eintritt berichtigt, ohne Versetzung';
|
||||
raise notice '17/22 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/21 Planstelle vor ihrer Einheit wird abgewiesen';
|
||||
raise notice '18/22 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/21 Anschliessende Abwesenheit frühestens am Ende der laufenden';
|
||||
raise notice '19/22 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/21 Rückkehr angepasst, die der anschliessenden Abwesenheit bleibt';
|
||||
raise notice '20/22 Rückkehr angepasst, die der anschliessenden Abwesenheit bleibt';
|
||||
|
||||
-- ── Sofortige Rückkehr ──────────────────────────────────────────
|
||||
perform rueckkehr_anpassen(jsonb_build_object(
|
||||
@@ -574,7 +574,41 @@ 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/21 Rückkehr heute wird sofort verbucht, die geplante Abwesenheit bleibt';
|
||||
raise notice '21/22 Rückkehr heute wird sofort verbucht, die geplante Abwesenheit bleibt';
|
||||
|
||||
-- ── Checklisten (20261019230000) ────────────────────────────────
|
||||
-- Eine Liste lässt sich abschliessen und sperrt dann; eine neue zur
|
||||
-- Rückkehr beginnt leer, die alte bleibt unverändert.
|
||||
perform start_onboarding(jsonb_build_object('employee_id', v_e, 'item_keys', jsonb_build_array('a', 'b')));
|
||||
perform set_onboarding_task(jsonb_build_object('employee_id', v_e, 'item_key', 'a', 'erledigt', true));
|
||||
perform checkliste_abschliessen(jsonb_build_object('checkliste_id', app_aktuelle_checkliste(v_e, 'onboarding')));
|
||||
|
||||
v_ging := false;
|
||||
begin
|
||||
perform set_onboarding_task(jsonb_build_object('employee_id', v_e, 'item_key', 'b', 'erledigt', true));
|
||||
v_ging := true;
|
||||
exception
|
||||
when others then v_meldung := SQLERRM;
|
||||
end;
|
||||
if v_ging or v_meldung not like '%Die Checkliste ist abgeschlossen%' then
|
||||
raise exception 'Eine abgeschlossene Checkliste liess sich ändern (%).', v_meldung;
|
||||
end if;
|
||||
|
||||
perform start_onboarding(jsonb_build_object('employee_id', v_e, 'item_keys', jsonb_build_array('a', 'b'),
|
||||
'neu', true, 'anlass', 'Rückkehr'));
|
||||
perform set_onboarding_task(jsonb_build_object('employee_id', v_e, 'item_key', 'b', 'erledigt', true));
|
||||
if (select count(*) from checklisten where employee_id = v_e and art = 'onboarding') <> 2 then
|
||||
raise exception 'Erwartet wurden zwei Onboarding-Listen.';
|
||||
end if;
|
||||
if (select count(*) from onboarding_tasks t join checklisten c on c.id = t.checkliste_id
|
||||
where c.employee_id = v_e and c.anlass = 'Eintritt' and t.erledigt) <> 1 then
|
||||
raise exception 'Die abgeschlossene Liste hat sich verändert.';
|
||||
end if;
|
||||
if (select string_agg(item_key, ',') from onboarding_tasks
|
||||
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/22 Checkliste abschliessen sperrt, neue Liste zur Rückkehr beginnt leer';
|
||||
|
||||
raise notice '';
|
||||
raise notice 'Rauchtest bestanden. Alles Angelegte wird gleich verworfen.';
|
||||
|
||||
Reference in New Issue
Block a user