feat: implement maximum net working hours validation and auto-stop timer after 10 hours
All checks were successful
Build and Push Docker Image / build (push) Successful in 36s

This commit is contained in:
Felix Schlusche
2025-10-24 17:41:38 +02:00
parent defc0f3161
commit 3f36ec3cc7

View File

@@ -549,6 +549,14 @@ function updateTimer() {
document.getElementById('timerStatus').textContent = `Läuft seit ${timerStartTimeString} - Pause (${remainingMinutes} Min)`; document.getElementById('timerStatus').textContent = `Läuft seit ${timerStartTimeString} - Pause (${remainingMinutes} Min)`;
} else { } else {
elapsed = Math.floor((now - timerStartTime) / 1000) - timerPausedDuration; 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); document.getElementById('timerDisplay').textContent = formatDuration(elapsed);
@@ -1686,6 +1694,13 @@ async function handleFormSubmit(e) {
return; 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) { if (currentEditingId) {
// Update existing entry // Update existing entry
const success = await updateEntry(currentEditingId, date, startTime, endTime, pauseMinutes, location); 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 * Handle delete button click
*/ */
@@ -2872,6 +2916,15 @@ function handleCellClick(e) {
pauseToSend = null; // Trigger auto-calculation on server 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 // Update via API
const success = await updateEntry( const success = await updateEntry(
entryId, entryId,