$FechaDePrimerIncumplimiento = "";
     }
 }
 /* 2014-08-03 */
 if ($SaldoVencido > 1 and $PagoActual == "V") {
     if (setNoMenorQueCero($NumeroPagosVencidos) <= 0) {
         $PagoActual = "01";
     } else {
         $PagoActual = "{$NumeroPagosVencidos}";
     }
 }
 if ($SaldoActual > TOLERANCIA_SALDOS + 0.01) {
     if (setNoMenorQueCero($PagoActual) > $xCred->getPagosAutorizados()) {
         //pago actual reset
         //$xMs	= new cNotificaciones();
         $xLog->add("WARN\t{$idpersona}-{$idcredito}\t{$sucres}\t({$PagoActual} . {$NumeroPagosVencidos})ERROR\tCredito " . $xCred->getNumeroDeCredito() . " Saldo {$SaldoActual}\r\n", $xLog->DEVELOPER);
         $PagoActual = "01";
         //sprintf("%02d", setNoMenorQueCero(($xCred->getPagosAutorizados() - $NumeroPagosVencidos)) );
     }
 }
 if ($SaldoVencido > $SaldoActual) {
     $SaldoVencido = $SaldoActual;
 }
 $HistoricoPagos = "";
 $ClavePrevencion = "";
 $TotalPagosReportados = 0;
 $ClaveOtorganteAnterior = "";
 //ENTIDAD_CLAVE_SIC;
 $NombreOtorganteAnterior = "";
 //
 $NumeroOtorganteAnterior = "";
 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;
 }
echo $oFrm7->get();
?>
</div>
<?php 
echo $xHP->setBodyEnd();
$jsb = new jsBasicForm("frmrenegociar");
$jsb->show();
$jxc->drawJavaScript(false, true);
?>

<script>
    var xGen	= new Gen();
    var ogen	= new Gen();
    var mobj	= "#avisos";
	var idCredito	= <?php 
echo $xCred->getNumeroDeCredito();
?>
;
	var idSocio		= <?php 
echo $xCred->getClaveDePersona();
?>
;
	var idRecibo	= <?php 
echo $idrecibo;
?>
;
    
    function jsCambiarEstado(){ 				getModalTip(mobj, $("#divestatus"), xGen.lang(["Modificar", "Estado"]));   }
    function jsCambiarMonto(){ 				getModalTip(mobj, $("#divmontomin"), xGen.lang(["Modificar" ,"Monto", "Ministrado"]));  }
    function jsCambiarFechaMinistracion() {	getModalTip(mobj, $("#divfechamin"), xGen.lang(["Modificar", "Fecha_de",  "Ministracion"]) );  }
    function jsCambiarProducto(){ 				getModalTip(mobj, $("#divpdto"), xGen.lang(["Modificar", "Producto"]));  }
     $msg .= "WARN\tCredito marcado como Renovado \r\n";
 }
 $xCred = new cCredito();
 $result = $xCred->add($tipoconvenio, $persona, $contrato_corriente, $monto_solicitado, $periocidad, $numeropagos, $dias_solicitados, $rubro_destino, false, $grupo_asociado, $amp_destino, $observaciones, $oficial_de_credito, $fecha_solicitud, $tipo_de_pago, INTERES_POR_SALDO_INSOLUTO, false, $fecha_ministracion, $xSoc->getClaveDeEmpresa(), $TipoDeAutorizacion);
 if ($result == false) {
     $xFRM->addToolbar($xBtn->getRegresar("solicitud_de_credito.frm.php", true));
     $xFRM->addAviso($xHP->lang(MSG_ERROR_SAVE));
     $xFL = new cFileLog();
     $xFL->setWrite($xCred->getMessages(OUT_TXT));
     $xFL->setWrite($xSoc->getMessages());
     $xFL->setClose();
     $xFRM->addToolbar($xFL->getLinkDownload("Log de eventos", ""));
     $xFRM->addAviso($xCred->getMessages());
 } else {
     $xCred->init();
     $credito = $xCred->getNumeroDeCredito();
     //Si es Automatizado
     $xCat = new cCreditosOtrosDatos();
     if ($tieneprops == true) {
         $xCred->setOtrosDatos($xCat->AML_CON_PROPIETARIO, "1");
     }
     if ($tieneprovs == true) {
         $xCred->setOtrosDatos($xCat->AML_CON_PROVEEDOR, "1");
     }
     if ($xCred->getTipoDeAutorizacion() == CREDITO_TIPO_AUTORIZACION_AUTOMATICA) {
         //$saldo_actual = $monto_autorizado;
         //TODO: Acabar con este modulo
         $xFRM->addToolbar($xBtn->getBasic($xHP->lang("Imprimir", "Orden de Desembolso"), "jsImprimirOrdenDeDesembolso()", "imprimir", "cmdprintdes", false));
     }
     //----------------------------------------------------------------------
     $xFRM->addHTML($xCred->getFichaDeSocio());
 $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);
     $setSql3 = $mSQL->getListadoDeNotificaciones($idsolicitud);
     $c2Tbl = new cTabla($mSQL->getListadoDeNotas(false, $idsolicitud), 0);
     $c2Tbl->setWidth();
     $xHTabs->addTab("TR.NOTAS", $c2Tbl->Show());
     $c4Tbl = new cTabla($mSQL->getListadoDeCompromisos($idsolicitud), 5);
     $c4Tbl->setWidth();
     $xHTabs->addTab("TR.COMPROMISOS", $c4Tbl->Show());
     $cTbl = new cTabla($setSql, 0);
     $cTbl->addTool(SYS_DOS);
