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, };