src/Controller/DashboardController.php line 94

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\DTO\DashboardBuscarDto;
  4. use App\DTO\DashboardLocalizacionDto;
  5. use App\DTO\DashboardTemperaturaDto;
  6. use App\DTO\DashboardTemperaturaResultadoDto;
  7. use App\DTO\DTOTemperaturaGeneral;
  8. use App\DTO\DocumentoTributarioListarDto;
  9. use App\Form\DashboardBuscarFormType;
  10. use App\Form\DashboardLocalizacionFormType;
  11. use App\Form\DashboardTemperaturaFormType;
  12. use App\Repository\BitacoraTemperaturaRepository;
  13. use App\Repository\ClienteRepository;
  14. use App\Repository\GeneradorTemperaturaRangoRepository;
  15. use App\Repository\MatrizTransitoRepository;
  16. use App\Repository\OrdenRepository;
  17. use App\Repository\RegionRepository;
  18. use App\Repository\RutaRepository;
  19. use App\Repository\TipoCargaRepository;
  20. use App\Repository\TipoEstadoOrdenRepository;
  21. use App\Repository\VehiculoRepository;
  22. use App\Repository\ViaTransporteRepository;
  23. use Doctrine\ORM\EntityManagerInterface;
  24. use Doctrine\Common\Collections\ArrayCollection;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use Symfony\Component\HttpFoundation\JsonResponse;
  31. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  32. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  33. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  34. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  35. use Symfony\Component\Security\Core\Security;
  36. use App\Services\BaseOptimizadaHelper;
  37. use Psr\Log\LoggerInterface;
  38. class DashboardController extends AbstractController
  39. {
  40.     private $security;
  41.     private $entityManager;
  42.     private $session;
  43.     private $logger;
  44.     private $clienteRepository;
  45.     private $generadorTemperaturaRangoRepository;
  46.     private $matrizTransitoRepository;
  47.     private $ordenRepository;
  48.     private $regionRepository;
  49.     private $rutaRepository;
  50.     private $tipoCargaRepository;
  51.     private $tipoEstadoOrdenRepository;
  52.     private $vehiculoRepository;
  53.     private $viaTransporteRepository;
  54.     public function __construct(Security $securityEntityManagerInterface $entityManager
  55.         SessionInterface $session,
  56.         LoggerInterface $logger,
  57.         BitacoraTemperaturaRepository $bitacoraTemperaturaRepository
  58.         ClienteRepository $clienteRepository
  59.         GeneradorTemperaturaRangoRepository $generadorTemperaturaRangoRepository,
  60.         MatrizTransitoRepository $matrizTransitoRepository,
  61.         OrdenRepository $ordenRepository,
  62.         RegionRepository $regionRepository,
  63.         RutaRepository $rutaRepository,
  64.         TipoCargaRepository $tipoCargaRepository,
  65.         TipoEstadoOrdenRepository $tipoEstadoOrdenRepository,
  66.         VehiculoRepository $vehiculoRepository,
  67.         ViaTransporteRepository $viaTransporteRepository
  68.         )
  69.     {
  70.         date_default_timezone_set("America/Santiago");
  71.         $this->security $security;
  72.         $this->entityManager $entityManager;
  73.         $this->session $session;
  74.         $this->logger $logger;
  75.         $this->bitacoraTemperaturaRepository $bitacoraTemperaturaRepository;
  76.         $this->clienteRepository $clienteRepository;
  77.         $this->generadorTemperaturaRangoRepository $generadorTemperaturaRangoRepository;
  78.         $this->matrizTransitoRepository $matrizTransitoRepository;
  79.         $this->ordenRepository $ordenRepository;
  80.         $this->regionRepository $regionRepository;
  81.         $this->rutaRepository $rutaRepository;
  82.         $this->tipoCargaRepository $tipoCargaRepository;
  83.         $this->tipoEstadoOrdenRepository $tipoEstadoOrdenRepository;
  84.         $this->vehiculoRepository $vehiculoRepository;
  85.         $this->viaTransporteRepository $viaTransporteRepository;
  86.         if(!$this->session->isStarted()) //Starting the session if not done yet
  87.         {
  88.             $this->session->start();
  89.         }
  90.     }
  91.     /**
  92.      * @Route("/", name="app_admin_index")
  93.      * @IsGranted("ROLE_USER")
  94.      */
  95.     public function index(Request $request): Response
  96.     
  97.         try{
  98.             //return $this->render("admin/mantencion.html.twig");
  99.             return $this->render('admin/main.html.twig');
  100.         }
  101.         catch(\Exception $e){
  102.             $this->logger->error($e->getMessage(), [
  103.                 'exception' => $e,
  104.                 'trace'  => $e->getTraceAsString(), 
  105.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  106.                 'method' => $request->getMethod(), // GET, POST, etc.
  107.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  108.                 'params' => $request->request->all()
  109.             ]);
  110.             $this->addFlash('danger',$e->getMessage());
  111.             return $this->redirectToRoute('app_admin_index');
  112.         }        
  113.     }
  114.     /**
  115.      * @Route("/dashboard/", name="dashboard")
  116.      * @IsGranted("ROLE_USER")
  117.      */
  118.     public function dashboard(Request $request): Response
  119.     {
  120.         try
  121.         {
  122.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'null);
  123.             return $this->render('dashboard/index.html.twig');
  124.         }
  125.         catch(\Exception $e){
  126.             $this->logger->error($e->getMessage(), [
  127.                 'exception' => $e,
  128.                 'trace'  => $e->getTraceAsString(), 
  129.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  130.                 'method' => $request->getMethod(), // GET, POST, etc.
  131.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  132.                 'params' => $request->request->all()
  133.             ]);
  134.             $this->addFlash('danger',$e->getMessage());
  135.             return $this->redirectToRoute('app_admin_index');
  136.         }
  137.     }
  138.     /**
  139.      * @Route("/dashboard/inicial/", name="dashboard_inicial")
  140.      * @IsGranted("ROLE_USER")
  141.      */
  142.     public function dashboard_inicial(Request $request): Response
  143.     {
  144.         try
  145.         {
  146.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  147.             if(!$dto)
  148.             {
  149.                 $dto = new DashboardBuscarDto();
  150.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  151.                 $dto->fechaHasta = (new \DateTime('today'));
  152.             }
  153.             else
  154.             {
  155.                 if($dto->supermandante)
  156.                 {
  157.                     $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  158.                 }
  159.                 if($dto->cliente)
  160.                 {
  161.                     if(!is_array($dto->cliente))
  162.                     {
  163.                         $dto->cliente $this->entityManager->merge($dto->cliente); 
  164.                     }
  165.                     else
  166.                     {
  167.                         $posicion 0;
  168.                         foreach($dto->cliente as $item_cliente){
  169.                             $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  170.                             $posicion++;
  171.                         }
  172.                     }
  173.                 }
  174.                 else
  175.                 {
  176.                     $dto->cliente = array();
  177.                 }
  178.                 if($dto->clienteFinal)
  179.                 {
  180.                     if(!is_array($dto->clienteFinal))
  181.                     {
  182.                         $dto->clienteFinal $this->entityManager->merge($dto->clienteFinal); 
  183.                     }
  184.                     else
  185.                     {
  186.                         $posicion 0;
  187.                         foreach($dto->clienteFinal as $item_cliente){
  188.                             $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  189.                             $posicion++;
  190.                         }
  191.                     }
  192.                 }
  193.                 else
  194.                 {
  195.                     $dto->clienteFinal = array();
  196.                 }
  197.                 if($dto->tipoCarga)
  198.                 {
  199.                     $dto->tipoCarga $this->entityManager->merge($dto->tipoCarga); 
  200.                 }
  201.                 if($dto->region)
  202.                 {
  203.                     $dto->region $this->entityManager->merge($dto->region); 
  204.                 }
  205.                 if($dto->viaTransporte)
  206.                 {
  207.                     $dto->viaTransporte $this->entityManager->merge($dto->viaTransporte); 
  208.                 }
  209.                 
  210.             }
  211.             $form $this->createForm(DashboardBuscarFormType::class, $dto);
  212.             $form->handleRequest($request);
  213.             if ($form->isSubmitted() && $form->isValid()) {
  214.                 $dto->tipoCarga null;
  215.                 $dto->tipoEstadoOrden null;
  216.                 $dto->region null;
  217.                 $dto->viaTransporte null;
  218.             }
  219.             if($this->security->isGranted('ROLE_CLIENTE'))
  220.             {
  221.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  222.                 {
  223.                     $dto->cliente = array();
  224.                     $user $this->security->getUser();
  225.                     if (!$user) {
  226.                         throw new \LogicException('No se identifica el usuario actual');
  227.                     }
  228.                     foreach($user->getClientes() as $item_cliente)
  229.                     {
  230.                         $dto->cliente[] = $item_cliente;
  231.                     }
  232.                 }
  233.             }
  234.             if($this->security->isGranted('ROLE_TEVA'))
  235.             {
  236.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  237.                 {
  238.                     $dto->cliente = array();
  239.                     $clientes $this->clienteRepository->findBy(array('activo' => 1'integracionTeva' => 1), array());
  240.                     foreach($clientes as $item_cliente)
  241.                     {
  242.                         $dto->cliente[] = $item_cliente;
  243.                     }
  244.                 }
  245.             }
  246.             $cliente_final = array();
  247.             if($dto->clienteFinal)
  248.             {
  249.                 foreach($dto->clienteFinal as $item_cliente_final)
  250.                 {
  251.                     $cliente_final[] = $item_cliente_final;
  252.                 }
  253.             }
  254.             if($this->security->isGranted('ROLE_CLIENTE_FINAL'))
  255.             {
  256.                 if(!$dto->clienteFinal || sizeof($dto->clienteFinal) == 0)
  257.                 {
  258.                     $user $this->security->getUser();
  259.                     if (!$user) {
  260.                         throw new \LogicException('No se identifica el usuario actual');
  261.                     }
  262.                     $cliente_final $user->getClientesFinales();
  263.                 }
  264.             }
  265.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'$dto);
  266.             $lista $this->ordenRepository->findPorDashboardBuscarDto($dto$cliente_finalTRUE);
  267.             $resumen $this->dashboard_get_datos_resumen($dto$cliente_final);            
  268.             $regiones $this->ordenRepository->getDashboadRegiones($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  269.             $fechas $this->ordenRepository->getDashboadFechas($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  270.             
  271.             $dto_gd = new DocumentoTributarioListarDto();
  272.             $dto_gd->fechaSolicitudInicial $dto->fechaDesde;
  273.             $dto_gd->fechaSolicitudFinal $dto->fechaHasta;
  274.             $dto_gd->folio null;
  275.             $dto_gd->supermandante $dto->supermandante;
  276.             $dto_gd->cliente $dto->cliente;
  277.             $dto_gd->clienteFinal $cliente_final;
  278.             $dto_gd->estadoDocumentoTributario null;
  279.             $dto_gd->agencia null;
  280.             $dto_gd->tipoDocumentoGestionDocumental null;
  281.             $dto_gd->region $dto->region;
  282.             
  283.             $baseOptimizadaHelper = new BaseOptimizadaHelper();
  284.             $total_gd $baseOptimizadaHelper->getSpGestionDocumentalListTodosCount($dto_gd$cliente_final);
  285.                
  286.             return $this->render('dashboard/inicial.html.twig', array(
  287.                 'form' => $form->createView(),
  288.                 'filtros' => $dto->getFiltros(),
  289.                 'resumen' => $resumen,
  290.                 'regiones' => $regiones,
  291.                 'fechas' => $fechas,
  292.                 'lista' => $lista,
  293.                 'total_gd' => $total_gd['total']
  294.             ));
  295.         }
  296.         catch(\Exception $e){
  297.             $this->logger->error($e->getMessage(), [
  298.                 'exception' => $e,
  299.                 'trace'  => $e->getTraceAsString(), 
  300.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  301.                 'method' => $request->getMethod(), // GET, POST, etc.
  302.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  303.                 'params' => $request->request->all()
  304.             ]);
  305.             $this->addFlash('danger',$e->getMessage());
  306.             return $this->redirectToRoute('app_admin_index');
  307.         }
  308.     }
  309.      /**
  310.      * @Route("/dashboard/seleccionar-tipo-estado-orden/",name="dashboard_seleccionar_tipo_estado_orden")
  311.      * @param Request $request
  312.      */
  313.     public function dashboard_seleccionar_tipo_estado_orden(Request $request)
  314.     {
  315.         try
  316.         {
  317.             $tipoEstadoOrdenId $request->query->get("tipo_estado_orden_id");
  318.             $tipoEstadoOrden $this->tipoEstadoOrdenRepository->findOneById($tipoEstadoOrdenId);
  319.             if(!$tipoEstadoOrden)
  320.             {
  321.                 $this->addFlash('danger','No se encuentra información de tipo de estado');
  322.                 return $this->redirectToRoute('dashboard_inicial');
  323.             }
  324.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  325.             if(!$dto)
  326.             {
  327.                 $dto = new DashboardBuscarDto();
  328.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  329.                 $dto->fechaHasta = (new \DateTime('today'));
  330.             }
  331.             else
  332.             {
  333.                 if($dto->supermandante)
  334.                 {
  335.                     $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  336.                 }
  337.                 if($dto->cliente)
  338.                 {
  339.                     $posicion 0;
  340.                     foreach($dto->cliente as $item_cliente){
  341.                         $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  342.                         $posicion++;
  343.                     }
  344.                 }
  345.                 if($dto->clienteFinal)
  346.                 {
  347.                     $posicion 0;
  348.                     foreach($dto->clienteFinal as $item_cliente){
  349.                         $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  350.                         $posicion++;
  351.                     }
  352.                 }
  353.             }
  354.             
  355.             $dto->tipoEstadoOrden $tipoEstadoOrdenId;
  356.             $dto->tipoEstadoOrdenNombre $tipoEstadoOrden->getNombre();
  357.             if($this->security->isGranted('ROLE_CLIENTE'))
  358.             {
  359.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  360.                 {
  361.                     $dto->cliente = array();
  362.                     $user $this->security->getUser();
  363.                     if (!$user) {
  364.                         throw new \LogicException('No se identifica el usuario actual');
  365.                     }
  366.                     foreach($user->getClientes() as $item_cliente)
  367.                     {
  368.                         $dto->cliente[] = $item_cliente;
  369.                     }
  370.                 }
  371.             }
  372.             if($this->security->isGranted('ROLE_TEVA'))
  373.             {
  374.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  375.                 {
  376.                     $dto->cliente = array();
  377.                     $clientes $this->clienteRepository->findBy(array('activo' => 1'integracionTeva' => 1), array());
  378.                     foreach($clientes as $item_cliente)
  379.                     {
  380.                         $dto->cliente[] = $item_cliente;
  381.                     }
  382.                 }
  383.             }
  384.             $cliente_final = array();
  385.             if($dto->clienteFinal)
  386.             {
  387.                 foreach($dto->clienteFinal as $item_cliente_final)
  388.                 {
  389.                     $cliente_final[] = $item_cliente_final;
  390.                 }
  391.             }
  392.             if($this->security->isGranted('ROLE_CLIENTE_FINAL'))
  393.             {
  394.                 if(!$dto->clienteFinal || sizeof($dto->clienteFinal) == 0)
  395.                 {
  396.                     $user $this->security->getUser();
  397.                     if (!$user) {
  398.                         throw new \LogicException('No se identifica el usuario actual');
  399.                     }
  400.                     $cliente_final $user->getClientesFinales();
  401.                 }
  402.             }
  403.             //$this->session->set('SESION_DASHBOARD_BUSCAR_DTO', $dto);
  404.             //return $this->redirectToRoute('dashboard_inicial');
  405.             $lista $this->ordenRepository->findPorDashboardBuscarDto($dto$cliente_finalTRUE);
  406.         
  407.             return $this->render('dashboard/tipo_estado_orden.html.twig', array(
  408.                 'lista' => $lista,
  409.             ));
  410.         }
  411.         catch(\Exception $e){
  412.             $this->logger->error($e->getMessage(), [
  413.                 'exception' => $e,
  414.                 'trace'  => $e->getTraceAsString(), 
  415.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  416.                 'method' => $request->getMethod(), // GET, POST, etc.
  417.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  418.                 'params' => $request->request->all()
  419.             ]);
  420.             $this->addFlash('danger',$e->getMessage());
  421.             return $this->redirectToRoute('dashboard_inicial');
  422.         }
  423.     }
  424.     
  425.     /**
  426.      * @Route("/dashboard/seleccionar-tipo-estado-orden/excel/", name="dashboard_seleccionar_tipo_estado_orden_excel")
  427.      * @IsGranted("ROLE_USER")
  428.      */
  429.     public function dashboard_seleccionar_tipo_estado_orden_excel(Request $request): Response
  430.     {
  431.         try{      
  432.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  433.             if(!$dto)
  434.             {
  435.                 $dto = new DashboardBuscarDto();
  436.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  437.                 $dto->fechaHasta = (new \DateTime('today'));
  438.             }
  439.             else
  440.             {
  441.                 if($dto->supermandante)
  442.                 {
  443.                     $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  444.                 }
  445.                 if($dto->cliente)
  446.                 {
  447.                     $posicion 0;
  448.                     foreach($dto->cliente as $item_cliente){
  449.                         $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  450.                         $posicion++;
  451.                     }
  452.                 }
  453.                 if($dto->clienteFinal)
  454.                 {
  455.                     $posicion 0;
  456.                     foreach($dto->clienteFinal as $item_cliente){
  457.                         $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  458.                         $posicion++;
  459.                     }
  460.                 }
  461.             }
  462.             if($this->security->isGranted('ROLE_CLIENTE'))
  463.             {
  464.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  465.                 {
  466.                     $dto->cliente = array();
  467.                     $user $this->security->getUser();
  468.                     if (!$user) {
  469.                         throw new \LogicException('No se identifica el usuario actual');
  470.                     }
  471.                     foreach($user->getClientes() as $item_cliente)
  472.                     {
  473.                         $dto->cliente[] = $item_cliente;
  474.                     }
  475.                 }
  476.             }
  477.             if($this->security->isGranted('ROLE_TEVA'))
  478.             {
  479.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  480.                 {
  481.                     $dto->cliente = array();
  482.                     $clientes $this->clienteRepository->findBy(array('activo' => 1'integracionTeva' => 1), array());
  483.                     foreach($clientes as $item_cliente)
  484.                     {
  485.                         $dto->cliente[] = $item_cliente;
  486.                     }
  487.                 }
  488.             }
  489.             $cliente_final = array();
  490.             if($dto->clienteFinal)
  491.             {
  492.                 foreach($dto->clienteFinal as $item_cliente_final)
  493.                 {
  494.                     $cliente_final[] = $item_cliente_final;
  495.                 }
  496.             }
  497.             if($this->security->isGranted('ROLE_CLIENTE_FINAL'))
  498.             {
  499.                 if(!$dto->clienteFinal || sizeof($dto->clienteFinal) == 0)
  500.                 {
  501.                     $user $this->security->getUser();
  502.                     if (!$user) {
  503.                         throw new \LogicException('No se identifica el usuario actual');
  504.                     }
  505.                     $cliente_final $user->getClientesFinales();
  506.                 }
  507.             }
  508.             $lista $this->ordenRepository->findPorDashboardBuscarDto($dto$cliente_finalTRUE);
  509.             if(!$lista)
  510.             {
  511.                 $this->addFlash("error"'No se encuentra ordenes coincidentes');
  512.             }
  513.             $ahora = new \DateTime('now');
  514.             $spreadsheet = new Spreadsheet();
  515.             /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  516.             $sheet $spreadsheet->getActiveSheet();
  517.             $sheet->setShowGridlines(false);
  518.             $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
  519.             $drawing->setName('logo');
  520.             $drawing->setDescription('logo');
  521.             $drawing->setPath('media/logo_transfarma_verde.png'); // put your path and image here
  522.             $drawing->setCoordinates('A1');
  523.             $drawing->setWorksheet($sheet);
  524.             $sheet->setCellValue('A6''DASHBOARD');
  525.             $sheet->getStyle('A6')->getFont()->setBoldtrue );
  526.             $sheet->setCellValue('A7'$ahora->format('d-m-Y H:i'));
  527.             $sheet->mergeCells("A6:Q6"); 
  528.             $sheet->mergeCells("A7:Q7"); 
  529.                                 
  530.             $sheet->setCellValue('A9''Nro');
  531.             $sheet->setCellValue('B9''Codigo de Barra');
  532.             $sheet->setCellValue('C9''Fecha de Solicitud');
  533.             $sheet->setCellValue('D9''Estado');
  534.             $sheet->setCellValue('E9''Origen');
  535.             $sheet->setCellValue('F9''Destino');
  536.             $sheet->setCellValue('G9''Comuna');
  537.             $sheet->setCellValue('H9''Región');
  538.             $sheet->setCellValue('I9''Documento');
  539.             $sheet->setCellValue('J9''Orden de Compra');
  540.             $sheet->setCellValue('K9''Tipo de Servicio');
  541.             $sheet->setCellValue('L9''Tipo de Carga');
  542.             $sheet->setCellValue('M9''Tipo de Transporte');
  543.             $sheet->setCellValue('N9''Via de Transporte');
  544.             $sheet->setCellValue('O9''Requiere Cedible');
  545.             $sheet->setCellValue('P9''Seguro');
  546.             $sheet->setCellValue('Q9''Cenabast');
  547.             $sheet->setCellValue('R9''Muestra Médica');
  548.             $sheet->setCellValue('S9''Peso Fisico');
  549.             $sheet->setCellValue('T9''Peso Vol.');
  550.             $sheet->setCellValue('U9''Peso Max. (Transfarma)');
  551.             $sheet->setCellValue('V9''Bultos');
  552.             if(!$this->security->isGranted('ROLE_CLIENTE'))
  553.             {
  554.                 $sheet->setCellValue('W9''Kilos (Operador)');
  555.             }
  556.        
  557.             $fila 9;
  558.             $i 0;
  559.             foreach($lista as $item)
  560.             {
  561.                 $i++;
  562.                 $fila++;
  563.                 $sheet->setCellValue('A'.$fila$i);
  564.                 $sheet->setCellValue('B'.$fila$item->getCodigoBarra());
  565.                 $sheet->setCellValue('C'.$fila$item->getFechaSolicitud()->format('d-m-Y'));
  566.                 $sheet->setCellValue('D'.$fila$item->getEstadoOrden());
  567.                 $sheet->setCellValue('E'.$fila$item->getDireccionOrigen());
  568.                 $sheet->setCellValue('F'.$fila$item->getDireccionDestino());
  569.                 if($item->getDireccionDestino()->getComuna())
  570.                 {
  571.                     $sheet->setCellValue('G'.$fila$item->getDireccionDestino()->getComuna());
  572.                     if($item->getDireccionDestino()->getComuna()->getRegion())
  573.                     {
  574.                         $sheet->setCellValue('H'.$fila$item->getDireccionDestino()->getComuna()->getRegion());
  575.                     }
  576.                 }
  577.                 $sheet->setCellValue('I'.$fila$item->getTipoDocumento().' '.$item->getFolioTipoDocumento());
  578.                 $sheet->setCellValue('J'.$fila$item->getFolioOrdenCompra());
  579.                 $sheet->setCellValue('K'.$fila$item->getTipoServicio());
  580.                 $sheet->setCellValue('L'.$fila$item->getTipoCarga());
  581.                 $sheet->setCellValue('M'.$fila$item->getTipoTransporte());
  582.                 $sheet->setCellValue('N'.$fila$item->getViaTransporte());
  583.                 $sheet->setCellValue('O'.$fila$item->getRequiereCedible() ? 'SI' 'NO');
  584.                 $sheet->setCellValue('P'.$fila$item->getSeguro() ? 'SI' 'NO');
  585.                 $sheet->setCellValue('Q'.$fila$item->isCenabast() ? 'SI' 'NO');
  586.                 $sheet->setCellValue('R'.$fila$item->isMuestraMedica() ? 'SI' 'NO');
  587.                 $sheet->setCellValue('S'.$fila$item->getSumaPeso());
  588.                 $sheet->setCellValue('T'.$fila$item->getSumaPesoVol());
  589.                 $sheet->setCellValue('U'.$fila$item->getSumaPesoMax());
  590.                 $sheet->setCellValue('V'.$fila$item->getSumaBultos());
  591.                 if(!$this->security->isGranted('ROLE_CLIENTE'))
  592.                 {
  593.                     $sheet->setCellValue('W'.$fila$item->getUrbanoPeso());
  594.                 }
  595.             }
  596.             //$sheet->setAutoFilter($sheet->calculateWorksheetDimension());
  597.             $sheet->getColumnDimension('A')->setAutoSize(true);
  598.             $sheet->getColumnDimension('B')->setAutoSize(true);
  599.             $sheet->getColumnDimension('C')->setAutoSize(true);
  600.             $sheet->getColumnDimension('D')->setAutoSize(true);
  601.             $sheet->getColumnDimension('E')->setAutoSize(true);
  602.             $sheet->getColumnDimension('F')->setAutoSize(true);
  603.             $sheet->getColumnDimension('G')->setAutoSize(true);
  604.             $sheet->getColumnDimension('H')->setAutoSize(true);
  605.             $sheet->getColumnDimension('I')->setAutoSize(true);
  606.             $sheet->getColumnDimension('J')->setAutoSize(true);
  607.             $sheet->getColumnDimension('K')->setAutoSize(true);
  608.             $sheet->getColumnDimension('L')->setAutoSize(true);
  609.             $sheet->getColumnDimension('M')->setAutoSize(true);
  610.             $sheet->getColumnDimension('N')->setAutoSize(true);
  611.             $sheet->getColumnDimension('O')->setAutoSize(true);
  612.             $sheet->getColumnDimension('P')->setAutoSize(true);
  613.             $sheet->getColumnDimension('Q')->setAutoSize(true);
  614.             $sheet->getColumnDimension('R')->setAutoSize(true);
  615.             $sheet->getColumnDimension('S')->setAutoSize(true);
  616.             $sheet->getColumnDimension('T')->setAutoSize(true);
  617.             $sheet->getColumnDimension('U')->setAutoSize(true);
  618.             $sheet->getColumnDimension('V')->setAutoSize(true);
  619.             $sheet->getColumnDimension('W')->setAutoSize(true);
  620.             $sheet->getStyle('A9:W9')->getFont()->setBoldtrue );
  621.             $sheet->getStyle('A9:W9')->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  622.             $sheet->getStyle('A9:W9')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('FF426384');
  623.             // Create your Office 2007 Excel (XLSX Format)
  624.             $writer = new Xlsx($spreadsheet);
  625.             
  626.             // Create a Temporary file in the system
  627.             $fileName 'TRF-DASHBOARD-'.($ahora->format('Ymd-Hi')).'.xlsx';
  628.             $temp_file tempnam($this->getParameter('kernel.project_dir').'/temp/'$fileName);
  629.             
  630.             // Create the excel file in the tmp directory of the system
  631.             $writer->save($temp_file);
  632.             
  633.             // Return the excel file as an attachment
  634.             return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  635.             
  636.         } catch(\Exception $e){
  637.             $this->logger->error($e->getMessage(), [
  638.                 'exception' => $e,
  639.                 'trace'  => $e->getTraceAsString(), 
  640.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  641.                 'method' => $request->getMethod(), // GET, POST, etc.
  642.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  643.                 'params' => $request->request->all()
  644.             ]);
  645.             $this->addFlash('danger',$e->getMessage());
  646.             return $this->redirectToRoute('app_admin_index');
  647.         }
  648.     }
  649.     private function dashboard_get_datos_resumen(DashboardBuscarDto $dto$cliente_final)
  650.     {
  651.         $resumen $this->ordenRepository->getDashboadResumen($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  652.         $envios_total 0;
  653.         $envios_entregados 0;
  654.         $envios_parciales 0;
  655.         $envios_error 0;
  656.         $envios_no_entregados 0;
  657.         $envios_devueltos 0;
  658.         $metricas_kilos_total 0;
  659.         $metricas_bultos_total 0;
  660.         $metricas_kilos_promedio 0;
  661.         $metricas_bultos_promedio 0;
  662.         $metricas_envios_promedio 0;
  663.         $sla_no_entregados 0;
  664.         $sla_entregados 0;
  665.         $sla_parciales 0;
  666.         $via_transporte_terrestre 0;
  667.         $via_transporte_aereo 0;
  668.         $kilos_transporte_terrestre 0;
  669.         $kilos_transporte_aereo 0;
  670.         $tipo_carga_ambiente 0;
  671.         $tipo_carga_refrigerado 0;
  672.         $tipo_carga_congelado 0;
  673.         $tipo_carga_temperatura_controlada 0;
  674.         $tiempo_entrega_promedio 0;
  675.         $tiempo_entrega_tipo_carga_ambiente 0;
  676.         $tiempo_entrega_tipo_carga_refrigerado 0;
  677.         $tiempo_entrega_tipo_carga_congelado 0;
  678.         $tiempo_entrega_tipo_carga_temperatura_controlada 0;
  679.         $total_documentos_tributarios 0;
  680.         if($resumen)
  681.         {
  682.             $envios_total $resumen["envios_total"];
  683.             $envios_entregados $resumen["envios_entregados"];
  684.             $envios_parciales $resumen["envios_parciales"];
  685.             $envios_error $resumen["envios_error"];
  686.             $envios_no_entregados $resumen["envios_no_entregados"];
  687.             $envios_devueltos $resumen["envios_devueltos"];
  688.             $metricas_kilos_total $resumen["metricas_kilos_total"];
  689.             $metricas_bultos_total $resumen["metricas_bultos_total"];
  690.             $metricas_kilos_promedio $resumen["metricas_kilos_promedio"];
  691.             $metricas_bultos_promedio $resumen["metricas_bultos_promedio"];
  692.             $metricas_envios_promedio $resumen["metricas_envios_promedio"];
  693.             $sla_no_entregados $resumen["sla_no_entregados"];
  694.             $sla_entregados $resumen["sla_entregados"];
  695.             $sla_parciales $resumen["sla_parciales"];
  696.             $via_transporte_terrestre $resumen["via_transporte_terrestre"];
  697.             $via_transporte_aereo $resumen["via_transporte_aereo"];
  698.             $kilos_transporte_terrestre $resumen["kilos_transporte_terrestre"];
  699.             $kilos_transporte_aereo $resumen["kilos_transporte_aereo"];
  700.             $tipo_carga_ambiente $resumen["tipo_carga_ambiente"];
  701.             $tipo_carga_refrigerado $resumen["tipo_carga_refrigerado"];
  702.             $tipo_carga_congelado $resumen["tipo_carga_congelado"];
  703.             $tipo_carga_temperatura_controlada $resumen["tipo_carga_temperatura_controlada"];
  704.             $tiempo_entrega_promedio $resumen["tiempo_entrega_promedio"];
  705.             $tiempo_entrega_tipo_carga_ambiente $resumen["tiempo_entrega_tipo_carga_ambiente"];
  706.             $tiempo_entrega_tipo_carga_refrigerado $resumen["tiempo_entrega_tipo_carga_refrigerado"];
  707.             $tiempo_entrega_tipo_carga_congelado $resumen["tiempo_entrega_tipo_carga_congelado"];
  708.             $tiempo_entrega_tipo_carga_temperatura_controlada $resumen["tiempo_entrega_tipo_carga_temperatura_controlada"];
  709.             $total_documentos_tributarios $resumen["total_documentos_tributarios"];
  710.         }
  711.         $tiempo_entrega_promedio_d 0;
  712.         $tiempo_entrega_promedio_h 0;
  713.         $tiempo_entrega_promedio_m 0;
  714.         $tiempo_entrega_tipo_carga_ambiente_d 0;
  715.         $tiempo_entrega_tipo_carga_ambiente_h 0;
  716.         $tiempo_entrega_tipo_carga_ambiente_m 0;
  717.         $tiempo_entrega_tipo_carga_refrigerado_d 0;
  718.         $tiempo_entrega_tipo_carga_refrigerado_h 0;
  719.         $tiempo_entrega_tipo_carga_refrigerado_m 0;
  720.         $tiempo_entrega_tipo_carga_congelado_d 0;
  721.         $tiempo_entrega_tipo_carga_congelado_h 0;
  722.         $tiempo_entrega_tipo_carga_congelado_m 0;
  723.         $tiempo_entrega_tipo_carga_temperatura_controlada_d 0;
  724.         $tiempo_entrega_tipo_carga_temperatura_controlada_h 0;
  725.         $tiempo_entrega_tipo_carga_temperatura_controlada_m 0;
  726.         if($tiempo_entrega_promedio)
  727.         {
  728.             $tiempo_entrega_promedio_d floor($tiempo_entrega_promedio 1440);
  729.             $tiempo_entrega_promedio_h floor(($tiempo_entrega_promedio - ($tiempo_entrega_promedio_d 1440)) / 60);
  730.             $tiempo_entrega_promedio_m = ($tiempo_entrega_promedio 60);
  731.         }
  732.         if($tiempo_entrega_tipo_carga_ambiente)
  733.         {
  734.             $tiempo_entrega_tipo_carga_ambiente_d floor($tiempo_entrega_tipo_carga_ambiente 1440);
  735.             $tiempo_entrega_tipo_carga_ambiente_h floor(($tiempo_entrega_tipo_carga_ambiente - ($tiempo_entrega_tipo_carga_ambiente_d 1440)) / 60);
  736.             $tiempo_entrega_tipo_carga_ambiente_m = ($tiempo_entrega_tipo_carga_ambiente 60);
  737.         }
  738.         if($tiempo_entrega_tipo_carga_refrigerado)
  739.         {
  740.             $tiempo_entrega_tipo_carga_refrigerado_d floor($tiempo_entrega_tipo_carga_refrigerado 1440);
  741.             $tiempo_entrega_tipo_carga_refrigerado_h floor(($tiempo_entrega_tipo_carga_refrigerado - ($tiempo_entrega_tipo_carga_refrigerado_d 1440)) / 60);
  742.             $tiempo_entrega_tipo_carga_refrigerado_m = ($tiempo_entrega_tipo_carga_refrigerado 60);
  743.         }
  744.         if($tiempo_entrega_tipo_carga_congelado)
  745.         {
  746.             $tiempo_entrega_tipo_carga_congelado_d floor($tiempo_entrega_tipo_carga_congelado 1440);
  747.             $tiempo_entrega_tipo_carga_congelado_h floor(($tiempo_entrega_tipo_carga_congelado - ($tiempo_entrega_tipo_carga_congelado_d 1440)) / 60);
  748.             $tiempo_entrega_tipo_carga_congelado_m = ($tiempo_entrega_tipo_carga_congelado 60);
  749.         }
  750.         if($tiempo_entrega_tipo_carga_temperatura_controlada)
  751.         {
  752.             $tiempo_entrega_tipo_carga_temperatura_controlada_d floor($tiempo_entrega_tipo_carga_temperatura_controlada 1440);
  753.             $tiempo_entrega_tipo_carga_temperatura_controlada_h floor(($tiempo_entrega_tipo_carga_temperatura_controlada - ($tiempo_entrega_tipo_carga_temperatura_controlada_d 1440)) / 60);
  754.             $tiempo_entrega_tipo_carga_temperatura_controlada_m = ($tiempo_entrega_tipo_carga_temperatura_controlada 60);
  755.         }
  756.         return array(
  757.             'envios_total' => $envios_total,
  758.             'envios_entregados' => $envios_entregados,
  759.             'envios_parciales' => $envios_parciales,
  760.             'envios_error' => $envios_error,
  761.             'envios_no_entregados' => $envios_no_entregados,
  762.             'envios_devueltos' => $envios_devueltos,
  763.             'metricas_kilos_total' => $metricas_kilos_total,
  764.             'metricas_bultos_total' => $metricas_bultos_total,
  765.             'metricas_kilos_promedio' => $metricas_kilos_promedio,
  766.             'metricas_bultos_promedio' => $metricas_bultos_promedio,
  767.             'metricas_envios_promedio' => $metricas_envios_promedio,
  768.             'sla_no_entregados' => $sla_no_entregados,
  769.             'sla_entregados' => $sla_entregados,
  770.             'sla_parciales' => $sla_parciales,
  771.             'via_transporte_terrestre' => $via_transporte_terrestre,
  772.             'via_transporte_aereo' => $via_transporte_aereo,
  773.             'kilos_transporte_terrestre' => $kilos_transporte_terrestre,
  774.             'kilos_transporte_aereo' => $kilos_transporte_aereo,
  775.             'tipo_carga_ambiente' => $tipo_carga_ambiente,
  776.             'tipo_carga_refrigerado' => $tipo_carga_refrigerado,
  777.             'tipo_carga_congelado' => $tipo_carga_congelado,
  778.             'tipo_carga_temperatura_controlada' => $tipo_carga_temperatura_controlada,
  779.             'tiempo_entrega_promedio_d' => $tiempo_entrega_promedio_d,
  780.             'tiempo_entrega_promedio_h' => $tiempo_entrega_promedio_h,
  781.             'tiempo_entrega_promedio_m' => $tiempo_entrega_promedio_m,
  782.             'tiempo_entrega_tipo_carga_ambiente_d' => $tiempo_entrega_tipo_carga_ambiente_d,
  783.             'tiempo_entrega_tipo_carga_ambiente_h' => $tiempo_entrega_tipo_carga_ambiente_h,
  784.             'tiempo_entrega_tipo_carga_ambiente_m' => $tiempo_entrega_tipo_carga_ambiente_m,
  785.             'tiempo_entrega_tipo_carga_refrigerado_d' => $tiempo_entrega_tipo_carga_refrigerado_d,
  786.             'tiempo_entrega_tipo_carga_refrigerado_h' => $tiempo_entrega_tipo_carga_refrigerado_h,
  787.             'tiempo_entrega_tipo_carga_refrigerado_m' => $tiempo_entrega_tipo_carga_refrigerado_m,
  788.             'tiempo_entrega_tipo_carga_congelado_d' => $tiempo_entrega_tipo_carga_congelado_d,
  789.             'tiempo_entrega_tipo_carga_congelado_h' => $tiempo_entrega_tipo_carga_congelado_h,
  790.             'tiempo_entrega_tipo_carga_congelado_m' => $tiempo_entrega_tipo_carga_congelado_m,
  791.             'tiempo_entrega_tipo_carga_temperatura_controlada_d' => $tiempo_entrega_tipo_carga_temperatura_controlada_d,
  792.             'tiempo_entrega_tipo_carga_temperatura_controlada_h' => $tiempo_entrega_tipo_carga_temperatura_controlada_h,
  793.             'tiempo_entrega_tipo_carga_temperatura_controlada_m' => $tiempo_entrega_tipo_carga_temperatura_controlada_m,
  794.             'total_documentos_tributarios' => $total_documentos_tributarios,
  795.         );
  796.     }
  797.     /**
  798.      * @Route("/dashboard/graficos/", name="dashboard_graficos")
  799.      * @IsGranted("ROLE_USER")
  800.      */
  801.     public function dashboard_graficos(Request $request): Response
  802.     {
  803.         try
  804.         {
  805.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  806.             if(!$dto)
  807.             {
  808.                 $dto = new DashboardBuscarDto();
  809.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  810.                 $dto->fechaHasta = (new \DateTime('today'));
  811.             }
  812.             else
  813.             {
  814.                 if($dto->supermandante)
  815.                 {
  816.                     $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  817.                 }
  818.                 if($dto->cliente)
  819.                 {
  820.                     $posicion 0;
  821.                     foreach($dto->cliente as $item_cliente){
  822.                         $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  823.                         $posicion++;
  824.                     }
  825.                 }
  826.                 if($dto->clienteFinal)
  827.                 {
  828.                     $posicion 0;
  829.                     foreach($dto->clienteFinal as $item_cliente){
  830.                         $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  831.                         $posicion++;
  832.                     }
  833.                 }
  834.             }
  835.             $form $this->createForm(DashboardBuscarFormType::class, $dto);
  836.             $form->handleRequest($request);
  837.             if ($form->isSubmitted() && $form->isValid()) {
  838.                 $dto->tipoCarga null;
  839.                 $dto->tipoEstadoOrden null;
  840.                 $dto->region null;
  841.                 $dto->viaTransporte null;
  842.             }
  843.             if($this->security->isGranted('ROLE_CLIENTE'))
  844.             {
  845.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  846.                 {
  847.                     $dto->cliente = array();
  848.                     $user $this->security->getUser();
  849.                     if (!$user) {
  850.                         throw new \LogicException('No se identifica el usuario actual');
  851.                     }
  852.                     foreach($user->getClientes() as $item_cliente)
  853.                     {
  854.                         $dto->cliente[] = $item_cliente;
  855.                     }
  856.                 }
  857.             }
  858.             if($this->security->isGranted('ROLE_TEVA'))
  859.             {
  860.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  861.                 {
  862.                     $dto->cliente = array();
  863.                     $clientes $this->clienteRepository->findBy(array('activo' => 1'integracionTeva' => 1), array());
  864.                     foreach($clientes as $item_cliente)
  865.                     {
  866.                         $dto->cliente[] = $item_cliente;
  867.                     }
  868.                 }
  869.             }
  870.             $cliente_final = array();
  871.             if($dto->clienteFinal)
  872.             {
  873.                 foreach($dto->clienteFinal as $item_cliente_final)
  874.                 {
  875.                     $cliente_final[] = $item_cliente_final;
  876.                 }
  877.             }
  878.             if($this->security->isGranted('ROLE_CLIENTE_FINAL'))
  879.             {
  880.                 if(!$dto->clienteFinal || sizeof($dto->clienteFinal) == 0)
  881.                 {
  882.                     $user $this->security->getUser();
  883.                     if (!$user) {
  884.                         throw new \LogicException('No se identifica el usuario actual');
  885.                     }
  886.                     $cliente_final $user->getClientesFinales();
  887.                 }
  888.             }
  889.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'$dto);
  890.             $resumen $this->dashboard_get_datos_resumen($dto$cliente_final);            
  891.             $estados_orden $this->ordenRepository->getDashboadEstadoOrden($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  892.             $fechas_temperaturas $this->ordenRepository->getDashboadFechasTemperaturas($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  893.             $tiempo_promedio_region $this->ordenRepository->getDashboadTiempoPromedioRegion($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  894.             $tiempo_promedio_ciudad $this->ordenRepository->getDashboadTiempoPromedioCiudad($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  895.             $resumen_dia $this->ordenRepository->getDashboadResumenDia($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  896.             $kilos_region $this->ordenRepository->getDashboadKilosRegion($dto->supermandante$dto->cliente$cliente_final$dto->fechaDesde$dto->fechaHasta$dto->tipoCarga$dto->tipoEstadoOrden$dto->region$dto->viaTransporte);
  897.             return $this->render('dashboard/graficos.html.twig', array(
  898.                 'form' => $form->createView(),
  899.                 'filtros' => $dto->getFiltros(),
  900.                 'resumen' => $resumen,
  901.                 'estados_orden' => $estados_orden,
  902.                 'fechas_temperaturas' => $fechas_temperaturas,
  903.                 'tiempo_promedio_region' => $tiempo_promedio_region,
  904.                 'tiempo_promedio_ciudad' => $tiempo_promedio_ciudad,
  905.                 'resumen_dia' => $resumen_dia,
  906.                 'kilos_region' => $kilos_region
  907.             ));
  908.         } catch(\Exception $e){
  909.             $this->logger->error($e->getMessage(), [
  910.                 'exception' => $e,
  911.                 'trace'  => $e->getTraceAsString(), 
  912.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  913.                 'method' => $request->getMethod(), // GET, POST, etc.
  914.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  915.                 'params' => $request->request->all()
  916.             ]);
  917.             $this->addFlash('danger',$e->getMessage());
  918.             return $this->redirectToRoute('app_admin_index');
  919.         }
  920.     }
  921.     /**
  922.      * @Route("/dashboard/datos/", name="dashboard_datos")
  923.      * @IsGranted("ROLE_USER")
  924.      */
  925.     public function dashboard_datos(Request $request)
  926.     {
  927.         try
  928.         {
  929.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'NULL);
  930.             return $this->dashboard_datos_page($request1);
  931.         }
  932.         catch(\Exception $e){
  933.             $this->logger->error($e->getMessage(), [
  934.                 'exception' => $e,
  935.                 'trace'  => $e->getTraceAsString(), 
  936.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  937.                 'method' => $request->getMethod(), // GET, POST, etc.
  938.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  939.                 'params' => $request->request->all()
  940.             ]);
  941.             $this->addFlash('danger',$e->getMessage());
  942.             return $this->redirectToRoute('app_admin_index');
  943.         }
  944.     }
  945.     /**
  946.      * @Route("/dashboard/datos/page/{currentPage}/", name="dashboard_datos_page")
  947.      * @IsGranted("ROLE_USER")
  948.      */
  949.     public function dashboard_datos_page(Request $request$currentPage 1): Response
  950.     {
  951.         try{
  952.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  953.             if(!$dto)
  954.             {
  955.                 $dto = new DashboardBuscarDto();
  956.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  957.                 $dto->fechaHasta = (new \DateTime('today'));
  958.             }
  959.             else
  960.             {
  961.                 if($dto->supermandante)
  962.                 {
  963.                     $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  964.                 }
  965.                 if($dto->cliente)
  966.                 {
  967.                     $posicion 0;
  968.                     foreach($dto->cliente as $item_cliente){
  969.                         $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  970.                         $posicion++;
  971.                     }
  972.                 }
  973.                 if($dto->clienteFinal)
  974.                 {
  975.                     $posicion 0;
  976.                     foreach($dto->clienteFinal as $item_cliente){
  977.                         $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  978.                         $posicion++;
  979.                     }
  980.                 }
  981.             }
  982.             $form $this->createForm(DashboardBuscarFormType::class, $dto);
  983.             $form->handleRequest($request);
  984.             if ($form->isSubmitted() && $form->isValid()) {
  985.                 $dto->tipoCarga null;
  986.                 $dto->tipoEstadoOrden null;
  987.                 $dto->region null;
  988.                 $dto->viaTransporte null;
  989.             }
  990.             if($this->security->isGranted('ROLE_CLIENTE'))
  991.             {
  992.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  993.                 {
  994.                     $dto->cliente = array();
  995.                     $user $this->security->getUser();
  996.                     if (!$user) {
  997.                         throw new \LogicException('No se identifica el usuario actual');
  998.                     }
  999.                     foreach($user->getClientes() as $item_cliente)
  1000.                     {
  1001.                         $dto->cliente[] = $item_cliente;
  1002.                     }
  1003.                 }
  1004.             }
  1005.             if($this->security->isGranted('ROLE_TEVA'))
  1006.             {
  1007.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  1008.                 {
  1009.                     $dto->cliente = array();
  1010.                     $clientes $this->clienteRepository->findBy(array('activo' => 1'integracionTeva' => 1), array());
  1011.                     foreach($clientes as $item_cliente)
  1012.                     {
  1013.                         $dto->cliente[] = $item_cliente;
  1014.                     }
  1015.                 }
  1016.             }
  1017.             $cliente_final = array();
  1018.             if($dto->clienteFinal)
  1019.             {
  1020.                 foreach($dto->clienteFinal as $item_cliente_final)
  1021.                 {
  1022.                     $cliente_final[] = $item_cliente_final;
  1023.                 }
  1024.             }
  1025.             if($this->security->isGranted('ROLE_CLIENTE_FINAL'))
  1026.             {
  1027.                 if(!$dto->clienteFinal || sizeof($dto->clienteFinal) == 0)
  1028.                 {
  1029.                     $user $this->security->getUser();
  1030.                     if (!$user) {
  1031.                         throw new \LogicException('No se identifica el usuario actual');
  1032.                     }
  1033.                     $cliente_final $user->getClientesFinales();
  1034.                 }
  1035.             }
  1036.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'$dto);
  1037.             //$lista = $this->ordenRepository->getOrdenesPorDashboardBuscarDto($dto, $cliente_final);
  1038.             $limit 100;
  1039.             $total $this->ordenRepository->countOrdenesPorDashboardBuscarDto($dto$cliente_final);
  1040.             $lista $this->ordenRepository->getOrdenesPorDashboardBuscarDto($dto$cliente_final$currentPage$limit);
  1041.             $maxPages ceil($total['total'] / $limit);
  1042.             if(!$lista)
  1043.             {
  1044.                 $this->addFlash("error"'No se encuentra ordenes coincidentes');
  1045.             }
  1046.             return $this->render('dashboard/datos.html.twig', array(
  1047.                 'form' => $form->createView(),
  1048.                 'lista' => $lista,
  1049.                 'thisPage' => $currentPage,
  1050.                 'maxPages' => $maxPages,
  1051.                 'total' => $total['total'],
  1052.             ));
  1053.         }
  1054.         catch(\Exception $e){
  1055.             $this->logger->error($e->getMessage(), [
  1056.                 'exception' => $e,
  1057.                 'trace'  => $e->getTraceAsString(), 
  1058.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  1059.                 'method' => $request->getMethod(), // GET, POST, etc.
  1060.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  1061.                 'params' => $request->request->all()
  1062.             ]);
  1063.             $this->addFlash('danger',$e->getMessage());
  1064.             return $this->redirectToRoute('app_admin_index');
  1065.         }
  1066.     }
  1067.    
  1068.     /**
  1069.      * @Route("/dashboard/datos/excel/", name="dashboard_datos_excel")
  1070.      * @IsGranted("ROLE_USER")
  1071.      */
  1072.     public function dashboard_datos_excel(Request $request): Response
  1073.     {
  1074.         try{
  1075.             set_time_limit(0);
  1076.             
  1077.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  1078.             if(!$dto)
  1079.             {
  1080.                 $dto = new DashboardBuscarDto();
  1081.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  1082.                 $dto->fechaHasta = (new \DateTime('today'));
  1083.             }
  1084.             else
  1085.             {
  1086.                 if($dto->supermandante)
  1087.                 {
  1088.                     $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  1089.                 }
  1090.                 if($dto->cliente)
  1091.                 {
  1092.                     $posicion 0;
  1093.                     foreach($dto->cliente as $item_cliente){
  1094.                         $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  1095.                         $posicion++;
  1096.                     }
  1097.                 }
  1098.                 if($dto->clienteFinal)
  1099.                 {
  1100.                     $posicion 0;
  1101.                     foreach($dto->clienteFinal as $item_cliente){
  1102.                         $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  1103.                         $posicion++;
  1104.                     }
  1105.                 }
  1106.             }
  1107.             if($this->security->isGranted('ROLE_CLIENTE'))
  1108.             {
  1109.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  1110.                 {
  1111.                     $dto->cliente = array();
  1112.                     $user $this->security->getUser();
  1113.                     if (!$user) {
  1114.                         throw new \LogicException('No se identifica el usuario actual');
  1115.                     }
  1116.                     foreach($user->getClientes() as $item_cliente)
  1117.                     {
  1118.                         $dto->cliente[] = $item_cliente;
  1119.                     }
  1120.                 }
  1121.             }
  1122.             if($this->security->isGranted('ROLE_TEVA'))
  1123.             {
  1124.                 if(!$dto->cliente || sizeof($dto->cliente) == 0)
  1125.                 {
  1126.                     $dto->cliente = array();
  1127.                     $clientes $this->clienteRepository->findBy(array('activo' => 1'integracionTeva' => 1), array());
  1128.                     foreach($clientes as $item_cliente)
  1129.                     {
  1130.                         $dto->cliente[] = $item_cliente;
  1131.                     }
  1132.                 }
  1133.             }
  1134.             
  1135.             $cliente_final = array();
  1136.             if($dto->clienteFinal)
  1137.             {
  1138.                 foreach($dto->clienteFinal as $item_cliente_final)
  1139.                 {
  1140.                     $cliente_final[] = $item_cliente_final;
  1141.                 }
  1142.             }
  1143.             if($this->security->isGranted('ROLE_CLIENTE_FINAL'))
  1144.             {
  1145.                 if(!$dto->clienteFinal || sizeof($dto->clienteFinal) == 0)
  1146.                 {
  1147.                     $user $this->security->getUser();
  1148.                     if (!$user) {
  1149.                         throw new \LogicException('No se identifica el usuario actual');
  1150.                     }
  1151.                     $cliente_final $user->getClientesFinales();
  1152.                 }
  1153.             }
  1154.             
  1155.             $lista $this->ordenRepository->getOrdenesPorDashboardBuscarDtoAll($dto$cliente_final);
  1156.             if(!$lista)
  1157.             {
  1158.                 $this->addFlash("error"'No se encuentra ordenes coincidentes');
  1159.             }
  1160.             $ahora = new \DateTime('now');
  1161.             $esTransfarma   $this->security->isGranted('ROLE_TRANSFARMA');
  1162.             $esMandante     $this->security->isGranted('ROLE_CLIENTE');
  1163.             $esClienteFinal $this->security->isGranted('ROLE_CLIENTE_FINAL');
  1164.             $ocultarPesos = ($esMandante || $esClienteFinal);
  1165.             $spreadsheet = new Spreadsheet();
  1166.             /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  1167.             $sheet $spreadsheet->getActiveSheet();
  1168.             $sheet->setShowGridlines(false);
  1169.             $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
  1170.             $drawing->setName('logo');
  1171.             $drawing->setDescription('logo');
  1172.             $drawing->setPath('media/logo_transfarma_verde.png'); // put your path and image here
  1173.             $drawing->setCoordinates('A1');
  1174.             $drawing->setWorksheet($sheet);
  1175.             $sheet->setCellValue('A6''DASHBOARD');
  1176.             $sheet->getStyle('A6')->getFont()->setBoldtrue );
  1177.             $sheet->setCellValue('A7'$ahora->format('d-m-Y H:i'));
  1178.             $sheet->mergeCells("A6:Z6"); 
  1179.             $sheet->mergeCells("A7:Z7"); 
  1180.                                 
  1181.             $sheet->setCellValue('A9''Nro');
  1182.             $sheet->setCellValue('B9''Codigo de Barra');
  1183.             $sheet->setCellValue('C9''Fecha de Solicitud');
  1184.             $sheet->setCellValue('D9''Mandante');
  1185.             $sheet->setCellValue('E9''Cliente');
  1186.             $sheet->setCellValue('F9''Estado');
  1187.             $sheet->setCellValue('G9''Origen');
  1188.             $sheet->setCellValue('H9''Ciudad de Origen');
  1189.             $sheet->setCellValue('I9''Destino');
  1190.             $sheet->setCellValue('J9''Dirección');
  1191.             $sheet->setCellValue('K9''Comuna');
  1192.             $sheet->setCellValue('L9''Región');
  1193.             $sheet->setCellValue('M9''Zona');
  1194.             $sheet->setCellValue('N9''Base de Cobertura');
  1195.             $sheet->setCellValue('O9''Documento');
  1196.             $sheet->setCellValue('P9''Nº Doc');
  1197.             $sheet->setCellValue('Q9''Orden de Compra');
  1198.             $sheet->setCellValue('R9''Tipo de Servicio');
  1199.             $sheet->setCellValue('S9''Tipo de Carga');
  1200.             $sheet->setCellValue('T9''Tipo de Transporte');
  1201.             $sheet->setCellValue('U9''Via de Transporte');
  1202.             $sheet->setCellValue('V9''Requiere Cedible');
  1203.             $sheet->setCellValue('W9''Seguro');
  1204.             $sheet->setCellValue('X9''Cenabast');
  1205.             $sheet->setCellValue('Y9''Muestra Médica');
  1206.             $sheet->setCellValue('Z9''Bultos');
  1207.             if (!$ocultarPesos) {
  1208.                 $sheet->setCellValue('AA9''Peso Kilos');
  1209.                 $sheet->setCellValue('AB9''Peso Vol.');
  1210.             }
  1211.             $sheet->setCellValue('AC9''Nombre Receptor');
  1212.             $sheet->setCellValue('AD9''RUT Receptor');
  1213.             $sheet->setCellValue('AE9''Fecha Recepcion');
  1214.             $sheet->setCellValue('AF9''Fecha Ruta');
  1215.             if($this->security->isGranted('ROLE_TRANSFARMA'))
  1216.             {
  1217.                 $sheet->setCellValue('AG9''Patente Ruta');
  1218.             }
  1219.             $sheet->setCellValue('AH9''Tramo Vehiculo');
  1220.             $sheet->setCellValue('AI9''Tiempo Transcurrido (hrs)');
  1221.             $sheet->setCellValue('AJ9''Lead Time MT (Hrs)');
  1222.             $sheet->setCellValue('AK9''OTIF (ON TIME)');
  1223.             $sheet->setCellValue('AL9''Bultos (cantidad PK Solicitados)');
  1224.             $sheet->setCellValue('AM9''Bultos (cantidad PK recibidos)');
  1225.             $sheet->setCellValue('AN9''OTIF (IN FULL)');
  1226.             $sheet->setCellValue('AO9''Clasificación OTIF');
  1227.             $sheet->setCellValue('AP9''Clasificación Compliance OTIF');
  1228.             
  1229.            // Peso Max lo ve Transfarma + Mandante + Cliente Final
  1230.             if ($esTransfarma || $ocultarPesos) {
  1231.                 $sheet->setCellValue('AQ9''Peso Max. (Transfarma)');
  1232.             }
  1233.             // Estas columnas SOLO Transfarma
  1234.             if ($esTransfarma) {
  1235.                 $sheet->setCellValue('AR9''Codigo de Delivery');
  1236.                 $sheet->setCellValue('AS9''Código Reversa');
  1237.                 $sheet->setCellValue('AT9''Estado');
  1238.                 $sheet->setCellValue('AU9''Subestado');
  1239.                 $sheet->setCellValue('AV9''Codigo Data Logger');
  1240.                 $sheet->setCellValue('AW9''Codigo Vacutec');
  1241.                 $sheet->setCellValue('AX9''Manifiesto Ruta asignado');
  1242.             }
  1243.             
  1244.             $fila 9;
  1245.             $i 0;
  1246.             foreach($lista as $item)
  1247.             {
  1248.                 $i++;
  1249.                 $fila++;
  1250.                 $sheet->setCellValue('A'.$fila$i);
  1251.                 $sheet->setCellValue('B'.$fila$item["codigo_barra"]);
  1252.                 $sheet->setCellValue('C'.$fila, (new \DateTime($item["fecha_solicitud"]))->format('d-m-Y'));
  1253.                 $sheet->setCellValue('D'.$fila$item["nombre_cliente"]);
  1254.                 $sheet->setCellValue('E'.$fila$item["nombre_cliente_final"]);
  1255.                 $sheet->setCellValue('F'.$fila$item["nombre_estado"]);
  1256.                 $sheet->setCellValue('G'.$fila$item["nombre_direccion_origen"]);
  1257.                 $sheet->setCellValue('H'.$fila$item["ciudad_direccion_origen"]);
  1258.                 $sheet->setCellValue('I'.$fila$item["nombre_direccion_destino"]);
  1259.                 $sheet->setCellValue('J'.$fila$item["direccion"]);
  1260.                 $sheet->setCellValue('K'.$fila$item["nombre_comuna"]);
  1261.                 $sheet->setCellValue('L'.$fila$item["nombre_region"]);
  1262.                 $sheet->setCellValue('M'.$fila$item["nombre_zona"]);
  1263.                 $sheet->setCellValue('N'.$fila$item["nombre_sucursal"]);
  1264.                 
  1265.                 $documentos '';
  1266.                 if($item['tipo_documento_01'])
  1267.                 {
  1268.                     $documentos $documentos.$item['tipo_documento_01'].' '.$item['folio_tipo_documento_01'].' ';
  1269.                     if($item['copia_tipo_documento01'])
  1270.                     {
  1271.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento01'].') ';
  1272.                     }
  1273.                 }
  1274.                 if($item['tipo_documento_02'])
  1275.                 {
  1276.                     $documentos $documentos.$item['tipo_documento_02'].' '.$item['folio_tipo_documento_02'].' ';
  1277.                     if($item['copia_tipo_documento02'])
  1278.                     {
  1279.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento02'].') ';
  1280.                     }
  1281.                 }
  1282.                 if($item['tipo_documento_03'])
  1283.                 {
  1284.                     $documentos $documentos.$item['tipo_documento_03'].' '.$item['folio_tipo_documento_03'].' ';
  1285.                     if($item['copia_tipo_documento03'])
  1286.                     {
  1287.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento03'].') ';
  1288.                     }
  1289.                 }
  1290.                 if($item['tipo_documento_04'])
  1291.                 {
  1292.                     $documentos $documentos.$item['tipo_documento_04'].' '.$item['folio_tipo_documento_04'].' ';
  1293.                     if($item['copia_tipo_documento04'])
  1294.                     {
  1295.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento04'].') ';
  1296.                     }
  1297.                 }
  1298.                 if($item['tipo_documento_05'])
  1299.                 {
  1300.                     $documentos $documentos.$item['tipo_documento_05'].' '.$item['folio_tipo_documento_05'].' ';
  1301.                     if($item['copia_tipo_documento05'])
  1302.                     {
  1303.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento05'].') ';
  1304.                     }
  1305.                 }
  1306.                 if($item['tipo_documento_06'])
  1307.                 {
  1308.                     $documentos $documentos.$item['tipo_documento_06'].' '.$item['folio_tipo_documento_06'].' ';
  1309.                     if($item['copia_tipo_documento06'])
  1310.                     {
  1311.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento06'].') ';
  1312.                     }
  1313.                 }
  1314.                 if($item['tipo_documento_07'])
  1315.                 {
  1316.                     $documentos $documentos.$item['tipo_documento_07'].' '.$item['folio_tipo_documento_07'].' ';
  1317.                     if($item['copia_tipo_documento07'])
  1318.                     {
  1319.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento07'].') ';
  1320.                     }
  1321.                 }
  1322.                 if($item['tipo_documento_08'])
  1323.                 {
  1324.                     $documentos $documentos.$item['tipo_documento_08'].' '.$item['folio_tipo_documento_08'].' ';
  1325.                     if($item['copia_tipo_documento08'])
  1326.                     {
  1327.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento08'].') ';
  1328.                     }
  1329.                 }
  1330.                 if($item['tipo_documento_09'])
  1331.                 {
  1332.                     $documentos $documentos.$item['tipo_documento_09'].' '.$item['folio_tipo_documento_09'].' ';
  1333.                     if($item['copia_tipo_documento09'])
  1334.                     {
  1335.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento09'].') ';
  1336.                     }
  1337.                 }
  1338.                 if($item['tipo_documento_10'])
  1339.                 {
  1340.                     $documentos $documentos.$item['tipo_documento_10'].' '.$item['folio_tipo_documento_10'].' ';
  1341.                     if($item['copia_tipo_documento10'])
  1342.                     {
  1343.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento10'].') ';
  1344.                     }
  1345.                 }
  1346.                 if($item['tipo_documento_11'])
  1347.                 {
  1348.                     $documentos $documentos.$item['tipo_documento_11'].' '.$item['folio_tipo_documento_11'].' ';
  1349.                     if($item['copia_tipo_documento11'])
  1350.                     {
  1351.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento11'].') ';
  1352.                     }
  1353.                 }
  1354.                 if($item['tipo_documento_12'])
  1355.                 {
  1356.                     $documentos $documentos.$item['tipo_documento_12'].' '.$item['folio_tipo_documento_12'].' ';
  1357.                     if($item['copia_tipo_documento12'])
  1358.                     {
  1359.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento12'].') ';
  1360.                     }
  1361.                 }
  1362.                 if($item['tipo_documento_13'])
  1363.                 {
  1364.                     $documentos $documentos.$item['tipo_documento_13'].' '.$item['folio_tipo_documento_13'].' ';
  1365.                     if($item['copia_tipo_documento13'])
  1366.                     {
  1367.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento13'].') ';
  1368.                     }
  1369.                 }
  1370.                 if($item['tipo_documento_14'])
  1371.                 {
  1372.                     $documentos $documentos.$item['tipo_documento_14'].' '.$item['folio_tipo_documento_14'].' ';
  1373.                     if($item['copia_tipo_documento14'])
  1374.                     {
  1375.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento14'].') ';
  1376.                     }
  1377.                 }
  1378.                 if($item['tipo_documento_15'])
  1379.                 {
  1380.                     $documentos $documentos.$item['tipo_documento_15'].' '.$item['folio_tipo_documento_15'].' ';
  1381.                     if($item['copia_tipo_documento15'])
  1382.                     {
  1383.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento15'].') ';
  1384.                     }
  1385.                 }
  1386.                 if($item['tipo_documento_16'])
  1387.                 {
  1388.                     $documentos $documentos.$item['tipo_documento_16'].' '.$item['folio_tipo_documento_16'].' ';
  1389.                     if($item['copia_tipo_documento16'])
  1390.                     {
  1391.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento16'].') ';
  1392.                     }
  1393.                 }
  1394.                 if($item['tipo_documento_17'])
  1395.                 {
  1396.                     $documentos $documentos.$item['tipo_documento_17'].' '.$item['folio_tipo_documento_17'].' ';
  1397.                     if($item['copia_tipo_documento17'])
  1398.                     {
  1399.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento17'].') ';
  1400.                     }
  1401.                 }
  1402.                 if($item['tipo_documento_18'])
  1403.                 {
  1404.                     $documentos $documentos.$item['tipo_documento_18'].' '.$item['folio_tipo_documento_18'].' ';
  1405.                     if($item['copia_tipo_documento18'])
  1406.                     {
  1407.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento18'].') ';
  1408.                     }
  1409.                 }
  1410.                 if($item['tipo_documento_19'])
  1411.                 {
  1412.                     $documentos $documentos.$item['tipo_documento_19'].' '.$item['folio_tipo_documento_19'].' ';
  1413.                     if($item['copia_tipo_documento19'])
  1414.                     {
  1415.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento19'].') ';
  1416.                     }
  1417.                 }
  1418.                 if($item['tipo_documento_20'])
  1419.                 {
  1420.                     $documentos $documentos.$item['tipo_documento_20'].' '.$item['folio_tipo_documento_20'].' ';
  1421.                     if($item['copia_tipo_documento20'])
  1422.                     {
  1423.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento20'].') ';
  1424.                     }
  1425.                 }
  1426.                 if($item['tipo_documento_21'])
  1427.                 {
  1428.                     $documentos $documentos.$item['tipo_documento_21'].' '.$item['folio_tipo_documento_21'].' ';
  1429.                     if($item['copia_tipo_documento21'])
  1430.                     {
  1431.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento21'].') ';
  1432.                     }
  1433.                 }
  1434.                 if($item['tipo_documento_22'])
  1435.                 {
  1436.                     $documentos $documentos.$item['tipo_documento_22'].' '.$item['folio_tipo_documento_22'].' ';
  1437.                     if($item['copia_tipo_documento22'])
  1438.                     {
  1439.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento22'].') ';
  1440.                     }
  1441.                 }
  1442.                 if($item['tipo_documento_23'])
  1443.                 {
  1444.                     $documentos $documentos.$item['tipo_documento_23'].' '.$item['folio_tipo_documento_23'].' ';
  1445.                     if($item['copia_tipo_documento23'])
  1446.                     {
  1447.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento23'].') ';
  1448.                     }
  1449.                 }
  1450.                 if($item['tipo_documento_24'])
  1451.                 {
  1452.                     $documentos $documentos.$item['tipo_documento_24'].' '.$item['folio_tipo_documento_24'].' ';
  1453.                     if($item['copia_tipo_documento24'])
  1454.                     {
  1455.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento24'].') ';
  1456.                     }
  1457.                 }
  1458.                 if($item['tipo_documento_25'])
  1459.                 {
  1460.                     $documentos $documentos.$item['tipo_documento_25'].' '.$item['folio_tipo_documento_25'].' ';
  1461.                     if($item['copia_tipo_documento25'])
  1462.                     {
  1463.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento25'].') ';
  1464.                     }
  1465.                 }
  1466.                 if($item['tipo_documento_26'])
  1467.                 {
  1468.                     $documentos $documentos.$item['tipo_documento_26'].' '.$item['folio_tipo_documento_26'].' ';
  1469.                     if($item['copia_tipo_documento26'])
  1470.                     {
  1471.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento26'].') ';
  1472.                     }
  1473.                 }
  1474.                 if($item['tipo_documento_27'])
  1475.                 {
  1476.                     $documentos $documentos.$item['tipo_documento_27'].' '.$item['folio_tipo_documento_27'].' ';
  1477.                     if($item['copia_tipo_documento27'])
  1478.                     {
  1479.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento27'].') ';
  1480.                     }
  1481.                 }
  1482.                 if($item['tipo_documento_28'])
  1483.                 {
  1484.                     $documentos $documentos.$item['tipo_documento_28'].' '.$item['folio_tipo_documento_28'].' ';
  1485.                     if($item['copia_tipo_documento28'])
  1486.                     {
  1487.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento28'].') ';
  1488.                     }
  1489.                 }
  1490.                 if($item['tipo_documento_29'])
  1491.                 {
  1492.                     $documentos $documentos.$item['tipo_documento_29'].' '.$item['folio_tipo_documento_29'].' ';
  1493.                     if($item['copia_tipo_documento29'])
  1494.                     {
  1495.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento29'].') ';
  1496.                     }
  1497.                 }
  1498.                 if($item['tipo_documento_30'])
  1499.                 {
  1500.                     $documentos $documentos.$item['tipo_documento_30'].' '.$item['folio_tipo_documento_30'].' ';
  1501.                     if($item['copia_tipo_documento30'])
  1502.                     {
  1503.                         $documentos $documentos.' (Copia '.$item['copia_tipo_documento30'].') ';
  1504.                     }
  1505.                 }
  1506.                
  1507.                 $sheet->setCellValue('O'.$fila$documentos);
  1508.                 
  1509.                 $sheet->setCellValue('P'.$fila$item["suma_documentos"]);
  1510.                 $sheet->setCellValue('Q'.$fila$item["folio_orden_compra"]);
  1511.                 $sheet->setCellValue('R'.$fila$item["nombre_tipo_servicio"]);
  1512.                 $sheet->setCellValue('S'.$fila$item["nombre_tipo_carga"]);
  1513.                 $sheet->setCellValue('T'.$fila$item["nombre_tipo_transporte"]);
  1514.                 $sheet->setCellValue('U'.$fila$item["nombre_via_transporte"]);
  1515.                 $sheet->setCellValue('V'.$fila$item["requiere_cedible"] ? 'SI' 'NO');
  1516.                 $sheet->setCellValue('W'.$fila$item["seguro"] ? 'SI' 'NO');
  1517.                 $sheet->setCellValue('X'.$fila$item["cenabast"] ? 'SI' 'NO');
  1518.                 $sheet->setCellValue('Y'.$fila$item["muestra_medica"] ? 'SI' 'NO');
  1519.                 $sheet->setCellValue('Z'.$fila$item["suma_bultos"]);
  1520.                 if (!$ocultarPesos) {
  1521.                     $sheet->setCellValue('AA'.$fila$item["suma_peso_kilos"]);
  1522.                     $sheet->setCellValue('AB'.$fila$item["suma_peso_vol"]);
  1523.                 }
  1524.                 $sheet->setCellValue('AC'.$fila$item["nombre_entrega"]);
  1525.                 $sheet->setCellValue('AD'.$fila$item["rut_entrega"]);
  1526.                 if($item["fecha_entrega"])
  1527.                 {
  1528.                     $sheet->setCellValue('AE'.$fila, (new \DateTime($item["fecha_entrega"]))->format('d-m-Y'));
  1529.                 }
  1530.                 if($item["fecha_ruta"])
  1531.                 {
  1532.                     $sheet->setCellValue('AF'.$fila, (new \DateTime($item["fecha_ruta"]))->format('d-m-Y'));
  1533.                 }
  1534.                 if($this->security->isGranted('ROLE_TRANSFARMA'))
  1535.                 {
  1536.                     $sheet->setCellValue('AG'.$fila$item["vehiculo_patente"].$item["urbano_patente"]);
  1537.                 }             
  1538.                 $sheet->setCellValue('AH'.$fila$item["tramo_vehiculo"]);                
  1539.                 $sheet->setCellValue('AI'.$fila$item["tiempo_transcurrido"]);                
  1540.                 $sheet->setCellValue('AJ'.$fila$item["lead_time_cliente"]);                
  1541.                 $sheet->setCellValue('AK'.$fila$item["otif_cliente"]);                
  1542.                 $sheet->setCellValue('AL'.$fila$item["cantidad_bultos_solicitados"]);                
  1543.                 $sheet->setCellValue('AM'.$fila$item["cantidad_bultos_recibidos"]);                
  1544.                 $sheet->setCellValue('AN'.$fila$item["otif_in_full"]);                
  1545.                 $sheet->setCellValue('AO'.$fila$item["otif_cliente"].' - '.$item["otif_in_full"]);                
  1546.                 $sheet->setCellValue('AP'.$fila$item["compliance_cliente"]);                
  1547.                 
  1548.               if ($esTransfarma || $ocultarPesos) {
  1549.                     $sheet->setCellValue('AQ'.$fila$item["suma_kilos"]);
  1550.                 }
  1551.                   if ($esTransfarma) {
  1552.                 $sheet->setCellValue('AR'.$fila$item["codigo_delivery"].' '.$item["dhl_guia"].' '.$item["extern_order_key"]);
  1553.                 $sheet->setCellValue('AS'.$fila$item["codigo_barra_logistica_inversa"]);
  1554.                 $sheet->setCellValue('AT'.$fila$item["nombre_estado"]);
  1555.                 $sheet->setCellValue('AU'.$fila$item["nombre_subestado"]);
  1556.                 $sheet->setCellValue('AV'.$fila$item["codigo_data_logger"]);
  1557.                 $sheet->setCellValue('AW'.$fila$item["codigo_vacutec"]);
  1558.                 $sheet->setCellValue('AX'.$fila$item["codigo_manifiesto"]);
  1559.             }
  1560.                 
  1561.             }
  1562.             //$sheet->setAutoFilter($sheet->calculateWorksheetDimension());
  1563.          
  1564.             
  1565.            if ($esTransfarma) {
  1566.                     $ultimaColumna 'AX';
  1567.                 } elseif ($ocultarPesos) {
  1568.                     $ultimaColumna 'AQ';
  1569.                 } else {
  1570.                     $ultimaColumna 'AP';
  1571.                 }
  1572.                 $sheet->getStyle('A9:'.$ultimaColumna.'9')->getFont()->setBold(true);
  1573.                 $sheet->getStyle('A9:'.$ultimaColumna.'9')->getFont()->getColor()
  1574.                     ->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  1575.                 $sheet->getStyle('A9:'.$ultimaColumna.'9')->getFill()
  1576.                     ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
  1577.                     ->getStartColor()->setARGB('FF426384');
  1578.                     
  1579.             // Create your Office 2007 Excel (XLSX Format)
  1580.             $writer = new Xlsx($spreadsheet);
  1581.             
  1582.             // Create a Temporary file in the system
  1583.             $fileName 'TRF-DASHBOARD-'.($ahora->format('Ymd-Hi')).'.xlsx';
  1584.             $temp_file tempnam($this->getParameter('kernel.project_dir').'/temp/'$fileName);
  1585.             
  1586.             // Create the excel file in the tmp directory of the system
  1587.             $writer->save($temp_file);
  1588.             
  1589.             // Return the excel file as an attachment
  1590.             return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1591.             
  1592.         } catch(\Exception $e){
  1593.             $this->logger->error($e->getMessage(), [
  1594.                 'exception' => $e,
  1595.                 'trace'  => $e->getTraceAsString(), 
  1596.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  1597.                 'method' => $request->getMethod(), // GET, POST, etc.
  1598.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  1599.                 'params' => $request->request->all()
  1600.             ]);
  1601.             $this->addFlash('danger',$e->getMessage());
  1602.             return $this->redirectToRoute('app_admin_index');
  1603.         }
  1604.     }
  1605.     /**
  1606.      * @Route("/dashboard/seleccionar-region/",name="dashboard_seleccionar_region")
  1607.      * @param Request $request
  1608.      */
  1609.     public function dashboard_seleccionar_region(Request $request)
  1610.     {
  1611.         try
  1612.         {
  1613.             $regionNombre $request->query->get("region_nombre");
  1614.             $region $this->regionRepository->findOneByNombre($regionNombre);
  1615.             if(!$region)
  1616.             {
  1617.                 $this->addFlash('danger','No se encuentra información de región');
  1618.                 return $this->redirectToRoute('dashboard_inicial');
  1619.             }
  1620.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  1621.             if(!$dto)
  1622.             {
  1623.                 $dto = new DashboardBuscarDto();
  1624.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  1625.                 $dto->fechaHasta = (new \DateTime('today'));
  1626.             }
  1627.             else
  1628.             {
  1629.                 if($dto->supermandante)
  1630.                     {
  1631.                         $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  1632.                     }
  1633.                 if($dto->cliente)
  1634.                     {
  1635.                         $posicion 0;
  1636.                         foreach($dto->cliente as $item_cliente){
  1637.                             $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  1638.                             $posicion++;
  1639.                         }
  1640.                     }
  1641.                 if($dto->clienteFinal)
  1642.                     {
  1643.                         $posicion 0;
  1644.                         foreach($dto->clienteFinal as $item_cliente){
  1645.                             $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  1646.                             $posicion++;
  1647.                         }
  1648.                     }
  1649.             }
  1650.             $dto->region $region;
  1651.             $dto->regionNombre $region->getNombre();
  1652.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'$dto);
  1653.             return $this->redirectToRoute('dashboard_inicial');
  1654.         }
  1655.         catch(\Exception $e){
  1656.             $this->logger->error($e->getMessage(), [
  1657.                 'exception' => $e,
  1658.                 'trace'  => $e->getTraceAsString(), 
  1659.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  1660.                 'method' => $request->getMethod(), // GET, POST, etc.
  1661.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  1662.                 'params' => $request->request->all()
  1663.             ]);
  1664.             $this->addFlash('danger',$e->getMessage());
  1665.             return $this->redirectToRoute('dashboard_inicial');
  1666.         }
  1667.     }
  1668.     /**
  1669.      * @Route("/dashboard/seleccionar-tipo-carga/",name="dashboard_seleccionar_tipo_carga")
  1670.      * @param Request $request
  1671.      */
  1672.     public function dashboard_seleccionar_tipo_carga(Request $request)
  1673.     {
  1674.         try
  1675.         {
  1676.             $tipoCargaId $request->query->get("tipo_carga_id");
  1677.             $tipoCarga $this->tipoCargaRepository->findOneById($tipoCargaId);
  1678.             if(!$tipoCarga)
  1679.             {
  1680.                 $this->addFlash('danger','No se encuentra información de tipo de carga');
  1681.                 return $this->redirectToRoute('dashboard_inicial');
  1682.             }
  1683.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  1684.             if(!$dto)
  1685.             {
  1686.                 $dto = new DashboardBuscarDto();
  1687.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  1688.                 $dto->fechaHasta = (new \DateTime('today'));
  1689.             }
  1690.             else
  1691.             {
  1692.                 if($dto->supermandante)
  1693.                     {
  1694.                         $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  1695.                     }
  1696.                 if($dto->cliente)
  1697.                 {
  1698.                     $posicion 0;
  1699.                     foreach($dto->cliente as $item_cliente){
  1700.                         $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  1701.                         $posicion++;
  1702.                     }
  1703.                 }
  1704.                 if($dto->clienteFinal)
  1705.                 {
  1706.                     $posicion 0;
  1707.                     foreach($dto->clienteFinal as $item_cliente){
  1708.                         $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  1709.                         $posicion++;
  1710.                     }
  1711.                 }
  1712.             }
  1713.             $dto->tipoCarga $tipoCargaId;
  1714.             $dto->tipoCargaNombre $tipoCarga->getNombre();
  1715.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'$dto);
  1716.             return $this->redirectToRoute('dashboard_inicial');
  1717.         }
  1718.         catch(\Exception $e){
  1719.             $this->logger->error($e->getMessage(), [
  1720.                 'exception' => $e,
  1721.                 'trace'  => $e->getTraceAsString(), 
  1722.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  1723.                 'method' => $request->getMethod(), // GET, POST, etc.
  1724.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  1725.                 'params' => $request->request->all()
  1726.             ]);
  1727.             $this->addFlash('danger',$e->getMessage());
  1728.             return $this->redirectToRoute('dashboard_inicial');
  1729.         }
  1730.     }
  1731.     /**
  1732.      * @Route("/dashboard/seleccionar-via-transporte/",name="dashboard_seleccionar_via_transporte")
  1733.      * @param Request $request
  1734.      */
  1735.     public function dashboard_seleccionar_via_transporte(Request $request)
  1736.     {
  1737.         try
  1738.         {
  1739.             $viaTransporteId $request->query->get("via_transporte_id");
  1740.             $viaTransporte $this->viaTransporteRepository->findOneById($viaTransporteId);
  1741.             if(!$viaTransporte)
  1742.             {
  1743.                 $this->addFlash('danger','No se encuentra información de via de transporte');
  1744.                 return $this->redirectToRoute('dashboard_inicial');
  1745.             }
  1746.             $dto $this->session->get('SESION_DASHBOARD_BUSCAR_DTO');
  1747.             if(!$dto)
  1748.             {
  1749.                 $dto = new DashboardBuscarDto();
  1750.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  1751.                 $dto->fechaHasta = (new \DateTime('today'));
  1752.             }
  1753.             else
  1754.             {
  1755.                 if($dto->supermandante)
  1756.                     {
  1757.                         $dto->supermandante $this->entityManager->merge($dto->supermandante); 
  1758.                     }
  1759.                 if($dto->cliente)
  1760.                     {
  1761.                         $posicion 0;
  1762.                         foreach($dto->cliente as $item_cliente){
  1763.                             $dto->cliente[$posicion] = $this->entityManager->merge($item_cliente); 
  1764.                             $posicion++;
  1765.                         }
  1766.                     }
  1767.                 if($dto->clienteFinal)
  1768.                     {
  1769.                         $posicion 0;
  1770.                         foreach($dto->clienteFinal as $item_cliente){
  1771.                             $dto->clienteFinal[$posicion] = $this->entityManager->merge($item_cliente); 
  1772.                             $posicion++;
  1773.                         }
  1774.                     }
  1775.             }
  1776.             $dto->viaTransporte $viaTransporteId;
  1777.             $dto->viaTransporteNombre $viaTransporte->getNombre();
  1778.             $this->session->set('SESION_DASHBOARD_BUSCAR_DTO'$dto);
  1779.             return $this->redirectToRoute('dashboard_inicial');
  1780.         }
  1781.         catch(\Exception $e){
  1782.             $this->logger->error($e->getMessage(), [
  1783.                 'exception' => $e,
  1784.                 'trace'  => $e->getTraceAsString(), 
  1785.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  1786.                 'method' => $request->getMethod(), // GET, POST, etc.
  1787.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  1788.                 'params' => $request->request->all()
  1789.             ]);
  1790.             $this->addFlash('danger',$e->getMessage());
  1791.             return $this->redirectToRoute('dashboard_inicial');
  1792.         }
  1793.     }
  1794.     /**
  1795.      * @Route("/dashboard/temperatura/anterior/", name="dashboard_temperatura_anterior")
  1796.      * @IsGranted("ROLE_USER")
  1797.      */
  1798.     public function dashboard_temperatura_anterior(Request $request): Response
  1799.     {
  1800.         try{
  1801.             $dto = new DashboardTemperaturaDto();
  1802.             $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  1803.             $dto->fechaHasta = (new \DateTime('now'));
  1804.         
  1805.             $lista null;
  1806.             $rango_operacion null;
  1807.             $vehiculo null;
  1808.             $dispositivo null;
  1809.             $fecha_inicio null;
  1810.             $fecha_fin null;
  1811.             $numero_puntos_medidos 0;
  1812.             $limite_inferior null;
  1813.             $limite_superior null;
  1814.             $temperatura_maxima null;
  1815.             $temperatura_minima null;
  1816.             $temperatura_suma 0;
  1817.             $temperatura_promedio null;
  1818.             $desviacion_estandar null;
  1819.             $tiempo_sobre_limite 0;
  1820.             $tiempo_bajo_limite 0;
  1821.             $grafico_minimo = -40;
  1822.             $grafico_maximo 40;
  1823.             $tiempo_sobre_limite_h 0;
  1824.             $tiempo_sobre_limite_m 0;
  1825.             $tiempo_sobre_limite_s 0;
  1826.             $tiempo_bajo_limite_h 0;
  1827.             $tiempo_bajo_limite_m 0;
  1828.             $tiempo_bajo_limite_s 0;
  1829.             $form $this->createForm(DashboardTemperaturaFormType::class, $dto);
  1830.             $form->handleRequest($request);
  1831.             if ($form->isSubmitted() && $form->isValid()) {
  1832.                 $lista $this->bitacoraTemperaturaRepository->findByDashboardTemperaturaDto($dto);
  1833.                 $rango_operacion $this->tipoCargaRepository->findOneById($dto->tipoCarga);
  1834.                 $vehiculo $this->vehiculoRepository->findOneById($dto->vehiculo);
  1835.                 if($vehiculo)
  1836.                 {
  1837.                     $dispositivo $vehiculo->getDispositivo();
  1838.                 }
  1839.                 if($rango_operacion)
  1840.                 {
  1841.                     $limite_inferior $rango_operacion->getMinimo();
  1842.                     $limite_superior $rango_operacion->getMaximo();
  1843.                     $grafico_minimo $rango_operacion->getMinimo();
  1844.                     $grafico_maximo $rango_operacion->getMaximo();
  1845.                 }
  1846.                 $time_anterior null;
  1847.                 foreach($lista as $item)
  1848.                 {
  1849.                     $temperatura_actual $item->getTemp1();
  1850.                     $time_actual $item->getTimestamp();
  1851.                     if($temperatura_actual)
  1852.                     {
  1853.                         if($fecha_inicio == null)
  1854.                         {
  1855.                             $fecha_inicio $time_actual;
  1856.                         }
  1857.                         $fecha_fin $time_actual;
  1858.                         $numero_puntos_medidos++;
  1859.                         $temperatura_suma $temperatura_suma $temperatura_actual;
  1860.                         if((!$temperatura_maxima) or ($temperatura_maxima $temperatura_actual))
  1861.                         {
  1862.                             $temperatura_maxima $temperatura_actual;
  1863.                         }
  1864.                         if((!$temperatura_minima) or ($temperatura_minima $temperatura_actual))
  1865.                         {
  1866.                             $temperatura_minima $temperatura_actual;
  1867.                         }
  1868.                         if(($limite_inferior) and ($temperatura_actual $limite_inferior))
  1869.                         {
  1870.                             if($time_anterior)
  1871.                             {
  1872.                                 $diff $time_actual->diff($time_anterior);
  1873.                                 $segundos $diff->days 24 60 60;
  1874.                                 $segundos += $diff->60 60;
  1875.                                 $segundos += $diff->60;
  1876.                                 $segundos += $diff->s;
  1877.                                 $tiempo_bajo_limite $tiempo_bajo_limite $segundos;
  1878.                             }
  1879.                         }
  1880.                         if(($limite_superior) and ($temperatura_actual $limite_superior))
  1881.                         {
  1882.                             if($time_anterior)
  1883.                             {
  1884.                                 $diff $time_actual->diff($time_anterior);
  1885.                                 $segundos $diff->days 24 60 60;
  1886.                                 $segundos += $diff->60 60;
  1887.                                 $segundos += $diff->60;
  1888.                                 $segundos += $diff->s;
  1889.                                 $tiempo_sobre_limite $tiempo_sobre_limite $segundos;
  1890.                             }
  1891.                         }
  1892.                         $time_anterior $time_actual;
  1893.                     }
  1894.                     
  1895.                 }
  1896.                 if($numero_puntos_medidos 0)
  1897.                 {
  1898.                     $temperatura_promedio $temperatura_suma $numero_puntos_medidos;
  1899.                     // calculo de desviacion estandar
  1900.                     $ans=0;
  1901.                     foreach($lista as $item)
  1902.                     {
  1903.                         if($item->getTemp1())
  1904.                         {
  1905.                             $ans+=pow(($item->getTemp1()-$temperatura_promedio),2);
  1906.                         }
  1907.                     }
  1908.                     $desviacion_estandar sqrt($ans/$numero_puntos_medidos);
  1909.                 }
  1910.                 if($grafico_minimo $temperatura_minima)
  1911.                 {
  1912.                     $grafico_minimo $temperatura_minima;
  1913.                 }
  1914.                 if($grafico_maximo $temperatura_maxima)
  1915.                 {
  1916.                     $grafico_maximo $temperatura_maxima;
  1917.                 }
  1918.                 if($grafico_minimo 0)
  1919.                 {
  1920.                     $grafico_minimo 0;
  1921.                 }else
  1922.                 {
  1923.                     $grafico_minimo $grafico_minimo 5;
  1924.                 }
  1925.                 $grafico_maximo $grafico_maximo 5;
  1926.  
  1927.                 if($tiempo_sobre_limite)
  1928.                 {
  1929.                     $tiempo_sobre_limite_h floor($tiempo_sobre_limite 3600);
  1930.                     $tiempo_sobre_limite_m floor(($tiempo_sobre_limite - ($tiempo_sobre_limite_h 3600)) / 60);
  1931.                     $tiempo_sobre_limite_s = ($tiempo_sobre_limite 60);
  1932.                 }
  1933.                 if($tiempo_bajo_limite)
  1934.                 {
  1935.                     $tiempo_bajo_limite_h floor($tiempo_bajo_limite 3600);
  1936.                     $tiempo_bajo_limite_m floor(($tiempo_bajo_limite - ($tiempo_bajo_limite_h 3600)) / 60);
  1937.                     $tiempo_bajo_limite_s = ($tiempo_sobre_limite 60);
  1938.                 }
  1939.             }
  1940.             $intervalo 120// 2 horas
  1941.             if($fecha_inicio && $fecha_fin)
  1942.             {
  1943.                 $di_fechas $fecha_inicio->diff($fecha_fin);
  1944.                 $minutes $di_fechas->days 24 60;
  1945.                 $minutes += $di_fechas->60;
  1946.                 $minutes += $di_fechas->i;
  1947.                 if($minutes <= 20)
  1948.                 {
  1949.                     $intervalo 1;
  1950.                 }
  1951.                 elseif($minutes 2400)
  1952.                 {
  1953.                     $intervalo 120;
  1954.                 }
  1955.                 else
  1956.                 {
  1957.                     $intervalo = ($minutes 20);
  1958.                 }
  1959.             }
  1960.             return $this->render('dashboard/temperatura2.html.twig', array(
  1961.                 'form' => $form->createView(),
  1962.                 'lista' => $lista,
  1963.                 'rango_operacion' => $rango_operacion,
  1964.                 'vehiculo' => $vehiculo,
  1965.                 'dispositivo' => $dispositivo,
  1966.                 'fecha_inicio' => $fecha_inicio,
  1967.                 'fecha_fin' => $fecha_fin,
  1968.                 'numero_puntos_medidos' => $numero_puntos_medidos,
  1969.                 'limite_inferior' => $limite_inferior,
  1970.                 'limite_superior' => $limite_superior,
  1971.                 'temperatura_maxima' => $temperatura_maxima,
  1972.                 'temperatura_minima' => $temperatura_minima,
  1973.                 'temperatura_promedio' => $temperatura_promedio,
  1974.                 'desviacion_estandar' => $desviacion_estandar,
  1975.                 'tiempo_sobre_limite_h' => $tiempo_sobre_limite_h,
  1976.                 'tiempo_sobre_limite_m' => $tiempo_sobre_limite_m,
  1977.                 'tiempo_sobre_limite_s' => $tiempo_sobre_limite_s,
  1978.                 'tiempo_bajo_limite_h' => $tiempo_bajo_limite_h,
  1979.                 'tiempo_bajo_limite_m' => $tiempo_bajo_limite_m,
  1980.                 'tiempo_bajo_limite_s' => $tiempo_bajo_limite_s,
  1981.                 'grafico_minimo' => $grafico_minimo,
  1982.                 'grafico_maximo' => $grafico_maximo,
  1983.                 'intervalo' => $intervalo,
  1984.             ));
  1985.         }
  1986.         catch(\Exception $e){
  1987.             $this->logger->error($e->getMessage(), [
  1988.                 'exception' => $e,
  1989.                 'trace'  => $e->getTraceAsString(), 
  1990.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  1991.                 'method' => $request->getMethod(), // GET, POST, etc.
  1992.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  1993.                 'params' => $request->request->all()
  1994.             ]);
  1995.             $this->addFlash('danger',$e->getMessage());
  1996.             return $this->redirectToRoute('dashboard_inicial');
  1997.         }
  1998.     }
  1999.     /**
  2000.      * @Route("/dashboard/temperatura/", name="dashboard_temperatura")
  2001.      * @IsGranted("ROLE_USER")
  2002.      */
  2003.     public function dashboard_temperatura(Request $request): Response
  2004.     {
  2005.         try
  2006.         {
  2007.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_1'null);
  2008.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_2'null);
  2009.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_3'null);
  2010.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_4'null);
  2011.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_5'null);
  2012.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_RESULTADO_DTO_1'null);
  2013.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_RESULTADO_DTO_2'null);
  2014.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_RESULTADO_DTO_3'null);
  2015.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_RESULTADO_DTO_4'null);
  2016.             $this->session->set('SESION_DASHBOARD_TEMPERATURA_RESULTADO_DTO_5'null);
  2017.             //return $this->redirectToRoute('dashboard_temperatura_buscar');
  2018.             return $this->render('dashboard/temperatura_opciones.html.twig');
  2019.         } 
  2020.         catch(\Exception $e){
  2021.             $this->logger->error($e->getMessage(), [
  2022.                 'exception' => $e,
  2023.                 'trace'  => $e->getTraceAsString(), 
  2024.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  2025.                 'method' => $request->getMethod(), // GET, POST, etc.
  2026.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  2027.                 'params' => $request->request->all()
  2028.             ]);
  2029.             $this->addFlash('danger',$e->getMessage());
  2030.             return $this->redirectToRoute('dashboard_inicial');
  2031.         }
  2032.     }
  2033.     /**
  2034.      * @Route("/dashboard/temperatura/distribucion/dedicada/", name="dashboard_temperatura_distribucion_dedicada")
  2035.      * @IsGranted("ROLE_USER")
  2036.      */
  2037.     public function dashboard_temperatura_distribucion_dedicada(Request $request): Response
  2038.     {
  2039.         try
  2040.         {
  2041.             $dto4 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_4');
  2042.             if(!$dto4)
  2043.             {
  2044.                 $dto4 = new DashboardTemperaturaDto();
  2045.                 $dto4->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2046.                 $dto4->fechaHasta = (new \DateTime('now'));
  2047.             }
  2048.             else
  2049.             {
  2050.                 if($dto4->vehiculo)
  2051.                 {
  2052.                     $dto4->vehiculo $this->entityManager->merge($dto4->vehiculo); 
  2053.                 }
  2054.             }
  2055.             $form4 $this->createForm(DashboardTemperaturaFormType::class, $dto4, array('id_tramo' => 4));
  2056.             $form4->handleRequest($request);
  2057.             if ($form4->isSubmitted() && $form4->isValid()) 
  2058.             {
  2059.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_4'$dto4);
  2060.             }
  2061.             $resultado4 $this->getTemperaturaResultado_v2($dto4);
  2062.  
  2063.             return $this->render('dashboard/temperatura_distribucion_dedicada.html.twig', array(
  2064.                 'form4' => $form4->createView(),
  2065.                 'dto4' => $dto4,
  2066.                 'resultado4' => $resultado4,
  2067.             ));
  2068.         } 
  2069.         catch(\Exception $e){
  2070.             $this->logger->error($e->getMessage(), [
  2071.                 'exception' => $e,
  2072.                 'trace'  => $e->getTraceAsString(), 
  2073.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  2074.                 'method' => $request->getMethod(), // GET, POST, etc.
  2075.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  2076.                 'params' => $request->request->all()
  2077.             ]);
  2078.             $this->addFlash('danger',$e->getMessage());
  2079.             return $this->redirectToRoute('dashboard_temperatura');
  2080.         }
  2081.     }
  2082.     /**
  2083.      * @Route("/dashboard/temperatura/distribucion/courier/", name="dashboard_temperatura_distribucion_courier")
  2084.      * @IsGranted("ROLE_USER")
  2085.      */
  2086.     public function dashboard_temperatura_distribucion_courier(Request $request): Response
  2087.     {
  2088.         try
  2089.         {
  2090.             $dto1 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_1');
  2091.             if(!$dto1)
  2092.             {
  2093.                 $dto1 = new DashboardTemperaturaDto();
  2094.                 $dto1->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2095.                 $dto1->fechaHasta = (new \DateTime('now'));
  2096.             }
  2097.             else
  2098.             {
  2099.                 if($dto1->vehiculo)
  2100.                 {
  2101.                     $dto1->vehiculo $this->entityManager->merge($dto1->vehiculo); 
  2102.                 }
  2103.             }
  2104.             $dto2 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_2');
  2105.             if(!$dto2)
  2106.             {
  2107.                 $dto2 = new DashboardTemperaturaDto();
  2108.                 $dto2->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2109.                 $dto2->fechaHasta = (new \DateTime('now'));
  2110.             }
  2111.             else
  2112.             {
  2113.                 if($dto2->vehiculo)
  2114.                 {
  2115.                     $dto2->vehiculo $this->entityManager->merge($dto2->vehiculo); 
  2116.                 }
  2117.             }
  2118.             $dto3 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_3');
  2119.             if(!$dto3)
  2120.             {
  2121.                 $dto3 = new DashboardTemperaturaDto();
  2122.                 $dto3->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2123.                 $dto3->fechaHasta = (new \DateTime('now'));
  2124.             }
  2125.             else
  2126.             {
  2127.                 if($dto3->vehiculo)
  2128.                 {
  2129.                     $dto3->vehiculo $this->entityManager->merge($dto3->vehiculo); 
  2130.                 }
  2131.             }
  2132.             $dto5 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_5');
  2133.             if(!$dto5)
  2134.             {
  2135.                 $dto5 = new DashboardTemperaturaDto();
  2136.                 $dto5->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2137.                 $dto5->fechaHasta = (new \DateTime('now'));
  2138.             }
  2139.             else
  2140.             {
  2141.                 if($dto5->vehiculo)
  2142.                 {
  2143.                     $dto5->vehiculo $this->entityManager->merge($dto5->vehiculo); 
  2144.                 }
  2145.             }
  2146.             $form1 $this->createForm(DashboardTemperaturaFormType::class, $dto1, array('id_tramo' => 1));
  2147.             $form1->handleRequest($request);
  2148.             if ($form1->isSubmitted() && $form1->isValid()) 
  2149.             {
  2150.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_1'$dto1);
  2151.             }
  2152.             $form2 $this->createForm(DashboardTemperaturaFormType::class, $dto2, array('id_tramo' => 2));
  2153.             $form2->handleRequest($request);
  2154.             if ($form2->isSubmitted() && $form2->isValid()) 
  2155.             {
  2156.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_2'$dto2);
  2157.             }
  2158.             $form3 $this->createForm(DashboardTemperaturaFormType::class, $dto3, array('id_tramo' => 3));
  2159.             $form3->handleRequest($request);
  2160.             if ($form3->isSubmitted() && $form3->isValid()) 
  2161.             {
  2162.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_3'$dto3);
  2163.             }
  2164.             $form5 $this->createForm(DashboardTemperaturaFormType::class, $dto5, array('id_tramo' => 5));
  2165.             $form5->handleRequest($request);
  2166.             if ($form5->isSubmitted() && $form5->isValid()) 
  2167.             {
  2168.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_5'$dto5);
  2169.             }
  2170.             $resultado1 $this->getTemperaturaResultado_v2($dto1);
  2171.             $resultado2 $this->getTemperaturaResultado_v2($dto2);
  2172.             $resultado3 $this->getTemperaturaResultado_v2($dto3);
  2173.             $resultado5 $this->getTemperaturaResultado_v2($dto5);
  2174.  
  2175.             return $this->render('dashboard/temperatura_distribucion_courier.html.twig', array(
  2176.                 'form1' => $form1->createView(),
  2177.                 'form2' => $form2->createView(),
  2178.                 'form3' => $form3->createView(),
  2179.                 'form5' => $form5->createView(),
  2180.                 'dto1' => $dto1,
  2181.                 'dto2' => $dto2,
  2182.                 'dto3' => $dto3,
  2183.                 'dto5' => $dto5,
  2184.                 'resultado1' => $resultado1,
  2185.                 'resultado2' => $resultado2,
  2186.                 'resultado3' => $resultado3,
  2187.                 'resultado5' => $resultado5,
  2188.             ));
  2189.         }
  2190.         catch(\Exception $e){
  2191.             $this->logger->error($e->getMessage(), [
  2192.                 'exception' => $e,
  2193.                 'trace'  => $e->getTraceAsString(), 
  2194.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  2195.                 'method' => $request->getMethod(), // GET, POST, etc.
  2196.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  2197.                 'params' => $request->request->all()
  2198.             ]);
  2199.             $this->addFlash('danger',$e->getMessage());
  2200.             return $this->redirectToRoute('dashboard_temperatura');
  2201.         }
  2202.     }
  2203.     
  2204.     /**
  2205.      * @Route("/dashboard/temperatura/distribucion/excel/{tramo}/", name="dashboard_temperatura_distribucion_excel")
  2206.      * @IsGranted("ROLE_USER")
  2207.      */
  2208.     public function dashboard_temperatura_distribucion_excel(Request $requestint $tramo)
  2209.     {
  2210.         try
  2211.         {
  2212.             $ahora = new \DateTime('now');
  2213.             $sesion '';
  2214.             if($tramo == 1)
  2215.                 $sesion 'SESION_DASHBOARD_TEMPERATURA_DTO_1';
  2216.             elseif($tramo == 2)
  2217.                 $sesion 'SESION_DASHBOARD_TEMPERATURA_DTO_2';
  2218.             elseif($tramo == 3)
  2219.                 $sesion 'SESION_DASHBOARD_TEMPERATURA_DTO_3';
  2220.             elseif($tramo == 4)
  2221.                 $sesion 'SESION_DASHBOARD_TEMPERATURA_DTO_4';
  2222.             $dto $this->session->get($sesion);
  2223.             if(!$dto)
  2224.             {
  2225.                 $dto = new DashboardTemperaturaDto();
  2226.                 $dto->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2227.                 $dto->fechaHasta = (new \DateTime('now'));
  2228.             }
  2229.             else
  2230.             {
  2231.                 if($dto->vehiculo)
  2232.                 {
  2233.                     $dto->vehiculo $this->entityManager->merge($dto->vehiculo); 
  2234.                 }
  2235.             }
  2236.  
  2237.             $resultado $this->getTemperaturaResultado_v2($dto);
  2238.             if(!$resultado)
  2239.             {
  2240.                 $this->addFlash("error"'No se encuentra informacion de bitacora');
  2241.                 return $this->redirectToRoute("dashboard_temperatura");
  2242.             }
  2243.             $spreadsheet = new Spreadsheet();
  2244.             /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  2245.             $sheet $spreadsheet->getActiveSheet();
  2246.             $sheet->setShowGridlines(false);
  2247.             $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
  2248.             $drawing->setName('logo');
  2249.             $drawing->setDescription('logo');
  2250.             $drawing->setPath('media/logo_transfarma_verde.png'); // put your path and image here
  2251.             $drawing->setCoordinates('A1');
  2252.             $drawing->setWorksheet($sheet);
  2253.             $sheet->setCellValue('A6''BITACORA');
  2254.             $sheet->getStyle('A6')->getFont()->setBoldtrue );
  2255.             $sheet->setCellValue('A7'$ahora->format('d-m-Y H:i'));
  2256.             $sheet->mergeCells("A6:E6"); 
  2257.             $sheet->mergeCells("A7:D7"); 
  2258.                                                     
  2259.             $sheet->setCellValue('A9''Latitud');
  2260.             $sheet->setCellValue('B9''Longuitud');
  2261.             $sheet->setCellValue('C9''Timestamp');
  2262.             $sheet->setCellValue('D9''Temperatura');
  2263.             $sheet->setCellValue('E9''Humedad');
  2264.             
  2265.             $fila 9;
  2266.             foreach($resultado["lista"] as $item)
  2267.             {
  2268.                 $fila++;
  2269.             
  2270.                 $sheet->setCellValue('A'.$fila$item->getLatitud());
  2271.                 $sheet->setCellValue('B'.$fila$item->getLonguitud());
  2272.                 $sheet->setCellValue('C'.$fila$item->getTimestamp() ? $item->getTimestamp()->format('d-m-Y H:i:s') : '');
  2273.                 $sheet->setCellValue('D'.$fila$item->getTemp1());
  2274.                 $sheet->setCellValue('E'.$fila$item->getHum1());
  2275.             }
  2276.             //$sheet->setAutoFilter($sheet->calculateWorksheetDimension());
  2277.             $sheet->getColumnDimension('A')->setAutoSize(true);
  2278.             $sheet->getColumnDimension('B')->setAutoSize(true);
  2279.             $sheet->getColumnDimension('C')->setAutoSize(true);
  2280.             $sheet->getColumnDimension('D')->setAutoSize(true);
  2281.             $sheet->getColumnDimension('E')->setAutoSize(true);
  2282.             
  2283.             $sheet->getStyle('A9:E9')->getFont()->setBoldtrue );
  2284.             $sheet->getStyle('A9:E9')->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
  2285.             $sheet->getStyle('A9:E9')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('FF426384');
  2286.             $sheet->getStyle('A9:E'.$fila)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP);
  2287.             // Create your Office 2007 Excel (XLSX Format)
  2288.             $writer = new Xlsx($spreadsheet);
  2289.             
  2290.             // Create a Temporary file in the system
  2291.             $fileName 'BITACORA-'.($ahora->format('Ymd-Hi')).'.xlsx';
  2292.             $temp_file tempnam($this->getParameter('kernel.project_dir').'/temp/'$fileName);
  2293.             
  2294.             // Create the excel file in the tmp directory of the system
  2295.             $writer->save($temp_file);
  2296.             
  2297.             // Return the excel file as an attachment
  2298.             return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);  
  2299.         } 
  2300.         catch(\Exception $e){
  2301.             $this->logger->error($e->getMessage(), [
  2302.                 'exception' => $e,
  2303.                 'trace'  => $e->getTraceAsString(), 
  2304.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  2305.                 'method' => $request->getMethod(), // GET, POST, etc.
  2306.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  2307.                 'params' => $request->request->all()
  2308.             ]);
  2309.             $this->addFlash('danger',$e->getMessage());
  2310.             return $this->redirectToRoute('dashboard_temperatura');
  2311.         }
  2312.     }
  2313.     /**
  2314.      * @Route("/dashboard/temperatura/buscar/", name="dashboard_temperatura_buscar")
  2315.      * @IsGranted("ROLE_USER")
  2316.      */
  2317.     public function dashboard_temperatura_buscar(Request $request): Response
  2318.     {
  2319.         try
  2320.         {
  2321.             $dto1 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_1');
  2322.             if(!$dto1)
  2323.             {
  2324.                 $dto1 = new DashboardTemperaturaDto();
  2325.                 $dto1->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2326.                 $dto1->fechaHasta = (new \DateTime('now'));
  2327.             }
  2328.             else
  2329.             {
  2330.                 if($dto1->vehiculo)
  2331.                 {
  2332.                     $dto1->vehiculo $this->entityManager->merge($dto1->vehiculo); 
  2333.                 }
  2334.             }
  2335.             $dto2 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_2');
  2336.             if(!$dto2)
  2337.             {
  2338.                 $dto2 = new DashboardTemperaturaDto();
  2339.                 $dto2->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2340.                 $dto2->fechaHasta = (new \DateTime('now'));
  2341.             }
  2342.             else
  2343.             {
  2344.                 if($dto2->vehiculo)
  2345.                 {
  2346.                     $dto2->vehiculo $this->entityManager->merge($dto2->vehiculo); 
  2347.                 }
  2348.             }
  2349.             $dto3 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_3');
  2350.             if(!$dto3)
  2351.             {
  2352.                 $dto3 = new DashboardTemperaturaDto();
  2353.                 $dto3->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2354.                 $dto3->fechaHasta = (new \DateTime('now'));
  2355.             }
  2356.             else
  2357.             {
  2358.                 if($dto3->vehiculo)
  2359.                 {
  2360.                     $dto3->vehiculo $this->entityManager->merge($dto3->vehiculo); 
  2361.                 }
  2362.             }
  2363.             $dto4 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_4');
  2364.             if(!$dto4)
  2365.             {
  2366.                 $dto4 = new DashboardTemperaturaDto();
  2367.                 $dto4->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2368.                 $dto4->fechaHasta = (new \DateTime('now'));
  2369.             }
  2370.             else
  2371.             {
  2372.                 if($dto4->vehiculo)
  2373.                 {
  2374.                     $dto4->vehiculo $this->entityManager->merge($dto4->vehiculo); 
  2375.                 }
  2376.             }
  2377.             $dto5 $this->session->get('SESION_DASHBOARD_TEMPERATURA_DTO_5');
  2378.             if(!$dto5)
  2379.             {
  2380.                 $dto5 = new DashboardTemperaturaDto();
  2381.                 $dto5->fechaDesde = (new \DateTime('today'))->modify('-7 day');
  2382.                 $dto5->fechaHasta = (new \DateTime('now'));
  2383.             }
  2384.             else
  2385.             {
  2386.                 if($dto5->vehiculo)
  2387.                 {
  2388.                     $dto5->vehiculo $this->entityManager->merge($dto5->vehiculo); 
  2389.                 }
  2390.             }
  2391.             $form1 $this->createForm(DashboardTemperaturaFormType::class, $dto1, array('id_tramo' => 1));
  2392.             $form1->handleRequest($request);
  2393.             if ($form1->isSubmitted() && $form1->isValid()) 
  2394.             {
  2395.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_1'$dto1);
  2396.             }
  2397.             $form2 $this->createForm(DashboardTemperaturaFormType::class, $dto2, array('id_tramo' => 2));
  2398.             $form2->handleRequest($request);
  2399.             if ($form2->isSubmitted() && $form2->isValid()) 
  2400.             {
  2401.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_2'$dto2);
  2402.             }
  2403.             $form3 $this->createForm(DashboardTemperaturaFormType::class, $dto3, array('id_tramo' => 3));
  2404.             $form3->handleRequest($request);
  2405.             if ($form3->isSubmitted() && $form3->isValid()) 
  2406.             {
  2407.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_3'$dto3);
  2408.             }
  2409.             $form4 $this->createForm(DashboardTemperaturaFormType::class, $dto4, array('id_tramo' => 4));
  2410.             $form4->handleRequest($request);
  2411.             if ($form4->isSubmitted() && $form4->isValid()) 
  2412.             {
  2413.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_4'$dto4);
  2414.             }
  2415.             $form5 $this->createForm(DashboardTemperaturaFormType::class, $dto5, array('id_tramo' => 5));
  2416.             $form5->handleRequest($request);
  2417.             if ($form5->isSubmitted() && $form5->isValid()) 
  2418.             {
  2419.                 $this->session->set('SESION_DASHBOARD_TEMPERATURA_DTO_5'$dto5);
  2420.             }
  2421.             $resultado1 $this->getTemperaturaResultado_v2($dto1);
  2422.             $resultado2 $this->getTemperaturaResultado_v2($dto2);
  2423.             $resultado3 $this->getTemperaturaResultado_v2($dto3);
  2424.             $resultado4 $this->getTemperaturaResultado_v2($dto4);
  2425.             $resultado5 $this->getTemperaturaResultado_v2($dto5);
  2426.             $resultado_general = array();
  2427.             $grafico_minimo_general 0;
  2428.             $grafico_maximo_general 25;
  2429.             if($resultado1->lista_grafico)
  2430.             {
  2431.                 if($grafico_minimo_general $resultado1->grafico_minimo)
  2432.                 {
  2433.                     $grafico_minimo_general $resultado1->grafico_minimo;
  2434.                 }
  2435.                 if($grafico_maximo_general $resultado1->grafico_maximo)
  2436.                 {
  2437.                     $grafico_maximo_general $resultado1->grafico_maximo;
  2438.                 }
  2439.                 foreach($resultado1->lista_grafico as $item_temperatura)
  2440.                 {
  2441.                     if (isset($resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')])) 
  2442.                     {
  2443.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')]->tramo1 $item_temperatura->getTemp1();
  2444.                     }
  2445.                     else
  2446.                     {
  2447.                         $dto = new DTOTemperaturaGeneral();
  2448.                         $dto->fecha $item_temperatura->getTimestamp();
  2449.                         $dto->tramo1 $item_temperatura->getTemp1();
  2450.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')] = $dto;
  2451.                     }
  2452.                 }
  2453.             }
  2454.             if($resultado2->lista)
  2455.             {
  2456.                 if($grafico_minimo_general $resultado2->grafico_minimo)
  2457.                 {
  2458.                     $grafico_minimo_general $resultado2->grafico_minimo;
  2459.                 }
  2460.                 if($grafico_maximo_general $resultado2->grafico_maximo)
  2461.                 {
  2462.                     $grafico_maximo_general $resultado2->grafico_maximo;
  2463.                 }
  2464.                 foreach($resultado2->lista_grafico as $item_temperatura)
  2465.                 {
  2466.                     if (isset($resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')])) 
  2467.                     {
  2468.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')]->tramo2 $item_temperatura->getTemp1();
  2469.                     }
  2470.                     else
  2471.                     {
  2472.                         $dto = new DTOTemperaturaGeneral();
  2473.                         $dto->fecha $item_temperatura->getTimestamp();
  2474.                         $dto->tramo2 $item_temperatura->getTemp1();
  2475.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')] = $dto;
  2476.                     }
  2477.                 }
  2478.             }                
  2479.             if($resultado3->lista)
  2480.             {
  2481.                 if($grafico_minimo_general $resultado3->grafico_minimo)
  2482.                 {
  2483.                     $grafico_minimo_general $resultado3->grafico_minimo;
  2484.                 }
  2485.                 if($grafico_maximo_general $resultado3->grafico_maximo)
  2486.                 {
  2487.                     $grafico_maximo_general $resultado3->grafico_maximo;
  2488.                 }
  2489.                 foreach($resultado3->lista_grafico as $item_temperatura)
  2490.                 {
  2491.                     if (isset($resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')])) 
  2492.                     {
  2493.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')]->tramo3 $item_temperatura->getTemp1();
  2494.                     }
  2495.                     else
  2496.                     {
  2497.                         $dto = new DTOTemperaturaGeneral();
  2498.                         $dto->fecha $item_temperatura->getTimestamp();
  2499.                         $dto->tramo3 $item_temperatura->getTemp1();
  2500.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')] = $dto;
  2501.                     }
  2502.                 }
  2503.             }
  2504.             if($resultado4->lista_grafico)
  2505.             {
  2506.                 if($grafico_minimo_general $resultado4->grafico_minimo)
  2507.                 {
  2508.                     $grafico_minimo_general $resultado4->grafico_minimo;
  2509.                 }
  2510.                 if($grafico_maximo_general $resultado4->grafico_maximo)
  2511.                 {
  2512.                     $grafico_maximo_general $resultado4->grafico_maximo;
  2513.                 }
  2514.                 foreach($resultado4->lista_grafico as $item_temperatura)
  2515.                 {
  2516.                     if (isset($resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')])) 
  2517.                     {
  2518.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')]->tramo1 $item_temperatura->getTemp1();
  2519.                     }
  2520.                     else
  2521.                     {
  2522.                         $dto = new DTOTemperaturaGeneral();
  2523.                         $dto->fecha $item_temperatura->getTimestamp();
  2524.                         $dto->tramo4 $item_temperatura->getTemp1();
  2525.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')] = $dto;
  2526.                     }
  2527.                 }
  2528.             }
  2529.             if($resultado5->lista_grafico)
  2530.             {
  2531.                 if($grafico_minimo_general $resultado5->grafico_minimo)
  2532.                 {
  2533.                     $grafico_minimo_general $resultado5->grafico_minimo;
  2534.                 }
  2535.                 if($grafico_maximo_general $resultado5->grafico_maximo)
  2536.                 {
  2537.                     $grafico_maximo_general $resultado5->grafico_maximo;
  2538.                 }
  2539.                 foreach($resultado5->lista_grafico as $item_temperatura)
  2540.                 {
  2541.                     if (isset($resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')])) 
  2542.                     {
  2543.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')]->tramo1 $item_temperatura->getTemp1();
  2544.                     }
  2545.                     else
  2546.                     {
  2547.                         $dto = new DTOTemperaturaGeneral();
  2548.                         $dto->fecha $item_temperatura->getTimestamp();
  2549.                         $dto->tramo5 $item_temperatura->getTemp1();
  2550.                         $resultado_general[$item_temperatura->getTimestamp()->format('Y-m-d H:i:s')] = $dto;
  2551.                     }
  2552.                 }
  2553.             }
  2554.             ksort($resultado_general);
  2555.             return $this->render('dashboard/temperatura_buscar.html.twig', array(
  2556.                 'form1' => $form1->createView(),
  2557.                 'form2' => $form2->createView(),
  2558.                 'form3' => $form3->createView(),
  2559.                 'form4' => $form4->createView(),
  2560.                 'form5' => $form5->createView(),
  2561.                 'dto1' => $dto1,
  2562.                 'dto2' => $dto2,
  2563.                 'dto3' => $dto3,
  2564.                 'dto4' => $dto4,
  2565.                 'dto5' => $dto5,
  2566.                 'resultado1' => $resultado1,
  2567.                 'resultado2' => $resultado2,
  2568.                 'resultado3' => $resultado3,
  2569.                 'resultado4' => $resultado4,
  2570.                 'resultado5' => $resultado5,
  2571.                 'resultado_general' => $resultado_general,
  2572.                 'grafico_minimo_general' => $grafico_minimo_general,
  2573.                 'grafico_maximo_general' => $grafico_maximo_general,
  2574.             ));
  2575.         }
  2576.         catch(\Exception $e){
  2577.             $this->logger->error($e->getMessage(), [
  2578.                 'exception' => $e,
  2579.                 'trace'  => $e->getTraceAsString(), 
  2580.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  2581.                 'method' => $request->getMethod(), // GET, POST, etc.
  2582.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  2583.                 'params' => $request->request->all()
  2584.             ]);
  2585.             $this->addFlash('danger',$e->getMessage());
  2586.             return $this->redirectToRoute('dashboard_temperatura');
  2587.         }
  2588.     }
  2589.     function getTemperaturaResultado_v1(DashboardTemperaturaDto $dto)
  2590.     {
  2591.         $tipo_carga_id 1//Refrigerado
  2592.         $dispositivo null;
  2593.         $fecha_inicio null;
  2594.         $fecha_fin null;
  2595.         $numero_puntos_medidos 0;
  2596.         $limite_inferior null;
  2597.         $limite_superior null;
  2598.         $temperatura_maxima null;
  2599.         $temperatura_minima null;
  2600.         $temperatura_suma 0;
  2601.         $temperatura_promedio null;
  2602.         $desviacion_estandar null;
  2603.         $tiempo_sobre_limite 0;
  2604.         $tiempo_bajo_limite 0;
  2605.         $grafico_minimo 0;
  2606.         $grafico_maximo 25;
  2607.         $tiempo_sobre_limite_h 0;
  2608.         $tiempo_sobre_limite_m 0;
  2609.         $tiempo_sobre_limite_s 0;
  2610.         $tiempo_bajo_limite_h 0;
  2611.         $tiempo_bajo_limite_m 0;
  2612.         $tiempo_bajo_limite_s 0;
  2613.         $lista $this->bitacoraTemperaturaRepository->findByDashboardTemperaturaDto($dto);
  2614.         $rango_operacion $this->tipoCargaRepository->findOneById($tipo_carga_id);
  2615.         $vehiculo $this->vehiculoRepository->findOneById($dto->vehiculo);
  2616.         if($vehiculo)
  2617.         {
  2618.             $dispositivo $vehiculo->getDispositivo();
  2619.         }
  2620.         $resultado = new DashboardTemperaturaResultadoDto();
  2621.         if($rango_operacion)
  2622.         {
  2623.             $limite_inferior $rango_operacion->getMinimo();
  2624.             $limite_superior $rango_operacion->getMaximo();
  2625.             $grafico_minimo 0// $rango_operacion->getMinimo();
  2626.             $grafico_maximo 25//$rango_operacion->getMaximo();
  2627.         }
  2628.         $time_anterior null;
  2629.         foreach($lista as $item)
  2630.         {
  2631.             $temperatura_actual $item->getTemp1();
  2632.             $time_actual $item->getTimestamp();
  2633.             if($temperatura_actual)
  2634.             {
  2635.                 if($fecha_inicio == null)
  2636.                 {
  2637.                     $fecha_inicio $time_actual;
  2638.                 }
  2639.                 $fecha_fin $time_actual;
  2640.                 $numero_puntos_medidos++;
  2641.                 $temperatura_suma $temperatura_suma $temperatura_actual;
  2642.                 if((!$temperatura_maxima) or ($temperatura_maxima $temperatura_actual))
  2643.                 {
  2644.                     $temperatura_maxima $temperatura_actual;
  2645.                 }
  2646.                 if((!$temperatura_minima) or ($temperatura_minima $temperatura_actual))
  2647.                 {
  2648.                     $temperatura_minima $temperatura_actual;
  2649.                 }
  2650.                 if(($limite_inferior) and ($temperatura_actual $limite_inferior))
  2651.                 {
  2652.                     if($time_anterior)
  2653.                     {
  2654.                         $diff $time_actual->diff($time_anterior);
  2655.                         $segundos $diff->days 24 60 60;
  2656.                         $segundos += $diff->60 60;
  2657.                         $segundos += $diff->60;
  2658.                         $segundos += $diff->s;
  2659.                         $tiempo_bajo_limite $tiempo_bajo_limite $segundos;
  2660.                     }
  2661.                 }
  2662.                 if(($limite_superior) and ($temperatura_actual $limite_superior))
  2663.                 {
  2664.                     if($time_anterior)
  2665.                     {
  2666.                         $diff $time_actual->diff($time_anterior);
  2667.                         $segundos $diff->days 24 60 60;
  2668.                         $segundos += $diff->60 60;
  2669.                         $segundos += $diff->60;
  2670.                         $segundos += $diff->s;
  2671.                         $tiempo_sobre_limite $tiempo_sobre_limite $segundos;
  2672.                     }
  2673.                 }
  2674.                 $time_anterior $time_actual;
  2675.             }
  2676.         }
  2677.         if($numero_puntos_medidos 0)
  2678.         {
  2679.             $temperatura_promedio $temperatura_suma $numero_puntos_medidos;
  2680.             // calculo de desviacion estandar
  2681.             $ans=0;
  2682.             foreach($lista as $item)
  2683.             {
  2684.                 if($item->getTemp1())
  2685.                 {
  2686.                     $ans+=pow(($item->getTemp1()-$temperatura_promedio),2);
  2687.                 }
  2688.             }
  2689.             $desviacion_estandar sqrt($ans/$numero_puntos_medidos);
  2690.         }
  2691.         if($grafico_minimo $temperatura_minima)
  2692.         {
  2693.             $grafico_minimo $temperatura_minima;
  2694.         }
  2695.         if($grafico_maximo $temperatura_maxima)
  2696.         {
  2697.             $grafico_maximo $temperatura_maxima;
  2698.         }
  2699.         if($grafico_minimo 0)
  2700.         {
  2701.             $grafico_minimo 0;
  2702.         }
  2703.         if($tiempo_sobre_limite)
  2704.         {
  2705.             $tiempo_sobre_limite_h floor($tiempo_sobre_limite 3600);
  2706.             $tiempo_sobre_limite_m floor(($tiempo_sobre_limite - ($tiempo_sobre_limite_h 3600)) / 60);
  2707.             $tiempo_sobre_limite_s = ($tiempo_sobre_limite 60);
  2708.         }
  2709.         if($tiempo_bajo_limite)
  2710.         {
  2711.             $tiempo_bajo_limite_h floor($tiempo_bajo_limite 3600);
  2712.             $tiempo_bajo_limite_m floor(($tiempo_bajo_limite - ($tiempo_bajo_limite_h 3600)) / 60);
  2713.             $tiempo_bajo_limite_s = ($tiempo_sobre_limite 60);
  2714.         }
  2715.        
  2716.         $cantidad_referencia 30;
  2717.         $total_datos count($lista);
  2718.         $intervalo max(1floor($total_datos $cantidad_referencia));
  2719.         $lista_grafico = new ArrayCollection();
  2720.         $contador_intervalo 0;
  2721.         $anterior_minimo 0;
  2722.         $anterior_maximo 0;
  2723.         foreach($lista as $item)
  2724.         {
  2725.             $contador_intervalo++;
  2726.             if($anterior_minimo == 0)
  2727.             {
  2728.                 if($item->getTemp1() == $temperatura_minima)
  2729.                 {
  2730.                     $contador_intervalo $intervalo;
  2731.                     $anterior_minimo 1;
  2732.                 }
  2733.             }
  2734.             else
  2735.             {
  2736.                 if($item->getTemp1() != $temperatura_minima)
  2737.                 {
  2738.                     $anterior_minimo 0;
  2739.                 }
  2740.             }
  2741.             if($anterior_maximo == 0)
  2742.             {
  2743.                 if($item->getTemp1() == $temperatura_maxima)
  2744.                 {
  2745.                     $contador_intervalo $intervalo;
  2746.                     $anterior_maximo 1;
  2747.                 }
  2748.             }
  2749.             else
  2750.             {
  2751.                 if($item->getTemp1() != $temperatura_maxima)
  2752.                 {
  2753.                     $anterior_maximo 0;
  2754.                 }
  2755.             }
  2756.             if($contador_intervalo >= $intervalo)
  2757.             {
  2758.                 $lista_grafico[] = $item;
  2759.                 $contador_intervalo 0;
  2760.             }
  2761.         }
  2762.         
  2763.         $resultado = new DashboardTemperaturaResultadoDto();
  2764.         $resultado->lista $lista;
  2765.         $resultado->lista_grafico $lista_grafico;
  2766.         $resultado->rango_operacion $rango_operacion;
  2767.         $resultado->vehiculo $vehiculo;
  2768.         $resultado->dispositivo $dispositivo;
  2769.         $resultado->fecha_inicio $fecha_inicio;
  2770.         $resultado->fecha_fin $fecha_fin;
  2771.         $resultado->numero_puntos_medidos $numero_puntos_medidos;
  2772.         $resultado->limite_inferior $limite_inferior;
  2773.         $resultado->limite_superior $limite_superior;
  2774.         $resultado->temperatura_maxima $temperatura_maxima;
  2775.         $resultado->temperatura_minima $temperatura_minima;
  2776.         $resultado->temperatura_promedio $temperatura_promedio;
  2777.         $resultado->desviacion_estandar $desviacion_estandar;
  2778.         $resultado->tiempo_sobre_limite_h $tiempo_sobre_limite_h;
  2779.         $resultado->tiempo_sobre_limite_m $tiempo_sobre_limite_m;
  2780.         $resultado->tiempo_sobre_limite_s $tiempo_sobre_limite_s;
  2781.         $resultado->tiempo_bajo_limite_h $tiempo_bajo_limite_h;
  2782.         $resultado->tiempo_bajo_limite_m $tiempo_bajo_limite_m;
  2783.         $resultado->tiempo_bajo_limite_s $tiempo_bajo_limite_s;
  2784.         $resultado->grafico_minimo $grafico_minimo;
  2785.         $resultado->grafico_maximo $grafico_maximo;
  2786.         $resultado->intervalo $intervalo;
  2787.         return $resultado;
  2788.     }
  2789.     function getTemperaturaResultado_v2(DashboardTemperaturaDto $dto)
  2790.     {
  2791.         $rango_operacion null;
  2792.         $lista $this->bitacoraTemperaturaRepository->findByDashboardTemperaturaDto($dto);
  2793.         $vehiculo $dto->vehiculo;
  2794.         if($vehiculo)
  2795.         {
  2796.             $rango_operacion $vehiculo->getRango();
  2797.         }
  2798.      
  2799.         $contador 0;
  2800.         $min 0;
  2801.         $max 20;
  2802.         if($rango_operacion)
  2803.         {
  2804.             $max $rango_operacion->getHasta();
  2805.         }
  2806.       
  2807.         $primer_punto null;
  2808.         $ultimo_punto null;
  2809.         foreach($lista as $item_detalle)
  2810.         {
  2811.             $contador++;
  2812.             if(!$primer_punto)
  2813.             {
  2814.                 $primer_punto $item_detalle->getTimestamp();
  2815.             }
  2816.             elseif($primer_punto $item_detalle->getTimestamp())
  2817.             {
  2818.                 $primer_punto $item_detalle->getTimestamp();
  2819.             }
  2820.             if(!$ultimo_punto)
  2821.             {
  2822.                 $ultimo_punto $item_detalle->getTimestamp();
  2823.             }
  2824.             elseif($ultimo_punto $item_detalle->getTimestamp())
  2825.             {
  2826.                 $ultimo_punto $item_detalle->getTimestamp();
  2827.             }
  2828.             if($item_detalle->getTemp1() < $min)
  2829.             {
  2830.                 $min $item_detalle->getTemp1();
  2831.             }
  2832.             if($item_detalle->getTemp1() > $max)
  2833.             {
  2834.                 $max $item_detalle->getTemp1();
  2835.             }
  2836.         }
  2837.         $max round($max 20PHP_ROUND_HALF_UP);
  2838.         return array(
  2839.             'lista' => $lista,
  2840.             'contador' => $contador,
  2841.             'min' => $min,
  2842.             'max' => $max,
  2843.             'primer_punto' => $primer_punto,
  2844.             'ultimo_punto' => $ultimo_punto,
  2845.             'vehiculo' => $vehiculo,
  2846.             'rango' => $rango_operacion
  2847.         );
  2848.     }
  2849.     function distanceCalculation($point1_lat$point1_long$point2_lat$point2_long$unit 'km'$decimals 2
  2850.     {
  2851.         // Cálculo de la distancia en grados
  2852.         $degrees rad2deg(acos((sin(deg2rad($point1_lat))*sin(deg2rad($point2_lat))) + (cos(deg2rad($point1_lat))*cos(deg2rad($point2_lat))*cos(deg2rad($point1_long-$point2_long)))));
  2853.     
  2854.         // Conversión de la distancia en grados a la unidad escogida (kilómetros, millas o millas naúticas)
  2855.         switch($unit) {
  2856.             case 'km':
  2857.                 $distance $degrees 111.13384// 1 grado = 111.13384 km, basándose en el diametro promedio de la Tierra (12.735 km)
  2858.                 break;
  2859.             case 'mi':
  2860.                 $distance $degrees 69.05482// 1 grado = 69.05482 millas, basándose en el diametro promedio de la Tierra (7.913,1 millas)
  2861.                 break;
  2862.             case 'nmi':
  2863.                 $distance =  $degrees 59.97662// 1 grado = 59.97662 millas naúticas, basándose en el diametro promedio de la Tierra (6,876.3 millas naúticas)
  2864.         }
  2865.         return round($distance$decimals);
  2866.     }
  2867.     /**
  2868.      * @Route("/dashboard/localizacion/", name="dashboard_localizacion")
  2869.      * @IsGranted("ROLE_USER")
  2870.      */
  2871.     public function dashboard_localizacion(Request $request): Response
  2872.     {
  2873.         try
  2874.         {
  2875.             $dto = new DashboardLocalizacionDto();
  2876.        
  2877.             $lista null;
  2878.        
  2879.             $form $this->createForm(DashboardLocalizacionFormType::class, $dto);
  2880.             $form->handleRequest($request);
  2881.             if ($form->isSubmitted() && $form->isValid()) 
  2882.             {
  2883.                 $lista $this->vehiculoRepository->getLocalizacion($dto->vehiculo);
  2884.                 
  2885.             }
  2886.             
  2887.             return $this->render('dashboard/localizacion2.html.twig', array(
  2888.                 'form' => $form->createView(),
  2889.                 'lista' => $lista,
  2890.             ));
  2891.         } 
  2892.         catch(\Exception $e){
  2893.             $this->logger->error($e->getMessage(), [
  2894.                 'exception' => $e,
  2895.                 'trace'  => $e->getTraceAsString(), 
  2896.                 'url' => $request->getUri(), // Devuelve la URL completa: https://tu-dominio.com/ruta?param=1
  2897.                 'method' => $request->getMethod(), // GET, POST, etc.
  2898.                 'user' => $this->getUser() ? $this->getUser()->getUsername() : '',
  2899.                 'params' => $request->request->all()
  2900.             ]);
  2901.             $this->addFlash('danger',$e->getMessage());
  2902.             return $this->redirectToRoute('app_admin_index');
  2903.         }
  2904.     }
  2905. }