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) <noreply@anthropic.com>
This commit is contained in:
@@ -371,13 +371,14 @@ export async function getWorkfund(year: number) {
|
||||
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; fund_to_date: number; business_days: number; users: Record<string, { name: string; worked: number; covered: number; overtime: number; missing: number }> }> = {};
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user