From 426859ea0d221726db14531602247dcd3b2f2769 Mon Sep 17 00:00:00 2001 From: Felix Schlusche Date: Thu, 23 Oct 2025 19:13:48 +0200 Subject: [PATCH] feat: update bulk export logic to correctly handle flextime hours on weekends/holidays --- public/js/main.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index aeb7db2..085f344 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -2145,7 +2145,14 @@ async function bulkExportPDF() { totalNetHours += entry.netHours; } else if (entry.entryType === 'flextime') { flextimeDays++; - totalNetHours += entry.netHours; + // Only add flextime hours if it's on a weekend/holiday + // (otherwise it's already counted as workday hours) + const dateObj = new Date(entry.date); + const isWeekendHoliday = isWeekendOrHoliday(dateObj); + if (isWeekendHoliday) { + totalNetHours += entry.netHours; + } + // If flextime on regular workday, don't add hours (already in work entries) } } }); @@ -3019,6 +3026,15 @@ async function handleExportPDF() { let flextimeDays = 0; let workEntriesCount = 0; + // Create map of entries by date for proper handling + const entriesByDate = new Map(); + entries.forEach(entry => { + if (!entriesByDate.has(entry.date)) { + entriesByDate.set(entry.date, []); + } + entriesByDate.get(entry.date).push(entry); + }); + entries.forEach(entry => { const entryDate = new Date(entry.date); if (entryDate <= today) { @@ -3027,10 +3043,18 @@ async function handleExportPDF() { workEntriesCount++; } else if (entry.entryType === 'vacation') { vacationDays++; + // Vacation hours are already included in netHours (8h per day typically) totalNetHours += entry.netHours; } else if (entry.entryType === 'flextime') { flextimeDays++; - totalNetHours += entry.netHours; + // Only add flextime hours if it's on a weekend/holiday + // (otherwise it's already counted as workday hours) + const dateObj = new Date(entry.date); + const isWeekendHoliday = isWeekendOrHoliday(dateObj); + if (isWeekendHoliday) { + totalNetHours += entry.netHours; + } + // If flextime on regular workday, hours are already counted in work entries } } });