Stundensätze im Personalmodul, Übergabe ans Angebot (0.26.0)
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled

Rechentabellen je Lohnart wie Hennings Excel (Zeit, Kosten, Vollkostensatz),
Mittellohn mit Schaltern, Versionen mit gilt ab. Excel-Fassung centgenau
(80,38 / 107,81 EUR), Fassung nach S2 mit Akquise/Verwaltung als Kosten.
Angebote schreiben die geltenden Sätze fest, Lohnzuschlag 0 %, Nachfrage
bei neuer Version.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
Claude
2026-10-22 06:55:22 +00:00
parent 0d5f11c842
commit 45c21943bf
24 changed files with 1305 additions and 42 deletions

View File

@@ -543,6 +543,9 @@ describe.skipIf(!url)("Anmeldung und Rollen (U1, U2)", () => {
expect((await als(b, "GET", "/api/projekte")).statusCode).toBe(200);
expect((await als(b, "GET", "/api/benutzer")).statusCode).toBe(403);
expect((await als(b, "GET", "/api/export")).statusCode).toBe(403);
// Stundensätze zeigen Löhne (U2): nur Inhaber; die Namen der Lohnarten braucht das Büro
expect((await als(b, "GET", "/api/stundensaetze")).statusCode).toBe(403);
expect((await als(b, "GET", "/api/lohnarten")).statusCode).toBe(200);
expect((await als(b, "PATCH", `/api/projekte/${p2.id}`, { notiz: "Büro war hier" })).statusCode).toBe(200);
const j = await anmelden("jan", "jan123456");
@@ -1282,3 +1285,74 @@ describe.skipIf(!url)("Angebote mit Kalkulation (Stufe 3a)", () => {
.toEqual([{ id: "x1", menge: 12.5, grund: "a" }, { id: "x2", menge: null, grund: "" }]);
});
});
describe.skipIf(!url)("Stundensätze im Personalmodul (M15–M19)", () => {
let pool: Pool;
let app: FastifyInstance;
beforeAll(async () => {
pool = erstellePool(url!);
await pool.query("drop schema public cascade; create schema public;");
await migriere(pool);
app = await baueApp({ pool, webOrdner: "/gibt-es-nicht", anmeldung: "testversion" });
});
afterAll(async () => {
await app?.close();
await pool?.end();
});
const neu = async (pfad: string, body: object = {}) => {
const r = await app.inject({ method: "POST", url: `/api/${pfad}`, payload: body });
expect(r.statusCode, r.body).toBe(201);
return r.json();
};
const hole = async (pfad: string) => (await app.inject(`/api/${pfad}`)).json();
it("Excel übernehmen, Personen zählen, ins Angebot festschreiben, neue Version nachfragen (A36, A37)", async () => {
const chef = await neu("kontakte", { name: "Henning", rolle: "mitarbeiter" });
const ges = await neu("kontakte", { name: "Rosty", rolle: "mitarbeiter" });
await neu("mitarbeiter", { kontakt_id: chef.id, angestellt: false });
await neu("mitarbeiter", { kontakt_id: ges.id, angestellt: true });
const p = await neu("projekte", { nummer: "A-26-140", bezeichnung: "Dach Probe", status: "anfrage" });
const alt = await neu("angebote/neu", { projekt_id: p.id });
expect(alt.saetze.stundensaetze).toEqual({ planer: 8000, geselle: 5831, helfer: 5000 });
const v2 = await neu("stundensaetze/excel");
expect((await app.inject({ method: "POST", url: "/api/stundensaetze/excel" })).statusCode).toBe(409);
const s = await hole("stundensaetze");
expect(s.versionen.map((v: { name: string }) => v.name)).toEqual(["Excel 26.05.2026", "Akquise und Verwaltung als Kosten"]);
expect(s.gilt).toBe(v2.id);
const jahr = Number(v2.gilt_ab.slice(0, 4));
expect(s.umfeld[jahr]).toMatchObject({ koepfe: 2, personen: { chef: 1, geselle: 1 } });
const a = await neu("angebote/neu", { projekt_id: p.id });
expect(a.saetze).toMatchObject({ stundensaetze: { mittellohn: 7238, chef: 7238, planer: 10101, geselle: 7238 }, zuschlaege: { lohn: 0 },
stundensatz_version: { id: v2.id } });
expect(a.saetze.lohnarten[0]).toEqual({ id: "mittellohn", name: "Mittellohn" });
const pos = await neu("angebot-positionen", { angebot_id: a.id, kurztext: "Abbund", menge: 10, einheit: "m" });
await neu("angebot-kosten", { position_id: pos.id, kostenart: "lohn", lohnart: "mittellohn", menge: 1 });
expect((await hole(`angebote/${a.id}/voll`)).ergebnis.positionen[pos.id].kosten_je_einheit).toBe(7238);
expect((await hole(`angebote/${a.id}/voll`)).neue_stundensaetze).toBeNull();
// das alte Angebot (Sätze aus den Einstellungen) fragt nach; Übernehmen setzt den Lohnzuschlag auf 0 %
expect((await hole(`angebote/${alt.id}/voll`)).neue_stundensaetze.stundensatz_version.id).toBe(v2.id);
const r = await app.inject({ method: "POST", url: `/api/angebote/${alt.id}/stundensaetze` });
expect(r.json()).toMatchObject({ stundensaetze: { mittellohn: 7238 }, zuschlaege: { lohn: 0 } });
// Gesellenlohn ändern: das Angebot behält seinen Satz, bis es übernimmt
const d = structuredClone(v2.daten);
d.tabellen.find((t: { id: string }) => t.id === "geselle").kosten[0].betrag = 250000;
expect((await app.inject({ method: "PATCH", url: `/api/stundensaetze/${v2.id}`, payload: { daten: d } })).statusCode).toBe(200);
const voll = await hole(`angebote/${a.id}/voll`);
expect(voll.saetze.stundensaetze.mittellohn).toBe(7238);
expect(voll.neue_stundensaetze.stundensaetze.mittellohn).toBeLessThan(7238);
// Lohnarten für die Rolle im Personal; eigene Lohnart als Rolle speicherbar
expect((await hole("lohnarten")).map((x: { id: string }) => x.id)).toEqual(["chef", "planer", "geselle", "helfer"]);
const m = (await hole("mitarbeiter")).find((x: { kontakt_id: string }) => x.kontakt_id === ges.id);
expect((await app.inject({ method: "PATCH", url: `/api/mitarbeiter/${m.id}`, payload: { funktion: "vorarbeiter" } })).statusCode).toBe(200);
// gleiches „gilt ab“ zweimal geht nicht
expect((await app.inject({ method: "POST", url: "/api/stundensaetze", payload: { name: "x", gilt_ab: v2.gilt_ab, daten: d } })).statusCode).toBe(409);
});
});

