fix: work fund — prorate current month to today's date
Past months use full month working days. Current month counts working days only up to today (e.g., March 24 = 16 working days out of 21), so the +/- column shows an accurate difference instead of always showing a deficit mid-month. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,10 +10,10 @@ const MONTH_NAMES = [
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
function countWorkingDays(year: number, month: number): number {
|
||||
function countWorkingDays(year: number, month: number, upToDay?: number): number {
|
||||
let count = 0;
|
||||
const cur = new Date(year, month, 1);
|
||||
while (cur.getMonth() === month) {
|
||||
while (cur.getMonth() === month && (!upToDay || cur.getDate() <= upToDay)) {
|
||||
const dow = cur.getDay();
|
||||
if (dow !== 0 && dow !== 6) count++;
|
||||
cur.setDate(cur.getDate() + 1);
|
||||
@@ -374,7 +374,9 @@ export async function getWorkfund(year: 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 <= maxMonth; m++) {
|
||||
const bizDays = countWorkingDays(year, 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 fund = bizDays * 8;
|
||||
const monthStart = new Date(year, m, 1);
|
||||
const monthEnd = new Date(year, m + 1, 0, 23, 59, 59);
|
||||
|
||||
Reference in New Issue
Block a user