Add Prozent im ADmin für wochenende
This commit is contained in:
@@ -54,6 +54,43 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// LDAP-Konfiguration laden
|
||||
loadLDAPConfig();
|
||||
|
||||
// Optionen laden
|
||||
loadOptions();
|
||||
|
||||
// Optionen-Formular
|
||||
const optionsForm = document.getElementById('optionsForm');
|
||||
if (optionsForm) {
|
||||
optionsForm.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = {
|
||||
saturday_percentage: document.getElementById('saturdayPercentage').value,
|
||||
sunday_percentage: document.getElementById('sundayPercentage').value
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('/admin/options', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(formData)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert('Optionen wurden erfolgreich gespeichert!');
|
||||
} else {
|
||||
alert('Fehler: ' + (result.error || 'Optionen konnten nicht gespeichert werden'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler:', error);
|
||||
alert('Fehler beim Speichern der Optionen');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// LDAP-Konfigurationsformular
|
||||
const ldapConfigForm = document.getElementById('ldapConfigForm');
|
||||
if (ldapConfigForm) {
|
||||
@@ -161,6 +198,27 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
});
|
||||
|
||||
// Optionen laden und Formular ausfüllen
|
||||
async function loadOptions() {
|
||||
try {
|
||||
const response = await fetch('/admin/options');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.config) {
|
||||
const config = result.config;
|
||||
|
||||
if (document.getElementById('saturdayPercentage')) {
|
||||
document.getElementById('saturdayPercentage').value = config.saturday_percentage || 0;
|
||||
}
|
||||
if (document.getElementById('sundayPercentage')) {
|
||||
document.getElementById('sundayPercentage').value = config.sunday_percentage || 0;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Optionen:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// LDAP-Konfiguration laden und Formular ausfüllen
|
||||
async function loadLDAPConfig() {
|
||||
try {
|
||||
|
||||
@@ -4,6 +4,36 @@ let currentWeekStart = getMonday(new Date());
|
||||
let currentEntries = {};
|
||||
let currentHolidayDates = new Set(); // Feiertage der aktuellen Woche (YYYY-MM-DD)
|
||||
let userWochenstunden = 0; // Wochenstunden des Users
|
||||
let weekendPercentages = { saturday: 100, sunday: 100 }; // Wochenend-Prozentsätze (100% = normal)
|
||||
|
||||
// Wochenend-Prozentsätze laden
|
||||
async function loadWeekendPercentages() {
|
||||
try {
|
||||
const response = await fetch('/api/user/weekend-percentages');
|
||||
if (!response.ok) {
|
||||
throw new Error('Fehler beim Laden der Wochenend-Prozentsätze');
|
||||
}
|
||||
const data = await response.json();
|
||||
weekendPercentages.saturday = data.saturday_percentage || 100;
|
||||
weekendPercentages.sunday = data.sunday_percentage || 100;
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Wochenend-Prozentsätze:', error);
|
||||
// Standardwerte verwenden
|
||||
weekendPercentages.saturday = 100;
|
||||
weekendPercentages.sunday = 100;
|
||||
}
|
||||
}
|
||||
|
||||
// Hilfsfunktion: Prüft ob ein Datum ein Wochenendtag ist und gibt den Prozentsatz zurück
|
||||
function getWeekendPercentage(date) {
|
||||
const day = date.getDay();
|
||||
if (day === 6) { // Samstag
|
||||
return weekendPercentages.saturday;
|
||||
} else if (day === 0) { // Sonntag
|
||||
return weekendPercentages.sunday;
|
||||
}
|
||||
return 100; // Kein Wochenende = 100% (normal)
|
||||
}
|
||||
|
||||
// Statistiken laden
|
||||
async function loadUserStats() {
|
||||
@@ -110,6 +140,9 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
// Ping-IP laden
|
||||
loadPingIP();
|
||||
|
||||
// Wochenend-Prozentsätze laden
|
||||
loadWeekendPercentages();
|
||||
|
||||
// Statistiken laden
|
||||
loadUserStats();
|
||||
|
||||
@@ -374,11 +407,19 @@ function renderWeek() {
|
||||
// Bei ganztägigem Urlaub oder Krank sollten es bereits 8 Stunden sein (vom Backend gesetzt)
|
||||
// Feiertag: 8h Basis + gearbeitete Stunden (jede gearbeitete Stunde = Überstunde)
|
||||
// Bei halbem Tag Urlaub werden die Urlaubsstunden später in der Überstunden-Berechnung hinzugezählt
|
||||
// Wochenend-Prozentsätze: Nur auf tatsächlich gearbeitete Stunden anwenden (nicht auf Urlaub, Krankheit, Feiertage)
|
||||
let hoursToAdd = 0;
|
||||
if (isHoliday) {
|
||||
totalHours += 8 + (hours || 0); // 8h Feiertag + gearbeitete Stunden (= Überstunden)
|
||||
hoursToAdd = 8 + (hours || 0); // 8h Feiertag + gearbeitete Stunden (= Überstunden)
|
||||
} else {
|
||||
totalHours += hours;
|
||||
hoursToAdd = hours || 0;
|
||||
// Wochenend-Prozentsatz anwenden (nur auf tatsächlich gearbeitete Stunden, nicht auf Urlaub/Krankheit)
|
||||
const weekendPercentage = getWeekendPercentage(date);
|
||||
if (weekendPercentage >= 100 && hours > 0 && vacationType !== 'full' && !sickStatus && !isFullDayOvertime) {
|
||||
hoursToAdd = hours * (weekendPercentage / 100);
|
||||
}
|
||||
}
|
||||
totalHours += hoursToAdd;
|
||||
|
||||
// Bearbeitung ist immer möglich, auch nach Abschicken
|
||||
// Bei ganztägigem Urlaub oder Krank werden Zeitfelder deaktiviert; Feiertag: Anzeige, Zeitfelder optional (Überstunden)
|
||||
@@ -662,10 +703,22 @@ function updateOvertimeDisplay() {
|
||||
const end = new Date(`2000-01-01T${endTime}`);
|
||||
const diffMs = end - start;
|
||||
const hours = (diffMs / (1000 * 60 * 60)) - (breakMinutes / 60);
|
||||
totalHours += hours;
|
||||
// Wochenend-Prozentsatz anwenden (nur auf tatsächlich gearbeitete Stunden)
|
||||
const weekendPercentage = getWeekendPercentage(date);
|
||||
let adjustedHours = hours;
|
||||
if (weekendPercentage >= 100 && hours > 0 && vacationType !== 'full' && !sickStatus && !isFullDayOvertime) {
|
||||
adjustedHours = hours * (weekendPercentage / 100);
|
||||
}
|
||||
totalHours += adjustedHours;
|
||||
} else if (currentEntries[dateStr]?.total_hours && !isFullDayOvertime) {
|
||||
// Fallback auf gespeicherte Werte
|
||||
totalHours += parseFloat(currentEntries[dateStr].total_hours) || 0;
|
||||
let hours = parseFloat(currentEntries[dateStr].total_hours) || 0;
|
||||
// Wochenend-Prozentsatz anwenden (nur auf tatsächlich gearbeitete Stunden)
|
||||
const weekendPercentage = getWeekendPercentage(date);
|
||||
if (weekendPercentage >= 100 && hours > 0 && vacationType !== 'full' && !sickStatus) {
|
||||
hours = hours * (weekendPercentage / 100);
|
||||
}
|
||||
totalHours += hours;
|
||||
}
|
||||
} else if (sickStatus) {
|
||||
totalHours += 8; // Krank = 8 Stunden
|
||||
@@ -706,10 +759,22 @@ function updateOvertimeDisplay() {
|
||||
const end = new Date(`2000-01-01T${endTime}`);
|
||||
const diffMs = end - start;
|
||||
const hours = (diffMs / (1000 * 60 * 60)) - (breakMinutes / 60);
|
||||
totalHours += hours;
|
||||
// Wochenend-Prozentsatz anwenden (nur auf tatsächlich gearbeitete Stunden)
|
||||
const weekendPercentage = getWeekendPercentage(date);
|
||||
let adjustedHours = hours;
|
||||
if (weekendPercentage >= 100 && hours > 0 && !isFullDayOvertime) {
|
||||
adjustedHours = hours * (weekendPercentage / 100);
|
||||
}
|
||||
totalHours += adjustedHours;
|
||||
} else if (currentEntries[dateStr]?.total_hours) {
|
||||
// Fallback auf gespeicherte Werte
|
||||
totalHours += parseFloat(currentEntries[dateStr].total_hours) || 0;
|
||||
let hours = parseFloat(currentEntries[dateStr].total_hours) || 0;
|
||||
// Wochenend-Prozentsatz anwenden (nur auf tatsächlich gearbeitete Stunden)
|
||||
const weekendPercentage = getWeekendPercentage(date);
|
||||
if (weekendPercentage >= 100 && hours > 0 && !isFullDayOvertime) {
|
||||
hours = hours * (weekendPercentage / 100);
|
||||
}
|
||||
totalHours += hours;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user