diff --git a/public/js/main.js b/public/js/main.js index 06b0df5..61609a9 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -549,6 +549,14 @@ function updateTimer() { document.getElementById('timerStatus').textContent = `Läuft seit ${timerStartTimeString} - Pause (${remainingMinutes} Min)`; } else { elapsed = Math.floor((now - timerStartTime) / 1000) - timerPausedDuration; + + // Check if 10h net time reached - auto stop timer + const netHours = elapsed / 3600; + if (netHours >= 10) { + showNotification('🛑 Maximale Arbeitszeit (10h netto) erreicht. Timer wird automatisch gestoppt.', 'warning'); + stopWork(); + return; + } } document.getElementById('timerDisplay').textContent = formatDuration(elapsed); @@ -1686,6 +1694,13 @@ async function handleFormSubmit(e) { return; } + // Validate max 10h net time + const netHours = calculateNetHours(startTime, endTime, pauseMinutes); + if (netHours > 10) { + showNotification('❌ Maximale Arbeitszeit überschritten! Netto-Arbeitszeit darf maximal 10,0h betragen.', 'error'); + return; + } + if (currentEditingId) { // Update existing entry const success = await updateEntry(currentEditingId, date, startTime, endTime, pauseMinutes, location); @@ -1705,6 +1720,35 @@ async function handleFormSubmit(e) { } } +/** + * Calculate net hours from times and pause + */ +function calculateNetHours(startTime, endTime, pauseMinutes) { + const [startHour, startMin] = startTime.split(':').map(Number); + const [endHour, endMin] = endTime.split(':').map(Number); + + const startMinutes = startHour * 60 + startMin; + const endMinutes = endHour * 60 + endMin; + + let grossMinutes = endMinutes - startMinutes; + if (grossMinutes < 0) grossMinutes += 24 * 60; // Handle overnight + + const grossHours = grossMinutes / 60; + + // Calculate pause if not provided + let pause = pauseMinutes || 0; + if (pauseMinutes === null || pauseMinutes === undefined) { + if (grossHours >= 9) { + pause = 45; + } else if (grossHours >= 6) { + pause = 30; + } + } + + const netHours = grossHours - (pause / 60); + return netHours; +} + /** * Handle delete button click */ @@ -2872,6 +2916,15 @@ function handleCellClick(e) { pauseToSend = null; // Trigger auto-calculation on server } + // Validate max 10h net time + const netHours = calculateNetHours(values.startTime, values.endTime, pauseToSend); + if (netHours > 10) { + showNotification('❌ Maximale Arbeitszeit überschritten! Netto-Arbeitszeit darf maximal 10,0h betragen.', 'error'); + cell.classList.remove('editing'); + cell.innerHTML = originalContent; + return; + } + // Update via API const success = await updateEntry( entryId,