feat : refacto de la partie calendrier + ajout de validation sur les formulaires + ajout des jours fériés
This commit is contained in:
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use DateTimeInterface;
|
||||
@@ -19,6 +22,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
'datetime_format' => 'Y-m-d',
|
||||
]
|
||||
)]
|
||||
#[ApiFilter(DateFilter::class, properties: ['startDate', 'endDate'])]
|
||||
#[ApiFilter(SearchFilter::class, properties: ['employee.site' => 'exact'])]
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'absences')]
|
||||
class Absence
|
||||
|
||||
@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Entity\Absence;
|
||||
use App\Entity\Employee;
|
||||
use App\Service\PublicHolidayServiceInterface;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -15,6 +16,7 @@ use Dompdf\Dompdf;
|
||||
use Dompdf\Options;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Throwable;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
@@ -26,6 +28,7 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
private Environment $twig,
|
||||
private readonly RequestStack $requestStack,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private PublicHolidayServiceInterface $publicHolidayService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -56,6 +59,7 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
|
||||
$days = $this->buildDays($fromDate, $toDate);
|
||||
$absenceMap = $this->buildAbsenceMap($absences, $fromDate, $toDate);
|
||||
$holidayMap = $this->buildHolidayMap($fromDate, $toDate);
|
||||
|
||||
$options = new Options();
|
||||
$options->set('isRemoteEnabled', true);
|
||||
@@ -67,6 +71,7 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
'days' => $days,
|
||||
'employees' => $employees,
|
||||
'absenceMap' => $absenceMap,
|
||||
'holidayMap' => $holidayMap,
|
||||
]);
|
||||
|
||||
$dompdf->loadHtml($html);
|
||||
@@ -116,7 +121,7 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
;
|
||||
}
|
||||
|
||||
/** @var list<Employee> $result */
|
||||
// @var list<Employee> $result
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
@@ -140,7 +145,7 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
->setParameter('employees', $employees)
|
||||
;
|
||||
|
||||
/** @var list<Absence> $result */
|
||||
// @var list<Absence> $result
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
@@ -194,4 +199,24 @@ class AbsencePrintProvider implements ProviderInterface
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function buildHolidayMap(DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||
{
|
||||
$map = [];
|
||||
$startYear = (int) $from->format('Y');
|
||||
$endYear = (int) $to->format('Y');
|
||||
|
||||
try {
|
||||
for ($year = $startYear; $year <= $endYear; ++$year) {
|
||||
$holidays = $this->publicHolidayService->getHolidaysDayByYears('metropole', (string) $year);
|
||||
foreach ($holidays as $date => $label) {
|
||||
$map[$date] = (string) $label;
|
||||
}
|
||||
}
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user