Monatswechsel ausßerhalb des Dienstjahres.

- Jahresansicht verknüpft
- Lokal getestet
26-10-Jahreswechsel
Samuel Zielke 3 days ago
parent bdf1ba261f
commit 4178738fbb

@ -226,29 +226,35 @@ function formatDate(dateString) {
return `${day}.${month}.${year}`; // Format tt.mm.yy return `${day}.${month}.${year}`; // Format tt.mm.yy
} }
// Einträge nach Monat und/oder Jahr filtern // Dienstjahr-Label für ein Datum ermitteln.
// Dienstjahr läuft September(Jahr X) bis August(Jahr X+1) und wird mit dem Label X+1 bezeichnet.
// Beispiel: 15. September 2025 -> Dienstjahr-Label 2026; 15. Mai 2026 -> Dienstjahr-Label 2026.
function getServiceYear(date) {
const d = (date instanceof Date) ? date : new Date(date);
const calendarYear = d.getFullYear();
const calendarMonth = d.getMonth() + 1; // 1-basiert
return (calendarMonth >= 9) ? calendarYear + 1 : calendarYear;
}
// Einträge nach Monat und/oder Kalenderjahr filtern.
// WICHTIG: 'year' ist hier immer das ECHTE Kalenderjahr, KEIN Dienstjahr-Label.
// Für Dienstjahr-Filterung siehe filterEntriesByServiceYear().
function filterEntriesByMonthYear(month, year) { function filterEntriesByMonthYear(month, year) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const transaction = db.transaction(['hours'], 'readonly'); const transaction = db.transaction(['hours'], 'readonly');
const store = transaction.objectStore('hours'); const store = transaction.objectStore('hours');
const request = store.getAll(); const request = store.getAll();
request.onsuccess = function () { request.onsuccess = function () {
const allEntries = request.result; const allEntries = request.result;
// Filter nach Monat und Jahr // Filter nach Monat und Jahr
const filteredEntries = allEntries.filter(entry => { const filteredEntries = allEntries.filter(entry => {
const entryDate = new Date(entry.date); // Konvertiere das date-Feld in ein Date-Objekt const entryDate = new Date(entry.date); // Konvertiere das date-Feld in ein Date-Objekt
var actualYear = year;
const matchesMonth = month ? entryDate.getMonth() + 1 === month : true; // +1 da getMonth() 0-basiert ist const matchesMonth = month ? entryDate.getMonth() + 1 === month : true; // +1 da getMonth() 0-basiert ist
if (entryDate.getMonth() + 1 >= 9){ const matchesYear = year ? entryDate.getFullYear() === year : true;
actualYear = actualYear - 0;
} else {
actualYear = actualYear;
};
const matchesYear = actualYear ? entryDate.getFullYear() === actualYear : true;
return matchesMonth && matchesYear; return matchesMonth && matchesYear;
}); });
@ -262,6 +268,30 @@ function filterEntriesByMonthYear(month, year) {
}); });
} }
// Einträge für ein komplettes Dienstjahr (Sept. Vorjahr - Aug. Label-Jahr) filtern.
// serviceYearLabel entspricht dem Rückgabewert von getServiceYear(), z.B. 2026 für Sept 2025 - Aug 2026.
function filterEntriesByServiceYear(serviceYearLabel) {
return new Promise((resolve, reject) => {
const transaction = db.transaction(['hours'], 'readonly');
const store = transaction.objectStore('hours');
const request = store.getAll();
request.onsuccess = function () {
const allEntries = request.result;
const filteredEntries = allEntries.filter(entry => {
return getServiceYear(new Date(entry.date)) === serviceYearLabel;
});
resolve(filteredEntries);
};
request.onerror = function (event) {
reject('Fehler beim Abrufen der Einträge:', event.target.error);
};
});
}
// Tabelle auf dem Dashboard mit Infos füllen // Tabelle auf dem Dashboard mit Infos füllen
function fillTableWithEntries(entries) { function fillTableWithEntries(entries) {
const tableBody = document.getElementById('entriesTableBody'); const tableBody = document.getElementById('entriesTableBody');

@ -215,12 +215,9 @@ async function getActualDataAndFillView(monat = currentDate.getMonth(), jahr = c
document.getElementById('monthHourLDC').innerText = formatDuration(sumDurations(filteredEntries,2,true), true) document.getElementById('monthHourLDC').innerText = formatDuration(sumDurations(filteredEntries,2,true), true)
document.getElementById('monthHourOther').innerText = formatDuration(sumDurations(filteredEntries,3,true), true) document.getElementById('monthHourOther').innerText = formatDuration(sumDurations(filteredEntries,3,true), true)
// Jahres Ansicht füllen // Jahres Ansicht füllen (Dienstjahr, gekoppelt an den gerade angezeigten Monat/Jahr)
var requestYear = currentDate.getFullYear() var requestServiceYear = getServiceYear(new Date(jahr, monat, 1));
if (currentDate.getMonth() +1 >= 9) { var yearData = await filterEntriesByServiceYear(requestServiceYear)
requestYear += 1;
}
var yearData = await filterEntriesByMonthYear(null, requestYear)
yearData = formatDuration(sumDurations(yearData, null, true), true) yearData = formatDuration(sumDurations(yearData, null, true), true)
document.getElementById('yearHours').innerText = yearData document.getElementById('yearHours').innerText = yearData
document.getElementById('yearRest').innerText = 600 - parseInt(yearData) document.getElementById('yearRest').innerText = 600 - parseInt(yearData)
@ -358,7 +355,12 @@ document.getElementById('DeleteEntryButton').addEventListener('click', () => {
// //
const monthEntrys = document.querySelectorAll('.monthEntrys'); const monthEntrys = document.querySelectorAll('.monthEntrys');
var diffMonth = 0
// Cursor für die Monatsnavigation: echtes Kalenderjahr + 0-basierter Monat (JS-Konvention).
// Startet auf dem aktuellen Monat/Jahr und wird bei Vor/Zurück direkt fortgeschrieben,
// unabhängig vom Dienstjahr-Label - dadurch keine künstliche Sperre mehr bei Sept/Aug.
var cursorMonth = new Date().getMonth();
var cursorYear = new Date().getFullYear();
document.getElementById('dashbord_month_area').addEventListener('click', () =>{ document.getElementById('dashbord_month_area').addEventListener('click', () =>{
if (!document.getElementById('dashbord_month_area').classList.contains('ActiveMonth')) { if (!document.getElementById('dashbord_month_area').classList.contains('ActiveMonth')) {
@ -388,38 +390,32 @@ document.getElementById('dashbord_month_area').addEventListener('click', () =>{
element.classList.replace('fade-in', 'fade-out'); element.classList.replace('fade-in', 'fade-out');
}); });
document.getElementById('MonthNameOfActual').innerHTML = "Monat:" document.getElementById('MonthNameOfActual').innerHTML = "Monat:"
// document.getElementById('actualMonthName').innerHTML = monate[new Date().getMonth()]; cursorMonth = new Date().getMonth();
diffMonth = 0; cursorYear = new Date().getFullYear();
getActualDataAndFillView(new Date().getMonth() + diffMonth) getActualDataAndFillView(cursorMonth, cursorYear)
} }
}) })
document.getElementById('btn-month-before').addEventListener('click', () =>{ document.getElementById('btn-month-before').addEventListener('click', () =>{
console.log("CLICK-BEFORE: ", diffMonth) if (cursorMonth === 0) {
if (new Date().getMonth() + diffMonth == 0) { // Januar -> Dezember des Vorjahres
diffMonth = 11 - new Date().getMonth(); cursorMonth = 11;
getActualDataAndFillView(new Date().getMonth() + diffMonth) cursorYear -= 1;
console.log("CLICK-BEFRORE-0TO11: ", diffMonth)
} else { } else {
diffMonth = ((monate[new Date().getMonth() + diffMonth]) != 'September') ? diffMonth - 1 : diffMonth; cursorMonth -= 1;
// document.getElementById('actualMonthName').innerHTML = monate[new Date().getMonth() + diffMonth]; }
getActualDataAndFillView(new Date().getMonth() + diffMonth) getActualDataAndFillView(cursorMonth, cursorYear)
};
console.log("CLICK-BEFORE-AFTER: ", diffMonth)
}); });
document.getElementById('btn-month-next').addEventListener('click', () =>{ document.getElementById('btn-month-next').addEventListener('click', () =>{
console.log("CLICK-NEXT: ", diffMonth) if (cursorMonth === 11) {
if (new Date().getMonth() + diffMonth == 11) { // Dezember -> Januar des Folgejahres
diffMonth = 0 - new Date().getMonth(); cursorMonth = 0;
getActualDataAndFillView(new Date().getMonth() + diffMonth) cursorYear += 1;
console.log("CLICK-NEXT-11TO0: ", diffMonth)
} else { } else {
diffMonth = ((monate[new Date().getMonth() + diffMonth]) != 'August') ? diffMonth + 1 : diffMonth; cursorMonth += 1;
// document.getElementById('actualMonthName').innerHTML = monate[new Date().getMonth() + diffMonth]; }
getActualDataAndFillView(new Date().getMonth() + diffMonth) getActualDataAndFillView(cursorMonth, cursorYear)
};
console.log("CLICK-NEXT-AFTER: ", diffMonth)
}) })
function setNewCalsOfMonth(TheMonth) { function setNewCalsOfMonth(TheMonth) {

Loading…
Cancel
Save

Powered by TurnKey Linux.