src/Controller/AspirantesController.php line 471

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use App\Entity\Recluta;
  7. use App\Entity\ReclutaProceso;
  8. //use App\Entity\ReclutaProcesoPregunta;
  9. use App\Entity\TestReclutaProcesoPregunta;
  10. use App\Entity\NmclDominioLocalizacion;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use App\Enum\VolverPresentarseEnum;
  13. use App\Enum\CausaNoIdoneoEnum;
  14. class AspirantesController extends RegistrantesController
  15. {
  16.     protected $procesoActivo null;
  17.     
  18.     public function registroLineaAction()
  19.     {
  20.         $em $this ->em;
  21.         
  22.         $allow=true;
  23.         $msg='';
  24.         if (!$this->procesoActivo)
  25.         {
  26.             $this->procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  27.                                                 ->createQueryBuilder('p')
  28.                                                 ->where('p.activo=true')
  29.                                                 ->getQuery()->getOneOrNullResult();
  30.         }
  31.         $procesoActivo $this->procesoActivo;
  32.         if (!$procesoActivo)
  33.         {
  34.             $allow=false;
  35.             $msg 'No hay ningĂșn proceso activo para el registro';
  36.         }
  37.         else
  38.         {
  39.             $hoy = new \DateTime();
  40.             if ($hoy<$procesoActivo->getFechaInicioRegistro() || $hoy>$procesoActivo->getFechaFinRegistro())
  41.             {
  42.                 $allow=false;
  43.                 $msg 'El perĂ­odo de registro es desde '.$procesoActivo->getFechaInicioRegistro()->format('d/m/Y H:m').' hasta '.$procesoActivo->getFechaFinRegistro()->format('d/m/Y H:m');
  44.             }
  45.         }
  46.         
  47.         if (!$allow)
  48.         {
  49.             return $this->render('Aspirantes/registroenlinea.html.twig'
  50.                 array('allow'=>$allow'msg'=>$msg'tiempoTest'=>0'distintivo'=>''));
  51.         }    
  52.         
  53.         $regiones $em->getRepository('App\\Entity\\NmclDominioLocalizacion')
  54.                                                 ->createQueryBuilder('r')
  55.                                                 ->leftJoin('r.nivelLocalizacion','nivel')
  56.                                                 ->leftJoin('nivel.localizacion','localizacion')
  57.                                                 ->where('localizacion.id=1')
  58.                                                 ->andWhere('nivel.nivel=1')
  59.                                                 ->orderBy('r.valor')
  60.                                                 ->getQuery()->getResult();
  61.         
  62.         $provincias $em->getRepository('App\\Entity\\NmclDominioLocalizacion')
  63.                                                 ->createQueryBuilder('r')
  64.                                                 ->leftJoin('r.nivelLocalizacion','nivel')
  65.                                                 ->leftJoin('nivel.localizacion','localizacion')
  66.                                                 ->where('localizacion.id=1')
  67.                                                 ->andWhere('nivel.nivel=2')
  68.                                                 ->orderBy('r.valor')
  69.                                                 ->getQuery()->getResult();
  70.         
  71.         $cantones $em->getRepository('App\\Entity\\NmclDominioLocalizacion')
  72.                                                 ->createQueryBuilder('r')
  73.                                                 ->leftJoin('r.nivelLocalizacion','nivel')
  74.                                                 ->leftJoin('nivel.localizacion','localizacion')
  75.                                                 ->where('localizacion.id=1')
  76.                                                 ->andWhere('nivel.nivel=3')
  77.                                                 ->orderBy('r.valor')
  78.                                                 ->getQuery()->getResult();
  79.         
  80.         $parroquias $em->getRepository('App\\Entity\\NmclDominioLocalizacion')
  81.                                                 ->createQueryBuilder('r')
  82.                                                 ->leftJoin('r.nivelLocalizacion','nivel')
  83.                                                 ->leftJoin('nivel.localizacion','localizacion')
  84.                                                 ->where('localizacion.id=1')
  85.                                                 ->andWhere('nivel.nivel=4')
  86.                                                 ->orderBy('r.valor')
  87.                                                 ->getQuery()->getResult();
  88.         
  89.         $tiempoTest $procesoActivo->getMinutosTest();
  90.         
  91. /*        $preguntasProcesoActivo =  $em->getRepository('App\\Entity\\ProcesoReclutamientoPregunta')
  92.                                                 ->createQueryBuilder('r')
  93.                                                 ->leftJoin('r.proceso', 'proceso')
  94.                                                 ->leftJoin('r.pregunta', 'pregunta')
  95.                                                 ->where('proceso.activo=true')
  96.                                                 ->select('pregunta.id')
  97.                                                 ->getQuery()->getDql();
  98.         $preguntasTest = $em->getRepository('App\\Entity\\PreguntaTest')
  99.                                                 ->createQueryBuilder('p')
  100.                                                 ->leftJoin('p.etapa', 'etapa')
  101.                                                 ->orderBy('etapa.orden')
  102.                                                 ->where('p.id in ('.$preguntasProcesoActivo.')')
  103.                                                 ->getQuery()->getResult();
  104. */        
  105.         $preguntasTest $em->getRepository('App\\Entity\\TestPregunta')
  106.                                                 ->createQueryBuilder('p')
  107.                                                 ->innerJoin('p.criterio''criterio')
  108.                                                 ->innerJoin('criterio.eje''eje')
  109.                                                 ->innerJoin('eje.sistema''sistema')
  110.                                                 ->innerJoin('sistema.proceso''proceso')
  111.                                                 ->where('proceso.activo = true')
  112.                                                 ->getQuery()->getResult();
  113.         shuffle($preguntasTest);
  114.  
  115.         return  $this->render(
  116.                     'Aspirantes/registroenlinea.html.twig'
  117.                     array(
  118.                         'allow'               => $allow'regiones'=>$regiones'provincias'=>$provincias,
  119.                         'cantones'            => $cantones,'parroquias'=>$parroquias,
  120. //                        'centrosMovilizacion' => $centrosMovilizacion,
  121.                         'preguntas'           => $preguntasTest,
  122.                         'tiempoTest'          => $tiempoTest,
  123.                         'distintivo'          => '',
  124.                         'proceso'             => $procesoActivo,
  125.                     )
  126.                 );
  127.     }
  128.     
  129.     public function verificaIdentidadAction($identificacion)
  130.     {
  131.         
  132.         $data = array('ok'=>true'idoneo'=>true);
  133.         $em $this ->em;
  134.         if (!$this->procesoActivo)
  135.         {
  136.             $this->procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  137.                                                 ->createQueryBuilder('p')
  138.                                                 ->where('p.activo=true')
  139.                                                 ->getQuery()->getOneOrNullResult();
  140.         }
  141.         $procesoActivo $this->procesoActivo;
  142.         
  143.         $recluta $em->getRepository('App\\Entity\\Recluta')->findOneBy(array('identificacion'=>$identificacion));
  144.         if ($recluta)
  145.         {
  146.             $ret $this->puedeRegistrarse($recluta$procesoActivo);
  147.             
  148. //            $data['idoneo'] = true;   //WILLY: Usar esta linea para probar sin usar los servicios
  149.             $data['idoneo'] = $ret['ok'];  
  150.             $data['msg'] = $ret['msg'];
  151.             $data['causa'] = $ret['causa'];
  152.             $data['reclutaID']=$recluta->getId();
  153.             
  154.             $data['procesoId'] = $ret['procesoId'];
  155.             
  156.             /*if($ret['causa']=='registrado')
  157.                 return $this->redirect($this->generateUrl('crud_plain_show', array('routeClassName'=>'reclutaproceso', 'id'=>$ret['procesoId'])));
  158.             */
  159.             
  160.             $data['cedula']=$recluta->getIdentificacion();
  161.             $data['nombres']=$recluta->getNombres(); 
  162.             $data['apellidoP']=$recluta->getApellidoPaterno(); 
  163.             $data['apellidoM']=$recluta->getApellidoMaterno();
  164.             $data['edad']=$recluta->getEdad();
  165.             $data['edadString']=$recluta->getEdadString();
  166.             $data['sexo']=$recluta->getSexo();
  167.             $data['estadoCivil']=$recluta->getEstadoCivil();
  168.             $data['estatura']=$recluta->getEstatura();
  169.             $data['telefono']=$recluta->getTelefono();
  170.             $data['telefonoEmergencias']=$recluta->getTelefonoEmergencias();
  171.             $data['email']=$recluta->getEmail();            
  172.             $data['fechaNacimiento']=$recluta->getFechaNacimiento()->format('d/m/Y');
  173.             $data['paisNacimiento']=$recluta->getPaisNacimiento();
  174.             $data['email']=$recluta->getEmail();
  175.             $data['telefono']=$recluta->getTelefono();
  176.             if ($recluta->getLugarNacimiento())
  177.             {
  178.                 $data['parroquiaNacimiento']=$recluta->getLugarNacimiento();
  179.                 $data['cantonNacimiento']=$data['parroquiaNacimiento']->getDominioPadre();
  180.                 $data['provinciaNacimiento']=$data['cantonNacimiento']->getDominioPadre();
  181.                 $data['regionNacimiento']=$data['provinciaNacimiento']->getDominioPadre();
  182.                 $data['parroquiaNacimiento']=$data['parroquiaNacimiento']->__toString();
  183.                 $data['cantonNacimiento']=$data['cantonNacimiento']->__toString();
  184.                 $data['provinciaNacimiento']=$data['provinciaNacimiento']->__toString();
  185.                 $data['regionNacimiento']=$data['regionNacimiento']->__toString();
  186.             }
  187.         }    
  188.         
  189.         if ($data['idoneo'])
  190.         {
  191. //            if (true)  //WILLY: Usar esta lĂ­nea para probar sin usar los servicios
  192.             if ($this->verificaIdentidad($data$identificacion$procesoActivo->getFechaAcuartelamiento()))
  193.             { 
  194. //                if (true)  //WILLY: Usar esta lĂ­nea para probar sin usar los servicios
  195.                 if (false)
  196.                 {
  197.                     $data['cedula'] = $identificacion;
  198.                     $data['nombres'] = 'nombres';
  199.                     $data['fechaNacimiento'] = '04/12/1972';
  200.                     $data['edad'] = '20';
  201.                     $data['edadString'] = 'edadString';
  202.                     $data['lugarNacimientoStr'] = 'lugarNacimientoStr';
  203.                     $data['sexo'] = 'Masculino';
  204.                     $data['estadoCivil'] = 'estadoCivil';
  205.                     $data['paisNacimiento'] = 'paisNacimiento';
  206.                 }
  207.                 
  208.                 $data['reclutaID'] = $this->salvaRecluta($data);
  209. //                if (false)  //WILLY: Usar esta lĂ­nea para probar sin usar los servicios
  210.                 if (!$this->edadValida($data['fechaNacimiento'], $procesoActivo))
  211.                 {
  212.                     $data['idoneo']=false;
  213.                     $data['causa']= CausaNoIdoneoEnum::EDAD;
  214.                     $data['volverPresentarse']='PROXIMO';
  215.                     $data['msg']=$this->translator->trans('noidoneo.causa.edad',array(),'crud'); 
  216.                     $data['fechaResultado'] = new \DateTime();
  217.                 }
  218.                 $this->salvaReclutaProceso($data);
  219.             }
  220.         }
  221.         $data = new Response(json_encode($data));
  222.         $data->headers->set('Content-Type''application/json');
  223.         return $data;
  224.     }
  225.         
  226.     public function verificaAntecedentesAction($identificacion)
  227.     {       
  228.         $data = array('ok'=>true'idoneo'=>true'cedula'=>$identificacion);
  229.         $em $this ->em;
  230.         if (!$this->procesoActivo)
  231.         {
  232.             $this->procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  233.                                                 ->createQueryBuilder('p')
  234.                                                 ->where('p.activo=true')
  235.                                                 ->getQuery()->getOneOrNullResult();
  236.         }
  237.         $proceso $this->procesoActivo;
  238.         $reclutaBajas $em->getRepository('App\\Entity\\ReclutaBajas')->findOneBy(array('identificacion' => $identificacion));
  239.         $bajasPermitidas $proceso->getBajasPermitidas();
  240.         if ($reclutaBajas && $reclutaBajas->getNumeroBajas() > $bajasPermitidas)
  241.         {
  242.             $data['ok']=true;  
  243.             $data['idoneo']=false;  //no tiene antecedentes
  244.             $data['msg']=$this->translator->trans('noidoneo.causa.bajas',array(),'crud'); 
  245.             $data['antecedente'] = 5//pendiente 
  246.         }
  247.         else 
  248.         {
  249.             /*** BEGIN CONSULTAR SERVICIO WEB POLICIA NACIONAL ***/
  250.             $data['ok']=true;  //se pudo comunicar con el ws
  251.             $data['idoneo']=true;  //no tiene antecedentes
  252.             $data['antecedente'] =0//NO tiene problemas                       
  253. //            $this->callPolice($identificacion, $data, false);    //WILLY  usar esta linea para probar sin consumir el servicio
  254.             $this->callPolice($identificacion$datatrue);
  255.         }
  256.         if ($data['ok'])
  257.         {
  258.             $data['fechaConsultaAntecedentes'] = new \DateTime();
  259.             if (!$data['idoneo'])
  260.             {
  261.                 $data['resultadosAntecedentes'] = json_encode($data['antecedente']);
  262.                 $data['causaRechazo'] = CausaNoIdoneoEnum::POLICIA;
  263.                 $data['fechaResultado'] = new \DateTime();
  264.                 $data['volverPresentarse']='PROXIMO';
  265.             }
  266.             $this->salvaReclutaProceso($data);
  267.             unset($data['resultadosAntecedentes']);
  268.             unset($data['fechaConsultaAntecedentes']);
  269.             unset($data['causaRechazo']);
  270.             unset($data['fechaResultado']);
  271.             unset($data['volverPresentarse']);
  272.         }
  273.         else
  274.         {
  275.             $data['msg']= $this->translator->trans('noidoneo.causa.network.policia',array(),'crud');
  276.         }
  277.         $data = new Response(json_encode($data));
  278.         $data->headers->set('Content-Type''application/json');
  279.         return $data;
  280.     }
  281.     
  282.     public function verificaEstudiosAction($identificacion)
  283.     {
  284.      
  285.         $data = array('ok'=>true'cedula'=>$identificacion);
  286.         /*** BEGIN CONSULTAR SERVICIO WEB MIN EDUCACION ***/
  287.         $data['ok']=true;  //se pudo comunicar con el ws
  288.         $data['estudios'] = array();        
  289.         //$data['estudios'][]=array('anno'=>2013, 'institucion'=>'Colegio XXX', 'titulo'=>'Ingenieron mecĂĄnico'); 
  290.         /*** END CONSULTAR SERVICIO WEB MIN EDUCACION ***/
  291.         
  292. //        $this->callMinEducacion($identificacion, $data, false);    //WILLY usar esta lĂ­nea para probar sin consumir el servicio
  293.         $this->callMinEducacion($identificacion$data);
  294.         
  295.         if ($data['ok'])
  296.         {
  297.             $data['resultadosEstudios'] = json_encode($data['estudios']);
  298.             $data['fechaConsultaEstudios'] = new \DateTime();
  299.             $this->salvaReclutaProceso($data);
  300.             unset($data['resultadosEstudios']);
  301.             unset($data['fechaConsultaEstudios']);
  302.         }
  303.         else
  304.         {
  305.             $data['msg']=$this->translator->trans('noidoneo.causa.network.educacion',array(),'crud');
  306.         }
  307.         $data = new Response(json_encode($data));
  308.         $data->headers->set('Content-Type''application/json');
  309.         return $data;
  310.     }
  311.     
  312.     private function puedeRegistrarse($recluta$proceso)
  313.     {
  314.        
  315.         $em $this ->em;
  316.         $ret = array();
  317.         $ret['procesoId']=0;
  318.         //buscar al recluta en procesos con resultado NUNCA MÁS
  319.         $procesoRecluta $em->getRepository('App\\Entity\\ReclutaProceso')
  320.                                             ->createQueryBuilder('r')
  321.                                             ->leftJoin('r.recluta''recluta')
  322.                                             ->where('recluta.id=:RECLUTA')
  323.                                             ->andwhere('r.idoneo=false')
  324.                                             ->andwhere('r.volverPresentarse=:TEXTO')
  325.                                             ->setParameter('RECLUTA',$recluta->getId())
  326.                                             ->setParameter('TEXTO','NUNCA')
  327.                                             ->getQuery()->getOneOrNullResult();
  328.         if ($procesoRecluta)
  329.         {
  330.             $ret['ok']=false;
  331.             $ret['causa']='nunca';
  332.             $ret['msg']=$this->translator->trans('noidoneo.causa.nunca',array(),'crud');
  333.             return $ret;
  334.         }
  335.         //buscar al recluta en el proceso activo
  336.         $procesoRecluta $em->getRepository('App\\Entity\\ReclutaProceso')
  337.                                             ->createQueryBuilder('r')
  338.                                             ->leftJoin('r.procesoReclutamiento''proceso')
  339.                                             ->leftJoin('r.recluta''recluta')
  340.                                             ->where('recluta.id=:RECLUTA')
  341.                                             ->andWhere('proceso.activo=true')
  342.                                             ->setParameter('RECLUTA',$recluta->getId())
  343.                                             ->getQuery()->getOneOrNullResult();
  344.         if ($procesoRecluta)
  345.         {
  346.             if ($procesoRecluta->getIdoneo())
  347.             {
  348.                 if ($procesoRecluta->getFechaResultado())
  349.                 {
  350.                     $ret['ok']=false;
  351.                     $ret['msg'] = $this->translator->trans('noidoneo.causa.aceptado',array(),'crud'); 
  352.                     $ret['causa']='aceptado';
  353.                 }
  354.                 else 
  355.                 if ($procesoRecluta->getTurno())
  356.                 {
  357.                     $ret['ok']=false;
  358.                     $ret['msg'] = $this->translator->trans('noidoneo.causa.registrado',array(),'crud'); 
  359.                     $ret['causa']='registrado';
  360.                     $ret['procesoId']=$procesoRecluta->getId();
  361.                                         
  362.                 }
  363.                 else 
  364.                 {
  365.                     $ret['ok']=true;
  366.                     $ret['msg'] = 'YA REGISTRADO';
  367.                     $ret['causa']=null;                
  368.                 }
  369.             }
  370.             else
  371.             {
  372.                 if ($procesoRecluta->getFechaResultado())
  373.                 {
  374.                     if ($procesoRecluta->getVolverPresentarse()==VolverPresentarseEnum::MISMO)
  375.                     {
  376.                         $ret['ok']=true;
  377.                         $ret['msg'] = '';
  378.                         $ret['causa']=null;                
  379.                     }
  380.                     elseif ($procesoRecluta->getVolverPresentarse()==VolverPresentarseEnum::PROXIMO)
  381.                     {
  382.                         $ret['ok']=false;
  383.                         $ret['msg'] = $this->translator->trans('noidoneo.causa.proxproceso',array(),'crud'); 
  384.                         $ret['causa']='proxproceso';
  385.                     }
  386.                 }
  387.                 else
  388.                 {
  389.                     $ret['ok']=true;
  390.                     $ret['causa']=null;
  391.                     $ret['msg']='NO IDONEO';
  392.                 }
  393.             }
  394.             return $ret;
  395.         }
  396.             
  397.         //buscar al recluta en procesos anteriores del mismo año del activo con resultado no idoneo confirmado
  398.         //(a)    En el mismo proceso        (b)   En siguiente proceso
  399.         /*$procesoRecluta = $em->getRepository('App\\Entity\\ReclutaProceso')
  400.                                             ->createQueryBuilder('r')
  401.                                             ->leftJoin('r.procesoReclutamiento', 'proceso')
  402.                                             ->leftJoin('r.recluta', 'recluta')
  403.                                             ->where('recluta.id=:RECLUTA')
  404.                                             ->andWhere('proceso.activo=false')
  405.                                             ->andWhere('r.idoneo=false')
  406.                                             ->andWhere('r.fechaResultado is not null')
  407.                                             ->andWhere('proceso.anno=:ANNO')
  408.                                             ->setParameter('RECLUTA',$recluta->getId())
  409.                                             ->setParameter('ANNO',$proceso->getAnno())
  410.                                             ->getQuery()->getOneOrNullResult();
  411.         if ($procesoRecluta && $procesoRecluta->getVolverPresentarse()->getValue()==VolverPresentarseEnum::PROXIMO)
  412.         {
  413.             $ret['ok']=false;
  414.             $ret['msg'] = $this->translator->trans('noidoneo.causa.proxproceso');
  415.             $ret['causa']='proxproceso';
  416.             return $ret;
  417.         }*/
  418.         $ret['ok']=true;
  419.         $ret['causa']=null;
  420.         $ret['msg']='';
  421.         return $ret;
  422.     }
  423.     
  424.     private function edadValida($fechaNacimiento$proceso)
  425.     {
  426.         $minEdad 18;
  427.         $maxEdadAnnos 22;
  428.         $maxEdadMeses 11;
  429.         $maxEdadDias 29;
  430.         $fechaAcuartelamientodate_format($proceso->getfechaAcuartelamiento(),'d/m/Y');
  431.         $edad=$this->calculaEdad($fechaAcuartelamiento$fechaNacimiento);
  432.         $edad explode('/',$edad);
  433.         return ($edad[0]>=$minEdad && $edad[0]<$maxEdadAnnos); // &&      ($edad[0]=$maxEdadAnnos && $edad[1]<=$maxEdadMeses && $edad[2]<=$maxEdadDias));
  434.     }
  435.      
  436.     public function registroSalvarEncuestaAction()
  437.     {
  438.         try
  439.         {
  440.             $data $this->request->get('encuesta');
  441.         
  442.             $id $this->salvaReclutaProceso($data);
  443.         
  444.             $data = array('ok'=>true'id'=>$id);
  445.         }
  446.         catch (\RuntimeException $e)
  447.         {
  448.             $data = array('ok'=>false'msg'=>'No se pudo grabar la operaciĂłn. Intente nuevamente mĂĄs tarde. '.$e->getMessage());
  449.         }
  450.         
  451.         $data = new Response(json_encode($data));
  452.         $data->headers->set('Content-Type''application/json');
  453.         return $data;
  454.     }
  455.     public function registroSalvarAction()
  456.     {
  457.         try
  458.         {
  459.             $data $this->request->get('form');
  460.         
  461.             $id $this->salvaReclutaProceso($data);
  462.         
  463.             $this->salvaRespuestas($data);
  464.             if ($data['gameover']=='completed' || $data['intentos']==3)
  465.                 $data = array('ok'=>true'id'=>$id);
  466.             else
  467.                 $data = array('ok'=>false'id'=>$id);
  468.         }
  469.         catch (\RuntimeException $e)
  470.         {
  471.             $data = array('ok'=>false'msg'=>'No se pudo grabar la operaciĂłn. Intente nuevamente mĂĄs tarde.');
  472.         }
  473.         
  474.         $data = new Response(json_encode($data));
  475.         $data->headers->set('Content-Type''application/json');
  476.         return $data;
  477.     }
  478.     public function salvaReclutaAction()
  479.     {
  480.         $data $this->request->get('recluta');
  481.         $this->salvaRecluta($data);
  482.         //validar cupos para el sexo
  483.         $ret = array('ok'=>true'hayCupos' => false);
  484.         if (isset($data['sexo']))
  485.         {
  486.             $em $this ->em;
  487.             if (!$this->procesoActivo)
  488.             {
  489.                 $this->procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  490.                                                     ->createQueryBuilder('p')
  491.                                                     ->where('p.activo=true')
  492.                                                     ->getQuery()->getOneOrNullResult();
  493.             }
  494.             $procesoActivo $this->procesoActivo;
  495.             
  496.             $fecha $procesoActivo->getFechaAcuartelamiento();
  497.             $fechaFin $procesoActivo->getFechaFinDias();
  498.             
  499.             $htmlFechas '';
  500.             $htmlCentros '';
  501.             while ($fecha<=$fechaFin)
  502.             {
  503.                 $centros $this->getCentrosConCupo($fecha$data['sexo']);
  504.                 if ($centros)
  505.                 {
  506.                     $ret['hayCupos'] = true;
  507.                     $htmlFechas .= '<option value="'.$fecha->format('Y-m-d').'">'.$this->dateToTxt($fecha).'</option>';
  508.                     if (!$htmlCentros)
  509.                     {
  510.                         $htmlCentros $centros;
  511.                     }
  512.                 }
  513.                 $fecha->add(new \DateInterval('P1D'));
  514.             }
  515.             $ret['fechas'] = $htmlFechas;
  516.             $ret['centros'] = $htmlCentros;
  517.             
  518.         }
  519.         
  520.         $data = new Response(json_encode($ret));
  521.         $data->headers->set('Content-Type''application/json');
  522.         return $data;
  523.     }
  524.     
  525.     public function dateToTxt($field)
  526.     {
  527.        // $date = date_format($field, 'Y-m-d');
  528.         if($field){
  529.             $diaSemana = ['Domingo''Lunes''Martes''MiĂ©rcoles''Jueves''Viernes''SĂĄbado'];
  530.             $diaSemana $diaSemana[$field->format('w')];
  531.             $mes = ['Enero''Febrero''Marzo''Abril''Mayo''Junio''Julio''Agosto''Septiembre''Octubre''Noviembre''Diciembre'];
  532.             $mes $mes[$field->format('n')-1];
  533.             return $diaSemana.' '.date_format($field,'d').' de '.$mes.' del '.date_format($field,'Y');
  534.         }else{
  535.             return 'NO DEFINIDO';
  536.         }
  537.     }
  538.     
  539.     
  540.     public function getCentrosConCupoAction($fecha$sexo)
  541.     {
  542.         //validar cupos para el sexo y fecha
  543.         $fecha = new \DateTime($fecha);
  544.         $data = ['centros' => $this->getCentrosConCupo($fecha$sexo)];
  545.         
  546.         $data = new Response(json_encode($data));
  547.         $data->headers->set('Content-Type''application/json');
  548.         return $data;
  549.     }
  550.     
  551.     private function getCentrosConCupo($fecha$sexo)
  552.     {
  553.         $em $this ->em;
  554.         $conn $em->getConnection();
  555.         if (!$this->procesoActivo)
  556.         {
  557.             $this->procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  558.                                                 ->createQueryBuilder('p')
  559.                                                 ->where('p.activo=true')
  560.                                                 ->getQuery()->getOneOrNullResult();
  561.         }
  562.         $procesoActivo $this->procesoActivo;
  563.         $dias 2;//$procesoActivo->getDuracion();
  564.         
  565.         if ($sexo=='Masculino')
  566.         {
  567.             $field 'cupo_masculino';
  568.         }
  569.         else
  570.         {
  571.             $field 'cupo_femenino';
  572.         }
  573.         //$sql = "select distinct cm.id as id, prc.nombre_lugar ||' - '|| cm.direccion_acuartelamiento as nombre from proceso_reclutamiento_lugar_base prc inner join centro_movilizacion cm on cm.id = prc.lugar where prc.proceso=".$procesoActivo->getId()." and ceiling(prc.".$field."/".$dias.".0)>(select count(rp.id) from recluta_proceso rp inner join recluta rec on rec.id=rp.recluta where prc.proceso=rp.proceso and rp.proceso=".$procesoActivo->getId()." and prc.lugar=rp.centro_movilizacion and rec.sexo='".$sexo."' and rp.fecha_asignacion<='".$fecha->format('Y-m-d H:i:s')."') order by prc.nombre_lugar ||' - '|| cm.direccion_acuartelamiento";
  574.         
  575.         $sql "select distinct cm.id as id, prc.nombre_lugar ||' - '|| cm.direccion_acuartelamiento as nombre from proceso_reclutamiento_lugar_base prc inner join centro_movilizacion cm on cm.id = prc.lugar where prc.proceso=".$procesoActivo->getId()." and prc.".$field.">(select count(rp.id) from recluta_proceso rp inner join recluta rec on rec.id=rp.recluta where prc.proceso=rp.proceso and rp.proceso=".$procesoActivo->getId()." and prc.lugar=rp.centro_movilizacion and rec.sexo='".$sexo."' and rp.fecha_asignacion<='".$fecha->format('Y-m-d H:i:s')."') order by prc.nombre_lugar ||' - '|| cm.direccion_acuartelamiento";
  576.         
  577.         
  578.         
  579.         $this->logger->info('*********RESULTADO CUPO'.$sql);
  580.             
  581.         $query $conn->executeQuery($sql);
  582. //        $query->execute();
  583.         $prc $query->fetchAllAssociative();
  584.         $html '';
  585.         if (!empty($prc))
  586.         {
  587.             $html .= '<option value="">-- Seleccione --</option>';
  588.             foreach ($prc as $centro)
  589.             {
  590.                 $html .= '<option value="'.$centro['id'].'">'.$centro['nombre'].'</option>';
  591.             }
  592.         }
  593.         return $html;                        
  594.     }
  595.     private function salvaRecluta($data)
  596.     {
  597.         $em $this ->em;
  598.         $recluta $em->getRepository('App\\Entity\\Recluta')->findOneBy(array('identificacion'=>$data['cedula']));
  599.         
  600.         if (!$recluta)
  601.         {
  602.             $recluta= new Recluta();
  603.             $recluta->setIdentificacion($data['cedula']);
  604.             $recluta->setNombres($data['nombres']);
  605.             $recluta->setFechaRegistro(new \DateTime());
  606.             if($data['fechaNacimiento'])
  607.                 $recluta->setFechaNacimiento(\DateTime::createFromFormat('d/m/Y'$data['fechaNacimiento']));           
  608.             $recluta->setEstadoCivil($data['estadoCivil']);
  609.             $recluta->setPaisNacimiento($data['paisNacimiento']);
  610.             if (isset($data['parroquiaNacimiento']) && $data['parroquiaNacimiento'])
  611.             {
  612.                 /*$parroquia = $em->getRepository('App\\Entity\\NmclDominioLocalizacion')
  613.                         ->createQueryBuilder('r')
  614.                         ->leftJoin('r.nivelLocalizacion','nivel')
  615.                         ->leftJoin('nivel.localizacion','localizacion')
  616.                         ->where('localizacion.id=1')
  617.                         ->andWhere('nivel.nivel=4')
  618.                         ->andWhere('upper(r.valor)=:VALOR')
  619.                         ->setParameter('VALOR',strtoupper($data['parroquiaNacimiento']))
  620.                         ->getQuery()->getOneOrNullResult();
  621.                 */
  622.                 $parroquia $em->getRepository('App\\Entity\\NmclDominioLocalizacion')
  623.                                                 ->createQueryBuilder('r')
  624.                                                 ->leftJoin('r.nivelLocalizacion','nivel')
  625.                                                 ->leftJoin('nivel.localizacion','localizacion')
  626.                                                 ->leftJoin('r.dominioPadre','dominioPadre')
  627.                                                 ->where('localizacion.id=1')
  628.                                                 ->andWhere('nivel.nivel=4')
  629.                                                 ->andWhere('upper(r.valor)=:VALOR')
  630.                                                 ->setParameter('VALOR',strtoupper($data['provinciaNacimiento']))
  631.                                                 ->andWhere('upper(dominioPadre.valor)=:VALOR2')
  632.                                                 ->setParameter('VALOR2',strtoupper($data['parroquiaNacimiento']))
  633.                                                 ->getQuery()->getOneOrNullResult();     
  634.                 if($parroquia)
  635.                     $recluta->setLugarNacimiento($parroquia);               
  636.             }
  637.             
  638.             $recluta->setLugarNacimientoStr($data['lugarNacimientoStr']);            
  639.             
  640.         }
  641.         
  642.         if (isset($data['edad']))
  643.         $recluta->setEdad($data['edad']);
  644.         
  645.         if (isset($data['edadString']))            
  646.         $recluta->setEdadString($data['edadString']);
  647.             
  648.         /*if (isset($data['apellidoP']))
  649.             $recluta->setApellidoPaterno($data['apellidoP']);
  650.         if (isset($data['apellidoM']))
  651.             $recluta->setApellidoMaterno($data['apellidoM']);*/
  652.         if (isset($data['telefono']))
  653.             $recluta->setTelefono($data['telefono']);
  654.         if (isset($data['email']))
  655.             $recluta->setEmail($data['email']);
  656.         if (isset($data['telefonoEmergencias']))
  657.             $recluta->setTelefonoEmergencias($data['telefonoEmergencias']);
  658.         if (isset($data['estatura']) && $data['estatura'])
  659.             $recluta->setEstatura($data['estatura']);
  660.         
  661.         //$this->logger->info('*********Sexo'.$data['sexo']);
  662.         
  663.         if (isset($data['sexo']))
  664.             $recluta->setSexo($data['sexo']);          
  665.         
  666.         if (isset($data['fotoCedula']))
  667.             $recluta->setFotoCedula($data['fotoCedula']);                    
  668.         
  669.         if(isset($data['estatura']))
  670.             $recluta->setEstatura($data['estatura']==''?null:$data['estatura']);              
  671.         
  672.         $em->persist($recluta);
  673.         $em->flush();
  674.         return $recluta->getId();
  675.     }
  676.     
  677.     public function salvaReclutaProcesoAction()
  678.     {
  679.         $data $this->request->get('form');
  680.         $this->salvaReclutaProceso($data);
  681.         
  682.         $data = array('ok'=>true);
  683.         
  684.         $data = new Response(json_encode($data));
  685.         $data->headers->set('Content-Type''application/json');
  686.         return $data;
  687.     }
  688.     
  689.     private function salvaReclutaProceso(&$data)
  690.     {
  691.         $em $this ->em;
  692.         $recluta $em->getRepository('App\\Entity\\Recluta')->findOneBy(array('identificacion'=>$data['cedula']));
  693.         $procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  694.                                     ->createQueryBuilder('p')
  695.                                     ->where('p.activo=true')
  696.                                     ->getQuery()->getOneOrNullResult();
  697.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')
  698.                 ->findOneBy(array('recluta'=>$recluta->getId(), 'procesoReclutamiento'=>$procesoActivo->getId()));
  699.         
  700.         if (!$reclutaProceso)
  701.         {
  702.             $reclutaProceso= new ReclutaProceso();
  703.             $reclutaProceso->setRecluta($recluta);
  704.             $reclutaProceso->setFechaRegistro(new \DateTime());
  705.             $reclutaProceso->setProcesoReclutamiento($procesoActivo);
  706.         }
  707.         $data['intentos'] = $reclutaProceso->getIntentos();
  708.         
  709.         if (isset($data['fechaConsultaAntecedentes']))
  710.             $reclutaProceso->setFechaConsultaAntecedentes($data['fechaConsultaAntecedentes']);
  711.         if (isset($data['fechaConsultaEstudios']))
  712.             $reclutaProceso->setFechaConsultaEstudios($data['fechaConsultaEstudios']);
  713.         if (isset($data['geometria']))
  714.             $reclutaProceso->setGeometria($data['geometria']);
  715.         if (isset($data['residenciaEcuador']) && $data['residenciaEcuador'])
  716.         {
  717.             $reclutaProceso->setPaisResidencia('Ecuador');
  718.             if (isset($data['callePrincipal']))
  719.                 $reclutaProceso->setCallePrincipalResidencia($data['callePrincipal']);
  720.             if (isset($data['calleSecundaria']))
  721.                 $reclutaProceso->setCalleSecundariaResidencia($data['calleSecundaria']);
  722.             if (isset($data['nroCasa']))
  723.                 $reclutaProceso->setNumeroCasa($data['nroCasa']);
  724.             if (isset($data['parroquiaResidencia']))
  725.             {
  726.                 $localizacion =$em->getRepository('App\\Entity\\NmclDominioLocalizacion')->find($data['parroquiaResidencia']);
  727.                 $reclutaProceso->setLugarResidencia($localizacion);
  728.             }
  729.         }
  730.         else
  731.         {
  732.             if (isset($data['paisResidencia']))
  733.                 $reclutaProceso->setPaisResidencia($data['paisResidencia']);
  734.         }
  735.         if (isset($data['referenciaResidencia']))
  736.             $reclutaProceso->setReferencias($data['referenciaResidencia']);
  737.         
  738.         if (isset($data['causa']) && $data['causa'])
  739.             $reclutaProceso->setCausaRechazo($data['causa']);
  740.         if (isset($data['volverPresentarse']))
  741.             $reclutaProceso->setVolverPresentarse($data['volverPresentarse']);
  742.         if (isset($data['idoneo']))
  743.             $reclutaProceso->setIdoneo($data['idoneo']);
  744.         if (isset($data['fechaAsignacion']))
  745.         {
  746.             $reclutaProceso->setFechaAsignacion(new \DateTime($data['fechaAsignacion']));
  747.         }
  748.         if (isset($data['fechaResultado']))
  749.             $reclutaProceso->setFechaResultado($data['fechaResultado']);
  750.         if (isset($data['resultadosAntecedentes']))
  751.             $reclutaProceso->setResultadosAntecedentes($data['resultadosAntecedentes']);
  752.         if (isset($data['resultadosEstudios']))
  753.             $reclutaProceso->setResultadosEstudios($data['resultadosEstudios']);
  754.         $centro null;
  755.         if (isset($data['centroMovilizacion']))
  756.         {
  757.             $centro $em->getRepository('App\\Entity\\CentroMovilizacion')->find($data['centroMovilizacion']);
  758.             $reclutaProceso->setCentroMovilizacion($centro);
  759.             $base $em->getRepository('App\\Entity\\ProcesoReclutamientoCentro')->findOneBy(['lugar'=>$centro->getId(), 'proceso'=>$procesoActivo->getId()]);
  760.             if ($base)
  761.             {
  762.                 $reclutaProceso->setBaseMovilizacion($base->getBase());
  763.             }
  764.         }
  765.         
  766.         if (isset($data['gameover']))
  767.         {
  768.             $intento $reclutaProceso->getIntentos()+1;
  769.             $data['intentos']=$intento;            
  770.             $reclutaProceso->setIntentos($intento);
  771.             if ($intento==1)
  772.                 $reclutaProceso->setFechaIntento1(new \DateTime());
  773.             elseif ($intento==2)
  774.                 $reclutaProceso->setFechaIntento2(new \DateTime());
  775.             else
  776.             {
  777.                 $reclutaProceso->setFechaIntento3(new \DateTime());
  778.                 if ($data['gameover']=='gameover')
  779.                 {
  780.                     $reclutaProceso->setIdoneo(false);
  781.                     $reclutaProceso->setCausaRechazo(CausaNoIdoneoEnum::PSICOLOGICA);
  782.                     $reclutaProceso->setFechaResultado(new \DateTime());
  783.                     $reclutaProceso->setObservaciones('No pudo completar el test psicolĂłgico en 3 intentos');
  784.                     $reclutaProceso->setVolverPresentarse(VolverPresentarseEnum::PROXIMO);
  785.                 }
  786.             }
  787.             if ($data['gameover']=='completed')
  788.             {
  789.                 if ($centro && $procesoActivo)
  790.                 {
  791.                     $procesoCentro $em->getRepository('App\\Entity\\ProcesoReclutamientoCentro')
  792.                             ->findOneBy(array('lugar'=>$centro->getId(),'proceso'=>$procesoActivo->getId()));
  793.                     if ($procesoCentro)
  794.                     {
  795.                         $turno $procesoCentro->getTurno()+1;
  796.                         $procesoCentro->setTurno($turno);
  797.                         $reclutaProceso->setTurno($turno);
  798.                         if ($recluta->getSexo()=='Masculino')
  799.                             $procesoCentro->setRegistradoMasculino($procesoCentro->getRegistradoMasculino()+1);
  800.                         else
  801.                             $procesoCentro->setRegistradoFemenino($procesoCentro->getRegistradoFemenino()+1);
  802.                         $em->persist($procesoCentro);
  803.                         $em->flush();
  804.                     }
  805.                 }
  806.             }
  807.         }
  808.         
  809.         if (isset($data['cursos']))
  810.         {
  811.             $cursosArray = [];
  812.             foreach ($reclutaProceso->getCursos() as $curso)
  813.             {
  814.                 $cursosArray[$curso->getId()] = $curso;
  815.             }
  816.             
  817.             foreach ($data['cursos'] as $curso)
  818.             {
  819.                 if (isset($cursosArray[$curso]))
  820.                 {
  821.                     unset($cursosArray[$curso]);
  822.                 }
  823.                 else
  824.                 {
  825.                     $curso $em->getRepository('App\\Entity\\Curso')->find($curso);
  826.                     if ($curso)
  827.                     {
  828.                         $reclutaProceso->addCursos($curso);
  829.                     }
  830.                 }
  831.             }
  832.             foreach ($cursosArray as $curso)
  833.             {
  834.                 $reclutaProceso->removeCursos($curso);
  835.             }
  836.         }
  837.         if (isset($data['uniforme']))
  838.         {
  839.             $reclutaProceso->setTallaUniforme($data['uniforme']);
  840.         }
  841.         if (isset($data['jockey']))
  842.         {
  843.             $reclutaProceso->setTallaJockey($data['jockey']);
  844.         }
  845.         if (isset($data['calzado']))
  846.         {
  847.             $reclutaProceso->setTallaCalzado($data['calzado']);
  848.         }
  849.         if (isset($data['camiseta']))
  850.         {
  851.             $reclutaProceso->setTallaCamiseta($data['camiseta']);
  852.         }
  853.         if (isset($data['estudios_finalizados']))
  854.         {
  855.             $reclutaProceso->setEstudio($data['estudios_finalizados']);
  856.         }
  857.         $em->persist($reclutaProceso);
  858.         $em->flush();
  859.         return $reclutaProceso->getId();
  860.     }
  861.     
  862.     private function salvaRespuestas($data)
  863.     {
  864.         if ($data['gameover']=='completed')
  865.         {
  866.             $em $this->em;
  867.             $recluta $em->getRepository('App\\Entity\\Recluta')->findOneBy(array('identificacion'=>$data['cedula']));
  868.             $procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  869.                                         ->createQueryBuilder('p')
  870.                                         ->where('p.activo=true')
  871.                                         ->getQuery()->getOneOrNullResult();
  872.             $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')
  873.                     ->findOneBy(array('recluta'=>$recluta->getId(), 'procesoReclutamiento'=>$procesoActivo->getId()));
  874.             if ($reclutaProceso)
  875.             {
  876.                 $preguntasIds array_keys($data['respuesta']);
  877.                 $preguntasBD $em->getRepository('App\\Entity\\TestPregunta')
  878.                     ->createQueryBuilder('p')
  879.                     ->where('p.id in (:IDS)')
  880.                     ->setParameter('IDS'$preguntasIds)    
  881.                     ->getQuery()->getResult();
  882.                 $preguntas = [];
  883.                 foreach ($preguntasBD as $pregunta)
  884.                 {
  885.                     $preguntas[$pregunta->getId()] = $pregunta;
  886.                 }
  887.                 foreach ($data['respuesta'] as $key=>$valor) {
  888.                     $respuesta $em->getRepository('App\\Entity\\TestReclutaProcesoPregunta')
  889.                             ->findOneBy(array('reclutaProceso'=>$reclutaProceso->getId(),'pregunta'=>$key));
  890.                     if (!$respuesta) {
  891.                         $pregunta $preguntas[$key];
  892.                         $respuesta = new TestReclutaProcesoPregunta();
  893.                         $respuesta->setPregunta($pregunta);
  894.                         $respuesta->setReclutaProceso($reclutaProceso);
  895.                     }
  896.                     $respuesta->setRespuesta($valor);
  897.                     $em->persist($respuesta);
  898.                 }
  899.                 $em->flush();
  900.             }
  901.         }
  902.     }
  903.     
  904.     public function getDominiosCentroMovilizacionAction$centro)
  905.     {
  906.         $data = array('ok'=>true);
  907.         $em $this ->em;
  908.         $centro $em->getRepository('App\\Entity\\CentroMovilizacion')->find($centro);
  909.         if ($centro)
  910.         {
  911.             $dominio $centro->getLocalizacion();
  912.             $data['geometria'] = $centro->getGeometria();
  913.             if ($dominio)
  914.             {
  915.                 $data['parroquia'] = $dominio->__toString();
  916.                 $dominio $dominio->getDominioPadre();
  917.                 $data['canton'] = $dominio->__toString();
  918.                 $dominio $dominio->getDominioPadre();
  919.                 $data['provincia'] = $dominio->__toString();
  920.                 $dominio $dominio->getDominioPadre();
  921.                 $data['region'] = $dominio->__toString();
  922.                 $data['direccion'] = $centro->getDireccion();
  923.                 $data['direccionAcuartelamiento'] = $centro->getDireccionAcuartelamiento();
  924.             }
  925.             else
  926.             {
  927.                 $data['ok']=false;
  928.             }
  929.         }    
  930.         else
  931.         {
  932.             $data['ok']=false;
  933.         }
  934.         $data = new Response(json_encode($data));
  935.         $data->headers->set('Content-Type''application/json');
  936.         return $data;
  937.     }
  938.     
  939.     public function asignarUnidadAction$reclutaProceso)
  940.     {
  941.         $user $this->getUser();
  942.         $fecha=new \DateTime();
  943.         $fecha->setTime(000);
  944.         
  945.         $em $this ->em;
  946.         $idReclutaProceso=$reclutaProceso;
  947.         
  948.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($reclutaProceso);
  949.         $fechaFin=$reclutaProceso->getProcesoReclutamiento()->getFechaFinDiasPosteriores();
  950.         $fechaFin->setTime(23,5959);
  951.               
  952.         if($fecha >= $reclutaProceso->getProcesoReclutamiento()->getFechaAcuartelamiento() and $fecha<=$fechaFin){
  953.             if ($user->isRoleAssigned('ROLE_OPERADOR_INSTRUCCION') or $user->isRoleAssigned('ROLE_COORDINADOR_DIRECCION'))
  954.             {                                        
  955.                 return $this->asignaUnidadDirectamente($idReclutaProceso);
  956.             }
  957.             
  958.             $centro=null;
  959.             if ($user->isRoleAssigned('ROLE_ADMINISTRADOR') === false and $user->isRoleAssigned('ROLE_COORDINADOR_DIRECCION') === false) {
  960.                 $centro $user->getCentroMovilizacion();
  961.             }
  962.             $em $this ->em;
  963.             $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($reclutaProceso);
  964.     //        $centro = $reclutaProceso->getCentroMovilizacion();
  965.             $recluta $reclutaProceso->getRecluta();
  966.             $proceso $reclutaProceso->getProcesoReclutamiento();
  967.             $unidades $em->getRepository('App\\Entity\\ProcesoReclutamientoUnidad')
  968.                     ->createQueryBuilder('u')
  969.                     ->innerJoin('u.proceso','proceso')
  970.                     ->where('proceso.id=:PROCESO')
  971.                     ->setParameter('PROCESO'$proceso->getId())
  972.                     ->orderBy('u.prioridad''ASC' );
  973.             if (!$centro)
  974.                 $centro $reclutaProceso->getCentroMovilizacion();
  975.             $unidades->andWhere('(u.lugar = '.$centro->getId().')');
  976.             if ($user->isRoleAssigned('ROLE_OPERADOR_UNIDAD'))
  977.             {
  978.                 $unidades
  979.                     ->innerJoin('u.unidad','unidad')
  980.                     ->andWhere('(unidad.id = '.$user->getUnidadMilitar()->getId().')');
  981.             }
  982.             if ($recluta->getSexo()=='Masculino')
  983.             {
  984.                 $unidades->andWhere('( (u.registradoMasculino is null or u.registradoMasculino<u.organicoMasculino)  and u.organicoMasculino >0)');
  985.             }
  986.             else
  987.             {
  988.                 $unidades->andWhere('((u.registradoFemenino is null or u.registradoFemenino<u.organicoFemenino) and u.organicoFemenino >0)');
  989.             }
  990.             $unidades $unidades->getQuery()->getResult();
  991.             if (empty($unidades))
  992.             {
  993.                 $data=array('ok'=>false,'msg'=>'No hay cupos disponibles');
  994.             }
  995.             else
  996.             {
  997.                 $unidadProceso $unidades[0];
  998.                 $unidad $unidadProceso->getUnidad();
  999.                 $data=array('ok'=>true'choose'=>false'unidad'=>$unidad->__toString(), 'unidadId'=>$unidad->getId(), 'centro'=>$unidad->getCentroInstruccion()->__toString());
  1000.             } 
  1001.         }
  1002.         else{
  1003.             $data=array('ok'=>false,'msg'=>'No se encuentra en las fechas habilitadas para asignaciĂłn de unidad');
  1004.         }
  1005.         
  1006.         $data = new Response(json_encode($data));
  1007.         $data->headers->set('Content-Type''application/json');
  1008.         return $data;
  1009.     }
  1010.     
  1011.     protected function asignaUnidadDirectamente$reclutaProceso)
  1012.     {
  1013.         $em $this ->em;
  1014.         $user $this->getUser();                
  1015.                 
  1016.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($reclutaProceso);
  1017.         $centro $reclutaProceso->getCentroMovilizacion();
  1018.         $recluta $reclutaProceso->getRecluta();
  1019.         $proceso $reclutaProceso->getProcesoReclutamiento();
  1020.         $procesoUnidades $em->getRepository('App\\Entity\\ProcesoReclutamientoUnidad')
  1021.                 ->createQueryBuilder('u')
  1022.                 ->leftJoin('u.proceso','proceso')
  1023.                 ->leftJoin('u.unidad','unidad')
  1024.                 ->where('proceso.id=:PROCESO')
  1025.                 ->setParameter('PROCESO'$proceso->getId());
  1026.        
  1027.         /*if ($user->isRoleAssigned('ROLE_OPERADOR_INSTRUCCION'))
  1028.         {
  1029.             // habilitar luego             
  1030. //            $centroInstruccion= $user->getCentroInstruccion();
  1031. //            $procesoUnidades =$procesoUnidades->andWhere('(unidad.centroInstruccion = '.$centroInstruccion->getId().')');
  1032.                     
  1033.         }*/
  1034.         if ($user->isRoleAssigned('ROLE_OPERADOR_CENTRO')) /*&& verificar las fechas*/
  1035.         {
  1036.             $centro$user->getCentroMovilizacion()?$user->getCentroMovilizacion():$reclutaProceso->getCentroMovilizacion();
  1037.             $procesoUnidades =$procesoUnidades->andWhere('(u.lugar = '.$centro->getId().')');
  1038.                     
  1039.         }
  1040.         
  1041.                 
  1042.         $procesoUnidades =$procesoUnidades->orderBy('u.prioridad''ASC' );
  1043.         
  1044.         if ($recluta->getSexo()=='Masculino')
  1045.         {
  1046.             $procesoUnidades->andWhere('( (u.registradoMasculino is null or u.registradoMasculino<u.cupoMasculino)  and u.cupoMasculino >0)');
  1047.         }
  1048.         else
  1049.         {
  1050.             $procesoUnidades->andWhere('((u.registradoFemenino is null or u.registradoFemenino<u.cupoFemenino) and u.cupoFemenino >0)');
  1051.         }
  1052.         
  1053.         $procesoUnidades $procesoUnidades->getQuery()->getResult();
  1054.         if (empty($procesoUnidades))
  1055.         {
  1056.             $data=array('ok'=>false'sql'=>$procesoUnidades->getQuery()->getSQL());
  1057.         }
  1058.         else
  1059.         {
  1060.             $unidades = array();
  1061.             $html='<option value="">-- Seleccione --</option>';
  1062.             foreach ($procesoUnidades as $procesoUnidad)
  1063.             {
  1064.                 $unidad $procesoUnidad->getUnidad();
  1065.                 $html.='<option value="'.$unidad->getId().'">'.$unidad->__toString().'</option>';
  1066.             }
  1067.             if ($user->isRoleAssigned('ROLE_COORDINADOR_DIRECCION')){
  1068.                 $data=array('ok'=>true'choose'=>true'unidades'=>$html'centro'=>'DIRECCION DE MOVILIZACION');
  1069.             }else{
  1070.                 $data=array('ok'=>true'choose'=>true'unidades'=>$html'centro'=>$unidad->getCentroInstruccion()->__toString());
  1071.             }
  1072.         }        
  1073.         $data = new Response(json_encode($data));
  1074.         $data->headers->set('Content-Type''application/json');
  1075.         return $data;
  1076.     }
  1077.     
  1078.     public function resultadoSalvarAction()
  1079.     {
  1080.         $em $this ->em;
  1081.         $resultado $this->request->get('resultado');
  1082.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($resultado['reclutaProceso']);
  1083.         $recluta $reclutaProceso->getRecluta();
  1084.         $proceso $reclutaProceso->getProcesoReclutamiento();
  1085.         $fullMasculino false;
  1086.         $fullFemenino false;
  1087.             
  1088.         try {
  1089.             if ($resultado['resultado']=='idoneo')
  1090.             {
  1091.                 $unidadProceso $em->getRepository('App\\Entity\\ProcesoReclutamientoUnidad')
  1092.                         ->findOneBy(array('proceso'=>$proceso->getId(),'unidad'=>$resultado['unidad']));
  1093.                 $unidad $unidadProceso->getUnidad();
  1094.                 $reclutaProceso->setUnidadMilitar($unidad);
  1095.                 if ($recluta->getSexo()=='Masculino')
  1096.                 {
  1097.                     $unidadProceso->setRegistradoMasculino($unidadProceso->getRegistradoMasculino()+1);
  1098.                     $fullMasculino = ($unidadProceso->getRegistradoMasculino()==$unidad->getCupoMasculino());
  1099.                 }
  1100.                 else        
  1101.                 {
  1102.                     $unidadProceso->setRegistradoFemenino($unidadProceso->getRegistradoFemenino()+1);
  1103.                     $fullFemenino = ($unidadProceso->getRegistradoFemenino()==$unidad->getCupoFemenino());
  1104.                 }
  1105.                 $reclutaProceso->setIdoneo(true);
  1106.                 $reclutaProceso->setCausaRechazo(null);
  1107.                 $reclutaProceso->setFechaResultado(new \DateTime());
  1108.                 $em->persist($reclutaProceso);
  1109.                 $em->persist($unidadProceso);
  1110.                 $em->flush();
  1111.                 
  1112.                 $data = array('ok'=>true'fullFemenino'=>$fullFemenino'fullMasculino'=>$fullMasculino'unidadId'=>$unidad->getId());
  1113.                 
  1114.             }
  1115.             else
  1116.             {
  1117.                 $this->logger->info('*********No idoneo');
  1118.                 $reclutaProceso->setIdoneo(false);
  1119.                 $reclutaProceso->setCausaRechazo($resultado['causa']);                                            
  1120.                 $reclutaProceso->setObservaciones($resultado['observaciones']);                                            
  1121.                 $reclutaProceso->setVolverPresentarse($resultado['volver']);                                            
  1122.                 $reclutaProceso->setFechaResultado(new \DateTime());
  1123.                 $em->persist($reclutaProceso);
  1124.                 $em->flush();
  1125.                 
  1126.                 $data = array('ok'=>true'fullFemenino'=>null'fullMasculino'=>null'unidadId'=>null);
  1127.             }
  1128.         
  1129.         
  1130.         } catch (\RuntimeException $exc) {
  1131.             
  1132.             $this->logger->info('*********No idoneo error'.$exc->getMessage());
  1133.             
  1134.             $data = array('ok'=>false'error'=>$exc);
  1135.         }
  1136.         
  1137.         $data = new Response(json_encode($data));
  1138.         $data->headers->set('Content-Type''application/json');
  1139.         return $data;
  1140.     }
  1141.     
  1142.     public function resultadoSalvarVacunacionAction()
  1143.     {
  1144.         $em $this ->em;
  1145.         $resultado $this->request->get('resultado');
  1146.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($resultado['reclutaProceso']);
  1147.         $recluta $reclutaProceso->getRecluta();
  1148.         $proceso $reclutaProceso->getProcesoReclutamiento();
  1149.         if ($resultado['resultado']=='valido')
  1150.         {
  1151.             $reclutaProceso->setCertificadoVacunacionOk(true);
  1152.             $reclutaProceso->setCausaRechazo(null);    
  1153.             $reclutaProceso->setVolverPresentarse(null);   
  1154.             $reclutaProceso->setFechaResultado(null);
  1155.             $reclutaProceso->setObservaciones(null);
  1156.             $em->persist($reclutaProceso);
  1157.             $em->flush();
  1158.         }
  1159.         else
  1160.         {
  1161.             $reclutaProceso->setIdoneo(false);
  1162.             $reclutaProceso->setCertificadoVacunacionOk(false);
  1163.             $reclutaProceso->setCausaRechazo(CausaNoIdoneoEnum::VACUNACION);                                            
  1164.             $reclutaProceso->setObservaciones($resultado['observaciones']);
  1165.             $reclutaProceso->setVolverPresentarse($resultado['volver']);                                            
  1166.             $reclutaProceso->setFechaResultado(new \DateTime());
  1167.             $em->persist($reclutaProceso);
  1168.             
  1169.             $centro $reclutaProceso->getCentroMovilizacion();
  1170. /*            $procesoCentro = $em->getRepository('App\\Entity\\ProcesoReclutamientoCentro')
  1171.                         ->findOneBy(array('lugar'=>$centro->getId(),'proceso'=>$reclutaProceso->getProcesoReclutamiento()));
  1172.             
  1173.             if ($recluta->getSexo()=='Masculino')
  1174.             {
  1175.                 $procesoCentro->setRegistradoMasculino($procesoCentro->getRegistradoMasculino()-1);
  1176.             }
  1177.             else
  1178.             {
  1179.                 $procesoCentro->setRegistradoFemenino($procesoCentro->getRegistradoFemenino()-1);
  1180.             }
  1181.             $em->persist($procesoCentro);*/
  1182.             
  1183.             $em->flush();
  1184.         }
  1185.         $data = array('ok'=>true);
  1186.         $data = new Response(json_encode($data));
  1187.         $data->headers->set('Content-Type''application/json');
  1188.         return $data;
  1189.     }
  1190.     
  1191.     public function cambiarCentroMovilizacionAction$idReclutaProceso)
  1192.     {
  1193.         $em $this ->em;
  1194.         
  1195.         if (!$this->procesoActivo)
  1196.         {
  1197.             $this->procesoActivo $em->getRepository('App\\Entity\\ProcesoReclutamiento')
  1198.                                                 ->createQueryBuilder('p')
  1199.                                                 ->where('p.activo=true')
  1200.                                                 ->getQuery()->getOneOrNullResult();
  1201.         }
  1202.         $procesoActivo $this->procesoActivo;
  1203.         
  1204.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($idReclutaProceso);
  1205.         $sexo $reclutaProceso->getRecluta()->getSexo();
  1206.             
  1207.         $fecha $procesoActivo->getFechaAcuartelamiento();
  1208.         $fechaFin $procesoActivo->getFechaFinDias();
  1209.             
  1210.         $hayCupos false;
  1211.         $htmlFechas '';
  1212.         $htmlCentros '';
  1213.         while ($fecha<=$fechaFin)
  1214.         {
  1215.             $centros $this->getCentrosConCupo($fecha$sexo);
  1216.             if ($centros)
  1217.             {
  1218.                 $hayCupos true;
  1219.                 $htmlFechas .= '<option value="'.$fecha->format('Y-m-d').'">'.$this->dateToTxt($fecha).'</option>';
  1220.                 if (!$htmlCentros)
  1221.                 {
  1222.                     $htmlCentros $centros;
  1223.                 }
  1224.             }
  1225.             $fecha->add(new \DateInterval('P1D'));
  1226.         }
  1227.         
  1228.         return $this->render('Aspirantes/cambiarCentro.html.twig'
  1229.                 array( 'sexo'=>$sexo'hayCupo'=>$hayCupos'fechas'=>$htmlFechas'centros'=>$htmlCentros ));
  1230.     }
  1231.     public function actualizarCentroMovilizacionAction$idReclutaProceso$idCentro$fecha)
  1232.     {
  1233.         $em $this ->em;
  1234.         $reclutaProceso $em->getRepository('App\\Entity\\ReclutaProceso')->find($idReclutaProceso);
  1235.         $recluta $em->getRepository('App\\Entity\\Recluta')->find($reclutaProceso->getRecluta());
  1236.         
  1237.         $data = array('ok'=>false);
  1238.         if ($reclutaProceso && isset($idCentro))
  1239.         {
  1240.             $centro $em->getRepository('App\\Entity\\CentroMovilizacion')->find($idCentro);
  1241.             if (($centro))
  1242.             {
  1243.                 $oldCentro $reclutaProceso->getCentroMovilizacion();
  1244.                 $oldProcesoCentro $em->getRepository('App\\Entity\\ProcesoReclutamientoCentro')
  1245.                         ->findOneBy(array('lugar'=>$oldCentro->getId(),'proceso'=>$reclutaProceso->getProcesoReclutamiento()));
  1246.                 $procesoCentro $em->getRepository('App\\Entity\\ProcesoReclutamientoCentro')
  1247.                         ->findOneBy(array('lugar'=>$centro->getId(),'proceso'=>$reclutaProceso->getProcesoReclutamiento()));
  1248.                 if ($procesoCentro)
  1249.                 {
  1250.                     $fecha = new \DateTime($fecha);
  1251.                     $reclutaProceso->setCentroMovilizacion($centro);
  1252.                     $base $em->getRepository('App\\Entity\\ProcesoReclutamientoCentro')->findOneBy(['lugar'=>$centro->getId(), 'proceso'=>$reclutaProceso->getProcesoReclutamiento()->getId()]);
  1253.                     if ($base)
  1254.                     {
  1255.                         $reclutaProceso->setBaseMovilizacion($base->getBase());
  1256.                     }
  1257.                     $reclutaProceso->setFechaAsignacion($fecha);
  1258.                     $turno $procesoCentro->getTurno()+1;
  1259.                     $procesoCentro->setTurno($turno);
  1260.                     $reclutaProceso->setTurno($turno);
  1261.                     if ($recluta->getSexo()=='Masculino')
  1262.                     {
  1263.                         $procesoCentro->setRegistradoMasculino($procesoCentro->getRegistradoMasculino()+1);
  1264.                         $oldProcesoCentro->setRegistradoMasculino($oldProcesoCentro->getRegistradoMasculino()-1);
  1265.                     }
  1266.                     else
  1267.                     {
  1268.                         $procesoCentro->setRegistradoFemenino($procesoCentro->getRegistradoFemenino()+1);
  1269.                         $oldProcesoCentro->setRegistradoFemenino($oldProcesoCentro->getRegistradoFemenino()-1);
  1270.                     }
  1271.                     
  1272.                     $em->persist($procesoCentro);
  1273.                     $em->persist($oldProcesoCentro);
  1274.                     $em->persist($reclutaProceso);
  1275.                     $em->flush();
  1276.                     
  1277.                     $data=array('ok'=>true'centro'=>$centro->__toString(), 'direccion'=>$centro->getDireccion(),'turno'=>$turno'fecha'=> $this->dateToTxt($fecha));
  1278.                 }
  1279.             }
  1280.         }    
  1281.         
  1282.         $data = new Response(json_encode($data));
  1283.         $data->headers->set('Content-Type''application/json');
  1284.         return $data;
  1285.     }
  1286. }