Kostenstelle anlegen, Leitungsplanstelle nicht mehr beim Anlegen einer Einheit
- Unter Planstellen gibt es "Kostenstelle anlegen" (Nummer, Bezeichnung, gueltig ab; create_cost_center). Danach steht sie bei jeder Planstelle zur Auswahl. Doppelte Nummern werden abgewiesen. - "Einheit anlegen" fragt nicht mehr nach einer Leitungsplanstelle: das war ein freies Textfeld, aus dem eine Taetigkeit entstand. Die Leitung wird ueber "Planstelle anlegen" erfasst, mit Taetigkeit aus dem Katalog. Rauchtest: Schritt 23. Geprueft: lint, tsc, types:check, 928 Tests, Uebergabe-Waechter
This commit is contained in:
61
db/migrations/20261020110000_kostenstelle_anlegen.sql
Normal file
61
db/migrations/20261020110000_kostenstelle_anlegen.sql
Normal file
@@ -0,0 +1,61 @@
|
||||
-- Eine Kostenstelle anlegen.
|
||||
--
|
||||
-- Kostenstellen werden Planstellen zugeordnet (set_position_cost_center).
|
||||
-- Neue entstehen in der Anwendung, damit eine neue Planstelle nicht auf eine
|
||||
-- Kostenstelle warten muss, die nur über die Datenbank hinzukäme.
|
||||
--
|
||||
-- Die Nummer ist eindeutig und muss zum führenden System passen; sie wird
|
||||
-- erfasst, nicht vergeben. Die verantwortliche Einheit bleibt leer — sie ist
|
||||
-- nur ein Hinweis, und eine Planstelle wird ohnehin einzeln kontiert.
|
||||
create or replace function public.create_cost_center(payload jsonb)
|
||||
returns uuid
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_code text := nullif(btrim(payload->>'code'), '');
|
||||
v_name text := nullif(btrim(payload->>'name'), '');
|
||||
v_ab date := coalesce(nullif(payload->>'valid_from', '')::date, current_date);
|
||||
v_id uuid;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
if v_code is null or v_name is null then
|
||||
raise exception 'Nummer und Bezeichnung der Kostenstelle sind anzugeben.';
|
||||
end if;
|
||||
if v_code ~ '\s' then
|
||||
raise exception 'Die Kostenstellennummer darf keine Leerzeichen enthalten.';
|
||||
end if;
|
||||
if exists (select 1 from cost_centers where code = v_code) then
|
||||
raise exception 'Die Kostenstelle % gibt es bereits.', v_code;
|
||||
end if;
|
||||
|
||||
insert into cost_centers (code, name, valid_from)
|
||||
values (v_code, v_name, v_ab)
|
||||
returning id into v_id;
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, details)
|
||||
values (app_current_user_id(), current_actor_name(), 'Kostenstelle angelegt',
|
||||
v_code || ' · ' || v_name, 'gültig ab ' || to_char(v_ab, 'DD.MM.YYYY'));
|
||||
|
||||
return v_id;
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.create_cost_center(jsonb) to alpenwerk_app;
|
||||
|
||||
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 = 'create_cost_center';
|
||||
if position(E'begin\n perform require_hr_admin();' in v_def) = 0 then
|
||||
raise exception 'create_cost_center prüft die Rechte nicht in der ersten Zeile.';
|
||||
end if;
|
||||
if position('insert into audit_log' in v_def) = 0 then
|
||||
raise exception 'create_cost_center schreibt kein Protokoll.';
|
||||
end if;
|
||||
end
|
||||
$pruefung$;
|
||||
Reference in New Issue
Block a user