Standort Shop mit Unterauswahl; C-Level nur als Code; Sonstige im Import
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m26s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m22s
CI / Ausrollen (push) Successful in 7s

Standort: locations.parent_id, eine Ebene. Neu "Shop" mit sechs Shops
(Shop W17, Shop Wodo, Shop Parndorf, Shop Donaupark, Shop W1, Shop Wien
Hauptbahnhof). Personen sitzen nur auf Standorten ohne Unterstandorte;
zwei Trigger halten das auch fuer Import und Nachtlauf fest. Einstellung,
Externe und Versetzung zeigen bei "Shop" eine zweite Auswahl
(StandortAuswahl). Filter in Liste und Berichten und die Importliste
bieten "Shop" selbst nicht an; der Import nennt bei "Shop" die Shops.
rauchtest.sql und vertragsangaben.sql waehlen einen zuweisbaren Standort.

C-Level: ueberall nur der Code (Formular, Akte, Zusammenfassung,
Historie, Berichte, Import). Export ohne Spalte "C-Level Bezeichnung".

Angehoerige und Notfallkontakte im Import wie im Formular: Auswahl als
feste Liste und daneben "Verhaeltnis (Sonstige)" fuer den eigenen Text.
Gespeichert wird bei "Sonstige" der Text; ein Text ohne "Sonstige" ist
ein Fehler. Der Download teilt einen eigenen Text in beide Spalten.

Geprueft: lint, tsc, types:check, npm test, waechter; Migrationen auf
leerer Datenbank zweimal (Nichts anzuwenden), rauchtest.sql,
vertragsangaben.sql; als alpenwerk_app: Einstellung auf "Shop" abgewiesen,
auf "Shop W17" angenommen, Wechsel auf "Shop" abgewiesen, auf "Shop Wodo"
angenommen, Unterstandort unter einem Shop abgewiesen.
This commit is contained in:
2026-11-23 11:50:45 +01:00
parent e1ef57d44b
commit 79979216e4
37 changed files with 587 additions and 113 deletions

View File

