feat : modification de la gestion des jours fériés
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
This commit is contained in:
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Contracts;
|
||||
|
||||
use App\Entity\Contract;
|
||||
use App\Entity\EmployeeContractPeriod;
|
||||
use App\Enum\ContractNature;
|
||||
use App\Enum\TrackingMode;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
@@ -60,4 +62,63 @@ final class EmployeeContractPeriodValidator
|
||||
throw new UnprocessableEntityHttpException('contractStartDate must be after current contract end date.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the per-period work schedule (`workDaysHours`) against the contract.
|
||||
*
|
||||
* Mandatory for non-standard TIME contracts (weeklyHours ∉ {35, 39}, non-INTERIM,
|
||||
* non-Forfait). Forbidden on standard/forfait/interim contracts (ambiguity).
|
||||
* When provided, sum of minutes MUST equal weeklyHours × 60.
|
||||
*
|
||||
* @param null|array<int, int> $workDaysHours
|
||||
*/
|
||||
public function assertWorkDaysHours(?Contract $contract, ContractNature $nature, ?array $workDaysHours): void
|
||||
{
|
||||
if (null === $contract) {
|
||||
return;
|
||||
}
|
||||
|
||||
$trackingMode = $contract->getTrackingMode();
|
||||
$weeklyHours = $contract->getWeeklyHours();
|
||||
$isStandard = 35 === $weeklyHours || 39 === $weeklyHours;
|
||||
$isForfait = TrackingMode::PRESENCE->value === $trackingMode;
|
||||
$isInterim = ContractNature::INTERIM === $nature;
|
||||
|
||||
if ($isForfait || $isInterim || $isStandard) {
|
||||
if (null !== $workDaysHours && [] !== $workDaysHours) {
|
||||
throw new UnprocessableEntityHttpException('workDaysHours must not be provided for Forfait, Interim or 35h/39h contracts.');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $workDaysHours || [] === $workDaysHours) {
|
||||
throw new UnprocessableEntityHttpException('workDaysHours is required for non-standard contracts.');
|
||||
}
|
||||
|
||||
$totalMinutes = 0;
|
||||
foreach ($workDaysHours as $isoDay => $minutes) {
|
||||
if (!is_int($isoDay) && !(is_string($isoDay) && ctype_digit($isoDay))) {
|
||||
throw new UnprocessableEntityHttpException('workDaysHours keys must be iso weekdays 1-5 (Mon-Fri) as integers.');
|
||||
}
|
||||
$iso = (int) $isoDay;
|
||||
if ($iso < 1 || $iso > 5) {
|
||||
throw new UnprocessableEntityHttpException('workDaysHours keys must be iso weekdays 1-5 (Mon-Fri).');
|
||||
}
|
||||
|
||||
if (!is_int($minutes) || $minutes < 0) {
|
||||
throw new UnprocessableEntityHttpException('workDaysHours values must be non-negative integer minutes.');
|
||||
}
|
||||
$totalMinutes += $minutes;
|
||||
}
|
||||
|
||||
$expectedMinutes = ($weeklyHours ?? 0) * 60;
|
||||
if ($totalMinutes !== $expectedMinutes) {
|
||||
throw new UnprocessableEntityHttpException(sprintf(
|
||||
'workDaysHours total must equal contract weekly hours: got %d min, expected %d min.',
|
||||
$totalMinutes,
|
||||
$expectedMinutes
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user