src/Controller/HomeController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Repository\DealRepository;
  7. use App\Repository\SoustraitantRepository;
  8. use App\Repository\ContratRepository;
  9. use App\Repository\InstallateurRepository;
  10. use App\Repository\ObligesRepository;
  11. use App\Repository\DepotDossierRepository;
  12. use App\Repository\UserRepository;
  13. use App\Repository\NotificationsRepository;
  14. use App\Repository\EquipeRepository;
  15. use Doctrine\Common\Collections\Collection;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use DateTime;
  18. use App\Entity\Notifications;
  19. class HomeController extends AbstractController
  20. {
  21.   
  22.     /**
  23.      * @Route("/", name="app_home")
  24.      */
  25.     public function index(DealRepository $dealRepositoryContratRepository $contratRepositoryInstallateurRepository $installateurRepositorySoustraitantRepository $soustraitantRepositoryDepotDossierRepository $depotDossierRepository,
  26.     NotificationsRepository $notificationsRepository,EquipeRepository $equipeRepository,ObligesRepository $obligesRepository): Response
  27.     {   
  28.         
  29.         if (!$this->getUser()) {
  30.             return $this->redirectToRoute('app_login');
  31.         }
  32.         $isCompleted "oui";
  33.         $champsinstallateurexpire=[];
  34.         $champsdealexpire=[];
  35.         $cumacaafcour=0;
  36.         $cumacEnAttente=0;
  37.         $cumacnonvalide=0;
  38.         $cumacnouveau=0;
  39.         $cumacurgent=0;
  40.         $cumacvalide=0;
  41.         $cumacpayeraaf=0;
  42.         $cumacpretdepot=0;
  43.         $equipes=[];
  44.         $dossiercontroler=[];
  45.         $obligedeal=[];
  46.         $oblige $obligesRepository->findAll();
  47.        
  48.         foreach ($obligesRepository->findAll() as $key => $value) {
  49.             $dealcal=[];
  50.             foreach ($dealRepository->findAll() as $key => $deal) {
  51.                 if ($deal->getDealoblige()->getOblige()->getId() == $value->getId()) {
  52.                     $dealcal[]=$deal->getDealoblige()->getOblige()->getSociete();
  53.                 }
  54.                
  55.             }
  56.             
  57.             // $uniqueElements = array_unique($dealcal);
  58.             $lengthWithoutDuplicates count($dealcal);
  59.             $obligedeal[]=$value->getSociete().'-'.$lengthWithoutDuplicates;
  60.         }
  61.        
  62.         foreach ($equipeRepository->findBy(["role"=>"ROLE_CONTROLER"]) as $key => $value) {
  63.             $equipes[]=$value;
  64.             $dossiercal=[];
  65.             foreach ($value->getCommentairesControlles() as $key => $control) {
  66.                 $dossiercal[]=$control->getDossier()->getId();
  67.             }
  68.             // if (count($dossiercal)>1) {
  69.             //     dd($dossiercal);
  70.             // }
  71.             
  72.             $uniqueElements array_unique($dossiercal);
  73.             $lengthWithoutDuplicates count($uniqueElements);
  74.             $dossiercontroler[]=$value->getPrenom().'-'.$lengthWithoutDuplicates;
  75.         }
  76.         //dd($dossiercontroler);
  77.         if ($this->isGranted('ROLE_INSTALLATEUR')){
  78.             
  79.             foreach ($this->getUser()->getInstallateur()->getChampsinstallateur() as $key => $champsinstallateur) {
  80.                 if ($champsinstallateur->getDurevalidite() != null and $champsinstallateur->getType() == "file" and $champsinstallateur->getDate() != null ) {
  81.                 
  82.                     $date $champsinstallateur->getDate(); // Date de départ
  83.                     $nombreDeMois $champsinstallateur->getDurevalidite(); // Nombre de mois à ajouter
  84.                     
  85.                     $date->modify("+$nombreDeMois month"); // Ajoute le nombre de mois spécifié
  86.                     
  87.                     $nouvelleDate $date->format('Y-m-d');
  88.                     $dateday = new DateTime();
  89.                     $dateday $dateday->format('Y-m-d');
  90.                     if ( $dateday $nouvelleDate ) {
  91.                        // dd($nouvelleDate);
  92.                         $champsinstallateurexpire[]=$champsinstallateur;
  93.                         
  94.                         $inst=$this->getUser()->getInstallateur();
  95.                         $inst->setStatus("En Attente");
  96.                         foreach ($inst->getDeals() as $key => $dl) {
  97.                             if ($dl->getStatus() == "Validé") {
  98.                                 $dl->setStatus("En Attente");
  99.                                 $dealRepository->add($dltrue);
  100.                             }
  101.                         }
  102.                         $installateurRepository->add($insttrue);
  103.                     }
  104.                   
  105.                 }
  106.                 
  107.             }
  108.             $dossierAll=[];
  109.             $j=1;
  110.         
  111.             foreach ($this->getUser()->getInstallateur()->getDeals() as  $deal) {
  112.                
  113.                 foreach ($deal->getChampsdeal() as $key => $champsdeal) {
  114.                     if ($champsdeal->getDurevalidite() != null and $champsdeal->getType() == "file" and $champsdeal->getDate() != null ) {
  115.                 
  116.                         $date $champsdeal->getDate(); // Date de départ
  117.                         $nombreDeMois $champsdeal->getDurevalidite(); // Nombre de mois à ajouter
  118.                         
  119.                         $date->modify("+$nombreDeMois month"); // Ajoute le nombre de mois spécifié
  120.                         
  121.                         $nouvelleDate $date->format('Y-m-d');
  122.                         $dateday = new DateTime();
  123.                         $dateday $dateday->format('Y-m-d');
  124.                         if ( $dateday $nouvelleDate ) {
  125.                            // dd($nouvelleDate);
  126.                            $champsdealexpire[]=$champsdealexpire;
  127.                           
  128.                            $deal->setStatus("En Attente");
  129.                            $dealRepository->add($dealtrue);
  130.                         }
  131.                       
  132.                     }
  133.                     
  134.                 }
  135.                 foreach ($depotDossierRepository->findBy(["deal"=>$deal]) as $dls) {
  136.                     foreach ($depotDossierRepository->findAll() as  $value) {
  137.                         
  138.                         
  139.                         if ($value->getId() == $dls->getId()) {
  140.                             if ($j<10) {
  141.                                 $dossierAll[]=$value;
  142.                             }
  143.                             $j $j 1;
  144.                             
  145.                         }
  146.                      }
  147.                 }
  148.                  
  149.                 
  150.             }
  151.             $dealAll $dealRepository->findBy(['installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  152.             $dealAllten =$dealRepository->findBy(['installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 8);
  153.             $installateur $installateurRepository->findOneBy(["id" => $this->getUser()->getInstallateur()->getId()]);
  154.             $dealsNew $dealRepository->findBy(['status' => 'Nouveau''installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  155.             $dealsValide $dealRepository->findBy(['status' => 'Validé''installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  156.             $dealsVerification $dealRepository->findBy(['status' => "En Attente"'installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  157.             $dealsBloquer $dealRepository->findBy(['status' => "Bloqué"'installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  158.             $dealscontratgenere $dealRepository->findBy(['status' => "Contrat généré"'installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  159.             $dealscontratsigne $dealRepository->findBy(['status' => "Contrat Signé"'installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  160.             
  161.             if($installateur->getNom() == null || $installateur->getPrenom() == null || $installateur->getSociete() == null || 
  162.             $installateur->getPhone() == null || $installateur->getEmail() == null || $installateur->getAdresse() == null ){
  163.                 $isCompleted "non";
  164.             }
  165.             foreach($installateur->getChampsinstallateur() as $key => $value){
  166.                 if($value->getType() !="file" && $value->getValeur() == null){
  167.                     $isCompleted "non";
  168.                 }
  169.                 if($value->getType() =="file" && $value->getStatus() == "Non Transmis"){
  170.                     $isCompleted "non";
  171.                 }
  172.             }
  173.             if(count($installateur->getOperationStandards()) < 1){
  174.                 $isCompleted "non";
  175.             }
  176.             $expirechampsinstallateur=0;
  177.             $btexpirechampsinstallateur=0;
  178.            foreach ($installateur->getChampsinstallateur() as $key => $champsinstallateur) {
  179.             
  180.                 if ($champsinstallateur->getStatus()=="Validé") {
  181.                  
  182.                      if ($champsinstallateur->getDurevalidite() > 0) {
  183.                       
  184.                        $dateday = new  DateTime();
  185.                        $dateday15 = new  DateTime("+15 days");
  186.                        if ($dateday $champsinstallateur->getDate()) {
  187.                         
  188.                         $expirechampsinstallateur$expirechampsinstallateur 1;
  189.                         
  190.                        }else{
  191.                         if ($dateday15 $champsinstallateur->getDate()) {
  192.                        
  193.                              $btexpirechampsinstallateur$btexpirechampsinstallateur 1;
  194.                            }
  195.                        }
  196.                       
  197.                      }
  198.                 }
  199.            }
  200.         //    if($expirechampsinstallateur > 0){
  201.         //     $notifications = new Notifications();
  202.         //     $notifications->setUserId($this->getUser());
  203.         //     $notifications->setMessage("Vous avez ".$expirechampsinstallateur." document(s) expiré.");
  204.         //     $notifications->setAction("app_installateur_edit");
  205.         //     $notifications->setActionId($installateur->getId());
  206.         //     $notifications->setSender($this->getUser());
  207.         //     $notifications->setStatuts("non lu");
  208.         //     $notifications->setDate(new DateTime());
  209.         //     $notificationsRepository->add($notifications, true);
  210.         //    }
  211.         //    if($btexpirechampsinstallateur > 0){
  212.         //     $notifications = new Notifications();
  213.         //     $notifications->setUserId($this->getUser());
  214.         //     $notifications->setMessage("Vous avez ".$btexpirechampsinstallateur." document(s) sur le point d'expirer.");
  215.         //     $notifications->setAction("app_installateur_edit");
  216.         //     $notifications->setActionId($installateur->getId());
  217.         //     $notifications->setSender($this->getUser());
  218.         //     $notifications->setStatuts("non lu");
  219.         //     $notifications->setDate(new DateTime());
  220.         //     $notificationsRepository->add($notifications, true);
  221.         //    }
  222.           
  223.         } else {
  224.             if ($this->isGranted('ROLE_CONTROLER') ) {
  225.                 $dossierAll=[];
  226.                 foreach ($depotDossierRepository->findBy(["controler1"=>$this->getUser()->getEquipe()],['id' => 'DESC'], 10) as $key => $value) {
  227.                     $dossierAll[]=$value;
  228.                 }
  229.                 foreach ($depotDossierRepository->findBy(["controler2"=>$this->getUser()->getEquipe()],['id' => 'DESC'], 10) as $key => $value) {
  230.                     $dossierAll[]=$value;
  231.                 }
  232.                
  233.             }elseif($this->isGranted('ROLE_CONTROLER')){
  234.                 $dossierAll=[];
  235.                 foreach ($depotDossierRepository->findBy(["controler1"=>$this->getUser()->getEquipe()],['id' => 'DESC'], 10) as $key => $value) {
  236.                     $dossierAll[]=$value;
  237.                 }
  238.                 
  239.                 foreach ($depotDossierRepository->findBy(["controler2"=>$this->getUser()->getEquipe()],['id' => 'DESC'], 10) as $key => $value) {
  240.                     $dossierAll[]=$value;
  241.                 }
  242.                 //dd($dossier);
  243.             }elseif($this->isGranted('ROLE_OBLIGE')){
  244.                 $dossierAll=[];
  245.                 foreach ($this->getUser()->getObliges()->getDeals() as  $deal) {
  246.                     foreach ($deal->getDepotDossiers() as  $value) {
  247.                         $dossierAll[]=$value;
  248.                     }
  249.                 }
  250.                
  251.             }
  252.             else{
  253.                 $dossierAll=$depotDossierRepository->findBy([], ['id' => 'DESC'], 10);
  254.                 
  255.                
  256.                foreach ($depotDossierRepository->findBy(['status' => 'Déposé / AAF en cours'], ['id' => 'DESC']) as $key => $value) {
  257.                 $cumacaafcour $cumacaafcour $value->getCumac();
  258.                }
  259.                foreach ($depotDossierRepository->findBy(['status' => 'En Attente'], ['id' => 'DESC']) as $key => $value) {
  260.                 $cumacEnAttente $cumacEnAttente $value->getCumac();
  261.                }
  262.                foreach ($depotDossierRepository->findBy(['status' => 'Non validé'], ['id' => 'DESC']) as $key => $value) {
  263.                 $cumacnonvalide $cumacnonvalide $value->getCumac();
  264.                }
  265.                foreach ($depotDossierRepository->findBy(['status' => 'Nouveau'], ['id' => 'DESC']) as $key => $value) {
  266.                 $cumacnouveau $cumacnouveau $value->getCumac();
  267.                }
  268.                foreach ($depotDossierRepository->findBy(['status' => 'Urgent'], ['id' => 'DESC']) as $key => $value) {
  269.                 $cumacurgent $cumacurgent $value->getCumac();
  270.                }
  271.                foreach ($depotDossierRepository->findBy(['status' => 'Validé'], ['id' => 'DESC']) as $key => $value) {
  272.                 $cumacvalide $cumacvalide $value->getCumac();
  273.                }
  274.                foreach ($depotDossierRepository->findBy(['status' => 'Payé sur AAF'], ['id' => 'DESC']) as $key => $value) {
  275.                 $cumacpayeraaf $cumacpayeraaf $value->getCumac();
  276.                }
  277.                foreach ($depotDossierRepository->findBy(['status' => 'Prêt pour dépôt'], ['id' => 'DESC']) as $key => $value) {
  278.                 $cumacpretdepot $cumacpretdepot $value->getCumac();
  279.                }
  280.                
  281.             }
  282.             
  283.             if($this->isGranted('ROLE_OBLIGE')){
  284.                 $dealAll $dealRepository->findBy(['oblige' => $this->getUser()->getObliges()->getId()], ['id' => 'DESC']);
  285.                 $dealAllten $dealRepository->findBy(['oblige' => $this->getUser()->getObliges()->getId()], ['id' => 'DESC'],8);
  286.                 $dealsNew=[];
  287.                 $dealsValide=[];
  288.                 $dealsVerification=[];
  289.                 $dealsBloquer=[];
  290.                 $dealscontratgenere=[];
  291.                 $dealscontratsigne=[];
  292.                 
  293.                 foreach ($dealAll as $value) {
  294.                    if ($value->getStatus() == "Nouveau") {
  295.                     $dealsNew[]=$value;
  296.                    }elseif($value->getStatus() == "Validé"){
  297.                     $dealsValide[]=$value;
  298.                    }elseif($value->getStatus() == "En Attente"){
  299.                     $dealsVerification[]=$value;
  300.                    }
  301.                    elseif($value->getStatus() == "Bloqué"){
  302.                     $dealsBloquer[]=$value;
  303.                    }
  304.                    elseif($value->getStatus() == "Contrat généré"){
  305.                     $dealscontratgenere[]=$value;
  306.                    }
  307.                    elseif($value->getStatus() == "Contrat Signé"){
  308.                     $dealscontratsigne[]=$value;
  309.                    }
  310.                    
  311.                    
  312.                 }
  313.                 
  314.             }
  315.             else{
  316.                 $dealAll $dealRepository->findBy([], ['id' => 'DESC']);
  317.                 $dealAllten $dealRepository->findBy([], ['id' => 'DESC'], 8);
  318.                 $dealsNew $dealRepository->findBy(['status' => 'Nouveau'], ['id' => 'DESC']);
  319.                 $dealsValide $dealRepository->findBy(['status' => 'Validé'], ['id' => 'DESC']);
  320.                 $dealsVerification $dealRepository->findBy(['status' => "En Attente"], ['id' => 'DESC']);
  321.                 $dealsBloquer $dealRepository->findBy(['status' => "Bloqué"], ['id' => 'DESC']);
  322.                 $dealscontratgenere $dealRepository->findBy(['status' => "Contrat généré"], ['id' => 'DESC']);
  323.                 $dealscontratsigne $dealRepository->findBy(['status' => "Contrat Signé"], ['id' => 'DESC']);
  324.             }
  325.            
  326.             $installateur = [];
  327.         }
  328.         $installateursAll=[];
  329.         foreach ($installateurRepository->findAll() as $key => $inst) {
  330.             if ($inst->getStatus() != "archive") {
  331.                 $installateursAll[]=$inst;
  332.             }
  333.         }
  334.         $depotAll=[];
  335.        
  336.         // foreach ($installateurRepository->findAll() as $key => $inst) {
  337.         //     if ($inst->getStatus() != "archive") {
  338.         //         $installateursAll[]=$inst;
  339.         //     }
  340.         // }
  341.         if($this->isGranted('ROLE_OBLIGE')){
  342.             $contratAll=[];
  343.             $contrats=[];
  344.             foreach ($this->getUser()->getObliges()->getDeals() as  $deal) {
  345.                 foreach ($deal->getDepotDossiers() as  $value) {
  346.                     $depotAll[]=$value;
  347.                 }
  348.                 $contratAll[]=$deal->getContrat();
  349.                 if ($deal->getContrat()) {
  350.                    if ($deal->getContrat()->getStatus()=="Contrat Signé") {
  351.                        $contrats[]=$deal->getContrat();
  352.                    }
  353.                 }
  354.             }
  355.         }else{
  356.             foreach ($depotDossierRepository->findAll() as $key => $dossier) {
  357.                 if ($dossier->getStatus() != "archive") {
  358.                     $depotAll[]=$dossier;
  359.                 }
  360.             }
  361.             $contratAll $contratRepository->findAll();
  362.             $contrats $contratRepository->findBy(['status' => 'Contrat Signé'], ['id' => 'DESC'], 10);
  363.         }
  364.        
  365.           
  366.         return $this->render('home/index.html.twig', [
  367.             'dashboard' => 'dashboard',
  368.             'dealsAll' => $dealAll,
  369.             'dossierAll'=>$dossierAll,
  370.             'depotAll' => $depotAll,
  371.             'dealAllten' => $dealAllten,
  372.             'contratAll' => $contratAll,
  373.             'installateursAll' => $installateursAll,
  374.             'dealsNew' => $dealsNew,
  375.             'dealsValide' => $dealsValide,
  376.             'dealsVerification' => $dealsVerification,
  377.             'dealscontratgenere' => $dealscontratgenere,
  378.             'dealscontratsigne' => $dealscontratsigne,
  379.             'dealsBloquer' => $dealsBloquer,
  380.             'installateurs' => $installateurRepository->findBy([], ['id' => 'DESC'], 10),
  381.             'contrats' => $contrats,
  382.             'installateur' => $installateur,
  383.             'isCompleted' => $isCompleted,
  384.             "champsinstallateurexpire" => $champsinstallateurexpire,
  385.             "champsdealexpire" => $champsdealexpire,
  386.             "cumacaafcour" => $cumacaafcour,
  387.             "cumacEnAttente" => $cumacEnAttente,
  388.             "cumacnonvalide" => $cumacnonvalide,
  389.             "cumacnouveau" => $cumacnouveau,
  390.             "cumacurgent" => $cumacurgent,
  391.             "cumacvalide" => $cumacvalide,
  392.             "cumacpayeraaf" => $cumacpayeraaf,
  393.             "cumacpretdepot" => $cumacpretdepot,
  394.             "equipes" => $equipes,
  395.             "dossiercontroler" => $dossiercontroler,
  396.             "oblige" =>$oblige,
  397.             "obligedeal" =>$obligedeal,
  398.             "dealtotal" =>count($dealRepository->findAll())
  399.         ]);
  400.     }
  401.     /**
  402.      * @Route("/user/email", methods={"GET"})
  403.      */
  404.     public function user(UserRepository $userRepository): Response
  405.     {
  406.         $donnees $userRepository->findAll();
  407.         $response $this->CollectionToArray($donnees);
  408.         return new JsonResponse($response200);
  409.         // return $this->render('champs_installateur/index.html.twig', [
  410.         //     'champs_installateurs' => $champsInstallateurRepository->findAll(),
  411.         // ]);
  412.     }
  413.     /**
  414.      * This function convert a champs Collection to an array
  415.      */
  416.     private function CollectionToArray($collection): array
  417.     {
  418.         $response = [];
  419.         
  420.         foreach ($collection as $champ) {
  421.           
  422.             $response[] = [
  423.                 'id' => $champ->getId(),
  424.                 'email' => $champ->getEmail()
  425.             ];
  426.           
  427.         }
  428.         return $response;
  429.     }
  430.     public function search(InstallateurRepository $installateurRepositoryObligesRepository $obligesRepositoryDealRepository $dealRepository): Response
  431.     {
  432.         if($this->isGranted('ROLE_INSTALLATEUR')){
  433.             $deals $dealRepository->findBy(['installateur' => $this->getUser()->getInstallateur()->getId()], ['id' => 'DESC'], 10);
  434.             $installateurs "";
  435.             $obliges "";
  436.         } else {
  437.             $installateurs $installateurRepository->findAll();
  438.             $obliges $obligesRepository->findAll();
  439.             $deals $dealsRepository->findAll();
  440.         }
  441.         return $this->render('home/search.html.twig', [
  442.             'installateurs' => $installateurs,
  443.             'obliges' => $obliges,
  444.             "deals" => $deals
  445.         ]);
  446.     }
  447. }