FL statt VL, Stufen 1 bis 7
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 11m56s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m27s
CI / Ausrollen (push) Successful in 7s

Die Angabe heisst ueberall "FL" (Einstellung, Wiedereintritt, Daten aendern,
Akte, Zusammenfassung, Export, Austauschdatei). Gespeichert bleibt sie in
vl, in Historie und Feldkarte als "VL"; anzeige() zeigt dort "FL".

Migration 20261201120000: chk_vl auf 1 bis 7. Bestand mit 8 wird geleert
und je Person im Protokoll vermerkt ("FL geleert"). Geplante Aenderungen
auf 8 verlieren diese Angabe in Vormerkung und Historienzeile; bleibt
nichts uebrig, entfaellt der Vorgang samt Zeile. Jeweils Protokolleintrag.

Geprueft: lint, tsc, types:check, npm test (1123), waechter; Migrationen auf
leerer Datenbank zweimal (Nichts anzuwenden), rauchtest.sql,
vertragsangaben.sql (FL 8 abgewiesen, Wiedereintritt mit FL 6); Bestand
mit FL 8, geplanter Aenderung FL 8 plus Bonus und geplanter Aenderung nur
FL 8: geleert, Bonus bleibt vorgemerkt, Vorgang entfaellt.
This commit is contained in:
2026-12-01 12:12:59 +01:00
parent 1729c2faad
commit 9ce6375b33
14 changed files with 119 additions and 28 deletions

View File

