Files
Betriebsf-hrungssoftware/test/kalkulation.test.ts
Claude 8979795502
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled
Angebote mit Kalkulation: Leistungsverzeichnis, Kostenzeilen, Versandprüfung, Annehmen macht den Auftrag (0.16.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
2026-10-20 22:16:30 +00:00

93 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from "vitest";
import { berechneAngebot, berechnePosition, einheitRichtig, naechsteNummer, pruefeAngebot, rundeCent, verteile, type Saetze } from "../src/domain/kalkulation.js";
const OHNE_WG: Saetze = {
stundensaetze: { planer: 8000, geselle: 5831, helfer: 5000 },
zuschlaege: { lohn: 28, material: 30, geraet: 10, sonstiges: 0 },
wagnis: 0, gewinn: 0, ausfall: 0,
};
describe("Angebotskalkulation (A2, A19, A28, A32, A37)", () => {
it("Verkaufs-Stundensatz wie im Plancraft-Muster A-26-112: 58,31 € + 28 % = 74,64 €", () => {
const r = berechnePosition({ id: "p", kurztext: "Stundenlohn", menge: 6.5, einheit: "h" },
[{ position_id: "p", kostenart: "lohn", lohnart: "geselle", menge: 1 }], OHNE_WG);
expect(r.ep).toBe(7464);
expect(r.gb).toBe(48516);
expect(r.stunden).toBe(6.5);
});
it("Faktor je Kostenzeile und Wagnis/Gewinn zusätzlich zu den Zuschlägen", () => {
const s = { ...OHNE_WG, zuschlaege: { lohn: 20, material: 5, geraet: 10, sonstiges: 10 }, wagnis: 5, gewinn: 5, ausfall: 5 };
// je m: 0,035 h Geselle + 1 m KVH zu 4,20 € mit Faktor 1,10 (Verschnitt)
const r = berechnePosition({ id: "p", kurztext: "Abbund KVH", menge: 100, einheit: "m" }, [
{ position_id: "p", kostenart: "lohn", lohnart: "geselle", menge: 0.035 },
{ position_id: "p", kostenart: "material", menge: 1, ek: 420, faktor: 1.1 },
], s);
// Lohn 0,035 × 58,31 × 1,2 × 1,15 = 2,8164; Material 4,20 × 1,1 × 1,05 × 1,15 = 5,5787 → 8,40 €
expect(r.ep).toBe(840);
expect(r.gb).toBe(84000);
expect(r.stunden).toBe(3.5);
});
it("Netto zählt nur Normal und Eventual einkalkuliert; Kostenarten ergeben genau das Netto", () => {
const titel = [{ id: "t1", bezeichnung: "Dach" }];
const pos = [
{ id: "a", titel_id: "t1", kurztext: "Sparren", menge: 12.5, einheit: "m²" },
{ id: "b", titel_id: "t1", kurztext: "Anstrich", menge: 3, einheit: "m²", art: "eventual" as const },
{ id: "c", titel_id: "t1", kurztext: "Netz", menge: 1, einheit: "psch", art: "eventual_summe" as const, ep_fest: 15000 },
];
const kosten = [
{ position_id: "a", kostenart: "lohn" as const, lohnart: "geselle" as const, menge: 0.4 },
{ position_id: "a", kostenart: "material" as const, menge: 1.05, ek: 1890 },
{ position_id: "b", kostenart: "material" as const, menge: 1, ek: 500 },
];
const e = berechneAngebot({ ust_satz: 19 }, titel, pos, kosten, OHNE_WG);
const a = e.positionen.a!;
expect(e.positionen.b!.zaehlt).toBe(false);
expect(e.netto).toBe(a.gb + 15000);
expect(e.titel.t1).toBe(e.netto);
const summe = Object.values(e.kostenarten).reduce((s, k) => s + k.verkauf, 0);
expect(summe).toBe(e.netto);
expect(e.kostenarten.ohne.verkauf).toBe(15000);
expect(e.stunden).toBe(5);
expect(e.ust).toBe(Math.round(e.netto * 0.19));
for (const k of Object.values(e.kostenarten)) expect(k.zuschlag).toBe(k.verkauf - k.kosten);
});
it("rundet kaufmännisch ohne Gleitkommafehler und verteilt centgenau", () => {
expect(rundeCent(267.4999)).toBe(267);
expect(rundeCent(267.49999999)).toBe(268);
expect(rundeCent(2.675 * 100)).toBe(268);
expect(rundeCent(-0.5)).toBe(-1);
expect(verteile(100, [1, 1, 1])).toEqual([34, 33, 33]);
expect(verteile(0, [0, 0])).toEqual([0, 0]);
});
it("Einheiten nach DIN 18334 und Angebotsnummern", () => {
expect(einheitRichtig("Stk.")).toBe("St");
expect(einheitRichtig("m2")).toBe("m²");
expect(einheitRichtig("lfm")).toBe("m");
expect(einheitRichtig("Psch")).toBe("psch");
expect(einheitRichtig("Fass")).toBeUndefined();
expect(naechsteNummer(["A-26-120", "P-26-123", "A-25-300", "26-01"], 2026)).toBe("A-26-124");
expect(naechsteNummer([], 2027)).toBe("A-27-001");
});
it("Versandprüfung findet Platzhalter, fehlende Preise, Einheiten und Bindefrist (A14)", () => {
const pos = [
{ id: "a", kurztext: "Abschlag nach x-richten-x", menge: 1, einheit: "Stk." },
{ id: "b", kurztext: "Dämmung", menge: 0, einheit: "m²" },
];
const e = berechneAngebot({}, [], pos, [], OHNE_WG);
const p = pruefeAngebot({ datum: "2026-09-13", bindefrist: "2026-04-10", schlusstext: "Annahmen: ???", empfaenger: false }, [], pos, [], e);
const texte = p.map((x) => x.text).join("\n");
expect(texte).toContain("Bindefrist liegt vor dem Angebotsdatum");
expect(texte).toContain("Schlusstext steht noch ein Platzhalter");
expect(texte).toContain("Position Abschlag nach x-richten-x: Im Text steht noch ein Platzhalter");
expect(texte).toContain("„Stk.“ bitte als „St“");
expect(texte).toContain("Position Dämmung hat keine Menge");
expect(texte).toContain("kein Bauherr");
expect(pruefeAngebot({ datum: "2026-10-20" }, [], [], [], berechneAngebot({}, [], [], [], OHNE_WG))[0]!.text).toContain("keine Position");
});
});