diff --git a/components/employees/tabs/StammdatenTab.tsx b/components/employees/tabs/StammdatenTab.tsx
index e472002..8f070e9 100644
--- a/components/employees/tabs/StammdatenTab.tsx
+++ b/components/employees/tabs/StammdatenTab.tsx
@@ -50,6 +50,7 @@ export function StammdatenTab({ employee, location, dependents }: { employee: Em
],
] as [string, string][])
: []),
+ ["Erlernter Beruf", employee.erlernter_beruf ?? "–"],
["Adresse", employee.address ?? "–"],
["Postleitzahl", employee.postal_code ?? "–"],
["Ort", employee.city ?? "–"],
diff --git a/components/hire/HireWizard.tsx b/components/hire/HireWizard.tsx
index 71faf81..d311078 100644
--- a/components/hire/HireWizard.tsx
+++ b/components/hire/HireWizard.tsx
@@ -155,6 +155,7 @@ export function HireWizard({ open, onClose, openPositions, locations, resumeDraf
company_email: draft.companyEmail.trim() || undefined,
cornerstone_id: draft.cornerstoneId.trim() || undefined,
zustaendige_hr_id: draft.zustaendigeHrId || undefined,
+ erlernter_beruf: draft.erlernterBeruf.trim() || undefined,
phone: draft.phone || undefined,
position_id: draft.positionId,
location_id: draft.locationId,
diff --git a/components/hire/RehireWizard.tsx b/components/hire/RehireWizard.tsx
index f0b073e..caa6f5b 100644
--- a/components/hire/RehireWizard.tsx
+++ b/components/hire/RehireWizard.tsx
@@ -128,6 +128,7 @@ export function RehireWizard({ open, onClose, employee, openPositions, locations
company_email: draft.companyEmail.trim(),
cornerstone_id: draft.cornerstoneId.trim(),
zustaendige_hr_id: draft.zustaendigeHrId,
+ erlernter_beruf: draft.erlernterBeruf.trim(),
phone: draft.phone.trim(),
location_id: draft.locationId,
// Anschrift, Staatsbürgerschaft und Aufenthaltstitel stehen bewusst
diff --git a/components/hire/StepPerson.tsx b/components/hire/StepPerson.tsx
index c43d905..bb90ed5 100644
--- a/components/hire/StepPerson.tsx
+++ b/components/hire/StepPerson.tsx
@@ -64,6 +64,12 @@ export function StepPerson({ draft, update, locations, onNummerBefund, nummerGes
locationCountry={locations.find((l) => l.id === draft.locationId)?.country}
birthDate={draft.birthDate || null}
/>
+
update({ erlernterBeruf })}
+ hint="Freiwillig. Der gelernte Beruf, nicht die Tätigkeit der Planstelle."
+ />
{/* Die private Adresse, nicht die Firmenadresse — die entsteht erst
mit dem Eintritt. Freiwillig: wer keine hat oder keine angeben
diff --git a/components/hire/StepSummary.tsx b/components/hire/StepSummary.tsx
index 3caa4a1..776ed77 100644
--- a/components/hire/StepSummary.tsx
+++ b/components/hire/StepSummary.tsx
@@ -33,6 +33,7 @@ export function StepSummary({ draft, selectedPosition, locations }: StepSummaryP
["Geschlecht", draft.gender === "m" ? "männlich" : "weiblich"],
["Geburtsdatum", fmtDate(draft.birthDate)],
["SV-Nummer", draft.svNummer || "–"],
+ ["Erlernter Beruf", draft.erlernterBeruf.trim() || "–"],
["E-Mail (privat)", draft.email || "–"],
["Telefon", draft.phone || "–"],
["Notfallkontakt", notfall || "–"],
diff --git a/components/hire/types.ts b/components/hire/types.ts
index 11f2765..e5d6536 100644
--- a/components/hire/types.ts
+++ b/components/hire/types.ts
@@ -40,6 +40,8 @@ export type HireDraftData = {
cornerstoneId: string;
/** profiles.id der zuständigen Person in der Personalabteilung; "" heisst nicht zugeordnet. */
zustaendigeHrId: string;
+ /** Freier Text, freiwillig; "" heisst nicht erfasst. */
+ erlernterBeruf: string;
phone: string;
locationId: string;
positionId: string;
@@ -96,6 +98,7 @@ export const EMPTY_HIRE_DRAFT: HireDraftData = {
companyEmail: "",
cornerstoneId: "",
zustaendigeHrId: "",
+ erlernterBeruf: "",
phone: "",
locationId: "",
positionId: "",
diff --git a/db/migrations/20261008100000_erlernter_beruf.sql b/db/migrations/20261008100000_erlernter_beruf.sql
new file mode 100644
index 0000000..c8f2357
--- /dev/null
+++ b/db/migrations/20261008100000_erlernter_beruf.sql
@@ -0,0 +1,212 @@
+-- Erlernter Beruf
+--
+-- Ein freies Textfeld in den Stammdaten, freiwillig: der Beruf, den jemand
+-- gelernt hat — nicht die Tätigkeit der Planstelle. Gehört zur Gruppe
+-- `person`, steht im Einstellungsassistenten (Schritt „Person"), im
+-- Wiedereintritt und in „Daten ändern".
+--
+-- Gespeichert wird getrimmt; leer heisst nicht erfasst (null). Ein Feld, in
+-- dem nur ein Leerzeichen stehen geblieben ist, wäre sonst eine Angabe, die
+-- in jeder Auswertung als eigener Wert auftaucht.
+--
+-- Ergänzt wird wie in 20261007100000: aus der laufenden Definition gelesen,
+-- an genau einem Anker je Stelle, einzeilig, sonst Abbruch. Die Anker sind die
+-- Zeilen der zuständigen HR, die jene Migration eingefügt hat.
+
+-- ═══ 1. Die Spalte ═════════════════════════════════════════════════
+alter table employees add column if not exists erlernter_beruf text;
+comment on column employees.erlernter_beruf is
+ 'Erlernter Beruf, freier Text. Null heisst nicht erfasst.';
+
+-- ═══ 2. hire_employee ═════════════════════════════════════════════
+do $migration$
+declare
+ v_alt_spalten constant text := $anker$paygrade, vl, has_bonusanspruch, bonusanspruch_art, zustaendige_hr_id,$anker$;
+ v_neu_spalten constant text := $anker$paygrade, vl, has_bonusanspruch, bonusanspruch_art, zustaendige_hr_id, erlernter_beruf,$anker$;
+ v_alt_werte constant text := $anker$nullif(payload->>'zustaendige_hr_id', '')::uuid,$anker$;
+ v_neu_werte constant text := $anker$nullif(payload->>'zustaendige_hr_id', '')::uuid,
+ nullif(btrim(payload->>'erlernter_beruf'), ''),$anker$;
+ 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.proname = 'hire_employee' and p.prokind = 'f';
+
+ if v_def is null then
+ raise exception 'hire_employee ist nicht vorhanden.';
+ end if;
+ if v_def like '%erlernter_beruf%' then
+ raise exception 'hire_employee kennt den erlernten Beruf bereits.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt_spalten, ''))) / length(v_alt_spalten) <> 1 then
+ raise exception 'hire_employee: der Anker für die Spalten kommt nicht genau einmal vor.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt_werte, ''))) / length(v_alt_werte) <> 1 then
+ raise exception 'hire_employee: der Anker für die Werte kommt nicht genau einmal vor.';
+ end if;
+
+ execute replace(replace(v_def, v_alt_spalten, v_neu_spalten), v_alt_werte, v_neu_werte);
+end
+$migration$;
+
+-- ═══ 3. rehire_employee ═══════════════════════════════════════════
+do $migration$
+declare
+ v_alt constant text := $anker$zustaendige_hr_id = case when payload ? 'zustaendige_hr_id' then nullif(payload->>'zustaendige_hr_id', '')::uuid else zustaendige_hr_id end,$anker$;
+ v_neu constant text := $anker$zustaendige_hr_id = case when payload ? 'zustaendige_hr_id' then nullif(payload->>'zustaendige_hr_id', '')::uuid else zustaendige_hr_id end,
+ erlernter_beruf = case when payload ? 'erlernter_beruf' then nullif(btrim(payload->>'erlernter_beruf'), '') else erlernter_beruf end,$anker$;
+ 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.proname = 'rehire_employee' and p.prokind = 'f';
+
+ if v_def is null then
+ raise exception 'rehire_employee ist nicht vorhanden.';
+ end if;
+ if v_def like '%erlernter_beruf%' then
+ raise exception 'rehire_employee kennt den erlernten Beruf bereits.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt, ''))) / length(v_alt) <> 1 then
+ raise exception 'rehire_employee: der Anker kommt nicht genau einmal vor.';
+ end if;
+
+ execute replace(v_def, v_alt, v_neu);
+end
+$migration$;
+
+-- ═══ 4. change_employee_data ══════════════════════════════════════
+do $migration$
+declare
+ v_alt_log constant text := $anker$if v_person ? 'zustaendige_hr_id' then v_person_changes := app_aenderung(v_person_changes, 'Zuständige HR', v_old.zustaendige_hr_id::text, (nullif(v_person->>'zustaendige_hr_id', '')::uuid)::text); end if;$anker$;
+ v_neu_log constant text := $anker$if v_person ? 'zustaendige_hr_id' then v_person_changes := app_aenderung(v_person_changes, 'Zuständige HR', v_old.zustaendige_hr_id::text, (nullif(v_person->>'zustaendige_hr_id', '')::uuid)::text); end if;
+ if v_person ? 'erlernter_beruf' then v_person_changes := app_aenderung(v_person_changes, 'Erlernter Beruf', v_old.erlernter_beruf, nullif(btrim(v_person->>'erlernter_beruf'), '')); end if;$anker$;
+ v_alt_upd constant text := $anker$zustaendige_hr_id = case when v_person ? 'zustaendige_hr_id' then nullif(v_person->>'zustaendige_hr_id', '')::uuid else zustaendige_hr_id end,$anker$;
+ v_neu_upd constant text := $anker$zustaendige_hr_id = case when v_person ? 'zustaendige_hr_id' then nullif(v_person->>'zustaendige_hr_id', '')::uuid else zustaendige_hr_id end,
+ erlernter_beruf = case when v_person ? 'erlernter_beruf' then nullif(btrim(v_person->>'erlernter_beruf'), '') else erlernter_beruf end,$anker$;
+ 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.proname = 'change_employee_data' and p.prokind = 'f';
+
+ if v_def is null then
+ raise exception 'change_employee_data ist nicht vorhanden.';
+ end if;
+ if v_def like '%erlernter_beruf%' then
+ raise exception 'change_employee_data kennt den erlernten Beruf bereits.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt_log, ''))) / length(v_alt_log) <> 1 then
+ raise exception 'change_employee_data: der Anker für das Protokoll kommt nicht genau einmal vor.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt_upd, ''))) / length(v_alt_upd) <> 1 then
+ raise exception 'change_employee_data: der Anker für die Spalten kommt nicht genau einmal vor.';
+ end if;
+
+ execute replace(replace(v_def, v_alt_log, v_neu_log), v_alt_upd, v_neu_upd);
+end
+$migration$;
+
+-- ═══ 5. apply_due_pending_changes ═════════════════════════════════
+do $migration$
+declare
+ v_alt constant text := $anker$zustaendige_hr_id = case when (v_rec.payload->'person') ? 'zustaendige_hr_id' then nullif(v_rec.payload->'person'->>'zustaendige_hr_id', '')::uuid else zustaendige_hr_id end,$anker$;
+ v_neu constant text := $anker$zustaendige_hr_id = case when (v_rec.payload->'person') ? 'zustaendige_hr_id' then nullif(v_rec.payload->'person'->>'zustaendige_hr_id', '')::uuid else zustaendige_hr_id end,
+ erlernter_beruf = case when (v_rec.payload->'person') ? 'erlernter_beruf' then nullif(btrim(v_rec.payload->'person'->>'erlernter_beruf'), '') else erlernter_beruf end,$anker$;
+ 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.proname = 'apply_due_pending_changes' and p.prokind = 'f';
+
+ if v_def is null then
+ raise exception 'apply_due_pending_changes ist nicht vorhanden.';
+ end if;
+ if v_def like '%erlernter_beruf%' then
+ raise exception 'apply_due_pending_changes kennt den erlernten Beruf bereits.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt, ''))) / length(v_alt) <> 1 then
+ raise exception 'apply_due_pending_changes: der Anker kommt nicht genau einmal vor.';
+ end if;
+
+ execute replace(v_def, v_alt, v_neu);
+end
+$migration$;
+
+-- ═══ 6. app_feld_karte ════════════════════════════════════════════
+do $migration$
+declare
+ v_alt constant text := $anker$jsonb_build_array('zustaendige_hr_id', 'uuid', 'person')$anker$;
+ v_neu constant text := $anker$jsonb_build_array('zustaendige_hr_id', 'uuid', 'person'),
+ 'Erlernter Beruf', jsonb_build_array('erlernter_beruf', 'text', 'person')$anker$;
+ 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.proname = 'app_feld_karte' and p.prokind = 'f';
+
+ if v_def is null then
+ raise exception 'app_feld_karte ist nicht vorhanden.';
+ end if;
+ if v_def like '%erlernter_beruf%' then
+ raise exception 'app_feld_karte kennt den erlernten Beruf bereits.';
+ end if;
+ if (length(v_def) - length(replace(v_def, v_alt, ''))) / length(v_alt) <> 1 then
+ raise exception 'app_feld_karte: der Anker kommt nicht genau einmal vor.';
+ end if;
+
+ execute replace(v_def, v_alt, v_neu);
+end
+$migration$;
+
+-- ═══ 7. Selbstprüfung ═════════════════════════════════════════════
+do $$
+declare
+ v_def text;
+ v_karte jsonb;
+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.proname = 'hire_employee' and p.prokind = 'f';
+ if v_def not like '%zustaendige_hr_id, erlernter_beruf%' or v_def not like '%payload->>''erlernter_beruf''%'
+ or v_def not like '%bonusanspruch_art%' or v_def not like '%require_hr_admin()%' then
+ raise exception 'hire_employee schreibt den erlernten Beruf nicht oder hat Bonus/Rechtepruefung verloren.';
+ end if;
+
+ 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.proname = 'rehire_employee' and p.prokind = 'f';
+ if v_def not like '%payload ? ''erlernter_beruf''%' or v_def not like '%::employment_status%' then
+ raise exception 'rehire_employee schreibt den erlernten Beruf nicht oder hat die Status-Umwandlung verloren.';
+ end if;
+
+ 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.proname = 'change_employee_data' and p.prokind = 'f';
+ if v_def not like '%''Erlernter Beruf''%' or v_def not like '%''Zuständige HR''%' or v_def not like '%''Bonusregelung''%'
+ or v_def not like '%require_hr_admin()%' or v_def not like '%search_path%' then
+ raise exception 'change_employee_data protokolliert den erlernten Beruf nicht oder hat Bestehendes verloren.';
+ end if;
+
+ 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.proname = 'apply_due_pending_changes' and p.prokind = 'f';
+ if v_def not like '%''person''->>''erlernter_beruf''%' or v_def not like '%''person''->>''zustaendige_hr_id''%'
+ or v_def not like '%''contract''->>''has_bonusanspruch''%' or v_def not like '%target_position_id%' then
+ raise exception 'Der Nachtlauf wendet den erlernten Beruf nicht an oder hat Bestehendes verloren.';
+ end if;
+ if not exists (
+ select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace
+ where n.nspname = 'public' and p.proname = 'apply_due_pending_changes' and p.prosecdef
+ ) then
+ raise exception 'Der Nachtlauf ist nicht mehr SECURITY DEFINER.';
+ end if;
+
+ v_karte := app_feld_karte();
+ if not (v_karte ? 'Erlernter Beruf' and v_karte ? 'Zuständige HR' and v_karte ? 'Hay-Grade' and v_karte ? 'Geplante Rückkehr') then
+ raise exception 'Die Feldkarte ist unvollständig.';
+ end if;
+
+ raise notice 'Erlernter Beruf steht in Einstellung, Wiedereintritt, Daten aendern, Nachtlauf und Feldkarte.';
+end
+$$;
diff --git a/db/tests/vertragsangaben.sql b/db/tests/vertragsangaben.sql
index 2707a00..4cc5c7d 100644
--- a/db/tests/vertragsangaben.sql
+++ b/db/tests/vertragsangaben.sql
@@ -1,4 +1,4 @@
--- Rauchtest: VL, Bonusanspruch, zuständige HR und die neuen Kollektivverträge
+-- Rauchtest: VL, Bonusanspruch, zuständige HR, erlernter Beruf und die neuen Kollektivverträge
--
-- psql -f db/tests/vertragsangaben.sql
--
@@ -72,8 +72,11 @@ begin
'position_id', v_p1, 'entry_date', (current_date - 10)::text,
'worker_type', 'Arbeiter:in', 'collective_agreement', 'Süßware Arbeiter',
'vl', 3, 'has_bonusanspruch', true, 'bonusanspruch_art', 'Shop',
- 'zustaendige_hr_id', v_hr1));
+ 'zustaendige_hr_id', v_hr1, 'erlernter_beruf', ' Konditorin '));
select * into v_e from employees where id = v_a;
+ if v_e.erlernter_beruf is distinct from 'Konditorin' then
+ raise exception '1: Erlernter Beruf ist „%", erwartet getrimmt „Konditorin".', v_e.erlernter_beruf;
+ end if;
if v_e.vl <> 3 or not v_e.has_bonusanspruch or v_e.bonusanspruch_art <> 'Shop'
or v_e.zustaendige_hr_id <> v_hr1 or v_e.collective_agreement::text <> 'Süßware Arbeiter' then
raise exception '1: Einstellung hat VL/Bonus/HR/KV nicht geschrieben: % % % % %',
@@ -148,7 +151,7 @@ begin
-- ── 4. Daten ändern, sofort ────────────────────────────────────
perform change_employee_data(jsonb_build_object(
'employee_id', v_a, 'effective_date', current_date::text,
- 'person', jsonb_build_object('zustaendige_hr_id', v_hr2),
+ 'person', jsonb_build_object('zustaendige_hr_id', v_hr2, 'erlernter_beruf', ' '),
'contract', jsonb_build_object('vl', '5', 'has_bonusanspruch', false, 'bonusanspruch_art', ''),
'role', jsonb_build_object('collective_agreement', 'Handel')));
select * into v_e from employees where id = v_a;
@@ -170,6 +173,13 @@ begin
and changes @> jsonb_build_array(jsonb_build_object('feld', 'Zuständige HR', 'vorher', v_hr1::text, 'nachher', v_hr2::text))) then
raise exception '4: Die Historie nennt den Wechsel der zuständigen HR nicht.';
end if;
+ if v_e.erlernter_beruf is not null then
+ raise exception '4: Ein Leerzeichen als erlernter Beruf wurde nicht zu leer.';
+ end if;
+ if not exists (select 1 from employee_history where employee_id = v_a and event_type = 'Stammdatenänderung'
+ and changes @> '[{"feld":"Erlernter Beruf","vorher":"Konditorin","nachher":null}]') then
+ raise exception '4: Die Historie nennt das Leeren des erlernten Berufs nicht.';
+ end if;
raise notice '4/9 Daten ändern sofort: VL 3→5, Bonus Ja→Nein, HR gewechselt, KV Handel — alles in der Historie';
-- ── 5. Eintrag löschen und zurücksetzen ───────────────────────
@@ -252,10 +262,11 @@ begin
'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,
- 'collective_agreement', 'Süßware Angestellter'));
+ '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
- or v_e.zustaendige_hr_id <> v_hr1 or v_e.collective_agreement::text <> 'Süßware Angestellter' then
+ 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;
diff --git a/docs/datenkatalog.md b/docs/datenkatalog.md
index 37ebc75..b45860e 100644
--- a/docs/datenkatalog.md
+++ b/docs/datenkatalog.md
@@ -112,6 +112,7 @@ die kommt über die Planstelle.
| `vl` | smallint | ja | – | VL 1–8 (`chk_vl`); leer heisst nicht erfasst |
| `has_bonusanspruch` | bool | – | `false` | Bonusanspruch |
| `bonusanspruch_art` | text | ja | – | Bonusregelung: `RL ab 01.01.2027` / `RL bis 31.12.2026` / `Außendienst` / `Shop`; nur zusammen mit `has_bonusanspruch` (`chk_bonusanspruch_art`) |
+| `erlernter_beruf` | text | ja | – | Erlernter Beruf, freier Text; getrimmt, leer = null |
| `zustaendige_hr_id` | uuid | ja | – | Zuständige HR → `profiles`; nur aktive HR-Konten wählbar, `on delete set null` |
| `source` | `source_type` | – | `Extern` | Intern besetzt oder extern geholt |
| `work_days` | text[] | – | `{Mo,Di,Mi,Do,Fr}` | In Klickreihenfolge gespeichert, nicht sortiert |
diff --git a/lib/reports-data.ts b/lib/reports-data.ts
index 6c1dc2d..e9af375 100644
--- a/lib/reports-data.ts
+++ b/lib/reports-data.ts
@@ -201,8 +201,15 @@ const SNAPSHOT_EMPLOYEE_COLUMNS = [
"is_laterale_fuehrung",
"is_c_level",
"teilzeit_art",
+ "zustaendige_hr_id",
] as const;
+/** Name je HR-Konto — für die Gruppierung nach zuständiger HR. */
+export async function loadHrNamen(tx: Tx): Promise