85
test/stundensatz.test.ts Normal file
View File

@@ -0,0 +1,85 @@
import { describe, expect, it } from "vitest";
import { rechneStundensaetze, saetzeFuerAngebot, schluesselFuer, zeitRechnen } from "../src/domain/stundensatz.js";
import { stundensaetzeAusExcel, stundensaetzeNachS2 } from "../src/domain/stundensatz-excel.js";
const umfeld = { koepfe: 2, personen: { chef: 1, geselle: 1 }, laufend: {} };
describe("Stundensätze wie Hennings Excel (Abnahme M19)", () => {
const e = rechneStundensaetze(stundensaetzeAusExcel(), umfeld);
const t = (id: string) => e.tabellen.find((x) => x.id === id)!;
it("Personalzeit: 2.000 Std Jahresarbeitszeit, 208 Tage anwesend, 1.184 produktive Std", () => {
const z = t("chef").zeit;
expect(z.jahresStd).toBe(2000);
expect(z.ausfallStd).toBe(336);
expect(z.anwesenheitTage).toBe(208);
expect(z.produktiv).toBe(1184);
expect(z.unproduktiv.map((u) => u.tage)).toEqual([11, 11, 26, 13]);
});
it("Chef: 95.174,51 € im Jahr = 80,38 €/Std", () => {
expect(t("chef").summe / 100).toBeCloseTo(95174.51237, 2);
expect(t("chef").satz).toBe(8038);
expect(t("chef").bloecke.map((b) => Math.round(b.bis) / 100)).toEqual([51548.57, 71137.03, 71787.03, 86981.44, 95174.51]);
});
it("Planer: 127.648,54 € im Jahr = 107,81 €/Std", () => {
expect(t("planer").summe / 100).toBeCloseTo(127648.544, 2);
expect(t("planer").satz).toBe(10781);
});
it("Mittellohn 60,63 € und Gemeinkostenanteil 19,75 € beim Chef", () => {
expect(t("chef").lohnkostensatz).toBe(6063);
expect(t("chef").gemeinkostenanteil).toBe(1975);
});
it("Umsatzbedarf 183.027,91 € (Chef-Blatt) und 131.596,44 € (Planer-Blatt)", () => {
expect(Math.round(t("chef").umsatzbedarf) / 100).toBe(183027.91);
expect(Math.round(t("planer").umsatzbedarf) / 100).toBe(131596.44);
});
it("Mittellohn gewichtet nach Stunden: Chef und Geselle gleich", () => {
expect(e.mittellohn.satz).toBe(8038);
expect(e.mittellohn.personen).toBe(2);
expect(saetzeFuerAngebot(e).stundensaetze).toMatchObject({ mittellohn: 8038, chef: 8038, planer: 10781, geselle: 8038 });
});
});
describe("Fassung nach S2: Akquise und Verwaltung als Kosten", () => {
const d = stundensaetzeNachS2(stundensaetzeAusExcel());
const e = rechneStundensaetze(d, umfeld);
const chef = e.tabellen.find((x) => x.id === "chef")!;
it("kein Zeitabzug mehr: 1.352 produktive Std", () => expect(chef.zeit.produktiv).toBe(1352));
it("14 Std/Monat × Lohnkostensatz des Gesellen, keine pauschalen 65 € mehr", () => {
const lks = Math.round(7178702.857142859 / 1352);
expect(e.bewertungssatz).toBe(lks);
const z = chef.zeilen.filter((x) => x.ausZeit);
expect(z.map((x) => x.jahr)).toEqual([84 * lks, 84 * lks]);
expect(chef.zeilen.some((x) => x.name === "Verwaltung" && !x.ausZeit)).toBe(false);
expect(chef.satz).toBe(Math.round((9517451.237156226 - 624000 + 168 * lks) / 1352));
});
it("Mittellohn gewichtet: Σ(Satz × Std × Personen) ÷ Σ(Std × Personen)", () => {
const x = structuredClone(d);
x.tabellen.find((t) => t.id === "geselle")!.kosten[0]!.betrag = 250000;
x.mittellohn.geselle = { an: true, personen: 2 };
const r = rechneStundensaetze(x, umfeld);
const c = r.tabellen.find((t) => t.id === "chef")!, g = r.tabellen.find((t) => t.id === "geselle")!;
expect(r.mittellohn.satz).toBe(Math.round((c.satz * c.zeit.produktiv + g.satz * g.zeit.produktiv * 2) / (c.zeit.produktiv + g.zeit.produktiv * 2)));
});
});
describe("Hilfen", () => {
it("Schlüssel aus dem Namen, eindeutig", () => {
expect(schluesselFuer("2. Vorarbeiter", [])).toBe("2-vorarbeiter");
expect(schluesselFuer("Geselle", ["geselle"])).toBe("geselle-2");
expect(schluesselFuer("Mittellohn", [])).toBe("lohnart");
});
it("Rüstzeit je Anwesenheitstag", () => {
const t = stundensaetzeAusExcel().tabellen[0]!;
t.zeit.ausfall[0]!.tage = 25;
expect(zeitRechnen(t).unproduktiv[2]!.std).toBe(213);
});
});