src/Controller/GHCambioContratoController.php line 120

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\GHCambioContrato;
  4. use App\Entity\GHCandidato;
  5. use App\Entity\GHPeriodoPrueba;
  6. use App\Entity\ParCargo;
  7. use App\Entity\ParEstado;
  8. use App\Entity\TerPersona;
  9. use App\Form\GHCambioContratoType;
  10. use App\Form\GHPeriodoPruebaType;
  11. use App\Repository\GHCambioContratoRepository;
  12. use App\Repository\GHPeriodoPruebaRepository;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Dompdf\Dompdf;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\Form\FormInterface;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Component\Validator\Constraints\File;
  21. #[Route('/cambio_contrato')]
  22. class GHCambioContratoController extends AbstractController {
  23.     private $code 0;
  24.     private $msj "";
  25.     private $url "";
  26.     private $html "";
  27.     private $em null;
  28.     private $documentHandler null;
  29.     private $mailerCore null;
  30.     private $repo;
  31.     public function __construct(\App\Services\DocumentHandler $documentHandler\App\Services\MailerCore $mailerCore\Doctrine\ORM\EntityManagerInterface $entityManagerGHCambioContratoRepository $repo) {
  32.         $this->em $entityManager;
  33.         $this->mailerCore $mailerCore;
  34.         $this->documentHandler $documentHandler;
  35.         $this->repo $repo;
  36.     }
  37.     #[Route('/'name'gh_cambio_contrato'methods: ['GET'])]
  38.     public function index(): Response
  39.     {
  40.         $procesoPersona $this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId();
  41.         //dump($procesoPersona);
  42.         $autoridadPersona $this->getUser()->getPersona()->getPerfilCargo()->getParNivelAutoridad()->getId();
  43.         //dump($autoridadPersona);
  44.         $idPersona $this->getUser()->getPersona()->getId();
  45.         //dump($idPersona);
  46.         if ($procesoPersona === || $autoridadPersona === ) {
  47.             $entities $this->repo->getAll([46535]);
  48.         } else {
  49.             $entities $this->repo->getAll([46535], $this->getUser()->getPersona()->getId());
  50.         }
  51.         return $this->render('gh_cambio_contrato/index.html.twig', [
  52.             'entities' => $entities,
  53.         ]);
  54.     }
  55.     #[Route('/gestionar'name'gh_cambio_contrato_gestionar'methods: ['GET'])]
  56.     public function gestionar(GHCambioContratoRepository $gHCambioContratoRepository): Response {
  57.         $entities $gHCambioContratoRepository->getAll([5]); //35
  58.         return $this->render('gh_cambio_contrato/index.html.twig', [
  59.             'entities' => $entities,
  60.         ]);
  61.     }
  62.     #[Route('/gh/periodo/prueba'name'gh_periodo_prueba_cambio')]
  63.     public function periodoPruebaIndex(GHPeriodoPruebaRepository $GHPeriodoPruebaRepository): Response {
  64.         $entities $GHPeriodoPruebaRepository->getAllMantenimiento([49,5,6], nulltrue);
  65.         return $this->render('gh_periodo_prueba/index.html.twig', [
  66.             'controller_name' => 'GHPeriodoPruebaController',
  67.             'entities' => $entities,
  68.         ]);
  69.     }
  70.     private function limpiarValorMonetario($valor): ?float
  71.     {
  72.         if (is_null($valor)) {
  73.             return null;
  74.         }
  75.         // Convertir a string si es número
  76.         $valorString = (string) $valor;
  77.         // Remover símbolo de pesos, puntos y espacios
  78.         $valorLimpio str_replace(['$''.'' '','], ''$valorString);
  79.         // Convertir a float
  80.         return is_numeric($valorLimpio) ? (int) $valorLimpio null;
  81.     }
  82.     public function validarCamposMoneda(GHCambioContrato $cambioContratoEntityManagerInterface $entityManagerFormInterface $form){
  83.         $camposMoneda = [
  84.             'salario' => 'setSalario',
  85.             'bonoSalarial' => 'setBonoSalarial',
  86.         ];
  87.         foreach ($camposMoneda as $campo => $valor) {
  88.             if($form->get($campo)->getData()){
  89.                 $cambioContrato->{$valor}(strval($this->limpiarValorMonetario($form->get($campo)->getData())));
  90.             }
  91.         }
  92.         $entityManager->persist($cambioContrato);
  93.     }
  94.     #[Route('/new'name'gh_cambio_contrato_new'methods: ['GET''POST'])]
  95.     public function new(Request $requestEntityManagerInterface $entityManager\App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore): Response {
  96.         // Validar al colaborador para saber el tipo de contrato
  97.         $idColaborador $request->request->get('gh_cambio_contrato')['colaborador'] ?? null;
  98.         // Buscar al colaborador
  99.         if($idColaborador){
  100.             $colaborador $entityManager->getRepository(TerPersona::class)->find($idColaborador);
  101.             // Si el tipo contrato es null, entonces no filtrar, mostrar TODOS
  102.             $idTipoContrato $colaborador && $colaborador->getPerfilCargo()?->getTipoContrato()?->first() ? $colaborador->getPerfilCargo()?->getTipoContrato()?->first()?->getId() : null;
  103.         }else{
  104.             $idTipoContrato null;
  105.         }
  106.         $gHCambioContrato = new GHCambioContrato();
  107.         $form $this->createForm(GHCambioContratoType::class, $gHCambioContrato, ['method' => 'POST''action' => $this->generateUrl($request->attributes->get('_route')),
  108.             'id_tipo_contrato' => $idTipoContrato]);
  109.         $form->remove('observacionAprobacion')
  110.             ->remove('fechaPeriodoPrueba')
  111.             ->remove('aproboPeriodoPrueba')
  112.             ->remove('estado')
  113.             ->remove('aprobacionGerenteDirector')
  114.         ;
  115.         $form
  116.             ->add('fechaFinPeriodoPrueba'\Symfony\Component\Form\Extension\Core\Type\DateTimeType::class, [
  117.                 'required' => false,
  118.                 'widget' => 'single_text',
  119.                 'html5' => false,
  120.                 'format' => 'yyyy-MM-dd',
  121.                 'attr' => [
  122.                     'class' => 'fc-datepicker'
  123.                 ],
  124.                 'label' => 'Fecha Fin Periodo Prueba'
  125.             ])
  126.         ;
  127.         $form->handleRequest($request);
  128.         if ($form->isSubmitted() && $form->isValid()) {
  129.             //verificar si el colaborador tiene cambios en proceso (ID #4)
  130.             $tieneProceso $entityManager->createQuery("
  131.                 SELECT COUNT(e.id)
  132.                 FROM App\Entity\GHCambioContrato cc
  133.                 JOIN cc.estado e
  134.                 WHERE cc.colaborador = :idColaborador
  135.                 AND e.id = 4 
  136.             ")
  137.                     ->setParameter('idColaborador'$gHCambioContrato->getColaborador()->getId())
  138.                     ->getSingleScalarResult() > 0;
  139.             //En caso de tener proceso arrancar advertencia y recargar módulo
  140.             if($tieneProceso){
  141.                 // $this->addFlash('warning', "El colaborador cuenta con un cambio de contrato que se encuentra actualmente proceso");
  142.                 $this->code 'warning';
  143.                 $this->msj "El colaborador cuenta con una solicitud actualmente En Proceso";
  144.                 return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  145.                 // return $this->redirectToRoute('gh_cambio_contrato_new');
  146.             }
  147.             $gHCambioContrato->setUsuarioSolicita($this->getUser()->getPersona());
  148.             //$gHCambioContrato->setCargo($gHCambioContrato->getColaborador()->getPerfilCargo()->getCargo()->getNombre());
  149.             // Validar campos moneda
  150.             $this->validarCamposMoneda($gHCambioContrato$entityManager$form);
  151.             // if ($this->getUser()->getPersona()->hasNivelDirector()) {
  152.             //     // si es admin notificar y autorizar. (SE PIDIO CAMBIAR ESTO PARA QUE SIEMPRE SEA 'EN PROCESO)
  153.             //     $gHCambioContrato->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(5));
  154.             //     $entityManager->persist($gHCambioContrato);
  155.             //     $entityManager->flush();
  156.             // } else {
  157.             $gHCambioContrato->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(4));
  158.             $entityManager->persist($gHCambioContrato);
  159.             $entityManager->flush();
  160.             // Validar que si la persona no es gerente o directo , envia este correo
  161.             $colaborador->getPerfilCargo()->getCargo()->getId();
  162.             $esGerenteDirector $this->getUser()->getPersona()->getPerfilCargo()?->getCargo()?->getId() ?? null;
  163.             if(!in_array($esGerenteDirector,[1,2,5,8,11,19,29])) // Validar los IDS gerentes, directores
  164.                 $mailerCore->cambioContrato('notificacion', [$gHCambioContrato]);
  165.             $mailerCore->cambioContrato('notificacionGH', [$gHCambioContrato]);
  166.             $this->code 'success';
  167.             $this->msj "Registro cargado exitosamente";
  168.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  169.         }
  170.         return $this->render('gh_cambio_contrato/new.html.twig', [
  171.             'gh_cambio_contrato' => $gHCambioContrato,
  172.             'form' => $form->createView(),
  173.         ]);
  174.     }
  175.     #[Route('/{id}/editar'name'gh_cambio_contrato_editar'methods: ['GET''POST'])]
  176.     public function editar(Request $requestGHCambioContrato $gHCambioContratoEntityManagerInterface $entityManager\App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore): Response {
  177.         if ($gHCambioContrato->getEstado()->getId() === 3) {
  178.             $this->code 'warning';
  179.             $this->msj "Registro ya procesado, imposible continuar.";
  180.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  181.         }
  182.         $form $this->createForm(GHCambioContratoType::class, $gHCambioContrato, [
  183.             'method' => 'POST',
  184.             'colaborador' => $gHCambioContrato->getColaborador(),
  185.             'action' => $this->generateUrl($request->attributes->get('_route'),
  186.                 [
  187.                     'id' => $gHCambioContrato->getId()
  188.                 ]),
  189.             'disabled_fields' => false,
  190.             // Perfil cargo de cambio contrato
  191.             'perfilCargo' => $gHCambioContrato->getCargo() ?? null
  192.         ]);
  193.         $form->remove('persona')
  194.             ->remove('fechaPeriodoPrueba')
  195.             ->remove('aproboPeriodoPrueba')
  196.             ->remove('estado')
  197.             ->remove('observacionAprobacion')
  198.             ->remove('aprobacionGerenteDirector')
  199.         ;
  200.         $form
  201.             ->add('fechaFinPeriodoPrueba'\Symfony\Component\Form\Extension\Core\Type\DateTimeType::class, [
  202.             'required' => false,
  203.             'widget' => 'single_text',
  204.             'html5' => false,
  205.             'format' => 'yyyy-MM-dd',
  206.             'attr' => [
  207.                 'class' => 'fc-datepicker'
  208.             ],
  209.             'label' => 'Fecha Fin Periodo Prueba'
  210.             ])
  211.         ;
  212.         $colaborador $gHCambioContrato->getColaborador();
  213.         $cargoTmp $colaborador?->getPerfilCargo()?->getCargo()?->getNombre() ?? 'N/A';
  214.         $empresaObj $colaborador->getEmpresa();
  215.         $empresaTmp $empresaObj?->getNombre() ?? 'N/A';
  216.         $candidato $entityManager->getRepository(GHCandidato::class)->findOneBy([
  217.             'numeroDocumento' => $colaborador->getNumeroDocumento()
  218.         ]);
  219.         $tipoContrato null;
  220.         $sucursal null;
  221.         $salario null;
  222.         if($candidato){
  223.             $salario $candidato->getContratacion() && $candidato->getContratacion()->last() ? $candidato->getContratacion()->last()->getSalario()  : 'N/A';
  224.             $sucursal $candidato->getVacante()->getSede() ? $candidato->getVacante()->getSede()->getNombre() : 'N/A';
  225.             $tipoContrato $candidato->getVacante()->getParTipoContrato() ? $candidato->getVacante()->getParTipoContrato()->getNombre() : 'N/A';
  226.         }
  227.         $form->get('cargoTmp')->setData($cargoTmp);
  228.         $form->get('salarioTmp')->setData($salario);
  229.         $form->get('empresaTmp')->setData($empresaTmp);
  230.         $form->get('sedeTmp')->setData($sucursal);
  231.         $form->get('tipoContratoTmp')->setData($colaborador->getTipoContrato() ? $colaborador->getTipoContrato()->getNombre() : ($tipoContrato ?? 'N/A'));
  232.         $form->handleRequest($request);
  233.         if ($form->isSubmitted() && $form->isValid()) {
  234.             $gHCambioContrato->setUpdateAt(new \DateTime('now'));
  235.             $gHCambioContrato->setUpdateUser($this->getUser()->getUsername());
  236.             // Actualizar el cambio de sucursal
  237.             if($form->get('sede')->getData() !== null){
  238.                 $gHCambioContrato->getColaborador()->setSede($entityManager->getRepository(\App\Entity\TerSedeEmpresa::class)->find($form->get('sede')->getData()));
  239.             }
  240.             // Validar campos moneda
  241.             $this->validarCamposMoneda($gHCambioContrato$entityManager$form);
  242.             $entityManager->flush();
  243.             if ($gHCambioContrato->getEstado()->getId() == 6) {
  244.                 $mailerCore->cambioContrato('rechazo', [$gHCambioContrato]);
  245.             }
  246.             $this->code 'success';
  247.             $this->msj "Registro cargado exitosamente.";
  248.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  249.         }
  250.         return $this->render('gh_cambio_contrato/editar.html.twig', [
  251.             'entity' => $gHCambioContrato,
  252.             'form' => $form->createView(),
  253.         ]);
  254.     }
  255.     #[Route('/{id}/confirmar_condiciones'name'gh_cambio_contrato_confirmar_condiciones'methods: ['GET''POST'])]
  256.     public function confirmarCondiciones(Request $requestGHCambioContrato $gHCambioContratoEntityManagerInterface $entityManager\App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore\App\Services\DocumentHandler $documentHandler): Response {
  257.         if ($gHCambioContrato->getEstado()->getId() == 6) {
  258.             $this->code 'warning';
  259.             $this->msj "Registro ya procesado, imposible continuar.";
  260.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  261.         }
  262.         $form $this->createForm(GHCambioContratoType::class, $gHCambioContrato, ['method' => 'POST''action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $gHCambioContrato->getId()]), 'disabled_fields' => true]);
  263.         $form->add('file'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  264.             'label' => 'Prueba Técnica',
  265.             'mapped' => false,
  266.             'required' => false,
  267.             'constraints' => [
  268.                 new File([
  269.                     'maxSize' => '5120k',
  270.                 ])
  271.             ]
  272.         ])
  273.             ->remove('colaborador')
  274.             ->remove('motivo')
  275.             ->remove('empresa')
  276.             ->remove('sede')
  277.             ->remove('aproboPeriodoPrueba')
  278.             ->remove('cambio')
  279.             ->remove('cargoTmp')
  280.             ->remove('salarioTmp')
  281.             ->remove('empresaTmp')
  282.             ->remove('sedeTmp')
  283.             ->remove('tipoContratoTmp')
  284.             ->remove('periodoPrueba')
  285.              ->remove('observacion')
  286.             ->remove('cargo')
  287.             ->remove('tipoContrato')
  288.         ;
  289.         /* if ($gHCambioContrato->getCargo()->getPerfilCargo()->getParCriticidad()->getId() == 1) { */
  290.         $form->add('file2'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  291.             'label' => 'Examen medico ocupacional',
  292.             'mapped' => false,
  293.             'required' => false,
  294.             'constraints' => [
  295.                 new File([
  296.                     'maxSize' => '5120k',
  297.                 ])
  298.             ]
  299.         ])
  300.             ->add('file3'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  301.                 'label' => 'Visita Domiciliaria',
  302.                 'mapped' => false,
  303.                 'required' => false,
  304.                 'constraints' => [
  305.                     new File([
  306.                         'maxSize' => '5120k',
  307.                     ])
  308.                 ]
  309.             ])
  310.             ->add('file4'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  311.                 'label' => 'Otro Si',
  312.                 'mapped' => false,
  313.                 'required' => false,
  314.                 'constraints' => [
  315.                     new File([
  316.                         'maxSize' => '5120k',
  317.                     ])
  318.                 ]
  319.             ])
  320.             ->add('file5'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  321.                 'label' => 'Cesión de Contrato',
  322.                 'mapped' => false,
  323.                 'required' => false,
  324.                 'constraints' => [
  325.                     new File([
  326.                         'maxSize' => '5120k',
  327.                     ])
  328.                 ]
  329.             ])
  330.             ->add('file6'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  331.                 'label' => 'Carta de Notificación',
  332.                 'mapped' => false,
  333.                 'required' => false,
  334.                 'constraints' => [
  335.                     new File([
  336.                         'maxSize' => '5120k',
  337.                     ])
  338.                 ]
  339.             ])
  340.             ->add('fechaNovedad'\Symfony\Component\Form\Extension\Core\Type\DateTimeType::class, ['required' => false'widget' => 'single_text''html5' => false'format' => 'yyyy-MM-dd''attr' => ['class' => 'fc-datepicker'], 'label' => 'Fecha Novedad'])
  341.             ->add('entrevistaJefe'null, ['required' => false'label' => 'Entrevista Jefe Inmediato'])
  342.             ->add('resultadoPruebaTecnica'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['label' => 'Concepto Prueba Técnica','required' => false'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione una opción'])
  343.             ->add('resultadoExamenMedico'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['label' => 'Concepto Examen Médico','required' => false'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione una opción'])
  344.             ->add('resultadoVisitaDomiciliaria'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['label' => 'Concepto Visita Domiciliaria','required' => false'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione una opción'])
  345.             ->add('resultadoCarta'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['label' => 'Concepto Entrevista Jefe Inmediato','required' => false'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione una opción'])
  346.         ;
  347.         if (null == $gHCambioContrato->getCargo()){
  348.             $form->remove('entrevistaJefe');
  349.         }
  350.         $form->handleRequest($request);
  351.         if ($form->isSubmitted() && $form->isValid()) {
  352.             $colaborador $gHCambioContrato->getColaborador();
  353.             $pruebaTecnica $form->get('file')->getData();
  354.             $examen $form->get('file2')->getData();
  355.             $visita $form->get('file3')->getData();
  356.             $contrato null;
  357.             $otrosi $form->get('file4')->getData();
  358.             $carta null;
  359.             $cesion $form->get('file5')->getData();
  360.             $carta $form->get('file6')->getData();
  361.             if ($pruebaTecnica) {
  362.                 $rutaArchivo $documentHandler->cargarArchivo($pruebaTecnicaGHCambioContrato::class);
  363.                 if ($rutaArchivo['code'] != 'success') {
  364.                     $this->code 'warning';
  365.                     $this->msj "Imposible continuar, valide la Prueba Técnica, {$rutaArchivo['msj']}";
  366.                     return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  367.                 }
  368.                 $gHCambioContrato->setPruebaTecnica($rutaArchivo['msj']);
  369.             }
  370.             if ($examen) {
  371.                 $rutaArchivo $documentHandler->cargarArchivo($examenGHCambioContrato::class);
  372.                 if ($rutaArchivo['code'] != 'success') {
  373.                     $this->code 'warning';
  374.                     $this->msj "Imposible cargar el registro examen medico, {$rutaArchivo['msj']}";
  375.                     return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  376.                 }
  377.                 $gHCambioContrato->setExamenMedico($rutaArchivo['msj']);
  378.             }
  379.             if ($visita) {
  380.                 $rutaArchivo $documentHandler->cargarArchivo($visitaGHCambioContrato::class);
  381.                 if ($rutaArchivo['code'] != 'success') {
  382.                     $this->code 'warning';
  383.                     $this->msj "Imposible cargar el registro visita domiciliaria, {$rutaArchivo['msj']}";
  384.                     return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  385.                 }
  386.                 $gHCambioContrato->setVisitaDomiciliaria($rutaArchivo['msj']);
  387.             }
  388.             if ($otrosi) {
  389.                 $rutaArchivo $documentHandler->cargarArchivo($otrosiGHCambioContrato::class);
  390.                 if ($rutaArchivo['code'] != 'success') {
  391.                     $this->code 'warning';
  392.                     $this->msj "Imposible cargar el otro si, {$rutaArchivo['msj']}";
  393.                     return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  394.                 }
  395.                 $gHCambioContrato->setOtroSi($rutaArchivo['msj']);
  396.             }
  397.             if ($cesion) {
  398.                 $rutaArchivo $documentHandler->cargarArchivo($cesionGHCambioContrato::class);
  399.                 if ($rutaArchivo['code'] != 'success') {
  400.                     $this->code 'warning';
  401.                     $this->msj "Imposible cargar la cesion de contrato, {$rutaArchivo['msj']}";
  402.                     return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  403.                 }
  404.                 $gHCambioContrato->setCesionContrato($rutaArchivo['msj']);
  405.             }
  406.             if ($carta) {
  407.                 $rutaArchivo $documentHandler->cargarArchivo($cartaGHCambioContrato::class);
  408.                 if ($rutaArchivo['code'] != 'success') {
  409.                     $this->code 'warning';
  410.                     $this->msj "Imposible cargar la carta de notificación, {$rutaArchivo['msj']}";
  411.                     return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  412.                 }
  413.                 $gHCambioContrato->setCartaNotificacion($rutaArchivo['msj']);
  414.             }
  415.             // Guardar la ruta de lois archivos en base de datos.
  416.             $entityManager->persist($gHCambioContrato);
  417.             $entityManager->flush();
  418. //            if ($gHCambioContrato->getEstado() && $gHCambioContrato->getEstado()->getId() === 35) {
  419. //                $colaborador = $entityManager->getRepository(TerPersona::class)->find($gHCambioContrato->getColaborador()->getId());
  420. //
  421. //                if ($colaborador && $colaborador->getPerfilCargo()) {
  422. //                    $cargoActual = $colaborador->getPerfilCargo()->getCargo();
  423. //                    $cargoActualizado = $gHCambioContrato->getCargo()?->getCargo();
  424. //
  425. //                    if ($cargoActual && $cargoActualizado && $cargoActual->getId() !== $cargoActualizado->getId()) {
  426. //                        $colaborador->getPerfilCargo()->setCargo($cargoActualizado);
  427. //                    }
  428. //
  429. //                    $salarioActual = $colaborador->getPerfilCargo()->getRangoSalarial();
  430. //                    $salarioActualizado = $gHCambioContrato->getSalario();
  431. //
  432. //                    if ($salarioActual && $salarioActualizado && $salarioActual != $salarioActualizado) {
  433. //                        $colaborador->getPerfilCargo()->setRangoSalarial($salarioActualizado);
  434. //                    }
  435. //
  436. //                    $empresaActual = $colaborador->getPerfilCargo()->getEmpresaFilial();
  437. //                    $empresaActualizado = $gHCambioContrato->getEmpresa();
  438. //
  439. //                    if ($empresaActual && $empresaActualizado && $empresaActual->first()->getId() !== $empresaActualizado->getId()) {
  440. //                        $colaborador->getPerfilCargo()->addEmpresaFilial($empresaActualizado);
  441. //                    }
  442. //
  443. //                    $sucursalActual = $colaborador->getPerfilCargo()->getSede();
  444. //                    $sucursalActualizado = $gHCambioContrato->getSede();
  445. //
  446. //                    if ($sucursalActual && $sucursalActualizado && $sucursalActual->first()->getId() !== $sucursalActualizado->getId()) {
  447. //                        $colaborador->getPerfilCargo()->addSede($sucursalActualizado);
  448. //                    }
  449. //
  450. //                    $tipoContratoActual = $colaborador->getPerfilCargo()->getTipoContrato();
  451. //                    $tipoContratoActualizado = $gHCambioContrato->getTipoContrato();
  452. //
  453. //                    if ($tipoContratoActual && $tipoContratoActualizado && $tipoContratoActual->first()->getId() !== $tipoContratoActualizado->getId()) {
  454. //                        $colaborador->getPerfilCargo()->addTipoContrato($tipoContratoActualizado);
  455. //                    }
  456. //                    $colaborador->setUpdateAt(new \DateTime());
  457. //                    $colaborador->setUpdateUser($this->getUser()->getUsername());
  458. //                    $entityManager->persist($colaborador);
  459. //                    $entityManager->flush();
  460. //                }
  461. //            }
  462.             // Validar que solo valido el estado EJECUTADO
  463.             if($gHCambioContrato->getEstado()->getId() == 35) {
  464.                 dump($gHCambioContrato);
  465.                 // Actualizar sede
  466.                 if($gHCambioContrato->getSede()) {
  467.                     $colaborador->setSede($gHCambioContrato->getSede());
  468.                 }
  469.                 // Actualizar Salario
  470.                 if($gHCambioContrato->getSalario()){
  471.                     $colaborador->setSalario("$".number_format(intval($gHCambioContrato->getSalario()),0,',','.')); // Guardar $25.500.500
  472.                 }
  473.                 // Cambio tipo contrato
  474.                 if($gHCambioContrato->getTipoContrato()) {
  475.                     $colaborador->setTipoContrato($gHCambioContrato->getTipoContrato());
  476.                 }
  477.                 // Cambio empresa
  478.                 if($gHCambioContrato->getEmpresa()){
  479.                     $colaborador->setEmpresa($gHCambioContrato->getEmpresa());
  480.                 }
  481.                 $entityManager->persist($colaborador);
  482.                 $entityManager->flush();
  483.             }
  484.             if ($gHCambioContrato->getPeriodoPrueba() && $gHCambioContrato->getEstado()->getId() == 35) {
  485.                 $periodoPrueba = new \App\Entity\GHPeriodoPrueba();
  486.                 $periodoPrueba->setPersona($gHCambioContrato->getColaborador());
  487.                 $periodoPrueba->setFechaIngreso($gHCambioContrato->getFechaNovedad());
  488.                 // $periodoPrueba->setFechaFinPeriodo($gHCambioContrato->getFechaFinPeriodoPrueba());
  489. //                $periodoPrueba->setCreateAt(new \DateTime('now'));
  490. //                $periodoPrueba->setCreateUser($this->getUser()->getUsername());
  491. //                $periodoPrueba->setUpdateAt(new \DateTime('now'));
  492. //                $periodoPrueba->setUpdateUser($this->getUser()->getUsername());
  493.                 $periodoPrueba->setEstado($entityManager->getRepository(ParEstado::class)->find(49));
  494.                 $periodoPrueba->setModuloMantenimiento(true);
  495.                 $cambioContrato $entityManager->getRepository(GHPeriodoPrueba::class)->findOneBy([
  496.                     'cambioContrato' => $gHCambioContrato,
  497.                 ]);
  498.                 if(!$cambioContrato)
  499.                     $periodoPrueba->setCambioContrato($gHCambioContrato);
  500.                 // Validar a la persona el cambio de proceso
  501.                 if($gHCambioContrato->getCargo()) {
  502.                     $colaborador->setPerfilCargo($gHCambioContrato->getCargo());
  503.                 }
  504.                 $entityManager->persist($periodoPrueba);
  505.                 $entityManager->persist($colaborador);
  506.                 $entityManager->flush();
  507.                 $this->code 'success';
  508.                 $this->msj "Registro cargado exitosamente.";
  509.                 return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  510.             }
  511. //            dump($gHCambioContrato->getCargo());
  512. //            dump($gHCambioContrato->getColaborador());
  513.             $this->code 'success';
  514.             $this->msj "Registro cargado exitosamente.";
  515.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  516.         }
  517.         return $this->render('gh_cambio_contrato/confirmarCondiciones.html.twig', [
  518.             'entity' => $gHCambioContrato,
  519.             'form' => $form->createView(),
  520.         ]);
  521.     }
  522.     #[Route('/{id}/ver'name'gh_cambio_contrato_ver')]
  523.     public function ver(Request $requestGHCambioContrato $gHCambioContratoEntityManagerInterface $entityManager\App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore\App\Services\DocumentHandler $documentHandler): Response {
  524.         if ($gHCambioContrato->getEstado()->getId() == 6) {
  525.             $this->code 'warning';
  526.             $this->msj "Registro ya procesado, imposible continuar.";
  527.             return new Response(json_encode(['code' => $this->code'msj' => $this->msj'url' => $this->url'html' => $this->html]));
  528.         }
  529.         $colaborador $gHCambioContrato->getColaborador();
  530.         $cambios $entityManager->getRepository(\App\Entity\GHCambioContrato::class)->findBy(['colaborador' => $colaborador->getId()]);
  531.         $form $this->createForm(GHCambioContratoType::class, $gHCambioContrato, ['method' => 'POST''action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $gHCambioContrato->getId()]), 'disabled_fields' => true]);
  532.         // Validar si el colaborador fue en algun momento vacante
  533.         $candidato $entityManager->getRepository(GHCandidato::class)->findOneBy([
  534.             'numeroDocumento' => $colaborador->getNumeroDocumento()
  535.         ]);
  536.         $salario null;
  537.         $tipoContrato null;
  538.         $sucursal null;
  539.         if($candidato){
  540.             $salario $candidato->getContratacion() && $candidato->getContratacion()->last() ? $candidato->getContratacion()->last()->getSalario()  : 'N/A';
  541.             $tipoContrato $candidato->getVacante()->getParTipoContrato() ? $candidato->getVacante()->getParTipoContrato()->getNombre() : 'N/A';
  542.             $sucursal $candidato->getVacante()->getSede() ? $candidato->getVacante()->getSede()->getNombre() : 'N/A';
  543.         }
  544.         // Sigue actualizando los campos visibles si deseas:
  545.         $cargo $colaborador?->getPerfilCargo()?->getCargo()?->getNombre() ?? 'N/A';
  546.         $salario $colaborador->getSalario() ? $colaborador->getSalario() : ($salario ?? 'N/A'); // Validar si encontro registro de salario desde la contratacion
  547.         $empresaObj $colaborador?->getEmpresa();
  548.         $empresa $empresaObj $empresaObj->getNombre() : 'N/A';
  549.         $tipoContrato $colaborador->getTipoContrato() ? $colaborador->getTipoContrato()->getNombre() : ($tipoContrato ?? 'N/A');
  550.         // Comprimir la info de el colaborador
  551.         $colaboradorInfoVer = [
  552.             'empresa' => $empresa,
  553.             'cargo' => $cargo,
  554.             'salario' => $salario,
  555.             'tipoContrato' => $tipoContrato,
  556.             'sucursal' => ($colaborador->getSede() ? $colaborador->getSede()->getNombre() : ($sucursal ?? 'N/A')),
  557.         ];
  558.         $form->add('file'\Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  559.             'label' => 'Prueba Técnica',
  560.             'mapped' => false,
  561.             'required' => true,
  562.             'constraints' => [
  563.                 new File([
  564.                     'maxSize' => '5120k',
  565.                 ])
  566.             ]
  567.         ])
  568.             ->remove('colaborador')
  569.             ->remove('sede')
  570.             ->remove('tipoContrato')
  571.             ->remove('aproboPeriodoPrueba')
  572.             ->remove('cambio')
  573.             ->remove('cargoTmp')
  574.             ->remove('salarioTmp')
  575.             ->remove('empresaTmp')
  576.             ->remove('sedeTmp')
  577.             ->remove('tipoContratoTmp')
  578.             ->remove('periodoPrueba')
  579.             ->remove('observacionAprobacion')
  580.             ->remove('fechaPeriodoPrueba')
  581.             ->remove('salario')
  582.             ->remove('bonoSalarial')
  583.             ->remove('cargo')
  584.             ->remove('estado');
  585.             $form
  586.                 ->add('fechaNovedad'\Symfony\Component\Form\Extension\Core\Type\DateTimeType::class, ['required' => true'widget' => 'single_text''html5' => false'format' => 'yyyy-MM-dd''attr' => ['class' => 'fc-datepicker'], 'label' => 'Fecha Novedad''disabled' => true])
  587.                 ->add('entrevistaJefe'null, ['required' => true'label' => 'Entrevista Jefe Inmediato''disabled' => true])
  588.                 ->add('resultadoPruebaTecnica'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['required' => true'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione un Concepto''disabled' => true])
  589.                 ->add('resultadoExamenMedico'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['required' => true'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione un Concepto''disabled' => true])
  590.                 ->add('resultadoVisitaDomiciliaria'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['required' => true'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione un Concepto''disabled' => true])
  591.                 ->add('resultadoCarta'\Symfony\Component\Form\Extension\Core\Type\ChoiceType::class, ['required' => true'choices' => ['Aprobado' => 'Aprobado''Rechazado' => 'Rechazado'], 'placeholder' => 'Seleccione un Concepto''disabled' => true])
  592.                 ->add('estado'\Symfony\Bridge\Doctrine\Form\Type\EntityType::class, ['class' => \App\Entity\ParEstado::class, 'query_builder' => function (\Doctrine\ORM\EntityRepository $er) {
  593.                 return $er->createQueryBuilder('e')
  594.                     ->where('e.id in (4,35,6)')
  595.                     ->orderBy('e.nombre''ASC');
  596.                 }, 'label' => 'Estado',
  597.                     'placeholder' => 'Seleccione una Opción.',
  598.                     'disabled' => true,
  599.                     'attr' => ['class' => 'form-control']])
  600.         ;
  601.         return $this->render('gh_cambio_contrato/ver.html.twig', [
  602.             'entity' => $gHCambioContrato,
  603.             'cambios' => $cambios,
  604.             'form' => $form->createView(),
  605.             'colaboradorInfoVer' => $colaboradorInfoVer,
  606.         ]);
  607.     }
  608.     #[Route('/gh/periodo_prueba/editar/{id}'name'gh_periodo_prueba_edit_cambio')]
  609.     public function editarPeriodoPrueba(Request $requestGHPeriodoPrueba $periodoPrueba,EntityManagerInterface $entityManager,  \App\Services\ResponseHandler $responseHandler\App\Services\MailerCore $mailerCore): Response {
  610.         if (!$periodoPrueba) {
  611.             throw $this->createNotFoundException('No se encontró el período de prueba.');
  612.         }
  613.         $referencia $periodoPrueba->getPersona()?->getNombres() ?? 'Sin nombre';
  614.         $form $this->createForm(GHPeriodoPruebaType::class, $periodoPrueba, [
  615.             'method' => 'POST',
  616.             'action' => $this->generateUrl('gh_periodo_prueba_edit', [
  617.                 'id' => $periodoPrueba->getId(),
  618.             ])
  619.         ]);
  620.         $form->handleRequest($request);
  621.         if ($form->isSubmitted() && $form->isValid()) {
  622.             $periodoPrueba->setUpdateAt(new \DateTime('now'));
  623.             $periodoPrueba->setUpdateUser($this->getUser()->getUsername());
  624.             // Limpiar el valor de porcentaje
  625.             $valor $form->get('porcentajeTotal')->getData();
  626.             $valorLimpio intval(str_replace('%'''$valor));
  627.             $periodoPrueba->setPorcentajeTotal($valorLimpio);
  628.             $estado $entityManager->getRepository(\App\Entity\ParEstado::class)
  629.                 ->find($periodoPrueba->getPorcentajeTotal() < 80 5);
  630.             $periodoPrueba->setEstado($estado);
  631.             $nombreArchivo uniqid() . ".pdf";
  632.             $periodoPrueba->setCarta($nombreArchivo);
  633.             $entityManager->persist($periodoPrueba);
  634.             $entityManager->flush();
  635. //            // Logo como imagen base64
  636. //            $path = $this->getParameter('kernel.project_dir') . '/public_html/assets/img/brand/logos-empresas.png';
  637. //            $type = pathinfo($path, PATHINFO_EXTENSION);
  638. //            $data = file_get_contents($path);
  639. //            $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
  640. //            $html = $this->renderView('formatos/calificacionPeriodoPrueba.html.twig', [
  641. //                'logo' => $base64,
  642. //                'entity' => $periodoPrueba
  643. //            ]);
  644. //            $dompdf = new Dompdf();
  645. //            $dompdf->setPaper([0, 0, 220, 130]);
  646. //            $dompdf->loadHtml($html);
  647. //            $dompdf->render();
  648. //
  649. //            $output = $dompdf->output();
  650. //            $ruta = $this->getParameter('kernel.project_dir') . "/public_html/Repository/GHPeriodoPrueba/$nombreArchivo";
  651. //            file_put_contents($ruta, $output);
  652.             if ($estado->getId() === 6) {
  653.                 $mailerCore->periodoPrueba('rechazo', [$periodoPrueba]);
  654.             }
  655.             $this->code 'success';
  656.             $this->msj "Registro cargado exitosamente.";
  657.             return new Response(json_encode([
  658.                 'code' => $this->code,
  659.                 'msj' => $this->msj,
  660.                 'url' => $this->url,
  661.                 'html' => $this->html
  662.             ]));
  663.         }
  664.         return $this->render('gh_cambio_contrato/peridoPruebaCambio.html.twig', [
  665.             'entity' => $periodoPrueba,
  666.             'form' => $form->createView(),
  667.             'referencia' => $referencia,
  668.         ]);
  669.     }
  670.     #[Route('/gh/periodo_prueba/imprimir/{id}'name'gh_periodo_prueba_cambio_imprimir'methods: ['GET'])]
  671.     public function imprimir(EntityManagerInterface $entityManagerGHPeriodoPrueba $periodoPrueba\App\Services\ResponseHandler $responseHandler): Response {
  672.         if ($periodoPrueba->getEstado() == null) {
  673.             $this->addFlash('warning'"No es posible imprimir, no se ha registrado la calificación");
  674.             return $this->redirectToRoute($responseHandler->manejoRespuesta());
  675.         }
  676.         $path $this->getParameter('kernel.project_dir') . '/public_html/assets/img/brand/logos-empresas.png';
  677.         $type pathinfo($pathPATHINFO_EXTENSION);
  678.         $data file_get_contents($path);
  679.         $base64 'data:image/' $type ';base64,' base64_encode($data);
  680.         $rutaLogo $base64;
  681.         // Validar la persona que ejecuto la calificacion del periodo de prueba
  682.         $usuario null;
  683.         if(str_contains($periodoPrueba->getUpdateUser(),"(")) // Validar que no tenga caracteres
  684.             $usuario strstr($periodoPrueba->getUpdateUser(),"(",true);
  685.         $personaCalifica $entityManager->getRepository(TerPersona::class)->findOneBy([
  686.             'nombres' => $usuario
  687.         ]);
  688.         // validar que encontro una persona
  689.         if(!$personaCalifica) {
  690.             Throw $this->createNotFoundException("¡Error al generar PDF!");
  691.         }
  692.         $html $this->renderView('formatos/periodoPrueba.html.twig', [
  693.             'logo' => $rutaLogo,
  694.             'entity' => $periodoPrueba,
  695.             'personaCalifica' => $personaCalifica,
  696.         ]);
  697.         $dompdf = new Dompdf();
  698.         //$customPaper = array(0, 0, 220, 130);
  699.         //$dompdf->setPaper($customPaper);
  700.         $dompdf->loadHtml($html);
  701.         $dompdf->render();
  702.         return new Response(
  703.             $dompdf->stream('resume', ["Attachment" => false]),
  704.             Response::HTTP_OK,
  705.             ['Content-Type' => 'application/pdf']
  706.         );
  707.     }
  708. //    #[Route('/gh/periodo_prueba_cambio/otro_si/{id}', name: 'gh_periodo_prueba_cambio_otro_si')]
  709. //    public function otrosiPeriodoPrueba(EntityManagerInterface $entityManager, $id, \App\Services\ResponseHandler $responseHandler, \App\Services\DocumentHandler $documentHandler): Response {
  710. //
  711. //        $periodoPrueba = $entityManager->getRepository(GHPeriodoPrueba::class)->find($id);
  712. //
  713. //        if (!$periodoPrueba) {
  714. //            throw $this->createNotFoundException('');
  715. //        }
  716. //        if ($periodoPrueba->getEstado() == null || $periodoPrueba->getEstado()->getId() != 5) {
  717. //
  718. //            $this->code = 'warning';
  719. //            $this->msj = "Imposible continuar, el periodo de prueba no fue aprobado.";
  720. //            return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
  721. //            //  $this->addFlash('danger', "Imposible continuar, el periodo de prueba no fue aprobado.");
  722. //            //   return $this->redirectToRoute($responseHandler->manejoRespuesta());
  723. //        }
  724. //
  725. //        $referencia = $periodoPrueba->getPersona()->getNombres();
  726. //
  727. //        $form = $this->createForm(GHPeriodoPruebaType::class, $periodoPrueba, ['disabled_fields' => true, 'method' => 'POST', 'action' => $this->generateUrl($request->attributes->get('_route'),['id'=>$periodoPrueba->getId()]  )]);
  728. //        $form->add('file', \Symfony\Component\Form\Extension\Core\Type\FileType::class, [
  729. //            'label' => 'Otro Si',
  730. //            'mapped' => false,
  731. //            'required' => true,
  732. //            'constraints' => [
  733. //                new File([
  734. //                    'maxSize' => '5120k',
  735. //                ])
  736. //            ]
  737. //        ]);
  738. //        $form->handleRequest($request);
  739. //
  740. //        if ($form->isSubmitted() && $form->isValid()) {
  741. //            $otroSi = $form->get('file')->getData();
  742. //            if ($otroSi) {
  743. //                $rutaArchivo = $documentHandler->cargarArchivo($otroSi, GHPeriodoPrueba::class);
  744. //                if ($rutaArchivo['code'] == 'success') {
  745. //                    $periodoPrueba->setOtrosi($rutaArchivo['msj']);
  746. //                }
  747. //
  748. //                $periodoPrueba->setUpdateAt(new \DateTime('now'));
  749. //                $periodoPrueba->setUpdateUser($this->getUser()->getUsername());
  750. //
  751. //                $entityManager->flush();
  752. //                $this->code = 'success';
  753. //                $this->msj = "Registro cargado exitosamente.";
  754. //                return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
  755. //
  756. //                //              $this->addFlash('success', "Registro cargado exitosamente.");
  757. //                //              return $this->redirectToRoute($responseHandler->manejoRespuesta());
  758. //            } else {
  759. //                $this->addFlash('danger', "Imposible continuar, valide el otro si.");
  760. //            }
  761. //
  762. //            return $this->redirectToRoute($responseHandler->manejoRespuesta());
  763. //        }
  764. //
  765. //        return $this->render('gh_cambio_contrato/peridoPruebaCambio.html.twig', [
  766. //            'entity' => $periodoPrueba,
  767. //            'form' => $form->createView(),
  768. //            'referencia' => $referencia,
  769. //        ]);
  770. //    }
  771. }