From 9724a7b2e91e88aed7c9cb56f9f4b346697a6c4f Mon Sep 17 00:00:00 2001 From: BOHA Date: Tue, 24 Mar 2026 19:12:13 +0100 Subject: [PATCH] fix: separate full month fund from prorated fund Monthly cards show full month fund (e.g., 168h for 21 days). Yearly summary table uses fund_to_date (prorated to today for current month) so the +/- column is accurate mid-month. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/admin/pages/AttendanceBalances.tsx | 3 ++- src/services/attendance.service.ts | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/admin/pages/AttendanceBalances.tsx b/src/admin/pages/AttendanceBalances.tsx index 98dd46f..36db791 100644 --- a/src/admin/pages/AttendanceBalances.tsx +++ b/src/admin/pages/AttendanceBalances.tsx @@ -275,7 +275,8 @@ export default function AttendanceBalances() { let totalWorked = 0 let totalCovered = 0 for (const monthData of Object.values(fundData.months)) { - totalFund += monthData.fund + // Use prorated fund (fund_to_date) for current month, full fund for past + totalFund += (monthData as any).fund_to_date ?? monthData.fund const us = monthData.users?.[userId] if (us) { totalWorked += us.worked diff --git a/src/services/attendance.service.ts b/src/services/attendance.service.ts index 1d9717c..feafb81 100644 --- a/src/services/attendance.service.ts +++ b/src/services/attendance.service.ts @@ -371,13 +371,14 @@ export async function getWorkfund(year: number) { where: { shift_date: { gte: yearStart, lte: yearEnd } }, }); - const months: Record }> = {}; + const months: Record }> = {}; for (let m = 0; m <= maxMonth; 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 bizDays = countWorkingDays(year, m); + const bizDaysToDate = isCurrentMonth ? countWorkingDays(year, m, now.getDate()) : bizDays; const fund = bizDays * 8; + const fundToDate = bizDaysToDate * 8; const monthStart = new Date(year, m, 1); const monthEnd = new Date(year, m + 1, 0, 23, 59, 59); @@ -424,6 +425,7 @@ export async function getWorkfund(year: number) { months[String(m + 1)] = { month_name: MONTH_NAMES[m], fund, + fund_to_date: fundToDate, business_days: bizDays, users: monthUsers, };