src/Controller/PrestationController.php line 321

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Prestation;
  4. use App\Form\PrestationType;
  5. use App\Repository\PrestationRepository;
  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. use \Knp\Component\Pager\PaginatorInterface;
  11. use \App\Services\AppSevices;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. /**
  14.  * @Route("/user/prestation")
  15.  */
  16. class PrestationController extends AbstractController {
  17.     
  18.     /**
  19.      * @Route("/prestation/vue-cga", name="prestation_vue_cga")
  20.      */
  21.     public function vuePrestationCga(EntityManagerInterface $em): Response
  22.     {
  23.         $conn $em->getConnection();
  24.         $sql "SELECT * FROM vue_prestation_cga";
  25.         $stmt $conn->prepare($sql);
  26.         $resultSet $stmt->executeQuery();
  27.         $rows $resultSet->fetchAllAssociative();
  28.    
  29.         return $this->render('prestation/vue_cga.html.twig', [
  30.             'prestations' => $rows,
  31.         ]);
  32.     }
  33.     
  34.     /**
  35.      * @Route("/Admin/", name="app_prestation_index", methods={"GET"})
  36.      */
  37.     public function index(Request $requestPaginatorInterface $paginatorAppSevices $services): Response {
  38.         $annee $services->getAnneExercice(['sort' => 'u.annee'"order" => "desc"])->setMaxResults(1)->getQuery()->getOneOrNullResult();
  39.         $etat = ($request->query->get('etat')) == "" "all" $request->get('etat');
  40.         $anne = ($request->query->get('anne')) == "" $annee->getId() : $request->get('anne');
  41.         $type = ($request->query->get('type')) == "" "all" $request->get('type');
  42.         $adherent = ($request->query->get('adherent')) == "" "all" $request->get('adherent');
  43.         $prestations $services->getPrestations(array("etat" => $etat"anne" => $anne"type" => $type"adherent" => $adherent))->getQuery()->getResult();
  44.         return $this->render('prestation/index.html.twig', [
  45.                     'prestations' => $prestations,
  46.         ]);
  47.     }
  48.     /**
  49.      * @Route("/{id}/{type}/new", name="app_prestation_new", methods={"GET", "POST"})
  50.      * @Route("/{id}/Admin/edit", name="app_prestation_edit", methods={"GET", "POST"})
  51.      */
  52.     public function new(Request $request$type null$id, \App\Services\AppSevices $servicePrestationRepository $prestationRepository, \App\Repository\EnfantRepository $enfantRepositoryPrestation $prestation null): Response {
  53.         if (!$prestation) {
  54.             $prestation = new Prestation();
  55.         }
  56.         if ($type && $type == 'en') {
  57.             $enfant $enfantRepository->find($id);
  58.             $adr $enfant->getAdherent();
  59.             $prestation->setEnfant($enfant);
  60.         } else {
  61.             $adr $service->getAdherents(['id' => $id])->getQuery()->getOneOrNullResult();
  62.         }
  63.         if (!$prestation->getAdherent()) {
  64.             $prestation->setAdherent($adr);
  65.             $prestation->setEtat('Cour');
  66.             $prestation->setDateInsertion(new \DateTime());
  67.         }
  68.         $form $this->createForm(PrestationType::class, $prestation);
  69.         $form->handleRequest($request);
  70.         if ($form->isSubmitted() && $form->isValid()) {
  71.    if ($prestation->getMontantMois() && $prestation->getValeur()) {
  72.                 $this->addFlash(
  73.                         'danger',
  74.                         'Vous devez saisir soit le montant par mois, soit le montant global'
  75.                 );
  76.                 return $this->renderForm('prestation/new.html.twig', [
  77.                             'prestation' => $prestation,
  78.                             'form' => $form,
  79.                             'id' => $id
  80.                             'type' => $type
  81.                 ]);
  82.             }
  83.              if ($prestation->getMontantMois() && !$prestation->getNbMois()) {
  84.                 $this->addFlash(
  85.                         'danger',
  86.                         'Vous devez saisir le nbr mois'
  87.                 );
  88.                 return $this->renderForm('prestation/new.html.twig', [
  89.                             'prestation' => $prestation,
  90.                             'form' => $form,
  91.                             'id' => $id
  92.                             'type' => $type
  93.                 ]);
  94.             }
  95.              if ($prestation->getTypePrestation()->getPerodisite() == "1" && !$prestation->getValeur()) {
  96.                   $this->addFlash(
  97.                         'danger',
  98.                         'Vous devez saisir le montant global et non pas le montant par mois.'
  99.                 );
  100.                 return $this->renderForm('prestation/new.html.twig', [
  101.                             'prestation' => $prestation,
  102.                             'form' => $form,
  103.                             'id' => $id
  104.                             'type' => $type
  105.                 ]);
  106.              }
  107.               if ($prestation->getTypePrestation()->getPerodisite() == "1" && $prestation->getNbMois()) {
  108.                   $this->addFlash(
  109.                         'danger',
  110.                         'Vous ne devez pas saisir le nombre de mois'
  111.                 );
  112.                 return $this->renderForm('prestation/new.html.twig', [
  113.                             'prestation' => $prestation,
  114.                             'form' => $form,
  115.                             'id' => $id
  116.                             'type' => $type
  117.                 ]);
  118.              }
  119.  //if(count($form['documents'])<1){
  120.    //               $this->addFlash(
  121.      //                       'danger',
  122.        //                     'vous devez ajouter au moins un document'
  123.          //           );
  124.            //          return $this->renderForm('prestation/new.html.twig', [
  125.              //                   'prestation' => $prestation,
  126.                //                 'form' => $form,
  127.                  //               'id' => $id
  128.                    //             , 'type' => $type
  129.                     //]);
  130.                 //}
  131.             $e null;
  132.             if ($prestation->getEnfant()) {
  133.                 $e $prestation->getEnfant()->getId();
  134.                 if ($prestation->getTypePrestation()->getId() == 13 && $prestation->getEnfant()->getClassEtude()) {
  135.                     $prestation->setValeur($prestation->getEnfant()->getClassEtude()->getMotantInscription());
  136.                 } elseif ($prestation->getTypePrestation()->getId() == 14 && $prestation->getEnfant()->getClassEtude()) {
  137.                     $prestation->setValeur($prestation->getEnfant()->getClassEtude()->getMontantReuissite());
  138.                 }
  139.                 else if($prestation->getTypePrestation()->getId() != 11) {
  140.                     $this->addFlash(
  141.                             'danger',
  142.                             'ce type de prestation ne correspond pas aux enfant'
  143.                     );
  144.                     return $this->renderForm('prestation/new.html.twig', [
  145.                                 'prestation' => $prestation,
  146.                                 'form' => $form,
  147.                                 'id' => $id
  148.                                 'type' => $type
  149.                     ]);
  150.                 }
  151.             }
  152.             if ($prestation->getTypePrestation()->getId() == 13 
  153.             || $prestation->getTypePrestation()->getId() == 14 
  154.             || $prestation->getTypePrestation()->getId()==11) {
  155.                 if (!$prestation->getEnfant()) {
  156.                     $this->addFlash(
  157.                             'danger',
  158.                             'pour bénéficier de cette prestation vous devez avoir un enfant '
  159.                     );
  160.                     return $this->renderForm('prestation/new.html.twig', [
  161.                                 'prestation' => $prestation,
  162.                                 'form' => $form,
  163.                                 'id' => $id,
  164.                                 'type' => $type
  165.                     ]);
  166.                 }
  167.             }
  168.             if ($prestation->getTypePrestation()->getTaux() || 
  169.             $prestation->getTypePrestation()->getTaux() != 0) {
  170.                 if ($prestation->getMontantMois())
  171.                     $val $prestation->getTypePrestation()->getTaux() * $prestation->getMontantMois();
  172.                 else
  173.                     $val $prestation->getTypePrestation()->getTaux() * $prestation->getValeur();
  174.             } else {
  175.                  if ($prestation->getMontantMois())
  176.                        $val $prestation->getMontantMois();
  177.                      else 
  178.                 $val $prestation->getValeur();
  179.             }
  180.             if ($prestation->getTypePrestation()->getValeutMax()) {
  181.                 if ($prestation->getTypePrestation()->getValeutMax() > $val) {
  182.                     $prestation->setValeurPayer($val);
  183.                 } else {
  184.                     $prestation->setValeurPayer($prestation->getTypePrestation()->getValeutMax());
  185.                 }
  186.             } else {
  187.                 $prestation->setValeurPayer($val);
  188.             }
  189.             foreach ($prestation->getDocuments() as $d) {
  190.                 $prestation->removeDocument($d);
  191.             }
  192.             if ($prestation->getTypePrestation()->getPerodisite() == "2" && $prestation->getNbMois()) {
  193.                 $prestation->setValeurPayer($prestation->getValeurPayer() * $prestation->getNbMois());
  194.                 $prestation->setValeur($prestation->getMontantMois() * $prestation->getNbMois());
  195.             }
  196.            $per $service->getPrestations(['id' => $prestation->getId()])->setMaxResults(1)->getQuery()->getOneOrNullResult();
  197.             if ($per) {
  198.                 $plafon = ($service->getAnneExercice(['anne' => $prestation->getAnneeExercice()->getAnnee()])->setMaxResults(1)->getQuery()->getOneOrNullResult()->getPalafon()) - $service->getSumPrestation(['idp'=>$prestation->getId(),'id' => $prestation->getAdherent()->getId(), 'anne' => $prestation->getAnneeExercice()->getId(), 'etat' => 'Total']);
  199.             } else {
  200.                 $plafon $service->getAnneExercice(['anne' => $prestation->getAnneeExercice()->getAnnee()])->setMaxResults(1)->getQuery()->getOneOrNullResult()->getPalafon() - $service->getSumPrestation(['id' => $prestation->getAdherent()->getId(), 'anne' => $prestation->getAnneeExercice()->getId(), 'etat' => 'Total']);
  201.             }
  202.             $prestationVoyage $service->getPrestations(["anne" => $prestation->getAnneeExercice()->getId(),
  203.                         'adherent' => $prestation->getAdherent()->getId(),
  204.                         'type' => '9',
  205.                     ])->getQuery()->getResult();
  206.             if (count($prestationVoyage) > 0) {
  207.                 $plafon $plafon 500;
  208.             }
  209.             if ($prestation->getId()) {
  210.                 $presUpdate $service->getPrestations(['id' => $prestation->getId()])->setMaxResults(1)->getQuery()->getOneOrNullResult();
  211.                
  212.             }
  213.             if ($prestation->getTypePrestation()->isPalfont() === true) {
  214.                 if ($plafon <= 0) {
  215.                     $this->addFlash(
  216.                             'danger',
  217.                             'Votre palfond=0'
  218.                     );
  219.                     return $this->renderForm('prestation/new.html.twig', [
  220.                                 'prestation' => $prestation,
  221.                                 'form' => $form,
  222.                                 'id' => $id,
  223.                                 'type' => $type
  224.                     ]);
  225.                 } elseif ($prestation->getValeurPayer() > $plafon) {
  226.                     $prestation->setValeurPayer($plafon);
  227.                 }
  228.                 $this->addFlash('success',
  229.                         'Vous aveez ajoutez une prestation'
  230.                 );
  231.                 foreach ($form['documents'] as $value) {
  232.                     $document $value->getData();
  233.                     $prestation->addDocument($document);
  234.                 }
  235.                 $prestationRepository->add($prestationtrue);
  236.             } else {
  237.                 foreach ($form['documents'] as $value) {
  238.                     $document $value->getData();
  239.                     $prestation->addDocument($document);
  240.                 }
  241.                 $this->addFlash(
  242.                         'success',
  243.                         'Vous aveez ajoutez une prestation'
  244.                 );
  245.                 $prestationRepository->add($prestationtrue);
  246.             }
  247.             return $this->redirectToRoute('app_adherent_show', ['id' => $prestation->getAdherent()->getId()], Response::HTTP_SEE_OTHER);
  248.         }
  249.         return $this->renderForm('prestation/new.html.twig', [
  250.                     'prestation' => $prestation,
  251.                     'form' => $form,
  252.                     'id' => $id,
  253.                     'type' => $type
  254.         ]);
  255.     }
  256.     public function creaDir($prestation) {
  257.         $dir $this->getParameter('brochures_directory') . '/' $prestation->getAdherent()->getNom() . '-' $prestation->getAdherent()->getNumeroAdhesion();
  258.         if (!is_dir($dir)) {
  259.             mkdir($dir0700);
  260.         }
  261.         $dir $this->getParameter('brochures_directory') . '/' $prestation->getAdherent()->getNom() . '-' $prestation->getAdherent()->getNumeroAdhesion() . '/' $prestation->getTypePrestation()->getLib();
  262.         if (!is_dir($dir)) {
  263.             mkdir($dir0700);
  264.         }
  265.         return($dir);
  266.     }
  267.     /**
  268.      * @Route("/{id}", name="app_prestation_show", methods={"GET"})
  269.      */
  270.     public function show(Prestation $prestation): Response {
  271.         return $this->render('prestation/show.html.twig', [
  272.                     'prestation' => $prestation,
  273.         ]);
  274.     }
  275. //    /**
  276. //     * @Route("/{id}/edit", name="app_prestation_edit", methods={"GET", "POST"})
  277. //     */
  278. //    public function edit(Request $request, Prestation $prestation, PrestationRepository $prestationRepository): Response {
  279. //        $form = $this->createForm(PrestationType::class, $prestation);
  280. //        $form->handleRequest($request);
  281. //
  282. //        if ($form->isSubmitted() && $form->isValid()) {
  283. //            $prestationRepository->add($prestation, true);
  284. //
  285. //            return $this->redirectToRoute('app_prestation_index', [], Response::HTTP_SEE_OTHER);
  286. //        }
  287. //
  288. //        return $this->renderForm('prestation/edit.html.twig', [
  289. //                    'prestation' => $prestation,
  290. //                    'form' => $form,
  291. //        ]);
  292. //    }
  293.     /**
  294.      * @Route("/{id}/{etat}/Admin/edit_Etat", name="app_prestation_edit_etat", methods={"GET", "POST"})
  295.      */
  296.     public function editEtat($id$etatPrestationRepository $prestationRepositoryAppSevices $service): Response {
  297.         $prestation $service->getPrestations(['id' => $id])->getQuery()->getOneOrNullResult();
  298.         $prestation->setEtat($etat);
  299.         $prestationRepository->add($prestationtrue);
  300.         return $this->redirectToRoute('app_adherent_show', ['id' => $prestation->getAdherent()->getId()], Response::HTTP_SEE_OTHER);
  301.     }
  302.     /**
  303.      * @Route("/{id}", name="app_prestation_delete", methods={"POST"})
  304.      */
  305.     public function delete(Request $requestPrestation $prestationPrestationRepository $prestationRepository): Response {
  306.         if ($this->isCsrfTokenValid('delete' $prestation->getId(), $request->request->get('_token'))) {
  307.             $prestationRepository->remove($prestationtrue);
  308.         }
  309.         return $this->redirectToRoute('app_prestation_index', [], Response::HTTP_SEE_OTHER);
  310.     }
  311. }