Standort Shop mit Unterauswahl; C-Level nur als Code; Sonstige im Import
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:
@@ -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 ?? "" });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user