src/Controller/Alis/ParutionController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Alis;
  3. use App\Entity\RoutageJustif;
  4. use App\Services\EnvDetector;
  5. use App\Services\MontageService;
  6. use PhpOffice\PhpSpreadsheet\Shared\Date;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  12. use Knp\Component\Pager\PaginatorInterface;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use App\Entity\Annonce;
  15. use App\Entity\Parution;
  16. use App\Entity\Greffe\Demat as GreffeDemat;
  17. use App\Entity\Departement;
  18. use App\Repository\AnnonceRepository;
  19. use App\Repository\DepartementRepository;
  20. use App\Repository\ParutionRepository;
  21. use App\Repository\Greffe\DematRepository as GreffeDematRepository;
  22. use App\Repository\Annonce\TypeRepository;
  23. use App\Repository\Annonce\TypeChapitreRepository;
  24. use App\Repository\Greffe\ImportRepository as ImportGreffeRepository;
  25. use App\Services\LignageService;
  26. use App\Services\FileService;
  27. use App\Services\XtagService;
  28. use App\Services\EmailSender;
  29. use App\Services\FactureService;
  30. use App\Services\PdfService;
  31. use App\Factory\AnnonceFactory;
  32. #[Route('/alis/parution')]
  33. class ParutionController extends AbstractController
  34. {
  35.     private ParutionRepository $parRepo;
  36.     public function __construct(ParutionRepository $parRepo)
  37.     {
  38.         $this->parRepo $parRepo;
  39.     }
  40.     #[Route('/'methods: ['GET'])]
  41.     public function index(Request $request): Response
  42.     {
  43.         return $this->render('alis/parution/index.html.twig', []);
  44.     }
  45.     #[Route('/infos/{type}'methods: ['GET'])]
  46.     public function infos(
  47.             DepartementRepository $depRepoAnnonceRepository $annRepo,
  48.             GreffeDematRepository $greffeDematRepoRequest $request$type=""): Response
  49.     {
  50.         $depsWeb = [];
  51.         if(!$type || $type=="web") {
  52.             $depsWeb $depRepo->findAllWeb();
  53.         }
  54.         $parutions_open = [];
  55.         if(!$type || $type=="open") {
  56.             $parutions_open $this->parRepo->findAllOpenArray(); //findAllOpen();
  57.         }
  58.         $parutions_closed = [];
  59.         if(!$type || $type=="closed") {
  60.             $limit 12;
  61.             if(!$type=="closed") {
  62.                 $limit 30;
  63.             }
  64.             $parutions_closed $this->parRepo->findAllClosed($limit);
  65.         }
  66.         $webDepartements = [];
  67.         foreach($depsWeb as $dep) {
  68.             $annonces $annRepo->findForWebDep($dep->getCode(), falsetrue)->getQuery()->getResult();
  69.             $bodaccs =  count($annRepo->findWithBodaccForWebDep($dep->getCode()));
  70.             $bodaccsB255 =  count($annRepo->findWithBodaccB255ForWebDep($dep->getCode()));
  71.             $greffes $greffeDematRepo->findDepActive($dep);
  72.             $webDepartements[$dep->getCode()] = [
  73.                 "departement" => $dep,
  74.                 "annonces" => $annonces,
  75.                 "bodaccs" => $bodaccs,
  76.                 "bodaccsB255" => $bodaccsB255,
  77.                 "greffes" => $greffes
  78.             ];
  79.         }
  80.         $xtag_du = new \DateTime("last thursday");
  81.         $xtag_au = new \DateTime("yesterday");
  82.         if($xtag_du == $xtag_au) {
  83.             $xtag_du->sub(new \DateInterval("P7D"));
  84.             $xtag_au->sub(new \DateInterval("P1D"));
  85.         }
  86.         $xtag55_du = new \DateTime("last friday");
  87.         $xtag55_au = new \DateTime("yesterday");
  88.         
  89.         $montage_au = new \DateTime("last sunday");
  90.         $montage_du = new \DateTime("last sunday");
  91.         $montage_du->sub(new \DateInterval("P6D"));
  92.         return $this->render('alis/parution/infos.html.twig', [
  93.             'webDepartements' => $webDepartements,
  94.             'parutions_open' => $parutions_open,
  95.             'parutions_closed' => $parutions_closed,
  96.             'xtag_du' => $xtag_du,
  97.             'xtag_au' => $xtag_au,
  98.             'xtag55_du' => $xtag55_du,
  99.             'xtag55_au' => $xtag55_au,
  100.             'montage_du' => $montage_du,
  101.             'montage_au' => $montage_au,
  102.         ]);
  103.     }
  104.     
  105.     #[Route('/info/{dep}'methods: ['GET'])]
  106.     public function info(AnnonceRepository $annRepoGreffeDematRepository $greffeDematRepoRequest $requestDepartement $dep): Response
  107.     {
  108.         $annonces $annRepo->findForWebDep($dep->getCode())->getQuery()->getResult();
  109.         $bodaccs $annRepo->findWithBodaccForWebDep($dep->getCode());
  110.         $bodaccsB255 $annRepo->findWithBodaccB255ForWebDep($dep->getCode());
  111.         $greffes $greffeDematRepo->findDepActive($dep);
  112.         
  113.         $webDepartement = [
  114.             "departement" => $dep,
  115.             "annonces" => $annonces,
  116.             "bodaccs" => $bodaccs,
  117.             "bodaccsB255" => $bodaccsB255,
  118.             "greffes" => $greffes
  119.         ];
  120.         
  121.         return $this->render('alis/parution/info.html.twig', [
  122.             'webDepartement' => $webDepartement
  123.         ]);
  124.     }
  125.     #[Route('/show_id/{id}'methods: ['GET'])]
  126.     public function show_id(Request $requestParution $parution): Response
  127.     {
  128.         $dep $parution->getDepartement()->getCode();
  129.         $num $parution->getNum();
  130.         return $this->redirectToRoute('app_alis_parution_show', ['dep'=>$dep'num'=>$num]);
  131.     }
  132.     #[Route('/recalcXtag/{dep}/{num}/'methods: ['GET','POST'])]
  133.     public function recalXtag(Request $request$dep$num): Response
  134.     {
  135.         $parution $this->parRepo->findOneByDepNum($dep$num);
  136.         foreach ($parution->getAnnonces() as $annonce) {
  137.             $annonce->getEditeur()?->setTexteBalise();
  138.         }
  139.         $this->getDoctrine()->getManager()->flush();
  140.         return new Response('OK');
  141.     }
  142.     #[Route('/show/{dep}/{num}/{conducteur}'methods: ['GET','POST'])]
  143.     public function show(
  144.             AnnonceRepository $annRepoPaginatorInterface $paginatorXtagService $xtagService
  145.             TypeChapitreRepository $typeChapitreRepoImportGreffeRepository $importGreffeRepo,
  146.             Request $request$dep$num$conducteur=null): Response
  147.     {
  148.         $form null//conducteur
  149.         $parution null;
  150.         $annonces = [];
  151.         $type 'papier';
  152.         $label '';
  153.         $show_planned false;
  154.         $show_conducteur false;
  155.         $show_corrigee false;
  156.         $chapitres = [];
  157.         $greffe_demats = [];
  158.         $array_stats = [];
  159.         $recherche_enabled true;
  160.         if($num == "web") {
  161.             $annonces $annRepo->findForWebDep($dep);
  162.             $type 'web';
  163.             $label 'Parution web '.$dep;
  164.             $show_planned true;
  165.             $show_corrigee true;
  166.             
  167.             $array_stats $annRepo->findForWebDepStat($dep); 
  168.             
  169.         }
  170.         elseif($num == "external") {
  171.             $annonces $annRepo->findExternalEnCours();
  172.             $type "external";
  173.             $dep $parution null;
  174.             $label "Annonces extérieures en cours";
  175.             $show_corrigee false;
  176.         }
  177.         else {
  178.             $show_corrigee true;
  179.             $parution $this->parRepo->findOneByDepNum($dep$num);
  180.             if(!$parution) {
  181.                 throw new \Exception("NOT found parution ".$dep." ".$num);
  182.             }
  183.             $annonces $annRepo->findForParution($parution);
  184.             if($conducteur === "1") {
  185.                 $annonces $annRepo->getAnnoncesOrdered($parutiontrue);
  186.             }
  187.             
  188.             $label 'Edition '.$dep." n. ".$num." du ".$parution->getDate()->format("d/m/Y");
  189.             
  190.             $array_stats $annRepo->findForParutionStat($parution); 
  191.         }
  192.         
  193.         if($conducteur === "1") {
  194.             $recherche_enabled false;
  195.             $array_stats = [];
  196.             
  197.             $chapitres $typeChapitreRepo->findAll();
  198.             if($parution) {
  199.                 $greffe_demats $importGreffeRepo->findOnParution($parution);
  200.             }
  201.            
  202.             
  203.             $show_conducteur true;
  204.             $show_corrigee false;
  205.             $model = [];
  206.             $form $this->createForm(\App\Form\Parution\ConducteurType::class, $model, ['attr' => ['target' => '_blank']]);
  207.             $form->handleRequest($request);
  208.             if($form->isSubmitted() && $form->isValid()) {
  209.                 
  210.                 $annonces_all $annonces_xtag = [];
  211.                 if($parution) {
  212.                     $annonces_all $annRepo->getAnnoncesOrdered($parution);
  213.                 } else {
  214.                     $annonces_all $paginator->paginate($annonces11000)->getItems();
  215.                 }
  216.                 
  217.                 $selected $form->get("selected")->getData();
  218.                 //if($selected) {                   
  219.                     $ids explode(","$selected);
  220.                     foreach($annonces_all as $annonce) {
  221.                         if(in_array($annonce->getId(), $ids)) {
  222.                             array_push($annonces_xtag$annonce);
  223.                         }
  224.                     }
  225.                     
  226.                 /*} else {
  227.                     $annonces_xtag = $annonces_all;
  228.                 }*/
  229.                 
  230.                 $xtag $xtagService->getXtagForAnnonces($annonces_xtag);
  231.                 return $this->xtagResponse($xtag);
  232.             }
  233.             
  234.             //era così prima
  235.             /*if($request->get("xtag")) {
  236.                 $annonces_xtag = null;
  237.                 if($parution) {
  238.                     //per avere ordine corretto e quindi sempre tutti non + i selezionati in questo caso
  239.                     $annonces_xtag = $annRepo->getAnnoncesOrdered($parution);
  240.                 } else {
  241.                     $annonces_xtag = $paginator->paginate($annonces, 1, 1000)->getItems();
  242.                 }
  243.                 $xtag = $xtagService->getXtagForAnnonces($annonces_xtag);
  244.                 return $this->xtagResponse($xtag);
  245.             }*/
  246.         }
  247.         $pagination $paginator->paginate(
  248.             $annonces,
  249.             $request->query->getInt('page'1),
  250.             500
  251.         );
  252.         return $this->render('alis/parution/show.html.twig', [
  253.             //'clients' => $clientRepository->findAll(),
  254.             'pagination' => $pagination,
  255.             'parution' => $parution,
  256.             'type' => $type,
  257.             'dep' => $dep,
  258.             'label' => $label,
  259.             'show_planned' => $show_planned,
  260.             'show_conducteur' => $show_conducteur,
  261.             'show_corrigee' => $show_corrigee,
  262.             'form' => $form $form->createView() : null,
  263.             'chapitres' => $chapitres,
  264.             'greffe_demats' => $greffe_demats,
  265.             'array_stats' => $array_stats,
  266.             'recherche_enabled' => $recherche_enabled
  267.         ]);
  268.     }
  269.     #[Route('/external'methods: ['GET'])]
  270.     public function external(AnnonceRepository $annRepoPaginatorInterface $paginatorRequest $request): Response
  271.     {
  272.         return $this->redirectToRoute("app_alis_parution_show", ["dep"=>"0","num"=>"external"]);
  273.     }
  274.     #[Route('/menu'methods: ['GET'])]
  275.     public function menu(DepartementRepository $depRepoRequest $request): Response
  276.     {
  277.         //rendered by menu
  278.         $depsPapier $depRepo->findAllPapier();
  279.         $depsWeb $depRepo->findAllWeb();
  280.         $parutions = [];
  281.         foreach($depsPapier as $dep) {
  282.             $par $this->parRepo->findCurrent($dep->getCode());
  283.             if($par) {
  284.                 array_push($parutions$par);
  285.             }
  286.         }
  287.         return $this->render('alis/parution/menu.html.twig', [
  288.             'parutions' => $parutions,
  289.             'depsWeb' => $depsWeb
  290.         ]);
  291.     }
  292.     #[Route('/conducteur/{id}'methods: ['GET'])]
  293.     public function conducteur(Request $requestParution $parution): Response
  294.     {
  295.         $dep $parution->getDepartement()->getCode();
  296.         $num $parution->getNum();
  297.         return $this->redirectToRoute('app_alis_parution_show', ['dep'=>$dep'num'=>$num'conducteur'=>'1']);
  298.     }
  299.     #[Route('/close/{id}'methods: ['GET'])]
  300.     public function close(Request $requestParution $parution): Response
  301.     {
  302.         try {
  303.             if(!$parution->isClosable()) {
  304.                 throw new \Exception("Parution ".$parution." NOT closable");
  305.             }
  306.             $parution->close();
  307.             $this->getDoctrine()->getManager()->flush();
  308.             $this->addFlash('success''parution clôturée');
  309.         } catch(\Exception $ex) {
  310.             $this->addFlash('danger'$ex->getMessage());
  311.         }
  312.         return $this->redirectToRoute('app_alis_parution_show_id', ['id'=>$parution->getId()]);
  313.     }
  314.     #[Route('/lignages/extl'methods: ['GET'])]
  315.     public function lignages(LignageService $lignageServiceAnnonceFactory $annonceFactoryAnnonceRepository $annonceRepoFactureService $factureService): Response
  316.     {
  317.         //verfica le parution chiuse se tutti gli annunci sono scritti
  318.         //se si calcola il lignage
  319.         
  320.         /*$now = new \DateTime();
  321.         if($now > new \DateTime("2023-12-29 00:00:00") && $now < new \DateTime("2024-01-01 05:00:00") ) {
  322.             return new Response("script blocked --> invali day ".$now->format("Y-m-d"));
  323.         }*/
  324.         
  325.         $tot $pars 0;
  326.         $parutions $this->parRepo->findAllClosed(12);
  327.         foreach($parutions as $parution) {
  328.             if($parution->needsLignage()) {
  329.                 
  330.                 $callLignage=true;
  331.                 
  332.                 foreach($parution->getLignageAnnonces() as $annonce) {
  333.                     if(!$annonce->isSaisie()) {
  334.                         $callLignage=false;
  335.                         break;
  336.                     }
  337.                 }
  338.                 
  339.                 if($callLignage) {
  340.                     $arrPar $lignageService->calculateParution($parution$annonceFactory);
  341.                     $count $arrPar['count'];
  342.                     
  343.                     $pars++;
  344.                     $tot += $count;
  345.                 }
  346.             }
  347.         }
  348.         
  349.         $this->getDoctrine()->getManager()->flush();
  350.         
  351.         //app_alis_facture_generate
  352.         $annonces $annonceRepo->findToFactureGeneration();
  353.         if(count($annonces) > 0) {
  354.             $factureService->generateFactureForAnnonces($annoncesfalse);
  355.         }       
  356.         
  357.         return new Response($pars." parution calculated, ".$tot." annonces");
  358.     }
  359.     
  360.     #[Route('/lignage/{id}/extl'methods: ['GET'])]
  361.     public function lignage(LignageService $lignageServiceAnnonceFactory $annonceFactoryRequest $requestParution $parution): Response
  362.     {
  363.         set_time_limit(-1);
  364.     ini_set('memory_limit','4096M');
  365.         try {
  366.             if(!$parution->isClosed()) {
  367.                 throw new \Exception("Parution ".$parution." NOT closed");
  368.             }
  369.             
  370.             if(!$parution->needsLignage()) {
  371.                 throw new \Exception("Parution ".$parution." NOT need lignage");
  372.             }
  373.             
  374.             $arrPar $lignageService->calculateParution($parution$annonceFactory);
  375.             $msg $arrPar['msg'];
  376.             $count $arrPar['count'];
  377.             $this->getDoctrine()->getManager()->flush();
  378.             $this->addFlash('success'$count.' annonces : lignage calculé');
  379.             if($msg) {
  380.                 $this->addFlash('danger''annonce '.$msg.' pas saisie');
  381.             } else {
  382.                 return $this->redirectToRoute("app_alis_facture_generate");
  383.             }
  384.         } catch(\Exception $ex) {
  385.             $this->addFlash('danger'$ex->getMessage());
  386.         }
  387.         return $this->redirectToRoute('app_alis_parution_show_id', ['id'=>$parution->getId()]);
  388.     }
  389.     #[Route('/indesign/{id}'methods: ['GET','POST'])]
  390.     public function indesign(FileService $fileServiceAnnonceFactory $annonceFactoryRequest $requestParution $parutionEnvDetector $envDetector): Response
  391.     {
  392.         $form $this->createForm(\App\Form\Parution\IndesignType::class);
  393.         try {
  394.             if(!$parution->isClosed()) {
  395.                 throw new \Exception("Parution ".$parution." NOT closed");
  396.             }
  397.             $parution->checkIfAllReadyForIndesign();
  398.             $form->handleRequest($request);
  399.             if ($form->isSubmitted() && $form->isValid()) {
  400.                 $file $form->get('filename')->getData();
  401.                 $now = new \DateTime();
  402.                 $dir $fileService->getProjectDir()."/var/alis/parution/import/";
  403.                 $fileName $parution->getId()."_".$now->format("ymdHis");
  404.                 $path $dir.$fileName;
  405.                 $file->move($dir$fileName);
  406.                 $arrayAnnonces $fileService->importFileIndesign($parution$path);
  407.                 foreach($arrayAnnonces as $row) {
  408.                     $annonce $row["annonce"];
  409.                     $numpage $row["numpage"];
  410.                     $annonce->getMisenpage()->setNumpage($numpage);
  411.                     foreach($annonce->getFactures() as $facture) {
  412.                         if($facture->getEtat() == 0) {
  413.                             $facture->setEtat(1);
  414.                         }
  415.                         $facture->getInfo()->setNumpage($numpage);
  416.                     }
  417.                     $annonceFactory->set($annonce)->changeEtat("monte");
  418.                 }
  419.                 $parution->setStartPage($form->get('start_page')->getData());
  420.                 $this->getDoctrine()->getManager()->flush();
  421.                 $this->addFlash("success""Importation indesign parution ".$parution." terminée avec succès (".count($arrayAnnonces)." annonces)");
  422.                 return $this->redirectToRoute('app_alis_parution_index');
  423.             }
  424.         } catch(\Exception $ex) {
  425.             if($envDetector->isTest()) {
  426.                 throw $ex;
  427.             }
  428.             $this->addFlash('danger'"<b>Erreur lors de l'importation</b><br/>".$ex->getMessage());
  429.         }
  430.         return $this->render('alis/parution/indesign.html.twig', [
  431.             'form' => $form->createView(),
  432.             'parution' => $parution,
  433.         ]);
  434.     }
  435.     
  436.     #[Route('/lignage/{id}/upload'methods: ['GET','POST'])]
  437.     public function lignage_upload(FileService $fileServiceAnnonceFactory $annonceFactoryRequest $requestParution $parutionEnvDetector $envDetector): Response
  438.     {
  439.         $form $this->createForm(\App\Form\Parution\IndesignType::class);
  440.         try {
  441.             if(!$parution->isClosed()) {
  442.                 throw new \Exception("Parution ".$parution." NOT closed");
  443.             }
  444.             
  445.             if(!$parution->needsUploadLignage()) {
  446.                 throw new \Exception("Parution ".$parution." NOT neeeds lignage upload");
  447.             }
  448.             $form->handleRequest($request);
  449.             if ($form->isSubmitted() && $form->isValid()) {
  450.                 $file $form->get('filename')->getData();
  451.                 $now = new \DateTime();
  452.                 $dir $fileService->getProjectDir()."/var/alis/parution/import/";
  453.                 $fileName "lignage_".$parution->getId()."_".$now->format("ymdHis");
  454.                 $path $dir.$fileName;
  455.                 $file->move($dir$fileName);
  456.                 $arrayAnnonces $fileService->importFileLignage($parution$path);
  457.                 if(count($arrayAnnonces) > 0) {
  458.                     foreach($arrayAnnonces as $row) {
  459.                         $annonce $row["annonce"];
  460.                         $numligs $row["numligs"];
  461.                     
  462.                         $annonce->setLignage($numligs);
  463.                         $annonceFactory->set($annonce)->changeEtat("lignage"); //->flush();
  464.                     }
  465.                     $this->getDoctrine()->getManager()->flush();
  466.                     $this->addFlash("success""Importation lignage parution ".$parution." terminée avec succès (".count($arrayAnnonces)." annonces)");
  467.                     return $this->redirectToRoute("app_alis_facture_generate");
  468.                  }
  469.                  $this->addFlash("danger""Importation lignage parution ".$parution." terminée avec 0 annonces");
  470.                  return $this->redirectToRoute('app_alis_parution_index');
  471.             }
  472.         } catch(\Exception $ex) {
  473.             if($envDetector->isTest()) {
  474.                 throw $ex;
  475.             }
  476.             $this->addFlash('danger'"<b>Erreur lors de l'importation</b><br/>".$ex->getMessage());
  477.         }
  478.         return $this->render('alis/parution/lignage.html.twig', [
  479.             'form' => $form->createView(),
  480.             'parution' => $parution,
  481.         ]);
  482.     }
  483.     
  484.     #[Route('/lignage/{id}/download'methods: ['GET','POST'])]
  485.     public function lignage_download(FileService $fileServiceRequest $requestParution $parution): Response
  486.     {
  487.         if(!$parution->isClosed()) {
  488.             throw new \Exception("Parution ".$parution." NOT closed");
  489.         }
  490.         if(!$parution->needsUploadLignage()) {
  491.             throw new \Exception("Parution ".$parution." NOT neeeds lignage upload");
  492.         }
  493.         
  494.         $text "";
  495.         foreach($parution->getLignageAnnonces() as $annonce) {
  496.             $text .= $annonce->getId()."|\n";
  497.         }
  498.         
  499.         return $this->xtagResponse($text"lignage_".$parution->getNum().".txt");
  500.     }
  501.     private function xtagResponse($xtag$filename='xtag.txt') : Response
  502.     {
  503.         $response = new Response($xtag);
  504.         $disposition $response->headers->makeDisposition(
  505.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  506.             $filename
  507.         );
  508.         $response->headers->set('Content-Disposition'$disposition);
  509.            return $response;
  510.     }
  511.     #[Route('/xtag/greffe/{parution}/{greffe}'methods: ['GET'])]
  512.     public function xtag_greffe (
  513.         AnnonceRepository $annonceRepoXtagService $xtagServiceRequest $request,
  514.         Parution $parutionGreffeDemat $greffe): Response
  515.     {
  516.         $annonces $annonceRepo->getAnnoncesGreffeDematOrdered($parution$greffe);
  517.         //dump($annonces);
  518.         $xtag $xtagService->getXtagForAnnoncesGreffe($greffe$annonces);
  519.         return $this->xtagResponse($xtag);
  520.     }
  521.     #[Route('/xtag/greffe_demat/{greffe}/{du}/{au}'methods: ['GET'])]
  522.     public function xtag_greffe_demat (
  523.         AnnonceRepository $annonceRepoXtagService $xtagServiceRequest $request,
  524.         GreffeDemat $greffe$du$au): Response
  525.     {
  526.         $du = new \DateTime($du." 00:00:00");
  527.         $au = new \DateTime($au." 23:59:59");
  528.            $annonces $annonceRepo->getAnnoncesGreffeDematOrdered(null$greffe$du$au);
  529.         //dump($annonces);
  530.            $xtag $xtagService->getXtagForAnnoncesGreffe($greffe$annonces);
  531.         return $this->xtagResponse($xtag);
  532.     }
  533.     #[Route('/xtag/departement/{dep}/{du}/{au}'methods: ['GET'])]
  534.     public function xtag_departement (
  535.         AnnonceRepository $annonceRepoXtagService $xtagServiceRequest $request,
  536.         \App\Entity\Departement $dep$du$au): Response
  537.     {
  538.         $du = new \DateTime($du." 00:00:00");
  539.         $au = new \DateTime($au." 23:59:59");
  540.         //degli annunci pubblicati nel dep nel periodo selezionato
  541.            $annonces $annonceRepo->getAnnoncesDepPulishedOrdered($dep$du$au);
  542.         //dump($annonces);
  543.         $xtag $xtagService->getXtagForAnnonces($annoncestrue);
  544.         return $this->xtagResponse($xtag);
  545.     }
  546.     #[Route('/xtag/parution/{parution}'methods: ['GET'])]
  547.     public function xtag(AnnonceRepository $annonceRepoXtagService $xtagServiceRequest $requestParution $parution): Response
  548.     {
  549.         $annonces $annonceRepo->getAnnoncesOrdered($parution);
  550.         //dump($annonces);
  551.         $xtag $xtagService->getXtagForAnnonces($annonces);
  552.         return $this->xtagResponse($xtag);
  553.     }
  554.     #[Route('/pdf/{id}'methods: ['GET'])]
  555.     public function pdf(Request $requestParution $parution): Response
  556.     {
  557.         $codedep $parution->getDepartement()->getCode();
  558.         $societe $parution->getSociete();
  559.         $journal_prefix $societe->getPrefix();
  560.         $numparution $parution->getNum();
  561.         $dateparution $parution->getDate();
  562.         $filename $journal_prefix.'_'.$numparution;
  563.         if($codedep == "02" && $numparution 3866) {
  564.             $filename .= '_A';
  565.         }
  566.         if($codedep == "80" && $numparution 3866) {
  567.             $filename .= '_S';
  568.         }
  569.         //Since 2023, single file
  570.         if($parution->getDate() < new \DateTime('2023-01-01')) {
  571.             $filename .= '_al';
  572.         }
  573.         $filename .= '.pdf';
  574.         $filepath $dateparution->format('Y/m/').$filename;
  575.         $ftphost $societe->getFtpHost();
  576.         $ftpuser $societe->getFtpUser();
  577.         $ftppass $societe->getFtpPsw();
  578.         $pdf = @file_get_contents('ftp://'.$ftpuser.':'.$ftppass.'@'.$ftphost.'/'.$filepath);
  579.         //return $pdf;
  580.         if (empty($pdf)) {
  581.             return new Response('PDF NOT FOUND');
  582.         }
  583.         return new Response($pdf200, array(
  584.             'Content-Disposition' => 'filename="'.$filename.'"',
  585.             'Content-Type' => 'application/pdf'
  586.         ));
  587.     }
  588.     #[Route('/mail/{id}/cloture'methods: ['GET'])]
  589.     public function mail_cloture(EmailSender $emailSenderRequest $requestParution $parution): Response
  590.     {
  591.         try {
  592.             if(!$parution->isClosed()) {
  593.                 throw new \Exception("Parution ".$parution." NOT closed");
  594.             }
  595.             $emailSender->sendEmailCloture($parution);
  596.             $this->addFlash('success''mail sent');
  597.         } catch(\Exception $ex) {
  598.             $this->addFlash('danger'$ex->getMessage());
  599.         }
  600.         return $this->redirectToRoute('app_alis_parution_show_id', ['id'=>$parution->getId()]);
  601.     }
  602.     #[Route('/parchapitre/{id}/'methods: ['GET'])]
  603.     public function parchapitre(Request $requestParution $parutionTypeChapitreRepository $typeChapitreRepoTypeRepository $typeRepoAnnonceRepository $annonceRepoPdfService $pdfService): Response
  604.     {
  605.         /*$chapitres = $typeChapitreRepo->findAll();
  606.         $types = $typeRepo->findAll();
  607.         $annonces = [];
  608.         foreach ($chapitres as $chapitre)
  609.         {
  610.             $annonces[] = [
  611.                 'chapitre' => $chapitre,
  612.                 'annonces'  => $annonceRepo->findByType($parution, $chapitre)
  613.             ];
  614.         }*/
  615.         
  616.         $annonces = [];
  617.         $annonces_all $annonceRepo->getAnnoncesOrdered($parutiontrue);
  618.         foreach($annonces_all as $annonce) {
  619.             $chapitre $annonce->getType() ? $annonce->getType()->getTypeChapitre() : null;
  620.             if($chapitre) {
  621.                 $idChapitre $chapitre->getId();
  622.                 
  623.                 if(!array_key_exists($idChapitre$annonces)) {
  624.                     $annonces[$idChapitre] = [
  625.                         'chapitre' => $chapitre,
  626.                         'annonces' => []
  627.                     ];
  628.                 } 
  629.                 
  630.                 $currentAnnonces $annonces[$idChapitre]['annonces'];
  631.                 array_push($currentAnnonces$annonce);
  632.                 $annonces[$idChapitre] = [
  633.                     'chapitre' => $chapitre,
  634.                     'annonces' => $currentAnnonces
  635.                 ];
  636.             }
  637.         }
  638.         
  639.         $pdf $pdfService->getPdfParchapitre($parution$annonces);
  640.         return new Response($pdf200, [
  641.             'Content-Type'        => 'application/pdf',
  642.             'Content-Disposition' => 'filename="parchapitre.pdf"',
  643.         ]);
  644.     }
  645.     #[Route('/previsualisation-montage/{dep}/{num}'methods: ['GET','POST'])]
  646.     public function montagePreview(ParutionRepository $parutionRepo$dep$numMontageService $ms): Response
  647.     {
  648.         $parution $this->parRepo->findOneByDepNum($dep$num);
  649.         if(!$parution) {
  650.             throw new \Exception("NOT found parution ".$dep." ".$num);
  651.         }
  652.         $html $ms->getMontageParutionHtml($parution);
  653.         return new Response($html);
  654.     }
  655.     
  656.     #[Route('/previsualisation-montage-web/{dep}/{date1}/{date2}'methods: ['GET','POST'])]
  657.     public function montagePreviewWeb(Request $request$dep$date1$date2MontageService $msPdfService $pdfServiceGreffeDematRepository $gdRepo): Response
  658.     {
  659.         $greffes $gdRepo->findAllActive();
  660.         $min 4//param per non creare nuovo oneCol se annunci nel capito < min
  661.         if($request->get('min')) {
  662.             $min $request->get('min');
  663.         }
  664.         
  665.         $xtag false;
  666.         if($request->get('xtag')) {
  667.             $xtag $request->get('xtag') == "1";
  668.         }
  669.         
  670.         $html $ms->getMontageParutionWebHtml($dep$date1$date2$greffes$min$xtag);
  671.         if($xtag) {
  672.             return $this->xtagResponse($html);
  673.         }
  674.         /*$filename = 'test.pdf';
  675.         $pdf = $pdfService->getPdfByHtml($filename, $html);
  676.         return new Response($pdf, 200, array(
  677.             'Content-Disposition' => 'filename="'.$filename.'"',
  678.             'Content-Type' => 'application/pdf'
  679.         ));*/
  680.         
  681.         return new Response($html);
  682.     }
  683. }