| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #322 | Page horaire | ## Description de la PR [#322] Page horaire ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #4 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #4.
This commit is contained in:
84
src/Dto/WorkHours/DayContextRow.php
Normal file
84
src/Dto/WorkHours/DayContextRow.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Dto\WorkHours;
|
||||
|
||||
final class DayContextRow
|
||||
{
|
||||
public function __construct(
|
||||
public int $employeeId,
|
||||
public ?string $absenceLabel = null,
|
||||
public ?string $absenceHalf = null,
|
||||
public bool $absentMorning = false,
|
||||
public bool $absentAfternoon = false,
|
||||
public int $creditedMinutes = 0,
|
||||
public float $creditedPresenceUnits = 0.0,
|
||||
) {}
|
||||
|
||||
public function addAbsence(
|
||||
?string $label,
|
||||
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';
|
||||
}
|
||||
|
||||
// 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,
|
||||
* absenceLabel:?string,
|
||||
* absenceHalf:?string,
|
||||
* absentMorning:bool,
|
||||
* absentAfternoon:bool,
|
||||
* creditedMinutes:int,
|
||||
* creditedPresenceUnits:float
|
||||
* }
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'employeeId' => $this->employeeId,
|
||||
'absenceLabel' => $this->absenceLabel,
|
||||
'absenceHalf' => $this->absenceHalf,
|
||||
'absentMorning' => $this->absentMorning,
|
||||
'absentAfternoon' => $this->absentAfternoon,
|
||||
'creditedMinutes' => $this->creditedMinutes,
|
||||
'creditedPresenceUnits' => $this->creditedPresenceUnits,
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user