$credito_de_pruebas = 29000201;
$xAML = new cAMLPersonas($persona_de_pruebas);
$x2AML = new cAMLPersonas_PerfilTransaccional($persona_de_pruebas);
if ($runTest == true) {
    $xCred = new cCredito($credito_de_pruebas);
    $init = true;
    $xCred->init();
    //Ministrar
    if ($xCred->getEsAfectable() == false) {
        $xCred->setForceMinistracion();
        $xCred->setMinistrar("", DEFAULT_CHEQUE, 0, DEFAULT_CUENTA_BANCARIA, 0, 0, "", '2014-01-01');
        $init = $xCred->init();
    }
    if ($init == true) {
        $xRec = new cReciboDeOperacion(RECIBOS_TIPO_PAGO_CREDITO, true);
        $xRec->setDocumento($xCred->getNumeroDeCredito());
        $xRec->setSocio($xCred->getClaveDePersona());
        $idrec = $xRec->setNuevoRecibo($xCred->getClaveDePersona(), $xCred->getNumeroDeCredito(), fechasys(), 1);
        $xCred->setReciboDeOperacion($idrec);
        //agregar pagos
        $xCred->setAbonoCapital(2200, 1, DEFAULT_CHEQUE, TESORERIA_COBRO_EFECTIVO, DEFAULT_RECIBO_FISCAL, "", DEFAULT_GRUPO, "2014-01-15");
        //if($xCred->getORecibo() != null){ $xCred->getORecibo()->setFinalizarRecibo(true); }
        $xCred->setAbonoCapital(5200, 1, DEFAULT_CHEQUE, TESORERIA_COBRO_EFECTIVO, DEFAULT_RECIBO_FISCAL, "", DEFAULT_GRUPO, "2014-01-20");
        //if($xCred->getORecibo() != null){ $xCred->getORecibo()->setFinalizarRecibo(true); }
        $xCred->setAbonoCapital(6200, 1, DEFAULT_CHEQUE, TESORERIA_COBRO_EFECTIVO, DEFAULT_RECIBO_FISCAL, "", DEFAULT_GRUPO, "2014-01-30");
        //if($xCred->getORecibo() != null){ $xCred->getORecibo()->setFinalizarRecibo(true); }
        $xCred->setAbonoCapital(8200, 1, DEFAULT_CHEQUE, TESORERIA_COBRO_EFECTIVO, DEFAULT_RECIBO_FISCAL, "", DEFAULT_GRUPO, "2014-02-05");
        //if($xCred->getORecibo() != null){ $xCred->getORecibo()->setFinalizarRecibo(true); }
        $xCred->setAbonoCapital(9200, 1, DEFAULT_CHEQUE, TESORERIA_COBRO_EFECTIVO, DEFAULT_RECIBO_FISCAL, "", DEFAULT_GRUPO, "2014-02-06");
        $xCred->setAbonoCapital(9200, 1, DEFAULT_CHEQUE, TESORERIA_COBRO_EFECTIVO, DEFAULT_RECIBO_FISCAL, "", DEFAULT_GRUPO, "2014-02-10");
        //if($xCred->getORecibo() != null){ $xCred->getORecibo()->setFinalizarRecibo(true); }
 function init($arrData = false, $credito = false, $dataPagos = false)
 {
     $fecha = $this->mFechaDeCorte;
     $credito = $credito == false ? $this->mClaveDeCredito : $credito;
     $xCred = new cCredito($credito);
     $xCred->init($arrData);
     $xCred->initPagosEfectuados($dataPagos, $fecha);
     //setLog($dataPagos);
     $xSoc = new cSocio($xCred->getClaveDePersona());
     $xSoc->init();
     $this->mInfoLinea[1] = $this->getText($this->getClaveDeOtorgante());
     $this->mInfoLinea[2] = $this->getText($this->getNombreOtorgante());
     $this->mInfoLinea[3] = $this->getFechaDeReporte();
     $this->mInfoLinea[4] = $this->getText($xSoc->getApellidoPaterno());
     $this->mInfoLinea[5] = $this->getText($xSoc->getApellidoMaterno());
     $this->mInfoLinea[6] = "";
     $nombres = explode(" ", $xSoc->getNombre(), 2);
     $this->mInfoLinea[7] = isset($nombres[SYS_CERO]) ? $this->getText($nombres[SYS_CERO]) : "";
     $this->mInfoLinea[8] = isset($nombres[SYS_UNO]) ? $this->getText($nombres[SYS_UNO]) : "";
     $this->mInfoLinea[9] = $this->getDate($xSoc->getFechaDeNacimiento());
     $this->mInfoLinea[10] = $this->getText($xSoc->getRFC());
     $this->mInfoLinea[11] = isset($this->mTituloPersonal[$xSoc->getTipoGenero()]) ? $this->mTituloPersonal[$xSoc->getTipoGenero()] : "";
     //Hiber Tadeo
     $this->mInfoLinea[12] = $this->getEstadoCivil($xSoc->getEstadoCivil());
     $this->mInfoLinea[13] = $this->mEquivGenero[$xSoc->getTipoGenero()];
     //TODO: terminar defuncion/muerte de la persona
     $this->mInfoLinea[14] = "";
     $this->mInfoLinea[15] = "";
     $xDom = $xSoc->getODomicilio();
     if ($xDom == null) {
         for ($i = 16; $i <= 23; $i++) {
             $this->mInfoLinea[$i] = "";
         }
     } else {
         $this->mInfoLinea[16] = $this->getText($xDom->getCalleConNumero());
         $this->mInfoLinea[17] = "";
         $this->mInfoLinea[18] = $this->getText($xDom->getColonia());
         $this->mInfoLinea[19] = $this->getText($xDom->getMunicipio());
         $this->mInfoLinea[20] = $this->getText($xDom->getCiudad());
         $this->mInfoLinea[21] = $this->getText($xDom->getClaveDeEstadoEnSIC());
         $this->mInfoLinea[22] = $this->getText($xDom->getCodigoPostal());
         $xTel = $xSoc->getTelefonoPrincipal();
         //Hiber Tadeo
         $this->mInfoLinea[23] = $xTel == 0 ? "" : $xTel;
         //Hiber Tadeo
     }
     $xAE = $xSoc->getOActividadEconomica();
     if ($xAE == null) {
         $this->mInfoLinea[24] = $this->getText($xSoc->getRFC(true));
         //Para Finsureste debe de ser este RFC del cliente
         $this->mInfoLinea[33] = 0;
     } else {
         $this->mInfoLinea[24] = $this->getText($xSoc->getRFC(true));
         //Para Finsureste debe de ser este RFC del cliente//$this->getText($xAE->getNombreEmpresa());
         $this->mInfoLinea[33] = $this->getText($xDom->getCalleConNumero());
         //Para Finsureste debe de ser direccion del cliente //Hiber Tadeo Aca es direccion
     }
     //direccion 2
     $this->mInfoLinea[25] = "";
     $this->mInfoLinea[26] = $this->getText($xDom->getColonia());
     //Para Finsureste
     $this->mInfoLinea[27] = $this->getText($xDom->getMunicipio());
     //Para Finsureste
     $this->mInfoLinea[28] = $this->getText($xDom->getCiudad());
     //Para Finsureste
     $this->mInfoLinea[29] = $this->getText($xDom->getClaveDeEstadoEnSIC());
     //Para Finsureste
     $this->mInfoLinea[30] = $this->getText($xDom->getCodigoPostal());
     //Para Finsureste
     $this->mInfoLinea[31] = $xTel == 0 ? "" : $xTel;
     //Hiber Tadeo  //Para Finsureste
     $this->mInfoLinea[32] = "";
     $this->mInfoLinea[34] = $this->getClaveDeOtorgante();
     $this->mInfoLinea[35] = $this->getText($this->getNombreOtorgante());
     $this->mInfoLinea[36] = $xCred->getNumeroDeCredito();
     $this->mInfoLinea[38] = $this->getTipoDeCuenta($xCred->getTipoDePago());
     //datos del convenio
     $DConv = $xCred->getOProductoDeCredito();
     $this->mInfoLinea[37] = $this->getTipoDeResponsabilidad($DConv->getTipoDeIntegracion());
     $this->mInfoLinea[39] = $DConv->getTipoDeContratoCR();
     //"PL";//$DConv->getTipoDeContratoCR(); //Hiber Tadeo CL=LINEA DE CREDITO PL=PRESTAMO PERSONAL
     $this->mInfoLinea[40] = AML_CLAVE_MONEDA_LOCAL;
     //TODO: mejorar
     $this->mInfoLinea[41] = $xCred->getPagosAutorizados();
     if ($xCred->getTipoEnSistema() == CREDITO_PRODUCTO_NOMINA) {
         //TODO: Parchar con el de TADEO
         $this->mInfoLinea[42] = "P";
     } else {
         $this->mInfoLinea[42] = $this->mEquivFrecPagos[$xCred->getPeriocidadDePago()];
     }
     $this->mInfoLinea[43] = $this->getDate($xCred->getFechaDeMinistracion());
     $this->mInfoLinea[44] = $this->getMonto($xCred->getMontoDeParcialidad());
     $this->mInfoLinea[45] = $this->getDate($xCred->getFechaUltimoDePago());
     $this->mInfoLinea[46] = $this->getDate($xCred->getFechaDeMinistracion());
     $this->mInfoLinea[47] = "";
     //$this->getDate("2029-12-31" );
     if ($xCred->getSaldoActual($fecha) <= TOLERANCIA_SALDOS) {
         $this->mInfoLinea[47] = $this->getDate($xCred->getFechaUltimoDePago());
     }
     $this->mInfoLinea[48] = $this->getFechaDeReporte();
     $DCapacidad = $xSoc->getOCapacidadDePago();
     $this->mInfoLinea[49] = $this->getMonto($DCapacidad->getMontoDeCreditoMaximo());
     $this->mInfoLinea[50] = $this->getMonto($xCred->getSaldoIntegrado($fecha));
     //$xCred->getSaldoActual();
     $this->mInfoLinea[51] = $this->getMonto($DCapacidad->getLimiteDeCredito());
     $this->mInfoLinea[52] = $this->getMonto($xCred->getSaldoVencido());
     //53 numero de pagos vencidos
     $this->mInfoLinea[53] = 0;
     //54 forma mop
     $this->mInfoLinea[54] = $xCred->getMOP($fecha);
     // ($this->mOut == OUT_CSV) ? "01" : "'01";
     //55 clave de observacion, segun catalogo
     $this->mInfoLinea[55] = "";
     //56 clave de otorgante anterior
     //57 nombre otorgante anterior
     $this->mInfoLinea[56] = "";
     $this->mInfoLinea[57] = "";
     $this->mInfoLinea[58] = "";
     //Numero de cuenta anterior en caso de cartera tranferida
     $this->mInfoLinea[59] = $xCred->getFechaDePrimerAtraso() == null ? "" : $this->getDate($xCred->getFechaDePrimerAtraso());
     //TODO: Fecha de Primera atraso
     $this->mInfoLinea[60] = $this->getMonto($xCred->getSaldoActual($fecha));
     //Saldo Insoluto del Principal
     $this->mInfoLinea[61] = $this->getMonto($xCred->getMontoUltimoPago());
     // $xCred->getMontoDeParcialidad();//0; //TODO: Monto de Ultimo pago
     if (MODO_DEBUG == true) {
         $this->mMessages .= $xCred->getMessages(OUT_TXT);
     }
 }
 $cCred->init();
 $idsocio = $cCred->getClaveDePersona();
 $numero_de_socio = $cCred->getClaveDePersona();
 $afectaCaja = 1;
 //datos del socio
 $cSoc = new cSocio($numero_de_socio);
 $DSoc = $cSoc->getDatosInArray();
 $numero_caja_local = $DSoc["cajalocal"];
 $cCL = new cCajaLocal($numero_caja_local);
 $caja_local = $cCL->getNombre();
 $variable_nombre_del_socio = $idsocio == DEFAULT_SOCIO ? $DRec["cadena_distributiva"] : $cSoc->getNombreCompleto();
 $tipo_de_pago = "efectivo";
 //$variable_nombre_del_cajero
 //
 $tipoderecibo = 1;
 $docto = $cCred->getNumeroDeCredito();
 $origen = "";
 $variable_tipo_de_recibo = eltipo("operaciones_recibostipo", $tipoderecibo);
 $totaloperacion = $cCred->getMontoAutorizado();
 //<----------------------------------------------------------
 $variable_monto_del_recibo = number_format($totaloperacion, 2, '.', ',');
 $variable_monto_del_recibo_en_letras = convertirletras($totaloperacion);
 $variable_fecha_del_recibo = "";
 $variable_tipo_de_pago = "";
 $xCajero = new cSystemUser(getUsuarioActual());
 $variable_nombre_del_cajero = $xCajero->getNombreCompleto();
 $variable_observacion_del_recibo = "";
 $xSuc = new cSucursal(getSucursal());
 $xSuc->init();
 $DSuc = $xSuc->getDatosInArray();
 $variable_lugar = $DSuc["municipio"] . ", " . $DSuc["estado"];
$interes_normal_devengado = $xCred->getInteresNormalDevengado();
$interes_normal_pagado = $xCred->getInteresNormalPagado();
$interes_moratorio_pagado = $xCred->getInteresMoratorioPagado();
$interes_moratorio_devengado = $xCred->getInteresMoratorioDev();
$periocidad = $xCred->getPeriocidadDePago();
$ByLetra = "";
$solo_mora_corriente = $pago_total == true ? true : false;
//Corrige calculo de Interes.- Si es primer pago
$DInteres = $xCred->getInteresDevengado($fecha_operacion, $parcialidad, false, $solo_mora_corriente);
$interes_normal_calculado = $DInteres[SYS_INTERES_NORMAL];
$interes_moratorio_calculado = $DInteres[SYS_INTERES_MORATORIO];
$gastos_de_cobranza_calculado = $DInteres[SYS_GASTOS_DE_COBRANZA];
$fecha_de_pago = $fecha_vencimiento;
if ($xCred->getPeriocidadDePago() != CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
    $xLetra = new cParcialidadDeCredito();
    if ($xLetra->init($xCred->getClaveDePersona(), $xCred->getNumeroDeCredito(), $parcialidad) == true) {
        $fecha_de_pago = $xLetra->getFechaDePago();
        $xLog->add("OK\tFecha de Pago establecida a {$fecha_de_pago}\r\n", $xLog->DEVELOPER);
    } else {
        $xLog->add("ERROR\tParcialidad {$parcialidad} no inicializada\r\n", $xLog->DEVELOPER);
        $xLog->add("ERROR\tNo existe el Periodo de Pago\r\n", $xLog->COMMON);
    }
}
//=========================================================
//Datos del Respeto al Plan de Pagos
// ================================== VERIFICAR EL PLAN DE PAGOS =======================================
//======================================= END VERIFICATION =============================================
$interes_normal = 0;
$interes_moratorio = 0;
$base_iva_otros = 0;
$base_iva_intereses = 0;