src/Controller/Admin/MatierePremiereAgricole/QuotationController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin\MatierePremiereAgricole;
  3. use App\Entity\Quotation;
  4. use App\Form\QuotationType;
  5. use App\Repository\QuotationRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/bscm/admin/gestion/quotation", name="app_admin_gestion_quotation_")
  12.  */
  13. class QuotationController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("s", name="index", methods={"GET"})
  17.      */
  18.     public function index(QuotationRepository $quotationRepository): Response
  19.     {
  20.         return $this->render('admin/quotation/index.html.twig', [
  21.             'quotations' => $quotationRepository->findBy([],['date_saisie'=>'DESC']),
  22.             'countCotation'=>$quotationRepository->countCotation(),
  23.         ]);
  24.     }
  25.     /**
  26.      * @Route("/new", name="new", methods={"GET","POST"})
  27.      */
  28.     public function new(Request $request): Response
  29.     {
  30.         $quotation = new Quotation();
  31.         $form $this->createForm(QuotationType::class, $quotation);
  32.         $form->handleRequest($request);
  33.         if ($form->isSubmitted() && $form->isValid()) {
  34.             $entityManager $this->getDoctrine()->getManager();
  35.             $entityManager->persist($quotation);
  36.             $entityManager->flush();
  37.             return $this->redirectToRoute('app_admin_gestion_quotation_index');
  38.         }
  39.         return $this->render('admin/quotation/new.html.twig', [
  40.             'quotation' => $quotation,
  41.             'form' => $form->createView(),
  42.         ]);
  43.     }
  44.     /**
  45.      * @Route("/{id}/show", name="show", methods={"GET"})
  46.      */
  47.     public function show(Quotation $quotation): Response
  48.     {
  49.         return $this->render('admin/quotation/cotation.html.twig', [
  50.             'quotation' => $quotation,
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/{id}/edit", name="edit", methods={"GET","POST"})
  55.      *
  56.      */
  57.     public function edit(Request $requestQuotation $quotation): Response
  58.     {
  59.         $form $this->createForm(QuotationType::class, $quotation);
  60.         $form->handleRequest($request);
  61.         if ($form->isSubmitted() && $form->isValid()) {
  62.             $this->getDoctrine()->getManager()->flush();
  63.             $this->addFlash('success','Enregistrement fait avec succès.');
  64.             return $this->redirectToRoute('app_admin_gestion_quotation_new');
  65.         }
  66.         return $this->render('admin/quotation/edit.html.twig', [
  67.             'quotation' => $quotation,
  68.             'form' => $form->createView(),
  69.         ]);
  70.     }
  71.     /**
  72.      * @Route("/{id}", name="delete", methods={"DELETE"})
  73.      */
  74.     public function delete(Request $requestQuotation $quotation): Response
  75.     {
  76.         if ($this->isCsrfTokenValid('delete'.$quotation->getId(), $request->request->get('_token'))) {
  77.             $entityManager $this->getDoctrine()->getManager();
  78.             $entityManager->remove($quotation);
  79.             $entityManager->flush();
  80.         }
  81.         return $this->redirectToRoute('app_admin_gestion_quotation_index');
  82.     }
  83.     /**
  84.      * @Route("s/a_suivre", name="a_suivre", methods={"GET"})
  85.      */
  86.     public function aSuivre(QuotationRepository $quotationRepository): Response
  87.     {
  88.         return $this->render('admin/quotation/index.html.twig', [
  89.             'quotations' => $quotationRepository->findBy(['status'=>'A suivre'],['date_saisie'=>'DESC']),
  90.             'countCotation'=>$quotationRepository->cotationByStatus('A suivre')
  91.         ]);
  92.     }
  93.     /**
  94.      * @Route("s/echu-non-echues", name="non_echues", methods={"GET"})
  95.      */
  96.     public function nonEchu(QuotationRepository $quotationRepository): Response
  97.     {
  98.         $quotations $quotationRepository->getByDifferentStatus();
  99.         $countCotation =count($quotations);
  100.         return $this->render('admin/quotation/index.html.twig'compact(['quotations','countCotation']));
  101.     }
  102. }