[209] Kostenschätzung grob: Kennwert-Methode nach eBKP-H (Panel, Blatt-Tabelle, CSV/PDF)
- Modell: Project.costEstimate (CostEstimate/CostGroup/CostBasis/CostMethod) in generated.rs, KNOWN_KEYS, set_field; LayoutTableSource „costs“; npm run gen:types. - Kern kosten.rs: Menge × Kennwert je Zeile (Bezug Methode = m³ GV oder m² GF, wahlweise HNF, Fassade, Dach, pauschal) × Region × Index; Summe B–J, Honorare V auf B–J, Reserve Y auf B–J + V, MwSt Z, Bandbreite ±, Total je m³ GV / m² GF. Mengen aus der SIA-416-Flächentabelle (eine Quelle mit [225]); neu in flaechen.rs facade_area (Aussenumfang × Geschosshöhe bzw. Körper) und above_ground_outline_area (Dach ohne Dachelement). Abfragen costEstimate / costDefaults. Kaputte Eingaben (NaN, negative %) ohne Panic. - Vorgaben: BEISPIELWERTE ≈ 800 CHF/m³ GV bzw. 2'600 CHF/m² GF für B–J (Preisstand 2025, typische Verteilung der Hauptgruppen), Honorare 15 %, Reserve 10 % — keine offizielle Quelle, im Code dokumentiert und in Panel, Tabelle und Export als Beispielwert markiert. Belegt: MwSt 8.1 % (seit 1.1.2024), Genauigkeit nach SIA 102 (Vorprojekt ±15 %, Vorstudie ±25 %). - Blatt-Tabelle Quelle „costs“ (sheet_table.rs), Franken mit Tausender-Apostroph (Cell.g, area_report::fmt_num; CSV ohne Trenner). - TS: Fassade analysis/costEstimate.ts, Bericht export/costReport.ts (CSV/PDF über den Flächen-Nachweis), Panel CostEstimateSection im Flächenbilanz-Panel (Methode, Zuschläge, Faktoren, Preisstand, Kennwerte je Zeile, Zeile hinzufügen/entfernen, Beispielwerte). Methodenwechsel: Beispielwerte getauscht, eigene Werte über das Mengenverhältnis umgerechnet. i18n de+en. - e2e release10: Schritte 5b (Panel, Kennwert ändern, CSV/PDF, Methode GF) und 10b (Blatt-Tabelle) statt fixme; RELEASE-1.0.md Abschnitt 9 nachgeführt. Geprüft: cargo test dossier-core (1585 ok), tsc, vitest gesamt (3070 ok, Goldens unverändert), e2e/release10.spec.ts (Chromium, Port 5186). Nicht geprüft: Tauri-App/Mac, PDF nur über das SVG-Layout angesehen.
This commit is contained in:
28 files changed
+1595
-25
No files matched your search
@@ -36,6 +36,7 @@ bekommen.
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `areaReport.ts` | Flächen- und Kennzahlen-Nachweis (`[70]`); Aufbau, den die übrigen Berichte nutzen |
|
||||
| `costReport.ts` | Kostenschätzung grob als Bericht (CSV/PDF über `areaReport.ts`, [209]) |
|
||||
| `programReport.ts` | Soll/Ist-Vergleich des Raumprogramms (`[61]`) |
|
||||
| `elementSchedule.ts` | Bauteilliste mit U-Werten (`[71]`) |
|
||||
| `openingSchedule.ts` | Fenster- und Türliste (`[97]`) |
|
||||
|
||||
@@ -17,7 +17,7 @@ import { computeAreaTable, computeIvhb } from "../analysis/areaTable";
|
||||
import type { AreaRow, IvhbOptions } from "../analysis/areaTable";
|
||||
|
||||
/** Zelle: Text oder Zahl (`d` Nachkommastellen, `null` = nicht berechenbar). */
|
||||
export type Cell = string | { n: number | null; d: number };
|
||||
export type Cell = string | { n: number | null; d: number; g?: boolean };
|
||||
|
||||
export interface ReportRow {
|
||||
cells: Cell[];
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Layout, Project, Room, Wall } from "../model/types";
|
||||
import { computeAreaTable } from "../analysis/areaTable";
|
||||
import { computeCostEstimate, defaultCostEstimate, formatChf } from "../analysis/costEstimate";
|
||||
import { areaReportToCsv, layoutAreaReport, parseAreaReportCsv } from "./areaReport";
|
||||
import { buildCostReport } from "./costReport";
|
||||
import { sheetTables } from "./sheetTable";
|
||||
|
||||
// Haus wie im Flächen-Nachweis-Test: Achsen 10 × 8 m, Wände 0.3 m, GF 85.49 m², GV = GF × 2.6 m.
|
||||
function house(): Project {
|
||||
const base = structuredClone(sampleProject) as Project;
|
||||
const wt = base.wallTypes[0]!;
|
||||
const type = { ...wt, id: "w30", layers: [{ ...wt.layers[0]!, thickness: 0.3 }] };
|
||||
const pts = [[0, 0], [10, 0], [10, 8], [0, 8]] as const;
|
||||
const walls = pts.map((a, i): Wall => {
|
||||
const b = pts[(i + 1) % 4]!;
|
||||
return { ...(base.walls[0] as Wall), id: `hw${i}`, floorId: "eg", start: { x: a[0], y: a[1] }, end: { x: b[0], y: b[1] }, wallTypeId: "w30", height: 2.6, bottom: undefined, top: undefined };
|
||||
});
|
||||
const room: Room = { ...(base.rooms![0] as Room), id: "a", floorId: "eg", siaCategory: "HNF", name: "a", boundary: [{ x: 0.15, y: 0.15 }, { x: 9.85, y: 0.15 }, { x: 9.85, y: 7.85 }, { x: 0.15, y: 7.85 }] };
|
||||
return { ...base, name: "Haus", wallTypes: [type], walls, rooms: [room], openings: [], extrudedSolids: undefined, roofs: undefined, layouts: [] };
|
||||
}
|
||||
|
||||
describe("Kostenschätzung grob [209]", () => {
|
||||
it("Beispielwerte: Mengen aus der Flächentabelle, Summen und MwSt", () => {
|
||||
const p = house();
|
||||
const r = computeCostEstimate(p);
|
||||
const area = computeAreaTable(p);
|
||||
expect(r.isDefault).toBe(true);
|
||||
expect(r.hasExample).toBe(true);
|
||||
expect(r.method).toBe("gv");
|
||||
expect(r.quantities.gv).toBeCloseTo(area.gv, 9);
|
||||
expect(r.quantities.gf).toBeCloseTo(area.total.gf, 9);
|
||||
expect(r.rows.map((x) => x.code)).toEqual(["B", "C", "D", "E", "F", "G", "H", "I", "J"]);
|
||||
// 800 CHF/m³ GV für B–J (Beispiel), +15 % Honorare, +10 % Reserve, +8.1 % MwSt.
|
||||
expect(r.subtotal).toBeCloseTo(area.gv * 800, 6);
|
||||
expect(r.gross).toBeCloseTo(area.gv * 800 * 1.15 * 1.1 * 1.081, 4);
|
||||
expect(r.low).toBeCloseTo(r.gross * 0.85, 4);
|
||||
expect(r.perGv).toBeCloseTo(r.gross / area.gv, 6);
|
||||
});
|
||||
|
||||
it("Methode m² GF, eigene Kennwerte und Bezug Fassade", () => {
|
||||
const p = house();
|
||||
const est = defaultCostEstimate(p, "gf");
|
||||
est.groups = [{ code: "B–J", name: "Gebäude", basis: "method", rate: 3000 }, { code: "E", basis: "facade", rate: 200 }];
|
||||
est.feesPct = 0;
|
||||
est.reservePct = 0;
|
||||
const r = computeCostEstimate({ ...p, costEstimate: est });
|
||||
expect(r.hasExample).toBe(false);
|
||||
expect(r.rows[0]!.unit).toBe("m²");
|
||||
expect(r.rows[0]!.amount).toBeCloseTo(85.49 * 3000, 1); // i_overlay-Raster
|
||||
// Fassade: Aussenumfang 2 × (10.3 + 8.3) × 2.6 m.
|
||||
expect(r.rows[1]!.quantity).toBeCloseTo(37.2 * 2.6, 3);
|
||||
expect(r.net).toBeCloseTo(r.subtotal, 9);
|
||||
});
|
||||
|
||||
it("Bericht: CSV-Rundreise mit denselben Zahlen, PDF-Layout mit Apostroph", () => {
|
||||
const p = house();
|
||||
const r = computeCostEstimate(p);
|
||||
const report = buildCostReport(p, r);
|
||||
const csv = areaReportToCsv(report);
|
||||
expect(csv).toContain("Kostenschätzung grob");
|
||||
expect(csv).toContain("Konstruktion Gebäude");
|
||||
expect(csv).not.toMatch(/\d'\d{3}/); // CSV ohne Tausender-Trenner
|
||||
const back = parseAreaReportCsv(csv);
|
||||
const rows = back.sections[0]!.rows;
|
||||
const gross = rows.find((x) => x[1] === "Total inkl. MwSt.")!;
|
||||
expect(gross[5]).toBe(Math.round(r.gross));
|
||||
const texts = layoutAreaReport(report).pages.flat().flatMap((x) => (x.k === "text" ? [x.s] : []));
|
||||
expect(texts).toContain(formatChf(r.gross));
|
||||
expect(texts.some((s) => s.includes("Beispielwert"))).toBe(true);
|
||||
});
|
||||
|
||||
it("Blatt-Tabelle „costs“ folgt dem Modell", () => {
|
||||
const p = house();
|
||||
const layout: Layout = { id: "L", name: "Blatt", tables: [{ id: "k", source: "costs", xMm: 10, yMm: 10, widthMm: 180 }] } as unknown as Layout;
|
||||
const q = { ...p, layouts: [layout] };
|
||||
const out = sheetTables(q, "L");
|
||||
const texts = out[0]!.prims.flatMap((x) => (x.k === "text" ? [x.s] : []));
|
||||
expect(texts).toContain(formatChf(computeCostEstimate(q).gross));
|
||||
expect(texts.some((s) => s.startsWith("Total inkl. MwSt."))).toBe(true);
|
||||
expect(texts).toContain("Konstruktion Gebäude");
|
||||
});
|
||||
|
||||
it("formatChf: Schweizer Schreibweise", () => {
|
||||
expect(formatChf(1234567.5, 2)).toBe("1'234'567.50");
|
||||
expect(formatChf(-1000)).toBe("-1'000");
|
||||
expect(formatChf(999)).toBe("999");
|
||||
expect(formatChf(Number.NaN)).toBe("–");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
// Kostenschätzung grob ([209]) als Bericht: dasselbe Berichtsmodell wie der Flächen-Nachweis ([70]), daher
|
||||
// dieselben Ausgaben (CSV über `areaReportToCsv`, Vektor-PDF über `buildAreaReportPdf`). Gerechnet wird im
|
||||
// Kern (`analysis/costEstimate.ts` → `kosten.rs`); hier nur Aufbau und Beschriftung mit `t()`.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { t } from "../i18n/translate";
|
||||
import { computeCostEstimate, formatChf } from "../analysis/costEstimate";
|
||||
import type { CostResult, CostRow } from "../analysis/costEstimate";
|
||||
import type { AreaReport, Cell, ReportRow } from "./areaReport";
|
||||
|
||||
/** Franken (ganze, Tausender-Apostroph in PDF/Blatt; die CSV bleibt ohne Trenner). */
|
||||
const chf = (n: number | null | undefined): Cell => ({ n: n === undefined || n === null || !Number.isFinite(n) ? null : n, d: 0, g: true });
|
||||
const qty = (n: number, d = 1): Cell => ({ n: Number.isFinite(n) ? n : null, d, g: true });
|
||||
const pctText = (v: number) => `${Number.isInteger(v) ? v.toFixed(0) : v.toFixed(1)} %`;
|
||||
|
||||
/** Bezeichnung einer Kennwert-Zeile: eigener Name oder eBKP-H-Hauptgruppe. */
|
||||
export function costGroupLabel(code: string, name?: string | null): string {
|
||||
if (name && name.trim()) return name;
|
||||
const key = `costs.group.${code}`;
|
||||
const s = t(key);
|
||||
return s === key ? code : s;
|
||||
}
|
||||
|
||||
export function costUnitLabel(r: Pick<CostRow, "unit">): string {
|
||||
return r.unit || t("costs.lump");
|
||||
}
|
||||
|
||||
/** Bericht der Kostenschätzung (Tabelle, Mengen, Kennwerte/Bandbreite, Fussnoten). */
|
||||
export function buildCostReport(project: Project, result: CostResult = computeCostEstimate(project)): AreaReport {
|
||||
const r = result;
|
||||
const rows: ReportRow[] = r.rows.map((g) => ({
|
||||
cells: [g.code, costGroupLabel(g.code, g.name) + (g.example ? " *" : ""), qty(g.quantity, g.unit ? 1 : 0), costUnitLabel(g), chf(g.rate), chf(g.amount)],
|
||||
}));
|
||||
const sum = (label: string, n: number, total = false, code = ""): ReportRow => ({ total, cells: [code, label, "", "", "", chf(n)] });
|
||||
rows.push(sum(t("costs.row.subtotal"), r.subtotal, true));
|
||||
rows.push(sum(`${t("costs.row.fees")} ${pctText(r.feesPct)}`, r.fees, false, "V"));
|
||||
rows.push(sum(`${t("costs.row.reserve")} ${pctText(r.reservePct)}`, r.reserve, false, "Y"));
|
||||
rows.push(sum(t("costs.row.net"), r.net, true));
|
||||
rows.push(sum(`${t("costs.row.vat")} ${pctText(r.vatPct)}`, r.vat, false, "Z"));
|
||||
rows.push(sum(t("costs.row.gross"), r.gross, true));
|
||||
|
||||
const q = r.quantities;
|
||||
const notes: string[] = [];
|
||||
if (r.hasExample) notes.push(t("costs.foot.example"));
|
||||
notes.push(t("costs.foot.priceBase", { base: r.priceBase || "–", region: r.regionFactor.toFixed(2), index: r.indexFactor.toFixed(2) }));
|
||||
for (const k of r.notes) notes.push(t(`costs.note.${k}`, { pct: pctText(r.accuracyPct) }));
|
||||
notes.push(t("costs.foot.ebkp"));
|
||||
|
||||
return {
|
||||
title: t("costs.title"),
|
||||
projectName: project.name ?? "",
|
||||
sections: [
|
||||
{
|
||||
heading: `${t("costs.table")} · ${t(`costs.method.${r.method}`)}`,
|
||||
columns: [t("costs.col.code"), t("costs.col.group"), t("costs.col.quantity"), t("costs.col.unit"), t("costs.col.rate"), t("costs.col.amount")],
|
||||
widths: [1, 5, 1.8, 1, 1.6, 2.2],
|
||||
rows,
|
||||
},
|
||||
{
|
||||
heading: t("costs.range.title"),
|
||||
columns: [t("costs.col.value"), "CHF"],
|
||||
widths: [6, 2.2],
|
||||
rows: [
|
||||
{ cells: [t("costs.range.low", { pct: pctText(r.accuracyPct) }), chf(r.low)] },
|
||||
{ cells: [t("costs.range.high", { pct: pctText(r.accuracyPct) }), chf(r.high)] },
|
||||
{ cells: [t("costs.perGv"), chf(r.perGv)] },
|
||||
{ cells: [t("costs.perGf"), chf(r.perGf)] },
|
||||
],
|
||||
},
|
||||
{
|
||||
heading: t("costs.quantities"),
|
||||
columns: [t("costs.col.quantityName"), t("costs.col.quantity"), t("costs.col.unit")],
|
||||
widths: [6, 1.8, 1],
|
||||
rows: [
|
||||
{ cells: [t("costs.q.gv"), qty(q.gv), "m³"] },
|
||||
{ cells: [t("costs.q.gf"), qty(q.gf), "m²"] },
|
||||
{ cells: [t("costs.q.hnf"), qty(q.hnf), "m²"] },
|
||||
{ cells: [t("costs.q.facade"), qty(q.facade), "m²"] },
|
||||
{ cells: [t("costs.q.roof"), qty(q.roof), "m²"] },
|
||||
],
|
||||
},
|
||||
],
|
||||
notes,
|
||||
};
|
||||
}
|
||||
|
||||
export { formatChf };
|
||||
@@ -55,10 +55,10 @@ describe("Tabellen auf dem Blatt ([111])", () => {
|
||||
|
||||
it("alle Quellen liefern Primitive; Katalog nennt die Spalten", () => {
|
||||
const cat = tableCatalog(sampleProject);
|
||||
expect(Object.keys(cat.sources).sort()).toEqual(["areas", "earthworks", "elements", "openings", "roomBook", "rooms"]);
|
||||
const p = withTables((["openings", "areas", "rooms", "elements", "earthworks", "roomBook"] as const).map((source) => table({ id: source, source })));
|
||||
expect(Object.keys(cat.sources).sort()).toEqual(["areas", "costs", "earthworks", "elements", "openings", "roomBook", "rooms"]);
|
||||
const p = withTables((["openings", "areas", "rooms", "elements", "earthworks", "roomBook", "costs"] as const).map((source) => table({ id: source, source })));
|
||||
const out = sheetTables(p, "L1");
|
||||
expect(out.map((o) => o.id)).toEqual(["openings", "areas", "rooms", "elements", "earthworks", "roomBook"]);
|
||||
expect(out.map((o) => o.id)).toEqual(["openings", "areas", "rooms", "elements", "earthworks", "roomBook", "costs"]);
|
||||
for (const o of out) expect(o.prims.some((x) => x.k === "text")).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ interface Catalog {
|
||||
valueKeys: string[];
|
||||
}
|
||||
|
||||
export const TABLE_SOURCES: readonly LayoutTableSource[] = ["openings", "areas", "rooms", "elements", "earthworks", "roomBook"];
|
||||
export const TABLE_SOURCES: readonly LayoutTableSource[] = ["openings", "areas", "rooms", "elements", "earthworks", "roomBook", "costs"];
|
||||
|
||||
export function tableSourceLabel(s: LayoutTableSource): string {
|
||||
return t(`sheetTable.source.${s}`);
|
||||
|
||||
Reference in new issue
Block a user