faafd99ef8
Auto Tag Develop / tag (push) Successful in 8s
MR unique regroupant tout le module M5 « Tickets de pesée » (remplace les MR empilées #140/#141/#142/#143).
## Périmètre
- **ERP-188** — Page liste des tickets de pesée + export XLSX (colonnes Fournisseur/Client/Autre + Statut).
- **ERP-189** — Écran « Ajouter » (4 champs en haut, 2 blocs de pesée, pesée bascule/manuelle, date+heure horodatée à la validation).
- **ERP-190** — Écran « Modifier » + bouton Imprimer.
- **ERP-191** — i18n + libellés + branchement site courant.
- **ERP-192** — Bon de pesée PDF généré côté back (template Twig → Dompdf), endpoint `GET /api/weighing_tickets/{id}/print.pdf`.
- **ERP-193** — Cycle de vie brouillon/validé (status DRAFT/VALIDATED, numéro attribué à la validation), DSD saisi conservé en pesée manuelle, retours métier design.
## Vérifications
- Back : tests Logistique + architecture verts, php-cs-fixer propre, migrations appliquées (dev + test).
- Front : suite Vitest complète verte, ESLint propre.
Base : `develop` — contient les 16 commits du M5 (rien d'autre).
Reviewed-on: #144
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
76 lines
2.5 KiB
PHP
76 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Module\Logistique\Infrastructure\Pdf;
|
|
|
|
use App\Module\Logistique\Domain\Entity\WeighingTicket;
|
|
use Dompdf\Dompdf;
|
|
use Dompdf\Options;
|
|
use Twig\Environment;
|
|
|
|
/**
|
|
* Rend le ticket de pesee (M5, spec-back § 2.12 / § 4.6 — RG-5.08) : hydrate le
|
|
* template Twig `logistique/weighing_ticket_print.html.twig` avec le ticket, puis
|
|
* convertit le HTML en PDF via Dompdf (pur PHP, aucune dependance systeme — choix
|
|
* valide avec Matthieu, ERP-192).
|
|
*
|
|
* Le gabarit reproduit le modele fourni (ticket_pesee.pdf) : en-tete FIXE (logo +
|
|
* identite societe), titre, les deux pesees (poids / N° pesee / DSD + date) et le
|
|
* poids net. Le rendu ne depend PAS du site (decision Tristan, ERP-192) : le logo
|
|
* et l'identite societe sont constants.
|
|
*
|
|
* Service technique d'infrastructure (pas de logique metier) : le contenu/affiche
|
|
* est decide par le template ; ICI on ne fait que charger le logo et generer le
|
|
* binaire.
|
|
*/
|
|
final class WeighingTicketPdfRenderer
|
|
{
|
|
/** Logo societe embarque dans l'en-tete (fixe, hors versioning par site). */
|
|
private const string LOGO_PATH = __DIR__.'/assets/logo-lpc-liot.png';
|
|
|
|
public function __construct(
|
|
private readonly Environment $twig,
|
|
) {}
|
|
|
|
/**
|
|
* Genere le binaire PDF du ticket de pesee pour un ticket donne.
|
|
*
|
|
* Dompdf : remote desactive (aucune ressource externe chargee — securite ; le
|
|
* logo passe en data-URI), A4 portrait, police par defaut DejaVu Sans (UTF-8
|
|
* -> accents FR et « ° » corrects).
|
|
*/
|
|
public function render(WeighingTicket $ticket): string
|
|
{
|
|
$html = $this->twig->render('logistique/weighing_ticket_print.html.twig', [
|
|
'ticket' => $ticket,
|
|
'logoSrc' => $this->logoDataUri(),
|
|
]);
|
|
|
|
$options = new Options();
|
|
$options->set('isRemoteEnabled', false);
|
|
$options->set('defaultFont', 'DejaVu Sans');
|
|
|
|
$dompdf = new Dompdf($options);
|
|
$dompdf->loadHtml($html, 'UTF-8');
|
|
$dompdf->setPaper('A4', 'portrait');
|
|
$dompdf->render();
|
|
|
|
return (string) $dompdf->output();
|
|
}
|
|
|
|
/**
|
|
* Logo societe encode en data-URI base64, ou null s'il est introuvable (le
|
|
* template degrade alors sans bloquer la generation du PDF).
|
|
*/
|
|
private function logoDataUri(): ?string
|
|
{
|
|
$binary = @file_get_contents(self::LOGO_PATH);
|
|
if (false === $binary) {
|
|
return null;
|
|
}
|
|
|
|
return 'data:image/png;base64,'.base64_encode($binary);
|
|
}
|
|
}
|