feat : ajout d'une page de creation d'une expedition

This commit is contained in:
2026-02-11 16:12:33 +01:00
parent 0181d72144
commit 5f4139fde3
31 changed files with 1292 additions and 356 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Entity\Shipment;
use Doctrine\ORM\EntityManagerInterface;
use Dompdf\Dompdf;
use Dompdf\Options;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
final readonly class ShipmentReceiptProvider implements ProviderInterface
{
public function __construct(
private Environment $twig,
private EntityManagerInterface $entityManager,
) {}
/**
* @throws RuntimeError
* @throws SyntaxError
* @throws LoaderError
*/
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Response
{
$id = $uriVariables['id'] ?? null;
if (null === $id) {
throw new NotFoundHttpException('Shipment not found.');
}
$shipment = $this->entityManager->getRepository(Shipment::class)->find($id);
if (!$shipment instanceof Shipment) {
throw new NotFoundHttpException('Shipment not found.');
}
$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$html = $this->twig->render('shipment_voucher.html.twig', [
'shipment' => $shipment,
]);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4');
$dompdf->render();
$filename = sprintf('bon-expedition-%d.pdf', $shipment->getId());
return new Response($dompdf->output(), Response::HTTP_OK, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'.$filename.'"',
]);
}
}