Public Class Amortizacion_Prestamos Dim cuota

Anuncio
Public Class Amortizacion_Prestamos
Dim cuota, interes, mes
Private Sub BtnNew_Click(sender As System.Object, e As System.EventArgs) Handles
BtnNew.Click
Dim i As Integer
i = Val(TxtNPag.Text)
For i = 1 To Val(TxtNPag.Text)
'procedemos a limpiar la tabla de datos
DgvPrestamos.Rows.RemoveAt(DgvPrestamos.CurrentRow.Index)
Next
TxtAde.Text = ""
TxtCuota.Text = ""
TxtAtr.Text = ""
TxtDPag.Text = ""
TxtMonto.Text = ""
TxtNPag.Text = ""
CmbPeriodo.Text = ""
TxtUser.Text = ""
TxtMonto.Enabled = True
TxtNPag.Enabled = True
TxtUser.Enabled = True
CmbPeriodo.Enabled = True
DtpFecInc.Enabled = True
BtnProcesar.Enabled = True
BtnPago.Enabled = False
BtnNew.Enabled = False
End Sub
Private Sub BtnExit_Click(sender As System.Object, e As System.EventArgs)
Handles BtnExit.Click
'Salimos de la aplicación
If MsgBox("Esta seguro que desea Salir", MsgBoxStyle.Information +
MsgBoxStyle.YesNo, "Mensaje") = MsgBoxResult.Yes Then
End
Else
Exit Sub
End If
End Sub
Private Sub BtnProcesar_Click(sender As System.Object, e As System.EventArgs)
Handles BtnProcesar.Click
Dim i As Integer
Dim ultimafila As Integer
Dim resto
resto = Val(TxtMonto.Text)
TxtMonto.Enabled = False
TxtUser.Enabled = False
CmbPeriodo.Enabled = False
TxtNPag.Enabled = False
DtpFecInc.Enabled = False
BtnNew.Enabled = True
BtnNewPago.Enabled = True
BtnProcesar.Enabled = False
'caculo el valor de la cuota de pago
cuota = (Val(TxtMonto.Text) / Val(TxtNPag.Text))
'calculo el valor de pago incuido el Interes
interes = Val((cuota) * Val(TxtInteres.Text) / 100)
'Procesamos los datos del prestamo en la tabla
If TxtUser.Text = "" Or TxtMonto.Text = "" Or TxtInteres.Text = "" Or
TxtNPag.Text = "" Or CmbPeriodo.Text = "" Then
MsgBox("Verifique que los datos esten completos",
MsgBoxStyle.Information, "Mensaje")
Exit Sub
Else
If (Val(TxtMonto.Text) >= 1000 And Val(TxtMonto.Text) <= 100000) Then
If CmbPeriodo.Text = "MENSUAL" Then
If Val(TxtNPag.Text) > 72 Then
MsgBox("El Nº de pago no es correcto",
MsgBoxStyle.Information, "Mensaje")
Exit Sub
Else
'Pagos mensuales
Dim FechaInicial As Date = DtpFecInc.Value 'extraemos la
fecha de DataTimerPicker
mes = 1
For i = 1 To Val(TxtNPag.Text)
DgvPrestamos.Rows.Add()
Dim fechaFinal As Date = DateAdd(DateInterval.Month,
mes, FechaInicial) ' Incrementamos el mes de
resto = Format(resto - cuota, "0.00")
ultimafila = i
DgvPrestamos.Item(0, ultimafila - 1).Value = (i)
DgvPrestamos.Item(1, ultimafila - 1).Value =
fechaFinal.ToShortDateString
DgvPrestamos.Item(2, ultimafila - 1).Value =
Format(cuota, "0.00")
DgvPrestamos.Item(3, ultimafila - 1).Value =
Format(interes, "0.00")
DgvPrestamos.Item(4, ultimafila - 1).Value =
Format(interes + cuota, "0.00")
DgvPrestamos.Item(5, ultimafila - 1).Value = resto
mes = mes + 1
Next
End If
Else
If Val(TxtNPag.Text) > 12 Then
MsgBox("El Nº de pago no es correcto",
MsgBoxStyle.Information, "Mensaje")
Exit Sub
Else
'proceso para los pagos semestrales
mes = 6
'lleno los datos de la tabla
Dim FechaInicial As Date = DtpFecInc.Value 'extraemos la
fecha de DataTimerPicker
For i = 1 To Val(TxtNPag.Text)
DgvPrestamos.Rows.Add()
Dim fechaFinal As Date = DateAdd(DateInterval.Month,
mes, FechaInicial) ' Incrementamos el mes de
resto = Format(resto - cuota, "0.00")
ultimafila = i
DgvPrestamos.Item(0, ultimafila - 1).Value = (i)
DgvPrestamos.Item(1, ultimafila - 1).Value =
fechaFinal.ToShortDateString
DgvPrestamos.Item(2, ultimafila - 1).Value =
Format(cuota, "0.00")
DgvPrestamos.Item(3, ultimafila - 1).Value =
Format(interes, "0.00")
DgvPrestamos.Item(4, ultimafila - 1).Value =
Format(interes + cuota, "0.00")
DgvPrestamos.Item(5, ultimafila - 1).Value = resto
mes = mes + 6
Next
End If
End If
Else
MsgBox("El monto especificado no es correcto",
MsgBoxStyle.Information, "Mensaje")
Exit Sub
End If
End If
End Sub
Private Sub TxtMonto_KeyPress(sender As Object, e As
System.Windows.Forms.KeyPressEventArgs) Handles TxtMonto.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub TxtNPag_KeyPress(sender As Object, e As
System.Windows.Forms.KeyPressEventArgs) Handles TxtNPag.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub TxtTime_KeyPress(sender As Object, e As
System.Windows.Forms.KeyPressEventArgs)
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub TxtInteres_KeyPress(sender As Object, e As
System.Windows.Forms.KeyPressEventArgs) Handles TxtInteres.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub BtnPago_Click(sender As System.Object, e As System.EventArgs)
Handles BtnPago.Click
Dim contador
If TxtCuota.Text = "" Then
MsgBox("Ingrese la cuota", MsgBoxStyle.Information, "Mensaje")
TxtCuota.Focus()
Exit Sub
End If
'Controlamos que las cuota no se exedad de las nomales
If TxtCuota.Text > DgvPrestamos.Rows.Count Then
MsgBox("La cuota es mayor de las espesificadas")
TxtCuota.Focus()
Exit Sub
End If
contador = 0
'Recorremo la tabla y comparamos
While contador < DgvPrestamos.Rows.Count
If TxtCuota.Text = DgvPrestamos.Item(0, contador).Value Then
If DtpFecPag.Text = DgvPrestamos.Item(1, contador).Value Then
MsgBox("Pago puntual")
Exit Sub
Else
Call fechas()
End If
End If
contador = contador + 1
End While
BtnNewPago.Enabled = True
TxtCuota.Enabled = False
DtpFecPag.Enabled = False
BtnPago.Enabled = False
End Sub
Public Function fechas()
Dim i As Integer
Dim ultimafila As Integer
Dim resto, N, Dias, dias1, inter, cuo
inter = interes
cuo = cuota
resto = Val(TxtMonto.Text)
For i = 1 To Val(TxtCuota.Text)
dias1 = DgvPrestamos.Item(1, i - 1).Value
Next
Dias = (DateDiff(DateInterval.Day, dias1, DtpFecPag.Value))
If Dias < 0 Then
TxtAde.Text = System.Math.Abs(Dias)
Else
TxtAtr.Text = Dias
End If
If Val(TxtAde.Text = "") Then
If Val(TxtAtr.Text) < 11 Then
MsgBox("Tiene un atraso de: " & Dias & " Dias",
MsgBoxStyle.Information, "Mensaje")
inter = inter + (interes * 0.1)
Else
MsgBox("Tiene un atraso de " & Dias & " Dias",
MsgBoxStyle.Information, "Mensaje")
cuo = cuo * 2
inter = Val((cuota) * Val(TxtInteres.Text) / 100)
End If
Else
MsgBox("Tiene un adelanto de " & Val(TxtAde.Text) & " Dias",
MsgBoxStyle.Information, "Mensaje")
inter = inter - (inter * 0.1)
End If
For i = Val(TxtCuota.Text) To Val(TxtCuota.Text)
ultimafila = i
DgvPrestamos.Item(2, ultimafila - 1).Value = Format(cuo, "0.00")
DgvPrestamos.Item(3, ultimafila - 1).Value = Format(inter, "0.00")
DgvPrestamos.Item(4, ultimafila - 1).Value = Format(inter + cuo, "0.00")
Next
N =
i =
Dim
For
0
Val(TxtNPag.Text)
FechaInicial As Date = DtpFecPag.Value
i = Val(TxtCuota.Text) To Val(DgvPrestamos.Rows.Count)
Dim fechaFinal As Date = DateAdd(DateInterval.Month, N, FechaInicial)
fechaFinal = fechaFinal
ultimafila = Val(i)
DgvPrestamos.Item(1, ultimafila - 1).Value =
fechaFinal.ToShortDateString
N = N + 1
Next
End Function
Private Sub BtnNewPago_Click(sender As System.Object, e As System.EventArgs)
Handles BtnNewPago.Click
TxtCuota.Text = ""
TxtCuota.Focus()
TxtCuota.Enabled = True
DtpFecPag.Enabled = True
TxtAtr.Text = ""
TxtAde.Text = ""
BtnPago.Enabled = True
BtnNewPago.Enabled = False
End Sub
Private Sub CmbPeriodo_KeyPress(sender As Object, e As
System.Windows.Forms.KeyPressEventArgs) Handles CmbPeriodo.KeyPress
e.Handled = True
End Sub
Private Sub TxtCuota_KeyPress(sender As Object, e As
System.Windows.Forms.KeyPressEventArgs) Handles TxtCuota.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
End Class
Descargar