From 3c5d9c0f94aef0b0773e75acd97d40c981998f33 Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Wed, 8 Apr 2026 20:04:24 +0200 Subject: [PATCH] fix: auto-generation PDF a la creation echeancier + bouton regenerer - create() genere le PDF automatiquement apres creation - Extraction generateEcheancierPdf() methode privee reutilisable - Bouton "Regenerer PDF" (jaune) si PDF existe, "Generer PDF" sinon - Bouton visible dans tous les etats sauf cancelled/completed - Redirect vers show apres creation (au lieu de l'onglet client) Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Controller/Admin/EcheancierController.php | 22 +++++++++++++------ templates/admin/echeancier/show.html.twig | 14 ++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Controller/Admin/EcheancierController.php b/src/Controller/Admin/EcheancierController.php index 9210fe9..d7812b3 100644 --- a/src/Controller/Admin/EcheancierController.php +++ b/src/Controller/Admin/EcheancierController.php @@ -32,7 +32,7 @@ class EcheancierController extends AbstractController } #[Route('/create/{customerId}', name: 'create', requirements: ['customerId' => '\d+'], methods: ['POST'])] - public function create(int $customerId, Request $request): Response + public function create(int $customerId, Request $request, KernelInterface $kernel): Response { $customer = $this->em->getRepository(Customer::class)->find($customerId); if (null === $customer) { @@ -76,9 +76,12 @@ class EcheancierController extends AbstractController $this->em->persist($echeancier); $this->em->flush(); - $this->addFlash('success', 'Echeancier cree avec '.$nbEcheances.' echeances de '.$monthlyAmount.' EUR/mois.'); + // Generer le PDF automatiquement + $this->generateEcheancierPdf($echeancier, $kernel); - return $this->redirectToRoute('app_admin_clients_show', ['id' => $customerId, 'tab' => 'echeancier']); + $this->addFlash('success', 'Echeancier cree avec '.$nbEcheances.' echeances de '.$monthlyAmount.' EUR/mois. PDF genere.'); + + return $this->redirectToRoute('app_admin_echeancier_show', ['id' => $echeancier->getId()]); } #[Route('/{id}', name: 'show', requirements: ['id' => '\d+'])] @@ -183,6 +186,15 @@ class EcheancierController extends AbstractController throw $this->createNotFoundException(self::MSG_NOT_FOUND); } + $this->generateEcheancierPdf($echeancier, $kernel); + + $this->addFlash('success', 'PDF echeancier '.($echeancier->getPdfUnsigned() ? 'regenere' : 'genere').'.'); + + return $this->redirectToRoute('app_admin_echeancier_show', ['id' => $id]); + } + + private function generateEcheancierPdf(Echeancier $echeancier, KernelInterface $kernel): void + { $pdf = new EcheancierPdf($kernel, $echeancier); $pdf->generate(); @@ -200,10 +212,6 @@ class EcheancierController extends AbstractController $this->em->flush(); @unlink($tmpPath); - - $this->addFlash('success', 'PDF echeancier genere.'); - - return $this->redirectToRoute('app_admin_echeancier_show', ['id' => $id]); } /** diff --git a/templates/admin/echeancier/show.html.twig b/templates/admin/echeancier/show.html.twig index c689050..8b0f56e 100644 --- a/templates/admin/echeancier/show.html.twig +++ b/templates/admin/echeancier/show.html.twig @@ -67,10 +67,16 @@ {# Actions #}
- {% if echeancier.state == 'draft' %} -
- -
+ {% if echeancier.state not in ['cancelled', 'completed'] %} + {% if echeancier.pdfUnsigned %} +
+ +
+ {% else %} +
+ +
+ {% endif %} {% endif %} {% if echeancier.pdfUnsigned %}