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 jsaAmortizarLetras($persona, $credito, $letra, $amortizable)
{
    $NLetra = $letra + 1;
    $xCred = new cCredito($credito);
    $xCred->init();
    if ($xCred->isAFinalDePlazo() == false) {
        $xPlan = new cPlanDePagos();
        $xPlan->initByCredito($credito);
        $msg = "";
        $DPlan = $xPlan->getLetrasInArray(OPERACION_CLAVE_PLAN_CAPITAL, $NLetra);
        $amortizable = setNoMenorQueCero($amortizable);
        for ($ixletra = $NLetra; $ixletra <= $xCred->getPagosAutorizados(); $ixletra++) {
            if (isset($DPlan[$ixletra])) {
                $monto = setNoMenorQueCero($DPlan[$ixletra]);
                if ($amortizable > 0) {
                    if ($amortizable >= $monto) {
                        //cancelar
                        $xPlan->setNeutralizarParcialidad($ixletra);
                    } else {
                        $xPlan->setActualizarParcialidad($ixletra, $monto - $amortizable, false, false);
                    }
                }
                $msg .= "WARN\t  {$ixletra} --- {$amortizable} {$monto};\r\n";
                $amortizable -= $monto;
            }
        }
        $msg .= $xPlan->getMessages();
        if (MODO_DEBUG == true) {
            setLog($msg);
        }
    }
}
 function setCreditoPagado($fecha = false)
 {
     $fecha = $fecha == false ? fechasys() : $fecha;
     //efectuar las operaciones de cierre de credito
     if ($this->getPeriocidadDePago() == CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
         $idPlan = $this->getNumeroDePlanDePagos();
         if (isset($idPlan) and $idPlan > 1) {
             $xPlan = new cPlanDePagos($idPlan);
             $xPlan->setEliminar();
             $this->mMessages .= $xPlan->getMessages();
         }
     }
     $this->setUpdate(array("saldo_conciliado" => 0, "saldo_actual" => 0, "saldo_vencido" => 0, "fecha_conciliada" => $fecha, "fecha_revision" => $fecha, "ultimo_periodo_afectado" => $this->getPagosAutorizados(), "sdo_int_ant" => 0, "fecha_ultimo_mvto" => $fecha));
 }
    header("location:../404.php?i=999");
}
$_SESSION["current_file"] = addslashes($theFile);
//<=====	FIN_H
$iduser = $_SESSION["log_id"];
//=====================================================================================================
$xHP = new cHPage("LETRAS X CREDITO");
$oficial = elusuario($iduser);
$solicitud = $_GET["i"];
//Solicitud
$f = isset($_GET["f"]) ? $_GET["f"] : "frm";
if (!$solicitud) {
    echo "<script languaje=\"javascript\">window.close();</script>";
}
echo $xHP->getHeader();
$xPlan = new cPlanDePagos();
$xPlan->initByCredito($solicitud);
$xT = $xPlan->getEnTabla(false);
$xT->setEventKey("setLetra");
$xT->setFootSum(array(2 => "monto"));
?>
<body>
<hr />

<form name="" method="post" action="">
	<?php 
echo $xT->Show();
?>
	<p class="aviso"><input type="button" onclick="window.close();" value="cerrar ventana" /></p>
