Projektnummern: keine doppelten, Buchstabe A/P/G/I nach Status, Aufräumen (0.40.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
48
src/domain/nummer.ts
Normal file
48
src/domain/nummer.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// Projektnummern (Henning, 26.10.2026): keine doppelten, der Buchstabe folgt dem Status.
|
||||
// A = Anfrage/Angebot, P = Auftrag bis Abgeschlossen, G = Gewährleistung, I = Intern (eigene Reihe).
|
||||
// Verglichen wird nur Jahr, Zahl und Teil (26-021, 26-007.1), egal ob mit Bindestrich oder welcher Buchstabe davor steht.
|
||||
|
||||
export interface Nummer { buchstabe: string; jj: string; zahl: number; teil: string }
|
||||
|
||||
const MUSTER = /^\s*([APGI])?\s*-?\s*(\d{2})\s*-\s*(\d{1,4})((?:\.\d+)*)\s*$/i;
|
||||
|
||||
/** Nummer zerlegen; was nicht nach Jahr-Zahl aussieht (z. B. A-OHNE-1 aus V70), liefert null. */
|
||||
export function zerlege(nummer: string): Nummer | null {
|
||||
const m = MUSTER.exec(nummer);
|
||||
return m ? { buchstabe: (m[1] ?? "").toUpperCase(), jj: m[2]!, zahl: Number(m[3]), teil: m[4] ?? "" } : null;
|
||||
}
|
||||
|
||||
export function buchstabeFuer(status: string): string {
|
||||
if (status === "intern") return "I";
|
||||
if (status === "gewaehrleistung") return "G";
|
||||
return ["anfrage", "angebot"].includes(status) ? "A" : "P";
|
||||
}
|
||||
|
||||
const kern = (x: Nummer) => `${x.jj}-${String(x.zahl).padStart(3, "0")}${x.teil}`;
|
||||
|
||||
/** Jahr und Zahl zum Anzeigen, z. B. 26-021 */
|
||||
export const nummerKern = (nummer: string) => { const x = zerlege(nummer); return x ? kern(x) : nummer.trim(); };
|
||||
|
||||
/** Woran doppelte Nummern erkannt werden: interne Projekte zählen für sich. */
|
||||
export function nummerSchluessel(nummer: string): string {
|
||||
const x = zerlege(nummer);
|
||||
return x ? `${x.buchstabe === "I" ? "I" : ""}${kern(x)}` : nummer.trim().toUpperCase();
|
||||
}
|
||||
|
||||
/** Einheitliche Schreibweise mit dem Buchstaben des Status; Fremdformate bleiben, wie sie sind. */
|
||||
export function projektNummer(nummer: string, status: string): string {
|
||||
const x = zerlege(nummer);
|
||||
return x ? `${buchstabeFuer(status)}-${kern(x)}` : nummer.trim();
|
||||
}
|
||||
|
||||
/** Nächste freie Zahl der Reihe (normal oder intern) im Jahr, mit dem Buchstaben des Status */
|
||||
export function naechsteProjektNummer(vorhanden: string[], jahr: number, status: string): string {
|
||||
const jj = String(jahr % 100).padStart(2, "0");
|
||||
const intern = status === "intern";
|
||||
let max = 0;
|
||||
for (const n of vorhanden) {
|
||||
const x = zerlege(n);
|
||||
if (x && x.jj === jj && (x.buchstabe === "I") === intern) max = Math.max(max, x.zahl);
|
||||
}
|
||||
return `${buchstabeFuer(status)}-${jj}-${String(max + 1).padStart(3, "0")}`;
|
||||
}
|
||||
Reference in New Issue
Block a user