feat : sélecteur d'exercice sur l'onglet RTT de la fiche employé
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled

Permet de consulter les exercices passés (table hebdomadaire RTT) en
réutilisant le pattern de l'onglet Congés. Plage bornée par
max(début historique contrat, RTT_START_DATE). Bouton + Payer les RTT
verrouillé sur exercices clos. Onglet masqué pour FORFAIT (inchangé).

Backend : rttStartDate désormais toujours exposé sur EmployeeRttSummary
pour que le sélecteur conserve sa borne lors de la navigation vers un
exercice passé. Le masquage existant des lignes Report continue de
fonctionner (comparaison mois-à-mois).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-04 09:58:50 +02:00
parent 7cadcfa362
commit 47f9bea57d
7 changed files with 204 additions and 14 deletions

View File

@@ -3,25 +3,94 @@ import type { EmployeeRttSummary } from '~/services/dto/employee-rtt-summary'
import type { Employee } from '~/services/dto/employee'
import { getEmployeeRttSummary, createRttPayment } from '~/services/employee-rtt-summary'
export type RttYearOption = {
value: number
label: string
}
export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: () => Promise<void>) => {
const rttSummary = ref<EmployeeRttSummary | null>(null)
const isRttLoading = ref(false)
const rttDataLoaded = ref(false)
const selectedRttYear = ref<number | null>(null)
// Exercice RTT : Juin (Y-1) → Mai (Y). Toujours, peu importe le type de contrat
// (l'onglet RTT est masqué pour les FORFAIT côté page).
const computeRttYearForDate = (date: Date): number =>
date.getMonth() >= 5 ? date.getFullYear() + 1 : date.getFullYear()
const currentRttYear = computed<number | null>(() => {
if (!employee.value) return null
return computeRttYearForDate(new Date())
})
const availableRttYears = computed<RttYearOption[]>(() => {
if (!employee.value || currentRttYear.value === null) return []
const current = currentRttYear.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
}
// Hard floor : rttStartDate (env RTT_START_DATE) — pas d'historique avant.
let dataFloor: number | null = null
const dataStart = rttSummary.value?.rttStartDate
if (dataStart) {
const dataStartDate = new Date(`${dataStart.substring(0, 10)}T00:00:00`)
if (!Number.isNaN(dataStartDate.getTime())) {
dataFloor = computeRttYearForDate(dataStartDate)
}
}
const minYear = dataFloor !== null ? Math.max(contractFloor, dataFloor) : contractFloor
const years: RttYearOption[] = []
for (let y = current; y >= minYear; y -= 1) {
years.push({ value: y, label: `Juin ${y - 1} → Mai ${y}` })
}
return years
})
const initSelectedRttYear = () => {
if (selectedRttYear.value !== null) return
if (currentRttYear.value !== null) {
selectedRttYear.value = currentRttYear.value
}
}
const loadRttData = async () => {
if (!employee.value || isRttLoading.value) return
initSelectedRttYear()
if (selectedRttYear.value === null) return
isRttLoading.value = true
try {
const rttYear = new Date().getMonth() >= 5 ? new Date().getFullYear() + 1 : new Date().getFullYear()
rttSummary.value = await getEmployeeRttSummary(employee.value.id, rttYear)
rttSummary.value = await getEmployeeRttSummary(employee.value.id, selectedRttYear.value)
rttDataLoaded.value = true
} finally {
isRttLoading.value = false
}
}
const setSelectedRttYear = async (year: number) => {
if (selectedRttYear.value === year) return
selectedRttYear.value = year
rttDataLoaded.value = false
await loadRttData()
}
const resetLoaded = () => {
rttDataLoaded.value = false
selectedRttYear.value = null
}
const submitRttPayment = async (month: number, base25Minutes: number, bonus25Minutes: number, base50Minutes: number, bonus50Minutes: number) => {
@@ -35,6 +104,10 @@ export const useEmployeeRtt = (employee: Ref<Employee | null>, reloadEmployee: (
rttSummary,
isRttLoading,
rttDataLoaded,
selectedRttYear,
currentRttYear,
availableRttYears,
setSelectedRttYear,
loadRttData,
resetLoaded,
submitRttPayment