<?php
namespace App\Controller\Admin;
use App\Entity\Agent;
use App\Entity\AjoutManuel;
use App\Entity\AleaAgentIndisponible;
use App\Entity\AleaTrainLimite;
use App\Entity\AleaTrainSupprime;
use App\Entity\Axe;
use App\Entity\Contrat;
use App\Entity\DecisionStatut;
use App\Entity\Gare;
use App\Entity\Impact;
use App\Entity\ImpactStatut;
use App\Entity\Jour;
use App\Entity\Parametre;
use App\Entity\PatternJour;
use App\Entity\Periode;
use App\Entity\PlanningTemporaire;
use App\Entity\PlanningTemporaireGenere;
use App\Entity\Train;
use App\Entity\User;
use App\Service\ExcelService;
use App\Service\PlanningTemporaireNewService;
use DateInterval;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractDashboardController
{
private $jours_ = array(
1 => "lundi",
2 => "mardi",
3 => "mercredi",
4 => "jeudi",
5 => "vendredi",
6 => "samedi",
7 => "dimanche"
);
public function __construct(private EntityManagerInterface $em,
private PlanningTemporaireNewService $planning_temporaire_service_new,
private AdminUrlGenerator $admin_url_generator, private KernelInterface $kernel)
{
}
public function configureAssets(): Assets
{
return Assets::new()
->addJsFile('plugins/jquery/jquery-3.1.0.min.js')
->addJsFile('plugins/jquery-ui/jquery-ui.min.js')
->addJsFile('plugins/notify/notify.min.js')
->addCssFile('https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css')
->addWebpackEncoreEntry('app')
;
}
#[Route('/admin', name: 'admin')]
public function index(): Response
{
$date = new \DateTime();
$user = $this->getUser();
$user->setDateConnexion($date);
$this->em->persist($user);
$this->em->flush();
return $this->render('admin/home.html.twig');
// Option 1. You can make your dashboard redirect to some common page of your backend
//
// $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
// return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());
// Option 2. You can make your dashboard redirect to different pages depending on the user
//
// if ('jane' === $this->getUser()->getUsername()) {
// return $this->redirect('...');
// }
// Option 3. You can render some custom template to display a proper dashboard with widgets, etc.
// (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)
//
// return $this->render('some/path/my-dashboard.html.twig');
}
#[Route('/admin/generer_planningv2', name: 'generer_planning_v2')]
public function generer_planning_v2():Response{
$periodes = $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
$poles = $this->em->getRepository(Agent::class)->getPoles();
return $this->render('admin/generer_planning_v2.html.twig', array('periodes' => $periodes, 'poles' => $poles));
}
#[Route('/admin/add_manual', name: 'add_manual')]
public function add_manual(Request $request):Response{
$periodes = $this->em->getRepository(Periode::class)->findAll();
$agents = $this->em->getRepository(Agent::class)->findBy(array('actif' => 1), array('nom' => 'ASC'));
if($request->isMethod('POST')){
$agent = $this->em->getRepository(Agent::class)->find($request->request->get('agent'));
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$train_aller = $this->em->getRepository(Train::class)->find($request->request->get('train_aller'));
$train_retour = $this->em->getRepository(Train::class)->find($request->request->get('train_retour'));
$jour = $this->em->getRepository(Jour::class)->findOneBy(array('name' => $request->request->get('jour')));
$check_manuel = $this->em->getRepository(AjoutManuel::class)->findOneBy(
array(
'periode' => $periode,
'jour' => $jour,
'agent' => $agent,
'train_aller' => $train_aller,
'train_retour' => $train_retour
)
);
if($check_manuel == null){
$ajout_manuel = new AjoutManuel;
$ajout_manuel->setPeriode($periode)
->setAgent($agent)
->setTrainAller($train_aller)
->setTrainRetour($train_retour)
->setJour($jour)
;
$this->em->persist($ajout_manuel);
$this->em->flush();
}
return $this->redirect($this->admin_url_generator->setController(AjoutManuelCrudController::class)->setAction(Action::INDEX)->generateUrl());
}
return $this->render('admin/add_manual.html.twig', array('periodes' => $periodes, 'agents' => $agents));
}
#[Route('/admin/ajax_remove_plan', name: 'ajax_remove_plan')]
public function ajax_remove_plan(Request $request){
$plan_id = $request->request->get('plan_id');
$plan = $this->em->getRepository(PlanningTemporaire::class)->find($plan_id);
$jour = $this->em->getRepository(Jour::class)->findOneBy(array('name' => $plan->getJour()));
$ajout_manuel = $this->em->getRepository(AjoutManuel::class)->findOneBy(
array(
'periode' => $plan->getPeriode(),
'jour' => $jour,
'agent' => $plan->getAgent(),
'train_aller' => $plan->getTrainAller(),
'train_retour' => $plan->getTrainRetour()
)
);
$this->em->remove($ajout_manuel);
$this->em->flush();
return new JsonResponse(array('done' => true));
}
#[Route('/admin/save_comment', name: 'save_comment')]
public function save_comment(Request $request){
if($request->isMethod('POST')){
$data = json_decode($request->getContent(), true);
if (!$data) {
return new JsonResponse(['success' => false, 'message' => 'Invalid JSON'], 400);
}
$agentId = $data['agent'] ?? null;
$periodeId = $data['periode'] ?? null;
$trainAllerId = $data['train_aller'] ?? null;
$trainRetourId = $data['train_retour'] ?? null;
$jourName = $data['jour'] ?? null;
$comment = $data['comment'] ?? null;
if (!$agentId || !$periodeId || !$trainAllerId || !$trainRetourId || !$jourName || !$comment) {
return new JsonResponse(['success' => false, 'message' => 'Missing data'], 400);
}
$agent = $this->em->getRepository(Agent::class)->find((int)$agentId);
$periode = $this->em->getRepository(Periode::class)->find((int)$periodeId);
$train_aller = $this->em->getRepository(Train::class)->find((int)$trainAllerId);
$train_retour = $this->em->getRepository(Train::class)->find((int)$trainRetourId);
$jour = $this->em->getRepository(Jour::class)->findOneBy(array('name' => $jourName));
$check_manuel = $this->em->getRepository(AjoutManuel::class)->findOneBy([
'periode' => $periode,
'jour' => $jour,
'agent' => $agent,
'train_aller' => $train_aller,
'train_retour' => $train_retour
]);
if($check_manuel !== null){
$check_manuel->setCommentaire($comment);
$this->em->persist($check_manuel);
$this->em->flush();
}else{
return new JsonResponse(['success' => false]);
}
return new JsonResponse(['success' => true, 'comment' => $comment]);
}
return new JsonResponse(['success' => false]);
}
#[Route('/admin/save_swap_boucle', name: 'save_swap_boucle')]
public function save_swap_boucle(Request $request){
$plan_id = $request->request->get('plan_id');
$plan = $this->em->getRepository(PlanningTemporaire::class)->find($plan_id);
$jour = $this->em->getRepository(Jour::class)->findOneBy(array('name' => $plan->getJour()));
$agent_cible = $this->em->getRepository(Agent::class)->find($request->request->get('agent_id'));
//Jour actuel de l'agent cible
$ajout_manuel_cible = $this->em->getRepository(AjoutManuel::class)->findBy([
'periode' =>$plan->getPeriode(),
'jour' => $jour,
'agent' => $agent_cible
]);
foreach($ajout_manuel_cible as $am){
$this->em->remove($am);
$this->em->flush();
}
$ajout_manuel = $this->em->getRepository(AjoutManuel::class)->findOneBy(
array(
'periode' => $plan->getPeriode(),
'jour' => $jour,
'agent' => $plan->getAgent(),
'train_aller' => $plan->getTrainAller(),
'train_retour' => $plan->getTrainRetour()
)
);
$ajout_manuel->setAgent($agent_cible);
$this->em->persist($ajout_manuel);
$this->em->flush();
return new JsonResponse(array('done' => true));
}
#[Route('/admin/get_pole_agents', name: 'get_pole_agents')]
public function get_pole_agents(Request $request){
$agents = $this->em->getRepository(Agent::class)->getPoleAgents($request->request->get('gare_id'), $request->request->get('agent_id'));
return new JsonResponse(['agents' => $agents]);
}
#[Route('/admin/ajax_duplicate_plan', name: 'ajax_duplicate_plan')]
public function ajax_duplicate_plan(Request $request){
$plan_id = $request->request->get('plan_id');
$plan = $this->em->getRepository(PlanningTemporaire::class)->find($plan_id);
$jour = $this->em->getRepository(Jour::class)->findOneBy(array('name' => $plan->getJour()));
$check_manuel = $this->em->getRepository(AjoutManuel::class)->findOneBy(
array(
'periode' => $plan->getPeriode(),
'jour' => $jour,
'agent' => $plan->getAgent(),
'train_aller' => $plan->getTrainAller(),
'train_retour' => $plan->getTrainRetour()
)
);
if($check_manuel == null){
$ajout_manuel = new AjoutManuel;
$ajout_manuel->setPeriode($plan->getPeriode())
->setAgent($plan->getAgent())
->setTrainAller($plan->getTrainAller())
->setTrainRetour($plan->getTrainRetour())
->setJour($jour)
;
$this->em->persist($ajout_manuel);
$this->em->flush();
return new JsonResponse(array('done' => true));
}else{
return new JsonResponse(array('done' => false));
}
}
#[Route('/admin/ajax_manual_load_train', name: 'ajax_manual_load_train')]
public function ajax_manual_load_train(Request $request):Response{
$array_trains = array();
$jour = $this->em->getRepository(Jour::class)->findOneBy(array('name' => $request->request->get('jour')));
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$trains = $this->em->getRepository(Train::class)->getTrainSpbJourAjax($request->request->get('jour'), $periode);
foreach($trains as $train){
array_push($array_trains, array(
'numero' => $train->getNumero(),
'id' => $train->getId()
));
}
return new JsonResponse(array('trains' => $array_trains));
}
#[Route('/admin/display_calendar', name: 'display_calendar')]
public function display_calendar():Response{
$plannings_temporaires = $this->em->getRepository(PlanningTemporaire::class)->getUniqueNames();
$agents = $this->em->getRepository(Agent::class)->findBy(array('actif' => 1), array('nom' => 'ASC'));
return $this->render('admin/calendar.html.twig', array('plannings_temporaires' => $plannings_temporaires, 'agents' => $agents));
}
#[Route('/admin/ajax/generer_planning_v2', name: 'ajax_generer_planning_v2')]
public function ajax_generer_planning_v2(Request $request, KernelInterface $kernel):JsonResponse{
$response = $this->planning_temporaire_service_new->generatePlanningTemporaire($request->request->get('periode'));
return new JsonResponse($response);
}
#[Route('/admin/planning_temporaire/{name}', name: 'display_planning_temporaire')]
public function display_planning_temporaire($name):Response{
$temps_semaine_par_agents = $this->em->getRepository(PlanningTemporaire::class)->getTempsSemaineParAgent($name);
$i = 0;
foreach($temps_semaine_par_agents as $temps_agent){
//$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);
$plans = $this->em->getRepository(PlanningTemporaire::class)->getByName($name, $temps_agent['plan']->getAgent()->getId());
$temps_semaine_par_agents[$i]['plannings'] = $plans;
$i++;
}
//Chaque agent ?
//Puis recherche planning de cette periode ?
return $this->render('admin/display_planning_temporaire.html.twig', array('temps_semaine_par_agent' => $temps_semaine_par_agents));
}
#[Route('/admin/planning_temporaire/sncf/{name}', name: 'display_planning_temporaire_sncf')]
public function display_planning_temporaire_sncf($name):Response{
//QUE LES TRAINS SPB
$results = array();
$planning_temporaires = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
$periode = $planning_temporaires[0]->getPeriode();
$jours = $this->em->getRepository(Jour::class)->findAll();
foreach($jours as $jour){
$trains = $this->em->getRepository(Train::class)->getTrainsSncf($periode, $jour->getName());
/*$planning_temporaires_jour = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'jour' => $jour->getName()));
foreach($planning_temporaires_jour as $plan){
}*/
$trains_du_jour = array();
foreach($trains as $train){
$demande_spb = $this->isSpb($train, $jour);
$prevu_spb = false;
if($demande_spb == false){
$check_retours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_retour' => $train));
if(!empty($check_retours)){
$prevu_spb = true;
}else{
continue;
}
}else{
$check_allers = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_aller' => $train));
if(!empty($check_allers)){
$prevu_spb = true;
}
$check_retours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_retour' => $train));
if(!empty($check_retours)){
$prevu_spb = true;
}
}
$caboteur = $this->isCaboteur($train);
$date_depart = \DateTime::createFromFormat('H:i', $train->getHeureDepart());
array_push($trains_du_jour,array(
'jour' => strtoupper($jour->getName()),
'numero' => $train->getNumero(),
'origine' => $train->getOrigine(),
'destination' => $train->getDestination(),
'origine_spb' => $train->getOrigineSpbDi(),
'destination_spb' => $train->getDestinationSpbDi(),
'caboteur' => $caboteur,
'demande_spb' => ($demande_spb== true)?"O":"N",
'prevu_spb' => ($prevu_spb== true)?"O":"N",
'date_depart' => $date_depart,
'date_str' => $date_depart->format('H:i')
));
}
array_multisort(array_column($trains_du_jour, 'date_depart'), SORT_ASC, $trains_du_jour);
$results = array_merge($results, $trains_du_jour);
}
return $this->render('admin/display_planning_temporaire_sncf.html.twig', array('results' => $results));
}
private function isCaboteur($train){
//Verifier si entre les etapes qui sont en spb il y'a des etapes ou non
if($train->getEtapes()->isEmpty()){
return "N";
}else{
$i = 0;
$etape_spb = null;
foreach($train->getEtapes() as $etape){
if($etape->getGare()->isPoleSpb() == 1){
if($etape_spb !== null){
if($etape_spb == $i+1){
return "N";
}else{
return "O";
}
}
$etape_spb = $i;
}
$i++;
}
}
return "N";
}
private function isSpb($train, $jour){
foreach($train->getSpbParJours() as $j){
if($j == $jour){
return true;
}
}
return false;
}
#[Route('/admin/export_service/{name}', name: 'export_service')]
public function export_service($name){
$excel = new ExcelService;
$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');
$jours = $this->em->getRepository(Jour::class)->findAll();
$trains_par_jours = [];
foreach($jours as $jour){
$trains_par_jours[$jour->getName()] = [];
$excel->setNextSheet($jour->getName());
$planning_temporaires = $this->em->getRepository(PlanningTemporaire::class)->getForService($name, $jour->getName());
foreach($planning_temporaires as $plan){
//temps parcours
$date_depart_aller = \DateTime::createFromFormat('H:i', $plan->getTrainDepartAller());
/*array_push($trains_par_jours[$jour->getName()], array(
$plan->getTrainNumeroAller(),
$plan->getTrainOrigineAller(),
$plan->getTrainDestinationAller(),
$plan->getTrainDepartAller(),
$plan->getTrainArriveeAller(),
$plan->getCorrespondance(),
$plan->getTrainNumeroRetour(),
$plan->getTrainOrigineRetour(),
$plan->getTrainDestinationRetour(),
$plan->getTrainDepartRetour(),
$plan->getTrainArriveeRetour(),
$plan->getAgentName(),
$date_depart_aller
));*/
array_push($trains_par_jours[$jour->getName()], array(
"jour" => $jour->getName(),
"aller_numero" => $plan->getTrainNumeroAller(),
"aller_origine" => $plan->getTrainOrigineAller(),
"aller_destination" => $plan->getTrainDestinationAller(),
"aller_pdf" => $plan->getTrainPriseDeServiceAller(),
"aller_depart" => $plan->getTrainDepartAller(),
"aller_arrivee" => $plan->getTrainArriveeAller(),
"aller_fdf" => $plan->getTrainFinDeServiceAller(),
"correspondance" => $plan->getCorrespondance(),
"retour_numero" => $plan->getTrainNumeroRetour(),
"retour_origine" => $plan->getTrainOrigineRetour(),
"retour_destination" => $plan->getTrainDestinationRetour(),
"retour_pdf" => $plan->getTrainPriseDeServiceRetour(),
"retour_depart" => $plan->getTrainDepartRetour(),
"retour_arrivee" => $plan->getTrainArriveeRetour(),
"retour_fdf" => $plan->getTrainFinDeServiceRetour(),
"agent" => $plan->getAgentName(),
"date_order" => $date_depart_aller
));
}
//Trier par date
array_multisort(array_column($trains_par_jours[$jour->getName()], 'date_order'), SORT_ASC, $trains_par_jours[$jour->getName()]);
$excel->sendDataToCurrentSheet($header, $trains_par_jours[$jour->getName()]);
}
//Excel
return $excel->getNewExcel();
}
#[Route('/admin/export_capacite/{name}', name: 'export_capacite')]
public function export_capacite($name){
//Colonne origine - destination
//Nombre de demandés SPB
//Regrouper par orig - dest ou dest - orig
//puis orig spb - dest spb | avec ou sans etapes
$array_results = [];
$array_results1 = [];
$planning_temporaires = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
$periode = $planning_temporaires[0]->getPeriode();
$trains_demandes_spb = $this->em->getRepository(Train::class)->getTrainSpbJour(null, $periode);
//Trains demandes
foreach($trains_demandes_spb as $train){
if($train->getOrigineSpb() !== null && $train->getDestinationSpb() !== null){
$key = $train->getAxe()->getCode();
if(array_key_exists($key, $array_results) == false){
//Créer
$array_results[$key] = [];
$array_results1[$key] = [];
}
$key_spb = $train->getOrigineSpb()->getCode().'-'.$train->getDestinationSpb()->getCode();
$iscaboteur = false;
if($train->getEtapes()->isEmpty()){
}else{
$iscaboteur = true;
$key_spb = $train->getOrigineSpb()->getCode().'-'.$train->getDestinationSpb()->getCode()."-CABOTEUR";
}
//NOMBRE PLANIFIES
//NOMBRE ROUGE
if(array_key_exists($key_spb, $array_results[$key]) == false){
//Créer
$array_results[$key][$key_spb] = [
"origine_spb" => $train->getOrigineSpb()->getName(),
"destination_spb" => $train->getDestinationSpb()->getName(),
"origine_spb_code" => $train->getOrigineSpb()->getCode(),
"destination_spb_code" => $train->getDestinationSpb()->getCode(),
"nombre_demande_semaine" => 0,
"nombre_demande_dimanche" => 0,
"nombre_couvert_semaine" => 0,
"nombre_couvert_dimanche" => 0,
"nombre_rouge_semaine" => 0,
"nombre_rouge_dimanche" => 0,
"iscaboteur" => $iscaboteur
];
//Second tableau
$array_results1[$key][$key_spb] = [
"origine_spb" => $train->getOrigineSpb()->getName(),
"destination_spb" => $train->getDestinationSpb()->getName(),
"origine_spb_code" => $train->getOrigineSpb()->getCode(),
"destination_spb_code" => $train->getDestinationSpb()->getCode(),
"nombre_demande_lundi" => 0,
"nombre_demande_mardi" => 0,
"nombre_demande_mercredi" => 0,
"nombre_demande_jeudi" => 0,
"nombre_demande_vendredi" => 0,
"nombre_demande_samedi" => 0,
"nombre_demande_dimanche" => 0,
"nombre_couvert_lundi" => 0,
"nombre_couvert_mardi" => 0,
"nombre_couvert_mercredi" => 0,
"nombre_couvert_jeudi" => 0,
"nombre_couvert_vendredi" => 0,
"nombre_couvert_samedi" => 0,
"nombre_couvert_dimanche" => 0,
"nombre_rouge_lundi" => 0,
"nombre_rouge_mardi" => 0,
"nombre_rouge_mercredi" => 0,
"nombre_rouge_jeudi" => 0,
"nombre_rouge_vendredi" => 0,
"nombre_rouge_samedi" => 0,
"nombre_rouge_dimanche" => 0,
"iscaboteur" => $iscaboteur
];
}
//Ajouter dans le tableau les nombres demandes
//si jour um *2
foreach($train->getSpbParJours() as $jour){
$couvert = false;
$check_retours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_retour' => $train, 'jour' => $jour->getName()));
$check_allers = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_aller' => $train, 'jour' => $jour->getName()));
if(!empty($check_retours) || !empty($check_allers)){
$couvert = true;
}
$array_results1[$key][$key_spb]["nombre_demande_".$jour->getName()]++;
if($couvert == true){
$array_results1[$key][$key_spb]["nombre_couvert_".$jour->getName()]++;
}
//Check um
foreach($train->getJoursUm() as $jour_um){
if($jour_um == $jour){
$array_results1[$key][$key_spb]["nombre_demande_".$jour->getName()]++;
if($couvert == true){
$array_results1[$key][$key_spb]["nombre_couvert_".$jour->getName()]++;
}
}
}
if($jour->getName() !== "dimanche"){
$array_results[$key][$key_spb]["nombre_demande_semaine"]++;
if($couvert == true){
$array_results[$key][$key_spb]["nombre_couvert_semaine"]++;
}
//Check um
foreach($train->getJoursUm() as $jour_um){
if($jour_um == $jour){
$array_results[$key][$key_spb]["nombre_demande_semaine"]++;
if($couvert == true){
$array_results[$key][$key_spb]["nombre_couvert_semaine"]++;
}
}
}
}else{
$array_results[$key][$key_spb]["nombre_demande_dimanche"]++;
if($couvert == true){
$array_results[$key][$key_spb]["nombre_couvert_dimanche"]++;
}
//Check um
foreach($train->getJoursUm() as $jour_um){
if($jour_um == $jour){
$array_results[$key][$key_spb]["nombre_demande_dimanche"]++;
if($couvert == true){
$array_results[$key][$key_spb]["nombre_couvert_dimanche"]++;
}
}
}
}
}
}
}
$plans_aller_rouge = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'aller_spb' => false));
foreach($plans_aller_rouge as $aller_rouge){
if($aller_rouge->getTrainAller()->getOrigineSpb() !== null && $aller_rouge->getTrainAller()->getDestinationSpb() !==null){
$key = $aller_rouge->getTrainAller()->getAxe()->getCode();
$key_spb = $aller_rouge->getTrainAller()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainAller()->getDestinationSpb()->getCode();
$iscaboteur = false;
if($aller_rouge->getTrainAller()->getEtapes()->isEmpty()){
}else{
$iscaboteur = true;
$key_spb = $aller_rouge->getTrainAller()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainAller()->getDestinationSpb()->getCode()."-CABOTEUR";
}
if(array_key_exists($key_spb, $array_results[$key]) == false){
//Créer
$array_results[$key][$key_spb] = [
"origine_spb" => $aller_rouge->getTrainAller()->getOrigineSpb()->getName(),
"destination_spb" => $aller_rouge->getTrainAller()->getDestinationSpb()->getName(),
"origine_spb_code" => $aller_rouge->getTrainAller()->getOrigineSpb()->getCode(),
"destination_spb_code" => $aller_rouge->getTrainAller()->getDestinationSpb()->getCode(),
"nombre_demande_semaine" => 0,
"nombre_demande_dimanche" => 0,
"nombre_couvert_semaine" => 0,
"nombre_couvert_dimanche" => 0,
"nombre_rouge_semaine" => 0,
"nombre_rouge_dimanche" => 0,
"iscaboteur" => $iscaboteur
];
//Second tableau
$array_results1[$key][$key_spb] = [
"origine_spb" => $train->getOrigineSpb()->getName(),
"destination_spb" => $train->getDestinationSpb()->getName(),
"origine_spb_code" => $train->getOrigineSpb()->getCode(),
"destination_spb_code" => $train->getDestinationSpb()->getCode(),
"nombre_demande_lundi" => 0,
"nombre_demande_mardi" => 0,
"nombre_demande_mercredi" => 0,
"nombre_demande_jeudi" => 0,
"nombre_demande_vendredi" => 0,
"nombre_demande_samedi" => 0,
"nombre_demande_dimanche" => 0,
"nombre_couvert_lundi" => 0,
"nombre_couvert_mardi" => 0,
"nombre_couvert_mercredi" => 0,
"nombre_couvert_jeudi" => 0,
"nombre_couvert_vendredi" => 0,
"nombre_couvert_samedi" => 0,
"nombre_couvert_dimanche" => 0,
"nombre_rouge_lundi" => 0,
"nombre_rouge_mardi" => 0,
"nombre_rouge_mercredi" => 0,
"nombre_rouge_jeudi" => 0,
"nombre_rouge_vendredi" => 0,
"nombre_rouge_samedi" => 0,
"nombre_rouge_dimanche" => 0,
"iscaboteur" => $iscaboteur
];
}
$array_results1[$key][$key_spb]["nombre_rouge_".$jour->getName()]++;
if($aller_rouge->getJour() == "dimanche"){
$array_results[$key][$key_spb]['nombre_rouge_dimanche']++;
}else{
$array_results[$key][$key_spb]['nombre_rouge_semaine']++;
}
}
}
$plans_retour_rouge = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'retour_spb' => false));
foreach($plans_retour_rouge as $aller_rouge){
if($aller_rouge->getTrainRetour()->getOrigineSpb() !== null && $aller_rouge->getTrainRetour()->getDestinationSpb() !==null){
$key = $aller_rouge->getTrainRetour()->getAxe()->getCode();
$key_spb = $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainRetour()->getDestinationSpb()->getCode();
$iscaboteur = false;
/*if($this->isCaboteur($aller_rouge->getTrainRetour()) == "O"){
$iscaboteur = true;
$key_spb = $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainRetour()->getDestinationSpb()->getCode()."-CABOTEUR";
}*/
if($aller_rouge->getTrainRetour()->getEtapes()->isEmpty()){
}else{
$iscaboteur = true;
$key_spb = $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode().'-'.$aller_rouge->getTrainRetour()->getDestinationSpb()->getCode()."-CABOTEUR";
}
if(array_key_exists($key_spb, $array_results[$key]) == false){
//Créer
$array_results[$key][$key_spb] = [
"origine_spb" => $aller_rouge->getTrainRetour()->getOrigineSpb()->getName(),
"destination_spb" => $aller_rouge->getTrainRetour()->getDestinationSpb()->getName(),
"origine_spb_code" => $aller_rouge->getTrainRetour()->getOrigineSpb()->getCode(),
"destination_spb_code" => $aller_rouge->getTrainRetour()->getDestinationSpb()->getCode(),
"nombre_demande_semaine" => 0,
"nombre_demande_dimanche" => 0,
"nombre_couvert_semaine" => 0,
"nombre_couvert_dimanche" => 0,
"nombre_rouge_semaine" => 0,
"nombre_rouge_dimanche" => 0,
"iscaboteur" => $iscaboteur
];
//Second tableau
$array_results1[$key][$key_spb] = [
"origine_spb" => $train->getOrigineSpb()->getName(),
"destination_spb" => $train->getDestinationSpb()->getName(),
"origine_spb_code" => $train->getOrigineSpb()->getCode(),
"destination_spb_code" => $train->getDestinationSpb()->getCode(),
"nombre_demande_lundi" => 0,
"nombre_demande_mardi" => 0,
"nombre_demande_mercredi" => 0,
"nombre_demande_jeudi" => 0,
"nombre_demande_vendredi" => 0,
"nombre_demande_samedi" => 0,
"nombre_demande_dimanche" => 0,
"nombre_couvert_lundi" => 0,
"nombre_couvert_mardi" => 0,
"nombre_couvert_mercredi" => 0,
"nombre_couvert_jeudi" => 0,
"nombre_couvert_vendredi" => 0,
"nombre_couvert_samedi" => 0,
"nombre_couvert_dimanche" => 0,
"nombre_rouge_lundi" => 0,
"nombre_rouge_mardi" => 0,
"nombre_rouge_mercredi" => 0,
"nombre_rouge_jeudi" => 0,
"nombre_rouge_vendredi" => 0,
"nombre_rouge_samedi" => 0,
"nombre_rouge_dimanche" => 0,
"iscaboteur" => $iscaboteur
];
}
$array_results1[$key][$key_spb]["nombre_rouge_".$jour->getName()]++;
if($aller_rouge->getJour() == "dimanche"){
$array_results[$key][$key_spb]['nombre_rouge_dimanche']++;
}else{
$array_results[$key][$key_spb]['nombre_rouge_semaine']++;
}
}
}
foreach($array_results1 as $key => $lignes){
foreach($lignes as $key_spb => $array){
if($array['origine_spb_code'] !== "PMP" && $array['origine_spb_code'] !== "MPW"){
$check_key_spb = $array['destination_spb_code'] .'-'.$array['origine_spb_code'] ;
if($array['iscaboteur'] == true){
$check_key_spb.="-CABOTEUR";
}
if(array_key_exists($check_key_spb, $lignes)){
$array_results1[$key][$check_key_spb]['nombre_demande_lundi'] += $array['nombre_demande_lundi'];
$array_results1[$key][$check_key_spb]['nombre_demande_mardi'] += $array['nombre_demande_mardi'];
$array_results1[$key][$check_key_spb]['nombre_demande_mercredi'] += $array['nombre_demande_mercredi'];
$array_results1[$key][$check_key_spb]['nombre_demande_jeudi'] += $array['nombre_demande_jeudi'];
$array_results1[$key][$check_key_spb]['nombre_demande_vendredi'] += $array['nombre_demande_vendredi'];
$array_results1[$key][$check_key_spb]['nombre_demande_samedi'] += $array['nombre_demande_samedi'];
$array_results1[$key][$check_key_spb]['nombre_demande_dimanche'] += $array['nombre_demande_dimanche'];
$array_results1[$key][$check_key_spb]['nombre_couvert_lundi'] += $array['nombre_couvert_lundi'];
$array_results1[$key][$check_key_spb]['nombre_couvert_mardi'] += $array['nombre_couvert_mardi'];
$array_results1[$key][$check_key_spb]['nombre_couvert_mercredi'] += $array['nombre_couvert_mercredi'];
$array_results1[$key][$check_key_spb]['nombre_couvert_jeudi'] += $array['nombre_couvert_jeudi'];
$array_results1[$key][$check_key_spb]['nombre_couvert_vendredi'] += $array['nombre_couvert_vendredi'];
$array_results1[$key][$check_key_spb]['nombre_couvert_samedi'] += $array['nombre_couvert_samedi'];
$array_results1[$key][$check_key_spb]['nombre_couvert_dimanche'] += $array['nombre_couvert_dimanche'];
$array_results1[$key][$check_key_spb]['nombre_rouge_lundi'] += $array['nombre_rouge_lundi'];
$array_results1[$key][$check_key_spb]['nombre_rouge_mardi'] += $array['nombre_rouge_mardi'];
$array_results1[$key][$check_key_spb]['nombre_rouge_mercredi'] += $array['nombre_rouge_mercredi'];
$array_results1[$key][$check_key_spb]['nombre_rouge_jeudi'] += $array['nombre_rouge_jeudi'];
$array_results1[$key][$check_key_spb]['nombre_rouge_vendredi'] += $array['nombre_rouge_vendredi'];
$array_results1[$key][$check_key_spb]['nombre_rouge_samedi'] += $array['nombre_rouge_samedi'];
$array_results1[$key][$check_key_spb]['nombre_rouge_dimanche'] += $array['nombre_rouge_dimanche'];
}else{
$array_results1[$key][$check_key_spb] = $array;
}
unset($array_results1[$key][$key_spb]);
}
}
}
foreach($array_results as $key => $lignes){
//key = axe
foreach($lignes as $key_spb => $array){
if($array['origine_spb_code'] !== "PMP" && $array['origine_spb_code'] !== "MPW"){
$check_key_spb = $array['destination_spb_code'] .'-'.$array['origine_spb_code'] ;
if($array['iscaboteur'] == true){
$check_key_spb.="-CABOTEUR";
}
if(array_key_exists($check_key_spb, $lignes)){
$array_results[$key][$check_key_spb]['nombre_demande_semaine'] += $array['nombre_demande_semaine'];
$array_results[$key][$check_key_spb]['nombre_demande_dimanche'] += $array['nombre_demande_dimanche'];
$array_results[$key][$check_key_spb]['nombre_couvert_semaine'] += $array['nombre_couvert_semaine'];
$array_results[$key][$check_key_spb]['nombre_couvert_dimanche'] += $array['nombre_couvert_dimanche'];
$array_results[$key][$check_key_spb]['nombre_rouge_semaine'] += $array['nombre_rouge_semaine'];
$array_results[$key][$check_key_spb]['nombre_rouge_dimanche'] += $array['nombre_rouge_dimanche'];
}else{
$array_results[$key][$check_key_spb] = $array;
}
unset($array_results[$key][$key_spb]);
}
}
}
$excel = new ExcelService;
$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");
$excel->setDatasCapacite($header, $array_results);
$excel->setDatasCapacite($header, $array_results1, 1);
return $excel->getExcel("export_capacite");
}
private function search_multidimensional_array($array, $key, $value, $key2 = null, $value2 = null) {
$results = array();
// if it is array
if (is_array($array)) {
// if array has required key and value
// matched store result
if (isset($array[$key]) && $array[$key] == $value
&& ($key2 == null || (isset($array[$key2]) && $array[$key2] == $value2))) {
$results[] = $array;
}
// Iterate for each element in array
foreach ($array as $subarray) {
// recur through each element and append result
$results = array_merge($results,
$this->search_multidimensional_array($subarray, $key, $value, $key2, $value2));
}
}
return $results;
}
#[Route('/admin/planning_temporaire/sis/{name}', name: 'export_sis')]
public function export_sis($name){
$results = array();
$jours = $this->em->getRepository(Jour::class)->findAll();
$plans = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
$periode = $plans[0]->getPeriode();
$date_debut_periode = $periode->getDateDebut()->format('d/m/Y');
$date_fin_periode = $periode->getDateFin()->format('d/m/Y');
$jours = $this->em->getRepository(Jour::class)->findAll();
$trains = $this->em->getRepository(Train::class)->findBy(array('periode' => $periode));
foreach($trains as $train){
$origine = $train->getOrigine();
$destination = $train->getDestination();
if($train->getOrigineSpb() !== null){
$origine = $train->getOrigineSpb();
}
if($train->getDestinationSpb() !== null){
$destination = $train->getDestinationSpb();
}
$check_planning_allers = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_aller' => $train));
$check_planning_retours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name, 'train_retour' => $train));
if($train->getSpbParJours()->isEmpty() == true && empty($check_planning_retours) && empty($check_planning_retours)){
array_push($results, array(
"numero" => $train->getNumero(),
"date_debut_periode" => $date_debut_periode,
"date_fin_periode" => $date_fin_periode,
"origine" => $origine->getCode().'-BV',
"destination" => $destination->getCode().'-BV',
"particularite" => "",
"lundi" => "",
"mardi" => "",
"mercredi" => "",
"jeudi" => "",
"vendredi" => "",
"samedi" => "",
"dimanche" => "",
));
continue;
}
$train_um = false;
if($train->getJoursUm()->isEmpty() == false){
$train_um = true;
}
if($train_um == false){
$lundi = "";
$mardi = "";
$mercredi = "";
$jeudi = "";
$vendredi = "";
$samedi = "";
$dimanche = "";
foreach($train->getSpbParJours() as $jour){
$jour_name = $jour->getName();
$check_train_aller_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_aller" => $train
));
if(!empty($check_train_aller_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
$check_train_retour_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_retour" => $train
));
if(!empty($check_train_retour_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
}
array_push($results, array(
"numero" => $train->getNumero(),
"date_debut_periode" => $date_debut_periode,
"date_fin_periode" => $date_fin_periode,
"origine" => $origine->getCode().'-BV',
"destination" => $destination->getCode().'-BV',
"particularite" => "",
"lundi" => $lundi,
"mardi" => $mardi,
"mercredi" => $mercredi,
"jeudi" => $jeudi,
"vendredi" => $vendredi,
"samedi" => $samedi,
"dimanche" => $dimanche,
));
}else{
//D'abord NON UM
$lundi = "";
$mardi = "";
$mercredi = "";
$jeudi = "";
$vendredi = "";
$samedi = "";
$dimanche = "";
foreach($train->getSpbParJours() as $jour){
//Check si le jour en question est en um
foreach($train->getJoursUm() as $jour_um){
if($jour_um == $jour){
continue 2;
}
}
$jour_name = $jour->getName();
$check_train_aller_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_aller" => $train
));
if(!empty($check_train_aller_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
$check_train_retour_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_retour" => $train
));
if(!empty($check_train_retour_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
}
//pour les jours non um
array_push($results, array(
"numero" => $train->getNumero(),
"date_debut_periode" => $date_debut_periode,
"date_fin_periode" => $date_fin_periode,
"origine" => $origine->getCode().'-BV',
"destination" => $destination->getCode().'-BV',
"particularite" => "",
"lundi" => $lundi,
"mardi" => $mardi,
"mercredi" => $mercredi,
"jeudi" => $jeudi,
"vendredi" => $vendredi,
"samedi" => $samedi,
"dimanche" => $dimanche,
));
//pour les jours um
$lundi = "";
$mardi = "";
$mercredi = "";
$jeudi = "";
$vendredi = "";
$samedi = "";
$dimanche = "";
//TETE
foreach($train->getSpbParJours() as $jour){
//Check si le jour en question est en um
foreach($train->getJoursUm() as $jour_um){
if($jour_um !== $jour){
continue 2;
}
}
$jour_name = $jour->getName();
$check_train_aller_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_numero_aller" => "T".$train->getNumero()
));
if(!empty($check_train_aller_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
$check_train_retour_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_numero_retour" => "T".$train->getNumero()
));
if(!empty($check_train_aller_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
}
//pour les jours non um TETE
array_push($results, array(
"numero" => $train->getNumero(),
"date_debut_periode" => $date_debut_periode,
"date_fin_periode" => $date_fin_periode,
"origine" => $origine->getCode().'-BV',
"destination" => $destination->getCode().'-BV',
"particularite" => "TETE",
"lundi" => $lundi,
"mardi" => $mardi,
"mercredi" => $mercredi,
"jeudi" => $jeudi,
"vendredi" => $vendredi,
"samedi" => $samedi,
"dimanche" => $dimanche,
));
$lundi = "";
$mardi = "";
$mercredi = "";
$jeudi = "";
$vendredi = "";
$samedi = "";
$dimanche = "";
//QUEU
foreach($train->getSpbParJours() as $jour){
//Check si le jour en question est en um
foreach($train->getJoursUm() as $jour_um){
if($jour_um !== $jour){
continue 2;
}
}
$jour_name = $jour->getName();
$check_train_aller_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_numero_aller" => "Q".$train->getNumero()
));
if(!empty($check_train_aller_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
$check_train_retour_jours = $this->em->getRepository(PlanningTemporaire::class)->findBy(array(
"name" => $name,
"jour" => $jour_name,
"train_numero_retour" => "Q".$train->getNumero()
));
if(!empty($check_train_aller_jours)){
$$jour_name = "1";
continue;
}else{
$$jour_name = "0";
}
}
//pour les jours non um TETE
array_push($results, array(
"numero" => $train->getNumero(),
"date_debut_periode" => $date_debut_periode,
"date_fin_periode" => $date_fin_periode,
"origine" => $origine->getCode().'-BV',
"destination" => $destination->getCode().'-BV',
"particularite" => "QUEUE",
"lundi" => $lundi,
"mardi" => $mardi,
"mercredi" => $mercredi,
"jeudi" => $jeudi,
"vendredi" => $vendredi,
"samedi" => $samedi,
"dimanche" => $dimanche,
));
}
/*- les lignes de train qui sont demandées en SPB mais n'existent pas dans notre planif, on les met en 0
- les lignes de train en blanc on les met en 1
- les lignes de train en orange = 1
- les lignes en rouge = 1*/
}
//Excel
$excel = new ExcelService;
$excel->dataRows[] = array('N° TGV', 'du', 'au', 'Origine SPB', 'Destination SPB','Particularite', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
$excel->setDatasMultiDimensional($results);
return $excel->getCsv($name);
}
#[Route('/admin/planning_temporaire/export_boucles/{name}', name: 'export_boucles')]
public function export_boucles($name){
$template = $this->kernel->getProjectDir().'/xls_template/Gabarit_export_boucles.xlsx';
//DATAS
$datas = [];
$plannings = $this->em->getRepository(PlanningTemporaire::class)->findBy(['name' => $name], ['order_jour' => 'ASC']);
foreach($plannings as $plan){
$tmp = [];
//Crochet court 0 ou 1
$crochet_aller = 0;
$rame_aller = 'US';
$etape_aller = "OUI";
$crochet_retour = 0;
$rame_retour = 'US';
$etape_retour = "OUI";
$ouinon_aller = "OUI";
$ouinon_retour = "OUI";
$jour = $this->em->getRepository(Jour::class)->findOneBy(['name' => $plan->getJour()]);
if($plan->getTrainAller()->getJoursCrochetCourt()->contains($jour)){
$crochet_aller = 1;
}
if($plan->getTrainAller()->getJoursUm()->contains($jour)){
$rame_aller = "UM2";
}
if($plan->getTrainAller()->getEtapes()->isEmpty()){
$etape_aller = "NON";
}
if($plan->getTrainRetour()->getJoursCrochetCourt()->contains($jour)){
$crochet_aller = 1;
}
if($plan->getTrainRetour()->getJoursUm()->contains($jour)){
$rame_aller = "UM2";
}
if($plan->getTrainRetour()->getEtapes()->isEmpty()){
$etape_aller = "NON";
}
if($plan->isAllerSpb() == false){
$ouinon_aller = "NON";
}else if($plan->isAllerMultiAgent() == true){
$ouinon_aller = "";
}
if($plan->isRetourSpb() == false){
$ouinon_aller = "NON";
}else if($plan->isRetourMultiAgent() == true){
$ouinon_aller = "";
}
$tmp = [strtoupper($plan->getJour()), $plan->getTrainNumeroAller(), $plan->getTrainAller()->getAxe()->getCode(), $plan->getTrainOrigineAller(), $plan->getTrainDestinationAller(), $plan->getTrainPriseDeServiceAller(),
$plan->getTrainDepartAller(), $plan->getTrainArriveeAller(), $plan->getTrainFinDeServiceAller(), $crochet_aller, $rame_aller, $etape_aller, $ouinon_aller, $plan->getCorrespondance(),
$plan->getTrainNumeroRetour(), $plan->getTrainRetour()->getAxe()->getCode(), $plan->getTrainOrigineRetour(), $plan->getTrainDestinationRetour(), $plan->getTrainPriseDeServiceRetour(),
$plan->getTrainDepartRetour(), $plan->getTrainArriveeRetour(), $plan->getTrainFinDeServiceRetour(), $crochet_retour, $rame_retour, $etape_retour, $ouinon_retour
];
array_push($datas, $tmp);
}
//Excel
$excel = new ExcelService;
$excel->createFromTemplate($template);
$excel->setDatas($datas);
return $excel->getExcel($name, 'A2');
}
#[Route('/admin/planning_temporaire/trains_par_jour/{name}', name: 'export_train_par_jour')]
public function export_train_par_jour($name){
//Les trains spb qui ont un agent ou non
/*N°train
Origine SPB
Destination SPB
Lundi O/N
Mardi O/N
Mercredi O/N
Jeudi O/N
Vendredi O/N
Samedi O/N
Dimanche O/N
*/
$planning_temporaires = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('name' => $name));
$periode = $planning_temporaires[0]->getPeriode();
$results = array();
$jours = $this->em->getRepository(Jour::class)->findAll();
$trains_spb = $this->em->getRepository(Train::class)->getTrainSpbJour(null, $periode);
foreach($trains_spb as $train){
$caboteur = $this->isCaboteur($train);
//Rechertche pour chaque jour? si agent ou non dans le planning
$lundi = "";
$mardi = "";
$mercredi = "";
$jeudi = "";
$vendredi = "";
$samedi = "";
$dimanche = "";
foreach($train->getSpbParJours() as $jour){
switch($jour->getName()){
case 'lundi':
$lundi = "N";
break;
case 'mardi':
$mardi = "N";
break;
case 'mercredi':
$mercredi = "N";
break;
case 'jeudi':
$jeudi = "N";
break;
case 'vendredi':
$vendredi = "N";
break;
case 'samedi':
$samedi = "N";
break;
case 'dimanche':
$dimanche = "N";
break;
}
}
foreach($jours as $jour){
//check planning
$check_aller = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('jour' => $jour->getName(), 'name' => $name, 'train_aller' => $train));
if(!empty($check_aller)){
switch($jour->getName()){
case 'lundi':
$lundi = "O";
break;
case 'mardi':
$mardi = "O";
break;
case 'mercredi':
$mercredi = "O";
break;
case 'jeudi':
$jeudi = "O";
break;
case 'vendredi':
$vendredi = "O";
break;
case 'samedi':
$samedi = "O";
break;
case 'dimanche':
$dimanche = "O";
break;
}
continue;
}
$check_aller = $this->em->getRepository(PlanningTemporaire::class)->findBy(array('jour' => $jour->getName(), 'name' => $name, 'train_retour' => $train));
$acheminement = 0;
if(!empty($check_aller)){
if($check_aller[0]->isNoWork() == 1){
$acheminement = 1;
}
switch($jour->getName()){
case 'lundi':
$lundi = "O";
if($acheminement == 1){
$lundi = "ND";
}
break;
case 'mardi':
$mardi = "O";
if($acheminement == 1){
$mardi = "ND";
}
break;
case 'mercredi':
$mercredi = "O";
if($acheminement == 1){
$mercredi = "ND";
}
break;
case 'jeudi':
$jeudi = "O";
if($acheminement == 1){
$jeudi = "ND";
}
break;
case 'vendredi':
$vendredi = "O";
if($acheminement == 1){
$vendredi = "ND";
}
break;
case 'samedi':
$samedi = "O";
if($acheminement == 1){
$samedi = "ND";
}
break;
case 'dimanche':
$dimanche = "O";
if($acheminement == 1){
$dimanche = "ND";
}
break;
}
continue;
}
}
array_push($results, array(
$train->getNumero(),
$train->getOrigineSpb(),
$train->getDestinationSpb(),
$lundi,
$mardi,
$mercredi,
$jeudi,
$vendredi,
$samedi,
$dimanche,
$caboteur
));
}
//Excel
$excel = new ExcelService;
$excel->dataRows[] = array('numero', 'origine_spb', 'destination_spb', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'caboteur');
$excel->setDatas($results);
return $excel->getExcel($name);
}
#[Route('/admin/planning_temporaire/{name}/{pole}', name: 'display_planning_temporaire_pole')]
public function display_planning_temporaire_pole($name, $pole):Response{
$gare = $this->em->getRepository(Gare::class)->findOneBy(array('code' => $pole));
$temps_semaine_par_agents = $this->em->getRepository(PlanningTemporaire::class)->getTempsSemaineParAgent($name, $gare);
$i = 0;
foreach($temps_semaine_par_agents as $temps_agent){
//$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);
$plans = $this->em->getRepository(PlanningTemporaire::class)->getByName($name, $temps_agent['plan']->getAgent()->getId());
$temps_semaine_par_agents[$i]['plannings'] = $plans;
$i++;
}
//dd($temps_semaine_par_agents);
//Chaque agent ?
//Puis recherche planning de cette periode ?
return $this->render('admin/display_planning_temporaire_pole.html.twig', array('temps_semaine_par_agent' => $temps_semaine_par_agents, 'gare' => $gare));
}
#[Route('/admin/add_train_limite', name: 'add_train_limite')]
public function add_train_limite(Request $request):Response{
$periodes = $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
if($request->isMethod('POST')){
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$train = $this->em->getRepository(Train::class)->find($request->request->get('train'));
$request->request->get('destination');
$origine = null;
$destination = null;
if($request->request->get('origine') !== null){
$origine = $this->em->getRepository(Gare::class)->find($request->request->get('origine'));
}
if($request->request->get('destination') !== null){
$destination = $this->em->getRepository(Gare::class)->find($request->request->get('destination'));
}
$json_dates = $request->request->get('json');
$str_dates = null;
$json_horaires = json_decode($json_dates, true);
switch($json_horaires['modeDates']){
case "range":
$str_dates = 'Du '.$json_horaires['datesRange']['dateStart'].' au '.$json_horaires['datesRange']['dateFinish'];
break;
case 'multiple':
$str_dates.= 'Les ';
$i = 0;
foreach($json_horaires['datesMultiple']['dates'] as $date){
if($i>0){
$str_dates.= ', ';
}
$str_dates.= $date;
$i++;
}
break;
case 'single':
$str_dates = 'Le '.$json_horaires['dateSingle']['dates'][0];
break;
}
$plan_gen = $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1, 'periode' => $periode));
$alea = new AleaTrainLimite;
$alea->setJson($json_dates)
->setCommentaire($request->request->get('commentaire'))
->setPeriode($periode)
->setTrain($train)
->setVersion($plan_gen->getName())
->setTextDates($str_dates)
->setNewOrigine($origine)
->setNewDestination($destination)
->setAvanceDepart($request->request->get('avance_depart'))
->setRetardDepart($request->request->get('retard_depart'))
->setAvanceArrivee($request->request->get('avance_arrivee'))
->setRetardArrivee($request->request->get('retard_arrivee'))
;
$this->em->persist($alea);
$this->em->flush();
//IMPACTS
//RECHERCHE PLANNING PERMANENT OU UN/DES AGENTS SONT CONCERNES
switch($json_horaires['modeDates']){
case "range":
$date_debut = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateStart']);
$date_fin = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateFinish']);
$interval = $date_debut->diff($date_fin);
$nb_jour = $interval->d;
for ($i=0;$i<$nb_jour+1;$i++){
$date = clone($date_debut);
if($i > 0){
$date->add(new DateInterval('P'.$i.'D'));
}
$this->addImpact($this->jours_[$date->format('N')], $periode, $train, null, $json_dates, $str_dates, 'Train limité: '.$train->getNumero(), 'limite', $date->format('d/m/Y'), $origine, $destination, $alea);
}
break;
case 'multiple':
foreach($json_horaires['datesMultiple']['dates'] as $date){
$date = date_create_from_format('d/m/Y', $date);
$this->addImpact($this->jours_[$date->format('N')], $periode, $train, null, $json_dates, $str_dates, 'Train limité: '.$train->getNumero(), 'limite', $date->format('d/m/Y'), $origine, $destination, $alea);
}
break;
case 'single':
$date = date_create_from_format('d/m/Y', $json_horaires['dateSingle']['dates'][0]);
$this->addImpact($this->jours_[$date->format('N')], $periode, $train, null, $json_dates, $str_dates, 'Train limité: '.$train->getNumero(), 'limite', $date->format('d/m/Y'), $origine, $destination, $alea);
break;
}
$this->em->flush();
return $this->redirect($this->admin_url_generator->setController(AleaTrainLimiteCrudController::class)->setAction(Action::INDEX)->generateUrl());
}
return $this->render('admin/impacts/add_train_limite.html.twig', array('periodes' => $periodes));
}
#[Route('/admin/ajax_planning_load_train', name: 'ajax_planning_load_train')]
public function ajax_planning_load_train(Request $request):Response{
$array_trains = array();
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$trains = $this->em->getRepository(Train::class)->getPermTrainsAller($periode);
foreach($trains as $tr){
array_push($array_trains, array(
'id' => $tr->getId(),
'name' => $tr->getNumero().' '.($tr->getOrigineSpb()!==null?$tr->getOrigineSpb()->getCode():$tr->getOrigine()->getCode()).' -> '.($tr->getDestinationSpb()!==null?$tr->getDestinationSpb()->getCode():$tr->getDestination()->getCode())
));
}
$trains = $this->em->getRepository(Train::class)->getPermTrainsRetour($periode);
foreach($trains as $tr){
array_push($array_trains, array(
'id' => $tr->getId(),
'name' => $tr->getNumero().' '.($tr->getOrigineSpb()!==null?$tr->getOrigineSpb()->getCode():$tr->getOrigine()->getCode()).' -> '.($tr->getDestinationSpb()!==null?$tr->getDestinationSpb()->getCode():$tr->getDestination()->getCode())
));
}
$array_trains = array_unique($array_trains, SORT_REGULAR);
array_multisort(array_column($array_trains, 'name'), SORT_ASC, $array_trains);
return new JsonResponse(array('trains' => $array_trains));
}
#[Route('/admin/add_train_supprime', name: 'add_train_supprime')]
public function add_train_supprime(Request $request):Response{
$periodes = $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
if($request->isMethod('POST')){
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$train = $this->em->getRepository(Train::class)->find($request->request->get('train'));
$json_dates = $request->request->get('json');
$str_dates = null;
$json_horaires = json_decode($json_dates, true);
switch($json_horaires['modeDates']){
case "range":
$str_dates = 'Du '.$json_horaires['datesRange']['dateStart'].' au '.$json_horaires['datesRange']['dateFinish'];
break;
case 'multiple':
$str_dates.= 'Les ';
$i = 0;
foreach($json_horaires['datesMultiple']['dates'] as $date){
if($i>0){
$str_dates.= ', ';
}
$str_dates.= $date;
$i++;
}
break;
case 'single':
$str_dates = 'Le '.$json_horaires['dateSingle']['dates'][0];
break;
}
$plan_gen = $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1, 'periode' => $periode));
$alea = new AleaTrainSupprime;
$alea->setJson($json_dates)
->setCommentaire($request->request->get('commentaire'))
->setPeriode($periode)
->setTrain($train)
->setVersion($plan_gen->getName())
->setTextDates($str_dates)
;
$this->em->persist($alea);
$this->em->flush();
//IMPACTS
//RECHERCHE PLANNING PERMANENT OU UN/DES AGENTS SONT CONCERNES
switch($json_horaires['modeDates']){
case "range":
$date_debut = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateStart']);
$date_fin = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateFinish']);
$interval = $date_debut->diff($date_fin);
$nb_jour = $interval->d;
for ($i=0;$i<$nb_jour+1;$i++){
$date = clone($date_debut);
if($i > 0){
$date->add(new DateInterval('P'.$i.'D'));
}
$this->addImpact($this->jours_[$date->format('N')], $periode, $train, null, $json_dates, $str_dates, 'Train supprimé: '.$train->getNumero(), 'supprime', $date->format('d/m/Y'));
}
break;
case 'multiple':
foreach($json_horaires['datesMultiple']['dates'] as $date){
$date = date_create_from_format('d/m/Y', $date);
$this->addImpact($this->jours_[$date->format('N')], $periode, $train, null, $json_dates, $str_dates, 'Train supprimé: '.$train->getNumero(), 'supprime', $date->format('d/m/Y'));
}
break;
case 'single':
$date = date_create_from_format('d/m/Y', $json_horaires['dateSingle']['dates'][0]);
$this->addImpact($this->jours_[$date->format('N')], $periode, $train, null, $json_dates, $str_dates, 'Train supprimé: '.$train->getNumero(), 'supprime', $date->format('d/m/Y'));
break;
}
$this->em->flush();
return $this->redirect($this->admin_url_generator->setController(AleaTrainSupprimeCrudController::class)->setAction(Action::INDEX)->generateUrl());
}
return $this->render('admin/impacts/add_train_supprime.html.twig', array('periodes' => $periodes));
}
#[Route('/admin/add_agent_indisponible', name: 'add_agent_indisponible')]
public function add_agent_indisponible(Request $request):Response{
$periodes = $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
if($request->isMethod('POST')){
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$agent = $this->em->getRepository(Agent::class)->find($request->request->get('agent'));
$json_dates = $request->request->get('json');
$str_dates = null;
$json_horaires = json_decode($json_dates, true);
switch($json_horaires['modeDates']){
case "range":
$str_dates = 'Du '.$json_horaires['datesRange']['dateStart'].' au '.$json_horaires['datesRange']['dateFinish'];
break;
case 'multiple':
$str_dates.= 'Les ';
$i = 0;
foreach($json_horaires['datesMultiple']['dates'] as $date){
if($i>0){
$str_dates.= ', ';
}
$str_dates.= $date;
$i++;
}
break;
case 'single':
$str_dates = 'Le '.$json_horaires['dateSingle']['dates'][0];
break;
}
$plan_gen = $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1, 'periode' => $periode));
$alea = new AleaAgentIndisponible;
$alea->setJson($json_dates)
->setCommentaire($request->request->get('commentaire'))
->setPeriode($periode)
->setAgent($agent)
->setVersion($plan_gen->getName())
->setTextDates($str_dates)
;
$this->em->persist($alea);
//IMPACTS
//RECHERCHE PLANNING PERMANENT OU UN/DES AGENTS SONT CONCERNES
switch($json_horaires['modeDates']){
case "range":
$date_debut = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateStart']);
$date_fin = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateFinish']);
$interval = $date_debut->diff($date_fin);
$nb_jour = $interval->d;
for ($i=0;$i<$nb_jour+1;$i++){
$date = date_create_from_format('d/m/Y', $json_horaires['datesRange']['dateStart']);
if($i > 0){
$date->add(new DateInterval('P'.$i.'D'));
}
//RECHERCHE TOUS LES TRAINS DU JOUR OU C'EST CET AGENT
//$plans = $this->em->getRepository(PlanningTemporaire::class)->getAgentsPerm($periode, $agent, $this->jours_[$date->format('N')]);
//foreach($plans as $p){
//SI RESERVE
//if($p->getTrainAller() == null && $p->getTrainRetour() == null){
$this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible', 'agent', $date->format('d/m/Y'));
//}else{
// $this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible', 'agent', $date->format('d/m/Y'));
//}
//}
}
break;
case 'multiple':
foreach($json_horaires['datesMultiple']['dates'] as $date){
$date = date_create_from_format('d/m/Y', $date);
//$plans = $this->em->getRepository(PlanningTemporaire::class)->getAgentsPerm($periode, $agent, $this->jours_[$date->format('N')]);
//foreach($plans as $p){
// if($p->getTrainAller() == null && $p->getTrainRetour() == null){
// $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'));
// }else{
$this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible', 'agent', $date->format('d/m/Y'));
// }
//}
}
break;
case 'single':
$date = date_create_from_format('d/m/Y', $json_horaires['dateSingle']['dates'][0]);
//$plans = $this->em->getRepository(PlanningTemporaire::class)->getAgentsPerm($periode, $agent, $this->jours_[$date->format('N')]);
//foreach($plans as $p){
// if($p->getTrainAller() == null && $p->getTrainRetour() == null){
// $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'));
// }else{
$this->addImpact($this->jours_[$date->format('N')], $periode, null, $agent, $json_dates, $str_dates, 'Agent indisponible', 'agent', $date->format('d/m/Y'));
// }
//}
break;
}
$this->em->flush();
return $this->redirect($this->admin_url_generator->setController(AleaAgentIndisponibleCrudController::class)->setAction(Action::INDEX)->generateUrl());
}
return $this->render('admin/impacts/add_agent_indisponible.html.twig', array('periodes' => $periodes));
}
#[Route('/admin/ajax_planning_load_agents', name: 'ajax_planning_load_agents')]
public function ajax_planning_load_agents(Request $request):Response{
$array_agents= array();
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$agents = $this->em->getRepository(Agent::class)->getPermAgents($periode);
foreach($agents as $a){
array_push($array_agents, array(
'id' => $a->getId(),
'name' => $a->getPrenom().' '.$a->getNom()
));
}
return new JsonResponse(array('agents' => $array_agents));
}
#[Route('/admin/ajax_planning_load_gare', name: 'ajax_planning_load_gare')]
public function ajax_planning_load_gare(Request $request):Response{
$array_gares = array();
$periode = $this->em->getRepository(Periode::class)->find($request->request->get('periode'));
$train = $this->em->getRepository(Train::class)->find($request->request->get('train'));
foreach($train->getEtapes() as $etape){
array_push($array_gares, [
'id' => $etape->getGare()->getId(),
'name' => $etape->getGare()->getCode()
]);
}
return new JsonResponse(array('gares' => $array_gares));
}
//Permanent
#[Route('/admin/planning_actif', name: 'planning_actif')]
public function planning_actif():Response{
$periodes = $this->em->getRepository(Periode::class)->findBy(array('actif' => 1));
$poles = $this->em->getRepository(Agent::class)->getPoles();
return $this->render('admin/planning_actif.html.twig', array('periodes' => $periodes, 'poles' => $poles));
}
#[Route('/admin/planning_actif/{periode_name}/{pole}/{date_debut}/{date_fin}', name: 'display_planning_actif_pole')]
public function display_planning_actif_pole(Request $request, $periode_name, $pole, $date_debut, $date_fin):Response{
$temp = array("pouet", "kpkpkpkp", "aedadeadza");
$date_debut = date_create_from_format('Y-m-d', $date_debut);
$date_debut->setTime(0,0,0);
$date_fin = date_create_from_format('Y-m-d', $date_fin);
$date_fin->setTime(23,59,59);
$periode = $this->em->getRepository(Periode::class)->findOneBy(array('name' => $periode_name));
$periode_actif = $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('periode' => $periode, 'valide' => 1));
$gare = $this->em->getRepository(Gare::class)->findOneBy(array('code' => $pole));
$interval = $date_debut->diff($date_fin);
$array_dates = [];
array_push($array_dates, $date_debut->format('d/m/Y'));
for($i=1;$i<=$interval->d;$i++){
$tmp_date = clone $date_debut;
$tmp_date->add(new DateInterval('P'.$i.'D'));
array_push($array_dates, $tmp_date->format('d/m/Y'));
}
$plans = $this->em->getRepository(PlanningTemporaire::class)->getPlanActif($periode_actif->getName(), $gare);
$i = 0;
foreach($plans as $plan){
//CHECK SI IMPACT A LA DATE ANNULE
$impacts = $this->em->getRepository(Impact::class)->findBy(array('planning_temporaire' => $plan));
foreach($impacts as $imp){
//Verifier
if(in_array($imp->getDate(), $array_dates) == true){
switch($imp->getStatutDecision()->getName()){
case 'annule':
unset($plans[$i]);
break;
case 'modifie':
$heures = $this->calculNewDates($imp);
$plans[$i]['train_depart_aller'] = $heures['heure_depart_aller'];
$plans[$i]['train_arrivee_aller'] = $heures['heure_arrivee_aller'];
$plans[$i]['train_depart_retour'] = $heures['heure_depart_retour'];
$plans[$i]['train_arrivee_retour'] = $heures['heure_arrivee_retour'];
$plans[$i]['train_prise_de_service_aller'] = $heures['heure_prise_de_service_aller'];
$plans[$i]['train_fin_de_service_aller'] = $heures['heure_fin_de_service_aller'];
$plans[$i]['train_prise_de_service_retour'] = $heures['heure_prise_de_service_retour'];
$plans[$i]['train_fin_de_service_retour'] = $heures['heure_fin_de_service_retour'];
//CALCULER PRISE ET FIN DE SERVICE
break;
case 'agent':
$plans[$i]['agent_name'] = $imp->getNewAgent()->getNom().' '.$imp->getNewAgent()->getPrenom();
$a = $this->em->getRepository(Agent::class)->findArray($imp->getNewAgent()->getId());
$plans[$i]['agent'] = $a;
break;
case 'boucle':
if($imp->getNewTrainAllerNumero() !== null){
$plans[$i]['train_numero_aller'] = $imp->getNewTrainAllerNumero();
$plans[$i]['train_depart_aller']= $imp->getNewHoraireDepartAller();
$plans[$i]['train_arrivee_aller']= $imp->getNewHoraireArriveeAller();
//CALCULER PRISE ET FIN DE SERVICE
}
if($imp->getNewTrainRetourNumero() !== null){
$plans[$i]['train_numero_retour'] = $imp->getNewTrainRetourNumero();
$plans[$i]['train_depart_retour']= $imp->getNewHoraireDepartRetour();
$plans[$i]['train_arrivee_retour']= $imp->getNewHoraireArriveeRetour();
//CALCULER PRISE ET FIN DE SERVICE
}
break;
}
}
}
$i++;
}
return $this->render('admin/planning_actif_pole.html.twig', array('plans' => $plans, 'gare' => $gare, 'periode' => $periode, 'date_debut' => $date_debut, 'date_fin' => $date_fin ));
}
private function calculNewDates($imp){
$train_aller = $imp->getPlanningTemporaire()->getTrainAller();
$train_retour = $imp->getPlanningTemporaire()->getTrainRetour();
$heure_depart_aller = $imp->getPlanningTemporaire()->getTrainDepartAller();
$heure_arrivee_aller= $imp->getPlanningTemporaire()->getTrainArriveeAller();
$heure_prise_de_service_aller = $imp->getPlanningTemporaire()->getTrainPriseDeServiceAller();
$heure_fin_de_service_aller = $imp->getPlanningTemporaire()->getTrainFinDeServiceAller();
$heure_depart_retour = $imp->getPlanningTemporaire()->getTrainDepartRetour();
$heure_arrivee_retour = $imp->getPlanningTemporaire()->getTrainArriveeRetour();
$heure_prise_de_service_retour = $imp->getPlanningTemporaire()->getTrainPriseDeServiceRetour();
$heure_fin_de_service_retour = $imp->getPlanningTemporaire()->getTrainFinDeServiceRetour();
if($imp->getNewHoraireDepartAller() !== null){
$heure_depart_aller = $imp->getNewHoraireDepartAller();
}
if($imp->getNewHoraireArriveeAller() !== null){
$heure_arrivee_aller = $imp->getNewHoraireArriveeAller();
}
$date_depart_aller = \DateTime::createFromFormat('H:i', $heure_depart_aller);
$date_arrivee_aller = \DateTime::createFromFormat('H:i', $heure_arrivee_aller);
if($imp->getNewHoraireDepartAller() !== null || $imp->getNewHoraireArriveeAller() !== null){
//CALCUL PRISE ET FIN DE SERVICE
$date_prise_de_service_aller = clone $date_depart_aller;
if($train_aller->getOrigineSpb()->getTempsPriseDeServiceAller() != null){
$i= new \DateInterval('PT'.$train_aller->getOrigineSpb()->getTempsPriseDeServiceAller().'M');
$date_prise_de_service_aller->sub($i);
$heure_prise_de_service_aller = $date_prise_de_service_aller->format('H:i');
}
$date_fin_de_service_aller = clone $date_arrivee_aller;
if($train_aller->getOrigineSpb()->getTempsFinDeServiceAller() != null){
$i = new \DateInterval('PT'.$train_aller->getDestinationSpb()->getTempsFinDeServiceAller().'M');
$date_fin_de_service_aller->add($i);
$heure_fin_de_service_aller = $date_fin_de_service_aller->format('H:i');
}
}
if($imp->getNewHoraireDepartRetour() !== null){
$heure_depart_retour = $imp->getNewHoraireDepartRetour();
}
if($imp->getNewHoraireArriveeRetour() !== null){
$heure_arrivee_retour = $imp->getNewHoraireArriveeRetour();
}
$date_depart_retour = \DateTime::createFromFormat('H:i', $heure_depart_retour);
$date_arrivee_retour = \DateTime::createFromFormat('H:i', $heure_arrivee_retour);
if($imp->getNewHoraireDepartRetour() !== null || $imp->getNewHoraireArriveeRetour() !== null){
//CALCUL PRISE ET FIN DE SERVICE
$date_prise_de_service_retour = clone $date_depart_retour;
if($train_retour->getOrigineSpb()->getTempsPriseDeServiceRetour() != null){
$i= new \DateInterval('PT'.$train_retour->getOrigineSpb()->getTempsPriseDeServiceRetour().'M');
$date_prise_de_service_retour->sub($i);
$heure_prise_de_service_retour = $date_prise_de_service_retour->format('H:i');
}
$date_fin_de_service_retour = clone $date_arrivee_retour;
if($train_retour->getOrigineSpb()->getTempsFinDeServiceRetour() != null){
$i = new \DateInterval('PT'.$train_retour->getDestinationSpb()->getTempsFinDeServiceRetour().'M');
$date_fin_de_service_retour->add($i);
$heure_fin_de_service_retour = $date_fin_de_service_retour->format('H:i');
}
}
return [
'heure_depart_aller' => $heure_depart_aller,
'heure_arrivee_aller' => $heure_arrivee_aller,
'heure_prise_de_service_aller' => $heure_prise_de_service_aller,
'heure_fin_de_service_aller' => $heure_fin_de_service_aller,
'heure_depart_retour' => $heure_depart_retour,
'heure_arrivee_retour' => $heure_arrivee_retour,
'heure_prise_de_service_retour' => $heure_prise_de_service_retour,
'heure_fin_de_service_retour' => $heure_fin_de_service_retour
];
}
private function addImpact($jour, $periode, $train = null, $agent = null, $json_dates = null, $str_dates= null, $description= null, $type= null, $date= null, $origine = null, $destination = null, $alea_limite = null){
$statut_decision = $this->em->getRepository(DecisionStatut::class)->find(5);
$statut = $this->em->getRepository(ImpactStatut::class)->find(1);
$plan_gen = $this->em->getRepository(PlanningTemporaireGenere::class)->findOneBy(array('valide' => 1, 'periode' => $periode));
$datetime = date_create_from_format('d/m/Y', $date);
if($agent !== null){
$perms = $this->em->getRepository(PlanningTemporaire::class)->findBy(['agent' => $agent, 'jour' => $jour, 'periode' => $periode, 'name' => $plan_gen->getName()]);
foreach($perms as $perm){
if($perm->getTrainAller() == null && $perm->getTrainRetour() == null){
$description.= ' pour réserve';
}
$impact = new Impact;
$impact
->setStatutDecision($statut_decision)
->setStatut($statut)
->setPeriode($periode)
->setDescription($description)
->setVersion($plan_gen->getName())
->setType($type)
->setTrainAller($perm->getTrainAller())
->setTrainRetour($perm->getTrainRetour())
->setJson($json_dates)
->setTextDates($str_dates)
->setAgent($perm->getAgent())
->setDate($date)
->setDatetime($datetime)
->setJour($jour)
->setPlanningTemporaire($perm)
->setAleaLimite($alea_limite)
;
$this->em->persist($impact);
}
}else{
$perms_aller = $this->em->getRepository(PlanningTemporaire::class)->findBy(['jour' => $jour, 'periode' => $periode, 'train_aller' => $train, 'name' => $plan_gen->getName()]);
foreach($perms_aller as $perm){
$impact = new Impact;
$impact
->setStatutDecision($statut_decision)
->setImpactTrain($train)
->setStatut($statut)
->setPeriode($periode)
->setDescription($description)
->setVersion($plan_gen->getName())
->setType($type)
->setTrainAller($train)
->setTrainRetour($perm->getTrainRetour())
->setJson($json_dates)
->setTextDates($str_dates)
->setAgent($perm->getAgent())
->setDate($date)
->setNewDestinationAller($destination)
->setNewOrigineAller($origine)
->setDatetime($datetime)
->setJour($jour)
->setPlanningTemporaire($perm)
->setAleaLimite($alea_limite)
;
$this->em->persist($impact);
}
$perms_retour = $this->em->getRepository(PlanningTemporaire::class)->findBy(['jour' => $jour, 'periode' => $periode, 'train_retour' => $train, 'name' => $plan_gen->getName()]);
foreach($perms_retour as $perm){
$impact = new Impact;
$impact
->setStatutDecision($statut_decision)
->setImpactTrain($train)
->setStatut($statut)
->setPeriode($periode)
->setDescription($description)
->setVersion($plan_gen->getName())
->setType($type)
->setTrainAller($perm->getTrainAller())
->setTrainRetour($train)
->setJson($json_dates)
->setTextDates($str_dates)
->setAgent($perm->getAgent())
->setDate($date)
->setNewDestinationRetour($destination)
->setNewOrigineRetour($origine)
->setDatetime($datetime)
->setJour($jour)
->setPlanningTemporaire($perm)
->setAleaLimite($alea_limite)
;
$this->em->persist($impact);
}
}
return true;
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle('NICOLLIN PLANIF SPB')
->setFaviconPath('img/favicon.svg')
;
}
public function configureMenuItems(): iterable
{
$menu = [
MenuItem::linkToDashboard('Dashboard', 'fa fa-home'),
MenuItem::section("Prévisionnel"),
MenuItem::subMenu('Planning prévisionnel', '')->setSubItems([
MenuItem::linkToRoute('Ajouter horaire/agent', '', 'add_manual'),
MenuItem::linkToCrud('Ajouts manuels', '', AjoutManuel::class),
MenuItem::linkToRoute('Générer planning v2', '', 'generer_planning_v2'),
MenuItem::linkToCrud('Plannings générés', '', PlanningTemporaireGenere::class),
MenuItem::linkToRoute('Calendrier temporaire', '', 'display_calendar'),
]),
MenuItem::section("Suivi d'exploitation"),
MenuItem::subMenu("Aléas", '')->setSubItems([
MenuItem::linkToCrud('Trains limités', '', AleaTrainLimite::class),
MenuItem::linkToCrud('Trains supprimés', '', AleaTrainSupprime::class),
MenuItem::linkToCrud('Agents indisponibles', '', AleaAgentIndisponible::class),
]),
MenuItem::linkToCrud('Impacts par jour', '', Impact::class),
MenuItem::linkToRoute('Planning actif', '', 'planning_actif'),
MenuItem::subMenu("Partage d'info", '')->setSubItems([
]),
MenuItem::section("Données"),
MenuItem::subMenu('Agents', '')->setSubItems([
MenuItem::linkToCrud('Tous', '', Agent::class),
MenuItem::linkToCrud('Actifs', '', Agent::class)->setQueryParameter('actif', 1),
]),
MenuItem::linkToCrud('Gares', '', Gare::class),
MenuItem::linkToCrud('Trains', '', Train::class),
MenuItem::linkToCrud('Axes', '', Axe::class),
MenuItem::linkToCrud('Contrats', '', Contrat::class),
MenuItem::linkToCrud('Périodes', '', Periode::class),
MenuItem::linkToCrud('Utilisateurs', '', User::class),
MenuItem::linkToCrud('Pattern jours', '', PatternJour::class),
MenuItem::linkToCrud('Paramétrage', '', Parametre::class)->setAction('edit')->setQueryParameter('entityId', 1),
MenuItem::linkToCrud('Sens de parcours', '', Jour::class)->setAction('index')
];
return $menu;
}
}