src/Controller/Admin/DashboardController.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Agent;
  4. use App\Entity\AjoutManuel;
  5. use App\Entity\AleaAgentIndisponible;
  6. use App\Entity\AleaTrainLimite;
  7. use App\Entity\AleaTrainSupprime;
  8. use App\Entity\Axe;
  9. use App\Entity\Contrat;
  10. use App\Entity\DecisionStatut;
  11. use App\Entity\Gare;
  12. use App\Entity\Impact;
  13. use App\Entity\ImpactStatut;
  14. use App\Entity\Jour;
  15. use App\Entity\Parametre;
  16. use App\Entity\PatternJour;
  17. use App\Entity\Periode;
  18. use App\Entity\PlanningTemporaire;
  19. use App\Entity\PlanningTemporaireGenere;
  20. use App\Entity\Train;
  21. use App\Entity\User;
  22. use App\Service\ExcelService;
  23. use App\Service\PlanningTemporaireNewService;
  24. use DateInterval;
  25. use Doctrine\ORM\EntityManagerInterface;
  26. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  27. use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
  28. use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
  29. use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
  30. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
  31. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  32. use Symfony\Component\HttpFoundation\JsonResponse;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\HttpFoundation\Response;
  35. use Symfony\Component\HttpKernel\KernelInterface;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. class DashboardController extends AbstractDashboardController
  38. {
  39.     private $jours_ = array(
  40.         => "lundi",
  41.         => "mardi",
  42.         => "mercredi",
  43.         => "jeudi",
  44.         => "vendredi",
  45.         => "samedi",
  46.         => "dimanche"
  47.     );
  48.     public function __construct(private EntityManagerInterface $em
  49.         private PlanningTemporaireNewService $planning_temporaire_service_new,
  50.         private AdminUrlGenerator $admin_url_generator, private KernelInterface $kernel)
  51.     {
  52.     }
  53.     public function configureAssets(): Assets
  54.     {
  55.         return Assets::new()
  56.             ->addJsFile('plugins/jquery/jquery-3.1.0.min.js')
  57.             ->addJsFile('plugins/jquery-ui/jquery-ui.min.js')
  58.             ->addJsFile('plugins/notify/notify.min.js')
  59.             ->addCssFile('https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css')
  60.             ->addWebpackEncoreEntry('app')
  61.         ;
  62.     }
  63.     #[Route('/admin'name'admin')]
  64.     public function index(): Response
  65.     {
  66.         $date = new \DateTime();
  67.         $user $this->getUser();
  68.         $user->setDateConnexion($date);
  69.         $this->em->persist($user);
  70.         $this->em->flush();
  71.         return $this->render('admin/home.html.twig');
  72.         // Option 1. You can make your dashboard redirect to some common page of your backend
  73.         //
  74.         // $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
  75.         // return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());
  76.         // Option 2. You can make your dashboard redirect to different pages depending on the user
  77.         //
  78.         // if ('jane' === $this->getUser()->getUsername()) {
  79.         //     return $this->redirect('...');
  80.         // }
  81.         // Option 3. You can render some custom template to display a proper dashboard with widgets, etc.
  82.         // (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)
  83.         //
  84.         // return $this->render('some/path/my-dashboard.html.twig');
  85.     }
  86.     #[Route('/admin/generer_planningv2'name'generer_planning_v2')]
  87.     public function generer_planning_v2():Response{
  88.         $periodes $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
  89.         $poles $this->em->getRepository(Agent::class)->getPoles();
  90.         return $this->render('admin/generer_planning_v2.html.twig', array('periodes' => $periodes'poles' => $poles));
  91.     }
  92.     #[Route('/admin/add_manual'name'add_manual')]
  93.     public function add_manual(Request $request):Response{
  94.         $periodes $this->em->getRepository(Periode::class)->findAll();
  95.         $agents $this->em->getRepository(Agent::class)->findBy(array('actif' => 1), array('nom' => 'ASC'));
  96.         if($request->isMethod('POST')){
  97.             $agent $this->em->getRepository(Agent::class)->find($request->request->get('agent'));
  98.             $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  99.             $train_aller $this->em->getRepository(Train::class)->find($request->request->get('train_aller'));
  100.             $train_retour $this->em->getRepository(Train::class)->find($request->request->get('train_retour'));
  101.             $jour $this->em->getRepository(Jour::class)->findOneBy(array('name' => $request->request->get('jour')));
  102.             $check_manuel $this->em->getRepository(AjoutManuel::class)->findOneBy(
  103.                 array(
  104.                     'periode' => $periode,
  105.                     'jour' => $jour,
  106.                     'agent' => $agent,
  107.                     'train_aller' => $train_aller,
  108.                     'train_retour' => $train_retour
  109.                 )
  110.             );
  111.             if($check_manuel == null){
  112.                 $ajout_manuel = new AjoutManuel;
  113.                 $ajout_manuel->setPeriode($periode)
  114.                     ->setAgent($agent)
  115.                     ->setTrainAller($train_aller)
  116.                     ->setTrainRetour($train_retour)
  117.                     ->setJour($jour)
  118.                 ;
  119.                 $this->em->persist($ajout_manuel);
  120.                 $this->em->flush();
  121.             }
  122.             return $this->redirect($this->admin_url_generator->setController(AjoutManuelCrudController::class)->setAction(Action::INDEX)->generateUrl());
  123.         }
  124.         return $this->render('admin/add_manual.html.twig', array('periodes' => $periodes'agents' => $agents));
  125.     }
  126.     #[Route('/admin/ajax_remove_plan'name'ajax_remove_plan')]
  127.     public function ajax_remove_plan(Request $request){
  128.         $plan_id $request->request->get('plan_id');
  129.         $plan $this->em->getRepository(PlanningTemporaire::class)->find($plan_id);
  130.         $jour $this->em->getRepository(Jour::class)->findOneBy(array('name' => $plan->getJour()));
  131.         $ajout_manuel $this->em->getRepository(AjoutManuel::class)->findOneBy(
  132.             array(
  133.                 'periode' => $plan->getPeriode(),
  134.                 'jour' => $jour,
  135.                 'agent' => $plan->getAgent(),
  136.                 'train_aller' => $plan->getTrainAller(),
  137.                 'train_retour' => $plan->getTrainRetour()
  138.             )
  139.         );
  140.         $this->em->remove($ajout_manuel);
  141.         $this->em->flush();
  142.         return new JsonResponse(array('done' => true));
  143.     }
  144.     #[Route('/admin/save_comment'name'save_comment')]
  145.     public function save_comment(Request $request){
  146.         if($request->isMethod('POST')){
  147.             $data json_decode($request->getContent(), true);
  148.             if (!$data) {
  149.               return new JsonResponse(['success' => false'message' => 'Invalid JSON'], 400);
  150.             }
  151.             $agentId $data['agent'] ?? null;
  152.             $periodeId $data['periode'] ?? null;
  153.             $trainAllerId $data['train_aller'] ?? null;
  154.             $trainRetourId $data['train_retour'] ?? null;
  155.             $jourName $data['jour'] ?? null;
  156.             $comment $data['comment'] ?? null;
  157.             if (!$agentId || !$periodeId || !$trainAllerId || !$trainRetourId || !$jourName || !$comment) {
  158.               return new JsonResponse(['success' => false'message' => 'Missing data'], 400);
  159.             }
  160.             $agent $this->em->getRepository(Agent::class)->find((int)$agentId);
  161.             $periode $this->em->getRepository(Periode::class)->find((int)$periodeId);
  162.             $train_aller $this->em->getRepository(Train::class)->find((int)$trainAllerId);
  163.             $train_retour $this->em->getRepository(Train::class)->find((int)$trainRetourId);
  164.             $jour $this->em->getRepository(Jour::class)->findOneBy(array('name' => $jourName));
  165.             $check_manuel $this->em->getRepository(AjoutManuel::class)->findOneBy([
  166.                 'periode' => $periode,
  167.                 'jour' => $jour,
  168.                 'agent' => $agent,
  169.                 'train_aller' => $train_aller,
  170.                 'train_retour' => $train_retour
  171.             ]);
  172.             if($check_manuel !== null){
  173.                 $check_manuel->setCommentaire($comment);
  174.                 $this->em->persist($check_manuel);
  175.                 $this->em->flush();
  176.             }else{
  177.                 return new JsonResponse(['success' => false]);
  178.             }
  179.             return new JsonResponse(['success' => true'comment' => $comment]);
  180.         }
  181.         return new JsonResponse(['success' => false]);
  182.     }
  183.     #[Route('/admin/save_swap_boucle'name'save_swap_boucle')]
  184.     public function save_swap_boucle(Request $request){
  185.         $plan_id $request->request->get('plan_id');
  186.         $plan $this->em->getRepository(PlanningTemporaire::class)->find($plan_id);
  187.         $jour $this->em->getRepository(Jour::class)->findOneBy(array('name' => $plan->getJour()));
  188.         $agent_cible $this->em->getRepository(Agent::class)->find($request->request->get('agent_id'));
  189.         //Jour actuel de l'agent cible
  190.         $ajout_manuel_cible $this->em->getRepository(AjoutManuel::class)->findBy([
  191.             'periode' =>$plan->getPeriode(),
  192.             'jour' => $jour,
  193.             'agent' => $agent_cible 
  194.         ]);
  195.         foreach($ajout_manuel_cible as $am){
  196.             $this->em->remove($am);
  197.             $this->em->flush();
  198.         }
  199.         $ajout_manuel $this->em->getRepository(AjoutManuel::class)->findOneBy(
  200.             array(
  201.                 'periode' => $plan->getPeriode(),
  202.                 'jour' => $jour,
  203.                 'agent' => $plan->getAgent(),
  204.                 'train_aller' => $plan->getTrainAller(),
  205.                 'train_retour' => $plan->getTrainRetour()
  206.             )
  207.         );
  208.         $ajout_manuel->setAgent($agent_cible);
  209.         $this->em->persist($ajout_manuel);
  210.         $this->em->flush();
  211.         
  212.         return new JsonResponse(array('done' => true));
  213.     }
  214.     #[Route('/admin/get_pole_agents'name'get_pole_agents')]
  215.     public function get_pole_agents(Request $request){
  216.         $agents $this->em->getRepository(Agent::class)->getPoleAgents($request->request->get('gare_id'), $request->request->get('agent_id'));
  217.         return new JsonResponse(['agents' => $agents]);
  218.     }
  219.     #[Route('/admin/ajax_duplicate_plan'name'ajax_duplicate_plan')]
  220.     public function ajax_duplicate_plan(Request $request){
  221.         $plan_id $request->request->get('plan_id');
  222.         $plan $this->em->getRepository(PlanningTemporaire::class)->find($plan_id);
  223.         $jour $this->em->getRepository(Jour::class)->findOneBy(array('name' => $plan->getJour()));
  224.         $check_manuel $this->em->getRepository(AjoutManuel::class)->findOneBy(
  225.             array(
  226.                 'periode' => $plan->getPeriode(),
  227.                 'jour' => $jour,
  228.                 'agent' => $plan->getAgent(),
  229.                 'train_aller' => $plan->getTrainAller(),
  230.                 'train_retour' => $plan->getTrainRetour()
  231.             )
  232.         );
  233.         if($check_manuel == null){
  234.             $ajout_manuel = new AjoutManuel;
  235.             $ajout_manuel->setPeriode($plan->getPeriode())
  236.                     ->setAgent($plan->getAgent())
  237.                     ->setTrainAller($plan->getTrainAller())
  238.                     ->setTrainRetour($plan->getTrainRetour())
  239.                     ->setJour($jour)
  240.             ;
  241.             $this->em->persist($ajout_manuel);
  242.             $this->em->flush();
  243.             return new JsonResponse(array('done' => true));
  244.         }else{
  245.             return new JsonResponse(array('done' => false));
  246.         }
  247.     }
  248.     #[Route('/admin/ajax_manual_load_train'name'ajax_manual_load_train')]
  249.     public function ajax_manual_load_train(Request $request):Response{
  250.         $array_trains = array();
  251.         $jour $this->em->getRepository(Jour::class)->findOneBy(array('name' => $request->request->get('jour')));
  252.         $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  253.         $trains =  $this->em->getRepository(Train::class)->getTrainSpbJourAjax($request->request->get('jour'), $periode);
  254.         foreach($trains as $train){
  255.             array_push($array_trains, array(
  256.                 'numero' => $train->getNumero(),
  257.                 'id' => $train->getId()
  258.             ));
  259.         }
  260.         return new JsonResponse(array('trains' => $array_trains));
  261.     }
  262.     #[Route('/admin/display_calendar'name'display_calendar')]
  263.     public function display_calendar():Response{
  264.         $plannings_temporaires $this->em->getRepository(PlanningTemporaire::class)->getUniqueNames();
  265.         $agents $this->em->getRepository(Agent::class)->findBy(array('actif' => 1), array('nom' => 'ASC'));
  266.         return $this->render('admin/calendar.html.twig', array('plannings_temporaires' => $plannings_temporaires'agents' => $agents));
  267.     }
  268.     #[Route('/admin/ajax/generer_planning_v2'name'ajax_generer_planning_v2')]
  269.     public function ajax_generer_planning_v2(Request $requestKernelInterface $kernel):JsonResponse{
  270.         $response $this->planning_temporaire_service_new->generatePlanningTemporaire($request->request->get('periode'));
  271.         return new JsonResponse($response);
  272.     }
  273.     #[Route('/admin/planning_temporaire/{name}'name'display_planning_temporaire')]
  274.     public function display_planning_temporaire($name):Response{
  275.         $temps_semaine_par_agents $this->em->getRepository(PlanningTemporaire::class)->getTempsSemaineParAgent($name);
  276.         $i 0;
  277.         foreach($temps_semaine_par_agents as $temps_agent){
  278.             //$temps_semaine_par_agents[$i]['temps_travail'] = str_pad((int)($temps_semaine_par_agents[$i]['temps_travail']/60),2,"0",STR_PAD_LEFT).':'.str_pad(($temps_semaine_par_agents[$i]['temps_travail']%60),2,"0",STR_PAD_LEFT);
  279.             $plans $this->em->getRepository(PlanningTemporaire::class)->getByName($name$temps_agent['plan']->getAgent()->getId());
  280.             $temps_semaine_par_agents[$i]['plannings'] = $plans;
  281.             $i++;
  282.         }
  283.         //Chaque agent ?
  284.         //Puis recherche planning de cette periode ?
  285.         return $this->render('admin/display_planning_temporaire.html.twig', array('temps_semaine_par_agent' => $temps_semaine_par_agents));
  286.     }
  287.     #[Route('/admin/planning_temporaire/sncf/{name}'name'display_planning_temporaire_sncf')]
  288.     public function display_planning_temporaire_sncf($name):Response{
  289.         //QUE LES TRAINS SPB
  290.         $results = array();
  291.         $planning_temporaires $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
  292.         $periode $planning_temporaires[0]->getPeriode();
  293.         $jours $this->em->getRepository(Jour::class)->findAll();
  294.         foreach($jours as $jour){
  295.             $trains $this->em->getRepository(Train::class)->getTrainsSncf($periode$jour->getName());
  296.             /*$planning_temporaires_jour = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'jour' => $jour->getName()));
  297.             foreach($planning_temporaires_jour as $plan){
  298.             }*/
  299.             $trains_du_jour = array();
  300.             foreach($trains as $train){
  301.                 $demande_spb $this->isSpb($train$jour);
  302.                 $prevu_spb false;
  303.                 if($demande_spb == false){
  304.                     $check_retours $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_retour' => $train));
  305.                     if(!empty($check_retours)){
  306.                         $prevu_spb true;
  307.                     }else{
  308.                         continue;
  309.                     }
  310.                 }else{
  311.                     $check_allers $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_aller' => $train));
  312.                     if(!empty($check_allers)){
  313.                         $prevu_spb true;
  314.                     }
  315.                     $check_retours $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_retour' => $train));
  316.                     if(!empty($check_retours)){
  317.                         $prevu_spb true;
  318.                     }
  319.                 }
  320.                 $caboteur $this->isCaboteur($train);
  321.                 $date_depart \DateTime::createFromFormat('H:i'$train->getHeureDepart());
  322.                 array_push($trains_du_jour,array(
  323.                     'jour' => strtoupper($jour->getName()),
  324.                     'numero' => $train->getNumero(),
  325.                     'origine' => $train->getOrigine(),
  326.                     'destination' => $train->getDestination(),
  327.                     'origine_spb' => $train->getOrigineSpbDi(),
  328.                     'destination_spb' => $train->getDestinationSpbDi(),
  329.                     'caboteur' => $caboteur,
  330.                     'demande_spb' => ($demande_spb== true)?"O":"N",
  331.                     'prevu_spb' => ($prevu_spb== true)?"O":"N",
  332.                     'date_depart' => $date_depart,
  333.                     'date_str' => $date_depart->format('H:i')
  334.                 )); 
  335.             }
  336.             array_multisort(array_column($trains_du_jour'date_depart'), SORT_ASC$trains_du_jour);
  337.             $results array_merge($results$trains_du_jour);
  338.         }
  339.         return $this->render('admin/display_planning_temporaire_sncf.html.twig', array('results' => $results));
  340.     }
  341.     private function isCaboteur($train){
  342.         //Verifier si entre les etapes qui sont en spb il y'a des etapes ou non
  343.         if($train->getEtapes()->isEmpty()){
  344.             return "N";
  345.         }else{
  346.             $i 0;
  347.             $etape_spb null;
  348.             foreach($train->getEtapes() as $etape){
  349.                 if($etape->getGare()->isPoleSpb() == 1){
  350.                     if($etape_spb !== null){
  351.                         if($etape_spb == $i+1){
  352.                             return "N";
  353.                         }else{
  354.                             return "O";
  355.                         }
  356.                     }
  357.                     $etape_spb $i;
  358.                 }
  359.                 $i++;
  360.             }
  361.         }
  362.         return "N";
  363.     }
  364.     private function isSpb($train$jour){
  365.         foreach($train->getSpbParJours() as $j){
  366.             if($j == $jour){
  367.                 return true;
  368.             }
  369.         }
  370.         return false;
  371.     }
  372.     #[Route('/admin/export_service/{name}'name'export_service')]
  373.     public function export_service($name){
  374.         $excel = new ExcelService;
  375.         $header = array('JOUR''N°TGV''ORIGINE''DESTINA°''PRISE DE SERVICE''DEPART''ARRIVEE''FIN DE SERVICE''CORRESP''N°TGV''ORIGINE''DESTINA°''PRISE DE SERVICE''DEPART''ARRIVEE''FIN DE SERVICE''AGENT');
  376.         $jours $this->em->getRepository(Jour::class)->findAll();
  377.         $trains_par_jours = [];
  378.         foreach($jours as $jour){
  379.             $trains_par_jours[$jour->getName()] = [];
  380.             $excel->setNextSheet($jour->getName());
  381.             $planning_temporaires $this->em->getRepository(PlanningTemporaire::class)->getForService($name$jour->getName());
  382.             foreach($planning_temporaires as $plan){
  383.                 //temps parcours  
  384.                 $date_depart_aller \DateTime::createFromFormat('H:i'$plan->getTrainDepartAller());
  385.                 /*array_push($trains_par_jours[$jour->getName()], array(
  386.                     $plan->getTrainNumeroAller(),
  387.                     $plan->getTrainOrigineAller(),
  388.                     $plan->getTrainDestinationAller(),
  389.                     $plan->getTrainDepartAller(),
  390.                     $plan->getTrainArriveeAller(),
  391.                     $plan->getCorrespondance(),
  392.                     $plan->getTrainNumeroRetour(),
  393.                     $plan->getTrainOrigineRetour(),
  394.                     $plan->getTrainDestinationRetour(),
  395.                     $plan->getTrainDepartRetour(),
  396.                     $plan->getTrainArriveeRetour(),
  397.                     $plan->getAgentName(),
  398.                     $date_depart_aller
  399.                 ));*/
  400.                 array_push($trains_par_jours[$jour->getName()], array(
  401.                     "jour" => $jour->getName(),
  402.                     "aller_numero" => $plan->getTrainNumeroAller(),
  403.                     "aller_origine" => $plan->getTrainOrigineAller(),
  404.                     "aller_destination" => $plan->getTrainDestinationAller(),
  405.                     "aller_pdf" => $plan->getTrainPriseDeServiceAller(),
  406.                     "aller_depart" => $plan->getTrainDepartAller(),
  407.                     "aller_arrivee" => $plan->getTrainArriveeAller(),
  408.                     "aller_fdf" => $plan->getTrainFinDeServiceAller(),
  409.                     "correspondance" => $plan->getCorrespondance(),
  410.                     "retour_numero" => $plan->getTrainNumeroRetour(),
  411.                     "retour_origine" => $plan->getTrainOrigineRetour(),
  412.                     "retour_destination" => $plan->getTrainDestinationRetour(),
  413.                     "retour_pdf" => $plan->getTrainPriseDeServiceRetour(),
  414.                     "retour_depart" => $plan->getTrainDepartRetour(),
  415.                     "retour_arrivee" => $plan->getTrainArriveeRetour(),
  416.                     "retour_fdf" => $plan->getTrainFinDeServiceRetour(),
  417.                     "agent" => $plan->getAgentName(),
  418.                     "date_order" => $date_depart_aller
  419.                 ));
  420.             }
  421.             //Trier par date
  422.             array_multisort(array_column($trains_par_jours[$jour->getName()], 'date_order'), SORT_ASC$trains_par_jours[$jour->getName()]);
  423.             $excel->sendDataToCurrentSheet($header$trains_par_jours[$jour->getName()]);
  424.         }
  425.         //Excel
  426.         return $excel->getNewExcel();
  427.     }
  428.     #[Route('/admin/export_capacite/{name}'name'export_capacite')]
  429.     public function export_capacite($name){
  430.         //Colonne origine - destination
  431.         //Nombre de demandés SPB
  432.         //Regrouper par orig - dest ou dest - orig
  433.         //puis orig spb - dest spb | avec ou sans etapes
  434.         $array_results = [];
  435.         $array_results1 = [];
  436.         $planning_temporaires $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
  437.         $periode $planning_temporaires[0]->getPeriode();
  438.         $trains_demandes_spb $this->em->getRepository(Train::class)->getTrainSpbJour(null$periode);
  439.         //Trains demandes
  440.         foreach($trains_demandes_spb as $train){
  441.             if($train->getOrigineSpb() !== null && $train->getDestinationSpb() !== null){
  442.                 $key $train->getAxe()->getCode();
  443.                 if(array_key_exists($key$array_results) == false){
  444.                      //Créer
  445.                      $array_results[$key] = [];
  446.                      $array_results1[$key] = [];
  447.                 }
  448.                 $key_spb $train->getOrigineSpb()->getCode().'-'.$train->getDestinationSpb()->getCode();
  449.                 $iscaboteur false;
  450.                 if($train->getEtapes()->isEmpty()){
  451.                 }else{
  452.                     $iscaboteur true;
  453.                     $key_spb $train->getOrigineSpb()->getCode().'-'.$train->getDestinationSpb()->getCode()."-CABOTEUR";
  454.                 }
  455.                 //NOMBRE PLANIFIES
  456.                 //NOMBRE ROUGE
  457.                 if(array_key_exists($key_spb$array_results[$key]) == false){
  458.                     //Créer
  459.                     $array_results[$key][$key_spb] = [
  460.                         "origine_spb" => $train->getOrigineSpb()->getName(),
  461.                         "destination_spb" => $train->getDestinationSpb()->getName(),
  462.                         "origine_spb_code" => $train->getOrigineSpb()->getCode(),
  463.                         "destination_spb_code" => $train->getDestinationSpb()->getCode(),
  464.                         "nombre_demande_semaine" => 0,
  465.                         "nombre_demande_dimanche" => 0,
  466.                         "nombre_couvert_semaine" => 0,
  467.                         "nombre_couvert_dimanche" => 0,
  468.                         "nombre_rouge_semaine" => 0,
  469.                         "nombre_rouge_dimanche" => 0,
  470.                         "iscaboteur" => $iscaboteur
  471.                     ];
  472.                     //Second tableau
  473.                     $array_results1[$key][$key_spb] = [
  474.                         "origine_spb" => $train->getOrigineSpb()->getName(),
  475.                         "destination_spb" => $train->getDestinationSpb()->getName(),
  476.                         "origine_spb_code" => $train->getOrigineSpb()->getCode(),
  477.                         "destination_spb_code" => $train->getDestinationSpb()->getCode(),
  478.                         "nombre_demande_lundi" => 0,
  479.                         "nombre_demande_mardi" => 0,
  480.                         "nombre_demande_mercredi" => 0,
  481.                         "nombre_demande_jeudi" => 0,
  482.                         "nombre_demande_vendredi" => 0,
  483.                         "nombre_demande_samedi" => 0,
  484.                         "nombre_demande_dimanche" => 0,
  485.                         "nombre_couvert_lundi" => 0,
  486.                         "nombre_couvert_mardi" => 0,
  487.                         "nombre_couvert_mercredi" => 0,
  488.                         "nombre_couvert_jeudi" => 0,
  489.                         "nombre_couvert_vendredi" => 0,
  490.                         "nombre_couvert_samedi" => 0,
  491.                         "nombre_couvert_dimanche" => 0,
  492.                         "nombre_rouge_lundi" => 0,
  493.                         "nombre_rouge_mardi" => 0,
  494.                         "nombre_rouge_mercredi" => 0,
  495.                         "nombre_rouge_jeudi" => 0,
  496.                         "nombre_rouge_vendredi" => 0,
  497.                         "nombre_rouge_samedi" => 0,
  498.                         "nombre_rouge_dimanche" => 0,
  499.                         "iscaboteur" => $iscaboteur
  500.                     ];
  501.                 }
  502.                 //Ajouter dans le tableau les nombres demandes
  503.                 //si jour um *2
  504.                 
  505.                 foreach($train->getSpbParJours() as $jour){
  506.                     $couvert false;
  507.                     $check_retours $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_retour' => $train'jour' => $jour->getName()));
  508.                     $check_allers $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_aller' => $train'jour' => $jour->getName()));
  509.                     if(!empty($check_retours) || !empty($check_allers)){
  510.                         $couvert true;
  511.                     }
  512.                     $array_results1[$key][$key_spb]["nombre_demande_".$jour->getName()]++;
  513.                     if($couvert == true){
  514.                         $array_results1[$key][$key_spb]["nombre_couvert_".$jour->getName()]++;
  515.                     }
  516.                     //Check um
  517.                     foreach($train->getJoursUm() as $jour_um){
  518.                         if($jour_um == $jour){
  519.                             $array_results1[$key][$key_spb]["nombre_demande_".$jour->getName()]++;
  520.                             if($couvert == true){
  521.                                 $array_results1[$key][$key_spb]["nombre_couvert_".$jour->getName()]++;
  522.                             }
  523.                         }
  524.                     }
  525.                     if($jour->getName() !== "dimanche"){
  526.                         $array_results[$key][$key_spb]["nombre_demande_semaine"]++;
  527.                         if($couvert == true){
  528.                             $array_results[$key][$key_spb]["nombre_couvert_semaine"]++;
  529.                         }
  530.                         //Check um
  531.                         foreach($train->getJoursUm() as $jour_um){
  532.                             if($jour_um == $jour){
  533.                                 $array_results[$key][$key_spb]["nombre_demande_semaine"]++;
  534.                                 if($couvert == true){
  535.                                     $array_results[$key][$key_spb]["nombre_couvert_semaine"]++;
  536.                                 }
  537.                             }
  538.                         }
  539.                     }else{
  540.                         $array_results[$key][$key_spb]["nombre_demande_dimanche"]++;
  541.                         if($couvert == true){
  542.                             $array_results[$key][$key_spb]["nombre_couvert_dimanche"]++;
  543.                         }
  544.                         //Check um
  545.                         foreach($train->getJoursUm() as $jour_um){
  546.                             if($jour_um == $jour){
  547.                                 $array_results[$key][$key_spb]["nombre_demande_dimanche"]++;
  548.                                 if($couvert == true){
  549.                                     $array_results[$key][$key_spb]["nombre_couvert_dimanche"]++;
  550.                                 }
  551.                             }
  552.                         }
  553.                     }
  554.                 }
  555.             }
  556.         }
  557.         
  558.         $plans_aller_rouge $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'aller_spb' => false));
  559.         foreach($plans_aller_rouge as $aller_rouge){
  560.             if($aller_rouge->getTrainAller()->getOrigineSpb() !== null && $aller_rouge->getTrainAller()->getDestinationSpb() !==null){
  561.                 $key $aller_rouge->getTrainAller()->getAxe()->getCode();
  562.                 $key_spb $aller_rouge->getTrainAller()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainAller()->getDestinationSpb()->getCode();
  563.                 $iscaboteur false;
  564.                 if($aller_rouge->getTrainAller()->getEtapes()->isEmpty()){
  565.                 }else{
  566.                     $iscaboteur true;
  567.                     $key_spb $aller_rouge->getTrainAller()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainAller()->getDestinationSpb()->getCode()."-CABOTEUR";
  568.                 }
  569.                 if(array_key_exists($key_spb$array_results[$key]) == false){
  570.                     //Créer
  571.                     $array_results[$key][$key_spb] = [
  572.                         "origine_spb" => $aller_rouge->getTrainAller()->getOrigineSpb()->getName(),
  573.                         "destination_spb" => $aller_rouge->getTrainAller()->getDestinationSpb()->getName(),
  574.                         "origine_spb_code" => $aller_rouge->getTrainAller()->getOrigineSpb()->getCode(),
  575.                         "destination_spb_code" => $aller_rouge->getTrainAller()->getDestinationSpb()->getCode(),
  576.                         "nombre_demande_semaine" => 0,
  577.                         "nombre_demande_dimanche" => 0,
  578.                         "nombre_couvert_semaine" => 0,
  579.                         "nombre_couvert_dimanche" => 0,
  580.                         "nombre_rouge_semaine" => 0,
  581.                         "nombre_rouge_dimanche" => 0,
  582.                         "iscaboteur" => $iscaboteur
  583.                     ];
  584.                     //Second tableau
  585.                     $array_results1[$key][$key_spb] = [
  586.                         "origine_spb" => $train->getOrigineSpb()->getName(),
  587.                         "destination_spb" => $train->getDestinationSpb()->getName(),
  588.                         "origine_spb_code" => $train->getOrigineSpb()->getCode(),
  589.                         "destination_spb_code" => $train->getDestinationSpb()->getCode(),
  590.                         "nombre_demande_lundi" => 0,
  591.                         "nombre_demande_mardi" => 0,
  592.                         "nombre_demande_mercredi" => 0,
  593.                         "nombre_demande_jeudi" => 0,
  594.                         "nombre_demande_vendredi" => 0,
  595.                         "nombre_demande_samedi" => 0,
  596.                         "nombre_demande_dimanche" => 0,
  597.                         "nombre_couvert_lundi" => 0,
  598.                         "nombre_couvert_mardi" => 0,
  599.                         "nombre_couvert_mercredi" => 0,
  600.                         "nombre_couvert_jeudi" => 0,
  601.                         "nombre_couvert_vendredi" => 0,
  602.                         "nombre_couvert_samedi" => 0,
  603.                         "nombre_couvert_dimanche" => 0,
  604.                         "nombre_rouge_lundi" => 0,
  605.                         "nombre_rouge_mardi" => 0,
  606.                         "nombre_rouge_mercredi" => 0,
  607.                         "nombre_rouge_jeudi" => 0,
  608.                         "nombre_rouge_vendredi" => 0,
  609.                         "nombre_rouge_samedi" => 0,
  610.                         "nombre_rouge_dimanche" => 0,
  611.                         "iscaboteur" => $iscaboteur
  612.                     ];
  613.                 }
  614.                 $array_results1[$key][$key_spb]["nombre_rouge_".$jour->getName()]++;
  615.                 
  616.                 if($aller_rouge->getJour() == "dimanche"){
  617.                     $array_results[$key][$key_spb]['nombre_rouge_dimanche']++;
  618.                 }else{
  619.                     $array_results[$key][$key_spb]['nombre_rouge_semaine']++;
  620.                 }
  621.             }
  622.         }
  623.         $plans_retour_rouge $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'retour_spb' => false));
  624.         foreach($plans_retour_rouge as $aller_rouge){
  625.             if($aller_rouge->getTrainRetour()->getOrigineSpb() !== null && $aller_rouge->getTrainRetour()->getDestinationSpb() !==null){
  626.                 $key $aller_rouge->getTrainRetour()->getAxe()->getCode();
  627.                 $key_spb $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainRetour()->getDestinationSpb()->getCode();
  628.                 $iscaboteur false;
  629.                 /*if($this->isCaboteur($aller_rouge->getTrainRetour()) == "O"){
  630.                     $iscaboteur = true;
  631.                     $key_spb = $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainRetour()->getDestinationSpb()->getCode()."-CABOTEUR";
  632.                 }*/
  633.                 if($aller_rouge->getTrainRetour()->getEtapes()->isEmpty()){
  634.                 }else{
  635.                     $iscaboteur true;
  636.                     $key_spb $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainRetour()->getDestinationSpb()->getCode()."-CABOTEUR";
  637.                 }
  638.                 if(array_key_exists($key_spb$array_results[$key]) == false){
  639.                     //Créer
  640.                     $array_results[$key][$key_spb] = [
  641.                         "origine_spb" => $aller_rouge->getTrainRetour()->getOrigineSpb()->getName(),
  642.                         "destination_spb" => $aller_rouge->getTrainRetour()->getDestinationSpb()->getName(),
  643.                         "origine_spb_code" => $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode(),
  644.                         "destination_spb_code" => $aller_rouge->getTrainRetour()->getDestinationSpb()->getCode(),
  645.                         "nombre_demande_semaine" => 0,
  646.                         "nombre_demande_dimanche" => 0,
  647.                         "nombre_couvert_semaine" => 0,
  648.                         "nombre_couvert_dimanche" => 0,
  649.                         "nombre_rouge_semaine" => 0,
  650.                         "nombre_rouge_dimanche" => 0,
  651.                         "iscaboteur" => $iscaboteur
  652.                     ];
  653.                     //Second tableau
  654.                     $array_results1[$key][$key_spb] = [
  655.                         "origine_spb" => $train->getOrigineSpb()->getName(),
  656.                         "destination_spb" => $train->getDestinationSpb()->getName(),
  657.                         "origine_spb_code" => $train->getOrigineSpb()->getCode(),
  658.                         "destination_spb_code" => $train->getDestinationSpb()->getCode(),
  659.                         "nombre_demande_lundi" => 0,
  660.                         "nombre_demande_mardi" => 0,
  661.                         "nombre_demande_mercredi" => 0,
  662.                         "nombre_demande_jeudi" => 0,
  663.                         "nombre_demande_vendredi" => 0,
  664.                         "nombre_demande_samedi" => 0,
  665.                         "nombre_demande_dimanche" => 0,
  666.                         "nombre_couvert_lundi" => 0,
  667.                         "nombre_couvert_mardi" => 0,
  668.                         "nombre_couvert_mercredi" => 0,
  669.                         "nombre_couvert_jeudi" => 0,
  670.                         "nombre_couvert_vendredi" => 0,
  671.                         "nombre_couvert_samedi" => 0,
  672.                         "nombre_couvert_dimanche" => 0,
  673.                         "nombre_rouge_lundi" => 0,
  674.                         "nombre_rouge_mardi" => 0,
  675.                         "nombre_rouge_mercredi" => 0,
  676.                         "nombre_rouge_jeudi" => 0,
  677.                         "nombre_rouge_vendredi" => 0,
  678.                         "nombre_rouge_samedi" => 0,
  679.                         "nombre_rouge_dimanche" => 0,
  680.                         "iscaboteur" => $iscaboteur
  681.                     ];
  682.                 }
  683.                 $array_results1[$key][$key_spb]["nombre_rouge_".$jour->getName()]++;
  684.                 if($aller_rouge->getJour() == "dimanche"){
  685.                     $array_results[$key][$key_spb]['nombre_rouge_dimanche']++;
  686.                 }else{
  687.                     $array_results[$key][$key_spb]['nombre_rouge_semaine']++;
  688.                 }
  689.             }
  690.         }
  691.         foreach($array_results1 as $key => $lignes){
  692.             foreach($lignes as $key_spb => $array){
  693.                 if($array['origine_spb_code'] !== "PMP" && $array['origine_spb_code'] !== "MPW"){
  694.                     $check_key_spb $array['destination_spb_code'] .'-'.$array['origine_spb_code'] ;
  695.                     if($array['iscaboteur'] == true){
  696.                         $check_key_spb.="-CABOTEUR";
  697.                     }
  698.                     if(array_key_exists($check_key_spb$lignes)){
  699.                         $array_results1[$key][$check_key_spb]['nombre_demande_lundi'] += $array['nombre_demande_lundi'];
  700.                         $array_results1[$key][$check_key_spb]['nombre_demande_mardi'] += $array['nombre_demande_mardi'];
  701.                         $array_results1[$key][$check_key_spb]['nombre_demande_mercredi'] += $array['nombre_demande_mercredi'];
  702.                         $array_results1[$key][$check_key_spb]['nombre_demande_jeudi'] += $array['nombre_demande_jeudi'];
  703.                         $array_results1[$key][$check_key_spb]['nombre_demande_vendredi'] += $array['nombre_demande_vendredi'];
  704.                         $array_results1[$key][$check_key_spb]['nombre_demande_samedi'] += $array['nombre_demande_samedi'];
  705.                         $array_results1[$key][$check_key_spb]['nombre_demande_dimanche'] += $array['nombre_demande_dimanche'];
  706.                         $array_results1[$key][$check_key_spb]['nombre_couvert_lundi'] += $array['nombre_couvert_lundi'];
  707.                         $array_results1[$key][$check_key_spb]['nombre_couvert_mardi'] += $array['nombre_couvert_mardi'];
  708.                         $array_results1[$key][$check_key_spb]['nombre_couvert_mercredi'] += $array['nombre_couvert_mercredi'];
  709.                         $array_results1[$key][$check_key_spb]['nombre_couvert_jeudi'] += $array['nombre_couvert_jeudi'];
  710.                         $array_results1[$key][$check_key_spb]['nombre_couvert_vendredi'] += $array['nombre_couvert_vendredi'];
  711.                         $array_results1[$key][$check_key_spb]['nombre_couvert_samedi'] += $array['nombre_couvert_samedi'];
  712.                         $array_results1[$key][$check_key_spb]['nombre_couvert_dimanche'] += $array['nombre_couvert_dimanche'];
  713.                         $array_results1[$key][$check_key_spb]['nombre_rouge_lundi'] += $array['nombre_rouge_lundi'];
  714.                         $array_results1[$key][$check_key_spb]['nombre_rouge_mardi'] += $array['nombre_rouge_mardi'];
  715.                         $array_results1[$key][$check_key_spb]['nombre_rouge_mercredi'] += $array['nombre_rouge_mercredi'];
  716.                         $array_results1[$key][$check_key_spb]['nombre_rouge_jeudi'] += $array['nombre_rouge_jeudi'];
  717.                         $array_results1[$key][$check_key_spb]['nombre_rouge_vendredi'] += $array['nombre_rouge_vendredi'];
  718.                         $array_results1[$key][$check_key_spb]['nombre_rouge_samedi'] += $array['nombre_rouge_samedi'];
  719.                         $array_results1[$key][$check_key_spb]['nombre_rouge_dimanche'] += $array['nombre_rouge_dimanche'];
  720.                     }else{
  721.                         $array_results1[$key][$check_key_spb] = $array;
  722.                     }
  723.                     unset($array_results1[$key][$key_spb]);
  724.                 } 
  725.             }
  726.         }
  727.         foreach($array_results as $key => $lignes){
  728.             //key = axe
  729.             foreach($lignes as $key_spb => $array){
  730.                 if($array['origine_spb_code'] !== "PMP" && $array['origine_spb_code'] !== "MPW"){
  731.                     $check_key_spb $array['destination_spb_code'] .'-'.$array['origine_spb_code'] ;
  732.                     if($array['iscaboteur'] == true){
  733.                         $check_key_spb.="-CABOTEUR";
  734.                     }
  735.                     if(array_key_exists($check_key_spb$lignes)){
  736.                         $array_results[$key][$check_key_spb]['nombre_demande_semaine'] += $array['nombre_demande_semaine'];
  737.                         $array_results[$key][$check_key_spb]['nombre_demande_dimanche'] += $array['nombre_demande_dimanche'];
  738.                         $array_results[$key][$check_key_spb]['nombre_couvert_semaine'] += $array['nombre_couvert_semaine'];
  739.                         $array_results[$key][$check_key_spb]['nombre_couvert_dimanche'] += $array['nombre_couvert_dimanche'];
  740.                         $array_results[$key][$check_key_spb]['nombre_rouge_semaine'] += $array['nombre_rouge_semaine'];
  741.                         $array_results[$key][$check_key_spb]['nombre_rouge_dimanche'] += $array['nombre_rouge_dimanche'];
  742.                     }else{
  743.                         $array_results[$key][$check_key_spb] = $array;
  744.                     }
  745.                     unset($array_results[$key][$key_spb]);
  746.                 } 
  747.             }
  748.         }
  749.         $excel = new ExcelService;
  750.         $header = array("AXE""LIGNE""TYPE D'OPERATION""NB TOTAL DE RAME SEMAINE DEMANDE INITIAL SJ""NB TOTAL DE RAMES COUVERTES SEMAINE MF""POUR INFO NON->OUI");
  751.         $excel->setDatasCapacite($header$array_results);
  752.         $excel->setDatasCapacite($header$array_results11);
  753.         return $excel->getExcel("export_capacite");
  754.     }
  755.     
  756.     private function search_multidimensional_array($array$key$value$key2 null$value2 null) {
  757.         $results = array();
  758.             
  759.         // if it is array
  760.         if (is_array($array)) {
  761.                 
  762.             // if array has required key and value
  763.             // matched store result 
  764.             if (isset($array[$key]) && $array[$key] == $value
  765.                     && ($key2 == null || (isset($array[$key2]) && $array[$key2] == $value2))) {
  766.                 $results[] = $array;
  767.             }
  768.                 
  769.             // Iterate for each element in array
  770.             foreach ($array as $subarray) {
  771.                     
  772.                 // recur through each element and append result 
  773.                 $results array_merge($results
  774.                     $this->search_multidimensional_array($subarray$key$value$key2$value2));
  775.             }
  776.         }
  777.         
  778.         return $results;
  779.     }
  780.     #[Route('/admin/planning_temporaire/sis/{name}'name'export_sis')]
  781.     public function export_sis($name){
  782.         $results = array();
  783.         $jours $this->em->getRepository(Jour::class)->findAll();
  784.         $plans $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
  785.         $periode $plans[0]->getPeriode();
  786.         $date_debut_periode $periode->getDateDebut()->format('d/m/Y');
  787.         $date_fin_periode $periode->getDateFin()->format('d/m/Y');
  788.         $jours $this->em->getRepository(Jour::class)->findAll();
  789.         $trains $this->em->getRepository(Train::class)->findBy(array('periode' => $periode));
  790.         foreach($trains as $train){
  791.             $origine $train->getOrigine();
  792.             $destination $train->getDestination();
  793.             if($train->getOrigineSpb() !== null){
  794.                 $origine $train->getOrigineSpb();
  795.             }
  796.             if($train->getDestinationSpb() !== null){
  797.                 $destination $train->getDestinationSpb();
  798.             }
  799.             $check_planning_allers $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_aller' => $train));
  800.             $check_planning_retours $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name'train_retour' => $train));
  801.             if($train->getSpbParJours()->isEmpty() == true && empty($check_planning_retours) && empty($check_planning_retours)){
  802.                 array_push($results, array(
  803.                     "numero" => $train->getNumero(),
  804.                     "date_debut_periode" => $date_debut_periode,
  805.                     "date_fin_periode" => $date_fin_periode,
  806.                     "origine" => $origine->getCode().'-BV',
  807.                     "destination" => $destination->getCode().'-BV',
  808.                     "particularite" => "",
  809.                     "lundi" => "",
  810.                     "mardi" => "",
  811.                     "mercredi" => "",
  812.                     "jeudi" => "",
  813.                     "vendredi" => "",
  814.                     "samedi" => "",
  815.                     "dimanche" => "",
  816.                 ));
  817.                 continue;
  818.             }
  819.             $train_um false;
  820.             if($train->getJoursUm()->isEmpty() == false){
  821.                 $train_um true;
  822.             }
  823.             if($train_um == false){
  824.                 $lundi "";
  825.                 $mardi "";
  826.                 $mercredi "";
  827.                 $jeudi "";
  828.                 $vendredi "";
  829.                 $samedi "";
  830.                 $dimanche "";
  831.                 foreach($train->getSpbParJours() as $jour){
  832.                         $jour_name $jour->getName();
  833.                         $check_train_aller_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  834.                             "name" => $name,
  835.                             "jour" => $jour_name,
  836.                             "train_aller" => $train
  837.                         ));
  838.                         if(!empty($check_train_aller_jours)){
  839.                             $$jour_name "1";
  840.                             continue;
  841.                         }else{
  842.                             $$jour_name "0";
  843.                         }
  844.                         $check_train_retour_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  845.                             "name" => $name,
  846.                             "jour" => $jour_name,
  847.                             "train_retour" => $train
  848.                         ));
  849.                         if(!empty($check_train_retour_jours)){
  850.                             $$jour_name "1";
  851.                             continue;
  852.                         }else{
  853.                             $$jour_name "0";
  854.                         }
  855.                 }
  856.                 array_push($results, array(
  857.                     "numero" => $train->getNumero(),
  858.                     "date_debut_periode" => $date_debut_periode,
  859.                     "date_fin_periode" => $date_fin_periode,
  860.                     "origine" => $origine->getCode().'-BV',
  861.                     "destination" => $destination->getCode().'-BV',
  862.                     "particularite" => "",
  863.                     "lundi" => $lundi,
  864.                     "mardi" => $mardi,
  865.                     "mercredi" => $mercredi,
  866.                     "jeudi" => $jeudi,
  867.                     "vendredi" => $vendredi,
  868.                     "samedi" => $samedi,
  869.                     "dimanche" => $dimanche,
  870.                 ));
  871.             }else{
  872.                 //D'abord NON UM
  873.                 $lundi "";
  874.                 $mardi "";
  875.                 $mercredi "";
  876.                 $jeudi "";
  877.                 $vendredi "";
  878.                 $samedi "";
  879.                 $dimanche "";
  880.                 
  881.                 foreach($train->getSpbParJours() as $jour){
  882.                     //Check si le jour en question est en um
  883.                     foreach($train->getJoursUm() as $jour_um){
  884.                         if($jour_um == $jour){
  885.                             continue 2;
  886.                         }
  887.                     }
  888.                     $jour_name $jour->getName();
  889.                     $check_train_aller_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  890.                             "name" => $name,
  891.                             "jour" => $jour_name,
  892.                             "train_aller" => $train
  893.                     ));
  894.                     if(!empty($check_train_aller_jours)){
  895.                             $$jour_name "1";
  896.                             continue;
  897.                     }else{
  898.                             $$jour_name "0";
  899.                     }
  900.                     $check_train_retour_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  901.                             "name" => $name,
  902.                             "jour" => $jour_name,
  903.                             "train_retour" => $train
  904.                     ));
  905.                     if(!empty($check_train_retour_jours)){
  906.                             $$jour_name "1";
  907.                             continue;
  908.                     }else{
  909.                             $$jour_name "0";
  910.                     }
  911.                 }
  912.                 //pour les jours non um
  913.                 array_push($results, array(
  914.                     "numero" => $train->getNumero(),
  915.                     "date_debut_periode" => $date_debut_periode,
  916.                     "date_fin_periode" => $date_fin_periode,
  917.                     "origine" => $origine->getCode().'-BV',
  918.                     "destination" => $destination->getCode().'-BV',
  919.                     "particularite" => "",
  920.                     "lundi" => $lundi,
  921.                     "mardi" => $mardi,
  922.                     "mercredi" => $mercredi,
  923.                     "jeudi" => $jeudi,
  924.                     "vendredi" => $vendredi,
  925.                     "samedi" => $samedi,
  926.                     "dimanche" => $dimanche,
  927.                 ));
  928.                 //pour les jours um 
  929.                 $lundi "";
  930.                 $mardi "";
  931.                 $mercredi "";
  932.                 $jeudi "";
  933.                 $vendredi "";
  934.                 $samedi "";
  935.                 $dimanche "";
  936.                 //TETE
  937.                 foreach($train->getSpbParJours() as $jour){
  938.                     //Check si le jour en question est en um
  939.                     foreach($train->getJoursUm() as $jour_um){
  940.                         if($jour_um !== $jour){
  941.                             continue 2;
  942.                         }
  943.                     }
  944.                     $jour_name $jour->getName();
  945.                     $check_train_aller_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  946.                             "name" => $name,
  947.                             "jour" => $jour_name,
  948.                             "train_numero_aller" => "T".$train->getNumero()
  949.                     ));
  950.                     if(!empty($check_train_aller_jours)){
  951.                             $$jour_name "1";
  952.                             continue;
  953.                     }else{
  954.                             $$jour_name "0";
  955.                     }
  956.                     $check_train_retour_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  957.                             "name" => $name,
  958.                             "jour" => $jour_name,
  959.                             "train_numero_retour" => "T".$train->getNumero()
  960.                     ));
  961.                     if(!empty($check_train_aller_jours)){
  962.                             $$jour_name "1";
  963.                             continue;
  964.                     }else{
  965.                             $$jour_name "0";
  966.                     }
  967.                 }
  968.                 //pour les jours non um TETE
  969.                 array_push($results, array(
  970.                     "numero" => $train->getNumero(),
  971.                     "date_debut_periode" => $date_debut_periode,
  972.                     "date_fin_periode" => $date_fin_periode,
  973.                     "origine" => $origine->getCode().'-BV',
  974.                     "destination" => $destination->getCode().'-BV',
  975.                     "particularite" => "TETE",
  976.                     "lundi" => $lundi,
  977.                     "mardi" => $mardi,
  978.                     "mercredi" => $mercredi,
  979.                     "jeudi" => $jeudi,
  980.                     "vendredi" => $vendredi,
  981.                     "samedi" => $samedi,
  982.                     "dimanche" => $dimanche,
  983.                 ));
  984.                 $lundi "";
  985.                 $mardi "";
  986.                 $mercredi "";
  987.                 $jeudi "";
  988.                 $vendredi "";
  989.                 $samedi "";
  990.                 $dimanche "";
  991.                 //QUEU
  992.                 foreach($train->getSpbParJours() as $jour){
  993.                     //Check si le jour en question est en um
  994.                     foreach($train->getJoursUm() as $jour_um){
  995.                         if($jour_um !== $jour){
  996.                             continue 2;
  997.                         }
  998.                     }
  999.                     $jour_name $jour->getName();
  1000.                     $check_train_aller_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  1001.                             "name" => $name,
  1002.                             "jour" => $jour_name,
  1003.                             "train_numero_aller" => "Q".$train->getNumero()
  1004.                     ));
  1005.                     if(!empty($check_train_aller_jours)){
  1006.                             $$jour_name "1";
  1007.                             continue;
  1008.                     }else{
  1009.                             $$jour_name "0";
  1010.                     }
  1011.                     $check_train_retour_jours $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
  1012.                             "name" => $name,
  1013.                             "jour" => $jour_name,
  1014.                             "train_numero_retour" => "Q".$train->getNumero()
  1015.                     ));
  1016.                     if(!empty($check_train_aller_jours)){
  1017.                             $$jour_name "1";
  1018.                             continue;
  1019.                     }else{
  1020.                             $$jour_name "0";
  1021.                     }
  1022.                 }
  1023.                 //pour les jours non um TETE
  1024.                 array_push($results, array(
  1025.                     "numero" => $train->getNumero(),
  1026.                     "date_debut_periode" => $date_debut_periode,
  1027.                     "date_fin_periode" => $date_fin_periode,
  1028.                     "origine" => $origine->getCode().'-BV',
  1029.                     "destination" => $destination->getCode().'-BV',
  1030.                     "particularite" => "QUEUE",
  1031.                     "lundi" => $lundi,
  1032.                     "mardi" => $mardi,
  1033.                     "mercredi" => $mercredi,
  1034.                     "jeudi" => $jeudi,
  1035.                     "vendredi" => $vendredi,
  1036.                     "samedi" => $samedi,
  1037.                     "dimanche" => $dimanche,
  1038.                 ));
  1039.             }
  1040.             /*- les lignes de train qui sont demandées en SPB mais n'existent pas dans notre planif, on les met en 0
  1041.             - les lignes de train en blanc on les met en 1
  1042.             - les lignes de train en orange = 1 
  1043.             - les lignes en rouge = 1*/
  1044.         
  1045.         //Excel
  1046.         $excel = new ExcelService;
  1047.         $excel->dataRows[] = array('N° TGV''du''au''Origine SPB''Destination SPB','Particularite''lundi''mardi''mercredi''jeudi''vendredi''samedi''dimanche');
  1048.         $excel->setDatasMultiDimensional($results);
  1049.         return $excel->getCsv($name);
  1050.     }
  1051.     #[Route('/admin/planning_temporaire/export_boucles/{name}'name'export_boucles')]
  1052.     public function export_boucles($name){
  1053.         $template $this->kernel->getProjectDir().'/xls_template/Gabarit_export_boucles.xlsx';
  1054.         //DATAS
  1055.         $datas = [];
  1056.         $plannings $this->em->getRepository(PlanningTemporaire::class)->findBy(['name' => $name], ['order_jour' => 'ASC']);
  1057.         foreach($plannings as $plan){
  1058.             $tmp = [];
  1059.             //Crochet court 0 ou 1
  1060.             $crochet_aller 0;
  1061.             $rame_aller 'US';
  1062.             $etape_aller "OUI";
  1063.             $crochet_retour 0;
  1064.             $rame_retour 'US';
  1065.             $etape_retour "OUI";
  1066.             $ouinon_aller "OUI";
  1067.             $ouinon_retour "OUI";
  1068.             $jour $this->em->getRepository(Jour::class)->findOneBy(['name' => $plan->getJour()]);
  1069.             if($plan->getTrainAller()->getJoursCrochetCourt()->contains($jour)){
  1070.                 $crochet_aller 1;
  1071.             }
  1072.             if($plan->getTrainAller()->getJoursUm()->contains($jour)){
  1073.                 $rame_aller "UM2";
  1074.             }
  1075.             if($plan->getTrainAller()->getEtapes()->isEmpty()){
  1076.                 $etape_aller "NON";
  1077.             }
  1078.             if($plan->getTrainRetour()->getJoursCrochetCourt()->contains($jour)){
  1079.                 $crochet_aller 1;
  1080.             }
  1081.             if($plan->getTrainRetour()->getJoursUm()->contains($jour)){
  1082.                 $rame_aller "UM2";
  1083.             }
  1084.             if($plan->getTrainRetour()->getEtapes()->isEmpty()){
  1085.                 $etape_aller "NON";
  1086.             }
  1087.             if($plan->isAllerSpb() == false){
  1088.                 $ouinon_aller "NON";
  1089.             }else if($plan->isAllerMultiAgent() == true){
  1090.                 $ouinon_aller "";
  1091.             }
  1092.             if($plan->isRetourSpb() == false){
  1093.                 $ouinon_aller "NON";
  1094.             }else if($plan->isRetourMultiAgent() == true){
  1095.                 $ouinon_aller "";
  1096.             }
  1097.             $tmp = [strtoupper($plan->getJour()), $plan->getTrainNumeroAller(), $plan->getTrainAller()->getAxe()->getCode(), $plan->getTrainOrigineAller(), $plan->getTrainDestinationAller(), $plan->getTrainPriseDeServiceAller(),
  1098.                 $plan->getTrainDepartAller(), $plan->getTrainArriveeAller(), $plan->getTrainFinDeServiceAller(), $crochet_aller$rame_aller$etape_aller$ouinon_aller$plan->getCorrespondance(),
  1099.                 $plan->getTrainNumeroRetour(), $plan->getTrainRetour()->getAxe()->getCode(), $plan->getTrainOrigineRetour(), $plan->getTrainDestinationRetour(), $plan->getTrainPriseDeServiceRetour(),
  1100.                 $plan->getTrainDepartRetour(), $plan->getTrainArriveeRetour(), $plan->getTrainFinDeServiceRetour(), $crochet_retour$rame_retour$etape_retour$ouinon_retour
  1101.             ];
  1102.             array_push($datas$tmp);
  1103.         }
  1104.         //Excel
  1105.         $excel = new ExcelService;
  1106.         $excel->createFromTemplate($template);
  1107.         $excel->setDatas($datas);
  1108.         return $excel->getExcel($name'A2');
  1109.     }
  1110.     #[Route('/admin/planning_temporaire/trains_par_jour/{name}'name'export_train_par_jour')]
  1111.     public function export_train_par_jour($name){
  1112.         //Les trains spb qui ont un agent ou non
  1113.         /*N°train
  1114.         Origine SPB
  1115.         Destination SPB
  1116.         Lundi O/N
  1117.         Mardi  O/N
  1118.         Mercredi  O/N
  1119.         Jeudi O/N
  1120.         Vendredi O/N
  1121.         Samedi  O/N
  1122.         Dimanche  O/N
  1123.         */
  1124.         $planning_temporaires $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
  1125.         $periode $planning_temporaires[0]->getPeriode();
  1126.         $results = array();
  1127.         $jours $this->em->getRepository(Jour::class)->findAll();
  1128.         $trains_spb $this->em->getRepository(Train::class)->getTrainSpbJour(null$periode);
  1129.         foreach($trains_spb as $train){
  1130.             $caboteur $this->isCaboteur($train);
  1131.             //Rechertche pour chaque jour? si agent ou non dans le planning
  1132.             $lundi "";
  1133.             $mardi "";
  1134.             $mercredi "";
  1135.             $jeudi "";
  1136.             $vendredi "";
  1137.             $samedi "";
  1138.             $dimanche "";
  1139.             foreach($train->getSpbParJours() as $jour){
  1140.                 switch($jour->getName()){
  1141.                     case 'lundi':
  1142.                         $lundi "N";
  1143.                         break;
  1144.                     case 'mardi':
  1145.                         $mardi "N";
  1146.                         break;
  1147.                     case 'mercredi':
  1148.                         $mercredi "N";
  1149.                         break;
  1150.                     case 'jeudi':
  1151.                         $jeudi "N";
  1152.                         break;
  1153.                     case 'vendredi':
  1154.                         $vendredi "N";
  1155.                         break;
  1156.                     case 'samedi':
  1157.                         $samedi "N";
  1158.                         break;
  1159.                     case 'dimanche':
  1160.                         $dimanche "N";
  1161.                         break;
  1162.                 }
  1163.             }
  1164.             foreach($jours as $jour){
  1165.                 //check planning
  1166.                 $check_aller $this->em->getRepository(PlanningTemporaire::class)->findBy(array('jour' => $jour->getName(), 'name' => $name'train_aller' => $train));
  1167.                 if(!empty($check_aller)){
  1168.                     switch($jour->getName()){
  1169.                         case 'lundi':
  1170.                             $lundi "O";
  1171.                             break;
  1172.                         case 'mardi':
  1173.                             $mardi "O";
  1174.                             break;
  1175.                         case 'mercredi':
  1176.                             $mercredi "O";
  1177.                             break;
  1178.                         case 'jeudi':
  1179.                             $jeudi "O";
  1180.                             break;
  1181.                         case 'vendredi':
  1182.                             $vendredi "O";
  1183.                             break;
  1184.                         case 'samedi':
  1185.                             $samedi "O";
  1186.                             break;
  1187.                         case 'dimanche':
  1188.                             $dimanche "O";
  1189.                             break;
  1190.                     }
  1191.                     continue;
  1192.                 }
  1193.                 $check_aller $this->em->getRepository(PlanningTemporaire::class)->findBy(array('jour' => $jour->getName(), 'name' => $name'train_retour' => $train));
  1194.                 $acheminement 0;
  1195.                 if(!empty($check_aller)){
  1196.                     if($check_aller[0]->isNoWork() == 1){
  1197.                         $acheminement 1;
  1198.                     }
  1199.                     switch($jour->getName()){
  1200.                         case 'lundi':
  1201.                             $lundi "O";
  1202.                             if($acheminement == 1){
  1203.                                 $lundi "ND";
  1204.                             }
  1205.                             break;
  1206.                         case 'mardi':
  1207.                             $mardi "O";
  1208.                             if($acheminement == 1){
  1209.                                 $mardi "ND";
  1210.                             }
  1211.                             break;
  1212.                         case 'mercredi':
  1213.                             $mercredi "O";
  1214.                             if($acheminement == 1){
  1215.                                 $mercredi "ND";
  1216.                             }
  1217.                             break;
  1218.                         case 'jeudi':
  1219.                             $jeudi "O";
  1220.                             if($acheminement == 1){
  1221.                                 $jeudi "ND";
  1222.                             }
  1223.                             break;
  1224.                         case 'vendredi':
  1225.                             $vendredi "O";
  1226.                             if($acheminement == 1){
  1227.                                 $vendredi "ND";
  1228.                             }
  1229.                             break;
  1230.                         case 'samedi':
  1231.                             $samedi "O";
  1232.                             if($acheminement == 1){
  1233.                                 $samedi "ND";
  1234.                             }
  1235.                             break;
  1236.                         case 'dimanche':
  1237.                             $dimanche "O";
  1238.                             if($acheminement == 1){
  1239.                                 $dimanche "ND";
  1240.                             }
  1241.                             break;
  1242.                     }
  1243.                     continue;
  1244.                 }
  1245.             }
  1246.             array_push($results, array(
  1247.                 $train->getNumero(),
  1248.                 $train->getOrigineSpb(),
  1249.                 $train->getDestinationSpb(),
  1250.                 $lundi,
  1251.                 $mardi,
  1252.                 $mercredi,
  1253.                 $jeudi,
  1254.                 $vendredi,
  1255.                 $samedi,
  1256.                 $dimanche,
  1257.                 $caboteur
  1258.             ));
  1259.         }
  1260.         //Excel
  1261.         $excel = new ExcelService;
  1262.         $excel->dataRows[] = array('numero''origine_spb''destination_spb''lundi''mardi''mercredi''jeudi''vendredi''samedi''dimanche''caboteur');
  1263.         $excel->setDatas($results);
  1264.         return $excel->getExcel($name);
  1265.     }
  1266.     #[Route('/admin/planning_temporaire/{name}/{pole}'name'display_planning_temporaire_pole')]
  1267.     public function display_planning_temporaire_pole($name$pole):Response{
  1268.         $gare $this->em->getRepository(Gare::class)->findOneBy(array('code' => $pole));
  1269.         $temps_semaine_par_agents $this->em->getRepository(PlanningTemporaire::class)->getTempsSemaineParAgent($name$gare);
  1270.         $i 0;
  1271.         foreach($temps_semaine_par_agents as $temps_agent){
  1272.             //$temps_semaine_par_agents[$i]['temps_travail'] = str_pad((int)($temps_semaine_par_agents[$i]['temps_travail']/60),2,"0",STR_PAD_LEFT).':'.str_pad(($temps_semaine_par_agents[$i]['temps_travail']%60),2,"0",STR_PAD_LEFT);
  1273.             $plans $this->em->getRepository(PlanningTemporaire::class)->getByName($name$temps_agent['plan']->getAgent()->getId());
  1274.             $temps_semaine_par_agents[$i]['plannings'] = $plans;
  1275.             $i++;
  1276.         }
  1277.         //dd($temps_semaine_par_agents);
  1278.         //Chaque agent ?
  1279.         //Puis recherche planning de cette periode ?
  1280.         return $this->render('admin/display_planning_temporaire_pole.html.twig', array('temps_semaine_par_agent' => $temps_semaine_par_agents'gare' => $gare));
  1281.     }
  1282.     #[Route('/admin/add_train_limite'name'add_train_limite')]
  1283.     public function add_train_limite(Request $request):Response{
  1284.         $periodes $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
  1285.         if($request->isMethod('POST')){
  1286.             $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  1287.             $train $this->em->getRepository(Train::class)->find($request->request->get('train'));
  1288.             $request->request->get('destination');
  1289.             $origine null;
  1290.             $destination null;
  1291.             if($request->request->get('origine') !== null){
  1292.                 $origine $this->em->getRepository(Gare::class)->find($request->request->get('origine'));
  1293.             }
  1294.             if($request->request->get('destination') !== null){
  1295.                 $destination $this->em->getRepository(Gare::class)->find($request->request->get('destination'));
  1296.             }
  1297.             $json_dates $request->request->get('json');
  1298.             $str_dates null;
  1299.             $json_horaires json_decode($json_datestrue);
  1300.             switch($json_horaires['modeDates']){
  1301.                 case "range":
  1302.                     $str_dates 'Du '.$json_horaires['datesRange']['dateStart'].' au '.$json_horaires['datesRange']['dateFinish'];
  1303.                     break;
  1304.                 case 'multiple':
  1305.                     $str_dates.= 'Les ';
  1306.                     $i 0;
  1307.                     foreach($json_horaires['datesMultiple']['dates'] as $date){
  1308.                         if($i>0){
  1309.                             $str_dates.= ', ';
  1310.                         }
  1311.                         $str_dates.= $date;
  1312.                         $i++;
  1313.                     }
  1314.                     break;
  1315.                 case 'single':
  1316.                     $str_dates 'Le '.$json_horaires['dateSingle']['dates'][0];
  1317.                     break;
  1318.             }
  1319.             $plan_gen $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1'periode' => $periode));
  1320.             $alea = new AleaTrainLimite;
  1321.             $alea->setJson($json_dates)
  1322.                 ->setCommentaire($request->request->get('commentaire'))
  1323.                 ->setPeriode($periode)
  1324.                 ->setTrain($train)
  1325.                 ->setVersion($plan_gen->getName())
  1326.                 ->setTextDates($str_dates)
  1327.                 ->setNewOrigine($origine)
  1328.                 ->setNewDestination($destination)
  1329.                 ->setAvanceDepart($request->request->get('avance_depart'))
  1330.                 ->setRetardDepart($request->request->get('retard_depart'))
  1331.                 ->setAvanceArrivee($request->request->get('avance_arrivee'))
  1332.                 ->setRetardArrivee($request->request->get('retard_arrivee'))
  1333.             ;
  1334.             $this->em->persist($alea);
  1335.             $this->em->flush();
  1336.             //IMPACTS
  1337.             //RECHERCHE PLANNING PERMANENT OU UN/DES AGENTS SONT CONCERNES
  1338.             switch($json_horaires['modeDates']){
  1339.                 case "range":
  1340.                     $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  1341.                     $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  1342.                     $interval $date_debut->diff($date_fin);
  1343.                     $nb_jour $interval->d;
  1344.                     for ($i=0;$i<$nb_jour+1;$i++){
  1345.                         $date = clone($date_debut);
  1346.                         if($i 0){
  1347.                             $date->add(new DateInterval('P'.$i.'D'));
  1348.                         }
  1349.                         $this->addImpact($this->jours_[$date->format('N')], $periode$trainnull$json_dates$str_dates'Train limité: '.$train->getNumero(), 'limite'$date->format('d/m/Y'), $origine$destination$alea);
  1350.                     }
  1351.                     break;
  1352.                 case 'multiple':
  1353.                     foreach($json_horaires['datesMultiple']['dates'] as $date){
  1354.                         $date date_create_from_format('d/m/Y'$date);
  1355.                         $this->addImpact($this->jours_[$date->format('N')], $periode$trainnull$json_dates$str_dates'Train limité: '.$train->getNumero(), 'limite'$date->format('d/m/Y'), $origine$destination$alea);
  1356.                     }
  1357.                     break;
  1358.                 case 'single':
  1359.                     $date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  1360.                     $this->addImpact($this->jours_[$date->format('N')], $periode$trainnull$json_dates$str_dates'Train limité: '.$train->getNumero(), 'limite'$date->format('d/m/Y'), $origine$destination$alea);
  1361.                     break;
  1362.             }
  1363.             $this->em->flush();
  1364.             return $this->redirect($this->admin_url_generator->setController(AleaTrainLimiteCrudController::class)->setAction(Action::INDEX)->generateUrl());
  1365.         }
  1366.         return $this->render('admin/impacts/add_train_limite.html.twig', array('periodes' => $periodes));
  1367.     }
  1368.     #[Route('/admin/ajax_planning_load_train'name'ajax_planning_load_train')]
  1369.     public function ajax_planning_load_train(Request $request):Response{
  1370.         $array_trains = array();
  1371.         $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  1372.         $trains =  $this->em->getRepository(Train::class)->getPermTrainsAller($periode);
  1373.         foreach($trains as $tr){
  1374.             array_push($array_trains, array(
  1375.                 'id' => $tr->getId(),
  1376.                 'name' => $tr->getNumero().' '.($tr->getOrigineSpb()!==null?$tr->getOrigineSpb()->getCode():$tr->getOrigine()->getCode()).' -> '.($tr->getDestinationSpb()!==null?$tr->getDestinationSpb()->getCode():$tr->getDestination()->getCode())
  1377.             ));
  1378.         }
  1379.         $trains $this->em->getRepository(Train::class)->getPermTrainsRetour($periode);
  1380.         foreach($trains as $tr){
  1381.             array_push($array_trains, array(
  1382.                 'id' => $tr->getId(),
  1383.                 'name' => $tr->getNumero().' '.($tr->getOrigineSpb()!==null?$tr->getOrigineSpb()->getCode():$tr->getOrigine()->getCode()).' -> '.($tr->getDestinationSpb()!==null?$tr->getDestinationSpb()->getCode():$tr->getDestination()->getCode())
  1384.             ));
  1385.         }
  1386.         $array_trains array_unique($array_trainsSORT_REGULAR);
  1387.         array_multisort(array_column($array_trains'name'), SORT_ASC$array_trains);
  1388.         return new JsonResponse(array('trains' => $array_trains));
  1389.     }
  1390.     #[Route('/admin/add_train_supprime'name'add_train_supprime')]
  1391.     public function add_train_supprime(Request $request):Response{
  1392.         $periodes $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
  1393.         if($request->isMethod('POST')){
  1394.             $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  1395.             $train $this->em->getRepository(Train::class)->find($request->request->get('train'));
  1396.             $json_dates $request->request->get('json');
  1397.             $str_dates null;
  1398.             $json_horaires json_decode($json_datestrue);
  1399.             switch($json_horaires['modeDates']){
  1400.                 case "range":
  1401.                     $str_dates 'Du '.$json_horaires['datesRange']['dateStart'].' au '.$json_horaires['datesRange']['dateFinish'];
  1402.                     break;
  1403.                 case 'multiple':
  1404.                     $str_dates.= 'Les ';
  1405.                     $i 0;
  1406.                     foreach($json_horaires['datesMultiple']['dates'] as $date){
  1407.                         if($i>0){
  1408.                             $str_dates.= ', ';
  1409.                         }
  1410.                         $str_dates.= $date;
  1411.                         $i++;
  1412.                     }
  1413.                     break;
  1414.                 case 'single':
  1415.                     $str_dates 'Le '.$json_horaires['dateSingle']['dates'][0];
  1416.                     break;
  1417.             }
  1418.             $plan_gen $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1'periode' => $periode));
  1419.             $alea = new AleaTrainSupprime;
  1420.             $alea->setJson($json_dates)
  1421.                 ->setCommentaire($request->request->get('commentaire'))
  1422.                 ->setPeriode($periode)
  1423.                 ->setTrain($train)
  1424.                 ->setVersion($plan_gen->getName())
  1425.                 ->setTextDates($str_dates)
  1426.             ;
  1427.             $this->em->persist($alea);
  1428.             $this->em->flush();
  1429.             //IMPACTS
  1430.             //RECHERCHE PLANNING PERMANENT OU UN/DES AGENTS SONT CONCERNES
  1431.             switch($json_horaires['modeDates']){
  1432.                 case "range":
  1433.                     $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  1434.                     $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  1435.                     $interval $date_debut->diff($date_fin);
  1436.                     $nb_jour $interval->d;
  1437.                     for ($i=0;$i<$nb_jour+1;$i++){
  1438.                         $date = clone($date_debut);
  1439.                         if($i 0){
  1440.                             $date->add(new DateInterval('P'.$i.'D'));
  1441.                         }
  1442.                         $this->addImpact($this->jours_[$date->format('N')], $periode$trainnull$json_dates$str_dates'Train supprimé: '.$train->getNumero(), 'supprime'$date->format('d/m/Y'));
  1443.                     }
  1444.                     break;
  1445.                 case 'multiple':
  1446.                     foreach($json_horaires['datesMultiple']['dates'] as $date){
  1447.                         $date date_create_from_format('d/m/Y'$date);
  1448.                         $this->addImpact($this->jours_[$date->format('N')], $periode$trainnull$json_dates$str_dates'Train supprimé: '.$train->getNumero(), 'supprime'$date->format('d/m/Y'));
  1449.                     }
  1450.                     break;
  1451.                 case 'single':
  1452.                     $date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  1453.                     $this->addImpact($this->jours_[$date->format('N')], $periode$trainnull$json_dates$str_dates'Train supprimé: '.$train->getNumero(), 'supprime'$date->format('d/m/Y'));
  1454.                     break;
  1455.             }
  1456.             $this->em->flush();
  1457.             return $this->redirect($this->admin_url_generator->setController(AleaTrainSupprimeCrudController::class)->setAction(Action::INDEX)->generateUrl());
  1458.         }
  1459.         return $this->render('admin/impacts/add_train_supprime.html.twig', array('periodes' => $periodes));
  1460.     }
  1461.     #[Route('/admin/add_agent_indisponible'name'add_agent_indisponible')]
  1462.     public function add_agent_indisponible(Request $request):Response{
  1463.         $periodes $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
  1464.         if($request->isMethod('POST')){
  1465.             $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  1466.             $agent $this->em->getRepository(Agent::class)->find($request->request->get('agent'));
  1467.             $json_dates $request->request->get('json');
  1468.             $str_dates null;
  1469.             $json_horaires json_decode($json_datestrue);
  1470.             switch($json_horaires['modeDates']){
  1471.                 case "range":
  1472.                     $str_dates 'Du '.$json_horaires['datesRange']['dateStart'].' au '.$json_horaires['datesRange']['dateFinish'];
  1473.                     break;
  1474.                 case 'multiple':
  1475.                     $str_dates.= 'Les ';
  1476.                     $i 0;
  1477.                     foreach($json_horaires['datesMultiple']['dates'] as $date){
  1478.                         if($i>0){
  1479.                             $str_dates.= ', ';
  1480.                         }
  1481.                         $str_dates.= $date;
  1482.                         $i++;
  1483.                     }
  1484.                     break;
  1485.                 case 'single':
  1486.                     $str_dates 'Le '.$json_horaires['dateSingle']['dates'][0];
  1487.                     break;
  1488.             }
  1489.             $plan_gen $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1'periode' => $periode));
  1490.             $alea = new AleaAgentIndisponible;
  1491.             $alea->setJson($json_dates)
  1492.                 ->setCommentaire($request->request->get('commentaire'))
  1493.                 ->setPeriode($periode)
  1494.                 ->setAgent($agent)
  1495.                 ->setVersion($plan_gen->getName())
  1496.                 ->setTextDates($str_dates)
  1497.             ;
  1498.             $this->em->persist($alea);
  1499.             //IMPACTS
  1500.             //RECHERCHE PLANNING PERMANENT OU UN/DES AGENTS SONT CONCERNES
  1501.             switch($json_horaires['modeDates']){
  1502.                 case "range":
  1503.                     $date_debut date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  1504.                     $date_fin date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateFinish']);
  1505.                     $interval $date_debut->diff($date_fin);
  1506.                     $nb_jour $interval->d;
  1507.                     for ($i=0;$i<$nb_jour+1;$i++){
  1508.                         $date date_create_from_format('d/m/Y'$json_horaires['datesRange']['dateStart']);
  1509.                         if($i 0){
  1510.                             $date->add(new DateInterval('P'.$i.'D'));
  1511.                         }
  1512.                         //RECHERCHE TOUS LES TRAINS DU JOUR OU C'EST CET AGENT
  1513.                         //$plans = $this->em->getRepository(PlanningTemporaire::class)->getAgentsPerm($periode, $agent, $this->jours_[$date->format('N')]);
  1514.                         //foreach($plans as $p){
  1515.                             //SI RESERVE
  1516.                             //if($p->getTrainAller() == null && $p->getTrainRetour() == null){
  1517.                         $this->addImpact($this->jours_[$date->format('N')], $periodenull$agent$json_dates$str_dates'Agent indisponible''agent'$date->format('d/m/Y'));
  1518.                             //}else{
  1519.                             //    $this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible', 'agent', $date->format('d/m/Y'));
  1520.                             //}
  1521.                         //}
  1522.                     }
  1523.                     break;
  1524.                 case 'multiple':
  1525.                     foreach($json_horaires['datesMultiple']['dates'] as $date){
  1526.                         $date date_create_from_format('d/m/Y'$date);
  1527.                         //$plans = $this->em->getRepository(PlanningTemporaire::class)->getAgentsPerm($periode, $agent, $this->jours_[$date->format('N')]);
  1528.                         //foreach($plans as $p){
  1529.                         //    if($p->getTrainAller() == null && $p->getTrainRetour() == null){
  1530.                         //        $this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible pour réserve', 'agent', $date->format('d/m/Y'));
  1531.                         //    }else{
  1532.                                 $this->addImpact($this->jours_[$date->format('N')], $periodenull$agent$json_dates$str_dates'Agent indisponible''agent'$date->format('d/m/Y'));
  1533.                         //    }
  1534.                         //}
  1535.                     }
  1536.                     break;
  1537.                 case 'single':
  1538.                     $date date_create_from_format('d/m/Y'$json_horaires['dateSingle']['dates'][0]);
  1539.                     //$plans = $this->em->getRepository(PlanningTemporaire::class)->getAgentsPerm($periode, $agent, $this->jours_[$date->format('N')]);
  1540.                     //foreach($plans as $p){
  1541.                     //    if($p->getTrainAller() == null && $p->getTrainRetour() == null){
  1542.                     //        $this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible pour réserve', 'agent', $date->format('d/m/Y'));
  1543.                     //    }else{
  1544.                             $this->addImpact($this->jours_[$date->format('N')], $periodenull$agent$json_dates$str_dates'Agent indisponible''agent'$date->format('d/m/Y'));
  1545.                     //    }
  1546.                     //}
  1547.                     break;
  1548.             }
  1549.             $this->em->flush();
  1550.             return $this->redirect($this->admin_url_generator->setController(AleaAgentIndisponibleCrudController::class)->setAction(Action::INDEX)->generateUrl());
  1551.         }
  1552.         return $this->render('admin/impacts/add_agent_indisponible.html.twig', array('periodes' => $periodes));
  1553.     }
  1554.     #[Route('/admin/ajax_planning_load_agents'name'ajax_planning_load_agents')]
  1555.     public function ajax_planning_load_agents(Request $request):Response{
  1556.         $array_agents= array();
  1557.         $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  1558.         $agents $this->em->getRepository(Agent::class)->getPermAgents($periode);
  1559.         foreach($agents as $a){
  1560.             array_push($array_agents, array(
  1561.                 'id' => $a->getId(),
  1562.                 'name' => $a->getPrenom().' '.$a->getNom()
  1563.             ));
  1564.         }
  1565.         return new JsonResponse(array('agents' => $array_agents));
  1566.     }
  1567.     #[Route('/admin/ajax_planning_load_gare'name'ajax_planning_load_gare')]
  1568.     public function ajax_planning_load_gare(Request $request):Response{
  1569.         $array_gares = array();
  1570.         $periode $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
  1571.         $train $this->em->getRepository(Train::class)->find($request->request->get('train'));
  1572.         foreach($train->getEtapes() as $etape){
  1573.             array_push($array_gares, [
  1574.                 'id' => $etape->getGare()->getId(),
  1575.                 'name' => $etape->getGare()->getCode()
  1576.             ]);
  1577.         }
  1578.         return new JsonResponse(array('gares' => $array_gares));
  1579.     }
  1580.     //Permanent
  1581.     #[Route('/admin/planning_actif'name'planning_actif')]
  1582.     public function planning_actif():Response{
  1583.         $periodes $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
  1584.         $poles $this->em->getRepository(Agent::class)->getPoles();
  1585.         return $this->render('admin/planning_actif.html.twig', array('periodes' => $periodes'poles' => $poles));
  1586.     }
  1587.     #[Route('/admin/planning_actif/{periode_name}/{pole}/{date_debut}/{date_fin}'name'display_planning_actif_pole')]
  1588.     public function display_planning_actif_pole(Request $request$periode_name$pole$date_debut$date_fin):Response{
  1589.         $temp = array("pouet""kpkpkpkp""aedadeadza");
  1590.         $date_debut date_create_from_format('Y-m-d'$date_debut);
  1591.         $date_debut->setTime(0,0,0);
  1592.         $date_fin date_create_from_format('Y-m-d'$date_fin);
  1593.         $date_fin->setTime(23,59,59);
  1594.         $periode $this->em->getRepository(Periode::class)->findOneBy(array('name' => $periode_name));
  1595.         $periode_actif $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('periode' => $periode'valide' => 1));
  1596.         $gare $this->em->getRepository(Gare::class)->findOneBy(array('code' => $pole));
  1597.         $interval $date_debut->diff($date_fin);
  1598.         $array_dates = [];
  1599.         array_push($array_dates$date_debut->format('d/m/Y'));
  1600.         for($i=1;$i<=$interval->d;$i++){
  1601.             $tmp_date = clone $date_debut;
  1602.             $tmp_date->add(new DateInterval('P'.$i.'D'));
  1603.             array_push($array_dates$tmp_date->format('d/m/Y'));
  1604.         }
  1605.         $plans $this->em->getRepository(PlanningTemporaire::class)->getPlanActif($periode_actif->getName(), $gare);
  1606.         $i 0;
  1607.         foreach($plans as $plan){
  1608.             //CHECK SI IMPACT A LA DATE ANNULE
  1609.             $impacts $this->em->getRepository(Impact::class)->findBy(array('planning_temporaire' => $plan));
  1610.             foreach($impacts as $imp){
  1611.                 //Verifier
  1612.                 if(in_array($imp->getDate(), $array_dates) == true){
  1613.                     switch($imp->getStatutDecision()->getName()){
  1614.                         case 'annule':
  1615.                             unset($plans[$i]);
  1616.                             break;
  1617.                         case 'modifie':
  1618.                             $heures $this->calculNewDates($imp);
  1619.                             $plans[$i]['train_depart_aller'] = $heures['heure_depart_aller'];
  1620.                             $plans[$i]['train_arrivee_aller'] = $heures['heure_arrivee_aller'];
  1621.                             $plans[$i]['train_depart_retour'] = $heures['heure_depart_retour'];
  1622.                             $plans[$i]['train_arrivee_retour'] = $heures['heure_arrivee_retour'];
  1623.                             $plans[$i]['train_prise_de_service_aller'] = $heures['heure_prise_de_service_aller'];
  1624.                             $plans[$i]['train_fin_de_service_aller'] = $heures['heure_fin_de_service_aller'];
  1625.                             $plans[$i]['train_prise_de_service_retour'] = $heures['heure_prise_de_service_retour'];
  1626.                             $plans[$i]['train_fin_de_service_retour'] = $heures['heure_fin_de_service_retour'];
  1627.                             //CALCULER PRISE ET FIN DE SERVICE
  1628.                             break;
  1629.                         case 'agent':
  1630.                             $plans[$i]['agent_name'] = $imp->getNewAgent()->getNom().' '.$imp->getNewAgent()->getPrenom();
  1631.                             $a $this->em->getRepository(Agent::class)->findArray($imp->getNewAgent()->getId());
  1632.                             $plans[$i]['agent'] = $a;
  1633.                             break;
  1634.                         case 'boucle':
  1635.                             if($imp->getNewTrainAllerNumero() !== null){
  1636.                                 $plans[$i]['train_numero_aller'] = $imp->getNewTrainAllerNumero();
  1637.                                 $plans[$i]['train_depart_aller']= $imp->getNewHoraireDepartAller();
  1638.                                 $plans[$i]['train_arrivee_aller']= $imp->getNewHoraireArriveeAller();
  1639.                                 //CALCULER PRISE ET FIN DE SERVICE
  1640.                             }
  1641.                             if($imp->getNewTrainRetourNumero() !== null){
  1642.                                 $plans[$i]['train_numero_retour'] = $imp->getNewTrainRetourNumero();
  1643.                                 $plans[$i]['train_depart_retour']= $imp->getNewHoraireDepartRetour();
  1644.                                 $plans[$i]['train_arrivee_retour']= $imp->getNewHoraireArriveeRetour();
  1645.                                 //CALCULER PRISE ET FIN DE SERVICE
  1646.                             }
  1647.                             break;
  1648.                     }
  1649.                 }
  1650.             }
  1651.             $i++;
  1652.         }
  1653.         return $this->render('admin/planning_actif_pole.html.twig', array('plans' => $plans'gare' => $gare'periode' => $periode'date_debut' => $date_debut'date_fin' => $date_fin ));
  1654.     }
  1655.     
  1656.     private function calculNewDates($imp){
  1657.         $train_aller $imp->getPlanningTemporaire()->getTrainAller();
  1658.         $train_retour $imp->getPlanningTemporaire()->getTrainRetour();
  1659.         $heure_depart_aller $imp->getPlanningTemporaire()->getTrainDepartAller();
  1660.         $heure_arrivee_aller$imp->getPlanningTemporaire()->getTrainArriveeAller();
  1661.         $heure_prise_de_service_aller $imp->getPlanningTemporaire()->getTrainPriseDeServiceAller();
  1662.         $heure_fin_de_service_aller $imp->getPlanningTemporaire()->getTrainFinDeServiceAller();
  1663.         $heure_depart_retour $imp->getPlanningTemporaire()->getTrainDepartRetour();
  1664.         $heure_arrivee_retour $imp->getPlanningTemporaire()->getTrainArriveeRetour();
  1665.         $heure_prise_de_service_retour $imp->getPlanningTemporaire()->getTrainPriseDeServiceRetour();
  1666.         $heure_fin_de_service_retour $imp->getPlanningTemporaire()->getTrainFinDeServiceRetour();
  1667.         
  1668.         if($imp->getNewHoraireDepartAller() !== null){
  1669.             $heure_depart_aller $imp->getNewHoraireDepartAller();
  1670.         }
  1671.         if($imp->getNewHoraireArriveeAller() !== null){
  1672.             $heure_arrivee_aller $imp->getNewHoraireArriveeAller();
  1673.         }
  1674.         $date_depart_aller \DateTime::createFromFormat('H:i'$heure_depart_aller);
  1675.         $date_arrivee_aller \DateTime::createFromFormat('H:i'$heure_arrivee_aller);
  1676.         if($imp->getNewHoraireDepartAller() !== null || $imp->getNewHoraireArriveeAller() !== null){
  1677.             //CALCUL PRISE ET FIN DE SERVICE
  1678.             $date_prise_de_service_aller = clone $date_depart_aller;
  1679.             if($train_aller->getOrigineSpb()->getTempsPriseDeServiceAller() != null){
  1680.                 $i= new \DateInterval('PT'.$train_aller->getOrigineSpb()->getTempsPriseDeServiceAller().'M');
  1681.                 $date_prise_de_service_aller->sub($i);
  1682.                 $heure_prise_de_service_aller $date_prise_de_service_aller->format('H:i');
  1683.             }
  1684.             $date_fin_de_service_aller = clone $date_arrivee_aller;
  1685.             if($train_aller->getOrigineSpb()->getTempsFinDeServiceAller() != null){
  1686.                 $i = new \DateInterval('PT'.$train_aller->getDestinationSpb()->getTempsFinDeServiceAller().'M');
  1687.                 $date_fin_de_service_aller->add($i);
  1688.                 $heure_fin_de_service_aller $date_fin_de_service_aller->format('H:i');
  1689.             }
  1690.         }
  1691.         if($imp->getNewHoraireDepartRetour() !== null){
  1692.             $heure_depart_retour $imp->getNewHoraireDepartRetour();
  1693.         }
  1694.         if($imp->getNewHoraireArriveeRetour() !== null){
  1695.             $heure_arrivee_retour $imp->getNewHoraireArriveeRetour();
  1696.         }
  1697.         $date_depart_retour \DateTime::createFromFormat('H:i'$heure_depart_retour);
  1698.         $date_arrivee_retour \DateTime::createFromFormat('H:i'$heure_arrivee_retour);
  1699.         if($imp->getNewHoraireDepartRetour() !== null || $imp->getNewHoraireArriveeRetour() !== null){
  1700.             //CALCUL PRISE ET FIN DE SERVICE
  1701.             $date_prise_de_service_retour = clone $date_depart_retour;
  1702.             if($train_retour->getOrigineSpb()->getTempsPriseDeServiceRetour() != null){
  1703.                 $i= new \DateInterval('PT'.$train_retour->getOrigineSpb()->getTempsPriseDeServiceRetour().'M');
  1704.                 $date_prise_de_service_retour->sub($i);
  1705.                 $heure_prise_de_service_retour $date_prise_de_service_retour->format('H:i');
  1706.             }
  1707.             $date_fin_de_service_retour = clone $date_arrivee_retour;
  1708.             if($train_retour->getOrigineSpb()->getTempsFinDeServiceRetour() != null){
  1709.                 $i = new \DateInterval('PT'.$train_retour->getDestinationSpb()->getTempsFinDeServiceRetour().'M');
  1710.                 $date_fin_de_service_retour->add($i);
  1711.                 $heure_fin_de_service_retour $date_fin_de_service_retour->format('H:i');
  1712.             }
  1713.         }
  1714.         return [
  1715.             'heure_depart_aller' => $heure_depart_aller,
  1716.             'heure_arrivee_aller' => $heure_arrivee_aller,
  1717.             'heure_prise_de_service_aller' => $heure_prise_de_service_aller,
  1718.             'heure_fin_de_service_aller' => $heure_fin_de_service_aller,
  1719.             'heure_depart_retour' => $heure_depart_retour,
  1720.             'heure_arrivee_retour' => $heure_arrivee_retour,
  1721.             'heure_prise_de_service_retour' => $heure_prise_de_service_retour,
  1722.             'heure_fin_de_service_retour' => $heure_fin_de_service_retour
  1723.         ];
  1724.     }
  1725.     private function addImpact($jour$periode$train null$agent null$json_dates null$str_datesnull$descriptionnull$typenull$datenull$origine null$destination null$alea_limite null){
  1726.         $statut_decision $this->em->getRepository(DecisionStatut::class)->find(5);
  1727.         $statut $this->em->getRepository(ImpactStatut::class)->find(1);
  1728.         $plan_gen $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1'periode' => $periode));
  1729.         $datetime date_create_from_format('d/m/Y'$date);
  1730.         if($agent !== null){
  1731.             $perms $this->em->getRepository(PlanningTemporaire::class)->findBy(['agent' => $agent'jour' => $jour'periode' => $periode'name' => $plan_gen->getName()]);
  1732.             foreach($perms as $perm){
  1733.                 if($perm->getTrainAller() == null && $perm->getTrainRetour() == null){
  1734.                     $description.= ' pour réserve';
  1735.                 }
  1736.                 $impact = new Impact;
  1737.                 $impact
  1738.                     ->setStatutDecision($statut_decision)
  1739.                     ->setStatut($statut)
  1740.                     ->setPeriode($periode)
  1741.                     ->setDescription($description)
  1742.                     ->setVersion($plan_gen->getName())
  1743.                     ->setType($type)
  1744.                     ->setTrainAller($perm->getTrainAller())
  1745.                     ->setTrainRetour($perm->getTrainRetour())
  1746.                     ->setJson($json_dates)
  1747.                     ->setTextDates($str_dates)
  1748.                     ->setAgent($perm->getAgent())
  1749.                     ->setDate($date)
  1750.                     ->setDatetime($datetime)
  1751.                     ->setJour($jour)
  1752.                     ->setPlanningTemporaire($perm)
  1753.                     ->setAleaLimite($alea_limite)
  1754.                 ;
  1755.                 $this->em->persist($impact);
  1756.             }
  1757.         }else{
  1758.             $perms_aller $this->em->getRepository(PlanningTemporaire::class)->findBy(['jour' => $jour'periode' => $periode'train_aller' => $train'name' => $plan_gen->getName()]);
  1759.             foreach($perms_aller as $perm){
  1760.                 $impact = new Impact;
  1761.                 $impact
  1762.                     ->setStatutDecision($statut_decision)
  1763.                     ->setImpactTrain($train)
  1764.                     ->setStatut($statut)
  1765.                     ->setPeriode($periode)
  1766.                     ->setDescription($description)
  1767.                     ->setVersion($plan_gen->getName())
  1768.                     ->setType($type)
  1769.                     ->setTrainAller($train)
  1770.                     ->setTrainRetour($perm->getTrainRetour())
  1771.                     ->setJson($json_dates)
  1772.                     ->setTextDates($str_dates)
  1773.                     ->setAgent($perm->getAgent())
  1774.                     ->setDate($date)
  1775.                     ->setNewDestinationAller($destination)
  1776.                     ->setNewOrigineAller($origine)
  1777.                     ->setDatetime($datetime)
  1778.                     ->setJour($jour)
  1779.                     ->setPlanningTemporaire($perm)
  1780.                     ->setAleaLimite($alea_limite)
  1781.                 ;
  1782.                 $this->em->persist($impact);
  1783.             }
  1784.             $perms_retour $this->em->getRepository(PlanningTemporaire::class)->findBy(['jour' => $jour'periode' => $periode'train_retour' => $train'name' => $plan_gen->getName()]);
  1785.             foreach($perms_retour as $perm){
  1786.                 $impact = new Impact;
  1787.                 $impact
  1788.                     ->setStatutDecision($statut_decision)
  1789.                     ->setImpactTrain($train)    
  1790.                     ->setStatut($statut)
  1791.                     ->setPeriode($periode)
  1792.                     ->setDescription($description)
  1793.                     ->setVersion($plan_gen->getName())
  1794.                     ->setType($type)
  1795.                     ->setTrainAller($perm->getTrainAller())
  1796.                     ->setTrainRetour($train)
  1797.                     ->setJson($json_dates)
  1798.                     ->setTextDates($str_dates)
  1799.                     ->setAgent($perm->getAgent())
  1800.                     ->setDate($date)
  1801.                     ->setNewDestinationRetour($destination)
  1802.                     ->setNewOrigineRetour($origine)
  1803.                     ->setDatetime($datetime)
  1804.                     ->setJour($jour)
  1805.                     ->setPlanningTemporaire($perm)
  1806.                     ->setAleaLimite($alea_limite)
  1807.                 ;
  1808.                 $this->em->persist($impact);
  1809.             }
  1810.         }
  1811.         return true;
  1812.     }
  1813.     public function configureDashboard(): Dashboard
  1814.     {
  1815.         return Dashboard::new()
  1816.             ->setTitle('NICOLLIN PLANIF SPB')
  1817.             ->setFaviconPath('img/favicon.svg')    
  1818.         ;
  1819.     }
  1820.     public function configureMenuItems(): iterable
  1821.     {
  1822.         $menu = [
  1823.             MenuItem::linkToDashboard('Dashboard''fa fa-home'),
  1824.             
  1825.             MenuItem::section("Prévisionnel"),
  1826.             MenuItem::subMenu('Planning prévisionnel''')->setSubItems([
  1827.                 MenuItem::linkToRoute('Ajouter horaire/agent''''add_manual'),
  1828.                 MenuItem::linkToCrud('Ajouts manuels'''AjoutManuel::class),
  1829.                 MenuItem::linkToRoute('Générer planning v2''''generer_planning_v2'),
  1830.                 MenuItem::linkToCrud('Plannings générés'''PlanningTemporaireGenere::class),
  1831.                 MenuItem::linkToRoute('Calendrier temporaire''''display_calendar'),
  1832.             ]),
  1833.             MenuItem::section("Suivi d'exploitation"),
  1834.             MenuItem::subMenu("Aléas"'')->setSubItems([
  1835.                 MenuItem::linkToCrud('Trains limités'''AleaTrainLimite::class),
  1836.                 MenuItem::linkToCrud('Trains supprimés'''AleaTrainSupprime::class),
  1837.                 MenuItem::linkToCrud('Agents indisponibles'''AleaAgentIndisponible::class),
  1838.             ]),
  1839.             MenuItem::linkToCrud('Impacts par jour'''Impact::class),
  1840.             MenuItem::linkToRoute('Planning actif''''planning_actif'),
  1841.             MenuItem::subMenu("Partage d'info"'')->setSubItems([
  1842.                 
  1843.             ]),
  1844.             MenuItem::section("Données"),
  1845.             MenuItem::subMenu('Agents''')->setSubItems([
  1846.                 MenuItem::linkToCrud('Tous'''Agent::class),
  1847.                 MenuItem::linkToCrud('Actifs'''Agent::class)->setQueryParameter('actif'1),
  1848.             ]),
  1849.             MenuItem::linkToCrud('Gares'''Gare::class),
  1850.             MenuItem::linkToCrud('Trains'''Train::class),
  1851.             MenuItem::linkToCrud('Axes'''Axe::class),
  1852.             MenuItem::linkToCrud('Contrats'''Contrat::class),
  1853.             MenuItem::linkToCrud('Périodes'''Periode::class),
  1854.             MenuItem::linkToCrud('Utilisateurs'''User::class),
  1855.             MenuItem::linkToCrud('Pattern jours'''PatternJour::class),
  1856.             MenuItem::linkToCrud('Paramétrage'''Parametre::class)->setAction('edit')->setQueryParameter('entityId'1),
  1857.             MenuItem::linkToCrud('Sens de parcours'''Jour::class)->setAction('index')
  1858.         ];
  1859.         return $menu;
  1860.     }
  1861. }