From 4178738fbb9abb75f21a25ab44dde1b0391bb33a Mon Sep 17 00:00:00 2001 From: samuelzielke Date: Sat, 5 Sep 2026 01:32:20 +0200 Subject: [PATCH] =?UTF-8?q?Monatswechsel=20aus=C3=9Ferhalb=20des=20Dienstj?= =?UTF-8?q?ahres.=20-=20Jahresansicht=20verkn=C3=BCpft=20-=20Lokal=20getes?= =?UTF-8?q?tet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/app/js/dbcontrol.js | 48 +++++++++++++++++++++++------ app/static/app/js/home01.js | 56 ++++++++++++++++------------------ 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/app/static/app/js/dbcontrol.js b/app/static/app/js/dbcontrol.js index 331327e..99814e4 100644 --- a/app/static/app/js/dbcontrol.js +++ b/app/static/app/js/dbcontrol.js @@ -226,29 +226,35 @@ function formatDate(dateString) { 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) { 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; // Filter nach Monat und Jahr const filteredEntries = allEntries.filter(entry => { 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 - if (entryDate.getMonth() + 1 >= 9){ - actualYear = actualYear - 0; - } else { - actualYear = actualYear; - }; - const matchesYear = actualYear ? entryDate.getFullYear() === actualYear : true; + const matchesYear = year ? entryDate.getFullYear() === year : true; 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 function fillTableWithEntries(entries) { const tableBody = document.getElementById('entriesTableBody'); diff --git a/app/static/app/js/home01.js b/app/static/app/js/home01.js index fb9df18..df77087 100644 --- a/app/static/app/js/home01.js +++ b/app/static/app/js/home01.js @@ -215,12 +215,9 @@ async function getActualDataAndFillView(monat = currentDate.getMonth(), jahr = c document.getElementById('monthHourLDC').innerText = formatDuration(sumDurations(filteredEntries,2,true), true) document.getElementById('monthHourOther').innerText = formatDuration(sumDurations(filteredEntries,3,true), true) - // Jahres Ansicht füllen - var requestYear = currentDate.getFullYear() - if (currentDate.getMonth() +1 >= 9) { - requestYear += 1; - } - var yearData = await filterEntriesByMonthYear(null, requestYear) + // Jahres Ansicht füllen (Dienstjahr, gekoppelt an den gerade angezeigten Monat/Jahr) + var requestServiceYear = getServiceYear(new Date(jahr, monat, 1)); + var yearData = await filterEntriesByServiceYear(requestServiceYear) yearData = formatDuration(sumDurations(yearData, null, true), true) document.getElementById('yearHours').innerText = yearData document.getElementById('yearRest').innerText = 600 - parseInt(yearData) @@ -358,7 +355,12 @@ document.getElementById('DeleteEntryButton').addEventListener('click', () => { // 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', () =>{ 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'); }); document.getElementById('MonthNameOfActual').innerHTML = "Monat:" - // document.getElementById('actualMonthName').innerHTML = monate[new Date().getMonth()]; - diffMonth = 0; - getActualDataAndFillView(new Date().getMonth() + diffMonth) + cursorMonth = new Date().getMonth(); + cursorYear = new Date().getFullYear(); + getActualDataAndFillView(cursorMonth, cursorYear) } }) document.getElementById('btn-month-before').addEventListener('click', () =>{ - console.log("CLICK-BEFORE: ", diffMonth) - if (new Date().getMonth() + diffMonth == 0) { - diffMonth = 11 - new Date().getMonth(); - getActualDataAndFillView(new Date().getMonth() + diffMonth) - console.log("CLICK-BEFRORE-0TO11: ", diffMonth) + if (cursorMonth === 0) { + // Januar -> Dezember des Vorjahres + cursorMonth = 11; + cursorYear -= 1; } else { - diffMonth = ((monate[new Date().getMonth() + diffMonth]) != 'September') ? diffMonth - 1 : diffMonth; - // document.getElementById('actualMonthName').innerHTML = monate[new Date().getMonth() + diffMonth]; - getActualDataAndFillView(new Date().getMonth() + diffMonth) - }; - console.log("CLICK-BEFORE-AFTER: ", diffMonth) + cursorMonth -= 1; + } + getActualDataAndFillView(cursorMonth, cursorYear) }); document.getElementById('btn-month-next').addEventListener('click', () =>{ - console.log("CLICK-NEXT: ", diffMonth) - if (new Date().getMonth() + diffMonth == 11) { - diffMonth = 0 - new Date().getMonth(); - getActualDataAndFillView(new Date().getMonth() + diffMonth) - console.log("CLICK-NEXT-11TO0: ", diffMonth) + if (cursorMonth === 11) { + // Dezember -> Januar des Folgejahres + cursorMonth = 0; + cursorYear += 1; } else { - diffMonth = ((monate[new Date().getMonth() + diffMonth]) != 'August') ? diffMonth + 1 : diffMonth; - // document.getElementById('actualMonthName').innerHTML = monate[new Date().getMonth() + diffMonth]; - getActualDataAndFillView(new Date().getMonth() + diffMonth) - }; - console.log("CLICK-NEXT-AFTER: ", diffMonth) + cursorMonth += 1; + } + getActualDataAndFillView(cursorMonth, cursorYear) }) function setNewCalsOfMonth(TheMonth) { -- 2.30.2