Example #1
0
 /**
  * @Route("agentes/")
  * @Template("YacareMunirgBundle:Importar:importar.html.twig")
  */
 public function importarAgentesAction(Request $request)
 {
     $desde = (int) $request->query->get('desde');
     $cant = 100;
     mb_internal_encoding('UTF-8');
     ini_set('display_errors', 1);
     set_time_limit(600);
     ini_set('memory_limit', '2048M');
     $em = $this->getDoctrine()->getManager();
     $DbRecursos = $this->ConectarRrhh();
     $importar_importados = 0;
     $importar_actualizados = 0;
     $importar_procesados = 0;
     $log = array();
     $GrupoAgentes = $em->getRepository('YacareBaseBundle:PersonaGrupo')->find(1);
     foreach ($DbRecursos->query("SELECT * FROM agentes WHERE legajo = 54") as $Agente) {
         $entity = $em->getRepository('YacareRecursosHumanosBundle:Agente')->findOneBy(array('ImportSrc' => 'rr_hh.agentes', 'ImportId' => $Agente['legajo']));
         if (!$entity) {
             $entity = new \Yacare\RecursosHumanosBundle\Entity\Agente();
             // Asigno manualmente el ID
             $entity->setId((int) $Agente['legajo']);
             $metadata = $em->getClassMetaData(get_class($entity));
             $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
             $Persona = $em->getRepository('YacareBaseBundle:Persona')->findOneBy(array('DocumentoNumero' => trim($Agente['nrodoc'])));
             if (!$Persona) {
                 $Persona = new \Yacare\BaseBundle\Entity\Persona();
                 $Persona->setDocumentoNumero($Agente['nrodoc']);
                 $Persona->setDocumentoTipo((int) $Agente['tipodoc']);
             }
             $Persona->setNombre(StringHelper::Desoraclizar($Agente['name']));
             $Persona->setApellido(StringHelper::Desoraclizar($Agente['lastname']));
             if ($Agente['fechanacim']) {
                 $Persona->setFechaNacimiento(new \DateTime($Agente['fechanacim']));
             }
             $Persona->setTelefonoNumero(trim(str_ireplace('NO DECLARA', '', $Agente['telefono']) . ' ' . str_ireplace('NO DECLARA', '', $Agente['celular'])));
             $Persona->setGenero($Agente['sexo'] == 1 ? 1 : 0);
             $Persona->setEmail(str_ireplace('NO DECLARA', '', strtolower($Agente['email'])));
             $Persona->setCuilt(trim($Agente['cuil']));
             $em->persist($Persona);
             $em->flush();
             $entity->setPersona($Persona);
             $entity->setImportSrc('rr_hh.agentes');
             $entity->setImportId($Agente['legajo']);
             $importar_importados++;
         } else {
             $Persona = $entity->getPersona();
             $importar_actualizados++;
         }
         $Departamento = $em->getRepository('YacareOrganizacionBundle:Departamento')->findOneBy(array('ImportSrc' => 'rr_hh.sectores', 'ImportId' => $Agente['secretaria'] . '.' . $Agente['direccion'] . '.' . $Agente['sector']));
         if (!$Departamento) {
             $Departamento = $em->getRepository('YacareOrganizacionBundle:Departamento')->findOneBy(array('ImportSrc' => 'rr_hh.direcciones', 'ImportId' => $Agente['secretaria'] . '.' . $Agente['direccion']));
         }
         if (!$Departamento) {
             $Departamento = $em->getRepository('YacareOrganizacionBundle:Departamento')->findOneBy(array('ImportSrc' => 'rr_hh.secretarias', 'ImportId' => $Agente['secretaria']));
         }
         $entity->setDepartamento($Departamento);
         $entity->setCategoria($Agente['categoria']);
         $entity->setSituacion($Agente['situacion']);
         $entity->setFuncion(StringHelper::Desoraclizar($Agente['funcion']));
         $entity->setBajaMotivo($Agente['motivo']);
         if ($Agente['excombatie'] == 'S') {
             $entity->setExCombatiente(1);
         }
         if ($Agente['discapacit'] == 'S') {
             $entity->setDiscapacitado(1);
         }
         if ($Agente['manohabil'] == 'I') {
             $entity->setManoHabil(1);
         }
         $entity->setEstudiosNivel($Agente['estudios']);
         if ($Agente['titulo'] == 999) {
             $entity->setEstudiosTitulo(null);
         } else {
             $entity->setEstudiosTitulo($Agente['titulo']);
         }
         if (\Tapir\BaseBundle\Helper\Cbu::EsCbuValida($Agente['cbu'])) {
             $entity->setCBUCuentaAgente(\Tapir\BaseBundle\Helper\Cbu::FormatearCbu($Agente['cbu']));
         }
         // Si no está en el grupo agentes, lo agrego
         if ($Persona->getGrupos()->contains($GrupoAgentes) == false) {
             $Persona->getGrupos()->add($GrupoAgentes);
             $em->persist($Persona);
         }
         // Le pongo el número de legajo en la persona
         if ($entity->getId()) {
             $Persona->setAgenteId($entity->getId());
         }
         if ($Agente['fechaingre']) {
             $entity->setFechaIngreso(new \DateTime($Agente['fechaingre']));
         } else {
             $entity->setFechaIngreso(null);
         }
         if (is_null($Agente['fechabaja']) || $Agente['fechabaja'] === '0000-00-00') {
             $entity->setBajaFecha(null);
             $entity->setArchivado(false);
         } else {
             $entity->setBajaFecha(new \DateTime($Agente['fechabaja']));
             $entity->setArchivado(true);
         }
         if (is_null($Agente['fechanacion'] || $Agente['fechanacion'] === '0000-00-00')) {
             $entity->setFechaNacionalizacion(null);
         } else {
             $entity->setFechaNacionalizacion(new \DateTime($Agente['fechanacion']));
         }
         if (is_null($Agente['ult_act_d'] || $Agente['ult_act_d'] === '0000-00-00')) {
             $entity->setUltimaActualizacionDomicilio(null);
         } else {
             $entity->setUltimaActualizacionDomicilio(new \DateTime($Agente['ult_act_d']));
         }
         if (is_null($Agente['fecha_psico'] || $Agente['fecha_psico'] === '0000-00-00')) {
             $entity->setFechaPsicofisico(null);
         } else {
             $entity->setFechaPsicofisico(new \DateTime($Agente['ult_act_d']));
         }
         if (is_null($Agente['fecha_CBC'] || $Agente['fecha_CBC'] === '0000-00-00')) {
             $entity->setFechaCertificadoBuenaConducta(null);
         } else {
             $entity->setFechaCertificadoBuenaConducta(new \DateTime($Agente['fecha_CBC']));
         }
         if (is_null($Agente['fecha_CAP'] || $Agente['fecha_CAP'] === '0000-00-00')) {
             $entity->setFechaCertificadoAntecedentesPenales(null);
         } else {
             $entity->setFechaCertificadoAntecedentesPenales(new \DateTime($Agente['fecha_CAP']));
         }
         if (is_null($Agente['fecha_CD'] || $Agente['fecha_CD'] === '0000-00-00')) {
             $entity->setFechaCertificadoDomicilio(null);
         } else {
             $entity->setFechaCertificadoDomicilio(new \DateTime($Agente['fecha_CD']));
         }
         if (\Tapir\BaseBundle\Helper\Cbu::EsCbuValida($Agente['cbu'])) {
             $entity->setCBUCuentaAgente($Agente['cbu']);
         }
         if (is_null($Agente['finalcontr'] || $Agente['finalcontr'] === '0000-00-00')) {
             $entity->setBajaFechaContrato(null);
         } else {
             $entity->setBajaFechaContrato(new \DateTime($Agente['finalcontr']));
         }
         if ($Agente['decreto2']) {
             $entity->setBajaDecreto(\Yacare\MunirgBundle\Helper\StringHelper::FormatearDecreto($Agente['decreto2']));
         }
         $entity->setSuprimido(false);
         $em->persist($entity);
         $em->flush();
         $importar_procesados++;
         $log[] = $Agente['legajo'] . ': ' . (string) $entity . ($entity->getSuprimido() ? '*' : '') . ' -- ' . (string) $entity->getDepartamento();
     }
     return array('importar_importados' => $importar_importados, 'importar_actualizados' => $importar_actualizados, 'importar_procesados' => $importar_procesados, 'redir_desde' => $importar_procesados == $cant ? $desde + $cant : 0, 'log' => $log);
 }