@@ -0,0 +1,78 @@
-- FL: Stufen 1 bis 7
--
-- Die Angabe heisst fachlich „FL" und kennt die Stufen 1 bis 7. Gespeichert
-- bleibt sie in der Spalte vl, und in der Historie und der Feldkarte heisst
-- das Feld weiter „VL": daran hängen Berichtigen und Zurücksetzen bestehender
-- Einträge. Die Oberfläche zeigt „FL" (lib/anzeige.ts).
--
-- Bestand mit Stufe 8: welche Stufe stattdessen gilt, geht aus den Daten
-- nicht hervor. Die Angabe wird geleert und je Person im Protokoll vermerkt;
-- ein geratener Wert sähe aus wie ein erfasster. Geplante Änderungen auf
-- Stufe 8 verlieren diese eine Angabe, in der Vormerkung und in ihrer
-- Historienzeile; der Rest des Vorgangs bleibt. Bleibt nichts übrig, entfällt
-- der Vorgang samt Zeile, wie beim Abbrechen in der Historie.
do $geplant$
declare
v_plan record;
v_payload jsonb;
begin
for v_plan in
select * from pending_org_changes
where status = 'pending' and payload->'contract'->>'vl' = '8'
loop
v_payload := jsonb_set(v_plan.payload, '{contract}', (v_plan.payload->'contract') - 'vl');
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
select null, 'Wartung', 'Geplante Änderung angepasst', e.first_name || ' ' || e.last_name, e.id,
'Zum ' || v_plan.effective_date || ' war FL 8 vorgemerkt. Die Stufe 8 gibt es nicht mehr; '
|| 'diese Angabe entfällt aus dem Vorgang.'
from employees e where e.id = v_plan.employee_id;
if coalesce(v_payload->'person', '{}'::jsonb) = '{}'::jsonb
and coalesce(v_payload->'contract', '{}'::jsonb) = '{}'::jsonb
and coalesce(v_payload->'role', '{}'::jsonb) = '{}'::jsonb then
update pending_org_changes set status = 'cancelled' where id = v_plan.id;
delete from employee_history where pending_id = v_plan.id;
else
update pending_org_changes set payload = v_payload where id = v_plan.id;
-- In der Beschreibung steht die Liste der Felder, jedes gefolgt von
-- einem Komma („Geänderte Felder: VL, Bonusanspruch, wirksam ab …").
update employee_history h
set changes = (select coalesce(jsonb_agg(a), '[]'::jsonb)
from jsonb_array_elements(h.changes) a
where a->>'feld' <> 'VL'),
description = replace(h.description, 'VL, ', '')
where h.pending_id = v_plan.id;
end if;
end loop;
end
$geplant$;
insert into audit_log (actor_user_id, actor_name, action, target_label, target_employee_id, details)
select null, 'Wartung', 'FL geleert', e.first_name || ' ' || e.last_name, e.id,
'Die Stufe 8 gibt es nicht mehr; FL war 8 und ist jetzt leer. Bitte die zutreffende Stufe (1 bis 7) nachtragen.'
from employees e
where e.vl = 8;
update employees set vl = null where vl = 8;
alter table employees drop constraint if exists chk_vl;
alter table employees add constraint chk_vl check (vl is null or vl between 1 and 7);
comment on column employees.vl is 'FL, Stufe 1 bis 7; leer heisst nicht erfasst. In Historie und Feldkarte als „VL" geführt.';
do $pruefung$
begin
if exists (select 1 from employees where vl not between 1 and 7) then
raise exception 'Es gibt noch FL-Werte ausserhalb von 1 bis 7.';
end if;
if exists (select 1 from pending_org_changes where status = 'pending' and payload->'contract'->>'vl' = '8') then
raise exception 'Es gibt noch geplante Änderungen auf FL 8.';
end if;
if pg_get_constraintdef((select oid from pg_constraint where conname = 'chk_vl' and conrelid = 'public.employees'::regclass))
not like '%vl >= 1%vl <= 7%' then
raise exception 'chk_vl erlaubt nicht genau 1 bis 7.';
end if;
end
$pruefung$;

View File

@@ -149,14 +149,14 @@ begin
perform hire_employee(jsonb_build_object(
'personnel_number', v_nr + 2, 'first_name', 'X', 'last_name', 'Y', 'gender', 'm',
'birth_date', '1980-01-01', 'location_id', v_ort, 'position_id', v_p3,
'entry_date', current_date::text, 'vl', 9));
'entry_date', current_date::text, 'vl', 8));
v_ging := true;
exception when others then v_ging := false;
end;
if v_ging then
raise exception '3: VL 9 wurde angenommen.';
raise exception '3: FL 8 wurde angenommen.';
end if;
raise notice '3/9 Abgewiesen: Bonus ohne Regelung, abgeschaltete HR, „Süßwaren", VL 9';
raise notice '3/9 Abgewiesen: Bonus ohne Regelung, abgeschaltete HR, „Süßwaren", FL 8';
-- ── 4. Daten ändern, sofort ────────────────────────────────────
perform change_employee_data(jsonb_build_object(
@@ -271,16 +271,16 @@ begin
'employee_id', v_a, 'rehire_date', current_date::text, 'position_id', v_p3,
'first_name', 'Vertrag', 'last_name', 'Test-A', 'gender', 'w',
'birth_date', '1990-01-01', 'nationality', 'Österreich', 'location_id', v_ort,
'vl', 8, 'has_bonusanspruch', false, 'zustaendige_hr_id', v_hr1,
'vl', 6, 'has_bonusanspruch', false, 'zustaendige_hr_id', v_hr1,
'collective_agreement', 'Süßware Angestellter', 'erlernter_beruf', 'Bäckerin'));
select * into v_e from employees where id = v_a;
if v_e.vl <> 8 or v_e.has_bonusanspruch or v_e.bonusanspruch_art is not null
if v_e.vl <> 6 or v_e.has_bonusanspruch or v_e.bonusanspruch_art is not null
or v_e.zustaendige_hr_id <> v_hr1 or v_e.collective_agreement::text <> 'Süßware Angestellter'
or v_e.erlernter_beruf is distinct from 'Bäckerin' then
raise exception '9: Wiedereintritt hat VL/Bonus/HR/KV nicht übernommen: % % % % %',
v_e.vl, v_e.has_bonusanspruch, v_e.bonusanspruch_art, v_e.zustaendige_hr_id, v_e.collective_agreement;
end if;
raise notice '9/9 Wiedereintritt übernimmt VL 8, Bonus Nein, HR und Süßware Angestellter';
raise notice '9/9 Wiedereintritt übernimmt FL 6, Bonus Nein, HR und Süßware Angestellter';
raise notice 'Vertragsangaben-Rauchtest bestanden. Alles Angelegte wird gleich verworfen.';
end