Imports System.Reflection Public Class frmPrestamoPersonal Dim Prestamo As New PrestamoPersonalCE Dim PrestamoConsulta As New PrestamoPersonalDAO Dim EstadoAccion As String = "Nada" Dim IndexIterable As Boolean = True Dim Operaciones As New Operaciones Dim FinCarga As Boolean = False Dim FechaCorte As Date Dim IndexCorte As Integer = 0 Private Sub frmPrestamoPersonal_Load(sender As Object, e As EventArgs) Handles MyBase.Load dgvAmortizacion.Columns.Clear() AgregarCampos() CargarColecciones() CargarAmortizacion() FinCarga = True Formato() Calculos(False) ExisteInversion() ValidarExistencia() End Sub Function ExisteInversion() Dim Codigo As String = Variables.Codigo Dim TablaINV As String = "INV0" Dim TablaPINV As String = "PIN0" Dim General As New DAOGeneral Dim InvPro = Variables.InvPro If InvPro = "I" Then Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV) If INV0 Then navNuevo.Visible = True Return True Else navNuevo.Visible = False Return False End If End If If InvPro = "P" Then Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV) If PINV0 Then navNuevo.Visible = True Return True Else navNuevo.Visible = False Return False End If End If Return False End Function Private Sub LLenarCuotaSinSeguro() Dim MontoPrestamo As Double = 0 Dim CuotasMensuales As Double = 0 Dim TasaInteres As Double = 0 MontoPrestamo = Operaciones.ConvertirDecimal(txtMontoPrestamo.Text.ToString) CuotasMensuales = Operaciones.ConvertirDecimal(txtCuotasMensuales.Text.ToString) TasaInteres = Operaciones.ConvertirDecimal(txtTasaInteres.Text.ToString) txtCuotaSinSeguro.Text = Operaciones.ConvertirDecimal(Prestamo.TIR(MontoPrestamo, CuotasMensuales, TasaInteres / 100).ToString) End Sub Private Sub txtTasaInteres_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasaInteres.KeyUp If txtTasaInteres.Text = "." Then txtTasaInteres.Text = ".0" End If LLenarCuotaSinSeguro() End Sub Private Sub txtMontoPrestamo_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMontoPrestamo.KeyUp If txtMontoPrestamo.Text = "." Then txtMontoPrestamo.Text = ".0" End If LLenarCuotaSinSeguro() End Sub Private Sub txtCuotasMensuales_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCuotasMensuales.KeyUp If txtCuotasMensuales.Text = "." Then txtCuotasMensuales.Text = ".0" End If LLenarCuotaSinSeguro() End Sub Private Sub txtSeguro_KeyUp(sender As Object, e As KeyEventArgs) Handles txtSeguro.KeyUp If txtSeguro.Text = "." Then txtSeguro.Text = ".0" End If Dim CuotaSinSeguro As Double = 0 Dim Seguro As Double = 0 CuotaSinSeguro = Operaciones.ConvertirDecimal(txtCuotaSinSeguro.Text.ToString) Seguro = Operaciones.ConvertirDecimal(txtSeguro.Text.ToString) txtCuotaReal.Text = Prestamo.SumarCuota(CuotaSinSeguro, Seguro) End Sub Sub AgregarCampos() Dim Numero, Periodo, Fecha, FechaCorte, SaldoInicial, PagoCuota, PagoInteresIVA, IVA, PagoInteres, Abono, PrestamoRem, PagoSeguroDaños, PagoSeguroVivienda, TotalCuota, TotalPagado, AbonoExtra As New DataGridViewTextBoxColumn Numero.Name = "No. Cuota" Fecha.Name = "Fecha" FechaCorte.Name = "Fecha de Corte" Periodo.Name = "Periodo" SaldoInicial.Name = "Saldo Inicial" PagoCuota.Name = "Pago Cuota Mensual" PagoInteresIVA.Name = "Pago Interes(IVA)" IVA.Name = "IVA de Intereses" PagoInteres.Name = "Pago de Intereses" Abono.Name = "Abono a Capital" PrestamoRem.Name = "Prestamo Remanente" PagoSeguroDaños.Name = "Pago de Seguro de Daños" PagoSeguroVivienda.Name = "Pago de Seguro de Vivienda" TotalCuota.Name = "Total Cuota Mensual" TotalPagado.Name = "Total Pagado" AbonoExtra.Name = "Abono Extra a Capital" dgvAmortizacion.Columns.Add(Numero) dgvAmortizacion.Columns.Add(FechaCorte) dgvAmortizacion.Columns.Add(Fecha) dgvAmortizacion.Columns.Add(Periodo) dgvAmortizacion.Columns.Add(SaldoInicial) dgvAmortizacion.Columns.Add(PagoCuota) dgvAmortizacion.Columns.Add(PagoInteresIVA) dgvAmortizacion.Columns.Add(IVA) dgvAmortizacion.Columns.Add(PagoInteres) dgvAmortizacion.Columns.Add(Abono) dgvAmortizacion.Columns.Add(PrestamoRem) dgvAmortizacion.Columns.Add(PagoSeguroDaños) dgvAmortizacion.Columns.Add(PagoSeguroVivienda) dgvAmortizacion.Columns.Add(TotalCuota) dgvAmortizacion.Columns.Add(TotalPagado) dgvAmortizacion.Columns.Add(AbonoExtra) End Sub Sub CargarDatos() Dim Index As Integer = dgvAmortizacion.CurrentRow.Index Dim Anterior As Integer = Index - 1 Dim Cantidad As Integer = dgvAmortizacion.Rows.Count Dim Fecha = Date.Today.Date Dim strFecha = Format(Fecha, "dd/MM/yyyy") If (String.IsNullOrEmpty(dgvAmortizacion.Rows(Index).Cells("Fecha").Value)) Then dgvAmortizacion.Rows(Index).Cells("Fecha").Value = strFecha End If End Sub Sub Formato() If (String.IsNullOrEmpty(txtCuotasMensuales.Text.ToString)) Then txtCuotasMensuales.Text = "0.0" End If If (String.IsNullOrEmpty(txtTasaInteres.Text.ToString)) Then txtTasaInteres.Text = "0.0" End If If (String.IsNullOrEmpty(txtAñoPrestamo.Text.ToString)) Then txtAñoPrestamo.Text = 0 End If If (String.IsNullOrEmpty(txtCuotasMensuales.Text.ToString)) Then txtCuotasMensuales.Text = "0.0" End If If (String.IsNullOrEmpty(txtMontoPrestamo.Text.ToString)) Then txtMontoPrestamo.Text = "0.0" End If If (String.IsNullOrEmpty(txtPeriodo.Text.ToString)) Then txtPeriodo.Text = 0 End If If (String.IsNullOrEmpty(txtCuotaSinSeguro.Text.ToString)) Then txtCuotaSinSeguro.Text = Format(txtCuotaSinSeguro.Text, "0.0") If Double.IsInfinity(txtCuotaSinSeguro.Text) Then txtCuotaSinSeguro.Text = Format(txtCuotaSinSeguro.Text, "0.0") End If End If If (String.IsNullOrEmpty(txtSeguro.Text.ToString) Or txtSeguro.Text.ToString = "0") Then txtSeguro.Text = Format(txtSeguro.Text, "0.0") End If If (String.IsNullOrEmpty(txtCuotaReal.Text.ToString) Or txtCuotaReal.Text.ToString = "0") Then txtCuotaReal.Text = "0.0" End If If (txtTasaInteres.Text.ToString.IndexOf("%") = -1) Then txtTasaInteres.Text = txtTasaInteres.Text.ToString + "%" End If End Sub Sub Calculos(ByVal Corte As Boolean) If (FinCarga) Then Dim FechaInicial As Date = dtpFechaOtorgamiento.Value Dim FechaFinal As Date = dtpFechaOtorgamiento.Value Dim FechaVencimiento As Date = dtpFechaOtorgamiento.Value Dim FechaVen As Date = dtpFechaPago.Value Dim FechaAux As Date = dtpFechaOtorgamiento.Value Dim Index = 0 Dim Contador As Integer = 1 Dim BaseContador As Double = Operaciones.ConvertirDecimal(txtCuotasMensuales.Text.ToString) Dim V_txtTasaInteres As Double = 0.0 If (String.IsNullOrEmpty(txtTasaInteres.Text.Trim("%"))) Then V_txtTasaInteres = 0 Else V_txtTasaInteres = txtTasaInteres.Text.TrimEnd("%") / 100 End If LLenarCuotaSinSeguro() Dim Cantidad As Integer = dgvAmortizacion.Rows.Count Dim TipoCalculo As Integer = 0 If (FechaInicial.Day = 31) Then TipoCalculo = 1 ElseIf (FechaInicial.Day = 30) Then TipoCalculo = 2 ElseIf (FechaInicial.Day = 29) Then TipoCalculo = 3 Else TipoCalculo = 4 End If Dim Salir As Boolean = False Dim TotalCuotas As Double = 0 TotalCuotas = Operaciones.ConvertirDecimal(txtCuotasMensuales.Text.ToString) Dim FechaAnterior As Date = FechaInicial Dim FechaPrimera = FechaInicial, FechaUltima = FechaInicial Dim AumentarDia As Boolean = False Dim DisminuirDia30 As Integer = True While (True) Dim Eliminar As Integer = dgvAmortizacion.Rows.Count - 2 Dim CuotasMensuales As Integer = 0 CuotasMensuales = Operaciones.ConvertirDecimal(txtCuotasMensuales.Text.ToString) If Eliminar > CuotasMensuales Then While True If Eliminar >= CuotasMensuales Then dgvAmortizacion.Rows.Remove(dgvAmortizacion.Rows(Eliminar)) Eliminar -= 1 Else Exit While End If End While End If Dim ContadorMes As Integer = 0 Dim Dia As Integer = 0 Dia = FechaInicial.Day FechaPrimera = FechaInicial If (TipoCalculo = 1) Then FechaAnterior = FechaInicial If (Operaciones.AñoBisiesto(FechaAnterior) = 365) Then If FechaInicial.Month = 1 Then FechaUltima = FechaInicial.AddDays(29) FechaInicial = FechaInicial.AddDays(29) ElseIf (FechaInicial.Month = 12 Or FechaInicial.Month = 2 Or FechaInicial.Month = 4 Or FechaInicial.Month = 6 Or FechaInicial.Month = 7 Or FechaInicial.Month = 9 Or FechaInicial.Month = 11) Then FechaUltima = FechaInicial.AddDays(31) FechaInicial = FechaInicial.AddDays(31) Else FechaUltima = FechaInicial.AddDays(30) FechaInicial = FechaInicial.AddDays(30) End If Else If FechaInicial.Month = 1 Then FechaUltima = FechaInicial.AddDays(28) FechaInicial = FechaInicial.AddDays(28) ElseIf (FechaInicial.Month = 12 Or FechaInicial.Month = 2 Or FechaInicial.Month = 4 Or FechaInicial.Month = 6 Or FechaInicial.Month = 7 Or FechaInicial.Month = 9 Or FechaInicial.Month = 11) Then FechaUltima = FechaInicial.AddDays(31) FechaInicial = FechaInicial.AddDays(31) Else FechaUltima = FechaInicial.AddDays(30) FechaInicial = FechaInicial.AddDays(30) End If End If End If If (TipoCalculo = 3 Or TipoCalculo = 2) Then 'Fecha Anterior toma el valor de la primera fecha y fecha ultima, como la ultima If (FechaInicial.Month = 2) Then FechaAnterior = FechaInicial If (Operaciones.AñoBisiesto(FechaAnterior) = 365) Then If (TipoCalculo = 2) Then If FechaInicial.Month = 1 Then FechaUltima = FechaInicial.AddDays(29) FechaInicial = FechaInicial.AddDays(29) Else FechaUltima = FechaInicial.AddMonths(1) FechaInicial = FechaInicial.AddMonths(1) End If If (TipoCalculo = 2) Then DisminuirDia30 = 1 End If Else If FechaInicial.Month = 1 Then FechaUltima = FechaInicial.AddDays(29) FechaInicial = FechaInicial.AddDays(29) Else FechaUltima = FechaInicial.AddMonths(1) FechaInicial = FechaInicial.AddMonths(1) End If If (TipoCalculo = 1) Then DisminuirDia30 = 1 End If End If Else If (TipoCalculo = 2) Then If FechaInicial.Month = 1 Then FechaUltima = FechaInicial.AddDays(29) FechaInicial = FechaInicial.AddDays(29) Else FechaUltima = FechaInicial.AddMonths(1) FechaInicial = FechaInicial.AddMonths(1) End If If (TipoCalculo = 2) Then DisminuirDia30 = 1 AumentarDia = True End If Else FechaUltima = FechaInicial.AddDays(29) FechaInicial = FechaInicial.AddDays(29) If (TipoCalculo = 1) Then DisminuirDia30 = 2 ElseIf (TipoCalculo = 2) Then AumentarDia = True End If End If End If Else If (AumentarDia) Then FechaInicial = FechaInicial.AddDays(1) FechaPrimera = FechaInicial AumentarDia = False End If If (DisminuirDia30 = 1) Then FechaInicial = FechaInicial.AddDays(1) FechaPrimera = FechaInicial DisminuirDia30 = False ElseIf (DisminuirDia30 = 2) Then FechaInicial = FechaInicial.AddDays(2) FechaPrimera = FechaInicial DisminuirDia30 = False End If FechaAnterior = FechaInicial FechaUltima = FechaInicial.AddMonths(1) FechaInicial = FechaInicial.AddMonths(1) End If End If If (TipoCalculo = 4) Then FechaAnterior = FechaInicial FechaUltima = FechaInicial.AddMonths(1) FechaInicial = FechaInicial.AddMonths(1) End If If (Corte) Then If (Index >= IndexCorte) Then While Not FechaUltima.Date <= FechaCorte.Date FechaUltima = FechaUltima.AddDays(-1) End While Salir = True End If Else If (Contador >= TotalCuotas) Then Salir = True End If End If Dim PeriodoDias As Integer = 0 Dim PagoDeCuotaMensual As Double = 0 Dim PagoIni As Double = 0 Dim PagoIVA As Double = 0 Dim PagoInt As Double = 0 Dim IVAInteres As Double = 0 Dim SegDaños As Double = 0 Dim SegVivienda As Double = 0 Dim TotalPagado As Double = 0 Dim AbonoDinero As Double = 0 Dim PrestRemanente As Double = 0 Dim Agregar As Integer = dgvAmortizacion.Rows.Count - 2 Dim FechaProv As Date = Date.Now.Date Dim CambioFecha As Boolean = False If Agregar >= Index Then If Not (dgvAmortizacion.Rows(Index).Cells("Fecha de Corte").Value) Is DBNull.Value Then If Not String.IsNullOrEmpty(dgvAmortizacion.Rows(Index).Cells("Fecha de Corte").Value) Then FechaProv = FechaUltima FechaUltima = dgvAmortizacion.Rows(Index).Cells("Fecha de Corte").Value CambioFecha = True End If End If End If If Index = 0 Then If CkbPrueba.Checked Then FechaAnterior = dtpFechaPago.Value Dim FechaResp As Date = FechaAnterior Dim Meses As Integer = FechaResp.Month While Meses = FechaResp.Month FechaResp = FechaResp.AddDays(1) End While FechaUltima = FechaResp.AddDays(-1) End If End If PeriodoDias = Periodo(Index, FechaAnterior, FechaUltima) If Double.IsInfinity(PeriodoDias) Then PeriodoDias = 0 End If PagoDeCuotaMensual = PagoCuotaMensual(Index, PeriodoDias, V_txtTasaInteres) If Double.IsInfinity(PagoDeCuotaMensual) Or Double.IsNaN(PagoDeCuotaMensual) Then PagoDeCuotaMensual = 0 End If PagoIni = PagoInicial(Index) If Double.IsInfinity(PagoIni) Then PagoIni = 0 End If PagoIVA = PagoInteresIVA(Index, PagoIni, PeriodoDias, FechaAnterior, FechaUltima, Contador, V_txtTasaInteres) If Double.IsInfinity(PagoIVA) Then PagoIVA = 0 End If PagoInt = PagoIntereses(Index, PagoIVA) If Double.IsInfinity(PagoInt) Then PagoInt = 0 End If IVAInteres = IVAIntereses(Index, PagoIVA, PagoInt) If Double.IsInfinity(IVAInteres) Then IVAInteres = 0 End If SegDaños = SeguroDaños(Index) If Double.IsInfinity(SegDaños) Then SegDaños = 0 End If SegVivienda = SeguroVivienda(Index) If Double.IsInfinity(SegVivienda) Then SegVivienda = 0 End If TotalPagado = TotalCuota(Index, SegDaños, SegVivienda, PagoDeCuotaMensual) If Double.IsInfinity(TotalPagado) Then TotalPagado = 0 End If AbonoDinero = Abono(Index, TotalPagado, PagoIVA) If Double.IsInfinity(AbonoDinero) Then AbonoDinero = 0 End If PrestRemanente = PrestamoRemanente(Index, AbonoDinero) If Double.IsInfinity(PrestRemanente) Then PrestRemanente = 0 End If Dim CuotaSeguro As Double = 0 Dim Seguro As Double = 0 If Not String.IsNullOrEmpty(txtCuotaSinSeguro.Text) Then CuotaSeguro = txtCuotaSinSeguro.Text End If If Not String.IsNullOrEmpty(txtSeguro.Text) Then Seguro = txtSeguro.Text End If txtCuotaReal.Text = Prestamo.SumarCuota(CuotaSeguro, Seguro) If Double.IsInfinity(txtCuotaReal.Text) Then txtCuotaReal.Text = 0 End If If Agregar >= Index Then If CambioFecha Then FechaUltima = FechaProv CambioFecha = False End If End If Dim FechaCalculo As Date = FechaUltima Dim FechaRespaldo As Date = FechaUltima Dim Mes = FechaCalculo.Month While Mes = FechaCalculo.Month FechaCalculo = FechaCalculo.AddDays(1) End While FechaUltima = FechaCalculo.AddDays(-1) If Cantidad > 1 Then If Agregar >= Index Then dgvAmortizacion.Rows(Index).Cells("Fecha").Value = Operaciones.ConvertirFecha(FechaUltima.ToString) dgvAmortizacion.Rows(Index).Cells("Periodo").Value = Operaciones.ConvertirEntero(PeriodoDias.ToString) dgvAmortizacion.Rows(Index).Cells("Saldo Inicial").Value = Operaciones.ConvertirDecimal(PagoIni.ToString) dgvAmortizacion.Rows(Index).Cells("Pago Cuota Mensual").Value = Operaciones.ConvertirDecimal(PagoDeCuotaMensual.ToString) dgvAmortizacion.Rows(Index).Cells("Pago Interes(IVA)").Value = Operaciones.ConvertirDecimal(PagoIVA.ToString) dgvAmortizacion.Rows(Index).Cells("IVA de Intereses").Value = Operaciones.ConvertirDecimal(IVAInteres.ToString) dgvAmortizacion.Rows(Index).Cells("Pago de Intereses").Value = Operaciones.ConvertirDecimal(PagoInt.ToString) dgvAmortizacion.Rows(Index).Cells("Abono a Capital").Value = Operaciones.ConvertirDecimal(AbonoDinero.ToString) dgvAmortizacion.Rows(Index).Cells("Prestamo Remanente").Value = Operaciones.ConvertirDecimal(PrestRemanente.ToString) dgvAmortizacion.Rows(Index).Cells("Pago de Seguro de Daños").Value = Operaciones.ConvertirDecimal(SegDaños.ToString) dgvAmortizacion.Rows(Index).Cells("Pago de Seguro de Vivienda").Value = Operaciones.ConvertirDecimal(SegVivienda.ToString) dgvAmortizacion.Rows(Index).Cells("Total Pagado").Value = Operaciones.ConvertirDecimal(TotalPagado.ToString) dgvAmortizacion.Rows(Index).Cells("Total Cuota Mensual").Value = Operaciones.ConvertirDecimal(TotalPagado.ToString) Else dgvAmortizacion.Rows.Add(Contador, "", FechaUltima, PeriodoDias, PagoIni, PagoDeCuotaMensual, PagoIVA, IVAInteres, PagoInt, AbonoDinero, PrestRemanente, SegDaños, SegVivienda, TotalPagado, TotalPagado, 0) End If Else dgvAmortizacion.Rows.Add(Contador, "", FechaUltima, PeriodoDias, PagoIni, PagoDeCuotaMensual, PagoIVA, IVAInteres, PagoInt, AbonoDinero, PrestRemanente, SegDaños, SegVivienda, TotalPagado, TotalPagado, 0) End If FechaUltima = FechaRespaldo Contador += 1 If (Salir) Then Exit While End If Index += 1 End While End If End Sub Function Periodo(ByVal Index As Integer, ByVal Fech As Date, ByVal Fecha2 As Date) Dim Valor As Integer = 0 Valor = Prestamo.Periodo(Fech, Fecha2) Return Valor End Function Function PagoCuotaMensual(ByVal Index As Integer, ByVal Dias As Integer, ByVal V_txtTasaInteres As Double) Dim MontoPrestamo As Double = 0 Dim CuotasMensuales As Integer = 0 MontoPrestamo = Operaciones.ConvertirDecimal(txtMontoPrestamo.Text.ToString) CuotasMensuales = Operaciones.ConvertirEntero(txtCuotasMensuales.Text.ToString) Dim Pago As Double = Prestamo.TIR(MontoPrestamo, CuotasMensuales, V_txtTasaInteres) Dim Total As Double = 0 If (Index = 0) Then Total = Pago / 31 * Dias ElseIf (Index > 0) Then Total = Pago End If Return Total End Function Function SeguroDaños(ByVal Index As Integer) Dim Total As Double = 0 If (Index = 0) Then Total = 0 ElseIf (Index > 0) Then Index = Index - 1 Total = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago de Seguro de Daños").Value) End If Return Total End Function Function SeguroVivienda(ByVal Index As Integer) Dim Total As Double = 0 If (Index = 0) Then Total = 0 ElseIf (Index > 0) Then Index = Index - 1 Total = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago de Seguro de Vivienda").Value) End If Return Total End Function Function TotalCuota(ByVal Index As Integer, ByVal PagoSeguroDaño As Double, ByVal PagoSeguroVivienda As Double, ByVal PagoCuota As Double) Dim Total = PagoSeguroDaño + PagoSeguroVivienda + PagoCuota Return Total End Function Function PagoInicial(ByVal Index As Integer) Dim Total As Double = 0 Dim Anterior As Integer = Index - 1 If (Index = 0) Then Total = Operaciones.ConvertirDecimal(txtMontoPrestamo.Text.ToString) ElseIf (Index > 0) Then Total = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Anterior).Cells("Prestamo Remanente").Value) End If Return Total End Function Function PagoInteresIVA(ByVal Index As Integer, ByVal SaldoInicial As Double, ByVal Periodo As Integer, ByVal Fechainicial As Date, ByVal FechaFinal As Date, ByVal Contador As Integer, ByVal V_txtTasaInteres As Double) Fechainicial = Format(Fechainicial, "yyyy/MM/dd") FechaFinal = Format(FechaFinal, "yyyy/MM/dd") Dim CambioDeFecha As Integer = Operaciones.CambioBase(Fechainicial, FechaFinal) Dim TasaInteres As Double = 0 TasaInteres = V_txtTasaInteres Dim PrimeraFechaUltima = Operaciones.PrimeraFechaCambioBase(Fechainicial) Dim UltimaFechaPrimero = Operaciones.FinalFechaCambioBase(FechaFinal) Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0 Dim Valor1 = 0.0, Valor2 = 0.0, Valor = 0.0 If (Not CambioDeFecha = 0) Then If CambioDeFecha = 1 Then DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(Fechainicial, PrimeraFechaUltima, CambioDeFecha) DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha) Valor1 = SaldoInicial * TasaInteres * DiasPrimeraFecha / 366 Valor2 = SaldoInicial * TasaInteres * DiasSegundaFecha / 365 ElseIf CambioDeFecha = 2 Then DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(Fechainicial, PrimeraFechaUltima, CambioDeFecha) DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha) Valor1 = SaldoInicial * TasaInteres * DiasPrimeraFecha / 365 Valor2 = SaldoInicial * TasaInteres * DiasSegundaFecha / 366 End If Valor = Valor1 + Valor2 Else If (Operaciones.AñoBisiesto(Fechainicial) = 364) Then Valor = SaldoInicial * TasaInteres * Periodo / 365 End If If (Operaciones.AñoBisiesto(Fechainicial) = 365) Then Valor = SaldoInicial * TasaInteres * Periodo / 366 End If End If Return Valor End Function Function PagoIntereses(ByVal Index As Integer, ByVal PagoIVA As Double) Dim Total As Double = PagoIVA / 1.13 Return Total End Function Function IVAIntereses(ByVal Index As Integer, ByVal PagoIVA As Double, ByVal PagoIVAInt As Double) Dim Total As Double = 0 Total = PagoIVA - PagoIVAInt Return Total End Function Function Abono(ByVal Index As Integer, ByVal TotalPagado As Double, ByVal PagoInteres As Double) Dim Total As Double = 0 Total = TotalPagado - PagoInteres Return Total End Function Function PrestamoRemanente(ByVal Index As Integer, ByVal Abono As Double) Dim Total As Double = 0 Dim Monto As Double = 0 Monto = Operaciones.ConvertirDecimal(txtMontoPrestamo.Text.ToString) Dim Anterior As Integer = Index - 1 Try If (Index = 0) Then Total = Monto - Abono ElseIf (Index > 0) Then Dim AnteriorValor = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Anterior).Cells("Prestamo Remanente").Value) Total = AnteriorValor - Abono End If Catch ex As Exception Total = 0 End Try Return Total End Function Private Sub dgvAmortizacion_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAmortizacion.CellContentClick CargarDatos() End Sub Private Sub dgvAmortizacion_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAmortizacion.CellEndEdit CargarDatos() Calculos(False) End Sub Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click EstadoAccion = "M" btnAccion.Text = "Modificar" End Sub Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click EstadoAccion = "N" btnAccion.Text = "Nuevo" End Sub Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click EstadoAccion = "B" btnAccion.Text = "Eliminar" End Sub Sub CargarColecciones() CargarDeudor() CargarDetalles() End Sub Sub CargarDeudor() Dim codigo As String = Variables.Codigo Dim Retorno = PrestamoConsulta.CargarDeudor(codigo) Dim coleccion As New Collection If (TypeOf Retorno Is Boolean) Then Exit Sub Else coleccion = PrestamoConsulta.CargarDeudor(codigo) End If txtNombreDeudor.Text = coleccion(1).ToString txtNumeroDeudor.Text = coleccion(2).ToString dtpFechaPago.Value = Operaciones.ConvertirFecha(coleccion(3).ToString) dtpFechaOtorgamiento.Value = Operaciones.ConvertirFecha(coleccion(4).ToString) txtPeriodo.Text = Operaciones.ConvertirDecimal(coleccion(5).ToString) End Sub Sub CargarDetalles() Dim codigo As String = Variables.Codigo Dim Retorno = PrestamoConsulta.CargarDetalles(codigo) Dim coleccion As New Collection If (TypeOf Retorno Is Boolean) Then Exit Sub Else coleccion = PrestamoConsulta.CargarDetalles(codigo) End If txtTasaInteres.Text = Operaciones.ConvertirDecimal(coleccion(1).ToString) * 100 txtAñoPrestamo.Text = Operaciones.ConvertirEntero(coleccion(2).ToString) txtCuotasMensuales.Text = Operaciones.ConvertirEntero(coleccion(3).ToString) txtMontoPrestamo.Text = Operaciones.ConvertirDecimal(coleccion(4).ToString) txtSeguro.Text = Operaciones.ConvertirDecimal(coleccion(5).ToString) End Sub Sub CargarAmortizacion() Dim codigo As String = Variables.Codigo Dim dr = PrestamoConsulta.CargarAmortizacion(codigo) Dim Iterador As Integer = 0 Dim ConvertirString As String While dr.Read ConvertirString = Format(Operaciones.ConvertirFecha(dr("fecha").ToString), "dd/MM/yyyy") dgvAmortizacion.Rows.Add(dr("correlativo"), dr("fechacorte").ToString, ConvertirString, dr("periodo"), dr("saldoinicial"), dr("pagocuota"), dr("pagointeresIVA"), dr("IVAinteres"), dr("pagointeres"), dr("abono"), dr("prestamoremanente"), dr("pagodanos"), dr("pagovivienta"), dr("totalcuota"), dr("totalpagado"), dr("abonoextra")) End While End Sub Function ValidarDatos() Dim Continuar = True If (String.IsNullOrEmpty(txtNombreDeudor.Text)) Then Continuar = False MsgBox("Agregue un Nombre") End If If (String.IsNullOrEmpty(txtNumeroDeudor.Text)) Then MsgBox("Agregue un Numero") Continuar = False End If Return Continuar End Function Private Sub btnAccion_Click(sender As Object, e As EventArgs) Handles btnAccion.Click Dim codigo As String = Variables.Codigo Dim colecciondetalle = ColeccionDetalles() Dim colecciondeuda = ColeccionDeudor() Dim diccionarioAmort As Dictionary(Of String, Collection) = NuevoAmortDiccionario() If (EstadoAccion = "B") Then PrestamoConsulta.Eliminar(codigo) ValidarExistencia() End If If (EstadoAccion = "M") Then Dim Validar = ValidarDatos() If (Validar) Then PrestamoConsulta.ProcesoDatos(colecciondeuda, colecciondetalle, codigo, diccionarioAmort, "Modificar", "Modificar") ValidarExistencia() End If End If If (EstadoAccion = "N") Then Dim Validar = ValidarDatos() If (Validar) Then PrestamoConsulta.ProcesoDatos(colecciondeuda, colecciondetalle, codigo, diccionarioAmort, "Nuevo", "Nuevo") ValidarExistencia() End If ElseIf Not ExisteValidacion() Then Variables.ColeccionPPERDETALLE = colecciondetalle Variables.ColeccionPPERDEUDOR = colecciondeuda Variables.ColeccionPPERAMORTDi = diccionarioAmort Me.Close() End If End Sub Sub ValidarExistencia() Dim General As New DAOGeneral Dim Codigo As String = Variables.Codigo Dim Tabla As String = String.Empty Tabla = "PPER0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) If (Existe) Then navNuevo.Enabled = False navModificar.Enabled = True navEliminar.Enabled = True Else navNuevo.Enabled = True navModificar.Enabled = False navEliminar.Enabled = False End If EstadoAccion = String.Empty btnAccion.Text = "Aceptar" End Sub Function ExisteValidacion() Dim General As New DAOGeneral Dim Codigo As String = Variables.Codigo Dim Tabla As String = String.Empty Tabla = "PPER0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) Return Existe End Function Function ColeccionDeudor() Dim coleccion As New Collection Dim NombreDeudor As String = txtNombreDeudor.Text.ToString Dim NumeroDeudor As String = txtNumeroDeudor.Text.ToString Dim fechaotor As Date = dtpFechaOtorgamiento.Value Dim fechapago As Date = dtpFechaPago.Value Dim periodogracias As Double = Operaciones.ConvertirDecimal(txtPeriodo.Text.ToString) coleccion.Add(NombreDeudor) coleccion.Add(NumeroDeudor) coleccion.Add(fechapago) coleccion.Add(fechaotor) coleccion.Add(periodogracias) Return coleccion End Function Function ColeccionDetalles() Dim coleccion As New Collection Dim tasainteres = Operaciones.ConvertirDecimal(txtTasaInteres.Text.ToString) / 100 Dim duracionprestamo = Operaciones.ConvertirEntero(txtAñoPrestamo.Text.ToString) Dim totalcuotas = Operaciones.ConvertirEntero(txtCuotasMensuales.Text.ToString) Dim montoprestamo = Operaciones.ConvertirDecimal(txtMontoPrestamo.Text.ToString) Dim seguro = Operaciones.ConvertirDecimal(txtSeguro.Text.ToString) Dim CuotaSinSeguro = Operaciones.ConvertirDecimal(txtCuotaSinSeguro.Text.ToString) Dim CuotaReal = Operaciones.ConvertirDecimal(txtCuotaReal.Text.ToString) coleccion.Add(tasainteres) coleccion.Add(duracionprestamo) coleccion.Add(totalcuotas) coleccion.Add(montoprestamo) coleccion.Add(seguro) coleccion.Add(CuotaSinSeguro) coleccion.Add(CuotaReal) Return coleccion End Function Function coleccionAmortizacion(ByVal Index As Integer) Dim coleccion As New Collection Dim Posicion As Integer = Operaciones.ConvertirEntero(dgvAmortizacion.Rows(Index).Cells("No. Cuota").Value) Dim fecha As Date = Operaciones.ConvertirFecha(dgvAmortizacion.Rows(Index).Cells("Fecha").Value) Dim fechaCorte = dgvAmortizacion.Rows(Index).Cells("Fecha de Corte").Value Dim Periodo As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Periodo").Value) Dim saldoinicial As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Saldo Inicial").Value) Dim pagocuota As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago Cuota Mensual").Value) Dim PagoInteresIVA As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago Interes(IVA)").Value) Dim IVAinteres As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("IVA de Intereses").Value) Dim pagointeres As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago de Intereses").Value) Dim Abono As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Abono a Capital").Value) Dim PrestamoRemanente As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Prestamo Remanente").Value) Dim pagodanos As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago de Seguro de Daños").Value) Dim pagovivienta As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Pago de Seguro de Vivienda").Value) Dim TotalCuota As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Total Cuota Mensual").Value) Dim totalpagado As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Total Pagado").Value) Dim abonoextra As Double = Operaciones.ConvertirDecimal(dgvAmortizacion.Rows(Index).Cells("Abono Extra a Capital").Value) coleccion.Add(Posicion) coleccion.Add(fecha) coleccion.Add(Periodo) coleccion.Add(saldoinicial) coleccion.Add(pagocuota) coleccion.Add(PagoInteresIVA) coleccion.Add(IVAinteres) coleccion.Add(pagointeres) coleccion.Add(Abono) coleccion.Add(PrestamoRemanente) coleccion.Add(pagodanos) coleccion.Add(pagovivienta) coleccion.Add(TotalCuota) coleccion.Add(totalpagado) coleccion.Add(abonoextra) coleccion.Add(fechaCorte) Return coleccion End Function Sub NuevoAmort(ByVal codigo As String) Dim Index As Integer = dgvAmortizacion.Rows.Count - 2 For i As Integer = 0 To Index Dim ColeccionAmort = coleccionAmortizacion(i) PrestamoConsulta.NuevaAmortizacion(ColeccionAmort, codigo) Next End Sub Function NuevoAmortDiccionario() Dim diccionario As New Dictionary(Of String, Collection) Dim Index As Integer = dgvAmortizacion.Rows.Count - 2 For i As Integer = 0 To Index Dim ColeccionAmort = coleccionAmortizacion(i) diccionario.Add(i, ColeccionAmort) Next Return diccionario End Function Private Sub txtTasaInteres_TextChanged(sender As Object, e As EventArgs) Handles txtTasaInteres.TextChanged Calculos(False) End Sub Private Sub btnagregar_Click(sender As Object, e As EventArgs) End Sub Private Sub btnAccion2_Click(sender As Object, e As EventArgs) End Sub Private Sub txtSeguro_TextChanged(sender As Object, e As EventArgs) Handles txtSeguro.TextChanged End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Calculos(False) End Sub Private Sub txtAñoPrestamo_TextChanged(sender As Object, e As EventArgs) Handles txtAñoPrestamo.TextChanged Calculos(False) End Sub Private Sub txtCuotasMensuales_TextChanged(sender As Object, e As EventArgs) Handles txtCuotasMensuales.TextChanged Calculos(False) End Sub Private Sub txtMontoPrestamo_TextChanged(sender As Object, e As EventArgs) Handles txtMontoPrestamo.TextChanged Calculos(False) End Sub Private Sub txtAplicacionCodigo_TextChanged(sender As Object, e As EventArgs) Calculos(False) End Sub Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems End Sub Private Sub txtCuotaSinSeguro_TextChanged(sender As Object, e As EventArgs) Handles txtCuotaSinSeguro.TextChanged End Sub Private Sub txtCuotaReal_TextChanged(sender As Object, e As EventArgs) Handles txtCuotaReal.TextChanged End Sub Private Sub txtTasaInteres_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasaInteres.KeyPress If String.IsNullOrEmpty(txtTasaInteres.Text) Then If e.KeyChar = "." Then txtTasaInteres.Text = "0" Exit Sub End If End If If (Not txtTasaInteres.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtAñoPrestamo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtAñoPrestamo.KeyPress If String.IsNullOrEmpty(txtAñoPrestamo.Text) Then If e.KeyChar = "." Then txtAñoPrestamo.Text = "0" Exit Sub End If End If If (Not txtAñoPrestamo.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtCuotasMensuales_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCuotasMensuales.KeyPress If String.IsNullOrEmpty(txtCuotasMensuales.Text) Then If e.KeyChar = "." Then txtCuotasMensuales.Text = "0" Exit Sub End If End If If (Not txtCuotasMensuales.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtMontoPrestamo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMontoPrestamo.KeyPress If String.IsNullOrEmpty(txtMontoPrestamo.Text) Then If e.KeyChar = "." Then txtMontoPrestamo.Text = "0" Exit Sub End If End If If (Not txtMontoPrestamo.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtSeguro_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtSeguro.KeyPress If String.IsNullOrEmpty(txtSeguro.Text) Then If e.KeyChar = "." Then txtSeguro.Text = "0" Exit Sub End If End If If (Not txtSeguro.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtPeriodo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPeriodo.KeyPress If String.IsNullOrEmpty(txtPeriodo.Text) Then If e.KeyChar = "." Then txtPeriodo.Text = "0" Exit Sub End If End If If (Not txtPeriodo.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub btnCancelar_Click(sender As Object, e As EventArgs) End Sub Private Sub txtPeriodo_TextChanged(sender As Object, e As EventArgs) Handles txtPeriodo.TextChanged Calculos(False) End Sub Private Sub dtpFechaOtorgamiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOtorgamiento.ValueChanged Formato() Calculos(False) End Sub Private Sub dtpFechaPago_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaPago.ValueChanged Formato() Calculos(False) End Sub Private Sub txtPeriodo_Leave(sender As Object, e As EventArgs) Handles txtPeriodo.Leave Formato() End Sub Private Sub txtTasaInteres_Leave(sender As Object, e As EventArgs) Handles txtTasaInteres.Leave Formato() End Sub Private Sub txtAñoPrestamo_Leave(sender As Object, e As EventArgs) Handles txtAñoPrestamo.Leave Formato() End Sub Private Sub txtCuotasMensuales_Leave(sender As Object, e As EventArgs) Handles txtCuotasMensuales.Leave Formato() End Sub Private Sub txtMontoPrestamo_Leave(sender As Object, e As EventArgs) Handles txtMontoPrestamo.Leave Formato() End Sub Private Sub txtSeguro_Leave(sender As Object, e As EventArgs) Handles txtSeguro.Leave Formato() End Sub Private Sub txtAñoPrestamo_KeyUp(sender As Object, e As KeyEventArgs) Handles txtAñoPrestamo.KeyUp If txtAñoPrestamo.Text = "." Then txtAñoPrestamo.Text = ".0" End If End Sub Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click End Sub Private Sub txtNumeroDeudor_TextChanged(sender As Object, e As EventArgs) Handles txtNumeroDeudor.TextChanged End Sub End Class