src/Controller/IncidenciaController.php line 271

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Incidencia;
  4. use App\Entity\Periodo;
  5. use App\Entity\Usuario;
  6. use App\Form\IncidenciaFiltroType;
  7. use App\Form\IncidenciaType;
  8. use App\Form\ReporteType;
  9. use App\Service\DocumentoPDF;
  10. use Box\Spout\Common\Exception\InvalidArgumentException;
  11. use Box\Spout\Common\Exception\IOException;
  12. use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
  13. use Box\Spout\Writer\Exception\WriterNotOpenedException;
  14. use DateInterval;
  15. use DateTime;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\Filesystem\Filesystem;
  19. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use TCPDF;
  26. //#[Route('/incidencia')]
  27. /**
  28.  * @Route("/incidencia")
  29.  */
  30. class IncidenciaController extends AbstractController
  31. {
  32.     public EntityManagerInterface $emi;
  33.     public function __construct(EntityManagerInterface $entityManager)
  34.     {
  35.         $this->emi $entityManager;
  36.     }
  37.     //#[Route('/', name: 'app_incidencia_index', methods: ['GET'])]
  38.     /**
  39.      * @Route("/", name= "app_incidencia_index", methods= {"GET", "POST"})
  40.      * @param Request $request
  41.      * @return Response
  42.      */
  43.     public function index(Request $request): Response
  44.     {
  45.         $perfil $request->getSession()->get('perfilLecciones');
  46.         $nivel $perfil[1]["nivel"];
  47.         if ($nivel == 0) {
  48.             $this->addFlash('danger''El acceso al módulo de "Lecciones" está restringido.');
  49.             return $this->redirectToRoute('homepage');
  50.         }
  51.         /** @var Usuario $user */
  52.         $user $this->getUser();
  53.         $incidencias "";
  54.         $perSession $request->getSession()->get('periodoLecciones');
  55.         $perSession $this->emi->getRepository(Periodo::class)->findOneBy(['idPrd' => $perSession->getIdPrd()]);
  56.         # Formulario de filtro de lecciones aprendidas
  57.         ($nivel == 2) ? $uni true $uni false;
  58.         $form $this->createForm(IncidenciaFiltroType::class, null, ['uni' => $uni'periodo' => $perSession]);
  59.         $form->handleRequest($request);
  60.         $periodo $form['periodo']->getData();
  61.         $tema $form['tema']->getData();
  62.         $unidad = (isset($form['unidad'])) ? $form['unidad']->getData() : $user->getUnidad();
  63.         if ($request->isMethod('POST')) {
  64.             $incidencias $this->emi->getRepository(Incidencia::class)->filtroLecciones($periodo$unidad$tema);
  65.             $data = [];
  66.             $estatus "";
  67.             $estatusd "";
  68.             foreach ($incidencias as $incidencia) {
  69.                 $ver $this->generateUrl('app_incidencia_show', ['idInc' => $incidencia->getIdInc()]);
  70.                 $editar $this->generateUrl('app_incidencia_edit', ['idInc' => $incidencia->getIdInc()]);
  71.                 if ($incidencia->getAtendidoDir() == 0) {
  72.                     $estatusd '<span class="badge bg-gradient-primary d-block">P</span>';
  73.                 }
  74.                 if ($incidencia->getAtendidoDir() == 1) {
  75.                     $estatusd '<span class="badge bg-gradient-yellow d-block">S</span>';
  76.                 }
  77.                 if ($incidencia->getAtendidoDir() == 2) {
  78.                     $estatusd '<span class="badge bg-gradient-success d-block">A</span>';
  79.                 }
  80.                 if ($incidencia->getAtendido() == 0) {
  81.                     $estatus '<span class="badge bg-gradient-primary d-block">Pendiente</span>';
  82.                 }
  83.                 if ($incidencia->getAtendido() == 1) {
  84.                     $estatus '<span class="badge bg-gradient-yellow d-block">Seguimiento</span>';
  85.                 }
  86.                 if ($incidencia->getAtendido() == 2) {
  87.                     $estatus '<span class="badge bg-gradient-success d-block">Atendido</span>';
  88.                 }
  89.                 $data[] = [
  90.                     'idInc' => $incidencia->getIdInc(),
  91.                     'fecha' => $incidencia->getFcreacion()->format('d-m-Y'),
  92.                     'dataSort' => $incidencia->getFcreacion()->format('Ymd'),
  93.                     'registro' => $incidencia->getIdInc(),
  94.                     'periodo' => $incidencia->getPeriodo()->getDescripcion(),
  95.                     'estatus' => $estatus,
  96.                     'estatusDir' => $estatusd,
  97.                     'atendido' => $incidencia->getAtendido(),
  98.                     'atendidoDir' => $incidencia->getAtendidoDir(),
  99.                     'tema' => $incidencia->getTema()->getSiglas(),
  100.                     'perfil'=> $incidencia->getPerfil(),
  101.                     'descripcion'=> $incidencia->getDescripcion(),
  102.                     'sugerencia'=> $incidencia->getSugerencia(),
  103.                     'unidad'=> $incidencia->getUnidad()->getNombre(),
  104.                     'ver' => $ver,
  105.                     'editar' => $editar
  106.                 ];
  107.             }
  108.             return new JsonResponse($dataResponse::HTTP_OK);
  109.         }
  110.         if ($nivel == 1) {
  111.             $incidencias $this->emi->getRepository(Incidencia::class)->findBy([
  112.                 'unidad' => $user->getUnidad(),
  113.                 'periodo' => $perSession
  114.             ]);
  115.         }
  116.         if ($nivel == 2) {
  117.             $incidencias $this->emi->getRepository(Incidencia::class)->findBy([
  118.                 'periodo' => $perSession
  119.             ]);
  120.         }
  121.         if ($nivel == 3) {
  122.             $incidencias $this->emi->getRepository(Incidencia::class)->findBy([
  123.                 'unidad' => $user->getUnidad(),
  124.                 'periodo' => $perSession
  125.             ]);
  126.         }
  127.         return $this->render('incidencia/index.html.twig', [
  128.             'url' => $this->generateUrl('app_incidencia_index'),
  129.             'incidencias' => $incidencias,
  130.             'nivel' => $nivel,
  131.             'form' => $form->createView()
  132.         ]);
  133.     }
  134.     /**
  135.      * @Route("/reporte", name= "app_incidencia_reporte", methods={"GET", "POST"})
  136.      */
  137.     public function generarReporte(Request $request): Response
  138.     {
  139.         $perfil $request->getSession()->get('perfilLecciones');
  140.         $nivel $perfil[2]["nivel"];
  141.         /** @var Usuario $user */
  142.         $user $this->getUser();
  143.         if ($nivel == 0) {
  144.             $this->addFlash('danger''El acceso al módulo de "Reporte PDF" está restringido.');
  145.             return $this->redirectToRoute('homepage');
  146.         }
  147.         $reporte = new \stdClass();
  148.         $reporte->finicio null;
  149.         $reporte->ftermino null;
  150.         $reporte->unidad $user->getUnidad();
  151.         $form $this->createForm(ReporteType::class, $reporte);
  152.         $form->handleRequest($request);
  153.         if ($form->isSubmitted() && $form->isValid()) {
  154.             $data = [
  155.                 'unidad' => $form->get('unidad')->getData(),
  156.                 'finicio' => $form->get('finicio')->getData(),
  157.                 'ftermino' => $form->get('ftermino')->getData(),
  158.                 'correo' => $user->getCorreo(),
  159.                 'nombre' => $user->getNombre() . " " $user->getPapellido() . " " $user->getSapellido()
  160.             ];
  161.             $this->generarPDFReporteAction($data);
  162.             die();
  163.         }
  164.         if ($form->isSubmitted() && !$form->isValid()){
  165.         }
  166.         return $this->render('incidencia/reporte.html.twig', [
  167.             'form' => $form->createView(),
  168.             'nivel' => $nivel
  169.         ]);
  170.     }
  171.     //#[Route('/new', name: 'app_incidencia_new', methods: ['GET', 'POST'])]
  172.     /**
  173.      * @Route("/new", name="app_incidencia_new", methods={"GET", "POST"})
  174.      */
  175.     public function new(Request $requestEntityManagerInterface $entityManager): Response
  176.     {
  177.         $perfil $request->getSession()->get('perfilLecciones');
  178.         $nivel $perfil[1]["nivel"];
  179.         if ($nivel != 3) {
  180.             $this->addFlash('danger''El acceso a agregar "Incidencias" está restringido.');
  181.             return $this->redirectToRoute('homepage');
  182.         }
  183.         /** @var Usuario $user */
  184.         $user $this->getUser();
  185.         date_default_timezone_set("America/Mexico_City");
  186.         $incidencium = new Incidencia();
  187.         $form $this->createForm(IncidenciaType::class, $incidencium);
  188.         $form->remove('idInc');
  189.         $form->remove('seguimientoDir');
  190.         $form->remove('atendidoDir');
  191.         $form->handleRequest($request);
  192.         if ($form->isSubmitted() && $form->isValid()) {
  193.             #identificador de incidencia
  194.             $year date('Y');
  195.             $p1 substr($year22);
  196.             $unidad $user->getUnidad();
  197.             $p2 substr($unidad->getIdUni(), 33);
  198.             $consecutivo $unidad->getConsecutivo();
  199.             if ($consecutivo <= 999) {
  200.                 $p3 str_pad($consecutivo4"0"STR_PAD_LEFT);
  201.             } else {
  202.                 $p3 '0001';
  203.             }
  204.             $unidad->setConsecutivo($consecutivo 1);
  205.             $ident $p1 $p2 $p3;
  206.             $incidencium->setIdInc($ident);
  207.             #Identificador de periodo
  208.             $periodo $request->getSession()->get('periodoLecciones');
  209.             $periodo $entityManager->getRepository(Periodo::class)->findOneBy(['idPrd' => $periodo->getIdPrd()]);
  210.             $incidencium->setPeriodo($periodo);
  211.             #usuario
  212.             $incidencium->setUsuario($user);
  213.             #unidad
  214.             $incidencium->setUnidad($user->getUnidad());
  215.             #fecha
  216.             $incidencium->setFcreacion(new DateTime());
  217.             $entityManager->persist($incidencium);
  218.             $entityManager->flush();
  219.             $entityManager->persist($unidad);
  220.             $entityManager->flush();
  221.             return $this->redirectToRoute('app_incidencia_index', [], Response::HTTP_SEE_OTHER);
  222.         }
  223.         return $this->renderForm('incidencia/new.html.twig', [
  224.             'incidencium' => $incidencium,
  225.             'form' => $form,
  226.         ]);
  227.     }
  228.     //#[Route('/{idInc}', name: 'app_incidencia_show', methods: ['GET'])]
  229.     /**
  230.      * @Route("/{idInc}", name= "app_incidencia_show", methods= {"GET"})
  231.      */
  232.     public function show(Incidencia $incidencium): Response
  233.     {
  234.         return $this->render('incidencia/show.html.twig', [
  235.             'incidencium' => $incidencium,
  236.         ]);
  237.     }
  238.     //#[Route('/{idInc}/edit', name: 'app_incidencia_edit', methods: ['GET', 'POST'])]
  239.     /**
  240.      * @Route("/{idInc}/edit", name= "app_incidencia_edit", methods= {"GET", "POST"})
  241.      */
  242.     public function edit(Request $requestIncidencia $incidenciumEntityManagerInterface $entityManager): Response
  243.     {
  244.         // Periodo Actual
  245.         $a $request->getSession()->get('periodoLecciones');
  246.         $a $a->getIdPrd();
  247.         // Periodo de la Incidencia
  248.         $b $incidencium->getPeriodo()->getIdPrd();
  249.         $c true;
  250.         $form $this->createForm(IncidenciaType::class, $incidencium);
  251.         $form->handleRequest($request);
  252.         if ($form->isSubmitted() && $form->isValid()) {
  253.             $entityManager->flush();
  254.             if ($incidencium->getAtendido() == 2) {
  255.                 $estatus "Atendido";
  256.             } elseif ($incidencium->getAtendido() == 1) {
  257.                 $estatus "Seguimiento";
  258.             } else {
  259.                 $estatus "Pendiente";
  260.             }
  261.             $data = array(
  262.                 'idInc' => $incidencium->getIdInc(),
  263.                 'fcreacion' => $incidencium->getFcreacion()->format('Y-m-d H:m:s'),
  264.                 'perfil' => $incidencium->getPerfil(),
  265.                 'tema' => $incidencium->getTema()->getSiglas(),
  266.                 'descripcion' => $incidencium->getDescripcion(),
  267.                 'sugerencia' => $incidencium->getSugerencia(),
  268.                 'estatus' => $estatus,
  269.                 'atendido' => $incidencium->getAtendido(),
  270.                 'atendido_dir' => $incidencium->getAtendidoDir(),
  271.                 'seguimiento' => $incidencium->getSeguimiento(),
  272.                 'mensaje' => 'Se actualizo correctamente',
  273.             );
  274.             if ($incidencium->getAtendido() == || $incidencium->getAtendido() == null) {
  275.                 $data['atendido'] = "Pendiente";
  276.             } elseif ($incidencium->getAtendido() == 1) {
  277.                 $data['atendido'] = "Seguimiento";
  278.             } else {
  279.                 $data['atendido'] = "Atendido";
  280.             }
  281.             return new JsonResponse($data);
  282.         }
  283.         if($form->isSubmitted() && !$form->isValid()){
  284.             $view $this->renderForm('incidencia/modal.html.twig', [
  285.                 'incidencium' => $incidencium,
  286.                 'form' => $form,
  287.             ]);
  288.             $response = new JsonResponse(['form' => $view]);
  289.             $response->setStatusCode(Response::HTTP_BAD_REQUEST);
  290.             return $response;
  291.         }
  292.         if ($a != $b){
  293.             $c false;
  294.         }
  295.         return $this->renderForm('incidencia/modal.html.twig', [
  296.             'incidencium' => $incidencium,
  297.             'form' => $form,
  298.             'actual' => $c
  299.         ]);
  300.     }
  301.     //#[Route('/{idInc}', name: 'app_incidencia_delete', methods: ['POST'])]
  302.     /**
  303.      *@Route("/delete/{idInc}", name= "app_incidencia_delete", methods= {"POST"})
  304.      */
  305.     public function delete(Request $requestIncidencia $incidenciumEntityManagerInterface $entityManager): Response
  306.     {
  307.         if ($this->isCsrfTokenValid('delete'.$incidencium->getIdInc(), $request->request->get('_token'))) {
  308.             $entityManager->remove($incidencium);
  309.             $entityManager->flush();
  310.         }
  311.         return $this->redirectToRoute('app_incidencia_index', [], Response::HTTP_SEE_OTHER);
  312.     }
  313.     private function generarPDFReporteAction($data) {
  314.         date_default_timezone_set('America/Mexico_City');
  315.         setlocale(LC_ALL'es_MX');
  316.         # Obtenemos el documento que se imprimirá
  317.         $formato strftime('%d %b %Y, %H:%M hrs'strtotime(date('d-m-Y H:i')));
  318.         # Obtenemos los datos del documento
  319.         $ffinal $data['ftermino']->format('d/m/Y');
  320.         $ftermino $data['ftermino']->add(new DateInterval('P1D'));
  321.         $bd $this->emi->getRepository(Incidencia::class);
  322.         $query $bd->createQueryBuilder('i')
  323.             ->where('i.unidad = :unidad AND i.fcreacion >= :inicio AND i.fcreacion <= :fin')
  324.             ->setParameter('unidad'$data['unidad'])
  325.             ->setParameter('inicio'$data['finicio'])
  326.             ->setParameter('fin'$ftermino)
  327.         ;
  328.         $consulta $query->getQuery();
  329.         $incidencias $consulta->getResult();
  330.         $finicial $data['finicio']->format('d/m/Y');
  331.         $fconsulta date('d/m/Y H:i');
  332.         $cadenaOriginal $data['unidad'] . '||' $data['nombre'] . '||' $data['correo'] . '||' $finicial '||';
  333.         $cadenaOriginal .= $ffinal '||' $fconsulta;
  334.         $cadenaOriginal str_replace(' ''+'$cadenaOriginal);
  335.         $hash hash('sha512'$cadenaOriginal);
  336.         $cadena64 base64_encode($cadenaOriginal '^' $hash);
  337.         #Declaración de la instancia de TCPDF con el encabezado personalizado
  338.         $pdf = new DocumentoPDF();
  339.         $pdf->femision date('d/m/Y');
  340.         $pdf->finicio $data['finicio']->format('d/m/Y');
  341.         $pdf->ftermino $data['ftermino']->format('d/m/Y');
  342.         $pdf->correo $data['correo'];
  343.         $pdf->nombre $data['nombre'];
  344.         $pdf->setPrintFooter(false);
  345.         # Información del documento
  346.         $pdf->SetCreator('Conalep Estado de México');
  347.         $pdf->SetAuthor('Registro de Incidencias');
  348.         $pdf->SetTitle('Reporte de Observaciones e Incidencias');
  349.         # Definimos los saltos de página como automáticos
  350.         #$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  351.         #Nueva página con sus respectivas características
  352.         $pdf->AddPage('L');
  353.         $pdf->SetY(70);
  354.         # Definimos la utilización de tipigrafías
  355.         $pdf->setFontSubsetting(true);
  356.         # Declaramos una nueva tipografía para el contenido del documento
  357.         $pdf->SetFont('freesans'''10''true);
  358.         ### Generamos el contenido a mostrar ###
  359.         ob_start();
  360.         $html = <<<EOD
  361.         <table width="100%" cellpadding="5" border="0">
  362.             <tr>
  363.                 <td style="font-size: 12px; width: 30%">Unidad Administrativa/Plantel/Área: <strong>{$data['unidad']}</strong></td>
  364.                 <td style="font-size: 12px; width: 50%; text-align: right">Periodo: </td>
  365.                 <td style="font-size: 12px; width: 10%">Inicial: <strong>{$finicial}</strong></td>
  366.                 <td style="font-size: 12px; width: 10%">Final: <strong>{$ffinal}</strong></td>
  367.             </tr>
  368.         </table>
  369.         <table cellpadding="5" border="0.1">
  370.         <thead>
  371.             <tr>
  372.                 <td style="width: 8%; text-align: center"><strong>Folio</strong></td>
  373.                 <td style="width: 8%; text-align: center"><strong>Fecha</strong></td>
  374.                 <td style="width: 8%; text-align: center"><strong>Tipo</strong></td>
  375.                 <td style="width: 15%; text-align: center"><strong>Sistema o actividad donde se genera</strong></td>
  376.                 <td style="width: 17%; text-align: center"><strong>Perfil, rol o interesado que identifica</strong></td>
  377.                 <td style="width: 17%; text-align: center"><strong>Descripción de incidente u oportunidad</strong></td>
  378.                 <td style="width: 17%; text-align: center"><strong>Sugerencia de acción o recomendacion</strong></td>
  379.                 <td style="width: 10%; text-align: center"><strong>Estatus</strong></td>
  380.             </tr>
  381.         </thead>
  382.         <tbody>
  383.         EOD;
  384.         $pdf->setMargins(10,75);
  385.         foreach ($incidencias as $i) {
  386.             $tipo "";
  387.             $atendido "";
  388.             if ($i->getTipo() == 1){
  389.                 $tipo "Observación";
  390.             } else {
  391.                 $tipo "Incidencia";
  392.             }
  393.             if ($i->getAtendido() == || $i->getAtendido() == null) {
  394.                 $atendido "Pendiente";
  395.             } elseif ($i->getAtendido() == 1) {
  396.                 $atendido "Seguimiento";
  397.             } else {
  398.                 $atendido "Atendido";
  399.             }
  400.             $html .= <<<EOD
  401.             <tr>
  402.                 <td style="width: 8%">{$i->getIdInc()}</td>
  403.                 <td style="width: 8%">{$i->getFcreacion()->format('d/m/Y')}</td>
  404.                 <td style="width: 8%">{$tipo}</td>
  405.                 <td style="width: 15%; text-align: center">({$i->getTema()->getSiglas()}{$i->getTema()->getNombre()}</td>
  406.                 <td style="width: 17%; text-align: center">{$i->getPerfil()}</td>
  407.                 <td style="width: 17%">{$i->getDescripcion()}</td>
  408.                 <td style="width: 17%">{$i->getSugerencia()}</td>
  409.                 <td style="width: 10%; text-align: center">{$atendido}</td>
  410.             </tr>
  411.             EOD;
  412.         }
  413.         $html .= <<<EOD
  414.                 </tbody>  
  415.             </table>
  416.         EOD;
  417.         # $pdf->write2DBarcode($cadenaOriginal, 'QRCODE,H', false, false, 20, 20, $styleQR, 'N')
  418.         $qr = new \TCPDF2DBarcode($cadenaOriginal'QRCODE,M');
  419.         $imgdata $qr->getBarcodePngData(2.52.5, array(000));
  420.         file_put_contents('assets/img/tmp/qr.png'$imgdata);
  421.         $html .=
  422. <<<EOD
  423. <br>
  424. <br>
  425. <br>
  426. <table width="100%" cellpadding="5" border="0">
  427.     <tbody>
  428.         <tr>
  429.             <td style="font-size: 12px"><strong>ELABORÓ:</strong></td>
  430.             <td><strong>Usuario: </strong>{$data['nombre']}</td>
  431.             <td><strong>Correo: </strong>{$data['correo']}</td>
  432.             <td rowspan="3"><img src="assets/img/tmp/qr.png" alt="QRCODE" /></td>
  433.         </tr>
  434.         <tr>
  435.             <td><strong>Fecha inicio: </strong>{$finicial}</td>
  436.             <td><strong>Fecha final: </strong>{$ffinal}</td>
  437.             <td><strong>Fecha consulta: </strong>{$fconsulta}</td>
  438.         </tr>
  439.         <tr>
  440.             <td colspan="3">{$cadena64}</td>
  441.         </tr>
  442.     </tbody>
  443. </table>
  444. EOD;
  445.         
  446.         # Imprimimos el contenido como HTML
  447.         $pdf->writeHTMLCell($w=0$h=0$x=''$y=''$html$border=0$ln=1$fill=0$reseth=true$align=''$autopadding=true);
  448.         ob_end_clean();
  449.         # ---------------------------------------------------------
  450.         # Mostramos el resultado en pantalla
  451.         $pdf->Output('ReporteIncidencias-' date('Ymd') . '.pdf''D');
  452.     }
  453.     /**
  454.      * @Route("/reporte/excel", name= "app_incidencia_reporte_excel")
  455.      * @param Request $request
  456.      * @param EntityManagerInterface $entityManager
  457.      * @return BinaryFileResponse
  458.      * @throws IOException
  459.      * @throws InvalidArgumentException
  460.      * @throws WriterNotOpenedException
  461.      */
  462.     public function generarExcelReporteAction(Request $requestEntityManagerInterface $entityManager): BinaryFileResponse
  463.     {
  464.         ini_set('memory_limit''5120M');
  465.         ini_set('max_execution_time'0);
  466.         ini_set('output_buffering'0);
  467.         # Obtenemos los datos de la petición
  468.         /** @var Usuario $user */
  469.         $user $this->getUser();
  470.         $parameters $request->request->get('incidencia_filtro');
  471.         $periodo $parameters['periodo'];
  472.         $tema $parameters['tema'];
  473.         $unidad = (array_key_exists('unidad'$request->request->all()['incidencia_filtro'])) ? $parameters['unidad'] : $user->getUnidad();
  474.         # Obtenemos los datos del documento
  475.         $incidencias $entityManager->getRepository(Incidencia::class)->filtroLecciones($periodo$unidad$tema);
  476.         # Definir el nombre temporal del archivo
  477.         $filePath 'incidencias.xlsx';
  478.         # Se definen las cabeceras del archivo
  479.         $cabecera WriterEntityFactory::createRowFromArray([
  480.             '#',
  481.             'Fecha de creacion',
  482.             'Tipo',
  483.             'Periodo',
  484.             'Usuario',
  485.             'Unidad/Plantel',
  486.             'Persona que detecta o Perfil',
  487.             'Sistema',
  488.             'Descripcion',
  489.             'Sugerencia',
  490.             'Seguimiento por Usuario',
  491.             'Estatus por Usuario',
  492.             'Seguimiento por Coordinación',
  493.             'Estatus por Coordinación',
  494.         ]);
  495.         # Se crea el arreglo con los datos del cuerpo del documento
  496.         $data = [];
  497.         $n 1;
  498.         foreach ($incidencias as $i) {
  499.             $estatus "";
  500.             $estatusDir "";
  501.             $tipo "";
  502.             if ($i->getTipo() == 1){
  503.                 $tipo "Observación";
  504.             } else {
  505.                 $tipo "Incidencia";
  506.             }
  507.             if ($i->getAtendido() == 0)
  508.                 $estatus "Pendiente";
  509.             if ($i->getAtendido() == 1)
  510.                 $estatus "Seguimiento";
  511.             if ($i->getAtendido() == 2)
  512.                 $estatus "Atendido";
  513.             if ($i->getAtendidoDir() == 0)
  514.                 $estatusDir "Pendiente";
  515.             if ($i->getAtendidoDir() == 1)
  516.                 $estatusDir "Seguimiento";
  517.             if ($i->getAtendidoDir() == 2)
  518.                 $estatusDir "Atendido";
  519.             $data[] = WriterEntityFactory::createRowFromArray([
  520.                 $i->getIdInc(),
  521.                 $i->getFcreacion()->format('d/m/Y'),
  522.                 $tipo,
  523.                 $i->getPeriodo()->getDescripcion(),
  524.                 $i->getUsuario()->getNombre() . ' ' $i->getUsuario()->getPapellido() . ' - ' $i->getUsuario()->getCorreo(),
  525.                 $i->getUnidad()->getNombre(),
  526.                 $i->getPerfil(),
  527.                 $i->getTema()->getNombre(),
  528.                 $i->getDescripcion(),
  529.                 $i->getSugerencia(),
  530.                 $i->getSeguimiento(),
  531.                 $estatus,
  532.                 $i->getSeguimientoDir(),
  533.                 $estatusDir,
  534.             ]);
  535.             $n++;
  536.         }
  537.         # Se crea el documento en formato CSV
  538.         $writer WriterEntityFactory::createXLSXWriter();
  539.         $writer
  540.             ->openToFile($filePath)
  541.             ->addRow($cabecera)
  542.             ->addRows($data)
  543.             ->close()
  544.         ;
  545.         $response = new BinaryFileResponse($filePath);
  546.         $response->setContentDisposition(
  547.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  548.             'ReporteIncidencias' '_' date('Y-m-d') . '.xlsx'
  549.         );
  550.         $response->deleteFileAfterSend(true);
  551.         return $response;
  552.     }
  553. }