Files
Betriebsf-hrungssoftware/src/server/kalender.ts
Claude f3dd3678f6
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled
0.36.0: Status Intern mit I-Nummern und Ordner 05 Intern, Eckdaten unten und einklappbar
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
2026-10-24 05:49:21 +00:00

71 lines
3.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.
// Kalender-Abos für Outlook classic (T11): Baustellen (Vorgänge) und fällige Aufgaben.
// Die Links enthalten ein Geheimnis statt einer Anmeldung, weil Outlook classic sich bei
// Internetkalendern nicht anmelden kann.
import { type Datum, plusTage } from "../domain/datum.js";
import { type Arbeitswoche, istArbeitstag, wocheVon } from "../domain/kalender.js";
import { type Termin, kalender } from "../domain/ical.js";
import type { Pool } from "./db.js";
import { terminplan } from "./terminplan.js";
const IM_KALENDER = new Set(["auftrag", "ausfuehrung", "intern"]);
/** Vorgang in Abschnitte aus zusammenhängenden Arbeitstagen teilen, damit Freitag und Wochenende frei bleiben. */
export function arbeitsbloecke(von: Datum, bis: Datum, woche: Arbeitswoche): [Datum, Datum][] {
const bloecke: [Datum, Datum][] = [];
let start: Datum | undefined;
let letzter: Datum | undefined;
for (let d = von; d <= bis; d = plusTage(d, 1)) {
if (istArbeitstag(d, woche)) {
start ??= d;
letzter = d;
} else if (start) {
bloecke.push([start, letzter!]);
start = undefined;
}
}
if (start) bloecke.push([start, letzter!]);
return bloecke.length ? bloecke : [[von, bis]];
}
export async function baustellenKalender(pool: Pool, woche: Arbeitswoche): Promise<string> {
const tp = await terminplan(pool, woche);
const projektVon = new Map(tp.abschnitte.map((a) => [a.id, tp.projekte.find((p) => p.id === a.projekt_id)]));
const termine: Termin[] = [];
for (const v of tp.vorgaenge) {
const p = projektVon.get(v.abschnitt_id);
if (!p || !IM_KALENDER.has(p.status)) continue;
const bs = tp.besetzungen.filter((b) => b.vorgang_id === v.id);
const personen = (b: (typeof bs)[number]) => (Number(b.personen) !== 1 ? ` ×${String(b.personen).replace(".", ",")}` : "");
const kurz = bs.map((b) => `${b.kurz}${personen(b)}${b.freigegeben ? "" : "?"}`).join(", ");
const meilenstein = Number(v.dauer) === 0;
const titel = `${meilenstein ? "◆ " : ""}${p.nummer} ${v.name}${kurz ? ` · ${kurz}` : ""}`;
const beschreibung = [
`Projekt: ${p.nummer} ${p.bezeichnung}`,
p.bauherr ? `Bauherr: ${p.bauherr}` : "",
bs.length ? `Besetzung: ${bs.map((b) => `${b.anzeige}${personen(b)}${b.freigegeben ? "" : " (vorgemerkt)"}`).join("; ")}` : meilenstein ? "" : "Besetzung: noch offen",
meilenstein ? "Meilenstein" : `Dauer: ${String(Number(v.dauer)).replace(".", ",")} ${Number(v.dauer) === 1 ? "Arbeitstag" : "Arbeitstage"}`,
].filter(Boolean).join("\n");
arbeitsbloecke(v.anfang, v.ende, wocheVon(v, woche)).forEach(([von, bis], i) =>
termine.push({ uid: `${v.id}-${i}@betrieb.schaarschmidt-holzbau.de`, von, bis, titel, beschreibung }));
}
return kalender("Baustellen", termine);
}
export async function aufgabenKalender(pool: Pool): Promise<string> {
const r = await pool.query(`select a.id, a.text, a.faellig_am, a.geaendert_am, p.nummer from aufgabe a left join projekt p on p.id = a.projekt_id
where a.erledigt_am is null and a.faellig_am is not null`);
// A35: Ende der Bindefrist offener Angebote als Termin (Outlook classic gleicht keine Aufgaben ab, E15)
const b = await pool.query(`select a.id, a.nummer, a.bindefrist, a.geaendert_am, p.bezeichnung from angebot a join projekt p on p.id = a.projekt_id
where a.status = 'versendet' and a.bindefrist is not null`);
return kalender("Aufgaben", [
...r.rows.map((a) => ({
uid: `${a.id}@betrieb.schaarschmidt-holzbau.de`, von: a.faellig_am, bis: a.faellig_am,
titel: `Aufgabe: ${a.text}${a.nummer ? ` (${a.nummer})` : ""}`, geaendert: a.geaendert_am,
})),
...b.rows.map((a) => ({
uid: `bindefrist-${a.id}@betrieb.schaarschmidt-holzbau.de`, von: a.bindefrist, bis: a.bindefrist,
titel: `Bindefrist Angebot ${a.nummer} (${a.bezeichnung})`, geaendert: a.geaendert_am,
})),
]);
}