diff --git a/app/(app)/page.tsx b/app/(app)/page.tsx index 016b860..4484e7c 100644 --- a/app/(app)/page.tsx +++ b/app/(app)/page.tsx @@ -70,7 +70,10 @@ export default async function DashboardPage({ const today = todayIso(); const year = today.slice(0, 4); const yearStart = `${year}-01-01`; - const yearEnd = `${year}-12-31`; + // Das obere Ende des YTD-Fensters ist **heute**. Hier stand der 31.12., also + // das ganze Kalenderjahr — womit die Kacheln auch zählten, was erst + // bevorsteht (B.02). + const ytdBis = today; // Der Vorschauzeitraum ist einstellbar, und mit ihm, was überhaupt geladen // wird. Deshalb steht die Auswahl in der Adresse und nicht im Browser: 90 @@ -103,7 +106,7 @@ export default async function DashboardPage({ upcomingReturns, upcomingNotes, history, - } = await withUser(userId, (tx) => loadDashboardData(tx, { userId, today, yearStart, yearEnd, bisIso, arten })); + } = await withUser(userId, (tx) => loadDashboardData(tx, { userId, today, yearStart, ytdBis, bisIso, arten })); // "Aktiv" means status Aktiv — somebody on Karenz is employed but not // active, and is counted by its own tile instead. FTE follows the same // set: Karenz contributes no capacity, so including it would overstate @@ -225,16 +228,18 @@ export default async function DashboardPage({ kacheln: [ { // YTD: seit Jahresbeginn bis heute, nicht das ganze Kalenderjahr. + // Der Verweis trägt denselben Zeitraum — sonst zeigte der Bericht + // eine andere Zahl als die Kachel, über die man ihn geöffnet hat. label: "Eintritte (YTD)", value: hiresYtd, tone: "success", - href: `/reports?mode=events&eventType=Eintritt&from=${yearStart}&to=${yearEnd}`, + href: `/reports?mode=events&eventType=Eintritt&from=${yearStart}&to=${ytdBis}`, }, { label: "Austritte (YTD)", value: exitsYtd, tone: "danger", - href: `/reports?mode=events&eventType=Austritt&from=${yearStart}&to=${yearEnd}`, + href: `/reports?mode=events&eventType=Austritt&from=${yearStart}&to=${ytdBis}`, }, ], }, diff --git a/lib/dashboard-data.ts b/lib/dashboard-data.ts index 1331aee..6d06d69 100644 --- a/lib/dashboard-data.ts +++ b/lib/dashboard-data.ts @@ -22,13 +22,22 @@ export type DashboardParams = { userId: string | null; today: string; yearStart: string; - yearEnd: string; + /** + * Das obere Ende des YTD-Fensters — **heute**, nicht der 31.12. + * + * Hier stand das Jahresende, womit die Kacheln „Eintritte/Austritte (YTD)" + * auch zählten, was erst bevorsteht: ein für den 01.11. erfasster Austritt + * stand schon im September als geschehen da. „Year to date" heisst bis + * heute, und die Kachel soll sagen, was war — was kommt, steht in + * „Anstehend" daneben. Gemeldet im Test vom 29.09. (B.02). + */ + ytdBis: string; bisIso: string; arten: AnstehendArt[]; }; export async function loadDashboardData(tx: Tx, p: DashboardParams) { - const { userId, today, yearStart, yearEnd, bisIso, arten } = p; + const { userId, today, yearStart, ytdBis, bisIso, arten } = p; const zeigt = (art: AnstehendArt) => arten.includes(art); // Elf Abfragen standen hier in einem Promise.all, das keine // Gleichzeitigkeit war: eine Transaktion hängt an einer Verbindung, und @@ -43,7 +52,7 @@ export async function loadDashboardData(tx: Tx, p: DashboardParams) { .select(({ fn }) => fn.countAll().as("anzahl")) .where("event_type", "in", [...types]) .where("event_date", ">=", yearStart) - .where("event_date", "<=", yearEnd); + .where("event_date", "<=", ytdBis); const g = await tx .selectNoFrom((eb) => [