Files
SIRH/src/Dto/WorkHours/DayContextRow.php
tristan 339d650b41
All checks were successful
Auto Tag Develop / tag (push) Successful in 8s
feat : ajout de la gestion des heures chauffeurs
2026-03-15 19:04:52 +01:00

102 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Dto\WorkHours;
final class DayContextRow
{
public function __construct(
public int $employeeId,
public bool $hasContractAtDate = true,
public ?string $absenceLabel = null,
public ?string $absenceColor = null,
public ?string $absenceHalf = null,
public bool $absentMorning = false,
public bool $absentAfternoon = false,
public int $creditedMinutes = 0,
public float $creditedPresenceUnits = 0.0,
public bool $isDriverContract = false,
) {}
public function addAbsence(
?string $label,
?string $color,
bool $morning,
bool $afternoon,
int $creditedMinutes,
float $creditedPresenceUnits
): void {
// Fusionne plusieurs absences du même jour sur la ligne salarié.
$this->absentMorning = $this->absentMorning || $morning;
$this->absentAfternoon = $this->absentAfternoon || $afternoon;
// Garde un libellé lisible: unique si possible, sinon "Absences multiples".
if (null === $this->absenceLabel) {
$this->absenceLabel = $label;
} elseif ($label !== $this->absenceLabel) {
$this->absenceLabel = 'Absences multiples';
}
// Si plusieurs types d'absence différents sont fusionnés sur la même journée,
// on retire la couleur métier spécifique.
if (null === $this->absenceColor) {
$this->absenceColor = $color;
} elseif ($color !== $this->absenceColor) {
$this->absenceColor = null;
}
// AM/PM seulement pour les demi-journées, null pour journée complète.
$this->absenceHalf = $this->resolveHalfLabel($this->absentMorning, $this->absentAfternoon);
// Cumule les minutes créditées par les absences "comptées comme travaillées".
$this->creditedMinutes += $creditedMinutes;
// Cumule les unités de présence créditées (0.5 par demi-journée).
$this->creditedPresenceUnits += $creditedPresenceUnits;
}
/**
* @return array{
* employeeId:int,
* hasContractAtDate:bool,
* absenceLabel:?string,
* absenceColor:?string,
* absenceHalf:?string,
* absentMorning:bool,
* absentAfternoon:bool,
* creditedMinutes:int,
* creditedPresenceUnits:float
* }
*/
public function toArray(): array
{
return [
'employeeId' => $this->employeeId,
'hasContractAtDate' => $this->hasContractAtDate,
'absenceLabel' => $this->absenceLabel,
'absenceColor' => $this->absenceColor,
'absenceHalf' => $this->absenceHalf,
'absentMorning' => $this->absentMorning,
'absentAfternoon' => $this->absentAfternoon,
'creditedMinutes' => $this->creditedMinutes,
'creditedPresenceUnits' => $this->creditedPresenceUnits,
'isDriverContract' => $this->isDriverContract,
];
}
private function resolveHalfLabel(bool $morning, bool $afternoon): ?string
{
// Matin + après-midi => journée complète, pas de libellé AM/PM.
if ($morning && $afternoon) {
return null;
}
if ($morning) {
return 'AM';
}
if ($afternoon) {
return 'PM';
}
return null;
}
}