Compare commits

...

28 Commits

Author SHA1 Message Date
gitea-actions
1858817649 chore: bump version to v0.1.31
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m12s
2026-03-12 15:58:05 +00:00
99f0f191f4 Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-12 16:57:55 +01:00
96617f04bc fix : style du drawer de suspension 2026-03-12 16:57:45 +01:00
gitea-actions
25d961c367 chore: bump version to v0.1.30
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m13s
2026-03-12 15:46:17 +00:00
38f09914cb feat : ajout des suspensions et des jours de présence
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-12 16:46:06 +01:00
gitea-actions
e6819bc68a chore: bump version to v0.1.29
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m11s
2026-03-12 11:30:22 +00:00
6153175ca0 feat : ajout des icons dans la sidebar et redirection après login sur le calendrier
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-12 12:30:13 +01:00
gitea-actions
49a1c07ed1 chore: bump version to v0.1.28
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m10s
2026-03-12 10:23:20 +00:00
9fe2397386 feat : ajout d'une date d'entrée pour les employés
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-12 11:23:09 +01:00
gitea-actions
bf3f7b35a5 chore: bump version to v0.1.27
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m15s
2026-03-12 09:37:13 +00:00
5c251800fa Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
2026-03-12 10:37:03 +01:00
e34e928264 fix : calcule des congés en cours d'acquisition au prorata (date début contrat) 2026-03-12 10:36:49 +01:00
gitea-actions
f7dc9b6988 chore: bump version to v0.1.26
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m11s
2026-03-11 16:34:29 +00:00
b0de877b27 Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-11 17:34:15 +01:00
59f05717bf fix : prise en compte des congés au provisionnel sauf pour les en cours d'acquisition 2026-03-11 17:34:07 +01:00
gitea-actions
f96fd64767 chore: bump version to v0.1.25
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m12s
2026-03-11 16:27:05 +00:00
523d4f296b fix : prise en compte des congés au provisionnel
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-11 17:26:48 +01:00
gitea-actions
3994be6556 chore: bump version to v0.1.24
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m8s
2026-03-11 12:53:39 +00:00
f46eeaa893 fix : prise en compte des jours de congés sur l'année N-1 même si on a pas d'historique de contrat sur l'année N-1
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-11 13:53:29 +01:00
gitea-actions
eb703272c7 chore: bump version to v0.1.23
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m11s
2026-03-11 10:41:38 +00:00
6629eb98cb fix : on ne prend plus en compte les jour de congé du samedi et dimanche pour les forfaits dans le calcule des RTT
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-11 11:41:26 +01:00
gitea-actions
029bc03a5a chore: bump version to v0.1.22
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m12s
2026-03-11 09:05:51 +00:00
82e575fff0 fix : plus de date de fin obligatoire sur les contrats interim
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-11 10:05:41 +01:00
gitea-actions
0213c0a97d chore: bump version to v0.1.21
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m11s
2026-03-11 07:50:38 +00:00
12def35dda Merge remote-tracking branch 'origin/develop' into develop
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-11 08:50:23 +01:00
2d1c1e6e22 fix : api jour férié qui a changé d'url 2026-03-11 08:42:57 +01:00
gitea-actions
f7568f2d09 chore: bump version to v0.1.20
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m30s
2026-03-10 16:07:18 +00:00
9c164fe78e fix : prise en compte de la balance des congés
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-10 17:07:09 +01:00
40 changed files with 4198 additions and 107 deletions

View File

@@ -6,7 +6,22 @@
"Bash(php:*)",
"Bash(docker compose:*)",
"Bash(make test:*)",
"Bash(grep:*)"
"Bash(grep:*)",
"Bash(docker exec:*)",
"Bash(php8.3 bin/phpunit tests/State/EmployeeWriteProcessorTest.php --filter=testSetsEntryDateOnNewEmployee 2>&1)",
"Read(//usr/bin/**)",
"Read(//usr/local/bin/**)",
"Bash(command -v php8.2)",
"Bash(command -v php8.1)",
"Bash(ls /usr/bin/php*)",
"Read(//opt/**)",
"Read(//home/m-tristan/.nix-profile/**)",
"Read(//home/m-tristan/.local/bin/**)",
"Bash(env)",
"Bash(ls /home/m-tristan/workspace/SIRH/docker* /home/m-tristan/workspace/SIRH/Makefile 2>/dev/null; cat /home/m-tristan/workspace/SIRH/Makefile 2>/dev/null | grep -E \"\\(phpunit|test|php\\)\" | head -20)",
"Bash(which python3:*)",
"Bash(sudo apt-get:*)",
"Bash(npx xlsx-cli:*)"
]
}
}

View File

@@ -22,6 +22,10 @@ services:
App\:
resource: '../src/'
App\Service\PublicHolidayService:
arguments:
$holidayUrl: '%env(HOLIDAY_URL)%'
App\Repository\Contract\AbsenceReadRepositoryInterface: '@App\Repository\AbsenceRepository'
App\Repository\Contract\EmployeeContractPeriodReadRepositoryInterface: '@App\Repository\EmployeeContractPeriodRepository'
App\Repository\Contract\EmployeeScopedRepositoryInterface: '@App\Repository\EmployeeRepository'

View File

@@ -1,2 +1,2 @@
parameters:
app.version: '0.1.19'
app.version: '0.1.31'

View File

@@ -169,11 +169,13 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
- acquis annuel samedi: `5`
- 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 cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
- samedis acquis affiches: uniquement `opening_saturdays` (report N-1)
- contrat `4h`:
- acquis annuel CP: `10`
- acquis annuel samedi: `0`
- 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
- contrat `FORFAIT`:
- 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
@@ -198,13 +200,16 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
- lecture des compteurs:
- `acquis` = droits reportés de l'exercice N-1 (après application des règles de soldé)
- `en cours d'acquisition` = total droits générés sur l'exercice N (jours + samedis en cours), sans detail séparé en UI
- `en cours d'acquisition` est arrêté au dernier jour du mois précédent
- règle de consommation:
- les absences s'imputent d'abord sur `acquis`, puis sur `en cours d'acquisition`
- la prise sur `en cours d'acquisition` est autorisée (usage anticipé)
- `en cours d'acquisition` peut devenir négatif si la prise dépasse le généré (ex: `2.08 - 3 = -0.92`), puis se reconstitue avec les acquisitions suivantes
- date d'arret de calcul:
- les compteurs sont calculés jusqu'au dernier jour du mois précédent (le mois en cours est exclu)
- exemple: au `04/03/2026`, l'arret de calcul est le `28/02/2026` (ou `29/02` en année bissextile)
- `reste à prendre` est calculé en prévisionnel jusqu'à la fin de l'exercice
- les absences futures déjà posées sur l'exercice sont déduites du `reste à prendre`
- `en cours d'acquisition` reste calculé jusqu'au dernier jour du mois précédent
- exemple: au `11/03/2026`, l'exercice `2026` déduit les absences posées jusqu'au `31/05/2026`, mais l'acquisition reste arrêtée au `28/02/2026`
- hors périmètre phase 1: `INTERIM` (retour non supporté)
- onglet `RTT`:
- endpoint de synthèse: `GET /api/employees/{id}/rtt-summary?year=YYYY`

View File

