frmNotaEstructurada.vb 25 KB

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