fix: work fund overview — only show past and current month, not future

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) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-03-24 19:05:31 +01:00
parent 0ec2cde5e5
commit a0f86deedb

View File

@@ -356,15 +356,24 @@ export async function getWorkfund(year: number) {
orderBy: { last_name: 'asc' }, 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 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({ const allRecords = await prisma.attendance.findMany({
where: { shift_date: { gte: yearStart, lte: yearEnd } }, where: { shift_date: { gte: yearStart, lte: yearEnd } },
}); });
const months: Record<string, { month_name: string; fund: number; business_days: number; users: Record<string, { name: string; worked: number; covered: number; overtime: number; missing: number }> }> = {}; const months: Record<string, { month_name: string; fund: number; business_days: number; users: Record<string, { name: string; worked: number; covered: number; overtime: number; missing: number }> }> = {};
for (let m = 0; m < 12; m++) { for (let m = 0; m <= maxMonth; m++) {
const bizDays = countWorkingDays(year, m); const bizDays = countWorkingDays(year, m);
const fund = bizDays * 8; const fund = bizDays * 8;
const monthStart = new Date(year, m, 1); const monthStart = new Date(year, m, 1);