function jsaGuardarCastigo($credito, $fecha, $razones)
{
    $xCred = new cCredito($credito);
    $xCred->init();
    $xCred->setCastigado($razones, $fecha);
    return $xCred->getMessages();
}
 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 jsaGetComisionPorApertura($idcredito)
{
    $xCred = new cCredito($idcredito);
    $xCred->init();
    $tasa = $xCred->getOProductoDeCredito()->getTasaComisionApertura();
    return round($xCred->getMontoAutorizado() * $tasa, 2);
}
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 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 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 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 jsaSetUltimoCheque($persona, $credito, $cuenta_bancaria)
{
    $xBanc = new cCuentaBancaria($cuenta_bancaria);
    $cheque = $xBanc->getUltimoCheque();
    $xCred = new cCredito($credito);
    $xCred->init();
    $montocheque = $xCred->getMontoAutorizado();
    $tab = new TinyAjaxBehavior();
    $tab->add(TabSetValue::getBehavior("idnumerocheque", $cheque));
    $tab->add(TabSetValue::getBehavior("idmontocheque", $montocheque));
    $tab->add(TabSetValue::getBehavior("idmontooriginal", $montocheque));
    return $tab->getString();
}
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);
}
function jsaGetLetras($idcredito, $idfecha)
{
    $xCred = new cCredito($idcredito);
    $xCred->init();
    //$xPlas	= $xCred->getPlanDePago();
    $xF = new cFecha();
    $idfecha = $xF->getFechaISO($idfecha);
    $xQL = new MQL();
    //$xQL->setRawQuery("SET @fecha_de_corte:='$idfecha';");
    my_query("SET @fecha_de_corte:='{$idfecha}';");
    $sql = "SELECT\r\n\t`letras`.`socio_afectado` AS `persona`,\r\n\t`letras`.`docto_afectado` AS `credito`,\r\n\t`letras`.`periodo_socio`  AS `parcialidad`,\r\n\t`letras`.`fecha_de_pago`,\r\n\r\n\t`letras`.`capital`,\r\n\t`letras`.`interes`,\r\n\t`letras`.`iva`,\r\n\t`letras`.`ahorro`,\r\n\t`letras`.`otros`,\r\n\t`letras`.`letra`,\t\r\n\t\r\n\t(`creditos_solicitud`.`tasa_moratorio`*100) AS `tasa_de_mora`,\r\n\t(`creditos_solicitud`.`tasa_interes`*100)   AS `tasa_de_interes` ,\r\n\tDATEDIFF(getFechaDeCorte(), fecha_de_pago) AS 'dias',\r\n\t ((letras.capital * DATEDIFF(getFechaDeCorte(), fecha_de_pago) * (`creditos_solicitud`.`tasa_moratorio` + `creditos_solicitud`.`tasa_interes`))/getDivisorDeInteres()) AS 'mora'\r\n\tFROM\r\n\t\t`creditos_solicitud` `creditos_solicitud` \r\n\t\t\tINNER JOIN `letras` `letras` \r\n\t\t\tON `creditos_solicitud`.`numero_solicitud` = `letras`.`docto_afectado`\r\n\t\r\n\t WHERE capital >0 AND docto_afectado={$idcredito} AND fecha_de_pago <= getFechaDeCorte()";
    $xT = new cTabla($sql);
    $xT->setFootSum(array(4 => "capital", 5 => "interes", 6 => "iva", 7 => "ahorro", 8 => "otros", 9 => "letra", 13 => "mora"));
    return $xT->Show();
}
/**
 * Funcion que retorna la descripcion Corta de una Solicitud de Credito
 *
 * @param integer $params
 * @return string
 */
