function setValidarCuentas($ForzarCorreccion = false)
 {
     $msg = "";
     $msg .= "============== VALIDANDO CUENTAS DE CAPTACION\t==========\r\n";
     $msg .= "============== FECHA:     " . fechasys() . "             ==========\r\n";
     /**
      * Valida si la Cuenta de captacion por defecto existe 
      * @since 2010-12-31
      */
     $xPCta = new cCuentaALaVista(CTA_GLOBAL_CORRIENTE, DEFAULT_SOCIO);
     if ($xPCta->setContarCuenta() == 0) {
         $msg .= "LA Cuenta por DEFECTO no EXISTE\r\n";
         $xPCta->setNuevaCuenta(99, 1, DEFAULT_SOCIO, "", DEFAULT_CREDITO, "", "", DEFAULT_GRUPO, false, 10);
         $msg .= $xPCta->getMessages("txt");
     }
     $xTb = new cSAFETabla(TCAPTACION_CUENTAS);
     $SqlCta = $xTb->getQueryInicial() . "\n\t\t\t\tFROM\n\t\t\t\t\t`captacion_cuentas` `captacion_cuentas`\n\t\t\t\t\t\tINNER JOIN `captacion_cuentastipos` `captacion_cuentastipos`\n\t\t\t\t\t\tON `captacion_cuentas`.`tipo_cuenta` = `captacion_cuentastipos`.\n\t\t\t\t\t\t`idcaptacion_cuentastipos`\n\t\t\t\t\t\t\tINNER JOIN `captacion_subproductos` `captacion_subproductos`\n\t\t\t\t\t\t\tON `captacion_cuentas`.`tipo_subproducto` = `captacion_subproductos`\n\t\t\t\t\t\t\t.`idcaptacion_subproductos` ";
     $rs = getRecordset($SqlCta);
     while ($rw = mysql_fetch_array($rs)) {
         $xCta = new cCuentaDeCaptacion($rw["numero_cuenta"], $rw["numero_socio"]);
         $xCta->init($rw);
         $msg .= $xCta->setValidar($ForzarCorreccion);
         //$msg		.= $xCta->getMessages("txt");
     }
     return $msg;
 }
 $xFRM->addToolbar($xBtn->getIrAlInicio(true));
 $xCta = new cCuentaALaVista($iddocto, $idsocio);
 if ($xCta->init() == true) {
     //$xCta->setCuentaBancaria($cuenta_cheques);
     $maximo_retirable = $xCta->getMaximoRetirable();
     if ($monto > $maximo_retirable) {
         $msg .= "ERROR\tNo puede Retirar mas de {$maximo_retirable}, usted quizo retirar {$monto}\r\n";
         $sucess = false;
     } else {
         $recibo = $xCta->setRetiro($monto, $cheque, $comopago, $foliofiscal, $detalles, DEFAULT_GRUPO, $Fecha);
     }
 } else {
     $sucess = false;
 }
 if (MODO_DEBUG == true) {
     $msg .= $xCta->getMessages();
 }
 $xFRM->addAviso($msg);
 if ($sucess == true) {
     //Imprime la Ficha del socio
     $xCta->init();
     $xSoc = new cSocio($xCta->getClaveDePersona());
     $xSoc->init();
     $xFRM->addHTML($xSoc->getFicha());
     $xFRM->addHTML($xCta->getFicha(true));
     $xFRM->addHTML($xCta->getORec()->getFicha(true));
     $xFRM->addHTML($xCta->getORec()->getJsPrint(true));
     // *****************************************************************************
     $xFRM->addPrintRecibo();
     $xFRM->addAvisoRegistroOK();
 }
                 $xCL = new cCajaLocal(99);
                 if ($xCL->getExistenciaSocio($socio) <= 0) {
                     $msg .= "{$iReg}\t{$socio}\tERROR_SOCIO\tLa Linea({$iReg}) no se leyo por que no existe el socio. (" . substr($bufer, 0, 20) . ")\r\n";
                 } else {
                     $xCta = new cCuentaALaVista($NumCuenta, $socio, 0, false, $fechaApertura);
                     if ($xCta->setContarCuenta() <= 0) {
                         $xCta = new cCuentaALaVista(false, $socio, 0, false, $fechaApertura);
                         $NumCuenta = $xCta->setNuevaCuenta(99, $Producto, $socio, $observaciones, DEFAULT_CREDITO, "", "", DEFAULT_GRUPO, $fechaApertura, 10);
                         $msg .= "{$iReg}\t{$socio}\tCUENTA\tSe Agrego Exitosamente la cuenta {$NumCuenta} \r\n";
                     }
                     if ($NumCuenta != false) {
                         if ($importe > 0) {
                             $xCta->init();
                             $RDeposito = $xCta->setDeposito($importe, DEFAULT_CHEQUE, DEFAULT_TIPO_PAGO, DEFAULT_RECIBO_FISCAL, $observaciones, DEFAULT_GRUPO, $fechaApertura);
                             $msg .= "{$iReg}\t{$socio}\tRECIBO_DEPOSITO\tSe Efectua un Deposito de {$importe} al Recibo {$RDeposito}\r\n";
                             $msg .= $xCta->getMessages("txt");
                         }
                     } else {
                         $msg .= "{$iReg}\t{$socio}\tERROR\tSe Fallo al Agregar la Cuenta\r\n";
                     }
                 }
             }
             $iReg++;
         }
     }
     fclose($gestor);
     $xLog->setWrite($msg);
     echo $xLog->getLinkDownload("Archivo del proceso");
 } else {
     echo "<p class='aviso'>EL TIPO DE ARCHIVO DE " . $usrFiles[$i]['name'] . "(" . $mExt . ") NO SE ACEPTA</p>";
 }
