ready to deployment
This commit is contained in:
113
frontend/src/stores/attendanceStore.js
Normal file
113
frontend/src/stores/attendanceStore.js
Normal file
@@ -0,0 +1,113 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import utils from '@/utils/utils.js'
|
||||
|
||||
export const useAttendanceStore = defineStore('attendanceStore', () => {
|
||||
const employee = ref('')
|
||||
const year = ref(null)
|
||||
const month = ref('')
|
||||
const daysInMonth = ref(0)
|
||||
const workingDays = ref(0)
|
||||
const workingHours = ref(0)
|
||||
const days = ref([])
|
||||
|
||||
// const lastThreeMonth = ['lipiec', 'czerwiec', 'maj']
|
||||
const lastThreeMonth = utils.getLastMonths(new Date().getMonth() + 1, 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)
|
||||
const holidayHours = computed(() => holidayCount.value * 8)
|
||||
const sickHours = computed(() => sickCount.value * 6.4)
|
||||
const toGoHours = computed(() => leaveDayCount.value * 8)
|
||||
const sickCount = computed(() => days.value.filter((d) => d.isSickLeave)?.length || 0)
|
||||
const holidayCount = computed(() => days.value.filter((d) => d.isHolidayLeave)?.length || 0)
|
||||
|
||||
const leaveDayCount = computed(() => {
|
||||
console.log('wywylanie leaveFayCount')
|
||||
return (
|
||||
workingDays.value -
|
||||
days.value.filter(
|
||||
(day) =>
|
||||
utils.isValidWorkDay(day) &&
|
||||
(day.workedHours > 0 || day.isSickLeave || day.isHolidayLeave),
|
||||
).length
|
||||
)
|
||||
})
|
||||
|
||||
function updateDay(day) {
|
||||
utils.calculateMonthFromDay(day, days.value)
|
||||
}
|
||||
|
||||
function loadFromResponse(response) {
|
||||
employee.value = response.employee
|
||||
year.value = response.year
|
||||
month.value = response.month
|
||||
daysInMonth.value = response.days_in_month
|
||||
workingDays.value = response.working_days
|
||||
workingHours.value = workingDays.value * 8
|
||||
|
||||
let workingDaysCount = 0
|
||||
let accumulated = 0
|
||||
let balance = 0
|
||||
|
||||
days.value = []
|
||||
|
||||
for (let d = 1; d <= daysInMonth.value; d++) {
|
||||
const dateStr = `${year.value}-${month.value.toString().padStart(2, '0')}-${d.toString().padStart(2, '0')}`
|
||||
const dayData = response.days.find((day) => day.check_in.startsWith(dateStr)) || {}
|
||||
const isPublicHoliday = response.public_holidays.some((h) => h.date === dateStr)
|
||||
const alert = dayData.attendance_reason_ids?.length > 0
|
||||
|
||||
const day = {
|
||||
dayOfMonth: d,
|
||||
dayOfWeek: utils.getDayOfWeek(dateStr),
|
||||
entryTime: utils.extractTimeFromDateString(dayData.check_in),
|
||||
exitTime: utils.extractTimeFromDateString(dayData.check_out),
|
||||
isSickLeave: false,
|
||||
isHolidayLeave: false,
|
||||
isPublicHoliday: isPublicHoliday,
|
||||
workedHours: 0,
|
||||
overtime: 0,
|
||||
accumulatedHours: 0,
|
||||
balanceHours: 0,
|
||||
alert: alert,
|
||||
}
|
||||
|
||||
if (utils.isValidWorkDay(day)) {
|
||||
workingDaysCount++
|
||||
}
|
||||
|
||||
accumulated += utils.calculateDay(day)
|
||||
balance = parseFloat((accumulated - workingDaysCount * 8).toFixed(9))
|
||||
|
||||
day.accumulatedHours = parseFloat(accumulated.toFixed(9))
|
||||
day.balanceHours = balance
|
||||
|
||||
days.value.push(day)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// state
|
||||
employee,
|
||||
year,
|
||||
month,
|
||||
daysInMonth,
|
||||
workingDays,
|
||||
workingHours,
|
||||
days,
|
||||
sickCount,
|
||||
holidayCount,
|
||||
leaveDayCount,
|
||||
sumOfHours,
|
||||
workedHours,
|
||||
overtimeHours,
|
||||
holidayHours,
|
||||
sickHours,
|
||||
toGoHours,
|
||||
lastThreeMonth,
|
||||
// actions
|
||||
loadFromResponse,
|
||||
updateDay,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user