A round of interface corrections from use, plus one schema change behind them. The private email address is now optional. It was NOT NULL — the wrong default for a private detail: someone without one had to invent one, and invented data in a personnel file is worse than missing data. Both fields are relabelled to say whose they are, "Private E-Mail" and "Private Telefonnummer", because the company address does not exist until the person starts. Uniqueness stays; several NULLs coexist in a Postgres unique index, which is exactly what is wanted. The summary step still promised that "Personalnummer und Firmen-E-Mail-Adresse werden automatisch vergeben". Neither is true any more. Removed rather than reworded — the step lists what was entered, and a banner claiming otherwise is worse than no banner. Dependents move into the wizard as step three, optional. They can only be attached after the hire, because add_employee_dependent needs an id that does not exist while the form is open, so they are collected in the draft and written afterwards. That puts them outside the transaction the person is created in: if one fails the person still exists, so the message names who is missing instead of failing silently, and the SV number is checked in the step rather than after. The emergency contact gets its own step, second to last, and its relationship is a dropdown of the common ones rather than free text — otherwise "Gattin", "Ehefrau" and "Frau" end up side by side and nothing can be counted. "Sonstige" is there because a closed list would otherwise be presumptuous. On the master-data tab it now sits below the dependents rather than above: both are people around the employee, and this is the one you reach for in a hurry. Returning from a long absence: the choice read "unverändert", which made you open the file to find out what you were agreeing to. It now reads "Wie vor Abwesenheit (38,5 h)" with the hours actually worked, and the alternative is "Reduziert" — whose hours field starts empty on purpose. A number already filled in gets confirmed rather than read off the agreement it comes from. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
191 lines
6.5 KiB
TypeScript
191 lines
6.5 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { currentUserId } from "@/lib/auth/session";
|
|
import { withUser } from "@/lib/db";
|
|
import { callFunction, runMutation, type ActionResult, type MutationFn } from "@/lib/db/rpc";
|
|
import type { CollectiveAgreement, DienstwagenArt, NoteCategory, RelationshipType, Weekday, WorkerType } from "@/lib/supabase/types";
|
|
|
|
async function callRpc(fn: MutationFn, payload: Record<string, unknown>, revalidate: string[]): Promise<ActionResult> {
|
|
const result = await runMutation(await currentUserId(), fn, payload);
|
|
if (!result.success) return result;
|
|
for (const path of revalidate) revalidatePath(path);
|
|
return result;
|
|
}
|
|
|
|
export async function hireEmployee(payload: {
|
|
/**
|
|
* Wird eingegeben, nicht vergeben.
|
|
*
|
|
* Sie muss mit Loga und Interflex übereinstimmen; eine hier selbst gezogene
|
|
* Nummer wäre dort unbekannt und die Person hätte in drei Systemen zwei
|
|
* Nummern. Die Datenbank weist eine bereits vergebene Nummer ab.
|
|
*/
|
|
personnel_number: number;
|
|
first_name: string;
|
|
last_name: string;
|
|
title_prefix?: string[];
|
|
title_suffix?: string[];
|
|
gender: "m" | "w";
|
|
birth_date: string;
|
|
sv_nummer?: string;
|
|
/**
|
|
* Die **private** Adresse, freiwillig.
|
|
*
|
|
* Sie war einmal Pflicht, weil die Spalte NOT NULL war — für eine private
|
|
* Angabe die falsche Vorgabe: wer keine hat, musste eine erfinden. Bleibt
|
|
* eindeutig, wenn angegeben.
|
|
*/
|
|
email?: string;
|
|
phone?: string;
|
|
position_id?: string;
|
|
team_id?: string;
|
|
job_title?: string;
|
|
location_id: string;
|
|
entry_date: string;
|
|
contract_type?: "unbefristet" | "befristet";
|
|
contract_end_date?: string;
|
|
employment_type?: "Vollzeit" | "Teilzeit";
|
|
weekly_hours?: number;
|
|
paygrade?: "A" | "B" | "C" | "D" | "E" | "F";
|
|
source: "Intern" | "Extern";
|
|
worker_type?: WorkerType;
|
|
collective_agreement?: CollectiveAgreement;
|
|
work_days?: Weekday[];
|
|
is_betriebsrat?: boolean;
|
|
has_dienstwagen?: boolean;
|
|
dienstwagen_art?: DienstwagenArt | null;
|
|
emergency_contact_name?: string;
|
|
emergency_contact_phone?: string;
|
|
emergency_contact_relation?: string;
|
|
is_laterale_fuehrung?: boolean;
|
|
is_c_level?: boolean;
|
|
}): Promise<ActionResult & { employeeId?: string }> {
|
|
// Einzige Mutation, deren Rückgabewert gebraucht wird: die neue
|
|
// Personen-Kennung, damit die Oberfläche direkt auf die Akte springen kann.
|
|
try {
|
|
const employeeId = await withUser(await currentUserId(), (tx) =>
|
|
callFunction(tx, "hire_employee", payload as Record<string, unknown>)
|
|
);
|
|
revalidatePath("/employees");
|
|
revalidatePath("/");
|
|
revalidatePath("/positions");
|
|
return { success: true, employeeId: employeeId as string };
|
|
} catch (err) {
|
|
return { success: false, error: err instanceof Error ? err.message : "Unbekannter Fehler." };
|
|
}
|
|
}
|
|
|
|
export async function terminateEmployee(payload: {
|
|
employee_id: string;
|
|
exit_date: string;
|
|
exit_reason: string;
|
|
note?: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("terminate_employee", payload, [`/employees/${payload.employee_id}`, "/employees", "/"]);
|
|
}
|
|
|
|
export async function transferEmployee(payload: {
|
|
employee_id: string;
|
|
effective_date: string;
|
|
/** Die Zielplanstelle; Bereich, Abteilung und Team ergeben sich aus ihrer Einheit. */
|
|
target_position_id: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("transfer_employee", payload, [`/employees/${payload.employee_id}`, "/employees"]);
|
|
}
|
|
|
|
export async function promoteEmployee(payload: {
|
|
employee_id: string;
|
|
effective_date: string;
|
|
new_title: string;
|
|
new_paygrade?: "A" | "B" | "C" | "D" | "E" | "F";
|
|
}): Promise<ActionResult> {
|
|
return callRpc("promote_employee", payload, [`/employees/${payload.employee_id}`, "/employees"]);
|
|
}
|
|
|
|
export async function startKarenz(payload: {
|
|
employee_id: string;
|
|
karenz_start_date: string;
|
|
planned_return_date: string;
|
|
absence_type: string;
|
|
note?: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("start_karenz", payload, [`/employees/${payload.employee_id}`, "/employees", "/"]);
|
|
}
|
|
|
|
export async function adjustKarenzReturn(payload: {
|
|
employee_id: string;
|
|
new_return_date: string;
|
|
note?: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("adjust_karenz_return", payload, [`/employees/${payload.employee_id}`]);
|
|
}
|
|
|
|
export async function recordKarenzReturn(payload: {
|
|
employee_id: string;
|
|
return_date: string;
|
|
employment_mode: "unverändert" | "Vollzeit" | "Teilzeit";
|
|
weekly_hours?: number;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("record_karenz_return", payload, [`/employees/${payload.employee_id}`, "/employees", "/"]);
|
|
}
|
|
|
|
export async function changeEmployeeData(payload: {
|
|
employee_id: string;
|
|
effective_date: string;
|
|
person: Record<string, unknown>;
|
|
contract: Record<string, unknown>;
|
|
role: Record<string, unknown>;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("change_employee_data", payload, [`/employees/${payload.employee_id}`, "/employees"]);
|
|
}
|
|
|
|
/**
|
|
* `position_id` ist Pflicht — die Datenbankfunktion verlangt sie seit jeher.
|
|
*
|
|
* Die alte Stelle taugt nicht als stille Vorgabe: sie kann inzwischen besetzt
|
|
* oder ausgelaufen sein. Sie fehlte hier nur in der Signatur, weshalb jede
|
|
* Wiedereinstellung an einer Meldung scheiterte, die im Dialog nicht zu
|
|
* beheben war.
|
|
*/
|
|
export async function rehireEmployee(payload: {
|
|
employee_id: string;
|
|
rehire_date: string;
|
|
position_id: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("rehire_employee", payload, [`/employees/${payload.employee_id}`, "/employees", "/"]);
|
|
}
|
|
|
|
export async function addEmployeeDependent(payload: {
|
|
employee_id: string;
|
|
first_name: string;
|
|
last_name: string;
|
|
relationship: RelationshipType;
|
|
sv_nummer?: string;
|
|
birth_date: string;
|
|
effective_date: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("add_employee_dependent", payload, [`/employees/${payload.employee_id}`]);
|
|
}
|
|
|
|
export async function deleteEmployeeDependent(payload: {
|
|
dependent_id: string;
|
|
employee_id: string;
|
|
effective_date: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("delete_employee_dependent", payload, [`/employees/${payload.employee_id}`]);
|
|
}
|
|
|
|
export async function addEmployeeNote(payload: {
|
|
employee_id: string;
|
|
category: NoteCategory;
|
|
note_text: string;
|
|
due_date?: string;
|
|
}): Promise<ActionResult> {
|
|
return callRpc("add_employee_note", payload, [`/employees/${payload.employee_id}`, "/"]);
|
|
}
|
|
|
|
export async function completeEmployeeNote(payload: { note_id: string; employee_id: string }): Promise<ActionResult> {
|
|
return callRpc("complete_employee_note", payload, [`/employees/${payload.employee_id}`, "/"]);
|
|
}
|