@@ -0,0 +1,484 @@
# RTT : Affichage en heures + Paiement RTT
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Afficher les RTT en heures (plus en jours), permettre le paiement RTT via drawer avec majoration 25%/50%, stocker en BDD et afficher par mois.
**Architecture:** Nouvelle entity `EmployeeRttPayment` (employee, year, month, minutes, rate). Le provider RTT agrège les paiements par mois et les soustrait du disponible. Le frontend ajoute un drawer de saisie et deux lignes par mois (25% / 50%).
**Tech Stack:** Symfony + Doctrine + API Platform (backend), Nuxt 4 + Vue 3 + TypeScript + Tailwind (frontend)
---
## Contexte existant
- **Entity:** `EmployeeRttBalance` dans `src/Entity/EmployeeRttBalance.php` - stocke `openingMinutes` par exercice
- **Provider:** `src/State/EmployeeRttSummaryProvider.php` - calcule `availableMinutes = carry + currentYearRecovery`
- **Service:** `src/Service/Rtt/RttRecoveryComputationService.php` - calcul semaine par semaine
- **Frontend:** `frontend/components/employees/RttTab.vue` - affichage grille mois/semaines
- **DTO backend:** `src/ApiResource/EmployeeRttSummary.php` - champs `availableMinutes`, `weeks[]`
- **DTO frontend:** `frontend/services/dto/employee-rtt-summary.ts`
- Les minutes sont la base de calcul. 1 jour = 7h = 420 minutes.
- Exercice RTT : 1er juin N-1 -> 31 mai N (year = N)
---
### Task 1: Migration - Créer la table `employee_rtt_payments`
**Files:**
- Create: `migrations/Version20260309140000.php`
**Step 1: Créer la migration**
```php
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260309140000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create employee_rtt_payments table for RTT paid hours tracking.';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE TABLE employee_rtt_payments (
id SERIAL PRIMARY KEY,
employee_id INT NOT NULL REFERENCES employees(id) ON DELETE CASCADE,
year INT NOT NULL,
month INT NOT NULL,
minutes INT NOT NULL,
rate VARCHAR(10) NOT NULL,
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL DEFAULT NOW()
)
SQL);
$this->addSql('CREATE INDEX idx_rtt_payment_employee_year ON employee_rtt_payments (employee_id, year)');
$this->addSql("COMMENT ON TABLE employee_rtt_payments IS 'Paiements RTT par employe, mois et taux de majoration.'");
$this->addSql("COMMENT ON COLUMN employee_rtt_payments.rate IS 'Taux de majoration: 25 ou 50.'");
$this->addSql("COMMENT ON COLUMN employee_rtt_payments.minutes IS 'Minutes RTT payees pour ce mois et ce taux.'");
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE employee_rtt_payments');
}
}
```
**Step 2: Exécuter la migration**
Run: `make migrate` ou `docker compose exec php php bin/console doctrine:migrations:migrate --no-interaction`
Expected: Migration exécutée sans erreur
**Step 3: Commit**
```bash
git add migrations/Version20260309140000.php
git commit -m "feat(rtt): add employee_rtt_payments table"
```
---
### Task 2: Entity + Repository `EmployeeRttPayment`
**Files:**
- Create: `src/Entity/EmployeeRttPayment.php`
- Create: `src/Repository/EmployeeRttPaymentRepository.php`
**Step 1: Créer l'entity**
```php
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\EmployeeRttPaymentRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmployeeRttPaymentRepository::class)]
#[ORM\Table(name: 'employee_rtt_payments')]
#[ORM\Index(columns: ['employee_id', 'year'], name: 'idx_rtt_payment_employee_year')]
class EmployeeRttPayment
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Employee::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Employee $employee = null;
#[ORM\Column(type: 'integer')]
private int $year = 0;
#[ORM\Column(type: 'integer')]
private int $month = 0;
#[ORM\Column(type: 'integer', options: ['comment' => 'Minutes RTT payees pour ce mois et ce taux.'])]
private int $minutes = 0;
#[ORM\Column(length: 10, options: ['comment' => 'Taux de majoration: 25 ou 50.'])]
private string $rate = '25';
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $createdAt;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $updatedAt;
public function __construct()
{
$now = new DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
}
// Getters & setters (getId, getEmployee/setEmployee, getYear/setYear,
// getMonth/setMonth, getMinutes/setMinutes, getRate/setRate, touch)
// Suivre le même pattern que EmployeeLeaveBalance
}
```
**Step 2: Créer le repository**
```php
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\Employee;
use App\Entity\EmployeeRttPayment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<EmployeeRttPayment>
*/
final class EmployeeRttPaymentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EmployeeRttPayment::class);
}
/**
* @return list<EmployeeRttPayment>
*/
public function findByEmployeeAndYear(Employee $employee, int $year): array
{
return $this->createQueryBuilder('p')
->andWhere('p.employee = :employee')
->andWhere('p.year = :year')
->setParameter('employee', $employee)
->setParameter('year', $year)
->orderBy('p.month', 'ASC')
->getQuery()
->getResult();
}
}
```
**Step 3: Vérifier le lint**
Run: `docker compose exec php php -l src/Entity/EmployeeRttPayment.php && docker compose exec php php -l src/Repository/EmployeeRttPaymentRepository.php`
Expected: No syntax errors
**Step 4: Commit**
```bash
git add src/Entity/EmployeeRttPayment.php src/Repository/EmployeeRttPaymentRepository.php
git commit -m "feat(rtt): add EmployeeRttPayment entity and repository"
```
---
### Task 3: API Resource + Provider + Processor pour le paiement RTT
**Files:**
- Create: `src/ApiResource/EmployeeRttPaymentInput.php`
- Create: `src/State/EmployeeRttPaymentProvider.php`
- Create: `src/State/EmployeeRttPaymentProcessor.php`
**Step 1: Créer l'API Resource**
Endpoint: `PATCH /employees/{id}/rtt-payments` (ROLE_ADMIN)
Body: `{ "month": 3, "minutes": 120, "rate": "25" }`
```php
// src/ApiResource/EmployeeRttPaymentInput.php
#[ApiResource(
operations: [
new Patch(
uriTemplate: '/employees/{id}/rtt-payments',
security: "is_granted('ROLE_ADMIN')",
provider: EmployeeRttPaymentProvider::class,
processor: EmployeeRttPaymentProcessor::class
),
],
paginationEnabled: false
)]
final class EmployeeRttPaymentInput
{
public int $month = 0;
public int $minutes = 0;
public string $rate = '25';
public ?int $year = null;
}
```
**Step 2: Créer le Provider** (retourne un DTO vide, même pattern que `EmployeeFractionedDaysProvider`)
**Step 3: Créer le Processor**
Logique:
- Valider `rate` in `['25', '50']`, `month` in `[1..12]`, `minutes >= 0`
- Résoudre l'année (même logique exercice RTT que le provider existant)
- Persister un `EmployeeRttPayment`
**Step 4: Vérifier le lint**
**Step 5: Commit**
```bash
git add src/ApiResource/EmployeeRttPaymentInput.php src/State/EmployeeRttPaymentProvider.php src/State/EmployeeRttPaymentProcessor.php
git commit -m "feat(rtt): add PATCH endpoint for RTT payment"
```
---
### Task 4: Modifier le DTO + Provider RTT pour inclure les paiements par mois
**Files:**
- Modify: `src/ApiResource/EmployeeRttSummary.php`
- Modify: `src/State/EmployeeRttSummaryProvider.php`
- Create: `src/Dto/Rtt/RttMonthPayment.php`
- Modify: `frontend/services/dto/employee-rtt-summary.ts`
**Step 1: Créer le DTO mois-paiement**
```php
// src/Dto/Rtt/RttMonthPayment.php
final class RttMonthPayment
{
public function __construct(
public int $month,
public int $paidMinutes25 = 0,
public int $paidMinutes50 = 0,
) {}
}
```
**Step 2: Ajouter au summary backend**
Dans `EmployeeRttSummary.php`, ajouter:
```php
public int $totalPaidMinutes = 0;
/** @var list<RttMonthPayment> */
public array $monthPayments = [];
```
Et modifier `availableMinutes` pour soustraire les paiements:
```php
$summary->availableMinutes = $summary->carryFromPreviousYearMinutes
+ $summary->currentYearRecoveryMinutes
- $summary->totalPaidMinutes;
```
**Step 3: Modifier le provider** pour charger les paiements via le repository et les agréger par mois
Dans `EmployeeRttSummaryProvider::provide()`:
- Charger `$payments = $this->rttPaymentRepository->findByEmployeeAndYear($employee, $year)`
- Agréger par mois + rate pour construire les `RttMonthPayment`
- Calculer `totalPaidMinutes = sum(minutes)`
- Soustraire du `availableMinutes`
**Step 4: Mettre à jour le DTO frontend**
Dans `frontend/services/dto/employee-rtt-summary.ts`:
```typescript
export type RttMonthPayment = {
month: number
paidMinutes25: number
paidMinutes50: number
}
export type EmployeeRttSummary = {
// ... champs existants ...
totalPaidMinutes: number
monthPayments: RttMonthPayment[]
}
```
**Step 5: Commit**
```bash
git commit -m "feat(rtt): include paid hours in RTT summary by month"
```
---
### Task 5: Frontend - Afficher les RTT en heures + lignes payées
**Files:**
- Modify: `frontend/components/employees/RttTab.vue`
**Step 1: Changer l'affichage du header de jours en heures**
Ligne 4 actuelle:
```html
<p>...: {{ formatDays(summary?.availableMinutes ?? 0) }}</p>
```
Remplacer par:
```html
<p>...: {{ formatMinutes(summary?.availableMinutes ?? 0) }}</p>
```
**Step 2: Ajouter les 2 lignes de paiement par mois**
Après la ligne `Heure payée` existante (ligne 33-34), remplacer par 2 lignes distinctes:
```html
<div class="py-[6px] pl-3 border-r border-b border-primary-500">Heure payée 25%</div>
<div class="py-[6px] pl-3 border-b border-primary-500">{{ formatMinutes(getMonthPaid25(month.month)) }}</div>
<div class="py-[6px] pl-3 border-r border-primary-500">Heure payée 50%</div>
<div class="py-[6px] pl-3">{{ formatMinutes(getMonthPaid50(month.month)) }}</div>
```
**Step 3: Ajouter les helpers computed**
```typescript
const paymentsByMonth = computed(() => {
const map = new Map<number, { paid25: number; paid50: number }>()
for (const mp of props.summary?.monthPayments ?? []) {
map.set(mp.month, { paid25: mp.paidMinutes25, paid50: mp.paidMinutes50 })
}
return map
})
const getMonthPaid25 = (month: number) => paymentsByMonth.value.get(month)?.paid25 ?? 0
const getMonthPaid50 = (month: number) => paymentsByMonth.value.get(month)?.paid50 ?? 0
```
**Step 4: Commit**
```bash
git commit -m "feat(rtt): display hours instead of days + paid hours per month"
```
---
### Task 6: Frontend - Drawer de paiement RTT
**Files:**
- Modify: `frontend/components/employees/RttTab.vue`
- Modify: `frontend/services/employee-rtt-summary.ts`
- Modify: `frontend/composables/useEmployeeDetailPage.ts`
- Modify: `frontend/pages/employees/[id].vue`
**Step 1: Ajouter le service API**
Dans `frontend/services/employee-rtt-summary.ts`:
```typescript
export const createRttPayment = async (
employeeId: number,
month: number,
minutes: number,
rate: '25' | '50',
year?: number
) => {
const api = useApi()
const body: Record<string, unknown> = { month, minutes, rate }
if (year) body.year = year
return api.patch(`/employees/${employeeId}/rtt-payments`, body)
}
```
**Step 2: Ajouter au composable**
Dans `useEmployeeDetailPage.ts`:
- Import `createRttPayment`
- Ajouter `submitRttPayment(month, minutes, rate)` qui appelle l'API puis `loadEmployee()`
- Exposer dans le return
**Step 3: Passer l'event dans la page**
Dans `frontend/pages/employees/[id].vue`:
- Destructurer `submitRttPayment`
- Ajouter `@submit-rtt-payment="submitRttPayment"` sur `<EmployeesRttTab>`
**Step 4: Ajouter le drawer dans RttTab.vue**
Même pattern que le drawer fractionnés dans LeaveTab:
- Import `AppDrawer`
- State: `isPaymentDrawerOpen`, `paymentForm: { month, minutes, rate }`
- Bouton "Payer les RTT" ouvre le drawer
- Formulaire avec:
- Select mois (Janvier..Décembre)
- Input number "Nombre d'heures" (step 0.5, converti en minutes au submit)
- Select rate: "25%" / "50%"
- Boutons Annuler / Enregistrer
- Emit `submit-rtt-payment` au submit
**Step 5: Commit**
```bash
git commit -m "feat(rtt): add payment drawer with month/hours/rate fields"
```
---
### Task 7: Documentation fonctionnelle
**Files:**
- Modify: `doc/functional-rules.md`
**Step 1: Mettre à jour la section RTT**
Ajouter après les règles RTT existantes:
- Paiement RTT: saisie RH via `PATCH /employees/{id}/rtt-payments`
- Stocké dans `employee_rtt_payments` (employee, year, month, minutes, rate)
- Les heures payées sont soustraites du disponible RTT
- Affichage: 2 lignes par mois (25% et 50%)
- L'affichage global RTT est en heures (plus en jours)
**Step 2: Commit**
```bash
git commit -m "docs: update functional rules with RTT payment feature"
```
---
## Résumé des fichiers
| Action | Fichier |
|--------|---------|
| Create | `migrations/Version20260309140000.php` |
| Create | `src/Entity/EmployeeRttPayment.php` |
| Create | `src/Repository/EmployeeRttPaymentRepository.php` |
| Create | `src/ApiResource/EmployeeRttPaymentInput.php` |
| Create | `src/State/EmployeeRttPaymentProvider.php` |
| Create | `src/State/EmployeeRttPaymentProcessor.php` |
| Create | `src/Dto/Rtt/RttMonthPayment.php` |
| Modify | `src/ApiResource/EmployeeRttSummary.php` |
| Modify | `src/State/EmployeeRttSummaryProvider.php` |
| Modify | `frontend/services/dto/employee-rtt-summary.ts` |
| Modify | `frontend/services/employee-rtt-summary.ts` |
| Modify | `frontend/components/employees/RttTab.vue` |
| Modify | `frontend/composables/useEmployeeDetailPage.ts` |
| Modify | `frontend/pages/employees/[id].vue` |
| Modify | `doc/functional-rules.md` |

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,273 @@
# Employee Entry Date Implementation Plan
> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Add an `entryDate` field to Employee, automatically populated from `contractStartDate` at creation.
**Architecture:** New nullable `DATE` column on `employees` table. The `EmployeeWriteProcessor` sets `entryDate` from the first contract period's start date during employee creation. Exposed read-only in the API. No fallback needed — existing employees will be updated manually in prod DB.
**Tech Stack:** Symfony/Doctrine (backend), Nuxt/Vue/TypeScript (frontend)
---
## File Structure
| File | Action | Responsibility |
|------|--------|----------------|
| `src/Entity/Employee.php` | Modify | Add `entryDate` column + getter/setter, expose in `employee:read` |
| `src/State/EmployeeWriteProcessor.php` | Modify | Set `entryDate` from `contractStartDate` on creation |
| `migrations/Version20260312120000.php` | Create | Add `entry_date` column to `employees` table |
| `tests/State/EmployeeWriteProcessorTest.php` | Modify | Assert `entryDate` is set on new employee |
| `frontend/services/dto/employee.ts` | Modify | Add `entryDate` field to `Employee` type |
| `frontend/pages/employees/index.vue` | Modify | Display entry date in employee list |
---
## Chunk 1: Backend
### Task 1: Migration
**Files:**
- Create: `migrations/Version20260312120000.php`
- [ ] **Step 1: Create the migration file**
```php
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260312120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add entry_date column to employees table';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE employees ADD entry_date DATE DEFAULT NULL COMMENT \'(DC2Type:date_immutable)\'');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE employees DROP entry_date');
}
}
```
- [ ] **Step 2: Run migration**
Run: `php bin/console doctrine:migrations:migrate --no-interaction`
Expected: Migration applied successfully
- [ ] **Step 3: Commit**
```bash
git add migrations/Version20260312120000.php
git commit -m "feat : ajout colonne entry_date sur employees"
```
---
### Task 2: Entity — add `entryDate` property
**Files:**
- Modify: `src/Entity/Employee.php:56-61` (insert after `displayOrder`)
- [ ] **Step 1: Add the column, getter, and setter to Employee entity**
Add after the `displayOrder` property (line 58):
```php
#[ORM\Column(type: 'date_immutable', nullable: true)]
#[Groups(['employee:read'])]
private ?\DateTimeImmutable $entryDate = null;
```
Add getter and setter after `setDisplayOrder()` (after line 167):
```php
public function getEntryDate(): ?\DateTimeImmutable
{
return $this->entryDate;
}
public function setEntryDate(?\DateTimeImmutable $entryDate): self
{
$this->entryDate = $entryDate;
return $this;
}
```
- [ ] **Step 2: Verify schema is in sync**
Run: `php bin/console doctrine:schema:validate`
Expected: OK (or only existing unrelated warnings)
- [ ] **Step 3: Commit**
```bash
git add src/Entity/Employee.php
git commit -m "feat : ajout propriete entryDate sur Employee"
```
---
### Task 3: Set `entryDate` on employee creation
**Files:**
- Modify: `src/State/EmployeeWriteProcessor.php:60-71`
- Modify: `tests/State/EmployeeWriteProcessorTest.php`
- [ ] **Step 1: Write the failing test**
Add `use ApiPlatform\Metadata\Post;` to the imports at the top of the test file (alongside the existing `Delete` and `Patch` imports).
Then add this test method to `EmployeeWriteProcessorTest`:
```php
public function testSetsEntryDateOnNewEmployee(): void
{
$employee = new Employee();
$employee->setFirstName('Jane');
$employee->setLastName('Doe');
$employee->setContractStartDate('2026-04-01');
$employee->setContractNature('CDI');
$contract = new Contract()
->setName('35h')
->setTrackingMode(Contract::TRACKING_TIME)
->setWeeklyHours(35);
$employee->setContract($contract);
$persistProcessor = $this->createMock(ProcessorInterface::class);
$removeProcessor = $this->createStub(ProcessorInterface::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$periodRepository = $this->createStub(EmployeeContractPeriodReadRepositoryInterface::class);
$changeRequestFactory = new EmployeeContractChangeRequestFactory();
$periodManager = $this->createMock(EmployeeContractPeriodManagerInterface::class);
$persistProcessor
->expects(self::once())
->method('process')
->willReturn($employee);
$periodManager
->expects(self::once())
->method('ensureContractPeriodExists');
$processor = new EmployeeWriteProcessor(
$persistProcessor,
$removeProcessor,
$entityManager,
$periodRepository,
$changeRequestFactory,
$periodManager
);
$processor->process($employee, new Post());
self::assertNotNull($employee->getEntryDate());
self::assertSame('2026-04-01', $employee->getEntryDate()->format('Y-m-d'));
}
```
- [ ] **Step 2: Run test to verify it fails**
Run: `php bin/phpunit tests/State/EmployeeWriteProcessorTest.php --filter=testSetsEntryDateOnNewEmployee`
Expected: FAIL — `entryDate` is null
- [ ] **Step 3: Implement — set entryDate in EmployeeWriteProcessor**
In `src/State/EmployeeWriteProcessor.php`, inside the `if ($isNew)` block (line 60-71), add **before** `return $result;` (line 71):
```php
$data->setEntryDate($startDate);
```
The full block becomes:
```php
if ($isNew) {
$startDate = $changeRequest->contractStartDate ?? new DateTimeImmutable('1970-01-01');
$nature = $changeRequest->contractNature ?? ContractNature::CDI;
$this->periodManager->ensureContractPeriodExists(
employee: $data,
contract: $currentContract,
startDate: $startDate,
endDate: $changeRequest->contractEndDate,
nature: $nature
);
$data->setEntryDate($startDate);
return $result;
}
```
- [ ] **Step 4: Run test to verify it passes**
Run: `php bin/phpunit tests/State/EmployeeWriteProcessorTest.php --filter=testSetsEntryDateOnNewEmployee`
Expected: PASS
- [ ] **Step 5: Run all EmployeeWriteProcessor tests**
Run: `php bin/phpunit tests/State/EmployeeWriteProcessorTest.php`
Expected: All tests pass (no regression)
- [ ] **Step 6: Commit**
```bash
git add src/State/EmployeeWriteProcessor.php tests/State/EmployeeWriteProcessorTest.php
git commit -m "feat : remplissage automatique entryDate a la creation employe"
```
---
## Chunk 2: Frontend
### Task 4: Update frontend DTO and display entry date
**Files:**
- Modify: `frontend/services/dto/employee.ts:14-25`
- Modify: `frontend/pages/employees/index.vue`
- [ ] **Step 1: Add `entryDate` to the Employee DTO**
In `frontend/services/dto/employee.ts:24`, add `entryDate` after `displayOrder`:
```typescript
displayOrder?: number
entryDate?: string | null
```
- [ ] **Step 2: Display entry date in the employee card hover overlay**
In `frontend/pages/employees/index.vue`, inside the hover overlay `<div>` (line 49-54), add a new line after the "Site" line (after line 53):
```vue
<p><strong>Entree :</strong> {{ employee.entryDate ? employee.entryDate.split('-').reverse().join('/') : '-' }}</p>
```
This uses string splitting instead of `new Date()` to avoid timezone parsing issues with date-only strings.
- [ ] **Step 3: Verify in browser**
1. Check the API response for an employee: `GET /api/employees` should include `entryDate` field (confirms backend `employee:read` group works)
2. Open the employee list page, hover over a card — entry date should appear in the overlay
3. Create a new employee, verify the entry date shows the contract start date
4. Existing employees without entry date should show "-"
- [ ] **Step 4: Commit**
```bash
git add frontend/services/dto/employee.ts frontend/pages/employees/index.vue
git commit -m "feat : affichage date d'entree dans la liste employes"
```

