function setNewError($tipo = 0, $usr = false, $txt = "", $fecha = false)
 {
     $ip1 = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "0";
     $ip2 = isset($_SERVER['HTTP_VIA']) ? $_SERVER['HTTP_VIA'] : "DESCONOCIDO";
     $ip3 = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : "DESCONOCIDO";
     $defUsr = isset($_SESSION["SN_b80bb7740288fda1f201890375a60c8f"]) ? $_SESSION["SN_b80bb7740288fda1f201890375a60c8f"] : "USUARIO_DESCONOCIDO";
     $usr = $usr == false ? $defUsr : $usr;
     $txt = (!isset($txt) or $txt == false or $txt == "") ? "" : addslashes("{$txt}");
     //$txt 	= addslashes($txt);
     $fecha = $fecha == false ? date("Y-m-d") : $fecha;
     $hora = date("H:i:s");
     $sqlIE = "INSERT INTO general_log( fecha_log, hour_log, \r\n\t\t\t\t\t\t\ttype_error, usr_log, text_log,\r\n\t\t\t\t\t\t\tip_private, ip_proxy, ip_public) \r\n\t    \t\t\tVALUES('{$fecha}', '{$hora}', '{$tipo}', '{$usr}', '{$txt}', '{$ip1}', '{$ip2}', '{$ip3}')";
     $xMQL = new MQL();
     $xMQL->setRawQuery($sqlIE);
     return $xMQL->getLastInsertID();
 }