@@ -5,6 +5,7 @@ import { fmtName } from "../format";
import { pruefePlz } from "../plz";
import { requiresAustrianSvnr, svnrErrorMessage, svnrHaeltAuf, validateSvnr } from "../svnr";
import type { Database } from "../types";
import { SONSTIGE, verhaeltnisAusDatei } from "../verhaeltnis";
import { pruefsumme } from "./abgleich";
import { BLAETTER, WIRKSAM_AB, type Blatt, type Spalte } from "./katalog";
import {
@@ -158,7 +159,7 @@ async function rufe(tx: Tx, fn: MutationFn, payload: Record<string, unknown>): P
/** Lookups, die sich mit jedem Blatt ändern können: was die Datei neu anlegt, gilt sofort. */
type Bestand = {
standorte: Map<string, { id: string; name: string; country: string }>;
standorte: Map<string, { id: string; name: string; country: string; parent_id: string | null }>;
kostenstellen: Map<string, { id: string; name: string }>;
einheiten: Map<string, Record<string, unknown> & { id: string }>;
planstellen: Map<string, Record<string, unknown> & { id: string }>;
@@ -168,7 +169,7 @@ type Bestand = {
async function bestandLaden(tx: Tx, heute: string): Promise<Bestand> {
const [standorte, kostenstellen, einheiten, planstellen, personen, hr] = await Promise.all([
tx.selectFrom("locations").select(["id", "name", "country"]).execute(),
tx.selectFrom("locations").select(["id", "name", "country", "parent_id"]).execute(),
tx.selectFrom("cost_centers").select(["id", "code", "name"]).execute(),
tx
.selectFrom("org_units as u")
@@ -649,6 +650,15 @@ function mitarbeiterZeile(
const planstelle = (n: unknown) => bestand.planstellen.get(String(n));
if (zeile.wert("location_id") && !standortId(zeile.wert("location_id"))) {
zeile.fehler(`Den Standort „${String(zeile.wert("location_id"))}“ gibt es nicht (auch nicht im Blatt „Standorte“).`, "location_id");
} else if (zeile.wert("location_id")) {
const id = standortId(zeile.wert("location_id"));
const unter = [...bestand.standorte.values()].filter((s) => s.parent_id === id).map((s) => s.name);
if (unter.length > 0) {
zeile.fehler(
`„${String(zeile.wert("location_id"))}“ fasst mehrere Standorte zusammen. Bitte einen davon angeben: ${unter.sort((a, b) => a.localeCompare(b, "de")).join(", ")}.`,
"location_id"
);
}
}
if (zeile.wert("zustaendige_hr_id") && !hrId(zeile.wert("zustaendige_hr_id"))) {
zeile.fehler(`„${String(zeile.wert("zustaendige_hr_id"))}“ ist kein aktives HR-Konto.`, "zustaendige_hr_id");
@@ -943,6 +953,34 @@ function eintragZu(zeile: Zeile, aktuell: Datensaetze, person: Person) {
return eintrag;
}
/**
* Das Verhältnis, wie es gespeichert wird: aus der Auswahl und dem Text zu
* „Sonstige" (lib/verhaeltnis.ts). Steht eine der beiden Spalten nicht in
* der Zeile, gilt der bisherige Wert — der Text aber nur, solange
* „Sonstige" gewählt bleibt. `undefined` bei einem Widerspruch.
*/
function verhaeltnisDerZeile(zeile: Zeile, feld: string, alt: Record<string, unknown> | null): string | null | undefined {
const textFeld = `${feld}_sonstige`;
const auswahl = (zeile.gesetzt(feld) ? zeile.wert(feld) : alt?.[feld]) as string | null | undefined;
const text = (zeile.gesetzt(textFeld) ? zeile.wert(textFeld) : auswahl === SONSTIGE ? alt?.[textFeld] : null) as
| string
| null
| undefined;
const ergebnis = verhaeltnisAusDatei(auswahl, text);
if ("fehler" in ergebnis) {
zeile.fehler(ergebnis.fehler, textFeld);
return undefined;
}
return ergebnis.wert;
}
/** Die geänderten Felder für die SQL-Funktion: Auswahl und Text als ein Verhältnis. */
function mitVerhaeltnis(g: Map<string, unknown>, feld: string, wert: string | null): Record<string, unknown> {
const out = Object.fromEntries(g);
delete out[`${feld}_sonstige`];
return { ...out, [feld]: wert };
}
function angehoerigerZeile(tx: Tx, zeile: Zeile, bestand: Bestand, aktuell: Datensaetze, { modus, heute }: { modus: Modus; heute: string }) {
const person = personZu(zeile, bestand);
if (!person) return;
@@ -953,9 +991,15 @@ function angehoerigerZeile(tx: Tx, zeile: Zeile, bestand: Bestand, aktuell: Date
if (eintrag === null) {
if (zeile.wert("entfernen") === "ja") return zeile.fehler("Ein neuer Eintrag lässt sich nicht entfernen.", "entfernen");
if (!pflichtNeu(zeile)) return;
const verhaeltnis = verhaeltnisDerZeile(zeile, "relationship", null);
if (verhaeltnis === undefined) return;
const g = zeile.geaendert(null);
zeile.schritt("Angehörige:r angelegt", "last_name", async () => {
await rufe(tx, "add_employee_dependent", { employee_id: person.id, effective_date: datum, ...Object.fromEntries(g) });
await rufe(tx, "add_employee_dependent", {
employee_id: person.id,
effective_date: datum,
...mitVerhaeltnis(g, "relationship", verhaeltnis),
});
});
return;
}
@@ -968,6 +1012,8 @@ function angehoerigerZeile(tx: Tx, zeile: Zeile, bestand: Bestand, aktuell: Date
});
return;
}
const verhaeltnis = verhaeltnisDerZeile(zeile, "relationship", eintrag.werte);
if (verhaeltnis === undefined) return;
const g = zeile.geaendert(eintrag.werte, (f) => f !== "id" && f !== "entfernen");
if (g.size === 0) return;
const neu = { ...eintrag.werte, ...Object.fromEntries(g) };
@@ -976,7 +1022,7 @@ function angehoerigerZeile(tx: Tx, zeile: Zeile, bestand: Bestand, aktuell: Date
dependent_id: id,
first_name: neu.first_name,
last_name: neu.last_name,
relationship: neu.relationship,
relationship: verhaeltnis,
birth_date: neu.birth_date ?? "",
sv_nummer: neu.sv_nummer ?? "",
});
@@ -993,9 +1039,11 @@ function notfallkontaktZeile(tx: Tx, zeile: Zeile, bestand: Bestand, aktuell: Da
if (eintrag === null) {
if (zeile.wert("entfernen") === "ja") return zeile.fehler("Ein neuer Eintrag lässt sich nicht entfernen.", "entfernen");
if (!pflichtNeu(zeile)) return;
const verhaeltnis = verhaeltnisDerZeile(zeile, "relation", null);
if (verhaeltnis === undefined) return;
const g = zeile.geaendert(null);
zeile.schritt("Notfallkontakt angelegt", "name", async () => {
await rufe(tx, "add_emergency_contact", { employee_id: person.id, ...Object.fromEntries(g) });
await rufe(tx, "add_emergency_contact", { employee_id: person.id, ...mitVerhaeltnis(g, "relation", verhaeltnis) });
});
return;
}
@@ -1008,10 +1056,12 @@ function notfallkontaktZeile(tx: Tx, zeile: Zeile, bestand: Bestand, aktuell: Da
});
return;
}
const verhaeltnis = verhaeltnisDerZeile(zeile, "relation", eintrag.werte);
if (verhaeltnis === undefined) return;
const g = zeile.geaendert(eintrag.werte, (f) => f !== "id" && f !== "entfernen");
if (g.size === 0) return;
const neu = { ...eintrag.werte, ...Object.fromEntries(g) };
zeile.schritt("Notfallkontakt geändert", [...g.keys()][0], async () => {
await rufe(tx, "update_emergency_contact", { id, name: neu.name, phone: neu.phone, relation: neu.relation ?? "" });
await rufe(tx, "update_emergency_contact", { id, name: neu.name, phone: neu.phone, relation: verhaeltnis ?? "" });
});
}

View File

@@ -274,7 +274,7 @@ const MITARBEITER_ROH: Spalte[] = [
}),
feld("Vertrag und Arbeitszeit", "Laterale Führung", "Laterale Führung", "is_laterale_fuehrung", JA_NEIN),
feld("Vertrag und Arbeitszeit", "C-Level", "C-Level", "c_level", auswahlAusKarte("C-Level"), {
hinweis: "Code oder Code mit Bezeichnung, etwa „C9“ oder „C9 – Mitarbeiter“.",
hinweis: "Der Code aus der Liste, etwa „C9“.",
}),
feld("Vertrag und Arbeitszeit", "Besonderer Kündigungsschutz", "Besonderer Kündigungsschutz", "has_kuendigungsschutz", JA_NEIN),
feld("Vertrag und Arbeitszeit", "Personenkreis", "Kündigungsschutz Personenkreis", "kuendigungsschutz_grund", auswahlAusKarte("Kündigungsschutz Personenkreis"), {
@@ -471,8 +471,22 @@ const PERSONALNUMMER_VERWEIS: Spalte = {
pflicht: true,
};
/** Verhältnis bei Angehörigen und Notfallkontakten: Liste oder eigener Text. */
const VERHAELTNIS: Format = { art: "auswahl", optionen: anzeigeAuswahl(EMERGENCY_RELATIONS), frei: true };
/**
* Verhältnis bei Angehörigen und Notfallkontakten: die Liste wie im Formular,
* und für „Sonstige" eine Spalte daneben mit dem eigenen Text
* (lib/verhaeltnis.ts).
*/
const VERHAELTNIS: Format = { art: "auswahl", optionen: anzeigeAuswahl(EMERGENCY_RELATIONS) };
const VERHAELTNIS_HINWEIS = "Aus der Liste. Ist es keines davon: „Sonstige“ und den Text in der Spalte daneben.";
function verhaeltnisSonstige(feld: string): Spalte {
return {
titel: "Verhältnis (Sonstige)",
feld,
format: TEXT,
hinweis: "Nur bei „Sonstige“, etwa Onkel oder Nachbarin. Leer bleibt es bei „Sonstige“.",
};
}
const ENTFERNEN: Spalte = {
titel: "Entfernen",
@@ -487,6 +501,7 @@ export const BLATT_ANGEHOERIGE: Blatt = {
zweck: "Angehörige je Person. Leere ID = neu anlegen.",
schluessel: PERSONALNUMMER_VERWEIS,
wirksamAb: "Leer = heute. Gilt für Neuanlage und Entfernen.",
bedingungen: [{ feld: "relationship_sonstige", art: "leer", wenn: { feld: "relationship", nicht: "Sonstige" } }],
spalten: [
{ titel: "ID", feld: "id", format: TEXT, hinweis: "Vergibt das System. Leer = neuer Eintrag." },
{ titel: "Nachname", feld: "last_name", format: TEXT, pflichtNeu: true, pflicht: true },
@@ -497,8 +512,9 @@ export const BLATT_ANGEHOERIGE: Blatt = {
format: VERHAELTNIS,
pflichtNeu: true,
pflicht: true,
hinweis: "Aus der Liste oder frei eingetragen, wie „Sonstige“ in der Personalakte.",
hinweis: VERHAELTNIS_HINWEIS,
},
verhaeltnisSonstige("relationship_sonstige"),
{ titel: "Geburtsdatum", feld: "birth_date", format: DATUM },
{ titel: "SV-Nummer", feld: "sv_nummer", format: TEXT },
ENTFERNEN,
@@ -510,6 +526,7 @@ export const BLATT_NOTFALLKONTAKTE: Blatt = {
zweck: "Notfallkontakte je Person. Leere ID = neu anlegen.",
schluessel: PERSONALNUMMER_VERWEIS,
wirksamAb: "Leer lassen: Notfallkontakte gelten sofort.",
bedingungen: [{ feld: "relation_sonstige", art: "leer", wenn: { feld: "relation", nicht: "Sonstige" } }],
spalten: [
{ titel: "ID", feld: "id", format: TEXT, hinweis: "Vergibt das System. Leer = neuer Eintrag." },
{ titel: "Name", feld: "name", format: TEXT, pflichtNeu: true, pflicht: true },
@@ -518,8 +535,9 @@ export const BLATT_NOTFALLKONTAKTE: Blatt = {
titel: "Verhältnis",
feld: "relation",
format: VERHAELTNIS,
hinweis: "Aus der Liste oder frei eingetragen, wie „Sonstige“ in der Personalakte.",
hinweis: VERHAELTNIS_HINWEIS,
},
verhaeltnisSonstige("relation_sonstige"),
ENTFERNEN,
],
};

View File

@@ -8,6 +8,7 @@ import { loadOrgMaps, type OrgMaps } from "../org";
import { loadPlacements, loadReportingLineMap, type Placement } from "../placement";
import { deriveStatusAsOf } from "../reports";
import type { Database } from "../types";
import { verhaeltnisFuerDatei } from "../verhaeltnis";
import type { Listen } from "./herunterladen";
import type { Datensatz } from "./herunterladen";
@@ -132,7 +133,14 @@ export async function ladeAngehoerige(tx: Tx, personen: readonly Person[]): Prom
.orderBy("employee_id")
.orderBy("created_at")
.execute();
return zeilen.map((z) => ({ schluessel: nummer.get(z.employee_id)!, kennung: z.id, werte: { ...z } }));
return zeilen.map((z) => {
const v = verhaeltnisFuerDatei(z.relationship);
return {
schluessel: nummer.get(z.employee_id)!,
kennung: z.id,
werte: { ...z, relationship: v.auswahl, relationship_sonstige: v.sonstige },
};
});
}
export async function ladeNotfallkontakte(tx: Tx, personen: readonly Person[]): Promise<Datensatz[]> {
@@ -145,7 +153,14 @@ export async function ladeNotfallkontakte(tx: Tx, personen: readonly Person[]):
.orderBy("employee_id")
.orderBy("created_at")
.execute();
return zeilen.map((z) => ({ schluessel: nummer.get(z.employee_id)!, kennung: z.id, werte: { ...z } }));
return zeilen.map((z) => {
const v = verhaeltnisFuerDatei(z.relation);
return {
schluessel: nummer.get(z.employee_id)!,
kennung: z.id,
werte: { ...z, relation: v.auswahl, relation_sonstige: v.sonstige },
};
});
}
export async function ladeHistorie(tx: Tx, personen: readonly Person[], b: Bezuege): Promise<Datensatz[]> {
@@ -242,7 +257,13 @@ export async function ladeStandorte(tx: Tx): Promise<Datensatz[]> {
*/
export async function ladeListen(tx: Tx, heute: string): Promise<Listen> {
const [standorte, jobs, einheiten, stellen, kostenstellen, hr] = await Promise.all([
tx.selectFrom("locations").select("name").orderBy("name").execute(),
// Ohne zusammenfassende Standorte wie „Shop": auf ihnen sitzt niemand.
tx
.selectFrom("locations as l")
.select("l.name")
.where((eb) => eb.not(eb.exists(eb.selectFrom("locations as u").select("u.id").whereRef("u.parent_id", "=", "l.id"))))
.orderBy("l.name")
.execute(),
tx.selectFrom("jobs").select("title").execute(),
tx.selectFrom("org_units").select("org_number").where("valid_to", "is", null).orderBy("org_number").execute(),
// Nur freie Planstellen: niemand sitzt heute oder später darauf, keine

View File

@@ -1,44 +1,21 @@
// C-Level: die Führungs- bzw. Funktionsstufe einer Person, als Code mit
// Bezeichnung. Fachlich vorgegebene Liste; dieselben Werte stehen in
// chk_c_level (Migration 20261123120000) — tests/unit/c-level.test.ts
// gleicht beide ab.
// C-Level: die Führungs- bzw. Funktionsstufe einer Person als Code.
// Fachlich vorgegebene Liste; dieselben Werte stehen in chk_c_level
// (Migration 20261123120000) — tests/unit/c-level.test.ts gleicht beide ab.
//
// Gespeichert wird der Code, angezeigt Code und Bezeichnung zusammen
// („C9 – Mitarbeiter"): der Code allein ist ausserhalb der
// Personalabteilung nicht lesbar, die Bezeichnung allein nicht eindeutig
// genug für die Systeme, die den Code weiterverarbeiten.
// Gespeichert und angezeigt wird nur der Code, in Formularen, Akte,
// Historie, Berichten, Export und Import gleich.
//
// Freiwillig: leer heisst „nicht erfasst".
export const C_LEVEL = [
{ code: "C1", bezeichnung: "Bereichsleitung" },
{ code: "C11", bezeichnung: "Mitarbeiter gfg." },
{ code: "C2", bezeichnung: "Abteilungsleitung" },
{ code: "C3", bezeichnung: "Experte" },
{ code: "C4", bezeichnung: "Teamleitung" },
{ code: "C8", bezeichnung: "Lehrling" },
{ code: "C9", bezeichnung: "Mitarbeiter" },
{ code: "MG", bezeichnung: "Manager" },
{ code: "P", bezeichnung: "Prokurist" },
{ code: "VD", bezeichnung: "Vorstand" },
] as const;
export const C_LEVEL_CODES = ["C1", "C11", "C2", "C3", "C4", "C8", "C9", "MG", "P", "VD"] as const;
export type CLevel = (typeof C_LEVEL)[number]["code"];
export const C_LEVEL_CODES: readonly CLevel[] = C_LEVEL.map((c) => c.code);
export type CLevel = (typeof C_LEVEL_CODES)[number];
/** Für Anzeigen ohne Wert. */
export const OHNE_C_LEVEL = "Ohne C-Level";
/** „C9 – Mitarbeiter"; ein unbekannter Code bleibt, wie er ist; leer bleibt leer. */
export function cLevelText(code: string | null | undefined): string {
if (!code) return "";
const eintrag = C_LEVEL.find((c) => c.code === code);
return eintrag ? `${eintrag.code} – ${eintrag.bezeichnung}` : code;
}
/** Auswahl für Formulare: Wert = Code, Beschriftung = Code und Bezeichnung. */
export const C_LEVEL_AUSWAHL: readonly { value: CLevel; label: string }[] = C_LEVEL.map((c) => ({
value: c.code,
label: cLevelText(c.code),
/** Auswahl für Formulare: Wert und Beschriftung sind der Code. */
export const C_LEVEL_AUSWAHL: readonly { value: CLevel; label: string }[] = C_LEVEL_CODES.map((c) => ({
value: c,
label: c,
}));

View File

@@ -1,6 +1,6 @@
import { ABSENCE_TYPES, KEINE_TEILZEITVARIANTE, STUNDEN_GRUENDE, statusLabel } from "./absence";
import { anzeige, anzeigeAuswahl } from "./anzeige";
import { C_LEVEL_AUSWAHL, cLevelText } from "./c-level";
import { C_LEVEL_AUSWAHL } from "./c-level";
import { GESCHLECHTER } from "./geschlecht";
import { HAY_GRADE_WERTE } from "./hay-grade";
import { KOLLEKTIVVERTRAEGE } from "./kollektivvertrag";
@@ -128,7 +128,6 @@ export const STATUS_FELD = "Status";
/** Ein gespeicherter Feldwert, wie Historie und Protokoll ihn zeigen. */
export function feldwertAnzeige(feld: string, text: string | null): string | null {
if (feld === STATUS_FELD && text) return statusLabel(text as EmploymentStatus);
if (feld === "C-Level" && text) return cLevelText(text);
return anzeige(text);
}

View File

@@ -3,7 +3,7 @@ import { AUSTRITTSART_LABELS, AUSTRITTSARTEN, BEENDIGUNGSART_WERTE } from "./bee
import { fmtDate } from "./format";
import { GESCHLECHTER } from "./geschlecht";
import { HAY_GRADE_WERTE } from "./hay-grade";
import { C_LEVEL_CODES, cLevelText } from "./c-level";
import { C_LEVEL_CODES } from "./c-level";
import { KUENDIGUNGSSCHUTZ_GRUENDE } from "./kuendigungsschutz";
import { MITARBEITERARTEN } from "./mitarbeiterart";
import { anzeige } from "./anzeige";
@@ -58,7 +58,7 @@ export const AUSWAHL_KRITERIEN: readonly AuswahlKriterium[] = [
{ key: "mitarbeiterart", label: "Anstellungs-/Beschäftigungsart", alle: "Alle Anstellungs-/Beschäftigungsarten", optionen: werte(...MITARBEITERARTEN) },
{ key: "kv", label: "Kollektivvertrag", alle: "Alle Kollektivverträge", optionen: werte(...KOLLEKTIVVERTRAEGE) },
{ key: "paygrade", label: "Hay-Grade", alle: "Alle Hay-Grades", optionen: werte(...HAY_GRADE_WERTE) },
{ key: "clevel", label: "C-Level", alle: "Alle C-Level", optionen: C_LEVEL_CODES.map((c) => ({ wert: c, label: cLevelText(c) })) },
{ key: "clevel", label: "C-Level", alle: "Alle C-Level", optionen: C_LEVEL_CODES.map((c) => ({ wert: c, label: c })) },
{ key: "source", label: "Intern/Extern", alle: "Intern und Extern", optionen: werte("Intern", "Extern") },
{
key: "gender",

View File

@@ -5,6 +5,7 @@ import { ancestorsOf, loadOrgMaps, subtreeOf, type OrgMaps } from "./org";
import { istBereich } from "./org-art";
import { loadKontierungen } from "./cost-centers";
import { loadPlacements } from "./placement";
import { zuweisbareStandorte } from "./standorte";
import type { Austrittsart } from "./types";
import { LEERE_CRITERIA, passtImSpeicher, type Criteria } from "./report-criteria";
import { werteListe } from "./werteliste";
@@ -181,10 +182,10 @@ export async function loadOrgLookups(tx: Tx): Promise<{
locations: { id: string; name: string }[];
}> {
const orgMaps = await loadOrgMaps(tx);
const locations = orgMaps.locationList.map((l) => ({ id: l.id, name: l.name }));
const alleStandorte = orgMaps.locationList.map((l) => ({ id: l.id, name: l.name }));
return {
lookups: lookupsFromOrgMaps(orgMaps, locations),
lookups: lookupsFromOrgMaps(orgMaps, alleStandorte),
orgMaps,
// Jede Ebene, nicht nur die Bereiche: wer eine einzelne Abteilung
// auswerten will, soll sie nicht über einen Umweg zusammensuchen müssen.
@@ -195,7 +196,9 @@ export async function loadOrgLookups(tx: Tx): Promise<{
depth: orgMaps.depthOf.get(u.id) ?? 0,
unitType: u.unit_type,
})),
locations,
// Zur Auswahl nur Standorte, auf denen jemand sitzen kann; „Shop" selbst
// ergäbe immer eine leere Auswertung.
locations: zuweisbareStandorte(orgMaps.locationList).map((l) => ({ id: l.id, name: l.name })),
};
}

View File

@@ -2,7 +2,7 @@ import { ABSENCE_TYPES, statusLabel } from "./absence";
import { BEENDIGUNGSART_WERTE } from "./beendigung";
import { fmtName, todayIso, yearsBetweenIso } from "./format";
import { HAY_GRADE_WERTE, OHNE_HAY_GRADE } from "./hay-grade";
import { C_LEVEL_CODES, cLevelText, OHNE_C_LEVEL } from "./c-level";
import { C_LEVEL_CODES, OHNE_C_LEVEL } from "./c-level";
import { anzeige } from "./anzeige";
import { WOCHENTAGE } from "./wochentage";
import { werteListe } from "./werteliste";
@@ -267,7 +267,7 @@ export function groupKeyFor(e: ReportEmployee, dim: GroupDimension, lookups: Org
return e.is_laterale_fuehrung ? "Ja" : "Nein";
case "c_level":
// Eine eigene Gruppe statt „–": wer keine Stufe hat, ist hier eine Antwort.
return e.c_level ? cLevelText(e.c_level) : OHNE_C_LEVEL;
return e.c_level || OHNE_C_LEVEL;
case "has_dependents":
return e.dependents_count > 0 ? "Ja" : "Nein";
case "teilzeit_art":
@@ -304,7 +304,7 @@ export function groupKeyFor(e: ReportEmployee, dim: GroupDimension, lookups: Org
const EIGENE_REIHENFOLGE: Partial<Record<GroupDimension, readonly string[]>> = {
weekday: WOCHENTAGE,
paygrade: [OHNE_HAY_GRADE, ...HAY_GRADE_WERTE],
c_level: [...C_LEVEL_CODES.map(cLevelText), OHNE_C_LEVEL],
c_level: [...C_LEVEL_CODES, OHNE_C_LEVEL],
};
function rang(dim: GroupDimension, key: string): number {

34
lib/standorte.ts Normal file
View File

@@ -0,0 +1,34 @@
// Standorte mit Unterstandorten (Migration 20261123140000): „Shop" fasst die
// einzelnen Shops zusammen. Eine Person sitzt nur auf einem Standort ohne
// Unterstandorte; die Auswahl zeigt zuerst die oberste Ebene und bei einem
// zusammenfassenden Standort eine zweite Liste.
export type StandortEintrag = { id: string; name: string; parent_id?: string | null };
/** Standorte der obersten Ebene, wie die erste Auswahl sie zeigt. */
export function oberstandorte<T extends StandortEintrag>(alle: readonly T[]): T[] {
return alle.filter((s) => !s.parent_id);
}
/** Die Unterstandorte eines Standorts, leer bei einem gewöhnlichen. */
export function unterstandorte<T extends StandortEintrag>(alle: readonly T[], id: string): T[] {
return id ? alle.filter((s) => s.parent_id === id) : [];
}
/** Standorte, auf denen eine Person sitzen kann — für Filter und Importlisten. */
export function zuweisbareStandorte<T extends StandortEintrag>(alle: readonly T[]): T[] {
const gruppen = new Set(alle.map((s) => s.parent_id).filter(Boolean));
return alle.filter((s) => !gruppen.has(s.id));
}
/** Welcher Eintrag der ersten Auswahl zu einem gespeicherten Standort gehört. */
export function oberstandortVon(alle: readonly StandortEintrag[], id: string): string {
const s = alle.find((x) => x.id === id);
return s ? (s.parent_id ?? s.id) : "";
}
/** „Shop W17" unter „Shop" zeigt die zweite Auswahl als „W17". */
export function kurzname(unter: StandortEintrag, ober: StandortEintrag | undefined): string {
const praefix = ober ? `${ober.name} ` : "";
return praefix && unter.name.startsWith(praefix) ? unter.name.slice(praefix.length) : unter.name;
}

View File

@@ -197,9 +197,9 @@ export type Database = {
public: {
Tables: {
locations: {
Row: { id: string; name: string; country: string };
Insert: { id?: string; name: string; country: string };
Update: Partial<{ id: string; name: string; country: string }>;
Row: { id: string; name: string; country: string; parent_id: string | null };
Insert: { id?: string; name: string; country: string; parent_id?: string | null };
Update: Partial<{ id: string; name: string; country: string; parent_id: string | null }>;
};
profiles: {
Row: {

41
lib/verhaeltnis.ts Normal file
View File

@@ -0,0 +1,41 @@
import { EMERGENCY_RELATIONS } from "./types";
// Das Verhältnis bei Angehörigen und Notfallkontakten: ein Wert aus der Liste,
// und unter „Sonstige" ein frei eingetragener Text. Gespeichert wird dann der
// Text selbst („Onkel"); steht nichts darin, bleibt „Sonstige" gespeichert
// (components/employees/VerhaeltnisField.tsx).
//
// Die Austauschdatei führt beides wie das Formular in zwei Spalten: die
// Auswahl und daneben den Text zu „Sonstige". So bleibt die Auswahl in Excel
// eine feste Liste, und ein eigener Text hat trotzdem seinen Platz.
export const SONSTIGE = "Sonstige";
/** Ob ein gespeicherter Wert frei eingetragen wurde. */
export function istFreiesVerhaeltnis(wert: string): boolean {
return wert.trim() !== "" && !(EMERGENCY_RELATIONS as readonly string[]).includes(wert);
}
/** Der gespeicherte Wert, aufgeteilt in Auswahl und Text zu „Sonstige". */
export function verhaeltnisFuerDatei(gespeichert: string | null | undefined): { auswahl: string | null; sonstige: string | null } {
const wert = gespeichert ?? "";
if (istFreiesVerhaeltnis(wert)) return { auswahl: SONSTIGE, sonstige: wert };
return { auswahl: wert || null, sonstige: null };
}
/**
* Auswahl und Text aus der Datei zum Wert, der gespeichert wird. Ein Text
* ohne „Sonstige" ist ein Widerspruch; welche der beiden Angaben gilt, lässt
* sich nicht entscheiden.
*/
export function verhaeltnisAusDatei(
auswahl: string | null | undefined,
sonstige: string | null | undefined
): { wert: string | null } | { fehler: string } {
const text = sonstige?.trim() ?? "";
if (text && auswahl !== SONSTIGE) {
return { fehler: `Ein Text zu „Sonstige“ steht nur bei der Auswahl „Sonstige“.` };
}
if (auswahl === SONSTIGE && text) return { wert: text };
return { wert: auswahl ?? null };
}