function Common_c5fe0408555dbf392918c6f77a4d01b2($params)
{
    $stdDiv = STD_LITERAL_DIVISOR;
    $DPar = explode($stdDiv, $params, 10);
    //mensajes
    //grupo
    $xTip = new cTipos();
    //
    $socio = $xTip->cInt($DPar[0]);
    $credito = $xTip->cInt($DPar[1]);
    $letra = $xTip->cInt($DPar[2]);
    $capital = $xTip->cFloat($DPar[3]);
    $interes = $xTip->cFloat($DPar[4]);
    $iva = $xTip->cFloat($DPar[5]);
    $ahorro = $xTip->cFloat($DPar[6]);
    $nota = $xTip->cChar($DPar[7]);
    $numero = $xTip->cInt($DPar[8]);
    $limit = $xTip->cInt($DPar[9]);
    $msg = "====================== MOVIMIENTO {$numero} DE {$limit} ====================\r\n";
    //Datos del Credito
    $Cred = new cCredito($credito, $socio);
    $Cred->initCredito();
    $DCred = $Cred->getDatosDeCredito();
    $saldo = $DCred["saldo_actual"] - $capital;
    $contrato_captacion = $DCred["contrato_corriente_relacionado"];
    $grupo = $DCred["grupo_asociado"];
    $msg .= $Cred->getMessages();
    if (isset($_SESSION["recibo_en_proceso"])) {
        $recibo = $_SESSION["recibo_en_proceso"];
        $fecha = fechasys();
        $_SESSION["total_recibo_en_proceso"] += $capital + $interes + $ahorro;
        $xRec = new cReciboDeOperacion(200, false, $recibo);
        $xRec->setNumeroDeRecibo($recibo, true);
        $xRec->setNumeroDeRecibo($recibo, true);
        $DRec = $xRec->getDatosInArray();
        $cheque = $DRec["cheque_afectador"];
        $tipopago = $DRec["tipo_pago"];
        $recibofiscal = $DRec["recibo_fiscal"];
        $xRec->setGenerarPoliza();
        $msg .= "{$socio}\t{$credito}\tCREDITO\tMovimiento {$i} del Credito {$credito} del Socio {$socio} con Saldo {$saldo}\r\n ";
        $msg .= "{$socio}\t{$credito}\tMONTOS\tCapital: {$capital} || Interes: {$interes} || Ahorro: {$ahorro} \r\n";
        //Agregando Capital
        if ($capital > 0) {
            $xRec->setNuevoMvto($fecha, $capital, 120, $letra, $nota . ";SDO:" . $saldo, 1, TM_ABONO, $socio, $credito);
            $arrCred = array("saldo_actual" => $saldo);
            $Cred->setUpdate($arrCred);
        }
        //Agregando Interes
        if ($interes > 0) {
            $xRec->setNuevoMvto($fecha, $interes, 140, $letra, $nota, 1, TM_ABONO, $socio, $credito);
        }
        //agregando el IVA
        if ($interes > 0) {
            $xRec->setNuevoMvto($fecha, $iva, 151, $letra, $nota, 1, TM_ABONO, $socio, $credito);
        }
        //Agregando Ahorro
        if ($ahorro > 0) {
            $xC = new cCuentaALaVista($contrato_captacion);
            if (!isset($contrato_captacion) or $contrato_captacion == CTA_GLOBAL_CORRIENTE or $contrato_captacion == 0) {
                $contrato_captacion = $xC->setNuevaCuenta(2, 1, $socio, "CUENTA_AUTOMATICA", $credito);
                $msg .= "{$socio}\t{$credito}\tNuevaCta\tse dio de alta a la cuenta {$contrato_captacion}\r\n";
                //2011-nov-30 se agrego la actualizacion del contrato relacionado
                $arrCred = array("contrato_corriente_relacionado" => $contrato_captacion);
                $Cred->setUpdate($arrCred);
            }
            $xC = new cCuentaALaVista($contrato_captacion);
            $xC->setSocioTitular($socio);
            $xC->setReciboDeOperacion($recibo);
            $xC->setDeposito($ahorro, $cheque, $tipopago, $recibofiscal, $nota, $grupo, $fecha, $recibo);
            $msg .= $xC->getMessages("txt");
            $msg .= "{$socio}\t{$credito}\tAhorro\t El Saldo Quedo en " . $xC->getNuevoSaldo() . "\r\n";
        }
        $msg .= "{$socio}\t{$credito}\tObservacion\t {$nota}\r\n";
        $msg .= $xRec->getMessages("txt");
    } else {
        $msg .= "NO_SE_HA_DEFINIDO_UN_RECIBO";
    }
    $xLog = new cFileLog("log_de_recibo_" . $recibo);
    $xLog->setWrite($msg);
    $xLog->setClose();
    $MsgEnd = "";
    if ($numero == $limit) {
        $xRec->setForceUpdateSaldos();
        $xRec->setFinalizarRecibo(true);
        //$MsgEnd		.= "**** proceso terminado ****";
    }
    //retorna el id del control de origen para neutralizar
    return "-{$numero}";
}
//Verificar lo Valores por defecto
if ($xSuc->existeSocio(DEFAULT_SOCIO) == false) {
    $cajaLocalR = $xSuc->getCajaLocalResidente();
    $xSoc = new cSocio(DEFAULT_SOCIO);
    $xSoc->add("", "PUBLICO_GENERAL", "", "POR_REGISTRAR", "POR_REGISTRAR", $cajaLocalR, false, "DESCONOCIDO", 99, 99, 99, 99, 99, 1, DEFAULT_GRUPO, "", 1, "0", DEFAULT_SOCIO, getSucursal());
    $messages .= $xSoc->getMessages(OUT_TXT);
}
if ($xSuc->existeCredito(DEFAULT_CREDITO) == false) {
    $xCred = new cCredito(DEFAULT_CREDITO, DEFAULT_SOCIO);
    $xCred->add(DEFAULT_TIPO_CONVENIO, DEFAULT_SOCIO, DEFAULT_CUENTA_CORRIENTE, 0, CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO, 1, 1, CREDITO_DEFAULT_DESTINO, DEFAULT_CREDITO, DEFAULT_GRUPO, "CREDITO POR DEFECTO");
    $messages .= $xCred->getMessages(OUT_TXT);
}
if ($xSuc->existeCuenta(DEFAULT_CUENTA_CORRIENTE) == false) {
    $xCta = new cCuentaALaVista(DEFAULT_CUENTA_CORRIENTE);
    $xCta->setNuevaCuenta("99", "99", DEFAULT_SOCIO);
    $messages .= $xCta->getMessages(OUT_TXT);
}
$ql = new MQL();
/*
 * ====================================================================================================================================================
 * Agregar codigo de actualizar menores a personas fisicas
 * ====================================================================================================================================================
 */
