From db9c2929a8a61c91cd95e2f8644ec6b5ce5bdeff Mon Sep 17 00:00:00 2001 From: BOHA Date: Tue, 24 Mar 2026 19:09:24 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20work=20fund=20=E2=80=94=20prorate=20curr?= =?UTF-8?q?ent=20month=20to=20today's=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Past months use full month working days. Current month counts working days only up to today (e.g., March 24 = 16 working days out of 21), so the +/- column shows an accurate difference instead of always showing a deficit mid-month. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/services/attendance.service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/attendance.service.ts b/src/services/attendance.service.ts index 848c3b6..1d9717c 100644 --- a/src/services/attendance.service.ts +++ b/src/services/attendance.service.ts @@ -10,10 +10,10 @@ const MONTH_NAMES = [ // ── Helpers ────────────────────────────────────────────────────────── -function countWorkingDays(year: number, month: number): number { +function countWorkingDays(year: number, month: number, upToDay?: number): number { let count = 0; const cur = new Date(year, month, 1); - while (cur.getMonth() === month) { + while (cur.getMonth() === month && (!upToDay || cur.getDate() <= upToDay)) { const dow = cur.getDay(); if (dow !== 0 && dow !== 6) count++; cur.setDate(cur.getDate() + 1); @@ -374,7 +374,9 @@ export async function getWorkfund(year: number) { const months: Record }> = {}; for (let m = 0; m <= maxMonth; m++) { - const bizDays = countWorkingDays(year, m); + // Current month: prorate fund to today's date only + const isCurrentMonth = year === currentYear && m === currentMonth; + const bizDays = isCurrentMonth ? countWorkingDays(year, m, now.getDate()) : countWorkingDays(year, m); const fund = bizDays * 8; const monthStart = new Date(year, m, 1); const monthEnd = new Date(year, m + 1, 0, 23, 59, 59);