</form>
</body>
$msg = "";
if ($action == SYS_CERO) {
    $xFRM->addHElem("<div class='tx4'><label for='f1'>" . $xFRM->lang("archivo") . "</label><input type='file'  name='f1' id='f1'  /></div>");
    //$xFRM->addHElem( $xTxt2->getDeMoneda("idnumeropagina", $xFRM->lang("numero de", "pagina")) );
    $xFRM->addHElem($xTxt->get("idobservaciones", "", "Observaciones"));
    $xFRM->addSubmit();
    $xFRM->addFootElement('<input type="hidden" name="MAX_FILE_SIZE" value="1024000">');
    echo $xFRM->get();
} else {
    $doc1 = isset($_FILES["f1"]) ? $_FILES["f1"] : false;
    $observaciones = isset($DDATA["idobservaciones"]) ? $DDATA["idobservaciones"] : "";
    $xFil = new cFileImporter();
    //var_dump($_FILES["f1"]);
    if ($xFil->processFile($doc1) == true) {
        $data = $xFil->getData();
        $xPlan = new cPlanDePagos();
        //eliminar credito
        $xCred = new cCredito($credito);
        $xCred->init();
        $fecha_operacion = $xCred->getFechaDeMinistracion();
        if ($xCred->getNumeroDePlanDePagos() != false) {
            $xPlan->init($xCred->getNumeroDePlanDePagos());
            $xPlan->setEliminar();
        }
        $xPlan->initByCredito($credito);
        $xPlan->setClaveDeCredito($credito);
        $xPlan->setClaveDePersona($xCred->getClaveDePersona());
        $idrecibo = $xPlan->add($observaciones, $fecha_operacion);
        $xPlan->init($idrecibo);
        foreach ($data as $valores => $cont) {
            //periodo 	fecha 	saldo_inicial 	intereses 	impuesto 	capital 	pago_total 	saldo_final
 if ($PERIOCIDAD_DE_PAGO == CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO or $PERIOCIDAD_DE_PAGO == FALLBACK_CRED_TIPO_PERIOCIDAD) {
     $msgAlertas .= "NO APLICA POR EL TIPO DE FRECUENCIA DE PAGOS";
     $sucess = false;
 }
 //Si los dias entre la Ministracion y la fecha de Primer abono superan a la periocidad mas la tolerancia: Salir
 if (restarfechas($fecha_primer_abono, $fecha_ministracion) > $dias_tolerancia_no_pago + $PERIOCIDAD_DE_PAGO and $tipo_de_plan == 99) {
     $msgAlertas .= "ERROR\tLOS DIAS DEL PRIMER ABONO NO DEBEN SER MAYORES A {$dias_tolerancia_no_pago} MAS LA PERIOCIDAD DE {$PERIOCIDAD_DE_PAGO}\r\n";
     $sucess = false;
 }
 //--------------------------------- END ELIMINACION
 if (date("Y-m-d", strtotime($fecha_primer_abono)) <= date("Y-m-d", strtotime($fecha_ministracion))) {
     $msgAlertas .= "ERROR\tLA FECHA DEL PRIMER ABONO({$fecha_primer_abono}) NO PUEDE SER LA MISMA O MENOR QUE LA FECHA DE MINISTRACION({$fecha_ministracion})\r\n";
     $sucess = false;
 }
 //----------------------------------  ELIMINAR EL PLAN DE PAGOS ANTERIOR
 $xPlan = new cPlanDePagos();
 if ($xCred->getNumeroDePlanDePagos() != false) {
     $xPlan->init($xCred->getNumeroDePlanDePagos());
     $xPlan->setEliminar();
 }
 if (MODO_CORRECION == true) {
     //my_query("DELETE FROM operaciones_mvtos WHERE socio_afectado=$socio AND docto_afectado=$solicitud AND (tipo_operacion=410 OR tipo_operacion=412 OR tipo_operacion=413)");
 }
 if ($sucess == true) {
     $FInteres_normal = new cFormula("interes_normal");
     $factor_interes = $xPlan->getFactorIVA($iva_incluido);
     $DatosDePagos = array();
     if ($xCred->initPagosEfectuados() == true) {
         $DatosDePagos = $xCred->getListadoDePagos();
     }
     //=========================== Corrige el Monto extra de bonificaciones ================================================================
     $fechavcto = sumardias($fecha_ministracion_propuesta, $diasaut);
     $msg .= "WARN\tLa Fecha de Vencimiento es actualizada al " . getFechaLarga($fechavcto) . "; los dias autorizados son de {$diasaut}\r\n";
     $msg .= "WARN\tPARA OBTENER LOS DEMAS DOCUMENTOS DEBE GENERAR EL PLAN DE PAGOS\r\n";
 }
 /* ------------------------------ sentencia update -------------------------- */
 if ($sucess == true) {
     $xCred->setAutorizado($idmonto, $idpagos, $periocidad, $TipoDeAutorizacion, $fechaaut, $idautorizacion, $idtipodepago, $fecha_ministracion_propuesta, $idnivelderiesgo, $diasaut, $fechavcto, $estatusactual, $sdoactual, $intdev, $fechaultmvto, $TasaDeInteres);
     /* si es Credito de Grupos solidarios, Actualiza los Mvtos de Otorgacion */
     if ($OConv->getEsProductoDeGrupos() == true) {
         $sqlusolc = "UPDATE operaciones_mvtos\tSET estatus_mvto = 10\tWHERE\n\t\t\t\tgrupo_asociado={$gpoasoc}\tAND (tipo_operacion=112) AND (estatus_mvto=40)";
         my_query($sqlusolc);
     }
     //Eliminar Plan de Pagos
     $plan = setNoMenorQueCero($xCred->getNumeroDePlanDePagos());
     if ($plan > 0) {
         $xPlan = new cPlanDePagos($plan);
         $xPlan->setEliminar();
         $msg .= $xPlan->getMessages();
     }
 }
 //------------------------------- IMPRIME UNA PEQUE%A DESCRIPCION DE LA SOLICITUD -----------------------
 $xCred->init();
 $xFRM->addHTML($xCred->getFichaDeSocio(true));
 $xFRM->addHTML($xCred->getFicha(true));
 //$urlsend 				= "elUrl='" . $OConv->getPathPagare($idsolicitud) . "';";
 $cedula_grupal = 0;
 //$urctr 					= "esUrl='" . $xCred->getPathDelContrato() . "';";
 if ($OConv->getEsProductoDeGrupos() == true) {
     //Si la cedula Grupal existe y el Tipo de Integracion el GRUPO
     if (isset($_SESSION["recibo_en_proceso"])) {
         $cedula_grupal = $_SESSION["recibo_en_proceso"];
    header("location:../404.php?i=999");
}
$_SESSION["current_file"] = addslashes($theFile);
//<=====	FIN_H
//=====================================================================================================
$xInit = new cHPage("", HP_SERVICE);
$txt = "";
$ql = new MQL();
$lis = new cSQLListas();
$xF = new cFecha();
//$persona	= parametro("persona", DEFAULT_SOCIO, MQL_INT);
$credito = parametro("credito", DEFAULT_CREDITO, MQL_INT);
$letra = parametro("letra", false, MQL_INT);
//$tipo		= parametro("tipo", false, MQL_INT);
$rs = array();
if ($credito != DEFAULT_CREDITO) {
    //$xSoc	= new cSocio($persona); $xSoc->init();
    $xCred = new cCredito($credito);
    $xCred->init();
    $plan = $xCred->getNumeroDePlanDePagos();
    //letra //monto
    $xPlan = new cPlanDePagos($plan);
    $xPlan->init();
    //$D		= $xPlan->getDatosDeParcialidad($letra);
    $D = $xPlan->getOLetra($letra);
    $rs[SYS_MONTO] = $D->getMonto();
}
//header('Content-type: application/json');
//echo json_encode($rs);
//setLog(json_encode($rs));
//setLog($sql);