frmNotaEstructurada.vb 24 KB

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