Rueckkehrdatum in der Historie berichtigen zurueckgenommen
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m14s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m12s
CI / Ausrollen (push) Successful in 6s

Nimmt a57c033 vollstaendig zurueck: Migration 20261110100000, Schritt
35f im Rauchtest, Dialog "Eintrag berichtigen" fuer die Rueckkehr und
die Beschriftung bei Wochenhilfe. Die Berichtigung von Beginn und
Rueckkehr einer Langzeitabwesenheit wird als Ganzes neu entworfen.
Die Migration ist auf keiner Datenbank eingespielt.

Geprueft: lint, tsc, types:check, npm test, waechter.
This commit is contained in:
2026-11-10 13:09:47 +01:00
parent a57c033a3f
commit 8eac8cc7f9
8 changed files with 10 additions and 540 deletions

View File

@@ -1375,134 +1375,6 @@ begin
end if;
raise notice '35e/35 Arbeitszeitmodell: falsche Summe beim Berichtigen und Vormerken abgewiesen, stimmige übernommen';
-- ── Rückkehrdatum in der Historie berichtigen (20261110100000) ──
-- a) An der laufenden Abwesenheit auf heute: die Rückkehr ist verbucht,
-- nicht als offene Vormerkung liegengeblieben.
v_px := create_position(jsonb_build_object('org_unit_id', v_einheit,
'job_title', 'Rauchtest Rückkehr A', 'is_chief', false, 'valid_from', (current_date - 30)::text));
v_x := hire_employee(jsonb_build_object(
'personnel_number', v_nr + 26, 'first_name', 'Rauch', 'last_name', 'Test-RA',
'gender', 'w', 'birth_date', '1990-01-01', 'location_id', v_ort, 'nationality', 'Österreich',
'position_id', v_px, 'entry_date', (current_date - 25)::text,
'employment_type', 'Vollzeit', 'weekly_hours', 38.5));
perform start_karenz(jsonb_build_object(
'employee_id', v_x, 'karenz_start_date', (current_date - 10)::text,
'planned_return_date', (current_date + 10)::text, 'absence_type', 'Langer Krankenstand'));
perform update_history_entry(jsonb_build_object(
'history_id', (select id from employee_history where employee_id = v_x and event_type = 'Karenz'),
'werte', jsonb_build_array(jsonb_build_object('feld', 'Geplante Rückkehr', 'nachher', current_date::text))));
if exists (select 1 from pending_org_changes where employee_id = v_x and status = 'pending') then
raise exception 'Die Rückkehr auf heute liegt als offene Vormerkung herum.';
end if;
if (select status::text from employees where id = v_x) <> 'Aktiv'
or (select karenz_start_date from employees where id = v_x) is not null then
raise exception 'Nach der Rückkehr auf heute steht die Abwesenheit noch an der Person.';
end if;
if (select count(*) from employee_history where employee_id = v_x and event_type = 'Rückkehr'
and event_date = current_date and not app_vormerkung_offen(pending_id)) <> 1 then
raise exception 'Erwartet wurde genau eine verbuchte Rückkehr zu heute.';
end if;
if not exists (select 1 from checklisten where employee_id = v_x and art = 'onboarding' and anlass = 'Rückkehr') then
raise exception 'Die Rückkehr auf heute hat keine Onboarding-Checkliste angelegt.';
end if;
-- b) Die verbuchte Rückkehr in die Zukunft: die Abwesenheit läuft wieder,
-- die Rückkehr ist vorgemerkt, die unberührte Checkliste fällt weg.
v_px := create_position(jsonb_build_object('org_unit_id', v_einheit,
'job_title', 'Rauchtest Rückkehr B', 'is_chief', false, 'valid_from', (current_date - 30)::text));
v_x := hire_employee(jsonb_build_object(
'personnel_number', v_nr + 27, 'first_name', 'Rauch', 'last_name', 'Test-RB',
'gender', 'w', 'birth_date', '1990-01-01', 'location_id', v_ort, 'nationality', 'Österreich',
'position_id', v_px, 'entry_date', (current_date - 25)::text,
'employment_type', 'Vollzeit', 'weekly_hours', 38.5));
perform start_karenz(jsonb_build_object(
'employee_id', v_x, 'karenz_start_date', (current_date - 20)::text,
'planned_return_date', (current_date - 2)::text, 'absence_type', 'Bildungskarenz'));
-- Die Felder der Abwesenheit lassen sich an der Rückkehr nicht einzeln setzen …
v_ging := false;
begin
perform update_history_entry(jsonb_build_object(
'history_id', (select id from employee_history where employee_id = v_x and event_type = 'Rückkehr'),
'werte', jsonb_build_array(jsonb_build_object('feld', 'Geplante Rückkehr', 'nachher', (current_date + 7)::text))));
v_ging := true;
exception when others then v_meldung := SQLERRM;
end;
if v_ging or v_meldung not like 'Status, Art, Beginn und geplante Rückkehr folgen bei einer Rückkehr aus ihrem Datum.%' then
raise exception 'An einer Rückkehr liess sich die geplante Rückkehr einzeln setzen (%).', v_meldung;
end if;
-- … das Rückkehrdatum schon.
perform update_history_entry(jsonb_build_object(
'history_id', (select id from employee_history where employee_id = v_x and event_type = 'Rückkehr'),
'event_date', (current_date + 7)::text));
if (select status::text from employees where id = v_x) <> 'Karenz'
or (select karenz_start_date from employees where id = v_x) is distinct from current_date - 20
or (select absence_type from employees where id = v_x) is distinct from 'Bildungskarenz'
or (select karenz_return_date from employees where id = v_x) is distinct from current_date + 7 then
raise exception 'Nach dem Verschieben in die Zukunft läuft die Abwesenheit nicht wieder.';
end if;
if (select count(*) from pending_org_changes where employee_id = v_x and status = 'pending'
and change_type = 'karenz_return' and effective_date = current_date + 7) <> 1
or (select count(*) from employee_history where employee_id = v_x and event_type = 'Rückkehr') <> 1
or not exists (select 1 from employee_history where employee_id = v_x and event_type = 'Rückkehr'
and event_date = current_date + 7 and app_vormerkung_offen(pending_id)) then
raise exception 'Die verschobene Rückkehr ist nicht als einzige Rückkehr vorgemerkt.';
end if;
if exists (select 1 from checklisten where employee_id = v_x and anlass = 'Rückkehr') then
raise exception 'Die unberührte Checkliste der verschobenen Rückkehr ist stehen geblieben.';
end if;
if app_vormerkung_scheitert(array(select id from pending_org_changes where employee_id = v_x and status = 'pending')) is not null then
raise exception 'Der nächtliche Lauf übernimmt die verschobene Rückkehr nicht.';
end if;
-- c) Die verbuchte Rückkehr auf einen anderen vergangenen Tag: das
-- reduzierte Ausmass, mit dem die Person zurückkam, geht mit.
v_px := create_position(jsonb_build_object('org_unit_id', v_einheit,
'job_title', 'Rauchtest Rückkehr C', 'is_chief', false, 'valid_from', (current_date - 30)::text));
v_x := hire_employee(jsonb_build_object(
'personnel_number', v_nr + 28, 'first_name', 'Rauch', 'last_name', 'Test-RC',
'gender', 'w', 'birth_date', '1990-01-01', 'location_id', v_ort, 'nationality', 'Österreich',
'position_id', v_px, 'entry_date', (current_date - 25)::text,
'employment_type', 'Vollzeit', 'weekly_hours', 38.5));
perform start_karenz(jsonb_build_object(
'employee_id', v_x, 'karenz_start_date', (current_date - 20)::text,
'planned_return_date', (current_date + 5)::text, 'absence_type', 'Langer Krankenstand'));
perform rueckkehr_anpassen(jsonb_build_object(
'employee_id', v_x, 'return_date', (current_date - 3)::text,
'employment_mode', 'Teilzeit', 'weekly_hours', 20));
perform update_history_entry(jsonb_build_object(
'history_id', (select id from employee_history where employee_id = v_x and event_type = 'Rückkehr'),
'event_date', (current_date - 1)::text));
if (select status::text from employees where id = v_x) <> 'Aktiv'
or (select karenz_start_date from employees where id = v_x) is not null
or (select weekly_hours from employees where id = v_x) <> 20
or (select employment_type::text from employees where id = v_x) <> 'Teilzeit' then
raise exception 'Nach dem Verschieben in der Vergangenheit stimmt der Stand nicht.';
end if;
if (select count(*) from employee_history where employee_id = v_x and event_type = 'Rückkehr') <> 1
or not exists (select 1 from employee_history where employee_id = v_x and event_type = 'Rückkehr'
and event_date = current_date - 1 and pending_id is null) then
raise exception 'Die verschobene Rückkehr steht nicht als einzige am neuen Tag.';
end if;
if (select count(*) from checklisten where employee_id = v_x and anlass = 'Rückkehr') <> 1 then
raise exception 'Nach dem Verschieben in der Vergangenheit gibt es nicht genau eine Checkliste zur Rückkehr.';
end if;
-- Vor dem Beginn der Abwesenheit geht nicht.
v_ging := false;
begin
perform update_history_entry(jsonb_build_object(
'history_id', (select id from employee_history where employee_id = v_x and event_type = 'Rückkehr'),
'event_date', (current_date - 25)::text));
v_ging := true;
exception when others then v_meldung := SQLERRM;
end;
if v_ging or v_meldung not like 'Das Rückkehrdatum muss nach dem Beginn der Langzeitabwesenheit%' then
raise exception 'Die Rückkehr liess sich vor den Beginn der Abwesenheit legen (%).', v_meldung;
end if;
raise notice '35f/35 Rückkehrdatum berichtigt: heute verbucht, in die Zukunft wieder vorgemerkt, in der Vergangenheit verschoben';
raise notice '';
raise notice 'Rauchtest bestanden. Alles Angelegte wird gleich verworfen.';
end