コード例 #1
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;
 }
コード例 #2
0
 /**
  * @Route("badabum/")
  * @Template("YacareMunirgBundle:Importar:importar.html.twig")
  */
 public function importarBadabumAction(Request $request)
 {
     $desde = (int) $request->query->get('desde');
     $cant = 500;
     mb_internal_encoding('UTF-8');
     ini_set('display_errors', 1);
     set_time_limit(600);
     ini_set('memory_limit', '2048M');
     $em = $this->getDoctrine()->getManager();
     $ArchivoCsv = fopen('badaum.csv', 'r');
     $importar_importados = 0;
     $importar_actualizados = 0;
     $importar_procesados = 0;
     $log = array();
     for ($i = 0; $i < $desde; $i++) {
         fgetcsv($ArchivoCsv);
     }
     while (!feof($ArchivoCsv)) {
         $Row = fgetcsv($ArchivoCsv);
         if ($Row && count($Row) > 1 && $Row[0]) {
             $Persona = $em->getRepository('YacareBaseBundle:Persona')->findOneBy(array('DocumentoNumero' => trim($Row[0])));
             if (!$Persona) {
                 $Persona = new \Yacare\BaseBundle\Entity\Persona();
                 $Persona->setDocumentoNumero($Row[0]);
                 $Persona->setDocumentoTipo(1);
                 $ApellidoYNombres = StringHelper::ObtenerApellidoYNombres($Row[1]);
                 $Persona->setApellido(StringHelper::Desoraclizar($ApellidoYNombres[0]));
                 $Persona->setNombre(StringHelper::Desoraclizar($ApellidoYNombres[1]));
                 $log[] = 'Creando persona: DNI ' . $Row[0] . ', ' . $Row[1];
                 $importar_importados++;
             } else {
                 $importar_actualizados++;
             }
             $PartesDomicilio = StringHelper::ObtenerCalleYNumero($Row[2]);
             /*
              * $Calle = $em->getRepository ( 'YacareCatastroBundle:Calle' )->findOneBy ( array (
              * 'Nombre' => $this->ArreglarNombreCalle ( $PartesDomicilio [0] )
              * ) );
              */
             $Calles = $em->getRepository('YacareCatastroBundle:Calle')->createQueryBuilder('c')->where('c.Nombre LIKE :nombre')->setParameter('nombre', $this->ArreglarNombreCalle($PartesDomicilio[0]))->getQuery()->getResult();
             if (count($Calles) == 1) {
                 $Calle = $Calles[0];
                 $PartesDomicilio[0] = $Calle->getNombre();
             } else {
                 $Calle = null;
             }
             if ($Row[3]) {
                 $PartesDomicilio[1] = $Row[3];
             }
             if ($Row[4]) {
                 $PartesDomicilio[2] = $Row[4];
             }
             if (!$Calle) {
                 $log[] = 'No existe la calle ' . $PartesDomicilio[0];
             }
             $Persona->setDomicilioCalle($Calle);
             $Persona->setDomicilioCalleNombre($PartesDomicilio[0]);
             $Persona->setDomicilioNumero($PartesDomicilio[1]);
             if (count($PartesDomicilio) > 2) {
                 $Persona->setDomicilioPuerta($PartesDomicilio[2]);
             }
             if (!$Persona->getTelefonoNumero()) {
                 $Persona->setTelefonoNumero(trim($Row[6]));
             } else {
                 $Persona->setTelefonoNumero($Persona->getTelefonoNumero() . ', ' . trim($Row[6]));
             }
             if (!$Persona->getFechaNacimiento() && $Row[7]) {
                 $fecha = \DateTime::createFromFormat('d/m/Y', $Row[7]);
                 if ($fecha) {
                     $Persona->setFechaNacimiento($fecha);
                 }
             }
             // Si no está en el grupo, lo agrego
             if ($Row[8]) {
                 $Grupo = $em->getRepository('YacareBaseBundle:PersonaGrupo')->find($Row[8]);
                 if ($Persona->getGrupos()->contains($Grupo) == false) {
                     $Persona->getGrupos()->add($Grupo);
                 }
             }
             $em->persist($Persona);
             $em->flush();
             $importar_procesados++;
             $log[] = $Row[0] . ': ' . (string) $Persona;
         }
         if ($importar_procesados >= $cant) {
             break;
         }
     }
     fclose($ArchivoCsv);
     return array('importar_importados' => $importar_importados, 'importar_actualizados' => $importar_actualizados, 'importar_procesados' => $importar_procesados, 'redir_desde' => $importar_procesados == $cant ? $desde + $cant : 0, 'log' => $log);
 }