Operaciones.vb 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. Public Class Operaciones
  2. Private V_TipoOperacion As String
  3. Dim dia As Integer
  4. Dim dias31 As Integer
  5. Dim febreros As Integer
  6. Dim bisiesto As Integer
  7. Dim V_IngresoBruto As Double = 0.0
  8. Dim V_FechaInicial As Date
  9. Dim V_FechaCorte As Date
  10. Dim ElementosConsulta As New CargarElementosDAO
  11. Dim V_CodEmpr = ElementosConsulta.CodEmpr
  12. Dim V_CodEmis = ElementosConsulta.CodEmis
  13. Dim V_CodECalRi = ElementosConsulta.CodECalRi
  14. Dim V_CodPais = ElementosConsulta.CodPais
  15. Dim V_ListaPlazo = ElementosConsulta.ListaPlazosFactor
  16. Dim V_ListaTiposMercados = ElementosConsulta.ListaTiposMercado
  17. Dim V_ListaPeriodos = ElementosConsulta.ListaPeriodos
  18. Dim V_ListaTipoTasa = ElementosConsulta.ListaTipoTasa
  19. Dim V_ListaTipoRenta = ElementosConsulta.ListaTipoRenta
  20. Dim V_ListaEstado = ElementosConsulta.ListaEstado
  21. Dim V_ListaCasasCorredoras = ElementosConsulta.ListaCasasCorredoras
  22. Public Property TipoOperacion() As String
  23. Get
  24. Return V_TipoOperacion
  25. End Get
  26. Set(value As String)
  27. V_TipoOperacion = value
  28. End Set
  29. End Property
  30. Public Function DiasAcumulados(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
  31. Dim Total As Integer = 0
  32. fecha1 = Format(fecha1, "dd/MM/yyyy")
  33. fecha2 = Format(fecha2, "dd/MM/yyyy")
  34. If (Base = 0 Or Base = 2) Then
  35. Total = Base360(fecha1, fecha2)
  36. ElseIf (Base = 1 Or Base = 3) Then
  37. Total = Base365(fecha1, fecha2)
  38. Else
  39. Total = 0
  40. End If
  41. Return Total
  42. End Function
  43. Public Function Dias(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
  44. Dim Total As Integer = 0
  45. If (Base = 0 Or Base = 2) Then
  46. Total = Base360(fecha1, fecha2)
  47. ElseIf (Base = 1 Or Base = 3) Then
  48. Total = Base365(fecha1, fecha2)
  49. Else
  50. Total = 0
  51. End If
  52. Return Total
  53. End Function
  54. Public Function InteresAcumuladoPBUR(ByVal ValorNominal As Double, ByVal PorcCupon As Double, ByVal DiasAcumulados As Integer, ByVal IndexBase As Integer, ByVal FechaInicial As Date, FechaFinal As Date)
  55. Dim Proceso As Double = 0
  56. If (IndexBase = 0) Then
  57. Proceso = ValorNominal * PorcCupon * DiasAcumulados / 360
  58. ElseIf IndexBase = 1 Then
  59. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  60. Dim CambioDeFecha As Integer = CambioBase(FechaInicial, FechaFinal)
  61. Dim PrimeraFechaUltima = PrimeraFechaCambioBase(FechaInicial)
  62. Dim UltimaFechaPrimero = FinalFechaCambioBase(FechaFinal)
  63. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  64. If (Not CambioDeFecha = 0) Then
  65. If CambioDeFecha = 1 Then
  66. DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha366(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  67. DiasSegundaFecha = DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  68. PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 366
  69. PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 365
  70. ElseIf CambioDeFecha = 2 Then
  71. DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  72. DiasSegundaFecha = DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  73. PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 365
  74. PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 366
  75. End If
  76. Proceso = PrOpc1 + PrOpc2
  77. Else
  78. If (AñoBisiesto(FechaInicial) = 364) Then
  79. Proceso = ValorNominal * PorcCupon * DiasAcumulados / 365
  80. End If
  81. If (AñoBisiesto(FechaInicial) = 365) Then
  82. Proceso = ValorNominal * PorcCupon * DiasAcumulados / 366
  83. End If
  84. End If
  85. ElseIf IndexBase = 2 Then
  86. Dim PrOpc1 = 0.0, PrOpc2 = 0.0
  87. Dim CambioDeFecha As Integer = CambioBase(FechaInicial, FechaFinal)
  88. Dim PrimeraFechaUltima = PrimeraFechaCambioBase360(FechaInicial)
  89. Dim UltimaFechaPrimero = FinalFechaCambioBase360(FechaFinal)
  90. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  91. If (Not CambioDeFecha = 0) Then
  92. If CambioDeFecha = 1 Then
  93. DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha360(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  94. DiasSegundaFecha = DiasDespuesCambioPrimeraFecha360(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  95. PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 366
  96. PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 365
  97. ElseIf CambioDeFecha = 2 Then
  98. DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha360(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  99. DiasSegundaFecha = DiasDespuesCambioPrimeraFecha360(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  100. PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 365
  101. PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 366
  102. End If
  103. Proceso = PrOpc1 + PrOpc2
  104. Else
  105. If (AñoBisiesto(FechaInicial) = 364) Then
  106. Proceso = ValorNominal * PorcCupon * DiasAcumulados / 365
  107. End If
  108. If (AñoBisiesto(FechaInicial) = 365) Then
  109. Proceso = ValorNominal * PorcCupon * DiasAcumulados / 366
  110. End If
  111. End If
  112. ElseIf IndexBase = 3 Then
  113. Proceso = ValorNominal * PorcCupon * DiasAcumulados / 360
  114. End If
  115. Return Proceso
  116. End Function
  117. Public Function Comisiones(ByVal Comision As Double, ByVal ValorTrasado As Double)
  118. Dim Valor = CDec(Comision) * CDec(ValorTrasado)
  119. Return Valor
  120. End Function
  121. Public Function Base360(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  122. Dim Total As Integer = 0
  123. Dim dias = DateDiff(DateInterval.Day, Fecha1, Fecha2)
  124. Dim dia As Integer
  125. Dim dias31 As Integer
  126. Dim febreros As Integer
  127. Dim bisiesto As Integer
  128. While (Fecha1 < Fecha2)
  129. dia = dia + 1
  130. If (Fecha1.Day = 31) Then
  131. dias31 = dias31 + 1
  132. End If
  133. If (Fecha1.Month = 2 And Fecha1.Day = 28) Then
  134. febreros = febreros + 2
  135. End If
  136. If (Fecha1.Month = 2 And Fecha1.Day = 29) Then
  137. bisiesto = bisiesto + 1
  138. End If
  139. Fecha1 = Fecha1.AddDays(1)
  140. End While
  141. Total = dia - dias31 + febreros - bisiesto
  142. Return Total
  143. End Function
  144. Public Function FechaDias360(ByVal Fecha1 As Date, ByVal Day As Integer)
  145. Dim CorrelativoDias As Integer = 1
  146. Dim Dias As Integer = Day
  147. Dim Fecha As Date = Fecha1
  148. While CorrelativoDias <= Dias
  149. Dim Bisiesto As Integer = AñoBisiesto(Fecha)
  150. If Bisiesto = 365 Then
  151. If Fecha.Day = 31 Then
  152. Fecha = Fecha.AddDays(2)
  153. CorrelativoDias += 1
  154. ElseIf Fecha.Day = 29 And Fecha.Month = 2 Then
  155. Fecha = Fecha.AddDays(1)
  156. CorrelativoDias += 2
  157. Else
  158. Fecha = Fecha.AddDays(1)
  159. CorrelativoDias += 1
  160. End If
  161. Else
  162. If Fecha.Day = 31 Then
  163. Fecha = Fecha.AddDays(2)
  164. CorrelativoDias += 1
  165. ElseIf Fecha.Day = 28 And Fecha.Month = 2 Then
  166. Fecha = Fecha.AddDays(1)
  167. CorrelativoDias += 3
  168. Else
  169. Fecha = Fecha.AddDays(1)
  170. CorrelativoDias += 1
  171. End If
  172. End If
  173. End While
  174. Return Fecha
  175. End Function
  176. Public Function FechaDias3602829(ByVal Fecha1 As Date, ByVal Day As Integer,Byval DiaFijo As integer)
  177. Dim CorrelativoDias As Integer = 1
  178. Dim Dias As Integer = Day
  179. Dim Fecha As Date = Fecha1
  180. Dim Conteo As Integer = 0
  181. While CorrelativoDias <= Dias
  182. Conteo += 1
  183. Dim Bisiesto As Integer = AñoBisiesto(Fecha)
  184. If Bisiesto = 365 Then
  185. If Fecha.Day = 31 Then
  186. Fecha = Fecha.AddDays(2)
  187. CorrelativoDias += 1
  188. ElseIf Fecha.Day = 29 And Fecha.Month = 2 Then
  189. If DiaFijo = 30 Then
  190. If CorrelativoDias = Dias Then
  191. CorrelativoDias += 2
  192. Else
  193. Fecha = Fecha.AddDays(1)
  194. If Conteo = 1 Then
  195. CorrelativoDias += 1
  196. Else
  197. CorrelativoDias += 2
  198. End If
  199. End If
  200. Else
  201. Fecha = Fecha.AddDays(1)
  202. CorrelativoDias += 2
  203. End If
  204. Else
  205. Fecha = Fecha.AddDays(1)
  206. CorrelativoDias += 1
  207. End If
  208. Else
  209. If Fecha.Day = 31 Then
  210. Fecha = Fecha.AddDays(2)
  211. CorrelativoDias += 1
  212. ElseIf Fecha.Day = 28 And Fecha.Month = 2 Then
  213. If DiaFijo = 30 Then
  214. If (CorrelativoDias + 1) = Dias Then
  215. CorrelativoDias += 3
  216. Else
  217. Fecha = Fecha.AddDays(1)
  218. If Conteo = 1 Then
  219. CorrelativoDias += 1
  220. Else
  221. CorrelativoDias += 3
  222. End If
  223. End If
  224. ElseIf DiaFijo = 29 Then
  225. If CorrelativoDias = Dias Then
  226. CorrelativoDias += 3
  227. Else
  228. Fecha = Fecha.AddDays(1)
  229. If Conteo = 1 Then
  230. CorrelativoDias += 2
  231. Else
  232. CorrelativoDias += 3
  233. End If
  234. End If
  235. Else
  236. Fecha = Fecha.AddDays(1)
  237. CorrelativoDias += 3
  238. End If
  239. Else
  240. Fecha = Fecha.AddDays(1)
  241. CorrelativoDias += 1
  242. End If
  243. End If
  244. End While
  245. Return Fecha
  246. End Function
  247. Public Function Base365(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  248. Dim dias = DateDiff(DateInterval.Day, Fecha1, Fecha2)
  249. Return dias
  250. End Function
  251. Function AñoBisiesto(ByVal Fecha As Date)
  252. Dim Año As String = Fecha.Year
  253. Dim Dias As Integer = 0
  254. Dim FechaPrimero As Date = "01/01/" + Año
  255. Dim FechaFinal As Date = "31/12/" + Año
  256. Dias = DateDiff(DateInterval.Day, FechaPrimero, FechaFinal)
  257. Return Dias
  258. End Function
  259. Function CambioBase(ByVal FechaInicial As Date, ByVal FechaFinal As Date)
  260. Dim AñoInicial = FechaInicial.Year
  261. Dim AñoFinal = FechaFinal.Year
  262. Dim CambioDeBase As Integer = 0
  263. If (Not AñoInicial = AñoFinal) Then
  264. If (AñoBisiesto(FechaInicial) = 365) Then
  265. CambioDeBase = 1
  266. ElseIf (AñoBisiesto(FechaFinal) = 365) Then
  267. CambioDeBase = 2
  268. End If
  269. End If
  270. Return CambioDeBase
  271. End Function
  272. Function PrimeraFechaCambioBase(ByVal FechaInicial As Date)
  273. Dim AñoInicial As String = FechaInicial.Year
  274. Dim FechaPrimerCorte As Date = "31/12/" + AñoInicial
  275. Return FechaPrimerCorte
  276. End Function
  277. Function PrimeraFechaCambioBase360(ByVal FechaInicial As Date)
  278. Dim AñoInicial As String = FechaInicial.Year
  279. Dim FechaPrimerCorte As Date = "30/12/" + AñoInicial
  280. Return FechaPrimerCorte
  281. End Function
  282. Function FinalFechaCambioBase(ByVal FechaFinal As Date)
  283. Dim AñoFinal As String = FechaFinal.Year
  284. Dim FechaInicialSegundoCorte As Date = "01/01/" + AñoFinal
  285. Return FechaInicialSegundoCorte
  286. End Function
  287. Function FinalFechaCambioBase360(ByVal FechaFinal As Date)
  288. Dim AñoFinal As String = FechaFinal.Year
  289. Dim FechaInicialSegundoCorte As Date = "01/01/" + AñoFinal
  290. Return FechaInicialSegundoCorte
  291. End Function
  292. Function DiasDespuesCambioPrimeraFecha365(ByVal FechaIncial As Date, ByVal FechaFinal As Date, ByVal CambioDeFecha As Integer)
  293. Dim Dias As Integer
  294. If (CambioDeFecha = 1) Then
  295. Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal) + 1
  296. Else
  297. Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal)
  298. End If
  299. Return Dias
  300. End Function
  301. Function DiasDespuesCambioPrimeraFecha366(ByVal FechaIncial As Date, ByVal FechaFinal As Date, ByVal CambioDeFecha As Integer)
  302. Dim Dias As Integer
  303. If (CambioDeFecha = 2) Then
  304. Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal) + 1
  305. Else
  306. Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal)
  307. End If
  308. Return Dias
  309. End Function
  310. Function DiasDespuesCambioPrimeraFecha366Varios(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  311. Dim Dias As Integer = 0
  312. While (Fecha1 < Fecha2)
  313. If AñoBisiesto(Fecha1) = 365 Then
  314. Dias += 1
  315. End If
  316. Fecha1 = Fecha1.AddDays(1)
  317. End While
  318. Return Dias
  319. End Function
  320. Function DiasDespuesCambioPrimeraFecha365Varios(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  321. Dim Dias As Integer = 0
  322. While (Fecha1 < Fecha2)
  323. If AñoBisiesto(Fecha1) = 364 Then
  324. Dias += 1
  325. End If
  326. Fecha1 = Fecha1.AddDays(1)
  327. End While
  328. Return Dias
  329. End Function
  330. Function DiasDespuesCambioPrimeraFecha360Bi(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  331. Dim Dias As Integer = 0
  332. While (Fecha1 < Fecha2)
  333. If AñoBisiesto(Fecha1) = 365 Then
  334. If (Not Fecha1.Day = 31) Then
  335. If (Fecha1.Day = 29) Then
  336. Dias += 1
  337. End If
  338. Dias += 1
  339. End If
  340. End If
  341. Fecha1 = Fecha1.AddDays(1)
  342. End While
  343. Return Dias
  344. End Function
  345. Function DiasDespuesCambioPrimeraFecha360(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
  346. Dim Dias As Integer = 0
  347. While (Fecha1 < Fecha2)
  348. If AñoBisiesto(Fecha1) = 364 Then
  349. If (Not Fecha1.Day = 31) Then
  350. If (Fecha1.Day = 28) Then
  351. Dias += 2
  352. End If
  353. Dias += 1
  354. End If
  355. End If
  356. Fecha1 = Fecha1.AddDays(1)
  357. End While
  358. Return Dias
  359. End Function
  360. Function DiasDespuesCambioPrimeraFecha360(ByVal FechaIncial As Date, ByVal FechaFinal As Date, ByVal CambioDeFecha As Integer)
  361. Dim Dias As Integer
  362. Dias = Base360(FechaInicial, FechaFinal)
  363. Return Dias
  364. End Function
  365. Public Sub ValidarEntrada(sender As Object, e As KeyPressEventArgs, ByVal NoAgregar As Boolean)
  366. If (Char.IsNumber(e.KeyChar)) Then
  367. e.Handled = False
  368. ElseIf Char.IsSeparator(e.KeyChar) Then
  369. e.Handled = True
  370. ElseIf Char.IsLetter(e.KeyChar) Then
  371. e.Handled = True
  372. ElseIf Char.IsPunctuation(e.KeyChar) Then
  373. If Not e.KeyChar = "." Then
  374. e.Handled = True
  375. End If
  376. ElseIf Char.IsSymbol(e.KeyChar) Then
  377. e.Handled = True
  378. ElseIf Char.IsWhiteSpace(e.KeyChar) Then
  379. e.Handled = True
  380. End If
  381. If NoAgregar Then
  382. e.Handled = True
  383. End If
  384. End Sub
  385. Function Meses(ByVal CantidadMeses As Integer, ByVal Fecha As Date, ByVal MesFijo As Date)
  386. Dim i As Integer = 0
  387. Dim DiaInicial As Integer = 0
  388. Dim Dia = MesFijo.Day
  389. DiaInicial = Dia
  390. Fecha = Fecha.AddMonths(CantidadMeses)
  391. Dim Mes = Fecha.Month
  392. Mes = Fecha.Month
  393. If (DiaInicial = 31) Then
  394. If ((Mes = 1 Or Mes = 3 Or Mes = 5 Or Mes = 7 Or Mes = 8 Or Mes = 10 Or Mes = 12)) Then
  395. Dim Año = Fecha.Year
  396. Fecha = CDate(("31/" + Mes.ToString + "/" + Año.ToString))
  397. ElseIf (Mes = 2) Then
  398. Dim Año = Fecha.Year
  399. If (AñoBisiesto(Fecha) = 364) Then
  400. Fecha = CDate(("28/" + Mes.ToString + "/" + Año.ToString))
  401. End If
  402. If (AñoBisiesto(Fecha) = 365) Then
  403. Fecha = CDate(("29/" + Mes.ToString + "/" + Año.ToString))
  404. End If
  405. Else
  406. Dim Año = Fecha.Year
  407. Fecha = CDate(("30/" + Mes.ToString + "/" + Año.ToString))
  408. End If
  409. ElseIf (DiaInicial = 30) Then
  410. If (Mes = 2) Then
  411. Dim Año = Fecha.Year
  412. Fecha = CDate(("28/" + Mes.ToString + "/" + Año.ToString))
  413. Else
  414. Dim Año = Fecha.Year
  415. Fecha = CDate(("30/" + Mes.ToString + "/" + Año.ToString))
  416. End If
  417. ElseIf (DiaInicial = 29) Then
  418. If (Mes = 2) Then
  419. Dim Año = Fecha.Year
  420. Fecha = CDate(("28/" + Mes.ToString + "/" + Año.ToString))
  421. Else
  422. Dim Año = Fecha.Year
  423. Fecha = CDate(("29/" + Mes.ToString + "/" + Año.ToString))
  424. End If
  425. End If
  426. Return Fecha
  427. End Function
  428. Function FechaFinMes(ByVal FechaPri As Date, ByVal Periodicidad As String, ByVal Base As Integer)
  429. Dim Dias As Integer = 0
  430. Dim Meses As Integer = 0
  431. If Periodicidad = "M" Then
  432. Meses = 1
  433. ElseIf Periodicidad = "T" Then
  434. Meses = 3
  435. ElseIf Periodicidad = "S" Then
  436. Meses = 6
  437. ElseIf Periodicidad = "A" Then
  438. Meses = 12
  439. End If
  440. If Base = 365 Then
  441. Dim FechaAnterior As Date = Format(FechaPri, "dd/MM/yyyy")
  442. Dim FechaCreada As Date = Format(FechaPri, "dd/MM/yyyy")
  443. Dim DiaAnterior As Integer = FechaAnterior.Day
  444. Dim MesAnterior As Integer = FechaAnterior.Month
  445. Dim DiaDiferenciaAnterior31 As Integer = 31 - DiaAnterior
  446. Dim FechaTemporal31 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior31)
  447. Dim DiaDiferenciaAnterior30 As Integer = 30 - DiaAnterior
  448. Dim FechaTemporal30 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior30)
  449. Dim DiaDiferenciaAnterior29 As Integer = 29 - DiaAnterior
  450. Dim FechaTemporal29 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior29)
  451. Dim DiaDiferenciaAnterior28 As Integer = 28 - DiaAnterior
  452. Dim FechaTemporal28 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior28)
  453. ''''''''
  454. If FechaTemporal31.Month = MesAnterior Then
  455. If Periodicidad = "M" Then
  456. If DiaDiferenciaAnterior31 > 0 Then
  457. FechaCreada = FechaTemporal31
  458. Else
  459. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior31, 0, Base)
  460. End If
  461. Else
  462. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior31, 0, Base)
  463. End If
  464. ElseIf FechaTemporal30.Month = MesAnterior Then
  465. If Periodicidad = "M" Then
  466. If DiaDiferenciaAnterior30 > 0 Then
  467. FechaCreada = FechaTemporal30
  468. Else
  469. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior30, 0, Base)
  470. End If
  471. Else
  472. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior30, 0, Base)
  473. End If
  474. ElseIf FechaTemporal29.Month = MesAnterior Then
  475. If Periodicidad = "M" Then
  476. If DiaDiferenciaAnterior29 > 0 Then
  477. FechaCreada = FechaTemporal29
  478. Else
  479. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior29, 0, Base)
  480. End If
  481. Else
  482. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior29, 0, Base)
  483. End If
  484. ElseIf FechaTemporal28.Month = MesAnterior Then
  485. If Periodicidad = "M" Then
  486. If DiaDiferenciaAnterior28 > 0 Then
  487. FechaCreada = FechaTemporal28
  488. Else
  489. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior28, 0, Base)
  490. End If
  491. Else
  492. FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior28, 0, Base)
  493. End If
  494. End If
  495. Return FechaCreada
  496. ElseIf Base = 360 Then
  497. Dim FechaAnterior As Date = FechaPri
  498. Dim FechaCreada As Date = FechaPri
  499. Dim DiasAnterior As Integer = FechaAnterior.Day
  500. Dim DiasFaltantes As Integer = 30 - FechaAnterior.Day
  501. Dim FechaTemporalValidarDiasMes As Date = Date.Today.Date
  502. Dim CantidadDiasMes As Integer = 0
  503. Dim MesAnterior As Integer = FechaAnterior.Month
  504. If Periodicidad = "M" Then
  505. If DiasFaltantes > 0 Then
  506. FechaTemporalValidarDiasMes = Format(CDate("01/" + MesAnterior.ToString + "/" + FechaAnterior.Year.ToString), "dd/MM/yyyy")
  507. If FechaTemporalValidarDiasMes.AddDays(30).Month = MesAnterior Then
  508. 'Tiene 31 Dias
  509. CantidadDiasMes = 31
  510. ElseIf FechaTemporalValidarDiasMes.AddDays(29).Month = MesAnterior Then
  511. 'Tiene 30 Dias
  512. CantidadDiasMes = 30
  513. ElseIf FechaTemporalValidarDiasMes.AddDays(28).Month = MesAnterior Then
  514. 'Tiene 29 Dias
  515. CantidadDiasMes = 29
  516. ElseIf FechaTemporalValidarDiasMes.AddDays(27).Month = MesAnterior Then
  517. 'Tiene 28 Dias
  518. CantidadDiasMes = 28
  519. End If
  520. If CantidadDiasMes = 31 Or CantidadDiasMes = 30 Then
  521. FechaCreada = FechaCreada.AddDays(DiasFaltantes)
  522. ElseIf CantidadDiasMes = 29 Then
  523. If DiasFaltantes = 1 Then
  524. FechaCreada = FechaCreada.AddDays(30)
  525. Else
  526. FechaCreada = FechaCreada.AddDays(DiasFaltantes - 1)
  527. End If
  528. ElseIf CantidadDiasMes = 28 Then
  529. If DiasFaltantes = 2 Then
  530. FechaCreada = FechaCreada.AddDays(30)
  531. Else
  532. FechaCreada = FechaCreada.AddDays(DiasFaltantes - 2)
  533. End If
  534. End If
  535. Else
  536. FechaCreada = FechaCreada.AddMonths(Meses)
  537. End If
  538. Else
  539. Dim DiasCreada As Integer = 0
  540. Dim MesCreada As Integer = 0
  541. If DiasFaltantes > 0 Then
  542. FechaCreada = FechaAnterior.AddMonths(Meses - 1)
  543. DiasCreada = FechaCreada.Day
  544. DiasFaltantes = 30 - FechaCreada.Day
  545. MesCreada = FechaCreada.Month
  546. FechaTemporalValidarDiasMes = Format(CDate("01/" + MesCreada.ToString + "/" + FechaCreada.Year.ToString), "dd/MM/yyyy")
  547. If FechaTemporalValidarDiasMes.AddDays(30).Month = MesCreada Then
  548. 'Tiene 31 Dias
  549. CantidadDiasMes = 31
  550. ElseIf FechaTemporalValidarDiasMes.AddDays(29).Month = MesCreada Then
  551. 'Tiene 30 Dias
  552. CantidadDiasMes = 30
  553. ElseIf FechaTemporalValidarDiasMes.AddDays(28).Month = MesCreada Then
  554. 'Tiene 29 Dias
  555. CantidadDiasMes = 29
  556. ElseIf FechaTemporalValidarDiasMes.AddDays(27).Month = MesCreada Then
  557. 'Tiene 28 Dias
  558. CantidadDiasMes = 28
  559. End If
  560. If CantidadDiasMes = 31 Or CantidadDiasMes = 30 Then
  561. FechaCreada = FechaCreada.AddDays(DiasFaltantes)
  562. ElseIf CantidadDiasMes = 29 Then
  563. If DiasFaltantes = 1 Then
  564. FechaCreada = FechaCreada.AddDays(30)
  565. Else
  566. FechaCreada = FechaCreada.AddDays(DiasFaltantes - 1)
  567. End If
  568. ElseIf CantidadDiasMes = 28 Then
  569. If DiasFaltantes = 2 Then
  570. FechaCreada = FechaCreada.AddDays(30)
  571. Else
  572. FechaCreada = FechaCreada.AddDays(DiasFaltantes - 2)
  573. End If
  574. End If
  575. Else
  576. FechaCreada = FechaAnterior.AddMonths(Meses)
  577. End If
  578. End If
  579. Return FechaCreada
  580. End If
  581. End Function
  582. Function FechaMensual(ByRef Fecha As Date, ByRef Periodicidad As String, ByVal TipoCalculo As String, ByVal DiasSobrantes As Integer, ByVal DiaFijo As Integer, ByVal Base As Integer)
  583. Dim Meses As Integer = 0
  584. If Periodicidad = "M" Then
  585. Meses = 1
  586. ElseIf Periodicidad = "T" Then
  587. Meses = 3
  588. ElseIf Periodicidad = "S" Then
  589. Meses = 6
  590. ElseIf Periodicidad = "A" Then
  591. Meses = 12
  592. End If
  593. If Base = 365 Then
  594. 'TipoCalculo: FinMes,Mensual'
  595. Dim FechaAnterior As Date = Format(Fecha, "dd/MM/yyyy")
  596. Dim FechaCreada As Date = Format(Fecha, "dd/MM/yyyy")
  597. If DiasSobrantes > 0 Then
  598. FechaCreada = FechaCreada.AddMonths(Meses - 1)
  599. Else
  600. FechaCreada = FechaCreada.AddMonths(Meses)
  601. End If
  602. Dim DiaCreada As Integer = FechaCreada.Day
  603. Dim MesCreada As Integer = FechaCreada.Month
  604. Dim DiaDiferenciaAnterior31 As Integer = 31 - DiaCreada
  605. Dim FechaTemporal31 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior31)
  606. Dim DiaDiferenciaAnterior30 As Integer = 30 - DiaCreada
  607. Dim FechaTemporal30 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior30)
  608. Dim DiaDiferenciaAnterior29 As Integer = 29 - DiaCreada
  609. Dim FechaTemporal29 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior29)
  610. Dim DiaDiferenciaAnterior28 As Integer = 28 - DiaCreada
  611. Dim FechaTemporal28 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior28)
  612. If TipoCalculo = "FinMes" Then
  613. If FechaTemporal31.Month = MesCreada Then
  614. If DiaDiferenciaAnterior31 > 0 Then
  615. FechaCreada = FechaTemporal31
  616. End If
  617. ElseIf FechaTemporal30.Month = MesCreada Then
  618. If DiaDiferenciaAnterior30 > 0 Then
  619. FechaCreada = FechaTemporal30
  620. End If
  621. ElseIf FechaTemporal29.Month = MesCreada Then
  622. If DiaDiferenciaAnterior29 > 0 Then
  623. FechaCreada = FechaTemporal29
  624. End If
  625. ElseIf FechaTemporal28.Month = MesCreada Then
  626. If DiaDiferenciaAnterior28 > 0 Then
  627. FechaCreada = FechaTemporal28
  628. End If
  629. End If
  630. Return FechaCreada
  631. ElseIf TipoCalculo = "Mensual" Then
  632. FechaAnterior = Fecha
  633. FechaCreada = Fecha.AddMonths(Meses)
  634. MesCreada = FechaCreada.Month
  635. DiaCreada = FechaCreada.Day
  636. DiaDiferenciaAnterior31 = 31 - DiaCreada
  637. FechaTemporal31 = FechaCreada.AddDays(DiaDiferenciaAnterior31)
  638. DiaDiferenciaAnterior30 = 30 - DiaCreada
  639. FechaTemporal30 = FechaCreada.AddDays(DiaDiferenciaAnterior30)
  640. DiaDiferenciaAnterior29 = 29 - DiaCreada
  641. FechaTemporal29 = FechaCreada.AddDays(DiaDiferenciaAnterior29)
  642. If DiaFijo = 31 Then
  643. If MesCreada = FechaTemporal31.Month Then
  644. FechaCreada = FechaTemporal31
  645. ElseIf MesCreada = FechaTemporal30.Month Then
  646. FechaCreada = FechaTemporal30
  647. ElseIf MesCreada = FechaTemporal29.Month Then
  648. FechaCreada = FechaTemporal29
  649. Else
  650. FechaCreada = FechaTemporal28
  651. End If
  652. ElseIf DiaFijo = 30 Then
  653. If MesCreada = FechaTemporal30.Month Then
  654. FechaCreada = FechaTemporal30
  655. ElseIf MesCreada = FechaTemporal29.Month Then
  656. FechaCreada = FechaTemporal29
  657. Else
  658. FechaCreada = FechaTemporal28
  659. End If
  660. ElseIf DiaFijo = 29 Then
  661. If MesCreada = FechaTemporal29.Month Then
  662. FechaCreada = FechaTemporal29
  663. Else
  664. FechaCreada = FechaTemporal28
  665. End If
  666. Else
  667. Dim DiaAgregar As Integer = DiaFijo - FechaCreada.Day
  668. FechaCreada = FechaCreada.AddDays(DiaAgregar)
  669. End If
  670. Return FechaCreada
  671. End If
  672. ElseIf Base = 360 Then
  673. Dim Dias As Integer = Meses * 30
  674. Dim FechaAnterior As Date = Fecha
  675. FechaAnterior = FechaDias3602829(FechaAnterior, Dias, DiaFijo)
  676. Return FechaAnterior
  677. End If
  678. End Function
  679. Function ConvertirDecimal(ByVal Dec As String)
  680. Dim value As Double = 0
  681. If Dec Is Nothing Then
  682. Dec = 0
  683. End If
  684. Dec = Dec.ToString.Trim("%")
  685. If (Decimal.TryParse(Dec, value)) Then Return value Else Return 0
  686. End Function
  687. Function ConvertirBoolNum(ByVal Bool As String)
  688. Dim value As Boolean = 0
  689. If Bool Is Nothing Then
  690. value = False
  691. Else
  692. Bool = Bool.ToString.Trim("%")
  693. If String.IsNullOrEmpty(Bool) Then
  694. value = False
  695. Else
  696. If ConvertirEntero(Bool) = 1 Then
  697. value = True
  698. Else
  699. value = False
  700. End If
  701. End If
  702. End If
  703. Return value
  704. End Function
  705. Function ConvertirEntero(ByVal Int As String)
  706. Dim value As Integer = 0
  707. If Int Is Nothing Then
  708. Int = 0
  709. End If
  710. Int = Int.ToString.Trim("%")
  711. If (Integer.TryParse(Int, value)) Then Return value Else Return 0
  712. End Function
  713. Function ConvertirCadena(ByVal Cadena As Object)
  714. Dim value As Integer = 0
  715. If Cadena Is Nothing Then
  716. Cadena = String.Empty
  717. End If
  718. If Cadena Is DBNull.Value Then
  719. Cadena = String.Empty
  720. End If
  721. Return Cadena.ToString
  722. End Function
  723. Function ConvertirFecha(ByVal Fecha As String)
  724. Dim value As Date = Date.Today.Date
  725. If (Date.TryParse(Fecha, value)) Then Return value Else Return Date.Today.Date
  726. End Function
  727. Function ConvertirFechaBaseDatos(ByVal Fecha As String)
  728. Dim value As Date = Date.Today.Date
  729. If (Date.TryParse(Fecha, value)) Then Return value Else Return DBNull.Value
  730. End Function
  731. Sub TraspasarDatos(ByVal CodigoExiste As String, ByVal CodigoInstrumentoExiste As String,
  732. ByVal IsNueva As String, ByVal TipoTransaccionCompraVenta As String,
  733. ByVal FamiliaTitulo As String, ByVal Monto As Double,
  734. ByVal Precio As Double, ByVal RendimientoEsperado As Double,
  735. ByVal IngresosEsperados As Double)
  736. If IsNueva = "N" Then
  737. Dim General As New DAOGeneral
  738. Dim Tabla As String = String.Empty
  739. If CodigoInstrumentoExiste = "ACCI" Or CodigoInstrumentoExiste = "ACCNC" Or
  740. CodigoInstrumentoExiste = "ACCNP" Then
  741. Tabla = "ACC0"
  742. ElseIf CodigoInstrumentoExiste = "PPER" Then
  743. Tabla = "PPER0"
  744. ElseIf CodigoInstrumentoExiste = "DAP" Then
  745. Tabla = "DAP0"
  746. ElseIf CodigoInstrumentoExiste = "NEST" Then
  747. Tabla = "NETS0"
  748. ElseIf CodigoInstrumentoExiste = "FUTU" Then
  749. Tabla = "FUT0"
  750. ElseIf CodigoInstrumentoExiste = "OPC" Then
  751. Tabla = "OPC0"
  752. ElseIf CodigoInstrumentoExiste = "PEMP" Then
  753. Tabla = "PEMP0"
  754. ElseIf CodigoInstrumentoExiste = "LETE" Then
  755. Tabla = "LET0"
  756. ElseIf CodigoInstrumentoExiste = "CETE" Then
  757. Tabla = "CET0"
  758. ElseIf CodigoInstrumentoExiste = "PBUR" Then
  759. Tabla = "PBUR"
  760. ElseIf CodigoInstrumentoExiste = "VCN" Then
  761. Tabla = "VCN"
  762. ElseIf CodigoInstrumentoExiste = "BONO" Then
  763. Tabla = "BON0"
  764. ElseIf CodigoInstrumentoExiste = "CINV" Then
  765. Tabla = "CIN0"
  766. ElseIf CodigoInstrumentoExiste = "EURB" Then
  767. Tabla = "EURB0"
  768. ElseIf CodigoInstrumentoExiste = "TIT" Then
  769. Tabla = "TIT"
  770. ElseIf CodigoInstrumentoExiste = "FINV" Then
  771. Tabla = "FINV"
  772. ElseIf CodigoInstrumentoExiste = "REPO" Then
  773. Tabla = "REP0"
  774. ElseIf CodigoInstrumentoExiste = "REPOVENTA" Then
  775. Tabla = "REPOVENTA"
  776. End If
  777. Dim RetCodigoInversionExiste As Boolean = General.ExisteTitulo(CodigoExiste, Tabla)
  778. If Not RetCodigoInversionExiste Then
  779. Dim RetMonto As Double = 0
  780. Dim RetPrecio As Double = 0
  781. Dim RetRendimiento As Double = 0
  782. Dim RetIngresosEsp As Double = 0
  783. Dim RetUnidadesAcciones As Integer = 0
  784. Dim RetUnidadesContratosFuturos As Integer = 0
  785. Dim RetCantidadContratosFuturos As Integer = 0
  786. Dim RetCuotaParticipacionFINV As Integer = 0
  787. Dim RetValorParticipacionFINV As Integer = 0
  788. If FamiliaTitulo = "FamiliaAcciones" Then
  789. RetMonto = ConvertirDecimal(Monto.ToString)
  790. RetPrecio = ConvertirDecimal(Precio.ToString)
  791. RetRendimiento = 0
  792. RetIngresosEsp = 0
  793. RetUnidadesAcciones = ConvertirDecimal((RetMonto / RetPrecio).ToString)
  794. Variables.RetMonto = RetMonto
  795. Variables.RetPrecio = RetPrecio
  796. Variables.RetUnidadesAcciones = RetUnidadesAcciones
  797. ElseIf FamiliaTitulo = "FamiliaPrestamoPersonal" Then
  798. RetMonto = ConvertirDecimal(Monto.ToString)
  799. RetPrecio = 0
  800. RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
  801. RetIngresosEsp = 0
  802. Variables.RetMonto = RetMonto
  803. Variables.RetRendimiento = RetRendimiento
  804. ElseIf FamiliaTitulo = "FamiliaDAP" Then
  805. RetMonto = ConvertirDecimal(Monto.ToString)
  806. RetPrecio = 0
  807. RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
  808. RetIngresosEsp = 0
  809. Variables.RetMonto = RetMonto
  810. Variables.RetRendimiento = RetRendimiento
  811. ElseIf FamiliaTitulo = "FamiliaFuturos" Then
  812. RetMonto = ConvertirDecimal(Monto.ToString)
  813. RetPrecio = ConvertirDecimal(Precio.ToString)
  814. RetRendimiento = 0
  815. RetIngresosEsp = 0
  816. RetUnidadesContratosFuturos = 1
  817. RetCantidadContratosFuturos = ConvertirDecimal((RetMonto / (RetUnidadesContratosFuturos * RetPrecio)))
  818. Variables.RetMonto = RetMonto
  819. Variables.RetPrecio = RetPrecio
  820. Variables.RetUnidadesContratosFuturos = RetUnidadesContratosFuturos
  821. Variables.RetCantidadContratosFuturos = RetCantidadContratosFuturos
  822. ElseIf FamiliaTitulo = "FamiliaEmpresas" Then
  823. RetMonto = ConvertirDecimal(Monto.ToString)
  824. RetPrecio = 0
  825. RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
  826. RetIngresosEsp = 0
  827. Variables.RetMonto = RetMonto
  828. Variables.RetRendimiento = RetRendimiento
  829. ElseIf FamiliaTitulo = "FamiliaLetes" Then
  830. RetMonto = ConvertirDecimal(Monto.ToString)
  831. RetPrecio = 0
  832. RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
  833. RetIngresosEsp = 0
  834. Variables.RetMonto = RetMonto
  835. Variables.RetRendimiento = RetRendimiento
  836. ElseIf FamiliaTitulo = "FamiliaCINV" Then
  837. RetMonto = ConvertirDecimal(Monto.ToString)
  838. RetPrecio = ConvertirDecimal(Precio.ToString)
  839. RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
  840. RetIngresosEsp = 0
  841. Variables.RetMonto = RetMonto
  842. Variables.RetRendimiento = RetRendimiento
  843. Variables.RetPrecio = RetPrecio
  844. ElseIf FamiliaTitulo = "FamiliaFINV" Then
  845. RetMonto = ConvertirDecimal(Monto.ToString)
  846. RetPrecio = 0
  847. RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
  848. RetIngresosEsp = 0
  849. Variables.RetMonto = RetMonto
  850. Variables.RetRendimiento = RetRendimiento
  851. RetValorParticipacionFINV = 1
  852. RetCuotaParticipacionFINV = ConvertirDecimal(RetMonto / RetValorParticipacionFINV)
  853. Variables.RetValorParticipacionFINV = RetValorParticipacionFINV
  854. Variables.RetCuotaParticipacionFINV = RetCuotaParticipacionFINV
  855. ElseIf FamiliaTitulo = "FamiliaReporto" Then
  856. RetMonto = ConvertirDecimal(Monto.ToString)
  857. Variables.RetMonto = RetMonto
  858. End If
  859. Variables.TipoTransaccionCompraVenta = TipoTransaccionCompraVenta
  860. End If
  861. Else
  862. RetCodigoInversionExiste = True
  863. End If
  864. Variables.RetCodigoInversionExiste = RetCodigoInversionExiste
  865. End Sub
  866. End Class