| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230 |
- Public Class frmPrestamoEmpresariales
- Dim Prestamo As New PrestamoEmpresarialCE
- Dim PrestamoConsulta As New PrestamoEmpresarialDAO
- Dim oDAOGeneral As New DAOGeneral
- Dim Operaciones As New Operaciones
- Dim Base As Integer
- Dim FinCarga As Boolean = False
- Dim Estado As String = String.Empty
- Dim IndexCorte As Integer = 0
- Dim FechaCorte As Date
- Const IVA = 1.13
- Private Sub CargarTipoTasa()
- If cboTipoTasa.Items.Count = 0 Or cboTipoTasa.Items.Count = 1 Then
- Me.cboTipoTasa.DataSource = oDAOGeneral.ListaTipoTasa
- Me.cboTipoTasa.DisplayMember = "Descripcion"
- Me.cboTipoTasa.ValueMember = "Codigo"
- Me.cboTipoTasa.SelectedIndex = 0
- End If
- End Sub
- Private Sub CargarPeriodicidades()
- If cboPeriodicidad.Items.Count = 0 Or cboPeriodicidad.Items.Count = 1 Then
- Me.cboPeriodicidad.DataSource = oDAOGeneral.ListaPeriodicidad
- Me.cboPeriodicidad.DisplayMember = "Descripcion"
- Me.cboPeriodicidad.ValueMember = "Codigo"
- Me.cboPeriodicidad.SelectedIndex = 0
- End If
- End Sub
- Sub CargarBase()
- If cboBase.Items.Count = 0 Or cboBase.Items.Count = 1 Then
- Me.cboBase.DataSource = oDAOGeneral.ListaBase
- Me.cboBase.DisplayMember = "Descripcion"
- Me.cboBase.ValueMember = "Codigo"
- Me.cboBase.SelectedIndex = 0
- End If
- End Sub
- Private Sub frmPrestamoEmpresariales_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- dgvDetalles.Columns.Clear()
- Dias()
- AgregarCampos()
- CargarTipoTasa()
- CargarPeriodicidades()
- CargarBase()
- CargarDato()
- Dim Datos = CargarDetalles()
- RellenarDatos()
- If (Not Datos) Then
- Calculos(False, False)
- End If
- FinCarga = True
- ExisteInversion()
- ValidarExistencia()
- CargarTransladoNuevo()
- 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
- Calculos(False, 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
- Calculos(False, False)
- Return False
- End If
- End If
- Return False
- End Function
- Function CanRegistros()
- Dim Tabla As String = String.Empty
- Tabla = "PEMP1"
- Dim Codigo = Variables.Codigo
- Dim Cantidad As Integer = oDAOGeneral.CantidadRegistros(Codigo, Tabla)
- Return Cantidad
- End Function
- Sub ValidarExistencia()
- Dim General As New DAOGeneral
- Dim Codigo As String = Variables.Codigo
- Dim Tabla As String = String.Empty
- Tabla = "PEMP0"
- Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
- If (Existe) Then
- navNuevo.Enabled = False
- TbDetalles.Enabled = True
- navModificar.Enabled = True
- navEliminar.Enabled = True
- Else
- navNuevo.Enabled = True
- TbDetalles.Enabled = True
- navModificar.Enabled = False
- navEliminar.Enabled = False
- End If
- Estado = 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 = "PEMP0"
- Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
- Return Existe
- End Function
- Sub Dias()
- Dim fecha1, fecha2
- fecha1 = dtpFechaOperacion.Value.ToString
- fecha2 = dtpFechaVencimiento.Value.ToString
- txtPlazoDias.Text = Prestamo.FechaDias(fecha1, fecha2)
- End Sub
- Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged
- Formato()
- Dias()
- If (FinCarga) Then
- Calculos(False, False)
- End If
- End Sub
- Private Sub dtpFechaVencimiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimiento.ValueChanged
- Formato()
- Dias()
- If (FinCarga) Then
- Calculos(False, False)
- End If
- End Sub
- Sub AgregarCampos()
- Dim plazo, fechapago, fechacorte, Contador, SaldoPendiente, ingresarcomision, ingresarinteres, IVA, amortizacion, montorecibir As New DataGridViewTextBoxColumn
- plazo.Name = "Plazo (Desembolso)"
- fechacorte.Name = "Fecha de corte"
- fechapago.Name = "Fechas de Pago"
- ingresarcomision.Name = "Ingreso por Comision"
- ingresarinteres.Name = "Ingreso por Interes"
- IVA.Name = "IVA"
- amortizacion.Name = "Amortizacion"
- SaldoPendiente.Name = "Saldo Pendiente"
- montorecibir.Name = "Monto a Recibir"
- Contador.Name = "Correlativo"
- dgvDetalles.Columns.Add(Contador)
- dgvDetalles.Columns.Add(plazo)
- dgvDetalles.Columns.Add(fechacorte)
- dgvDetalles.Columns.Add(fechapago)
- dgvDetalles.Columns.Add(ingresarcomision)
- dgvDetalles.Columns.Add(ingresarinteres)
- dgvDetalles.Columns.Add(IVA)
- dgvDetalles.Columns.Add(amortizacion)
- dgvDetalles.Columns.Add(SaldoPendiente)
- dgvDetalles.Columns.Add(montorecibir)
- End Sub
- Sub Formato()
- If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then
- txtMonto.Text = 0
- txtMonto.Text = Format(txtMonto.Text, "0.0")
- End If
- If (String.IsNullOrEmpty(txtTasa.Text.ToString.TrimEnd("%"))) Then
- txtTasa.Text = 0
- txtTasa.Text = Format(txtTasa.Text, "0.0")
- End If
- If (String.IsNullOrEmpty(txtComisionDesembolso.Text.ToString.TrimEnd("%"))) Then
- txtComisionDesembolso.Text = 0
- txtComisionDesembolso.Text = Format(txtComisionDesembolso.Text, "0.0")
- End If
- If (txtTasa.Text.ToString.IndexOf("%") = -1) Then
- txtTasa.Text = txtTasa.Text.ToString + "%"
- End If
- If (txtComisionDesembolso.Text.ToString.IndexOf("%") = -1) Then
- txtComisionDesembolso.Text = txtComisionDesembolso.Text.ToString + "%"
- End If
- End Sub
- Sub Calculos(ByVal Modificar As Boolean, ByVal Corte As Boolean)
- Dim V_txtMonto = 0.0, V_txtTasa = 0.0, V_txtComisionDesembolso = 0.0
- If Not String.IsNullOrEmpty(txtMonto.Text.Trim("%")) Then
- V_txtMonto = txtMonto.Text.Trim("%")
- End If
- If Not String.IsNullOrEmpty(txtTasa.Text.ToString.Trim("%")) Then
- V_txtTasa = (CDec(txtTasa.Text.ToString.Trim("%")) / 100)
- End If
- If Not String.IsNullOrEmpty(txtComisionDesembolso.Text.ToString.TrimEnd("%")) Then
- V_txtComisionDesembolso = (CDec(txtComisionDesembolso.Text.ToString.TrimEnd("%")) / 100)
- End If
- If (cboTipoTasa.SelectedIndex = -1) Then
- cboTipoTasa.SelectedIndex = 0
- End If
- If (cboBase.SelectedIndex = -1) Then
- cboBase.SelectedIndex = 0
- End If
- If (cboPeriodicidad.SelectedIndex = -1) Then
- cboPeriodicidad.SelectedIndex = 0
- End If
- Dim FechaInicial = dtpFechaOperacion.Value
- Dim FechaFinal = dtpFechaOperacion.Value
- Dim FechaVencimiento = dtpFechaOperacion.Value
- Dim FechaVen = dtpFechaVencimiento.Value
- Dim FechaAux = dtpFechaOperacion.Value
- Dim Index = 0
- Dim Contador As Integer = 0
- Dim Borrar As Boolean = True
- Dim diccionario As New Dictionary(Of String, String)
- While (True)
- If (Not Modificar And Borrar) Then
- Dim Cantidad As Integer = dgvDetalles.Rows.Count
- If (Cantidad > 1) Then
- Dim CantidadReal = Cantidad - 2
- Dim i As Integer = 0
- While i <= CantidadReal
- Dim FechaCort = dgvDetalles.Rows(i).Cells("fecha de corte").Value
- If Not FechaCort Is DBNull.Value Then
- If Not String.IsNullOrEmpty(FechaCort) Then
- diccionario.Add(i, FechaCort)
- End If
- End If
- i += 1
- End While
- dgvDetalles.Rows.Clear()
- End If
- Borrar = False
- End If
- Dim Mes As Integer
- If (Index = 0) Then
- Mes = FechaFinal.Month
- Else
- FechaFinal = FechaFinal.AddDays(1)
- Mes = FechaFinal.Month
- End If
- Dim Salir As Boolean = False
- FechaAux = FechaFinal
- While (Mes = FechaFinal.Month)
- FechaFinal = Format(FechaFinal, "dd/MM/yyyy")
- FechaVen = Format(FechaVen, "dd/MM/yyyy")
- FechaFinal = FechaFinal.AddDays(1)
- If (FechaFinal > FechaVen) Then
- Salir = True
- Exit While
- End If
- End While
- If (Corte) Then
- If (Index >= IndexCorte) Then
- While FechaFinal.Date < FechaCorte.Date
- FechaCorte = FechaCorte.AddDays(-1)
- End While
- FechaFinal = FechaCorte
- Salir = True
- End If
- End If
- If (Index = 0) Then
- FechaInicial = dtpFechaOperacion.Value
- FechaFinal = dtpFechaOperacion.Value
- FechaAux = dtpFechaOperacion.Value
- ElseIf (Index = 1) Then
- Dim MesAño, Dia As Integer
- FechaAux = dtpFechaOperacion.Value
- MesAño = FechaAux.Month
- Dia = FechaAux.Day
- If (MesAño = 12 And Dia = 31) Then
- FechaInicial = FechaAux.AddDays(1)
- End If
- FechaFinal = FechaFinal.AddDays(-1)
- Else
- FechaInicial = FechaAux
- FechaFinal = FechaFinal.AddDays(-1)
- End If
- Dim FechaProv As Date = Date.Now.Date
- Dim CambioFecha As Boolean = False
- If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then
- If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then
- FechaProv = FechaFinal
- FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
- CambioFecha = True
- End If
- End If
- Dim PlazoDatos = Plazo(Index, FechaFinal)
- Dim IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
- Dim IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, V_txtMonto)
- Dim CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
- Dim CalculoAmort = CalculoAmortizacion(Salir, V_txtMonto)
- Dim MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
- Dim SaldoPendi = SaldoPendiente(Index, CalculoAmort, V_txtMonto)
- If CambioFecha Then
- FechaFinal = FechaProv
- CambioFecha = False
- End If
- If Modificar Then
- Dim Fila = dgvDetalles.CurrentRow.Index
- Dim SalAnterior As Double = 0
- Dim SumaAmortizado = 0
- Dim CantidadFilas As Integer = dgvDetalles.Rows.Count - 2
- Dim Filas As Integer = dgvDetalles.Rows.Count - 2
- If (Index >= Fila) Then
- If (SaldoPendi > V_txtMonto) Then
- dgvDetalles.Rows(Index).Cells("Amortizacion").Value = 0
- SaldoPendi = 0
- Else
- For j As Integer = 0 To CantidadFilas - 1
- SumaAmortizado += dgvDetalles.Rows(j).Cells("Amortizacion").Value
- Next
- SaldoPendi = SaldoPendiente(Index, SumaAmortizado, V_txtMonto)
- If (SumaAmortizado > V_txtMonto) Then
- Dim PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
- SaldoPendi = PagoPendienteAnterior
- dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi
- End If
- If (Index = CantidadFilas) Then
- Dim PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
- SaldoPendi = PagoPendienteAnterior
- dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi
- End If
- End If
- If (Salir) Then
- End If
- Dim FechaProv2 As Date = Date.Now.Date
- Dim CambioFecha2 As Boolean = False
- If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then
- If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then
- FechaProv2 = FechaFinal
- FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
- CambioFecha2 = True
- End If
- End If
- PlazoDatos = Plazo(Index, FechaFinal)
- IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
- IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, SaldoPendi)
- CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
- MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
- If CambioFecha2 Then
- FechaFinal = FechaProv2
- CambioFecha2 = False
- End If
- dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos
- dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom
- dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt
- dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi
- dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA
- dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir
- End If
- Else
- Dim FechaCorte As String = String.Empty
- For Each Valor In diccionario
- If Valor.Key = Index Then
- FechaCorte = Valor.Value
- End If
- Next
- If String.IsNullOrEmpty(FechaCorte) Then
- dgvDetalles.Rows.Add(Index + 1, PlazoDatos, "", FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir)
- Else
- dgvDetalles.Rows.Add(Index + 1, PlazoDatos, FechaCorte, FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir)
- PlazoDatos = Plazo(Index, FechaCorte)
- IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
- IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaCorte, V_txtTasa, SaldoPendi)
- CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
- MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
- dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos
- dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom
- dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt
- dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi
- dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA
- dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir
- End If
- Contador += 1
- End If
- If (Salir) Then
- Exit While
- End If
- Index += 1
- Dim IndexFin = dgvDetalles.Rows.Count - 3
- If (Index = IndexFin) Then
- Salir = True
- End If
- End While
- End Sub
- Function SaldoPendiente(ByVal Index As Integer, ByVal Amortizado As Double, ByVal Monto As Double)
- Dim Saldo As Double = 0
- Dim FilaAnterior As Integer = Index - 1
- Dim SaldoAnterior As Double = 0
- Dim PagoPendienteAnterior As Double = 0
- Dim PagoPendiente As Double = 0
- Dim Amortizacion As Double = 0
- If (Index = 0) Then
- Saldo = Monto - Amortizado
- ElseIf (Index > 0) Then
- SaldoAnterior = Monto
- PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
- Amortizacion = dgvDetalles.Rows(Index - 1).Cells("Amortizacion").Value
- If (SaldoAnterior = Amortizado) Then
- Saldo = 0
- ElseIf (SaldoAnterior = Amortizado) Then
- Saldo = PagoPendienteAnterior
- ElseIf (SaldoAnterior < Amortizado) Then
- Saldo = 0
- ElseIf (PagoPendienteAnterior = Amortizacion) Then
- Saldo = 0
- Else
- Saldo = SaldoAnterior - Amortizado
- End If
- End If
- If (PagoPendienteAnterior = Amortizacion And Not Amortizacion = 0) Then
- Saldo = 0
- End If
- Return Saldo
- End Function
- Function Plazo(ByVal Index As Integer, ByVal fecha2 As Date)
- Dim fecha1 As Date
- Dim Valor
- Dim Anterior = Index - 1
- If (Index = 0) Then
- Valor = 0
- ElseIf (Index > 0) Then
- fecha1 = dgvDetalles.Rows(Anterior).Cells("Fechas de Pago").Value
- fecha1 = Format(fecha1, "yyyy/MM/dd")
- fecha2 = Format(fecha2, "yyyy/MM/dd")
- Valor = Prestamo.FechaDias(fecha1, fecha2)
- Else
- Valor = 0
- End If
- Return Valor
- End Function
- Function IngresoComision(ByVal Index As Integer, ByVal V_txtComisionDesembolso As Double, ByVal V_txtMonto As Double)
- Dim Valor
- If (Index = 0) Then
- If (Not String.IsNullOrEmpty(V_txtComisionDesembolso) And Not String.IsNullOrEmpty(V_txtMonto)) Then
- Valor = V_txtComisionDesembolso * V_txtMonto
- Else
- Valor = 0
- End If
- Else
- Valor = 0
- End If
- Return Valor
- End Function
- Function IngresoInteres(ByVal Index As Integer, ByVal plazo As Integer, ByVal FechaInicial As Date, ByVal FechaFinal As Date, ByVal V_txtTasa As Double, ByVal V_txtMonto As Double)
- If (Index = 0) Then
- Return 0
- Else
- Dim CambioDeFecha As Integer = Operaciones.CambioBase(FechaInicial, FechaFinal)
- 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 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 366
- Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 365
- ElseIf CambioDeFecha = 2 Then
- DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
- DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
- Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 365
- Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 366
- End If
- Valor = Valor1 + Valor2
- Else
- If (Operaciones.AñoBisiesto(FechaInicial) = 364) Then
- Valor = V_txtMonto * V_txtTasa * plazo / 365
- End If
- If (Operaciones.AñoBisiesto(FechaInicial) = 365) Then
- Valor = V_txtMonto * V_txtTasa * plazo / 366
- End If
- End If
- Return Valor
- End If
- End Function
- Function CalculoIVA(ByVal Index As Integer, ByVal IngresoCom As Double, ByVal IngresoInteres As Double)
- Dim Valor
- If Index = 0 Then
- If (Not String.IsNullOrEmpty(IngresoCom) And Not String.IsNullOrEmpty(IngresoInteres)) Then
- Valor = IngresoCom - (IngresoCom / (1.13))
- End If
- Else
- If (Not String.IsNullOrEmpty(IngresoCom) And Not String.IsNullOrEmpty(IngresoInteres)) Then
- Valor = (IngresoCom + IngresoInteres) * 0.13
- Else
- Valor = 0
- End If
- End If
- Return Valor
- End Function
- Function CalculoAmortizacion(ByVal Ultimo As Integer, ByVal V_txtMonto As Double)
- Dim Monto As Integer = 0
- If (Ultimo) Then
- Monto = V_txtMonto
- End If
- Return Monto
- End Function
- Function MontoARecibir(ByVal IngresoComision As Double, ByVal IngresoInteres As Double, ByVal CalculoIVA As Double, ByVal Amortizacion As Double)
- Dim Monto As Double = 0
- If Not String.IsNullOrEmpty(txtMonto.Text) Then
- Monto = txtMonto.Text
- End If
- Dim Valor As Double = 0.0
- Valor = IngresoComision + IngresoInteres + CalculoIVA + Amortizacion
- If Amortizacion > Monto Then
- Valor = 0
- End If
- Return Valor
- End Function
- Function Coleccion()
- Dim colec As New Collection
- Dim fechaoper, fechaven, tasa, periodicidad, base, tipotasa, comisiondesembolso, plazodias, monto
- monto = txtMonto.Text
- fechaoper = dtpFechaOperacion.Value
- fechaven = dtpFechaVencimiento.Value
- tasa = CDec(txtTasa.Text.ToString.Trim("%")) / 100
- periodicidad = cboPeriodicidad.SelectedValue
- base = Me.Base
- tipotasa = cboTipoTasa.SelectedValue
- comisiondesembolso = txtComisionDesembolso.Text.ToString.Trim("%") / 100
- plazodias = txtPlazoDias.Text
- colec.Add(monto)
- colec.Add(fechaoper)
- colec.Add(fechaven)
- colec.Add(tasa)
- colec.Add(periodicidad)
- colec.Add(base)
- colec.Add(tipotasa)
- colec.Add(comisiondesembolso)
- colec.Add(plazodias)
- Return colec
- End Function
- Sub RellenarDatos()
- If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then
- txtMonto.Text = "0.0"
- End If
- If (String.IsNullOrEmpty(txtTasa.Text.TrimEnd("%").ToString)) Then
- txtTasa.Text = "0.0%"
- End If
- If (cboTipoTasa.SelectedIndex = -1) Then
- cboTipoTasa.SelectedIndex = 0
- End If
- If (cboBase.SelectedIndex = -1) Then
- cboBase.SelectedIndex = 0
- End If
- If (cboPeriodicidad.SelectedIndex = -1) Then
- cboPeriodicidad.SelectedIndex = 0
- End If
- If (String.IsNullOrEmpty(txtComisionDesembolso.Text.Trim("%").ToString)) Then
- txtComisionDesembolso.Text = "0.0%"
- End If
- If (String.IsNullOrEmpty(txtPlazoDias.Text.ToString)) Then
- txtPlazoDias.Text = "0.0"
- End If
- End Sub
- Function ColeccionDetalle(ByVal Index As Integer)
- Dim Coleccion As New Collection
- Dim plazo, fecha, fechacorte, ingresocomision, ingresointeres, IVA, amortizacion, montorecibir, saldopendiente, correlativo
- correlativo = dgvDetalles.Rows(Index).Cells("Correlativo").Value
- plazo = dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value
- fecha = dgvDetalles.Rows(Index).Cells("Fechas de Pago").Value
- ingresocomision = dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value
- ingresointeres = dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value
- IVA = dgvDetalles.Rows(Index).Cells("IVA").Value
- amortizacion = dgvDetalles.Rows(Index).Cells("Amortizacion").Value
- saldopendiente = dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value
- montorecibir = dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value
- fechacorte = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
- Coleccion.Add(correlativo)
- Coleccion.Add(plazo)
- Coleccion.Add(fecha)
- Coleccion.Add(ingresocomision)
- Coleccion.Add(ingresointeres)
- Coleccion.Add(IVA)
- Coleccion.Add(amortizacion)
- Coleccion.Add(saldopendiente)
- Coleccion.Add(montorecibir)
- Coleccion.Add(fechacorte)
- Return Coleccion
- End Function
- Sub NuevoDetalle(ByVal AgregarModificar As Boolean, ByVal Cantidad As Integer)
- Dim i As Integer = 0
- Dim Index = dgvDetalles.Rows.Count - 2
- i = Cantidad
- While i <= Index
- Dim coleccion = ColeccionDetalle(i)
- If PrestamoConsulta.NuevoDetalle(coleccion, Codigo) Is Nothing Then
- Exit Sub
- End If
- i += 1
- End While
- MsgBox("Registro de ingresos actualizados")
- End Sub
- Function ColeccionCampos()
- Dim i As Integer = 0
- Dim diccionario As New Dictionary(Of String, Collection)
- Dim Index = dgvDetalles.Rows.Count - 2
- While i <= Index
- Dim coleccion = ColeccionDetalle(i)
- diccionario.Add(i, coleccion)
- i += 1
- End While
- Return diccionario
- End Function
- Sub EliminarDetalles(ByVal CantidadRegistros As Integer, ByVal Cantidad As Integer)
- Dim i As Integer = 0
- Dim Index = CantidadRegistros + 1
- i = Cantidad
- While i >= Index
- If PrestamoConsulta.EliminarDetalles(Index, Codigo) Is Nothing Then
- Exit Sub
- End If
- Index += 1
- End While
- End Sub
- Function ColeccionNuevo(ByVal codigo As String)
- Dim i As Integer = 0
- Dim diccionario As New Dictionary(Of String, Collection)
- Dim Index = dgvDetalles.Rows.Count - 2
- While i <= Index
- Dim coleccion = ColeccionDetalle(i)
- diccionario.Add(i, coleccion)
- i += 1
- End While
- Return diccionario
- End Function
- Function ColeccionEliminar(ByVal codigo As String)
- Dim CantidadRegistros As Integer = dgvDetalles.Rows.Count - 1
- Dim Cantidad As Integer = CanRegistros()
- Dim i As Integer = 0
- Dim diccionario As New Dictionary(Of Integer, String)
- Dim Index = CantidadRegistros + 1
- i = Cantidad
- While i >= Index
- diccionario.Add(Index, codigo)
- Index += 1
- End While
- Return diccionario
- End Function
- Sub EliminarDatos(ByVal codigo As String)
- PrestamoConsulta.Eliminar(codigo)
- End Sub
- Private Sub dgvDetalles_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellContentClick
- End Sub
- Private Sub dgvDetalles_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellEndEdit
- Calculos(True, False)
- End Sub
- Private Sub cboBase_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboBase.SelectedIndexChanged
- Formato()
- If (cboBase.SelectedIndex = 0) Then
- Base = 360
- Else
- Base = 365
- End If
- End Sub
- Sub CargarDato()
- Dim codigo As String = Variables.Codigo
- Dim Retorno = PrestamoConsulta.CargarDato(codigo)
- Dim coleccion As New Collection
- If (TypeOf Retorno Is Boolean) Then
- Exit Sub
- Else
- coleccion = PrestamoConsulta.CargarDato(codigo)
- End If
- Dim Index As Integer = 0
- If (coleccion(6).ToString = "360") Then
- Index = 0
- Else
- Index = 1
- End If
- txtMonto.Text = coleccion(1)
- dtpFechaOperacion.Value = coleccion(2)
- dtpFechaVencimiento.Value = coleccion(3)
- txtTasa.Text = (CDec(coleccion(4).ToString.Trim("%")) * 100).ToString + "%"
- cboPeriodicidad.SelectedValue = coleccion(5)
- cboBase.SelectedIndex = Index
- cboTipoTasa.SelectedValue = coleccion(7)
- txtComisionDesembolso.Text = (CDec(coleccion(8).Trim("%")) * 100).ToString + "%"
- txtPlazoDias.Text = coleccion(9)
- End Sub
- Function CargarDetalles()
- Dim codigo As String = Variables.Codigo
- Dim dr = PrestamoConsulta.CargarDetalles(codigo)
- Dim Datos As Boolean = False
- If (Not dr Is Nothing) Then
- Dim Iterador As Integer = 0
- Dim ConvertirString As String
- While dr.Read
- ConvertirString = Format(dr("fechapago"), "dd/MM/yyyy")
- dgvDetalles.Rows.Add(dr("correlativo"), dr("plazo"), dr("fechacorte"), ConvertirString, dr("ingresarcomision"), dr("ingresarinteres"), dr("IVA"), dr("amortizacion"), dr("saldopendiente"), dr("montorecibir"))
- End While
- Datos = True
- End If
- Return Datos
- End Function
- Private Sub btnAccion_Click(sender As Object, e As EventArgs) Handles btnAccion.Click
- Dim codigo As String = Variables.Codigo
- Dim Colec As Collection = Coleccion()
- Dim Diccionario As Dictionary(Of Integer, String) = ColeccionEliminar(codigo)
- Dim Diccionario2 As Dictionary(Of String, Collection) = ColeccionNuevo(codigo)
- If (Estado = "N") Then
- PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Nuevo")
- ElseIf Not ExisteValidacion() Then
- Variables.ColeccionPEMP = Coleccion()
- Variables.ColeccionPEMPDi = ColeccionCampos()
- Me.Close()
- End If
- If (Estado = "M") Then
- PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Modificar")
- End If
- If (Estado = "B") Then
- EliminarDatos(codigo)
- End If
- ValidarExistencia()
- End Sub
- Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
- Estado = "M"
- btnAccion.Text = "Modificar"
- End Sub
- Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
- Estado = "N"
- btnAccion.Text = "Agregar"
- ' btnagregar.Text = "Agregar"
- End Sub
- Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
- Estado = "B"
- btnAccion.Text = "Eliminar"
- End Sub
- Private Sub btnagregar_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub txtMonto_TextChanged(sender As Object, e As EventArgs) Handles txtMonto.TextChanged
- If (FinCarga) Then
- Calculos(False, False)
- End If
- End Sub
- Private Sub txtTasa_TextChanged(sender As Object, e As EventArgs) Handles txtTasa.TextChanged
- If (FinCarga) Then
- Calculos(False, False)
- End If
- End Sub
- Private Sub txtComisionDesembolso_TextChanged(sender As Object, e As EventArgs) Handles txtComisionDesembolso.TextChanged
- If (FinCarga) Then
- Calculos(False, False)
- End If
- End Sub
- Private Sub txtMonto_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonto.KeyPress
- If String.IsNullOrEmpty(txtMonto.Text) Then
- If e.KeyChar = "." Then
- txtMonto.Text = "0"
- Exit Sub
- End If
- End If
- If (Not txtMonto.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 txtTasa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasa.KeyPress
- If String.IsNullOrEmpty(txtTasa.Text) Then
- If e.KeyChar = "." Then
- txtTasa.Text = "0"
- Exit Sub
- End If
- End If
- If (Not txtTasa.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 txtComisionDesembolso_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionDesembolso.KeyPress
- If String.IsNullOrEmpty(txtComisionDesembolso.Text) Then
- If e.KeyChar = "." Then
- txtComisionDesembolso.Text = "0"
- Exit Sub
- End If
- End If
- If (Not txtComisionDesembolso.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)
- Cancelar()
- End Sub
- Sub Cancelar()
- End Sub
- Private Sub txtMonto_Leave(sender As Object, e As EventArgs) Handles txtMonto.Leave
- Formato()
- End Sub
- Private Sub txtTasa_Leave(sender As Object, e As EventArgs) Handles txtTasa.Leave
- Formato()
- End Sub
- Private Sub cboTipoTasa_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTipoTasa.SelectedIndexChanged
- Formato()
- End Sub
- Private Sub cboPeriodicidad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPeriodicidad.SelectedIndexChanged
- Formato()
- End Sub
- Private Sub txtComisionDesembolso_Leave(sender As Object, e As EventArgs) Handles txtComisionDesembolso.Leave
- Formato()
- End Sub
- Private Sub txtPlazoDias_Leave(sender As Object, e As EventArgs) Handles txtPlazoDias.Leave
- Formato()
- End Sub
- Private Sub txtMonto_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMonto.KeyUp
- If txtMonto.Text = "." Then
- txtMonto.Text = ".0"
- End If
- End Sub
- Private Sub txtTasa_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasa.KeyUp
- If txtTasa.Text = "." Then
- txtTasa.Text = ".0"
- End If
- End Sub
- Private Sub txtComisionDesembolso_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionDesembolso.KeyUp
- If txtComisionDesembolso.Text = "." Then
- txtComisionDesembolso.Text = ".0"
- End If
- End Sub
- Sub CargarTransladoNuevo()
- Dim Existe As Boolean = ExisteInversion()
- If Not RetCodigoInversionExiste And Not Existe Then
- txtMonto.Text = Variables.RetMonto
- txtTasa.Text = Variables.RetRendimiento
- End If
- End Sub
- End Class
|