Umstellung auf Arbeitstage
This commit is contained in:
@@ -57,12 +57,15 @@ function registerUserRoutes(app) {
|
||||
app.get('/api/user/data', requireAuth, (req, res) => {
|
||||
const userId = req.session.userId;
|
||||
|
||||
db.get('SELECT wochenstunden FROM users WHERE id = ?', [userId], (err, user) => {
|
||||
db.get('SELECT wochenstunden, arbeitstage FROM users WHERE id = ?', [userId], (err, user) => {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: 'Fehler beim Abrufen der User-Daten' });
|
||||
}
|
||||
|
||||
res.json({ wochenstunden: user?.wochenstunden || 0 });
|
||||
res.json({
|
||||
wochenstunden: user?.wochenstunden || 0,
|
||||
arbeitstage: user?.arbeitstage || 5
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -223,12 +226,13 @@ function registerUserRoutes(app) {
|
||||
}
|
||||
|
||||
// User-Daten abrufen
|
||||
db.get('SELECT wochenstunden, urlaubstage, overtime_offset_hours, vacation_offset_days FROM users WHERE id = ?', [userId], (err, user) => {
|
||||
db.get('SELECT wochenstunden, urlaubstage, overtime_offset_hours, vacation_offset_days, arbeitstage FROM users WHERE id = ?', [userId], (err, user) => {
|
||||
if (err || !user) {
|
||||
return res.status(500).json({ error: 'Fehler beim Abrufen der User-Daten' });
|
||||
}
|
||||
|
||||
const wochenstunden = user.wochenstunden || 0;
|
||||
const arbeitstage = user.arbeitstage || 5;
|
||||
const urlaubstage = user.urlaubstage || 0;
|
||||
const overtimeOffsetHours = user.overtime_offset_hours ? parseFloat(user.overtime_offset_hours) : 0;
|
||||
const vacationOffsetDays = user.vacation_offset_days ? parseFloat(user.vacation_offset_days) : 0;
|
||||
@@ -407,7 +411,7 @@ function registerUserRoutes(app) {
|
||||
let weekVacationDays = 0;
|
||||
let weekVacationHours = 0;
|
||||
|
||||
const fullDayHours = wochenstunden > 0 ? wochenstunden / 5 : 8;
|
||||
const fullDayHours = wochenstunden > 0 && arbeitstage > 0 ? wochenstunden / arbeitstage : 8;
|
||||
let fullDayOvertimeDays = 0; // Anzahl Tage mit 8 Überstunden
|
||||
|
||||
entries.forEach(entry => {
|
||||
@@ -428,11 +432,11 @@ function registerUserRoutes(app) {
|
||||
// Urlaub hat Priorität - wenn Urlaub, zähle nur Urlaubsstunden, nicht zusätzlich Arbeitsstunden
|
||||
if (entry.vacation_type === 'full') {
|
||||
weekVacationDays += 1;
|
||||
weekVacationHours += 8; // Ganzer Tag = 8 Stunden
|
||||
weekVacationHours += fullDayHours; // Ganzer Tag = (Wochenarbeitszeit / Arbeitstage) Stunden
|
||||
// Bei vollem Tag Urlaub werden keine Arbeitsstunden gezählt
|
||||
} else if (entry.vacation_type === 'half') {
|
||||
weekVacationDays += 0.5;
|
||||
weekVacationHours += 4; // Halber Tag = 4 Stunden
|
||||
weekVacationHours += fullDayHours / 2; // Halber Tag = (Wochenarbeitszeit / Arbeitstage) / 2 Stunden
|
||||
// Bei halbem Tag Urlaub können noch Arbeitsstunden vorhanden sein
|
||||
// WICHTIG: total_hours enthält bereits Wochenend-Prozentsätze (aus timesheet.js)
|
||||
if (entry.total_hours && !isFullDayOvertime) {
|
||||
@@ -447,18 +451,18 @@ function registerUserRoutes(app) {
|
||||
}
|
||||
});
|
||||
|
||||
// Feiertagsstunden: 8h pro Werktag der ein Feiertag ist
|
||||
// Feiertagsstunden: (Wochenarbeitszeit / Arbeitstage) pro Werktag der ein Feiertag ist
|
||||
let holidayHours = 0;
|
||||
for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
|
||||
const day = d.getDay();
|
||||
if (day >= 1 && day <= 5) {
|
||||
const dateStr = d.toISOString().split('T')[0];
|
||||
if (holidaySet.has(dateStr)) holidayHours += 8;
|
||||
if (holidaySet.has(dateStr)) holidayHours += fullDayHours;
|
||||
}
|
||||
}
|
||||
|
||||
// Sollstunden berechnen
|
||||
const sollStunden = (wochenstunden / 5) * workdays;
|
||||
const sollStunden = (wochenstunden / arbeitstage) * workdays;
|
||||
|
||||
// Überstunden für diese Woche: (totalHours + vacationHours + holidayHours) - adjustedSollStunden
|
||||
const weekTotalHoursWithVacation = weekTotalHours + weekVacationHours + holidayHours;
|
||||
@@ -532,12 +536,13 @@ function registerUserRoutes(app) {
|
||||
}
|
||||
|
||||
// User-Daten abrufen
|
||||
db.get('SELECT wochenstunden, overtime_offset_hours FROM users WHERE id = ?', [userId], (err, user) => {
|
||||
db.get('SELECT wochenstunden, overtime_offset_hours, arbeitstage FROM users WHERE id = ?', [userId], (err, user) => {
|
||||
if (err || !user) {
|
||||
return res.status(500).json({ error: 'Fehler beim Abrufen der User-Daten' });
|
||||
}
|
||||
|
||||
const wochenstunden = user.wochenstunden || 0;
|
||||
const arbeitstage = user.arbeitstage || 5;
|
||||
const overtimeOffsetHours = user.overtime_offset_hours ? parseFloat(user.overtime_offset_hours) : 0;
|
||||
|
||||
// Alle eingereichten Wochen abrufen
|
||||
@@ -645,7 +650,7 @@ function registerUserRoutes(app) {
|
||||
let weekVacationDays = 0;
|
||||
let weekVacationHours = 0;
|
||||
|
||||
const fullDayHours = wochenstunden > 0 ? wochenstunden / 5 : 8;
|
||||
const fullDayHours = wochenstunden > 0 && arbeitstage > 0 ? wochenstunden / arbeitstage : 8;
|
||||
let fullDayOvertimeDays = 0;
|
||||
|
||||
entries.forEach(entry => {
|
||||
@@ -662,10 +667,10 @@ function registerUserRoutes(app) {
|
||||
|
||||
if (entry.vacation_type === 'full') {
|
||||
weekVacationDays += 1;
|
||||
weekVacationHours += 8;
|
||||
weekVacationHours += fullDayHours;
|
||||
} else if (entry.vacation_type === 'half') {
|
||||
weekVacationDays += 0.5;
|
||||
weekVacationHours += 4;
|
||||
weekVacationHours += fullDayHours / 2;
|
||||
// WICHTIG: total_hours enthält bereits Wochenend-Prozentsätze (aus timesheet.js)
|
||||
if (entry.total_hours && !isFullDayOvertime) {
|
||||
weekTotalHours += parseFloat(entry.total_hours) || 0;
|
||||
@@ -678,18 +683,18 @@ function registerUserRoutes(app) {
|
||||
}
|
||||
});
|
||||
|
||||
// Feiertagsstunden
|
||||
// Feiertagsstunden: (Wochenarbeitszeit / Arbeitstage) pro Werktag der ein Feiertag ist
|
||||
let holidayHours = 0;
|
||||
for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
|
||||
const day = d.getDay();
|
||||
if (day >= 1 && day <= 5) {
|
||||
const dateStr = d.toISOString().split('T')[0];
|
||||
if (holidaySet.has(dateStr)) holidayHours += 8;
|
||||
if (holidaySet.has(dateStr)) holidayHours += fullDayHours;
|
||||
}
|
||||
}
|
||||
|
||||
// Sollstunden berechnen
|
||||
const sollStunden = (wochenstunden / 5) * workdays;
|
||||
const sollStunden = (wochenstunden / arbeitstage) * workdays;
|
||||
const weekTotalHoursWithVacation = weekTotalHours + weekVacationHours + holidayHours;
|
||||
const adjustedSollStunden = sollStunden - (fullDayOvertimeDays * fullDayHours);
|
||||
const weekOvertimeHours = weekTotalHoursWithVacation - adjustedSollStunden;
|
||||
|
||||
Reference in New Issue
Block a user