Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ec1e1f10d | ||
| 24b7512c8a | |||
| f047e3ed4b | |||
|
|
1feedd0381 | ||
| f9cd5a0143 | |||
|
|
ede7decaa7 | ||
| 2cfb05e5de | |||
|
|
0a8399a950 | ||
| 6a64cb4c58 | |||
|
|
facded4c55 | ||
| 9787231052 | |||
|
|
8563ddb08c | ||
| 353d4d9d2b | |||
|
|
8745e5e425 | ||
| 4d8c850a77 | |||
| 1974ace1f2 |
6
.idea/sqldialects.xml
generated
Normal file
6
.idea/sqldialects.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/sirh.sql" dialect="GenericSQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.48'
|
app.version: '0.1.55'
|
||||||
|
|||||||
@@ -212,12 +212,19 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
|
|||||||
- en cours d'acquisition jours: `25/12 = 2,08` jours/mois
|
- en cours d'acquisition jours: `25/12 = 2,08` jours/mois
|
||||||
- en cours d'acquisition samedis: `5/12 = 0,42` samedi/mois (non detaille en UI)
|
- en cours d'acquisition samedis: `5/12 = 0,42` samedi/mois (non detaille en UI)
|
||||||
- en cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
|
- en cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
|
||||||
|
- en cas de suspension en cours de mois, l'acquisition est proratisée en jours ouvrés (lun-ven hors fériés) travaillés / 22 (standard mensuel)
|
||||||
|
- arrêt maladie long (absences continues de type `M` > 1 mois):
|
||||||
|
- premier mois de maladie (date début + 1 mois calendaire): acquisition normale (`2,50`/mois)
|
||||||
|
- après le premier mois: acquisition réduite à `2,00`/mois (facteur `0,80` appliqué aux deux taux jours et samedis)
|
||||||
|
- en cas de mois partiellement couvert par la période réduite, le prorata est calculé en jours calendaires (jours normaux × taux normal + jours réduits × taux réduit)
|
||||||
|
- la détection est automatique à partir des absences MALADIE consécutives en base (tolérance de gap ≤ 3 jours)
|
||||||
- samedis acquis affiches: uniquement `opening_saturdays` (report N-1)
|
- samedis acquis affiches: uniquement `opening_saturdays` (report N-1)
|
||||||
- contrat `4h`:
|
- contrat `4h`:
|
||||||
- acquis annuel CP: `10`
|
- acquis annuel CP: `10`
|
||||||
- acquis annuel samedi: `0`
|
- acquis annuel samedi: `0`
|
||||||
- en cours d'acquisition: `0.83` jour/mois
|
- en cours d'acquisition: `0.83` jour/mois
|
||||||
- en cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
|
- en cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
|
||||||
|
- en cas de suspension en cours de mois, l'acquisition est proratisée en jours ouvrés (lun-ven hors fériés) travaillés / 22
|
||||||
- contrat `FORFAIT`:
|
- contrat `FORFAIT`:
|
||||||
- base annuelle: `jours ouvrés de l'exercice (lundi-vendredi, hors jours fériés métropole) - 218`
|
- base annuelle: `jours ouvrés de l'exercice (lundi-vendredi, hors jours fériés métropole) - 218`
|
||||||
- prorata: en cas de démarrage/fin de contrat en cours d'année civile, le calcul ne couvre que l'intervalle actif du contrat dans l'année
|
- prorata: en cas de démarrage/fin de contrat en cours d'année civile, le calcul ne couvre que l'intervalle actif du contrat dans l'année
|
||||||
@@ -337,7 +344,24 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
|
|||||||
| CHAUFFEUR - samedi | WorkHour (samedi) | Samedis travaillés (chauffeurs uniquement) |
|
| CHAUFFEUR - samedi | WorkHour (samedi) | Samedis travaillés (chauffeurs uniquement) |
|
||||||
| Observations | — | Colonne vide pour saisie manuelle |
|
| Observations | — | Colonne vide pour saisie manuelle |
|
||||||
|
|
||||||
## 12) Notifications
|
## 12) Frais
|
||||||
|
|
||||||
|
- Onglet "Frais" sur la fiche employé (icône `mdi:account-cash-outline`)
|
||||||
|
- Entité `MileageAllowance` (table `mileage_allowances`)
|
||||||
|
- Champs:
|
||||||
|
- `month` (mois, obligatoire)
|
||||||
|
- `kilometers` (nombre de km, optionnel)
|
||||||
|
- `amount` (montant en €, optionnel)
|
||||||
|
- `comment` (commentaire, optionnel)
|
||||||
|
- `receiptPath` / `receiptName` (justificatif PDF)
|
||||||
|
- Règle de validation:
|
||||||
|
- le mois est obligatoire
|
||||||
|
- au moins un des deux champs `kilometers` ou `amount` doit être > 0
|
||||||
|
- les deux peuvent être remplis simultanément
|
||||||
|
- Tableau: colonnes Mois, Nombre de Km, Montant €, Commentaire, Justificatif
|
||||||
|
- Justificatif: upload PDF uniquement, téléchargement via endpoint dédié
|
||||||
|
|
||||||
|
## 13) Notifications
|
||||||
|
|
||||||
- Icône cloche en topbar:
|
- Icône cloche en topbar:
|
||||||
- badge = nombre de notifications non lues
|
- badge = nombre de notifications non lues
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
<template>
|
<template>
|
||||||
<section class="flex h-full min-h-0 flex-col overflow-hidden pt-8">
|
<section class="flex h-full min-h-0 flex-col overflow-hidden pt-8">
|
||||||
<div class="grid grid-cols-4 rounded-md bg-tertiary-500 text-primary-500 text-[18px] border border-primary-500">
|
<div class="grid grid-cols-4 rounded-md bg-tertiary-500 text-primary-500 text-[18px] border border-primary-500">
|
||||||
<p class="col-start-1 p-[10px] border-b border-b-black"><strong class="uppercase font-semibold">Année acquis :</strong> {{
|
<p class="col-start-1 p-[10px] border-b border-r border-primary-500"><strong class="uppercase font-semibold">Année acquis :</strong> {{
|
||||||
formatCount(summary?.acquiredDays)
|
formatCount(summary?.acquiredDays)
|
||||||
}} Jours
|
}} Jours
|
||||||
</p>
|
</p>
|
||||||
<p class="col-start-2 p-[10px] border-b border-b-black"><strong class="uppercase font-semibold">Pris :</strong>
|
<p class="col-start-2 p-[10px] border-b border-r border-primary-500"><strong class="uppercase font-semibold">Pris :</strong>
|
||||||
{{ formatCount(isForfaitRule ? currentYearTakenDays : summary?.takenDays) }} Jours
|
{{ formatCount(isForfaitRule ? currentYearTakenDays : summary?.takenDays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p class="col-start-3 p-[10px] border-b border-b-black"><strong class="uppercase font-semibold">Reste à prendre :</strong>
|
<p class="col-start-3 p-[10px] border-b border-r border-b-white border-r-primary-500 bg-primary-500 text-white"><strong class="uppercase font-semibold">Reste à prendre :</strong>
|
||||||
{{ formatCount(summary?.remainingDays) }} Jours
|
{{ formatCount(summary?.remainingDays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p class="col-start-4 p-[10px] border-b border-b-black"><strong class="uppercase font-semibold">En cours d'acquisition :</strong>
|
<p class="col-start-4 p-[10px] border-b border-primary-500"><strong class="uppercase font-semibold">En cours d'acquisition :</strong>
|
||||||
{{ formatCount(summary?.accruingDays) }} Jours
|
{{ formatCount(summary?.accruingDays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p v-if="!isForfaitRule" class="col-start-1 p-[10px]"><span class="uppercase font-semibold">Samedi acquis :</span>
|
<p v-if="!isForfaitRule" class="col-start-1 p-[10px] border-r border-primary-500"><span class="uppercase font-semibold">Samedi acquis :</span>
|
||||||
{{ formatCount(summary?.acquiredSaturdays) }} Jours
|
{{ formatCount(summary?.acquiredSaturdays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p v-else class="col-start-1 p-[10px]"><span class="uppercase font-semibold">Année N-1 acquis :</span>
|
<p v-else class="col-start-1 p-[10px] border-r border-primary-500"><span class="uppercase font-semibold">Année N-1 acquis :</span>
|
||||||
{{ formatCount(summary?.previousYearAcquiredDays) }} Jours
|
{{ formatCount(summary?.previousYearAcquiredDays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p v-if="!isForfaitRule" class="col-start-2 p-[10px]"><span class="uppercase font-semibold">Pris :</span>
|
<p v-if="!isForfaitRule" class="col-start-2 p-[10px] border-r border-primary-500"><span class="uppercase font-semibold">Pris :</span>
|
||||||
{{ formatCount(summary?.takenSaturdays) }} Jours
|
{{ formatCount(summary?.takenSaturdays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p v-if="!isForfaitRule" class="col-start-3 p-[10px]"><span class="uppercase font-semibold">Reste à prendre :</span>
|
<p v-if="!isForfaitRule" class="col-start-3 p-[10px] border-r border-r-primary-500 bg-primary-500 text-white"><span class="uppercase font-semibold">Reste à prendre :</span>
|
||||||
{{ formatCount(summary?.remainingSaturdays) }} Jours
|
{{ formatCount(summary?.remainingSaturdays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p v-else class="col-start-2 p-[10px]"><span class="uppercase font-semibold">Pris :</span>
|
<p v-else class="col-start-2 p-[10px] border-r border-primary-500"><span class="uppercase font-semibold">Pris :</span>
|
||||||
{{ formatCount(summary?.previousYearTakenDays) }} Jours
|
{{ formatCount(summary?.previousYearTakenDays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<p v-if="isForfaitRule" class="col-start-3 p-[10px]"><span class="uppercase font-semibold">Reste à prendre :</span>
|
<p v-if="isForfaitRule" class="col-start-3 p-[10px] border-r-primary-500 bg-primary-500 text-white"><span class="uppercase font-semibold">Reste à prendre :</span>
|
||||||
{{ formatCount(summary?.previousYearRemainingDays) }} Jours
|
{{ formatCount(summary?.previousYearRemainingDays) }} Jours
|
||||||
</p>
|
</p>
|
||||||
<div v-if="!isForfaitRule" class="col-start-4 p-[10px] flex gap-7 items-center">
|
<div v-if="!isForfaitRule" class="col-start-4 p-[10px] flex gap-7 items-center">
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
<section class="mt-8">
|
<section class="mt-8">
|
||||||
<div class="overflow-hidden bg-white">
|
<div class="overflow-hidden bg-white">
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-4 border border-black bg-tertiary-500 px-6 py-3 text-[20px] font-semibold text-black rounded-t-md">
|
class="grid grid-cols-5 border border-black bg-tertiary-500 px-6 py-3 text-[20px] font-semibold text-black rounded-t-md">
|
||||||
<p>Mois</p>
|
<p>Mois</p>
|
||||||
<p>Nombre de Km</p>
|
<p>Nombre de Km</p>
|
||||||
|
<p>Montant €</p>
|
||||||
<p>Commentaire</p>
|
<p>Commentaire</p>
|
||||||
<p>Justificatif</p>
|
<p>Justificatif</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -15,11 +16,12 @@
|
|||||||
<div
|
<div
|
||||||
v-for="item in allowances"
|
v-for="item in allowances"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
class="grid grid-cols-4 border-b border-primary-500 px-6 py-3 text-md font-bold text-primary-500 last:border-b-0 cursor-pointer hover:bg-tertiary-500"
|
class="grid grid-cols-5 border-b border-primary-500 px-6 py-3 text-md font-bold text-primary-500 last:border-b-0 cursor-pointer hover:bg-tertiary-500"
|
||||||
@click="onOpenEditDrawer(item)"
|
@click="onOpenEditDrawer(item)"
|
||||||
>
|
>
|
||||||
<p>{{ formatMonth(item.month) }}</p>
|
<p>{{ formatMonth(item.month) }}</p>
|
||||||
<p>{{ item.kilometers }}</p>
|
<p>{{ item.kilometers }}</p>
|
||||||
|
<p>{{ item.amount ? item.amount + ' €' : '-' }}</p>
|
||||||
<p>{{ item.comment ?? '-' }}</p>
|
<p>{{ item.comment ?? '-' }}</p>
|
||||||
<p>
|
<p>
|
||||||
<a
|
<a
|
||||||
@@ -48,7 +50,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<AppDrawer v-model="isDrawerOpen" title="Frais Kms">
|
<AppDrawer v-model="isDrawerOpen" title="Frais">
|
||||||
<form class="space-y-4" @submit.prevent="onSubmit">
|
<form class="space-y-4" @submit.prevent="onSubmit">
|
||||||
<div>
|
<div>
|
||||||
<label class="text-md font-semibold text-neutral-700" for="mileage-month">
|
<label class="text-md font-semibold text-neutral-700" for="mileage-month">
|
||||||
@@ -64,7 +66,7 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="text-md font-semibold text-neutral-700" for="mileage-kilometers">
|
<label class="text-md font-semibold text-neutral-700" for="mileage-kilometers">
|
||||||
Nombre de Km <span class="text-red-600">*</span>
|
Nombre de Km
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
id="mileage-kilometers"
|
id="mileage-kilometers"
|
||||||
@@ -76,6 +78,21 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="text-md font-semibold text-neutral-700" for="mileage-amount">
|
||||||
|
Montant (€)
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="mileage-amount"
|
||||||
|
v-model.number="form.amount"
|
||||||
|
type="number"
|
||||||
|
step="0.01"
|
||||||
|
min="0"
|
||||||
|
class="mt-2 w-full rounded-md border border-neutral-300 px-3 py-2 text-base text-neutral-900 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-secondary-500/20"
|
||||||
|
/>
|
||||||
|
<p class="mt-1 text-sm text-neutral-500">Au moins un des deux champs doit être rempli</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="text-md font-semibold text-neutral-700" for="mileage-receipt">
|
<label class="text-md font-semibold text-neutral-700" for="mileage-receipt">
|
||||||
Justificatif
|
Justificatif
|
||||||
@@ -148,8 +165,8 @@ const props = defineProps<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(event: 'create', data: { month: string; kilometers: number; comment?: string }, file?: File): void
|
(event: 'create', data: { month: string; kilometers: number; amount: number; comment?: string }, file?: File): void
|
||||||
(event: 'update', id: number, data: { month: string; kilometers: number; comment?: string }, file?: File): void
|
(event: 'update', id: number, data: { month: string; kilometers: number; amount: number; comment?: string }, file?: File): void
|
||||||
(event: 'delete', id: number): void
|
(event: 'delete', id: number): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
@@ -168,11 +185,12 @@ const currentYearMonth = () => {
|
|||||||
const form = reactive({
|
const form = reactive({
|
||||||
month: currentYearMonth(),
|
month: currentYearMonth(),
|
||||||
kilometers: 0,
|
kilometers: 0,
|
||||||
|
amount: 0,
|
||||||
comment: ''
|
comment: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const isFormValid = computed(() => {
|
const isFormValid = computed(() => {
|
||||||
return form.month && form.kilometers > 0 && !fileError.value
|
return form.month && (form.kilometers > 0 || form.amount > 0) && !fileError.value
|
||||||
})
|
})
|
||||||
|
|
||||||
const monthLabels: Record<number, string> = {
|
const monthLabels: Record<number, string> = {
|
||||||
@@ -201,6 +219,7 @@ const formatMonth = (dateStr: string): string => {
|
|||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
form.month = currentYearMonth()
|
form.month = currentYearMonth()
|
||||||
form.kilometers = 0
|
form.kilometers = 0
|
||||||
|
form.amount = 0
|
||||||
form.comment = ''
|
form.comment = ''
|
||||||
selectedFile.value = undefined
|
selectedFile.value = undefined
|
||||||
fileError.value = ''
|
fileError.value = ''
|
||||||
@@ -222,6 +241,7 @@ const onOpenEditDrawer = (item: MileageAllowance) => {
|
|||||||
// Extract YYYY-MM from YYYY-MM-DD
|
// Extract YYYY-MM from YYYY-MM-DD
|
||||||
form.month = item.month.substring(0, 7)
|
form.month = item.month.substring(0, 7)
|
||||||
form.kilometers = item.kilometers
|
form.kilometers = item.kilometers
|
||||||
|
form.amount = item.amount
|
||||||
form.comment = item.comment ?? ''
|
form.comment = item.comment ?? ''
|
||||||
selectedFile.value = undefined
|
selectedFile.value = undefined
|
||||||
if (fileInput.value) {
|
if (fileInput.value) {
|
||||||
@@ -247,6 +267,7 @@ const onSubmit = () => {
|
|||||||
const data = {
|
const data = {
|
||||||
month: `${form.month}-01`,
|
month: `${form.month}-01`,
|
||||||
kilometers: form.kilometers,
|
kilometers: form.kilometers,
|
||||||
|
amount: form.amount,
|
||||||
comment: form.comment || undefined
|
comment: form.comment || undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-[16px]">
|
<p class="text-[16px]">
|
||||||
<span class="font-bold">RTT À LA DATE DU JOUR :</span>
|
<span class="font-bold">RTT À LA SEMAINE {{ lastCompleteWeek }} : </span>
|
||||||
{{ formatMinutes(summary?.availableMinutes ?? 0) }}
|
<span class="font-bold">{{ formatMinutes(summary?.availableMinutes ?? 0) }}</span>
|
||||||
</p>
|
</p>
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
<button
|
<button
|
||||||
@@ -258,6 +258,17 @@ const emit = defineEmits<{
|
|||||||
(event: 'submit-rtt-payment', month: number, base25Minutes: number, bonus25Minutes: number, base50Minutes: number, bonus50Minutes: number): void
|
(event: 'submit-rtt-payment', month: number, base25Minutes: number, bonus25Minutes: number, base50Minutes: number, bonus50Minutes: number): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
// --- Last complete week number ---
|
||||||
|
|
||||||
|
const lastCompleteWeek = computed(() => {
|
||||||
|
const now = new Date()
|
||||||
|
const startOfYear = new Date(now.getFullYear(), 0, 1)
|
||||||
|
const dayOfYear = Math.floor((now.getTime() - startOfYear.getTime()) / 86400000) + 1
|
||||||
|
const dayOfWeek = now.getDay() || 7 // Monday = 1, Sunday = 7
|
||||||
|
const currentWeek = Math.ceil((dayOfYear - dayOfWeek + 10) / 7)
|
||||||
|
return currentWeek - 1
|
||||||
|
})
|
||||||
|
|
||||||
// --- Month navigation ---
|
// --- Month navigation ---
|
||||||
|
|
||||||
const orderedMonths = [6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5] as const
|
const orderedMonths = [6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5] as const
|
||||||
|
|||||||
@@ -32,12 +32,13 @@ export const useEmployeeMileage = (employee: Ref<Employee | null>, reloadEmploye
|
|||||||
mileageDataLoaded.value = false
|
mileageDataLoaded.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitCreateMileage = async (data: { month: string; kilometers: number; comment?: string }, file?: File) => {
|
const submitCreateMileage = async (data: { month: string; kilometers: number; amount: number; comment?: string }, file?: File) => {
|
||||||
if (!employee.value) return
|
if (!employee.value) return
|
||||||
const result = await createMileageAllowance({
|
const result = await createMileageAllowance({
|
||||||
employeeId: employee.value.id,
|
employeeId: employee.value.id,
|
||||||
month: data.month,
|
month: data.month,
|
||||||
kilometers: data.kilometers,
|
kilometers: data.kilometers,
|
||||||
|
amount: data.amount,
|
||||||
comment: data.comment
|
comment: data.comment
|
||||||
})
|
})
|
||||||
if (file && result?.id) {
|
if (file && result?.id) {
|
||||||
@@ -46,7 +47,7 @@ export const useEmployeeMileage = (employee: Ref<Employee | null>, reloadEmploye
|
|||||||
await reloadEmployee()
|
await reloadEmployee()
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitUpdateMileage = async (id: number, data: { month: string; kilometers: number; comment?: string }, file?: File) => {
|
const submitUpdateMileage = async (id: number, data: { month: string; kilometers: number; amount: number; comment?: string }, file?: File) => {
|
||||||
await updateMileageAllowance(id, data)
|
await updateMileageAllowance(id, data)
|
||||||
if (file) {
|
if (file) {
|
||||||
await uploadReceipt(apiBase, id, file)
|
await uploadReceipt(apiBase, id, file)
|
||||||
|
|||||||
@@ -1045,7 +1045,7 @@ export const useHoursPage = () => {
|
|||||||
isSubmitting.value = true
|
isSubmitting.value = true
|
||||||
try {
|
try {
|
||||||
const entries = employees.value
|
const entries = employees.value
|
||||||
.filter((employee) => hasContractAtSelectedDate(employee.id))
|
.filter((employee) => hasContractAtSelectedDate(employee.id) && !isRowLocked(employee.id))
|
||||||
.map((employee) => {
|
.map((employee) => {
|
||||||
const employeeId = employee.id
|
const employeeId = employee.id
|
||||||
const row = rows.value[employeeId] ?? emptyRow()
|
const row = rows.value[employeeId] ?? emptyRow()
|
||||||
|
|||||||
@@ -62,8 +62,8 @@
|
|||||||
: 'border-transparent text-primary-500/50 hover:text-primary-500'"
|
: 'border-transparent text-primary-500/50 hover:text-primary-500'"
|
||||||
@click="activeTab = 'mileage'"
|
@click="activeTab = 'mileage'"
|
||||||
>
|
>
|
||||||
<Icon name="mdi:car-outline" size="24" class="align-self"/>
|
<Icon name="mdi:account-cash-outline" size="24" class="align-self"/>
|
||||||
Frais Kms
|
Frais
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="pb-2 border-b-2 flex items-center gap-3"
|
class="pb-2 border-b-2 flex items-center gap-3"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export type MileageAllowance = {
|
|||||||
id: number
|
id: number
|
||||||
month: string
|
month: string
|
||||||
kilometers: number
|
kilometers: number
|
||||||
|
amount: number
|
||||||
comment: string | null
|
comment: string | null
|
||||||
receiptPath: string | null
|
receiptPath: string | null
|
||||||
receiptName: string | null
|
receiptName: string | null
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const createMileageAllowance = async (data: {
|
|||||||
employeeId: number
|
employeeId: number
|
||||||
month: string
|
month: string
|
||||||
kilometers: number
|
kilometers: number
|
||||||
|
amount: number
|
||||||
comment?: string
|
comment?: string
|
||||||
}) => {
|
}) => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
@@ -23,6 +24,7 @@ export const createMileageAllowance = async (data: {
|
|||||||
employee: `/api/employees/${data.employeeId}`,
|
employee: `/api/employees/${data.employeeId}`,
|
||||||
month: data.month,
|
month: data.month,
|
||||||
kilometers: data.kilometers,
|
kilometers: data.kilometers,
|
||||||
|
amount: data.amount,
|
||||||
comment: data.comment
|
comment: data.comment
|
||||||
}, {
|
}, {
|
||||||
toastSuccessKey: 'success.mileage.create',
|
toastSuccessKey: 'success.mileage.create',
|
||||||
@@ -33,12 +35,14 @@ export const createMileageAllowance = async (data: {
|
|||||||
export const updateMileageAllowance = async (id: number, data: {
|
export const updateMileageAllowance = async (id: number, data: {
|
||||||
month: string
|
month: string
|
||||||
kilometers: number
|
kilometers: number
|
||||||
|
amount: number
|
||||||
comment?: string
|
comment?: string
|
||||||
}) => {
|
}) => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
return api.patch<MileageAllowance>(`/mileage_allowances/${id}`, {
|
return api.patch<MileageAllowance>(`/mileage_allowances/${id}`, {
|
||||||
month: data.month,
|
month: data.month,
|
||||||
kilometers: data.kilometers,
|
kilometers: data.kilometers,
|
||||||
|
amount: data.amount,
|
||||||
comment: data.comment
|
comment: data.comment
|
||||||
}, {
|
}, {
|
||||||
toastSuccessKey: 'success.mileage.update',
|
toastSuccessKey: 'success.mileage.update',
|
||||||
|
|||||||
26
migrations/Version20260318143503.php
Normal file
26
migrations/Version20260318143503.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20260318143503 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add amount column to mileage_allowances';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE mileage_allowances ADD COLUMN amount DOUBLE PRECISION DEFAULT 0 NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE mileage_allowances DROP COLUMN amount');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ use App\State\EmployeeLeaveSummaryProvider;
|
|||||||
operations: [
|
operations: [
|
||||||
new Get(
|
new Get(
|
||||||
uriTemplate: '/employees/{id}/leave-summary',
|
uriTemplate: '/employees/{id}/leave-summary',
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_ADMIN')",
|
||||||
provider: EmployeeLeaveSummaryProvider::class
|
provider: EmployeeLeaveSummaryProvider::class
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use App\State\EmployeeRttSummaryProvider;
|
|||||||
operations: [
|
operations: [
|
||||||
new Get(
|
new Get(
|
||||||
uriTemplate: '/employees/{id}/rtt-summary',
|
uriTemplate: '/employees/{id}/rtt-summary',
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_ADMIN')",
|
||||||
provider: EmployeeRttSummaryProvider::class
|
provider: EmployeeRttSummaryProvider::class
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
new Get(
|
new Get(
|
||||||
security: "is_granted('ROLE_USER')"
|
security: "is_granted('ROLE_ADMIN')"
|
||||||
),
|
),
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
security: "is_granted('ROLE_USER')"
|
security: "is_granted('ROLE_ADMIN')"
|
||||||
),
|
),
|
||||||
new Post(
|
new Post(
|
||||||
security: "is_granted('ROLE_ADMIN')"
|
security: "is_granted('ROLE_ADMIN')"
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
new Get(
|
new Get(
|
||||||
security: "is_granted('ROLE_USER')"
|
security: "is_granted('ROLE_ADMIN')"
|
||||||
),
|
),
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
security: "is_granted('ROLE_USER')"
|
security: "is_granted('ROLE_ADMIN')"
|
||||||
),
|
),
|
||||||
new Post(
|
new Post(
|
||||||
security: "is_granted('ROLE_ADMIN')"
|
security: "is_granted('ROLE_ADMIN')"
|
||||||
@@ -47,7 +47,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
),
|
),
|
||||||
new Get(
|
new Get(
|
||||||
uriTemplate: '/mileage_allowances/{id}/receipt',
|
uriTemplate: '/mileage_allowances/{id}/receipt',
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_ADMIN')",
|
||||||
provider: MileageAllowanceReceiptDownloadProvider::class,
|
provider: MileageAllowanceReceiptDownloadProvider::class,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -87,6 +87,10 @@ class MileageAllowance
|
|||||||
#[Groups(['mileage_allowance:read', 'mileage_allowance:write'])]
|
#[Groups(['mileage_allowance:read', 'mileage_allowance:write'])]
|
||||||
private float $kilometers = 0;
|
private float $kilometers = 0;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'float', options: ['default' => 0])]
|
||||||
|
#[Groups(['mileage_allowance:read', 'mileage_allowance:write'])]
|
||||||
|
private float $amount = 0;
|
||||||
|
|
||||||
#[ORM\Column(type: 'text', nullable: true)]
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
#[Groups(['mileage_allowance:read', 'mileage_allowance:write'])]
|
#[Groups(['mileage_allowance:read', 'mileage_allowance:write'])]
|
||||||
private ?string $comment = null;
|
private ?string $comment = null;
|
||||||
@@ -149,6 +153,18 @@ class MileageAllowance
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAmount(): float
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount(float $amount): self
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getComment(): ?string
|
public function getComment(): ?string
|
||||||
{
|
{
|
||||||
return $this->comment;
|
return $this->comment;
|
||||||
|
|||||||
@@ -100,6 +100,38 @@ final class AbsenceRepository extends ServiceEntityRepository implements Absence
|
|||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<DateTimeImmutable> sorted maladie dates
|
||||||
|
*/
|
||||||
|
public function findMaladieDatesByEmployee(
|
||||||
|
Employee $employee,
|
||||||
|
DateTimeImmutable $from,
|
||||||
|
DateTimeImmutable $to
|
||||||
|
): array {
|
||||||
|
$results = $this->createQueryBuilder('a')
|
||||||
|
->select('a.startDate')
|
||||||
|
->join('a.type', 't')
|
||||||
|
->andWhere('a.employee = :employee')
|
||||||
|
->andWhere('t.code = :code')
|
||||||
|
->andWhere('a.startDate >= :from')
|
||||||
|
->andWhere('a.startDate <= :to')
|
||||||
|
->setParameter('employee', $employee)
|
||||||
|
->setParameter('code', 'M')
|
||||||
|
->setParameter('from', $from)
|
||||||
|
->setParameter('to', $to)
|
||||||
|
->orderBy('a.startDate', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getArrayResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
return array_map(
|
||||||
|
static fn (array $row): DateTimeImmutable => $row['startDate'] instanceof DateTimeImmutable
|
||||||
|
? $row['startDate']
|
||||||
|
: DateTimeImmutable::createFromInterface($row['startDate']),
|
||||||
|
$results
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<Absence>
|
* @return list<Absence>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ final readonly class LeaveBalanceComputationService
|
|||||||
private const float STANDARD_SATURDAY_ACCRUAL_PER_MONTH = self::STANDARD_ANNUAL_SATURDAYS / 12.0;
|
private const float STANDARD_SATURDAY_ACCRUAL_PER_MONTH = self::STANDARD_ANNUAL_SATURDAYS / 12.0;
|
||||||
private const float FOUR_HOUR_ANNUAL_DAYS = 10.0;
|
private const float FOUR_HOUR_ANNUAL_DAYS = 10.0;
|
||||||
private const float FOUR_HOUR_ACCRUAL_PER_MONTH = 0.83;
|
private const float FOUR_HOUR_ACCRUAL_PER_MONTH = 0.83;
|
||||||
|
private const float LONG_MALADIE_MONTHLY_ACCRUAL = 2.0;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private AbsenceRepository $absenceRepository,
|
private AbsenceRepository $absenceRepository,
|
||||||
@@ -31,6 +32,7 @@ final readonly class LeaveBalanceComputationService
|
|||||||
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
|
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
|
||||||
private PublicHolidayServiceInterface $publicHolidayService,
|
private PublicHolidayServiceInterface $publicHolidayService,
|
||||||
private SuspensionDaysCalculator $suspensionDaysCalculator,
|
private SuspensionDaysCalculator $suspensionDaysCalculator,
|
||||||
|
private LongMaladieService $longMaladieService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,19 +85,34 @@ final readonly class LeaveBalanceComputationService
|
|||||||
$suspensions = $this->suspensionDaysCalculator->applyFirstMonthGrace(
|
$suspensions = $this->suspensionDaysCalculator->applyFirstMonthGrace(
|
||||||
$this->resolveSuspensionsForEmployeePeriod($employee, $from, $to)
|
$this->resolveSuspensionsForEmployeePeriod($employee, $from, $to)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$longMaladiePeriods = [];
|
||||||
|
$longMaladieReductionFactor = 1.0;
|
||||||
|
if (4 !== $employee->getContract()?->getWeeklyHours()) {
|
||||||
|
$longMaladiePeriods = $this->longMaladieService->findReducedRatePeriods($employee, $effectiveFrom, $to);
|
||||||
|
if ([] !== $longMaladiePeriods) {
|
||||||
|
$totalNormalAccrual = $this->resolveDaysAccrualPerMonth($employee) + $this->resolveSaturdayAccrualPerMonth($employee);
|
||||||
|
$longMaladieReductionFactor = self::LONG_MALADIE_MONTHLY_ACCRUAL / $totalNormalAccrual;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$generatedDays = $this->computeAccruedDays(
|
$generatedDays = $this->computeAccruedDays(
|
||||||
$this->resolveAnnualDays($employee),
|
$this->resolveAnnualDays($employee),
|
||||||
$this->resolveDaysAccrualPerMonth($employee),
|
$this->resolveDaysAccrualPerMonth($employee),
|
||||||
$effectiveFrom,
|
$effectiveFrom,
|
||||||
$to,
|
$to,
|
||||||
$suspensions
|
$suspensions,
|
||||||
|
$longMaladiePeriods,
|
||||||
|
$longMaladieReductionFactor
|
||||||
);
|
);
|
||||||
$generatedSaturdays = $this->computeAccruedDays(
|
$generatedSaturdays = $this->computeAccruedDays(
|
||||||
$this->resolveAnnualSaturdays($employee),
|
$this->resolveAnnualSaturdays($employee),
|
||||||
$this->resolveSaturdayAccrualPerMonth($employee),
|
$this->resolveSaturdayAccrualPerMonth($employee),
|
||||||
$effectiveFrom,
|
$effectiveFrom,
|
||||||
$to,
|
$to,
|
||||||
$suspensions
|
$suspensions,
|
||||||
|
$longMaladiePeriods,
|
||||||
|
$longMaladieReductionFactor
|
||||||
);
|
);
|
||||||
|
|
||||||
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $effectiveFrom, $to);
|
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $effectiveFrom, $to);
|
||||||
@@ -267,21 +284,29 @@ final readonly class LeaveBalanceComputationService
|
|||||||
: self::STANDARD_SATURDAY_ACCRUAL_PER_MONTH;
|
: self::STANDARD_SATURDAY_ACCRUAL_PER_MONTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<ContractSuspension> $suspensions
|
||||||
|
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $longMaladiePeriods
|
||||||
|
*/
|
||||||
private function computeAccruedDays(
|
private function computeAccruedDays(
|
||||||
float $annualCap,
|
float $annualCap,
|
||||||
float $accrualPerMonth,
|
float $accrualPerMonth,
|
||||||
DateTimeImmutable $periodStart,
|
DateTimeImmutable $periodStart,
|
||||||
DateTimeImmutable $periodEnd,
|
DateTimeImmutable $periodEnd,
|
||||||
array $suspensions = []
|
array $suspensions = [],
|
||||||
|
array $longMaladiePeriods = [],
|
||||||
|
float $longMaladieReductionFactor = 1.0
|
||||||
): float {
|
): float {
|
||||||
if ($accrualPerMonth <= 0.0 || $periodEnd < $periodStart) {
|
if ($accrualPerMonth <= 0.0 || $periodEnd < $periodStart) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$periodStart = $this->normalizeDate($periodStart);
|
$periodStart = $this->normalizeDate($periodStart);
|
||||||
$periodEnd = $this->normalizeDate($periodEnd);
|
$periodEnd = $this->normalizeDate($periodEnd);
|
||||||
$coveredMonths = 0.0;
|
$publicHolidays = [] !== $suspensions ? $this->buildPublicHolidayMap($periodStart, $periodEnd) : [];
|
||||||
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
|
$normalMonths = 0.0;
|
||||||
|
$reducedMonths = 0.0;
|
||||||
|
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
|
||||||
while ($cursor <= $periodEnd) {
|
while ($cursor <= $periodEnd) {
|
||||||
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
|
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
|
||||||
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
|
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
|
||||||
@@ -289,18 +314,39 @@ final readonly class LeaveBalanceComputationService
|
|||||||
$monthEnd = $periodEnd;
|
$monthEnd = $periodEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
|
|
||||||
if ([] !== $suspensions) {
|
if ([] !== $suspensions) {
|
||||||
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
|
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
|
||||||
$coveredDays = max(0, $coveredDays - $suspendedDays);
|
if ($suspendedDays > 0) {
|
||||||
|
$businessDays = $this->countBusinessDaysInRange($monthStart, $monthEnd, $publicHolidays);
|
||||||
|
$suspendedBusinessDays = $this->suspensionDaysCalculator->countSuspendedBusinessDays($monthStart, $monthEnd, $suspensions, $publicHolidays);
|
||||||
|
$normalMonths += max(0, $businessDays - $suspendedBusinessDays) / 22.0;
|
||||||
|
$cursor = $cursor->modify('first day of next month');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
|
||||||
$daysInMonth = (int) $cursor->format('t');
|
$daysInMonth = (int) $cursor->format('t');
|
||||||
$coveredMonths += $coveredDays / $daysInMonth;
|
|
||||||
|
if ([] !== $longMaladiePeriods) {
|
||||||
|
$reducedDays = $this->longMaladieService->countReducedDaysInMonth($monthStart, $monthEnd, $longMaladiePeriods);
|
||||||
|
if ($reducedDays > 0) {
|
||||||
|
$normalDays = max(0, $coveredDays - $reducedDays);
|
||||||
|
$normalMonths += $normalDays / $daysInMonth;
|
||||||
|
$reducedMonths += min($coveredDays, $reducedDays) / $daysInMonth;
|
||||||
|
$cursor = $cursor->modify('first day of next month');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalMonths += $coveredDays / $daysInMonth;
|
||||||
|
|
||||||
$cursor = $cursor->modify('first day of next month');
|
$cursor = $cursor->modify('first day of next month');
|
||||||
}
|
}
|
||||||
|
|
||||||
return min($annualCap, $coveredMonths * $accrualPerMonth);
|
return min($annualCap, ($normalMonths + $reducedMonths * $longMaladieReductionFactor) * $accrualPerMonth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseYmdDate(string $value): ?DateTimeImmutable
|
private function parseYmdDate(string $value): ?DateTimeImmutable
|
||||||
@@ -317,8 +363,15 @@ final readonly class LeaveBalanceComputationService
|
|||||||
|
|
||||||
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to): int
|
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to): int
|
||||||
{
|
{
|
||||||
$publicHolidays = $this->buildPublicHolidayMap($from, $to);
|
return $this->countBusinessDaysInRange($from, $to, $this->buildPublicHolidayMap($from, $to));
|
||||||
$count = 0;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, string> $publicHolidays pre-built map
|
||||||
|
*/
|
||||||
|
private function countBusinessDaysInRange(DateTimeImmutable $from, DateTimeImmutable $to, array $publicHolidays): int
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
|
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
|
||||||
$weekDay = (int) $cursor->format('N');
|
$weekDay = (int) $cursor->format('N');
|
||||||
$dayKey = $cursor->format('Y-m-d');
|
$dayKey = $cursor->format('Y-m-d');
|
||||||
|
|||||||
116
src/Service/Leave/LongMaladieService.php
Normal file
116
src/Service/Leave/LongMaladieService.php
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Leave;
|
||||||
|
|
||||||
|
use App\Entity\Employee;
|
||||||
|
use App\Repository\AbsenceRepository;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
use function count;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects continuous MALADIE (sick leave) periods and computes
|
||||||
|
* the date ranges where reduced accrual applies (after the first month grace).
|
||||||
|
*/
|
||||||
|
final readonly class LongMaladieService
|
||||||
|
{
|
||||||
|
private const int MAX_GAP_DAYS = 3;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private AbsenceRepository $absenceRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns date ranges where the reduced maladie accrual rate applies.
|
||||||
|
* For continuous maladie periods > 1 month, the first month is excluded (grace period).
|
||||||
|
*
|
||||||
|
* @return list<array{start: DateTimeImmutable, end: DateTimeImmutable}>
|
||||||
|
*/
|
||||||
|
public function findReducedRatePeriods(
|
||||||
|
Employee $employee,
|
||||||
|
DateTimeImmutable $from,
|
||||||
|
DateTimeImmutable $to
|
||||||
|
): array {
|
||||||
|
// Look back 13 months to catch maladie that started before the exercise period
|
||||||
|
$extendedFrom = $from->modify('-13 months');
|
||||||
|
$dates = $this->absenceRepository->findMaladieDatesByEmployee($employee, $extendedFrom, $to);
|
||||||
|
if ([] === $dates) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$periods = $this->consolidateIntoPeriods($dates);
|
||||||
|
|
||||||
|
return $this->applyFirstMonthGrace($periods);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count calendar days in [monthStart, monthEnd] that fall within reduced maladie periods.
|
||||||
|
*
|
||||||
|
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $reducedPeriods
|
||||||
|
*/
|
||||||
|
public function countReducedDaysInMonth(
|
||||||
|
DateTimeImmutable $monthStart,
|
||||||
|
DateTimeImmutable $monthEnd,
|
||||||
|
array $reducedPeriods
|
||||||
|
): int {
|
||||||
|
$total = 0;
|
||||||
|
foreach ($reducedPeriods as $period) {
|
||||||
|
$overlapStart = $period['start'] > $monthStart ? $period['start'] : $monthStart;
|
||||||
|
$overlapEnd = $period['end'] < $monthEnd ? $period['end'] : $monthEnd;
|
||||||
|
|
||||||
|
if ($overlapStart > $overlapEnd) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$total += ((int) $overlapEnd->diff($overlapStart)->format('%a')) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<DateTimeImmutable> $dates sorted chronologically
|
||||||
|
*
|
||||||
|
* @return list<array{start: DateTimeImmutable, end: DateTimeImmutable}>
|
||||||
|
*/
|
||||||
|
private function consolidateIntoPeriods(array $dates): array
|
||||||
|
{
|
||||||
|
$periods = [];
|
||||||
|
$start = $dates[0];
|
||||||
|
$prev = $start;
|
||||||
|
|
||||||
|
for ($i = 1, $count = count($dates); $i < $count; ++$i) {
|
||||||
|
$current = $dates[$i];
|
||||||
|
$gap = (int) $prev->diff($current)->format('%a');
|
||||||
|
if ($gap > self::MAX_GAP_DAYS) {
|
||||||
|
$periods[] = ['start' => $start, 'end' => $prev];
|
||||||
|
$start = $current;
|
||||||
|
}
|
||||||
|
$prev = $current;
|
||||||
|
}
|
||||||
|
$periods[] = ['start' => $start, 'end' => $prev];
|
||||||
|
|
||||||
|
return $periods;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $periods
|
||||||
|
*
|
||||||
|
* @return list<array{start: DateTimeImmutable, end: DateTimeImmutable}>
|
||||||
|
*/
|
||||||
|
private function applyFirstMonthGrace(array $periods): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
foreach ($periods as $period) {
|
||||||
|
$gracedStart = $period['start']->modify('+1 month');
|
||||||
|
if ($gracedStart > $period['end']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$result[] = ['start' => $gracedStart, 'end' => $period['end']];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ namespace App\Service;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
@@ -17,7 +19,8 @@ final readonly class PublicHolidayService implements PublicHolidayServiceInterfa
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private HttpClientInterface $client,
|
private HttpClientInterface $client,
|
||||||
private string $holidayUrl
|
private string $holidayUrl,
|
||||||
|
private CacheInterface $cache,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,24 +33,29 @@ final readonly class PublicHolidayService implements PublicHolidayServiceInterfa
|
|||||||
public function getHolidaysDay(string $zone): array
|
public function getHolidaysDay(string $zone): array
|
||||||
{
|
{
|
||||||
$zone = strtolower(trim($zone));
|
$zone = strtolower(trim($zone));
|
||||||
$url = $this->holidayUrl."{$zone}.json";
|
$key = "public_holidays_{$zone}_all";
|
||||||
|
|
||||||
try {
|
return $this->cache->get($key, function (ItemInterface $item) use ($zone): array {
|
||||||
$response = $this->client->request(
|
$item->expiresAfter(30 * 86400);
|
||||||
'GET',
|
$url = $this->holidayUrl."{$zone}.json";
|
||||||
$url
|
|
||||||
);
|
|
||||||
} catch (TransportExceptionInterface) {
|
|
||||||
throw new RuntimeException('Unable to reach public holidays API.');
|
|
||||||
} catch (ClientExceptionInterface) {
|
|
||||||
throw new RuntimeException('Invalid zone provided for public holidays.');
|
|
||||||
} catch (ServerExceptionInterface) {
|
|
||||||
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
|
||||||
} catch (Throwable) {
|
|
||||||
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_decode($response->getContent(), true);
|
try {
|
||||||
|
$response = $this->client->request(
|
||||||
|
'GET',
|
||||||
|
$url
|
||||||
|
);
|
||||||
|
} catch (TransportExceptionInterface) {
|
||||||
|
throw new RuntimeException('Unable to reach public holidays API.');
|
||||||
|
} catch (ClientExceptionInterface) {
|
||||||
|
throw new RuntimeException('Invalid zone provided for public holidays.');
|
||||||
|
} catch (ServerExceptionInterface) {
|
||||||
|
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
||||||
|
} catch (Throwable) {
|
||||||
|
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($response->getContent(), true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,20 +68,25 @@ final readonly class PublicHolidayService implements PublicHolidayServiceInterfa
|
|||||||
{
|
{
|
||||||
$zone = strtolower(trim($zone));
|
$zone = strtolower(trim($zone));
|
||||||
$years = trim($years);
|
$years = trim($years);
|
||||||
$url = $this->holidayUrl."{$zone}/{$years}.json";
|
$key = "public_holidays_{$zone}_{$years}";
|
||||||
|
|
||||||
try {
|
return $this->cache->get($key, function (ItemInterface $item) use ($zone, $years): array {
|
||||||
$response = $this->client->request('GET', $url);
|
$item->expiresAfter(30 * 86400);
|
||||||
} catch (TransportExceptionInterface) {
|
$url = $this->holidayUrl."{$zone}/{$years}.json";
|
||||||
throw new RuntimeException('Unable to reach public holidays API.');
|
|
||||||
} catch (ClientExceptionInterface) {
|
|
||||||
throw new RuntimeException('Invalid zone or year provided for public holidays.');
|
|
||||||
} catch (ServerExceptionInterface) {
|
|
||||||
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
|
||||||
} catch (Throwable) {
|
|
||||||
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_decode($response->getContent(), true);
|
try {
|
||||||
|
$response = $this->client->request('GET', $url);
|
||||||
|
} catch (TransportExceptionInterface) {
|
||||||
|
throw new RuntimeException('Unable to reach public holidays API.');
|
||||||
|
} catch (ClientExceptionInterface) {
|
||||||
|
throw new RuntimeException('Invalid zone or year provided for public holidays.');
|
||||||
|
} catch (ServerExceptionInterface) {
|
||||||
|
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
||||||
|
} catch (Throwable) {
|
||||||
|
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($response->getContent(), true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use App\Repository\EmployeeRepository;
|
|||||||
use App\Repository\WorkHourRepository;
|
use App\Repository\WorkHourRepository;
|
||||||
use App\Security\EmployeeScopeService;
|
use App\Security\EmployeeScopeService;
|
||||||
use App\Service\Leave\LeaveBalanceComputationService;
|
use App\Service\Leave\LeaveBalanceComputationService;
|
||||||
|
use App\Service\Leave\LongMaladieService;
|
||||||
use App\Service\Leave\SuspensionDaysCalculator;
|
use App\Service\Leave\SuspensionDaysCalculator;
|
||||||
use App\Service\PublicHolidayServiceInterface;
|
use App\Service\PublicHolidayServiceInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
@@ -42,6 +43,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
private const float CDI_NON_FORFAIT_4H_ACQUIRED_SATURDAYS = 0.0;
|
private const float CDI_NON_FORFAIT_4H_ACQUIRED_SATURDAYS = 0.0;
|
||||||
private const float CDI_NON_FORFAIT_4H_ACCRUAL_PER_MONTH = 0.83;
|
private const float CDI_NON_FORFAIT_4H_ACCRUAL_PER_MONTH = 0.83;
|
||||||
private const float CDI_NON_FORFAIT_4H_SATURDAY_ACCRUAL_PER_MONTH = 0.0;
|
private const float CDI_NON_FORFAIT_4H_SATURDAY_ACCRUAL_PER_MONTH = 0.0;
|
||||||
|
private const float LONG_MALADIE_MONTHLY_ACCRUAL = 2.0;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private Security $security,
|
private Security $security,
|
||||||
@@ -52,6 +54,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
private EmployeeContractPeriodRepository $periodRepository,
|
private EmployeeContractPeriodRepository $periodRepository,
|
||||||
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
|
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
|
||||||
private LeaveBalanceComputationService $leaveBalanceComputationService,
|
private LeaveBalanceComputationService $leaveBalanceComputationService,
|
||||||
|
private LongMaladieService $longMaladieService,
|
||||||
private PublicHolidayServiceInterface $publicHolidayService,
|
private PublicHolidayServiceInterface $publicHolidayService,
|
||||||
private SuspensionDaysCalculator $suspensionDaysCalculator,
|
private SuspensionDaysCalculator $suspensionDaysCalculator,
|
||||||
private WorkHourRepository $workHourRepository,
|
private WorkHourRepository $workHourRepository,
|
||||||
@@ -187,13 +190,29 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
$suspensions = $this->suspensionDaysCalculator->applyFirstMonthGrace(
|
$suspensions = $this->suspensionDaysCalculator->applyFirstMonthGrace(
|
||||||
$this->resolveSuspensionsForPeriod($employee, $effectiveFrom, $to)
|
$this->resolveSuspensionsForPeriod($employee, $effectiveFrom, $to)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$longMaladiePeriods = [];
|
||||||
|
$longMaladieReductionFactor = 1.0;
|
||||||
|
if (LeaveRuleCode::CDI_CDD_NON_FORFAIT->value === $leavePolicy['ruleCode']
|
||||||
|
&& 4 !== $employee->getContract()?->getWeeklyHours()
|
||||||
|
&& null !== $accrualCalculationEnd
|
||||||
|
) {
|
||||||
|
$longMaladiePeriods = $this->longMaladieService->findReducedRatePeriods($employee, $effectiveFrom, $accrualCalculationEnd);
|
||||||
|
if ([] !== $longMaladiePeriods) {
|
||||||
|
$totalNormalAccrual = $leavePolicy['accrualPerMonth'] + $leavePolicy['saturdayAccrualPerMonth'];
|
||||||
|
$longMaladieReductionFactor = self::LONG_MALADIE_MONTHLY_ACCRUAL / $totalNormalAccrual;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
|
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
|
||||||
? $this->computeAccruedDaysFromStart(
|
? $this->computeAccruedDaysFromStart(
|
||||||
$leavePolicy['acquiredDays'],
|
$leavePolicy['acquiredDays'],
|
||||||
$leavePolicy['accrualPerMonth'],
|
$leavePolicy['accrualPerMonth'],
|
||||||
$effectiveFrom,
|
$effectiveFrom,
|
||||||
$accrualCalculationEnd,
|
$accrualCalculationEnd,
|
||||||
$suspensions
|
$suspensions,
|
||||||
|
$longMaladiePeriods,
|
||||||
|
$longMaladieReductionFactor
|
||||||
)
|
)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
$generatedSaturdays = $leavePolicy['saturdayAccrualPerMonth'] > 0.0
|
$generatedSaturdays = $leavePolicy['saturdayAccrualPerMonth'] > 0.0
|
||||||
@@ -202,7 +221,9 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
$leavePolicy['saturdayAccrualPerMonth'],
|
$leavePolicy['saturdayAccrualPerMonth'],
|
||||||
$effectiveFrom,
|
$effectiveFrom,
|
||||||
$accrualCalculationEnd,
|
$accrualCalculationEnd,
|
||||||
$suspensions
|
$suspensions,
|
||||||
|
$longMaladiePeriods,
|
||||||
|
$longMaladieReductionFactor
|
||||||
)
|
)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $from, $to);
|
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $from, $to);
|
||||||
@@ -375,12 +396,18 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
return $year;
|
return $year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<ContractSuspension> $suspensions
|
||||||
|
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $longMaladiePeriods
|
||||||
|
*/
|
||||||
private function computeAccruedDaysFromStart(
|
private function computeAccruedDaysFromStart(
|
||||||
float $acquiredDays,
|
float $acquiredDays,
|
||||||
float $accrualPerMonth,
|
float $accrualPerMonth,
|
||||||
DateTimeImmutable $periodStart,
|
DateTimeImmutable $periodStart,
|
||||||
?DateTimeImmutable $periodEnd,
|
?DateTimeImmutable $periodEnd,
|
||||||
array $suspensions = []
|
array $suspensions = [],
|
||||||
|
array $longMaladiePeriods = [],
|
||||||
|
float $longMaladieReductionFactor = 1.0
|
||||||
): float {
|
): float {
|
||||||
if ($accrualPerMonth <= 0.0) {
|
if ($accrualPerMonth <= 0.0) {
|
||||||
return $acquiredDays;
|
return $acquiredDays;
|
||||||
@@ -390,10 +417,12 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$periodStart = $this->normalizeDate($periodStart);
|
$periodStart = $this->normalizeDate($periodStart);
|
||||||
$periodEnd = $this->normalizeDate($periodEnd);
|
$periodEnd = $this->normalizeDate($periodEnd);
|
||||||
$coveredMonths = 0.0;
|
$publicHolidays = [] !== $suspensions ? $this->buildPublicHolidayMap($periodStart, $periodEnd) : [];
|
||||||
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
|
$normalMonths = 0.0;
|
||||||
|
$reducedMonths = 0.0;
|
||||||
|
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
|
||||||
while ($cursor <= $periodEnd) {
|
while ($cursor <= $periodEnd) {
|
||||||
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
|
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
|
||||||
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
|
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
|
||||||
@@ -401,18 +430,39 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
$monthEnd = $periodEnd;
|
$monthEnd = $periodEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
|
|
||||||
if ([] !== $suspensions) {
|
if ([] !== $suspensions) {
|
||||||
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
|
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
|
||||||
$coveredDays = max(0, $coveredDays - $suspendedDays);
|
if ($suspendedDays > 0) {
|
||||||
|
$businessDays = $this->countBusinessDays($monthStart, $monthEnd, $publicHolidays);
|
||||||
|
$suspendedBusinessDays = $this->suspensionDaysCalculator->countSuspendedBusinessDays($monthStart, $monthEnd, $suspensions, $publicHolidays);
|
||||||
|
$normalMonths += max(0, $businessDays - $suspendedBusinessDays) / 22.0;
|
||||||
|
$cursor = $cursor->modify('first day of next month');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
|
||||||
$daysInMonth = (int) $cursor->format('t');
|
$daysInMonth = (int) $cursor->format('t');
|
||||||
$coveredMonths += $coveredDays / $daysInMonth;
|
|
||||||
|
if ([] !== $longMaladiePeriods) {
|
||||||
|
$reducedDays = $this->longMaladieService->countReducedDaysInMonth($monthStart, $monthEnd, $longMaladiePeriods);
|
||||||
|
if ($reducedDays > 0) {
|
||||||
|
$normalDays = max(0, $coveredDays - $reducedDays);
|
||||||
|
$normalMonths += $normalDays / $daysInMonth;
|
||||||
|
$reducedMonths += min($coveredDays, $reducedDays) / $daysInMonth;
|
||||||
|
$cursor = $cursor->modify('first day of next month');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalMonths += $coveredDays / $daysInMonth;
|
||||||
|
|
||||||
$cursor = $cursor->modify('first day of next month');
|
$cursor = $cursor->modify('first day of next month');
|
||||||
}
|
}
|
||||||
|
|
||||||
return min($acquiredDays, $coveredMonths * $accrualPerMonth);
|
return min($acquiredDays, ($normalMonths + $reducedMonths * $longMaladieReductionFactor) * $accrualPerMonth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveAccrualCalculationEndDate(
|
private function resolveAccrualCalculationEndDate(
|
||||||
@@ -526,10 +576,13 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to): int
|
/**
|
||||||
|
* @param null|array<string, string> $publicHolidays pre-built map (built if null)
|
||||||
|
*/
|
||||||
|
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to, ?array $publicHolidays = null): int
|
||||||
{
|
{
|
||||||
$publicHolidays = $this->buildPublicHolidayMap($from, $to);
|
$publicHolidays ??= $this->buildPublicHolidayMap($from, $to);
|
||||||
$count = 0;
|
$count = 0;
|
||||||
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
|
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
|
||||||
$weekDay = (int) $cursor->format('N');
|
$weekDay = (int) $cursor->format('N');
|
||||||
$dayKey = $cursor->format('Y-m-d');
|
$dayKey = $cursor->format('Y-m-d');
|
||||||
|
|||||||
Reference in New Issue
Block a user