frmResultadoTitularizacion.vb 50 KB

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