Example #2
0
 public function ImportarRegistro($Row)
 {
     $resultado = new ResultadoLote();
     //$resultado->Registros[] = $Row;
     $entity = $this->em->getRepository('YacareRecursosHumanosBundle:Agente')->findOneBy(array('ImportSrc' => 'rr_hh.agentes', 'ImportId' => $Row['legajo']));
     if (!$entity) {
         $entity = $this->em->getRepository('YacareRecursosHumanosBundle:Agente')->findOneBy(array('id' => $Row['legajo']));
     }
     if (!$entity) {
         $entity = new \Yacare\RecursosHumanosBundle\Entity\Agente();
         // Asigno manualmente el ID
         $entity->setId((int) $Row['legajo']);
         $metadata = $this->em->getClassMetaData(get_class($entity));
         $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
         $Persona = $this->em->getRepository('YacareBaseBundle:Persona')->findOneBy(array('DocumentoNumero' => trim($Row['nrodoc'])));
         if (!$Persona) {
             $Persona = new \Yacare\BaseBundle\Entity\Persona();
             $Persona->setDocumentoNumero($Row['nrodoc']);
             $Persona->setDocumentoTipo((int) $Row['tipodoc']);
         }
         $Persona->setNombre(StringHelper::Desoraclizar($Row['name']));
         $Persona->setApellido(StringHelper::Desoraclizar($Row['lastname']));
         if ($Row['fechanacim']) {
             $Persona->setFechaNacimiento(new \DateTime($Row['fechanacim']));
         }
         $Persona->setTelefonoNumero(trim(str_ireplace('NO DECLARA', '', $Row['telefono']) . ' ' . str_ireplace('NO DECLARA', '', $Row['celular'])));
         $Persona->setGenero($Row['sexo'] == 1 ? 1 : 0);
         $Persona->setEmail(str_ireplace('NO DECLARA', '', strtolower($Row['email'])));
         $Persona->setCuilt(trim($Row['cuil']));
         $this->em->persist($Persona);
         //$this->em->flush();
         $entity->setPersona($Persona);
         $entity->setImportSrc('rr_hh.agentes');
         $entity->setImportId($Row['legajo']);
         $resultado->RegistrosNuevos++;
     } else {
         $resultado->RegistrosActualizados++;
         $Persona = $entity->getPersona();
     }
     $Departamento = $this->em->getRepository('YacareOrganizacionBundle:Departamento')->findOneBy(array('ImportSrc' => 'rr_hh.sectores', 'ImportId' => $Row['secretaria'] . '.' . $Row['direccion'] . '.' . $Row['sector']));
     if (!$Departamento) {
         $Departamento = $this->em->getRepository('YacareOrganizacionBundle:Departamento')->findOneBy(array('ImportSrc' => 'rr_hh.direcciones', 'ImportId' => $Row['secretaria'] . '.' . $Row['direccion']));
     }
     if (!$Departamento) {
         $Departamento = $this->em->getRepository('YacareOrganizacionBundle:Departamento')->findOneBy(array('ImportSrc' => 'rr_hh.secretarias', 'ImportId' => $Row['secretaria']));
     }
     $entity->setDepartamento($Departamento);
     $entity->setCategoria($Row['categoria']);
     $entity->setSituacion($Row['situacion']);
     $entity->setFuncion(StringHelper::Desoraclizar($Row['funcion']));
     $entity->setBajaMotivo($Row['motivo']);
     if ($Row['excombatie'] == 'S') {
         $entity->setExCombatiente(1);
     }
     if ($Row['discapacit'] == 'S') {
         $entity->setDiscapacitado(1);
     }
     if ($Row['manohabil'] == 'I') {
         $entity->setManoHabil(1);
     }
     $entity->setEstudiosNivel($Row['estudios']);
     if ($Row['titulo'] == 999) {
         $entity->setEstudiosTitulo(null);
     } else {
         $entity->setEstudiosTitulo($Row['titulo']);
     }
     if (\Tapir\BaseBundle\Helper\Cbu::EsCbuValida($Row['cbu'])) {
         $entity->setCBUCuentaAgente(\Tapir\BaseBundle\Helper\Cbu::FormatearCbu($Row['cbu']));
     }
     if ($Row['fechaingre']) {
         $entity->setFechaIngreso(new \DateTime($Row['fechaingre']));
     } else {
         $entity->setFechaIngreso(null);
     }
     if (is_null($Row['fechabaja']) || $Row['fechabaja'] === '0000-00-00') {
         $entity->setBajaFecha(null);
         $entity->setArchivado(false);
     } else {
         $entity->setBajaFecha(new \DateTime($Row['fechabaja']));
         $entity->setArchivado(true);
     }
     if (is_null($Row['fechanacion'] || $Row['fechanacion'] === '0000-00-00')) {
         $entity->setFechaNacionalizacion(null);
     } else {
         $entity->setFechaNacionalizacion(new \DateTime($Row['fechanacion']));
     }
     if (is_null($Row['ult_act_d'] || $Row['ult_act_d'] === '0000-00-00')) {
         $entity->setUltimaActualizacionDomicilio(null);
     } else {
         $entity->setUltimaActualizacionDomicilio(new \DateTime($Row['ult_act_d']));
     }
     if (is_null($Row['fecha_psico'] || $Row['fecha_psico'] === '0000-00-00')) {
         $entity->setFechaPsicofisico(null);
     } else {
         $entity->setFechaPsicofisico(new \DateTime($Row['ult_act_d']));
     }
     if (is_null($Row['fecha_CBC'] || $Row['fecha_CBC'] === '0000-00-00')) {
         $entity->setFechaCertificadoBuenaConducta(null);
     } else {
         $entity->setFechaCertificadoBuenaConducta(new \DateTime($Row['fecha_CBC']));
     }
     if (is_null($Row['fecha_CAP'] || $Row['fecha_CAP'] === '0000-00-00')) {
         $entity->setFechaCertificadoAntecedentesPenales(null);
     } else {
         $entity->setFechaCertificadoAntecedentesPenales(new \DateTime($Row['fecha_CAP']));
     }
     if (is_null($Row['fecha_CD'] || $Row['fecha_CD'] === '0000-00-00')) {
         $entity->setFechaCertificadoDomicilio(null);
     } else {
         $entity->setFechaCertificadoDomicilio(new \DateTime($Row['fecha_CD']));
     }
     if (\Tapir\BaseBundle\Helper\Cbu::EsCbuValida($Row['cbu'])) {
         $entity->setCBUCuentaAgente($Row['cbu']);
     }
     if (is_null($Row['finalcontr'] || $Row['finalcontr'] === '0000-00-00')) {
         $entity->setBajaFechaContrato(null);
     } else {
         $entity->setBajaFechaContrato(new \DateTime($Row['finalcontr']));
     }
     if ($Row['decreto2']) {
         $entity->setBajaDecreto(\Yacare\MunirgBundle\Helper\StringHelper::FormatearActoAdministrativo($Row['decreto2']));
     } else {
         $entity->setBajaDecreto(null);
     }
     $entity->setSuprimido(false);
     $this->em->persist($entity);
     $this->em->flush();
     return $resultado;
 }
Example #3
0
 /**
  * Devuelve el decreto con formato aplicado.
  * 
  * @param  string $Decreto para procesamiento.
  * @return string $Decreto formateado.
  */
 public static function FormatearDecreto($Decreto)
 {
     $Decreto = str_replace(array('.', ',', '-', ' ', 'Nº', 'N', 'Y'), '', trim($Decreto));
     $Decreto = strtoupper(str_replace('//', '/', $Decreto));
     return StringHelper::SustituirPrefijo($Decreto);
 }