$svc = new MQLService("", "");
$ql = new MQL();
$data = isset($_REQUEST["data"]) ? $svc->getDecryptData($_REQUEST["data"]) : null;
$command = isset($_REQUEST["cmd"]) ? $svc->getDecryptData($_REQUEST["cmd"]) : null;
//$context	= (isset($_REQUEST["ctx"])) ? $svc->getDecryptData($_REQUEST["ctx"]) : null;
$cnt = "";
//setLog("$data $command");
switch ($command) {
    case TPERSONAS_GENERALES:
        $xSoc = new cSocios_general();
        $xSoc->setData($xSoc->query()->initByID($data));
        $cnt = $svc->getEncryptData(json_encode($xSoc->query()->getCampos()));
        //setLog(json_encode($xSoc->query()->getCampos()));
        break;
    case TPERSONAS_DIRECCIONES:
        $xDom = new cSocios_vivienda();
        $D = obten_filas("SELECT * FROM socios_vivienda WHERE socio_numero = {$data} ORDER BY fecha_alta DESC LIMIT 0,1");
        $xDom->setData($D);
        //setLog("SELECT * FROM socios_vivienda WHERE socio_numero = $data ORDER BY fecha_alta DESC LIMIT 0,1");
        //$value = mb_check_encoding($value, 'UTF-8') ? $value : utf8_encode($value);
        //$comment = iconv('UTF-8', 'UTF-8//IGNORE', $comment);
        //SELECT column1, CONVERT(column2 USING utf8)
        $query = $xDom->query();
        $query->setToUTF8();
        //setLog(json_encode($query->getCampos()) );
        $cnt = $svc->getEncryptData(json_encode($query->getCampos()));
        break;
    case TPERSONAS_ACTIVIDAD_ECONOMICA:
        $xTrab = new cSocios_aeconomica();
        $D = obten_filas("SELECT * FROM `socios_aeconomica` WHERE\t(`socios_aeconomica`.`socio_aeconomica` = {$data} ) ORDER BY `socios_aeconomica`.`fecha_alta` DESC\tLIMIT 0,1");
        $xTrab->setData($D);
 function setCorregirDomicilios($correcion = false)
 {
     //obtener codigo postal
     $msg = "";
     //verificar si existe persona
     $ql = new MQL();
     $rs = $ql->getDataRecord("SELECT * FROM `socios_vivienda`");
     $xViv = new cSocios_vivienda();
     $xT = new cTipos();
     $xT->setForceMayus();
     $xT->setToUTF8();
     $xT->setForceClean();
     foreach ($rs as $rows) {
         $xViv->setData($rows);
         //codigo_postal
         $codigo_postal = $xViv->codigo_postal()->v();
         $id = $xViv->idsocios_vivienda()->v();
         $xCol = new cDomiciliosColonias();
         $idunico = $xCol->getClavePorCodigoPostal($codigo_postal);
         //corregir codigo postal
         //optener CP por sucursal
         if ($idunico <= 0) {
             //asignar codigo postal
             //iniciar por sucursal
             $xSuc = new cSucursal($xViv->sucursal()->v());
             if ($xSuc->init() == true) {
                 $codigo_postal = $xSuc->getCodigoPostal();
                 $idunico = $xCol->getClavePorCodigoPostal($codigo_postal);
                 $xViv->codigo_postal($codigo_postal);
             }
         }
         //verificar principal
         if (trim($xViv->principal()->v()) == "") {
             $xViv->principal(TIPO_DOMICILIO_PRINCIPAL);
         }
         //corregir pais
         if (trim($xViv->nombre_de_pais()->v()) == "") {
             $xViv->nombre_de_pais(strtoupper(EACP_DOMICILIO_PAIS));
         } else {
             $xViv->nombre_de_pais(strtoupper($xViv->nombre_de_pais()->v()));
         }
         if ($idunico > 0) {
             //cargar colonia
             $estado = $xViv->estado()->v();
             //if($xViv->clave_de_pais()->v() != $xCol->get)
             if ($estado != $xCol->getNombreEstado()) {
                 //$msg		.= "ERROR\tEl Estado " . $xViv->estado()->v() .  " es diferente a " . $xT->cChar( $xCol->getNombreEstado()) . "\r\n";
                 //$estado		= $xT->cChar( $xCol->getNombreEstado());
             }
             if ($correcion == true) {
                 //$msg		.= "OK\tCorrecion autorizada\r\n";
                 $xViv->estado($xT->cChar($xCol->getNombreEstado()));
                 $xViv->municipio($xT->cChar($xCol->getNombreMunicipio()));
                 $xViv->localidad($xT->cChar($xCol->getNombreLocalidad()));
                 $xViv->clave_de_localidad($xCol->getClaveDeLocalidad());
                 if (PERSONAS_PERMITIR_EXTRANJEROS == false) {
                     $xViv->clave_de_pais(EACP_CLAVE_DE_PAIS);
                 }
                 $qup = $xViv->query()->update();
                 $rx = $qup->save($id);
                 if ($rx == true) {
                     $msg .= "OK\tVivienda con CP {$codigo_postal} e ID {$id} actualizado a la Colonia {$idunico}\r\n";
                 } else {
                     $msg .= "ERROR\tAl actualizar la Vivienda con CP {$codigo_postal} e ID {$id} . Colonia {$idunico}\r\n";
                 }
                 if (MODO_DEBUG == true) {
                     $msg .= $qup->getMessages();
                 }
             }
         } else {
             $msg .= "WARN\tCodigo omitido por ser {$codigo_postal}\r\n";
         }
     }
     return $msg;
 }
 function getImportarDesdeAsociada($tipo)
 {
     $result = true;
     $svc = new MQLService("", "");
     $cmd = $svc->getEncryptData($tipo);
     $xTu = new cSystemUser(TASK_USR, false);
     $xTu->init();
     $ctx = $xTu->getCTX();
     $data = $svc->getEncryptData($this->mCodigo);
     $host = SVC_ASOCIADA_HOST;
     switch ($tipo) {
         case TPERSONAS_GENERALES:
             $dpersona = $svc->getService($host . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
             if (is_array($dpersona)) {
                 $xSoc = new cSocios_general($dpersona);
                 if (setNoMenorQueCero($xSoc->codigo()->v()) > 0) {
                     $xSoc->query()->insert()->save();
                     $result = true;
                 }
             }
             break;
         case TPERSONAS_DIRECCIONES:
             $ddomicilio = $svc->getService($host . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
             if (is_array($ddomicilio)) {
                 $xDom = new cSocios_vivienda($ddomicilio);
                 if (setNoMenorQueCero($xDom->idsocios_vivienda()->v())) {
                     $xDom->query()->insert()->save();
                     $result = true;
                 }
             }
             break;
         case TPERSONAS_ACTIVIDAD_ECONOMICA:
             $dtrabajo = $svc->getService($host . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
             if (is_array($dtrabajo)) {
                 $xTrab = new cSocios_aeconomica($dtrabajo);
                 if (setNoMenorQueCero($xTrab->idsocios_aeconomica()->v())) {
                     $xTrab->query()->insert()->save();
                     $result = true;
                 }
             }
             break;
         case TCATALOGOS_EMPRESAS:
             $dempresa = $svc->getService($host . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
             if (is_array($dempresa)) {
                 $xEmp = new cSocios_aeconomica_dependencias($dempresa);
                 if (setNoMenorQueCero($xEmp->idsocios_aeconomica_dependencias()->v())) {
                     $xEmp->query()->insert()->save();
                     $result = true;
                 }
             }
             break;
     }
     return $result;
 }
$xTu->init();
$ctx = $xTu->getCTX();
$cmd = $svc->getEncryptData($command);
switch ($command) {
    case TPERSONAS_GENERALES:
        $dpersona = $svc->getService(SVC_ASOCIADA_HOST . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
        if (is_array($dpersona)) {
            $xSoc = new cSocios_general($dpersona);
            $xSoc->query()->insert()->save();
            //Iniciar Cuenta de Captacion
        }
        break;
    case TPERSONAS_DIRECCIONES:
        $ddomicilio = $svc->getService(SVC_ASOCIADA_HOST . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
        if (is_array($ddomicilio)) {
            $xDom = new cSocios_vivienda($ddomicilio);
            $xDom->query()->insert()->save();
        }
        break;
    case TPERSONAS_ACTIVIDAD_ECONOMICA:
        $dtrabajo = $svc->getService(SVC_ASOCIADA_HOST . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
        if (is_array($dtrabajo)) {
            $xAe = new cSocios_aeconomica($dtrabajo);
            $xAe->query()->insert()->save();
        }
        break;
    case TCATALOGOS_EMPRESAS:
        $dempresa = $svc->getService(SVC_ASOCIADA_HOST . "svc/exportar.svc.php?ctx={$ctx}&data={$data}&cmd={$cmd}");
        foreach ($dempresa as $indice => $valor) {
            if ($indice == TCATALOGOS_EMPRESAS) {
                $dempresa = $valor;