From 356c1b329598ee6e42ebc937fba57d68c977d50f Mon Sep 17 00:00:00 2001 From: bartool Date: Tue, 6 Jan 2026 20:58:14 +0100 Subject: [PATCH] fix: update attendance month handling to use lastMonths and correct month indexing --- frontend/src/components/MonthMenu.vue | 14 ++++++-------- frontend/src/stores/attendanceStore.js | 5 +++-- frontend/src/utils/utils.js | 18 ++++++++++++++++++ frontend/src/views/DashboardView.vue | 2 +- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/MonthMenu.vue b/frontend/src/components/MonthMenu.vue index 61576c5..e5cce60 100644 --- a/frontend/src/components/MonthMenu.vue +++ b/frontend/src/components/MonthMenu.vue @@ -6,13 +6,13 @@ @@ -30,15 +30,13 @@ const showMenu = ref(false) const dropdownRef = ref(null) const loading = ref(false) -const select = async (newMonth) => { +const select = async (option) => { // console.log('newMonth: ', newMonth) showMenu.value = false loading.value = true - const year = attendanceStore.year - try { - const response = await getData(year, newMonth) // przykładowa data + const response = await getData(option.year, option.month) // przykładowa data attendanceStore.loadFromResponse(response) } catch (error) { error.value = 'Błąd pobierania danych.' diff --git a/frontend/src/stores/attendanceStore.js b/frontend/src/stores/attendanceStore.js index d87cf35..1c0a38b 100644 --- a/frontend/src/stores/attendanceStore.js +++ b/frontend/src/stores/attendanceStore.js @@ -12,7 +12,8 @@ export const useAttendanceStore = defineStore('attendanceStore', () => { const days = ref([]) // const lastThreeMonth = ['lipiec', 'czerwiec', 'maj'] - const lastThreeMonth = utils.getLastMonths(new Date().getMonth() + 1, 5) + // const lastMonths = ref(utils.getLastMonthsWithYear(5)) + const lastMonths = utils.getLastMonthsWithYear(5) const sumOfHours = computed(() => days.value[days.value.length - 1]?.accumulatedHours || 0) const workedHours = computed(() => sumOfHours.value - holidayHours.value - sickHours.value) const overtimeHours = computed(() => days.value[days.value.length - 1]?.balanceHours || 0) @@ -115,7 +116,7 @@ export const useAttendanceStore = defineStore('attendanceStore', () => { holidayHours, sickHours, toGoHours, - lastThreeMonth, + lastMonths, // actions loadFromResponse, updateDay, diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index 29a66fa..0d2a355 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -253,6 +253,23 @@ function calculateMonthFromDay(startDay, days) { } } +function getLastMonthsWithYear(count) { + const result = [] + const today = new Date() + let year = today.getFullYear() + let month = today.getMonth() // 0-11 + + for (let i = 0; i < count; i++) { + result.push({ year: year, month: month + 1 }) + month-- + if (month < 0) { + month = 11 + year-- + } + } + return result +} + export default { getDayOfWeek, extractTimeFromDateString, @@ -267,4 +284,5 @@ export default { getMonthNumber, getMonthName, daysOfWeek, + getLastMonthsWithYear, } diff --git a/frontend/src/views/DashboardView.vue b/frontend/src/views/DashboardView.vue index 47a8276..749011a 100644 --- a/frontend/src/views/DashboardView.vue +++ b/frontend/src/views/DashboardView.vue @@ -82,7 +82,7 @@ onMounted(async () => { loading.value = true const currentDate = new Date() try { - const response = await getData(currentDate.getFullYear(), currentDate.getMonth()) + const response = await getData(currentDate.getFullYear(), currentDate.getMonth() + 1) input.value = response attendanceStore.loadFromResponse(response) } catch (err) {