function Common_b05dfbfaf8125673c6dc350143777ee1($params)
{
    $xT = new cTipos();
    $solicitud = $xT->cInt($params);
    $description = "";
    if (isset($solicitud) and $solicitud != 0) {
        $xCred = new cCredito($solicitud);
        if ($xCred->init() == false) {
            $description = MSG_NO_PARAM_VALID;
        } else {
            $description = $xCred->getShortDescription();
        }
    } else {
        $description = MSG_NO_PARAM_VALID;
    }
    return $description;
}
 function getFactura($enviar = false, $out = OUT_PDF)
 {
     $ready = null;
     $xml = "";
     $unidad = "NO APLICA";
     $cantidad = 1;
     $mql = new MQL();
     $xLis = new cSQLListas();
     $xLoc = new cLocal();
     $xPais = new cDomiciliosPaises(EACP_CLAVE_DE_PAIS);
     $xLog = new cCoreLog();
     $sql = "SELECT * FROM `operaciones_archivo_de_facturas` WHERE `clave_de_recibo` = " . $this->mCodigoDeRecibo . " LIMIT 0,1";
     $xArch = new cOperaciones_archivo_de_facturas();
     $DFact = $mql->getDataRow($sql);
     if (isset($DFact["clave_de_recibo"])) {
         $xArch->setData($DFact);
         $this->mMessages .= "OK\tEl UUID existe  " . $xArch->uuid()->v(OUT_TXT) . "\r\n";
         if ($enviar == true) {
             if ($this->getOPersona() == null) {
             } else {
                 $xSoc = $this->getOPersona();
                 $email = $xSoc->getCorreoElectronico();
                 $comprobante = PATH_FACTURAS . $xArch->uuid()->v(OUT_TXT);
                 file_put_contents($comprobante . ".xml", base64_decode($xArch->contenido()->v(OUT_TXT)));
                 file_put_contents($comprobante . ".pdf", base64_decode($xArch->impreso()->v(OUT_TXT)));
                 $ready = $out == OUT_PDF ? base64_decode($xArch->impreso()->v(OUT_TXT)) : base64_decode($xArch->contenido()->v(OUT_TXT));
                 $xNotif = new cNotificaciones();
                 //PDF y XML
                 $arrFil = array();
                 $arrFil["archivo1"]["path"] = $comprobante . ".pdf";
                 $arrFil["archivo2"]["path"] = $comprobante . ".xml";
                 $xNotif->sendMail("Factura del Recibo " . $this->mCodigoDeRecibo, "Factura del Recibo " . $this->mCodigoDeRecibo, $email, $arrFil);
                 //Enviar al Archivo mail
                 $xNotif->sendMail("Factura del Recibo " . $this->mCodigoDeRecibo, "Factura del Recibo " . $this->mCodigoDeRecibo, FACTURACION_MAIL_ARCHIVO, $arrFil);
                 $this->mMessages .= $xNotif->getMessages();
             }
         } else {
             $ready = $out == OUT_PDF ? $xArch->impreso()->v(OUT_TXT) : $xArch->contenido()->v(OUT_TXT);
         }
     } else {
         $xLog->add("WARN\tGenerando Nueva Factura\r\n", $xLog->DEVELOPER);
         //cargar Archivo
         $xPais->init();
         if ($this->mReciboIniciado == false) {
             $this->init();
         }
         if ($this->getOPersona() == null) {
             $xLog->add("ERROR\tAl cargar la Persona\r\n");
         } else {
             $xFact = new cFacturaElectronica();
             //datos de la emisora
             //persona iniciada
             $xSoc = $this->getOPersona();
             $email = $xSoc->getCorreoElectronico();
             $xFact->setEmisor(EACP_NAME, EACP_RFC, EACP_DOMICILIO_CALLE, EACP_DOMICILIO_NUM_EXT, EACP_DOMICILIO_NUM_INT, EACP_CODIGO_POSTAL, EACP_COLONIA, EACP_MUNICIPIO, EACP_ESTADO, $xPais->getNombre());
             $xFact->setRegimenFiscal(EACP_REGIMEN_FISCAL);
             $calle = $xLoc->DomicilioCalle();
             $numeroInt = $xLoc->DomicilioNumeroInterior();
             $numeroExt = $xLoc->DomicilioNumeroExterior();
             $codigoPostal = $xLoc->DomicilioCodigoPostal();
             $colonia = $xLoc->DomicilioColonia();
             $xSocDom = $xSoc->getODomicilio();
             $pais = $xLoc->getNombreDePais();
             $estado = $xLoc->DomicilioEstado();
             $municipio = $xLoc->DomicilioMunicipio();
             $tasa_iva = TASA_IVA;
             $xFact->setLugarDeExpedicion($xLoc->DomicilioCalle(), $xLoc->DomicilioNumeroExterior(), $xLoc->DomicilioNumeroInterior(), $xLoc->DomicilioCodigoPostal(), $xLoc->DomicilioColonia(), $xLoc->DomicilioMunicipio(), $xLoc->DomicilioEstado(), $xLoc->getNombreDePais());
             if ($xSocDom == null) {
                 $xLog->add("WARN\tNo hay domicilio Valido\r\n", $xLog->DEVELOPER);
             } else {
                 $calle = $xSocDom->getCalle();
                 $numeroExt = $xSocDom->getNumeroExterior();
                 $numeroInt = $xSocDom->getNumeroInterior();
                 $codigoPostal = $xSocDom->getCodigoPostal();
                 $colonia = $xSocDom->getColonia();
                 $municipio = $xSocDom->getMunicipio();
                 $estado = $xSocDom->getEstado();
                 $pais = $xSocDom->getNombreDePais();
             }
             //Cargar datos del Docto
             //$this->getOrigen();
             $OTipoRec = $this->getOTipoRecibo();
             if ($OTipoRec->getOrigen() == RECIBOS_ORIGEN_MIXTO or $OTipoRec->getOrigen() == RECIBOS_ORIGEN_COLOCACION) {
                 $xCred = new cCredito($this->getCodigoDeDocumento());
                 $xCred->init();
                 $tasa_iva = $xCred->getTasaIVA();
                 $xLog->add("WARN\tLa tasa de IVA es {$tasa_iva}\r\n", $xLog->DEVELOPER);
             }
             $xFact->setReceptor($xSoc->getNombreCompleto(), $xSoc->getRFC(true, true), $calle, $numeroExt, $numeroInt, $codigoPostal, $colonia, $municipio, $estado, $pais);
             //Datos del pagos
             $formaDePago = "Pago en una sola exhibición";
             $cuentaDePago = "No Identificado";
             $arrEquiv = array(TESORERIA_COBRO_DOCTO => "Documentos", TESORERIA_COBRO_EFECTIVO => "Efectivo", TESORERIA_COBRO_INTERNO => "Documentos", TESORERIA_COBRO_MULTIPLE => "Documentos", TESORERIA_COBRO_NINGUNO => "Documentos", TESORERIA_COBRO_TRANSFERENCIA => "Transferencia", TESORERIA_COBRO_CHEQUE => "Cheque");
             $metodoDePago = $arrEquiv[$this->getTipoDePago()];
             //cargar equivalencias
             //TODO: Considerar cambios en otro de tipo de tributacion
             if ($this->getTipoDePago() == TESORERIA_COBRO_TRANSFERENCIA or $this->getTipoDePago() == TESORERIA_COBRO_CHEQUE) {
                 $OCaja = $this->getOCaja();
                 $cuentaDePago = $OCaja->getCuentaBancoActivo();
             }
             //Cheque, Transferencia, Depósito
             $xFact->setDatosDePago($formaDePago, $metodoDePago, $cuentaDePago);
             $sql = "SELECT\n\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`codigo_de_base`,\n\t\t\t\t\t`operaciones_mvtos`.`recibo_afectado`,\n\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`miembro`,\n\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`subclasificacion`,\n\t\t\t\t\t`operaciones_tipos`.`descripcion_operacion` AS `operacion`,\n\t\t\t\t\t`operaciones_mvtos`.`fecha_operacion`,\n\t\t\t\t\t`operaciones_mvtos`.`afectacion_real` AS 'monto'  \n\t\t\t\tFROM\n\t\t\t\t\t`operaciones_mvtos` `operaciones_mvtos` \n\t\t\t\t\t\tINNER JOIN `eacp_config_bases_de_integracion_miembros` \n\t\t\t\t\t\t`eacp_config_bases_de_integracion_miembros` \n\t\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` = \n\t\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`miembro` \n\t\t\t\t\t\t\tINNER JOIN `operaciones_tipos` `operaciones_tipos` \n\t\t\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` = `operaciones_tipos`.\n\t\t\t\t\t\t\t`idoperaciones_tipos` \n\t\t\t\tWHERE\n\t\t\t\t\t(`eacp_config_bases_de_integracion_miembros`.`codigo_de_base` =11000) AND\n\t\t\t\t\t(`operaciones_mvtos`.`recibo_afectado` =" . $this->mCodigoDeRecibo . " )";
             $iva = 0;
             $total = 0;
             $rs = $mql->getDataRecord($sql);
             foreach ($rs as $rows) {
                 $descripcion = $rows["operacion"];
                 $valor = $rows["monto"];
                 $tipo = $rows["subclasificacion"];
                 $total += $valor;
                 if ($tipo == 1000) {
                     $iva += $rows["monto"];
                 } else {
                     $xFact->addConcepto($cantidad, $unidad, $valor, $descripcion);
                 }
             }
             //agregar IVA
             if ($iva > 0) {
                 $xFact->addTrasladado("IVA", $tasa_iva, $iva);
             }
             $xml = $xFact->get();
             $this->mOFactura = $xFact;
             if ($total <= 0) {
                 $enviar = false;
             }
         }
         if ($enviar == true) {
             if ($this->mOFactura != null) {
                 if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                     if ($this->mOFactura->timbrar() == 1) {
                         //ready = true
                         $xNotif = new cNotificaciones();
                         //PDF y XML
                         $arrFil = array();
                         $arrFil["archivo1"]["path"] = $this->mOFactura->getComprobante() . ".pdf";
                         $arrFil["archivo2"]["path"] = $this->mOFactura->getComprobante() . ".xml";
                         $xNotif->sendMail("Factura del Recibo " . $this->mCodigoDeRecibo, "Factura del Recibo " . $this->mCodigoDeRecibo, $email, $arrFil);
                         //Enviar al Archivo mail
                         $xNotif->sendMail("Factura del Recibo " . $this->mCodigoDeRecibo, "Factura del Recibo " . $this->mCodigoDeRecibo, FACTURACION_MAIL_ARCHIVO, $arrFil);
                         //Guardar en DB
                         $this->mOFactura->setArchivar($this->mCodigoDeRecibo);
                         $xLog->add($xNotif->getMessages(), $xLog->DEVELOPER);
                         $ready = $out == OUT_PDF ? $this->mOFactura->getPDF() : $this->mOFactura->getXML();
                     }
                 } else {
                     $xLog->add("WARN\tNo hay email valido para la Factura ({$email})\r\n", $xLog->DEVELOPER);
                 }
                 $xLog->add($this->mOFactura->getMessages(), $xLog->DEVELOPER);
             }
         }
     }
     $this->mMessages .= $xLog->getMessages();
     return $ready;
 }
