Files
Betriebsf-hrungssoftware/src/domain/bezug.ts
Claude 4e07e0b89e
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled
Zahlungen, Kosten und Aufgaben im Terminplan, Aufgaben-Vorlage, Schlussrechnung als Rest, Zahlungsplan verschieben (0.14.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
2026-10-20 11:20:13 +00:00

55 lines
2.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.
// Zahlungen, Kosten und Aufgaben im Terminplan (Henning, 20.10.2026): jede kann an einem Vorgang hängen,
// am Anfang (AA) oder am Ende (EE), mit Versatz in Arbeitstagen, z. B. „4EE+3“ = 3 Arbeitstage nach dem
// Ende von Zeile 4, „3AA−5“ = 5 Arbeitstage vor ihrem Anfang. Verschiebt sich der Vorgang, wandert sie mit.
import { type Datum } from "./datum.js";
import { type Arbeitswoche, arbeitstageZwischen, naechsterArbeitstag, verschiebeArbeitstage } from "./kalender.js";
import { type PlanVorgang, anfang, ende } from "./terminplan.js";
export type BezugArt = "AA" | "EE";
export interface Bezug {
vorgang_id: string | null;
bezug_art: BezugArt;
/** Arbeitstage, negativ = davor */
bezug_tage: number;
}
/** Datum, das sich aus dem Vorgang ergibt */
export function bezugsTermin(v: PlanVorgang, art: BezugArt, tage: number, woche: Arbeitswoche): Datum {
const d = art === "AA" ? anfang(v, woche) : ende(v, woche);
return tage === 0 ? naechsterArbeitstag(d, woche) : verschiebeArbeitstage(d, tage, woche);
}
/** Versatz in Arbeitstagen, damit das Datum `ziel` herauskommt (z. B. nach dem Ziehen der Raute) */
export function bezugsTage(v: PlanVorgang, art: BezugArt, ziel: Datum, woche: Arbeitswoche): number {
const d = art === "AA" ? anfang(v, woche) : ende(v, woche);
const z = naechsterArbeitstag(ziel, woche);
return z >= d ? arbeitstageZwischen(d, z, woche) - 1 : -(arbeitstageZwischen(z, d, woche) - 1);
}
/**
* „4“, „4EE+3“, „4 AA -5“, „4AA−5t“ lesen. EA zählt wie EE, AE wie AA (bei einem Termin ohne Dauer dasselbe).
* Leer heißt: nicht verknüpft. `nummern` ordnet Zeilennummern den Vorgängen zu.
*/
export function leseBezug(text: string, nummern: Map<number, string>): Bezug {
const t = text.trim().replace(/[−–]/g, "-");
if (!t) return { vorgang_id: null, bezug_art: "EE", bezug_tage: 0 };
const m = /^(\d+)\s*(EA|AA|EE|AE)?\s*(?:([+-])\s*(\d+))?\s*(?:t|tage?|at)?\.?$/i.exec(t);
if (!m) throw new Error(`„${text}“ verstehe ich nicht. Beispiele: 4, 4EE+3, 4AA-5`);
const id = nummern.get(Number(m[1]));
if (!id) throw new Error(`Zeile ${m[1]} ist kein Vorgang.`);
const art: BezugArt = (m[2] ?? "EE").toUpperCase().startsWith("A") ? "AA" : "EE";
return { vorgang_id: id, bezug_art: art, bezug_tage: m[3] ? (m[3] === "-" ? -1 : 1) * Number(m[4]) : 0 };
}
/** Anzeige wie in der Spalte Vorgänger: „4“, „4EE+3“, „4AA−5“ */
export function bezugText(b: Partial<Bezug>, nummer: Map<string, number>): string {
if (!b.vorgang_id) return "";
const nr = nummer.get(b.vorgang_id);
if (nr === undefined) return "";
const tage = Number(b.bezug_tage ?? 0);
if (b.bezug_art !== "AA" && tage === 0) return String(nr);
return `${nr}${b.bezug_art === "AA" ? "AA" : "EE"}${tage ? `${tage > 0 ? "+" : "−"}${Math.abs(tage)}` : ""}`;
}