function initPorCredito($idcredito, $dataCredito = false)
 {
     $xCred = new cCredito($idcredito);
     $xCred->init($dataCredito);
     $xF = new cFecha();
     if ($xCred->getTipoEnSistema() == CREDITO_PRODUCTO_NOMINA) {
         //cargar datos de la empresa
         $idemp = $xCred->getClaveDeEmpresa();
         $periocidad = $xCred->getPeriocidadDePago();
         $this->setPeriocidadDePago($periocidad);
         $this->mTipoCreditoSis = $xCred->getTipoEnSistema();
         $this->mClaveDePlan = setNoMenorQueCero($xCred->getNumeroDePlanDePagos());
         if ($this->mClaveDePlan > 0) {
             //TODO: validar fecha de primer pago en calculos automaticos
             $this->mFechaPrimerPago = $xCred->getFechaPrimeraParc();
         } else {
             $this->mFechaPrimerPago = $this->getFechaDePago($xCred->getFechaDeMinistracion(), 1);
         }
         if ($xCred->getFechaPrimeraParc() == $this->mFechaFail or $xF->getInt($xCred->getFechaPrimeraParc()) <= $xF->getInt($xCred->getFechaDeMinistracion())) {
             $this->mFechaPrimerPago = $this->getFechaDePago($xCred->getFechaDeMinistracion(), 1);
         }
         $xEmp = new cEmpresas($idemp);
         $xEmp->init();
         $DDias = $xEmp->getDiasDeNomina($periocidad);
         $this->mDiaDeAbono1 = isset($DDias[0]) ? setNoMenorQueCero($DDias[0]) : $this->mDiaDeAbono1;
         $this->mDiaDeAbono2 = isset($DDias[1]) ? setNoMenorQueCero($DDias[1]) : $this->mDiaDeAbono2;
         $this->mDiaDeAbono3 = isset($DDias[2]) ? setNoMenorQueCero($DDias[2]) : $this->mDiaDeAbono3;
     } else {
         $this->mFechaPrimerPago = $this->getFechaDePago($xCred->getFechaDeMinistracion(), 1);
     }
 }
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 initByCredito($ClaveCredito = false)
 {
     $ClaveCredito = $ClaveCredito == false ? $this->mCredito : $ClaveCredito;
     $xCred = new cCredito($ClaveCredito);
     $xCred->init();
     $this->mClaveDeCredito = $xCred->getNumeroDeCredito();
     $this->mClaveDePersona = $xCred->getClaveDePersona();
     $this->mClaveDeGrupo = $xCred->getClaveDeGrupo();
     $this->mClaveDeEmpresa = $xCred->getClaveDeEmpresa();
     $this->mTasaDeIVA = $xCred->getTasaIVA();
     $this->mTotalParciales = $xCred->getPagosAutorizados();
     if ($this->mDiasTolerancia == 0) {
         $DProducto = $xCred->getOProductoDeCredito();
         $this->mDiasTolerancia = $DProducto->getDiasTolerados();
     }
     if ($xCred->getNumeroDePlanDePagos() != false) {
         $this->mNumeroDePlan = $xCred->getNumeroDePlanDePagos();
         $this->init();
     }
     $this->mIsInit = true;
     $this->mMessages .= $xCred->getMessages(OUT_TXT);
     return $this->mNumeroDePlan;
 }
 $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() );
 }
 $PagoActual = "V";
 if ($SaldoActual > TOLERANCIA_SALDOS + 0.01) {
$iduser = $_SESSION["log_id"];
//=====================================================================================================
$xHP = new cHPage("TR.Plan_de_Pagos", HP_REPORT);
$xF = new cFecha();
$ql = new MQL();
$oficial = elusuario($iduser);
$idrecibo = parametro("idrecibo", false, MQL_INT);
$idrecibo = parametro("recibo", $idrecibo, MQL_INT);
$idsolicitud = parametro("is", false, MQL_INT);
$idsolicitud = parametro("credito", $idsolicitud, MQL_INT);
$ShowAvales = parametro("p", false, MQL_BOOL);
if ($idrecibo == false) {
    if ($idsolicitud != false) {
        $xCred = new cCredito($idsolicitud);
        $xCred->init();
        $idrecibo = $xCred->getNumeroDePlanDePagos();
        if (setNoMenorQueCero($idrecibo) > 0) {
        } else {
            exit(JS_CLOSE);
        }
    } else {
        exit(JS_CLOSE);
    }
}
$xHP->setTitle($xHP->getTitle() . " # {$idrecibo}");
echo $xHP->getHeader(true);
echo $xHP->setBodyinit("window.print()");
echo $xHP->getEncabezado();
$PlanBody = $xHP->h1() . "<hr />";
$xRec = new cReciboDeOperacion(false, false, $idrecibo);
$xRec->init();
    $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
            //0		1	2		3		4		5		6		7
            //Periodo,Fecha de Pago,Saldo inicial,Intereses,Impuesto,Pago a Capital,Pago Total,Saldo final
            if ($xT->cInt($cont[0]) > 0) {
                $interes = $xT->cFloat($cont[3], 2);
                $fecha = $xF->getFechaISO($cont[1]);
 if (MODO_DEBUG == true) {
     $oFrm->addToolbar($xBtn->getBasic("TR.EDICION_AVANZADA", "jsActualizarCreditoRAW()", "aviso", "edit-credito2", false));
     $oFrm->addToolbar($xBtn->getBasic("TESTING", "var xG=new Gen();xG.w({url:'../unit/core.creditos.test.php?credito={$idsolicitud}'})", "checar", "test-cred", false));
 }
 $oFrm->addCreditoComandos($idsolicitud);
 $oFrm->addToolbar($xBtn->getBasic("TR.ACTUALIZAR DATOS", "jsActualizarCredito()", "editar", "edit-credito", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.IMPRIMIR PAGARE", "printpagare()", "dinero", "view-pagare", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.IMPRIMIR formato NOTARIAL", "cedulanotario({$idsolicitud})", "reporte", "view-cedula", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.ORDEN_DE_DESEMBOLSO", "printodes()", "imprimir", "print-order", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.CONTRATO", "contratocredito()", "imprimir", "print-contrato", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.IMPRIMIR RECIBO DE credito", "printrec()", "imprimir", "print-recP", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.IMPRIMIR MANDATO", "printMandato()", "imprimir", "print-mandato", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.ESTADO_DE_CUENTA", "getEstadoDeCuenta({$idsolicitud})", "statistics", "estado-cta", false));
 $oFrm->addToolbar($xBtn->getBasic("TR.ESTADO_DE_CUENTA Intereses", "getEstadoDeCuentaIntereses({$idsolicitud})", $oFrm->ic()->COBROS, "estado-cta2", false));
 $idrecibo = $xCred->getNumeroReciboDeMinistracion();
 $idnumeroplan = $xCred->getNumeroDePlanDePagos();
 if (setNoMenorQueCero($idnumeroplan) > 0) {
     $oFrm->addToolbar($xBtn->getBasic("TR.PLAN_DE_PAGOS #{$idnumeroplan}", "printplan({$idnumeroplan})", "print", "print-plan", false));
 }
 $oFrm->addToolbar($xBtn->getBasic("TR.RENEGOCIAR", "jsRenegociar()", "editar", "mcediatar", false));
 $oFrm->OButton("TR.Parcialidades Pendientes", "var xcg = new CredGen();xcg.getLetrasEnMora({$idsolicitud})", $oFrm->ic()->PREGUNTAR);
 if ($codigo_de_oficial == USUARIO_TIPO_OFICIAL_AML or OPERACION_LIBERAR_ACCIONES == true) {
 }
 //Agregar Listado de Recibos
 $cTblx = new cTabla($mSQL->getListadoDeRecibos("", $xCred->getClaveDePersona(), $xCred->getNumeroDeCredito()));
 $cTblx->setKeyField("idoperaciones_recibos");
 $cTblx->setTdClassByType();
 $cTblx->setEventKey("jsGoPanelRecibos");
 $xHTabs->addTab("TR.RECIBOS", $cTblx->Show());
 if ($codigo_de_oficial == getUsuarioActual() or OPERACION_LIBERAR_ACCIONES == true) {
     $setSql = $mSQL->getListadoDeLlamadas($idsolicitud);
     $intdev = $idmonto * $tasaot / EACP_DIAS_INTERES;
     // Interes Diario a Cero para otros Casos
     $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