Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
93 lines
4.1 KiB
TypeScript
93 lines
4.1 KiB
TypeScript
// GAEB DA XML (3.x) lesen: Leistungsverzeichnis mit Titeln (BoQCtgy) und Positionen (Item), z. B. .x81, .x83,
|
|
// .x84, .x86. Aus den Titeln werden Ordner der Stammdaten, aus den Positionen Leistungen mit OZ, Kurztext,
|
|
// Langtext, Einheit und, wenn vorhanden, Einheitspreis. GAEB 90 und GAEB 2000 (.d8x/.p8x) sind keine XML-Dateien.
|
|
import { type XmlElement, absatzText, elemente, kind, leseXml, pfad, textVon } from "./xml.js";
|
|
import { einheitRichtig } from "./kalkulation.js";
|
|
|
|
export interface GaebPosition {
|
|
oz: string;
|
|
/** Titelpfad, z. B. „03 Konstruktionen / 03.01 Dachstuhl“ */
|
|
ordner: string;
|
|
kurztext: string;
|
|
langtext: string;
|
|
einheit: string;
|
|
menge: number | null;
|
|
/** Einheitspreis in Cent (nur Dateien mit Preisen, z. B. .x84/.x86) */
|
|
ep: number | null;
|
|
art: "normal" | "eventual" | "alternativ";
|
|
}
|
|
|
|
export interface GaebLv {
|
|
name: string;
|
|
/** Datenaustauschphase, z. B. 81, 83, 84 */
|
|
phase: string | null;
|
|
positionen: GaebPosition[];
|
|
titel: number;
|
|
}
|
|
|
|
/** Einheiten aus GAEB (m2, Stck, lfm …) wie im Programm */
|
|
export function gaebEinheit(qu: string): string {
|
|
const t = qu.trim();
|
|
const klein = t.toLowerCase().replace(/\.$/, "");
|
|
const tabelle: Record<string, string> = {
|
|
m2: "m²", qm: "m²", "m²": "m²", m3: "m³", cbm: "m³", "m³": "m³", m: "m", lfm: "m", lm: "m",
|
|
st: "St", stk: "St", stck: "St", stück: "St", "stk.": "St", psch: "psch", pauschal: "psch", pausch: "psch",
|
|
h: "h", std: "h", kg: "kg", t: "t",
|
|
};
|
|
return tabelle[klein] ?? einheitRichtig(t) ?? t;
|
|
}
|
|
|
|
const zahl = (t: string | undefined) => {
|
|
if (!t?.trim()) return null;
|
|
const n = Number(t.trim().replace(",", "."));
|
|
return Number.isFinite(n) ? n : null;
|
|
};
|
|
|
|
export function leseGaeb(text: string): GaebLv {
|
|
if (!/<\s*([\w-]+:)?GAEB[\s>]/.test(text.slice(0, 5000))) {
|
|
throw new Error("Das ist keine GAEB-XML-Datei. Bitte das Leistungsverzeichnis als GAEB DA XML exportieren (Endung .x81, .x83 oder .x84).");
|
|
}
|
|
const gaeb = leseXml(text);
|
|
const award = kind(gaeb, "Award");
|
|
const boq = kind(award, "BoQ");
|
|
if (!boq) throw new Error("In der GAEB-Datei steht kein Leistungsverzeichnis (BoQ).");
|
|
const name = textVon(pfad(boq, "BoQInfo", "Name")) || textVon(pfad(boq, "BoQInfo", "LblBoQ")) || textVon(pfad(gaeb, "PrjInfo", "LblPrj")) || textVon(pfad(gaeb, "PrjInfo", "NamePrj")) || "GAEB";
|
|
const phase = textVon(kind(award, "DP")) || null;
|
|
const positionen: GaebPosition[] = [];
|
|
let titel = 0;
|
|
|
|
const koerper = (body: XmlElement | undefined, oz: string[], ordner: string[]) => {
|
|
if (!body) return;
|
|
for (const c of elemente(body, "BoQCtgy")) {
|
|
titel++;
|
|
const nr = c.attr.RNoPart ?? "";
|
|
const bez = absatzText(kind(c, "LblTx")).split("\n")[0] || "Titel";
|
|
const ozNeu = [...oz, nr].filter(Boolean);
|
|
koerper(kind(c, "BoQBody"), ozNeu, [...ordner, [ozNeu.join("."), bez].filter(Boolean).join(" ")]);
|
|
}
|
|
for (const liste of elemente(body, "Itemlist")) {
|
|
for (const it of elemente(liste, "Item")) {
|
|
const ct = pfad(it, "Description", "CompleteText");
|
|
const kurz = absatzText(pfad(ct, "OutlineText", "OutlTxt", "TextOutlTxt")) || absatzText(pfad(ct, "OutlineText", "OutlTxt"));
|
|
const lang = absatzText(pfad(ct, "DetailTxt", "Text")) || absatzText(kind(ct, "DetailTxt"));
|
|
const provis = textVon(kind(it, "Provis"));
|
|
const ozPos = [...oz, it.attr.RNoPart ?? ""].filter(Boolean).join(".");
|
|
const up = zahl(textVon(kind(it, "UP")));
|
|
positionen.push({
|
|
oz: ozPos,
|
|
ordner: ordner.join(" / "),
|
|
kurztext: (kurz || lang.split("\n")[0] || `Position ${ozPos}`).replace(/\n/g, " ").slice(0, 300),
|
|
langtext: lang,
|
|
einheit: gaebEinheit(textVon(kind(it, "QU"))),
|
|
menge: zahl(textVon(kind(it, "Qty"))),
|
|
ep: up === null ? null : Math.round(up * 100),
|
|
art: provis ? "eventual" : kind(it, "ALNSerNo") && textVon(kind(it, "ALNSerNo")) !== "0" ? "alternativ" : "normal",
|
|
});
|
|
}
|
|
}
|
|
};
|
|
koerper(kind(boq, "BoQBody"), [], []);
|
|
if (!positionen.length) throw new Error("In der GAEB-Datei stehen keine Positionen.");
|
|
return { name, phase, positionen, titel };
|
|
}
|