Erlernter Beruf und zustaendige HR im Report
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 11m57s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m15s

- Neues freiwilliges Textfeld "Erlernter Beruf": Hiring Wizard (Person,
  Zusammenfassung), Daten aendern, Stammdaten, Wiedereintritt, Export,
  Historie. Gespeichert getrimmt, leer heisst nicht erfasst.
- Reports: Aufteilen nach "Zustaendige HR" mit Gruppe "Nicht zugeordnet"
  und Vorlage "Headcount nach zustaendiger HR".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 11:21:11 +02:00
parent 0e9d2f2296
commit e77eaf7fba
18 changed files with 314 additions and 6 deletions

View File

@@ -89,6 +89,8 @@ export async function hireEmployee(payload: {
cornerstone_id?: string;
/** profiles.id einer aktiven HR-Person; hire_employee prüft das. */
zustaendige_hr_id?: string;
/** Freier Text, freiwillig. */
erlernter_beruf?: string;
phone?: string;
position_id?: string;
team_id?: string;

View File

@@ -46,6 +46,7 @@ function employeeExportColumns(
{ header: "Geburtsdatum", get: (e) => e.birth_date, kind: "date" },
{ header: "SV-Nummer", get: (e) => e.sv_nummer },
{ header: "Staatsbürgerschaft", get: (e) => e.nationality },
{ header: "Erlernter Beruf", get: (e) => e.erlernter_beruf },
{ header: "Aufenthaltstitel", get: (e) => e.hat_aufenthaltstitel },
{ header: "Aufenthaltstitel bis", get: (e) => e.aufenthaltstitel_bis, kind: "date" },
{ header: "Adresse", get: (e) => e.address },

View File

@@ -60,6 +60,7 @@ export function DatenAendernPanel({
const svNummerOk =
!svNummer.trim() || !requiresAustrianSvnr(locationCountry) || isValidSvnr(svNummer, birthDate || null);
const [nationality, setNationality] = useState(employee.nationality);
const [erlernterBeruf, setErlernterBeruf] = useState(employee.erlernter_beruf ?? "");
const [hatTitel, setHatTitel] = useState(employee.hat_aufenthaltstitel ?? false);
const [titelBis, setTitelBis] = useState(employee.aufenthaltstitel_bis ?? "");
// Die Staatsbürgerschaft entscheidet, ob die Frage überhaupt gestellt wird.
@@ -166,6 +167,7 @@ export function DatenAendernPanel({
birth_date: birthDate,
sv_nummer: svNummer,
nationality,
erlernter_beruf: erlernterBeruf.trim(),
// Wechselt die Staatsbürgerschaft in den Freizügigkeitsraum, fällt
// der Titel weg — sonst bliebe er als Rest an einer Person hängen,
// die ihn nicht mehr braucht. Die Datenbank prüft diese Kopplung
@@ -327,6 +329,7 @@ export function DatenAendernPanel({
)}
</>
)}
<TextField label="Erlernter Beruf" dense value={erlernterBeruf} onChange={setErlernterBeruf} />
<TextField label="Adresse (Straße und Hausnummer)" dense value={address} onChange={setAddress} />
<div className="grid grid-cols-[minmax(0,1fr)_minmax(0,2fr)] gap-3">
<TextField label="Postleitzahl" dense inputMode="numeric" value={postalCode} onChange={setPostalCode} />

View File

@@ -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 ?? "–"],

View File

@@ -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,

View File

@@ -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

View File

@@ -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}
/>
<TextField
label="Erlernter Beruf"
value={draft.erlernterBeruf}
onChange={(erlernterBeruf) => update({ erlernterBeruf })}
hint="Freiwillig. Der gelernte Beruf, nicht die Tätigkeit der Planstelle."
/>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
{/* Die private Adresse, nicht die Firmenadresse — die entsteht erst
mit dem Eintritt. Freiwillig: wer keine hat oder keine angeben

View File

@@ -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 || "–"],

View File

@@ -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: "",

View File

@@ -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
$$;

View File

@@ -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;

View File

@@ -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 |

View File

@@ -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<Map<string, string>> {
const rows = await tx.selectFrom("profiles").select(["id", "full_name", "email"]).where("role", "=", "hr").execute();
return new Map(rows.map((p) => [p.id, p.full_name?.trim() || p.email]));
}
// Anzahl der Angehörigen je Person. Nur der Fremdschlüssel wird gelesen —
// für die Berichtsdimensionen zählt die Anzahl, nicht wer es ist.
export async function loadDependentsCounts(tx: Tx): Promise<Map<string, number>> {
@@ -226,11 +233,12 @@ export async function loadSnapshotEmployees(tx: Tx, filters: SnapshotFilters): P
return applyCriteria(q, filters.criteria ?? LEERE_CRITERIA);
}
const [data, dependentsCounts, placements, orgMaps] = await Promise.all([
const [data, dependentsCounts, placements, orgMaps, hrNamen] = await Promise.all([
snapshotQuery().execute(),
loadDependentsCounts(tx),
loadPlacements(tx, { asOf }),
filters.division ? loadOrgMaps(tx) : Promise.resolve(null),
loadHrNamen(tx),
]);
// Der Bereichsfilter meint den ganzen Teilbaum: „Produktion" schliesst
@@ -274,6 +282,10 @@ export async function loadSnapshotEmployees(tx: Tx, filters: SnapshotFilters): P
is_c_level: e.is_c_level,
teilzeit_art: e.teilzeit_art,
dependents_count: dependentsCounts.get(e.id) ?? 0,
// Ein gelöschtes Konto setzt die Zuordnung auf null (on delete set
// null) — eine Kennung ohne Namen gibt es also nur in einer Lücke
// zwischen zwei Abfragen; dann lieber „Unbekannt" als die Kennung.
zustaendige_hr: e.zustaendige_hr_id ? (hrNamen.get(e.zustaendige_hr_id) ?? "Unbekannt") : null,
});
}

View File

@@ -24,6 +24,7 @@ export type GroupDimension =
| "paygrade"
| "worker_type"
| "collective_agreement"
| "zustaendige_hr"
| "betriebsrat"
| "dienstwagen"
| "laterale_fuehrung"
@@ -82,6 +83,7 @@ export const GROUP_LABELS: Record<GroupDimension, string> = {
paygrade: "Hay-Grade",
worker_type: "Beschäftigtengruppe",
collective_agreement: "Kollektivvertrag",
zustaendige_hr: "Zuständige HR",
betriebsrat: "Betriebsrat",
dienstwagen: "Dienstwagen",
laterale_fuehrung: "Laterale Führung",
@@ -136,6 +138,12 @@ export type ReportEmployee = {
is_c_level: boolean;
teilzeit_art: string | null;
dependents_count: number;
/**
* Der Name der zuständigen HR — beim Laden aufgelöst, weil der Bericht
* nach Namen gruppiert und nicht nach Kennungen. Null heisst nicht
* zugeordnet. Optional, damit Testbestände ohne die Angabe gültig bleiben.
*/
zustaendige_hr?: string | null;
};
// Alle drei sind über die *Einheit* der Planstelle geschlüsselt, nicht über
@@ -240,6 +248,10 @@ export function groupKeyFor(e: ReportEmployee, dim: GroupDimension, lookups: Org
return e.worker_type;
case "collective_agreement":
return e.collective_agreement;
case "zustaendige_hr":
// Eine eigene Gruppe statt „–": wer niemandem zugeordnet ist, ist genau
// die Antwort, nach der man hier sucht.
return e.zustaendige_hr ?? "Nicht zugeordnet";
case "betriebsrat":
return e.is_betriebsrat ? "Ja" : "Nein";
case "dienstwagen":
@@ -404,6 +416,7 @@ export const REPORT_PRESETS: { name: string; measure: Measure; group: GroupDimen
{ name: "Teilzeitquote nach Standort", measure: "parttime_rate", group: "location" },
{ name: "Headcount nach Wochentag", measure: "headcount", group: "weekday" },
{ name: "Headcount nach C-Level", measure: "headcount", group: "c_level" },
{ name: "Headcount nach zuständiger HR", measure: "headcount", group: "zustaendige_hr" },
{ name: "Ø Angehörige nach Bereich", measure: "avg_dependents", group: "division" },
];

View File

@@ -256,6 +256,8 @@ export type Database = {
cornerstone_id: string | null;
/** Zuständige Person in der Personalabteilung (profiles.id). Null heisst nicht zugeordnet. */
zustaendige_hr_id: string | null;
/** Erlernter Beruf, freier Text. Null heisst nicht erfasst. */
erlernter_beruf: string | null;
phone: string | null;
job_title: string;
location_id: string;
@@ -343,6 +345,7 @@ export type Database = {
company_email?: string | null;
cornerstone_id?: string | null;
zustaendige_hr_id?: string | null;
erlernter_beruf?: string | null;
phone?: string | null;
job_title: string;
location_id: string;

View File

@@ -62,6 +62,8 @@ export function vorbelegungAus(employee: EmployeeRow): Partial<HireDraftData> {
// Wie die Cornerstone-ID: der Assistent schickt das Feld immer mit, leer
// geliefert löschte es die Zuordnung stillschweigend.
zustaendigeHrId: employee.zustaendige_hr_id ?? "",
// Vorbelegt aus demselben Grund: der Assistent schickt das Feld immer mit.
erlernterBeruf: employee.erlernter_beruf ?? "",
phone: employee.phone ?? "",
locationId: employee.location_id,
besetzung: employee.source,

View File

@@ -62,6 +62,12 @@ describe("Abfolge der Schritte", () => {
]);
});
it("fragt im Schritt Person den erlernten Beruf, freiwillig", () => {
zeige(0);
const feld = screen.getByLabelText(/Erlernter Beruf/) as HTMLInputElement;
expect(feld.required).toBe(false);
});
it("zeigt an Schritt 3 den Vertrag", () => {
zeige(2);
expect(screen.getByLabelText(/Eintrittsdatum/)).toBeInTheDocument();

View File

@@ -8,6 +8,8 @@ import {
measureValue,
MEASURE_LABELS,
messgroesseLabel,
REPORT_PRESETS,
GROUP_LABELS,
type OrgLookups,
type ReportEmployee,
type ReportEvent,
@@ -98,6 +100,33 @@ describe("groupKeyFor", () => {
expect(groupKeyFor(emp({ entry_date: "2019-06-01" }), "entry_year", lookups)).toBe("2019");
});
it("gruppiert nach dem Namen der zuständigen HR", () => {
expect(groupKeyFor(emp({ zustaendige_hr: "Test HR Eins" }), "zustaendige_hr", lookups)).toBe("Test HR Eins");
});
it("fasst Personen ohne zuständige HR als eigene Gruppe zusammen", () => {
// Wer niemandem zugeordnet ist, ist genau die Antwort, nach der man hier sucht.
expect(groupKeyFor(emp({ zustaendige_hr: null }), "zustaendige_hr", lookups)).toBe("Nicht zugeordnet");
expect(groupKeyFor(emp(), "zustaendige_hr", lookups)).toBe("Nicht zugeordnet");
});
it("bietet die zuständige HR als Gruppierung und als Vorlage an", () => {
expect(GROUP_LABELS.zustaendige_hr).toBe("Zuständige HR");
expect(REPORT_PRESETS.some((p) => p.group === "zustaendige_hr")).toBe(true);
});
it("zählt je zuständiger HR", () => {
const rows = aggregateReport(
[emp({ id: "1", zustaendige_hr: "Anna" }), emp({ id: "2", zustaendige_hr: "Anna" }), emp({ id: "3", zustaendige_hr: null })],
"headcount",
"zustaendige_hr",
null,
lookups
);
const anzahl = Object.fromEntries(rows.map((r) => [r.key, r.value]));
expect(anzahl).toMatchObject({ Anna: 2, "Nicht zugeordnet": 1 });
});
it("resolves the Rolle & Anstellung boolean dimensions as Ja/Nein", () => {
const e = emp({ is_betriebsrat: true, has_dienstwagen: false, is_laterale_fuehrung: true, is_c_level: false });
expect(groupKeyFor(e, "betriebsrat", lookups)).toBe("Ja");