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) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-08 20:04:24 +02:00
parent 46ddb5786a
commit 3c5d9c0f94
2 changed files with 25 additions and 11 deletions

View File

@@ -32,7 +32,7 @@ class EcheancierController extends AbstractController
} }
#[Route('/create/{customerId}', name: 'create', requirements: ['customerId' => '\d+'], methods: ['POST'])] #[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); $customer = $this->em->getRepository(Customer::class)->find($customerId);
if (null === $customer) { if (null === $customer) {
@@ -76,9 +76,12 @@ class EcheancierController extends AbstractController
$this->em->persist($echeancier); $this->em->persist($echeancier);
$this->em->flush(); $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+'])] #[Route('/{id}', name: 'show', requirements: ['id' => '\d+'])]
@@ -183,6 +186,15 @@ class EcheancierController extends AbstractController
throw $this->createNotFoundException(self::MSG_NOT_FOUND); 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 = new EcheancierPdf($kernel, $echeancier);
$pdf->generate(); $pdf->generate();
@@ -200,10 +212,6 @@ class EcheancierController extends AbstractController
$this->em->flush(); $this->em->flush();
@unlink($tmpPath); @unlink($tmpPath);
$this->addFlash('success', 'PDF echeancier genere.');
return $this->redirectToRoute('app_admin_echeancier_show', ['id' => $id]);
} }
/** /**

View File

@@ -67,10 +67,16 @@
{# Actions #} {# Actions #}
<div class="flex flex-wrap gap-2 mb-6"> <div class="flex flex-wrap gap-2 mb-6">
{% if echeancier.state == 'draft' %} {% if echeancier.state not in ['cancelled', 'completed'] %}
<form method="post" action="{{ path('app_admin_echeancier_generate_pdf', {id: echeancier.id}) }}"> {% if echeancier.pdfUnsigned %}
<button type="submit" class="px-4 py-2 bg-gray-900 text-white font-bold uppercase text-[10px] tracking-wider hover:bg-[#fabf04] hover:text-gray-900 transition-all">Generer PDF</button> <form method="post" action="{{ path('app_admin_echeancier_generate_pdf', {id: echeancier.id}) }}" data-confirm="Regenerer le PDF ? Le fichier existant sera remplace.">
</form> <button type="submit" class="px-4 py-2 bg-yellow-500/20 text-yellow-700 hover:bg-yellow-500 hover:text-white font-bold uppercase text-[10px] tracking-wider transition-all">Regenerer PDF</button>
</form>
{% else %}
<form method="post" action="{{ path('app_admin_echeancier_generate_pdf', {id: echeancier.id}) }}">
<button type="submit" class="px-4 py-2 bg-gray-900 text-white font-bold uppercase text-[10px] tracking-wider hover:bg-[#fabf04] hover:text-gray-900 transition-all">Generer PDF</button>
</form>
{% endif %}
{% endif %} {% endif %}
{% if echeancier.pdfUnsigned %} {% if echeancier.pdfUnsigned %}
<a href="{{ vich_uploader_asset(echeancier, 'pdfUnsignedFile') }}" target="_blank" <a href="{{ vich_uploader_asset(echeancier, 'pdfUnsignedFile') }}" target="_blank"