frmPrestamoEmpresariales.vb 36 KB

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