$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 SISTEMA     ====================\r\n";
$messages .= "=========================\t\tRECIBO: {$idrecibo}\t\t\t\t   ====================\r\n";
//2011-01-26 : Agrega un recibo estadistico de control diario
$xNRec = new cReciboDeOperacion(10);
 function setConciliarCuentas($AppSucursal)
 {
     $msg = "";
     $AppSucursal = strtoupper($AppSucursal);
     $BySucursal = " AND (`sucursal` ='" . getSucursal() . "')  ";
     if ($AppSucursal != "SI") {
         $BySucursal = "";
     }
     //Crea un Array de los saldos de la Cuenta
     $arrSdoCtas = array();
     $arrNumCtas = array();
     $arrSdoCW = array();
     //
     $sqlCW = "SELECT\n\t\t\t\t\t\t\t\tCOUNT(`sisbancs_temp_depositos`.`numero_de_socio`) AS `existentes`,\n\t\t\t\t\t\t\t\t`sisbancs_temp_depositos`.`numero_de_socio`\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t`sisbancs_temp_depositos` `sisbancs_temp_depositos`\n\n\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\t`sisbancs_temp_depositos`.`numero_de_socio` ";
     $rsA = getRecordset($sqlCW);
     while ($rw = mysql_fetch_array($rsA)) {
         $arrSdoCW[$rw["numero_de_socio"]] = $rw["existentes"];
     }
     unset($rsA);
     unset($rw);
     // obtiene las cuentas tipo 10[A LA VISTA] en safe y crea un array
     $sqlSdoCta = " SELECT SQL_CACHE\n\t\t\t\t\t\t\t`captacion_cuentas`.`numero_socio`         AS `socio`,\n\t\t\t\t\t\t\t`captacion_cuentas`.`tipo_cuenta`\tAS `tipo`,\n\t\t\t\t\t\t\tCOUNT(`captacion_cuentas`.`numero_cuenta`) AS `cuentas`,\n\t\t\t\t\t\t\tSUM(`captacion_cuentas`.`saldo_cuenta`)    AS `suma`\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`captacion_cuentas` `captacion_cuentas`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t(`captacion_cuentas`.`estatus_cuenta` != 99)\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(`captacion_cuentas`.`tipo_cuenta` = 10)\n\t\t\t\t\t\t\t{$BySucursal}\n\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t`captacion_cuentas`.`numero_socio`,\n\t\t\t\t\t\t\t`captacion_cuentas`.`tipo_cuenta`\n\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t`captacion_cuentas`.`tipo_cuenta` ";
     $rsA = getRecordset($sqlSdoCta);
     while ($rw = mysql_fetch_array($rsA)) {
         $msocio = $rw["socio"];
         $arrSdoCtas[$msocio . "-" . $rw["tipo"]] = round($rw["suma"], 2);
         //OK: Verificar
         if (!isset($arrSdoCW[$rw["socio"]]) or is_null($arrSdoCW[$rw["socio"]])) {
             $msg .= "\t{$msocio}\tAgregando un cuadre al socio " . $msocio . " A COMPACW para Verificacion\r\n";
             $sqltmp = "INSERT INTO sisbancs_temp_depositos(numero_de_socio, cuenta_contable, nombre, tipo_de_saldo, monto, sucursal)\n    \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES({$msocio}, '', '_AGREGADO_PARA_CUADRE_MONTO_" . $rw["suma"] . "', 0, 0, 'matriz')";
             my_query($sqltmp);
         }
     }
     unset($rsA);
     unset($rw);
     //============================================================================================================================
     $sqlCuentasSISBANCS = "SELECT SQL_CACHE\n\t\t\t\t\t\t\t\t\t\t`temp_captacion_por_socio`.`numero_socio`,\n\t\t\t\t\t\t\t\t\t\t`temp_sisbancs_depositos`.`numero_de_socio`,\n\t\t\t\t\t\t\t\t\t\t`temp_captacion_por_socio`.`tipo_cuenta`,\n\t\t\t\t\t\t\t\t\t\tROUND(`temp_captacion_por_socio`.`monto`, 2) AS `saldo_safe`,\n\t\t\t\t\t\t\t\t\t\t`temp_sisbancs_depositos`.`total`,\n\t\t\t\t\t\t\t\t\t\t`temp_sisbancs_depositos`.`cuentas`,\n\t\t\t\t\t\t\t\t\t\tROUND((`temp_sisbancs_depositos`.`total`  - `temp_captacion_por_socio`.`monto`), 2) AS 'diferencia'\n\n\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t`temp_captacion_por_socio` `temp_captacion_por_socio`\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `temp_sisbancs_depositos` `temp_sisbancs_depositos`\n\t\t\t\t\t\t\t\t\t\t\tON `temp_captacion_por_socio`.`numero_socio` = `temp_sisbancs_depositos`\n\t\t\t\t\t\t\t\t\t\t\t.`numero_de_socio`\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t(`temp_captacion_por_socio`.`tipo_cuenta` =10)\n\t\t\t\t\t\t\t\t\t\t{$BySucursal}\n\t\t\t\t\t\t\t\t\tHAVING\n\t\t\t\t\t\t\t\t\t\t(diferencia > 0.02)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t(diferencia < -0.02)\n\t\t\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t\t\tdiferencia\n\t\t\t\t\t\t\t\t  /* LIMIT 0,600 */ ";
     $rs = getRecordset($sqlCuentasSISBANCS);
     $contar = 0;
     //Crear un nuevo Recibo de Ajuste
     $cRec = new cReciboDeOperacion(10);
     $xRec = $cRec->setNuevoRecibo(DEFAULT_SOCIO, DEFAULT_CREDITO, fechasys(), 1, 10, "RECIBO_DE_AJUSTES_DE_CAPTACION");
     $msg .= "\t\tRECIBO\tEl Recibo de Operacion es {$xRec}\r\n";
     $cRec->setNumeroDeRecibo($xRec, true);
     //$cRec->initRecibo();
     $msg .= "\t\t============= \r\n";
     $msg .= "\t\t============= APLICANDO CUENTAS DESDE COMPACW\r\n";
     $msg .= "\t\t============= \r\n";
     while ($rw = mysql_fetch_array($rs)) {
         $socio = $rw["numero_de_socio"];
         $ahorro = round($rw["total"], 2);
         $NCuentas = $rw["cuentas"];
         $Monto = 0;
         //Si el saldo EXISTE Y es Diferente a NULL
         if (isset($arrSdoCtas["{$socio}-10"]) and !is_null($arrSdoCtas["{$socio}-10"])) {
             $Monto = $arrSdoCtas["{$socio}-10"];
         }
         //SI es mayor el Monto que el Ahorro, entonces esta inflado la parte Operativa.- Saldo Negativo
         $diferencia = $ahorro - $Monto;
         //Si la Difrencia es menor a -0.99 entonces
         if ($diferencia < TOLERANCIA_SALDOS * -1) {
             $diferencia = $diferencia * -1;
             $msg .= "{$contar}\t{$socio}\tEXCESO\tExiste un monto en exceso de {$diferencia} en SAFE, debe tener {$ahorro} segun COMPACW\r\n";
             //FIXME: globalizar 5
             //TODO: Cambiar esta linea
             $sqlCSoc = "SELECT\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.*,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentastipos`.`descripcion_cuentastipos` AS `tipo`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`numero_cuenta`                 AS `cuenta`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`fecha_afectacion`              AS `apertura`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`inversion_fecha_vcto`          AS `vencimiento`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`tasa_otorgada`                 AS `tasa`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`dias_invertidos`               AS `dias`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`observacion_cuenta`            AS `observaciones`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`saldo_cuenta` \t\t\t        AS `saldo`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`descripcion_subproductos` AS `subproducto`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`algoritmo_de_premio`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`algoritmo_de_tasa_incremental`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`metodo_de_abono_de_interes`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`destino_del_interes`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`nombre_del_contrato`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`algoritmo_modificador_del_interes`\n\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas` `captacion_cuentas`\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `captacion_cuentastipos` `captacion_cuentastipos`\n\t\t\t\t\t\t\t\t\t\t\tON `captacion_cuentas`.`tipo_cuenta` = `captacion_cuentastipos`.\n\t\t\t\t\t\t\t\t\t\t\t`idcaptacion_cuentastipos`\n\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `captacion_subproductos` `captacion_subproductos`\n\t\t\t\t\t\t\t\t\t\t\t\tON `captacion_cuentas`.`tipo_subproducto` = `captacion_subproductos`\n\t\t\t\t\t\t\t\t\t\t\t\t.`idcaptacion_subproductos`\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(`captacion_cuentas`.`numero_socio` ={$socio})\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(`captacion_cuentas`.`tipo_cuenta` =10)\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(`captacion_cuentas`.`saldo_cuenta` != 0)\n\t\t\t\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`saldo_cuenta`,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`fecha_afectacion` ";
             $rsCSoc = getRecordset($sqlCSoc);
             while ($CRw = mysql_fetch_array($rsCSoc)) {
                 $cuenta = $CRw["numero_cuenta"];
                 $saldo = $CRw["saldo_cuenta"];
                 //Si la Diferencia es mayor al saldo de la cuenta, entonces
                 if ($diferencia >= $saldo and $diferencia > 0) {
                     //Retirar el saldo de la cuenta
                     $cCuenta = new cCuentaALaVista($cuenta);
                     $cCuenta->setReciboDeOperacion($xRec);
                     $cCuenta->set($cuenta);
                     $cCuenta->setForceOperations();
                     $cCuenta->init($CRw);
                     $cCuenta->setRetiro($saldo);
                     //Quitar el saldo de la cuenta de la diferencia
                     $diferencia = $diferencia - $saldo;
                     //Mensaje
                     $msg .= "{$contar}\t{$socio}\t{$cuenta}\tELIMINAR\tEliminando el saldo de la cuenta por {$saldo}, queda {$diferencia}\r\n";
                     $msg .= $cCuenta->getMessages("txt");
                 } elseif ($diferencia < $saldo and $diferencia > 0) {
                     //Restar la diferencia y dejar el saldo de la cuenta con el saldo de la cuenta
                     $NSaldo = $saldo - $diferencia;
                     $cCuenta = new cCuentaALaVista($cuenta);
                     $cCuenta->setReciboDeOperacion($xRec);
                     $cCuenta->set($cuenta);
                     $cCuenta->setForceOperations();
                     $cCuenta->init($CRw);
                     $cCuenta->setRetiro($diferencia);
                     $msg .= "{$contar}\t{$socio}\t{$cuenta}\tACTUALIZAR\tActualizar la Cuenta a {$NSaldo}, Anteriormente {$saldo}\r\n";
                     $NuevoSaldo = $cCuenta->getNuevoSaldo();
                     $msg .= $cCuenta->getMessages("txt");
                     $msg .= "{$contar}\t{$socio}\t{$cuenta}\tSALDO\tLa cuenta quedo en {$NuevoSaldo}\r\n";
                     //Llevar a Cero la Diferencia
                     $diferencia = 0;
                 } else {
                     $msg .= "{$contar}\t{$socio}\tIGNORAR\tNo efectuo ninguna accion (SAFE: {$Monto} / CW: {$ahorro})\r\n";
                 }
                 if ($diferencia <= TOLERANCIA_SALDOS) {
                     $diferencia = 0;
                 }
             }
             $msg .= "{$contar}\t{$socio}\tFIN_RET\t------\t------\t------\t------\t------\t------\t------\r\n";
             //Diferencia:	Si la Diferencia es Mayor a 0.99
         } elseif ($diferencia > TOLERANCIA_SALDOS) {
             $msg .= "{$contar}\t{$socio}\tINSUFICIENCIA\tExiste Insuficiencia de {$diferencia} en SAFE (SAFE: {$Monto} / CW: {$ahorro})\r\n";
             //Obtener una Cuenta
             //FIXME: Globalizar 6
             //TODO: Actualizar esta linea
             $sqlCSoc = "SELECT\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.*,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentastipos`.`descripcion_cuentastipos` AS `tipo`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`numero_cuenta`                 AS `cuenta`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`fecha_afectacion`              AS `apertura`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`inversion_fecha_vcto`          AS `vencimiento`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`tasa_otorgada`                 AS `tasa`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`dias_invertidos`               AS `dias`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`observacion_cuenta`            AS `observaciones`,\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`saldo_cuenta` \t\t\t        AS `saldo`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`descripcion_subproductos` AS `subproducto`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`algoritmo_de_premio`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`algoritmo_de_tasa_incremental`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`metodo_de_abono_de_interes`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`destino_del_interes`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`nombre_del_contrato`,\n\t\t\t\t\t\t\t\t\t\t`captacion_subproductos`.`algoritmo_modificador_del_interes`\n\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t`captacion_cuentas` `captacion_cuentas`\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `captacion_cuentastipos` `captacion_cuentastipos`\n\t\t\t\t\t\t\t\t\t\t\tON `captacion_cuentas`.`tipo_cuenta` = `captacion_cuentastipos`.\n\t\t\t\t\t\t\t\t\t\t\t`idcaptacion_cuentastipos`\n\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `captacion_subproductos` `captacion_subproductos`\n\t\t\t\t\t\t\t\t\t\t\t\tON `captacion_cuentas`.`tipo_subproducto` = `captacion_subproductos`\n\t\t\t\t\t\t\t\t\t\t\t\t.`idcaptacion_subproductos`\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(`captacion_cuentas`.`numero_socio` ={$socio})\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(`captacion_cuentas`.`tipo_cuenta` =10)\n\t\t\t\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`saldo_cuenta` DESC,\n\t\t\t\t\t\t\t\t\t\t\t`captacion_cuentas`.`fecha_afectacion` DESC\n\t\t\t\t\t\t\t\t\t\tLIMIT 0,1 ";
             $DCta = obten_filas($sqlCSoc);
             $cuenta = $DCta["numero_cuenta"];
             $cCuenta = new cCuentaALaVista($cuenta);
             $NSaldo = 0;
             //Si la cuenta no existe, crear una nueva
             if (!isset($cuenta) or $cuenta == 0 or $cuenta == false) {
                 $cuenta = $cCuenta->setNuevaCuenta(5, 1, $socio, "CUENTA_POR_AJUSTE");
                 $msg .= "{$contar}\t{$socio}\t{$cuenta}\tNUEVA\tNO Existe la Cuenta, se crea una NUEVA\r\n";
                 $DCta = false;
             }
             $cCuenta->set($cuenta);
             $cCuenta->init($DCta);
             $cCuenta->setReciboDeOperacion($xRec);
             $cCuenta->setDeposito($diferencia);
             $NSaldo = $cCuenta->getNuevoSaldo();
             $msg .= "{$contar}\t{$socio}\t{$cuenta}\tAGREGAR\tSe Agrega la Cuenta un monto de {$diferencia}, Saldo de {$NSaldo}\r\n";
             $msg .= $cCuenta->getMessages("txt");
             $diferencia = 0;
         }
         //$msg	.= "==========================================================================\r\n";
         $contar++;
     }
     $cRec->setFinalizarRecibo();
     $msg .= $cRec->getMessages("txt");
     return $msg;
 }
         $xCOrigen = new cCuentaInversionPlazoFijo($cuentaOrigen, $socio);
     } else {
         $xCOrigen = new cCuentaALaVista($cuentaOrigen, $socio);
     }
     $xCOrigen->init();
     //
     if ($tipoDestino == CAPTACION_TIPO_PLAZO) {
         $xCDestino = new cCuentaInversionPlazoFijo($cuentaDestino, $socio);
     } else {
         $xCDestino = new cCuentaALaVista($cuentaDestino, $socio);
     }
     $xCDestino->init();
     $msg .= $xCOrigen->setTraspaso($cuentaDestino, $tipoDestino, $observaciones, $monto);
     $ReciboTrasp = $xCOrigen->getReciboDeOperacion();
     $msg .= $xCOrigen->getMessages();
     $msg .= $xCDestino->getMessages();
     //Imprime la Ficha del socio
     echo $xSoc->getFicha();
     //$cCta->init();
     //Imprime la Ficha del Documento
     $xCDestino->init();
     $fd = $xCDestino->getFicha(true);
     $xCOrigen->init();
     $fo = $xCOrigen->getFicha(true);
     echo "<fieldset><legend>DATOS DEL TRAPASO</legend>\n\t\t\t\tCuenta de Origen:<br />\n\t\t\t\t{$fo}\t\n\t\tCuenta de Destino:<br />\n\t\t{$fd}\n\t\t</fieldset>";
     $mRec = new cFicha(iDE_RECIBO, $ReciboTrasp);
     $mRec->setTableWidth();
     $mRec->show();
     // *****************************************************************************
     echo "<input type='button' name='btsend' value='IMPRIMIR/VER RECIBO DE TRASPASO' onClick='jsGetComprobanteDeTraspaso();'>";
 } else {
                    $td .= "<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td {$c}>" . $rw["socio_afectado"] . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $NSocio . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td class='mny'>" . $rw["afectacion_real"] . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td class='mny'>" . $monto_gtia_individual . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>";
                    if ($solo_simular == 0) {
                        $cuenta = "50" . $rw["socio_afectado"] . "01";
                        $xCN = new cCuentaALaVista($cuenta);
                        //Contar las cuentas si existen
                        $ctas = $xCN->setContarCuentaBySocio($rw["socio_afectado"], 50);
                        if ($ctas == 0) {
                            //Crear una Cuenta Nueva
                            $xCN->setNuevaCuenta(3, 50, $rw["socio_afectado"], "ALTA_AUTOMATICA_POR_{$iduser}", $credito, "", "", $grupo);
                        } else {
                            $xCN->initCuentaByCodigo();
                        }
                        //Agregar el Movimiento
                        $xCN->setSocioTitular($rw["socio_afectado"]);
                        $xCN->setDeposito($monto_gtia_individual, "NA", "ninguno", "NA", "ALTA_AUTOMATICA_POR_{$iduser}", $grupo);
                        $messages .= $xCN->getMessages() . "<br />";
                    }
                }
                //Imprimir TABLA
                echo "<table width='100%' align='center'>\n\t\t\t\t\t\t\t\t\t\t<thead>\n\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t<th>Numero de <br />Socio</th>\n\t\t\t\t\t\t\t\t\t\t\t<th>Nombre del <br />Socio</th>\n\t\t\t\t\t\t\t\t\t\t\t<th>Monto Prestado</th>\n\t\t\t\t\t\t\t\t\t\t\t<th>% de garantia Liquida</th>\n\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t<tbody>\n\t\t\t\t\t\t\t\t\t\t\t{$td}\n\t\t\t\t\t\t\t\t\t\t</tbody>\n\t\t\t\t\t\t\t\t\t\t</thead>\n\t\t\t\t\t\t\t\t\t</table>\t";
                if ($sumPlan != $autorizado) {
                    echo "<p class='warn'>El Monto del Credito ({$autorizado}) No coincide con la Division de Montos ({$sumPlan})<br />\n\t\t\t\t\t\t\t\t\t\tSegun recibo {$recibo}</p>";
                } else {
                }
                //end if suma plan
            }
            //end if comp representante
        }
        //end if representante invalido
    }
}