function jsaGetLetras($idcredito)
{
    $idcred = setNoMenorQueCero($idcredito);
    $xF = new cFecha();
    if ($idcred > DEFAULT_CREDITO) {
        $xCred = new cCredito($idcred);
        $xCred->init();
        if ($xCred->getEsAfectable() == false or $xCred->getSaldoActual() <= 0) {
            if (MODO_CORRECION == true) {
                $xTxt = new cHText();
                $xTxt->setDivClass("");
                return $xTxt->getNumero("idparcialidad", $xCred->getPeriodoActual() + 1, "TR.Numero de Parcialidad");
            } else {
                return $xCred->getMessages();
            }
        } else {
            if ($xCred->getPeriocidadDePago() == CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
                //
                $xTxt = new cHText();
                $xTxt->setDivClass("");
                return $xTxt->getNumero("idparcialidad", $xCred->getPeriodoActual() + 1, "TR.Numero de Parcialidad");
            } else {
                $plan = $xCred->getNumeroDePlanDePagos();
                if ($plan != false) {
                    $xPlan = new cPlanDePagos($plan);
                    $xPlan->init();
                    $parcs = $xPlan->getParcsPendientes();
                    //$txt		= "";
                    $arrD = array();
                    foreach ($parcs as $p) {
                        //setLog( $p[SYS_NUMERO]. " " . $xF->getFechaDDMM($p[SYS_FECHA]) . " ". getFMoney($p[SYS_TOTAL]));
                        if (setNoMenorQueCero($p[SYS_TOTAL]) > 0) {
                            $arrD[$p[SYS_NUMERO]] = $p[SYS_NUMERO] . " " . $xF->getFechaDDMM($p[SYS_FECHA]) . " " . getFMoney($p[SYS_TOTAL]);
                        }
                    }
                    $xSel = new cHSelect();
                    $xSel->addOptions($arrD);
                    $xSel->setEnclose(false);
                    return $xSel->get("idparcialidad", "TR.Numero de Parcialidad", $xCred->getPeriodoActual() + 1);
                } else {
                    if (MODO_CORRECION == true) {
                        $xTxt = new cHText();
                        $xTxt->setDivClass("");
                        return $xTxt->getNumero("idparcialidad", $xCred->getPeriodoActual() + 1, "TR.Numero de Parcialidad");
                    }
                }
            }
        }
    }
}
function jsaSetPagarCredito($credito, $fecha, $observaciones)
{
    $msg = "";
    $xLng = new cLang();
    $xCred = new cCredito($credito);
    $xCred->init();
    $xdat = new cFecha(0);
    $fecha = $xdat->getFechaISO($fecha);
    //$xCred->setResetPersonaAsociada($fecha, $observaciones);
    //return $xLng->get(MSG_READY_SAVE);
    $xCred->setAbonoCapital($xCred->getSaldoActual(), $xCred->getPeriodoActual(), DEFAULT_CHEQUE, TESORERIA_COBRO_NINGUNO, DEFAULT_RECIBO_FISCAL, $observaciones, DEFAULT_GRUPO, $fecha);
    return $xCred->getMessages(OUT_HTML);
}
     $FechaUltimoPago = $xCR->getDate($xF100->setRestarDias(1, $xCred->getFechaDeMinistracion()));
     //setLog("2....$FechaUltimoPago");
 }
 $FechaUltimaCompra = $xCR->getDate($xCred->getFechaDeMinistracion());
 $FechaCierreCuenta = "";
 $FechaCorte = $FechaExtraccion;
 $Garantia = "";
 //TODO: Acabar garantia
 $CreditoMaximo = $xCR->getMonto($xSoc->getCreditoMaximo());
 $SaldoActual = $xCR->getMonto($xCred->getSaldoActual($FechaFinal));
 $LimiteCredito = $xCR->getMonto($xSoc->getCreditoMaximo());
 $SaldoVencido = 0;
 $NumeroPagosVencidos = 0;
 //Modificado en el plan de pagos
 //obtener la letra pendiente
 $UltimaLetraPagada = $xCR->getMonto($xCred->getPeriodoActual());
 //obtener datos de la letra
 $DPlanDePagos = $xCred->getDatosDelPlanDePagos();
 $NumeroDePlan = $xCred->getNumeroDePlanDePagos();
 $FechaDePrimerIncumplimiento = "";
 if ($SaldoActual <= 0) {
     if ($xF->getInt($xCred->getFechaUltimoDePago()) >= $xF->getInt($xCred->getFechaDeMinistracion())) {
         $FechaCierreCuenta = $xCR->getDate($xCred->getFechaDeMinistracion());
         $FechaAperturaCuenta = $xCR->getDate($xF->setRestarDias(3, $xCred->getFechaDeMinistracion()));
         $FechaUltimoPago = $xCR->getDate($xF->setRestarDias(2, $xCred->getFechaDeMinistracion()));
         //setLog("3....$FechaUltimoPago");
     } else {
         $FechaCierreCuenta = $xCR->getDate($xCred->getFechaUltimoDePago());
     }
     //$FechaUltimaCompra			= $xCR->getDate($xCred->getFechaDeMinistracion() );
     //$FechaAperturaCuenta		= $xCR->getDate($xCred->getFechaDeMinistracion() );
function jsaVincularEmpresa($credito, $observaciones, $empresa)
{
    $msg = "";
    $xCred = new cCredito($credito);
    $xCred->init();
    $xdat = new cFecha(0);
    $fecha = $xdat->get();
    // FechaISO($fecha);
    $xCred->init();
    $socio = $xCred->getClaveDePersona();
    $xSoc = new cSocio($socio);
    $xSoc->init();
    $xCred->setCambioProducto(CREDITO_PRODUCTO_NOMINA);
    $xCred->setResetPersonaAsociada($fecha, $observaciones, $empresa);
    //Agregar operacion de desvinculacion
    $xRe = new cReciboDeOperacion(RECIBOS_TIPO_ESTADISTICO, false, DEFAULT_RECIBO);
    $xRe->init();
    $xRe->setNuevoMvto($fecha, $xCred->getSaldoActual(), OPERACION_CLAVE_VINCULACION, $xCred->getPeriodoActual(), "", 1, false, $socio, $credito, $fecha);
    $xRe->setFinalizarRecibo();
    $msg .= $xSoc->getMessages(OUT_TXT);
    $msg .= $xCred->getMessages(OUT_TXT);
    $msg .= $xRe->getMessages(OUT_TXT);
    $xF = new cFileLog();
    $xF->setWrite($msg);
    $xF->setClose();
    return $xF->getLinkDownload("Descarga de Log");
}
    $nuevo_saldo = $xCred->getSaldoActual() - $baseM120;
    $nuevo_saldo = $nuevo_saldo < 0 ? 0 : $nuevo_saldo;
    $arrUCredito["saldo_actual"] = $nuevo_saldo;
}
if (setNoMenorQueCero($baseM120) <= 0) {
    $actualizar_parcialidad = false;
}
//Saldo ints devengados aldo_actual=(saldo_actual - ($baseM120)),
//monto_parcialidad 	$arrUCredito["saldo_actual"]
if ($xCred->getPagosAutorizados() <= $nueva_parcialidad) {
    if ($nuevo_saldo > TOLERANCIA_SALDOS) {
        $msg .= "WARN\tLa parcialidad no se Actualiza, el saldo queda a {$nuevo_saldo} de la Parcialidad {$nueva_parcialidad}\r\n";
        $actualizar_parcialidad = false;
    }
}
if ($nueva_parcialidad < $xCred->getPeriodoActual()) {
    $msg .= "WARN\tLa Parcialidad {$nueva_parcialidad} no se mueve por ser menor al actual " . $xCred->getSaldoActual() . "\r\n";
    $actualizar_parcialidad = false;
}
if ($actualizar_parcialidad == true) {
    $arrUCredito["ultimo_periodo_afectado"] = $nueva_parcialidad;
}
$arrUCredito["interes_normal_pagado"] = $xCred->getInteresNormalPagado() + $baseM140;
$arrUCredito["interes_moratorio_pagado"] = $xCred->getInteresMoratorioPagado() + $baseM141;
$xCred->setUpdate($arrUCredito);
//---------------------------- Agrega Movimientos extras ---------------------------------
if ($interesanticipado != 0) {
    $tds .= "<tr>\n                <th></th>\n                <td>Compensacion Intereses Cobrado por Ant</td>\n                <td class='mny'>" . getFMoney($interesanticipado) . "</td>\n            </tr>";
    $SQL_ICA = "UPDATE operaciones_mvtos SET estatus_mvto=60, docto_neutralizador={$recibo_pago} WHERE tipo_operacion=351 AND socio_afectado={$socio} AND estatus_mvto=30";
    my_query($SQL_ICA);
    //setPolizaProforma($recibo_pago, 352, $interesanticipado, $socio, $solicitud, TM_CARGO);