NotaEstructuradaCE.vb 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. Public Class NotaEstructuradaCE
  2. Private _DocId As Integer
  3. Private _CodigoInversion As String
  4. Private _MontoDeInversion As Double
  5. Private _FechaOperacion As Date
  6. Private _FechaVencimiento As Date
  7. Private _Tasa As Double
  8. Private _Plazo As Double
  9. Private _AnioBase As Integer
  10. Private _Periodicidad As String
  11. Private _RendimientoBruto As Double
  12. Private _RendimientoNeto As Double
  13. Private _IngresoBruto As Double
  14. Private _Impuestos As Double
  15. Private _IngresoNeto As Double
  16. Private _dtIntereses As DataTable
  17. Dim Operaciones As New Operaciones
  18. Public Property dtIntereses As DataTable
  19. Get
  20. Return _dtIntereses
  21. End Get
  22. Set(value As DataTable)
  23. _dtIntereses = value
  24. CalcularSumaIngresoBruto()
  25. CalcularSumaISR()
  26. CalcularIngresoNeto()
  27. End Set
  28. End Property
  29. Public Property CodigoInversion As String
  30. Get
  31. Return _CodigoInversion
  32. End Get
  33. Set(value As String)
  34. _CodigoInversion = value
  35. End Set
  36. End Property
  37. Public Property MontoDeInversion As Double
  38. Get
  39. Return _MontoDeInversion
  40. End Get
  41. Set(value As Double)
  42. _MontoDeInversion = value
  43. CalcularRendimientoBruto()
  44. CalcularRendimientoNeto()
  45. End Set
  46. End Property
  47. Public Property FechaOperacion As Date
  48. Get
  49. Return _FechaOperacion
  50. End Get
  51. Set(value As Date)
  52. _FechaOperacion = value
  53. End Set
  54. End Property
  55. Public Property FechaVencimiento As Date
  56. Get
  57. Return _FechaVencimiento
  58. End Get
  59. Set(value As Date)
  60. _FechaVencimiento = value
  61. End Set
  62. End Property
  63. Public Property Tasa As Double
  64. Get
  65. Return _Tasa
  66. End Get
  67. Set(value As Double)
  68. _Tasa = value
  69. End Set
  70. End Property
  71. Public Property Plazo As Double
  72. Get
  73. Return _Plazo
  74. End Get
  75. Set(value As Double)
  76. _Plazo = value
  77. CalcularRendimientoBruto()
  78. CalcularRendimientoNeto()
  79. End Set
  80. End Property
  81. Public Property AnioBase As Integer
  82. Get
  83. Return _AnioBase
  84. End Get
  85. Set(value As Integer)
  86. _AnioBase = value
  87. End Set
  88. End Property
  89. Public Property Periodicidad As String
  90. Get
  91. Return _Periodicidad
  92. End Get
  93. Set(value As String)
  94. _Periodicidad = value
  95. End Set
  96. End Property
  97. Public ReadOnly Property RendimientoBruto As Double
  98. Get
  99. Return _RendimientoBruto
  100. End Get
  101. End Property
  102. Public ReadOnly Property RendimientoNeto As Double
  103. Get
  104. Return _RendimientoNeto
  105. End Get
  106. End Property
  107. Public Property IngresoBruto As Double
  108. Get
  109. Return _IngresoBruto
  110. End Get
  111. Set(value As Double)
  112. _IngresoBruto = value
  113. End Set
  114. End Property
  115. Public Property Impuestos As Double
  116. Get
  117. Return _Impuestos
  118. End Get
  119. Set(value As Double)
  120. _Impuestos = value
  121. End Set
  122. End Property
  123. Public Property IngresoNeto As Double
  124. Get
  125. Return _IngresoNeto
  126. End Get
  127. Set(value As Double)
  128. _IngresoNeto = value
  129. End Set
  130. End Property
  131. Public Sub New()
  132. _MontoDeInversion = 0.00
  133. _FechaOperacion = Date.Now.Date
  134. _FechaVencimiento = Date.Now.Date
  135. _Tasa = 0.00
  136. _Plazo = 0
  137. _Periodicidad = "M"
  138. PreparaTablaIntereses()
  139. End Sub
  140. Private Sub PreparaTablaIntereses()
  141. _dtIntereses = New DataTable
  142. Dim column As DataColumn
  143. column = New DataColumn()
  144. column.DataType = GetType(String)
  145. column.ColumnName = "CodInv"
  146. column.Caption = "Codigo Inversion"
  147. column.ReadOnly = True
  148. _dtIntereses.Columns.Add(column)
  149. column = New DataColumn()
  150. column.DataType = GetType(Integer)
  151. column.ColumnName = "Correlativo"
  152. column.Caption = "Correlativo"
  153. column.ReadOnly = True
  154. _dtIntereses.Columns.Add(column)
  155. column = New DataColumn()
  156. column.DataType = GetType(Integer)
  157. column.ColumnName = "Plazo"
  158. column.Caption = "Plazo"
  159. _dtIntereses.Columns.Add(column)
  160. column = New DataColumn()
  161. column.DataType = GetType(Date)
  162. column.ColumnName = "Fecha"
  163. column.Caption = "Fecha"
  164. _dtIntereses.Columns.Add(column)
  165. column = New DataColumn()
  166. column.DataType = GetType(Double)
  167. column.ColumnName = "IngrBruto"
  168. column.Caption = "Ingreso Bruto"
  169. _dtIntereses.Columns.Add(column)
  170. column = New DataColumn()
  171. column.DataType = GetType(Double)
  172. column.ColumnName = "PorcImp"
  173. column.Caption = "Porc. de Impuesto"
  174. _dtIntereses.Columns.Add(column)
  175. column = New DataColumn()
  176. column.DataType = GetType(Double)
  177. column.ColumnName = "MontoImp"
  178. column.Caption = "Impuesto"
  179. _dtIntereses.Columns.Add(column)
  180. column = New DataColumn()
  181. column.DataType = GetType(Double)
  182. column.ColumnName = "IngrNeto"
  183. column.Caption = "Ingreso Neto"
  184. _dtIntereses.Columns.Add(column)
  185. column = New DataColumn()
  186. column.DataType = GetType(String)
  187. column.ColumnName = "Estado"
  188. column.Caption = "Estado"
  189. _dtIntereses.Columns.Add(column)
  190. End Sub
  191. Private Sub CalcularSumaIngresoBruto()
  192. If Not Double.TryParse(_dtIntereses.Compute("SUM(IngrBruto)", "").ToString, _IngresoBruto) Then
  193. _IngresoBruto = 0
  194. End If
  195. CalcularRendimientoBruto()
  196. End Sub
  197. Private Sub CalcularSumaISR()
  198. If Not Double.TryParse(_dtIntereses.Compute("SUM(MontoImp)", "").ToString, _Impuestos) Then
  199. _Impuestos = 0
  200. End If
  201. End Sub
  202. Private Sub CalcularIngresoNeto()
  203. If Not Double.TryParse(_dtIntereses.Compute("SUM(IngrNeto)", "").ToString, _IngresoNeto) Then
  204. _IngresoNeto = 0
  205. End If
  206. CalcularRendimientoNeto()
  207. End Sub
  208. Private Sub CalcularRendimientoBruto()
  209. Dim valor As Double
  210. Dim vIngresoBruto As Double = _IngresoBruto
  211. Dim vMontoInversion As Double = _MontoDeInversion
  212. Dim vDiasDelAnio As Integer = Utilidades.CalcularDiasDelAnio(_FechaVencimiento)
  213. Dim vPlazo As Integer = _Plazo
  214. valor = (vIngresoBruto / vMontoInversion) * (vDiasDelAnio / vPlazo)
  215. _RendimientoBruto = valor
  216. End Sub
  217. Private Sub CalcularRendimientoNeto()
  218. Dim valor As Double
  219. Dim vIngresoNeto As Double = _IngresoNeto
  220. Dim vMontoInversion As Double = _MontoDeInversion
  221. Dim vDiasDelAnio As Integer = Utilidades.CalcularDiasDelAnio(_FechaVencimiento)
  222. Dim vPlazo As Integer = _Plazo
  223. valor = (vIngresoNeto / vMontoInversion) * (vDiasDelAnio / vPlazo)
  224. _RendimientoNeto = valor
  225. End Sub
  226. Function CalcularPlazo(ByVal ValorPlazo As String)
  227. Dim Dias As Integer = 0
  228. If (ValorPlazo = "M") Then
  229. Dias = 30
  230. ElseIf (ValorPlazo = "T") Then
  231. Dias = 90
  232. ElseIf (ValorPlazo = "S") Then
  233. Dias = 180
  234. ElseIf (ValorPlazo = "A") Then
  235. Dias = 365
  236. End If
  237. Return Dias
  238. End Function
  239. Function CalcularIteraciones(ByVal PlazoGlobal As Integer, ByVal Plazo As Integer)
  240. Dim Cantidad As Integer = 0
  241. If (Not String.IsNullOrEmpty(Plazo.ToString) And Not Plazo.ToString = "0") Then
  242. Cantidad = PlazoGlobal / Plazo
  243. End If
  244. Return Cantidad
  245. End Function
  246. Function CalcularFecha(ByVal Dias As Integer, ByVal Fecha As Date)
  247. Return Fecha.AddDays(Dias)
  248. End Function
  249. Function CalculosIngrBruto(ByVal FechaInicial As Date, FechaFinal As Date, ByVal MontoInv As Double, ByVal Tasa As Double, ByVal Plazo As Integer)
  250. Dim IngresoBruto = 0.0, IngresoBrutoOpc1 = 0.0, IngresoBrutoOpc2 = 0.0
  251. Dim CambioDeFecha As Integer = Operaciones.CambioBase(FechaInicial, FechaFinal)
  252. Dim PrimeraFechaUltima = Operaciones.PrimeraFechaCambioBase(FechaInicial)
  253. Dim UltimaFechaPrimero = Operaciones.FinalFechaCambioBase(FechaFinal)
  254. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  255. If (Not CambioDeFecha = 0) Then
  256. If CambioDeFecha = 1 Then
  257. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  258. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  259. IngresoBrutoOpc1 = (MontoInv * Tasa * DiasPrimeraFecha) / 366
  260. IngresoBrutoOpc2 = (MontoInv * Tasa * DiasSegundaFecha) / 365
  261. ElseIf CambioDeFecha = 2 Then
  262. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  263. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  264. IngresoBrutoOpc1 = (MontoInv * Tasa * DiasPrimeraFecha) / 365
  265. IngresoBrutoOpc2 = (MontoInv * Tasa * DiasSegundaFecha) / 366
  266. End If
  267. IngresoBruto = IngresoBrutoOpc1 + IngresoBrutoOpc2
  268. Else
  269. If (Operaciones.AñoBisiesto(FechaInicial) = 364) Then
  270. IngresoBruto = (MontoInv * Tasa * Plazo) / 365
  271. End If
  272. If (Operaciones.AñoBisiesto(FechaInicial) = 365) Then
  273. IngresoBruto = (MontoInv * Tasa * Plazo) / 366
  274. End If
  275. End If
  276. Return IngresoBruto
  277. End Function
  278. Function Renta(ByVal PorcentajeRent As Double, ByVal IngBruto As Double)
  279. Dim DescuentoRenta As Double
  280. DescuentoRenta = IngBruto * PorcentajeRent
  281. Return DescuentoRenta
  282. End Function
  283. Function CalculosIngNeto(ByVal IngBruto As Double, ByVal Renta As Double)
  284. Dim CalculoIngrNeto As Double
  285. CalculoIngrNeto = IngBruto - Renta
  286. Return CalculoIngrNeto
  287. End Function
  288. End Class