From a0f86deedbd9b0f9037fc89947c10cd086f72794 Mon Sep 17 00:00:00 2001 From: BOHA Date: Tue, 24 Mar 2026 19:05:31 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20work=20fund=20overview=20=E2=80=94=20onl?= =?UTF-8?q?y=20show=20past=20and=20current=20month,=20not=20future?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matches PHP: past year shows all 12, current year shows up to current month, future year shows nothing. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/services/attendance.service.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/services/attendance.service.ts b/src/services/attendance.service.ts index 4fefd1b..848c3b6 100644 --- a/src/services/attendance.service.ts +++ b/src/services/attendance.service.ts @@ -356,15 +356,24 @@ export async function getWorkfund(year: number) { orderBy: { last_name: 'asc' }, }); + const now = new Date(); + const currentYear = now.getFullYear(); + const currentMonth = now.getMonth(); // 0-based + const maxMonth = year < currentYear ? 11 : (year === currentYear ? currentMonth : -1); + + if (maxMonth < 0) { + return { months: {}, users: users.map(u => ({ id: u.id, name: `${u.first_name} ${u.last_name}`.trim() })), balances: {} }; + } + const yearStart = new Date(year, 0, 1); - const yearEnd = new Date(year, 11, 31, 23, 59, 59); + const yearEnd = new Date(year, maxMonth + 1, 0, 23, 59, 59); const allRecords = await prisma.attendance.findMany({ where: { shift_date: { gte: yearStart, lte: yearEnd } }, }); const months: Record }> = {}; - for (let m = 0; m < 12; m++) { + for (let m = 0; m <= maxMonth; m++) { const bizDays = countWorkingDays(year, m); const fund = bizDays * 8; const monthStart = new Date(year, m, 1);