Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
- Nouvelle entité InterimAgency (table interim_agencies, API lecture seule) - Sélecteur agence conditionnel dans les formulaires création employé et ajout contrat - Affichage "Intérim (NomAgence)" sur la liste employés et l'historique contrat - Date de fin obligatoire côté frontend pour CDD et INTERIM (aligné backend) - Renommage "Types d'absence" → "Types de statut" (sidebar, page, titre) - Renommage en-tête "Absence" → "Statut" sur les vues jour heures et conducteurs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Contracts;
|
|
|
|
use App\Entity\Employee;
|
|
use App\Enum\ContractNature;
|
|
use DateTimeImmutable;
|
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
|
|
|
final class EmployeeContractChangeRequestFactory
|
|
{
|
|
public function fromEmployee(Employee $employee): EmployeeContractChangeRequest
|
|
{
|
|
return new EmployeeContractChangeRequest(
|
|
contractNature: $this->resolveContractNature($employee->getContractNature()),
|
|
contractStartDate: $this->parseOptionalYmd($employee->getContractStartDate(), 'contractStartDate'),
|
|
contractEndDate: $this->parseOptionalYmd($employee->getContractEndDate(), 'contractEndDate'),
|
|
contractPaidLeaveSettled: $employee->getContractPaidLeaveSettled(),
|
|
contractComment: $employee->getContractComment(),
|
|
isDriver: $employee->getIsDriverInput(),
|
|
workDaysHours: $employee->getWorkDaysHoursInput(),
|
|
interimAgencyId: $employee->getInterimAgencyId(),
|
|
);
|
|
}
|
|
|
|
private function resolveContractNature(?string $raw): ?ContractNature
|
|
{
|
|
if (null === $raw || '' === trim($raw)) {
|
|
return null;
|
|
}
|
|
|
|
return ContractNature::tryFrom(trim($raw))
|
|
?? throw new UnprocessableEntityHttpException('contractNature must be one of CDI, CDD, INTERIM.');
|
|
}
|
|
|
|
private function parseOptionalYmd(?string $raw, string $field): ?DateTimeImmutable
|
|
{
|
|
if (null === $raw || '' === trim($raw)) {
|
|
return null;
|
|
}
|
|
|
|
$value = trim($raw);
|
|
$date = DateTimeImmutable::createFromFormat('Y-m-d', $value);
|
|
if (!$date || $date->format('Y-m-d') !== $value) {
|
|
throw new UnprocessableEntityHttpException(sprintf('%s must use Y-m-d format.', $field));
|
|
}
|
|
|
|
return $date;
|
|
}
|
|
}
|