frmDepositosAPlazo.vb 26 KB

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