Files
alpenwerk-hr/lib/absence.ts
Maximilian Stubhan e6554e7982 Move the part-time arrangements out of the absence list
Bildungsteilzeit, Elternteilzeit, Pflegeteilzeit and
Wiedereingliederungsteilzeit were offered as kinds of long-term absence.
Recorded that way, the person counted as absent: they dropped out of
headcount, their reporting line fell to a stand-in, and reports stopped
counting them — while they were in the building every week, just for
fewer hours. A part-time arrangement is not an absence; it is a change
of hours.

They now sit where they belong. Wiedereingliederungs- and Elternteilzeit
appear when recording a return from absence, as the reason someone comes
back on reduced hours — both typically begin exactly when the absence
ends. Bildungs- and Pflegeteilzeit appear under "Daten ändern" beside
the hours, next to the ordinary contractual change.

The reason is recorded with the change, not as a state on the person. A
state would have to be maintained, and nobody goes back to note when a
Bildungsteilzeit ended; a field that quietly goes stale is worse than
none. In the history it stands next to the value it explains, and stays
readable for good.

The check constraint on absence_type is deliberately untouched. Three
people carry the old values right now — two Pflegeteilzeit, one
Wiedereingliederungsteilzeit. Forbidding them would make existing rows
illegal. They are gone from the list of choices; the history stays
readable. Those three are worth revisiting, but that is a data decision,
not a code one.

Rehearsed against real data: an hours change with a reason and one
without, a reduced return with a reason and an unchanged one — checked
by reading both new history rows rather than "the latest", since now()
stands still inside a transaction and made an earlier probe report a
false negative.

I also overwrote tests/unit/absence.test.ts instead of extending it. The
original cases are restored; the diff is 49 added lines and 3 changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 12:56:21 +02:00

79 lines
2.9 KiB
TypeScript

import type { EmploymentStatus } from "./supabase/types";
// Langzeitabwesenheit.
//
// The database still stores the employment status as 'Karenz' — renaming an
// enum value would mean rewriting every stored function that spells it, for
// a label change (see supabase/migrations/*_absence_type.sql). So the value
// is mapped to its display name here, in the one place the UI reads it from.
// Nur echte Abwesenheiten. Eine Teilzeit ist keine: wer in Bildungs-,
// Pflege-, Eltern- oder Wiedereingliederungsteilzeit ist, arbeitet — nur
// weniger. Als „Langzeitabwesenheit" geführt, verschwand die Person aus dem
// Bestand, verlor ihre Berichtslinie an eine Vertretung und zählte in
// Auswertungen nicht mehr mit, obwohl sie jede Woche im Haus war.
//
// Die vier sind deshalb hierher gewandert, wo sie hingehören: zur
// Stundenänderung (siehe STUNDEN_GRUENDE) und zur Rückkehr aus einer
// Abwesenheit (RUECKKEHR_GRUENDE).
export const ABSENCE_TYPES = [
"Wochenhilfe (Mutterschutz)",
"Elternkarenz (inkl. Väterkarenz)",
"Papamonat",
"Bildungskarenz",
"Präsenzdienst",
"Zivildienst",
"Langer Krankenstand",
"Pflegekarenz",
"Familienhospizkarenz",
"Sabbatical",
] as const;
export type AbsenceType = (typeof ABSENCE_TYPES)[number];
export function isAbsenceType(value: string | null | undefined): value is AbsenceType {
return ABSENCE_TYPES.includes(value as AbsenceType);
}
/**
* Warum jemand nach einer Abwesenheit mit weniger Stunden zurückkommt.
*
* Beides sind Ansprüche, keine freien Vereinbarungen — und beide beginnen
* typischerweise genau dann, wenn die Abwesenheit endet.
*/
export const RUECKKEHR_GRUENDE = ["Wiedereingliederungsteilzeit", "Elternteilzeit"] as const;
/**
* Warum sich die Wochenstunden ändern.
*
* Der erste Wert ist der Normalfall; die beiden anderen sind gesetzlich
* geregelte Teilzeiten, die man später wiederfinden können muss — im
* Zweifel Jahre danach, wenn jemand fragt, warum die Stunden damals sanken.
*/
export const STUNDEN_GRUENDE = ["Vertragliche Stundenänderung", "Bildungsteilzeit", "Pflegeteilzeit"] as const;
export type StundenGrund = (typeof STUNDEN_GRUENDE)[number];
/** Display names for the stored status values. */
const STATUS_LABELS: Record<EmploymentStatus, string> = {
Aktiv: "Aktiv",
Karenz: "Langzeitabwesenheit",
Geplant: "Geplant",
Ausgetreten: "Ausgetreten",
};
export function statusLabel(status: EmploymentStatus): string {
return STATUS_LABELS[status] ?? status;
}
/**
* The chip and the detail header show the specific kind when it is known —
* "Bildungskarenz" says more than "Langzeitabwesenheit". Absences recorded
* before the type existed have none, and fall back to the generic name
* rather than to a guess.
*/
export function absenceLabel(status: EmploymentStatus, absenceType: string | null | undefined): string {
if (status !== "Karenz") return statusLabel(status);
return isAbsenceType(absenceType) ? absenceType : STATUS_LABELS.Karenz;
}