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);