src/Controller/SecurityController.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Equipes;
  4. use App\Entity\User;
  5. use App\Entity\Client;
  6. use App\Entity\Adresse;
  7. use App\Entity\Interventions;
  8. use App\Entity\Entreprise;
  9. use App\Entity\TicketReseaux;
  10. use App\Entity\Tikets;
  11. use App\Entity\Site;
  12. use App\Entity\UserFilters;
  13. use App\Entity\InterventionTags;
  14. use App\Entity\InterventionAffectedTags;
  15. use App\Entity\InterventionAffectedUsers;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  20. use Symfony\Component\Form\Extension\Core\Type\TextType;
  21. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  22. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  23. use Symfony\Component\Validator\Validator\ValidatorInterface;
  24. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use \Symfony\Component\HttpFoundation\RedirectResponse;
  27. use Symfony\Component\HttpFoundation\Cookie;
  28. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  29. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  30. use Symfony\Component\HttpFoundation\Session\Session;
  31. use Symfony\Component\Translation\TranslatorInterface;
  32. use Symfony\Component\Validator\Constraints\DateTime;
  33. use Ovh\Sms\SmsApi;
  34. use Symfony\Component\DependencyInjection\ContainerInterface;
  35. use App\Repository\InterventionsRepository;
  36. use App\Repository\ProjectsRepository;
  37. use App\Repository\ClientRepository;
  38. use App\Repository\UserRepository;
  39. use App\Repository\UserCongesRepository;
  40. use App\Service\ServiceTeaminfo;
  41. class SecurityController extends Controller
  42.     public $InterventionsRepository;
  43.     public $ProjectsRepository;
  44.     public $ClientRepository;
  45.     public $UserRepository;
  46.     private $service;
  47.     
  48.     
  49.     
  50.     public function __construct(InterventionsRepository $InterventionsRepositoryProjectsRepository $ProjectsRepositoryClientRepository $ClientRepositoryUserRepository $UserRepositoryServiceTeaminfo $service)
  51.     {
  52.            $this->InterventionsRepository $InterventionsRepository;
  53.            $this->ProjectsRepository $ProjectsRepository;
  54.            $this->ClientRepository $ClientRepository;
  55.         $this->UserRepository $UserRepository ;
  56.         $this->service $service;
  57.     } 
  58.     /**
  59.      * @Route("/security", name="security")
  60.      */
  61.     public function indexRequest $reqTokenStorageInterface $tokenStorage )
  62.     {
  63.         $user $tokenStorage->getToken()->getUser();
  64.         $users $this->UserRepository->findAll();
  65.         $equipes $this->getDoctrine()->getRepository(Equipes::class)->findAll();
  66.         $years $this->getUniqueListYearsInterventions() ;
  67.         $entreprise_id $this->container->getParameter('entreprise_id');
  68.         $entreprise $this->getDoctrine()->getRepository(Entreprise::class)->find($entreprise_id);
  69.         
  70.         if( $user != "anon." ){
  71.             $now = new \Datetime('now');
  72.             $current_month $now->format("n");
  73.             $current_year $now->format("Y");
  74.             
  75.             return $this->render('security/index.html.twig', array(
  76.                 'titre_page' => "Tableau de bord",
  77.                 'current_month' => $current_month,
  78.                 'current_year' => $current_year,
  79.                 'users' => $users,
  80.                 'equipes' => $equipes,
  81.                 'years' => $years,
  82.                 'entreprise' => $entreprise,
  83.                 'controller_name' => 'SecurityController',
  84.                 'add_js_files' =>"security_js"
  85.             ));                        
  86.         }else 
  87.             return $this->redirectToRoute('connexion');
  88.     }
  89.     
  90.     
  91.     
  92.     
  93.     
  94.     
  95.     
  96.     public function conges_index(UserCongesRepository $userCongesRepository TokenStorageInterface $tokenStorage)
  97.     {
  98.         $user $tokenStorage->getToken()->getUser();
  99.         $now = new \Datetime('now');
  100.         $current_month $now->format("n");
  101.         $current_year $now->format("Y");
  102.         $conges_courant $userCongesRepository->getCongesCourant($now->format("Y-m-d"),$user);
  103.         $conges_venir $userCongesRepository->getCongesVenir($now->format("Y-m-d"),$user);
  104.         $conges $userCongesRepository->getNomberCongeAprendre($now->format("Y-m-d"),$user);
  105.         $nombre_conge_a_prendre $this->calculJoursCongesAprendre ($conges,$now->format("Y-m-d"));
  106.         
  107.         $conges_index $this->renderView('/security/conges_entreprise.html.twig', array(    
  108.             'conges_courant' => $conges_courant,
  109.             'conges_venir' => $conges_venir,
  110.             'nombre_conge_a_prendre' => $nombre_conge_a_prendre,
  111.         ));
  112.         
  113.         $response =new Response(json_encode(array($conges_index))); 
  114.         
  115.         return $response;    
  116.     }
  117.     
  118.     
  119.     
  120.     
  121.     
  122.     
  123.     
  124.     public function calculJoursCongesAprendre ($conges,$date_now)
  125.     {
  126.         $nombre_jours_conges 0;
  127.         
  128.         foreach ( $conges as $conge ){
  129.             if ( $conge->getDateDebut()->format('Y-m-d') > $date_now )
  130.                 $d1 date_create(($conge->getDateDebut()->format('Y-m-d')));
  131.             else
  132.                 $d1 date_create($date_now);
  133.             
  134.             $d2 date_create$conge->getDateFin()->format('Y-m-d') );
  135.             
  136.             $interval date_diff($d1,$d2);
  137.             
  138.             $nombre intval($interval->format('%d')) + 1;
  139.             
  140.             $nombre_jours_conges += $nombre;
  141.         }
  142.         
  143.         return     $nombre_jours_conges;
  144.     }
  145.     
  146.     
  147.     
  148.     
  149.     
  150.     
  151.     
  152.     
  153.     public function login(Request $requestAuthenticationUtils $authUtilsTokenStorageInterface $tokenStorage,ServiceTeaminfo $ServiceTeaminfo)
  154.     {    
  155.         $user $tokenStorage->getToken()->getUser();
  156.         $error_message null;
  157.         if( $user != "anon."){
  158.             if($user->getIsActive() == && $user->getDeleted() == null){
  159.                 $user_id $user->getId();    
  160.                 
  161.                 $cookies $request->cookies;
  162.                 $response = new RedirectResponse('home'302);
  163.                 
  164.                 if($cookies->has('indicateurs'))        $response->headers->clearCookie('indicateurs''/'null);
  165.                 
  166.                 if($cookies->has('site'))        $response->headers->clearCookie('site''/'null);
  167.                 
  168.                 if($cookies->has('current_'.$ServiceTeaminfo::PROJECT_FILTER))        $response->headers->clearCookie('current_'.$ServiceTeaminfo::PROJECT_FILTER'/'null);
  169.                 
  170.                 if($cookies->has('current_'.$ServiceTeaminfo::INTERVENTION_FILTER))        $response->headers->clearCookie($ServiceTeaminfo::INTERVENTION_FILTER'/'null);
  171.                 
  172.                 if($cookies->has('current_user_role'))        $response->headers->clearCookie('current_user_role''/'null);
  173.                 
  174.                 if($cookies->has('current_intervention_vue'))    $response->headers->clearCookie('current_intervention_vue''/'null);
  175.                 
  176.                 $current_vue $user->getCurrentInterventionVue();    
  177.                 
  178.                 if($current_vue){
  179.                     $current_vue_id $current_vue->getId();
  180.                     $current_vue_parameters $current_vue->getParameters();
  181.                 }else{
  182.                     $current_vue_id 0;
  183.                     $current_vue_parameters $ServiceTeaminfo-> getDefaultView($ServiceTeaminfo->widthsAndDefaultView);
  184.                     $nbr_items =$ServiceTeaminfo::DEFAULT_LIMIT;
  185.                     $current_vue_parameters array_merge($current_vue_parameters, array("nb_items_to_show"=>$nbr_items));    
  186.                 }
  187.                 
  188.                 $current_vue array_merge(array("id"=>$current_vue_id),$current_vue_parameters);
  189.                 $cookie = new Cookie('current_intervention_vue'serialize($current_vue), time() + (365 24 60 60), '/'nullfalsefalse);
  190.                 $response->headers->setCookie($cookie);
  191.             
  192.                 return $response;
  193.             }elseif(!$user->getIsActive())
  194.                 $error_message "Le compte de cet utilisateur n'est pas activé.";
  195.             else
  196.                 $error_message "Le compte de cet utilisateur est supprimé.";
  197.         }
  198.         
  199.         // get the login error if there is one
  200.         $error $authUtils->getLastAuthenticationError();
  201.         // last username entered by the user
  202.         $lastUsername $authUtils->getLastUsername();
  203.         
  204.         return $this->render('security/login.html.twig', array(
  205.             'titre_page' => "Connexion",
  206.             'last_username' => $lastUsername,
  207.             'error'         => $error,
  208.             'add_js_files' =>"security_js",
  209.             'error_message' => $error_message
  210.         ));
  211.     }
  212.     
  213.     
  214.     
  215.     public function logout(){}
  216.     
  217.     
  218.     
  219.     
  220.     public function forget_password(Request $request, \Swift_Mailer $mailerTranslatorInterface $translator )
  221.     {        
  222.         $entityManager $this->getDoctrine()->getManager();
  223.         $user $entityManager->getRepository(User::class)->findOneByEmail$request->get('email') );
  224.         
  225.         if($user && $user->getDeleted() !=1){
  226.             $reset '';
  227.             $chaine '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  228.             srand((double)microtime()*1000000);
  229.             
  230.             for($i=0$i<32$i++) 
  231.                 $reset .= $chaine[rand()%strlen($chaine)];
  232.             
  233.             $user->setReset($reset);
  234.             $user->setIsActive(false);            
  235.             $entityManager->flush();
  236.             
  237.             $e_mail $user->getEmail();
  238.             $base_url '/connexion/reset_password/'.$reset.'/'.$e_mail;
  239.             
  240.             $content $this->get('twig')->render('emails/mot_de_passe_obliee.html.twig', [
  241.                 'titre_page' => 'reset password',
  242.                 'e_mail' => $e_mail,
  243.                 'url'=> $base_url,
  244.                 'add_js_files' =>"security_js",
  245.             ]);    
  246.             
  247.             try{    
  248.                 $message = (new \Swift_Message())
  249.                     ->setSubject($translator->trans('Mot de passe oblié') )
  250.                     ->setFrom($this->getParameter('contact_email'))
  251.                     ->setTo($user->getEmail())
  252.                     ->setBody($content,'text/html')
  253.                     ->setContentType('text/html')
  254.                 ;
  255.                 
  256.                 $mailer->send($message);
  257.             }catch(\Swift_TransportException $Ste){};
  258.             
  259.             return $this->redirectToRoute('connexion', array(
  260.                 'valide_msg' => $translator->trans("Un email veins d'étre envoyer Ã  votre boite email"),
  261.             ));    
  262.         }else 
  263.             return $this->redirectToRoute('connexion');        
  264.     }
  265.     
  266.     
  267.     
  268.     
  269.     public function reset_password ($reset$e_mail)
  270.     {
  271.         $entityManager $this->getDoctrine()->getManager();
  272.         $user $entityManager->getRepository(User::class)->findOneByEmail($e_mail);
  273.         
  274.         if($user && strcmp ($user->getReset(), $reset)==&& $user->getDeleted() !=1){
  275.             return $this->render('security/reset.html.twig', [
  276.                 'titre_page' => 'reset password',
  277.                 'reset'=>$reset,
  278.                 'e_mail' => $e_mail,
  279.                 'add_js_files' =>"security_js",
  280.             ]);    
  281.         }else{
  282.             return $this->redirectToRoute('connexion');
  283.         }            
  284.     }
  285.     
  286.     
  287.     
  288.     
  289.     public function reset_password_check($reset,$e_mail Request $requestUserPasswordEncoderInterface $encoder, \Swift_Mailer $mailerTranslatorInterface $translator)
  290.     {
  291.         $entityManager $this->getDoctrine()->getManager();
  292.         $user $entityManager->getRepository(User::class)->findOneByEmail($e_mail);
  293.         
  294.         if($user && strcmp ($user->getReset(), $reset) == && $user->getDeleted() !=1){
  295.             if(strcmp ($request->get('password'), $request->get('password_confirm'))==0){
  296.                 $encoded_password $encoder->encodePassword($user$request->get('password') );
  297.                 $user->setPassword$encoded_password );
  298.                 $user->setReset(null);
  299.                 $base_url '/connexion';
  300.                 $entityManager->flush();
  301.                 
  302.                 $content $this->get('twig')->render('emails/nouveau_mot_de_passe.html.twig', [
  303.                     'titre_page' => 'Email',
  304.                     'user'=>$user,
  305.                     'pasword'=>$request->get('password'),
  306.                     'url'=> $base_url,
  307.                     'add_js_files' =>"security_js",
  308.                 ]);
  309.                 
  310.                 try{
  311.                     $message = (new \Swift_Message())
  312.                         ->setSubject($translator->trans('Nouveau mot de passe') )
  313.                         ->setFrom($this->getParameter('contact_email'))
  314.                         ->setTo($e_mail)
  315.                         ->setBody($content,'text/html')
  316.                         ->setContentType('text/html')
  317.                     ;
  318.                     
  319.                     $mailer->send($message);
  320.                 }catch(\Swift_TransportException $Ste){};    
  321.             }else {
  322.                 return $this->redirectToRoute('reset_password', array(
  323.                     'valide_msg' => $translator->trans("Mot de passe invalide"),
  324.                     'e_mail' =>$e_mail,
  325.                     'reset'=>$reset 
  326.                 ));
  327.             }    
  328.         }
  329.         
  330.         return $this->redirectToRoute('connexion');
  331.     }
  332.     
  333.     
  334.     
  335.     
  336.     public function connectivity (Request $requestTokenStorageInterface $tokenStorage)
  337.     {   
  338.         $user $tokenStorage->getToken()->getUser();
  339.         $connected "false";
  340.         
  341.         if($user != "anon.")    $connected "true";                
  342.         return new Response($connected);
  343.     }
  344.     
  345.     
  346.     
  347.     
  348.     
  349.     public function getClientAdresses(Request $requestTokenStorageInterface $tokenStorage )
  350.     {
  351.         $msg "";
  352.         $id_client $request->get('client');
  353.         $client $this->getDoctrine()->getRepository(Client::class)->find($id_client);
  354.         $id_adresse =  $request->get('id_adresse');
  355.         
  356.         if( $client ){
  357.             $adresses $this->getDoctrine()->getRepository(Adresse::class)->findBy(array('id_client' => $id_client'deleted' => null));
  358.             
  359.             $id_ent $this->container->getParameter('entreprise_id');
  360.             $entreprise $this->getDoctrine()->getRepository(Entreprise::class)->find($id_ent);
  361.             $id_client_interne $entreprise->getCompteInterne()->getId();
  362.             
  363.             $params = array(
  364.                 'adresses' => $adresses
  365.                 'id_adresse' =>$id_adresse,
  366.                 'id_client_interne' => $id_client_interne
  367.             );
  368.             
  369.             if($id_adresse == null && $id_client == $id_client_interne){
  370.                 $user $tokenStorage->getToken()->getUser();
  371.                 $site_ratachement $user->getSiteRatachement();
  372.                 $site $this->getDoctrine()->getRepository(Site::class)->find($site_ratachement->getId());
  373.                 $adresse $site->getAdresse();
  374.                 $id_adresse_interne $adresse->getId();
  375.             
  376.                 $params['id_adresse'] = $id_adresse_interne;
  377.             }
  378.             
  379.             $msg $this->get('twig')->render('clients/adresses/select_adresse.html.twig'$params );            
  380.         }else
  381.             $msg "invalide client";
  382.         
  383.         return new Response($msg);
  384.     }
  385.     
  386.     
  387.     
  388.     public function getClientsRequest $request )
  389.     {
  390.         $msg "";
  391.         $id_client $request->get('client');
  392.         
  393.         $clients $this->getDoctrine()->getRepository(Client::class)->findBy(['deleted' => null],["denomination" => "ASC"]);    
  394.         
  395.         $id_ent $this->container->getParameter('entreprise_id');
  396.         $entreprise $this->getDoctrine()->getRepository(Entreprise::class)->find($id_ent);
  397.         $id_client_interne $entreprise->getCompteInterne()->getId();
  398.         
  399.         $msg $this->get('twig')->render('clients/select_client.html.twig',[
  400.             'clients' =>$clients,
  401.             'newClient' => $id_client,
  402.             'id_client_interne' => $id_client_interne
  403.         ]);
  404.         
  405.         return new Response($msg);
  406.     }
  407.     
  408.     
  409.     
  410.     
  411.     public function getClientRequest $request )
  412.     {
  413.         $id $request->get('client');
  414.         $client $this->getDoctrine()->getRepository(Client::class)->find($id);
  415.     
  416.         $output = array(
  417.             "email"    => $client->getEmail(),
  418.             "telephone"  => ($client->getTelephoneMobile() || $client->getTelephone()) ? 
  419.                             ($client->getTelephoneMobile() ?: $client->getTelephone()) : 
  420.                             "",
  421.             "machine"  =>  $client->getMachineName(),
  422.             "teamviewer" => $client->getTeamviewerName()
  423.         );
  424.         
  425.         return new Response(json_encode($output), 200, ['Content-Type' => 'application/json']);        
  426.     }
  427.     
  428.     
  429.     
  430.     
  431.     
  432.     public function get_client_site(Request $request)
  433.     { 
  434.         $client $this->getDoctrine()->getRepository(Client::class)->find$request->get('client') );
  435.         
  436.         return new Response$client->getSiteAffectation()->getLibelle() );
  437.     }
  438.     
  439.     
  440.     
  441.     /**
  442.      * @Route("/interventions_chart", name="interventions_chart")
  443.      */
  444.     public function interventions_chartRequest $requestTokenStorageInterface $tokenStorage )
  445.     {    
  446.         $user $tokenStorage->getToken()->getUser();
  447.         $users $request->get("users");
  448.                 
  449.         $result = array("Names" => ["Names"]);
  450.         $index 1;
  451.         
  452.         if($request->get("years")){
  453.             $first_month_name "January";
  454.             $last_month_name "December";
  455.             $result_length 12;
  456.             $format_character "M";
  457.         
  458.             $years $request->get("years");
  459.             
  460.             $nb_columns count($years);
  461.             if($users)         $nb_columns *= count($users);
  462.             for($i=1$i <= $result_length$i++){    
  463.                 $dateObj = \DateTime::createFromFormat('!m'$i);
  464.                 $month_short_name $dateObj->format($format_character);
  465.                 
  466.                 switch ($month_short_name) {
  467.                    case "Feb":
  468.                         $result[$month_short_name] = ["fev"];
  469.                         break;
  470.                    case "Apr":
  471.                         $result[$month_short_name] = ["Avr"];
  472.                         break;
  473.                    case "May":
  474.                         $result[$month_short_name] = ["Mai"];
  475.                         break;
  476.                    case "Jun":
  477.                         $result[$month_short_name] = ["Jui"];
  478.                         break;
  479.                    case "Jul":
  480.                         $result[$month_short_name] = ["Juil"];
  481.                         break;
  482.                    case "Aug":
  483.                         $result[$month_short_name] = ["Aou"];
  484.                         break;
  485.                    default:
  486.                         $result[$month_short_name] = [$month_short_name];
  487.                    }
  488.                 
  489.                 $zero_array array_fill(1$nb_columns0);
  490.                 
  491.                 array_push($result[$month_short_name], ...$zero_array);
  492.             }
  493.                     
  494.             foreach($years as $year_key => $year){
  495.                 $first_month_name 'January '.$year;
  496.                 $last_month_name 'December '.$year;
  497.                 
  498.                 $interventions_filters = array(
  499.                     "start_date" => date('Y-m-01'strtotime($first_month_name)),
  500.                     "end_date" => date('Y-m-t'strtotime($last_month_name)),
  501.                 );
  502.                 
  503.                 if( $user->getClient() )        $interventions_filters['clients'] = [$user->getClient()->getId()];
  504.                 
  505.                 $result $this->addPeriodElementsToArray($result$index$users$interventions_filters$format_character$year);
  506.                 
  507.                 $index++;
  508.             }
  509.         }else{    
  510.             $format_character "j";
  511.             $months $request->get("months");
  512.             
  513.             $interventions_filters = array();
  514.             
  515.             if($user->getClient())        $interventions_filters['clients'] = [$user->getClient()->getId()];
  516.             $nb_columns    count($months);
  517.             if($users)         $nb_columns *= count($users);
  518.             
  519.             $result_length 31;
  520.             
  521.             if(count($months) == 1){
  522.                 $month = \DateTime::createFromFormat('!m'$months[0]);
  523.                 $result_length date("t"$month->getTimestamp());    
  524.             }
  525.             
  526.             for($day=1$day <= $result_length$day++){            
  527.                 $key strval($day);
  528.                 $result[$key] = [$key];
  529.                 $zero_array array_fill(1$nb_columns0);
  530.                 
  531.                 array_push($result[$key], ...$zero_array);
  532.             }
  533.             
  534.             foreach($months as $month_key => $month_number){
  535.                 $month = \DateTime::createFromFormat('!m'$month_number);
  536.                 $month_name $month->format("F");
  537.                 
  538.                 $fr_month_name $this->service::MONTHS[$month_number]["libelle"];
  539.                 
  540.                 $start_date = new \Datetime('first day of '.$month_name);
  541.                 $end_date = new \Datetime('last day of '.$month_name);    
  542.                 $interventions_filters["start_date"] = $start_date->format("Y-m-d");
  543.                 $interventions_filters["end_date"] = $end_date->format("Y-m-d");
  544.             
  545.                 $result $this->addPeriodElementsToArray($result$index$users$interventions_filters$format_character$fr_month_name);
  546.                 $index++;
  547.             }
  548.         }
  549.         
  550.         return new Response(json_encode($result));
  551.     }
  552.     
  553.     public function getUniqueListYearsInterventions()
  554.     {
  555.         $listAllDates array_column($this->InterventionsRepository->getlistDatesInterventions (),'date');
  556.         
  557.         $listAllYears array_map(
  558.             function ($date){
  559.                 return $date->format('Y');
  560.             },
  561.             $listAllDates
  562.         );
  563.         
  564.         $uniqueListYears array_unique($listAllYears);
  565.         
  566.         sort($uniqueListYears,SORT_NUMERIC);
  567.         
  568.         return $uniqueListYears ;
  569.     }
  570.     
  571.     
  572.     
  573.     
  574.     
  575.     private function addPeriodElementsToArray($result$index$users$interventions_filters$format_character$period)
  576.     {    
  577.         if($users){            
  578.             foreach($users as $user_key => $user_intervenant_id){
  579.                 $explode_result explode('|',$user_intervenant_id);
  580.                 $user_id $equipe_id null;
  581.                 
  582.                 if($explode_result[0] === "u")
  583.                     $user_id $explode_result[1];
  584.                 else
  585.                     $equipe_id $explode_result[1];
  586.                 
  587.                 if($user_id){
  588.                     $user_intervenant $this->getDoctrine()->getRepository(User::class)->find($user_id);
  589.                     
  590.                     $name $user_intervenant->getNom()." ".$user_intervenant->getPrenom()." ".$period;
  591.                     
  592.                     $result["Names"][] = $name;
  593.                     
  594.                     $interventions_filters['users'] = [$user_id] ;
  595.                 }else{
  596.                     $equipe $this->getDoctrine()->getRepository(Equipes::class)->find($equipe_id);
  597.                     
  598.                     $name $equipe->getLibelle()." ".$period;
  599.                     
  600.                     $result["Names"][] = $name;
  601.                     
  602.                     $interventions_filters['equipes'] = [$equipe_id];
  603.                 }
  604.                 
  605.                 $interventions $this->InterventionsRepository->getInterventionsByFilters($interventions_filtersfalsetrue);        
  606.             
  607.                 foreach($interventions as $intervention){
  608.                     $key $intervention->getDate()->format($format_character);
  609.                     $result[$key][$index]++;            
  610.                 }
  611.                 
  612.                 if( $user_key !== count($users) - )        $index++;
  613.             }
  614.         }else{
  615.             $result["Names"][] = $period;
  616.             $interventions $this->InterventionsRepository->getInterventionsByFilters($interventions_filtersfalsetrue);        
  617.             foreach($interventions as $intervention){
  618.                 $key $intervention->getDate()->format($format_character);
  619.                 $result[$key][$index]++;            
  620.             }
  621.         }
  622.         
  623.         return $result;
  624.     }
  625.     
  626.     
  627.     
  628.     
  629.     
  630.     /**
  631.      * @Route("/devis_chart", name="devis_chart")
  632.     */
  633.     public function chart_chiffre_affaire(Request $requestServiceTeaminfo $ServiceTeaminfo)
  634.     {
  635.         $year $request->get("year");
  636.         $result = array();
  637.         $chiffre_affaire_total 0;
  638.         $chiffre_affaire_reel 0;
  639.         $chiffre_affaire_preventional 0;
  640.     
  641.         for($m=1$m<=12$m++){
  642.             $month_number substr("0".$m, -2);
  643.             $first_part $year.'-'.$month_number;            
  644.             
  645.             $start_date = new \Datetime(date($first_part.'-01'));
  646.             $end_date = new \Datetime(date($first_part.'-t'));            
  647.             
  648.             $fr_month_name $this->service::MONTHS[$m]["key"];
  649.             
  650.             if($fr_month_name=="Feb")     $fr_month_name="Fev";
  651.             
  652.             if($fr_month_name=="Apr")     $fr_month_name="Avr";
  653.             
  654.             if($fr_month_name=="May")     $fr_month_name="Mai";
  655.             
  656.             if($fr_month_name=="Jun")     $fr_month_name="Jui";
  657.             
  658.             if($fr_month_name=="Jul")     $fr_month_name="Juil";
  659.             
  660.             if($fr_month_name=="Aug")     $fr_month_name="Aou";
  661.             
  662.             $thisdate = new \DateTime();
  663.             $curent_date $thisdate->format("Y/m/d");            
  664.             $curent_moth substr($curent_date,5,2);
  665.             $curent_moth $this->service::MONTHS[intval($curent_moth)]["key"];
  666.         
  667.             $projects_devis $this->ProjectsRepository->getProjectByDate($start_date->format("Y/m/d"), $end_date->format("Y/m/d"));
  668.     
  669.             $chifre_reel $this->ProjectsRepository->getChiffreReel($start_date->format("Y/m/d"), $end_date->format("Y/m/d"));
  670.             
  671.             $total_reel floatval($chifre_reel);
  672.             
  673.             $total_preventional floatval($projects_devis) - $total_reel    ;
  674.             
  675.             if ($fr_month_name != $curent_moth)            $total_preventional ;
  676.             
  677.             $table_chiffre_date[] = [$fr_month_name,$total_preventional,$total_reel];
  678.             
  679.             $chiffre_affaire_reel+= $total_reel;    
  680.             $chiffre_affaire_preventional += $total_preventional;        
  681.         }
  682.         
  683.         $total_devis_ans $this->ProjectsRepository->getProjectByDate($year.'/01/01'$year.'/12/31');
  684.         
  685.         $html = [
  686.             "cat" => $ServiceTeaminfo->formatPrice($total_devis_ans,true),
  687.             "car" => $ServiceTeaminfo->formatPrice($chiffre_affaire_reel,true),
  688.             "cap" => $ServiceTeaminfo->formatPrice($chiffre_affaire_preventional,true)
  689.         ] ;
  690.         
  691.         $data = [
  692.             "table_chiffre_date" => $table_chiffre_date,
  693.             "html" => $html
  694.         ];    
  695.     
  696.         return new Response(json_encode($data));
  697.     }    
  698.             
  699.     public function DeleteAllCookies() {
  700.          foreach ($_COOKIE as $name => $value) {
  701.             if (isset($_COOKIE[$name])) {
  702.                 unset($_COOKIE[$name]);
  703.                 setcookie($name''time() - 3600'/');
  704.             }
  705.         }
  706.         return new Response("done");
  707.     
  708.     }
  709.     
  710. }