$xDate = new cHDate();
$xDate2 = new cHDate(2, false, FECHA_TIPO_NACIMIENTO);
$xSel = new cHSelect();
$xHNot = new cHNotif();
$xChk = new cHCheckBox();
if ($action == SYS_NINGUNO) {
    $xFRM->addGuardar("jsCheck()");
}
//=========================================== AVALES
if (setNoMenorQueCero($con_relacion) > 0) {
    $xHSel = new cHSelect();
    $tipoRe = "";
    if (setNoMenorQueCero($persona_rel) <= 0) {
        if ($con_relacion == iDE_CREDITO) {
            $xDoc = new cCredito($documento_rel);
            $xDoc->init();
            $persona_rel = $xDoc->getClaveDePersona();
            $tipoRe = PERSONAS_REL_CLASE_AVAL;
        }
        //TODO: Iniciar cuenta de captacion
    }
    $tipo_de_ingreso = TIPO_INGRESO_RELACION;
    $con_domicilio = true;
    $con_actividad = true;
    $desde_sucursal = getSucursal();
    $xFRM->addHElem($xSel->getListaDeTiposDeRelaciones("", $tipoRe)->get(true));
    $xFRM->addHElem($xChk->get("TR.es dependiente_economico", "dependiente"));
    $xFRM->addHElem($xHSel->getListaDeTiposDeParentesco()->get(true));
    $xFRM->OHidden("iddocumentorelacionado", $documento_rel, "");
    $xFRM->OHidden("idpersonarelacionado", $persona_rel, "");
    $xFRM->OHidden("idorigenrelacionado", $con_relacion, "");
//Numero de Socio
$f15 = !isset($_GET["f15"]) ? false : $_GET["f15"];
$f14 = !isset($_GET["f14"]) ? false : $_GET["f14"];
$f16 = !isset($_GET["f16"]) ? false : $_GET["f16"];
$f18 = !isset($_GET["f18"]) ? false : $_GET["f18"];
//Mostrar Movimiento Especifico
$TOperacion = !isset($_GET["f19"]) ? false : $_GET["f19"];
//Codigo de Tipo de Operacion.- Mvto Especifico
$fecha_inicial = $_GET["on"];
$fecha_final = $_GET["off"];
$xHP->init("initComponents()");
$xRPT = new cReportes($xHP->getTitle());
echo $xHP->getEncabezado();
echo $xRPT->getEncabezado();
$cCred = new cCredito($idsolicitud);
$cCred->init();
//TODO: Modificar
echo $cCred->getFicha(true, "", true, true);
$sql = "SELECT\n\t`creditos_sdpm_historico`.`idcreditos_sdpm_historico` AS `control`,\n\t`creditos_sdpm_historico`.`numero_de_socio`,\n\t`creditos_sdpm_historico`.`numero_de_credito`,\n\t`creditos_sdpm_historico`.`fecha_anterior`,\n\t`creditos_sdpm_historico`.`fecha_actual`,\n\t`creditos_sdpm_historico`.`dias_transcurridos`,\n\t`creditos_sdpm_historico`.`monto_calculado`,\n\t`creditos_sdpm_historico`.`saldo`,\n\t`creditos_sdpm_historico`.`estatus`,\n\t`creditos_sdpm_historico`.`interes_normal`\nFROM\n\t`creditos_sdpm_historico` `creditos_sdpm_historico` \nWHERE\n\t(`creditos_sdpm_historico`.`numero_de_credito` ={$idsolicitud})\nORDER BY\n\t`creditos_sdpm_historico`.`fecha_anterior` ASC\n\t/*`creditos_sdpm_historico`.`fecha_actual` DESC */";
$cTbl = new cTabla($sql);
$cTbl->setTdClassByType();
$cTbl->setWidth();
$cTbl->Show("", false);
$TSum = $cTbl->getFieldsSum();
echo " <table width='100%'>\n\t\t<tr>\n\t\t<td />\n\t\t<td />\n\t\t<td />\n\t\t<td />\n\t\t\n\t\t<th class='mny'>" . getFMoney($TSum["dias_transcurridos"]) . "</th>\n\t\t<th class='mny'>" . getFMoney($TSum["monto_calculado"]) . "</th>\n\t\t<th class='mny'>" . getFMoney($TSum["saldo"]) . "</th>\n\t\t<td />\n\t\t<th class='mny'>" . getFMoney($TSum["interes_normal"]) . "</th>\n\t\t</tr>\n\t\t</table ";
echo $xHP->getPieDePagina();
?>
</body>
<script  >
<?php 
?>
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");
}
 SaldoActual
 LimiteCredito
 SaldoVencido
 NumeroPagosVencidos
 PagoActual
 HistoricoPagos
 ClavePrevencion
 TotalPagosReportados
 ClaveAnteriorOtorgante
 NombreAnteriorOtorgante
 NumeroCuentaAnterior	
 */
 //obtener parametros extras en una array
 //su valor es del producto
 $xCred = new cCredito($idcredito, $rw["numero_socio"]);
 $xCred->init($rw);
 if (isset($DPagos[$idcredito])) {
     $xCred->initPagosEfectuados($DPagos[$idcredito], $FechaFinal);
     ///$xLog->add("OK\t$icnt\tDatos del credito $idpersona|$idcredito SI existen \r\n", $xLog->DEVELOPER);
 } else {
     $xLog->add("WARN\t{$idpersona}-{$idcredito}\t{$sucres}\t{$icnt}\tDatos de Pago del credito {$idpersona}|{$idcredito} no existen \r\n", $xLog->DEVELOPER);
 }
 $ClaveActualOtorgante = $xCR->getClaveDeOtorgante();
 // ENTIDAD_CLAVE_SIC;
 $NombreOtorgante = $xCR->getNombreOtorgante();
 $CuentaActual = $rw["numero_solicitud"];
 $xTConv = new cProductoDeCredito($rw["tipo_convenio"]);
 $xTConv->init();
 $DTConv = $xTConv->getOtrosParametrosInArray();
 $TipoDeResponsabilidad = isset($DTConv["SIC_TIPO_DE_RESPONSABILIDAD"]) ? $DTConv["SIC_TIPO_DE_RESPONSABILIDAD"] : "I";
 //individual
 function addRelacionPorDocumento($relacionado, $documento, $tipo = DEFAULT_TIPO_RELACION)
 {
     $monto = 0;
     if ($tipo == PERSONAS_REL_AVAL_HIPO or $tipo == PERSONAS_REL_AVAL_QUIRO) {
         $xCred = new cCredito($documento);
         if ($xCred->init() == true) {
             $monto = $xCred->getMontoAutorizado();
         }
     }
     return $this->addRelacion($relacionado, $tipo, DEFAULT_TIPO_CONSANGUINIDAD, false, "", $monto, 1, false, $documento);
 }
    echo JS_CLOSE;
} else {
    $xCred = new cCredito($idsolicitud, $idsocio);
    $xCred->init();
    if ($xCred->getEstadoActual() == CREDITO_ESTADO_AUTORIZADO or $monto_cheque1 <= 0) {
        $recibo = $xCred->setMinistrar($recibo_fiscal, $cheque, $monto_cheque1, $cuenta_cheques, $cheque2, $cuenta_cheques2, $observaciones, $fecha);
        if (setNoMenorQueCero($recibo) > 0) {
            $xFRM->addHTML($xCred->getFichaDeSocio());
            $xFRM->addHTML($xCred->getFicha());
            $xFRM->OButton("TR.RECIBO DE MINISTRACION", "jsImprimirReciboMinistracion()", $xFRM->ic()->REPORTE, "id4");
            $xFRM->addToolbar($xBtn->getIrAlInicio(true));
            $uPagare = "elUrl='" . $xCred->getOProductoDeCredito()->getPathPagare($idsolicitud) . "';";
            $uContrato = "esUrl='" . $xCred->getPathDelContrato() . "';";
            if ($creditodescontado >= DEFAULT_CREDITO) {
                $xDCred = new cCredito($creditodescontado);
                $xDCred->init();
                $saldodesc = $xDCred->getSaldoActual($fecha);
                if ($saldodesc < $montocreditodesc) {
                    $montocreditodesc = $saldodesc;
                    $montocomision = $montocomision + ($montocreditodesc - $saldodesc);
                }
                $idrecibocap = $xDCred->setAbonoCapital($montocreditodesc, SYS_UNO, $cheque, TESORERIA_COBRO_DESCTO, $recibo_fiscal, $observaciones);
                if (setNoMenorQueCero($idrecibocap) > 0) {
                    $xRecCapt = new cReciboDeOperacion(false, false, $idrecibocap);
                    $xRecCapt->init();
                    if ($xRecCapt->setFinalizarRecibo(true) == true) {
                        $xFRM->OButton("TR.Recibo de Abono", "jsImprimirReciboCapital()", "imprimir");
                        $xFRM->addHTML($xRecCapt->getJsPrint(true, "jsImprimirReciboCapital"));
                        //finalizar tesoreria
                        $xRecCapt->setFinalizarTesoreria(array("cuenta" => $cuenta_cheques, "cheque" => $cheque));
                    }
 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);
     }
 }
 $iva = round($xT->cFloat($cadena[5]), 2);
 $ahorro = round($xT->cFloat($cadena[6]), 2);
 $observaciones = $xT->cChar($cadena[7]);
 $total = $capital + $ahorro + $interes + $iva;
 if (isset($socio) and isset($credito) and !empty($socio) and !empty($credito)) {
     $DSoc = new cSocio($socio);
     $SocioExiste = $DSoc->existe($socio);
     $CreditoExiste = $DSoc->existeCredito($credito);
     if ($SocioExiste == true and $CreditoExiste == true) {
         $DSoc->init();
         $nombre = $DSoc->getNombreCompleto();
         $nombre = substr($nombre, 0, 25);
         //Verificar el Saldo del Credito
         $CCred = new cCredito($credito, $socio);
         //echo "$credito ---- $socio<br>";
         $CCred->init();
         $DCred = $CCred->getDatosDeCredito();
         $saldo = $DCred["saldo_actual"];
         if (!isset($saldo) or $saldo == 0) {
             //$socio 		= "";
             if ($saldo != 0 && $capital != 0) {
                 $msg .= "{$iReg}\t{$socio}\t{$credito}\tDIF1\tEL Saldo({$saldo}) es menor al abono({$capital}), difiere por " . getFMoney($saldo - $capital) . " \r\n ";
             }
             $saldo = 0;
             $diferencias += $capital;
             $capital = 0;
             $total = $capital + $ahorro + $interes;
             $cls = " class='warn' ";
         }
         if ($saldo < $capital) {
             $msg .= "{$iReg}\t{$socio}\t{$credito}\tDIF2\tEL Saldo({$saldo}) es menor al abono({$capital}) , difiere por " . getFMoney($saldo - $capital) . " \r\n ";
echo $xP->setBodyinit();
//Crear formularios
$xHFrm = new cHForm("frmTest", "./test.php");
$xHTxt = new cHText("");
//$txt 	= $xHTxt->getDeMoneda("id", "Moneda de Prueba",  100);
$miFecha = fechasys();
$xF = new cFecha(0, $miFecha);
$runTest = isset($_GET["run"]) ? true : false;
$persona_de_pruebas = parametro("persona", 99999, MQL_INT);
$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); }
<?php 
if (setNoMenorQueCero($idsolicitud) <= 0) {
    $idsocio = getPersonaEnSession();
    $oFrm->addCreditBasico();
    $oFrm->addSubmit();
    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);
 function setRepararPlanDePagos()
 {
     $msg = "";
     $msg .= "============= RECONSTRUYENDO LETRAS SISBANCS \r\n";
     //Selecciona todo los pagos segun letra, en una base
     $arrFechas = array();
     $arrMontos = array();
     $sqlLetras = "SELECT SQL_CACHE\n\t\t\t\t\t\t\t`operaciones_mvtos`.`docto_afectado`,\n\t\t\t\t\t\t\t`operaciones_mvtos`.`periodo_socio`,\n\t\t\t\t\t\t\tMAX(`operaciones_mvtos`.`fecha_afectacion`) AS 'fecha',\n\t\t\t\t\t\t\tSUM(`operaciones_mvtos`.`afectacion_real`) AS 'monto'\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`operaciones_mvtos` `operaciones_mvtos`\n\t\t\t\t\t\t\t\tINNER JOIN `eacp_config_bases_de_integracion_miembros`\n\t\t\t\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`\n\t\t\t\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` =\n\t\t\t\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`miembro`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t(`eacp_config_bases_de_integracion_miembros`.`codigo_de_base` = 2003)\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(`operaciones_mvtos`.`afectacion_real` >0)\n\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t`operaciones_mvtos`.`docto_afectado`,\n\t\t\t\t\t\t\t`operaciones_mvtos`.`periodo_socio`\n\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t`eacp_config_bases_de_integracion_miembros`.`codigo_de_base`,\n\t\t\t\t\t\t\t`operaciones_mvtos`.`socio_afectado`,\n\t\t\t\t\t\t\t`operaciones_mvtos`.`docto_afectado`,\n\t\t\t\t\t\t\t`operaciones_mvtos`.`periodo_socio` ";
     $rsA = getRecordset($sqlLetras);
     while ($rw = mysql_fetch_array($rsA)) {
         $arrFechas[$rw["docto_afectado"] . "-" . $rw["periodo_socio"]] = $rw["fecha"];
         $arrMontos[$rw["docto_afectado"] . "-" . $rw["periodo_socio"]] = $rw["monto"];
     }
     $fecha_de_migracion = fechasys();
     //DELETE FROM sisbancs_amortizaciones WHERE credito = 0 AND parcialidad = 1
     $sql = "SELECT\n\t\t\t\t\t\t\t\t`sisbancs_amortizaciones`.*\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t`sisbancs_amortizaciones` `sisbancs_amortizaciones` ";
     $rs = getRecordset($sql);
     $contar = 0;
     while ($rw = mysql_fetch_array($rs)) {
         $credito = $rw["credito"];
         $socio = $rw["credito"];
         $parcialidad = $rw["parcialidad"];
         $vencimiento = $rw["fecha_de_vencimiento"];
         $saldo_vigente = $rw["saldo_vigente"];
         $saldo_vencido = 0;
         $interes_vigente = $rw["interes_vigente"];
         $interes_vencido = 0;
         $interes_moratorio = 0;
         $dias_en_mora = 0;
         $estatus = $rw["estatus"];
         $fecha_de_abono = $rw["fecha_de_abono"];
         $iva_normal = 0;
         $iva_moratorio = 0;
         $tasa_normal = 0;
         $tasa_moratorio = 0;
         $monto_abonado = 0;
         $saldo_teorico = 0;
         $DCredito = array();
         //TODO: Actualizar sentencia de obtencion de IVA
         $msg .= "{$contar}\t{$credito}\t{$parcialidad}\t\t=================================================\r\n";
         //Actualizar le fecha de Pago
         if (isset($arrFechas["{$credito}-{$parcialidad}"])) {
             $fecha_de_abono = $arrFechas["{$credito}-{$parcialidad}"];
             $monto_abonado = $arrMontos["{$credito}-{$parcialidad}"];
             //Corrige las idioteces de reestructuras
             if (strtotime($vencimiento) > strtotime($fecha_de_abono)) {
                 $fecha_de_abono = $vencimiento;
                 $msg .= "{$contar}\t{$credito}\t{$parcialidad}\tERROR_DE_FECHA\tLa fecha de abono(" . getFechaMediana($fecha_de_abono) . ") es menor a la de vencimiento " . getFechaMediana($vencimiento) . " \r\n";
             }
             $saldo_teorico = $saldo_vigente - $monto_abonado;
             $msg .= "{$contar}\t{$credito}\t{$parcialidad}\tFECHA_DE_ABONO\tLa fecha de Abono Existente es " . getFechaMediana($fecha_de_abono) . " y suma de {$monto_abonado} (saldo teorico {$saldo_teorico})\r\n";
         }
         if (strtotime($vencimiento) < strtotime($fecha_de_migracion)) {
             $msg .= "{$contar}\t{$credito}\t{$parcialidad}\tFECHA_DE_VCTO\tLa Vencimiento (" . getFechaMediana($vencimiento) . ") es Menor a la Fecha de Migracion\r\n";
             $estatus = 2;
             $saldo_vencido = $saldo_vigente;
             $saldo_vigente = 0;
             $interes_vencido = $interes_vigente;
             $interes_vigente = 0;
             $xCred = new cCredito($credito, $socio);
             $xCred->init();
             $DCredito = $xCred->getDatosDeCredito();
             $tasa_moratorio = $DCredito["tasa_moratorio"];
             $dias_morosos = setNoMenorQueCero(restarfechas($fecha_de_migracion, $fecha_de_abono));
             $interes_moratorio = $saldo_vencido * $dias_morosos * $tasa_moratorio / EACP_DIAS_INTERES;
             $msg .= "{$contar}\t{$credito}\t{$parcialidad}\tINTERES_MORATORIO\tEl Interes Moratorio es {$interes_moratorio}, por {$dias_morosos} dias en Mora y Capital {$saldo_vencido}\r\n";
         }
         $iva_normal = ($interes_vigente + $interes_vencido) * 0.15;
         $iva_moratorio = $interes_moratorio * 0.15;
         $sqlUD = "UPDATE sisbancs_amortizaciones\n\t\t\t\t\t\t\t\t\t\t\t\t    SET  fecha_de_abono='{$fecha_de_abono}', saldo_vigente={$saldo_vigente},\n\t\t\t\t\t\t\t\t\t\t\t\t\tsaldo_vencido={$saldo_vencido}, interes_vigente={$interes_vigente}, interes_vencido={$interes_vencido},\n\t\t\t\t\t\t\t\t\t\t\t\t\tsaldo_interes_vencido=0, interes_moratorio={$interes_moratorio}, estatus={$estatus},\n\t\t\t\t\t\t\t\t\t\t\t\t\tiva_interes_normal={$iva_normal}, iva_interes_moratorio={$iva_moratorio}\n\t\t\t\t\t\t\t\t\t\t\t\t    WHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\tcredito={$credito}, parcialidad={$parcialidad} ";
         my_query($sqlUD);
         $contar++;
     }
     return $msg;
 }
 function setCredito($credito)
 {
     $this->mDocumento = $credito;
     $xFDE = new cFecha();
     $xLng = new cLang();
     $cCred = new cCredito($credito);
     $cCred->init();
     $idsolicitud = $credito;
     $DCred = $cCred->getDatosDeCredito();
     $DProd = $cCred->getOProductoDeCredito();
     $OOParam = new cProductoDeCreditoOtrosDatosCatalogo();
     $numero_de_socio = $cCred->getClaveDePersona();
     $this->mPersona = $numero_de_socio;
     $cSoc = new cSocio($numero_de_socio);
     $cSoc->init();
     $svar_info_cred = "";
     $tblInfCred = new cFicha(iDE_CREDITO, $idsolicitud);
     $this->setPersona($numero_de_socio);
     $svar_info_cred = $tblInfCred->show(true);
     //Lista de Beneficiados
     $lst_beneficiados = "";
     $this->getListadoDeAvales($idsolicitud);
     $SQLCBen = "SELECT `socios_relacionestipos`.`descripcion_relacionestipos` AS 'relacion', `socios_relaciones`.`nombres`,\t`socios_relaciones`.`apellido_paterno`,\t`socios_relaciones`.`apellido_materno`,\n\t\t\t`socios_consanguinidad`.`descripcion_consanguinidad` AS 'consaguinidad'\n\t\t\tFROM `socios_relaciones` `socios_relaciones` INNER JOIN `socios_consanguinidad` `socios_consanguinidad` ON `socios_relaciones`.`consanguinidad` = `socios_consanguinidad`.`idsocios_consanguinidad`\n\t\t\tINNER JOIN `socios_relacionestipos` `socios_relacionestipos` ON `socios_relaciones`.`tipo_relacion` = `socios_relacionestipos`.`idsocios_relacionestipos`\n\t\t\tWHERE (`socios_relaciones`.`socio_relacionado` ={$numero_de_socio}) AND (`socios_relaciones`.`credito_relacionado` ={$idsolicitud})\tAND\t(`socios_relaciones`.`tipo_relacion`=11)";
     $tblCBen = new cTabla($SQLCBen);
     $lst_beneficiados = $tblCBen->Show();
     $firmas_de_avales = $this->mFirmasAvales;
     // $cSoc->getCoResponsables("firmas", "avales", $idsolicitud );
     //Plan de Pago segun SQL
     $splan_pagos = $cCred->getPlanDePago(OUT_HTML, true, true);
     //==================================================================================
     $fichas_de_avales = $this->mFichasAvales;
     //$cCred->getAvales_InText();
     $fecha_larga_de_documento = $xFDE->getFechaLarga($cCred->getFechaDeMinistracion());
     $fichas_de_respsolidarios = "";
     //TODO: FALTA
     //Otros Datos
     $monto_ministrado = $cCred->getMontoAutorizado();
     $tasa_interes_mensual_ordinario = round($cCred->getTasaDeInteres() / 12 * 100, 2);
     $tasa_interes_anual_ordinario = $cCred->getTasaDeInteres();
     $fecha_de_vencimiento = $cCred->getFechaDeVencimiento();
     $fecha_de_ministracion = $cCred->getFechaDeMinistracion();
     $tasa_garantia_liquida = $DCred["porciento_garantia_liquida"] * 100;
     $monto_garantia_liquida = $monto_ministrado * $tasa_garantia_liquida;
     $tasa_interes_mensual_moratorio = round($cCred->getTasaDeMora() / 12 * 100, 2);
     $dias_del_credito = $cCred->getDiasAutorizados();
     $meses_del_credito = sprintf("%02d", ceil($dias_del_credito / 30.416666666666668));
     $periocidad = $cCred->getPeriocidadDePago();
     //Tipo de Credito por SQL
     $SQLTCred = "SELECT * FROM creditos_modalidades WHERE idcreditos_modalidades=" . $DCred["tipo_credito"];
     $tipo_de_credito = mifila($SQLTCred, "descripcion_modalidades");
     //Datos del Grupo Solidarios por SQL
     $SQLGAsoc = "SELECT * FROM socios_grupossolidarios WHERE idsocios_grupossolidarios=" . $DCred["grupo_asociado"];
     $InfoGrupo = obten_filas($SQLGAsoc);
     $nombre_rep_social = $InfoGrupo["representante_nombrecompleto"];
     $codigo_rep_social = $InfoGrupo["representante_numerosocio"];
     $nombre_voc_vigila = $InfoGrupo["vocalvigilancia_nombrecompleto"];
     $nombre_del_grupo = $InfoGrupo["nombre_gruposolidario"];
     $domicilio_rep_social = domicilio($codigo_rep_social);
     $tabla_asociadas = "";
     $lista_asociadas = "";
     $tasa_de_cat = $cCred->getCAT();
     $DPeriocidad = new cPeriocidadDePago($cCred->getPeriocidadDePago());
     $DPeriocidad->init();
     $monto_con_interes = "";
     $monto_con_interes_letras = "";
     if ($DCred["grupo_asociado"] != DEFAULT_GRUPO) {
         $SQL_get_grupo = "SELECT `socios_general`.`codigo`, CONCAT(`socios_general`.`nombrecompleto`, ' ', `socios_general`.`apellidopaterno`, ' ', `socios_general`.`apellidomaterno`) AS 'nombre_completo'\n\t\t\t\t\t\t\t\t\tFROM `socios_general` `socios_general` WHERE (`socios_general`.`grupo_solidario` =" . $DCred["grupo_asociado"] . ")";
         $rsg = getRecordset($SQL_get_grupo);
         while ($rwt = mysql_fetch_array($rsg)) {
             $lista_asociadas .= ", " . $rwt["nombre_completo"];
         }
     }
     if (EACP_INCLUDE_INTERES_IN_PAGARE == true) {
         if ($periocidad == CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
             $monto_con_interes = $cCred->getMontoAutorizado() + $cCred->getInteresDiariogenerado() * $cCred->getDiasAutorizados();
         } else {
             $sqlInt = "SELECT `operaciones_mvtos`.`docto_afectado`, `operaciones_mvtos`.`tipo_operacion`, COUNT(`operaciones_mvtos`.`idoperaciones_mvtos`) AS `mvtos`,\n\t\t\t\t\tSUM(`operaciones_mvtos`.`afectacion_real` *\t`eacp_config_bases_de_integracion_miembros`.`afectacion`) AS 'monto'\n\t\t\t\t\tFROM `operaciones_mvtos` `operaciones_mvtos` INNER JOIN `eacp_config_bases_de_integracion_miembros`\t`eacp_config_bases_de_integracion_miembros`\n\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` = `eacp_config_bases_de_integracion_miembros`.`miembro` WHERE (`operaciones_mvtos`.`docto_afectado` = {$idsolicitud})\n\t\t\t\t\tAND (`eacp_config_bases_de_integracion_miembros`.`codigo_de_base` = 2601)\n\t\t\t\t\tGROUP BY `operaciones_mvtos`.`docto_afectado`, `eacp_config_bases_de_integracion_miembros`.`codigo_de_base`\n\t\t\t\t\tORDER BY `eacp_config_bases_de_integracion_miembros`.`codigo_de_base`, `operaciones_mvtos`.`fecha_afectacion`, `operaciones_mvtos`.`socio_afectado`\t";
             $xF = obten_filas($sqlInt);
             $monto_con_interes = $xF["monto"];
         }
         $monto_con_interes_letras = convertirletras($monto_con_interes);
         $monto_con_interes = getFMoney($monto_con_interes);
     }
     $this->mArr["variable_informacion_del_credito"] = $cCred->getFicha();
     //"variable_lista_de_beneficiados" 		=> $lst_beneficiados,
     $this->mArr["variable_tipo_de_credito"] = $tipo_de_credito;
     $this->mArr["variable_monto2_ministrado_con_intereses_en_letras"] = $monto_con_interes_letras;
     $this->mArr["variable_monto2_ministrado_con_intereses"] = $monto_con_interes;
     $this->mArr["variable_monto_ministrado"] = getFMoney($monto_ministrado);
     $this->mArr["variable_tasa_mensual_de_interes_ordinario"] = $tasa_interes_mensual_ordinario;
     $this->mArr["variable_credito_fecha_de_vencimiento"] = $xFDE->getFechaMediana($fecha_de_vencimiento);
     $this->mArr["variable_monto_garantia_liquida"] = getFMoney($monto_garantia_liquida);
     $this->mArr["variable_tasa_mensual_de_interes_moratorio"] = $tasa_interes_mensual_moratorio . "";
     $this->mArr["variable_tasa_de_garantia_liquida"] = $tasa_garantia_liquida . "";
     $this->mArr["variable_plan_de_pagos"] = $splan_pagos;
     $this->mArr["variable_docto_fecha_larga_actual"] = $fecha_larga_de_documento;
     $this->mArr["variable_nombre_de_la_representante_social"] = $nombre_rep_social;
     $this->mArr["variable_listado_de_integrantes"] = $lista_asociadas;
     $this->mArr["variable_nombre_de_la_vocal_de_vigilancia"] = $nombre_voc_vigila;
     $this->mArr["variable_nombre_del_grupo_solidario"] = $nombre_del_grupo;
     $this->mArr["variable_domicilio_de_la_representante_social"] = $domicilio_rep_social;
     $this->mArr["variable_meses_de_duracion_del_credito"] = $meses_del_credito;
     $this->mArr["variable_en_letras_monto_ministrado"] = convertirletras($monto_ministrado);
     $this->mArr["variable_credito_fecha_de_ministracion"] = $xFDE->getFechaCorta($fecha_de_ministracion);
     $this->mArr["variable_tasa_cat"] = $tasa_de_cat;
     $this->mArr["variable_credito_periocidad"] = $DPeriocidad->getNombre();
     $this->mArr["variable_credito_monto_parcialidad_fija"] = getFMoney($cCred->getMontoDeParcialidad());
     $this->mArr["variable_credito_numero_de_pagos"] = $cCred->getPagosAutorizados();
     $this->mArr["variable_tasa_anual_de_interes_moratorio"] = $cCred->getTasaDeInteres() * 2 * 100 . "%";
     $this->mArr["variable_tasa_anual_de_interes_ordinario"] = $cCred->getTasaDeInteres() * 100 . "%";
     //sobreescribir datos de la empresa
     $xEmp = new cEmpresas($cCred->getClaveDeEmpresa());
     $xEmp->init();
     $this->mArr["variable_nombre_de_la_empresa"] = $xEmp->getNombre();
     $this->mArr["variable_nombre_de_empresa"] = $xEmp->getNombre();
     $this->mArr["variable_fecha_de_primer_pago"] = $xFDE->getFechaMediana($cCred->getFechaPrimeraParc());
     $this->mArr["variable_avales_en_fichas"] = $fichas_de_avales;
     $this->mArr["variable_firmas_de_avales"] = $firmas_de_avales;
     $this->mArr["variable_avales_autorizacion_central_riesgo"] = $this->mFichaRiesgoAv;
     $this->mArr["variable_fecha_ultimo_abono"] = $xFDE->getFechaLarga($cCred->getFechaUltimaParc());
     $this->mArr["variable_fecha_de_primer_abono"] = $xFDE->getFechaMediana($cCred->getFechaPrimeraParc());
     //$this->mArr["variable_fecha_de_primer_abono"]						=
     $this->mArr["variable_en_letras_tasa_mensual_de_interes_moratorio"] = convertirletras_porcentaje($tasa_interes_mensual_moratorio);
     $this->mArr["variable_lista_de_avales_con_domicilio"] = $this->mLAvalesConDir;
     /*variable_aval1_nombre_completo variable_aval1_domicilio_completo variable_aval1_domicilio_localidad variable_aval1_domicilio_municipio*/
     //Cargar Avales
     $this->mArr["variable_listado_de_garantias"] = $this->getListadoDeGarantias();
     //$this->mArr["variable_modalidad_de_credito"]					= $cCred->getOEstado()
     $this->mArr["variable_estado_de_credito"] = $cCred->getOEstado()->descripcion_estatus()->v(OUT_TXT);
     //$this->mArr["variable_credito_num_de_pago_actual"]				= $cCred->getPeriodoActual();
     $this->mArr["variable_contrato_id_legal"] = $DProd->getOtrosParametros($OOParam->CONTRATO_ID_LEGAL);
     $this->mArr["variable_producto_comision_apertura"] = $DProd->getOtrosParametros($OOParam->TASA_DE_COMISION_AP);
 }
function jsGetDescSolicitud($solicitud)
{
    if ($solicitud != 0 && $solicitud != "") {
        $xCred = new cCredito($solicitud);
        $xCred->init();
        $description = $xCred->getShortDescription();
    }
}
 function calcular($fecha_inicial = false, $PrimerPago = false, $SegundoPago = false, $TercerPago = false)
 {
     $xCred = new cCredito($this->mClaveDeCredito);
     $xCred->init();
     $xF = new cFecha();
     $msg = "";
     $FORMA_DE_PAGO = $xCred->getFormaDePago();
     $PAGOS_AUTORIZADOS = $xCred->getPagosAutorizados();
     $PERIOCIDAD_DE_PAGO = $xCred->getPeriocidadDePago();
     $MONTO_AUTORIZADO = $xCred->getMontoAutorizado();
     $SALDO_ACTUAL = $xCred->getSaldoActual();
     $INTERES_PAGADO = $xCred->getInteresNormalPagado();
     $MORA_PAGADO = $xCred->getInteresMoratorioPagado();
     $xCred->initPagosEfectuados();
     $CAPITAL_PAGADO = setNoMenorQueCero($MONTO_AUTORIZADO - $SALDO_ACTUAL);
     $SALDO_DE_PLAN = $xCred->getMontoAutorizado();
     $TASA_NORMAL = $xCred->getTasaDeInteres();
     $TASA_MORA = $xCred->getTasaDeMora();
     $TASA_IVA = $xCred->getTasaIVA();
     $DIVISOR_DE_INTS = EACP_DIAS_INTERES;
     $FECHA_DE_PAGO = $xCred->getFechaPrimeraParc();
     $FECHA_INICIAL = $xCred->getFechaDeMinistracion();
     $opciondia_1 = $PrimerPago;
     $opciondia_2 = $SegundoPago;
     $opciondia_3 = $TercerPago;
     //sanitiza la fecha de pago
     if ($FECHA_DE_PAGO == false) {
         $FECHA_DE_PAGO = $xF->setSumarDias($PERIOCIDAD_DE_PAGO, $FECHA_INICIAL);
     }
     if (($PERIOCIDAD_DE_PAGO > CREDITO_TIPO_PERIOCIDAD_CATORCENAL or $PERIOCIDAD_DE_PAGO == CREDITO_TIPO_PERIOCIDAD_CATORCENAL) and ($opciondia_1 == false or $opciondia_2 == false or $opciondia_3 == false)) {
         if ($PERIOCIDAD_DE_PAGO == CREDITO_TIPO_PERIOCIDAD_QUINCENAL) {
             $opciondia_1 = $opciondia_1 == false ? PQ_DIA_PRIMERA_QUINCENA : $opciondia_1;
             $opciondia_2 = $opciondia_2 == false ? PQ_DIA_SEGUNDA_QUINCENA : $opciondia_2;
         } elseif ($PERIOCIDAD_DE_PAGO == CREDITO_TIPO_PERIOCIDAD_DECENAL) {
             $opciondia_1 = $opciondia_1 == false ? 10 : $opciondia_1;
             $opciondia_2 = $opciondia_2 == false ? 20 : $opciondia_2;
             $opciondia_3 = $opciondia_3 == false ? 30 : $opciondia_3;
         } else {
             $opciondia_1 = $opciondia_1 == false ? PM_DIA_DE_PAGO : $opciondia_1;
         }
     }
     //pagos decenales entre el mes
     $arrPagos = array();
     //obtener los dias de pago en el mes por tipo de pago
     $dia_de_pago = $xCred->getFechaDeMinistracion();
     for ($i = 1; $i <= $PAGOS_AUTORIZADOS; $i++) {
         $letra = $i;
         switch ($PERIOCIDAD_DE_PAGO) {
             case CREDITO_TIPO_PERIOCIDAD_DIARIO:
                 $dia_de_pago = $xF->getDiaHabil($xF->setSumarDias(1, $dia_de_pago));
                 $arrPagos[$letra][SYS_FECHA] = $dia_de_pago;
                 $msg .= "OK\t{$letra}\tDIARIO\tFecha de pago a {$dia_de_pago}\r\n";
                 break;
             case CREDITO_TIPO_PERIOCIDAD_SEMANAL:
                 break;
             case CREDITO_TIPO_PERIOCIDAD_DECENAL:
                 break;
             case CREDITO_TIPO_PERIOCIDAD_CATORCENAL:
                 //dias naturales, cada dos semanas?
                 break;
             case CREDITO_TIPO_PERIOCIDAD_QUINCENAL:
                 $dia_de_pago = $xF->setSumarDias(CREDITO_TIPO_PERIOCIDAD_QUINCENAL, $dia_de_pago);
                 $dia_de_pago = $xF->getDiaAbonoQuincenal($opciondia_1, $opciondia_2, $dia_de_pago);
                 $arrPagos[$letra][SYS_FECHA] = $dia_de_pago;
                 $msg .= "OK\t{$letra}\tQUINCENAL\tFecha de pago a {$dia_de_pago}, opcion {$opciondia_1}, {$opciondia_2}\r\n";
                 break;
             case CREDITO_TIPO_PERIOCIDAD_MENSUAL:
                 $dia_de_pago = date("Y-m-", $xF->getInt($dia_de_pago)) . $opciondia_1;
                 $dia_de_pago = $xF->setSumarMeses(1, $dia_de_pago);
                 $dia_de_pago = $xF->getDiaHabil($dia_de_pago);
                 $arrPagos[$letra][SYS_FECHA] = $dia_de_pago;
                 $msg .= "OK\t{$letra}\tMENSUAL\tFecha de pago a {$dia_de_pago}, opcion {$opciondia_1}\r\n";
                 break;
             case CREDITO_TIPO_PERIOCIDAD_BIMESTRAL:
                 break;
             case CREDITO_TIPO_PERIOCIDAD_TRIMESTRAL:
                 break;
         }
     }
     //$FORMULA_INT			= new cFormula("interes_normal");
     //dias de pago
     //si es empresa, tomar la fecha de la empresa semanal, quincenal, mensual, decenal
     //Iniciar los Pagos Actuales
     //$this->initParcsPendientes();
     $DatosDePagados = $xCred->getListadoDePagos();
     /* interes capital impuestos */
     switch ($FORMA_DE_PAGO) {
         case CREDITO_TIPO_PAGO_PERIODICO:
             //parcialidad interes + capital
             break;
         case CREDITO_TIPO_PAGO_FLAT_PARCIAL:
             for ($i = 1; $i <= $PAGOS_AUTORIZADOS; $i++) {
                 $letra = $i;
                 $letraAnterior = setNoMenorQueCero($letra - 1);
                 $PagoAnterior = isset($DatosDePagados[$letra]) ? $DatosDePagados[$letra] : array();
                 $capital_pagado = isset($DPago[SYS_CAPITAL]) ? $DPago[SYS_CAPITAL] : 0;
                 $SALDO_DE_PLAN = $SALDO_DE_PLAN - $capital_pagado;
                 $interes_normal = $MONTO_AUTORIZADO * $PERIOCIDAD_DE_PAGO * $TASA_NORMAL / $DIVISOR_DE_INTS;
                 $capital = $MONTO_AUTORIZADO / $PAGOS_AUTORIZADOS;
                 $capital = setNoMenorQueCero($capital - $capital_pagado);
                 $interes_pagado = isset($DPago[SYS_INTERES_NORMAL]) ? $DPago[SYS_INTERES_NORMAL] : 0;
                 $interes_normal = setNoMenorQueCero($interes_normal - $interes_pagado);
                 $arrPagos[$letra][SYS_INTERES_NORMAL] = $interes_normal;
                 if ($letra == $PAGOS_AUTORIZADOS) {
                     if ($SALDO_DE_PLAN > 0) {
                         $arrPagos[$letra][SYS_CAPITAL] = $SALDO_DE_PLAN;
                         $msg .= "WARN\t{$letra}\tCapital a ultimo pago {$SALDO_DE_PLAN} \r\n";
                     }
                 }
                 //determinar proxima fecha de pago
                 $msg .= "OK\t{$letra}\tInteres Normal en {$interes_normal}, Pagado {$interes_pagado} \r\n";
             }
             break;
         case CREDITO_TIPO_PAGO_INTERES_PERIODICO:
             for ($i = 1; $i <= $PAGOS_AUTORIZADOS; $i++) {
                 $letra = $i;
                 $letraAnterior = setNoMenorQueCero($letra - 1);
                 $DAnterior = isset($DatosDePagados[$letraAnterior]) ? $DatosDePagados[$letraAnterior] : array();
                 $capital_pagado = isset($DAnterior[SYS_CAPITAL]) ? $DAnterior[SYS_CAPITAL] : 0;
                 $SALDO_DE_PLAN = $SALDO_DE_PLAN - $capital_pagado;
                 $DPago = isset($DatosDePagados[$letra]) ? $DatosDePagados[$letra] : array();
                 $interes_pagado = isset($DPago[SYS_INTERES_NORMAL]) ? $DPago[SYS_INTERES_NORMAL] : 0;
                 //datos del pago anterior
                 $DLetraAnterior = isset($arrPagos[$letraAnterior]) ? $arrPagos[$letraAnterior] : array();
                 $DLetra = isset($arrPagos[$letra]) ? $arrPagos[$letra] : array();
                 $FechaAnterior = isset($DLetraAnterior[SYS_FECHA]) ? $DLetraAnterior[SYS_FECHA] : $xCred->getFechaDeMinistracion();
                 $FechaActual = isset($DLetra[SYS_FECHA]) ? $DLetra[SYS_FECHA] : false;
                 $DIAS_TRANSCURRIDOS = $xF->setRestarFechas($FechaActual, $FechaAnterior);
                 //INTERES NORMAL
                 $interes_normal = $SALDO_DE_PLAN * $DIAS_TRANSCURRIDOS * $TASA_NORMAL / $DIVISOR_DE_INTS;
                 $interes_normal = setNoMenorQueCero($interes_normal - $interes_pagado);
                 $arrPagos[$letra][SYS_INTERES_NORMAL] = $interes_normal;
                 if ($capital_pagado > 0) {
                     $msg .= "WARN\t{$letra}\tCapital en pago {$letraAnterior} de {$capital_pagado} \r\n";
                 }
                 if ($letra == $PAGOS_AUTORIZADOS) {
                     if ($SALDO_DE_PLAN > 0) {
                         $arrPagos[$letra][SYS_CAPITAL] = $SALDO_DE_PLAN;
                         $msg .= "WARN\t{$letra}\tCapital a ultimo pago {$SALDO_DE_PLAN} \r\n";
                     }
                 }
                 $msg .= "OK\t{$letra}\tInteres Normal en {$interes_normal}, Pagado {$interes_pagado}, Dias {$DIAS_TRANSCURRIDOS},Fecha : Actual {$FechaActual} Anterior {$FechaAnterior}\r\n";
             }
             break;
         case CREDITO_TIPO_PAGO_INTERES_COMERCIAL:
             for ($i = 1; $i <= $PAGOS_AUTORIZADOS; $i++) {
                 $letra = $i;
                 $letraAnterior = setNoMenorQueCero($letra - 1);
                 $DAnterior = isset($DatosDePagados[$letraAnterior]) ? $DatosDePagados[$letraAnterior] : array();
                 $capital_pagado = isset($DAnterior[SYS_CAPITAL]) ? $DAnterior[SYS_CAPITAL] : 0;
                 $SALDO_DE_PLAN = $SALDO_DE_PLAN - $capital_pagado;
                 $DPago = isset($DatosDePagados[$letra]) ? $DatosDePagados[$letra] : array();
                 $interes_pagado = isset($DPago[SYS_INTERES_NORMAL]) ? $DPago[SYS_INTERES_NORMAL] : 0;
                 //INTERES NORMAL
                 $interes_normal = $SALDO_DE_PLAN * $PERIOCIDAD_DE_PAGO * $TASA_NORMAL / $DIVISOR_DE_INTS;
                 $interes_normal = setNoMenorQueCero($interes_normal - $interes_pagado);
                 $arrPagos[$letra][SYS_INTERES_NORMAL] = $interes_normal;
                 if ($capital_pagado > 0) {
                     $msg .= "WARN\t{$letra}\tCapital en pago {$letraAnterior} de {$capital_pagado} \r\n";
                 }
                 if ($letra == $PAGOS_AUTORIZADOS) {
                     if ($SALDO_DE_PLAN > 0) {
                         $arrPagos[$letra][SYS_CAPITAL] = $SALDO_DE_PLAN;
                         $msg .= "WARN\t{$letra}\tCapital a ultimo pago {$SALDO_DE_PLAN} \r\n";
                     }
                 }
                 $msg .= "OK\t{$letra}\tInteres Normal en {$interes_normal}, Pagado {$interes_pagado} \r\n";
             }
             break;
     }
     $NumeroPlan = $this->mNumeroDePlan;
     //$this->setEliminar();
     //eliminar plan de pagos
     foreach ($arrPagos as $periodo) {
     }
     $this->mMessages .= $msg;
     return $msg;
 }
function jsaGetControlDias($mod, $Msolicitud)
{
    $txt = "";
    if (isset($mod) and isset($Msolicitud)) {
        $mod = intval($mod);
        $periocidad = 15;
        $p_quincena = PQ_DIA_PRIMERA_QUINCENA;
        $s_quincena = PQ_DIA_SEGUNDA_QUINCENA;
        $xF = new cFecha();
        $xT = new cTipos();
        //---------------------------------------------------------
        $xCred = new cCredito($Msolicitud);
        $xCred->init();
        $periocidad = $xCred->getPeriocidadDePago();
        //cargar si es Nomina
        $xPlanGen = new cPlanDePagosGenerador();
        $xPlanGen->initPorCredito($Msolicitud);
        switch ($mod) {
            case CREDITO_TIPO_DIAS_DE_PAGO_PERSONALIZADOS:
                if ($periocidad == CREDITO_TIPO_PERIOCIDAD_QUINCENAL) {
                    $p_quincena = $xPlanGen->getDiaAbono1();
                    $s_quincena = $xPlanGen->getDiaAbono2();
                    $txt = "\n\t\t\t\t\t\t<th>Primer Dia de Abono en el Mes</th>\n\t\t\t\t\t\t<td><input type=\"text\" name=\"dia_primer_abono\" id=\"iddia_primer_abono\" size=\"3\" class=\"mny\" value=\"{$p_quincena}\" /></td>\n\n\t\t\t\t\t\t<th>Segundo Dia de Abono en el Mes</th>\n\t\t\t\t\t\t<td><input type=\"text\" name=\"dia_segundo_abono\" id=\"iddia_segundo_abono\" size=\"3\" class=\"mny\" value=\"{$s_quincena}\" /></td>\n\t\t\t\t\t\t";
                } elseif ($periocidad == CREDITO_TIPO_PERIOCIDAD_SEMANAL) {
                    $txt = "\n\t\t\t\t\t\t<td>Primer Dia de Abono</td>\n\t\t\t\t\t\t<td><select name=\"dia_primer_abono\" id=\"iddia_primer_abono\" >\n\t\t\t\t\t\t\t<option value=\"1\">Lunes</option>\n\t\t\t\t\t\t\t<option value=\"2\">Martes</option>\n\t\t\t\t\t\t\t<option value=\"3\">Miercoles</option>\n\t\t\t\t\t\t\t<option value=\"4\">Jueves</option>\n\t\t\t\t\t\t\t<option value=\"5\">Viernes</option>\n\t\t\t\t\t\t\t<option value=\"6\">Sabado</option>\n\t\t\t\t\t\t</select> </td>";
                } elseif ($periocidad == CREDITO_TIPO_PERIOCIDAD_DECENAL) {
                    $txt = "<td>Dias de Abono(Decenal)</td>\n\t\t\t\t\t\t<td><input type=\"text\" name=\"dia_primer_abono\" onblur=\"jsCambiarDiaPago(this)\" id=\"iddia_primer_abono\" value=\"10,20,30\" /></td>";
                } else {
                    $pago_mensual = PM_DIA_DE_PAGO;
                    $xF->set($xCred->getFechaDeMinistracion());
                    $pago_mensual = date("j", $xF->getInt());
                    $pago_mensual = $xPlanGen->getDiaAbono1();
                    $txt = "<td>Dia de Abono</td>\n\t\t\t\t\t\t<td><input type=\"number\" name=\"dia_primer_abono\" onblur=\"jsCambiarDiaPago(this)\" id=\"iddia_primer_abono\" value=\"" . $pago_mensual . "\" /></td>";
                }
                break;
        }
    }
    return $txt;
}
         $xCred = new cCredito();
         //Crear Contrato corriente si el producto tiene ahorro
         $DConv = $xCred->getDatosDeProducto($producto);
         $tasaAhorro = $cT->cFloat($DConv["tasa_ahorro"]);
         if ($ContratoCorriente == 0 and $tasaAhorro > 0) {
             $xCapta = new cCuentaALaVista(false);
             $ContratoCorriente = $xCapta->setNuevaCuenta(99, DEFAULT_SUBPRODUCTO_CAPTACION, $socio, "CUENTA POR IMPORTACION", $credito);
             $msg .= "{$iReg}\t{$socio}\t{$credito}\tAgregando una Cuenta Corriente {$ContratoCorriente} NUEVO\r\n";
         }
         //Agregar
         $ok = $xCred->add($producto, $socio, $ContratoCorriente, $monto, $periocidad, $pagos, 0, CREDITO_DEFAULT_DESTINO, $credito, DEFAULT_GRUPO, "", "CREDITO IMPORTADO #{$iReg}", DEFAULT_USER, $ministracion);
         if ($ok == true) {
             ///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++;
function jsaSetSaveRechazados($solicitud, $texto)
{
    $xCred = new cCredito($solicitud);
    $xCred->init();
    $xCred->setRazonRechazo($texto);
}