function jsaGuardarReestructura($credito, $monto, $pagos, $periocidad, $tasa, $observaciones, $producto, $tipopago)
{
    $tasa = $tasa / 100;
    $xCred = new cCredito($credito);
    $xCred->init();
    $xCred->setReconvenido($monto, 0, $tasa, $periocidad, $pagos, $observaciones, false, false, $tipopago, $producto);
    $xF = new cFileLog();
    $xF->setWrite($xCred->getMessages());
    $xF->setClose();
    return $xCred->getMessages(OUT_HTML) . $xF->getLinkDownload("Descarga de Log");
}
function jsaGuardarCastigo($credito, $fecha, $razones)
{
    $xCred = new cCredito($credito);
    $xCred->init();
    $xCred->setCastigado($razones, $fecha);
    return $xCred->getMessages();
}
function jsaVincularAval($tipo, $AvalPersona, $monto, $consanguinidad, $vinculado, $documento, $depende = false)
{
    $xT = new cTipos();
    $xDoc = new cCredito($documento);
    $depende = $xT->cBool($depende);
    $xDoc->init();
    $xDoc->addAval($AvalPersona, $monto, $tipo, $consanguinidad, $depende);
    return $xDoc->getMessages(OUT_HTML);
}
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);
}
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 jsaGuardarDatosBanco($credito, $banco, $cuenta, $clabe)
{
    $xCred = new cCredito($credito);
    $xCred->init();
    $Cat = $xCred->OCatOtrosDatos();
    $datobanco = "";
    $xBan = new cBancos_entidades();
    $xBan->setData($xBan->query()->initByID($banco));
    $datobanco = $xBan->idbancos_entidades()->v() . " | " . $xBan->nombre_de_la_entidad()->v();
    $xCred->setOtrosDatos($Cat->DEPOSITO_BANCO, strtoupper($datobanco));
    $xCred->setOtrosDatos($Cat->DEPOSITO_CTA_BANCARIA, $cuenta);
    $xCred->setOtrosDatos($Cat->DEPOSITO_CLABE_BANCARIA, $clabe);
    return $xCred->getMessages(OUT_HTML);
}
 $xConv = new cProductoDeCredito($tipoconvenio);
 $xConv->init();
 if (USE_OFICIAL_BY_PRODUCTO == true) {
     $oficial_de_seguimiento = $xConv->getOficialDeSeguimiento();
 }
 if ($esrenovado == true) {
     $TipoDeAutorizacion = CREDITO_AUTORIZACION_RENOVADO;
     $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 ($addAct == false) {
         $msg .= "ERROR\tError al agregar la Actividad Economica \r\n";
     }
 }
 if (setNoMenorQueCero($origen_relacion) > 0 and setNoMenorQueCero($persona) > 0) {
     $documentorelacionado = parametro("iddocumentorelacionado", 0, MQL_INT);
     $personarelacionado = parametro("idpersonarelacionado", 0, MQL_INT);
     $idtipoderelacion = parametro("idtipoderelacion", 0, MQL_INT);
     $dependiente = parametro("dependiente", false, MQL_BOOL);
     $idtipodeparentesco = parametro("idtipodeparentesco", DEFAULT_TIPO_CONSANGUINIDAD, MQL_INT);
     if ($origen_relacion == iDE_CREDITO) {
         $xCred = new cCredito($documentorelacionado);
         $xCred->init();
         $MontoAvalado = $xCred->getMontoAutorizado();
         $addAval = $xCred->addAval($persona, $MontoAvalado, $idtipoderelacion, $idtipodeparentesco, $dependiente, $idobservaciones);
         $msg .= $xCred->getMessages();
     }
     //captacion
     //persona
     if ($origen_relacion == iDE_SOCIO) {
         if ($personarelacionado > 0) {
             $xPer = new cSocio($personarelacionado);
             if ($xPer->init() == true) {
                 $addRel = $xPer->addRelacion($persona, $idtipoderelacion, $idtipodeparentesco, $dependiente, $idobservaciones);
             }
             $msg .= $xPer->getMessages();
         } else {
             $msg .= "ERROR\tError al agregar a la Relacion, no existe relacionado \r\n";
         }
     }
 }
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");
}
    echo $oFrm->get();
    //echo $xJs->get();
    $idsolicitud = DEFAULT_CREDITO;
    //exit( "<p class='aviso'>AGREGUE UN NUMERO DE SOLICITUD</p></body></html>");
} else {
    $oFrm->OButton("TR.Recargar", "jsRecargar()", "refrescar", "refrescar");
    //Tabs
    $xHTabs = new cHTabs();
    $xBtn = new cHButton("");
    $xCred = new cCredito($idsolicitud);
    if ($xCred->init() == false) {
        $idsocio = getPersonaEnSession();
        $oFrm->addToolbar($xBtn->getRegresar("../index.xul.php?p=frmcreditos/creditos.panel.frm.php", true));
        $oFrm->addCreditBasico();
        $oFrm->addSubmit();
        $oFrm->addAviso($xCred->getMessages());
        //echo $oFrm->get();
    } else {
        if (setNoMenorQueCero($idsocio) <= 0) {
            $idsocio = $xCred->getClaveDePersona();
        }
        $xOPdto = $xCred->getOProductoDeCredito();
        if ($idsocio != $xCred->getClaveDePersona()) {
            $msg = "ERROR\tLa Persona {$idsocio} no es la propietaria del credito, el credito marca " . $xCred->getClaveDePersona() . "\r\n";
            $oFrm->addToolbar($xBtn->getRegresar("../index.xul.php?p=frmcreditos/creditos.panel.frm.php", true));
            $oFrm->addAviso($msg);
        } else {
            $oFrm->addHTML($xCred->getFichaDeSocio(true));
            $oFrm->addHTML($xCred->getFicha(true, "", true));
            $codigo_de_oficial = $xCred->getClaveDeOficialDeCredito();
            if (MODO_DEBUG == true) {
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}";
}
//Sql de especiales
$sqlEsp = "SELECT\n\t\t\t`eacp_config_bases_de_integracion_miembros`.`miembro`,\n\t\t\t`operaciones_tipos`.`descripcion_operacion`\n\n\t\tFROM\n\t\t\t`operaciones_tipos` `operaciones_tipos`\n\t\t\t\tINNER JOIN `eacp_config_bases_de_integracion_miembros`\n\t\t\t\t`eacp_config_bases_de_integracion_miembros`\n\t\t\t\tON `operaciones_tipos`.`idoperaciones_tipos` =\n\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`miembro`\n\t\tWHERE\n\t\t\t(`eacp_config_bases_de_integracion_miembros`.`codigo_de_base` = 1001)\n\t\t\tAND\n\t\t\t(`operaciones_tipos`.`estatus` =  1)\n\t\t\tAND (`eacp_config_bases_de_integracion_miembros`.`subclasificacion` = 1)\n\t\tORDER BY\n\t\t\t`eacp_config_bases_de_integracion_miembros`.`codigo_de_base`";
$cEsps = new cSelect("cMvtosEsp", "idMvtosEsp", $sqlEsp);
$cEsps->setOptionSelect(OPERACION_CLAVE_DE_CARGOS_VARIOS);
$cEsps->setEsSql();
$cEsps->addEvent("onblur", "addEspMvto");
$SEsp = $cEsps->show();
$xBtn = new cHButton();
$xFRM->addToolbar($xBtn->getBasic("Ajustar", "jsGetPagoAjustado()", "dinero", "idajust", false));
$xFRM->addToolbar($xBtn->getBasic("Sin Mora", "jsEliminarCargos()", "trabajo", "idsinmora", false));
$xFRM->addToolbar($xBtn->getBasic("Vista Previa", "showVistaPago()", "ver", "idprev", false));
$xFRM->addToolbar($xBtn->getBasic("Guardar Pago", "FormSucess()", "guardar", "idsave", false));
$xFRM->addFootElement("<table>\n\t<tbody id=\"tbCobros\">\t{$tds} </tbody>\n\t<tfoot>\n\t<tr>\n\t\t<td></td>\n\t\t<td colspan='2'>{$SEsp}</td></tr>\n    \t<tr>\n    \t\t<th><mark>Letra : {$parcialidad}</mark></th>\n      \t\t<th>TOTAL</th>\n      \t\t<th><input type=\"text\" name=\"ctotal\" id=\"idtotal\" value=\"{$total}\" class='mny' /></th>\n    \t</tr>\n\t</tfoot>\n</table>");
$xFRM->addAviso("", "id_letras_de_numeros", false, "success");
if (MODO_DEBUG == true) {
    $xLog->add($xCred->getMessages(OUT_TXT), $xLog->DEVELOPER);
    $xFRM->addLog($xLog->getMessages());
}
$xFRM->addAviso($xLog->getMessages(), "sysmsg", false, "notice");
echo $xFRM->get();
echo $xHP->setBodyEnd();
$jxc->drawJavaScript(false, true);
//XXX: Verificar generación de IVA
?>
<script>
var Wo				= new Gen();
var mMny 			= 0;
var goSucess 		= true;
var Frm 			= document.frmprocesarpago;
var jsWorkForm 		= document.frmprocesarpago;
var vTipoPago		= "<?php 
 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;
 }
    } else {
        $xCaja->setCloseBox(getUsuarioActual(), 0);
    }
    $messages .= $xCaja->getMessages(OUT_TXT);
}
//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";
 function setConciliarCreditos()
 {
     $msg = "";
     $cRec = new cReciboDeOperacion(10);
     $xRec = $cRec->setNuevoRecibo(DEFAULT_SOCIO, DEFAULT_CREDITO, fechasys(), 1, 10, "RECIBO_DE_AJUSTES_DE_PLAN_DE_PAGOS");
     $msg .= "\t\tRECIBO\tEl Recibo de Operacion es {$xRec}\r\n";
     $cRec->setNumeroDeRecibo($xRec, true);
     //Concilia Creditos sin Planes de Pago a SISBANCS
     $sql = "SELECT\n\t\t\t\t\t\t\t\t`migracion_creditos_por_socio`.`numero_socio`,\n\t\t\t\t\t\t\t\t`migracion_creditos_por_socio`.`creditos`,\n\t\t\t\t\t\t\t\t`migracion_creditos_por_socio`.`saldo`,\n\t\t\t\t\t\t\t\tgetCreditosCompac(numero_socio) AS `saldo_compac`,\n\t\t\t\t\t\t\t\t( `migracion_creditos_por_socio`.`saldo` -  getCreditosCompac(numero_socio)) AS 'diferencia'\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t`migracion_creditos_por_socio` `migracion_creditos_por_socio`\n\n\t\t\t\t\t\t\tHAVING\n\t\t\t\t\t\t\t\t(diferencia >0.99\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\tdiferencia < -0.99)";
     $rs = getRecordset($sql);
     while ($rw = mysql_fetch_array($rs)) {
         $socio = $rw["numero_socio"];
         $sqlCred = "SELECT\n\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_solicitud`.*,\n\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_tipoconvenio`.*,\n\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_periocidadpagos`.*,\n\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_estatus`.*,\n\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_solicitud`.`tasa_interes` AS `tasa_ordinaria_anual`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_solicitud`.`tipo_autorizacion` AS `tipo_de_autorizacion`,\n\t\t\t\t\t\t\t\t                    `creditos_solicitud`.`tasa_ahorro` AS `tasa_de_ahorro`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_tipoconvenio` `creditos_tipoconvenio`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `creditos_solicitud` `creditos_solicitud`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON `creditos_tipoconvenio`.`idcreditos_tipoconvenio`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t= `creditos_solicitud`.`tipo_convenio`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `creditos_periocidadpagos`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_periocidadpagos`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON `creditos_periocidadpagos`.\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`idcreditos_periocidadpagos` =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_solicitud`.`periocidad_de_pago`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `creditos_estatus`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_estatus`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON `creditos_estatus`.`idcreditos_estatus` =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`creditos_solicitud`.`estatus_actual`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(`creditos_solicitud`.`numero_socio` = {$socio} )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY fecha_vencimiento ASC, saldo_actual DESC,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfecha_solicitud DESC\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
         $ajuste = $rw["diferencia"];
         $SdoCW = $rw["saldo_compac"];
         $SdoSAFE = $rw["saldo"];
         $rsC = getRecordset($sqlCred);
         while ($rwC = mysql_fetch_array($rsC)) {
             $credito = $rwC["numero_solicitud"];
             $saldo = $rwC["saldo_actual"];
             $cCredito = new cCredito($credito, $socio);
             $cCredito->init($rwC);
             $DCred = $cCredito->getDatosDeCredito();
             $TAjustar = 0;
             //Generar un abono a Capital
             //si el ajuste es mayo a 0.09 o menor que -0.99 proseguir::
             if ($ajuste > 0.09 or $ajuste < -0.09) {
                 //Si 100 > 0.09 Y 0 < 0.09
                 if ($ajuste > 0.09 and $saldo <= 0.09) {
                     $msg .= "{$socio}\t{$credito}\tSe ignora el Credito por no tener Saldo (COMPACW {$SdoCW} / Credito {$saldo})\r\n";
                 } else {
                     // 50 > 30
                     //500 > -140
                     if ($ajuste > $saldo) {
                         //saldo <= 0
                         if ($saldo <= 0) {
                             //justar	= 500
                             $TAjustar = $ajuste;
                             //xajustar	= 0
                             $ajuste = 0;
                         } else {
                             //ajuste	= 30;
                             $TAjustar = $saldo;
                             //xajustar	= 50 - 30 = 20;
                             $ajuste = $ajuste - $saldo;
                         }
                         //80 < 100
                     } elseif ($ajuste < $saldo) {
                         //ajuste	= 80;
                         $TAjustar = $ajuste;
                         //xajustar	= 0;
                         $ajuste = 0;
                     } elseif ($ajuste == $saldo) {
                         //80 == 80
                         //ajustar	= 80
                         $TAjustar = $ajuste;
                         //xajustar	= 0;
                         $ajuste = 0;
                     }
                     $cCredito->setReciboDeOperacion($xRec);
                     $cCredito->setAbonoCapital($TAjustar);
                     $msg .= "{$socio}\t{$credito}\tRealizando un Ajuste de {$TAjustar} (COMPACW {$SdoCW} / Credito {$saldo})\r\n";
                     $msg .= $cCredito->getMessages("txt");
                 }
             } else {
                 $msg .= "{$socio}\t{$credito}\tNo se Realizan NINGUN ajuste (SAFE {$SdoSAFE} / COMPACW {$SdoCW} / Ajuste {$ajuste})\r\n";
             }
         }
         $msg .= "=============================\t{$socio}\t===========================\r\n";
         //$msg	.=  $cCredito->getMessages("txt");
     }
     $cRec->setFinalizarRecibo(true);
     $msg .= $cRec->getMessages("txt");
     return $msg;
 }
        $xRec->setFinalizarRecibo(true);
        $xRec->setMoneda("USD");
        $xRec->setUnidadesOriginales(100);
        $x2Rec = new cReciboDeOperacion(RECIBOS_TIPO_PAGO_APORTACIONES, true);
        $x2Rec->setNuevoRecibo($xCred->getClaveDePersona(), DEFAULT_CREDITO, "2013-01-01", 1);
        $x2Rec->setNuevoMvto("2013-01-01", 15000, OPERACION_CLAVE_APORT_CORRIENTE, 1, "Prueba de AML");
        $x2Rec->setNuevoMvto("2013-01-02", 1500, OPERACION_CLAVE_APORT_FONDO, 1, "Prueba de AML 2");
        $x2Rec->setNuevoMvto("2013-01-03", 45000, OPERACION_CLAVE_APORT_VOLUNTARIA, 1, "Prueba de AML 3");
        $x2Rec->setFinalizarRecibo(true);
        $xHFrm->addHElem("<p class='aviso'>" . $x2Rec->getMessages(OUT_HTML) . "</p>");
        $xAML->setGuardarPerfilTransaccional(101, "MX", 10000, 10, "");
        $xAML->setGuardarPerfilTransaccional(201, "MX", 20000, 2, "");
        $xAML->setGuardarPerfilTransaccional(301, "MX", 30000, 3, "");
        $xAML->setGuardarPerfilTransaccional(401, "MX", 40000, 4, "");
    }
    $xHFrm->addHElem("<p class='aviso'>" . $xCred->getMessages(OUT_HTML) . "</p>");
}
//$xHFrm->addHElem( $txt );
//$xHFrm->addHElem( $xF->show(true) );
//$xHFrm->addHElem( "<p class='aviso'>La $miFecha, Dias del Mes==". $xF->getDiasDelMes() ."</p>");
//$xAML->getSimilaresPorNombre("jose leonides", "cocom");
//$xAML->getSimilaresPorNombre("alberto", "chi");
$miFecha = "2014-03-01";
//$xAML->getSimilaresPorNombre();
//$acum	= $xAML->getOAcumuladoDeOperaciones("2013-12-30", $miFecha, SYS_TODAS);
$xAML->setVerificarPerfilTransaccional($miFecha);
//$acum6	= $xAML->get
//$xHFrm->addHElem( "<p class='aviso'> Las operaciones Acumulados son de " . $acum->getNumero() . " </p>");
//$xHFrm->addHElem( "<p class='aviso'> El Monto Acumulado es de " . $acum->getMonto() . " </p>");
//$xHFrm->addHElem( "<p class='aviso'>" . $acum->getSQL()  ."</p>");
$xHFrm->addHElem("<p class='aviso'>PAGOS EN EFECTIVO: " . $x2AML->getPagosEnEfectivoNac(SYS_MONTO) . "</p>");
 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);
     }
 }
 function setEliminarCreditosNegativos()
 {
     //Crear un nuevo Recibo de Ajuste
     $cRec = new cReciboDeOperacion(10);
     $xRec = $cRec->setNuevoRecibo(DEFAULT_SOCIO, DEFAULT_CREDITO, fechasys(), 1, 10, "RECIBO_DE_AJUSTES_DE_CREDITOS");
     $msg = "============\tRECIBO\tEl Recibo de Operacion es {$xRec}\r\n";
     $cRec->setNumeroDeRecibo($xRec, true);
     /*Esta funcion servira para eliminar saldos negativos de Créditos */
     $sql = "SELECT\n\t\t\t\t\t`creditos_solicitud`.*,\n\t\t\t\t\t`creditos_tipoconvenio`.*,\n\t\t\t\t\t`creditos_periocidadpagos`.*,\n\t\t\t\t\t`creditos_estatus`.*,\n\t\t\t\t\t`creditos_solicitud`.`tasa_interes` AS `tasa_ordinaria_anual`,\n\t\t\t\t\t`creditos_solicitud`.`tipo_autorizacion` AS `tipo_de_autorizacion`,\n                    `creditos_solicitud`.`tasa_ahorro` AS `tasa_de_ahorro`\n\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t`creditos_tipoconvenio` `creditos_tipoconvenio`\n\t\t\t\t\t\tINNER JOIN `creditos_solicitud` `creditos_solicitud`\n\t\t\t\t\t\tON `creditos_tipoconvenio`.`idcreditos_tipoconvenio`\n\t\t\t\t\t\t= `creditos_solicitud`.`tipo_convenio`\n\t\t\t\t\t\t\tINNER JOIN `creditos_periocidadpagos`\n\t\t\t\t\t\t\t`creditos_periocidadpagos`\n\t\t\t\t\t\t\tON `creditos_periocidadpagos`.\n\t\t\t\t\t\t\t`idcreditos_periocidadpagos` =\n\t\t\t\t\t\t\t`creditos_solicitud`.`periocidad_de_pago`\n\t\t\t\t\t\t\t\tINNER JOIN `creditos_estatus`\n\t\t\t\t\t\t\t\t`creditos_estatus`\n\t\t\t\t\t\t\t\tON `creditos_estatus`.`idcreditos_estatus` =\n\t\t\t\t\t\t\t\t`creditos_solicitud`.`estatus_actual`\n\t\t\t\t\t\t\t\tWHERE saldo_actual < " . TOLERANCIA_SALDOS . " ORDER BY saldo_actual ";
     $rs = getRecordset($sql);
     while ($rw = mysql_fetch_array($rs)) {
         $socio = $rw["numero_socio"];
         $credito = $rw["numero_solicitud"];
         $saldo_actual = $rw["saldo_actual"];
         //Se inicializa una nueva instancia de crédito
         $cCredito = new cCredito($credito, $socio);
         //y se neutralizara con su valor absoluto.
         $cCredito->init($rw);
         $cCredito->setReciboDeOperacion($xRec);
         //Generar un abono a Capital
         $cCredito->setAbonoCapital($saldo_actual);
         $msg .= "{$socio}\t{$credito}\tEliminando el saldo de {$saldo_actual}\r\n";
         $msg .= $cCredito->getMessages("txt");
     }
     $cRec->setFinalizarRecibo(true);
     return $msg;
 }
                                    ///Inicializar
                                    //autorizar
                                    $xCred->setAutorizado($monto, $pagos, $periocidad, CREDITO_TIPO_AUTORIZACION_AUTOMATICA, $ministracion, "CREDITO IMPORTADO #{$iReg}", false, $ministracion, 2, false, $vencimiento, CREDITO_ESTADO_AUTORIZADO, $monto, 0, $UltimaOperacion);
                                    $xCred->init();
                                    //ministrar
                                    $xCred->setForceMinistracion();
                                    $xCred->setMinistrar(DEFAULT_RECIBO_FISCAL, DEFAULT_CHEQUE, $monto, DEFAULT_CUENTA_BANCARIA, 0, DEFAULT_CUENTA_BANCARIA, "CREDITO IMPORTADO #{$iReg}", $ministracion);
                                    if ($monto > $saldo) {
                                        $abono = $monto - $saldo;
                                        $msg .= "{$iReg}\t{$socio}\t{$credito}\tAgregando un Abono por {$abono} por el Saldo {$saldo} del Monto {$monto}\r\n";
                                        $xCred->setAbonoCapital($abono, 1, DEFAULT_CHEQUE, DEFAULT_RECIBO_FISCAL, "CREDITO IMPORTADO #{$iReg}", DEFAULT_GRUPO, $UltimaOperacion);
                                    }
                                } else {
                                    $msg .= "{$iReg}\t{$socio}\t{$credito}\tEL Credito no se pudo agregar\r\n";
                                }
                                $msg .= $xCred->getMessages("txt");
                            }
                        }
                        $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>";
            }
        }
    }
    echo "</fieldset>\n</form> ";
}
//Agrega un abono a la ultima letra
if ($procesado == SYS_AUTOMATICO) {
    //$eqvalor			= round(($monto_a_operar - $totalAutomatico),2);
    $abonar_al_final = setNoMenorQueCero($monto_a_operar - $totalAutomatico, 2);
    if ($abonar_al_final > TOLERANCIA_SALDOS) {
        $msg .= "ERROR\tRECIBO {$recibo_pago} ... {$monto_a_operar} ....( {$totalAutomatico} ).... {$total_recibo} .... [{$abonar_al_final}] \r\n";
        $xCred->setAbonoCapital($abonar_al_final, $xCred->getPagosAutorizados(), DEFAULT_CHEQUE, $tipo_pago, $recibo_fiscal, $observaciones, $grupo, $fecha_operacion, $recibo_pago);
        $total_recibo += $abonar_al_final + $totalAutomatico;
    }
}
$oRec->init();
$oRec->setSumaDeRecibo($total_recibo);
$oRec->setFinalizarRecibo(true);
if (MODO_DEBUG == true) {
    $msg .= $oRec->getMessages(OUT_TXT);
    $msg .= $xCred->getMessages(OUT_TXT);
    $xFL = new cFileLog(false, true);
    $xFL->setWrite($msg);
    $xFL->setClose();
    if ($procesado != SYS_AUTOMATICO) {
        $xFRM->addToolbar($xFL->getLinkDownload("TR.Archivo de sucesos", ""));
    }
}
if ($procesado != SYS_AUTOMATICO) {
    $xFRM->addHElem($oRec->getFicha(true));
    $total_letras = convertirletras($total_recibo);
    $xBtn = new cHButton("");
    $xFRM->addToolbar($xBtn->getRegresar("./frmcobrosdecreditos.php", true));
    $xFRM->addToolbar($xBtn->getBasic("TR.Imprimir Recibo", "printrec()", "imprimir", "cmdPrint", false));
    $xFRM->addHTML("<table><tbody>{$tds}</tbody><tfoot><tr><th></th><th>TOTAL</th><th class='mny'>" . getFMoney($total_recibo) . "</th></tr><tr><th colspan=\"3\" class='warn'>{$total_letras}</th></tr></tfoot></table>");
    echo $xFRM->get();