feat(rtt) : phase-aware RTT tab loading
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Ref } from 'vue'
|
||||
import type { ContractPhase } from '~/services/dto/contract-phase'
|
||||
import type { EmployeeRttSummary } from '~/services/dto/employee-rtt-summary'
|
||||
import type { Employee } from '~/services/dto/employee'
|
||||
import { getEmployeeRttSummary, createRttPayment } from '~/services/employee-rtt-summary'
|
||||
@@ -8,7 +9,11 @@ export type RttYearOption = {
|
||||
label: string
|
||||
}
|
||||
|
||||
export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: () => Promise<void>) => {
|
||||
export const useEmployeeRtt = (
|
||||
employee: Ref<Employee | null>,
|
||||
reloadEmployee: () => Promise<void>,
|
||||
selectedPhase: Ref<ContractPhase | null>,
|
||||
) => {
|
||||
const rttSummary = ref<EmployeeRttSummary | null>(null)
|
||||
const isRttLoading = ref(false)
|
||||
const rttDataLoaded = ref(false)
|
||||
@@ -25,22 +30,14 @@ export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: (
|
||||
})
|
||||
|
||||
const availableRttYears = computed<RttYearOption[]>(() => {
|
||||
if (!employee.value || currentRttYear.value === null) return []
|
||||
const current = currentRttYear.value
|
||||
if (!employee.value || !selectedPhase.value || currentRttYear.value === null) return []
|
||||
const phase = selectedPhase.value
|
||||
|
||||
const startDates: string[] = []
|
||||
for (const period of employee.value.contractHistory ?? []) {
|
||||
if (period.startDate) startDates.push(period.startDate)
|
||||
}
|
||||
if (employee.value.entryDate) startDates.push(employee.value.entryDate)
|
||||
|
||||
let contractFloor = current
|
||||
for (const raw of startDates) {
|
||||
const date = new Date(`${raw.substring(0, 10)}T00:00:00`)
|
||||
if (Number.isNaN(date.getTime())) continue
|
||||
const rttYear = computeRttYearForDate(date)
|
||||
if (rttYear < contractFloor) contractFloor = rttYear
|
||||
}
|
||||
// Plage = exercices intersectant la phase.
|
||||
const phaseStartYear = computeRttYearForDate(new Date(`${phase.startDate}T00:00:00`))
|
||||
const phaseEndYear = phase.endDate
|
||||
? computeRttYearForDate(new Date(`${phase.endDate}T00:00:00`))
|
||||
: currentRttYear.value
|
||||
|
||||
// Hard floor : rttStartDate (env RTT_START_DATE) — pas d'historique avant.
|
||||
let dataFloor: number | null = null
|
||||
@@ -52,10 +49,11 @@ export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: (
|
||||
}
|
||||
}
|
||||
|
||||
const minYear = dataFloor !== null ? Math.max(contractFloor, dataFloor) : contractFloor
|
||||
const minYear = dataFloor !== null ? Math.max(phaseStartYear, dataFloor) : phaseStartYear
|
||||
const maxYear = phaseEndYear
|
||||
|
||||
const years: RttYearOption[] = []
|
||||
for (let y = current; y >= minYear; y -= 1) {
|
||||
for (let y = maxYear; y >= minYear; y -= 1) {
|
||||
years.push({ value: y, label: `Juin ${y - 1} → Mai ${y}` })
|
||||
}
|
||||
return years
|
||||
@@ -74,7 +72,11 @@ export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: (
|
||||
if (selectedRttYear.value === null) return
|
||||
isRttLoading.value = true
|
||||
try {
|
||||
rttSummary.value = await getEmployeeRttSummary(employee.value.id, selectedRttYear.value)
|
||||
rttSummary.value = await getEmployeeRttSummary(
|
||||
employee.value.id,
|
||||
selectedRttYear.value,
|
||||
selectedPhase.value?.id,
|
||||
)
|
||||
rttDataLoaded.value = true
|
||||
} finally {
|
||||
isRttLoading.value = false
|
||||
@@ -93,6 +95,13 @@ export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: (
|
||||
selectedRttYear.value = null
|
||||
}
|
||||
|
||||
watch(() => selectedPhase.value?.id, () => {
|
||||
// Reset l'année car la plage a peut-être changé.
|
||||
selectedRttYear.value = null
|
||||
rttDataLoaded.value = false
|
||||
// Le rechargement effectif est piloté par useEmployeeDetailPage.
|
||||
})
|
||||
|
||||
const submitRttPayment = async (month: number, base25Minutes: number, bonus25Minutes: number, base50Minutes: number, bonus50Minutes: number) => {
|
||||
if (!employee.value) return
|
||||
const year = rttSummary.value?.year ?? undefined
|
||||
|
||||
Reference in New Issue
Block a user