frmPrestamoEmpresariales.vb 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. Public Class frmPrestamoEmpresariales
  2. Dim Prestamo As New PrestamoEmpresarialCE
  3. Dim PrestamoConsulta As New PrestamoEmpresarialDAO
  4. Dim oDAOGeneral As New DAOGeneral
  5. Dim Operaciones As New Operaciones
  6. Dim Base As Integer
  7. Dim FinCarga As Boolean = False
  8. Dim Estado As String = String.Empty
  9. Dim IndexCorte As Integer = 0
  10. Dim FechaCorte As Date
  11. Const IVA = 1.13
  12. Private Sub CargarTipoTasa()
  13. If cboTipoTasa.Items.Count = 0 Or cboTipoTasa.Items.Count = 1 Then
  14. Me.cboTipoTasa.DataSource = oDAOGeneral.ListaTipoTasa
  15. Me.cboTipoTasa.DisplayMember = "Descripcion"
  16. Me.cboTipoTasa.ValueMember = "Codigo"
  17. Me.cboTipoTasa.SelectedIndex = 0
  18. End If
  19. End Sub
  20. Private Sub CargarPeriodicidades()
  21. If cboPeriodicidad.Items.Count = 0 Or cboPeriodicidad.Items.Count = 1 Then
  22. Me.cboPeriodicidad.DataSource = oDAOGeneral.ListaPeriodicidad
  23. Me.cboPeriodicidad.DisplayMember = "Descripcion"
  24. Me.cboPeriodicidad.ValueMember = "Codigo"
  25. Me.cboPeriodicidad.SelectedIndex = 0
  26. End If
  27. End Sub
  28. Sub CargarBase()
  29. If cboBase.Items.Count = 0 Or cboBase.Items.Count = 1 Then
  30. Me.cboBase.DataSource = oDAOGeneral.ListaBase
  31. Me.cboBase.DisplayMember = "Descripcion"
  32. Me.cboBase.ValueMember = "Codigo"
  33. Me.cboBase.SelectedIndex = 0
  34. End If
  35. End Sub
  36. Private Sub frmPrestamoEmpresariales_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  37. dgvDetalles.Columns.Clear()
  38. Dias()
  39. AgregarCampos()
  40. CargarTipoTasa()
  41. CargarPeriodicidades()
  42. CargarBase()
  43. CargarDato()
  44. Dim Datos = CargarDetalles()
  45. RellenarDatos()
  46. If (Not Datos) Then
  47. Calculos(False, False)
  48. End If
  49. FinCarga = True
  50. ExisteInversion()
  51. ValidarExistencia()
  52. CargarTransladoNuevo()
  53. End Sub
  54. Function ExisteInversion()
  55. Dim Codigo As String = Variables.Codigo
  56. Dim TablaINV As String = "INV0"
  57. Dim TablaPINV As String = "PIN0"
  58. Dim General As New DAOGeneral
  59. Dim InvPro = Variables.InvPro
  60. If InvPro = "I" Then
  61. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  62. If INV0 Then
  63. navNuevo.Visible = True
  64. Return True
  65. Else
  66. navNuevo.Visible = False
  67. Calculos(False, False)
  68. Return False
  69. End If
  70. End If
  71. If InvPro = "P" Then
  72. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  73. If PINV0 Then
  74. navNuevo.Visible = True
  75. Return True
  76. Else
  77. navNuevo.Visible = False
  78. Calculos(False, False)
  79. Return False
  80. End If
  81. End If
  82. Return False
  83. End Function
  84. Function CanRegistros()
  85. Dim Tabla As String = String.Empty
  86. Tabla = "PEMP1"
  87. Dim Codigo = Variables.Codigo
  88. Dim Cantidad As Integer = oDAOGeneral.CantidadRegistros(Codigo, Tabla)
  89. Return Cantidad
  90. End Function
  91. Sub ValidarExistencia()
  92. Dim General As New DAOGeneral
  93. Dim Codigo As String = Variables.Codigo
  94. Dim Tabla As String = String.Empty
  95. Tabla = "PEMP0"
  96. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  97. If (Existe) Then
  98. navNuevo.Enabled = False
  99. TbDetalles.Enabled = True
  100. navModificar.Enabled = True
  101. navEliminar.Enabled = True
  102. Else
  103. navNuevo.Enabled = True
  104. TbDetalles.Enabled = True
  105. navModificar.Enabled = False
  106. navEliminar.Enabled = False
  107. End If
  108. Estado = String.Empty
  109. btnAccion.Text = "Aceptar"
  110. End Sub
  111. Function ExisteValidacion()
  112. Dim General As New DAOGeneral
  113. Dim Codigo As String = Variables.Codigo
  114. Dim Tabla As String = String.Empty
  115. Tabla = "PEMP0"
  116. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  117. Return Existe
  118. End Function
  119. Sub Dias()
  120. Dim fecha1, fecha2
  121. fecha1 = dtpFechaOperacion.Value.ToString
  122. fecha2 = dtpFechaVencimiento.Value.ToString
  123. txtPlazoDias.Text = Prestamo.FechaDias(fecha1, fecha2)
  124. End Sub
  125. Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged
  126. Formato()
  127. Dias()
  128. If (FinCarga) Then
  129. Calculos(False, False)
  130. End If
  131. End Sub
  132. Private Sub dtpFechaVencimiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimiento.ValueChanged
  133. Formato()
  134. Dias()
  135. If (FinCarga) Then
  136. Calculos(False, False)
  137. End If
  138. End Sub
  139. Sub AgregarCampos()
  140. Dim plazo, fechapago, fechacorte, Contador, SaldoPendiente, ingresarcomision, ingresarinteres, IVA, amortizacion, montorecibir As New DataGridViewTextBoxColumn
  141. plazo.Name = "Plazo (Desembolso)"
  142. fechacorte.Name = "Fecha de corte"
  143. fechapago.Name = "Fechas de Pago"
  144. ingresarcomision.Name = "Ingreso por Comision"
  145. ingresarinteres.Name = "Ingreso por Interes"
  146. IVA.Name = "IVA"
  147. amortizacion.Name = "Amortizacion"
  148. SaldoPendiente.Name = "Saldo Pendiente"
  149. montorecibir.Name = "Monto a Recibir"
  150. Contador.Name = "Correlativo"
  151. dgvDetalles.Columns.Add(Contador)
  152. dgvDetalles.Columns.Add(plazo)
  153. dgvDetalles.Columns.Add(fechacorte)
  154. dgvDetalles.Columns.Add(fechapago)
  155. dgvDetalles.Columns.Add(ingresarcomision)
  156. dgvDetalles.Columns.Add(ingresarinteres)
  157. dgvDetalles.Columns.Add(IVA)
  158. dgvDetalles.Columns.Add(amortizacion)
  159. dgvDetalles.Columns.Add(SaldoPendiente)
  160. dgvDetalles.Columns.Add(montorecibir)
  161. End Sub
  162. Sub Formato()
  163. If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then
  164. txtMonto.Text = Format(txtMonto.Text, "0.0")
  165. End If
  166. If (String.IsNullOrEmpty(txtTasa.Text.ToString.TrimEnd("%"))) Then
  167. txtTasa.Text = Format(txtTasa.Text, "0.0")
  168. End If
  169. If (String.IsNullOrEmpty(txtComisionDesembolso.Text.ToString.Trim("%"))) Then
  170. txtComisionDesembolso.Text = Format(txtComisionDesembolso.Text, "0.0")
  171. End If
  172. If (txtTasa.Text.ToString.IndexOf("%") = -1) Then
  173. txtTasa.Text = txtTasa.Text.ToString + "%"
  174. End If
  175. If (txtComisionDesembolso.Text.ToString.IndexOf("%") = -1) Then
  176. txtComisionDesembolso.Text = txtComisionDesembolso.Text.ToString + "%"
  177. End If
  178. End Sub
  179. Sub Calculos(ByVal Modificar As Boolean, ByVal Corte As Boolean)
  180. Dim V_txtMonto = 0.0, V_txtTasa = 0.0, V_txtComisionDesembolso = 0.0
  181. V_txtMonto = Operaciones.ConvertirDecimal(txtMonto.Text.ToString)
  182. V_txtTasa = Operaciones.ConvertirDecimal(txtTasa.Text.ToString) / 100
  183. V_txtComisionDesembolso = Operaciones.ConvertirDecimal(txtComisionDesembolso.Text.ToString) / 100
  184. If (cboTipoTasa.SelectedIndex = -1) Then
  185. cboTipoTasa.SelectedIndex = 0
  186. End If
  187. If (cboBase.SelectedIndex = -1) Then
  188. cboBase.SelectedIndex = 0
  189. End If
  190. If (cboPeriodicidad.SelectedIndex = -1) Then
  191. cboPeriodicidad.SelectedIndex = 0
  192. End If
  193. Dim FechaInicial = dtpFechaOperacion.Value
  194. Dim FechaFinal = dtpFechaOperacion.Value
  195. Dim FechaVencimiento = dtpFechaOperacion.Value
  196. Dim FechaVen = dtpFechaVencimiento.Value
  197. Dim FechaAux = dtpFechaOperacion.Value
  198. Dim Index = 0
  199. Dim Contador As Integer = 0
  200. Dim Borrar As Boolean = True
  201. Dim diccionario As New Dictionary(Of String, String)
  202. While (True)
  203. If (Not Modificar And Borrar) Then
  204. Dim Cantidad As Integer = dgvDetalles.Rows.Count
  205. If (Cantidad > 1) Then
  206. Dim CantidadReal = Cantidad - 2
  207. Dim i As Integer = 0
  208. While i <= CantidadReal
  209. Dim FechaCort = dgvDetalles.Rows(i).Cells("fecha de corte").Value
  210. If Not FechaCort Is DBNull.Value Then
  211. If Not String.IsNullOrEmpty(FechaCort) Then
  212. diccionario.Add(i, FechaCort)
  213. End If
  214. End If
  215. i += 1
  216. End While
  217. dgvDetalles.Rows.Clear()
  218. End If
  219. Borrar = False
  220. End If
  221. Dim Mes As Integer
  222. If (Index = 0) Then
  223. Mes = FechaFinal.Month
  224. Else
  225. FechaFinal = FechaFinal.AddDays(1)
  226. Mes = FechaFinal.Month
  227. End If
  228. Dim Salir As Boolean = False
  229. FechaAux = FechaFinal
  230. While (Mes = FechaFinal.Month)
  231. FechaFinal = Format(FechaFinal, "dd/MM/yyyy")
  232. FechaVen = Format(FechaVen, "dd/MM/yyyy")
  233. FechaFinal = FechaFinal.AddDays(1)
  234. If (FechaFinal > FechaVen) Then
  235. Salir = True
  236. Exit While
  237. End If
  238. End While
  239. If (Corte) Then
  240. If (Index >= IndexCorte) Then
  241. While FechaFinal.Date < FechaCorte.Date
  242. FechaCorte = FechaCorte.AddDays(-1)
  243. End While
  244. FechaFinal = FechaCorte
  245. Salir = True
  246. End If
  247. End If
  248. If (Index = 0) Then
  249. FechaInicial = dtpFechaOperacion.Value
  250. FechaFinal = dtpFechaOperacion.Value
  251. FechaAux = dtpFechaOperacion.Value
  252. ElseIf (Index = 1) Then
  253. Dim MesAño, Dia As Integer
  254. FechaAux = dtpFechaOperacion.Value
  255. MesAño = FechaAux.Month
  256. Dia = FechaAux.Day
  257. If (MesAño = 12 And Dia = 31) Then
  258. FechaInicial = FechaAux.AddDays(1)
  259. End If
  260. FechaFinal = FechaFinal.AddDays(-1)
  261. Else
  262. FechaInicial = FechaAux
  263. FechaFinal = FechaFinal.AddDays(-1)
  264. End If
  265. Dim FechaProv As Date = Date.Now.Date
  266. Dim CambioFecha As Boolean = False
  267. If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then
  268. If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then
  269. FechaProv = FechaFinal
  270. FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
  271. CambioFecha = True
  272. End If
  273. End If
  274. Dim PlazoDatos = Plazo(Index, FechaFinal)
  275. Dim IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
  276. Dim IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, V_txtMonto)
  277. Dim CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
  278. Dim CalculoAmort = CalculoAmortizacion(Salir, V_txtMonto)
  279. Dim MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
  280. Dim SaldoPendi = SaldoPendiente(Index, CalculoAmort, V_txtMonto)
  281. If CambioFecha Then
  282. FechaFinal = FechaProv
  283. CambioFecha = False
  284. End If
  285. If Modificar Then
  286. Dim Fila = dgvDetalles.CurrentRow.Index
  287. Dim SalAnterior As Double = 0
  288. Dim SumaAmortizado = 0
  289. Dim CantidadFilas As Integer = dgvDetalles.Rows.Count - 2
  290. Dim Filas As Integer = dgvDetalles.Rows.Count - 2
  291. If (Index >= Fila) Then
  292. If (SaldoPendi > V_txtMonto) Then
  293. dgvDetalles.Rows(Index).Cells("Amortizacion").Value = 0
  294. SaldoPendi = 0
  295. Else
  296. For j As Integer = 0 To CantidadFilas - 1
  297. SumaAmortizado += Operaciones.ConvertirDecimal(dgvDetalles.Rows(j).Cells("Amortizacion").Value)
  298. Next
  299. SaldoPendi = SaldoPendiente(Index, SumaAmortizado, V_txtMonto)
  300. If (SumaAmortizado > V_txtMonto) Then
  301. Dim PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
  302. SaldoPendi = PagoPendienteAnterior
  303. dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi
  304. End If
  305. If (Index = CantidadFilas) Then
  306. Dim PagoPendienteAnterior = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value)
  307. SaldoPendi = PagoPendienteAnterior
  308. dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi
  309. End If
  310. End If
  311. If (Salir) Then
  312. End If
  313. Dim FechaProv2 As Date = Date.Now.Date
  314. Dim CambioFecha2 As Boolean = False
  315. If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then
  316. If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then
  317. FechaProv2 = FechaFinal
  318. FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
  319. CambioFecha2 = True
  320. End If
  321. End If
  322. PlazoDatos = Plazo(Index, FechaFinal)
  323. IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
  324. IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, SaldoPendi)
  325. CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
  326. MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
  327. If CambioFecha2 Then
  328. FechaFinal = FechaProv2
  329. CambioFecha2 = False
  330. End If
  331. dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos
  332. dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom
  333. dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt
  334. dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi
  335. dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA
  336. dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir
  337. End If
  338. Else
  339. Dim FechaCorte As String = String.Empty
  340. For Each Valor In diccionario
  341. If Valor.Key = Index Then
  342. FechaCorte = Valor.Value
  343. End If
  344. Next
  345. If String.IsNullOrEmpty(FechaCorte) Then
  346. dgvDetalles.Rows.Add(Index + 1, PlazoDatos, "", FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir)
  347. Else
  348. dgvDetalles.Rows.Add(Index + 1, PlazoDatos, FechaCorte, FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir)
  349. PlazoDatos = Plazo(Index, FechaCorte)
  350. IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
  351. IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaCorte, V_txtTasa, SaldoPendi)
  352. CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
  353. MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
  354. dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos
  355. dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom
  356. dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt
  357. dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi
  358. dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA
  359. dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir
  360. End If
  361. Contador += 1
  362. End If
  363. If (Salir) Then
  364. Exit While
  365. End If
  366. Index += 1
  367. Dim IndexFin = dgvDetalles.Rows.Count - 3
  368. If (Index = IndexFin) Then
  369. Salir = True
  370. End If
  371. End While
  372. End Sub
  373. Function SaldoPendiente(ByVal Index As Integer, ByVal Amortizado As Double, ByVal Monto As Double)
  374. Dim Saldo As Double = 0
  375. Dim FilaAnterior As Integer = Index - 1
  376. Dim SaldoAnterior As Double = 0
  377. Dim PagoPendienteAnterior As Double = 0
  378. Dim PagoPendiente As Double = 0
  379. Dim Amortizacion As Double = 0
  380. If (Index = 0) Then
  381. Saldo = Monto - Amortizado
  382. ElseIf (Index > 0) Then
  383. SaldoAnterior = Monto
  384. PagoPendienteAnterior = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value)
  385. Amortizacion = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index - 1).Cells("Amortizacion").Value)
  386. If (SaldoAnterior = Amortizado) Then
  387. Saldo = 0
  388. ElseIf (SaldoAnterior = Amortizado) Then
  389. Saldo = PagoPendienteAnterior
  390. ElseIf (SaldoAnterior < Amortizado) Then
  391. Saldo = 0
  392. ElseIf (PagoPendienteAnterior = Amortizacion) Then
  393. Saldo = 0
  394. Else
  395. Saldo = SaldoAnterior - Amortizado
  396. End If
  397. End If
  398. If (PagoPendienteAnterior = Amortizacion And Not Amortizacion = 0) Then
  399. Saldo = 0
  400. End If
  401. Return Saldo
  402. End Function
  403. Function Plazo(ByVal Index As Integer, ByVal fecha2 As Date)
  404. Dim fecha1 As Date
  405. Dim Valor
  406. Dim Anterior = Index - 1
  407. If (Index = 0) Then
  408. Valor = 0
  409. ElseIf (Index > 0) Then
  410. fecha1 = dgvDetalles.Rows(Anterior).Cells("Fechas de Pago").Value
  411. fecha1 = Format(fecha1, "yyyy/MM/dd")
  412. fecha2 = Format(fecha2, "yyyy/MM/dd")
  413. Valor = Prestamo.FechaDias(fecha1, fecha2)
  414. Else
  415. Valor = 0
  416. End If
  417. Return Valor
  418. End Function
  419. Function IngresoComision(ByVal Index As Integer, ByVal V_txtComisionDesembolso As Double, ByVal V_txtMonto As Double)
  420. Dim Valor
  421. If (Index = 0) Then
  422. Valor = Operaciones.ConvertirDecimal(V_txtComisionDesembolso.ToString) *
  423. Operaciones.ConvertirDecimal(V_txtMonto.ToString)
  424. Else
  425. Valor = 0
  426. End If
  427. Return Valor
  428. End Function
  429. 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)
  430. If (Index = 0) Then
  431. Return 0
  432. Else
  433. Dim CambioDeFecha As Integer = Operaciones.CambioBase(FechaInicial, FechaFinal)
  434. Dim PrimeraFechaUltima = Operaciones.PrimeraFechaCambioBase(FechaInicial)
  435. Dim UltimaFechaPrimero = Operaciones.FinalFechaCambioBase(FechaFinal)
  436. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  437. Dim Valor1 = 0.0, Valor2 = 0.0, Valor = 0.0
  438. If (Not CambioDeFecha = 0) Then
  439. If CambioDeFecha = 1 Then
  440. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  441. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  442. Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 366
  443. Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 365
  444. ElseIf CambioDeFecha = 2 Then
  445. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  446. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  447. Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 365
  448. Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 366
  449. End If
  450. Valor = Valor1 + Valor2
  451. Else
  452. If (Operaciones.AñoBisiesto(FechaInicial) = 364) Then
  453. Valor = V_txtMonto * V_txtTasa * plazo / 365
  454. End If
  455. If (Operaciones.AñoBisiesto(FechaInicial) = 365) Then
  456. Valor = V_txtMonto * V_txtTasa * plazo / 366
  457. End If
  458. End If
  459. Return Valor
  460. End If
  461. End Function
  462. Function CalculoIVA(ByVal Index As Integer, ByVal IngresoCom As Double, ByVal IngresoInteres As Double)
  463. Dim Valor As Double = 0
  464. If Index = 0 Then
  465. Valor = Operaciones.ConvertirDecimal(IngresoCom.ToString) -
  466. (Operaciones.ConvertirDecimal(IngresoCom.ToString) / (1.13))
  467. Else
  468. Valor = (Operaciones.ConvertirDecimal(IngresoCom.ToString) +
  469. Operaciones.ConvertirDecimal(IngresoInteres.ToString)) * 0.13
  470. End If
  471. Return Valor
  472. End Function
  473. Function CalculoAmortizacion(ByVal Ultimo As Integer, ByVal V_txtMonto As Double)
  474. Dim Monto As Integer = 0
  475. If (Ultimo) Then
  476. Monto = V_txtMonto
  477. End If
  478. Return Monto
  479. End Function
  480. Function MontoARecibir(ByVal IngresoComision As Double, ByVal IngresoInteres As Double, ByVal CalculoIVA As Double, ByVal Amortizacion As Double)
  481. Dim Monto As Double = Operaciones.ConvertirDecimal(txtMonto.Text.ToString)
  482. Dim Valor As Double = 0.0
  483. Valor = IngresoComision + IngresoInteres + CalculoIVA + Amortizacion
  484. If Amortizacion > Monto Then
  485. Valor = 0
  486. End If
  487. Return Valor
  488. End Function
  489. Function Coleccion()
  490. Dim colec As New Collection
  491. Dim fechaoper, fechaven, tasa, periodicidad, base, tipotasa, comisiondesembolso, plazodias, monto
  492. monto = Operaciones.ConvertirDecimal(txtMonto.Text.ToString)
  493. fechaoper = dtpFechaOperacion.Value
  494. fechaven = dtpFechaVencimiento.Value
  495. tasa = Operaciones.ConvertirDecimal(txtTasa.Text.ToString) / 100
  496. periodicidad = cboPeriodicidad.SelectedValue
  497. base = Me.Base
  498. tipotasa = cboTipoTasa.SelectedValue
  499. comisiondesembolso = Operaciones.ConvertirDecimal(txtComisionDesembolso.Text.ToString) / 100
  500. plazodias = Operaciones.ConvertirDecimal(txtPlazoDias.Text.ToString)
  501. colec.Add(monto)
  502. colec.Add(fechaoper)
  503. colec.Add(fechaven)
  504. colec.Add(tasa)
  505. colec.Add(periodicidad)
  506. colec.Add(base)
  507. colec.Add(tipotasa)
  508. colec.Add(comisiondesembolso)
  509. colec.Add(plazodias)
  510. Return colec
  511. End Function
  512. Sub RellenarDatos()
  513. If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then
  514. txtMonto.Text = "0.0"
  515. End If
  516. If (String.IsNullOrEmpty(txtTasa.Text.TrimEnd("%").ToString)) Then
  517. txtTasa.Text = "0.0%"
  518. End If
  519. If (cboTipoTasa.SelectedIndex = -1) Then
  520. cboTipoTasa.SelectedIndex = 0
  521. End If
  522. If (cboBase.SelectedIndex = -1) Then
  523. cboBase.SelectedIndex = 0
  524. End If
  525. If (cboPeriodicidad.SelectedIndex = -1) Then
  526. cboPeriodicidad.SelectedIndex = 0
  527. End If
  528. If (String.IsNullOrEmpty(txtComisionDesembolso.Text.Trim("%").ToString)) Then
  529. txtComisionDesembolso.Text = "0.0%"
  530. End If
  531. If (String.IsNullOrEmpty(txtPlazoDias.Text.ToString)) Then
  532. txtPlazoDias.Text = "0.0"
  533. End If
  534. End Sub
  535. Function ColeccionDetalle(ByVal Index As Integer)
  536. Dim Coleccion As New Collection
  537. Dim plazo, fecha, fechacorte, ingresocomision, ingresointeres, IVA, amortizacion, montorecibir, saldopendiente, correlativo
  538. correlativo = Operaciones.ConvertirEntero(dgvDetalles.Rows(Index).Cells("Correlativo").Value)
  539. plazo = Operaciones.ConvertirEntero(dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value)
  540. fecha = Operaciones.ConvertirFecha(dgvDetalles.Rows(Index).Cells("Fechas de Pago").Value)
  541. ingresocomision = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value)
  542. ingresointeres = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value)
  543. IVA = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("IVA").Value)
  544. amortizacion = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Amortizacion").Value)
  545. saldopendiente = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value)
  546. montorecibir = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value)
  547. fechacorte = Operaciones.ConvertirFechaBaseDatos(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value)
  548. Coleccion.Add(correlativo)
  549. Coleccion.Add(plazo)
  550. Coleccion.Add(fecha)
  551. Coleccion.Add(ingresocomision)
  552. Coleccion.Add(ingresointeres)
  553. Coleccion.Add(IVA)
  554. Coleccion.Add(amortizacion)
  555. Coleccion.Add(saldopendiente)
  556. Coleccion.Add(montorecibir)
  557. Coleccion.Add(fechacorte)
  558. Return Coleccion
  559. End Function
  560. Sub NuevoDetalle(ByVal AgregarModificar As Boolean, ByVal Cantidad As Integer)
  561. Dim i As Integer = 0
  562. Dim Index = dgvDetalles.Rows.Count - 2
  563. i = Cantidad
  564. While i <= Index
  565. Dim coleccion = ColeccionDetalle(i)
  566. If PrestamoConsulta.NuevoDetalle(coleccion, Codigo) Is Nothing Then
  567. Exit Sub
  568. End If
  569. i += 1
  570. End While
  571. MsgBox("Registro de ingresos actualizados")
  572. End Sub
  573. Function ColeccionCampos()
  574. Dim i As Integer = 0
  575. Dim diccionario As New Dictionary(Of String, Collection)
  576. Dim Index = dgvDetalles.Rows.Count - 2
  577. While i <= Index
  578. Dim coleccion = ColeccionDetalle(i)
  579. diccionario.Add(i, coleccion)
  580. i += 1
  581. End While
  582. Return diccionario
  583. End Function
  584. Sub EliminarDetalles(ByVal CantidadRegistros As Integer, ByVal Cantidad As Integer)
  585. Dim i As Integer = 0
  586. Dim Index = CantidadRegistros + 1
  587. i = Cantidad
  588. While i >= Index
  589. If PrestamoConsulta.EliminarDetalles(Index, Codigo) Is Nothing Then
  590. Exit Sub
  591. End If
  592. Index += 1
  593. End While
  594. End Sub
  595. Function ColeccionNuevo(ByVal codigo As String)
  596. Dim i As Integer = 0
  597. Dim diccionario As New Dictionary(Of String, Collection)
  598. Dim Index = dgvDetalles.Rows.Count - 2
  599. While i <= Index
  600. Dim coleccion = ColeccionDetalle(i)
  601. diccionario.Add(i, coleccion)
  602. i += 1
  603. End While
  604. Return diccionario
  605. End Function
  606. Function ColeccionEliminar(ByVal codigo As String)
  607. Dim CantidadRegistros As Integer = dgvDetalles.Rows.Count - 1
  608. Dim Cantidad As Integer = CanRegistros()
  609. Dim i As Integer = 0
  610. Dim diccionario As New Dictionary(Of Integer, String)
  611. Dim Index = CantidadRegistros + 1
  612. i = Cantidad
  613. While i >= Index
  614. diccionario.Add(Index, codigo)
  615. Index += 1
  616. End While
  617. Return diccionario
  618. End Function
  619. Sub EliminarDatos(ByVal codigo As String)
  620. PrestamoConsulta.Eliminar(codigo)
  621. End Sub
  622. Private Sub dgvDetalles_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellContentClick
  623. End Sub
  624. Private Sub dgvDetalles_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellEndEdit
  625. Calculos(True, False)
  626. End Sub
  627. Private Sub cboBase_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboBase.SelectedIndexChanged
  628. Formato()
  629. If (cboBase.SelectedIndex = 0) Then
  630. Base = 360
  631. Else
  632. Base = 365
  633. End If
  634. End Sub
  635. Sub CargarDato()
  636. Dim codigo As String = Variables.Codigo
  637. Dim Retorno = PrestamoConsulta.CargarDato(codigo)
  638. Dim coleccion As New Collection
  639. If (TypeOf Retorno Is Boolean) Then
  640. Exit Sub
  641. Else
  642. coleccion = PrestamoConsulta.CargarDato(codigo)
  643. End If
  644. Dim Index As Integer = 0
  645. If (coleccion(6).ToString = "360") Then
  646. Index = 0
  647. Else
  648. Index = 1
  649. End If
  650. txtMonto.Text = Operaciones.ConvertirDecimal(coleccion(1).ToString)
  651. dtpFechaOperacion.Value = Operaciones.ConvertirFecha(coleccion(2).ToString)
  652. dtpFechaVencimiento.Value = Operaciones.ConvertirFecha(coleccion(3).ToString)
  653. txtTasa.Text = (Operaciones.ConvertirDecimal(coleccion(4).ToString) * 100).ToString + "%"
  654. cboPeriodicidad.SelectedValue = coleccion(5).ToString
  655. cboBase.SelectedIndex = Index
  656. cboTipoTasa.SelectedValue = coleccion(7).ToString
  657. txtComisionDesembolso.Text = (Operaciones.ConvertirDecimal(coleccion(8).ToString) * 100).ToString + "%"
  658. txtPlazoDias.Text = Operaciones.ConvertirEntero(coleccion(9).ToString)
  659. End Sub
  660. Function CargarDetalles()
  661. Dim codigo As String = Variables.Codigo
  662. Dim dr = PrestamoConsulta.CargarDetalles(codigo)
  663. Dim Datos As Boolean = False
  664. If (Not dr Is Nothing) Then
  665. Dim Iterador As Integer = 0
  666. Dim ConvertirString As String
  667. While dr.Read
  668. ConvertirString = Format(Operaciones.ConvertirFecha(dr("fechapago").ToString), "dd/MM/yyyy")
  669. dgvDetalles.Rows.Add(Operaciones.ConvertirEntero(dr("correlativo").ToString),
  670. Operaciones.ConvertirEntero(dr("plazo").ToString),
  671. Operaciones.ConvertirFechaBaseDatos(dr("fechacorte").ToString),
  672. Operaciones.ConvertirFecha(ConvertirString),
  673. Operaciones.ConvertirDecimal(dr("ingresarcomision").ToString),
  674. Operaciones.ConvertirDecimal(dr("ingresarinteres").ToString),
  675. Operaciones.ConvertirDecimal(dr("IVA").ToString),
  676. Operaciones.ConvertirDecimal(dr("amortizacion").ToString),
  677. Operaciones.ConvertirDecimal(dr("saldopendiente").ToString),
  678. Operaciones.ConvertirDecimal(dr("montorecibir").ToString))
  679. End While
  680. Datos = True
  681. End If
  682. Return Datos
  683. End Function
  684. Private Sub btnAccion_Click(sender As Object, e As EventArgs) Handles btnAccion.Click
  685. Dim codigo As String = Variables.Codigo
  686. Dim Colec As Collection = Coleccion()
  687. Dim Diccionario As Dictionary(Of Integer, String) = ColeccionEliminar(codigo)
  688. Dim Diccionario2 As Dictionary(Of String, Collection) = ColeccionNuevo(codigo)
  689. If (Estado = "N") Then
  690. PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Nuevo")
  691. ElseIf Not ExisteValidacion() Then
  692. Variables.ColeccionPEMP = Coleccion()
  693. Variables.ColeccionPEMPDi = ColeccionCampos()
  694. Me.Close()
  695. End If
  696. If (Estado = "M") Then
  697. PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Modificar")
  698. End If
  699. If (Estado = "B") Then
  700. EliminarDatos(codigo)
  701. End If
  702. ValidarExistencia()
  703. End Sub
  704. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  705. Estado = "M"
  706. btnAccion.Text = "Modificar"
  707. End Sub
  708. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  709. Estado = "N"
  710. btnAccion.Text = "Agregar"
  711. ' btnagregar.Text = "Agregar"
  712. End Sub
  713. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  714. Estado = "B"
  715. btnAccion.Text = "Eliminar"
  716. End Sub
  717. Private Sub btnagregar_Click(sender As Object, e As EventArgs)
  718. End Sub
  719. Private Sub txtMonto_TextChanged(sender As Object, e As EventArgs) Handles txtMonto.TextChanged
  720. If (FinCarga) Then
  721. Calculos(False, False)
  722. End If
  723. End Sub
  724. Private Sub txtTasa_TextChanged(sender As Object, e As EventArgs) Handles txtTasa.TextChanged
  725. If (FinCarga) Then
  726. Calculos(False, False)
  727. End If
  728. End Sub
  729. Private Sub txtComisionDesembolso_TextChanged(sender As Object, e As EventArgs) Handles txtComisionDesembolso.TextChanged
  730. If (FinCarga) Then
  731. Calculos(False, False)
  732. End If
  733. End Sub
  734. Private Sub txtMonto_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonto.KeyPress
  735. If String.IsNullOrEmpty(txtMonto.Text) Then
  736. If e.KeyChar = "." Then
  737. txtMonto.Text = "0"
  738. Exit Sub
  739. End If
  740. End If
  741. If (Not txtMonto.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  742. Operaciones.ValidarEntrada(sender, e, True)
  743. Else
  744. Operaciones.ValidarEntrada(sender, e, False)
  745. End If
  746. End Sub
  747. Private Sub txtTasa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasa.KeyPress
  748. If String.IsNullOrEmpty(txtTasa.Text) Then
  749. If e.KeyChar = "." Then
  750. txtTasa.Text = "0"
  751. Exit Sub
  752. End If
  753. End If
  754. If (Not txtTasa.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  755. Operaciones.ValidarEntrada(sender, e, True)
  756. Else
  757. Operaciones.ValidarEntrada(sender, e, False)
  758. End If
  759. End Sub
  760. Private Sub txtComisionDesembolso_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionDesembolso.KeyPress
  761. If String.IsNullOrEmpty(txtComisionDesembolso.Text) Then
  762. If e.KeyChar = "." Then
  763. txtComisionDesembolso.Text = "0"
  764. Exit Sub
  765. End If
  766. End If
  767. If (Not txtComisionDesembolso.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  768. Operaciones.ValidarEntrada(sender, e, True)
  769. Else
  770. Operaciones.ValidarEntrada(sender, e, False)
  771. End If
  772. End Sub
  773. Private Sub btnCancelar_Click(sender As Object, e As EventArgs)
  774. Cancelar()
  775. End Sub
  776. Sub Cancelar()
  777. End Sub
  778. Private Sub txtMonto_Leave(sender As Object, e As EventArgs) Handles txtMonto.Leave
  779. Formato()
  780. End Sub
  781. Private Sub txtTasa_Leave(sender As Object, e As EventArgs) Handles txtTasa.Leave
  782. Formato()
  783. End Sub
  784. Private Sub cboTipoTasa_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTipoTasa.SelectedIndexChanged
  785. Formato()
  786. End Sub
  787. Private Sub cboPeriodicidad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPeriodicidad.SelectedIndexChanged
  788. Formato()
  789. End Sub
  790. Private Sub txtComisionDesembolso_Leave(sender As Object, e As EventArgs) Handles txtComisionDesembolso.Leave
  791. Formato()
  792. End Sub
  793. Private Sub txtPlazoDias_Leave(sender As Object, e As EventArgs) Handles txtPlazoDias.Leave
  794. Formato()
  795. End Sub
  796. Private Sub txtMonto_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMonto.KeyUp
  797. If txtMonto.Text = "." Then
  798. txtMonto.Text = ".0"
  799. End If
  800. End Sub
  801. Private Sub txtTasa_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasa.KeyUp
  802. If txtTasa.Text = "." Then
  803. txtTasa.Text = ".0"
  804. End If
  805. End Sub
  806. Private Sub txtComisionDesembolso_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionDesembolso.KeyUp
  807. If txtComisionDesembolso.Text = "." Then
  808. txtComisionDesembolso.Text = ".0"
  809. End If
  810. End Sub
  811. Sub CargarTransladoNuevo()
  812. Dim Existe As Boolean = ExisteInversion()
  813. If Not RetCodigoInversionExiste And Not Existe Then
  814. txtMonto.Text = Variables.RetMonto
  815. txtTasa.Text = Variables.RetRendimiento
  816. End If
  817. End Sub
  818. End Class