feat : ajout de la gestion Congé
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import type { Contract } from '~/services/dto/contract'
|
||||
import type { Absence } from '~/services/dto/absence'
|
||||
import type { EmployeeLeaveSummary } from '~/services/dto/employee-leave-summary'
|
||||
import type { ContractHistoryItem, Employee } from '~/services/dto/employee'
|
||||
import { CONTRACT_TYPES } from '~/services/dto/contract'
|
||||
import { listAbsences } from '~/services/absences'
|
||||
import { listContracts } from '~/services/contracts'
|
||||
import { getEmployeeLeaveSummary } from '~/services/employee-leave-summary'
|
||||
import { getEmployee, updateEmployee } from '~/services/employees'
|
||||
import { formatNullableYmdToFr, getTodayYmd, shiftYmd } from '~/utils/date'
|
||||
import { contractNatureLabel, isContractNature, requiresContractEndDate } from '~/utils/contract'
|
||||
@@ -13,6 +17,8 @@ export const useEmployeeDetailPage = () => {
|
||||
const isLoading = ref(false)
|
||||
const activeTab = ref<'contract' | 'leave' | 'rtt'>('contract')
|
||||
const contracts = ref<Contract[]>([])
|
||||
const employeeAbsences = ref<Absence[]>([])
|
||||
const leaveSummary = ref<EmployeeLeaveSummary | null>(null)
|
||||
const isContractDrawerOpen = ref(false)
|
||||
const isContractSubmitting = ref(false)
|
||||
const isCreateContractDrawerOpen = ref(false)
|
||||
@@ -24,7 +30,8 @@ export const useEmployeeDetailPage = () => {
|
||||
weeklyHours: null as number | null,
|
||||
contractNature: 'CDI' as 'CDI' | 'CDD' | 'INTERIM',
|
||||
startDate: '',
|
||||
endDate: ''
|
||||
endDate: '',
|
||||
paidLeaveSettled: false
|
||||
})
|
||||
|
||||
const validationTouched = reactive({
|
||||
@@ -46,6 +53,7 @@ export const useEmployeeDetailPage = () => {
|
||||
})
|
||||
|
||||
const contractHistory = computed(() => employee.value?.contractHistory ?? [])
|
||||
const showLeaveTab = computed(() => employee.value?.currentContractNature !== 'INTERIM')
|
||||
const employeeContractWorkLabel = computed(() => {
|
||||
const contract = employee.value?.contract
|
||||
if (!contract) return '-'
|
||||
@@ -126,6 +134,7 @@ export const useEmployeeDetailPage = () => {
|
||||
contractForm.contractNature = active.contractNature
|
||||
contractForm.startDate = active.startDate
|
||||
contractForm.endDate = getTodayYmd()
|
||||
contractForm.paidLeaveSettled = false
|
||||
}
|
||||
|
||||
const openCloseContractDrawer = () => {
|
||||
@@ -171,7 +180,35 @@ export const useEmployeeDetailPage = () => {
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
employee.value = await getEmployee(employeeId)
|
||||
const loadedEmployee = await getEmployee(employeeId)
|
||||
employee.value = loadedEmployee
|
||||
|
||||
const now = new Date()
|
||||
const isForfait = loadedEmployee.contract?.type === CONTRACT_TYPES.FORFAIT
|
||||
const leaveYear = isForfait
|
||||
? now.getFullYear()
|
||||
: (now.getMonth() >= 5 ? now.getFullYear() + 1 : now.getFullYear())
|
||||
const from = isForfait
|
||||
? `${leaveYear}-01-01`
|
||||
: `${leaveYear - 1}-06-01`
|
||||
const to = isForfait
|
||||
? `${leaveYear}-12-31`
|
||||
: `${leaveYear}-05-31`
|
||||
const [absences, summary] = await Promise.all([
|
||||
listAbsences({
|
||||
from,
|
||||
to,
|
||||
employeeId: loadedEmployee.id
|
||||
}),
|
||||
showLeaveTab.value
|
||||
? getEmployeeLeaveSummary(loadedEmployee.id, leaveYear)
|
||||
: Promise.resolve(null)
|
||||
])
|
||||
employeeAbsences.value = absences
|
||||
leaveSummary.value = summary
|
||||
if (!showLeaveTab.value && activeTab.value === 'leave') {
|
||||
activeTab.value = 'contract'
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
@@ -198,7 +235,8 @@ export const useEmployeeDetailPage = () => {
|
||||
lastName: employee.value.lastName,
|
||||
siteId: employee.value.site?.id ?? null,
|
||||
contractId: Number(contractForm.contractId),
|
||||
contractEndDate: contractForm.endDate || null
|
||||
contractEndDate: contractForm.endDate || null,
|
||||
contractPaidLeaveSettled: contractForm.paidLeaveSettled
|
||||
})
|
||||
|
||||
isContractDrawerOpen.value = false
|
||||
@@ -262,6 +300,9 @@ export const useEmployeeDetailPage = () => {
|
||||
isLoading,
|
||||
activeTab,
|
||||
contracts,
|
||||
employeeAbsences,
|
||||
leaveSummary,
|
||||
showLeaveTab,
|
||||
contractHistory,
|
||||
employeeContractWorkLabel,
|
||||
contractForm,
|
||||
|
||||
Reference in New Issue
Block a user