Zahlungen, Kosten und Aufgaben im Terminplan, Aufgaben-Vorlage, Schlussrechnung als Rest, Zahlungsplan verschieben (0.14.0)
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled

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:
Claude
2026-10-20 11:20:13 +00:00
parent 6d0c5f238b
commit 4e07e0b89e
19 changed files with 842 additions and 54 deletions

View File

@@ -20,8 +20,8 @@ export async function legeZahlungsplanAn(c: Client, projektId: string, umsatz: n
const neu = [];
for (const [i, z] of (await vorschlag(c, projektId, umsatz, woche)).entries()) {
neu.push((await c.query(
`insert into zahlung (projekt_id, vorgang_id, art, bezeichnung, netto, termin, status, reihenfolge) values ($1, $2, $3, $4, $5, $6, 'geplant', $7) returning *`,
[projektId, z.vorgang_id, z.art, z.bezeichnung, z.netto, z.termin, i])).rows[0]);
`insert into zahlung (projekt_id, vorgang_id, art, bezeichnung, netto, termin, status, reihenfolge, rest) values ($1, $2, $3, $4, $5, $6, 'geplant', $7, $8) returning *`,
[projektId, z.vorgang_id, z.art, z.bezeichnung, z.netto, z.termin, i, z.art === "schluss"])).rows[0]);
}
await c.query("update projekt set zahlungsplan = 'auto' where id = $1", [projektId]);
return neu;
@@ -57,3 +57,14 @@ export async function zahlungsplaeneAutomatisch(c: Client, woche: Arbeitswoche):
export async function zahlungsplanFest(c: Client, projektId: string): Promise<void> {
await c.query("update projekt set zahlungsplan = 'fest' where id = $1 and zahlungsplan is distinct from 'fest'", [projektId]);
}
/**
* Schlussrechnung ohne eigenen Betrag (Henning, 20.10.2026): solange sie geplant ist, ist sie der Rest aus
* Auftragswert und allen anderen Raten (gestellt, bezahlt und noch geplant), damit nichts doppelt zählt.
*/
export async function restNachziehen(c: Client): Promise<void> {
await c.query(`update zahlung z set netto = r.soll from (
select z2.id, greatest(0, coalesce(p.umsatz_netto, 0) - coalesce((select sum(a.netto) from zahlung a where a.projekt_id = z2.projekt_id and a.id <> z2.id), 0)) as soll
from zahlung z2 join projekt p on p.id = z2.projekt_id where z2.rest and z2.status = 'geplant') r
where z.id = r.id and z.netto <> r.soll`);
}