feat : ajout d'un onglet formation
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
This commit is contained in:
@@ -6,9 +6,11 @@ namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Entity\Formation;
|
||||
use App\Enum\ContractNature;
|
||||
use App\Enum\HalfDay;
|
||||
use App\Repository\AbsenceRepository;
|
||||
use App\Repository\Contract\FormationReadRepositoryInterface;
|
||||
use App\Repository\EmployeeRepository;
|
||||
use App\Service\PublicHolidayServiceInterface;
|
||||
use DateInterval;
|
||||
@@ -30,6 +32,7 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
private readonly RequestStack $requestStack,
|
||||
private EmployeeRepository $employeeRepository,
|
||||
private AbsenceRepository $absenceRepository,
|
||||
private FormationReadRepositoryInterface $formationRepository,
|
||||
private PublicHolidayServiceInterface $publicHolidayService,
|
||||
) {}
|
||||
|
||||
@@ -58,24 +61,27 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
$workContractIds = $this->parseIds($request->query->get('workContracts'));
|
||||
$contractNatures = $this->parseContractNatures($request->query->get('contractNatures'));
|
||||
|
||||
$employees = $this->loadEmployees($siteIds, $contractNatures, $workContractIds);
|
||||
$absences = $this->loadAbsences($fromDate, $toDate, $employees);
|
||||
$employees = $this->loadEmployees($siteIds, $contractNatures, $workContractIds);
|
||||
$absences = $this->loadAbsences($fromDate, $toDate, $employees);
|
||||
$formations = $this->formationRepository->findByDateRangeAndEmployees($fromDate, $toDate, $employees);
|
||||
|
||||
$days = $this->buildDays($fromDate, $toDate);
|
||||
$absenceMap = $this->buildAbsenceMap($absences, $fromDate, $toDate);
|
||||
$holidayMap = $this->buildHolidayMap($fromDate, $toDate);
|
||||
$days = $this->buildDays($fromDate, $toDate);
|
||||
$absenceMap = $this->buildAbsenceMap($absences, $fromDate, $toDate);
|
||||
$formationMap = $this->buildFormationMap($formations, $fromDate, $toDate);
|
||||
$holidayMap = $this->buildHolidayMap($fromDate, $toDate);
|
||||
|
||||
$options = new Options();
|
||||
$options->set('isRemoteEnabled', true);
|
||||
|
||||
$dompdf = new Dompdf($options);
|
||||
$html = $this->twig->render('absence/print.html.twig', [
|
||||
'from' => $fromDate,
|
||||
'to' => $toDate,
|
||||
'days' => $days,
|
||||
'employees' => $employees,
|
||||
'absenceMap' => $absenceMap,
|
||||
'holidayMap' => $holidayMap,
|
||||
'from' => $fromDate,
|
||||
'to' => $toDate,
|
||||
'days' => $days,
|
||||
'employees' => $employees,
|
||||
'absenceMap' => $absenceMap,
|
||||
'formationMap' => $formationMap,
|
||||
'holidayMap' => $holidayMap,
|
||||
]);
|
||||
|
||||
$dompdf->loadHtml($html);
|
||||
@@ -203,6 +209,37 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<Formation> $formations
|
||||
*
|
||||
* @return array<int, array<string, bool>>
|
||||
*/
|
||||
private function buildFormationMap(array $formations, DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||
{
|
||||
$map = [];
|
||||
|
||||
foreach ($formations as $formation) {
|
||||
$employeeId = $formation->getEmployee()?->getId();
|
||||
if (!$employeeId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formationStart = DateTimeImmutable::createFromInterface($formation->getStartDate());
|
||||
$formationEnd = DateTimeImmutable::createFromInterface($formation->getEndDate());
|
||||
|
||||
$start = max($formationStart, $from);
|
||||
$end = min($formationEnd, $to);
|
||||
|
||||
$current = $start;
|
||||
while ($current <= $end) {
|
||||
$map[$employeeId][$current->format('Y-m-d')] = true;
|
||||
$current = $current->add(new DateInterval('P1D'));
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function buildHolidayMap(DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||
{
|
||||
$map = [];
|
||||
|
||||
Reference in New Issue
Block a user