fix: update attendance month handling to use lastMonths and correct month indexing
This commit is contained in:
@@ -6,13 +6,13 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
<button
|
<button
|
||||||
v-for="option in attendanceStore.lastThreeMonth"
|
v-for="option in attendanceStore.lastMonths"
|
||||||
:key="option"
|
:key="`${option.year}-${option.month}`"
|
||||||
@click="select(option)"
|
@click="select(option)"
|
||||||
>
|
>
|
||||||
<span class="button-text">
|
<span class="button-text">
|
||||||
<span>{{ utils.getMonthName(option) }}</span>
|
<span>{{ utils.getMonthName(option.month) }}</span>
|
||||||
<span>{{ attendanceStore.year }}</span>
|
<span>{{ option.year }}</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,15 +30,13 @@ const showMenu = ref(false)
|
|||||||
const dropdownRef = ref(null)
|
const dropdownRef = ref(null)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const select = async (newMonth) => {
|
const select = async (option) => {
|
||||||
// console.log('newMonth: ', newMonth)
|
// console.log('newMonth: ', newMonth)
|
||||||
showMenu.value = false
|
showMenu.value = false
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
const year = attendanceStore.year
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getData(year, newMonth) // przykładowa data
|
const response = await getData(option.year, option.month) // przykładowa data
|
||||||
attendanceStore.loadFromResponse(response)
|
attendanceStore.loadFromResponse(response)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.value = 'Błąd pobierania danych.'
|
error.value = 'Błąd pobierania danych.'
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export const useAttendanceStore = defineStore('attendanceStore', () => {
|
|||||||
const days = ref([])
|
const days = ref([])
|
||||||
|
|
||||||
// const lastThreeMonth = ['lipiec', 'czerwiec', 'maj']
|
// 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 sumOfHours = computed(() => days.value[days.value.length - 1]?.accumulatedHours || 0)
|
||||||
const workedHours = computed(() => sumOfHours.value - holidayHours.value - sickHours.value)
|
const workedHours = computed(() => sumOfHours.value - holidayHours.value - sickHours.value)
|
||||||
const overtimeHours = computed(() => days.value[days.value.length - 1]?.balanceHours || 0)
|
const overtimeHours = computed(() => days.value[days.value.length - 1]?.balanceHours || 0)
|
||||||
@@ -115,7 +116,7 @@ export const useAttendanceStore = defineStore('attendanceStore', () => {
|
|||||||
holidayHours,
|
holidayHours,
|
||||||
sickHours,
|
sickHours,
|
||||||
toGoHours,
|
toGoHours,
|
||||||
lastThreeMonth,
|
lastMonths,
|
||||||
// actions
|
// actions
|
||||||
loadFromResponse,
|
loadFromResponse,
|
||||||
updateDay,
|
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 {
|
export default {
|
||||||
getDayOfWeek,
|
getDayOfWeek,
|
||||||
extractTimeFromDateString,
|
extractTimeFromDateString,
|
||||||
@@ -267,4 +284,5 @@ export default {
|
|||||||
getMonthNumber,
|
getMonthNumber,
|
||||||
getMonthName,
|
getMonthName,
|
||||||
daysOfWeek,
|
daysOfWeek,
|
||||||
|
getLastMonthsWithYear,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ onMounted(async () => {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
const currentDate = new Date()
|
const currentDate = new Date()
|
||||||
try {
|
try {
|
||||||
const response = await getData(currentDate.getFullYear(), currentDate.getMonth())
|
const response = await getData(currentDate.getFullYear(), currentDate.getMonth() + 1)
|
||||||
input.value = response
|
input.value = response
|
||||||
attendanceStore.loadFromResponse(response)
|
attendanceStore.loadFromResponse(response)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user