src/Controller/GHVacanteController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\GHCandidato;
  4. use App\Entity\GHPerfilCargo;
  5. use App\Entity\GHPeriodoPrueba;
  6. use App\Entity\GHVacante;
  7. use App\Entity\ParEstado;
  8. use App\Entity\TerPersona;
  9. use App\Form\GHVacanteEliminadaType;
  10. use App\Form\GHVacanteType;
  11. use App\Repository\GHVacanteRepository;
  12. use App\Services\ExcelExporterService;
  13. use App\Services\MailerCore;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Doctrine\ORM\EntityRepository;
  16. use Dompdf\Dompdf;
  17. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  24. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  25. class GHVacanteController extends AbstractController {
  26.     private $entityManager;
  27.     private $repository;
  28.     private $code 0;
  29.     private $msj "";
  30.     private $url "";
  31.     private $html "";
  32.     #[Route('/gh/vacante'name'gh_vacante')]
  33.     public function index(Request $request): Response {
  34. ////        //todos los registros para Gestión Humana
  35.         if ($this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId() == 1) {
  36.             $entities $this->repository->getAll([4,5]);
  37.         } else {
  38.             $entities $this->repository->getAll([4,5], $this->getUser()->getPersona()->getId());
  39.         }
  40.         //$entities = $this->repository->getAll([4, 5, 29]);
  41.         return $this->render('gh_vacante/index.html.twig', [
  42.                     'controller_name' => 'GHVacanteController',
  43.                     'entities' => $entities,
  44.                     'tipoFiltro' => "vacantesExcel",
  45.                     'titulo' => 'Vacantes'
  46.         ]);
  47.     }
  48.     #[Route('/gh/vacante_eliminadas'name'gh_vacante_eliminadas')]
  49.     public function eliminadas(Request $request): Response {
  50.         //todos los registros para Gestión Humana Eliminados
  51.         if ($this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId() == 1) {
  52.             $entities $this->repository->getAll([6]);
  53.         } else {
  54.             $entities $this->repository->getAll([6], $this->getUser()->getPersona()->getId());
  55.         }
  56.          //$entities = $this->repository->getAll([6]);
  57.         return $this->render('gh_vacante/index.html.twig', [
  58.                     'controller_name' => 'GHVacanteController',
  59.                     'entities' => $entities,
  60.                     'tipoFiltro' => "vacantesExcel",
  61.                     'titulo' => 'Vacantes Descartadas'
  62.         ]);
  63.     }
  64.     #[Route('/gh/vacante_revision'name'gh_vacante_revision')]
  65.     public function vacanteRevision(Request $request): Response {
  66.         $entities $this->repository->getAll([4]);
  67.         return $this->render('gh_vacante/index.html.twig', [
  68.                     'controller_name' => 'GHVacanteController',
  69.                     'entities' => $entities,
  70.                     'tipoFiltro' => "vacantesExcel",
  71.                     'titulo' => 'Aprobación Solicitud'
  72.         ]);
  73.     }
  74.     #[Route('/gh/vacante_seleccion'name'gh_vacante_seleccion')]
  75.     public function vacanteSeleccion(Request $request): Response {
  76.         $entities $this->repository->getAll([57]);
  77.         return $this->render('gh_vacante/index.html.twig', [
  78.                     'controller_name' => 'GHVacanteController',
  79.                     'entities' => $entities,
  80.                     'tipoFiltro' => "vacantesExcel",
  81.                     'titulo' => 'Proceso Seleccion'
  82.         ]);
  83.     }
  84.     public function __construct(EntityManagerInterface $entityManagerGHVacanteRepository $GHVacanteRepository) {
  85.         $this->entityManager $entityManager;
  86.         $this->repository $GHVacanteRepository;
  87.     }
  88.     #[Route('/gh/vacante/crear'name'gh_vacante_new')]
  89.     public function crearVacante(Request $request\App\Services\MailerCore $mailerCore\App\Services\ResponseHandler $responseHandler): Response {
  90.         $vacante = new GHVacante();
  91.         $form $this->createForm(GHVacanteType::class, $vacante, [
  92.             'method' => 'POST',
  93.             'with_extra_fields' => true// Correcto
  94.             'action' => $this->generateUrl($request->attributes->get('_route')),
  95.         ]);
  96.         $form->remove('observacionCierre')
  97.                 ->remove('empresaTpm')
  98.                 ->remove('fecha')
  99.                 ->remove('cargoTpm')
  100.                 ->remove('TipoSeleccionTmp')
  101.                 ->remove('TipoContratoTpm')
  102.                 ->remove('ResumenPerfilTpm')
  103.                 ->remove('rangoSalarialTpm')
  104.                 ->remove('sedeTpm')
  105.                 ->remove('estado')
  106.         ;
  107.         $form->handleRequest($request);
  108.         if ($form->isSubmitted() && $form->isValid()) {
  109.             $entityManager $this->entityManager;
  110. //            if ($vacante->getPerfilCargo()) {
  111. //                $vacanteRepetida = $entityManager->getRepository(GHVacante::class)->findOneBy(['perfilCargo' => $vacante->getPerfilCargo()->getId(), 'empresaFilial' => $vacante->getEmpresaFilial()->getId(), 'sede' => $vacante->getSede()->getId(), 'estado' => 4]);
  112. //                if ($vacanteRepetida) {
  113. //
  114. //                    $this->code = 'warning';
  115. //                    $this->msj = "El sistema ya cuenta con una vacante igual, valide e intente nuevamente.";
  116. //                    return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
  117. //                }
  118. //            }
  119.             $vacante->setFecha(new \DateTime('now'));
  120.             $vacante->setNumeroPostulados(0);
  121.             $vacante->setNumeroAdmitidos(0);
  122.             $vacante->setPersonaSolicita($this->getUser()->getPersona());
  123.             $cargoPersona $this->getUser()->getPersona()?->getPerfilCargo()?->getCargo()?->getId() ?? null;
  124.             if ($this->getUser()->getPersona()->getPerfilCargo()->getParNivelAutoridad()->getId() == 4) {
  125.                 // si es admin notificar y autorizar.
  126.                 $vacante->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(5));
  127.                 $entityManager->persist($vacante);
  128.                 $entityManager->flush();
  129.                 $mailerCore->notificarVacante('notificar', [$vacante]);
  130.             } else {
  131.                 $vacante->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(4));
  132.                 $entityManager->persist($vacante);
  133.                 $entityManager->flush();
  134.                 $mailerCore->notificarVacante('notificar', [$vacante], ['gestion.humana@logisticazf.com.co']); //notificacion de creacion
  135.                 // Validar si son directores en gerente para no enviar la aprobación
  136.                 $directoresGerentes in_array($cargoPersona,[11,2,5,8,19,29,38,1]);
  137.                 if($cargoPersona && !$directoresGerentes){
  138.                     $mailerCore->notificarVacante('gestionar', [$vacante]); //notificacion de aprobacion
  139.                 }
  140.                 if($directoresGerentes)
  141.                     // Queda en estado aprobado inmediatamente
  142.                     $vacante->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(5));
  143.             }
  144.             $vacante->setCreateUser($this->getUser()->getUsername());
  145.             $entityManager->persist($vacante);
  146.             $entityManager->flush();
  147.             $this->code 'success';
  148.             $this->msj "Registro cargado exitosamente.";
  149.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  150.         }
  151.         return $this->render('gh_vacante/crear.html.twig', [
  152.                     'vacante' => $vacante,
  153.                     'form' => $form->createView(),
  154.         ]);
  155.     }
  156.     #[Route('/gh/vacante/{id}/eliminar'name'gh_vacante_eliminar'methods: ['GET'])]
  157.     public function eliminar(EntityManagerInterface $entityManager\App\Services\MailerCore $mailerCoreGHVacante $entity\App\Services\ResponseHandler $responseHandler): Response {
  158.         $entity->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(3));
  159.         $vacante $entity;
  160.         $entityManager->persist($vacante);
  161.         $entityManager->flush();
  162.         $this->addFlash('success'"Registro Eliminado exitosamente");
  163.         return $this->redirectToRoute('gh_vacante');
  164.     }
  165.     #[Route('/gh/vacante/{id}/aprobar'name'gh_vacante_aprobar'methods: ['GET'])]
  166.     public function aprobarVacante(Request $request\App\Services\MailerCore $mailerCoreGHVacante $entity\App\Services\ResponseHandler $responseHandler): Response {
  167.         $vacante $entity;
  168.         if (!$vacante) {
  169.             throw $this->createNotFoundException('No se encontró la vacante');
  170.         }
  171.         $empresaFilial $vacante->getEmpresaFilial()->getId();
  172.         $idPerfilCargo $vacante->getPerfilCargo()->getId();
  173.         $estadoAnt $vacante->getEstado();
  174.         $form $this->createForm(GHVacanteType::class, $vacante, ['with_extra_fields' => true,'idEmpresaFilial' => $empresaFilial'idPerfilCargo' => $idPerfilCargo'method' => 'POST''action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $vacante->getId()])]);
  175.         $form
  176.             ->remove('empresaFilial')
  177.             ->remove('perfilCargo')
  178.             ->remove('ParTipoSeleccion')
  179.             ->remove('ParTipoContrato')
  180. //            ->remove('resumenPerfilCandidato')
  181.             ->remove('empresaFilial')
  182.             ->remove('empresaFilial')
  183.             ->remove('empresaFilial')
  184.             ->remove('empresaFilial')
  185.             ->remove('empresaFilial')
  186.             ->remove('empresaTpm')
  187.             ->remove('cargoTpm')
  188.             ->remove('TipoSeleccionTmp')
  189.             ->remove('TipoContratoTpm')
  190.             ->remove('ResumenPerfilTpm')
  191.             ->remove('rangoSalarialTpm')
  192.             ->remove('sedeTpm')
  193.             ->remove('fecha')
  194.             ->remove('sede')
  195.             ;
  196.         $form->handleRequest($request);
  197.         if ($form->isSubmitted() && $form->isValid()) {
  198.             $this->entityManager->persist($this->getUser());
  199.             $this->entityManager->flush();
  200.             $vacante->setPersonaAprueba($this->getUser()->getPersona());
  201.             $this->entityManager->persist($vacante);
  202.             $this->entityManager->flush();
  203.             $estado $vacante->getEstado()->getId();
  204.             if ($estado == 6) {
  205.                 // Validar el correo del solicitante
  206.                 $emailSolicitante = [$vacante->getPersonaSolicita()?->getEmail() ?? 'gestion.humana@logisticazf.com.co'];
  207.                 $mailerCore->notificarVacante('rechazar', [$vacante], $emailSolicitante);
  208.             }
  209.             $this->code 'success';
  210.             $this->msj "Registro almacenado con exito.";
  211.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  212.         }
  213.         return $this->render('gh_vacante/aprobar.html.twig', [
  214.                     'vacante' => $vacante,
  215.                     'form' => $form->createView(),
  216.         ]);
  217.     }
  218.     #[Route('/gh/vacante/editar/{id}'name'gh_vacante_edit')]
  219.     public function actualizarVacante(Request $requestGHVacante $vacante\App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore) {
  220.         $entityManager $this->entityManager;
  221.         if (!$vacante) {
  222.             throw $this->createNotFoundException('No se encontró la vacante');
  223.         }
  224.         dump($vacante);
  225.         $empresaFilial $vacante->getEmpresaFilial()->getId();
  226.         $idPerfilCargo $vacante->getPerfilCargo()->getId();
  227.         $estadoAnt $vacante->getEstado();
  228.         $form $this->createForm(GHVacanteType::class, $vacante, ['with_extra_fields' => true,'idEmpresaFilial' => $empresaFilial'idPerfilCargo' => $idPerfilCargo'method' => 'POST''action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $vacante->getId()])]);
  229.         $form
  230.                 ->remove('empresaTpm')
  231.                 ->remove('cargoTpm')
  232.                 ->remove('TipoSeleccionTmp')
  233.                 ->remove('TipoContratoTpm')
  234.                 ->remove('ResumenPerfilTpm')
  235.                 ->remove('rangoSalarialTpm')
  236.                 ->remove('sedeTpm')
  237.                 ->remove('estado')
  238.                 ->remove('observacionCierre')
  239.                 ->remove('fecha');
  240.         if ($this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId() != && !$this->getUser()->getPersona()->hasNivelDirector()) {
  241.             $form->remove('estado')->remove('observacionCierre');
  242.         }
  243.         $form->handleRequest($request);
  244.         if ($form->isSubmitted()) {
  245.             $vacante->setFecha(new \DateTime('now'));
  246.             $entityManager->persist($vacante);
  247.             $entityManager->flush();
  248.             $this->code 'success';
  249.             $this->msj 'Registro cargado exitosamente.';
  250.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  251.         }
  252.         return $this->render('gh_vacante/actualizar.html.twig', [
  253.                     'vacante' => $vacante,
  254.                     'form' => $form->createView(),
  255.                     'accion' => "Editar"
  256.         ]);
  257.     }
  258.     #[Route('/gh/vacante/editar_eliminada/{id}'name'gh_vacante_edit_eliminada')]
  259.     public function actualizarVacanteEliminada(Request $requestGHVacante $vacante\App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore) {
  260.         $entityManager $this->entityManager;
  261.         if (!$vacante) {
  262.             throw $this->createNotFoundException('No se encontró la vacante');
  263.         }
  264.         $empresaFilial $vacante->getEmpresaFilial()->getId();
  265.         $idPerfilCargo $vacante->getPerfilCargo()->getId();
  266.         $estadoAnt $vacante->getEstado();
  267.         $form $this->createForm(GHVacanteEliminadaType::class, $vacante, [
  268.             'with_extra_fields' => true,
  269.             'idEmpresaFilial' => $empresaFilial,
  270.             'idPerfilCargo' => $idPerfilCargo,
  271.             'method' => 'POST',
  272.             'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $vacante->getId()])]);
  273.         $form
  274.             ->remove('empresaTpm')
  275.             ->remove('cargoTpm')
  276.             ->remove('TipoSeleccionTmp')
  277.             ->remove('TipoContratoTpm')
  278.             ->remove('ResumenPerfilTpm')
  279.             ->remove('rangoSalarialTpm')
  280.             ->remove('sedeTpm')
  281.             ->remove('estado')
  282.             ->remove('observacionCierre')
  283.             ->remove('fecha')
  284.         ;
  285.         $estado $vacante->getEstado();
  286. //        if ($estado->getId() == 6) {
  287. //            $form ->add('estado', EntityType::class, [
  288. //                'class' =>  ParEstado::class,
  289. //                'query_builder' => function (EntityRepository $er) {
  290. //                    return $er->createQueryBuilder('e')
  291. //                        ->where('e.id in (5,6)')
  292. //                        ->orderBy('e.nombre', 'ASC');
  293. //                }
  294. //            ]);
  295. //        }
  296.         if ($this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId() != && !$this->getUser()->getPersona()->hasNivelDirector()) {
  297.             $form->remove('estado')->remove('observacionCierre');
  298.         }
  299.         $form->handleRequest($request);
  300.         if ($form->isSubmitted() && $form->isValid()) {
  301.             $entityManager->persist($vacante);
  302.             $entityManager->flush();
  303.             if ($this->getUser()->getPersona()->getPerfilCargo()->getParNivelAutoridad()->getId() == 4) {
  304.                 // si es admin notificar y autorizar.
  305.                 $vacante->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(5));
  306.                 $entityManager->persist($vacante);
  307.                 $entityManager->flush();
  308. //                $mailerCore->notificarVacante('notificar', [$vacante]);
  309.             } else {
  310.                 $vacante->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(4));
  311.                 $entityManager->persist($vacante);
  312.                 $entityManager->flush();
  313.                 //$mailerCore->notificarVacante('notificar', [$vacante], ['gestion.humana@logisticazf.com.co']); //notificacion de creacion
  314.                 $mailerCore->notificarVacante('gestionar', [$vacante]); //notificacion de aprobacion
  315.             }
  316.             $this->code 'success';
  317.             $this->msj 'Registro cargado exitosamente.';
  318.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  319.         }
  320.         return $this->render('gh_vacante/actualizar.html.twig', [
  321.             'vacante' => $vacante,
  322.             'form' => $form->createView(),
  323.             'accion' => "Editar"
  324.         ]);
  325.     }
  326.     /**
  327.      * Calcula los días hábiles entre dos fechas (de lunes a viernes)
  328.      *
  329.      * @param \DateTime $startDate Fecha de inicio
  330.      * @param \DateTime $endDate Fecha final
  331.      * @return int Número de días hábiles
  332.      */
  333.     private function calcularDiasHabiles(\DateTime $startDate\DateTime $endDate): int {
  334.         $diasHabiles 0;
  335.         $startDate = clone $startDate// para no modificar el original
  336.         $startDate->modify('+1 day');  // iniciar desde el día siguiente
  337.         while ($startDate <= $endDate) {
  338.             if (in_array($startDate->format('N'), [12345])) { // lunes a viernes (1 a 5)
  339.                 $diasHabiles++;
  340.             }
  341.             $startDate->modify('+1 day');
  342.         }
  343.         return $diasHabiles;
  344.     }
  345.     #[Route('/gh/vacante/ver/{id}'name'gh_vacante_view')]
  346.     public function verVacante(Request $requestGHVacante $vacante\App\Services\ResponseHandler $responseHandler) {
  347.         if (!$vacante) {
  348.             throw $this->createNotFoundException('No se encontró la vacante');
  349.         }
  350.         // Fecha actual
  351.         $diaActual = new \DateTime('now');
  352.         // Fecha de la vacante
  353.         $fechaVacante $vacante->getFecha();
  354.         // Calcular días hábiles
  355.         $diasHabiles $fechaVacante $this->calcularDiasHabiles($fechaVacante$diaActual) : null;
  356.         $candidatos $vacante->getCandidato(); // Esto ya es una colección
  357.         $candidatosContratado 0;
  358.         foreach ($candidatos as $candidato) {
  359.             $afiliaciones $candidato->getAfiliacionContratacion();
  360.             if (!$afiliaciones->isEmpty()) {
  361.                 $tieneTipoContratado false;
  362.                 foreach ($afiliaciones as $afiliacion) {
  363.                     $tipoId $afiliacion->getTipoAfiliacion()->getId();
  364.                     if (in_array($tipoId, [23])) {
  365.                         $tieneTipoContratado true;
  366.                         break; // ya no necesitamos seguir revisando este candidato
  367.                     }
  368.                 }
  369.                 if ($tieneTipoContratado) {
  370.                     $candidatosContratado++;
  371.                 }
  372.             }
  373.         }
  374.         return $this->render('gh_vacante/ver.html.twig', [
  375.                     'vacante' => $vacante,
  376.                     'accion' => 'Ver',
  377.                     'diasHabiles' => $diasHabiles,
  378.                     'candidatosContratado' => $candidatosContratado,
  379.         ]);
  380.     }
  381.     #[Route('/gh/vacante/ver_candidato/{id}'name'gh_vacante_ver_candidato')]
  382.     public function verCandidatoVacante(Request $request\App\Entity\GHCandidato $candidato\App\Services\ResponseHandler $responseHandler) {
  383.         if (!$candidato) {
  384.             throw $this->createNotFoundException('No se encontró la vacante');
  385.         }
  386.         $solicitante $candidato->getVacante()->getCreateUser();
  387.         $solicitanteEdit $candidato->getVacante()->getUpdateUser();
  388.         $cargoPersona $this->getUser()->getPersona()->getPerfilCargo()->getCargo()->getId(); // ID Del cargo
  389.         // Validar si el candidato alguna vez fue rechazado o desistio
  390.         $candidatoFinalizado false;
  391.         if($candidato->getMotivoFinalizacion())
  392.             $candidatoFinalizado true;
  393.         // Validar quien puede ver los enlaces
  394.         $verLink false;
  395.         if ($solicitante && $solicitante === $this->getUser()->getUsername() || $solicitante === $this->getUser()) {
  396.             $verLink true;
  397.         } elseif ($solicitanteEdit && $solicitanteEdit === $this->getUser()->getUsername() || $solicitanteEdit === $this->getUser()) {
  398.             $verLink true;
  399.         }
  400.         if(in_array($cargoPersona, [11,33,20]))
  401.             $verLink false;
  402.         $personaNombre $this->getUser()->getPersona()->getNombres();
  403.         $personaCargo $this->getUser()->getPersona()->getPerfilCargo()->getCargo()->getNombre();
  404.         $completo "$personaNombre ($personaCargo)";
  405.         $usuario $this->getUser();
  406.         $procesoGH 1;
  407.         return $this->render('gh_vacante/dashCandidato.html.twig', [
  408.             'candidato' => $candidato,
  409.             'accion' => "Ver",
  410.             'verLink' => $verLink,
  411.             'procesoGH' => $procesoGH,
  412.             'candidatoFinalizado' => $candidatoFinalizado,
  413.         ]);
  414.     }
  415.     #[Route('/gh/vacante/descargar_excel/{id}'name'gh_vacante_excel'methods: ['GET'])]
  416.     public function descargarExcel(GHVacante $vacanteExcelExporterService $excelExporterService): Response
  417.     {
  418.         if (!$vacante) {
  419.             throw $this->createNotFoundException('No se encontró la vacante');
  420.         }
  421.         $titulo 'Resumen Vacante ' $vacante->getPerfilCargo()->getCargo()->getNombre();
  422.         $perfil $vacante->getPerfilCargo();
  423.         $empresa $perfil->getEmpresaFilial()->first();
  424.         $sucursal $perfil->getSede()->first();
  425.         // Inicializar cabecera y datos
  426.         $cabecera = [
  427.             'Cargo',
  428.             'Descripción del cargo',
  429.             'Responsabilidades',
  430.             'Funciones',
  431.             'Críticidad',
  432.             'Educación',
  433.             'Formación',
  434.             'Experiencia',
  435.         ];
  436.         $datos = [[
  437.             strip_tags($perfil->getCargo()->getNombre() ?? ''),
  438.             strip_tags($perfil->getResumenCargo() ?? ''),
  439.             strip_tags($perfil->getResponsabilidades() ?? ''),
  440.             strip_tags($perfil->getFunciones() ?? ''),
  441.             $perfil->getParCriticidad()?->getNombreCriticidad() ?? '',
  442.             strip_tags($perfil->getEducacion() ?? ''),
  443.             strip_tags($perfil->getFormacionExperiencia() ?? ''),
  444.             strip_tags($perfil->getExperiencia() ?? ''),
  445.         ]];
  446.         // Validar si hay conocimientos específicos
  447.         $conocimientos strip_tags($perfil->getConocimientosEspecificos() ?? '');
  448.         if ($conocimientos !== '') {
  449.             $cabecera[] = 'Conocimientos Específicos';
  450.             $datos[0][] = $conocimientos;
  451.         }
  452.         // Agregar campos finales comunes
  453.         $cabecera array_merge($cabecera, [
  454.             'Empresa',
  455.             'Fecha Solicitud',
  456.             'Rango Salarial',
  457.             'Sucursal',
  458.             'Número Vacantes',
  459.             'Requerimiento Específico',
  460.         ]);
  461.         $datos[0] = array_merge($datos[0], [
  462.             $empresa->getNombre(),
  463.             $vacante->getFecha()?->format('d/m/Y') ?? '',
  464.             $perfil->getRangoSalarial() ?? '',
  465.             $sucursal->getNombre() ?? '',
  466.             $vacante->getNumeroVacante() ?? '',
  467.             strip_tags($vacante->getRequerimientoEspecifico() ?? ''),
  468.         ]);
  469.         return $excelExporterService->export(
  470.             $titulo,
  471.             $cabecera,
  472.             $datos,
  473.             'Consolidado_Vacante_' $perfil->getCargo()->getNombre() . '.xlsx'
  474.         );
  475.     }
  476.     #[Route('/gh/vacante/descargar'name'gh_vacante_descargar')]
  477.     public function descargarVacantes(Request $request) {
  478.         $data $this->repository->getDescargable([57]);
  479.         foreach ($data as $key => $value) {
  480.             foreach ($value as $key2 => $value2) {
  481.                 if ($key2 == 'descripcion') {
  482.                     $data[$key][$key2] = strip_tags($value2);
  483.                 }
  484.             }
  485.         }
  486.         $res $this->generateExcelAction(['nombreArchivo' => 'Listado de Vacantes'], ['Doc_legal' => $data]);
  487.         return $res;
  488.     }
  489.     private function generateExcelAction($archivo$datos) {
  490.         // ask the service for a excel object
  491.         $phpExcelObject = new Spreadsheet();
  492.         $fecha = new \DateTime('now');
  493.         $modificado = isset($archivo['modificado']) ? $archivo['modificado'] : "LOOGIC";
  494.         $titulo = isset($archivo['titulo']) ? $archivo['titulo'] : "INFORME_POR_LOOGIC";
  495.         $asunto = isset($archivo['asunto']) ? $archivo['asunto'] : "INFORME_LOOGIC";
  496.         $descripcion = isset($archivo['descripcion']) ? $archivo['descripcion'] : "INFORME GENERADO POR LOOGIC";
  497.         $keyWords = isset($archivo['keyWords']) ? $archivo['keyWords'] : "INFORME LOOGIC";
  498.         $categoria = isset($archivo['categoria']) ? $archivo['categoria'] : "LOOGIC";
  499.         $nombreArchivo = isset($archivo['nombreArchivo']) ? $archivo['nombreArchivo'] . {$fecha->format('Y-m-d His')}"INFORME_LOOGIC {$fecha->format('Y-m-d His')}";
  500.         $phpExcelObject->getProperties()->setCreator("LOOGIC COLOMBIA")
  501.                 ->setLastModifiedBy($modificado)
  502.                 ->setTitle($titulo)
  503.                 ->setSubject($asunto)
  504.                 ->setDescription($descripcion)
  505.                 ->setKeywords($keyWords)
  506.                 ->setCategory($categoria);
  507.         $hoja 0;
  508.         $styleEncabezado = array(
  509.             'font' => array(
  510.                 'bold' => true,
  511.                 //'color' => array('rgb' => 'FF0000'),
  512.                 'size' => 10,
  513.                 'name' => 'Verdana'
  514.         ));
  515.         $buffer 0;
  516.         foreach ($datos as $sheetName => $array) {
  517.             $col 'A';
  518.             $iteracion 2;
  519.             $cambio false;
  520.             $phpExcelObject->createSheet($hoja);
  521.             if (isset($archivo['nombreArchivo']) && $archivo['nombreArchivo'] == 'Matriz de Requisitos Legales') {
  522.                 $phpExcelObject->setActiveSheetIndex($hoja)->setCellValue("A1"mb_strtoupper("Matriz General de Requisitos Legales y Otros Requisitos (GER-FR-077)"'utf-8'));
  523.             }
  524.             foreach ($array as $arr => $val) {
  525.                 foreach ($val as $key => $result) {
  526.                     if ($iteracion == 2) {
  527.                         $phpExcelObject->setActiveSheetIndex($hoja)->setCellValue($col $iteracionmb_strtoupper($key'utf-8'));
  528.                         $phpExcelObject->getActiveSheet()->getStyle($col $iteracion)->applyFromArray($styleEncabezado);
  529.                         $phpExcelObject->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
  530.                         $phpExcelObject->setActiveSheetIndex($hoja)->setCellValue($col . ($iteracion 1), $result);
  531.                     } else if ($buffer !== count($val)) {
  532.                         //$iteracion = $iteracion + 2;
  533.                         $phpExcelObject->setActiveSheetIndex($hoja)->setCellValue($col . ($iteracion 2), mb_strtoupper($key'utf-8'));
  534.                         $phpExcelObject->getActiveSheet()->getStyle($col . ($iteracion 2))->applyFromArray($styleEncabezado);
  535.                         $phpExcelObject->setActiveSheetIndex($hoja)->setCellValue($col . ($iteracion 3), $result);
  536.                         $cambio true;
  537.                     } else {
  538.                         $phpExcelObject->setActiveSheetIndex($hoja)->setCellValue($col . ($iteracion 1), $result);
  539.                     }
  540.                     $col++;
  541.                 }
  542.                 $buffer count($val);
  543.                 if ($cambio === true) {
  544.                     $iteracion $iteracion 3//aumento proporcional de acuerdo a el ultimo valor del encabezado.
  545.                     $cambio false;
  546.                 } else {
  547.                     $iteracion++;
  548.                 }
  549.                 $col 'A';
  550.             }
  551.             $phpExcelObject->getActiveSheet()->setTitle($sheetName);
  552.             $hoja++;
  553.         }
  554.         // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  555.         $phpExcelObject->setActiveSheetIndex(0);
  556.         // create the writer
  557.         $writer = new Xlsx($phpExcelObject);
  558.         ob_start();
  559.         // create the response
  560.         $writer->save('php://output');
  561.         $excelOutput ob_get_clean();
  562.         return new Response(
  563.                 $excelOutput,
  564.                 200,
  565.                 [
  566.             'content-type' => 'text/x-csv; charset=windows-1251',
  567.             'Content-Disposition' => 'attachment; filename="' $nombreArchivo '.xlsx"'
  568.                 ]
  569.         );
  570.         //return $response;
  571.     }
  572.     #[Route('/gh/vacante/reaperturar/{id}'name'gh_vacante_reaperturar')]
  573.     public function reaperturarVacante(Request $requestGHVacante $vacanteEntityManagerInterface $entityManagerMailerCore $mailerCore) {
  574.         if (!$vacante) {
  575.             throw $this->createNotFoundException('No se encontró la vacante');
  576.         }
  577.         $candidatosNoAprobados false;
  578.         // Inicializamos el formulario antes del ciclo foreach
  579.         $empresaFilial $vacante->getEmpresaFilial()->getId();
  580.         $idPerfilCargo $vacante->getPerfilCargo()->getId();
  581.         $form $this->createForm(GHVacanteType::class, $vacante, [
  582.             'with_extra_fields' => true,
  583.             'idEmpresaFilial' => $empresaFilial,
  584.             'idPerfilCargo' => $idPerfilCargo,
  585.             'method' => 'POST',
  586.             'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $vacante->getId()])
  587.         ]);
  588.         $form
  589.             ->remove('empresaTpm')
  590.             ->remove('cargoTpm')
  591.             ->remove('TipoSeleccionTmp')
  592.             ->remove('TipoContratoTpm')
  593.             ->remove('ResumenPerfilTpm')
  594.             ->remove('rangoSalarialTpm')
  595.             ->remove('sedeTpm')
  596.             ->remove('estado')
  597.             ->remove('observacionCierre')
  598.             ->remove('fecha');
  599.         foreach ($vacante->getCandidato() as $candidato) {
  600.             $persona $this->entityManager->getRepository(TerPersona::class)->findOneBy(['numeroDocumento' => trim($candidato->getNumeroDocumento())]);
  601.             if ($persona) {
  602.                 foreach ($persona->getPeriodoPrueba() as $periodoPrueba) {
  603.                     if ($periodoPrueba && $periodoPrueba->getEstado() && $periodoPrueba->getEstado()->getId() == 6) {
  604.                         $candidatosNoAprobados true;
  605.                         break;
  606.                     }
  607.                 }
  608.             }
  609.             // Si no se encuentran candidatos no aprobados, no se puede reaperturar la vacante
  610.             if (!$candidatosNoAprobados) {
  611.                 $this->code 'warning';
  612.                 $this->msj 'No se puede reaperturar la vacante, ya que no hay candidatos desaprobados.';
  613.                 return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  614.             }
  615.         }
  616.         $form->handleRequest($request);
  617.         if ($form->isSubmitted()) {
  618.             $vacante->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(29));
  619.             $entityManager->persist($vacante);
  620.             $entityManager->flush();
  621.             $mailerCore->notificarVacante('reaperturar', [$vacante],[$vacante->getPersonaSolicita()->getEmail()]);
  622.             $this->code 'success';
  623.             $this->msj 'Registro cargado exitosamente.';
  624.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  625.         }
  626.         // Siempre debe estar aquí
  627.         return $this->render('gh_vacante/actualizar.html.twig', [
  628.             'vacante' => $vacante,
  629.             'form' => $form->createView(),
  630.             'accion' => "Editar"
  631.         ]);
  632.     }
  633. }