fix: update attendance month handling to use lastMonths and correct month indexing
This commit is contained in:
@@ -6,13 +6,13 @@
|
||||
</button>
|
||||
<div class="dropdown-content">
|
||||
<button
|
||||
v-for="option in attendanceStore.lastThreeMonth"
|
||||
:key="option"
|
||||
v-for="option in attendanceStore.lastMonths"
|
||||
:key="`${option.year}-${option.month}`"
|
||||
@click="select(option)"
|
||||
>
|
||||
<span class="button-text">
|
||||
<span>{{ utils.getMonthName(option) }}</span>
|
||||
<span>{{ attendanceStore.year }}</span>
|
||||
<span>{{ utils.getMonthName(option.month) }}</span>
|
||||
<span>{{ option.year }}</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -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.'
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user