feat(heures) : export PDF des heures (vue jour) par sites (#24)
Auto Tag Develop / tag (push) Successful in 7s

## Résumé
Ajoute un bouton **Exporter** (admin uniquement) à droite du titre « Heures » qui génère un **PDF d'une journée**, regroupé par site, reprenant les colonnes de la vue Jour **sans la colonne « Valider »**.

- Drawer : champ date (préremplit la date affichée) + cases à cocher des sites (préselectionnées sur le filtre courant).
- Portée identique à l'écran : non-conducteurs, sous contrat à la date, sites cochés (lignes vides incluses).
- Jour/Nuit/Total incluent le crédit d'absence et le crédit virtuel férié.

## Implémentation
- Back : `WorkHourDayExport` (ApiResource) + `WorkHourDayExportProvider`, endpoint `GET /work-hours/day-export?workDate=&siteIds=` (ROLE_ADMIN).
- Calcul des cellules mutualisé via `YearlyHoursExportBuilder::buildDayRowsForEmployees` (source unique de vérité).
- Gabarit `templates/work-hour-day-export/print.html.twig` (A4 portrait compact).
- Front : `HoursDayExportDrawer.vue` + câblage dans `pages/hours.vue`.
- Docs : `doc/hours-day-export.md`, `documentation-content.ts`, `CLAUDE.md`.

## Tests
- Test unitaire `YearlyHoursDayRowsTest` ajouté.
- Suite complète verte : 173 tests, 359 assertions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #24
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #24.
This commit is contained in:
2026-06-09 12:59:04 +00:00
committed by Autin
parent 2745f4e476
commit 6f9d19bda3
13 changed files with 1629 additions and 6 deletions
+110
View File
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Repository\EmployeeRepository;
use App\Service\WorkHours\YearlyHoursExportBuilder;
use DateTimeImmutable;
use Dompdf\Dompdf;
use Dompdf\Options;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Twig\Environment;
class WorkHourDayExportProvider implements ProviderInterface
{
public function __construct(
private Environment $twig,
private readonly RequestStack $requestStack,
private EmployeeRepository $employeeRepository,
private YearlyHoursExportBuilder $exportBuilder,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Response
{
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return new Response('Missing request.', Response::HTTP_BAD_REQUEST);
}
$workDateRaw = (string) $request->query->get('workDate');
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $workDateRaw)) {
throw new UnprocessableEntityHttpException('workDate must use YYYY-MM-DD format.');
}
$date = new DateTimeImmutable($workDateRaw);
$siteIdsRaw = (string) $request->query->get('siteIds', '');
$siteIds = array_values(array_filter(array_map(
static fn (string $value): int => (int) trim($value),
explode(',', $siteIdsRaw),
), static fn (int $id): bool => $id > 0));
if ([] === $siteIds) {
throw new UnprocessableEntityHttpException('siteIds is required.');
}
// Feature réservée admin : on charge tous les employés puis on filtre.
$employees = $this->employeeRepository->findAll();
// Regroupement par site (ordre displayOrder), non-conducteurs uniquement.
$bySite = [];
$siteMeta = [];
foreach ($employees as $employee) {
if (true === $employee->getIsDriver()) {
continue;
}
$site = $employee->getSite();
if (null === $site || !in_array($site->getId(), $siteIds, true)) {
continue;
}
$siteId = $site->getId();
$bySite[$siteId][] = $employee;
$siteMeta[$siteId] ??= [
'name' => $site->getName(),
'order' => $site->getDisplayOrder(),
'color' => $site->getColor(),
];
}
uasort($siteMeta, static function (array $a, array $b): int {
return [$a['order'], $a['name']] <=> [$b['order'], $b['name']];
});
$groups = [];
foreach ($siteMeta as $siteId => $meta) {
$siteEmployees = $bySite[$siteId];
usort($siteEmployees, static fn ($a, $b) => ($a->getLastName() ?? '') <=> ($b->getLastName() ?? ''));
$rows = $this->exportBuilder->buildDayRowsForEmployees($siteEmployees, $date);
if ([] === $rows) {
continue;
}
$groups[] = ['siteName' => $meta['name'], 'siteColor' => $meta['color'], 'rows' => $rows];
}
$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$html = $this->twig->render('work-hour-day-export/print.html.twig', [
'groups' => $groups,
'dateLabel' => $date->format('d/m/Y'),
'exportedAt' => new DateTimeImmutable('now')->format('d/m/Y H:i'),
]);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$filename = sprintf('heures_jour_%s.pdf', $date->format('Y-m-d'));
return new Response($dompdf->output(), Response::HTTP_OK, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
]);
}
}