<?php
namespace App\Controller\Admin\MatierePremiereAgricole;
use App\Entity\Quotation;
use App\Form\QuotationType;
use App\Repository\QuotationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/bscm/admin/gestion/quotation", name="app_admin_gestion_quotation_")
*/
class QuotationController extends AbstractController
{
/**
* @Route("s", name="index", methods={"GET"})
*/
public function index(QuotationRepository $quotationRepository): Response
{
return $this->render('admin/quotation/index.html.twig', [
'quotations' => $quotationRepository->findBy([],['date_saisie'=>'DESC']),
'countCotation'=>$quotationRepository->countCotation(),
]);
}
/**
* @Route("/new", name="new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$quotation = new Quotation();
$form = $this->createForm(QuotationType::class, $quotation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($quotation);
$entityManager->flush();
return $this->redirectToRoute('app_admin_gestion_quotation_index');
}
return $this->render('admin/quotation/new.html.twig', [
'quotation' => $quotation,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}/show", name="show", methods={"GET"})
*/
public function show(Quotation $quotation): Response
{
return $this->render('admin/quotation/cotation.html.twig', [
'quotation' => $quotation,
]);
}
/**
* @Route("/{id}/edit", name="edit", methods={"GET","POST"})
*
*/
public function edit(Request $request, Quotation $quotation): Response
{
$form = $this->createForm(QuotationType::class, $quotation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success','Enregistrement fait avec succès.');
return $this->redirectToRoute('app_admin_gestion_quotation_new');
}
return $this->render('admin/quotation/edit.html.twig', [
'quotation' => $quotation,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="delete", methods={"DELETE"})
*/
public function delete(Request $request, Quotation $quotation): Response
{
if ($this->isCsrfTokenValid('delete'.$quotation->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($quotation);
$entityManager->flush();
}
return $this->redirectToRoute('app_admin_gestion_quotation_index');
}
/**
* @Route("s/a_suivre", name="a_suivre", methods={"GET"})
*/
public function aSuivre(QuotationRepository $quotationRepository): Response
{
return $this->render('admin/quotation/index.html.twig', [
'quotations' => $quotationRepository->findBy(['status'=>'A suivre'],['date_saisie'=>'DESC']),
'countCotation'=>$quotationRepository->cotationByStatus('A suivre')
]);
}
/**
* @Route("s/echu-non-echues", name="non_echues", methods={"GET"})
*/
public function nonEchu(QuotationRepository $quotationRepository): Response
{
$quotations = $quotationRepository->getByDifferentStatus();
$countCotation =count($quotations);
return $this->render('admin/quotation/index.html.twig', compact(['quotations','countCotation']));
}
}