$action = MQL_ADD;
 }
 //Cedula de Identidad
 $xFi->setCharDelimiter("|");
 $xFi->setLimitCampos(4);
 //$xFi->setToUTF8();
 //var_dump($_FILES["f1"]);
 //$xFi->setExo($esqueleto);
 //var_dump($_FILES);
 if ($xFi->processFile($doc1) == true) {
     $data = $xFi->getData();
     $conteo = 1;
     foreach ($data as $rows) {
         if ($conteo > 1) {
             $xFi->setDataRow($rows);
             $cuenta = $xFi->getV($colcuenta, "");
             //$cuenta		= $xT->cSerial($largo)
             $xEQ = new cCuentaContableEsquema($cuenta);
             //$xCW		= new cCatalogoCompacW();
             //echo $xEQ->CUENTA_FORMATEADA . "<br/>" . $xEQ->CUENTARAW ."<br />" . $xCW->getEquivalencia( $xFi->getV($tmp->NATURALEZA, "") )  . $xEQ->NIVEL_ACTUAL . "<hr />";
             $cuenta = $xEQ->CUENTA_FORMATEADA;
             $xCCont = new cCuentaContable($cuenta);
             $nivel = $xCCont->determineNivel($cuenta);
             $sucess = true;
             $nombre = $xFi->getV($colnombre, "");
             $nombre = trim($nombre);
             $superior = $xEQ->CUENTA_SUPERIOR;
             // $xCCont->getInmediatoSuperior();
             $cuenta = $xCCont->getCuentaCompleta($cuenta);
             $nombre = $xT->setNoAcentos($nombre);
             $nombre = str_replace("'", "", $nombre);
             		
             		$tipo_de_ingreso = FALLBACK_PERSONAS_TIPO_ING, $estado_civil = DEFAULT_ESTADO_CIVIL,
             		
             		$genero = DEFAULT_GENERO, $dependencia = FALLBACK_CLAVE_EMPRESA, $regimen_conyugal = DEFAULT_REGIMEN_CONYUGAL,
             		
             		$personalidad_juridica = 1, $grupo_solidario = DEFAULT_GRUPO, $observaciones = "",
             		
             		$identificado_con = 1, $documento_de_identificacion = "0", $codigo = false, $sucursal = false,
             		
             		$movil	= "", $correo = "", $dependientes = 0, $fecha = false, $riesgo = AML_PERSONA_BAJO_RIESGO, $clave_fiel = "", 
             		$pais = EACP_CLAVE_DE_PAIS
             		*/
             $idpersona = $xFi->getEntero($tmp->ID_PERSONA);
             if ($idpersona > 0) {
                 $xSoc->setOmitirAML();
                 $pass = $xSoc->add($xFi->getV($tmp->NOMBRES), $xFi->getV($tmp->PRIMER_APELLIDO), $xFi->getV($tmp->SEGUNDO_APELLIDO), $xFi->getV($tmp->ID_FISCAL), $xFi->getV($tmp->ID_POBLACIONAL), getCajaLocal(), $xFi->getV($tmp->FECHA_NACIMIENTO), $xFi->getV($tmp->CIUDAD_NACIMIENTO), DEFAULT_TIPO_INGRESO, $xFi->getV($tmp->ESTADO_CIVIL, DEFAULT_ESTADO_CIVIL, MQL_INT, $arrEcivil), $xFi->getV($tmp->GENERO, DEFAULT_GENERO, MQL_INT, $arrGenero), FALLBACK_CLAVE_EMPRESA, DEFAULT_REGIMEN_CONYUGAL, $xFi->getV($tmp->TIPO_PERSONA, FALLBACK_PERSONAS_FIGURA_JURIDICA, MQL_INT, $arrFJuridica), FALLBACK_CLAVE_DE_GRUPO, "", FALLBACK_PERSONAS_TIPO_IDENTIFICACION, $xFi->getV($tmp->ID_POBLACIONAL), $idpersona, getSucursal(), 0, "", 0, $xFi->getV($tmp->FECHA_ALTA));
                 //sucess
                 if ($pass == true) {
                     $ingreso = $xFi->getFlotante($tmp->INGRESOS_MENSUALES);
                     if ($ingreso > 0) {
                         if ($xSoc->init() == true) {
                             $xSoc->addActividadEconomica($xFi->getV($tmp->EMPRESA_TRABAJO, ""), $ingreso, $xFi->getV($tmp->OCUPACION, ""));
                         }
                     }
                 }
             }
             $msg .= $xSoc->getMessages();
         }
         $conteo++;
     }
 }
 $xFi->setCharDelimiter("|");
 $xFi->setLimitCampos(10);
 //TODO: Evaluar carga de personas desde otra entidad
 //var_dump($_FILES["f1"]);
 if ($xFi->processFile($doc1) == true) {
     $data = $xFi->getData();
     $conteo = 1;
     $msg .= "";
     foreach ($data as $rows) {
         if ($conteo > 1) {
             //Omitir primera columna
             $xFi->setDataRow($rows);
             //$xHT = new cHTabla();
             //$xHT->addTR();
             $sucess = true;
             $persona = $xFi->getV($tmp->ID_PERSONA, false, MQL_INT);
             $cuenta = $xFi->getV($tmp->ID_CUENTA, false, MQL_INT);
             $deposito = $xFi->getV($tmp->DEPOSITO, 0, MQL_FLOAT);
             $retiro = $xFi->getV($tmp->RETIRO, 0, MQL_FLOAT);
             $rfc = $xFi->getV($tmp->ID_FISCAL);
             $curp = $xFi->getV($tmp->ID_POBLACIONAL);
             $nombre = $xFi->getV($tmp->NOMBRE_PERSONA);
             $apellido1 = $xFi->getV($tmp->PRIMER_APELLIDO);
             $apellido2 = $xFi->getV($tmp->SEGUNDO_APELLIDO);
             $xSoc = new cSocio($persona);
             //buscar por RFC/CURP
             if ($persona == false) {
                 if ($xSoc->initByIDLegal($rfc) == false) {
                     if ($xSoc->initByIDLegal($curp) == false) {
                         $sucess = false;
                         $msg .= "ERROR\tLa persona {$persona} por el ID_POBLACIONAL {$curp} ni por ID_FISCAL {$rfc} \r\n";
 4149|"CAVIEDES CRUZ, Leonardo"|"individual"|"SDNT"|
 -5  - 6  - 7  - 8  -  9 - 10 - 11
 -0- |-0- |-0- |-0- |-0- |-0- |-0-
 -12 
 |"DOB 23 Nov 1952; Cedula No. 16593470 (Colombia); Passport AB151486 (Colombia); alt. Passport AC444270 (Colombia); alt. Passport OC444290 (Colombia)." 
 					 * */
 $tipo = $xT->cChar(str_replace('"', "", $cont[2]));
 if ($id > 0) {
     if ($tipo == "individual" or $tipo == "-0-") {
         $xSoc = new cSocio($id);
         $programa = strtoupper(str_replace('"', "", $cont[3]));
         $idpoblacion = "{$programa}-{$id}";
         $nombres = strtoupper(str_replace('"', "", $cont[1]));
         $apellido1 = "";
         $apellido2 = "";
         $pobservaciones = trim($xFil->cleanString($xFil->getV(12)));
         if ($tipo == "-0-") {
             //$nombres	= $nombres;
         } else {
             $DNom = explode(",", $nombres, 2);
             $nombres = isset($DNom[1]) ? $DNom[1] : "";
             $apellidos = explode(" ", $DNom[0], 2);
             $apellido1 = isset($apellidos[0]) ? $apellidos[0] : "";
             $apellido2 = isset($apellidos[1]) ? $apellidos[1] : "";
         }
         if (setNoMenorQueCero($id) > DEFAULT_SOCIO) {
             if ($xSoc->existe() == true) {
                 $xSoc->setDeleteSocio();
             }
         }
         $nombres = trim($nombres);
 }
 //Cedula de Identidad
 $tmp = new cTmp();
 $xFi->setCharDelimiter("|");
 //$xFi->setLimitCampos(9);
 $xFi->setToUTF8();
 //var_dump($_FILES["f1"]);
 $xFi->setExo($esqueleto);
 //var_dump($_FILES);
 if ($xFi->processFile($doc1) == true) {
     $data = $xFi->getData();
     $conteo = 1;
     foreach ($data as $rows) {
         if ($conteo > 1) {
             $xFi->setDataRow($rows);
             $cuenta = $xFi->getV($tmp->CUENTA, "");
             $xEQ = new cCuentaContableEsquema($cuenta);
             $xCW = new cCatalogoCompacW();
             //echo $xEQ->CUENTA_FORMATEADA . "<br/>" . $xEQ->CUENTARAW ."<br />" . $xCW->getEquivalencia( $xFi->getV($tmp->NATURALEZA, "") )  . $xEQ->NIVEL_ACTUAL . "<hr />";
             $cuenta = $xEQ->CUENTA_FORMATEADA;
             $xCCont = new cCuentaContable($cuenta);
             $nivel = $xCCont->determineNivel($cuenta);
             $sucess = true;
             $nombre = $xFi->getV($tmp->CTA1, "");
             $nombre = trim($nombre);
             $superior = $xEQ->CUENTA_SUPERIOR;
             // $xCCont->getInmediatoSuperior();
             $cuenta = $xCCont->getCuentaCompleta($cuenta);
             $nombre = $xT->setNoAcentos($nombre);
             $nombre = str_replace("'", "", $nombre);
             $nombre = strtoupper($nombre);
     $linea = 0;
     foreach ($data as $valores => $cont) {
         //
         $xFil->setDataRow($data);
         $xSoc = new cSocio(false);
         /*$nombre, $apellidopaterno = "", $apellidomaterno = "",
         		$rfc = "", $curp = "", $cajalocal = DEFAULT_CAJA_LOCAL,
         		$fecha_de_nacimiento = false, $lugar_de_nacimiento = "",
         		$tipo_de_ingreso = FALLBACK_PERSONAS_TIPO_ING, $estado_civil = ,
         		$genero = , $dependencia = , $regimen_conyugal = ,
         		$personalidad_juridica = , $grupo_solidario = , $observaciones = "",
         		$identificado_con = 1, $documento_de_identificacion = "0", $codigo = false, $sucursal = false,
         		$movil	= "", $correo = "", $dependientes = 0, $fecha = false, $riesgo = AML_PERSONA_BAJO_RIESGO, $clave_fiel = "", 
         		$pais = EACP_CLAVE_DE_PAIS, $regimen_fiscal = DEFAULT_REGIMEN_FISCAL*/
         $xSoc->setOmitirAML();
         $ready = $xSoc->add($xFil->getV($xTmp->NOMBRE), $xFil->getV($xTmp->PRIMER_APP), $xFil->getV($xTmp->SEGUNDO_APP), "", "", false, false, "", TIPO_INGRESO_PEP, DEFAULT_ESTADO_CIVIL, DEFAULT_GENERO, FALLBACK_CLAVE_EMPRESA, DEFAULT_REGIMEN_CONYUGAL, PERSONAS_FIGURA_FISICA, DEFAULT_GRUPO, "", 1, 0, false, false, $xFil->getEntero($xTmp->TELEFONO), $xFil->cleanMail($xFil->getV($xTmp->MAIL)));
         if ($ready == true) {
             $xAct = new cPersonaActividadEconomica();
             //$clave_de_actividad, $ingreso, $antiguedad = DEFAULT_TIEMPO, $nombrecomercial = "",
             //$codigo_postal = 0, $telefono = 0, $idlocalidad = 0, $nombrelocalidad = "", $nombremunicipio = "", $nombreestado = ""
             $xAct->add($clave_de_actividad, $ingreso);
         }
         //$xSoc->addActividadEconomica($xFil->getV($indice), $ingreso)
         $linea++;
     }
 }
 $msg .= $xFil->getMessages();
 if (MODO_DEBUG == true) {
     $xFRM->addLog($msg);
 } else {
     echo JS_CLOSE;
 if ($aplicar == true) {
     $action = MQL_ADD;
 }
 //Cedula de Identidad
 $tmp = new cTmp();
 $xFi->setCharDelimiter("|");
 $xFi->setLimitCampos(9);
 $xFi->setToUTF8();
 //var_dump($_FILES["f1"]);
 if ($xFi->processFile($doc1) == true) {
     $data = $xFi->getData();
     $conteo = 1;
     foreach ($data as $rows) {
         if ($conteo > 1) {
             $xFi->setDataRow($rows);
             $cuenta = $xFi->getV($tmp->CUENTA, "");
             $xCCont = new cCuentaContable($cuenta);
             $DetNivel = $xCCont->determineNivel($cuenta);
             $sucess = true;
             $naturaleza = $xFi->getV($tmp->NATURALEZA, false);
             $nivel = $xFi->getV($tmp->NIVEL, 0, MQL_INT);
             $nombre = "";
             $nombre .= isset($rows[3]) ? $rows[3] : "";
             $nombre .= isset($rows[4]) ? $rows[4] : "";
             $nombre .= isset($rows[5]) ? $rows[5] : "";
             $nombre .= isset($rows[6]) ? $rows[6] : "";
             $nombre .= isset($rows[7]) ? $rows[7] : "";
             $nombre .= isset($rows[8]) ? $rows[8] : "";
             $nombre = trim($nombre);
             $superior = $xCCont->getInmediatoSuperior();
             $cuenta = $xCCont->getCuentaCompleta($cuenta);
 $xFi->setLimitCampos(14);
 $xTmp = new cTmp();
 //$xFi->setToUTF8();
 //var_dump($_FILES["f1"]);
 //$xFi->setExo($esqueleto);
 //var_dump($_FILES);
 if ($xFi->processFile($doc1) == true) {
     $data = $xFi->getData();
     $conteo = 1;
     foreach ($data as $rows) {
         if ($conteo > 1) {
             $xFi->setDataRow($rows);
             $persona = $xFi->getEntero($xTmp->IDPERSONA);
             $xSoc = new cSocio($persona);
             if ($xSoc->init() == true) {
                 $calle = $xFi->cleanCalle($xFi->getV($xTmp->CALLE, ""));
                 $numero = $xFi->getV($xTmp->NUMERO, "");
                 $codigo_postal = $xFi->getEntero($xTmp->CODPOS, DEFAULT_CODIGO_POSTAL);
                 $referencia = $xFi->getV($xTmp->CRUCE, "");
                 $es_principal = setNoMenorQueCero($xFi->getEntero($xTmp->PRINCIPAL)) >= 1 ? TIPO_DOMICILIO_PRINCIPAL : TIPO_DOMICILIO_ORDINARIO;
                 $telefono1 = $xFi->getEntero($xTmp->TEL1);
                 $telefono2 = $xFi->getEntero($xTmp->TEL3);
                 $tipo_dom = setNoMenorQueCero($xFi->getEntero($xTmp->PRINCIPAL)) >= 1 ? TIPO_DOMICILIO_PARTICULAR : DEFAULT_TIPO_DOMICILIO;
                 $fechaVivienda = $xFi->getFecha($xTmp->FECHA);
                 $tiempo_de_residir = $xF->getEscalaTiempo($fechaVivienda);
                 $colonia = $xFi->getV($xTmp->COL);
                 if ($action == MQL_ADD) {
                     $xSoc->addVivienda($calle, $numero, $codigo_postal, "", $referencia, $telefono1, $telefono2, $es_principal, TIPO_VIVIENDA_PROPIA, $tipo_dom, $tiempo_de_residir, $colonia);
                     $xSoc->setUpdate(array("correo_electronico" => strtolower($xFi->cleanMail($xFi->getV($xTmp->MAIL))), "telefono_principal" => $xFi->getEntero($xTmp->TEL2)));
                 }
             }
 $xT = new cTipos();
 $delimiter = "|";
 //var_dump($_FILES);
 $xFi->setCharDelimiter($delimiter);
 $xFi->setLimitCampos(16);
 $xFi->setToUTF8();
 if ($primerosql == true) {
     if ($xFi->processFile($doc1) == true) {
         $data = $xFi->getData();
         $conteo = 1;
         foreach ($data as $rows) {
             $xFi->setDataRow($rows);
             $pkey = "";
             //var_dump($rows);
             foreach ($aKeyFile as $ikey) {
                 $pkey .= $xFi->getV($ikey);
                 // $rows[$ikey];
             }
             $pkey = preg_replace("/[^a-zA-Z0-9]+/", "", $pkey);
             $keyFile[$pkey] = $pkey;
             //$msg				.= "WARN\tAgregar ARCHIVO con ID $pkey\r\n";
             //echo "WARN\tAgregar ARCHIVO con ID $pkey\r\n";
         }
     }
     //$msg	.= $xFi->getMessages();
     $rs = $xQL->getDataRecord($sql);
     foreach ($rs as $rec) {
         $pkey = "";
         foreach ($aKeySql as $ikey) {
             $pkey .= $rec[$ikey];
         }