frmNotaEstructurada.vb 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. Public Class frmNotaEstructurada
  2. Dim AnioBase As Integer = 365
  3. Dim oNETSCE As New NotaEstructuradaCE
  4. Dim oDAONEST As New DAONotaEstructurada
  5. Dim oDAOGeneral As New DAOGeneral
  6. Private vCargado As Boolean = False
  7. Dim Estado As String = " "
  8. Dim codigo As String = Variables.Codigo
  9. Dim Operaciones As New Operaciones
  10. Dim NotaCalcular As New NotaEstructuradaCE
  11. Private _TipoTransaccion As String
  12. Private _IdDocumento As Integer
  13. Private _TipoDocumento As String
  14. Private _CodigoInversion As String
  15. Private Property CodigoInversion As String
  16. Get
  17. Return _CodigoInversion
  18. End Get
  19. Set(value As String)
  20. _CodigoInversion = value
  21. End Set
  22. End Property
  23. Public Property TipoTransaccion As String
  24. Get
  25. Return _TipoTransaccion
  26. End Get
  27. Set(value As String)
  28. _TipoTransaccion = value
  29. End Set
  30. End Property
  31. Private Sub frmNotaEstructurada_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  32. dgvIntereses.Columns.Clear()
  33. AgregarCampos()
  34. Call CargarPeriodos()
  35. If TipoTransaccion Is Nothing Then
  36. TipoTransaccion = "N"
  37. PrepararNuevo()
  38. End If
  39. If TipoTransaccion = "C" Then
  40. Call CargarRegistroBD()
  41. End If
  42. CalcularPlazo()
  43. Calculo()
  44. vCargado = True
  45. ExisteInversion()
  46. ValidarExistencia()
  47. CargarTransladoNuevo()
  48. End Sub
  49. Sub RellenarDatos()
  50. If (String.IsNullOrEmpty(txtMontoInversion.Text.ToString)) Then
  51. txtMontoInversion.Text = "0.0"
  52. End If
  53. If (String.IsNullOrEmpty(txtPlazo.Text.ToString)) Then
  54. txtPlazo.Text = "0.0"
  55. End If
  56. If (String.IsNullOrEmpty(txtTasa.Text.ToString.Trim("%"))) Then
  57. txtTasa.Text = "0.0%"
  58. End If
  59. End Sub
  60. Function ExisteInversion()
  61. Dim Codigo As String = Variables.Codigo
  62. Dim TablaINV As String = "INV0"
  63. Dim TablaPINV As String = "PIN0"
  64. Dim General As New DAOGeneral
  65. Dim InvPro = Variables.InvPro
  66. If InvPro = "I" Then
  67. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  68. If INV0 Then
  69. navNuevo.Visible = True
  70. Return True
  71. Else
  72. navNuevo.Visible = False
  73. Return False
  74. End If
  75. End If
  76. If InvPro = "P" Then
  77. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  78. If PINV0 Then
  79. navNuevo.Visible = True
  80. Return True
  81. Else
  82. navNuevo.Visible = False
  83. Return False
  84. End If
  85. End If
  86. Return False
  87. End Function
  88. Sub ValidarExistencia()
  89. Dim General As New DAOGeneral
  90. Dim Codigo As String = Variables.Codigo
  91. Dim Tabla As String = String.Empty
  92. Tabla = "NEST0"
  93. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  94. If (Existe) Then
  95. navNuevo.Enabled = False
  96. navModificar.Enabled = True
  97. navEliminar.Enabled = True
  98. Else
  99. navNuevo.Enabled = True
  100. navModificar.Enabled = False
  101. navEliminar.Enabled = False
  102. End If
  103. Estado = String.Empty
  104. btnGME.Text = "Aceptar"
  105. End Sub
  106. Function ExisteValidacion()
  107. Dim General As New DAOGeneral
  108. Dim Codigo As String = Variables.Codigo
  109. Dim Tabla As String = String.Empty
  110. Tabla = "NEST0"
  111. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  112. Return Existe
  113. End Function
  114. Private Sub txtPlazo_TextChanged(sender As Object, e As EventArgs)
  115. Calculo()
  116. End Sub
  117. Private Sub txtPlazo_LostFocus(sender As Object, e As EventArgs)
  118. End Sub
  119. Private Sub ControlPlazo()
  120. Dim valor As Integer
  121. If Not Integer.TryParse(txtPlazo.Text.ToString, valor) Then
  122. txtPlazo.Focus()
  123. txtPlazo.BackColor = Configuraciones.ColorFondoError
  124. Else
  125. txtPlazo.BackColor = Color.White
  126. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  127. oNETSCE.Plazo = valor
  128. End If
  129. RefrescarValorControles()
  130. End If
  131. End Sub
  132. Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged
  133. CalcularPlazo()
  134. Calculo()
  135. End Sub
  136. Private Sub ControlFechaOperacion()
  137. Dim valor As Date
  138. valor = dtpFechaOperacion.Value.Date
  139. If TipoTransaccion = "N" Then
  140. oNETSCE.FechaOperacion = valor
  141. End If
  142. RefrescarValorControles()
  143. End Sub
  144. Private Sub txtIngresoBruto_TextChanged(sender As Object, e As EventArgs)
  145. End Sub
  146. Private Sub txtTasa_TextChanged(sender As Object, e As EventArgs) Handles txtTasa.TextChanged
  147. Calculo()
  148. If (txtTasa.ToString.IndexOf("%") = -1) Then
  149. txtTasa.Text += "%"
  150. End If
  151. CalcularPlazo()
  152. Calculo()
  153. End Sub
  154. Private Sub txtTasa_LostFocus(sender As Object, e As EventArgs) Handles txtTasa.LostFocus
  155. End Sub
  156. Private Sub ControlTasa()
  157. Dim valor As Double
  158. If Not Double.TryParse(txtTasa.Text, valor) Then
  159. txtTasa.Focus()
  160. txtTasa.BackColor = Configuraciones.ColorFondoError
  161. Else
  162. txtTasa.BackColor = Color.White
  163. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  164. oNETSCE.Tasa = valor
  165. End If
  166. RefrescarValorControles()
  167. End If
  168. End Sub
  169. Private Sub txtMontoInversion_TextChanged(sender As Object, e As EventArgs) Handles txtMontoInversion.TextChanged
  170. CalcularPlazo()
  171. Calculo()
  172. End Sub
  173. Private Sub txtMontoInversion_LostFocus(sender As Object, e As EventArgs) Handles txtMontoInversion.LostFocus
  174. End Sub
  175. Private Sub ControlMontoInversion()
  176. Dim valor As Double
  177. If Not Double.TryParse(txtMontoInversion.Text, valor) Then
  178. txtMontoInversion.Focus()
  179. txtMontoInversion.BackColor = Configuraciones.ColorFondoError
  180. Else
  181. txtMontoInversion.BackColor = Color.White
  182. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  183. oNETSCE.MontoDeInversion = valor
  184. End If
  185. RefrescarValorControles()
  186. End If
  187. End Sub
  188. Private Sub txtIngresoNeto_TextChanged(sender As Object, e As EventArgs)
  189. End Sub
  190. Sub CargarPeriodos()
  191. If cboPeriodicidad.Items.Count = 0 Or cboPeriodicidad.Items.Count = 1 Then
  192. Me.cboPeriodicidad.DataSource = oDAOGeneral.ListaPeriodicidad
  193. Me.cboPeriodicidad.DisplayMember = "Descripcion"
  194. Me.cboPeriodicidad.ValueMember = "Codigo"
  195. Me.cboPeriodicidad.SelectedIndex = 0
  196. End If
  197. End Sub
  198. Private Sub btnAceptar_Click(sender As Object, e As EventArgs)
  199. If (Estado = "N") Then
  200. NuevoElemento()
  201. ElseIf (Estado = "M") Then
  202. ModificarElemento()
  203. ElseIf (Estado = "B") Then
  204. EliminarElemento()
  205. End If
  206. End Sub
  207. Private Sub CargarRegistroBD()
  208. oNETSCE = Nothing
  209. oDAONEST = New DAONotaEstructurada
  210. CodigoInversion = Variables.Codigo
  211. oNETSCE = oDAONEST.CargarRegistro(Me.CodigoInversion)
  212. TipoTransaccion = "C"
  213. RefrescarValorControles()
  214. End Sub
  215. Private Sub dtpFechaVencimiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimiento.ValueChanged
  216. CalcularPlazo()
  217. Calculo()
  218. End Sub
  219. Private Sub ControlFechaVencimiento()
  220. Dim valor As Date
  221. valor = dtpFechaVencimiento.Value.Date.ToString
  222. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  223. oNETSCE.FechaVencimiento = valor
  224. End If
  225. RefrescarValorControles()
  226. End Sub
  227. Private Sub cboPeriodicidad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPeriodicidad.SelectedIndexChanged
  228. CalcularPlazo()
  229. Calculo()
  230. End Sub
  231. Private Sub ControlPreriodicidad()
  232. Dim valor As String
  233. If vCargado Then
  234. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  235. valor = cboPeriodicidad.SelectedValue
  236. oNETSCE.Periodicidad = valor
  237. End If
  238. If TipoTransaccion IsNot Nothing Then
  239. RefrescarValorControles()
  240. End If
  241. End If
  242. End Sub
  243. Public Sub CargarRegistro(ByRef vCodigoInversion As String)
  244. TipoTransaccion = "C"
  245. Me.CodigoInversion = vCodigoInversion
  246. End Sub
  247. Private Sub RefrescarValorControles()
  248. If Not oNETSCE Is Nothing Then
  249. Me.txtMontoInversion.Text = oNETSCE.MontoDeInversion.ToString(Configuraciones.CodigoTXTMontos)
  250. Me.dtpFechaOperacion.Value = oNETSCE.FechaOperacion
  251. Me.dtpFechaVencimiento.Value = oNETSCE.FechaVencimiento
  252. Me.txtTasa.Text = oNETSCE.Tasa.ToString(Configuraciones.CodigoTXTMontos)
  253. txtPlazo.Text = oNETSCE.Plazo.ToString
  254. 'anio base
  255. Me.cboPeriodicidad.SelectedValue = oNETSCE.Periodicidad
  256. Me.txtRendimientoBruto.Text = oNETSCE.RendimientoBruto.ToString(Configuraciones.CodigoTXTMontos)
  257. Me.txtRendimientoNeto.Text = oNETSCE.RendimientoNeto.ToString(Configuraciones.CodigoTXTMontos)
  258. For Each item As DataRow In oNETSCE.dtIntereses.Rows
  259. Me.txtImpuesto.Text = item("PorcImp") * 100
  260. Next
  261. End If
  262. End Sub
  263. Private Sub dgvIntereses_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles dgvIntereses.CellBeginEdit
  264. End Sub
  265. Private Sub RefrescarClaseEntidad()
  266. ControlMontoInversion()
  267. ControlFechaOperacion()
  268. ControlFechaVencimiento()
  269. ControlTasa()
  270. ControlPlazo()
  271. ControlPreriodicidad()
  272. End Sub
  273. Private Sub dgvIntereses_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellEndEdit
  274. End Sub
  275. Private Sub dgvIntereses_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellContentClick
  276. End Sub
  277. Private Sub PrepararNuevo()
  278. oNETSCE = New NotaEstructuradaCE
  279. RefrescarValorControles()
  280. End Sub
  281. Private Sub dgvIntereses_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellLeave
  282. End Sub
  283. Private Sub dgvIntereses_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellEnter
  284. End Sub
  285. Private Sub dgvIntereses_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles dgvIntereses.RowPostPaint
  286. End Sub
  287. Private Sub dgvIntereses_RowPrePaint(sender As Object, e As DataGridViewRowPrePaintEventArgs) Handles dgvIntereses.RowPrePaint
  288. End Sub
  289. Private Sub dgvIntereses_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles dgvIntereses.RowsAdded
  290. End Sub
  291. Private Sub dgvIntereses_RowValidated(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.RowValidated
  292. End Sub
  293. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  294. btnGME.Text = "Modificar"
  295. Estado = "M"
  296. End Sub
  297. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  298. btnGME.Text = "Nuevo"
  299. Estado = "N"
  300. End Sub
  301. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  302. btnGME.Text = "Eliminar"
  303. Estado = "B"
  304. End Sub
  305. Function ColeccionDatos()
  306. Dim Coleccion As New Collection
  307. Dim MontoInv, FOper, FVenc, Tasa, Plazo, Periodic, RendBr, RendNet, IngrBrutoTot, IngrNetoTot, Renta As String
  308. MontoInv = Operaciones.ConvertirDecimal(txtMontoInversion.Text.ToString)
  309. FOper = Operaciones.ConvertirFecha(dtpFechaOperacion.Value.ToString)
  310. FVenc = Operaciones.ConvertirFecha(dtpFechaVencimiento.Value.ToString)
  311. Tasa = Operaciones.ConvertirDecimal(txtTasa.Text.ToString)
  312. Plazo = Operaciones.ConvertirEntero(txtPlazo.Text.ToString)
  313. Periodic = cboPeriodicidad.SelectedValue
  314. RendBr = Operaciones.ConvertirDecimal(txtRendimientoBruto.Text.ToString) / 100
  315. RendNet = Operaciones.ConvertirDecimal(txtRendimientoNeto.Text.ToString) / 100
  316. IngrBrutoTot = Operaciones.ConvertirDecimal(txtIngresoBruto.Text.ToString)
  317. IngrNetoTot = Operaciones.ConvertirDecimal(txtIngresoNeto.Text.ToString)
  318. Renta = Operaciones.ConvertirDecimal(txtRenta.Text.ToString)
  319. Coleccion.Add(MontoInv)
  320. Coleccion.Add(FOper)
  321. Coleccion.Add(FVenc)
  322. Coleccion.Add(Tasa)
  323. Coleccion.Add(Plazo)
  324. Coleccion.Add(Periodic)
  325. Coleccion.Add(RendBr)
  326. Coleccion.Add(RendNet)
  327. Coleccion.Add(IngrBrutoTot)
  328. Coleccion.Add(IngrNetoTot)
  329. Coleccion.Add(Renta)
  330. Return Coleccion
  331. End Function
  332. Function ColeccionElementos(ByVal Index As Integer)
  333. Dim Coleccion As New Collection
  334. Dim Correlativo, plazo, Fecha, IngBruto, PorcImp, MontoImp, IngrNeto As String
  335. Correlativo = Operaciones.ConvertirEntero(dgvIntereses.Rows(Index).Cells("Correlativo").Value.ToString)
  336. plazo = Operaciones.ConvertirEntero(dgvIntereses.Rows(Index).Cells("Plazo").Value.ToString)
  337. Fecha = Operaciones.ConvertirFecha(dgvIntereses.Rows(Index).Cells("Fecha").Value.ToString)
  338. IngBruto = Operaciones.ConvertirDecimal(dgvIntereses.Rows(Index).Cells("Ingreso Bruto").Value.ToString)
  339. PorcImp = Operaciones.ConvertirDecimal(dgvIntereses.Rows(Index).Cells("% Impuesto").Value.ToString)
  340. MontoImp = Operaciones.ConvertirDecimal(dgvIntereses.Rows(Index).Cells("Monto del Impuesto").Value.ToString)
  341. IngrNeto = Operaciones.ConvertirDecimal(dgvIntereses.Rows(Index).Cells("Ingreso Neto").Value.ToString)
  342. Coleccion.Add(Correlativo)
  343. Coleccion.Add(plazo)
  344. Coleccion.Add(Fecha)
  345. Coleccion.Add(IngBruto)
  346. Coleccion.Add(PorcImp)
  347. Coleccion.Add(MontoImp)
  348. Coleccion.Add(IngrNeto)
  349. Return Coleccion
  350. End Function
  351. Sub Calculo()
  352. Dim Plazo As Integer = 0
  353. Plazo = Operaciones.ConvertirEntero(txtPlazo.Text.ToString)
  354. dtpFechaVencimiento.Value = dtpFechaOperacion.Value.AddDays(Plazo)
  355. CalcularRendBruto()
  356. CalcularRendNeto()
  357. End Sub
  358. Sub CalcularRendBruto()
  359. Dim Total As Double = TotalIngreso()
  360. Dim MontoInv As Double = Operaciones.ConvertirDecimal(txtMontoInversion.Text.ToString)
  361. Dim Base = 365
  362. Dim pla As Double = Operaciones.ConvertirEntero(txtPlazo.Text.ToString)
  363. Dim tot As Double = 0
  364. If (Not MontoInv = 0 And Not pla = 0) Then
  365. tot = (Total / MontoInv) * (Base / pla)
  366. End If
  367. txtRendimientoBruto.Text = CStr((tot * 100)) + "%"
  368. End Sub
  369. Sub CalcularRendNeto()
  370. Dim Total As Double = TotalIngresoNeto()
  371. Dim MontoInv As Double = Operaciones.ConvertirDecimal(txtMontoInversion.Text.ToString)
  372. Dim Base = 365
  373. Dim pla As Double = Operaciones.ConvertirDecimal(txtPlazo.Text.ToString)
  374. Dim tot As Double = 0
  375. If (Not MontoInv = 0 And Not pla = 0) Then
  376. tot = (Total / MontoInv) * (Base / pla)
  377. End If
  378. txtRendimientoNeto.Text = CStr((tot * 100)) + "%"
  379. End Sub
  380. Function TotalIngreso()
  381. Dim Cantidad As Integer = CDec(dgvIntereses.Rows.Count - 1)
  382. Dim TotalIngr As Double = 0
  383. For i As Integer = 0 To Cantidad
  384. TotalIngr = TotalIngr + Operaciones.ConvertirDecimal(dgvIntereses.Rows(i).Cells("Ingreso Bruto").Value)
  385. Next
  386. Return TotalIngr
  387. End Function
  388. Function TotalIngresoNeto()
  389. Dim Cantidad = dgvIntereses.Rows.Count - 1
  390. Dim TotalIngr As Double = 0
  391. For i As Integer = 0 To Cantidad
  392. TotalIngr = TotalIngr + Operaciones.ConvertirDecimal(dgvIntereses.Rows(i).Cells("Ingreso Neto").Value)
  393. Next
  394. Return TotalIngr
  395. End Function
  396. Private Sub Button1_Click(sender As Object, e As EventArgs)
  397. End Sub
  398. Function NuevoElemento()
  399. Dim Index As Integer = dgvIntereses.Rows.Count - 2
  400. Dim diccionario As New Dictionary(Of String, Collection)
  401. For i As Integer = 0 To Index
  402. Dim colec As Collection = ColeccionElementos(i)
  403. diccionario.Add(i, colec)
  404. Next
  405. Return diccionario
  406. End Function
  407. Sub NuevoElementoGuardar()
  408. Dim Index As Integer = dgvIntereses.Rows.Count - 2
  409. For i As Integer = 0 To Index
  410. Dim colec As Collection = ColeccionElementos(i)
  411. oDAONEST.NuevoElemento(colec, codigo)
  412. Next
  413. End Sub
  414. Sub ModificarElemento()
  415. oDAONEST.EliminarElemento(codigo)
  416. NuevoElementoGuardar()
  417. End Sub
  418. Sub EliminarElemento()
  419. oDAONEST.EliminarElemento(codigo)
  420. End Sub
  421. Sub Nuevo()
  422. Dim colec As Collection = ColeccionDatos()
  423. Dim Diccionario As Dictionary(Of String, Collection) = NuevoElemento()
  424. oDAONEST.NuevoDato(colec, Diccionario, codigo)
  425. End Sub
  426. Sub Modificar()
  427. Dim colec As Collection = ColeccionDatos()
  428. Dim Diccionario As Dictionary(Of String, Collection) = NuevoElemento()
  429. oDAONEST.ModificarDato(colec, codigo, NuevoElemento())
  430. End Sub
  431. Sub Eliminar()
  432. Dim codigo As String = Variables.Codigo
  433. oDAONEST.Eliminar(codigo)
  434. End Sub
  435. Private Sub btnGME_Click(sender As Object, e As EventArgs) Handles btnGME.Click
  436. If (Estado = "N") Then
  437. Nuevo()
  438. ElseIf (Estado = "M") Then
  439. Modificar()
  440. ElseIf (Estado = "B") Then
  441. Eliminar()
  442. ElseIf Not ExisteValidacion() Then
  443. Variables.ColeccionNEST = ColeccionDatos()
  444. Variables.ColeccionNESTDi = NuevoElemento()
  445. Me.Close()
  446. End If
  447. End Sub
  448. Private Sub txtRendimientoBruto_TextChanged(sender As Object, e As EventArgs) Handles txtRendimientoBruto.TextChanged
  449. End Sub
  450. Private Sub Button1_Click_1(sender As Object, e As EventArgs)
  451. Me.Operaciones.CambioBase(dtpFechaOperacion.Value, dtpFechaVencimiento.Value)
  452. End Sub
  453. Private Sub txtPlazo_TextChanged_1(sender As Object, e As EventArgs) Handles txtPlazo.TextChanged
  454. CalcularPlazo()
  455. Calculo()
  456. End Sub
  457. Sub AgregarCampos()
  458. Dim Correlativo, Plazo, Fecha, IngrBruto, PorcImp, MontoImp, IngrNeto As New DataGridViewTextBoxColumn
  459. Correlativo.Name = "Correlativo"
  460. Plazo.Name = "Plazo"
  461. Fecha.Name = "Fecha"
  462. IngrBruto.Name = "Ingreso Bruto"
  463. PorcImp.Name = "% Impuesto"
  464. PorcImp.DefaultCellStyle.Format = Configuraciones.CodigoTXTPorcentaje
  465. MontoImp.Name = "Monto del Impuesto"
  466. IngrNeto.Name = "Ingreso Neto"
  467. dgvIntereses.Columns.Add(Correlativo)
  468. dgvIntereses.Columns.Add(Plazo)
  469. dgvIntereses.Columns.Add(Fecha)
  470. dgvIntereses.Columns.Add(IngrBruto)
  471. dgvIntereses.Columns.Add(PorcImp)
  472. dgvIntereses.Columns.Add(MontoImp)
  473. dgvIntereses.Columns.Add(IngrNeto)
  474. End Sub
  475. Sub CalcularPlazo()
  476. dgvIntereses.Rows.Clear()
  477. Dim PlazoGlobal As Integer = Operaciones.ConvertirEntero(txtPlazo.Text.ToString)
  478. Dim Periodicidad As String = String.Empty
  479. If Not cboPeriodicidad.SelectedValue Is Nothing Then
  480. Try
  481. Periodicidad = cboPeriodicidad.SelectedValue
  482. Catch ex As Exception
  483. End Try
  484. End If
  485. Dim FechaInicial As Date = dtpFechaOperacion.Value
  486. Dim IngrBruto As Double = 0.0
  487. Dim Monto As Double = Operaciones.ConvertirDecimal(txtMontoInversion.Text.ToString)
  488. Dim Tasa As Double = Operaciones.ConvertirDecimal(txtTasa.Text.ToString) / 100
  489. Dim Impuesto As Double = Operaciones.ConvertirDecimal(txtImpuesto.Text.ToString) / 100
  490. Dim Renta As Double = 0.0
  491. Dim FechaAnterior As Date
  492. Dim IngresoNeto As Double = 0.0
  493. Dim SumaIngresoBruto, SumaRenta, SumaIngresoNeto As Double
  494. Dim Plazo = NotaCalcular.CalcularPlazo(Periodicidad)
  495. Dim Cantidad = NotaCalcular.CalcularIteraciones(PlazoGlobal, Plazo)
  496. Dim Fecha As String = String.Empty
  497. For i As Integer = 1 To Cantidad
  498. If (i = 1) Then
  499. Fecha = Format(NotaCalcular.CalcularFecha(Plazo, FechaInicial), "dd/MM/yyyy")
  500. IngrBruto = NotaCalcular.CalculosIngrBruto(FechaInicial, Fecha, Monto, Tasa, Plazo)
  501. Else
  502. If (String.IsNullOrEmpty(Fecha.ToString)) Then
  503. Exit Sub
  504. End If
  505. FechaAnterior = Fecha
  506. Fecha = Format(NotaCalcular.CalcularFecha(Plazo, Fecha), "dd/MM/yyyy")
  507. IngrBruto = NotaCalcular.CalculosIngrBruto(FechaAnterior, Fecha, Monto, Tasa, Plazo)
  508. End If
  509. Renta = NotaCalcular.Renta(Impuesto, IngrBruto)
  510. IngresoNeto = NotaCalcular.CalculosIngNeto(IngrBruto, Renta)
  511. SumaIngresoBruto = SumaIngresoBruto + IngrBruto
  512. SumaRenta = SumaRenta + Renta
  513. SumaIngresoNeto = SumaIngresoNeto + IngresoNeto
  514. dgvIntereses.Rows.Add(i, Plazo, Fecha, IngrBruto, Impuesto, Renta, IngresoNeto)
  515. Next
  516. txtIngresoBruto.Text = SumaIngresoBruto
  517. txtRenta.Text = SumaRenta
  518. txtIngresoNeto.Text = SumaIngresoNeto
  519. End Sub
  520. Private Sub txtMontoInversion_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMontoInversion.KeyPress
  521. If String.IsNullOrEmpty(txtMontoInversion.Text) Then
  522. If e.KeyChar = "." Then
  523. txtMontoInversion.Text = "0"
  524. Exit Sub
  525. End If
  526. End If
  527. If (Not txtMontoInversion.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  528. Operaciones.ValidarEntrada(sender, e, True)
  529. Else
  530. Operaciones.ValidarEntrada(sender, e, False)
  531. End If
  532. End Sub
  533. Private Sub txtPlazo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPlazo.KeyPress
  534. If String.IsNullOrEmpty(txtPlazo.Text) Then
  535. If e.KeyChar = "." Then
  536. txtPlazo.Text = "0"
  537. Exit Sub
  538. End If
  539. End If
  540. If (Not txtPlazo.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  541. Operaciones.ValidarEntrada(sender, e, True)
  542. Else
  543. Operaciones.ValidarEntrada(sender, e, False)
  544. End If
  545. End Sub
  546. Private Sub txtTasa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasa.KeyPress
  547. If String.IsNullOrEmpty(txtTasa.Text) Then
  548. If e.KeyChar = "." Then
  549. txtTasa.Text = "0"
  550. Exit Sub
  551. End If
  552. End If
  553. If (Not txtTasa.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  554. Operaciones.ValidarEntrada(sender, e, True)
  555. Else
  556. Operaciones.ValidarEntrada(sender, e, False)
  557. End If
  558. End Sub
  559. Private Sub txtMontoInversion_Leave(sender As Object, e As EventArgs) Handles txtMontoInversion.Leave
  560. RellenarDatos()
  561. End Sub
  562. Private Sub txtPlazo_Leave(sender As Object, e As EventArgs) Handles txtPlazo.Leave
  563. RellenarDatos()
  564. End Sub
  565. Private Sub txtTasa_Leave(sender As Object, e As EventArgs) Handles txtTasa.Leave
  566. RellenarDatos()
  567. End Sub
  568. Private Sub txtMontoInversion_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMontoInversion.KeyUp
  569. If txtMontoInversion.Text = "." Then
  570. txtMontoInversion.Text = ".0"
  571. End If
  572. End Sub
  573. Private Sub txtPlazo_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPlazo.KeyUp
  574. If txtPlazo.Text = "." Then
  575. txtPlazo.Text = ".0"
  576. End If
  577. End Sub
  578. Private Sub txtTasa_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasa.KeyUp
  579. If txtTasa.Text = "." Then
  580. txtTasa.Text = ".0"
  581. End If
  582. End Sub
  583. Private Sub txtImpuesto_TextChanged(sender As Object, e As EventArgs) Handles txtImpuesto.TextChanged
  584. CalcularPlazo()
  585. Calculo()
  586. End Sub
  587. Sub CargarTransladoNuevo()
  588. Dim Existe As Boolean = ExisteInversion()
  589. If Not RetCodigoInversionExiste And Not Existe Then
  590. txtMontoInversion.Text = Variables.RetMonto
  591. txtTasa.Text = Variables.RetRendimiento
  592. End If
  593. End Sub
  594. End Class