frmResultadoTitularizacion.vb 53 KB

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