$aliasFil = getSucursal() . "-eventos-al-cierre-de-colocacion-del-dia-{$fechaop}";
$xLog = new cFileLog($aliasFil);
$ql = new MQL();
$xRec = new cReciboDeOperacion(12);
$xRec->setGenerarPoliza();
$xRec->setForceUpdateSaldos();
$idrecibo = $xRec->setNuevoRecibo(DEFAULT_SOCIO, DEFAULT_CREDITO, $fechaop, 1, 12, "CIERRE_DE_COLOCACION_{$fechaop}", DEFAULT_CHEQUE, DEFAULT_TIPO_PAGO, DEFAULT_RECIBO_FISCAL, DEFAULT_GRUPO);
$xRec->setNumeroDeRecibo($idrecibo);
$messages .= "=======================================================================================\r\n";
$messages .= "=========================\t\t" . EACP_NAME . " \r\n";
$messages .= "=========================\t\t" . getSucursal() . " \r\n";
$messages .= "=======================================================================================\r\n";
$messages .= "=========================\t\tINICIANDO EL CIERRE DE COLOCACION ====================\r\n";
$messages .= "=========================\t\tRECIBO: {$idrecibo}\t\t\t\t   ====================\r\n";
//reconstruir db de pagos
$ql->setRawQuery("CALL `proc_historial_de_pagos` ");
$xCUtils = new cUtileriasParaCreditos();
$messages .= $xCUtils->setEstatusDeCreditos($idrecibo, $fechaop, false, true);
if (date("Y-m-t", strtotime($fechaop)) == date("Y-m-d", strtotime($fechaop))) {
    $messages .= $xCUtils->setGenerarMvtoFinDeMes($xF->getDiaInicial(), $xF->getDiaFinal());
}
if (CREDITO_CIERRE_FORZAR_DEVENGADOS == true) {
    $messages .= $xCUtils->setReestructurarSDPM_Planes(true, false, false, false, $xF->getDiaInicial(), false);
    $messages .= $xCUtils->setReestructurarSDPM(true, false, false, false, false, $xF->getDiaInicial(), false);
    $messages .= $xCUtils->setRegenerarInteresDevengado(false, $xF->get(), $xF->get());
}
$messages .= $xCUtils->setAcumularIntereses();
$xRec->setFinalizarRecibo(true);
$xLog->setWrite($messages);
$xLog->setClose();
if (ENVIAR_MAIL_LOGS == true) {
 function setGuardarPerfilTransaccional($tipo, $pais, $monto, $numero, $observaciones, $fecha = false)
 {
     $fecha = $fecha == false ? fechasys() : $fecha;
     $xPT = new cPersonas_perfil_transaccional();
     $xTT = new cPersonas_perfil_transaccional_tipos();
     $xF = new cFecha();
     $ql = new MQL();
     $pais = strtoupper($pais);
     $persona = $this->mClaveDePersona;
     $id = $xPT->query()->getLastID();
     $xPT->cantidad_calculada(0);
     $fv = $xF->setSumarDias(AML_KYC_PERFIL_VIGENCIA, $fecha);
     $xTT->setData($xTT->query()->initByID($tipo));
     $ntipo = $xTT->nombre_del_perfil()->v();
     //Eliminar perfil parecido..
     $sql = "DELETE FROM personas_perfil_transaccional WHERE clave_de_persona = {$persona} AND clave_de_tipo_de_perfil = {$tipo} AND pais_de_origen='{$pais}' ";
     $ql->setRawQuery($sql);
     $xPT->afectacion($xTT->afectacion()->v());
     $xPT->cantidad_maxima($monto);
     $xPT->clave_de_persona($persona);
     $xPT->clave_de_tipo_de_perfil($tipo);
     $xPT->fecha_de_calculo($xF->getInt($fecha));
     $xPT->fecha_de_registro($xF->getInt($fecha));
     $xPT->fecha_de_vencimiento($xF->getInt($fv));
     $xPT->idpersonas_perfil_transaccional($id);
     $xPT->maximo_de_operaciones($numero);
     $xPT->observaciones($observaciones);
     $xPT->operaciones_calculadas(0);
     $xPT->pais_de_origen($pais);
     $ql = $xPT->query()->insert();
     $id = $ql->save();
     $this->mMessages .= $id == false ? "ERROR\tError al agregar el perfil tipo {$ntipo} por un monto de {$monto}\r\n" : "OK\tSe agrego el perfil {$id} de tipo {$ntipo} por un monto de {$monto}\r\n";
     if (MODO_DEBUG == true) {
         $this->mMessages .= $ql->getMessages(OUT_TXT);
     }
 }
 function set($valor, $parametro)
 {
     $parametro = strtoupper($parametro);
     //, fecha_de_alta='2014-5-23', fecha_de_expiracion='2014-5-23'
     $sql = "UPDATE creditos_productos_otros_parametros SET  valor_del_parametro='{$valor}' WHERE clave_del_producto=" . $this->mProducto . " AND clave_del_parametro='{$parametro}' ";
     $ql = new MQL();
     $ql->setRawQuery($sql);
 }
 function setFecha($fecha, $actualizacion = false)
 {
     $this->mFechaDeOperacion = $fecha;
     $recibo = $this->mCodigoDeRecibo;
     $this->mMessages .= "WARN\tRecibo {$recibo} . Actualizando la fecha " . $this->getFechaDeRecibo() . " A  {$fecha}\r\n";
     $xQL = new MQL();
     if ($actualizacion == true) {
         $xQL->setRawQuery("UPDATE operaciones_recibos SET fecha_operacion='{$fecha}' WHERE idoperaciones_recibos={$recibo}");
         if ($this->mUnicoDocto == true) {
             $xQL->setRawQuery("UPDATE operaciones_mvtos SET fecha_afectacion='{$fecha}', fecha_operacion='{$fecha}' WHERE recibo_afectado={$recibo}");
         }
         //actualizar tesoreria
         $xQL->setRawQuery("UPDATE tesoreria_cajas_movimientos SET  fecha='{$fecha}'    WHERE  recibo={$recibo}");
         //actualizar bancos
         $xQL->setRawQuery("UPDATE `bancos_operaciones` SET `fecha_expedicion`='{$fecha}' WHERE`recibo_relacionado`={$recibo}");
         //ejecutar aviso
         $xLog = new cCoreLog();
         $xLog->add($this->mMessages);
         $xLog->guardar($xLog->OCat()->EDICION_RAW);
     }
 }
 function setActualizaFondosCobrados($fondos = false)
 {
     if ($fondos === false) {
         if ($this->mArqueoInit == false) {
             $this->getResumenDeCaja();
         }
         //obtiene la suma de valores
         $fondos = $this->getSumaDeRecibos() - $this->getSumaDeCobros();
     }
     $sql = "UPDATE `tesoreria_cajas` SET `total_cobrado` = '{$fondos}' WHERE `idtesoreria_cajas` = '" . $this->getKey() . "' ";
     $ql = new MQL();
     $ql->setRawQuery($sql);
     return setNoMenorQueCero($fondos);
 }
$tabla = parametro("tabla", false, MQL_RAW);
$clave = parametro("id", false, MQL_RAW);
$rs = array();
//AND MODO_DEBUG == true
if ($tabla != false and $clave != false) {
    $xObj = new cSAFETabla($tabla);
    if ($xObj->obj() == null) {
        $rs["message"] = "ERROR\tAl eliminar el Registro con ID {$clave} en la Tabla {$tabla}\r\n";
        $rs["error"] = true;
    } else {
        $obj = $xObj->obj();
        $key = $obj->getKey();
        $obj = new cSocios_aeconomica();
        $obj->setData($obj->query()->initByID($clave));
        $data = base64_encode(json_encode($obj->query()->getCampos()));
        $ql->setRawQuery("DELETE FROM {$tabla} WHERE {$key}='{$clave}'");
        $rs["message"] = "OK\tSe elimina el Registro con ID {$clave} en la Tabla {$tabla}\r\n";
        if (MODO_DEBUG == true) {
            $rs["message"] .= $ql->getMessages();
        }
        $rs["error"] = false;
        //guardar error
        $xLog = new cCoreLog();
        $xLog->add($rs["message"] . " {$data}", $xLog->COMMON);
        $xLog->guardar($xLog->OCat()->ELIMINAR_RAW);
        //agregar memo
    }
}
header('Content-type: application/json');
echo json_encode($rs);
//setLog(json_encode($rs));
if ($preguntar == true) {
    header('Content-type: application/json');
    $arr = array("mensajes" => $msg, "registros" => $operaciones, "errores" => $totalerrores);
    echo json_encode($arr);
} else {
    if ($production == true and $errors == false and $operaciones > 0) {
        $archivo = $xLayout->getClave() . $xT->cSerial(6, $casfin) . $FechaTitulo . "." . $xT->cSerial(3, $supervisor);
        //header("Content-type: text/x-csv");
        header("Content-type: text/plain");
        //header("Content-type: application/csv");
        header("Content-Disposition: attachment; filename={$archivo}");
        echo $rpt;
        if ($definitivo == true) {
            //Guardar
            $sqlUpdate = " UPDATE `aml_risk_register` SET `estado_de_envio` = 1, `fecha_de_envio`= " . $xF->getInt() . "\n\t\t\tWHERE (SELECT `tipo_de_riesgo` FROM `aml_risk_catalog` WHERE\n\t\t\t(`clave_de_control`= `aml_risk_register`.`tipo_de_riesgo`= " . AML_CLAVE_OPERACIONES_INTERNAS . "\n\t\t\t\tOR\n\t\t\t`clave_de_control`= `aml_risk_register`.`tipo_de_riesgo`= " . AML_CLAVE_OPERACIONES_INUSUALES . ")\n\t\t\tAND (getFechaByInt(`aml_risk_register`.`fecha_de_reporte`) <='{$FechaFinal}')\n\t\t\tAND (`aml_risk_register`.`estado_de_envio` =0)\n\t\t\tAND (`aml_risk_register`.`reporte_inmediato` =1)\t\t\t\n\t\t\t";
            $query->setRawQuery($sqlUpdate);
            //enviar por mail al administrador
            $xMail = new cNotificaciones();
            $xMail->sendMail($archivo, $rpt, ADMIN_MAIL);
        }
    } else {
        $xRPT = new cReportes();
        $xRPT->setOut(OUT_HTML);
        $xRPT->addContent($xRPT->getHInicial($xHP->getTitle(), $FechaInicial, $FechaFinal));
        $arrTitulos = array();
        foreach ($Estructura as $indice => $propiedades) {
            $xCampo = new cReportes_LayoutTipos($propiedades);
            $arrTitulos[] = $xCampo->getNombre();
        }
        $xHTable->addTitles($arrTitulos);
        if ($msg != "") {
 function setBaja($idrazon, $notas = "", $fecha = false, $fecha_de_vencimiento = false, $documento = "1", $fecha_de_documento = false)
 {
     $persona = $this->mCodigo;
     $xF = new cFecha();
     $xB = new cSocios_baja();
     $xQL = new MQL();
     $fecha = $xF->getFechaISO($fecha);
     $fecha_de_vencimiento = $fecha_de_vencimiento == false ? $xF->getFechaMaximaOperativa() : $fecha_de_vencimiento;
     $fecha_de_documento = $fecha_de_documento == false ? $fecha : $fecha_de_documento;
     //Actualizar las bajas activas
     $sqlU = "UPDATE `socios_baja` SET `fecha_de_vencimiento` = '{$fecha}' WHERE `fecha_de_vencimiento`>='{$fecha}' AND `numero_de_socio`= {$persona}";
     $xQL->setRawQuery($sqlU);
     $xB->docto_presentado($documento);
     $xB->fecha_de_baja($fecha);
     $xB->fecha_de_documento($fecha_de_documento);
     $xB->fecha_de_vencimiento($fecha_de_vencimiento);
     $xB->numero_de_socio($persona);
     $xB->observaciones_de_baja($notas);
     $xB->razon_de_la_baja($idrazon);
     $xB->sucursal(getSucursal());
     $xB->idsocios_baja($xB->query()->getLastID());
     $succ = $xB->query()->insert()->save();
     if ($succ == false) {
     } else {
         $this->addMemo(MEMOS_TIPO_HISTORIAL, "BAJA-SUSPENSION: {$notas}", $fecha);
         $this->setUpdate(array("estatusactual" => 20));
     }
     //agregar Nota
     return $succ == false ? false : true;
 }
 function setEditar($cuenta, $cargo = false, $abono = false, $referencia = false, $concepto = false, $diario = DEFAULT_CONTABLE_DIARIO_MVTOS)
 {
     $xLog = new cCoreLog();
     //,$NumMvto = false, $Fecha = false
     $xCta = new cCuentaContableEsquema($cuenta);
     $cuenta = $xCta->CUENTA;
     $rebuild = false;
     if ($cargo !== false) {
         $cargo = setNoMenorQueCero($cargo);
         if ($cargo != $this->mCargo) {
             $rebuild = true;
             $this->mCargo = $cargo;
             $this->mAbono = 0;
         }
     }
     $referencia = $referencia == false ? $this->mObj->referencia()->v(OUT_TXT) : $referencia;
     $concepto = $concepto == false ? $this->mObj->concepto()->v(OUT_TXT) : $concepto;
     if ($abono !== false) {
         $abono = setNoMenorQueCero($abono);
         if ($abono != $this->mAbono) {
             $rebuild = true;
             $this->mAbono = $abono;
             $this->mCargo = 0;
         }
     }
     if ($this->mNumeroCuenta != $cuenta) {
         $rebuild = true;
         $this->mNumeroCuenta = $cuenta;
     }
     //========================
     if ($rebuild == true) {
         //eliminar
         $this->setEliminar();
         //agregar
         $xPol = new cPoliza($this->mTipoDePoliza);
         $xPol->setPorCodigo($this->getCodigoDePoliza());
         $xPol->addMovimiento($this->mNumeroCuenta, $this->mCargo, $this->mAbono, $referencia, $concepto, $this->mNumeroDeMvto);
         $xLog->add($xPol->getMessages(), $xLog->DEVELOPER);
     } else {
         $sql = "UPDATE contable_movimientos\n\t\t\tSET referencia='{$referencia}', concepto='{$concepto}' \n\t\t\tWHERE clave_unica= " . $this->mCodigoUnico;
         $ql = new MQL();
         $ql->setRawQuery($sql);
     }
     $this->mMessages .= $xLog->getMessages();
     return $xLog->getMessages();
 }
        $msg .= $xUAml->setActualizarNivelDeRiesgo($ForzarCorreccion);
        break;
    case 8203:
        $xUPers = new cPersonas_utils();
        $xUPers->setCrearArbolRelaciones();
        break;
    case 9001:
        $desucursal = $id;
        $asucursal = $id2;
        $ql = new MQL();
        $sql = "SHOW TABLES IN " . MY_DB_IN;
        $rs = $ql->getDataRecord($sql);
        foreach ($rs as $row) {
            $tabla = $row["Tables_in_" . MY_DB_IN];
            $isql = "UPDATE {$tabla} SET sucursal='{$asucursal}' WHERE sucursal='{$desucursal}' ";
            $ql->setRawQuery($isql);
            $ql->setRawQuery("UPDATE {$tabla} SET sucursal=LOWER(sucursal)");
        }
        break;
}
if ($command != false) {
    //Graba los Mensajes del LOG y cierra el Archivo
    $xFLog->setWrite($msg);
    $xFLog->setClose();
    echo $xFLog->getLinkDownload("Registro de Eventos");
}
?>
	</fieldset>
<?php 
$jxc->drawJavaScript(false, true);
?>
$xSys = new cSystemTask();
$xDB = new cSAFEData();
//crear backup //
if ($xF->getDiaFinal() == $xF->get() or date("N", $xF->getInt()) == 5) {
    $messages .= "BACKUP\tRespaldo a la fecha " . $xF->getFechaDDMM() . "\r\n";
    $xDB->setCheckDatabase();
    $messages .= $xSys->setBackupDB_WithMail();
}
//cerrar el log
$xLog->setWrite($messages);
$xLog->setClose();
if (ENVIAR_MAIL_LOGS == true) {
    $xLog->setSendToMail("TR.Eventos del Cierre del Sistema");
}
//Stored procedures
$ql->setRawQuery("CALL `proc_listado_de_ingresos` ");
//$ql->setRawQuery("CALL `proc_historial_de_pagos` ");
$ql->setRawQuery("CALL `sp_clonar_actividades` ");
$ql->setRawQuery("CALL `proc_perfil_egresos_por_persona` ");
$ql->setRawQuery("CALL `proc_creditos_letras_pendientes` ");
//
//Limpiar el Cache
//$xSys->setPowerOff();
//apagar el sistema
$xCache = new cCache();
$xCache->clean();
if ($parser != false) {
    $log = $aliasFil;
    $xPage = new cHPage("TR.Cierre del Dia", HP_FORM);
    $xBtn = new cHButton("iact");
    $oFRM = new cHForm("frmSubmit", "");
 function setActualizarPrimerPago($default_fecha = "2014-01-01")
 {
     $xLi = new cSQLListas();
     $query = new MQL();
     $sql = $xLi->getInicialDeCreditos() . " WHERE `creditos_solicitud`.`fecha_de_primer_pago` ='{$default_fecha}'";
     // AND `creditos_solicitud`.`periocidad_de_pago` != " . CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO . " ";
     $data = $query->getDataRecord($sql);
     $msg = "";
     $FechaFinal = "";
     $ByPersona1 = "";
     $ByPersona3 = "";
     $rsPagos = $query->getDataRecord("SELECT * FROM `creditos_abonos_parciales` WHERE periodo_socio = 1 ");
     // /*WHERE	(`creditos_abonos_parciales`.`fecha_de_pago` <='$FechaFinal') $ByPersona1 */");
     $DPagos = array();
     foreach ($rsPagos as $dpags) {
         $credito = $dpags["docto_afectado"];
         $DPagos[$credito][] = $dpags;
     }
     $rsCal = $query->getDataRecord("SELECT * FROM `letras` WHERE periodo_socio = 1 ");
     // /*WHERE	(`fecha_de_pago` <='$FechaFinal') $ByPersona3 */");
     $DCal = array();
     foreach ($rsCal as $dscal) {
         $credito = $dscal["docto_afectado"];
         $DCal[$credito][] = $dscal;
     }
     foreach ($data as $rows) {
         $idcredito = $rows["numero_solicitud"];
         $antes = $rows["fecha_de_primer_pago"];
         $periocidad = $rows["periocidad_de_pago"];
         $FPrimerAb = false;
         $Tipo = "";
         if ($periocidad == CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
             $xCred = new cCredito($idcredito);
             $xCred->init($rows);
             $FPrimerAb = $xCred->getFechaDevencimientoLegal();
         } else {
             //info pagos
             $d1 = isset($DCal[$idcredito]) ? $DCal[$idcredito] : false;
             $d2 = isset($DPagos[$idcredito]) ? $DPagos[$idcredito] : false;
             if ($d2 == false) {
                 if ($d1 != false) {
                     $Tipo = "PLAN";
                     $record = $d2[0];
                     $FPrimerAb = $record["fecha_de_pago"];
                 }
             } else {
                 $Tipo = "PAG";
                 $record = $d2[0];
                 $FPrimerAb = $record["fecha_de_pago"];
             }
             if ($FPrimerAb == false) {
                 $xPlanGen = new cPlanDePagosGenerador();
                 $xPlanGen->initPorCredito($idcredito, $rows);
                 $FPrimerAb = $xPlanGen->getFechaDePrimerPago();
                 $Tipo = "EST";
             }
         }
         $msg .= "WARN\t{$idcredito}\t{$Tipo}\tLa fecha de Primer abono es {$FPrimerAb} de {$antes}\r\n";
         $query->setRawQuery("UPDATE creditos_solicitud SET `fecha_de_primer_pago`='{$FPrimerAb}' WHERE numero_solicitud = {$idcredito} ");
     }
     return $msg;
 }
 function patch($force = false, $version_inicial = false, $soloIdioma = false)
 {
     $ql = new MQL();
     $xConf = new cConfiguration();
     $localver = $xConf->get("safe_osms_database_version");
     //Actualiza la configuracion
     //if($force == true){			$xConf->set("safe_osms_database_version", $version);		}
     if (FORCE_UPDATES_ON_BOOT == true or $force == true) {
         //Ejecutar Vistas y Functions
         if ($soloIdioma == false) {
             $this->setAplicarScripts();
         }
         $current = $version_inicial === false ? intval(SAFE_DB_VERSION) : $version_inicial;
         //201406.01
         $dbversion = intval(SAFE_VERSION . SAFE_REVISION);
         $sqlMenu = "INSERT INTO `general_menu` (`idgeneral_menu`, `menu_parent`, `menu_title`, `menu_file`, `menu_type`, `menu_order`) VALUES ";
         $lang = array();
         $sql = array();
         $xSrv = new MQLService("", "");
         $ulang = $xSrv->getRequest(URL_UPDATES . "install/updates/lang.php");
         $lang = json_decode($ulang, true);
         $ulang2 = $xSrv->getRequest(URL_UPDATES . "install/updates/lang2.php");
         $lang2 = json_decode($ulang2, true);
         $usql = $xSrv->getRequest(URL_UPDATES . "install/updates/sql.php?version={$localver}");
         $sql = json_decode($usql, true);
         //setLog(URL_UPDATES . "install/updates/sql.php?version=$dbversion");
         $this->mMessages .= "URL\t" . URL_UPDATES . "install/updates/sql.php?version={$localver}" . "\r\n";
         $upt = false;
         if (is_array($lang)) {
             foreach ($lang as $version => $patchs) {
                 if ($current <= intval($version)) {
                     foreach ($patchs as $idx => $content) {
                         $palabra = $content[0];
                         $traduccion = $content[1];
                         $language = $content[2];
                         $this->addLang($palabra, $traduccion, $language);
                     }
                     $upt = true;
                 }
             }
         }
         if (is_array($lang2)) {
             foreach ($lang2 as $version2 => $patchs2) {
                 if ($current <= intval($version2)) {
                     foreach ($patchs2 as $idx2 => $content2) {
                         $palabra = $content2[0];
                         $spanish = $content2[1];
                         $english = $content2[2];
                         $this->addLang($palabra, $spanish, "es");
                         $this->addLang($palabra, $english, "en");
                     }
                     $upt = true;
                 }
             }
         }
         if ($soloIdioma == false) {
             foreach ($sql as $version => $patchs) {
                 if ($current <= intval($version)) {
                     $this->mMessages .= "WARN\t===========PATCH {$version}\r\n";
                     foreach ($patchs as $idx => $content) {
                         $ql->setRawQuery($content);
                         $content = preg_replace('!\\s+!', ' ', $content);
                         $this->mMessages .= "{$idx}\t===={$content}====\r\n";
                         $upt = true;
                         //syslog(E_ERROR, $content);
                     }
                 } else {
                     $this->mMessages .= "WARN\tDescartado por ser {$version} de {$current}\r\n";
                 }
             }
             //Obtener el codigo y parcharlo
             //URL_UPDATES
             //Convierte la DB a UTF8
             //ALTER TABLE `operaciones_recibos` CHANGE COLUMN `clave_de_moneda` `clave_de_moneda` VARCHAR(6) NULL DEFAULT 'MXN', ADD COLUMN `archivo_fisico` VARCHAR(200) NULL COMMENT 'Archivo fisico del recibo, almacenado en server ftp' AFTER `origen_aml`
             $codif = $ql->getDataRecord("SHOW TABLES IN " . MY_DB_IN);
             foreach ($codif as $rows) {
                 $table = $rows["Tables_in_" . MY_DB_IN];
                 $trs = "ALTER TABLE `{$table}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
                 //$ql->setRawQuery($trs);
             }
             $ql->setRawQuery("ALTER SCHEMA `" . MY_DB_IN . "`  DEFAULT CHARACTER SET utf8  DEFAULT COLLATE utf8_general_ci");
         }
         //Actualizar vistas y functions
         if ($soloIdioma == false) {
             if ($this->setAplicarScripts() == false) {
                 $this->mMessages .= "ERROR\tAl Aplicar Vistas y funciones...\r\n";
             } else {
                 $this->mMessages .= "OK\tSe aplicaron Vistas y funciones...\r\n";
             }
         }
         //ejecutar Mensajes
         $this->mMessages .= $ql->getMessages(OUT_TXT);
         if ($upt == true) {
             /*Actualiza la configuracion*/
             $xConf->set("safe_osms_database_version", $dbversion);
         }
     } else {
         $this->mMessages .= "WARN\tSistema no Actualizado\r\n";
     }
     return $this->mMessages;
 }
 function setCrearArbolRelaciones()
 {
     $QL = new MQL();
     //$id		= $this->mPersona;
     $sql = "SELECT `socios_relaciones`.`socio_relacionado`, `socios_relaciones`.`numero_socio` FROM `socios_relaciones` `socios_relaciones`  /*WHERE `socio_relacionado`=1901873*/ ";
     $QL->setRawQuery("DELETE FROM `personas_relaciones_recursivas`");
     $rs = $QL->getDataRecord($sql);
     $data = array();
     $datos = array();
     //array persona => relacion = nivel
     $nodos = array();
     $puntos = array();
     $Directos = array();
     $Niveles = array();
     foreach ($rs as $rw) {
         $persona = $rw["socio_relacionado"];
         $relacion = $rw["numero_socio"];
         $data[$persona][] = $relacion;
     }
     foreach ($data as $clave => $contenido) {
         foreach ($contenido as $idx => $xrelacion1) {
             $arrCurrRel = array();
             $arrCurrRel[$clave] = true;
             $isql = "";
             //existe relacion
             //Nivel 1
             $isql .= " ('{$clave}', '{$xrelacion1}', '1', '{$clave}') ";
             //Nivel 2
             if (isset($data[$xrelacion1]) and !isset($arrCurrRel[$xrelacion1])) {
                 $DN2 = $data[$xrelacion1];
                 $arrCurrRel[$xrelacion1] = true;
                 foreach ($DN2 as $idx2 => $xrelacion2) {
                     $isql .= ", ('{$clave}', '{$xrelacion2}', '2', '{$xrelacion1}') ";
                     //Nivel 3
                     if (isset($data[$xrelacion2]) and !isset($arrCurrRel[$xrelacion2])) {
                         $DN3 = $data[$xrelacion2];
                         $arrCurrRel[$xrelacion2] = true;
                         foreach ($DN3 as $idx3 => $xrelacion3) {
                             $isql .= ", ('{$clave}', '{$xrelacion3}', '3', '{$xrelacion2}') ";
                             //Nivel 4
                             if (isset($data[$xrelacion3]) and !isset($arrCurrRel[$xrelacion3])) {
                                 $DN4 = $data[$xrelacion3];
                                 $arrCurrRel[$xrelacion3] = true;
                                 foreach ($DN4 as $idx4 => $xrelacion4) {
                                     $isql .= ", ('{$clave}', '{$xrelacion4}', '4', '{$xrelacion3}') ";
                                     //Nivel 5
                                     if (isset($data[$xrelacion4]) and !isset($arrCurrRel[$xrelacion4])) {
                                         $DN5 = $data[$xrelacion4];
                                         $arrCurrRel[$xrelacion4] = true;
                                         foreach ($DN5 as $idx5 => $xrelacion5) {
                                             $isql .= ", ('{$clave}', '{$xrelacion5}', '5', '{$xrelacion4}') ";
                                             if (isset($data[$xrelacion5]) and !isset($arrCurrRel[$xrelacion5])) {
                                                 $DN6 = $data[$xrelacion5];
                                                 $arrCurrRel[$xrelacion5] = true;
                                                 foreach ($DN6 as $idx6 => $xrelacion6) {
                                                     $isql .= ", ('{$clave}', '{$xrelacion6}', '6', '{$xrelacion5}') ";
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             /* else { echo "$xrelacion1 No hay N2\r\n";}*/
             //si hay nivel 2
             //Terminar Insert
             $QL->setRawQuery("INSERT INTO `personas_relaciones_recursivas` (`persona`, `relacion`, `nivel`, `proxy`) VALUES {$isql} ");
         }
     }
     //foreach ($datos as $personas => $relacion){
     //$QL->setRawQuery("");
     //}
 }