frmNotaEstructurada.vb 32 KB

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