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:
@@ -275,7 +275,8 @@ export default function AttendanceBalances() {
|
|||||||
let totalWorked = 0
|
let totalWorked = 0
|
||||||
let totalCovered = 0
|
let totalCovered = 0
|
||||||
for (const monthData of Object.values(fundData.months)) {
|
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]
|
const us = monthData.users?.[userId]
|
||||||
if (us) {
|
if (us) {
|
||||||
totalWorked += us.worked
|
totalWorked += us.worked
|
||||||
|
|||||||
@@ -371,13 +371,14 @@ export async function getWorkfund(year: number) {
|
|||||||
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; 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++) {
|
for (let m = 0; m <= maxMonth; m++) {
|
||||||
// Current month: prorate fund to today's date only
|
|
||||||
const isCurrentMonth = year === currentYear && m === currentMonth;
|
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 fund = bizDays * 8;
|
||||||
|
const fundToDate = bizDaysToDate * 8;
|
||||||
const monthStart = new Date(year, m, 1);
|
const monthStart = new Date(year, m, 1);
|
||||||
const monthEnd = new Date(year, m + 1, 0, 23, 59, 59);
|
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)] = {
|
months[String(m + 1)] = {
|
||||||
month_name: MONTH_NAMES[m],
|
month_name: MONTH_NAMES[m],
|
||||||
fund,
|
fund,
|
||||||
|
fund_to_date: fundToDate,
|
||||||
business_days: bizDays,
|
business_days: bizDays,
|
||||||
users: monthUsers,
|
users: monthUsers,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user