frmResultadoTitularizacion.vb 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. 
  2. Imports System.Data.OleDb
  3. Imports System.IO
  4. Public Class frmResultadoTitularizacion
  5. Dim Estado As String = String.Empty
  6. Dim Codigo = Variables.Codigo
  7. Dim TitularizacionConsulta As New TitularizacionDAO
  8. Dim oDAOGeneral As New DAOGeneral
  9. Dim Operaciones As New Operaciones
  10. Dim IndexBase As Integer = 0
  11. Public FechaRedencion As Date = Date.Today.Date
  12. Private Sub txtRendimientoAntesISR_Op_TextChanged(sender As Object, e As EventArgs)
  13. End Sub
  14. Private Sub txtRendimientoIntereses_Op_TextChanged(sender As Object, e As EventArgs)
  15. End Sub
  16. Private Sub txtRendimientoGananciaPerdida_Op_TextChanged(sender As Object, e As EventArgs)
  17. End Sub
  18. Private Sub txtGananciaPerdidaTotal_Op_TextChanged(sender As Object, e As EventArgs)
  19. End Sub
  20. Private Sub txtCostosTotales_Op_TextChanged(sender As Object, e As EventArgs)
  21. End Sub
  22. Private Sub txtIngresosPorIntereses_Op_TextChanged(sender As Object, e As EventArgs)
  23. End Sub
  24. Private Sub txtGananciaPerdidaCapital_Op_TextChanged(sender As Object, e As EventArgs)
  25. End Sub
  26. Private Sub txtPrecioVenta_Op_TextChanged(sender As Object, e As EventArgs)
  27. End Sub
  28. Private Sub txtPrecioCompra_Op_TextChanged(sender As Object, e As EventArgs)
  29. End Sub
  30. Private Sub txtPlazo_Op_TextChanged(sender As Object, e As EventArgs)
  31. End Sub
  32. Private Sub txtValorNominal_Op_TextChanged(sender As Object, e As EventArgs)
  33. End Sub
  34. Private Sub Label35_Click(sender As Object, e As EventArgs)
  35. End Sub
  36. Private Sub lblRendimientoDespuesISR_Op_Click(sender As Object, e As EventArgs)
  37. End Sub
  38. Private Sub lblRendimientoAntesISR_Op_Click(sender As Object, e As EventArgs)
  39. End Sub
  40. Private Sub lblRendimientoIntereses_Op_Click(sender As Object, e As EventArgs)
  41. End Sub
  42. Private Sub lblRendimientoGananciaPerdida_Op_Click(sender As Object, e As EventArgs)
  43. End Sub
  44. Private Sub lblGananciaPerdidaTotal_Op_Click(sender As Object, e As EventArgs)
  45. End Sub
  46. Private Sub lblCostosTotales_Op_Click(sender As Object, e As EventArgs)
  47. End Sub
  48. Private Sub lblIngresosPorIntereses_Op_Click(sender As Object, e As EventArgs)
  49. End Sub
  50. Private Sub label27_Click(sender As Object, e As EventArgs)
  51. End Sub
  52. Private Sub Label26_Click(sender As Object, e As EventArgs)
  53. End Sub
  54. Private Sub Label25_Click(sender As Object, e As EventArgs)
  55. End Sub
  56. Private Sub Label24_Click(sender As Object, e As EventArgs)
  57. End Sub
  58. Private Sub Label23_Click(sender As Object, e As EventArgs)
  59. End Sub
  60. Private Sub frmResultadoTitularizacion_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  61. AgregarColumnasAmortCap()
  62. AgregarColumnasAmort()
  63. CargarTIT()
  64. CargarAmortCap()
  65. CargarAmort()
  66. ExisteInversion()
  67. ValidarExistencia()
  68. Formato()
  69. CargarIndexBase()
  70. DefinirVigencia()
  71. End Sub
  72. Sub CargarIndexBase()
  73. Dim Index As String = Variables.BaseTIT
  74. If Index = "0" Then
  75. IndexBase = CInt(Index)
  76. ElseIf Index = "1" Then
  77. IndexBase = CInt(Index)
  78. ElseIf Index = "2" Then
  79. IndexBase = CInt(Index)
  80. ElseIf Index = "3" Then
  81. IndexBase = CInt(Index)
  82. End If
  83. End Sub
  84. Function ExisteInversion()
  85. Dim Codigo As String = Variables.Codigo
  86. Dim TablaINV As String = "INV0"
  87. Dim TablaPINV As String = "PIN0"
  88. Dim General As New DAOGeneral
  89. Dim InvPro = Variables.InvPro
  90. If InvPro = "I" Then
  91. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  92. If INV0 Then
  93. navNuevo.Visible = True
  94. Return True
  95. Else
  96. navNuevo.Visible = False
  97. Return False
  98. End If
  99. End If
  100. If InvPro = "P" Then
  101. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  102. If PINV0 Then
  103. navNuevo.Visible = True
  104. Return True
  105. Else
  106. navNuevo.Visible = False
  107. Return False
  108. End If
  109. End If
  110. Return False
  111. End Function
  112. Sub AgregarColumnasAmortCap()
  113. Dim Correlativo, Fecha, CesionFlujo, AmortCapital, Interes, Amortizacion, Saldos, Vigente As New DataGridViewTextBoxColumn
  114. Correlativo.Name = " "
  115. Fecha.Name = "Fecha"
  116. CesionFlujo.Name = " Cesión de Flujo"
  117. AmortCapital.Name = "Amortizacion Capital "
  118. Interes.Name = "Interés"
  119. Amortizacion.Name = "Amortizacion"
  120. Saldos.Name = "Saldos"
  121. End Sub
  122. Sub ValidarExistencia()
  123. Dim General As New DAOGeneral
  124. Dim Codigo As String = Variables.Codigo
  125. Dim Tabla As String = String.Empty
  126. Tabla = "TIT0"
  127. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  128. If (Existe) Then
  129. navNuevo.Enabled = False
  130. TbAmortizacion.Enabled = True
  131. navModificar.Enabled = True
  132. navEliminar.Enabled = True
  133. Else
  134. navNuevo.Enabled = True
  135. TbAmortizacion.Enabled = False
  136. navModificar.Enabled = False
  137. navEliminar.Enabled = False
  138. End If
  139. Estado = String.Empty
  140. btnTit0.Text = "Aceptar"
  141. End Sub
  142. Sub AgregarColumnasAmort()
  143. Dim Correlativo, Fecha, Dias, Cuota, AmortCapital, Interes, Saldos, Porcentaje, Vigente As New DataGridViewTextBoxColumn
  144. Correlativo.Name = "Correlativo"
  145. Fecha.Name = "Fecha"
  146. Dias.Name = "Dias"
  147. Cuota.Name = "Cuotas"
  148. AmortCapital.Name = "Amortizacion de Capital"
  149. Interes.Name = "Interés"
  150. Saldos.Name = "Saldos"
  151. Porcentaje.Name = "Porcentaje"
  152. Vigente.Name = "Vigente"
  153. Vigente.Visible = False
  154. dgvAmortizacion.Columns.Add(Correlativo)
  155. dgvAmortizacion.Columns.Add(Porcentaje)
  156. dgvAmortizacion.Columns.Add(Fecha)
  157. dgvAmortizacion.Columns.Add(Dias)
  158. dgvAmortizacion.Columns.Add(Cuota)
  159. dgvAmortizacion.Columns.Add(AmortCapital)
  160. dgvAmortizacion.Columns.Add(Interes)
  161. dgvAmortizacion.Columns.Add(Saldos)
  162. dgvAmortizacion.Columns.Add(Vigente)
  163. End Sub
  164. Function ColeccionesTIT()
  165. Dim coleccion As New Collection
  166. Dim Tasa, MontoCompra, MontoCompraPrimario As Double
  167. Dim FechaEmision As Date = Date.Now.Date
  168. FechaEmision = dtpFechaEmision.Value
  169. Tasa = CDec(txtTasaEmision.Text.ToString.Trim("%")) / 100
  170. MontoCompra = txtMontoCompraEmision.Text
  171. MontoCompraPrimario = txtMontoCompraPrimario.Text
  172. coleccion.Add(FechaEmision)
  173. coleccion.Add(Tasa)
  174. coleccion.Add(MontoCompra)
  175. coleccion.Add(MontoCompraPrimario)
  176. Return coleccion
  177. End Function
  178. Function ColeccionAmort(ByVal Index As Integer)
  179. Dim coleccion As New Collection
  180. Dim Correlativo, Fecha2, Dias, Cuota, AmortCap2, Interes2, Saldo2, Porcentaje, Vigente As String
  181. If Not coleccion.Count < 0 Then
  182. Correlativo = dgvAmortizacion.Rows(Index).Cells("Correlativo").Value
  183. Porcentaje = dgvAmortizacion.Rows(Index).Cells("Porcentaje").Value
  184. Fecha2 = dgvAmortizacion.Rows(Index).Cells("Fecha").Value
  185. Dias = dgvAmortizacion.Rows(Index).Cells("Dias").Value
  186. Cuota = dgvAmortizacion.Rows(Index).Cells("Cuotas").Value
  187. AmortCap2 = dgvAmortizacion.Rows(Index).Cells("Amortizacion de Capital").Value
  188. Interes2 = dgvAmortizacion.Rows(Index).Cells("Interés").Value
  189. Saldo2 = dgvAmortizacion.Rows(Index).Cells("Saldos").Value
  190. Vigente = dgvAmortizacion.Rows(Index).Cells("Vigente").Value
  191. If Vigente = "True" Then
  192. Vigente = "1"
  193. Else
  194. Vigente = "0"
  195. End If
  196. coleccion.Add(Correlativo)
  197. coleccion.Add(Fecha2)
  198. coleccion.Add(Dias)
  199. coleccion.Add(Cuota)
  200. coleccion.Add(AmortCap2)
  201. coleccion.Add(Interes2)
  202. coleccion.Add(Saldo2)
  203. coleccion.Add(Porcentaje)
  204. coleccion.Add(Vigente)
  205. End If
  206. Return coleccion
  207. End Function
  208. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  209. btnTit0.Text = "Modificar"
  210. Estado = "M"
  211. End Sub
  212. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  213. btnTit0.Text = "Nuevo"
  214. Estado = "N"
  215. End Sub
  216. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  217. btnTit0.Text = "Eliminar"
  218. Estado = "B"
  219. End Sub
  220. Private Sub btnTit0_Click(sender As Object, e As EventArgs) Handles btnTit0.Click
  221. Dim codigo As String = Variables.Codigo
  222. Dim DatosAmortizacion As Collection = ColeccionesTIT()
  223. Dim Amortizacion As Dictionary(Of String, Collection) = coleccionNueva()
  224. If (Estado = "N") Then
  225. TitularizacionConsulta.ProcesoDatos(DatosAmortizacion, codigo, Amortizacion, "Nuevo")
  226. ElseIf (Estado = "M") Then
  227. TitularizacionConsulta.ProcesoDatos(DatosAmortizacion, codigo, Amortizacion, "Modificar")
  228. ElseIf (Estado = "B") Then
  229. EliminarTIT()
  230. End If
  231. ValidarExistencia()
  232. End Sub
  233. Sub NuevoTIT()
  234. Dim coleccion = ColeccionesTIT()
  235. TitularizacionConsulta.NuevaTIT(coleccion, Codigo)
  236. End Sub
  237. Sub NuevoAmortCap()
  238. End Sub
  239. Sub ModificarAmort()
  240. Dim i As Integer = 0
  241. Dim CantidadRegistrosDB = CanRegistros()
  242. While i < CantidadRegistrosDB
  243. Dim coleccion = ColeccionAmort(i)
  244. If (TitularizacionConsulta.ModificarAmort(coleccion, Codigo) Is Nothing) Then
  245. Exit Sub
  246. End If
  247. i += 1
  248. End While
  249. NuevoAmort(CantidadRegistrosDB)
  250. End Sub
  251. Sub NuevoAmort(ByVal Cantidad As Integer)
  252. Dim i As Integer = 0
  253. Dim Index = dgvAmortizacion.Rows.Count - 1
  254. i = Cantidad
  255. While i <= Index
  256. Dim coleccion = ColeccionAmort(i)
  257. If TitularizacionConsulta.NuevaAmort(coleccion, Codigo) Is Nothing Then
  258. Exit Sub
  259. End If
  260. i += 1
  261. End While
  262. MsgBox("Registro de ingresos actualizados")
  263. End Sub
  264. Function coleccionNueva()
  265. Dim i As Integer = 0
  266. Dim Index = dgvAmortizacion.Rows.Count - 1
  267. Dim diccionario As New Dictionary(Of String, Collection)
  268. While i <= Index
  269. Dim coleccion = ColeccionAmort(i)
  270. diccionario.Add(i, coleccion)
  271. i += 1
  272. End While
  273. Return diccionario
  274. End Function
  275. Function CanRegistros()
  276. Dim oDAOGeneral As New DAOGeneral
  277. Dim Codigo = Variables.Codigo
  278. Dim Cantidad As Integer = oDAOGeneral.CantidadRegistros(Codigo, "TIT2")
  279. Return Cantidad
  280. End Function
  281. Sub ModificarTIT()
  282. Dim coleccion = ColeccionesTIT()
  283. TitularizacionConsulta.ModificarTIT(coleccion, Codigo)
  284. End Sub
  285. Sub ModificarAmortCap()
  286. End Sub
  287. Sub EliminarTIT()
  288. Dim Eliminado As Boolean = TitularizacionConsulta.Eliminar(Codigo)
  289. If Eliminado Then
  290. dgvAmortizacion.Rows.Clear()
  291. End If
  292. End Sub
  293. Sub EliminarAmortCap()
  294. End Sub
  295. Sub EliminarAmort()
  296. Dim Correlativo = dgvAmortizacion.CurrentRow.Cells("Correlativo").Value
  297. TitularizacionConsulta.EliminarAmort(Codigo, Correlativo)
  298. End Sub
  299. Sub CargarTIT()
  300. Dim coleccion As Collection = TitularizacionConsulta.CargarTIT(Codigo)
  301. If (Not coleccion.Count = 0) Then
  302. dtpFechaEmision.Value = coleccion(1)
  303. txtTasaEmision.Text = CDec(coleccion(2)) * 100
  304. txtMontoCompraEmision.Text = coleccion(3)
  305. txtMontoCompraPrimario.Text = coleccion(4)
  306. End If
  307. End Sub
  308. Sub CargarAmortCap()
  309. Dim dr = TitularizacionConsulta.CargarAmortCap(Codigo)
  310. Dim Iterador As Integer = 0
  311. Dim ConvertirString As String
  312. While dr.Read
  313. ConvertirString = Format(dr("Fecha"), "dd/MM/yyyy")
  314. End While
  315. End Sub
  316. Sub CargarAmort()
  317. Dim dr = TitularizacionConsulta.CargarAmort(Codigo)
  318. Dim Iterador As Integer = 0
  319. Dim ConvertirString As String
  320. While dr.Read
  321. ConvertirString = Format(dr("Fecha"), "dd/MM/yyyy")
  322. Dim Vigente As String = dr("Vigente").ToString
  323. If String.IsNullOrEmpty(Vigente) Then
  324. Vigente = "1"
  325. End If
  326. If Vigente = "1" Then
  327. Vigente = "True"
  328. Else
  329. Vigente = "False"
  330. End If
  331. dgvAmortizacion.Rows.Add(dr("Correlativo"), dr("Porcentaje"), ConvertirString, dr("Dias"), dr("Cuota"), dr("AmortCap"), dr("Interes"), dr("Saldos"), Vigente)
  332. End While
  333. End Sub
  334. Private Sub btnAmortCap_Click(sender As Object, e As EventArgs)
  335. If (Estado = "N") Then
  336. NuevoAmortCap()
  337. ElseIf (Estado = "M") Then
  338. ModificarAmortCap()
  339. ElseIf (Estado = "B") Then
  340. EliminarAmortCap()
  341. End If
  342. End Sub
  343. Private Sub btnAmort_Click(sender As Object, e As EventArgs)
  344. If (Estado = "N") Then
  345. ModificarAmort()
  346. ElseIf (Estado = "M") Then
  347. ModificarAmort()
  348. ElseIf (Estado = "B") Then
  349. EliminarAmort()
  350. End If
  351. End Sub
  352. Function GenerarFecha()
  353. Dim Fecha As Date = Date.Now.Date
  354. Fecha = Format(Fecha, "dd/MM/yyyy")
  355. Return Fecha
  356. End Function
  357. Sub LLenarFechaAmortCap()
  358. Dim Fecha As String = GenerarFecha()
  359. End Sub
  360. Sub LLenarFechaAmort()
  361. Dim Cantidad As Integer = dgvAmortizacion.Rows.Count - 1
  362. Dim Index As Integer = 0
  363. Dim MesFijo As Date = dtpFechaEmision.Value
  364. Dim Periodicidad As String = Variables.PeriodicidadTIT
  365. Dim TipoPeriodicidad As Integer = 0
  366. If (Periodicidad = "M") Then
  367. TipoPeriodicidad = 1
  368. ElseIf (Periodicidad = "T") Then
  369. TipoPeriodicidad = 3
  370. ElseIf (Periodicidad = "S") Then
  371. TipoPeriodicidad = 6
  372. ElseIf (Periodicidad = "A") Then
  373. TipoPeriodicidad = 12
  374. Else
  375. TipoPeriodicidad = 1
  376. End If
  377. While Index <= Cantidad
  378. Dim FechaIni As Date = Date.Today.Date
  379. Dim Fecha = Format(FechaIni, "dd/MM/yyyy")
  380. Dim IndexAnterior As Integer = Index - 1
  381. If Index = 0 Then
  382. FechaIni = MesFijo
  383. Else
  384. FechaIni = dgvAmortizacion.Rows(IndexAnterior).Cells("Fecha").Value
  385. End If
  386. Fecha = Operaciones.Meses(TipoPeriodicidad, FechaIni, MesFijo)
  387. If (String.IsNullOrEmpty(dgvAmortizacion.Rows(Index).Cells("Fecha").Value)) Then
  388. dgvAmortizacion.Rows(Index).Cells("Fecha").Value = Format(CDate(Fecha), "dd/MM/yyyy")
  389. End If
  390. Index += 1
  391. End While
  392. End Sub
  393. Private Sub dgvAmortizacionCapital_CellClick(sender As Object, e As DataGridViewCellEventArgs)
  394. LLenarFechaAmortCap()
  395. End Sub
  396. Private Sub dgvAmortizacion_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAmortizacion.CellClick
  397. End Sub
  398. Function CalcularSaldos(ByVal Posicion As Double, ByVal Emistot As Double, ByVal AmortCap As Double, ByVal PosicionAnterior As Integer)
  399. Dim Saldos As Double = 0
  400. If Posicion = 0 Then
  401. Saldos = Emistot - AmortCap
  402. ElseIf (Posicion > 0) Then
  403. End If
  404. Return Saldos
  405. End Function
  406. Function CalcularAmort(ByVal Total As Double, ByVal AmortCap As Double)
  407. Dim Amort As Double = 0
  408. If (Not Total = 0) Then
  409. Amort = AmortCap / Total
  410. End If
  411. Return Amort
  412. End Function
  413. Function CalcularInteres(ByVal CF As Double, ByVal AmortCap As Double)
  414. Dim Interes As Double = 0
  415. Interes = CF - AmortCap
  416. Return Interes
  417. End Function
  418. Sub CalculosAmort()
  419. Dim Cantidad = 0, Dias = 0, Fecha = Date.Now.Date, FechaEmis = Date.Now.Date, Cuota = 0.0, Amort = 0.0, Interes = 0.0, Saldo = 0.0, AmortPriTabla = 0.0, SaldoAnterior = 0.0, Posicion, PosicionAnterior, PosicionSiguiente
  420. Posicion = dgvAmortizacion.Rows.Count - 1
  421. FechaEmis = dtpFechaEmision.Value
  422. For index As Integer = 0 To Posicion
  423. PosicionAnterior = index - 1
  424. PosicionSiguiente = index + 1
  425. Fecha = dgvAmortizacion.Rows(index).Cells("Fecha").Value
  426. SaldoAnterior = CalculosSaldoAnterior(PosicionAnterior)
  427. Dias = CalculosDias(index, FechaEmis, Fecha, PosicionAnterior)
  428. Amort = CalculosAmort2(index, Posicion, AmortPriTabla)
  429. Interes = CalculosInteres2(index, SaldoAnterior, Dias, FechaEmis, Fecha, IndexBase)
  430. Saldo = CalcularSaldos2(index, SaldoAnterior, Amort)
  431. Cuota = Amort + Interes
  432. dgvAmortizacion.Rows(index).Cells("Dias").Value = Dias
  433. dgvAmortizacion.Rows(index).Cells("Cuotas").Value = Cuota
  434. dgvAmortizacion.Rows(index).Cells("Amortizacion de Capital").Value = Amort
  435. dgvAmortizacion.Rows(index).Cells("Interés").Value = Interes
  436. dgvAmortizacion.Rows(index).Cells("Saldos").Value = Saldo
  437. dgvAmortizacion.Rows(index).Cells("Vigente").Value = "True"
  438. FechaEmis = Fecha
  439. Next
  440. End Sub
  441. Function CalcularCuota(ByVal Amort As Double, ByVal Interes As Double)
  442. Dim Cuota As Double = 0
  443. Cuota = Amort + Interes
  444. Return Cuota
  445. End Function
  446. Function CalcularSaldos2(ByVal Posicion As Integer, ByVal SaldoAnterior As Double, ByVal Amort As Double)
  447. Dim Saldo As Double = 0
  448. If (Posicion = 0) Then
  449. Saldo = (CDec(txtMontoCompraEmision.Text)) - Amort
  450. ElseIf (Posicion > 0) Then
  451. Saldo = SaldoAnterior - Amort
  452. Else
  453. Saldo = 0
  454. End If
  455. Return Saldo
  456. End Function
  457. Function CalculosInteres2(ByVal Posicion As Integer, ByVal SaldoAnterior As Double, ByVal Dias As Integer, ByVal Fecha1 As Date, ByVal Fecha2 As Date, ByVal IndexBase As Integer)
  458. Dim Saldo As Double = 0
  459. Dim Tasa As Double = 0
  460. If (Posicion = 0) Then
  461. Saldo = CDec(txtMontoCompraEmision.Text)
  462. ElseIf (Posicion > 0) Then
  463. Saldo = (CDec(SaldoAnterior))
  464. Else
  465. Saldo = 0
  466. End If
  467. Tasa = CDec(txtTasaEmision.Text.ToString.Trim("%"))
  468. Dim Valor As Double = 0
  469. If (IndexBase = 0) Then
  470. Valor = (Saldo * (Tasa / 100) * Dias) / 360
  471. Return Valor
  472. ElseIf (IndexBase = 1) Then
  473. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  474. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  475. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  476. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  477. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  478. PrOpc1 = (Saldo * (Tasa / 100) * DiasPrimeraFecha) / 366
  479. PrOpc2 = (Saldo * (Tasa / 100) * DiasSegundaFecha) / 365
  480. Valor = PrOpc1 + PrOpc2
  481. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  482. Valor = (Saldo * (Tasa / 100) * DiasSegundaFecha) / 365
  483. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  484. Valor = (Saldo * (Tasa / 100) * DiasPrimeraFecha) / 366
  485. Else
  486. Valor = 0
  487. End If
  488. Return Valor
  489. ElseIf (IndexBase = 2) Then
  490. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  491. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  492. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha360Bi(Fecha1, Fecha2)
  493. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha360(Fecha1, Fecha2)
  494. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  495. PrOpc1 = (Saldo * (Tasa / 100) * DiasPrimeraFecha) / 366
  496. PrOpc2 = (Saldo * (Tasa / 100) * DiasSegundaFecha) / 365
  497. Valor = PrOpc1 + PrOpc2
  498. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  499. Valor = (Saldo * (Tasa / 100) * DiasSegundaFecha) / 365
  500. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  501. Valor = (Saldo * (Tasa / 100) * DiasPrimeraFecha) / 366
  502. Else
  503. Valor = 0
  504. End If
  505. Return Valor
  506. Else
  507. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  508. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  509. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366Varios(Fecha1, Fecha2)
  510. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365Varios(Fecha1, Fecha2)
  511. If (DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  512. PrOpc1 = (Saldo * (Tasa / 100) * DiasPrimeraFecha) / 360
  513. PrOpc2 = (Saldo * (Tasa / 100) * DiasSegundaFecha) / 360
  514. Valor = PrOpc1 + PrOpc2
  515. ElseIf (Not DiasPrimeraFecha > 0 And DiasSegundaFecha > 0) Then
  516. Valor = (Saldo * (Tasa / 100) * DiasSegundaFecha) / 360
  517. ElseIf (DiasPrimeraFecha > 0 And Not DiasSegundaFecha > 0) Then
  518. Valor = (Saldo * (Tasa / 100) * DiasPrimeraFecha) / 360
  519. Else
  520. Valor = 0
  521. End If
  522. Return Valor
  523. End If
  524. Return Valor
  525. End Function
  526. Function CalculosAmort2(ByVal Index As Integer, ByVal Cantidad As Integer, ByVal AmortPriTabla As Double)
  527. Dim Amort As Double = 0
  528. AmortPriTabla = dgvAmortizacion.Rows(Index).Cells("Porcentaje").Value
  529. Amort = AmortPriTabla * CDec(txtMontoCompraPrimario.Text)
  530. Return Amort
  531. End Function
  532. Function CalculosDias(ByVal Posicion As Integer, ByVal FechaEmis As Date, ByVal Fecha As Date, ByVal PosicionAnterior As Integer)
  533. Dim Dias As Integer = 0
  534. If (Posicion = 0) Then
  535. Dias = DateDiff(DateInterval.Day, FechaEmis, Fecha)
  536. ElseIf (Posicion > 0) Then
  537. Dim FechaAnterior As Date = Date.Now.Date
  538. FechaAnterior = dgvAmortizacion.Rows(PosicionAnterior).Cells("Fecha").Value
  539. Dias = DateDiff(DateInterval.Day, FechaAnterior, Fecha)
  540. End If
  541. Return Dias
  542. End Function
  543. Function CalculosSaldoAnterior(ByVal PosicionAnterior As Integer)
  544. Dim SaldoAnterior As Double = 0
  545. If (PosicionAnterior >= 0) Then
  546. SaldoAnterior = dgvAmortizacion.Rows(PosicionAnterior).Cells("Saldos").Value
  547. End If
  548. Return SaldoAnterior
  549. End Function
  550. Private Sub dgvAmortizacionCapital_KeyUp(sender As Object, e As KeyEventArgs)
  551. End Sub
  552. Private Sub dgvAmortizacion_KeyUp(sender As Object, e As KeyEventArgs) Handles dgvAmortizacion.KeyUp
  553. End Sub
  554. Private Sub dgvAmortizacionCapital_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
  555. End Sub
  556. Private Sub dgvAmortizacionCapital_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs)
  557. End Sub
  558. Private Sub dgvAmortizacion_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAmortizacion.CellEndEdit
  559. End Sub
  560. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles TbAmortizacion.Click, btnExcel.Click
  561. CargarExcel()
  562. End Sub
  563. Sub CargarExcel()
  564. Dim result As DialogResult = OpenFileDialog1.ShowDialog()
  565. ' Test result.
  566. If result = System.Windows.Forms.DialogResult.OK Then
  567. ' Get the file name.
  568. Dim path As String = OpenFileDialog1.FileName
  569. Cargar(dgvAmortizacion, path, "Hoja1")
  570. End If
  571. End Sub
  572. Sub Cargar(ByVal dgView As DataGridView,
  573. ByVal SLibro As String,
  574. ByVal sHoja As String)
  575. Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
  576. "Data Source=" & SLibro & ";" &
  577. "Extended Properties=""Excel 8.0;HDR=YES"""
  578. Try
  579. ' cadena de conexión
  580. Dim cn As New OleDbConnection(cs)
  581. If Not System.IO.File.Exists(SLibro) Then
  582. MsgBox("No se encontró el Libro: " &
  583. SLibro, MsgBoxStyle.Critical,
  584. "Ruta inválida")
  585. Exit Sub
  586. End If
  587. Dim Conexion As New OleDbConnection(cs)
  588. Conexion.Open()
  589. ' se conecta con la hoja sheet 1
  590. Dim dAdapter As New OleDbCommand("Select * From [" & sHoja & "$]", Conexion)
  591. Dim reader As OleDbDataReader = dAdapter.ExecuteReader()
  592. Dim Cantidad As Integer = dgvAmortizacion.Rows.Count
  593. Dim Correlativo As Integer = Cantidad
  594. While (reader.Read())
  595. Correlativo += 1
  596. dgvAmortizacion.Rows.Add(Correlativo, reader(0))
  597. End While
  598. reader.Close()
  599. LLenarFechaAmort()
  600. CalculosAmort()
  601. Variables.dgvAmortizacion = dgvAmortizacion
  602. Catch oMsg As Exception
  603. MsgBox(oMsg.Message, MsgBoxStyle.Critical)
  604. End Try
  605. End Sub
  606. Private Sub dgvAmortizacion_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAmortizacion.CellContentClick
  607. End Sub
  608. Sub Formato()
  609. If String.IsNullOrEmpty(txtEmisionTotal.Text.ToString) Then
  610. txtEmisionTotal.Text = "0.0"
  611. End If
  612. If String.IsNullOrEmpty(txtTasaEmision.Text.ToString) Then
  613. txtTasaEmision.Text = "0.0%"
  614. End If
  615. If String.IsNullOrEmpty(txtPeriodicidadEmision.Text.ToString) Then
  616. txtPeriodicidadEmision.Text = "0.0"
  617. End If
  618. If String.IsNullOrEmpty(txtPeriodosEmision.Text.ToString) Then
  619. txtPeriodosEmision.Text = "0.0"
  620. End If
  621. If String.IsNullOrEmpty(txtMontoCompraEmision.Text.ToString) Then
  622. txtMontoCompraEmision.Text = "0.0"
  623. End If
  624. If String.IsNullOrEmpty(txtMontoCompraPrimario.Text.ToString) Then
  625. txtMontoCompraPrimario.Text = "0.0"
  626. End If
  627. If String.IsNullOrEmpty(txtCesionFlujo1.Text.ToString) Then
  628. txtCesionFlujo1.Text = "0.0"
  629. End If
  630. If String.IsNullOrEmpty(txtCesionFlujo2.Text.ToString) Then
  631. txtCesionFlujo2.Text = "0.0"
  632. End If
  633. If String.IsNullOrEmpty(txtCesionFlujo3.Text.ToString) Then
  634. txtCesionFlujo3.Text = "0.0"
  635. End If
  636. If String.IsNullOrEmpty(txtCesionFlujo4.Text.ToString) Then
  637. txtCesionFlujo4.Text = "0.0"
  638. End If
  639. If String.IsNullOrEmpty(txtCesionFlujo5.Text.ToString) Then
  640. txtCesionFlujo5.Text = "0.0"
  641. End If
  642. If txtTasaEmision.Text.ToString.IndexOf("%") = -1 Then
  643. txtTasaEmision.Text = txtTasaEmision.Text.ToString + "%"
  644. End If
  645. End Sub
  646. Private Sub txtEmisionTotal_TextChanged(sender As Object, e As EventArgs) Handles txtEmisionTotal.TextChanged
  647. End Sub
  648. Private Sub txtTasaEmision_TextChanged(sender As Object, e As EventArgs) Handles txtTasaEmision.TextChanged
  649. End Sub
  650. Private Sub txtPeriodicidadEmision_TextChanged(sender As Object, e As EventArgs) Handles txtPeriodicidadEmision.TextChanged
  651. End Sub
  652. Private Sub txtPeriodosEmision_TextChanged(sender As Object, e As EventArgs) Handles txtPeriodosEmision.TextChanged
  653. End Sub
  654. Private Sub txtMontoCompraEmision_TextChanged(sender As Object, e As EventArgs) Handles txtMontoCompraEmision.TextChanged
  655. End Sub
  656. Private Sub txtMontoCompraPrimario_TextChanged(sender As Object, e As EventArgs) Handles txtMontoCompraPrimario.TextChanged
  657. End Sub
  658. Private Sub txtCesionFlujo1_TextChanged(sender As Object, e As EventArgs) Handles txtCesionFlujo1.TextChanged
  659. End Sub
  660. Private Sub txtCesionFlujo2_TextChanged(sender As Object, e As EventArgs) Handles txtCesionFlujo2.TextChanged
  661. End Sub
  662. Private Sub esionFlujo3_TextChanged(sender As Object, e As EventArgs) Handles txtCesionFlujo3.TextChanged
  663. End Sub
  664. Private Sub txtCesionFlujo4_TextChanged(sender As Object, e As EventArgs) Handles txtCesionFlujo4.TextChanged
  665. End Sub
  666. Private Sub txtCesionFlujo5_TextChanged(sender As Object, e As EventArgs) Handles txtCesionFlujo5.TextChanged
  667. End Sub
  668. Private Sub txtEmisionTotal_Leave(sender As Object, e As EventArgs) Handles txtEmisionTotal.Leave
  669. Formato()
  670. End Sub
  671. Private Sub dtpFechaEmision_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaEmision.ValueChanged
  672. Formato()
  673. End Sub
  674. Private Sub txtTasaEmision_Leave(sender As Object, e As EventArgs) Handles txtTasaEmision.Leave
  675. Formato()
  676. End Sub
  677. Private Sub txtPeriodicidadEmision_Leave(sender As Object, e As EventArgs) Handles txtPeriodicidadEmision.Leave
  678. Formato()
  679. End Sub
  680. Private Sub txtPeriodosEmision_Leave(sender As Object, e As EventArgs) Handles txtPeriodosEmision.Leave
  681. Formato()
  682. End Sub
  683. Private Sub txtMontoCompraEmision_Leave(sender As Object, e As EventArgs) Handles txtMontoCompraEmision.Leave
  684. Formato()
  685. End Sub
  686. Private Sub txtMontoCompraPrimario_Leave(sender As Object, e As EventArgs) Handles txtMontoCompraPrimario.Leave
  687. Formato()
  688. End Sub
  689. Private Sub txtCesionFlujo1_Leave(sender As Object, e As EventArgs) Handles txtCesionFlujo1.Leave
  690. Formato()
  691. End Sub
  692. Private Sub txtCesionFlujo2_Leave(sender As Object, e As EventArgs) Handles txtCesionFlujo2.Leave
  693. Formato()
  694. End Sub
  695. Private Sub txtCesionFlujo3_Leave(sender As Object, e As EventArgs) Handles txtCesionFlujo3.Leave
  696. Formato()
  697. End Sub
  698. Private Sub txtCesionFlujo4_Leave(sender As Object, e As EventArgs) Handles txtCesionFlujo4.Leave
  699. Formato()
  700. End Sub
  701. Private Sub txtCesionFlujo5_Leave(sender As Object, e As EventArgs) Handles txtCesionFlujo5.Leave
  702. Formato()
  703. End Sub
  704. Private Sub txtEmisionTotal_KeyUp(sender As Object, e As KeyEventArgs) Handles txtEmisionTotal.KeyUp
  705. If txtEmisionTotal.Text = "." Then
  706. txtEmisionTotal.Text = ".0"
  707. End If
  708. End Sub
  709. Private Sub txtTasaEmision_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasaEmision.KeyUp
  710. If txtTasaEmision.Text = "." Then
  711. txtTasaEmision.Text = ".0%"
  712. End If
  713. End Sub
  714. Private Sub txtPeriodicidadEmision_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPeriodicidadEmision.KeyUp
  715. If txtPeriodicidadEmision.Text = "." Then
  716. txtPeriodicidadEmision.Text = ".0"
  717. End If
  718. End Sub
  719. Private Sub txtPeriodosEmision_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPeriodosEmision.KeyUp
  720. If txtPeriodosEmision.Text = "." Then
  721. txtPeriodosEmision.Text = ".0"
  722. End If
  723. End Sub
  724. Private Sub txtMontoCompraEmision_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMontoCompraEmision.KeyUp
  725. If txtMontoCompraEmision.Text = "." Then
  726. txtMontoCompraEmision.Text = ".0"
  727. End If
  728. End Sub
  729. Private Sub txtMontoCompraPrimario_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMontoCompraPrimario.KeyUp
  730. If txtMontoCompraPrimario.Text = "." Then
  731. txtMontoCompraPrimario.Text = ".0"
  732. End If
  733. End Sub
  734. Private Sub txtCesionFlujo1_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCesionFlujo1.KeyUp
  735. If txtCesionFlujo1.Text = "." Then
  736. txtCesionFlujo1.Text = ".0"
  737. End If
  738. End Sub
  739. Private Sub txtCesionFlujo2_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCesionFlujo2.KeyUp
  740. If txtCesionFlujo2.Text = "." Then
  741. txtCesionFlujo2.Text = ".0"
  742. End If
  743. End Sub
  744. Private Sub txtCesionFlujo3_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCesionFlujo3.KeyUp
  745. If txtCesionFlujo3.Text = "." Then
  746. txtCesionFlujo3.Text = ".0"
  747. End If
  748. End Sub
  749. Private Sub txtCesionFlujo4_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCesionFlujo4.KeyUp
  750. If txtCesionFlujo4.Text = "." Then
  751. txtCesionFlujo4.Text = ".0"
  752. End If
  753. End Sub
  754. Private Sub txtCesionFlujo5_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCesionFlujo5.KeyUp
  755. If txtCesionFlujo5.Text = "." Then
  756. txtCesionFlujo5.Text = ".0"
  757. End If
  758. End Sub
  759. Private Sub txtEmisionTotal_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtEmisionTotal.KeyPress
  760. If String.IsNullOrEmpty(txtEmisionTotal.Text) Then
  761. If e.KeyChar = "." Then
  762. txtEmisionTotal.Text = "0"
  763. Exit Sub
  764. End If
  765. End If
  766. If (Not txtEmisionTotal.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 txtTasaEmision_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasaEmision.KeyPress
  773. If String.IsNullOrEmpty(txtTasaEmision.Text) Then
  774. If e.KeyChar = "." Then
  775. txtTasaEmision.Text = "0%"
  776. Exit Sub
  777. End If
  778. End If
  779. If (Not txtTasaEmision.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  780. Operaciones.ValidarEntrada(sender, e, True)
  781. Else
  782. Operaciones.ValidarEntrada(sender, e, False)
  783. End If
  784. End Sub
  785. Private Sub txtPeriodicidadEmision_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPeriodicidadEmision.KeyPress
  786. If String.IsNullOrEmpty(txtPeriodicidadEmision.Text) Then
  787. If e.KeyChar = "." Then
  788. txtPeriodicidadEmision.Text = "0"
  789. Exit Sub
  790. End If
  791. End If
  792. If (Not txtPeriodicidadEmision.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  793. Operaciones.ValidarEntrada(sender, e, True)
  794. Else
  795. Operaciones.ValidarEntrada(sender, e, False)
  796. End If
  797. End Sub
  798. Private Sub txtPeriodosEmision_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPeriodosEmision.KeyPress
  799. If String.IsNullOrEmpty(txtPeriodosEmision.Text) Then
  800. If e.KeyChar = "." Then
  801. txtPeriodosEmision.Text = "0"
  802. Exit Sub
  803. End If
  804. End If
  805. If (Not txtPeriodosEmision.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  806. Operaciones.ValidarEntrada(sender, e, True)
  807. Else
  808. Operaciones.ValidarEntrada(sender, e, False)
  809. End If
  810. End Sub
  811. Private Sub txtMontoCompraEmision_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMontoCompraEmision.KeyPress
  812. If String.IsNullOrEmpty(txtMontoCompraEmision.Text) Then
  813. If e.KeyChar = "." Then
  814. txtMontoCompraEmision.Text = "0"
  815. Exit Sub
  816. End If
  817. End If
  818. If (Not txtMontoCompraEmision.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  819. Operaciones.ValidarEntrada(sender, e, True)
  820. Else
  821. Operaciones.ValidarEntrada(sender, e, False)
  822. End If
  823. End Sub
  824. Private Sub txtMontoCompraPrimario_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMontoCompraPrimario.KeyPress
  825. If String.IsNullOrEmpty(txtMontoCompraPrimario.Text) Then
  826. If e.KeyChar = "." Then
  827. txtMontoCompraPrimario.Text = "0"
  828. Exit Sub
  829. End If
  830. End If
  831. If (Not txtMontoCompraPrimario.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  832. Operaciones.ValidarEntrada(sender, e, True)
  833. Else
  834. Operaciones.ValidarEntrada(sender, e, False)
  835. End If
  836. End Sub
  837. Private Sub txtCesionFlujo1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCesionFlujo1.KeyPress
  838. If String.IsNullOrEmpty(txtCesionFlujo1.Text) Then
  839. If e.KeyChar = "." Then
  840. txtCesionFlujo1.Text = "0"
  841. Exit Sub
  842. End If
  843. End If
  844. If (Not txtCesionFlujo1.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  845. Operaciones.ValidarEntrada(sender, e, True)
  846. Else
  847. Operaciones.ValidarEntrada(sender, e, False)
  848. End If
  849. End Sub
  850. Private Sub txtCesionFlujo2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCesionFlujo2.KeyPress
  851. If String.IsNullOrEmpty(txtCesionFlujo2.Text) Then
  852. If e.KeyChar = "." Then
  853. txtCesionFlujo2.Text = "0"
  854. Exit Sub
  855. End If
  856. End If
  857. If (Not txtCesionFlujo2.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  858. Operaciones.ValidarEntrada(sender, e, True)
  859. Else
  860. Operaciones.ValidarEntrada(sender, e, False)
  861. End If
  862. End Sub
  863. Private Sub txtCesionFlujo3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCesionFlujo3.KeyPress
  864. If String.IsNullOrEmpty(txtCesionFlujo3.Text) Then
  865. If e.KeyChar = "." Then
  866. txtCesionFlujo3.Text = "0"
  867. Exit Sub
  868. End If
  869. End If
  870. If (Not txtCesionFlujo3.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  871. Operaciones.ValidarEntrada(sender, e, True)
  872. Else
  873. Operaciones.ValidarEntrada(sender, e, False)
  874. End If
  875. End Sub
  876. Private Sub txtCesionFlujo4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCesionFlujo4.KeyPress
  877. If String.IsNullOrEmpty(txtCesionFlujo4.Text) Then
  878. If e.KeyChar = "." Then
  879. txtCesionFlujo4.Text = "0"
  880. Exit Sub
  881. End If
  882. End If
  883. If (Not txtCesionFlujo4.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  884. Operaciones.ValidarEntrada(sender, e, True)
  885. Else
  886. Operaciones.ValidarEntrada(sender, e, False)
  887. End If
  888. End Sub
  889. Private Sub txtCesionFlujo5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCesionFlujo5.KeyPress
  890. If String.IsNullOrEmpty(txtCesionFlujo5.Text) Then
  891. If e.KeyChar = "." Then
  892. txtCesionFlujo5.Text = "0"
  893. Exit Sub
  894. End If
  895. End If
  896. If (Not txtCesionFlujo5.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  897. Operaciones.ValidarEntrada(sender, e, True)
  898. Else
  899. Operaciones.ValidarEntrada(sender, e, False)
  900. End If
  901. End Sub
  902. Private Sub TbGenerales_Click(sender As Object, e As EventArgs) Handles TbGenerales.Click
  903. End Sub
  904. Private Sub txtCantidadPeriodo_TextChanged(sender As Object, e As EventArgs)
  905. End Sub
  906. Private Sub cboPeriodoGracia_SelectedIndexChanged(sender As Object, e As EventArgs)
  907. End Sub
  908. Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems
  909. End Sub
  910. Private Sub Button1_Click_1(sender As Object, e As EventArgs)
  911. CargarIndexBase()
  912. End Sub
  913. Private Sub Panel2_Paint(sender As Object, e As PaintEventArgs) Handles Panel2.Paint
  914. End Sub
  915. Function BuscarPosicion()
  916. Dim FechaRedencionBuscar As Date = FechaRedencion
  917. Dim Posicion As Integer = -1
  918. Dim Cantidad As Integer = dgvAmortizacion.Rows.Count - 1
  919. Dim Index As Integer = 0
  920. Dim CantidadDiasFinal As Integer = 0
  921. Dim ExisteFecha As Boolean = False
  922. Dim Diccionario As New Dictionary(Of String, String)
  923. While Index <= Cantidad
  924. Dim Fecha As Date = dgvAmortizacion.Rows(Index).Cells("Fecha").Value
  925. Dim Correlativo = dgvAmortizacion.Rows(Index).Cells("Correlativo").Value
  926. Dim CantidadDias = dgvAmortizacion.Rows(Index).Cells("Dias").Value
  927. Dim InicioBucle As Integer = 0
  928. If IsNumeric(Correlativo) And IsNumeric(CantidadDias) Then
  929. Dim FechaBucle As Date = Fecha
  930. While InicioBucle < CantidadDias
  931. Dim FechaRedencionBuscar_Limpia As String = Format(FechaRedencionBuscar, "yyyy/MM/dd")
  932. Dim FechaBucle_Limpia As String = Format(FechaBucle, "yyyy/MM/dd")
  933. If FechaRedencionBuscar_Limpia = FechaBucle_Limpia Then
  934. Posicion = Correlativo - 1
  935. ExisteFecha = True
  936. CantidadDiasFinal = InicioBucle
  937. Exit While
  938. Else
  939. FechaBucle = FechaBucle.AddDays(-1)
  940. End If
  941. InicioBucle += 1
  942. End While
  943. End If
  944. Index += 1
  945. End While
  946. Diccionario.Add("Existencia", ExisteFecha)
  947. Diccionario.Add("Posicion", Posicion)
  948. Diccionario.Add("DiasAtras", CantidadDiasFinal)
  949. Return Diccionario
  950. End Function
  951. Sub CorteRedencion()
  952. Dim ListaValidacion As New Dictionary(Of String, String)
  953. ListaValidacion = BuscarPosicion()
  954. Dim Existencia As Boolean = False
  955. Dim Posicion As Integer = -1
  956. Dim DiasAtras As Integer = 0
  957. For Each Valores In ListaValidacion
  958. If Valores.Key = "Existencia" Then
  959. Existencia = Valores.Value
  960. ElseIf Valores.Key = "Posicion" Then
  961. Posicion = Valores.Value
  962. ElseIf Valores.Key = "DiasAtras" Then
  963. DiasAtras = Valores.Value
  964. End If
  965. Next
  966. If Existencia Then
  967. Dim PosicionActual As Integer = Posicion + 1
  968. Dim PrimeraMitad As String = PosicionActual.ToString + ".1"
  969. Dim SegundaMitad As String = PosicionActual.ToString + ".2"
  970. Dim PosicionPrimera As Integer = Posicion
  971. Dim PosicionSegunda = Posicion + 1
  972. Dim FechaPosicionAnterior As Date = dgvAmortizacion.Rows(Posicion).Cells("Fecha").Value
  973. Dim DiasPosicionAnterior As Integer = dgvAmortizacion.Rows(Posicion).Cells("Dias").Value
  974. Dim Porcentaje As Double = dgvAmortizacion.Rows(Posicion).Cells("Porcentaje").Value
  975. Dim PrimeraFecha As Date = FechaPosicionAnterior.AddDays((DiasAtras) * -1)
  976. Dim SegundaFecha As Date = FechaPosicionAnterior
  977. dgvAmortizacion.Rows.Insert(PosicionSegunda, New DataGridViewRow)
  978. dgvAmortizacion.Rows(PosicionPrimera).Cells("Correlativo").Value = PrimeraMitad
  979. dgvAmortizacion.Rows(PosicionSegunda).Cells("Correlativo").Value = SegundaMitad
  980. dgvAmortizacion.Rows(PosicionPrimera).Cells("Porcentaje").Value = Porcentaje
  981. dgvAmortizacion.Rows(PosicionSegunda).Cells("Porcentaje").Value = Porcentaje
  982. dgvAmortizacion.Rows(PosicionPrimera).Cells("Dias").Value = DiasPosicionAnterior - DiasAtras
  983. dgvAmortizacion.Rows(PosicionSegunda).Cells("Dias").Value = DiasAtras
  984. dgvAmortizacion.Rows(PosicionPrimera).Cells("Fecha").Value = Format(PrimeraFecha, "dd/MM/yyyy")
  985. dgvAmortizacion.Rows(PosicionSegunda).Cells("Fecha").Value = Format(SegundaFecha, "dd/MM/yyyy")
  986. CalculosAmortRedencion(PosicionPrimera, FechaPosicionAnterior, DiasPosicionAnterior, DiasAtras, "iniciales")
  987. CalculosAmortRedencion(PosicionSegunda, FechaPosicionAnterior, DiasPosicionAnterior, DiasAtras, "finales")
  988. CambiarFilas(PosicionSegunda)
  989. End If
  990. End Sub
  991. Sub CambiarFilas(ByVal IndexAnterior As Double)
  992. Dim Index As Integer = Math.Truncate(IndexAnterior)
  993. Dim Cantidad As Integer = dgvAmortizacion.Rows.Count - 1
  994. While Index <= Cantidad
  995. dgvAmortizacion.Rows(Index).DefaultCellStyle.BackColor = Color.LightGray
  996. dgvAmortizacion.Rows(Index).DefaultCellStyle.ForeColor = Color.Maroon
  997. Index += 1
  998. End While
  999. DefinirVigencia()
  1000. End Sub
  1001. Sub DefinirVigencia()
  1002. Dim Index As Integer = 0
  1003. Dim Cantidad As Integer = dgvAmortizacion.Rows.Count - 1
  1004. While Index <= Cantidad
  1005. Dim Vigente As String = dgvAmortizacion.Rows(Index).Cells("Vigente").Value
  1006. If Vigente = "False" Then
  1007. dgvAmortizacion.Rows(Index).DefaultCellStyle.BackColor = Color.LightGray
  1008. dgvAmortizacion.Rows(Index).DefaultCellStyle.ForeColor = Color.Maroon
  1009. End If
  1010. Index += 1
  1011. End While
  1012. End Sub
  1013. Sub CalculosAmortRedencion(ByVal Index As Integer, ByVal Fecha As Date, ByVal DiasTotales As Integer, ByVal DiasCortos As Integer, ByVal TipoDias As String)
  1014. Dim Cantidad = 0, Dias = 0, FechaEmis = Date.Now.Date, Cuota = 0.0, Amort = 0.0, Interes = 0.0, Saldo = 0.0, AmortPriTabla = 0.0, SaldoAnterior = 0.0, Posicion, PosicionAnterior, PosicionSiguiente
  1015. Posicion = dgvAmortizacion.Rows.Count - 1
  1016. Dim FechaCalculo As Date = Date.Today.Date
  1017. Dim PrimerosDias As Integer = DiasTotales - DiasCortos
  1018. Dim SegundosDias As Integer = DiasCortos
  1019. Dim DiasTotalesNegativos As Integer = DiasTotales * -1
  1020. Dim FechaFin As Date = Date.Today.Date
  1021. If TipoDias = "iniciales" Then
  1022. FechaCalculo = Fecha.AddDays(DiasTotalesNegativos)
  1023. Fecha = FechaCalculo
  1024. FechaCalculo = FechaCalculo.AddDays(PrimerosDias)
  1025. FechaEmis = Fecha
  1026. FechaFin = FechaCalculo
  1027. Dias = DiasTotales - DiasCortos
  1028. PosicionAnterior = Index - 1
  1029. PosicionSiguiente = Index + 1
  1030. Fecha = FechaCalculo
  1031. SaldoAnterior = CalculosSaldoAnterior(PosicionAnterior)
  1032. If IsNumeric(dgvAmortizacion.Rows(PosicionAnterior).Cells("Saldos").Value) Then
  1033. Amort = dgvAmortizacion.Rows(PosicionAnterior).Cells("Saldos").Value
  1034. End If
  1035. Interes = CalculosInteres2(Index, SaldoAnterior, Dias, FechaEmis, FechaFin, IndexBase)
  1036. Saldo = CalcularSaldos2(Index, SaldoAnterior, Amort)
  1037. Cuota = Amort + Interes
  1038. dgvAmortizacion.Rows(Index).Cells("Cuotas").Value = Cuota
  1039. dgvAmortizacion.Rows(Index).Cells("Amortizacion de Capital").Value = Amort
  1040. dgvAmortizacion.Rows(Index).Cells("Interés").Value = Interes
  1041. dgvAmortizacion.Rows(Index).Cells("Saldos").Value = Saldo
  1042. Else
  1043. FechaCalculo = Fecha.AddDays((SegundosDias * -1))
  1044. FechaEmis = FechaCalculo
  1045. FechaFin = Fecha
  1046. Dias = DiasCortos
  1047. PosicionAnterior = Index - 2
  1048. Fecha = FechaCalculo
  1049. SaldoAnterior = CalculosSaldoAnterior(PosicionAnterior)
  1050. Amort = CalculosAmort2(Index, Posicion, AmortPriTabla)
  1051. Interes = CalculosInteres2(Index, SaldoAnterior, Dias, FechaEmis, FechaFin, IndexBase)
  1052. Saldo = CalcularSaldos2(Index, SaldoAnterior, Amort)
  1053. Cuota = Amort + Interes
  1054. dgvAmortizacion.Rows(Index).Cells("Cuotas").Value = Cuota
  1055. dgvAmortizacion.Rows(Index).Cells("Amortizacion de Capital").Value = Amort
  1056. dgvAmortizacion.Rows(Index).Cells("Interés").Value = Interes
  1057. dgvAmortizacion.Rows(Index).Cells("Saldos").Value = Saldo
  1058. End If
  1059. End Sub
  1060. Sub Redencion()
  1061. Dim FormularioRedencion As New Form
  1062. Dim FechaRedencion As New DateTimePicker
  1063. Dim TextoFecha As New Label
  1064. Dim BotonFecha As New Button
  1065. FormularioRedencion.Name = "frmFechaRedencion"
  1066. FormularioRedencion.Text = "Buscar Fecha de Redencion"
  1067. FormularioRedencion.Width = 250
  1068. FormularioRedencion.Height = 250
  1069. FormularioRedencion.StartPosition = FormStartPosition.CenterParent
  1070. TextoFecha.Name = "lblfecha"
  1071. TextoFecha.Text = "Ingresar una fecha"
  1072. TextoFecha.Location = New Point(80, 25)
  1073. FechaRedencion.Name = "dtpFechaRedencion"
  1074. FechaRedencion.Width = FormularioRedencion.Width - 100
  1075. FechaRedencion.Location = New Point(50, 50)
  1076. FechaRedencion.Format = DateTimePickerFormat.Short
  1077. AddHandler FechaRedencion.ValueChanged, AddressOf EventOperarFecha
  1078. BotonFecha.Name = "btnfecha"
  1079. BotonFecha.Text = "Aceptar"
  1080. BotonFecha.Location = New Point(90, 100)
  1081. AddHandler BotonFecha.Click, AddressOf EventAceptar
  1082. FormularioRedencion.Controls.Add(TextoFecha)
  1083. FormularioRedencion.Controls.Add(FechaRedencion)
  1084. FormularioRedencion.Controls.Add(BotonFecha)
  1085. FormularioRedencion.Show()
  1086. End Sub
  1087. Sub EventOperarFecha(sender As Object, e As EventArgs)
  1088. FechaRedencion = sender.value
  1089. End Sub
  1090. Sub EventAceptar(sender As Object, e As EventArgs)
  1091. Dim Nombre As Form = sender.parent
  1092. Nombre.close()
  1093. CorteRedencion()
  1094. End Sub
  1095. Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
  1096. Redencion()
  1097. End Sub
  1098. Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click
  1099. dgvAmortizacion.Rows.Clear()
  1100. End Sub
  1101. End Class