| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284 |
- 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 FechaIncial 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
- If Int Is Nothing Then
- Int = 0
- End If
- Int = Int.ToString.Trim("%")
- If (Integer.TryParse(Int, value)) Then Return value Else Return 0
- 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, ByVal Monto As Double,
- ByVal Precio As Double, ByVal RendimientoEsperado As Double,
- ByVal IngresosEsperados As Double)
- 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 = "REPOVENTA"
- 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
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = ConvertirDecimal(Precio.ToString)
- RetRendimiento = 0
- RetIngresosEsp = 0
- RetUnidadesAcciones = ConvertirDecimal((RetMonto / RetPrecio).ToString)
- Variables.RetMonto = RetMonto
- Variables.RetPrecio = RetPrecio
- Variables.RetUnidadesAcciones = RetUnidadesAcciones
- ElseIf FamiliaTitulo = "FamiliaPrestamoPersonal" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = 0
- RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaDAP" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = 0
- RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaFuturos" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = ConvertirDecimal(Precio.ToString)
- 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
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = 0
- RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaLetes" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = 0
- RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- ElseIf FamiliaTitulo = "FamiliaCINV" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = ConvertirDecimal(Precio.ToString)
- RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- Variables.RetPrecio = RetPrecio
- ElseIf FamiliaTitulo = "FamiliaFINV" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- RetPrecio = 0
- RetRendimiento = ConvertirDecimal(RendimientoEsperado.ToString)
- RetIngresosEsp = 0
- Variables.RetMonto = RetMonto
- Variables.RetRendimiento = RetRendimiento
- RetValorParticipacionFINV = 1
- RetCuotaParticipacionFINV = ConvertirDecimal(RetMonto / RetValorParticipacionFINV)
- Variables.RetValorParticipacionFINV = RetValorParticipacionFINV
- Variables.RetCuotaParticipacionFINV = RetCuotaParticipacionFINV
- ElseIf FamiliaTitulo = "FamiliaReporto" Then
- RetMonto = ConvertirDecimal(Monto.ToString)
- Variables.RetMonto = RetMonto
- End If
- Variables.TipoTransaccionCompraVenta = TipoTransaccionCompraVenta
- End If
- Else
- RetCodigoInversionExiste = True
- End If
- Variables.RetCodigoInversionExiste = RetCodigoInversionExiste
- End Sub
- End Class
|