Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10a0ab0809 | ||
| 055f1187f9 | |||
|
|
f3ed359d3f | ||
| 906c245451 | |||
|
|
100ab340d4 | ||
| 0257e59671 | |||
|
|
f9979c9a19 | ||
| 1091147100 |
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.74'
|
app.version: '0.1.78'
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ export SIRH_IMAGE_TAG="$TAG"
|
|||||||
|
|
||||||
echo "==> Deploying sirh:${TAG}..."
|
echo "==> Deploying sirh:${TAG}..."
|
||||||
|
|
||||||
|
echo "==> Enabling maintenance mode..."
|
||||||
|
touch maintenance.on
|
||||||
|
|
||||||
echo "==> Pulling image..."
|
echo "==> Pulling image..."
|
||||||
docker compose pull
|
docker compose pull
|
||||||
|
|
||||||
@@ -24,5 +27,8 @@ echo "==> Clearing cache..."
|
|||||||
docker compose exec -T -u www-data app php bin/console cache:clear --env=prod
|
docker compose exec -T -u www-data app php bin/console cache:clear --env=prod
|
||||||
docker compose exec -T -u www-data app php bin/console cache:warmup --env=prod
|
docker compose exec -T -u www-data app php bin/console cache:warmup --env=prod
|
||||||
|
|
||||||
|
echo "==> Disabling maintenance mode..."
|
||||||
|
rm -f maintenance.on
|
||||||
|
|
||||||
VERSION=$(docker compose exec -T app cat config/version.yaml | grep 'app.version' | awk -F"'" '{print $2}')
|
VERSION=$(docker compose exec -T app cat config/version.yaml | grep 'app.version' | awk -F"'" '{print $2}')
|
||||||
echo "==> Deployed v${VERSION}"
|
echo "==> Deployed v${VERSION}"
|
||||||
|
|||||||
50
deploy/maintenance.html
Normal file
50
deploy/maintenance.html
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Maintenance en cours</title>
|
||||||
|
<style>
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||||
|
background: #f3f4f6;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
color: #1f2937;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
text-align: center;
|
||||||
|
padding: 3rem;
|
||||||
|
background: white;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
|
||||||
|
max-width: 500px;
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
.icon {
|
||||||
|
font-size: 4rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
color: #111827;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #6b7280;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="icon">🛠</div>
|
||||||
|
<h1>Maintenance en cours</h1>
|
||||||
|
<p>L'application est temporairement indisponible pour mise a jour. Elle sera de retour dans quelques instants.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -2,6 +2,23 @@ server {
|
|||||||
listen 80;
|
listen 80;
|
||||||
server_name sirh.malio-dev.fr;
|
server_name sirh.malio-dev.fr;
|
||||||
|
|
||||||
|
root /var/www/sirh/public;
|
||||||
|
|
||||||
|
# Maintenance mode : si le fichier maintenance.on existe, renvoyer la page 503
|
||||||
|
if (-f /var/www/sirh/maintenance.on) {
|
||||||
|
return 503;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 503 @maintenance;
|
||||||
|
|
||||||
|
location @maintenance {
|
||||||
|
rewrite ^(.*)$ /maintenance.html break;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /maintenance.html {
|
||||||
|
internal;
|
||||||
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://127.0.0.1:8080;
|
proxy_pass http://127.0.0.1:8080;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|||||||
@@ -197,6 +197,23 @@ server {
|
|||||||
listen 80;
|
listen 80;
|
||||||
server_name sirh.malio-dev.fr;
|
server_name sirh.malio-dev.fr;
|
||||||
|
|
||||||
|
root /var/www/sirh/public;
|
||||||
|
|
||||||
|
# Maintenance mode
|
||||||
|
if (-f /var/www/sirh/maintenance.on) {
|
||||||
|
return 503;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 503 @maintenance;
|
||||||
|
|
||||||
|
location @maintenance {
|
||||||
|
rewrite ^(.*)$ /maintenance.html break;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /maintenance.html {
|
||||||
|
internal;
|
||||||
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://127.0.0.1:8080;
|
proxy_pass http://127.0.0.1:8080;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
@@ -207,9 +224,10 @@ server {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Activer le site :
|
Copier la page de maintenance et activer le site :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
cp deploy/maintenance.html /var/www/sirh/public/maintenance.html
|
||||||
sudo ln -sf /etc/nginx/sites-available/sirh.conf /etc/nginx/sites-enabled/sirh.conf
|
sudo ln -sf /etc/nginx/sites-available/sirh.conf /etc/nginx/sites-enabled/sirh.conf
|
||||||
sudo nginx -t && sudo systemctl reload nginx
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
```
|
```
|
||||||
@@ -251,6 +269,8 @@ rm /tmp/sirh.sql
|
|||||||
├── config/jwt/
|
├── config/jwt/
|
||||||
│ ├── private.pem
|
│ ├── private.pem
|
||||||
│ └── public.pem
|
│ └── public.pem
|
||||||
|
├── public/
|
||||||
|
│ └── maintenance.html
|
||||||
└── uploads/
|
└── uploads/
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -266,7 +286,24 @@ cd /var/www/sirh
|
|||||||
./deploy.sh v0.1.61 # deploie une version specifique
|
./deploy.sh v0.1.61 # deploie une version specifique
|
||||||
```
|
```
|
||||||
|
|
||||||
C'est tout. Le script pull l'image, redemarre le conteneur, lance les migrations et vide le cache.
|
Le script active automatiquement la maintenance pendant le deploy et la desactive a la fin.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Maintenance manuelle
|
||||||
|
|
||||||
|
Activer la maintenance (sans deployer) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /var/www/sirh
|
||||||
|
touch maintenance.on
|
||||||
|
```
|
||||||
|
|
||||||
|
Desactiver :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
rm maintenance.on
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
|
|||||||
- pour `FORFAIT`:
|
- pour `FORFAIT`:
|
||||||
- pris: basé sur toutes les absences (demi-journées incluses)
|
- pris: basé sur toutes les absences (demi-journées incluses)
|
||||||
- restants = acquis - pris (borné à 0)
|
- restants = acquis - pris (borné à 0)
|
||||||
|
- paiement congés N-1: saisie RH via `PATCH /employees/{id}/paid-leave-days` (body: `paidLeaveDays`, `year`). Stocké dans `employee_leave_balances.paid_leave_days`. Les jours payés réduisent le stock N-1 **avant** l'attribution des jours pris : `disponible_N-1 = max(0, acquis_N-1 - payés)`, puis `pris_N-1 = min(disponible_N-1, total_pris)`, surplus pris basculé sur N. Reste à prendre N-1 = `max(0, disponible_N-1 - pris_N-1)`. Uniquement pour les contrats forfait.
|
||||||
- report annuel:
|
- report annuel:
|
||||||
- le reliquat (`restants`) de l'exercice précédent est reporté dans les acquis de l'exercice courant
|
- le reliquat (`restants`) de l'exercice précédent est reporté dans les acquis de l'exercice courant
|
||||||
- pour `CDI`/`CDD` non forfait: report séparé jours + samedis
|
- pour `CDI`/`CDD` non forfait: report séparé jours + samedis
|
||||||
@@ -274,8 +275,9 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
|
|||||||
- total mensuel des minutes de récupération
|
- total mensuel des minutes de récupération
|
||||||
- compteur global exercice = `report N-1 + acquis N`
|
- compteur global exercice = `report N-1 + acquis N`
|
||||||
- attribution mensuelle des semaines:
|
- attribution mensuelle des semaines:
|
||||||
- une semaine ISO est affichée une seule fois, dans le mois qui contient le **samedi** de cette semaine
|
- une semaine ISO qui chevauche deux mois est affichée dans **les deux mois**, avec les valeurs réparties proportionnellement aux minutes travaillées de chaque portion
|
||||||
- si le weekend tombe en début de mois suivant, c'est le mois suivant qui porte la semaine
|
- le calcul des heures supplémentaires reste hebdomadaire (seuils 35h/39h/43h appliqués sur la semaine entière), seul l'affichage est scindé
|
||||||
|
- exemple: S14 lundi-mardi en mars, mercredi-dimanche en avril → la S14 apparaît en mars (avec la part des heures de lun-mar) et en avril (avec la part mer-dim)
|
||||||
- logique de calcul:
|
- logique de calcul:
|
||||||
- base identique aux calculs d'heures supplémentaires de la vue semaine Heures
|
- base identique aux calculs d'heures supplémentaires de la vue semaine Heures
|
||||||
- minutes de récupération hebdomadaires = `HS totales + bonus 25% + bonus 50%`
|
- minutes de récupération hebdomadaires = `HS totales + bonus 25% + bonus 50%`
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ Principe:
|
|||||||
|
|
||||||
## 4) Attribution mensuelle des semaines
|
## 4) Attribution mensuelle des semaines
|
||||||
|
|
||||||
- une semaine ISO est affichee une seule fois, dans le mois qui contient le **samedi** de cette semaine
|
- une semaine ISO qui chevauche deux mois est affichee dans **les deux mois**, avec les valeurs reparties proportionnellement aux minutes travaillees de chaque portion
|
||||||
- si le weekend tombe en debut du mois suivant, c'est ce mois qui porte la semaine
|
- le calcul des heures supplementaires reste hebdomadaire (seuils 35h/39h/43h appliques sur la semaine entiere), seul l'affichage est scinde
|
||||||
- pas de prorata: la totalite des minutes de recuperation de la semaine est comptee dans un seul mois
|
- exemple: S14 lundi-mardi en mars, mercredi-dimanche en avril → la S14 apparait en mars (part lun-mar) et en avril (part mer-dim)
|
||||||
|
|
||||||
## 5) Table cible
|
## 5) Table cible
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,18 @@
|
|||||||
<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>
|
<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>
|
||||||
|
<span class="uppercase font-semibold">Année n-1 payés : </span>
|
||||||
|
<span> {{ formatCount(summary?.previousYearPaidDays) }} Jours</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
class="flex items-center"
|
||||||
|
@click="openPaidLeaveDrawer"
|
||||||
|
>
|
||||||
|
<Icon name="mdi:edit-box" size="24"/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<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">
|
||||||
<div>
|
<div>
|
||||||
<span class="uppercase font-semibold">Fractionné acquis : </span>
|
<span class="uppercase font-semibold">Fractionné acquis : </span>
|
||||||
@@ -112,6 +124,39 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</AppDrawer>
|
</AppDrawer>
|
||||||
|
<AppDrawer v-model="isPaidLeaveDrawerOpen" title="Congés N-1 payés">
|
||||||
|
<form class="space-y-4" @submit.prevent="handleSubmitPaidLeave">
|
||||||
|
<div>
|
||||||
|
<label class="text-md font-semibold text-neutral-700" for="paid-leave-days">
|
||||||
|
Nombre de jours <span class="text-red-600">*</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="paid-leave-days"
|
||||||
|
v-model="paidLeaveForm.days"
|
||||||
|
type="number"
|
||||||
|
step="0.5"
|
||||||
|
min="0"
|
||||||
|
class="mt-2 w-full rounded-md border border-neutral-300 px-3 py-2 text-md text-neutral-900 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-secondary-500/20"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-3 pt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-lg border border-neutral-200 px-4 py-2 text-md font-semibold text-neutral-700 hover:bg-neutral-100"
|
||||||
|
@click="isPaidLeaveDrawerOpen = false"
|
||||||
|
>
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="rounded-lg bg-primary-500 px-4 py-2 text-md font-semibold text-white hover:bg-secondary-500"
|
||||||
|
>
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</AppDrawer>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -136,11 +181,15 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(event: 'update-fractioned-days', days: number): void
|
(event: 'update-fractioned-days', days: number): void
|
||||||
|
(event: 'update-paid-leave-days', days: number): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const isFractionedDrawerOpen = ref(false)
|
const isFractionedDrawerOpen = ref(false)
|
||||||
const fractionedForm = reactive({days: 0})
|
const fractionedForm = reactive({days: 0})
|
||||||
|
|
||||||
|
const isPaidLeaveDrawerOpen = ref(false)
|
||||||
|
const paidLeaveForm = reactive({days: 0})
|
||||||
|
|
||||||
const openFractionedDrawer = () => {
|
const openFractionedDrawer = () => {
|
||||||
fractionedForm.days = props.summary?.fractionedDays ?? 0
|
fractionedForm.days = props.summary?.fractionedDays ?? 0
|
||||||
isFractionedDrawerOpen.value = true
|
isFractionedDrawerOpen.value = true
|
||||||
@@ -153,6 +202,18 @@ const handleSubmitFractioned = () => {
|
|||||||
isFractionedDrawerOpen.value = false
|
isFractionedDrawerOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openPaidLeaveDrawer = () => {
|
||||||
|
paidLeaveForm.days = props.summary?.previousYearPaidDays ?? 0
|
||||||
|
isPaidLeaveDrawerOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmitPaidLeave = () => {
|
||||||
|
const value = Number(paidLeaveForm.days)
|
||||||
|
if (Number.isNaN(value) || value < 0) return
|
||||||
|
emit('update-paid-leave-days', value)
|
||||||
|
isPaidLeaveDrawerOpen.value = false
|
||||||
|
}
|
||||||
|
|
||||||
const monthLabels = [
|
const monthLabels = [
|
||||||
'Janvier',
|
'Janvier',
|
||||||
'Fevrier',
|
'Fevrier',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
class="rounded-md bg-primary-500 px-8 py-2 font-bold text-white hover:bg-primary-600"
|
class="rounded-md bg-primary-500 px-8 py-2 font-bold text-white hover:bg-primary-600"
|
||||||
@click="openPaymentDrawer"
|
@click="openPaymentDrawer"
|
||||||
>
|
>
|
||||||
+ Payer les RRT
|
+ Payer les RTT
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { EmployeeLeaveSummary } from '~/services/dto/employee-leave-summary
|
|||||||
import type { Employee } from '~/services/dto/employee'
|
import type { Employee } from '~/services/dto/employee'
|
||||||
import { CONTRACT_TYPES } from '~/services/dto/contract'
|
import { CONTRACT_TYPES } from '~/services/dto/contract'
|
||||||
import { listAbsences } from '~/services/absences'
|
import { listAbsences } from '~/services/absences'
|
||||||
import { getEmployeeLeaveSummary, updateFractionedDays } from '~/services/employee-leave-summary'
|
import { getEmployeeLeaveSummary, updateFractionedDays, updatePaidLeaveDays } from '~/services/employee-leave-summary'
|
||||||
import { listPublicHolidays } from '~/services/public-holidays'
|
import { listPublicHolidays } from '~/services/public-holidays'
|
||||||
|
|
||||||
export const useEmployeeLeave = (employee: Ref<Employee | null>, reloadEmployee: () => Promise<void>) => {
|
export const useEmployeeLeave = (employee: Ref<Employee | null>, reloadEmployee: () => Promise<void>) => {
|
||||||
@@ -57,6 +57,13 @@ export const useEmployeeLeave = (employee: Ref<Employee | null>, reloadEmployee:
|
|||||||
await reloadEmployee()
|
await reloadEmployee()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const submitPaidLeaveDays = async (days: number) => {
|
||||||
|
if (!employee.value) return
|
||||||
|
const year = leaveSummary.value?.year ?? undefined
|
||||||
|
await updatePaidLeaveDays(employee.value.id, days, year)
|
||||||
|
await reloadEmployee()
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
employeeAbsences,
|
employeeAbsences,
|
||||||
leaveSummary,
|
leaveSummary,
|
||||||
@@ -65,6 +72,7 @@ export const useEmployeeLeave = (employee: Ref<Employee | null>, reloadEmployee:
|
|||||||
leaveDataLoaded,
|
leaveDataLoaded,
|
||||||
loadLeaveData,
|
loadLeaveData,
|
||||||
resetLoaded,
|
resetLoaded,
|
||||||
submitFractionedDays
|
submitFractionedDays,
|
||||||
|
submitPaidLeaveDays
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
<option value="contract_suspension">Suspension</option>
|
<option value="contract_suspension">Suspension</option>
|
||||||
<option value="rtt_payment">Paiement RTT</option>
|
<option value="rtt_payment">Paiement RTT</option>
|
||||||
<option value="fractioned_days">Jours fractionnés</option>
|
<option value="fractioned_days">Jours fractionnés</option>
|
||||||
|
<option value="paid_leave_days">Congés N-1 payés</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
@@ -241,6 +242,7 @@ const entityTypeLabel = (type: string): string => {
|
|||||||
contract_suspension: 'Suspension',
|
contract_suspension: 'Suspension',
|
||||||
rtt_payment: 'RTT',
|
rtt_payment: 'RTT',
|
||||||
fractioned_days: 'Fract.',
|
fractioned_days: 'Fract.',
|
||||||
|
paid_leave_days: 'Congés payés',
|
||||||
}
|
}
|
||||||
return map[type] ?? type
|
return map[type] ?? type
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,7 @@
|
|||||||
:summary="leaveSummary"
|
:summary="leaveSummary"
|
||||||
:public-holidays="publicHolidays"
|
:public-holidays="publicHolidays"
|
||||||
@update-fractioned-days="submitFractionedDays"
|
@update-fractioned-days="submitFractionedDays"
|
||||||
|
@update-paid-leave-days="submitPaidLeaveDays"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="showRttTab && activeTab === 'rtt'" class="h-full">
|
<div v-else-if="showRttTab && activeTab === 'rtt'" class="h-full">
|
||||||
@@ -259,6 +260,7 @@ const {
|
|||||||
submitContractUpdate,
|
submitContractUpdate,
|
||||||
submitCreateContract,
|
submitCreateContract,
|
||||||
submitFractionedDays,
|
submitFractionedDays,
|
||||||
|
submitPaidLeaveDays,
|
||||||
submitRttPayment,
|
submitRttPayment,
|
||||||
suspensionForms,
|
suspensionForms,
|
||||||
isSuspensionSubmitting,
|
isSuspensionSubmitting,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export type EmployeeLeaveSummary = {
|
|||||||
previousYearAcquiredDays: number
|
previousYearAcquiredDays: number
|
||||||
previousYearTakenDays: number
|
previousYearTakenDays: number
|
||||||
previousYearRemainingDays: number
|
previousYearRemainingDays: number
|
||||||
|
previousYearPaidDays: number
|
||||||
presenceDaysByMonth: Record<string, number>
|
presenceDaysByMonth: Record<string, number>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,3 +16,11 @@ export const updateFractionedDays = async (employeeId: number, fractionedDays: n
|
|||||||
return api.patch(`/employees/${employeeId}/fractioned-days`, body)
|
return api.patch(`/employees/${employeeId}/fractioned-days`, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updatePaidLeaveDays = async (employeeId: number, paidLeaveDays: number, year?: number) => {
|
||||||
|
const api = useApi()
|
||||||
|
const body: Record<string, unknown> = { paidLeaveDays }
|
||||||
|
if (year) body.year = year
|
||||||
|
|
||||||
|
return api.patch(`/employees/${employeeId}/paid-leave-days`, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
27
migrations/Version20260402064647.php
Normal file
27
migrations/Version20260402064647.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20260402064647 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add paid_leave_days column to employee_leave_balances for forfait N-1 leave payment';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE employee_leave_balances ADD paid_leave_days DOUBLE PRECISION DEFAULT 0 NOT NULL');
|
||||||
|
$this->addSql("COMMENT ON COLUMN employee_leave_balances.paid_leave_days IS 'Jours de conges N-1 payes par la RH (forfait uniquement).'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE employee_leave_balances DROP paid_leave_days');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ final class EmployeeLeaveSummary
|
|||||||
public float $previousYearAcquiredDays = 0.0;
|
public float $previousYearAcquiredDays = 0.0;
|
||||||
public float $previousYearTakenDays = 0.0;
|
public float $previousYearTakenDays = 0.0;
|
||||||
public float $previousYearRemainingDays = 0.0;
|
public float $previousYearRemainingDays = 0.0;
|
||||||
|
public float $previousYearPaidDays = 0.0;
|
||||||
|
|
||||||
/** @var array<string, float> YYYY-MM => count (0.5 for half-days) */
|
/** @var array<string, float> YYYY-MM => count (0.5 for half-days) */
|
||||||
public array $presenceDaysByMonth = [];
|
public array $presenceDaysByMonth = [];
|
||||||
|
|||||||
27
src/ApiResource/EmployeePaidLeaveDaysInput.php
Normal file
27
src/ApiResource/EmployeePaidLeaveDaysInput.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\ApiResource;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Patch;
|
||||||
|
use App\State\EmployeePaidLeaveDaysProcessor;
|
||||||
|
use App\State\EmployeePaidLeaveDaysProvider;
|
||||||
|
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Patch(
|
||||||
|
uriTemplate: '/employees/{id}/paid-leave-days',
|
||||||
|
security: "is_granted('ROLE_ADMIN')",
|
||||||
|
provider: EmployeePaidLeaveDaysProvider::class,
|
||||||
|
processor: EmployeePaidLeaveDaysProcessor::class
|
||||||
|
),
|
||||||
|
],
|
||||||
|
paginationEnabled: false
|
||||||
|
)]
|
||||||
|
final class EmployeePaidLeaveDaysInput
|
||||||
|
{
|
||||||
|
public float $paidLeaveDays = 0.0;
|
||||||
|
public ?int $year = null;
|
||||||
|
}
|
||||||
@@ -6,6 +6,9 @@ namespace App\Dto\Rtt;
|
|||||||
|
|
||||||
final class WeekRecoveryDetail
|
final class WeekRecoveryDetail
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, int> $dailyMinutes date (Y-m-d) => worked minutes
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public int $overtimeMinutes = 0,
|
public int $overtimeMinutes = 0,
|
||||||
public int $base25Minutes = 0,
|
public int $base25Minutes = 0,
|
||||||
@@ -13,5 +16,6 @@ final class WeekRecoveryDetail
|
|||||||
public int $base50Minutes = 0,
|
public int $base50Minutes = 0,
|
||||||
public int $bonus50Minutes = 0,
|
public int $bonus50Minutes = 0,
|
||||||
public int $totalMinutes = 0,
|
public int $totalMinutes = 0,
|
||||||
|
public array $dailyMinutes = [],
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ class EmployeeLeaveBalance
|
|||||||
#[ORM\Column(type: 'float', options: ['default' => 0, 'comment' => 'Jours de fractionnement saisis par la RH.'])]
|
#[ORM\Column(type: 'float', options: ['default' => 0, 'comment' => 'Jours de fractionnement saisis par la RH.'])]
|
||||||
private float $fractionedDays = 0.0;
|
private float $fractionedDays = 0.0;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'float', options: ['default' => 0, 'comment' => 'Jours de conges N-1 payes par la RH (forfait uniquement).'])]
|
||||||
|
private float $paidLeaveDays = 0.0;
|
||||||
|
|
||||||
#[ORM\Column(type: 'boolean', options: ['default' => false, 'comment' => 'Indique si le solde de l exercice est fige (verrouille RH).'])]
|
#[ORM\Column(type: 'boolean', options: ['default' => false, 'comment' => 'Indique si le solde de l exercice est fige (verrouille RH).'])]
|
||||||
private bool $isLocked = false;
|
private bool $isLocked = false;
|
||||||
|
|
||||||
@@ -222,6 +225,18 @@ class EmployeeLeaveBalance
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPaidLeaveDays(): float
|
||||||
|
{
|
||||||
|
return $this->paidLeaveDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPaidLeaveDays(float $paidLeaveDays): self
|
||||||
|
{
|
||||||
|
$this->paidLeaveDays = $paidLeaveDays;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function isLocked(): bool
|
public function isLocked(): bool
|
||||||
{
|
{
|
||||||
return $this->isLocked;
|
return $this->isLocked;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ final readonly class RttRecoveryComputationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<array{month:int,weekNumber:int,start:DateTimeImmutable,end:DateTimeImmutable}>
|
* @return list<array{weekNumber:int,start:DateTimeImmutable,end:DateTimeImmutable}>
|
||||||
*/
|
*/
|
||||||
public function buildWeeksForExercise(DateTimeImmutable $from, DateTimeImmutable $to): array
|
public function buildWeeksForExercise(DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||||
{
|
{
|
||||||
@@ -61,10 +61,7 @@ final readonly class RttRecoveryComputationService
|
|||||||
$effectiveEnd = $end > $to ? $to : $end;
|
$effectiveEnd = $end > $to ? $to : $end;
|
||||||
|
|
||||||
if ($effectiveEnd >= $effectiveStart) {
|
if ($effectiveEnd >= $effectiveStart) {
|
||||||
$saturday = $start->modify('+5 days');
|
$weeks[] = [
|
||||||
$monthAnchor = $saturday < $from ? $from : ($saturday > $to ? $to : $saturday);
|
|
||||||
$weeks[] = [
|
|
||||||
'month' => (int) $monthAnchor->format('n'),
|
|
||||||
'weekNumber' => (int) $effectiveStart->format('W'),
|
'weekNumber' => (int) $effectiveStart->format('W'),
|
||||||
'start' => $start,
|
'start' => $start,
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
@@ -82,7 +79,6 @@ final readonly class RttRecoveryComputationService
|
|||||||
$weeks = $this->buildWeeksForExercise($from, $to);
|
$weeks = $this->buildWeeksForExercise($from, $to);
|
||||||
$weekRanges = array_map(
|
$weekRanges = array_map(
|
||||||
static fn (array $week): array => [
|
static fn (array $week): array => [
|
||||||
'month' => (int) $week['month'],
|
|
||||||
'weekNumber' => (int) $week['weekNumber'],
|
'weekNumber' => (int) $week['weekNumber'],
|
||||||
'start' => $week['start'],
|
'start' => $week['start'],
|
||||||
'end' => $week['end'],
|
'end' => $week['end'],
|
||||||
@@ -108,7 +104,7 @@ final readonly class RttRecoveryComputationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<array{month:int,weekNumber:int,start:DateTimeImmutable,end:DateTimeImmutable}> $weeks
|
* @param list<array{weekNumber:int,start:DateTimeImmutable,end:DateTimeImmutable}> $weeks
|
||||||
*
|
*
|
||||||
* @return array<string, WeekRecoveryDetail>
|
* @return array<string, WeekRecoveryDetail>
|
||||||
*/
|
*/
|
||||||
@@ -189,6 +185,7 @@ final readonly class RttRecoveryComputationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$weeklyTotalMinutes = 0;
|
$weeklyTotalMinutes = 0;
|
||||||
|
$dailyWorkedMinutes = [];
|
||||||
$employeeContractsByDate = [];
|
$employeeContractsByDate = [];
|
||||||
foreach ($weekDays as $date) {
|
foreach ($weekDays as $date) {
|
||||||
$employeeContractsByDate[$date] = $contractsByDate[$employeeId][$date] ?? null;
|
$employeeContractsByDate[$date] = $contractsByDate[$employeeId][$date] ?? null;
|
||||||
@@ -198,6 +195,7 @@ final readonly class RttRecoveryComputationService
|
|||||||
$metrics = $metricsByDate[$date] ?? new WorkMetrics();
|
$metrics = $metricsByDate[$date] ?? new WorkMetrics();
|
||||||
$metrics->addCreditedMinutes($creditedByDate[$date] ?? 0);
|
$metrics->addCreditedMinutes($creditedByDate[$date] ?? 0);
|
||||||
$weeklyTotalMinutes += $metrics->totalMinutes;
|
$weeklyTotalMinutes += $metrics->totalMinutes;
|
||||||
|
$dailyWorkedMinutes[$date] = $metrics->totalMinutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([] === $weekDays) {
|
if ([] === $weekDays) {
|
||||||
@@ -244,6 +242,7 @@ final readonly class RttRecoveryComputationService
|
|||||||
base50Minutes: $base50,
|
base50Minutes: $base50,
|
||||||
bonus50Minutes: $bonus50,
|
bonus50Minutes: $bonus50,
|
||||||
totalMinutes: $totalMinutes,
|
totalMinutes: $totalMinutes,
|
||||||
|
dailyMinutes: $dailyWorkedMinutes,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,16 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fractionedDays = $this->resolveFractionedDays($employee, $yearSummary['ruleCode'], $year);
|
$fractionedDays = $this->resolveFractionedDays($employee, $yearSummary['ruleCode'], $year);
|
||||||
|
$paidLeaveDays = $this->resolvePaidLeaveDays($employee, $yearSummary['ruleCode'], $year);
|
||||||
|
|
||||||
|
// For forfait contracts, paid days reduce N-1 stock before taken-day attribution.
|
||||||
|
// Recompute with paidLeaveDays so taken days shift from N-1 to N when N-1 is consumed by payment.
|
||||||
|
if ($paidLeaveDays > 0.0) {
|
||||||
|
$yearSummary = $this->computeYearSummary($employee, $year, $paidLeaveDays);
|
||||||
|
if (null === $yearSummary) {
|
||||||
|
return $summary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$summary->isSupported = true;
|
$summary->isSupported = true;
|
||||||
$summary->ruleCode = $yearSummary['ruleCode'];
|
$summary->ruleCode = $yearSummary['ruleCode'];
|
||||||
@@ -107,6 +117,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
$summary->previousYearAcquiredDays = $yearSummary['previousYearAcquiredDays'];
|
$summary->previousYearAcquiredDays = $yearSummary['previousYearAcquiredDays'];
|
||||||
$summary->previousYearTakenDays = $yearSummary['previousYearTakenDays'];
|
$summary->previousYearTakenDays = $yearSummary['previousYearTakenDays'];
|
||||||
$summary->previousYearRemainingDays = $yearSummary['previousYearRemainingDays'];
|
$summary->previousYearRemainingDays = $yearSummary['previousYearRemainingDays'];
|
||||||
|
$summary->previousYearPaidDays = $paidLeaveDays;
|
||||||
|
|
||||||
[$periodFrom, $periodTo] = $this->resolvePeriodBounds($employee, $year);
|
[$periodFrom, $periodTo] = $this->resolvePeriodBounds($employee, $year);
|
||||||
$summary->presenceDaysByMonth = $this->computePresenceDaysByMonth($employee, $periodFrom, $periodTo);
|
$summary->presenceDaysByMonth = $this->computePresenceDaysByMonth($employee, $periodFrom, $periodTo);
|
||||||
@@ -129,7 +140,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
* previousYearRemainingDays: float
|
* previousYearRemainingDays: float
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public function computeYearSummary(Employee $employee, int $targetYear): ?array
|
public function computeYearSummary(Employee $employee, int $targetYear, float $paidLeaveDays = 0.0): ?array
|
||||||
{
|
{
|
||||||
$firstYear = max($this->resolveFirstComputationYear($employee), $targetYear - 1);
|
$firstYear = max($this->resolveFirstComputationYear($employee), $targetYear - 1);
|
||||||
if ($targetYear < $firstYear) {
|
if ($targetYear < $firstYear) {
|
||||||
@@ -269,13 +280,15 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
} else {
|
} else {
|
||||||
// Forfait: no "en cours d'acquisition" counter, all rights are in acquired.
|
// Forfait: no "en cours d'acquisition" counter, all rights are in acquired.
|
||||||
// Suspensions do not impact forfait 218 leave calculation.
|
// Suspensions do not impact forfait 218 leave calculation.
|
||||||
// Taken days are first deducted from N-1 carry, then from current year.
|
// Paid days reduce N-1 stock first, then taken days are attributed to what remains in N-1.
|
||||||
$previousYearAcquired = $carryDays;
|
$previousYearAcquired = $carryDays;
|
||||||
$takenFromPrevious = min(max(0.0, $previousYearAcquired), $takenDays);
|
$effectivePaidDays = ($year === $targetYear) ? $paidLeaveDays : 0.0;
|
||||||
$previousYearTaken = $takenFromPrevious;
|
$availableAfterPayment = max(0.0, $previousYearAcquired - $effectivePaidDays);
|
||||||
$takenFromCurrent = $takenDays - $takenFromPrevious;
|
$takenFromPrevious = min($availableAfterPayment, $takenDays);
|
||||||
|
$previousYearTaken = $takenFromPrevious;
|
||||||
|
$takenFromCurrent = $takenDays - $takenFromPrevious;
|
||||||
|
|
||||||
$previousYearRemaining = max(0.0, $previousYearAcquired - $takenFromPrevious);
|
$previousYearRemaining = max(0.0, $availableAfterPayment - $takenFromPrevious);
|
||||||
|
|
||||||
$acquiredDays = $leavePolicy['acquiredDays'];
|
$acquiredDays = $leavePolicy['acquiredDays'];
|
||||||
$accruingDays = 0.0;
|
$accruingDays = 0.0;
|
||||||
@@ -765,6 +778,13 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
return null !== $balance ? $balance->getFractionedDays() : 0.0;
|
return null !== $balance ? $balance->getFractionedDays() : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function resolvePaidLeaveDays(Employee $employee, string $ruleCode, int $year): float
|
||||||
|
{
|
||||||
|
$balance = $this->leaveBalanceRepository->findOneByEmployeeRuleAndYear($employee, $ruleCode, $year);
|
||||||
|
|
||||||
|
return null !== $balance ? $balance->getPaidLeaveDays() : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
private function resolveCurrentLeaveYear(DateTimeImmutable $today): int
|
private function resolveCurrentLeaveYear(DateTimeImmutable $today): int
|
||||||
{
|
{
|
||||||
$year = (int) $today->format('Y');
|
$year = (int) $today->format('Y');
|
||||||
|
|||||||
101
src/State/EmployeePaidLeaveDaysProcessor.php
Normal file
101
src/State/EmployeePaidLeaveDaysProcessor.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\State;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use App\ApiResource\EmployeePaidLeaveDaysInput;
|
||||||
|
use App\Entity\Employee;
|
||||||
|
use App\Entity\EmployeeLeaveBalance;
|
||||||
|
use App\Enum\ContractType;
|
||||||
|
use App\Enum\LeaveRuleCode;
|
||||||
|
use App\Repository\EmployeeLeaveBalanceRepository;
|
||||||
|
use App\Repository\EmployeeRepository;
|
||||||
|
use App\Service\AuditLogger;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||||
|
|
||||||
|
final readonly class EmployeePaidLeaveDaysProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private EmployeeRepository $employeeRepository,
|
||||||
|
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
|
private AuditLogger $auditLogger,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): EmployeePaidLeaveDaysInput
|
||||||
|
{
|
||||||
|
if (!$data instanceof EmployeePaidLeaveDaysInput) {
|
||||||
|
throw new UnprocessableEntityHttpException('Invalid payload.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$employeeId = (int) ($uriVariables['id'] ?? 0);
|
||||||
|
if ($employeeId <= 0) {
|
||||||
|
throw new UnprocessableEntityHttpException('id must be a positive integer.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$employee = $this->employeeRepository->find($employeeId);
|
||||||
|
if (!$employee instanceof Employee) {
|
||||||
|
throw new NotFoundHttpException('Employee not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$year = $data->year ?? $this->resolveCurrentYear($employee);
|
||||||
|
$ruleCode = $this->resolveRuleCode($employee);
|
||||||
|
|
||||||
|
$balance = $this->leaveBalanceRepository->findOneByEmployeeRuleAndYear($employee, $ruleCode, $year);
|
||||||
|
|
||||||
|
if (null === $balance) {
|
||||||
|
$balance = new EmployeeLeaveBalance();
|
||||||
|
$balance->setEmployee($employee);
|
||||||
|
$balance->setRuleCode($ruleCode);
|
||||||
|
$balance->setYear($year);
|
||||||
|
$this->entityManager->persist($balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
$balance->setPaidLeaveDays($data->paidLeaveDays);
|
||||||
|
$balance->touch();
|
||||||
|
|
||||||
|
$empName = trim(($employee->getLastName() ?? '').' '.($employee->getFirstName() ?? ''));
|
||||||
|
$this->auditLogger->log(
|
||||||
|
$employee,
|
||||||
|
'update',
|
||||||
|
'paid_leave_days',
|
||||||
|
$balance->getId(),
|
||||||
|
sprintf('Congés N-1 payés modifiés pour %s (année %d) : %s', $empName, $year, (string) $data->paidLeaveDays),
|
||||||
|
['new' => ['paidLeaveDays' => $data->paidLeaveDays, 'year' => $year]],
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$data->year = $year;
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveRuleCode(Employee $employee): LeaveRuleCode
|
||||||
|
{
|
||||||
|
if (ContractType::FORFAIT === $employee->getContract()?->getType()) {
|
||||||
|
return LeaveRuleCode::FORFAIT_218;
|
||||||
|
}
|
||||||
|
|
||||||
|
return LeaveRuleCode::CDI_CDD_NON_FORFAIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveCurrentYear(Employee $employee): int
|
||||||
|
{
|
||||||
|
$today = new DateTimeImmutable('today');
|
||||||
|
|
||||||
|
if (ContractType::FORFAIT === $employee->getContract()?->getType()) {
|
||||||
|
return (int) $today->format('Y');
|
||||||
|
}
|
||||||
|
|
||||||
|
$month = (int) $today->format('n');
|
||||||
|
|
||||||
|
return $month >= 6 ? (int) $today->format('Y') + 1 : (int) $today->format('Y');
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/State/EmployeePaidLeaveDaysProvider.php
Normal file
17
src/State/EmployeePaidLeaveDaysProvider.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\State;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\ApiResource\EmployeePaidLeaveDaysInput;
|
||||||
|
|
||||||
|
final readonly class EmployeePaidLeaveDaysProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): EmployeePaidLeaveDaysInput
|
||||||
|
{
|
||||||
|
return new EmployeePaidLeaveDaysInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,7 +71,6 @@ final readonly class EmployeeRttSummaryProvider implements ProviderInterface
|
|||||||
$weeks = $this->rttRecoveryService->buildWeeksForExercise($periodFrom, $periodTo);
|
$weeks = $this->rttRecoveryService->buildWeeksForExercise($periodFrom, $periodTo);
|
||||||
$weekRanges = array_map(
|
$weekRanges = array_map(
|
||||||
static fn (array $week): array => [
|
static fn (array $week): array => [
|
||||||
'month' => (int) $week['month'],
|
|
||||||
'weekNumber' => (int) $week['weekNumber'],
|
'weekNumber' => (int) $week['weekNumber'],
|
||||||
'start' => $week['start'],
|
'start' => $week['start'],
|
||||||
'end' => $week['end'],
|
'end' => $week['end'],
|
||||||
@@ -118,25 +117,7 @@ final readonly class EmployeeRttSummaryProvider implements ProviderInterface
|
|||||||
$summary->rttStartDate = $this->rttStartDate;
|
$summary->rttStartDate = $this->rttStartDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$summary->weeks = array_map(
|
$summary->weeks = $this->buildWeekSummaries($weekRanges, $currentByWeekStart, $periodFrom, $periodTo);
|
||||||
static function (array $week) use ($currentByWeekStart) {
|
|
||||||
$detail = $currentByWeekStart[$week['start']->format('Y-m-d')] ?? new WeekRecoveryDetail();
|
|
||||||
|
|
||||||
return new EmployeeRttWeekSummary(
|
|
||||||
month: (int) $week['month'],
|
|
||||||
weekNumber: (int) $week['weekNumber'],
|
|
||||||
weekStart: $week['start']->format('Y-m-d'),
|
|
||||||
weekEnd: $week['end']->format('Y-m-d'),
|
|
||||||
overtimeMinutes: $detail->overtimeMinutes,
|
|
||||||
base25Minutes: $detail->base25Minutes,
|
|
||||||
bonus25Minutes: $detail->bonus25Minutes,
|
|
||||||
base50Minutes: $detail->base50Minutes,
|
|
||||||
bonus50Minutes: $detail->bonus50Minutes,
|
|
||||||
totalMinutes: $detail->totalMinutes,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
$weekRanges
|
|
||||||
);
|
|
||||||
|
|
||||||
// Post-process: distribute deficit weeks across cumulative balance (50% first, then 25%)
|
// Post-process: distribute deficit weeks across cumulative balance (50% first, then 25%)
|
||||||
$cumulative50 = $carry->base50Minutes + $carry->bonus50Minutes;
|
$cumulative50 = $carry->base50Minutes + $carry->bonus50Minutes;
|
||||||
@@ -269,4 +250,77 @@ final readonly class EmployeeRttSummaryProvider implements ProviderInterface
|
|||||||
|
|
||||||
return $weekEnd;
|
return $weekEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build week summaries, splitting weeks that span two months into two entries
|
||||||
|
* with values distributed proportionally based on daily worked minutes.
|
||||||
|
*
|
||||||
|
* @param list<array{weekNumber:int,start:DateTimeImmutable,end:DateTimeImmutable}> $weekRanges
|
||||||
|
* @param array<string, WeekRecoveryDetail> $recoveryByWeek
|
||||||
|
*
|
||||||
|
* @return list<EmployeeRttWeekSummary>
|
||||||
|
*/
|
||||||
|
private function buildWeekSummaries(array $weekRanges, array $recoveryByWeek, DateTimeImmutable $periodFrom, DateTimeImmutable $periodTo): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($weekRanges as $week) {
|
||||||
|
$weekStart = $week['start'];
|
||||||
|
$weekEnd = $week['end'];
|
||||||
|
$weekKey = $weekStart->format('Y-m-d');
|
||||||
|
$detail = $recoveryByWeek[$weekKey] ?? new WeekRecoveryDetail();
|
||||||
|
|
||||||
|
$effectiveStart = $weekStart < $periodFrom ? $periodFrom : $weekStart;
|
||||||
|
$effectiveEnd = $weekEnd > $periodTo ? $periodTo : $weekEnd;
|
||||||
|
|
||||||
|
$startMonth = (int) $effectiveStart->format('n');
|
||||||
|
$endMonth = (int) $effectiveEnd->format('n');
|
||||||
|
|
||||||
|
if ($startMonth === $endMonth) {
|
||||||
|
$result[] = new EmployeeRttWeekSummary(
|
||||||
|
month: $startMonth,
|
||||||
|
weekNumber: (int) $week['weekNumber'],
|
||||||
|
weekStart: $weekStart->format('Y-m-d'),
|
||||||
|
weekEnd: $weekEnd->format('Y-m-d'),
|
||||||
|
overtimeMinutes: $detail->overtimeMinutes,
|
||||||
|
base25Minutes: $detail->base25Minutes,
|
||||||
|
bonus25Minutes: $detail->bonus25Minutes,
|
||||||
|
base50Minutes: $detail->base50Minutes,
|
||||||
|
bonus50Minutes: $detail->bonus50Minutes,
|
||||||
|
totalMinutes: $detail->totalMinutes,
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Week spans two months — split proportionally by daily worked minutes
|
||||||
|
$monthMinutes = [];
|
||||||
|
foreach ($detail->dailyMinutes as $date => $mins) {
|
||||||
|
$m = (int) new DateTimeImmutable($date)->format('n');
|
||||||
|
$monthMinutes[$m] = ($monthMinutes[$m] ?? 0) + $mins;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalWorked = array_sum($monthMinutes);
|
||||||
|
|
||||||
|
foreach ([$startMonth, $endMonth] as $month) {
|
||||||
|
$portion = $monthMinutes[$month] ?? 0;
|
||||||
|
$ratio = $totalWorked > 0 ? $portion / $totalWorked : 0.0;
|
||||||
|
|
||||||
|
$result[] = new EmployeeRttWeekSummary(
|
||||||
|
month: $month,
|
||||||
|
weekNumber: (int) $week['weekNumber'],
|
||||||
|
weekStart: $weekStart->format('Y-m-d'),
|
||||||
|
weekEnd: $weekEnd->format('Y-m-d'),
|
||||||
|
overtimeMinutes: (int) round($detail->overtimeMinutes * $ratio),
|
||||||
|
base25Minutes: (int) round($detail->base25Minutes * $ratio),
|
||||||
|
bonus25Minutes: (int) round($detail->bonus25Minutes * $ratio),
|
||||||
|
base50Minutes: (int) round($detail->base50Minutes * $ratio),
|
||||||
|
bonus50Minutes: (int) round($detail->bonus50Minutes * $ratio),
|
||||||
|
totalMinutes: (int) round($detail->totalMinutes * $ratio),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user