frmDepositosAPlazo.vb 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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. 'Dim oUtilidades As New Utilidades
  12. Private _TipoTransaccion As String
  13. Private _IdDocumento As Integer
  14. Private _TipoDocumento As String
  15. Private _CodigoInversion As String
  16. Private Property CodigoInversion As String
  17. Get
  18. Return _CodigoInversion
  19. End Get
  20. Set(value As String)
  21. _CodigoInversion = value
  22. End Set
  23. End Property
  24. Public Property TipoTransaccion As String
  25. Get
  26. Return _TipoTransaccion
  27. End Get
  28. Set(value As String)
  29. _TipoTransaccion = value
  30. End Set
  31. End Property
  32. Private Property IdDocumento As Integer
  33. Get
  34. Return _IdDocumento
  35. End Get
  36. Set(value As Integer)
  37. _IdDocumento = value
  38. End Set
  39. End Property
  40. Private Property TipoDocumento As String
  41. Get
  42. Return _TipoDocumento
  43. End Get
  44. Set(value As String)
  45. _TipoDocumento = value
  46. End Set
  47. End Property
  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. Private Sub frmDAP_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  60. 'Me.txtBase.Text = AnioBase.ToString
  61. dgvIntereses.Columns.Clear()
  62. AgregarCampos()
  63. Call CargarPeriodos()
  64. If TipoTransaccion Is Nothing Then
  65. TipoTransaccion = "N"
  66. PrepararNuevo()
  67. End If
  68. Call CargarRegistroBD()
  69. PreparardgvIntereses()
  70. CalcularPlazo()
  71. Calculo()
  72. vCargado = True
  73. ExisteInversion()
  74. ValidarExistencia()
  75. CargarTransladoNuevo()
  76. End Sub
  77. Function ExisteInversion()
  78. Dim Codigo As String = Variables.Codigo
  79. Dim TablaINV As String = "INV0"
  80. Dim TablaPINV As String = "PIN0"
  81. Dim General As New DAOGeneral
  82. Dim InvPro = Variables.InvPro
  83. If InvPro = "I" Then
  84. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  85. If INV0 Then
  86. navNuevo.Visible = True
  87. Return True
  88. Else
  89. navNuevo.Visible = False
  90. Return False
  91. End If
  92. End If
  93. If InvPro = "P" Then
  94. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  95. If PINV0 Then
  96. navNuevo.Visible = True
  97. Return True
  98. Else
  99. navNuevo.Visible = False
  100. Return False
  101. End If
  102. End If
  103. Return False
  104. End Function
  105. Sub ValidarExistencia()
  106. Dim General As New DAOGeneral
  107. Dim Codigo As String = Variables.Codigo
  108. Dim Tabla As String = String.Empty
  109. Tabla = "DAP0"
  110. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  111. If (Existe) Then
  112. navNuevo.Enabled = False
  113. navModificar.Enabled = True
  114. navEliminar.Enabled = True
  115. Else
  116. navNuevo.Enabled = True
  117. navModificar.Enabled = False
  118. navEliminar.Enabled = False
  119. 'LimpiarCampos()
  120. End If
  121. Estado = String.Empty
  122. btnGME.Text = "Aceptar"
  123. End Sub
  124. Function ExisteValidacion()
  125. Dim General As New DAOGeneral
  126. Dim Codigo As String = Variables.Codigo
  127. Dim Tabla As String = String.Empty
  128. Tabla = "DAP0"
  129. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  130. Return Existe
  131. End Function
  132. Sub LimpiarCampos()
  133. txtMontoInversion.Text = "0"
  134. txtPlazo.Text = 0
  135. txtTasa.Text = 0
  136. cboPeriodicidad.SelectedIndex = 0
  137. txtRendimientoBruto.Text = "0.0%"
  138. txtRendimientoNeto.Text = "0.0%"
  139. dtpFechaOperacion.Value = Date.Now.Date
  140. dtpFechaVencimiento.Value = Date.Now.Date
  141. End Sub
  142. Private Sub txtPlazo_TextChanged(sender As Object, e As EventArgs)
  143. 'If Modo = "N" Then
  144. ' RefrescarFechaVencimiento()
  145. ' CalcularIntereses()
  146. 'End If
  147. Calculo()
  148. End Sub
  149. Private Sub txtPlazo_LostFocus(sender As Object, e As EventArgs)
  150. ' ControlPlazo()
  151. End Sub
  152. Private Sub ControlPlazo()
  153. Dim valor As Integer
  154. If Not Integer.TryParse(txtPlazo.Text.ToString, valor) Then
  155. txtPlazo.Focus()
  156. txtPlazo.BackColor = Configuraciones.ColorFondoError
  157. Else
  158. txtPlazo.BackColor = Color.White
  159. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  160. oDAPCE.Plazo = valor
  161. End If
  162. RefrescarValorControles()
  163. End If
  164. End Sub
  165. Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged
  166. 'If Modo = "N" Then
  167. ' RefrescarFechaVencimiento()
  168. 'End If
  169. 'ControlFechaOperacion()
  170. CalcularPlazo()
  171. Calculo()
  172. End Sub
  173. Private Sub ControlFechaOperacion()
  174. Dim valor As Date
  175. valor = dtpFechaOperacion.Value.Date
  176. If TipoTransaccion = "N" Then
  177. oDAPCE.FechaOperacion = valor
  178. End If
  179. RefrescarValorControles()
  180. End Sub
  181. Private Sub txtIngresoBruto_TextChanged(sender As Object, e As EventArgs)
  182. 'If Modo = "N" Then
  183. ' RefrescarRendimientoBruto()
  184. 'End If
  185. End Sub
  186. Private Sub txtTasa_TextChanged(sender As Object, e As EventArgs) Handles txtTasa.TextChanged
  187. 'If Modo = "N" Then
  188. ' CalcularIntereses()
  189. 'End If
  190. Calculo()
  191. If (txtTasa.ToString.IndexOf("%") = -1) Then
  192. txtTasa.Text += "%"
  193. End If
  194. CalcularPlazo()
  195. Calculo()
  196. End Sub
  197. Private Sub txtTasa_LostFocus(sender As Object, e As EventArgs) Handles txtTasa.LostFocus
  198. ' ControlTasa()
  199. End Sub
  200. Private Sub ControlTasa()
  201. Dim valor As Double
  202. If Not Double.TryParse(txtTasa.Text, valor) Then
  203. txtTasa.Focus()
  204. txtTasa.BackColor = Configuraciones.ColorFondoError
  205. Else
  206. txtTasa.BackColor = Color.White
  207. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  208. oDAPCE.Tasa = valor
  209. End If
  210. RefrescarValorControles()
  211. End If
  212. End Sub
  213. Private Sub txtMontoInversion_TextChanged(sender As Object, e As EventArgs) Handles txtMontoInversion.TextChanged
  214. 'If Modo = "N" Then
  215. ' CalcularIntereses()
  216. 'End If
  217. CalcularPlazo()
  218. Calculo()
  219. End Sub
  220. Private Sub txtMontoInversion_LostFocus(sender As Object, e As EventArgs) Handles txtMontoInversion.LostFocus
  221. ' ControlMontoInversion()
  222. End Sub
  223. Private Sub ControlMontoInversion()
  224. Dim valor As Double
  225. If Not Double.TryParse(txtMontoInversion.Text, valor) Then
  226. txtMontoInversion.Focus()
  227. txtMontoInversion.BackColor = Configuraciones.ColorFondoError
  228. Else
  229. txtMontoInversion.BackColor = Color.White
  230. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  231. oDAPCE.MontoDeInversion = valor
  232. End If
  233. RefrescarValorControles()
  234. End If
  235. End Sub
  236. Private Sub txtIngresoNeto_TextChanged(sender As Object, e As EventArgs)
  237. 'If Modo = "N" Then
  238. ' RefrescarRendimientoNeto()
  239. 'End If
  240. End Sub
  241. Sub CargarPeriodos()
  242. If cboPeriodicidad.Items.Count = 0 Or cboPeriodicidad.Items.Count = 1 Then
  243. Me.cboPeriodicidad.DataSource = oDAOGeneral.ListaPeriodicidad
  244. Me.cboPeriodicidad.DisplayMember = "Descripcion"
  245. Me.cboPeriodicidad.ValueMember = "Codigo"
  246. Me.cboPeriodicidad.SelectedIndex = 0
  247. End If
  248. End Sub
  249. Private Sub btnAceptar_Click(sender As Object, e As EventArgs)
  250. If (Estado = "N") Then
  251. NuevoElemento()
  252. ElseIf (Estado = "M") Then
  253. ModificarElemento()
  254. ElseIf (Estado = "B") Then
  255. EliminarElemento()
  256. End If
  257. End Sub
  258. Function RetornarObjeto()
  259. Return oDAPCE
  260. End Function
  261. Private Sub CargarRegistroBD()
  262. oDAPCE = Nothing
  263. oDAPDAO = New DepositosAPlazoDAO
  264. CodigoInversion = Variables.Codigo
  265. 'oDAPDAO.CargarRegistro(oDAPCE, TipoDocumento, IdDocumento)
  266. oDAPCE = oDAPDAO.CargarRegistro(Me.CodigoInversion)
  267. TipoTransaccion = "C"
  268. RefrescarValorControles()
  269. End Sub
  270. Public Sub CargarRegistro(vId As Integer, vTipo As String)
  271. TipoTransaccion = "C"
  272. IdDocumento = vId
  273. TipoDocumento = vTipo
  274. End Sub
  275. Private Sub dtpFechaVencimiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimiento.ValueChanged
  276. 'ControlFechaVencimiento()
  277. CalcularPlazo()
  278. Calculo()
  279. End Sub
  280. Private Sub ControlFechaVencimiento()
  281. Dim valor As Date
  282. valor = dtpFechaVencimiento.Value.Date.ToString
  283. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  284. oDAPCE.FechaVencimiento = valor
  285. End If
  286. RefrescarValorControles()
  287. End Sub
  288. Private Sub cboPeriodicidad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPeriodicidad.SelectedIndexChanged
  289. 'ControlPreriodicidad()
  290. CalcularPlazo()
  291. Calculo()
  292. End Sub
  293. Private Sub ControlPreriodicidad()
  294. Dim valor As String
  295. If vCargado Then
  296. If TipoTransaccion = "N" Or TipoTransaccion = "M" Then
  297. valor = cboPeriodicidad.SelectedValue
  298. oDAPCE.Periodicidad = valor
  299. End If
  300. If TipoTransaccion IsNot Nothing Then
  301. RefrescarValorControles()
  302. End If
  303. End If
  304. End Sub
  305. Public Sub CargarRegistro(ByRef vCodigoInversion As String)
  306. TipoTransaccion = "C"
  307. Me.CodigoInversion = vCodigoInversion
  308. End Sub
  309. Private Sub RefrescarValorControles()
  310. If Not oDAPCE Is Nothing Then
  311. Me.txtMontoInversion.Text = oDAPCE.MontoDeInversion.ToString(Configuraciones.CodigoTXTMontos)
  312. Me.dtpFechaOperacion.Value = oDAPCE.FechaOperacion
  313. Me.dtpFechaVencimiento.Value = oDAPCE.FechaVencimiento
  314. Me.txtTasa.Text = oDAPCE.Tasa.ToString(Configuraciones.CodigoTXTMontos)
  315. txtPlazo.Text = oDAPCE.Plazo.ToString
  316. 'txtPlazo.Text = 10 'oDAPCE.Plazo.ToString
  317. 'anio base
  318. Me.cboPeriodicidad.SelectedValue = oDAPCE.Periodicidad
  319. Me.txtRendimientoBruto.Text = oDAPCE.RendimientoBruto.ToString(Configuraciones.CodigoTXTMontos)
  320. Me.txtRendimientoNeto.Text = oDAPCE.RendimientoNeto.ToString(Configuraciones.CodigoTXTMontos)
  321. For Each item As DataRow In oDAPCE.dtIntereses.Rows
  322. Me.txtImpuesto.Text = item("PorcImp") * 100
  323. Next
  324. End If
  325. End Sub
  326. Private Sub PreparardgvIntereses()
  327. End Sub
  328. Private Sub PrepararCalculoIntereses(ByVal IdFila As Integer, idColumna As Integer)
  329. Dim vFila As DataGridViewRow = dgvIntereses.Rows(IdFila)
  330. Dim vFilaAnterior As DataGridViewRow
  331. Dim vFecha As Date
  332. Dim vFechaAnterior As Date
  333. Dim vPeriodicidad As String = oDAPCE.Periodicidad
  334. Dim vDiasDelPeriodo As Integer
  335. If vFila.IsNewRow Then
  336. If IdFila = 0 Then
  337. vFecha = oDAPCE.FechaOperacion
  338. Else
  339. vFilaAnterior = dgvIntereses.Rows(IdFila - 1)
  340. vFecha = vFilaAnterior.Cells("Fecha").Value
  341. End If
  342. 'vFecha = vFechaAnterior
  343. If vPeriodicidad = "M" Then
  344. vDiasDelPeriodo = 30
  345. ElseIf vPeriodicidad = "T" Then
  346. vDiasDelPeriodo = 90
  347. ElseIf vPeriodicidad = "S" Then
  348. vDiasDelPeriodo = 180
  349. Else
  350. vDiasDelPeriodo = 30
  351. End If
  352. vFila.Cells("Plazo").Value = vDiasDelPeriodo
  353. If Not IdFila = 0 Then
  354. vFecha = vFecha.AddDays(vFila.Cells("Plazo").Value)
  355. End If
  356. vFila.Cells("Fecha").Value = vFecha
  357. vFila.Cells("PorcImp").Value = 0.1
  358. vFila.Cells("Estado").Value = "A"
  359. dgvIntereses.Rows(IdFila).Selected = False
  360. 'dgvIntereses.Rows.Insert(IdFila + 1)
  361. 'MsgBox("IsNewRow")
  362. Else
  363. 'MsgBox("No IsNewRow")
  364. End If
  365. 'CalcularIntereses(IdFila)
  366. 'dgvIntereses.Refresh()
  367. End Sub
  368. Private Sub dgvIntereses_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles dgvIntereses.CellBeginEdit
  369. 'MsgBox("CellBeginEdit")
  370. ' PrepararCalculoIntereses(e.RowIndex, e.ColumnIndex)
  371. End Sub
  372. Private Sub CalcularIntereses(ByVal IdFila As Integer, ByVal IdCol As Integer)
  373. Dim vFila As DataGridViewRow = dgvIntereses.Rows(IdFila)
  374. Dim vFilaAnterior As DataGridViewRow
  375. Dim vPlazo As Integer = 0
  376. Dim vFechaAnterior As Date
  377. Dim vFecha As Date
  378. Dim vIngresoBruto As Double = 0
  379. Dim vMontoInversion As Double = oDAPCE.MontoDeInversion
  380. Dim vTasa As Double = oDAPCE.Tasa
  381. Dim vPorcentajeImpuesto As Double = 0
  382. Dim vMontoImpuesto As Double = 0
  383. Dim vIngresoNeto As Double = 0
  384. If (Not String.IsNullOrEmpty(vTasa.ToString) And Not vTasa.ToString = "0") Then
  385. vTasa = vTasa / 100
  386. End If
  387. If (Not String.IsNullOrEmpty(vPorcentajeImpuesto.ToString) And Not vPorcentajeImpuesto.ToString = "0") Then
  388. vPorcentajeImpuesto = vPorcentajeImpuesto / 100
  389. End If
  390. If IdFila = 0 Then
  391. vFechaAnterior = oDAPCE.FechaOperacion
  392. Else
  393. vFilaAnterior = dgvIntereses.Rows(IdFila - 1)
  394. vFechaAnterior = vFilaAnterior.Cells("Fecha").Value
  395. End If
  396. 'vFecha = vFila.Cells("Fecha").Value
  397. vFecha = vFechaAnterior
  398. 'If vFila.IsNewRow Then
  399. Integer.TryParse(vFila.Cells("Plazo").Value.ToString, vPlazo)
  400. Double.TryParse(vFila.Cells("PorcImp").Value.ToString, vPorcentajeImpuesto)
  401. vFecha = DateAdd(DateInterval.Day, vPlazo, vFecha)
  402. vIngresoBruto = vMontoInversion * vTasa * vPlazo
  403. If (Not String.IsNullOrEmpty(Utilidades.CalcularDiasDelAnio(vFecha).ToString) And Not Utilidades.CalcularDiasDelAnio(vFecha) = 0) Then
  404. vIngresoBruto = vIngresoBruto / Utilidades.CalcularDiasDelAnio(vFecha)
  405. Else
  406. vIngresoBruto = "0.0"
  407. End If
  408. vFila.Cells("IngrBruto").Value = vIngresoBruto
  409. vMontoImpuesto = vIngresoBruto * vPorcentajeImpuesto
  410. vFila.Cells("MontoImp").Value = vMontoImpuesto
  411. vIngresoNeto = vIngresoBruto - vMontoImpuesto
  412. vFila.Cells("IngrNeto").Value = vIngresoNeto
  413. 'End If
  414. If dgvIntereses.IsCurrentCellDirty Then
  415. dgvIntereses.CommitEdit(DataGridViewDataErrorContexts.Commit)
  416. End If
  417. RefrescarClaseEntidad()
  418. RefrescarValorControles()
  419. End Sub
  420. Private Sub RefrescarClaseEntidad()
  421. ControlMontoInversion()
  422. ControlFechaOperacion()
  423. ControlFechaVencimiento()
  424. ControlTasa()
  425. ControlPlazo()
  426. ControlPreriodicidad()
  427. End Sub
  428. Private Sub dgvIntereses_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellEndEdit
  429. 'If e.ColumnIndex = dgvIntereses.Columns("PorcImp").Index Then
  430. ' Dim valor As Double
  431. ' valor = dgvIntereses.Rows(e.RowIndex).Cells("PorcImp").Value
  432. ' valor = valor / 100
  433. ' dgvIntereses.Rows(e.RowIndex).Cells("PorcImp").Value = valor
  434. 'End If
  435. 'CalcularIntereses(e.RowIndex, e.ColumnIndex)
  436. End Sub
  437. Private Sub dgvIntereses_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellContentClick
  438. End Sub
  439. Private Sub PrepararNuevo()
  440. oDAPCE = New DepositosAPlazoCE
  441. RefrescarValorControles()
  442. 'PreparardgvIntereses()
  443. End Sub
  444. Private Sub dgvIntereses_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellLeave
  445. End Sub
  446. Private Sub dgvIntereses_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.CellEnter
  447. End Sub
  448. Private Sub dgvIntereses_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles dgvIntereses.RowPostPaint
  449. 'MsgBox("RowPostPaint")
  450. End Sub
  451. Private Sub dgvIntereses_RowPrePaint(sender As Object, e As DataGridViewRowPrePaintEventArgs) Handles dgvIntereses.RowPrePaint
  452. 'MsgBox("RowPrePaint")
  453. End Sub
  454. Private Sub dgvIntereses_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles dgvIntereses.RowsAdded
  455. 'MsgBox("RowsAdded")
  456. End Sub
  457. Private Sub dgvIntereses_RowValidated(sender As Object, e As DataGridViewCellEventArgs) Handles dgvIntereses.RowValidated
  458. End Sub
  459. Private Sub ActualizarRegistro()
  460. Dim res As Integer
  461. RefrescarClaseEntidad()
  462. res = oDAPDAO.Actualizar(oDAPCE)
  463. If res > 0 Then
  464. MsgBox("Registro Guardado")
  465. Else
  466. MsgBox("Algo no salio bien.")
  467. End If
  468. End Sub
  469. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  470. btnGME.Text = "Modificar"
  471. Estado = "M"
  472. End Sub
  473. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  474. btnGME.Text = "Nuevo"
  475. Estado = "N"
  476. End Sub
  477. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  478. btnGME.Text = "Eliminar"
  479. Estado = "B"
  480. End Sub
  481. Function ColeccionDatos()
  482. Dim Coleccion As New Collection
  483. Dim MontoInv, FOper, FVenc, Tasa, Plazo, Periodic, RendBr, RendNet, IngrBrutoTot, IngrNetoTot, Renta As String
  484. MontoInv = CDec(txtMontoInversion.Text)
  485. FOper = CDate(dtpFechaOperacion.Value)
  486. FVenc = CDate(dtpFechaVencimiento.Value)
  487. Tasa = CDec(txtTasa.Text.ToString.Trim("%"))
  488. Plazo = CInt(txtPlazo.Text)
  489. Periodic = cboPeriodicidad.SelectedValue
  490. RendBr = CDec(txtRendimientoBruto.Text.ToString.Trim("%")) / 100
  491. RendNet = CDec(txtRendimientoNeto.Text.ToString.Trim("%")) / 100
  492. IngrBrutoTot = txtIngresoBruto.Text
  493. IngrNetoTot = txtIngresoNeto.Text
  494. Renta = txtRenta.Text
  495. Coleccion.Add(MontoInv)
  496. Coleccion.Add(FOper)
  497. Coleccion.Add(FVenc)
  498. Coleccion.Add(Tasa)
  499. Coleccion.Add(Plazo)
  500. Coleccion.Add(Periodic)
  501. Coleccion.Add(RendBr)
  502. Coleccion.Add(RendNet)
  503. Coleccion.Add(IngrBrutoTot)
  504. Coleccion.Add(IngrNetoTot)
  505. Coleccion.Add(Renta)
  506. Return Coleccion
  507. End Function
  508. Function ColeccionElementos(ByVal Index As Integer)
  509. Dim Coleccion As New Collection
  510. Dim Correlativo, plazo, Fecha, IngBruto, PorcImp, MontoImp, IngrNeto As String
  511. Correlativo = dgvIntereses.Rows(Index).Cells("Correlativo").Value.ToString
  512. plazo = dgvIntereses.Rows(Index).Cells("Plazo").Value.ToString
  513. Fecha = dgvIntereses.Rows(Index).Cells("Fecha").Value.ToString
  514. IngBruto = dgvIntereses.Rows(Index).Cells("Ingreso Bruto").Value.ToString
  515. PorcImp = dgvIntereses.Rows(Index).Cells("% Impuesto").Value.ToString.Trim("%")
  516. MontoImp = dgvIntereses.Rows(Index).Cells("Monto del Impuesto").Value.ToString
  517. IngrNeto = dgvIntereses.Rows(Index).Cells("Ingreso Neto").Value.ToString
  518. Coleccion.Add(Correlativo)
  519. Coleccion.Add(plazo)
  520. Coleccion.Add(Fecha)
  521. Coleccion.Add(IngBruto)
  522. Coleccion.Add(PorcImp)
  523. Coleccion.Add(MontoImp)
  524. Coleccion.Add(IngrNeto)
  525. Return Coleccion
  526. End Function
  527. Sub Calculo()
  528. Dim Plazo As Integer = 0
  529. If Not String.IsNullOrEmpty(txtPlazo.Text.ToString) Then
  530. Plazo = txtPlazo.Text
  531. End If
  532. dtpFechaVencimiento.Value = dtpFechaOperacion.Value.AddDays(Plazo)
  533. CalcularRendBruto()
  534. CalcularRendNeto()
  535. End Sub
  536. Sub CalcularRendBruto()
  537. 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
  538. Dim Total = TotalIngreso()
  539. Dim MontoInv = CDec(txtMontoInversion.Text)
  540. Dim Base = 365
  541. Dim pla = CDec(txtPlazo.Text)
  542. Dim tot As Double = 0
  543. If (Not MontoInv = 0 And Not pla = 0) Then
  544. tot = (Total / MontoInv) * (Base / pla)
  545. End If
  546. txtRendimientoBruto.Text = CStr((tot * 100)) + "%"
  547. Else
  548. txtRendimientoBruto.Text = "0.0%"
  549. End If
  550. End Sub
  551. Sub CalcularRendNeto()
  552. 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
  553. Dim Total = TotalIngresoNeto()
  554. Dim MontoInv = CDec(txtMontoInversion.Text)
  555. Dim Base = 365
  556. Dim pla = CDec(txtPlazo.Text)
  557. Dim tot As Double = 0
  558. If (Not MontoInv = 0 And Not pla = 0) Then
  559. tot = (Total / MontoInv) * (Base / pla)
  560. End If
  561. txtRendimientoNeto.Text = CStr((tot * 100)) + "%"
  562. Else
  563. txtRendimientoNeto.Text = "0.0%"
  564. End If
  565. End Sub
  566. Function TotalIngreso()
  567. Dim Cantidad = CDec(dgvIntereses.Rows.Count - 1)
  568. Dim TotalIngr As Double = 0
  569. For i As Integer = 0 To Cantidad
  570. TotalIngr = TotalIngr + CDec(dgvIntereses.Rows(i).Cells("Ingreso Bruto").Value)
  571. Next
  572. Return TotalIngr
  573. End Function
  574. Function TotalIngresoNeto()
  575. Dim Cantidad = dgvIntereses.Rows.Count - 1
  576. Dim TotalIngr As Double = 0
  577. For i As Integer = 0 To Cantidad
  578. TotalIngr = TotalIngr + CDec(dgvIntereses.Rows(i).Cells("Ingreso Neto").Value)
  579. Next
  580. Return TotalIngr
  581. End Function
  582. Private Sub Button1_Click(sender As Object, e As EventArgs)
  583. 'ColeccionElementos()
  584. End Sub
  585. Function NuevoElemento()
  586. Dim Index As Integer = dgvIntereses.Rows.Count - 2
  587. Dim diccionario As New Dictionary(Of String, Collection)
  588. For i As Integer = 0 To Index
  589. Dim colec As Collection = ColeccionElementos(i)
  590. 'oDAPDAO.NuevoElemento(colec, codigo)
  591. diccionario.Add(i, colec)
  592. Next
  593. Return diccionario
  594. End Function
  595. Function NuevoElementoGuardar()
  596. Dim Index As Integer = dgvIntereses.Rows.Count - 2
  597. For i As Integer = 0 To Index
  598. Dim colec As Collection = ColeccionElementos(i)
  599. oDAPDAO.NuevoElemento(colec, codigo)
  600. Next
  601. End Function
  602. Sub ModificarElemento()
  603. oDAPDAO.EliminarElemento(codigo)
  604. NuevoElementoGuardar()
  605. End Sub
  606. Sub EliminarElemento()
  607. oDAPDAO.EliminarElemento(codigo)
  608. End Sub
  609. Sub Nuevo()
  610. Dim colec As Collection = ColeccionDatos()
  611. Dim Diccionario As Dictionary(Of String, Collection) = NuevoElemento()
  612. oDAPDAO.NuevoDato(colec, Diccionario, codigo)
  613. End Sub
  614. Sub Modificar()
  615. Dim colec As Collection = ColeccionDatos()
  616. Dim Diccionario As Dictionary(Of String, Collection) = NuevoElemento()
  617. oDAPDAO.ModificarDato(colec, codigo, NuevoElemento())
  618. End Sub
  619. Sub Eliminar()
  620. Dim codigo As String = Variables.Codigo
  621. oDAPDAO.Eliminar(codigo)
  622. End Sub
  623. Private Sub btnGME_Click(sender As Object, e As EventArgs) Handles btnGME.Click
  624. If (Estado = "N") Then
  625. Nuevo()
  626. ElseIf (Estado = "M") Then
  627. Modificar()
  628. ElseIf (Estado = "B") Then
  629. Eliminar()
  630. ElseIf Not ExisteValidacion() Then
  631. Variables.ColeccionDAP = ColeccionDatos()
  632. Variables.ColeccionDAPDi = NuevoElemento()
  633. Me.Close()
  634. End If
  635. End Sub
  636. Private Sub txtRendimientoBruto_TextChanged(sender As Object, e As EventArgs) Handles txtRendimientoBruto.TextChanged
  637. End Sub
  638. Private Sub Button1_Click_1(sender As Object, e As EventArgs)
  639. Me.Operaciones.CambioBase(dtpFechaOperacion.Value, dtpFechaVencimiento.Value)
  640. End Sub
  641. Private Sub txtPlazo_TextChanged_1(sender As Object, e As EventArgs) Handles txtPlazo.TextChanged
  642. CalcularPlazo()
  643. Calculo()
  644. End Sub
  645. Sub AgregarCampos()
  646. Dim Correlativo, Plazo, Fecha, IngrBruto, PorcImp, MontoImp, IngrNeto As New DataGridViewTextBoxColumn
  647. Correlativo.Name = "Correlativo"
  648. Plazo.Name = "Plazo"
  649. Fecha.Name = "Fecha"
  650. IngrBruto.Name = "Ingreso Bruto"
  651. PorcImp.Name = "% Impuesto"
  652. PorcImp.DefaultCellStyle.Format = Configuraciones.CodigoTXTPorcentaje
  653. MontoImp.Name = "Monto del Impuesto"
  654. IngrNeto.Name = "Ingreso Neto"
  655. dgvIntereses.Columns.Add(Correlativo)
  656. dgvIntereses.Columns.Add(Plazo)
  657. dgvIntereses.Columns.Add(Fecha)
  658. dgvIntereses.Columns.Add(IngrBruto)
  659. dgvIntereses.Columns.Add(PorcImp)
  660. dgvIntereses.Columns.Add(MontoImp)
  661. dgvIntereses.Columns.Add(IngrNeto)
  662. End Sub
  663. Sub CalcularPlazo()
  664. dgvIntereses.Rows.Clear()
  665. Dim PlazoGlobal As Integer = 0
  666. If String.IsNullOrEmpty(txtPlazo.Text) Then
  667. PlazoGlobal = 0
  668. Else
  669. PlazoGlobal = CDec(txtPlazo.Text)
  670. End If
  671. Dim Periodicidad As String = String.Empty
  672. If Not cboPeriodicidad.SelectedValue Is Nothing Then
  673. Try
  674. Periodicidad = cboPeriodicidad.SelectedValue
  675. Catch ex As Exception
  676. End Try
  677. End If
  678. Dim FechaInicial As Date = dtpFechaOperacion.Value
  679. Dim IngrBruto As Double = 0.0
  680. Dim Monto
  681. If String.IsNullOrEmpty(txtMontoInversion.Text) Then
  682. Monto = 0
  683. Else
  684. Monto = txtMontoInversion.Text
  685. End If
  686. Dim Tasa As Double = 0
  687. If (Not String.IsNullOrEmpty(txtTasa.Text.ToString.Trim("%")) And Not txtTasa.Text.ToString.Trim("%") = "0") Then
  688. Tasa = (txtTasa.Text.Trim("%") / 100)
  689. End If
  690. Dim Impuesto As Double = 0
  691. If (Not String.IsNullOrEmpty(txtImpuesto.Text.ToString.Trim("%")) And Not txtImpuesto.Text.ToString.Trim("%") = "0") Then
  692. Impuesto = (txtImpuesto.Text.Trim("%") / 100)
  693. End If
  694. Dim Renta As Double = 0.0
  695. Dim FechaAnterior As Date
  696. Dim IngresoNeto As Double = 0.0
  697. Dim SumaIngresoBruto, SumaRenta, SumaIngresoNeto As Double
  698. Dim Plazo = DepositoCalcular.CalcularPlazo(Periodicidad)
  699. Dim Cantidad = DepositoCalcular.CalcularIteraciones(PlazoGlobal, Plazo)
  700. Dim Fecha As String = String.Empty
  701. For i As Integer = 1 To Cantidad
  702. If (i = 1) Then
  703. Fecha = Format(DepositoCalcular.CalcularFecha(Plazo, FechaInicial), "dd/MM/yyyy")
  704. IngrBruto = DepositoCalcular.CalculosIngrBruto(FechaInicial, Fecha, Monto, Tasa, Plazo)
  705. Else
  706. If (String.IsNullOrEmpty(Fecha.ToString)) Then
  707. Exit Sub
  708. End If
  709. FechaAnterior = Fecha
  710. Fecha = Format(DepositoCalcular.CalcularFecha(Plazo, Fecha), "dd/MM/yyyy")
  711. IngrBruto = DepositoCalcular.CalculosIngrBruto(FechaAnterior, Fecha, Monto, Tasa, Plazo)
  712. End If
  713. Renta = DepositoCalcular.Renta(Impuesto, IngrBruto)
  714. IngresoNeto = DepositoCalcular.CalculosIngNeto(IngrBruto, Renta)
  715. SumaIngresoBruto = SumaIngresoBruto + IngrBruto
  716. SumaRenta = SumaRenta + Renta
  717. SumaIngresoNeto = SumaIngresoNeto + IngresoNeto
  718. dgvIntereses.Rows.Add(i, Plazo, Fecha, IngrBruto, Impuesto, Renta, IngresoNeto)
  719. Next
  720. txtIngresoBruto.Text = SumaIngresoBruto
  721. txtRenta.Text = SumaRenta
  722. txtIngresoNeto.Text = SumaIngresoNeto
  723. End Sub
  724. Private Sub txtMontoInversion_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMontoInversion.KeyPress
  725. If String.IsNullOrEmpty(txtMontoInversion.Text) Then
  726. If e.KeyChar = "." Then
  727. txtMontoInversion.Text = "0"
  728. Exit Sub
  729. End If
  730. End If
  731. If (Not txtMontoInversion.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  732. Operaciones.ValidarEntrada(sender, e, True)
  733. Else
  734. Operaciones.ValidarEntrada(sender, e, False)
  735. End If
  736. End Sub
  737. Private Sub txtPlazo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPlazo.KeyPress
  738. If String.IsNullOrEmpty(txtPlazo.Text) Then
  739. If e.KeyChar = "." Then
  740. txtPlazo.Text = "0"
  741. Exit Sub
  742. End If
  743. End If
  744. If (Not txtPlazo.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  745. Operaciones.ValidarEntrada(sender, e, True)
  746. Else
  747. Operaciones.ValidarEntrada(sender, e, False)
  748. End If
  749. End Sub
  750. Private Sub txtTasa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasa.KeyPress
  751. If String.IsNullOrEmpty(txtTasa.Text) Then
  752. If e.KeyChar = "." Then
  753. txtTasa.Text = "0"
  754. Exit Sub
  755. End If
  756. End If
  757. If (Not txtTasa.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  758. Operaciones.ValidarEntrada(sender, e, True)
  759. Else
  760. Operaciones.ValidarEntrada(sender, e, False)
  761. End If
  762. End Sub
  763. Private Sub txtMontoInversion_Leave(sender As Object, e As EventArgs) Handles txtMontoInversion.Leave
  764. RellenarDatos()
  765. End Sub
  766. Private Sub txtPlazo_Leave(sender As Object, e As EventArgs) Handles txtPlazo.Leave
  767. RellenarDatos()
  768. End Sub
  769. Private Sub txtTasa_Leave(sender As Object, e As EventArgs) Handles txtTasa.Leave
  770. RellenarDatos()
  771. End Sub
  772. Private Sub txtMontoInversion_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMontoInversion.KeyUp
  773. If txtMontoInversion.Text = "." Then
  774. txtMontoInversion.Text = ".0"
  775. End If
  776. End Sub
  777. Private Sub txtPlazo_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPlazo.KeyUp
  778. If txtPlazo.Text = "." Then
  779. txtPlazo.Text = ".0"
  780. End If
  781. End Sub
  782. Private Sub txtTasa_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasa.KeyUp
  783. If txtTasa.Text = "." Then
  784. txtTasa.Text = ".0"
  785. End If
  786. End Sub
  787. Private Sub txtImpuesto_TextChanged(sender As Object, e As EventArgs) Handles txtImpuesto.TextChanged
  788. CalcularPlazo()
  789. Calculo()
  790. End Sub
  791. Sub CargarTransladoNuevo()
  792. Dim Existe As Boolean = ExisteInversion()
  793. If Not RetCodigoInversionExiste And Not Existe Then
  794. txtMontoInversion.Text = Variables.RetMonto
  795. txtTasa.Text = Variables.RetRendimiento
  796. End If
  797. End Sub
  798. End Class