Austritt und letzte Versetzung zuruecknehmen, Planstelle beim Eintritt berichtigen, Uebersicht Anstehend, Teilzeitvariante, Notiz erledigt von
Migration 20261019140000: - austritt_zuruecknehmen: Austrittsangaben leeren, Status neu ableiten, beendete Besetzung wieder oeffnen, wenn die Planstelle frei ist (sonst ohne Besetzung und mit Hinweis, dass eine andere gebraucht wird), Offboarding-Checkliste loeschen, Austritt aus der Historie nehmen und die Ruecknahme als eigene Zeile vermerken. Nichtantritt ausgenommen. - versetzung_zuruecknehmen: nur die letzte wirksame Versetzung, ohne spaetere Befoerderung; die Person kehrt auf die vorherige Planstelle zurueck, wenn diese frei ist, sonst Abweisung. delete_history_entry leitet die wirksame Versetzung dorthin um (Papierkorb in der Historie). - eintritt_planstelle_berichtigen: beim Eintritt gewaehlte Planstelle richtigstellen, solange keine Versetzung/Befoerderung folgte; keine Versetzung in der Historie. - app_planstelle_frei_ab: gemeinsame Pruefung (besetzt oder vorgemerkt). Oberflaeche: - Daten aendern: "Austritt zuruecknehmen" mit Rueckfrage; Abschnitt "Planstelle beim Eintritt". - Uebersicht, Karte Anstehend: Art "Anstehend" mit der vorgemerkten Historie aller Personen. - Teilzeitvariante auch im Reiter Stammdaten, "Keine" statt Strich; in den Formularen heisst der leere Eintrag "Keine (vertragliche Stundenaenderung)". - Notizen: bei erledigten steht, von wem und wann. Rauchtest Schritte 15-17. Geprueft: lint, tsc, types:check, 919 Tests, Waechter
This commit is contained in:
@@ -0,0 +1,343 @@
|
||||
-- Drei Vorgänge, die sich zurücknehmen oder berichtigen lassen:
|
||||
--
|
||||
-- 1. Ein erfasster Austritt wird vollständig zurückgenommen
|
||||
-- (austritt_zuruecknehmen).
|
||||
-- 2. Die letzte wirksame Versetzung wird gelöscht; die Person sitzt danach
|
||||
-- wieder auf der vorherigen Planstelle (versetzung_zuruecknehmen, über
|
||||
-- den Papierkorb in der Historie).
|
||||
-- 3. Die beim Eintritt gewählte Planstelle wird berichtigt, ohne dass eine
|
||||
-- Versetzung entsteht (eintritt_planstelle_berichtigen).
|
||||
--
|
||||
-- Alle drei bewegen Besetzungen. Gemeinsam ist ihnen die Frage, ob die
|
||||
-- Planstelle, auf die die Person zurückkehrt oder kommt, frei ist — besetzt
|
||||
-- von jemand anderem oder vorgemerkt (planstelle_vorgemerkt). Ist sie es
|
||||
-- nicht, wird abgewiesen bzw. beim Austritt ohne Besetzung zurückgenommen
|
||||
-- und das gesagt.
|
||||
|
||||
-- ── Hilfsfunktion: frei ab einem Tag? ────────────────────────────────────
|
||||
create or replace function public.app_planstelle_frei_ab(p_position_id uuid, p_ab date, p_employee_id uuid)
|
||||
returns boolean
|
||||
language sql
|
||||
stable
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
select not exists (
|
||||
select 1 from position_assignments pa
|
||||
where pa.position_id = p_position_id
|
||||
and pa.employee_id <> p_employee_id
|
||||
and (pa.valid_to is null or pa.valid_to > p_ab))
|
||||
and planstelle_vorgemerkt(p_position_id, p_ab, p_employee_id) is null
|
||||
$$;
|
||||
|
||||
grant execute on function public.app_planstelle_frei_ab(uuid, date, uuid) to alpenwerk_app;
|
||||
|
||||
-- ── 1. Austritt zurücknehmen ─────────────────────────────────────────────
|
||||
--
|
||||
-- Fachlich vorgegeben: eine begonnene Offboarding-Checkliste wird gelöscht;
|
||||
-- ist die Planstelle inzwischen neu besetzt oder vorgemerkt, sagt die
|
||||
-- Rückmeldung, dass für die Person eine andere gebraucht wird; ein
|
||||
-- Nichtantritt ist ausgenommen; die Rücknahme bleibt in der Historie
|
||||
-- sichtbar.
|
||||
--
|
||||
-- Die Zeile „Austritt" verschwindet aus der Historie — sonst zählten
|
||||
-- Berichte einen Austritt, der nicht stattfindet. An ihrer Stelle steht eine
|
||||
-- Zeile, die die Rücknahme nennt, ohne Feldwerte: sie lässt sich nicht über
|
||||
-- den Papierkorb „zurücknehmen", denn das hiesse, den Austritt ohne seine
|
||||
-- Besetzung wiederherzustellen.
|
||||
--
|
||||
-- Gibt einen Hinweis zurück, wenn die Planstelle nicht wiederhergestellt
|
||||
-- werden konnte; sonst null.
|
||||
create or replace function public.austritt_zuruecknehmen(payload jsonb)
|
||||
returns text
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_employee_id uuid := (payload->>'employee_id')::uuid;
|
||||
v_person employees%rowtype;
|
||||
v_besetzung position_assignments%rowtype;
|
||||
v_nummer text;
|
||||
v_hinweis text;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
select * into v_person from employees where id = v_employee_id for update;
|
||||
if not found then
|
||||
raise exception 'Die Person existiert nicht.';
|
||||
end if;
|
||||
if v_person.exit_date is null then
|
||||
raise exception 'Für diese Person ist kein Austritt erfasst.';
|
||||
end if;
|
||||
if v_person.exit_reason = 'No Show' then
|
||||
raise exception 'Ein Nichtantritt lässt sich hier nicht zurücknehmen.';
|
||||
end if;
|
||||
|
||||
-- Die Besetzung, die der Austritt beendet hat.
|
||||
select * into v_besetzung from position_assignments
|
||||
where employee_id = v_employee_id and valid_to = v_person.exit_date
|
||||
order by valid_from desc
|
||||
limit 1;
|
||||
|
||||
if found then
|
||||
select position_number into v_nummer from om_positions where id = v_besetzung.position_id;
|
||||
if app_planstelle_frei_ab(v_besetzung.position_id, v_person.exit_date, v_employee_id) then
|
||||
update position_assignments set valid_to = null where id = v_besetzung.id;
|
||||
else
|
||||
v_hinweis := 'Die Planstelle ' || coalesce(v_nummer, '') || ' ist inzwischen neu besetzt oder vorgemerkt. '
|
||||
|| 'Für diese Person wird eine andere benötigt — bitte über „Versetzen" zuweisen.';
|
||||
end if;
|
||||
else
|
||||
v_hinweis := 'Zu diesem Austritt war keine Planstelle beendet worden. Bitte über „Versetzen" eine zuweisen.';
|
||||
end if;
|
||||
|
||||
update employees set
|
||||
exit_date = null,
|
||||
exit_reason = null,
|
||||
austrittsart = null,
|
||||
status = (case
|
||||
when entry_date > current_date then 'Geplant'
|
||||
when karenz_start_date is not null and karenz_start_date <= current_date
|
||||
and (karenz_return_date is null or karenz_return_date > current_date) then 'Karenz'
|
||||
else 'Aktiv' end)::employment_status
|
||||
where id = v_employee_id;
|
||||
|
||||
delete from offboarding_tasks where employee_id = v_employee_id;
|
||||
|
||||
delete from employee_history
|
||||
where employee_id = v_employee_id and event_type = 'Austritt' and event_date = v_person.exit_date;
|
||||
|
||||
insert into employee_history (employee_id, event_date, event_type, description)
|
||||
values (v_employee_id, app_stichtag_vor_eintritt(v_employee_id, current_date), 'Stammdatenänderung',
|
||||
'Austritt zum ' || to_char(v_person.exit_date, 'DD.MM.YYYY') || ' zurückgenommen ('
|
||||
|| coalesce(v_person.exit_reason, '-') || ')'
|
||||
|| case when v_hinweis is not null then ' — ohne Planstelle' else '' end);
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
|
||||
values (app_current_user_id(), current_actor_name(), 'Austritt zurückgenommen',
|
||||
v_person.first_name || ' ' || v_person.last_name, v_employee_id,
|
||||
'Austritt zum ' || v_person.exit_date || ' (' || coalesce(v_person.exit_reason, '-') || ') zurückgenommen'
|
||||
|| coalesce('. ' || v_hinweis, ''));
|
||||
|
||||
return v_hinweis;
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.austritt_zuruecknehmen(jsonb) to alpenwerk_app;
|
||||
|
||||
-- ── 2. Letzte Versetzung zurücknehmen ────────────────────────────────────
|
||||
--
|
||||
-- Nur die letzte, fachlich so vorgegeben; nach ihr darf auch keine
|
||||
-- Beförderung stehen, sonst bezöge sich diese auf eine Planstelle, die die
|
||||
-- Person danach nicht mehr hat. Ist die vorherige Planstelle inzwischen
|
||||
-- besetzt oder vorgemerkt, wird abgewiesen.
|
||||
create or replace function public.versetzung_zuruecknehmen(p_history_id uuid)
|
||||
returns void
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_eintrag employee_history%rowtype;
|
||||
v_neu position_assignments%rowtype;
|
||||
v_alt position_assignments%rowtype;
|
||||
v_alt_nummer text;
|
||||
v_neu_nummer text;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
select * into v_eintrag from employee_history where id = p_history_id;
|
||||
if not found or v_eintrag.event_type <> 'Versetzung' then
|
||||
raise exception 'Das ist keine Versetzung.';
|
||||
end if;
|
||||
if v_eintrag.event_date > current_date or app_vormerkung_offen(v_eintrag.pending_id) then
|
||||
raise exception 'Diese Versetzung ist nicht wirksam — sie wird abgebrochen, nicht zurückgenommen.';
|
||||
end if;
|
||||
if exists (
|
||||
select 1 from employee_history h
|
||||
where h.employee_id = v_eintrag.employee_id
|
||||
and h.event_type in ('Versetzung', 'Beförderung')
|
||||
and (h.event_date, h.created_at) > (v_eintrag.event_date, v_eintrag.created_at)
|
||||
) then
|
||||
raise exception 'Nur die letzte Versetzung lässt sich zurücknehmen; danach steht noch eine Versetzung oder Beförderung.';
|
||||
end if;
|
||||
|
||||
select * into v_neu from position_assignments
|
||||
where employee_id = v_eintrag.employee_id and valid_from = v_eintrag.event_date
|
||||
order by valid_from desc
|
||||
limit 1;
|
||||
if not found then
|
||||
raise exception 'Die Besetzung dieser Versetzung ist nicht mehr vorhanden.';
|
||||
end if;
|
||||
|
||||
select * into v_alt from position_assignments
|
||||
where employee_id = v_eintrag.employee_id and valid_to = v_eintrag.event_date and id <> v_neu.id
|
||||
order by valid_from desc
|
||||
limit 1;
|
||||
if not found then
|
||||
raise exception 'Vor dieser Versetzung gab es keine Besetzung, auf die die Person zurückkehren könnte.';
|
||||
end if;
|
||||
|
||||
select position_number into v_alt_nummer from om_positions where id = v_alt.position_id;
|
||||
select position_number into v_neu_nummer from om_positions where id = v_neu.position_id;
|
||||
|
||||
if not app_planstelle_frei_ab(v_alt.position_id, v_eintrag.event_date, v_eintrag.employee_id) then
|
||||
raise exception 'Die vorherige Planstelle % ist inzwischen besetzt oder vorgemerkt — die Versetzung lässt sich nicht löschen.', v_alt_nummer;
|
||||
end if;
|
||||
|
||||
delete from position_assignments where id = v_neu.id;
|
||||
update position_assignments set valid_to = v_neu.valid_to where id = v_alt.id;
|
||||
update employees
|
||||
set job_title = (select j.title from om_positions p join jobs j on j.id = p.job_id where p.id = v_alt.position_id)
|
||||
where id = v_eintrag.employee_id;
|
||||
|
||||
delete from employee_history where id = v_eintrag.id;
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
|
||||
values (app_current_user_id(), current_actor_name(), 'Versetzung zurückgenommen',
|
||||
(select first_name || ' ' || last_name from employees where id = v_eintrag.employee_id), v_eintrag.employee_id,
|
||||
'Versetzung vom ' || v_eintrag.event_date || ' auf ' || coalesce(v_neu_nummer, '-')
|
||||
|| ' zurückgenommen, wieder auf ' || coalesce(v_alt_nummer, '-'));
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.versetzung_zuruecknehmen(uuid) to alpenwerk_app;
|
||||
|
||||
-- delete_history_entry leitet die wirksame Versetzung dorthin um, statt sie
|
||||
-- abzuweisen. So bleibt der Papierkorb in der Historie der eine Weg.
|
||||
do $migration$
|
||||
declare
|
||||
v_def text;
|
||||
v_treffer integer;
|
||||
v_anker constant text :=
|
||||
E' if v_eintrag.event_type in (''Versetzung'', ''Beförderung'') and v_eintrag.event_date <= current_date\n'
|
||||
|| E' and not app_vormerkung_offen(v_eintrag.pending_id) then\n';
|
||||
v_neu constant text :=
|
||||
E' if v_eintrag.event_type = ''Versetzung'' and v_eintrag.event_date <= current_date\n'
|
||||
|| E' and not app_vormerkung_offen(v_eintrag.pending_id) then\n'
|
||||
|| E' perform versetzung_zuruecknehmen(v_eintrag.id);\n'
|
||||
|| E' return;\n'
|
||||
|| E' end if;\n'
|
||||
|| v_anker;
|
||||
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 = 'delete_history_entry';
|
||||
|
||||
if position('versetzung_zuruecknehmen' in v_def) > 0 then
|
||||
raise notice 'delete_history_entry leitet die Versetzung bereits um — 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 delete_history_entry kommt % mal vor, erwartet genau einmal.', v_treffer;
|
||||
end if;
|
||||
execute replace(v_def, v_anker, v_neu);
|
||||
end if;
|
||||
end
|
||||
$migration$;
|
||||
|
||||
-- ── 3. Planstelle beim Eintritt berichtigen ──────────────────────────────
|
||||
--
|
||||
-- Fachlich vorgegeben: eine beim Eintritt falsch gewählte Planstelle wird
|
||||
-- über „Daten ändern" berichtigt, nicht über eine Versetzung — es hat nie
|
||||
-- eine stattgefunden. Möglich, solange nach dem Eintritt weder Versetzung
|
||||
-- noch Beförderung steht; danach ist „Versetzen" der Weg.
|
||||
create or replace function public.eintritt_planstelle_berichtigen(payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_employee_id uuid := (payload->>'employee_id')::uuid;
|
||||
v_ziel uuid := (payload->>'position_id')::uuid;
|
||||
v_person employees%rowtype;
|
||||
v_besetzung position_assignments%rowtype;
|
||||
v_alt_nummer text;
|
||||
v_neu_nummer text;
|
||||
v_titel text;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
select * into v_person from employees where id = v_employee_id;
|
||||
if not found then
|
||||
raise exception 'Die Person existiert nicht.';
|
||||
end if;
|
||||
if exists (select 1 from employee_history
|
||||
where employee_id = v_employee_id and event_type in ('Versetzung', 'Beförderung')) then
|
||||
raise exception 'Nach dem Eintritt gab es bereits eine Versetzung oder Beförderung — die Planstelle wird über „Versetzen" geändert.';
|
||||
end if;
|
||||
|
||||
select * into v_besetzung from position_assignments
|
||||
where employee_id = v_employee_id and valid_from = v_person.entry_date
|
||||
order by valid_from
|
||||
limit 1;
|
||||
if not found then
|
||||
raise exception 'Zu dieser Person ist keine Besetzung ab dem Eintritt erfasst.';
|
||||
end if;
|
||||
if v_besetzung.position_id = v_ziel then
|
||||
raise exception 'Das ist bereits die Planstelle dieser Person.';
|
||||
end if;
|
||||
|
||||
select p.position_number, j.title into v_neu_nummer, v_titel
|
||||
from om_positions p join jobs j on j.id = p.job_id
|
||||
where p.id = v_ziel
|
||||
and p.valid_from <= v_besetzung.valid_from
|
||||
and (p.valid_to is null or p.valid_to > v_besetzung.valid_from);
|
||||
if not found then
|
||||
raise exception 'Diese Planstelle gilt zum Eintritt am % nicht.', to_char(v_person.entry_date, 'DD.MM.YYYY');
|
||||
end if;
|
||||
if not app_planstelle_frei_ab(v_ziel, v_besetzung.valid_from, v_employee_id) then
|
||||
raise exception 'Die Planstelle % ist ab dem Eintritt besetzt oder vorgemerkt.', v_neu_nummer;
|
||||
end if;
|
||||
|
||||
select position_number into v_alt_nummer from om_positions where id = v_besetzung.position_id;
|
||||
|
||||
update position_assignments set position_id = v_ziel where id = v_besetzung.id;
|
||||
update employees set job_title = v_titel where id = v_employee_id;
|
||||
|
||||
insert into employee_history (employee_id, event_date, event_type, description)
|
||||
values (v_employee_id, app_stichtag_vor_eintritt(v_employee_id, current_date), 'Stammdatenänderung',
|
||||
'Planstelle beim Eintritt berichtigt: ' || coalesce(v_alt_nummer, '-') || ' → ' || v_neu_nummer);
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
|
||||
values (app_current_user_id(), current_actor_name(), 'Planstelle beim Eintritt berichtigt',
|
||||
v_person.first_name || ' ' || v_person.last_name, v_employee_id,
|
||||
coalesce(v_alt_nummer, '-') || ' → ' || v_neu_nummer);
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.eintritt_planstelle_berichtigen(jsonb) to alpenwerk_app;
|
||||
|
||||
-- ── Selbstprüfung ─────────────────────────────────────────────────────────
|
||||
do $pruefung$
|
||||
declare
|
||||
v_fn text;
|
||||
v_def text;
|
||||
begin
|
||||
foreach v_fn in array array['austritt_zuruecknehmen', 'versetzung_zuruecknehmen', 'eintritt_planstelle_berichtigen'] 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 position('require_hr_admin()' in v_def) = 0 then
|
||||
raise exception '% prüft die Rechte nicht.', v_fn;
|
||||
end if;
|
||||
if position('insert into audit_log' in v_def) = 0 then
|
||||
raise exception '% schreibt kein Protokoll.', v_fn;
|
||||
end if;
|
||||
if position('app_planstelle_frei_ab(' in v_def) = 0 then
|
||||
raise exception '% prüft nicht, ob die Planstelle frei ist.', v_fn;
|
||||
end if;
|
||||
if position('auth.uid()' in v_def) > 0 then
|
||||
raise exception '% ruft auth.uid().', v_fn;
|
||||
end if;
|
||||
end 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 = 'delete_history_entry';
|
||||
-- Die wirksame Versetzung geht zur Rücknahme, die wirksame Beförderung
|
||||
-- bleibt abgewiesen.
|
||||
if position('perform versetzung_zuruecknehmen(v_eintrag.id)' in v_def) = 0
|
||||
or position('Rückgängig macht sie nur eine neue Versetzung' in v_def) = 0 then
|
||||
raise exception 'delete_history_entry leitet die Versetzung nicht wie erwartet um.';
|
||||
end if;
|
||||
end
|
||||
$pruefung$;
|
||||
@@ -44,8 +44,8 @@ do $rauchtest$
|
||||
declare
|
||||
v_wurzel uuid;
|
||||
v_einheit uuid;
|
||||
v_p1 uuid; v_p2 uuid; v_p3 uuid; v_p4 uuid; v_p5 uuid; v_p6 uuid; v_p7 uuid;
|
||||
v_a uuid; v_b uuid; v_c uuid; v_d uuid;
|
||||
v_p1 uuid; v_p2 uuid; v_p3 uuid; v_p4 uuid; v_p5 uuid; v_p6 uuid; v_p7 uuid; v_p8 uuid; v_p9 uuid;
|
||||
v_a uuid; v_b uuid; v_c uuid; v_d uuid; v_e uuid;
|
||||
v_notiz uuid;
|
||||
v_ort uuid;
|
||||
v_nr int;
|
||||
@@ -76,14 +76,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/14 Einheit und vier Planstellen angelegt';
|
||||
raise notice '1/17 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/14 Einstellung auf Planstelle 1';
|
||||
raise notice '2/17 Einstellung auf Planstelle 1';
|
||||
|
||||
-- ── Versetzung am selben Tag (20260929180000) ───────────────────
|
||||
-- Die Besetzung begann heute; sie auf heute zu schliessen wäre ein
|
||||
@@ -96,7 +96,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/14 Versetzung am selben Tag';
|
||||
raise notice '3/17 Versetzung am selben Tag';
|
||||
|
||||
-- ── Beförderung mit Planstellenwechsel, ebenfalls heute ─────────
|
||||
perform promote_employee(jsonb_build_object(
|
||||
@@ -121,7 +121,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/14 Beförderung am selben Tag: Hay-Grade und Planstellenbezeichnung';
|
||||
raise notice '4/17 Beförderung am selben Tag: Hay-Grade und Planstellenbezeichnung';
|
||||
|
||||
-- Dieselbe Planstelle, nur ein neuer Name.
|
||||
perform promote_employee(jsonb_build_object(
|
||||
@@ -139,7 +139,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/14 Beförderung ohne Stellenwechsel benennt dieselbe Planstelle um';
|
||||
raise notice '4b/17 Beförderung ohne Stellenwechsel benennt dieselbe Planstelle um';
|
||||
|
||||
-- ── Vorgemerkte Planstelle (20260929200000) ─────────────────────
|
||||
-- Eine Versetzung in die Zukunft belegt die Zielstelle, obwohl dort noch
|
||||
@@ -170,13 +170,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/14 Vorgemerkte Planstelle wird abgewiesen';
|
||||
raise notice '5/17 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/14 Die eigene Vormerkung steht nicht im Weg';
|
||||
raise notice '6/17 Die eigene Vormerkung steht nicht im Weg';
|
||||
|
||||
-- ── Austritt am selben Tag (20260929220000) ─────────────────────
|
||||
perform terminate_employee(jsonb_build_object(
|
||||
@@ -188,7 +188,7 @@ begin
|
||||
if v_offen <> 0 then
|
||||
raise exception 'Nach dem Austritt ist die Planstelle nicht frei.';
|
||||
end if;
|
||||
raise notice '7/14 Austritt am selben Tag, Planstelle frei';
|
||||
raise notice '7/17 Austritt am selben Tag, Planstelle frei';
|
||||
|
||||
-- ── Wiedereintritt (20260929160000) ─────────────────────────────
|
||||
perform rehire_employee(jsonb_build_object(
|
||||
@@ -205,7 +205,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/14 Wiedereintritt';
|
||||
raise notice '8/17 Wiedereintritt';
|
||||
|
||||
-- ── Rückdatierte Versetzung (20261013140000) ────────────────────
|
||||
--
|
||||
@@ -240,7 +240,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/14 Rückdatierte Versetzung lässt keine zweite Besetzung stehen';
|
||||
raise notice '9/17 Rückdatierte Versetzung lässt keine zweite Besetzung stehen';
|
||||
|
||||
-- ── Versetzung bei datiertem Austritt (20261013140000) ──────────
|
||||
--
|
||||
@@ -274,7 +274,7 @@ begin
|
||||
if v_offen <> 1 then
|
||||
raise exception 'Die neue Besetzung endet nicht am Austrittstag.';
|
||||
end if;
|
||||
raise notice '10/14 Versetzung bei datiertem Austritt: kein Überlappen, kein Überleben';
|
||||
raise notice '10/17 Versetzung bei datiertem Austritt: kein Überlappen, kein Überleben';
|
||||
|
||||
-- ── Änderung vor dem Eintritt (20261018100000) ──────────────────
|
||||
--
|
||||
@@ -313,7 +313,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/14 Änderung vor dem Eintritt wirkt sofort und wandert mit dem Eintritt';
|
||||
raise notice '11/17 Änderung vor dem Eintritt wirkt sofort und wandert mit dem Eintritt';
|
||||
|
||||
-- ── Abwesenheit mit geplanter Rückkehr löschen (20261019100000) ─
|
||||
--
|
||||
@@ -347,7 +347,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/14 Abwesenheit mit geplanter Rückkehr lässt sich löschen';
|
||||
raise notice '12/17 Abwesenheit mit geplanter Rückkehr lässt sich löschen';
|
||||
|
||||
-- ── Zweite Versetzung zum selben Tag (20261019110000) ───────────
|
||||
--
|
||||
@@ -387,7 +387,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/14 Zweite Versetzung zum selben Tag abgewiesen, die erste lässt sich abbrechen';
|
||||
raise notice '13/17 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.
|
||||
@@ -400,7 +400,59 @@ 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/14 Eigene Notiz lässt sich löschen, das Protokoll behält sie';
|
||||
raise notice '14/17 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
|
||||
-- Planstelle 3 endet dort. Nach der Rücknahme läuft sie wieder offen.
|
||||
perform austritt_zuruecknehmen(jsonb_build_object('employee_id', v_b));
|
||||
if (select exit_date from employees where id = v_b) is not null then
|
||||
raise exception 'Nach der Rücknahme steht noch ein Austrittsdatum.';
|
||||
end if;
|
||||
if not exists (select 1 from position_assignments where employee_id = v_b and position_id = v_p3 and valid_to is null) then
|
||||
raise exception 'Nach der Rücknahme läuft die Besetzung nicht wieder offen.';
|
||||
end if;
|
||||
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/17 Austritt zurückgenommen, Besetzung läuft wieder';
|
||||
|
||||
-- ── Letzte Versetzung zurücknehmen (20261019140000) ─────────────
|
||||
v_p8 := create_position(jsonb_build_object('org_unit_id', v_einheit,
|
||||
'job_title', 'Rauchtest Acht', 'is_chief', false, 'valid_from', (current_date - 30)::text));
|
||||
v_p9 := create_position(jsonb_build_object('org_unit_id', v_einheit,
|
||||
'job_title', 'Rauchtest Neun', 'is_chief', false, 'valid_from', (current_date - 30)::text));
|
||||
v_e := hire_employee(jsonb_build_object(
|
||||
'personnel_number', v_nr + 5, 'first_name', 'Rauch', 'last_name', 'Test-F',
|
||||
'gender', 'w', 'birth_date', '1990-01-01', 'location_id', v_ort,
|
||||
'position_id', v_p8, 'entry_date', (current_date - 10)::text));
|
||||
perform transfer_employee(jsonb_build_object(
|
||||
'employee_id', v_e, 'target_position_id', v_p9, 'effective_date', (current_date - 5)::text));
|
||||
|
||||
perform delete_history_entry(jsonb_build_object(
|
||||
'history_id', (select id from employee_history where employee_id = v_e and event_type = 'Versetzung')));
|
||||
|
||||
if not exists (select 1 from position_assignments where employee_id = v_e and position_id = v_p8 and valid_to is null) then
|
||||
raise exception 'Nach der Rücknahme sitzt die Person nicht wieder auf ihrer vorherigen Planstelle.';
|
||||
end if;
|
||||
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/17 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.
|
||||
perform eintritt_planstelle_berichtigen(jsonb_build_object('employee_id', v_c, 'position_id', v_p9));
|
||||
if not exists (select 1 from position_assignments where employee_id = v_c and position_id = v_p9) then
|
||||
raise exception 'Die Planstelle beim Eintritt wurde nicht berichtigt.';
|
||||
end if;
|
||||
if exists (select 1 from position_assignments where employee_id = v_c and position_id = v_p5) then
|
||||
raise exception 'Nach der Berichtigung steht die Person auch noch auf der alten Planstelle.';
|
||||
end if;
|
||||
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/17 Planstelle beim Eintritt berichtigt, ohne Versetzung';
|
||||
|
||||
raise notice '';
|
||||
raise notice 'Rauchtest bestanden. Alles Angelegte wird gleich verworfen.';
|
||||
|
||||
Reference in New Issue
Block a user