View File

@@ -0,0 +1,187 @@
# Suspension de contrat — Design Spec
## Objectif
Permettre de suspendre un contrat employé. Une suspension empêche l'acquisition de congés durant la période concernée (prorata). S'applique aux CDI/CDD non forfait et aux forfaits 218.
## Contraintes
- Plusieurs suspensions possibles par période de contrat
- Pas de suppression de suspension (hors scope)
- Règle de calcul : on exclut les jours de suspension jusqu'au dernier mois complet terminé (cohérent avec la règle existante)
- Suspension sans date de fin = suspension en cours indéfiniment (exclut les mois jusqu'au dernier mois terminé)
- Les suspensions ne doivent pas se chevaucher sur une même période de contrat
## Modèle de données
### Nouvelle entité `ContractSuspension`
Nouvelle table `contract_suspensions` :
| Colonne | Type | Nullable | Description |
|---------|------|----------|-------------|
| `id` | SERIAL | non | PK |
| `contract_period_id` | INT | non | FK vers `employee_contract_periods`, CASCADE delete |
| `start_date` | DATE | non | Début de suspension |
| `end_date` | DATE | oui | Fin de suspension (null = en cours) |
| `comment` | TEXT | oui | Commentaire libre |
| `created_at` | TIMESTAMP | non | Date de création technique |
Index : `(contract_period_id, start_date)`.
Relation : `EmployeeContractPeriod` ← OneToMany → `ContractSuspension`.
## Backend — API
### Endpoint dédié
Les suspensions sont gérées via un endpoint dédié plutôt que via les champs transients Employee. Cela évite de complexifier le `EmployeeWriteProcessor` et permet de gérer N suspensions proprement.
**Nouvel ApiResource `ContractSuspension` :**
- `POST /api/contract_suspensions` — créer une suspension (body : `contractPeriod` IRI, `startDate`, `endDate`, `comment`)
- `PATCH /api/contract_suspensions/{id}` — modifier une suspension existante
- Security : `ROLE_ADMIN`
- Pagination désactivée
**Processor custom `ContractSuspensionWriteProcessor` :**
- Résout la période de contrat depuis l'IRI
- Validation :
- `startDate` requis
- `endDate >= startDate` si renseigné
- `startDate >= period.startDate`
- Pour les CDD/contrats avec date de fin : `startDate` et `endDate` dans les bornes de la période
- Pas de chevauchement avec les autres suspensions de la même période
- Rejet si la période de contrat est déjà clôturée (date de fin dans le passé)
### Lecture
Exposer les suspensions dans la sérialisation de l'Employee :
- `Employee::getCurrentSuspensions(): array` — retourne les suspensions de la période de contrat courante, groupe `employee:read`
- Ajouter les suspensions au `ContractHistoryItem` via `EmployeeContractPeriod::getSuspensions()`
## Backend — Calcul des congés
### Deux points d'impact
Le calcul d'acquisition existe à **deux endroits** qui doivent tous les deux prendre en compte les suspensions :
1. **`EmployeeLeaveSummaryProvider::computeAccruedDaysFromStart()`** — affichage live des congés en cours d'acquisition
2. **`LeaveBalanceComputationService::computeAccruedDays()`** — utilisé par le rollover (`LeaveRolloverCommand`) pour calculer le solde de report
Les deux méthodes ont la même structure (boucle mois par mois) et doivent être modifiées de la même manière.
### Modification des méthodes de calcul
Pour les deux méthodes, ajouter un paramètre optionnel : `array $suspensions = []` (tableau de `{start: DateTimeImmutable, end: ?DateTimeImmutable}`).
Dans la boucle mois par mois, pour chaque mois :
1. Calculer les jours couverts par la période de contrat (existant)
2. Pour chaque suspension, calculer le nombre de jours suspendus qui tombent dans ce mois
3. Soustraire le total des jours suspendus
4. Le ratio du mois = max(0, jours couverts - jours suspendus) / jours dans le mois
Cela gère automatiquement les suspensions qui commencent/finissent en milieu de mois (prorata).
Une suspension sans date de fin utilise la date de fin de calcul comme borne (dernier jour du mois précédent, cohérent avec la règle existante).
**Note :** chaque méthode est appelée deux fois — une pour les jours, une pour les samedis. La soustraction de suspension s'applique aux deux appels.
### Impact sur les forfaits 218
Pour les forfaits, les jours acquis en début d'exercice (ex: 34 jours pour 2026) sont réduits au prorata des jours de suspension.
Calcul : `jours acquis = base × (jours ouvrés effectifs / jours ouvrés totaux de l'exercice)`
`jours ouvrés effectifs = jours ouvrés totaux - jours ouvrés suspendus`.
Cela impacte `EmployeeLeaveSummaryProvider` dans la branche forfait et `LeaveBalanceComputationService` dans le calcul forfait de `computeDynamicClosingForYear()`.
### Passage des données de suspension aux méthodes
- **`EmployeeLeaveSummaryProvider`** : le provider a accès aux périodes de contrat via l'Employee. Il doit résoudre les suspensions de la période couvrant l'exercice et les passer aux méthodes de calcul.
- **`LeaveBalanceComputationService`** : le service utilise `$employee->getContractHistory()`. Il doit trouver les suspensions de la période couvrant l'exercice. L'accès au repository `EmployeeContractPeriodRepository` est déjà injecté — ajouter l'accès au repository `ContractSuspensionRepository` ou passer par la relation Doctrine.
### Impact sur la bascule d'exercice (rollover au 01/06)
Le rollover (`LeaveRolloverCommand`) appelle `LeaveBalanceComputationService::computeDynamicClosingForYear()` qui appelle `computeAccruedDays()`. En modifiant `computeAccruedDays()` pour accepter et traiter les suspensions, le rollover prendra automatiquement en compte les suspensions. Les jours acquis au rollover reflèteront la déduction.
**Exemple CDI :** exercice 2027 (juin 2026 - mai 2027), 2 suspensions totalisant 3 mois → au lieu de 25j acquis, l'employé bascule avec ~18.75j (9 mois effectifs × 2.083j/mois).
### Règles non impactées
- INTERIM : pas de congés gérés
## Frontend — UI
### Bouton et drawer
Le bouton "Clôturer" devient **"Modifier"**. Il ouvre le drawer existant avec le titre **"Modifier le contrat"**. Le bouton **"+ Ajouter"** (création de nouveau contrat) reste inchangé.
Le drawer contient 2 onglets :
**Onglet "Clôturer"** — contenu identique à l'actuel (type contrat, temps de travail, début contrat en readonly, date fin, commentaire, checkbox solde de tout compte).
**Onglet "Suspendre"** — formulaires empilés :
- Pour chaque suspension existante : un formulaire pré-rempli avec les 3 champs (date début, date fin, commentaire) et un bouton **"Modifier"**
- En bas : un bouton **"+ Ajouter"** qui ajoute un nouveau formulaire vide avec les 3 champs et un bouton **"Ajouter"**
- Chaque formulaire est indépendant (soumission individuelle)
### Champs par formulaire de suspension
- Date de début (required, input date)
- Date de fin (optionnel, input date)
- Commentaire (optionnel, textarea)
### Données nécessaires côté frontend
Nouveau type `ContractSuspension` (DTO) :
```typescript
type ContractSuspension = {
id: number
startDate: string
endDate?: string | null
comment?: string | null
}
```
Ajouter au type `Employee` (DTO) :
- `currentSuspensions?: ContractSuspension[]`
Ajouter au type `ContractHistoryItem` :
- `suspensions?: ContractSuspension[]`
Nouveau service `frontend/services/contractSuspensions.ts` :
- `createSuspension(payload)` — POST
- `updateSuspension(id, payload)` — PATCH
## Exemples de calcul
### CDI/CDD non forfait
Contrat CDI démarré le 01/06/2026, exercice 2027 (juin 2026 - mai 2027).
Accrual : 25j / 12 mois = 2.083j/mois.
Sans suspension au 12/03/2027 (9 mois complets : juin-février) :
- En cours d'acquisition = 9 × 2.083 = 18.75j
Avec 2 suspensions (01/01 au 31/01 + 01/03 au 31/03 = 2 mois) au 12/04/2027 (10 mois complets - 2 suspendus = 8 mois effectifs) :
- En cours d'acquisition = 8 × 2.083 = 16.67j
Samedis (5/12 par mois) :
- Sans suspension : 9 × 0.417 = 3.75j
- Avec 2 suspensions : 8 × 0.417 = 3.33j
### Forfait 218
Exercice 2026 (année civile), 34 jours acquis, 252 jours ouvrés dans l'année.
Suspension de 2 mois (44 jours ouvrés).
- Jours ouvrés effectifs = 252 - 44 = 208
- Jours acquis = 34 × (208 / 252) = 28.06j
## Hors scope
- Suppression d'une suspension
- Affichage de la suspension dans l'historique des contrats (les données sont sérialisées mais pas de rendu spécifique dans le tableau historique)
- Auto-fermeture des suspensions lors de la clôture du contrat

View File

@@ -17,7 +17,7 @@
</button>
</div>
<div class="p-6">
<div class="overflow-y-auto p-6" style="max-height: calc(100% - 65px)">
<slot />
</div>
</div>

View File

@@ -31,7 +31,7 @@
:disabled="isContractSubmitting || !canCloseCurrentContract"
@click="onOpenCloseContractDrawer"
>
Clôturer
Modifier
</button>
<button
type="button"
@@ -43,7 +43,30 @@
</button>
</div>
<AppDrawer :model-value="isContractDrawerOpen" title="Clôturer le contrat" @update:model-value="onUpdateContractDrawerOpen">
<AppDrawer :model-value="isContractDrawerOpen" title="Modifier le contrat" @update:model-value="onUpdateContractDrawerOpen">
<div class="mb-4 flex border-b border-neutral-200">
<button
type="button"
class="pb-2 px-4 border-b-2 font-semibold"
:class="drawerTab === 'close'
? 'border-primary-500 text-primary-500'
: 'border-transparent text-primary-500/50 hover:text-primary-500'"
@click="drawerTab = 'close'"
>
Clôturer
</button>
<button
type="button"
class="pb-2 px-4 border-b-2 font-semibold"
:class="drawerTab === 'suspend'
? 'border-primary-500 text-primary-500'
: 'border-transparent text-primary-500/50 hover:text-primary-500'"
@click="drawerTab = 'suspend'"
>
Suspendre
</button>
</div>
<div v-if="drawerTab === 'close'">
<form class="space-y-4" @submit.prevent="onSubmitCloseContract">
<div>
<label class="text-md font-semibold text-neutral-700" for="contract-nature">
@@ -128,6 +151,62 @@
</button>
</div>
</form>
</div>
<div v-if="drawerTab === 'suspend'" class="space-y-6">
<div
v-for="(form, index) in suspensionForms"
:key="form.id ?? `new-${index}`"
class="space-y-4 rounded-lg border border-neutral-200 p-4"
>
<div>
<label class="text-md font-semibold text-neutral-700">
Date de début <span class="text-red-600">*</span>
</label>
<input
v-model="form.startDate"
type="date"
class="mt-2 w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-base text-neutral-900 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-secondary-500/20"
/>
</div>
<div>
<label class="text-md font-semibold text-neutral-700">
Date de fin
</label>
<input
v-model="form.endDate"
type="date"
class="mt-2 w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-base text-neutral-900 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-secondary-500/20"
/>
</div>
<div>
<label class="text-md font-semibold text-neutral-700">
Commentaire
</label>
<textarea
v-model="form.comment"
rows="3"
class="mt-2 w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-base text-neutral-900 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-secondary-500/20"
/>
</div>
<button
type="button"
class="w-full rounded-md bg-primary-500 px-4 py-2 text-base font-semibold text-white transition hover:bg-secondary-500 disabled:cursor-not-allowed disabled:opacity-60"
:disabled="!form.startDate || isSuspensionSubmitting"
@click="onSubmitSuspension(index)"
>
{{ form.id ? 'Modifier' : 'Ajouter' }}
</button>
</div>
<button
type="button"
class="w-full rounded-md border-2 border-dashed border-primary-500/50 px-4 py-3 text-base font-semibold text-primary-500/50 transition hover:border-primary-500 hover:text-primary-500"
@click="onAddSuspensionForm"
>
+ Ajouter une suspension
</button>
</div>
</AppDrawer>
<AppDrawer :model-value="isCreateContractDrawerOpen" title="Ajouter un contrat" @update:model-value="onUpdateCreateContractDrawerOpen">
@@ -162,9 +241,9 @@
<input id="create-contract-start-date" v-model="createContractForm.startDate" type="date" :class="createContractStartDateFieldClass" />
</div>
<div v-if="requiresCreateContractEndDate">
<div v-if="showsCreateContractEndDate">
<label class="text-md font-semibold text-neutral-700" for="create-contract-end-date">
Fin contrat <span class="text-red-600">*</span>
Fin contrat <span v-if="requiresCreateContractEndDate" class="text-red-600">*</span>
</label>
<input id="create-contract-end-date" v-model="createContractForm.endDate" type="date" :class="createContractEndDateFieldClass" />
</div>
@@ -195,6 +274,13 @@
import type { Contract } from '~/services/dto/contract'
import type { ContractHistoryItem } from '~/services/dto/employee'
type SuspensionForm = {
id: number | null
startDate: string
endDate: string
comment: string
}
type ContractForm = {
contractId: number | ''
contractName: string
@@ -213,7 +299,7 @@ type CreateContractForm = {
endDate: string
}
defineProps<{
const props = defineProps<{
contractHistory: ContractHistoryItem[]
contractNatureLabel: (value?: 'CDI' | 'CDD' | 'INTERIM') => string
contractHistoryLabel: (item: ContractHistoryItem) => string
@@ -235,6 +321,7 @@ defineProps<{
createContractNatureFieldClass: string
createContractFieldClass: string
createContractStartDateFieldClass: string
showsCreateContractEndDate: boolean
requiresCreateContractEndDate: boolean
createContractEndDateFieldClass: string
isCreateContractFormValid: boolean
@@ -244,5 +331,16 @@ defineProps<{
onUpdateCreateContractDrawerOpen: (open: boolean) => void
onSubmitCloseContract: () => void
onSubmitCreateContract: () => void
suspensionForms: SuspensionForm[]
isSuspensionSubmitting: boolean
onSubmitSuspension: (index: number) => void
onAddSuspensionForm: () => void
currentContractPeriodId?: number | null
}>()
const drawerTab = ref<'close' | 'suspend'>('close')
watch(() => props.isContractDrawerOpen, (open) => {
if (open) drawerTab.value = 'close'
})
</script>

View File

@@ -29,7 +29,7 @@
</div>
<div class="mt-8 min-h-0 flex-1 overflow-y-auto pr-2">
<div class="grid grid-cols-4 gap-10">
<div v-for="month in months" :key="month.label" class="rounded-md bg-tertiary-500 text-primary-500">
<div v-for="month in months" :key="month.label" class="rounded-md bg-tertiary-500 text-primary-500 flex flex-col justify-between">
<div class="flex justify-center rounded-t-md bg-primary-500 py-1 font-bold uppercase text-white">
{{ month.label }}
</div>
@@ -54,6 +54,7 @@
</div>
</template>
</div>
<div class="px-2 py-2 text-center border-t border-primary-500">Jours de présence : {{ summary?.presenceDaysByMonth?.[month.monthKey] ?? 0 }}</div>
</div>
</div>
</div>
@@ -259,9 +260,12 @@ const months = computed(() => {
cells.push(null)
}
const monthKey = `${monthYear}-${String(monthIndex + 1).padStart(2, '0')}`
return {
label,
cells
cells,
monthKey
}
})
})

View File

@@ -11,7 +11,8 @@ import { getEmployeeRttSummary, createRttPayment } from '~/services/employee-rtt
import { getEmployee, updateEmployee } from '~/services/employees'
import { listPublicHolidays } from '~/services/public-holidays'
import { formatNullableYmdToFr, getTodayYmd, shiftYmd } from '~/utils/date'
import { contractNatureLabel, isContractNature, requiresContractEndDate } from '~/utils/contract'
import { contractNatureLabel, isContractNature, requiresContractEndDate, showsContractEndDate } from '~/utils/contract'
import { createSuspension, updateSuspension } from '~/services/contractSuspensions'
export const useEmployeeDetailPage = () => {
const route = useRoute()
@@ -29,6 +30,16 @@ export const useEmployeeDetailPage = () => {
const isCreateContractDrawerOpen = ref(false)
const isCreateContractSubmitting = ref(false)
type SuspensionForm = {
id: number | null
startDate: string
endDate: string
comment: string
}
const suspensionForms = ref<SuspensionForm[]>([])
const isSuspensionSubmitting = ref(false)
const contractForm = reactive({
contractId: '' as number | '',
contractName: '',
@@ -83,6 +94,11 @@ export const useEmployeeDetailPage = () => {
return history.find((item) => item.startDate <= today && (!item.endDate || item.endDate >= today)) ?? null
})
const currentActiveContractPeriodId = computed<number | null>(() => {
const period = currentActiveContractPeriod.value
return period?.periodId ?? null
})
const canCloseCurrentContract = computed(() => {
const active = currentActiveContractPeriod.value
if (!active) return false
@@ -99,6 +115,7 @@ export const useEmployeeDetailPage = () => {
const isContractEndDateValid = computed(() => contractForm.endDate !== '')
const showContractEndDateError = computed(() => validationTouched.endDate && !isContractEndDateValid.value)
const showsCreateContractEndDate = computed(() => showsContractEndDate(createContractForm.contractNature))
const requiresCreateContractEndDate = computed(() => requiresContractEndDate(createContractForm.contractNature))
const isCreateContractValid = computed(() => createContractForm.contractId !== '')
const isCreateContractNatureValid = computed(() => isContractNature(createContractForm.contractNature))
@@ -129,6 +146,16 @@ export const useEmployeeDetailPage = () => {
validationTouched.endDate = false
}
const hydrateSuspensionForms = () => {
const current = employee.value?.currentSuspensions ?? []
suspensionForms.value = current.map(s => ({
id: s.id,
startDate: s.startDate,
endDate: s.endDate ?? '',
comment: s.comment ?? ''
}))
}
const hydrateContractFormFromCurrent = () => {
const current = employee.value
const active = currentActiveContractPeriod.value
@@ -148,6 +175,7 @@ export const useEmployeeDetailPage = () => {
if (!employee.value || !canCloseCurrentContract.value) return
hydrateContractFormFromCurrent()
resetContractValidation()
hydrateSuspensionForms()
isContractDrawerOpen.value = true
}
@@ -300,6 +328,45 @@ export const useEmployeeDetailPage = () => {
}
}
const submitSuspension = async (index: number) => {
const form = suspensionForms.value[index]
if (!form || !form.startDate) return
const periodId = currentActiveContractPeriodId.value
if (!periodId) return
isSuspensionSubmitting.value = true
try {
if (form.id) {
await updateSuspension(form.id, {
startDate: form.startDate,
endDate: form.endDate || null,
comment: form.comment || null
})
} else {
await createSuspension({
contractPeriodId: periodId,
startDate: form.startDate,
endDate: form.endDate || null,
comment: form.comment || null
})
}
await loadEmployee()
hydrateSuspensionForms()
} finally {
isSuspensionSubmitting.value = false
}
}
const addSuspensionForm = () => {
suspensionForms.value.push({
id: null,
startDate: '',
endDate: '',
comment: ''
})
}
const submitFractionedDays = async (days: number) => {
if (!employee.value) return
const year = leaveSummary.value?.year ?? undefined
@@ -314,8 +381,8 @@ export const useEmployeeDetailPage = () => {
await loadEmployee()
}
watch(requiresCreateContractEndDate, (required) => {
if (!required) {
watch(showsCreateContractEndDate, (shows) => {
if (!shows) {
createContractForm.endDate = ''
}
})
@@ -353,6 +420,7 @@ export const useEmployeeDetailPage = () => {
createContractNatureFieldClass,
createContractFieldClass,
createContractStartDateFieldClass,
showsCreateContractEndDate,
requiresCreateContractEndDate,
createContractEndDateFieldClass,
isCreateContractFormValid,
@@ -366,6 +434,11 @@ export const useEmployeeDetailPage = () => {
submitContractUpdate,
submitCreateContract,
submitFractionedDays,
submitRttPayment
submitRttPayment,
suspensionForms,
isSuspensionSubmitting,
submitSuspension,
addSuspensionForm,
currentActiveContractPeriodId
}
}

View File

@@ -7,68 +7,67 @@
</div>
<nav class="flex-1 px-4 pb-6">
<template v-if="isAdmin">
<NuxtLink
to="/"
class="hidden flex items-center gap-3 px-4 pb-3 pt-6 text-md text-black hover:bg-tertiary-500 hover:text-primary-500 border-t border-secondary-500"
active-class="bg-tertiary-500 text-primary-500 font-bold"
>
Tableau de bord
</NuxtLink>
<NuxtLink
to="/calendar"
class="flex items-center gap-3 px-4 pb-3 pt-6 text-md text-black hover:bg-tertiary-500 hover:text-primary-500 border-t border-secondary-500"
class="flex items-center gap-2 pb-2 pt-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500 border-t border-secondary-500"
:class="route.path.startsWith('/calendar')
? 'bg-tertiary-500 text-primary-500 font-bold'
: ''"
>
Calendrier
<Icon name="mdi:calendar-blank" size="24"/>
<p>Calendrier</p>
</NuxtLink>
</template>
<NuxtLink
to="/hours"
class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
class="flex items-center gap-2 py-2 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
:class="route.path.startsWith('/hours')
? 'bg-tertiary-500 text-primary-500 font-bold'
: ''"
>
Heures
<Icon name="mdi:clock-time-four-outline" size="24"/>
<p>Heures</p>
</NuxtLink>
<template v-if="isAdmin">
<NuxtLink
to="/employees"
class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
class="flex items-center gap-2 py-2 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
:class="route.path.startsWith('/employees')
? 'bg-tertiary-500 text-primary-500 font-bold'
: ''"
>
Employés
<Icon name="mdi:account-group-outline" size="24"/>
<p>Employés</p>
</NuxtLink>
<NuxtLink
to="/sites"
class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
class="flex items-center gap-2 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
:class="route.path.startsWith('/sites')
? 'bg-tertiary-500 text-primary-500 font-bold'
: ''"
>
Sites
<Icon name="mdi:business" size="24"/>
<p>Sites</p>
</NuxtLink>
<NuxtLink
to="/absence-types"
class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
class="flex items-center gap-2 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
:class="route.path.startsWith('/absence-types')
? 'bg-tertiary-500 text-primary-500 font-bold'
: ''"
>
Types d'absence
<Icon name="mdi:umbrella-beach-outline" size="24"/>
<p>Types d'absence</p>
</NuxtLink>
<NuxtLink
to="/users"
class="flex items-center gap-3 px-4 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
class="flex items-center gap-3 py-3 text-md text-black hover:bg-tertiary-500 hover:text-primary-500"
:class="route.path.startsWith('/users')
? 'bg-tertiary-500 text-primary-500 font-bold'
: ''"
>
Utilisateurs
<Icon name="mdi:account-outline" size="24"/>
<p>Utilisateurs</p>
</NuxtLink>
</template>
</nav>

View File

@@ -12,9 +12,12 @@
<div v-else class="flex min-h-0 flex-1 flex-col">
<div class="flex items-center justify-between">
<h1 class="text-4xl font-bold text-primary-500">{{ employee.firstName }} {{ employee.lastName }}</h1>
<div>
<h1 class="text-[32px] font-bold">{{ employee.firstName }} {{ employee.lastName }}</h1>
<p>Date d'entrée : {{ employee.entryDate ? employee.entryDate.split('-').reverse().join('/') : '-' }}</p>
</div>
<div class="text-right">
<p class="font-bold text-[20px]">{{ contractNatureLabel(employee.currentContractNature) }} {{ employeeContractWorkLabel }}</p>
<p class="font-bold text-[22px]">{{ contractNatureLabel(employee.currentContractNature) }} {{ employeeContractWorkLabel }}</p>
<p class="text-[18px]">{{ employee.site?.name ?? '-' }}</p>
</div>
</div>
@@ -78,6 +81,7 @@
:create-contract-nature-field-class="createContractNatureFieldClass"
:create-contract-field-class="createContractFieldClass"
:create-contract-start-date-field-class="createContractStartDateFieldClass"
:shows-create-contract-end-date="showsCreateContractEndDate"
:requires-create-contract-end-date="requiresCreateContractEndDate"
:create-contract-end-date-field-class="createContractEndDateFieldClass"
:is-create-contract-form-valid="isCreateContractFormValid"
@@ -87,6 +91,11 @@
:on-update-create-contract-drawer-open="setCreateContractDrawerOpen"
:on-submit-close-contract="submitContractUpdate"
:on-submit-create-contract="submitCreateContract"
:suspension-forms="suspensionForms"
:is-suspension-submitting="isSuspensionSubmitting"
:on-submit-suspension="submitSuspension"
:on-add-suspension-form="addSuspensionForm"
:current-contract-period-id="currentActiveContractPeriodId"
/>
<EmployeesLeaveTab
v-else-if="showLeaveTab && activeTab === 'leave'"
@@ -131,6 +140,7 @@ const {
createContractNatureFieldClass,
createContractFieldClass,
createContractStartDateFieldClass,
showsCreateContractEndDate,
requiresCreateContractEndDate,
createContractEndDateFieldClass,
isCreateContractFormValid,
@@ -144,7 +154,12 @@ const {
submitContractUpdate,
submitCreateContract,
submitFractionedDays,
submitRttPayment
submitRttPayment,
suspensionForms,
isSuspensionSubmitting,
submitSuspension,
addSuspensionForm,
currentActiveContractPeriodId
} = useEmployeeDetailPage()
useHead(() => ({

View File

@@ -51,6 +51,7 @@
<p><strong>Type:</strong> {{ contractNatureLabel(employee.currentContractNature) }}</p>
<p><strong>Temps de travail:</strong> {{ employee.contract?.name ?? '-' }}</p>
<p><strong>Site:</strong> {{ employee.site?.name ?? '-' }}</p>
<p><strong>Date d'entrée :</strong> {{ employee.entryDate ? employee.entryDate.split('-').reverse().join('/') : '-' }}</p>
</div>
</div>
</NuxtLink>
@@ -154,7 +155,7 @@
La date de début est obligatoire.
</p>
</div>
<div v-if="requiresContractEndDateComputed">
<div v-if="showsContractEndDateComputed">
<label class="text-md font-semibold text-neutral-700" for="contract-end-date">
Fin contrat
<span v-if="requiresContractEndDateComputed" class="text-red-600">*</span>
@@ -166,7 +167,7 @@
:class="contractEndDateFieldClass"
/>
<p v-if="showContractEndDateError" class="mt-1 text-sm text-red-600">
La date de fin est obligatoire pour un CDD ou un intérim.
La date de fin est obligatoire pour un CDD.
</p>
</div>
</template>
@@ -199,7 +200,7 @@ import {listContracts} from '~/services/contracts'
import {createEmployee, deleteEmployee, listEmployees, updateEmployee} from '~/services/employees'
import {listSites} from '~/services/sites'
import SiteFilterSelector from '~/components/SiteFilterSelector.vue'
import {contractNatureLabel, isContractNature, requiresContractEndDate} from '~/utils/contract'
import {contractNatureLabel, isContractNature, requiresContractEndDate, showsContractEndDate} from '~/utils/contract'
useHead({
title: 'Employés'
@@ -264,6 +265,7 @@ const isSiteValid = computed(() => form.siteId !== '')
const isContractValid = computed(() => form.contractId !== '')
const isContractNatureValid = computed(() => isContractNature(form.contractNature))
const isContractStartDateValid = computed(() => form.contractStartDate !== '')
const showsContractEndDateComputed = computed(() => showsContractEndDate(form.contractNature))
const requiresContractEndDateComputed = computed(() => requiresContractEndDate(form.contractNature))
const isContractEndDateValid = computed(() => {
if (!requiresContractEndDateComputed.value) return true
@@ -429,7 +431,7 @@ const handleSubmit = async () => {
contractId: Number(form.contractId),
contractNature: form.contractNature,
contractStartDate: form.contractStartDate,
contractEndDate: requiresContractEndDateComputed.value ? form.contractEndDate : null
contractEndDate: form.contractEndDate || null
})
}
@@ -460,8 +462,8 @@ watch(isDrawerOpen, (isOpen) => {
}
})
watch(requiresContractEndDateComputed, (required) => {
if (!required) {
watch(showsContractEndDateComputed, (shows) => {
if (!shows) {
form.contractEndDate = ''
}
})

View File

@@ -68,7 +68,7 @@ const handleSubmit = async () => {
try {
await auth.login(username.value, password.value)
await router.push('/')
await router.push('/calendar')
} finally {
isSubmitting.value = false
}

View File

@@ -0,0 +1,38 @@
import type { ContractSuspension } from './dto/employee'
export const createSuspension = async (payload: {
contractPeriodId: number
startDate: string
endDate?: string | null
comment?: string | null
}) => {
const api = useApi()
return api.post<ContractSuspension>('/contract_suspensions', {
contractPeriodId: payload.contractPeriodId,
startDate: payload.startDate,
endDate: payload.endDate ?? null,
comment: payload.comment ?? null
}, {
toastSuccessKey: 'Suspension créée',
toastErrorKey: 'Erreur lors de la création de la suspension'
})
}
export const updateSuspension = async (
id: number,
payload: {
startDate: string
endDate?: string | null
comment?: string | null
}
) => {
const api = useApi()
return api.patch<ContractSuspension>(`/contract_suspensions/${id}`, {
startDate: payload.startDate,
endDate: payload.endDate ?? null,
comment: payload.comment ?? null
}, {
toastSuccessKey: 'Suspension modifiée',
toastErrorKey: 'Erreur lors de la modification de la suspension'
})
}

View File

@@ -10,5 +10,6 @@ export type EmployeeLeaveSummary = {
takenSaturdays: number
fractionedDays: number
accruingDays: number
presenceDaysByMonth: Record<string, number>
}

View File

@@ -1,6 +1,13 @@
import type { Site } from './site'
import type { Contract } from './contract'
export type ContractSuspension = {
id: number
startDate: string
endDate?: string | null
comment?: string | null
}
export type ContractHistoryItem = {
contractId?: number | null
contractName?: string | null
@@ -9,6 +16,8 @@ export type ContractHistoryItem = {
startDate: string
endDate?: string | null
comment?: string | null
periodId?: number | null
suspensions?: ContractSuspension[]
}
export type Employee = {
@@ -22,4 +31,6 @@ export type Employee = {
currentContractEndDate?: string | null
contractHistory?: ContractHistoryItem[]
displayOrder?: number
entryDate?: string | null
currentSuspensions?: ContractSuspension[]
}

View File

@@ -8,10 +8,14 @@ export const contractNatureLabel = (value?: ContractNature) => {
return 'CDI'
}
export const requiresContractEndDate = (nature: ContractNature) => {
export const showsContractEndDate = (nature: ContractNature) => {
return nature === 'CDD' || nature === 'INTERIM'
}
export const requiresContractEndDate = (nature: ContractNature) => {
return nature === 'CDD'
}
export const isContractNature = (value: string): value is ContractNature => {
return (CONTRACT_NATURES as readonly string[]).includes(value)
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260312120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add entry_date column to employees table';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE employees ADD entry_date DATE DEFAULT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE employees DROP entry_date');
}
}

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260312140000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create contract_suspensions table';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE contract_suspensions (
id SERIAL PRIMARY KEY,
contract_period_id INT NOT NULL REFERENCES employee_contract_periods(id) ON DELETE CASCADE,
start_date DATE NOT NULL,
end_date DATE DEFAULT NULL,
comment TEXT DEFAULT NULL,
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
)');
$this->addSql('CREATE INDEX idx_suspension_period_start ON contract_suspensions (contract_period_id, start_date)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE contract_suspensions');
}
}

View File

@@ -31,4 +31,7 @@ final class EmployeeLeaveSummary
public float $takenSaturdays = 0.0;
public float $fractionedDays = 0.0;
public float $accruingDays = 0.0;
/** @var array<string, float> YYYY-MM => count (0.5 for half-days) */
public array $presenceDaysByMonth = [];
}

View File

@@ -23,5 +23,9 @@ final class ContractHistoryItem
public ?string $endDate,
#[Groups(['employee:read'])]
public ?string $comment = null,
#[Groups(['employee:read'])]
public ?int $periodId = null,
#[Groups(['employee:read'])]
public array $suspensions = [],
) {}
}

View File

@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Repository\ContractSuspensionRepository;
use App\State\ContractSuspensionWriteProcessor;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
#[ApiResource(
operations: [
new GetCollection(),
new Post(processor: ContractSuspensionWriteProcessor::class),
new Patch(processor: ContractSuspensionWriteProcessor::class),
],
normalizationContext: ['groups' => ['suspension:read']],
denormalizationContext: ['groups' => ['suspension:write']],
paginationEnabled: false,
security: "is_granted('ROLE_ADMIN')",
)]
#[ORM\Entity(repositoryClass: ContractSuspensionRepository::class)]
#[ORM\Table(name: 'contract_suspensions')]
#[ORM\Index(columns: ['contract_period_id', 'start_date'], name: 'idx_suspension_period_start')]
class ContractSuspension
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['suspension:read', 'employee:read'])]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: EmployeeContractPeriod::class, inversedBy: 'suspensions')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?EmployeeContractPeriod $contractPeriod = null;
#[Groups(['suspension:write'])]
private ?int $contractPeriodId = null;
#[ORM\Column(type: 'date_immutable')]
#[Groups(['suspension:read', 'suspension:write', 'employee:read'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private DateTimeImmutable $startDate;
#[ORM\Column(type: 'date_immutable', nullable: true)]
#[Groups(['suspension:read', 'suspension:write', 'employee:read'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private ?DateTimeImmutable $endDate = null;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['suspension:read', 'suspension:write', 'employee:read'])]
private ?string $comment = null;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $createdAt;
public function __construct()
{
$this->createdAt = new DateTimeImmutable();
$this->startDate = new DateTimeImmutable('today');
}
public function getContractPeriodId(): ?int
{
return $this->contractPeriodId;
}
public function setContractPeriodId(?int $contractPeriodId): self
{
$this->contractPeriodId = $contractPeriodId;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getContractPeriod(): ?EmployeeContractPeriod
{
return $this->contractPeriod;
}
public function setContractPeriod(?EmployeeContractPeriod $contractPeriod): self
{
$this->contractPeriod = $contractPeriod;
return $this;
}
public function getStartDate(): DateTimeImmutable
{
return $this->startDate;
}
public function setStartDate(DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?DateTimeImmutable
{
return $this->endDate;
}
public function setEndDate(?DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
}

View File

@@ -14,7 +14,9 @@ use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
#[ApiResource(
normalizationContext: ['groups' => ['employee:read', 'site:read']],
@@ -57,6 +59,11 @@ class Employee
#[Groups(['employee:read', 'employee:write'])]
private int $displayOrder = 0;
#[ORM\Column(type: 'date_immutable', nullable: true)]
#[Groups(['employee:read'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private ?DateTimeImmutable $entryDate = null;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $createdAt;
@@ -166,6 +173,18 @@ class Employee
return $this;
}
public function getEntryDate(): ?DateTimeImmutable
{
return $this->entryDate;
}
public function setEntryDate(?DateTimeImmutable $entryDate): self
{
$this->entryDate = $entryDate;
return $this;
}
public function getContractNature(): ?string
{
return $this->contractNature;
@@ -244,6 +263,36 @@ class Employee
return $this->resolveCurrentContractPeriod()?->getEndDate()?->format('Y-m-d');
}
/**
* @return list<array{id: null|int, startDate: string, endDate: null|string, comment: null|string}>
*/
#[Groups(['employee:read'])]
public function getCurrentSuspensions(): array
{
$currentPeriod = $this->resolveCurrentContractPeriod();
if (null === $currentPeriod) {
return [];
}
return array_values(array_map(
static fn (ContractSuspension $s): array => [
'id' => $s->getId(),
'startDate' => $s->getStartDate()->format('Y-m-d'),
'endDate' => $s->getEndDate()?->format('Y-m-d'),
'comment' => $s->getComment(),
],
$currentPeriod->getSuspensions()->toArray()
));
}
/**
* @return Collection<int, EmployeeContractPeriod>
*/
public function getContractPeriods(): Collection
{
return $this->contractPeriods;
}
/**
* @return list<ContractHistoryItem>
*/
@@ -260,6 +309,16 @@ class Employee
static function (EmployeeContractPeriod $period): ContractHistoryItem {
$contract = $period->getContract();
$suspensionData = array_map(
static fn (ContractSuspension $s): array => [
'id' => $s->getId(),
'startDate' => $s->getStartDate()->format('Y-m-d'),
'endDate' => $s->getEndDate()?->format('Y-m-d'),
'comment' => $s->getComment(),
],
$period->getSuspensions()->toArray()
);
return new ContractHistoryItem(
contractId: $contract?->getId(),
contractName: $contract?->getName(),
@@ -268,6 +327,8 @@ class Employee
startDate: $period->getStartDate()->format('Y-m-d'),
endDate: $period->getEndDate()?->format('Y-m-d'),
comment: $period->getComment(),
periodId: $period->getId(),
suspensions: $suspensionData,
);
},
$periods

View File

@@ -7,6 +7,8 @@ namespace App\Entity;
use App\Enum\ContractNature;
use App\Repository\EmployeeContractPeriodRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmployeeContractPeriodRepository::class)]
@@ -43,13 +45,20 @@ class EmployeeContractPeriod
#[ORM\Column(type: 'text', nullable: true)]
private ?string $comment = null;
/**
* @var Collection<int, ContractSuspension>
*/
#[ORM\OneToMany(mappedBy: 'contractPeriod', targetEntity: ContractSuspension::class, cascade: ['persist', 'remove'])]
private Collection $suspensions;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $createdAt;
public function __construct()
{
$this->createdAt = new DateTimeImmutable();
$this->startDate = new DateTimeImmutable('today');
$this->createdAt = new DateTimeImmutable();
$this->startDate = new DateTimeImmutable('today');
$this->suspensions = new ArrayCollection();
}
public function getId(): ?int
@@ -151,4 +160,12 @@ class EmployeeContractPeriod
return $this;
}
/**
* @return Collection<int, ContractSuspension>
*/
public function getSuspensions(): Collection
{
return $this->suspensions;
}
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\ContractSuspension;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ContractSuspension>
*/
class ContractSuspensionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ContractSuspension::class);
}
}

View File

@@ -138,6 +138,48 @@ final class WorkHourRepository extends ServiceEntityRepository implements WorkHo
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @return array<string, float> YYYY-MM => presence day count (0.5 for half-days)
*/
public function countPresenceDaysByMonth(Employee $employee, DateTimeImmutable $from, DateTimeImmutable $to): array
{
$sql = <<<'SQL'
SELECT TO_CHAR(work_date, 'YYYY-MM') AS month,
SUM(
CASE
WHEN (morning_from IS NOT NULL OR is_present_morning = true)
AND (afternoon_from IS NOT NULL OR is_present_afternoon = true)
THEN 1.0
WHEN (morning_from IS NOT NULL OR is_present_morning = true)
OR (afternoon_from IS NOT NULL OR is_present_afternoon = true)
THEN 0.5
ELSE 0
END
) AS cnt
FROM work_hours
WHERE employee_id = :employee
AND work_date >= :from
AND work_date <= :to
AND (morning_from IS NOT NULL OR is_present_morning = true
OR afternoon_from IS NOT NULL OR is_present_afternoon = true)
GROUP BY month
SQL;
$conn = $this->getEntityManager()->getConnection();
$rows = $conn->fetchAllAssociative($sql, [
'employee' => $employee->getId(),
'from' => $from->format('Y-m-d'),
'to' => $to->format('Y-m-d'),
]);
$result = [];
foreach ($rows as $row) {
$result[(string) $row['month']] = (float) $row['cnt'];
}
return $result;
}
public function hasPendingSiteValidationForSiteAndDate(int $siteId, DateTimeInterface $date): bool
{
$workDate = DateTimeImmutable::createFromInterface($date);

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Service\Leave;
use App\Entity\Absence;
use App\Entity\ContractSuspension;
use App\Entity\Employee;
use App\Enum\LeaveRuleCode;
use App\Repository\AbsenceRepository;
@@ -29,6 +30,7 @@ final readonly class LeaveBalanceComputationService
private EmployeeContractPeriodRepository $periodRepository,
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
private PublicHolidayServiceInterface $publicHolidayService,
private SuspensionDaysCalculator $suspensionDaysCalculator,
) {}
/**
@@ -67,7 +69,18 @@ final readonly class LeaveBalanceComputationService
$fractionedDays = $this->resolveFractionedDays($employee, $ruleCode, $year);
if (LeaveRuleCode::FORFAIT_218 === $ruleCode) {
$acquiredDays = $carryDays + (float) max(0, $this->countBusinessDays($from, $to) - self::FORFAIT_TARGET_WORKED_DAYS) + $fractionedDays;
$totalBusinessDays = $this->countBusinessDays($from, $to);
$baseAcquiredDays = (float) max(0, $totalBusinessDays - self::FORFAIT_TARGET_WORKED_DAYS);
$suspensions = $this->resolveSuspensionsForEmployeePeriod($employee, $from, $to);
$acquiredDays = $carryDays + $baseAcquiredDays + $fractionedDays;
if ([] !== $suspensions) {
$totalMonths = $this->countFractionalMonths($from, $to);
$suspendedMonths = $this->countSuspendedFractionalMonths($from, $to, $suspensions);
if ($totalMonths > 0) {
$ratio = max(0.0, ($totalMonths - $suspendedMonths) / $totalMonths);
$acquiredDays = $carryDays + $baseAcquiredDays * $ratio + $fractionedDays;
}
}
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $effectiveFrom, $to);
[$takenDays] = $this->computeTakenAbsences($absences, $effectiveFrom, $to, false, false);
$previousRemainingDays = max(0.0, $acquiredDays - $takenDays);
@@ -76,17 +89,20 @@ final readonly class LeaveBalanceComputationService
continue;
}
$suspensions = $this->resolveSuspensionsForEmployeePeriod($employee, $from, $to);
$generatedDays = $this->computeAccruedDays(
$this->resolveAnnualDays($employee),
$this->resolveDaysAccrualPerMonth($employee),
$effectiveFrom,
$to
$to,
$suspensions
);
$generatedSaturdays = $this->computeAccruedDays(
$this->resolveAnnualSaturdays($employee),
$this->resolveSaturdayAccrualPerMonth($employee),
$effectiveFrom,
$to
$to,
$suspensions
);
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $effectiveFrom, $to);
@@ -117,14 +133,14 @@ final readonly class LeaveBalanceComputationService
{
if (LeaveRuleCode::FORFAIT_218 === $ruleCode) {
return [
new DateTimeImmutable(sprintf('%d-01-01', $year)),
new DateTimeImmutable(sprintf('%d-12-31', $year)),
new DateTimeImmutable(sprintf('%d-01-01 00:00:00', $year)),
new DateTimeImmutable(sprintf('%d-12-31 00:00:00', $year)),
];
}
return [
new DateTimeImmutable(sprintf('%d-06-01', $year - 1)),
new DateTimeImmutable(sprintf('%d-05-31', $year)),
new DateTimeImmutable(sprintf('%d-06-01 00:00:00', $year - 1)),
new DateTimeImmutable(sprintf('%d-05-31 00:00:00', $year)),
];
}
@@ -145,7 +161,7 @@ final readonly class LeaveBalanceComputationService
$oldestStartDate = null;
foreach ($history as $item) {
$start = DateTimeImmutable::createFromFormat('Y-m-d', $item->startDate);
$start = $this->parseYmdDate($item->startDate);
if (!$start) {
continue;
}
@@ -197,14 +213,14 @@ final readonly class LeaveBalanceComputationService
): ?DateTimeImmutable {
$earliest = null;
foreach ($employee->getContractHistory() as $period) {
$start = DateTimeImmutable::createFromFormat('Y-m-d', $period->startDate);
$start = $this->parseYmdDate($period->startDate);
if (!$start) {
continue;
}
$end = null;
if (null !== $period->endDate && '' !== trim($period->endDate)) {
$end = DateTimeImmutable::createFromFormat('Y-m-d', $period->endDate);
$end = $this->parseYmdDate($period->endDate);
}
if ($start > $to) {
@@ -262,17 +278,48 @@ final readonly class LeaveBalanceComputationService
float $annualCap,
float $accrualPerMonth,
DateTimeImmutable $periodStart,
DateTimeImmutable $periodEnd
DateTimeImmutable $periodEnd,
array $suspensions = []
): float {
if ($accrualPerMonth <= 0.0 || $periodEnd < $periodStart) {
return 0.0;
}
$monthsElapsed = ((int) $periodEnd->format('Y') - (int) $periodStart->format('Y')) * 12
+ ((int) $periodEnd->format('n') - (int) $periodStart->format('n'))
+ 1;
$periodStart = $this->normalizeDate($periodStart);
$periodEnd = $this->normalizeDate($periodEnd);
$coveredMonths = 0.0;
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
while ($cursor <= $periodEnd) {
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
if ($monthEnd > $periodEnd) {
$monthEnd = $periodEnd;
}
return min($annualCap, $monthsElapsed * $accrualPerMonth);
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
if ([] !== $suspensions) {
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
$coveredDays = max(0, $coveredDays - $suspendedDays);
}
$daysInMonth = (int) $cursor->format('t');
$coveredMonths += $coveredDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return min($annualCap, $coveredMonths * $accrualPerMonth);
}
private function parseYmdDate(string $value): ?DateTimeImmutable
{
$date = DateTimeImmutable::createFromFormat('!Y-m-d', trim($value));
return $date instanceof DateTimeImmutable ? $date : null;
}
private function normalizeDate(DateTimeImmutable $date): DateTimeImmutable
{
return $date->setTime(0, 0);
}
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to): int
@@ -349,14 +396,25 @@ final readonly class LeaveBalanceComputationService
}
for ($cursor = $rangeStart; $cursor <= $rangeEnd; $cursor = $cursor->modify('+1 day')) {
$dayOfWeek = (int) $cursor->format('N');
if ($splitSaturdays) {
if (7 === $dayOfWeek) {
continue;
}
} else {
if ($dayOfWeek >= 6) {
continue;
}
}
[$am, $pm] = $this->resolveSegmentsForDate($absence, $cursor->format('Y-m-d'));
$dayAmount = ($am ? 0.5 : 0.0) + ($pm ? 0.5 : 0.0);
if ($dayAmount <= 0.0) {
continue;
}
$isSaturday = $splitSaturdays && '6' === $cursor->format('N');
if ($isSaturday) {
if ($splitSaturdays && 6 === $dayOfWeek) {
$takenSaturdays += $dayAmount;
} else {
$takenDays += $dayAmount;
@@ -367,6 +425,80 @@ final readonly class LeaveBalanceComputationService
return [$takenDays, $takenSaturdays];
}
private function countFractionalMonths(DateTimeImmutable $from, DateTimeImmutable $to): float
{
$from = $this->normalizeDate($from);
$to = $this->normalizeDate($to);
$months = 0.0;
$cursor = $from->modify('first day of this month')->setTime(0, 0);
while ($cursor <= $to) {
$monthStart = $cursor > $from ? $cursor : $from;
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
if ($monthEnd > $to) {
$monthEnd = $to;
}
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
$daysInMonth = (int) $cursor->format('t');
$months += $coveredDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return $months;
}
/**
* @param list<ContractSuspension> $suspensions
*/
private function countSuspendedFractionalMonths(DateTimeImmutable $from, DateTimeImmutable $to, array $suspensions): float
{
$from = $this->normalizeDate($from);
$to = $this->normalizeDate($to);
$months = 0.0;
$cursor = $from->modify('first day of this month')->setTime(0, 0);
while ($cursor <= $to) {
$monthStart = $cursor > $from ? $cursor : $from;
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
if ($monthEnd > $to) {
$monthEnd = $to;
}
$daysInMonth = (int) $cursor->format('t');
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
$months += $suspendedDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return $months;
}
/**
* @return list<ContractSuspension>
*/
private function resolveSuspensionsForEmployeePeriod(Employee $employee, DateTimeImmutable $from, DateTimeImmutable $to): array
{
$suspensions = [];
foreach ($employee->getContractPeriods() as $period) {
$periodStart = $period->getStartDate();
$periodEnd = $period->getEndDate();
if ($periodStart > $to) {
continue;
}
if ($periodEnd instanceof DateTimeImmutable && $periodEnd < $from) {
continue;
}
foreach ($period->getSuspensions() as $suspension) {
$suspensions[] = $suspension;
}
}
return $suspensions;
}
/**
* @return array{bool, bool}
*/

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace App\Service\Leave;
use App\Entity\ContractSuspension;
use DateTimeImmutable;
final class SuspensionDaysCalculator
{
/**
* Count calendar days suspended within a month window [monthStart, monthEnd].
*
* @param list<ContractSuspension> $suspensions
*/
public function countSuspendedDaysInMonth(
DateTimeImmutable $monthStart,
DateTimeImmutable $monthEnd,
array $suspensions
): int {
$total = 0;
foreach ($suspensions as $suspension) {
$sStart = $suspension->getStartDate();
$sEnd = $suspension->getEndDate() ?? $monthEnd;
$overlapStart = $sStart > $monthStart ? $sStart : $monthStart;
$overlapEnd = $sEnd < $monthEnd ? $sEnd : $monthEnd;
if ($overlapStart > $overlapEnd) {
continue;
}
$total += ((int) $overlapEnd->diff($overlapStart)->format('%a')) + 1;
}
return $total;
}
/**
* Count business days (Mon-Fri, excl. public holidays) suspended within a period.
*
* @param list<ContractSuspension> $suspensions
* @param array<string, string> $publicHolidays map of Y-m-d => label
*/
public function countSuspendedBusinessDays(
DateTimeImmutable $periodStart,
DateTimeImmutable $periodEnd,
array $suspensions,
array $publicHolidays
): int {
$total = 0;
foreach ($suspensions as $suspension) {
$sStart = $suspension->getStartDate();
$sEnd = $suspension->getEndDate() ?? $periodEnd;
$overlapStart = $sStart > $periodStart ? $sStart : $periodStart;
$overlapEnd = $sEnd < $periodEnd ? $sEnd : $periodEnd;
if ($overlapStart > $overlapEnd) {
continue;
}
for ($cursor = $overlapStart; $cursor <= $overlapEnd; $cursor = $cursor->modify('+1 day')) {
$weekDay = (int) $cursor->format('N');
$dayKey = $cursor->format('Y-m-d');
if ($weekDay <= 5 && !isset($publicHolidays[$dayKey])) {
++$total;
}
}
}
return $total;
}
}

View File

@@ -13,12 +13,11 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Throwable;
final class PublicHolidayService implements PublicHolidayServiceInterface
final readonly class PublicHolidayService implements PublicHolidayServiceInterface
{
private const string BASE_URL = 'https://calendrier.api.gouv.fr/jours-feries/';
public function __construct(
private readonly HttpClientInterface $client,
private HttpClientInterface $client,
private string $holidayUrl
) {}
/**
@@ -31,7 +30,7 @@ final class PublicHolidayService implements PublicHolidayServiceInterface
public function getHolidaysDay(string $zone): array
{
$zone = strtolower(trim($zone));
$url = self::BASE_URL."{$zone}.json";
$url = $this->holidayUrl."{$zone}.json";
try {
$response = $this->client->request(
@@ -61,7 +60,7 @@ final class PublicHolidayService implements PublicHolidayServiceInterface
{
$zone = strtolower(trim($zone));
$years = trim($years);
$url = self::BASE_URL."{$zone}/{$years}.json";
$url = $this->holidayUrl."{$zone}/{$years}.json";
try {
$response = $this->client->request('GET', $url);

View File

@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\ContractSuspension;
use App\Entity\EmployeeContractPeriod;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
final readonly class ContractSuspensionWriteProcessor implements ProcessorInterface
{
public function __construct(
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
private ProcessorInterface $persistProcessor,
private EntityManagerInterface $entityManager,
) {}
public function process(
mixed $data,
Operation $operation,
array $uriVariables = [],
array $context = []
): mixed {
if (!$data instanceof ContractSuspension) {
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
}
$period = $data->getContractPeriod();
if (!$period instanceof EmployeeContractPeriod && null !== $data->getContractPeriodId()) {
$period = $this->entityManager->find(EmployeeContractPeriod::class, $data->getContractPeriodId());
if ($period instanceof EmployeeContractPeriod) {
$data->setContractPeriod($period);
}
}
if (!$period instanceof EmployeeContractPeriod) {
throw new UnprocessableEntityHttpException('contractPeriodId is required.');
}
$this->validate($data, $period);
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
}
private function validate(ContractSuspension $suspension, EmployeeContractPeriod $period): void
{
// Compare as Y-m-d strings to avoid timezone issues between Doctrine and API Platform DateTimeImmutable
$startDate = $suspension->getStartDate()->format('Y-m-d');
$endDate = $suspension->getEndDate()?->format('Y-m-d');
$periodStart = $period->getStartDate()->format('Y-m-d');
$periodEnd = $period->getEndDate()?->format('Y-m-d');
if (null !== $periodEnd && $periodEnd < new DateTimeImmutable('today')->format('Y-m-d')) {
throw new UnprocessableEntityHttpException('Impossible de suspendre une période de contrat clôturée.');
}
if (null !== $endDate && $endDate < $startDate) {
throw new UnprocessableEntityHttpException('La date de fin doit être postérieure à la date de début.');
}
if ($startDate < $periodStart) {
throw new UnprocessableEntityHttpException('La suspension ne peut pas commencer avant le début du contrat.');
}
if (null !== $periodEnd) {
if ($startDate > $periodEnd) {
throw new UnprocessableEntityHttpException('La suspension ne peut pas commencer après la fin du contrat.');
}
if (null !== $endDate && $endDate > $periodEnd) {
throw new UnprocessableEntityHttpException('La suspension ne peut pas se terminer après la fin du contrat.');
}
}
$this->validateNoOverlap($suspension, $period);
}
private function validateNoOverlap(ContractSuspension $suspension, EmployeeContractPeriod $period): void
{
$start = $suspension->getStartDate()->format('Y-m-d');
$end = $suspension->getEndDate()?->format('Y-m-d');
foreach ($period->getSuspensions() as $existing) {
if ($existing->getId() === $suspension->getId() && null !== $suspension->getId()) {
continue;
}
$existingStart = $existing->getStartDate()->format('Y-m-d');
$existingEnd = $existing->getEndDate()?->format('Y-m-d');
if (null === $end && null === $existingEnd) {
throw new UnprocessableEntityHttpException('Les suspensions ne peuvent pas se chevaucher.');
}
if (null === $end) {
if ($start <= $existingEnd) {
throw new UnprocessableEntityHttpException('Les suspensions ne peuvent pas se chevaucher.');
}
continue;
}
if (null === $existingEnd) {
if ($existingStart <= $end) {
throw new UnprocessableEntityHttpException('Les suspensions ne peuvent pas se chevaucher.');
}
continue;
}
if ($start <= $existingEnd && $end >= $existingStart) {
throw new UnprocessableEntityHttpException('Les suspensions ne peuvent pas se chevaucher.');
}
}
}
}

View File

@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\EmployeeLeaveSummary;
use App\Entity\Absence;
use App\Entity\ContractSuspension;
use App\Entity\Employee;
use App\Entity\User;
use App\Enum\ContractNature;
@@ -17,8 +18,10 @@ use App\Repository\AbsenceRepository;
use App\Repository\EmployeeContractPeriodRepository;
use App\Repository\EmployeeLeaveBalanceRepository;
use App\Repository\EmployeeRepository;
use App\Repository\WorkHourRepository;
use App\Security\EmployeeScopeService;
use App\Service\Leave\LeaveBalanceComputationService;
use App\Service\Leave\SuspensionDaysCalculator;
use App\Service\PublicHolidayServiceInterface;
use DateTimeImmutable;
use Symfony\Bundle\SecurityBundle\Security;
@@ -50,6 +53,8 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
private LeaveBalanceComputationService $leaveBalanceComputationService,
private PublicHolidayServiceInterface $publicHolidayService,
private SuspensionDaysCalculator $suspensionDaysCalculator,
private WorkHourRepository $workHourRepository,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): EmployeeLeaveSummary
@@ -97,6 +102,9 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$summary->remainingDays = $yearSummary['remainingDays'] + $fractionedDays;
$summary->remainingSaturdays = $yearSummary['remainingSaturdays'];
[$periodFrom, $periodTo] = $this->resolvePeriodBounds($employee, $year);
$summary->presenceDaysByMonth = $this->workHourRepository->countPresenceDaysByMonth($employee, $periodFrom, $periodTo);
return $summary;
}
@@ -163,18 +171,21 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$effectiveFrom = $this->resolveEffectivePeriodStart($employee, $from, $to);
$hasShiftedStart = $effectiveFrom > $from;
if ($hasShiftedStart) {
if ($hasShiftedStart && null === $openingBalance) {
$carryDays = 0.0;
$carrySaturdays = 0.0;
}
$calculationEnd = $this->resolveCalculationEndDate($leavePolicy['ruleCode'], $year, $to);
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
$accrualCalculationEnd = $this->resolveAccrualCalculationEndDate($leavePolicy['ruleCode'], $year, $to, $employee);
$takenCalculationEnd = $this->resolveTakenCalculationEndDate($to, $employee);
$suspensions = $this->resolveSuspensionsForPeriod($employee, $effectiveFrom, $to);
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
? $this->computeAccruedDaysFromStart(
$leavePolicy['acquiredDays'],
$leavePolicy['accrualPerMonth'],
$effectiveFrom,
$calculationEnd
$accrualCalculationEnd,
$suspensions
)
: 0.0;
$generatedSaturdays = $leavePolicy['saturdayAccrualPerMonth'] > 0.0
@@ -182,17 +193,25 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$leavePolicy['acquiredSaturdays'],
$leavePolicy['saturdayAccrualPerMonth'],
$effectiveFrom,
$calculationEnd
$accrualCalculationEnd,
$suspensions
)
: 0.0;
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $from, $to);
[$takenDays, $takenSaturdays] = $this->computeTakenAbsences(
$absences,
$effectiveFrom,
$calculationEnd,
$takenCalculationEnd,
$leavePolicy['countOnlyCp'],
$leavePolicy['splitSaturdays']
);
// Bootstrap support: if the opening balance has pre-filled taken days
// (e.g. manual data entry for production bootstrap), add them as an offset.
if (null !== $openingBalance) {
$takenDays += $openingBalance->getTakenDays();
$takenSaturdays += $openingBalance->getTakenSaturdays();
}
if (LeaveRuleCode::CDI_CDD_NON_FORFAIT->value === $leavePolicy['ruleCode']) {
$availableAcquired = max(0.0, $carryDays);
$takenFromAcquired = min($availableAcquired, $takenDays);
@@ -216,7 +235,16 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$previousRemainingSaturdays = $remainingAcquiredSaturdays + $remainingGeneratedSaturdays;
} else {
// Forfait: no "en cours d'acquisition" counter, all rights are in acquired.
$acquiredDays = $carryDays + $leavePolicy['acquiredDays'];
$acquiredDays = $carryDays + $leavePolicy['acquiredDays'];
$suspensions = $this->resolveSuspensionsForPeriod($employee, $from, $to);
if ([] !== $suspensions) {
$totalMonths = $this->countFractionalMonths($from, $to);
$suspendedMonths = $this->countSuspendedFractionalMonths($from, $to, $suspensions);
if ($totalMonths > 0) {
$ratio = max(0.0, ($totalMonths - $suspendedMonths) / $totalMonths);
$acquiredDays = $carryDays + $leavePolicy['acquiredDays'] * $ratio;
}
}
$accruingDays = 0.0;
$remainingDays = max(0.0, $acquiredDays - $takenDays);
$acquiredSaturdays = 0.0;
@@ -272,14 +300,14 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
): ?DateTimeImmutable {
$earliest = null;
foreach ($employee->getContractHistory() as $period) {
$start = DateTimeImmutable::createFromFormat('Y-m-d', $period->startDate);
$start = $this->parseYmdDate($period->startDate);
if (!$start instanceof DateTimeImmutable) {
continue;
}
$end = null;
if (null !== $period->endDate && '' !== trim($period->endDate)) {
$end = DateTimeImmutable::createFromFormat('Y-m-d', $period->endDate);
$end = $this->parseYmdDate($period->endDate);
}
if ($start > $to) {
@@ -326,7 +354,8 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
float $acquiredDays,
float $accrualPerMonth,
DateTimeImmutable $periodStart,
?DateTimeImmutable $periodEnd
?DateTimeImmutable $periodEnd,
array $suspensions = []
): float {
if ($accrualPerMonth <= 0.0) {
return $acquiredDays;
@@ -336,20 +365,36 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
return 0.0;
}
$monthsElapsed = ((int) $periodEnd->format('Y') - (int) $periodStart->format('Y')) * 12
+ ((int) $periodEnd->format('n') - (int) $periodStart->format('n'))
+ 1;
if ($monthsElapsed < 0) {
return 0.0;
$periodStart = $this->normalizeDate($periodStart);
$periodEnd = $this->normalizeDate($periodEnd);
$coveredMonths = 0.0;
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
while ($cursor <= $periodEnd) {
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
if ($monthEnd > $periodEnd) {
$monthEnd = $periodEnd;
}
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
if ([] !== $suspensions) {
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
$coveredDays = max(0, $coveredDays - $suspendedDays);
}
$daysInMonth = (int) $cursor->format('t');
$coveredMonths += $coveredDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return min($acquiredDays, $monthsElapsed * $accrualPerMonth);
return min($acquiredDays, $coveredMonths * $accrualPerMonth);
}
private function resolveCalculationEndDate(
private function resolveAccrualCalculationEndDate(
string $ruleCode,
int $year,
DateTimeImmutable $periodEnd
DateTimeImmutable $periodEnd,
Employee $employee
): ?DateTimeImmutable {
$today = new DateTimeImmutable('today');
$currentYear = LeaveRuleCode::FORFAIT_218->value === $ruleCode
@@ -357,18 +402,46 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
: $this->resolveCurrentLeaveYear($today);
if ($year < $currentYear) {
return $periodEnd;
}
if ($year > $currentYear) {
return null;
$end = $periodEnd;
} elseif ($year > $currentYear) {
$end = null;
} else {
$lastDayPreviousMonth = $today
->modify('first day of this month')
->modify('-1 day')
->setTime(0, 0)
;
$end = $lastDayPreviousMonth < $periodEnd ? $lastDayPreviousMonth : $periodEnd;
}
$lastDayPreviousMonth = $today
->modify('first day of this month')
->modify('-1 day')
;
// Cap at contract end date if the employee has left.
$contractEndRaw = $employee->getCurrentContractEndDate();
if (null !== $end && null !== $contractEndRaw && '' !== trim($contractEndRaw)) {
$contractEnd = $this->parseYmdDate($contractEndRaw);
if ($contractEnd instanceof DateTimeImmutable && $contractEnd < $end) {
$end = $contractEnd;
}
}
return $lastDayPreviousMonth < $periodEnd ? $lastDayPreviousMonth : $periodEnd;
return $end;
}
private function resolveTakenCalculationEndDate(
DateTimeImmutable $periodEnd,
Employee $employee
): ?DateTimeImmutable {
$end = $periodEnd;
// Cap at contract end date if the employee has left.
$contractEndRaw = $employee->getCurrentContractEndDate();
if (null !== $end && null !== $contractEndRaw && '' !== trim($contractEndRaw)) {
$contractEnd = $this->parseYmdDate($contractEndRaw);
if ($contractEnd instanceof DateTimeImmutable && $contractEnd < $end) {
$end = $contractEnd;
}
}
return $end;
}
/**
@@ -484,8 +557,8 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
private function resolveLeavePeriodBounds(int $leaveYear): array
{
// Exercice CP "2026" = du 1er juin 2025 au 31 mai 2026.
$from = new DateTimeImmutable(sprintf('%d-06-01', $leaveYear - 1));
$to = new DateTimeImmutable(sprintf('%d-05-31', $leaveYear));
$from = new DateTimeImmutable(sprintf('%d-06-01 00:00:00', $leaveYear - 1));
$to = new DateTimeImmutable(sprintf('%d-05-31 00:00:00', $leaveYear));
return [$from, $to];
}
@@ -495,12 +568,12 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
*/
private function resolveForfaitYearBounds(Employee $employee, int $year): array
{
$from = new DateTimeImmutable(sprintf('%d-01-01', $year));
$to = new DateTimeImmutable(sprintf('%d-12-31', $year));
$from = new DateTimeImmutable(sprintf('%d-01-01 00:00:00', $year));
$to = new DateTimeImmutable(sprintf('%d-12-31 00:00:00', $year));
$contractStartRaw = $employee->getCurrentContractStartDate();
if (null !== $contractStartRaw && '' !== trim($contractStartRaw)) {
$contractStart = DateTimeImmutable::createFromFormat('Y-m-d', $contractStartRaw);
$contractStart = $this->parseYmdDate($contractStartRaw);
if ($contractStart instanceof DateTimeImmutable && $contractStart > $from) {
$from = $contractStart;
}
@@ -508,7 +581,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$contractEndRaw = $employee->getCurrentContractEndDate();
if (null !== $contractEndRaw && '' !== trim($contractEndRaw)) {
$contractEnd = DateTimeImmutable::createFromFormat('Y-m-d', $contractEndRaw);
$contractEnd = $this->parseYmdDate($contractEndRaw);
if ($contractEnd instanceof DateTimeImmutable && $contractEnd < $to) {
$to = $contractEnd;
}
@@ -546,7 +619,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$oldestStartDate = null;
foreach ($history as $item) {
$start = DateTimeImmutable::createFromFormat('Y-m-d', $item->startDate);
$start = $this->parseYmdDate($item->startDate);
if (!$start) {
continue;
}
@@ -575,6 +648,18 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
return $firstYear;
}
private function parseYmdDate(string $value): ?DateTimeImmutable
{
$date = DateTimeImmutable::createFromFormat('!Y-m-d', trim($value));
return $date instanceof DateTimeImmutable ? $date : null;
}
private function normalizeDate(DateTimeImmutable $date): DateTimeImmutable
{
return $date->setTime(0, 0);
}
/**
* @param list<Absence> $absences
*
@@ -615,14 +700,27 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
}
for ($cursor = $rangeStart; $cursor <= $rangeEnd; $cursor = $cursor->modify('+1 day')) {
$dayOfWeek = (int) $cursor->format('N');
if ($splitSaturdays) {
// Mode CDI/CDD : dimanche ignoré, samedi compté séparément.
if (7 === $dayOfWeek) {
continue;
}
} else {
// Mode forfait : seuls les jours ouvrés (lun-ven) comptent.
if ($dayOfWeek >= 6) {
continue;
}
}
[$am, $pm] = $this->resolveSegmentsForDate($absence, $cursor->format('Y-m-d'));
$dayAmount = ($am ? 0.5 : 0.0) + ($pm ? 0.5 : 0.0);
if ($dayAmount <= 0.0) {
continue;
}
$isSaturday = $splitSaturdays && '6' === $cursor->format('N');
if ($isSaturday && $splitSaturdays) {
if ($splitSaturdays && 6 === $dayOfWeek) {
$takenSaturdays += $dayAmount;
} else {
$takenDays += $dayAmount;
@@ -633,6 +731,80 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
return [$takenDays, $takenSaturdays];
}
private function countFractionalMonths(DateTimeImmutable $from, DateTimeImmutable $to): float
{
$from = $this->normalizeDate($from);
$to = $this->normalizeDate($to);
$months = 0.0;
$cursor = $from->modify('first day of this month')->setTime(0, 0);
while ($cursor <= $to) {
$monthStart = $cursor > $from ? $cursor : $from;
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
if ($monthEnd > $to) {
$monthEnd = $to;
}
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
$daysInMonth = (int) $cursor->format('t');
$months += $coveredDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return $months;
}
/**
* @param list<ContractSuspension> $suspensions
*/
private function countSuspendedFractionalMonths(DateTimeImmutable $from, DateTimeImmutable $to, array $suspensions): float
{
$from = $this->normalizeDate($from);
$to = $this->normalizeDate($to);
$months = 0.0;
$cursor = $from->modify('first day of this month')->setTime(0, 0);
while ($cursor <= $to) {
$monthStart = $cursor > $from ? $cursor : $from;
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
if ($monthEnd > $to) {
$monthEnd = $to;
}
$daysInMonth = (int) $cursor->format('t');
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
$months += $suspendedDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return $months;
}
/**
* @return list<ContractSuspension>
*/
private function resolveSuspensionsForPeriod(Employee $employee, DateTimeImmutable $from, DateTimeImmutable $to): array
{
$suspensions = [];
foreach ($employee->getContractPeriods() as $period) {
$periodStart = $period->getStartDate();
$periodEnd = $period->getEndDate();
if ($periodStart > $to) {
continue;
}
if ($periodEnd instanceof DateTimeImmutable && $periodEnd < $from) {
continue;
}
foreach ($period->getSuspensions() as $suspension) {
$suspensions[] = $suspension;
}
}
return $suspensions;
}
/**
* @return array{bool, bool}
*/

View File

@@ -68,6 +68,9 @@ final readonly class EmployeeWriteProcessor implements ProcessorInterface
nature: $nature
);
$data->setEntryDate($startDate);
$this->entityManager->flush();
return $result;
}

View File

@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\Leave;
use App\Service\Leave\LeaveBalanceComputationService;
use App\Service\Leave\SuspensionDaysCalculator;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
/**
* @internal
*/
final class LeaveBalanceComputationServiceTest extends TestCase
{
public function testComputeAccruedDaysProratesPartialFirstMonth(): void
{
$service = $this->createServiceWithoutConstructor();
$method = new ReflectionClass(LeaveBalanceComputationService::class)->getMethod('computeAccruedDays');
$result = $method->invoke(
$service,
25.0,
25.0 / 12.0,
new DateTimeImmutable('2025-06-10'),
new DateTimeImmutable('2026-02-28')
);
self::assertEqualsWithDelta(18.125, $result, 0.0001);
}
public function testComputeAccruedDaysTotalMatchesAlainCase(): void
{
$service = $this->createServiceWithoutConstructor();
$method = new ReflectionClass(LeaveBalanceComputationService::class)->getMethod('computeAccruedDays');
$days = $method->invoke(
$service,
25.0,
25.0 / 12.0,
new DateTimeImmutable('2025-06-10'),
new DateTimeImmutable('2026-02-28')
);
$saturdays = $method->invoke(
$service,
5.0,
5.0 / 12.0,
new DateTimeImmutable('2025-06-10'),
new DateTimeImmutable('2026-02-28')
);
self::assertEqualsWithDelta(21.75, $days + $saturdays, 0.0001);
}
public function testComputeAccruedDaysIncludesLastDayOfMonthDespiteTimeComponents(): void
{
$service = $this->createServiceWithoutConstructor();
$method = new ReflectionClass(LeaveBalanceComputationService::class)->getMethod('computeAccruedDays');
$result = $method->invoke(
$service,
25.0,
25.0 / 12.0,
new DateTimeImmutable('2026-02-01 12:50:18'),
new DateTimeImmutable('2026-02-28 00:00:00')
);
self::assertEqualsWithDelta(25.0 / 12.0, $result, 0.0001);
}
private function createServiceWithoutConstructor(): LeaveBalanceComputationService
{
$rc = new ReflectionClass(LeaveBalanceComputationService::class);
$service = $rc->newInstanceWithoutConstructor();
$prop = $rc->getProperty('suspensionDaysCalculator');
$prop->setValue($service, new SuspensionDaysCalculator());
return $service;
}
}

View File

@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\Leave;
use App\Entity\ContractSuspension;
use App\Service\Leave\SuspensionDaysCalculator;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
final class SuspensionDaysCalculatorTest extends TestCase
{
public function testNoSuspensionsReturnsZero(): void
{
$calc = new SuspensionDaysCalculator();
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[]
);
self::assertSame(0, $result);
}
public function testFullMonthSuspension(): void
{
$calc = new SuspensionDaysCalculator();
$suspension = $this->buildSuspension('2026-03-01', '2026-03-31');
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[$suspension]
);
self::assertSame(31, $result);
}
public function testPartialMonthSuspension(): void
{
$calc = new SuspensionDaysCalculator();
$suspension = $this->buildSuspension('2026-03-10', '2026-03-20');
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[$suspension]
);
self::assertSame(11, $result);
}
public function testSuspensionSpanningMultipleMonths(): void
{
$calc = new SuspensionDaysCalculator();
$suspension = $this->buildSuspension('2026-02-15', '2026-04-10');
// March fully covered
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[$suspension]
);
self::assertSame(31, $result);
}
public function testSuspensionWithoutEndDate(): void
{
$calc = new SuspensionDaysCalculator();
$suspension = $this->buildSuspension('2026-03-15', null);
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[$suspension]
);
self::assertSame(17, $result);
}
public function testMultipleSuspensionsInSameMonth(): void
{
$calc = new SuspensionDaysCalculator();
$s1 = $this->buildSuspension('2026-03-01', '2026-03-10');
$s2 = $this->buildSuspension('2026-03-20', '2026-03-25');
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[$s1, $s2]
);
self::assertSame(16, $result);
}
public function testSuspensionOutsideMonthReturnsZero(): void
{
$calc = new SuspensionDaysCalculator();
$suspension = $this->buildSuspension('2026-01-01', '2026-01-31');
$result = $calc->countSuspendedDaysInMonth(
new DateTimeImmutable('2026-03-01'),
new DateTimeImmutable('2026-03-31'),
[$suspension]
);
self::assertSame(0, $result);
}
public function testCountSuspendedBusinessDays(): void
{
$calc = new SuspensionDaysCalculator();
// March 2-6, 2026 = Mon-Fri = 5 business days
$suspension = $this->buildSuspension('2026-03-02', '2026-03-06');
$result = $calc->countSuspendedBusinessDays(
new DateTimeImmutable('2026-01-01'),
new DateTimeImmutable('2026-12-31'),
[$suspension],
[]
);
self::assertSame(5, $result);
}
private function buildSuspension(string $start, ?string $end): ContractSuspension
{
$s = new ContractSuspension();
$s->setStartDate(new DateTimeImmutable($start));
if (null !== $end) {
$s->setEndDate(new DateTimeImmutable($end));
}
return $s;
}
}

View File

@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace App\Tests\State;
use ApiPlatform\Metadata\Post;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\ContractSuspension;
use App\Entity\EmployeeContractPeriod;
use App\Enum\ContractNature;
use App\State\ContractSuspensionWriteProcessor;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
/**
* @internal
*/
final class ContractSuspensionWriteProcessorTest extends TestCase
{
public function testPersistsValidSuspension(): void
{
$period = $this->buildPeriodWithId(1, '2026-01-01', null);
$suspension = new ContractSuspension();
$suspension->setContractPeriod($period);
$suspension->setStartDate(new DateTimeImmutable('2026-03-01'));
$suspension->setEndDate(new DateTimeImmutable('2026-04-30'));
$suspension->setComment('Congé sans solde');
$persistProcessor = $this->createMock(ProcessorInterface::class);
$persistProcessor->expects(self::once())->method('process')->willReturn($suspension);
$entityManager = $this->createStub(EntityManagerInterface::class);
$processor = new ContractSuspensionWriteProcessor($persistProcessor, $entityManager);
$result = $processor->process($suspension, new Post());
self::assertSame($suspension, $result);
}
public function testRejectsEndDateBeforeStartDate(): void
{
$period = $this->buildPeriodWithId(1, '2026-01-01', null);
$suspension = new ContractSuspension();
$suspension->setContractPeriod($period);
$suspension->setStartDate(new DateTimeImmutable('2026-05-01'));
$suspension->setEndDate(new DateTimeImmutable('2026-03-01'));
$persistProcessor = $this->createStub(ProcessorInterface::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$processor = new ContractSuspensionWriteProcessor($persistProcessor, $entityManager);
$this->expectException(UnprocessableEntityHttpException::class);
$processor->process($suspension, new Post());
}
public function testRejectsStartDateBeforePeriodStart(): void
{
$period = $this->buildPeriodWithId(1, '2026-06-01', null);
$suspension = new ContractSuspension();
$suspension->setContractPeriod($period);
$suspension->setStartDate(new DateTimeImmutable('2026-01-01'));
$persistProcessor = $this->createStub(ProcessorInterface::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$processor = new ContractSuspensionWriteProcessor($persistProcessor, $entityManager);
$this->expectException(UnprocessableEntityHttpException::class);
$processor->process($suspension, new Post());
}
public function testRejectsOverlappingSuspension(): void
{
$period = $this->buildPeriodWithId(1, '2026-01-01', null);
$existing = new ContractSuspension();
$existing->setContractPeriod($period);
$existing->setStartDate(new DateTimeImmutable('2026-03-01'));
$existing->setEndDate(new DateTimeImmutable('2026-04-30'));
$period->getSuspensions()->add($existing);
$suspension = new ContractSuspension();
$suspension->setContractPeriod($period);
$suspension->setStartDate(new DateTimeImmutable('2026-04-01'));
$suspension->setEndDate(new DateTimeImmutable('2026-05-31'));
$persistProcessor = $this->createStub(ProcessorInterface::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$processor = new ContractSuspensionWriteProcessor($persistProcessor, $entityManager);
$this->expectException(UnprocessableEntityHttpException::class);
$processor->process($suspension, new Post());
}
public function testRejectsClosedPeriod(): void
{
$period = $this->buildPeriodWithId(1, '2025-01-01', '2025-12-31');
$suspension = new ContractSuspension();
$suspension->setContractPeriod($period);
$suspension->setStartDate(new DateTimeImmutable('2025-06-01'));
$suspension->setEndDate(new DateTimeImmutable('2025-07-31'));
$persistProcessor = $this->createStub(ProcessorInterface::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$processor = new ContractSuspensionWriteProcessor($persistProcessor, $entityManager);
$this->expectException(UnprocessableEntityHttpException::class);
$processor->process($suspension, new Post());
}
private function buildPeriodWithId(int $id, string $start, ?string $end): EmployeeContractPeriod
{
$period = new EmployeeContractPeriod();
$period->setStartDate(new DateTimeImmutable($start));
if (null !== $end) {
$period->setEndDate(new DateTimeImmutable($end));
}
$period->setContractNature(ContractNature::CDI);
$ref = new ReflectionProperty($period, 'id');
$ref->setValue($period, $id);
return $period;
}
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace App\Tests\State;
use App\State\EmployeeLeaveSummaryProvider;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
/**
* @internal
*/
final class EmployeeLeaveSummaryProviderTest extends TestCase
{
public function testComputeAccruedDaysFromStartProratesPartialFirstMonth(): void
{
$provider = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->newInstanceWithoutConstructor();
$method = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->getMethod('computeAccruedDaysFromStart');
$result = $method->invoke(
$provider,
25.0,
25.0 / 12.0,
new DateTimeImmutable('2025-06-10'),
new DateTimeImmutable('2026-02-28')
);
self::assertEqualsWithDelta(18.125, $result, 0.0001);
}
public function testComputeAccruingDaysTotalMatchesAlainCase(): void
{
$provider = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->newInstanceWithoutConstructor();
$method = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->getMethod('computeAccruedDaysFromStart');
$days = $method->invoke(
$provider,
25.0,
25.0 / 12.0,
new DateTimeImmutable('2025-06-10'),
new DateTimeImmutable('2026-02-28')
);
$saturdays = $method->invoke(
$provider,
5.0,
5.0 / 12.0,
new DateTimeImmutable('2025-06-10'),
new DateTimeImmutable('2026-02-28')
);
self::assertEqualsWithDelta(21.75, $days + $saturdays, 0.0001);
}
public function testComputeAccruedDaysFromStartIncludesLastDayOfMonth(): void
{
$provider = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->newInstanceWithoutConstructor();
$method = new ReflectionClass(EmployeeLeaveSummaryProvider::class)->getMethod('computeAccruedDaysFromStart');
$result = $method->invoke(
$provider,
25.0,
25.0 / 12.0,
new DateTimeImmutable('2026-02-01 12:50:18'),
new DateTimeImmutable('2026-02-28 00:00:00')
);
self::assertEqualsWithDelta(25.0 / 12.0, $result, 0.0001);
}
}

View File

@@ -6,6 +6,7 @@ namespace App\Tests\State;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Contract;
use App\Entity\Employee;
@@ -194,6 +195,54 @@ final class EmployeeWriteProcessorTest extends TestCase
self::assertSame($employee, $result);
}
public function testSetsEntryDateOnNewEmployee(): void
{
$employee = new Employee();
$employee->setFirstName('Jane');
$employee->setLastName('Doe');
$employee->setContractStartDate('2026-04-01');
$employee->setContractNature('CDI');
$contract = new Contract()
->setName('35h')
->setTrackingMode(Contract::TRACKING_TIME)
->setWeeklyHours(35)
;
$employee->setContract($contract);
$persistProcessor = $this->createMock(ProcessorInterface::class);
$removeProcessor = $this->createStub(ProcessorInterface::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$periodRepository = $this->createStub(EmployeeContractPeriodReadRepositoryInterface::class);
$changeRequestFactory = new EmployeeContractChangeRequestFactory();
$periodManager = $this->createMock(EmployeeContractPeriodManagerInterface::class);
$persistProcessor
->expects(self::once())
->method('process')
->willReturn($employee)
;
$periodManager
->expects(self::once())
->method('ensureContractPeriodExists')
;
$processor = new EmployeeWriteProcessor(
$persistProcessor,
$removeProcessor,
$entityManager,
$periodRepository,
$changeRequestFactory,
$periodManager
);
$processor->process($employee, new Post());
self::assertNotNull($employee->getEntryDate());
self::assertSame('2026-04-01', $employee->getEntryDate()->format('Y-m-d'));
}
public function testDeleteOperationDelegatesToRemoveProcessor(): void
{
$employee = $this->buildEmployeeWithId(45);