| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285 |
- Public Class Operaciones
- Private V_TipoOperacion As String
- Dim dia As Integer
- Dim dias31 As Integer
- Dim febreros As Integer
- Dim bisiesto As Integer
- Dim V_IngresoBruto As Double = 0.0
- Dim V_FechaInicial As Date
- Dim V_FechaCorte As Date
- Dim ElementosConsulta As New CargarElementosDAO
- Dim V_CodEmpr = ElementosConsulta.CodEmpr
- Dim V_CodEmis = ElementosConsulta.CodEmis
- Dim V_CodECalRi = ElementosConsulta.CodECalRi
- Dim V_CodPais = ElementosConsulta.CodPais
- Dim V_ListaPlazo = ElementosConsulta.ListaPlazosFactor
- Dim V_ListaTiposMercados = ElementosConsulta.ListaTiposMercado
- Dim V_ListaPeriodos = ElementosConsulta.ListaPeriodos
- Dim V_ListaTipoTasa = ElementosConsulta.ListaTipoTasa
- Dim V_ListaTipoRenta = ElementosConsulta.ListaTipoRenta
- Dim V_ListaEstado = ElementosConsulta.ListaEstado
- Dim V_ListaCasasCorredoras = ElementosConsulta.ListaCasasCorredoras
- Public Property TipoOperacion() As String
- Get
- Return V_TipoOperacion
- End Get
- Set(value As String)
- V_TipoOperacion = value
- End Set
- End Property
- Public Function DiasAcumulados(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
- Dim Total As Integer = 0
- fecha1 = Format(fecha1, "dd/MM/yyyy")
- fecha2 = Format(fecha2, "dd/MM/yyyy")
- If (Base = 0 Or Base = 2) Then
- Total = Base360(fecha1, fecha2)
- ElseIf (Base = 1 Or Base = 3) Then
- Total = Base365(fecha1, fecha2)
- Else
- Total = 0
- End If
- Return Total
- End Function
- Public Function Dias(ByVal fecha1 As DateTime, ByVal fecha2 As DateTime, ByVal Base As Integer)
- Dim Total As Integer = 0
- If (Base = 0 Or Base = 2) Then
- Total = Base360(fecha1, fecha2)
- ElseIf (Base = 1 Or Base = 3) Then
- Total = Base365(fecha1, fecha2)
- Else
- Total = 0
- End If
- Return Total
- End Function
- 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)
- Dim Proceso As Double = 0
- If (IndexBase = 0) Then
- Proceso = ValorNominal * PorcCupon * DiasAcumulados / 360
- ElseIf IndexBase = 1 Then
- Dim PrOpc1 = 0.0, PrOpc2 = 0.0
- Dim CambioDeFecha As Integer = CambioBase(FechaInicial, FechaFinal)
- Dim PrimeraFechaUltima = PrimeraFechaCambioBase(FechaInicial)
- Dim UltimaFechaPrimero = FinalFechaCambioBase(FechaFinal)
- Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
- If (Not CambioDeFecha = 0) Then
- If CambioDeFecha = 1 Then
- DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha366(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
- DiasSegundaFecha = DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
- PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 366
- PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 365
- ElseIf CambioDeFecha = 2 Then
- DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
- DiasSegundaFecha = DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
- PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 365
- PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 366
- End If
- Proceso = PrOpc1 + PrOpc2
- Else
- If (AñoBisiesto(FechaInicial) = 364) Then
- Proceso = ValorNominal * PorcCupon * DiasAcumulados / 365
- End If
- If (AñoBisiesto(FechaInicial) = 365) Then
- Proceso = ValorNominal * PorcCupon * DiasAcumulados / 366
- End If
- End If
- ElseIf IndexBase = 2 Then
- Dim PrOpc1 = 0.0, PrOpc2 = 0.0
- Dim CambioDeFecha As Integer = CambioBase(FechaInicial, FechaFinal)
- Dim PrimeraFechaUltima = PrimeraFechaCambioBase360(FechaInicial)
- Dim UltimaFechaPrimero = FinalFechaCambioBase360(FechaFinal)
- Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
- If (Not CambioDeFecha = 0) Then
- If CambioDeFecha = 1 Then
- DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha360(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
- DiasSegundaFecha = DiasDespuesCambioPrimeraFecha360(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
- PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 366
- PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 365
- ElseIf CambioDeFecha = 2 Then
- DiasPrimeraFecha = DiasDespuesCambioPrimeraFecha360(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
- DiasSegundaFecha = DiasDespuesCambioPrimeraFecha360(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
- PrOpc1 = ValorNominal * PorcCupon * DiasPrimeraFecha / 365
- PrOpc2 = ValorNominal * PorcCupon * DiasSegundaFecha / 366
- End If
- Proceso = PrOpc1 + PrOpc2
- Else
- If (AñoBisiesto(FechaInicial) = 364) Then
- Proceso = ValorNominal * PorcCupon * DiasAcumulados / 365
- End If
- If (AñoBisiesto(FechaInicial) = 365) Then
- Proceso = ValorNominal * PorcCupon * DiasAcumulados / 366
- End If
- End If
- ElseIf IndexBase = 3 Then
- Proceso = ValorNominal * PorcCupon * DiasAcumulados / 360
- End If
- Return Proceso
- End Function
- Public Function Comisiones(ByVal Comision As Double, ByVal ValorTrasado As Double)
- Dim Valor = CDec(Comision) * CDec(ValorTrasado)
- Return Valor
- End Function
- Public Function Base360(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
- Dim Total As Integer = 0
- Dim dias = DateDiff(DateInterval.Day, Fecha1, Fecha2)
- Dim dia As Integer
- Dim dias31 As Integer
- Dim febreros As Integer
- Dim bisiesto As Integer
- While (Fecha1 < Fecha2)
- dia = dia + 1
- If (Fecha1.Day = 31) Then
- dias31 = dias31 + 1
- End If
- If (Fecha1.Month = 2 And Fecha1.Day = 28) Then
- febreros = febreros + 2
- End If
- If (Fecha1.Month = 2 And Fecha1.Day = 29) Then
- bisiesto = bisiesto + 1
- End If
- Fecha1 = Fecha1.AddDays(1)
- End While
- Total = dia - dias31 + febreros - bisiesto
- Return Total
- End Function
- Public Function FechaDias360(ByVal Fecha1 As Date, ByVal Day As Integer)
- Dim CorrelativoDias As Integer = 1
- Dim Dias As Integer = Day
- Dim Fecha As Date = Fecha1
- While CorrelativoDias <= Dias
- Dim Bisiesto As Integer = AñoBisiesto(Fecha)
- If Bisiesto = 365 Then
- If Fecha.Day = 31 Then
- Fecha = Fecha.AddDays(2)
- CorrelativoDias += 1
- ElseIf Fecha.Day = 29 And Fecha.Month = 2 Then
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 2
- Else
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 1
- End If
- Else
- If Fecha.Day = 31 Then
- Fecha = Fecha.AddDays(2)
- CorrelativoDias += 1
- ElseIf Fecha.Day = 28 And Fecha.Month = 2 Then
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 3
- Else
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 1
- End If
- End If
- End While
- Return Fecha
- End Function
- Public Function FechaDias3602829(ByVal Fecha1 As Date, ByVal Day As Integer,Byval DiaFijo As integer)
- Dim CorrelativoDias As Integer = 1
- Dim Dias As Integer = Day
- Dim Fecha As Date = Fecha1
- Dim Conteo As Integer = 0
- While CorrelativoDias <= Dias
- Conteo += 1
- Dim Bisiesto As Integer = AñoBisiesto(Fecha)
- If Bisiesto = 365 Then
- If Fecha.Day = 31 Then
- Fecha = Fecha.AddDays(2)
- CorrelativoDias += 1
- ElseIf Fecha.Day = 29 And Fecha.Month = 2 Then
- If DiaFijo = 30 Then
- If CorrelativoDias = Dias Then
- CorrelativoDias += 2
- Else
- Fecha = Fecha.AddDays(1)
- If Conteo = 1 Then
- CorrelativoDias += 1
- Else
- CorrelativoDias += 2
- End If
- End If
- Else
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 2
- End If
- Else
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 1
- End If
- Else
- If Fecha.Day = 31 Then
- Fecha = Fecha.AddDays(2)
- CorrelativoDias += 1
- ElseIf Fecha.Day = 28 And Fecha.Month = 2 Then
- If DiaFijo = 30 Then
- If (CorrelativoDias + 1) = Dias Then
- CorrelativoDias += 3
- Else
- Fecha = Fecha.AddDays(1)
- If Conteo = 1 Then
- CorrelativoDias += 1
- Else
- CorrelativoDias += 3
- End If
- End If
- ElseIf DiaFijo = 29 Then
- If CorrelativoDias = Dias Then
- CorrelativoDias += 3
- Else
- Fecha = Fecha.AddDays(1)
- If Conteo = 1 Then
- CorrelativoDias += 2
- Else
- CorrelativoDias += 3
- End If
- End If
- Else
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 3
- End If
- Else
- Fecha = Fecha.AddDays(1)
- CorrelativoDias += 1
- End If
- End If
- End While
- Return Fecha
- End Function
- Public Function Base365(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
- Dim dias = DateDiff(DateInterval.Day, Fecha1, Fecha2)
- Return dias
- End Function
- Function AñoBisiesto(ByVal Fecha As Date)
- Dim Año As String = Fecha.Year
- Dim Dias As Integer = 0
- Dim FechaPrimero As Date = "01/01/" + Año
- Dim FechaFinal As Date = "31/12/" + Año
- Dias = DateDiff(DateInterval.Day, FechaPrimero, FechaFinal)
- Return Dias
- End Function
- Function CambioBase(ByVal FechaInicial As Date, ByVal FechaFinal As Date)
- Dim AñoInicial = FechaInicial.Year
- Dim AñoFinal = FechaFinal.Year
- Dim CambioDeBase As Integer = 0
- If (Not AñoInicial = AñoFinal) Then
- If (AñoBisiesto(FechaInicial) = 365) Then
- CambioDeBase = 1
- ElseIf (AñoBisiesto(FechaFinal) = 365) Then
- CambioDeBase = 2
- End If
- End If
- Return CambioDeBase
- End Function
- Function PrimeraFechaCambioBase(ByVal FechaInicial As Date)
- Dim AñoInicial As String = FechaInicial.Year
- Dim FechaPrimerCorte As Date = "31/12/" + AñoInicial
- Return FechaPrimerCorte
- End Function
- Function PrimeraFechaCambioBase360(ByVal FechaInicial As Date)
- Dim AñoInicial As String = FechaInicial.Year
- Dim FechaPrimerCorte As Date = "30/12/" + AñoInicial
- Return FechaPrimerCorte
- End Function
- Function FinalFechaCambioBase(ByVal FechaFinal As Date)
- Dim AñoFinal As String = FechaFinal.Year
- Dim FechaInicialSegundoCorte As Date = "01/01/" + AñoFinal
- Return FechaInicialSegundoCorte
- End Function
- Function FinalFechaCambioBase360(ByVal FechaFinal As Date)
- Dim AñoFinal As String = FechaFinal.Year
- Dim FechaInicialSegundoCorte As Date = "01/01/" + AñoFinal
- Return FechaInicialSegundoCorte
- End Function
- Function DiasDespuesCambioPrimeraFecha365(ByVal FechaIncial As Date, ByVal FechaFinal As Date, ByVal CambioDeFecha As Integer)
- Dim Dias As Integer
- If (CambioDeFecha = 1) Then
- Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal) + 1
- Else
- Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal)
- End If
- Return Dias
- End Function
- Function DiasDespuesCambioPrimeraFecha366(ByVal FechaIncial As Date, ByVal FechaFinal As Date, ByVal CambioDeFecha As Integer)
- Dim Dias As Integer
- If (CambioDeFecha = 2) Then
- Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal) + 1
- Else
- Dias = DateDiff(DateInterval.Day, FechaIncial, FechaFinal)
- End If
- Return Dias
- End Function
- Function DiasDespuesCambioPrimeraFecha366Varios(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
- Dim Dias As Integer = 0
- While (Fecha1 < Fecha2)
- If AñoBisiesto(Fecha1) = 365 Then
- Dias += 1
- End If
- Fecha1 = Fecha1.AddDays(1)
- End While
- Return Dias
- End Function
- Function DiasDespuesCambioPrimeraFecha365Varios(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
- Dim Dias As Integer = 0
- While (Fecha1 < Fecha2)
- If AñoBisiesto(Fecha1) = 364 Then
- Dias += 1
- End If
- Fecha1 = Fecha1.AddDays(1)
- End While
- Return Dias
- End Function
- Function DiasDespuesCambioPrimeraFecha360Bi(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
- Dim Dias As Integer = 0
- While (Fecha1 < Fecha2)
- If AñoBisiesto(Fecha1) = 365 Then
- If (Not Fecha1.Day = 31) Then
- If (Fecha1.Day = 29) Then
- Dias += 1
- End If
- Dias += 1
- End If
- End If
- Fecha1 = Fecha1.AddDays(1)
- End While
- Return Dias
- End Function
- Function DiasDespuesCambioPrimeraFecha360(ByVal Fecha1 As Date, ByVal Fecha2 As Date)
- Dim Dias As Integer = 0
- While (Fecha1 < Fecha2)
- If AñoBisiesto(Fecha1) = 364 Then
- If (Not Fecha1.Day = 31) Then
- If (Fecha1.Day = 28) Then
- Dias += 2
- End If
- Dias += 1
- End If
- End If
- Fecha1 = Fecha1.AddDays(1)
- End While
- Return Dias
- End Function
- Function DiasDespuesCambioPrimeraFecha360(ByVal FechaInicial As Date, ByVal FechaFinal As Date, ByVal CambioDeFecha As Integer)
- Dim Dias As Integer
- Dias = Base360(FechaInicial, FechaFinal)
- Return Dias
- End Function
- Public Sub ValidarEntrada(sender As Object, e As KeyPressEventArgs, ByVal NoAgregar As Boolean)
- If (Char.IsNumber(e.KeyChar)) Then
- e.Handled = False
- ElseIf Char.IsSeparator(e.KeyChar) Then
- e.Handled = True
- ElseIf Char.IsLetter(e.KeyChar) Then
- e.Handled = True
- ElseIf Char.IsPunctuation(e.KeyChar) Then
- If Not e.KeyChar = "." Then
- e.Handled = True
- End If
- ElseIf Char.IsSymbol(e.KeyChar) Then
- e.Handled = True
- ElseIf Char.IsWhiteSpace(e.KeyChar) Then
- e.Handled = True
- End If
- If NoAgregar Then
- e.Handled = True
- End If
- End Sub
- Function Meses(ByVal CantidadMeses As Integer, ByVal Fecha As Date, ByVal MesFijo As Date)
- Dim i As Integer = 0
- Dim DiaInicial As Integer = 0
- Dim Dia = MesFijo.Day
- DiaInicial = Dia
- Fecha = Fecha.AddMonths(CantidadMeses)
- Dim Mes = Fecha.Month
- Mes = Fecha.Month
- If (DiaInicial = 31) Then
- If ((Mes = 1 Or Mes = 3 Or Mes = 5 Or Mes = 7 Or Mes = 8 Or Mes = 10 Or Mes = 12)) Then
- Dim Año = Fecha.Year
- Fecha = CDate(("31/" + Mes.ToString + "/" + Año.ToString))
- ElseIf (Mes = 2) Then
- Dim Año = Fecha.Year
- If (AñoBisiesto(Fecha) = 364) Then
- Fecha = CDate(("28/" + Mes.ToString + "/" + Año.ToString))
- End If
- If (AñoBisiesto(Fecha) = 365) Then
- Fecha = CDate(("29/" + Mes.ToString + "/" + Año.ToString))
- End If
- Else
- Dim Año = Fecha.Year
- Fecha = CDate(("30/" + Mes.ToString + "/" + Año.ToString))
- End If
- ElseIf (DiaInicial = 30) Then
- If (Mes = 2) Then
- Dim Año = Fecha.Year
- Fecha = CDate(("28/" + Mes.ToString + "/" + Año.ToString))
- Else
- Dim Año = Fecha.Year
- Fecha = CDate(("30/" + Mes.ToString + "/" + Año.ToString))
- End If
- ElseIf (DiaInicial = 29) Then
- If (Mes = 2) Then
- Dim Año = Fecha.Year
- Fecha = CDate(("28/" + Mes.ToString + "/" + Año.ToString))
- Else
- Dim Año = Fecha.Year
- Fecha = CDate(("29/" + Mes.ToString + "/" + Año.ToString))
- End If
- End If
- Return Fecha
- End Function
- Function FechaFinMes(ByVal FechaPri As Date, ByVal Periodicidad As String, ByVal Base As Integer)
- Dim Dias As Integer = 0
- Dim Meses As Integer = 0
- If Periodicidad = "M" Then
- Meses = 1
- ElseIf Periodicidad = "T" Then
- Meses = 3
- ElseIf Periodicidad = "S" Then
- Meses = 6
- ElseIf Periodicidad = "A" Then
- Meses = 12
- End If
- If Base = 365 Then
- Dim FechaAnterior As Date = Format(FechaPri, "dd/MM/yyyy")
- Dim FechaCreada As Date = Format(FechaPri, "dd/MM/yyyy")
- Dim DiaAnterior As Integer = FechaAnterior.Day
- Dim MesAnterior As Integer = FechaAnterior.Month
- Dim DiaDiferenciaAnterior31 As Integer = 31 - DiaAnterior
- Dim FechaTemporal31 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior31)
- Dim DiaDiferenciaAnterior30 As Integer = 30 - DiaAnterior
- Dim FechaTemporal30 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior30)
- Dim DiaDiferenciaAnterior29 As Integer = 29 - DiaAnterior
- Dim FechaTemporal29 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior29)
- Dim DiaDiferenciaAnterior28 As Integer = 28 - DiaAnterior
- Dim FechaTemporal28 As Date = FechaAnterior.AddDays(DiaDiferenciaAnterior28)
- ''''''''
- If FechaTemporal31.Month = MesAnterior Then
- If Periodicidad = "M" Then
- If DiaDiferenciaAnterior31 > 0 Then
- FechaCreada = FechaTemporal31
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior31, 0, Base)
- End If
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior31, 0, Base)
- End If
- ElseIf FechaTemporal30.Month = MesAnterior Then
- If Periodicidad = "M" Then
- If DiaDiferenciaAnterior30 > 0 Then
- FechaCreada = FechaTemporal30
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior30, 0, Base)
- End If
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior30, 0, Base)
- End If
- ElseIf FechaTemporal29.Month = MesAnterior Then
- If Periodicidad = "M" Then
- If DiaDiferenciaAnterior29 > 0 Then
- FechaCreada = FechaTemporal29
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior29, 0, Base)
- End If
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior29, 0, Base)
- End If
- ElseIf FechaTemporal28.Month = MesAnterior Then
- If Periodicidad = "M" Then
- If DiaDiferenciaAnterior28 > 0 Then
- FechaCreada = FechaTemporal28
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior28, 0, Base)
- End If
- Else
- FechaCreada = FechaMensual(FechaAnterior, Periodicidad, "FinMes", DiaDiferenciaAnterior28, 0, Base)
- End If
- End If
- Return FechaCreada
- ElseIf Base = 360 Then
- Dim FechaAnterior As Date = FechaPri
- Dim FechaCreada As Date = FechaPri
- Dim DiasAnterior As Integer = FechaAnterior.Day
- Dim DiasFaltantes As Integer = 30 - FechaAnterior.Day
- Dim FechaTemporalValidarDiasMes As Date = Date.Today.Date
- Dim CantidadDiasMes As Integer = 0
- Dim MesAnterior As Integer = FechaAnterior.Month
- If Periodicidad = "M" Then
- If DiasFaltantes > 0 Then
- FechaTemporalValidarDiasMes = Format(CDate("01/" + MesAnterior.ToString + "/" + FechaAnterior.Year.ToString), "dd/MM/yyyy")
- If FechaTemporalValidarDiasMes.AddDays(30).Month = MesAnterior Then
- 'Tiene 31 Dias
- CantidadDiasMes = 31
- ElseIf FechaTemporalValidarDiasMes.AddDays(29).Month = MesAnterior Then
- 'Tiene 30 Dias
- CantidadDiasMes = 30
- ElseIf FechaTemporalValidarDiasMes.AddDays(28).Month = MesAnterior Then
- 'Tiene 29 Dias
- CantidadDiasMes = 29
- ElseIf FechaTemporalValidarDiasMes.AddDays(27).Month = MesAnterior Then
- 'Tiene 28 Dias
- CantidadDiasMes = 28
- End If
- If CantidadDiasMes = 31 Or CantidadDiasMes = 30 Then
- FechaCreada = FechaCreada.AddDays(DiasFaltantes)
- ElseIf CantidadDiasMes = 29 Then
- If DiasFaltantes = 1 Then
- FechaCreada = FechaCreada.AddDays(30)
- Else
- FechaCreada = FechaCreada.AddDays(DiasFaltantes - 1)
- End If
- ElseIf CantidadDiasMes = 28 Then
- If DiasFaltantes = 2 Then
- FechaCreada = FechaCreada.AddDays(30)
- Else
- FechaCreada = FechaCreada.AddDays(DiasFaltantes - 2)
- End If
- End If
- Else
- FechaCreada = FechaCreada.AddMonths(Meses)
- End If
- Else
- Dim DiasCreada As Integer = 0
- Dim MesCreada As Integer = 0
- If DiasFaltantes > 0 Then
- FechaCreada = FechaAnterior.AddMonths(Meses - 1)
- DiasCreada = FechaCreada.Day
- DiasFaltantes = 30 - FechaCreada.Day
- MesCreada = FechaCreada.Month
- FechaTemporalValidarDiasMes = Format(CDate("01/" + MesCreada.ToString + "/" + FechaCreada.Year.ToString), "dd/MM/yyyy")
- If FechaTemporalValidarDiasMes.AddDays(30).Month = MesCreada Then
- 'Tiene 31 Dias
- CantidadDiasMes = 31
- ElseIf FechaTemporalValidarDiasMes.AddDays(29).Month = MesCreada Then
- 'Tiene 30 Dias
- CantidadDiasMes = 30
- ElseIf FechaTemporalValidarDiasMes.AddDays(28).Month = MesCreada Then
- 'Tiene 29 Dias
- CantidadDiasMes = 29
- ElseIf FechaTemporalValidarDiasMes.AddDays(27).Month = MesCreada Then
- 'Tiene 28 Dias
- CantidadDiasMes = 28
- End If
- If CantidadDiasMes = 31 Or CantidadDiasMes = 30 Then
- FechaCreada = FechaCreada.AddDays(DiasFaltantes)
- ElseIf CantidadDiasMes = 29 Then
- If DiasFaltantes = 1 Then
- FechaCreada = FechaCreada.AddDays(30)
- Else
- FechaCreada = FechaCreada.AddDays(DiasFaltantes - 1)
- End If
- ElseIf CantidadDiasMes = 28 Then
- If DiasFaltantes = 2 Then
- FechaCreada = FechaCreada.AddDays(30)
- Else
- FechaCreada = FechaCreada.AddDays(DiasFaltantes - 2)
- End If
- End If
- Else
- FechaCreada = FechaAnterior.AddMonths(Meses)
- End If
- End If
- Return FechaCreada
- End If
- End Function
- 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)
- Dim Meses As Integer = 0
- If Periodicidad = "M" Then
- Meses = 1
- ElseIf Periodicidad = "T" Then
- Meses = 3
- ElseIf Periodicidad = "S" Then
- Meses = 6
- ElseIf Periodicidad = "A" Then
- Meses = 12
- End If
- If Base = 365 Then
- 'TipoCalculo: FinMes,Mensual'
- Dim FechaAnterior As Date = Format(Fecha, "dd/MM/yyyy")
- Dim FechaCreada As Date = Format(Fecha, "dd/MM/yyyy")
- If DiasSobrantes > 0 Then
- FechaCreada = FechaCreada.AddMonths(Meses - 1)
- Else
- FechaCreada = FechaCreada.AddMonths(Meses)
- End If
- Dim DiaCreada As Integer = FechaCreada.Day
- Dim MesCreada As Integer = FechaCreada.Month
- Dim DiaDiferenciaAnterior31 As Integer = 31 - DiaCreada
- Dim FechaTemporal31 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior31)
- Dim DiaDiferenciaAnterior30 As Integer = 30 - DiaCreada
- Dim FechaTemporal30 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior30)
- Dim DiaDiferenciaAnterior29 As Integer = 29 - DiaCreada
- Dim FechaTemporal29 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior29)
- Dim DiaDiferenciaAnterior28 As Integer = 28 - DiaCreada
- Dim FechaTemporal28 As Date = FechaCreada.AddDays(DiaDiferenciaAnterior28)
- If TipoCalculo = "FinMes" Then
- If FechaTemporal31.Month = MesCreada Then
- If DiaDiferenciaAnterior31 > 0 Then
- FechaCreada = FechaTemporal31
- End If
- ElseIf FechaTemporal30.Month = MesCreada Then
- If DiaDiferenciaAnterior30 > 0 Then
- FechaCreada = FechaTemporal30
- End If
- ElseIf FechaTemporal29.Month = MesCreada Then
- If DiaDiferenciaAnterior29 > 0 Then
- FechaCreada = FechaTemporal29
- End If
- ElseIf FechaTemporal28.Month = MesCreada Then
- If DiaDiferenciaAnterior28 > 0 Then
- FechaCreada = FechaTemporal28
- End If
- End If
- Return FechaCreada
- ElseIf TipoCalculo = "Mensual" Then
- FechaAnterior = Fecha
- FechaCreada = Fecha.AddMonths(Meses)
- MesCreada = FechaCreada.Month
- DiaCreada = FechaCreada.Day
- DiaDiferenciaAnterior31 = 31 - DiaCreada
- FechaTemporal31 = FechaCreada.AddDays(DiaDiferenciaAnterior31)
- DiaDiferenciaAnterior30 = 30 - DiaCreada
- FechaTemporal30 = FechaCreada.AddDays(DiaDiferenciaAnterior30)
- DiaDiferenciaAnterior29 = 29 - DiaCreada
- FechaTemporal29 = FechaCreada.AddDays(DiaDiferenciaAnterior29)
- If DiaFijo = 31 Then
- If MesCreada = FechaTemporal31.Month Then
- FechaCreada = FechaTemporal31
- ElseIf MesCreada = FechaTemporal30.Month Then
- FechaCreada = FechaTemporal30
- ElseIf MesCreada = FechaTemporal29.Month Then
- FechaCreada = FechaTemporal29
- Else
- FechaCreada = FechaTemporal28
- End If
- ElseIf DiaFijo = 30 Then
- If MesCreada = FechaTemporal30.Month Then
- FechaCreada = FechaTemporal30
- ElseIf MesCreada = FechaTemporal29.Month Then
- FechaCreada = FechaTemporal29
- Else
- FechaCreada = FechaTemporal28
- End If
- ElseIf DiaFijo = 29 Then
- If MesCreada = FechaTemporal29.Month Then
- FechaCreada = FechaTemporal29
- Else
- FechaCreada = FechaTemporal28
- End If
- Else
- Dim DiaAgregar As Integer = DiaFijo - FechaCreada.Day
- FechaCreada = FechaCreada.AddDays(DiaAgregar)
- End If
- Return FechaCreada
- End If
- ElseIf Base = 360 Then
- Dim Dias As Integer = Meses * 30
- Dim FechaAnterior As Date = Fecha
- FechaAnterior = FechaDias3602829(FechaAnterior, Dias, DiaFijo)
- Return FechaAnterior
- End If
- End Function
- Function ConvertirDecimal(ByVal Dec As String)
- Dim value As Double = 0
- If Dec Is Nothing Then
- Dec = 0
- End If
- Dec = Dec.ToString.Trim("%")
- If (Decimal.TryParse(Dec, value)) Then Return value Else Return 0
- End Function
- Function ConvertirBoolNum(ByVal Bool As String)
- Dim value As Boolean = 0
- If Bool Is Nothing Then
- value = False
- Else
- Bool = Bool.ToString.Trim("%")
- If String.IsNullOrEmpty(Bool) Then
- value = False
- Else
- If ConvertirEntero(Bool) = 1 Then
- value = True
- Else
- value = False
- End If
- End If
- End If
- Return value
- End Function
- Function ConvertirEntero(ByVal Int As String)
- Dim value As Integer = 0
- Dim TemporaCadena As String = Int
- Dim TemporalNumero As Integer = 0
- If Int Is Nothing Then
- Int = 0
- End If
- Int = Int.ToString.Trim("%")
- If Integer.TryParse(Int, value) Then
- Return value
- Else
- Try
- TemporalNumero = TemporaCadena
- Return TemporalNumero
- Catch ex As Exception
- Return 0
- End Try
- End If
- End Function
- Function ConvertirCadena(ByVal Cadena As Object)
- Dim value As Integer = 0
- If Cadena Is Nothing Then
- Cadena = String.Empty
- End If
- If Cadena Is DBNull.Value Then
- Cadena = String.Empty
- End If
- Return Cadena.ToString
- End Function
- Function ConvertirFecha(ByVal Fecha As String)
- Dim value As Date = Date.Today.Date
- If (Date.TryParse(Fecha, value)) Then Return value Else Return Date.Today.Date
- End Function
- Function ConvertirFechaBaseDatos(ByVal Fecha As String)
- Dim value As Date = Date.Today.Date
- If (Date.TryParse(Fecha, value)) Then Return value Else Return DBNull.Value
- End Function
- Sub TraspasarDatos(ByVal CodigoExiste As String, ByVal CodigoInstrumentoExiste As String,
- ByVal IsNueva As String, ByVal TipoTransaccionCompraVenta As String,
- ByVal FamiliaTitulo As String)
- If IsNueva = "N" Then
- Dim General As New DAOGeneral
- Dim Tabla As String = String.Empty
- If CodigoInstrumentoExiste = "ACCI" Or CodigoInstrumentoExiste = "ACCNC" Or
- CodigoInstrumentoExiste = "ACCNP" Then
- Tabla = "ACC0"
- ElseIf CodigoInstrumentoExiste = "PPER" Then
- Tabla = "PPER0"
- ElseIf CodigoInstrumentoExiste = "DAP" Then
- Tabla = "DAP0"
- ElseIf CodigoInstrumentoExiste = "NEST" Then
- Tabla = "NETS0"
- ElseIf CodigoInstrumentoExiste = "FUTU" Then
- Tabla = "FUT0"
- ElseIf CodigoInstrumentoExiste = "OPC" Then
- Tabla = "OPC0"
- ElseIf CodigoInstrumentoExiste = "PEMP" Then
- Tabla = "PEMP0"
- ElseIf CodigoInstrumentoExiste = "LETE" Then
- Tabla = "LET0"
- ElseIf CodigoInstrumentoExiste = "CETE" Then
- Tabla = "CET0"
- ElseIf CodigoInstrumentoExiste = "PBUR" Then
- Tabla = "PBUR"
- ElseIf CodigoInstrumentoExiste = "VCN" Then
- Tabla = "VCN"
- ElseIf CodigoInstrumentoExiste = "BONO" Then
- Tabla = "BON0"
- ElseIf CodigoInstrumentoExiste = "CINV" Then
- Tabla = "CIN0"
- ElseIf CodigoInstrumentoExiste = "EURB" Then
- Tabla = "EURB0"
- ElseIf CodigoInstrumentoExiste = "TIT" Then
- Tabla = "TIT"
- ElseIf CodigoInstrumentoExiste = "FINV" Then
- Tabla = "FINV"
- ElseIf CodigoInstrumentoExiste = "REPO" Then
- Tabla = "REP0"
- ElseIf CodigoInstrumentoExiste = "REPOVENTA" Then
- Tabla = "REP0VENTA"
- End If
- Dim RetCodigoInversionExiste As Boolean = General.ExisteTitulo(CodigoExiste, Tabla)
- If Not RetCodigoInversionExiste Then
- Dim RetMonto As Double = 0
- Dim RetPrecio As Double = 0
- Dim RetRendimiento As Double = 0
- Dim RetIngresosEsp As Double = 0
- Dim RetUnidadesAcciones As Integer = 0
- Dim RetUnidadesContratosFuturos As Integer = 0
- Dim RetCantidadContratosFuturos As Integer = 0
- Dim RetCuotaParticipacionFINV As Integer = 0
- Dim RetValorParticipacionFINV As Integer = 0
- If FamiliaTitulo = "FamiliaAcciones" Then
- RetRendimiento = 0
- RetIngresosEsp = 0
- RetUnidadesAcciones = ConvertirDecimal((RetMonto / RetPrecio).ToString)
- Variables.RetMonto = RetMonto
- Variables.RetPrecio = RetPrecio
- Variables.RetUnidadesAcciones = RetUnidadesAcciones
- ElseIf FamiliaTitulo = "FamiliaPrestamoPersonal" Then
- RetPrecio = 0
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaDAP" Then
- RetPrecio = 0
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaFuturos" Then
- RetRendimiento = 0
- RetIngresosEsp = 0
- RetUnidadesContratosFuturos = 1
- RetCantidadContratosFuturos = ConvertirDecimal((RetMonto / (RetUnidadesContratosFuturos * RetPrecio)))
- Variables.RetMonto = RetMonto
- Variables.RetPrecio = RetPrecio
- Variables.RetUnidadesContratosFuturos = RetUnidadesContratosFuturos
- Variables.RetCantidadContratosFuturos = RetCantidadContratosFuturos
- ElseIf FamiliaTitulo = "FamiliaEmpresas" Then
- RetPrecio = 0
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaLetes" Then
- RetPrecio = 0
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaCINV" Then
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- Variables.RetPrecio = RetPrecio
- ElseIf FamiliaTitulo = "FamiliaFINV" Then
- RetPrecio = 0
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- RetValorParticipacionFINV = 1
- RetCuotaParticipacionFINV = ConvertirDecimal(RetMonto / RetValorParticipacionFINV)
- Variables.RetValorParticipacionFINV = RetValorParticipacionFINV
- Variables.RetCuotaParticipacionFINV = RetCuotaParticipacionFINV
- ElseIf FamiliaTitulo = "FamiliaReporto" Then
- Variables.RetMonto = RetMonto
- End If
- Variables.TipoTransaccionCompraVenta = TipoTransaccionCompraVenta
- End If
- Else
- RetCodigoInversionExiste = True
- End If
- Variables.RetCodigoInversionExiste = RetCodigoInversionExiste
- End Sub
- End Class
|