Files
Asegasa.NET/guia/Extensiones/gestionasegasaEntities.vb
2026-04-28 11:52:16 +02:00

1409 lines
99 KiB
VB.net

Imports System.Data.EntityClient
Imports System.Data.Objects
Imports System.Net
Imports tsl5
Imports tsl5.Enumeraciones
Imports tsl5.Extensiones
Imports tsWPF
Imports System.Data.Entity
Imports DevExpress.UnitConversion
Imports DevExpress.XtraSpreadsheet.DocumentFormats.Xlsb
Public Class gestionasegasaEntities
Implements tsWPF.ItsObjectContext
Public Shared Usuario As String
Public Shared dsc As New tsl5.Datos.DatosSesionCliente
Public Shared Property bdga As tsl5.Datos.BBDD
Public Shared Property EsRemoto As Boolean
Private Shared _ListaSituacionesWeb As List(Of enumeraciones) = Nothing
Private Shared _ListaPagoWeb As List(Of enumeraciones) = Nothing
Private _Ip As String
Private Shared _TippCIA As Integer
Private Shared _TippFAE As Integer
Private Shared _CabaSupl As Integer
Private Shared _CabaSust As Integer
Private Shared _CabaPGO As Integer
Public Property ip As String
Get
Return _Ip
End Get
Set(value As String)
_Ip = value
End Set
End Property
Public Shared Function TipoPagoCia() As Integer
If _TippCIA = 0 Then
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
_TippCIA = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.CIA").idEnumeracion
End If
Return _TippCIA
End Function
Public Shared Function TipoPagoFAE() As Integer
If _TippFAE = 0 Then
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
_TippFAE = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.FAE").idEnumeracion
End If
Return _TippFAE
End Function
Public Shared Function CabaPGO() As Integer
If _CabaPGO = 0 Then
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
_CabaPGO = bd.enumeraciones.First(Function(x) x.Codigo = "CABA.PGO").idEnumeracion
End If
Return _CabaPGO
End Function
Public Shared Function CabaSupl() As Integer
If _CabaSupl = 0 Then
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
_CabaSupl = bd.enumeraciones.First(Function(x) x.Codigo = "CABA.SUPL").idEnumeracion
End If
Return _CabaSupl
End Function
Public Shared Function CabaSust() As Integer
If _CabaSust = 0 Then
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
_CabaSust = bd.enumeraciones.First(Function(x) x.Codigo = "CABA.SUST").idEnumeracion
End If
Return _CabaSust
End Function
Shared Function NuevoContextoCN(NombreConexion As String, Optional ConEventos As Boolean = False, Optional Desarrollo As Boolean = False, Optional Remoto As Boolean? = Nothing, Optional FuerzaSeleccion As Boolean = True, Optional Aplicacion As tsUserControl = Nothing) As gestionasegasaEntities
Dim cn = bdGestionAsegasa.gestionasegasaEntities.ListaConexiones.First(Function(x) x.Nombre = NombreConexion)
Dim dbd = New Datos.BBDD
dbd.Usuario = cn.Usuario
dbd.Password = cn.Contraseña
dbd.DataBase = cn.Database
dbd.Tipo = TipoBD.MYSQL
Dim de As gestionasegasaEntities
If Remoto Then
de = New gestionasegasaEntities(tsl5.bbdd.ObtieneEntityConnectionStringMysql(cn.ServidorRemoto, cn.Database, cn.PuertoRemoto, cn.Usuario, cn.Contraseña, "GestionAsegasa", True,,,, 60 * 3))
Else
de = New gestionasegasaEntities(tsl5.bbdd.ObtieneEntityConnectionStringMysql(cn.ServidorLocal, cn.Database, cn.PuertoLocal, cn.Usuario, cn.Contraseña, "GestionAsegasa", True,,,, 60 * 3))
End If
de.CommandTimeout = 60 * 5
If ConEventos Then AddHandler de.SavingChanges, AddressOf GuardandoCambios
If de.ip = "" Then de.ip = tsl5.bbdd.ObtieneIPMysql(de)
de.Aplicacion = Aplicacion
Return de
End Function
Shared Function NuevoContextoCE(Optional Aplicaciones As String = "POLIZASSG|ENTIDADES", Optional Desarrollo As Boolean = False, Optional Remoto As Boolean? = Nothing, Optional FuerzaSeleccion As Boolean = True, Optional Aplicacion As tsUserControl = Nothing) As gestionasegasaEntities
Dim ctx = NuevoContextoCN(True, Desarrollo, Remoto, FuerzaSeleccion, Aplicacion)
ctx.OtrosDatos = Aplicaciones
Return ctx
End Function
Shared Function NuevoContextoCN(Optional ConEventos As Boolean = False, Optional Desarrollo As Boolean = False, Optional Remoto As Boolean? = Nothing, Optional FuerzaSeleccion As Boolean = True, Optional Aplicacion As tsUserControl = Nothing) As gestionasegasaEntities
Return NuevoContexto(ConEventos, Desarrollo, False, Remoto, FuerzaSeleccion, Aplicacion)
End Function
Shared Function NuevoContexto(Optional ConEventos As Boolean = False, Optional Desarrollo As Boolean = False, Optional ReusarConexion As Boolean = True, Optional Remoto As Boolean? = Nothing, Optional FuerzaSeleccion As Boolean = True, Optional Aplicacion As tsUserControl = Nothing) As gestionasegasaEntities
'
' SE ESTABLECE A FALSO EL REUSAR LA CONEXION POR ERRORES
'
'
ReusarConexion = False
'
'
'
If bdga Is Nothing Then
If FuerzaSeleccion Then
EstableceCBD(FuerzaSeleccion, Desarrollo, Remoto)
Else
EstableceCBD(False, Desarrollo, Remoto)
End If
End If
Dim de As gestionasegasaEntities
Dim iNumErrores As Integer = 0
Do
Try
' de = Conectar(bdga.Servidor, bdga.DataBase, bdga.Usuario, bdga.Password, bdga.Puerto)
If Conexion Is Nothing OrElse ReusarConexion = False OrElse Conexion.State = ConnectionState.Broken Then
de = New gestionasegasaEntities(tsl5.bbdd.ObtieneEntityConnectionStringMysql(bdga.Servidor, bdga.DataBase, bdga.Puerto, bdga.Usuario, bdga.Password, "GestionAsegasa", True,,,, 60 * 3))
If ReusarConexion Then Conexion = de.Connection
de.CommandTimeout = 60 * 5
If ConEventos Then AddHandler de.SavingChanges, AddressOf GuardandoCambios
If de.ip = "" Then de.ip = tsl5.bbdd.ObtieneIPMysql(de)
de.Aplicacion = Aplicacion
Else
de = New gestionasegasaEntities(Conexion)
End If
Return de
Exit Do
Catch ex As Exception
iNumErrores += 1
If iNumErrores > 1 Then
Throw ex
End If
Threading.Thread.Sleep(5000)
End Try
Loop
End Function
Public Shared Property Conexion As EntityConnection
Public Property Aplicacion As tsUserControl
Public Property OtrosDatos As String
Public Shared Function ListaConexiones() As List(Of Conexion)
Dim lc As New List(Of Conexion)
lc.Add(New Conexion With {.Nombre = "Producción", .ServidorLocal = "192.168.61.201", .PuertoLocal = 30002, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 30002, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "Desarrollo", .ServidorLocal = "fm1.tecnosis.net", .PuertoLocal = 33333, .ServidorRemoto = "fm1.tecnosis.net", .PuertoRemoto = 33333, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "lunes", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31021, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31021, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "martes", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31022, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31022, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "miercoles", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31023, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31023, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "jueves", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31024, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31024, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "viernes", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31025, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31025, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "sabado", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31026, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31026, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "domingo", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31020, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31020, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "mediodia", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31029, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31029, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "enero", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31001, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31001, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "febrero", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31002, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31002, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "marzo", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31003, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31003, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "abril", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31004, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31004, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "mayo", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31005, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31005, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "junio", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31006, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31006, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "julio", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31007, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31007, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "agosto", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31008, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31008, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "septiembre", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31009, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31009, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "octubre", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31010, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31010, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "noviembre", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31011, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31011, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "diciembre", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31012, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31012, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "replica tecnosis", .ServidorLocal = "192.168.41.26", .PuertoLocal = 3306, .ServidorRemoto = "192.168.41.26", .PuertoRemoto = 3306, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "replica asegasa", .ServidorLocal = "192.168.61.203", .PuertoLocal = 36200, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 36200, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
lc.Add(New Conexion With {.Nombre = "replica defectuosa 25-10-2024", .ServidorLocal = "192.168.61.202", .PuertoLocal = 31030, .ServidorRemoto = "sevilla.asegasa.com", .PuertoRemoto = 31030, .Usuario = "asegasa", .Contraseña = "A2OeVqigd7mHL", .Database = "gestionasegasa"})
Return lc
End Function
Public Shared Sub EstableceCBD(FuerzaSeleccion As Boolean, Optional Desarrollo As Boolean = False, Optional Remoto As Boolean? = Nothing)
Try
EstableceLocalizacion(Remoto)
Dim lc = ListaConexiones()
Dim cs As Conexion
If Desarrollo Then
cs = lc(8)
Else
If FuerzaSeleccion Then
Conexion = Nothing
Dim dx As New dxwConexiones(lc)
If dx.ShowDialog Then
cs = dx.ConexionSeleccionada
Else
cs = lc(0)
End If
Else
cs = lc(0)
End If
End If
bdga = New Datos.BBDD
bdga.Usuario = cs.Usuario
bdga.Password = cs.Contraseña
bdga.DataBase = cs.Database
bdga.Tipo = TipoBD.MYSQL
bdga.id = cs.Nombre
If EsRemoto AndAlso cs.Nombre = "Producción" AndAlso Environment.MachineName.ToUpper <> "ASEGASA1" Then
bdga.Servidor = cs.ServidorRemoto
bdga.Puerto = cs.PuertoRemoto
Else
If cs.Nombre = "Producción" AndAlso Environment.MachineName.ToUpper = "ASEGASA1" Then
bdga.Servidor = "localhost"
Else
bdga.Servidor = cs.ServidorLocal
End If
bdga.Puerto = cs.PuertoLocal
End If
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Sub
Public Shared Sub EstableceCBD(nombreconexion As String, remoto As Boolean)
Try
Dim lc = ListaConexiones()
Dim cs = lc.First(Function(x) x.Nombre = nombreconexion)
bdga = New Datos.BBDD
bdga.Usuario = cs.Usuario
bdga.Password = cs.Contraseña
bdga.DataBase = cs.Database
bdga.Tipo = TipoBD.MYSQL
bdga.id = cs.Nombre
If remoto Then
bdga.Servidor = cs.ServidorRemoto
bdga.Puerto = cs.PuertoRemoto
Else
If cs.Nombre = "Producción" AndAlso Environment.MachineName.ToUpper = "ASEGASA1" Then
bdga.Servidor = "localhost"
Else
bdga.Servidor = cs.ServidorLocal
End If
bdga.Puerto = cs.PuertoLocal
End If
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Sub
Private Shared Sub GuardandoCambios(sender As Object, e As EventArgs)
Dim bd = DirectCast(sender, bdGestionAsegasa.gestionasegasaEntities)
Try
Dim sAplicaciones As String = If(bd.Aplicacion IsNot Nothing AndAlso bd.Aplicacion.NombreTablaBase IsNot Nothing, bd.Aplicacion.NombreTablaBase.ToUpper, bd.OtrosDatos)
For Each saplicacion In sAplicaciones.NothingAVacio.Split("|")
Select Case saplicacion
Case "POLIZASSG", "VF_DOCUMENTOSPOLIZASSG"
bdGestionAsegasa.polizassg.GuardandoCambios(bd, saplicacion)
Case "ENTIDADES"
bdGestionAsegasa.entidades.GuardandoCambios(bd, saplicacion)
Case "SINIESTROS"
bdGestionAsegasa.siniestros.GuardandoCambios(bd)
Case "RECIBOS", "INCORPORACION_RECIBOS_EIAC"
bdGestionAsegasa.recibos.GuardandoCambios(bd, saplicacion)
End Select
Next
Catch ex As Exception
End Try
End Sub
Public Shared Sub EstableceLocalizacion(Remoto As Boolean?)
Try
If Remoto.HasValue = False Then
If Not IO.Directory.Exists("c:\tecnosis.tfs") Then
EsRemoto = False
Try
Dns.GetHostEntry("servidorbdgestionasegasa").AddressList(0).ToString()
EsRemoto = True
Catch ex As Exception
EsRemoto = False
End Try
Else
EsRemoto = True
End If
Else
EsRemoto = Remoto.Value
End If
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Sub
Public Function ObtenerAgente(usuario As String, pass As String) As agentes
Dim claveSha = tsl5.crypt.SHA1("M3Soft." & pass)
Try
Dim usus As List(Of agentes) = Me.agentes.Where(Function(x) x.Codigo = usuario And x.hashContrasena = claveSha).ToList
If Not usus.Count = 0 Then
Return usus.First
End If
Catch ex As Exception
Throw New Exception("Ha ocurrido un error al conectar con la base de datos, disculpe las molestias")
End Try
Return Nothing
End Function
Public Function ObtenerSubagente(codigoAgente As String, codigoSubAgente As String, contraseña As String) As subagentes
Try
Dim claveSha = tsl5.crypt.SHA1("M3Soft." & contraseña)
Dim agente As agentes = Me.agentes.Where(Function(x) x.Codigo = codigoAgente).First
Dim subs As List(Of subagentes) = Me.subagentes.Where(Function(x) x.idAgente = agente.idAgente AndAlso x.Codigo = codigoSubAgente AndAlso x.hashContrasena = claveSha).ToList
If Not subs.Count = 0 Then
Return subs.First
Else
Return Nothing
End If
Catch ex As Exception
Throw New Exception("Ha ocurrido un error al conectar con la base de datos, disculpe las molestias")
End Try
End Function
Friend Shared Function ObtieneSituacionWeb(idSituacion As Integer?, idTipoPago As Integer?)
If idSituacion.HasValue Then
If _ListaSituacionesWeb Is Nothing OrElse _ListaPagoWeb Is Nothing Then
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
If _ListaSituacionesWeb Is Nothing Then
_ListaSituacionesWeb = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "SITR").ToList
End If
If _ListaPagoWeb Is Nothing Then
_ListaPagoWeb = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "TIPP").ToList
End If
End If
Dim sitr = _ListaSituacionesWeb.First(Function(X) X.idEnumeracion = idSituacion)
If idTipoPago.HasValue Then
Dim tipp = _ListaPagoWeb.First(Function(x) x.idEnumeracion = idTipoPago)
If sitr.Codigo = "SITR.BJ" AndAlso (tipp.Codigo = "TIPP.CIA" OrElse tipp.Codigo = "TIPP.FAE") Then
Return tipp.Descripcion
Else
Return sitr.Descripcion
End If
Else
Return sitr.Descripcion
End If
Else
Return ""
End If
End Function
Public Function ObTieneMunicipio(CodigoPostal As String, Poblacion As String) As String
Try
Dim CodigoMunicipio As String = ""
If CodigoPostal.NothingAVacio.Length = 5 Then
If Me.codigospostales.Any(Function(x) x.CodigoPostal = CodigoPostal) Then
If Me.codigospostales.Where(Function(x) x.CodigoPostal = CodigoPostal).Count = 1 Then
CodigoMunicipio = Me.codigospostales.First(Function(x) x.CodigoPostal = CodigoPostal).CodigoMunicipio
Else
CodigoMunicipio = ObtieneCodigoMunicipioMasCoincidente(CodigoPostal, Poblacion)
End If
Else
Dim cpotmp = CodigoPostal.Substring(0, 4) & "0"
If Me.codigospostales.Any(Function(x) x.CodigoPostal = cpotmp) Then
If Me.codigospostales.Count(Function(x) x.CodigoPostal = cpotmp) = 1 Then
CodigoMunicipio = Me.codigospostales.First(Function(x) x.CodigoPostal = cpotmp).CodigoMunicipio
Else
CodigoMunicipio = ObtieneCodigoMunicipioMasCoincidente(CodigoPostal, Poblacion)
End If
Else
Dim cpotmp2 = CodigoPostal.Substring(0, 3) & "00"
If Me.codigospostales.Any(Function(x) x.CodigoPostal = cpotmp2) Then
If Me.codigospostales.Count(Function(x) x.CodigoPostal = cpotmp2) = 1 Then
CodigoMunicipio = Me.codigospostales.First(Function(x) x.CodigoPostal = cpotmp2).CodigoMunicipio
Else
CodigoMunicipio = ObtieneCodigoMunicipioMasCoincidente(CodigoPostal, Poblacion)
End If
End If
End If
End If
Else
If Poblacion.NothingAVacio = "" Then
Return Nothing
Else
Dim mun = Me.municipios.FirstOrDefault(Function(x) x.Nombre = Poblacion)
If mun IsNot Nothing Then
CodigoMunicipio = mun.CodigoMunicipio
Else
Return Nothing
End If
End If
End If
If CodigoMunicipio = "" Then
Return Nothing
Else
Return CodigoMunicipio
End If
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Function
Public Function ObtieneCodigoMunicipioMasCoincidente(CodigoPostal As String, Poblacion As String, Optional SinAñadir As Boolean = False) As String
Try
If Poblacion.NothingAVacio = "" Then
Return ""
Else
Dim municipios = Me.codigospostales.Where(Function(x) x.CodigoPostal = CodigoPostal And x.municipios.Nombre = Poblacion).ToList
If municipios.Count = 1 Then
Return municipios(0).CodigoMunicipio
Else
If CodigoPostal.Length = 5 Then
Dim codigoprovincia = CodigoPostal.Substring(0, 2)
municipios = Me.municipios.Where(Function(x) x.CodigoProvincia = codigoprovincia).SelectMany(Function(x) x.codigospostales).ToList
Dim IndiceMasCoincidente As Integer = 0
Dim Puntuacion As Integer = 0
If municipios.Count = 0 Then
Return ""
Else
For i = 0 To municipios.Count - 1
' Dim Porcentaje As Double = 0
Dim puntuaciontmp = ComparaPalabras(municipios(i).municipios.Nombre, Poblacion)
If i = 0 OrElse Puntuacion < puntuaciontmp Then
IndiceMasCoincidente = i
Puntuacion = puntuaciontmp
End If
Next
End If
If SinAñadir = False Then
If Puntuacion = 100 Then
CrearNuevoCodigoPostal(CodigoPostal, municipios(IndiceMasCoincidente).CodigoMunicipio)
Return municipios(IndiceMasCoincidente).CodigoMunicipio
Else
Return CrearNuevoMunicipio(CodigoPostal, Poblacion)
End If
Else
Return ""
End If
Else
Return ""
End If
End If
End If
Catch EX As Exception
Throw New Exception(EX.Message, EX)
End Try
End Function
Public Shared Function ObtieneCodigoMunicipioMasCoincidente(CodigosPostales As List(Of codigospostales), LMunicipios As List(Of municipios), CodigoPostal As String, Poblacion As String) As String
Try
Dim municipios = CodigosPostales.Where(Function(x) x.CodigoPostal = CodigoPostal).ToList
If municipios.Count = 1 Then
Return municipios(0).CodigoMunicipio
Else
If municipios.Count = 0 AndAlso CodigoPostal.Length = 5 Then
Dim codigoprovincia = CodigoPostal.Substring(0, 2)
municipios = LMunicipios.Where(Function(x) x.CodigoProvincia = codigoprovincia).SelectMany(Function(x) x.codigospostales).ToList
End If
If CodigosPostales.Any(Function(x) x.CodigoPostal = CodigoPostal And x.municipios.Nombre = Poblacion) Then
Return CodigosPostales.First(Function(x) x.CodigoPostal = CodigoPostal And x.municipios.Nombre = Poblacion).CodigoMunicipio
Else
Dim IndiceMasCoincidente As Integer = 0
Dim Puntuacion As Integer = 0
If municipios.Count = 0 Then
Return ""
Else
For i = 0 To municipios.Count - 1
Dim puntuaciontmp = ComparaPalabras(municipios(i).municipios.Nombre, Poblacion)
If i = 0 OrElse Puntuacion < puntuaciontmp Then
IndiceMasCoincidente = i
Puntuacion = puntuaciontmp
End If
Next
End If
If Puntuacion > 49 Then
Return municipios(IndiceMasCoincidente).CodigoMunicipio
Else
Return CrearNuevoMunicipio(CodigoPostal, Poblacion)
End If
End If
End If
Catch EX As Exception
Throw New Exception(EX.Message, EX)
End Try
End Function
Private Shared Function CrearNuevoMunicipio(CodigoPostal As String, Municipio As String) As String
If Municipio.NothingAVacio = "" Then
Return ""
Else
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
Dim nm As New municipios
Dim codpro As String = CodigoPostal.Substring(0, 2)
Dim ultmun = bd.municipios.Where(Function(x) x.CodigoProvincia = codpro).OrderByDescending(Function(x) x.CodigoMunicipio).First
Dim Letra As Char
Dim Numero As Integer = 0
If "0123456789".Contains(ultmun.CodigoMunicipio.Substring(2, 1)) Then
Letra = "A"c
Numero = 0
Else
Letra = ultmun.CodigoMunicipio.Substring(2, 1)
Numero = Integer.Parse(ultmun.CodigoMunicipio.Substring(3)) + 1
If Numero > 99 Then
Letra = ChrW(AscW(Letra) + 1)
Numero = 0
End If
End If
With nm
nm.CodigoProvincia = codpro
nm.Nombre = Municipio
nm.CodigoMunicipio = codpro & Letra & Numero.ToString.PadLeft(2, "0")
End With
bd.municipios.AddObject(nm)
bd.SaveChanges()
Dim cp As New codigospostales
With cp
.CodigoPostal = CodigoPostal
.CodigoMunicipio = nm.CodigoMunicipio
End With
bd.codigospostales.AddObject(cp)
bd.SaveChanges()
Return nm.CodigoMunicipio
End If
End Function
Private Shared Sub CrearNuevoCodigoPostal(CodigoPostal As String, CodigoMunicipio As String)
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
If bd.codigospostales.Any(Function(x) x.CodigoMunicipio = CodigoMunicipio And x.CodigoPostal = CodigoPostal) = False Then
Dim cp As New codigospostales
With cp
.CodigoPostal = CodigoPostal
.CodigoMunicipio = CodigoMunicipio
End With
bd.codigospostales.AddObject(cp)
bd.SaveChanges()
End If
End Sub
Private Shared Function ComparaPalabras(Cadena1 As String, Cadena2 As String) As Double
Try
Cadena1 = Cadena1.ToLower.Replace("á", "a").Replace("é", "e").Replace("í", "i").Replace("ó", "o").Replace("ú", "u").Replace("Ñ", "ñ").Replace("(", " ").Replace(")", " ").Replace(Chr(34), "").Replace("-", " ").Replace(",", "").Trim
Cadena2 = Cadena2.ToLower.Replace("á", "a").Replace("é", "e").Replace("í", "i").Replace("ó", "o").Replace("ú", "u").Replace("Ñ", "ñ").Replace("(", " ").Replace(")", " ").Replace(Chr(34), "").Replace("-", " ").Replace(",", "").Trim
Dim Cadenas1 = Cadena1.Split(" ").Where(Function(X) X <> "")
Dim Cadenas2 = Cadena2.Split(" ").Where(Function(X) X <> "")
Dim Coincidente As Integer = 0
For Each c In Cadenas1
If Cadenas2.Contains(c) Then
Coincidente += 1
End If
Next
For Each c In Cadenas2
If Cadenas1.Contains(c) Then
Coincidente += 1
End If
Next
Return (Coincidente * 100 / (Cadenas1.Count + Cadenas2.Count))
' Return Coincidente
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Function
Public Function GuardarCambios() As Integer Implements ItsObjectContext.GuardarCambios
Try
Return Me.SaveChanges()
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Function
Public Function ObtieneRecibosPendientesDescobro() As List(Of vf_recibosextendidos)
Dim idDescobro = Me.enumeraciones.First(Function(x) x.Codigo = "CABA.DES").idEnumeracion
Dim idTipLiqDes = Me.enumeraciones.First(Function(x) x.Codigo = "TIPLIQ.DESCOBRO").idEnumeracion
Dim idTipLiq = Me.enumeraciones.First(Function(x) x.Codigo = "TIPLIQ.LIQUIDACION").idEnumeracion
Return (From dcp In ((From lc In Me.liquidacionescompaniasrecibos Where lc.liquidacionescompanias.idTipoLiquidacion = idTipLiq And lc.recibos.idCausaBaja = idDescobro
From dc In Me.liquidacionescompaniasrecibos.Where(Function(dc) dc.idRecibo = lc.idRecibo And dc.liquidacionescompanias.idTipoLiquidacion = idTipLiqDes).DefaultIfEmpty).Where(Function(x) x.dc Is Nothing))
From re In Me.vf_recibosextendidos.Where(Function(x) x.idRecibo = dcp.lc.idRecibo) Select re).ToList
End Function
Public Function ObtieneRecibosPendientesDescobroAgentes() As List(Of vf_recibosextendidos)
'Dim idDescobro = Me.enumeraciones.First(Function(x) x.Codigo = "CABA.DES").idEnumeracion
'Dim idTipLiqDes = Me.enumeraciones.First(Function(x) x.Codigo = "TIPLIQAG.RETCOM").idEnumeracion
'Dim idTipLiq = Me.enumeraciones.First(Function(x) x.Codigo = "TIPLIQAG.LIQUIDACION").idEnumeracion
'Dim FechaInicio As New Date(2020, 11, 2)
'Dim recs = (From dcp In ((From lc In Me.liquidacionesagenterecibos Where lc.liquidacionesagentes.idTipoLiquidacion = idTipLiq And lc.recibos.idCausaBaja = idDescobro And lc.recibos.FechaBaja.HasValue AndAlso lc.recibos.FechaBaja.Value > FechaInicio
' From dc In Me.liquidacionesagenterecibos.Where(Function(dc) dc.idRecibo = lc.idRecibo And dc.liquidacionesagentes.idTipoLiquidacion = idTipLiqDes).DefaultIfEmpty).Where(Function(x) x.dc Is Nothing))
' From re In Me.vf_recibosextendidos.Where(Function(x) x.idRecibo = dcp.lc.idRecibo) Select re).ToList
'For Each r In recs
' r.EsRetornoComision_TMP = True
'Next
'Return recs
Dim idDescobro = Me.enumeraciones.First(Function(x) x.Codigo = "CABA.DES").idEnumeracion
' Dim idTipLiqDes = Me.enumeraciones.First(Function(x) x.Codigo = "TIPLIQAG.RETCOM").idEnumeracion
Dim idTipLiq = Me.enumeraciones.First(Function(x) x.Codigo = "TIPLIQAG.LIQUIDACION").idEnumeracion
Dim FechaInicio As New Date(2020, 11, 2)
Dim recs = (From rg In Me.regularizacionespagosagentes Where rg.idLiquidacionAgente.HasValue = False And rg.agentes.FechaBaja.HasValue = False Join re In Me.vf_recibosextendidos On re.idRecibo Equals rg.idRecibo Select New With {.Recibo = re, .Regularizacion = rg}).AsNoTracking.ToList
Dim lr As New List(Of vf_recibosextendidos)
For Each rg In recs
' If rg.Regularizacion.idRegularizacion = 162 Or rg.Regularizacion.idRegularizacion = 165 Then Debug.WriteLine("aqui")
Dim r = rg.Recibo
If r.idAgente <> rg.Regularizacion.idAgente Then
r.idAgente = rg.Regularizacion.idAgente
r.CodigoAgente = rg.Regularizacion.agentes.Codigo
r.Agente = rg.Regularizacion.agentes.Nombre
End If
r.EsRetornoComision_TMP = True
r.idRegularizacion_TMP = rg.Regularizacion.idRegularizacion
r.ComisionAgente = rg.Regularizacion.Importe
lr.Add(r)
Next
Return lr
End Function
Public Function ObtieneRecibosPendientesLiquidacionAgentes() As List(Of vf_recibosextendidos)
Dim idCabaPGO = Me.enumeraciones.First(Function(x) x.Codigo = "CABA.PGO").idEnumeracion
Dim idTippCIA = Me.enumeraciones.First(Function(x) x.Codigo = "TIPP.CIA").idEnumeracion
Dim idTippFAE = Me.enumeraciones.First(Function(x) x.Codigo = "TIPP.FAE").idEnumeracion
Dim idTippCO = Me.enumeraciones.First(Function(x) x.Codigo = "TIPP.CO").idEnumeracion
Dim idTippCTR = Me.enumeraciones.First(Function(x) x.Codigo = "TIPP.CTR").idEnumeracion
Dim idagente1 = Me.agentes.First(Function(x) x.Codigo = "1").idAgente
Dim idagente2 = Me.agentes.First(Function(x) x.Codigo = "2").idAgente
Dim Fhoy As Date = Today
' Dim rs1 = (From r In recibos.Where(Function(x) x.liquidacionesagenterecibos.Any = False And (x.liquidacionescompaniasrecibos.Any(Function(y) y.liquidacionescompanias.Fecha <= Fhoy) Or x.idTipoPago = idTippCIA) And (x.FechaPago.HasValue Or x.idCausaBaja = idCabaPGO) And x.idAgente <> idagente1 And x.idAgente <> idagente2 And x.agentes.FechaBaja.HasValue = False And x.agentes.IBAN <> "" And x.agentes.Email <> "" And x.PrimaNeta.Value <> 0 And x.ComisionAgente.Value <> 0) Join v_r In Me.vf_recibosextendidos On v_r.idRecibo Equals r.idRecibo Select v_r).ToList
Dim rs1 = (From r In recibos.Where(Function(x) x.liquidacionesagenterecibos.Where(Function(y) y.liquidacionesagentes.idAgente.HasValue = False OrElse y.liquidacionesagentes.idAgente.Value = y.recibos.idAgente).Any = False _
AndAlso (x.liquidacionescompaniasrecibos.Any(Function(y) y.liquidacionescompanias.Fecha <= Fhoy) OrElse x.idTipoPago = idTippCIA OrElse x.idTipoPago = idTippFAE OrElse x.idTipoPago = idTippCO OrElse x.idTipoPago = idTippCTR) _
AndAlso (x.FechaPago.HasValue OrElse x.idCausaBaja = idCabaPGO) _
AndAlso x.idAgente <> idagente1 AndAlso x.idAgente <> idagente2 _
AndAlso x.agentes.FechaBaja.HasValue = False AndAlso x.agentes.IBAN <> "" _
AndAlso x.agentes.Email <> "" _
AndAlso x.PrimaNeta.Value <> 0 _
AndAlso x.ComisionAgente.Value <> 0)
Join v_r In Me.vf_recibosextendidos On v_r.idRecibo Equals r.idRecibo Select v_r).AsNoTracking.ToList
Dim rsp = Me.ObtieneRecibosPendientesDescobroAgentes
If rsp.Count <> rsp.Except(rs1).Count Then Throw New Exception("Existen regularizaciones de recibos aún no liquidados")
Dim rs2 = rs1.Union(rsp).ToList
Dim recsag = rs2.GroupBy(Function(x) x.CodigoAgente).OrderBy(Function(x) x.First.CodigoAgente).ToList
Dim agesneg = recsag.Where(Function(x) x.Sum(Function(y) y.ImporteALiquidarAgente) <= 0).Select(Function(x) x.First.idAgente).ToList
If agesneg.Count > 0 Then
rs2 = rs2.Where(Function(x) agesneg.Contains(x.idAgente) = False).ToList
End If
Return rs2
End Function
Public Function ObtieneComisionesPendientesLiquidacionAgentesAgrario() As List(Of historicocomisiones)
'Dim idCabaPGO = Me.enumeraciones.First(Function(x) x.Codigo = "CABA.PGO").idEnumeracion
'Dim idagente1 = Me.agentes.First(Function(x) x.Codigo = "1").idAgente
'Dim idagente2 = Me.agentes.First(Function(x) x.Codigo = "2").idAgente
'Dim Fhoy As Date = Today
'Dim rs1 = (From r In (Me.recibos.Where(Function(x) x.liquidacionesagenterecibos.Any = False And x.liquidacionescompaniasrecibos.Any(Function(y) y.liquidacionescompanias.Fecha <= Fhoy) And (x.FechaPago.HasValue Or x.idCausaBaja = idCabaPGO) And x.idAgente <> idagente1 And x.idAgente <> idagente2 And x.agentes.FechaBaja.HasValue = False And x.agentes.IBAN <> "" And x.agentes.Email <> "" And x.PrimaNeta.Value <> 0 And x.ComisionAgente.Value <> 0)) Join v_r In Me.vf_recibosextendidos On v_r.idRecibo Equals r.idRecibo Select v_r).ToList
'Dim rs2 = rs1.Union(Me.ObtieneRecibosPendientesDescobroAgentes).ToList
'Dim recsag = rs2.GroupBy(Function(x) x.CodigoAgente).OrderBy(Function(x) x.First.CodigoAgente).ToList
'Dim agesneg = recsag.Where(Function(x) x.Sum(Function(y) y.ImporteALiquidarAgente) <= 0).Select(Function(x) x.First.idAgente).ToList
'If agesneg.Count > 0 Then
' rs2 = rs2.Where(Function(x) agesneg.Contains(x.idAgente) = False).ToList
'End If
Return Me.historicocomisiones.Where(Function(x) Not x.fechaLiquidacion.HasValue And x.agentes.Codigo.Trim <> "1" And x.agentes.Codigo.Trim <> "2" And x.agentes.IBAN <> "" And x.agentes.Email <> "" And Not x.agentes.FechaBaja.HasValue).ToList
End Function
Public Function EjemacHP(ByVal Macro As String, Optional ByVal Parametros As String = "") As String
Try
Dim sUrlEjemac As String = (From c In Me.enumeraciones Where c.Codigo = "CONF.CGIEJEMAC").First.ValorAlfabetico1
If IO.Directory.Exists("C:\tecnosis.tfs") Then
sUrlEjemac = "http://sevilla.asegasa.com:10080/cgi-bin/ejemac"
End If
If Parametros <> "" Then
Parametros = Parametros.Replace("¡", "?")
sUrlEjemac &= "?" & Macro & "=" & Web.HttpUtility.UrlEncode(Parametros)
Else
sUrlEjemac &= "?" & Macro
End If
Dim sRespuesta As String = tsl5.http.EjecutaURL(sUrlEjemac, , 500000)
If sRespuesta.Contains("#NO ENCONTRADO#") Then
Return sRespuesta
Else
Return tsl5.Ficheros.CleanInvalidXmlChars(sRespuesta)
End If
Catch EX As Exception
Throw New Exception(EX.Message, EX)
End Try
End Function
Public Function Obtiene_ve_amortizacionrecibos() As IQueryable(Of ve_amortizacionrecibos)
' Dim Mesactual = Today.Year * 100 + Today.Month
Dim ve = (From x In Me.amortizacionrecibos Join r In Me.vf_recibosextendidos On r.idRecibo Equals x.idRecibo Select New ve_amortizacionrecibos With
{
.idAmortizacion = x.idAmortizacion,
.idRecibo = x.idRecibo,
.FechaInicioAmortizacion = x.FechaInicioAmortizacion,
.FechaFinAmortizacion = x.FechaFinAmortizacion,
.PorcentajeAnual = x.PorcentajeAnual,
.FechaBaja = x.FechaBaja,
.idMotivoBaja = x.idMotivoBaja,
.idEmpresa = x.idEmpresa,
.NumeroCuenta = x.NumeroCuenta,
.Observaciones = x.Observaciones,
.FechaAlta = x.FechaAlta,
.Ramo = r.Ramo,
.CausaBaja = x.enumeraciones.Descripcion,
.Empresa = x.enumeraciones1.Descripcion,
.Compañía = r.Compania,
.Tomador = r.Tomador,
.CodigoRecibo = r.CodigoRecibo,
.CIFTomador = r.CIFTomador,
.TotalRecibo = r.TotalRecibo.Value}
)
Return ve
End Function
Public Function Obtiene_ve_detallesamortizacionrecibos(fechaInicio As Date, FechaFin As Date) As IQueryable(Of ve_detallesamortizacionrecibos)
Dim MesInicio = fechaInicio.Year * 100 + fechaInicio.Month
Dim Mesfin = FechaFin.Year * 100 + FechaFin.Month
Dim ve = From da In Me.detallesamortizacionrecibos Where da.Mes >= MesInicio And da.Mes <= Mesfin Join x In Me.amortizacionrecibos On x.idAmortizacion Equals da.idAmortizacion Join r In Me.vf_recibosextendidos On r.idRecibo Equals x.idRecibo Select New ve_detallesamortizacionrecibos With
{
.idDetalle = da.idDetalle,
.idAmortizacion = x.idAmortizacion,
.idRecibo = x.idRecibo,
.ValorAmortizado = da.ValorAmortizado,
.ValorAcumulado = da.ValorAcumulado,
.ValorResidual = da.ValorResidual,
.Mes = da.Mes,
.FechaAplicacion = da.FechaAplicacion,
.FechaInicioAmortizacion = x.FechaInicioAmortizacion,
.FechaFinAmortizacion = x.FechaFinAmortizacion,
.PorcentajeAnual = x.PorcentajeAnual,
.FechaBaja = x.FechaBaja,
.idMotivoBaja = x.idMotivoBaja,
.idEmpresa = x.idEmpresa,
.NumeroCuenta = x.NumeroCuenta,
.Observaciones = x.Observaciones,
.FechaAlta = x.FechaAlta,
.Ramo = r.Ramo,
.CausaBaja = x.enumeraciones.Descripcion,
.Empresa = x.enumeraciones1.Descripcion,
.Compañía = r.Compania,
.Tomador = r.Tomador,
.CodigoRecibo = r.CodigoRecibo,
.FechaEfecto = r.FechaEfecto,
.CIFTomador = r.CIFTomador,
.TotalRecibo = r.TotalRecibo.Value}
Return ve
End Function
Public Function Obtiene_ve_entidades() As IQueryable(Of ve_entidades)
Dim ents = Me.entidades.Select(Function(x) New bdGestionAsegasa.ve_entidades With {
.idEntidad = x.idEntidad,
.CIF = x.CIF,
.Direccion = If(x.idDireccionPrincipal.HasValue, x.direcciones1.Direccion, ""),
.Poblacion = If(x.idDireccionPrincipal.HasValue AndAlso x.direcciones1.CodigoMunicipio <> "", x.direcciones1.municipios.Nombre, ""),
.Provincia = If(x.idDireccionPrincipal.HasValue AndAlso x.direcciones1.CodigoMunicipio <> "", x.direcciones1.municipios.provincias.Nombre, ""),
.email = x.Email,
.RazonSocial = x.RazonSocial,
.FechaNacimiento = x.FechaNacimiento,
.Telefono1 = x.Telefono1,
.EsClienteSA = x.EsClienteSA,
.EsClienteSG = x.EsClienteSG,
.EsContrarioSiniestro = x.EsContrarioSiniestro,
.EsTaller = x.EsTaller})
Return ents
End Function
'Public Function Obtiene_ve_cuentas(idEjercicio As Integer, Nivel As Integer) As List(Of ve_cuentas)
' Dim lc As New List(Of ve_cuentas)
' Dim ctas1 = Me.Obtiene_ve_cuentas(Me.apuntes.Where(Function(x) x.asientos.idEjercicio = idEjercicio))
' Dim ctas = Me.cuentas.Where(Function(x) x.idEjercicio = idEjercicio).ToList
' Dim vec As ve_cuentas
' For Each cta In ctas.Where(Function(x) x.Nivel = Nivel).ToList
' If cta.EsCuentaFinal Then
' vec = ctas1.FirstOrDefault(Function(x) x.NumeroCuenta = cta.NumeroCuenta)
' If vec Is Nothing Then
' vec = New ve_cuentas
' With vec
' .idCuenta = cta.idCuenta
' .NumeroCuenta = cta.NumeroCuenta
' .idEjercicio = cta.idEjercicio
' .idEmpresaAmortizacion = cta.idEmpresaAmortizacion
' .EsCuentaFinal = cta.EsCuentaFinal
' End With
' End If
' Else
' vec = New ve_cuentas
' With vec
' .idCuenta = cta.idCuenta
' .DebeEnero = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeEnero), 2, MidpointRounding.AwayFromZero)
' .DebeFebrero = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeFebrero), 2, MidpointRounding.AwayFromZero)
' .DebeMarzo = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeMarzo), 2, MidpointRounding.AwayFromZero)
' .DebeAbril = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeAbril), 2, MidpointRounding.AwayFromZero)
' .DebeMayo = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeMayo), 2, MidpointRounding.AwayFromZero)
' .DebeJunio = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeJunio), 2, MidpointRounding.AwayFromZero)
' .DebeJulio = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeJulio), 2, MidpointRounding.AwayFromZero)
' .DebeAgosto = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeAgosto), 2, MidpointRounding.AwayFromZero)
' .DebeSeptiembre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeSeptiembre), 2, MidpointRounding.AwayFromZero)
' .DebeOctubre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeOctubre), 2, MidpointRounding.AwayFromZero)
' .DebeNoviembre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeNoviembre), 2, MidpointRounding.AwayFromZero)
' .DebeDiciembre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.DebeDiciembre), 2, MidpointRounding.AwayFromZero)
' .HaberEnero = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberEnero), 2, MidpointRounding.AwayFromZero)
' .HaberFebrero = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberFebrero), 2, MidpointRounding.AwayFromZero)
' .HaberMarzo = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberMarzo), 2, MidpointRounding.AwayFromZero)
' .HaberAbril = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberAbril), 2, MidpointRounding.AwayFromZero)
' .HaberMayo = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberMayo), 2, MidpointRounding.AwayFromZero)
' .HaberJunio = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberJunio), 2, MidpointRounding.AwayFromZero)
' .HaberJulio = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberJulio), 2, MidpointRounding.AwayFromZero)
' .HaberAgosto = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberAgosto), 2, MidpointRounding.AwayFromZero)
' .HaberSeptiembre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberSeptiembre), 2, MidpointRounding.AwayFromZero)
' .HaberOctubre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberOctubre), 2, MidpointRounding.AwayFromZero)
' .HaberNoviembre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberNoviembre), 2, MidpointRounding.AwayFromZero)
' .HaberDiciembre = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.HaberDiciembre), 2, MidpointRounding.AwayFromZero)
' .TotalDebe = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.TotalDebe), 2, MidpointRounding.AwayFromZero)
' .TotalHaber = Math.Round(ctas1.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta)).Sum(Function(Y) Y.TotalHaber), 2, MidpointRounding.AwayFromZero)
' .Denominacion = cta.Denominacion
' .PresupuestoEnero = cta.PresupuestoEnero
' .PresupuestoFebrero = cta.PresupuestoFebrero
' .PresupuestoMarzo = cta.PresupuestoMarzo
' .PresupuestoAbril = cta.PresupuestoAbril
' .PresupuestoMayo = cta.PresupuestoMayo
' .PresupuestoJunio = cta.PresupuestoJunio
' .PresupuestoJulio = cta.PresupuestoJulio
' .PresupuestoAgosto = cta.PresupuestoAgosto
' .PresupuestoSeptiembre = cta.PresupuestoSeptiembre
' .PresupuestoOctubre = cta.PresupuestoOctubre
' .PresupuestoNoviembre = cta.PresupuestoNoviembre
' .PresupuestoDiciembre = cta.PresupuestoDiciembre
' .Observaciones = cta.Observaciones
' .NumeroCuenta = cta.NumeroCuenta
' .idEjercicio = cta.idEjercicio
' .idEmpresaAmortizacion = cta.idEmpresaAmortizacion
' .EsCuentaFinal = cta.EsCuentaFinal
' End With
' End If
' With vec
' Dim cta1 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 1))
' .Grupo1 = cta1.NumeroCuenta & " " & cta1.Denominacion
' If cta.Nivel > 1 Then
' Dim cta2 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 2))
' .Grupo2 = cta2.NumeroCuenta & " " & cta2.Denominacion
' If cta.Nivel > 2 Then
' Dim cta3 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 3))
' .Grupo3 = cta3.NumeroCuenta & " " & cta3.Denominacion
' If cta.Nivel > 3 Then
' Dim cta4 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 4))
' .Grupo4 = cta4.NumeroCuenta & " " & cta4.Denominacion
' End If
' End If
' End If
' End With
' lc.Add(vec)
' Next
' Return lc
'End Function
'Public Function Obtiene_ve_cuentas(idEjercicio As Integer, Nivel As Integer) As List(Of ve_cuentas)
' Dim lc As New List(Of ve_cuentas)
' Dim aps = Me.apuntes.Where(Function(x) x.asientos.idEjercicio = idEjercicio).Select(Function(x) New With {.idCuenta = x.idCuenta, .NumeroCuenta = x.cuentas.NumeroCuenta, .Mes = x.asientos.Fecha.Month, .Debe = x.Debe, .Haber = x.Haber}).ToList
' Dim ctas = Me.cuentas.Where(Function(x) x.idEjercicio = idEjercicio).ToList
' For Each cta In ctas.Where(Function(x) x.Nivel = Nivel).ToList
' Dim vec As New ve_cuentas
' If cta.EsCuentaFinal Then
' With vec
' .idCuenta = cta.idCuenta
' .DebeEnero = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 1).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeFebrero = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 2).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeMarzo = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 3).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeAbril = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 4).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeMayo = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 5).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeJunio = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 6).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeJulio = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 7).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeAgosto = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 8).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeSeptiembre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 9).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeOctubre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 10).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeNoviembre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 11).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeDiciembre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 12).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .HaberEnero = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 1).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberFebrero = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 2).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberMarzo = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 3).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberAbril = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 4).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberMayo = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 5).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberJunio = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 6).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberJulio = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 7).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberAgosto = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 8).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberSeptiembre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 9).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberOctubre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 10).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberNoviembre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 11).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberDiciembre = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta And x.Mes = 12).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .TotalDebe = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .TotalHaber = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .Denominacion = cta.Denominacion
' .PresupuestoEnero = cta.PresupuestoEnero
' .PresupuestoFebrero = cta.PresupuestoFebrero
' .PresupuestoMarzo = cta.PresupuestoMarzo
' .PresupuestoAbril = cta.PresupuestoAbril
' .PresupuestoMayo = cta.PresupuestoMayo
' .PresupuestoJunio = cta.PresupuestoJunio
' .PresupuestoJulio = cta.PresupuestoJulio
' .PresupuestoAgosto = cta.PresupuestoAgosto
' .PresupuestoSeptiembre = cta.PresupuestoSeptiembre
' .PresupuestoOctubre = cta.PresupuestoOctubre
' .PresupuestoNoviembre = cta.PresupuestoNoviembre
' .PresupuestoDiciembre = cta.PresupuestoDiciembre
' .Observaciones = cta.Observaciones
' .NumeroCuenta = cta.NumeroCuenta
' .idEjercicio = cta.idEjercicio
' .idEmpresaAmortizacion = cta.idEmpresaAmortizacion
' .EsCuentaFinal = cta.EsCuentaFinal
' 'Dim cta1 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 1))
' 'Dim cta2 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 2))
' 'Dim cta3 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 3))
' 'Dim cta4 = ctas.First(Function(x) x.NumeroCuenta = cta.NumeroCuenta.Substring(0, 4))
' '.Grupo1 = cta1.NumeroCuenta & " " & cta1.Denominacion
' '.Grupo2 = cta2.NumeroCuenta & " " & cta2.Denominacion
' '.Grupo3 = cta3.NumeroCuenta & " " & cta3.Denominacion
' '.Grupo4 = cta4.NumeroCuenta & " " & cta4.Denominacion
' End With
' Else
' With vec
' .idCuenta = cta.idCuenta
' .DebeEnero = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 1).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeFebrero = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 2).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeMarzo = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 3).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeAbril = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 4).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeMayo = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 5).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeJunio = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 6).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeJulio = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 7).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeAgosto = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 8).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeSeptiembre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 9).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeOctubre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 10).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeNoviembre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 11).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .DebeDiciembre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 12).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .HaberEnero = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 1).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberFebrero = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 2).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberMarzo = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 3).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberAbril = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 4).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberMayo = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 5).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberJunio = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 6).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberJulio = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 7).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberAgosto = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 8).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberSeptiembre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 9).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberOctubre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 10).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberNoviembre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 11).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .HaberDiciembre = Math.Round(aps.Where(Function(x) x.NumeroCuenta.StartsWith(cta.NumeroCuenta) And x.Mes = 12).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .TotalDebe = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta).Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .TotalHaber = Math.Round(aps.Where(Function(x) x.idCuenta = cta.idCuenta).Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .Denominacion = cta.Denominacion
' .PresupuestoEnero = cta.PresupuestoEnero
' .PresupuestoFebrero = cta.PresupuestoFebrero
' .PresupuestoMarzo = cta.PresupuestoMarzo
' .PresupuestoAbril = cta.PresupuestoAbril
' .PresupuestoMayo = cta.PresupuestoMayo
' .PresupuestoJunio = cta.PresupuestoJunio
' .PresupuestoJulio = cta.PresupuestoJulio
' .PresupuestoAgosto = cta.PresupuestoAgosto
' .PresupuestoSeptiembre = cta.PresupuestoSeptiembre
' .PresupuestoOctubre = cta.PresupuestoOctubre
' .PresupuestoNoviembre = cta.PresupuestoNoviembre
' .PresupuestoDiciembre = cta.PresupuestoDiciembre
' .Observaciones = cta.Observaciones
' .NumeroCuenta = cta.NumeroCuenta
' .idEjercicio = cta.idEjercicio
' .idEmpresaAmortizacion = cta.idEmpresaAmortizacion
' .EsCuentaFinal = cta.EsCuentaFinal
' End With
' End If
' lc.Add(vec)
' Next
' Return lc
'End Function
'Public Function Obtiene_ve_cuentas(Apuntes As IQueryable(Of apuntes)) As List(Of ve_cuentas)
' Dim ctas = Me.apuntes.Select(Function(x) New With {.idCuenta = x.idCuenta,
' .Denominacion = x.cuentas.Denominacion,
' .PresupuestoEnero = x.cuentas.PresupuestoEnero,
' .PresupuestoFebrero = x.cuentas.PresupuestoFebrero,
' .PresupuestoMarzo = x.cuentas.PresupuestoMarzo,
' .PresupuestoAbril = x.cuentas.PresupuestoAbril,
' .PresupuestoMayo = x.cuentas.PresupuestoMayo,
' .PresupuestoJunio = x.cuentas.PresupuestoJunio,
' .PresupuestoJulio = x.cuentas.PresupuestoJulio,
' .PresupuestoAgosto = x.cuentas.PresupuestoAgosto,
' .PresupuestoSeptiembre = x.cuentas.PresupuestoSeptiembre,
' .PresupuestoOctubre = x.cuentas.PresupuestoOctubre,
' .PresupuestoNoviembre = x.cuentas.PresupuestoNoviembre,
' .PresupuestoDiciembre = x.cuentas.PresupuestoDiciembre,
' .Observaciones = x.cuentas.Observaciones,
' .NumeroCuenta = x.cuentas.NumeroCuenta,
' .idEjercicio = x.cuentas.idEjercicio,
' .idEmpresaAmortizacion = x.cuentas.idEmpresaAmortizacion,
' .EsCuentaFinal = x.cuentas.EsCuentaFinal,
' .Debe = x.Debe,
' .Haber = x.Haber,
' .DebeEnero = If(x.asientos.Fecha.Month = 1, x.Debe, 0),
' .DebeFebrero = If(x.asientos.Fecha.Month = 2, x.Debe, 0),
' .DebeMarzo = If(x.asientos.Fecha.Month = 3, x.Debe, 0),
' .DebeAbril = If(x.asientos.Fecha.Month = 4, x.Debe, 0),
' .DebeMayo = If(x.asientos.Fecha.Month = 5, x.Debe, 0),
' .DebeJunio = If(x.asientos.Fecha.Month = 6, x.Debe, 0),
' .DebeJulio = If(x.asientos.Fecha.Month = 7, x.Debe, 0),
' .DebeAgosto = If(x.asientos.Fecha.Month = 8, x.Debe, 0),
' .DebeSeptiembre = If(x.asientos.Fecha.Month = 9, x.Debe, 0),
' .DebeOctubre = If(x.asientos.Fecha.Month = 10, x.Debe, 0),
' .DebeNoviembre = If(x.asientos.Fecha.Month = 11, x.Debe, 0),
' .DebeDiciembre = If(x.asientos.Fecha.Month = 12, x.Debe, 0),
' .HaberEnero = If(x.asientos.Fecha.Month = 1, x.Haber, 0),
' .HaberFebrero = If(x.asientos.Fecha.Month = 2, x.Haber, 0),
' .HaberMarzo = If(x.asientos.Fecha.Month = 3, x.Haber, 0),
' .HaberAbril = If(x.asientos.Fecha.Month = 4, x.Haber, 0),
' .HaberMayo = If(x.asientos.Fecha.Month = 5, x.Haber, 0),
' .HaberJunio = If(x.asientos.Fecha.Month = 6, x.Haber, 0),
' .HaberJulio = If(x.asientos.Fecha.Month = 7, x.Haber, 0),
' .HaberAgosto = If(x.asientos.Fecha.Month = 8, x.Haber, 0),
' .HaberSeptiembre = If(x.asientos.Fecha.Month = 9, x.Haber, 0),
' .HaberOctubre = If(x.asientos.Fecha.Month = 10, x.Haber, 0),
' .HaberNoviembre = If(x.asientos.Fecha.Month = 11, x.Haber, 0),
' .HaberDiciembre = If(x.asientos.Fecha.Month = 12, x.Haber, 0)
' }).GroupBy(Function(x) x.idCuenta).ToList.Select(Function(x) New ve_cuentas With {
' .idCuenta = x.First.idCuenta,
' .DebeEnero = Math.Round(x.Sum(Function(Y) Y.DebeEnero), 2, MidpointRounding.AwayFromZero),
' .DebeFebrero = Math.Round(x.Sum(Function(Y) Y.DebeFebrero), 2, MidpointRounding.AwayFromZero),
' .DebeMarzo = Math.Round(x.Sum(Function(Y) Y.DebeMarzo), 2, MidpointRounding.AwayFromZero),
' .DebeAbril = Math.Round(x.Sum(Function(Y) Y.DebeAbril), 2, MidpointRounding.AwayFromZero),
' .DebeMayo = Math.Round(x.Sum(Function(Y) Y.DebeMayo), 2, MidpointRounding.AwayFromZero),
' .DebeJunio = Math.Round(x.Sum(Function(Y) Y.DebeJunio), 2, MidpointRounding.AwayFromZero),
' .DebeJulio = Math.Round(x.Sum(Function(Y) Y.DebeJulio), 2, MidpointRounding.AwayFromZero),
' .DebeAgosto = Math.Round(x.Sum(Function(Y) Y.DebeAgosto), 2, MidpointRounding.AwayFromZero),
' .DebeSeptiembre = Math.Round(x.Sum(Function(Y) Y.DebeSeptiembre), 2, MidpointRounding.AwayFromZero),
' .DebeOctubre = Math.Round(x.Sum(Function(Y) Y.DebeOctubre), 2, MidpointRounding.AwayFromZero),
' .DebeNoviembre = Math.Round(x.Sum(Function(Y) Y.DebeNoviembre), 2, MidpointRounding.AwayFromZero),
' .DebeDiciembre = Math.Round(x.Sum(Function(Y) Y.DebeDiciembre), 2, MidpointRounding.AwayFromZero),
' .HaberEnero = Math.Round(x.Sum(Function(Y) Y.HaberEnero), 2, MidpointRounding.AwayFromZero),
' .HaberFebrero = Math.Round(x.Sum(Function(Y) Y.HaberFebrero), 2, MidpointRounding.AwayFromZero),
' .HaberMarzo = Math.Round(x.Sum(Function(Y) Y.HaberMarzo), 2, MidpointRounding.AwayFromZero),
' .HaberAbril = Math.Round(x.Sum(Function(Y) Y.HaberAbril), 2, MidpointRounding.AwayFromZero),
' .HaberMayo = Math.Round(x.Sum(Function(Y) Y.HaberMayo), 2, MidpointRounding.AwayFromZero),
' .HaberJunio = Math.Round(x.Sum(Function(Y) Y.HaberJunio), 2, MidpointRounding.AwayFromZero),
' .HaberJulio = Math.Round(x.Sum(Function(Y) Y.HaberJulio), 2, MidpointRounding.AwayFromZero),
' .HaberAgosto = Math.Round(x.Sum(Function(Y) Y.HaberAgosto), 2, MidpointRounding.AwayFromZero),
' .HaberSeptiembre = Math.Round(x.Sum(Function(Y) Y.HaberSeptiembre), 2, MidpointRounding.AwayFromZero),
' .HaberOctubre = Math.Round(x.Sum(Function(Y) Y.HaberOctubre), 2, MidpointRounding.AwayFromZero),
' .HaberNoviembre = Math.Round(x.Sum(Function(Y) Y.HaberNoviembre), 2, MidpointRounding.AwayFromZero),
' .HaberDiciembre = Math.Round(x.Sum(Function(Y) Y.HaberDiciembre), 2, MidpointRounding.AwayFromZero),
' .TotalDebe = Math.Round(x.Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero),
' .TotalHaber = Math.Round(x.Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero),
' .Denominacion = x.First.Denominacion,
' .PresupuestoEnero = x.First.PresupuestoEnero,
' .PresupuestoFebrero = x.First.PresupuestoFebrero,
' .PresupuestoMarzo = x.First.PresupuestoMarzo,
' .PresupuestoAbril = x.First.PresupuestoAbril,
' .PresupuestoMayo = x.First.PresupuestoMayo,
' .PresupuestoJunio = x.First.PresupuestoJunio,
' .PresupuestoJulio = x.First.PresupuestoJulio,
' .PresupuestoAgosto = x.First.PresupuestoAgosto,
' .PresupuestoSeptiembre = x.First.PresupuestoSeptiembre,
' .PresupuestoOctubre = x.First.PresupuestoOctubre,
' .PresupuestoNoviembre = x.First.PresupuestoNoviembre,
' .PresupuestoDiciembre = x.First.PresupuestoDiciembre,
' .Observaciones = x.First.Observaciones,
' .NumeroCuenta = x.First.NumeroCuenta,
' .idEjercicio = x.First.idEjercicio,
' .idEmpresaAmortizacion = x.First.idEmpresaAmortizacion,
' .EsCuentaFinal = x.First.EsCuentaFinal}).ToList
' Return ctas
'End Function
'Public Function Obtiene_ve_cuentas(cuenta As cuentas) As ve_cuentas
' If cuenta.EsCuentaFinal Then
' Return Obtiene_ve_cuentas(Me.apuntes.Where(Function(x) x.idCuenta = cuenta.idCuenta)).First
' Else
' Dim apuntes = Me.apuntes.Where(Function(x) x.asientos.idEjercicio = cuenta.idEjercicio And x.cuentas.NumeroCuenta.StartsWith(cuenta.NumeroCuenta)).Select(Function(x) New With {.idCuenta = x.idCuenta,
' .DebeEnero = If(x.asientos.Fecha.Month = 1, x.Debe, 0),
' .DebeFebrero = If(x.asientos.Fecha.Month = 2, x.Debe, 0),
' .DebeMarzo = If(x.asientos.Fecha.Month = 3, x.Debe, 0),
' .DebeAbril = If(x.asientos.Fecha.Month = 4, x.Debe, 0),
' .DebeMayo = If(x.asientos.Fecha.Month = 5, x.Debe, 0),
' .DebeJunio = If(x.asientos.Fecha.Month = 6, x.Debe, 0),
' .DebeJulio = If(x.asientos.Fecha.Month = 7, x.Debe, 0),
' .DebeAgosto = If(x.asientos.Fecha.Month = 8, x.Debe, 0),
' .DebeSeptiembre = If(x.asientos.Fecha.Month = 9, x.Debe, 0),
' .DebeOctubre = If(x.asientos.Fecha.Month = 10, x.Debe, 0),
' .DebeNoviembre = If(x.asientos.Fecha.Month = 11, x.Debe, 0),
' .DebeDiciembre = If(x.asientos.Fecha.Month = 12, x.Debe, 0),
' .HaberEnero = If(x.asientos.Fecha.Month = 1, x.Haber, 0),
' .HaberFebrero = If(x.asientos.Fecha.Month = 2, x.Haber, 0),
' .HaberMarzo = If(x.asientos.Fecha.Month = 3, x.Haber, 0),
' .HaberAbril = If(x.asientos.Fecha.Month = 4, x.Haber, 0),
' .HaberMayo = If(x.asientos.Fecha.Month = 5, x.Haber, 0),
' .HaberJunio = If(x.asientos.Fecha.Month = 6, x.Haber, 0),
' .HaberJulio = If(x.asientos.Fecha.Month = 7, x.Haber, 0),
' .HaberAgosto = If(x.asientos.Fecha.Month = 8, x.Haber, 0),
' .HaberSeptiembre = If(x.asientos.Fecha.Month = 9, x.Haber, 0),
' .HaberOctubre = If(x.asientos.Fecha.Month = 10, x.Haber, 0),
' .HaberNoviembre = If(x.asientos.Fecha.Month = 11, x.Haber, 0),
' .HaberDiciembre = If(x.asientos.Fecha.Month = 12, x.Haber, 0),
' .Debe = x.Debe,
' .Haber = x.Haber})
' Dim vec As New ve_cuentas
' With vec
' .idCuenta = cuenta.idCuenta
' .DebeEnero = Math.Round(apuntes.Sum(Function(Y) Y.DebeEnero), 2, MidpointRounding.AwayFromZero)
' .DebeFebrero = Math.Round(apuntes.Sum(Function(Y) Y.DebeFebrero), 2, MidpointRounding.AwayFromZero)
' .DebeMarzo = Math.Round(apuntes.Sum(Function(Y) Y.DebeMarzo), 2, MidpointRounding.AwayFromZero)
' .DebeAbril = Math.Round(apuntes.Sum(Function(Y) Y.DebeAbril), 2, MidpointRounding.AwayFromZero)
' .DebeMayo = Math.Round(apuntes.Sum(Function(Y) Y.DebeMayo), 2, MidpointRounding.AwayFromZero)
' .DebeJunio = Math.Round(apuntes.Sum(Function(Y) Y.DebeJunio), 2, MidpointRounding.AwayFromZero)
' .DebeJulio = Math.Round(apuntes.Sum(Function(Y) Y.DebeJulio), 2, MidpointRounding.AwayFromZero)
' .DebeAgosto = Math.Round(apuntes.Sum(Function(Y) Y.DebeAgosto), 2, MidpointRounding.AwayFromZero)
' .DebeSeptiembre = Math.Round(apuntes.Sum(Function(Y) Y.DebeSeptiembre), 2, MidpointRounding.AwayFromZero)
' .DebeOctubre = Math.Round(apuntes.Sum(Function(Y) Y.DebeOctubre), 2, MidpointRounding.AwayFromZero)
' .DebeNoviembre = Math.Round(apuntes.Sum(Function(Y) Y.DebeNoviembre), 2, MidpointRounding.AwayFromZero)
' .DebeDiciembre = Math.Round(apuntes.Sum(Function(Y) Y.DebeDiciembre), 2, MidpointRounding.AwayFromZero)
' .HaberEnero = Math.Round(apuntes.Sum(Function(Y) Y.HaberEnero), 2, MidpointRounding.AwayFromZero)
' .HaberFebrero = Math.Round(apuntes.Sum(Function(Y) Y.HaberFebrero), 2, MidpointRounding.AwayFromZero)
' .HaberMarzo = Math.Round(apuntes.Sum(Function(Y) Y.HaberMarzo), 2, MidpointRounding.AwayFromZero)
' .HaberAbril = Math.Round(apuntes.Sum(Function(Y) Y.HaberAbril), 2, MidpointRounding.AwayFromZero)
' .HaberMayo = Math.Round(apuntes.Sum(Function(Y) Y.HaberMayo), 2, MidpointRounding.AwayFromZero)
' .HaberJunio = Math.Round(apuntes.Sum(Function(Y) Y.HaberJunio), 2, MidpointRounding.AwayFromZero)
' .HaberJulio = Math.Round(apuntes.Sum(Function(Y) Y.HaberJulio), 2, MidpointRounding.AwayFromZero)
' .HaberAgosto = Math.Round(apuntes.Sum(Function(Y) Y.HaberAgosto), 2, MidpointRounding.AwayFromZero)
' .HaberSeptiembre = Math.Round(apuntes.Sum(Function(Y) Y.HaberSeptiembre), 2, MidpointRounding.AwayFromZero)
' .HaberOctubre = Math.Round(apuntes.Sum(Function(Y) Y.HaberOctubre), 2, MidpointRounding.AwayFromZero)
' .HaberNoviembre = Math.Round(apuntes.Sum(Function(Y) Y.HaberNoviembre), 2, MidpointRounding.AwayFromZero)
' .HaberDiciembre = Math.Round(apuntes.Sum(Function(Y) Y.HaberDiciembre), 2, MidpointRounding.AwayFromZero)
' .TotalDebe = Math.Round(apuntes.Sum(Function(Y) Y.Debe), 2, MidpointRounding.AwayFromZero)
' .TotalHaber = Math.Round(apuntes.Sum(Function(Y) Y.Haber), 2, MidpointRounding.AwayFromZero)
' .Denominacion = cuenta.Denominacion
' .PresupuestoEnero = cuenta.PresupuestoEnero
' .PresupuestoFebrero = cuenta.PresupuestoFebrero
' .PresupuestoMarzo = cuenta.PresupuestoMarzo
' .PresupuestoAbril = cuenta.PresupuestoAbril
' .PresupuestoMayo = cuenta.PresupuestoMayo
' .PresupuestoJunio = cuenta.PresupuestoJunio
' .PresupuestoJulio = cuenta.PresupuestoJulio
' .PresupuestoAgosto = cuenta.PresupuestoAgosto
' .PresupuestoSeptiembre = cuenta.PresupuestoSeptiembre
' .PresupuestoOctubre = cuenta.PresupuestoOctubre
' .PresupuestoNoviembre = cuenta.PresupuestoNoviembre
' .PresupuestoDiciembre = cuenta.PresupuestoDiciembre
' .Observaciones = cuenta.Observaciones
' .NumeroCuenta = cuenta.NumeroCuenta
' .idEjercicio = cuenta.idEjercicio
' .idEmpresaAmortizacion = cuenta.idEmpresaAmortizacion
' .EsCuentaFinal = cuenta.EsCuentaFinal
' End With
' Return vec
' End If
'End Function
Public Function Obtiene_ve_recibos(Recibos As IQueryable(Of recibos), Optional ExpresionBusqueda As String = "", Optional Parametros() As Object = Nothing) As List(Of ve_recibos)
Dim recs = From x In Recibos Join t In Me.v_tomadores On t.idPoliza Equals x.idPoliza
Group Join vlc In Me.v_liquidacion_cia On vlc.idrecibo Equals x.idRecibo Into glqc = Group From lqc In glqc.DefaultIfEmpty
Group Join vlcd In Me.v_liquidacion_cia_devuelto On vlcd.idrecibo Equals x.idRecibo Into glqcd = Group From lqcd In glqcd.DefaultIfEmpty
Group Join vla In Me.v_liquidacion_agente On vla.idrecibo Equals x.idRecibo Into glqa = Group From lqa In glqa.DefaultIfEmpty
Select New ve_recibos With {
.idRecibo = x.idRecibo,
.idPoliza = x.idPoliza,
.FechaFacturacion = x.FechaFacturacion,
.FechaPago = x.FechaPago,
.CodigoRecibo = x.CodigoRecibo,
.Tomador = t.RazonSocial,
.CIFTomador = t.CIF,
.Telefono1Tomador = t.Telefono1,
.Telefono2Tomador = t.Telefono2,
.NumeroPoliza = x.polizassg.NumeroPoliza,
.Matricula = x.polizassg.Matricula,
.FechaEfecto = x.FechaEfecto,
.FechaRecepcionCia = x.FechaRecepcionCia,
.FechaVencimiento = x.FechaVencimiento,
.FechaRemesa = If(x.idRemesa.HasValue, x.remesas.Fecha, Nothing),
.Compania = x.polizassg.companias.Nombre,
.Agente = x.agentes.Nombre,
.SubAgente = x.subagentes.Nombre,
.Ramo = x.polizassg.ramos.Descripcion,
.FechaExpedicion = x.FechaExpedicion,
.BienesAsegurados = x.polizassg.BienesAsegurados,
.FechaBaja = x.FechaBaja,
.FechaDevolucionBanco = x.FechaDevolucionBanco,
.CausaBaja = x.enumeraciones3.Descripcion,
.TipoRecibo = x.enumeraciones1.Descripcion,
.TipoPago = x.enumeraciones2.Descripcion,
.PrimaNeta = x.PrimaNeta,
.BonificacionORecargo = x.BonificacionORecargo,
.Consorcio = x.Consorcio,
.Impuesto = x.Impuesto,
.RecargoExterno = x.RecargoExterno,
.TotalRecibo = x.TotalRecibo,
.ComisionReciboPrimaNeta = x.ComisionReciboPrimaNeta,
.PorcentajeReciboPrimaNeta = x.PorcentajeReciboPrimaNeta,
.TotalComision = x.TotalComision,
.SobreComision = x.Sobrecomision,
.ComisionPrevista = x.ComisionPrevista,
.PorcentajeComisionAgente = x.PorcentajeComisionAgente,
.ComisionAgente = x.ComisionAgente,
.ComisionAsegasaPrimaNeta = x.ComisionAsegasaPrimaNeta,
.AsegasaRecargoExterno = x.AsegasaRecargoExterno,
.AsegasaComisionConsorcio = x.AsegasaComisionConsorcio,
.AsegasaComisionTotal = x.AsegasaComisionTotal,
.idSituacion = x.idSituacion,
.Observaciones = x.Observaciones,
.ObservacionesPoliza = x.polizassg.Observaciones,
.FechaLiquidacionCia = lqc.UltimaFecha,
.FechaLiquidacionCiaDevuelto = lqcd.UltimaFecha,
.FechaLiquidacionAgente = lqa.UltimaFecha
}
' Dim kk = recs.Where(Function(x) x.TotalRecibo = 192.66).ToList
If ExpresionBusqueda <> "" Then
recs = recs.Where(ExpresionBusqueda, Parametros)
End If
Return recs.ToList
End Function
Public Function Obtiene_ve_recibosNuevo(IncluirBajas As Boolean, FechaInicio As Date?, FechaFin As Date?, Optional TextoBusqueda As String = "") As List(Of ve_recibos)
Dim CamposBusquedaDobles() As String = {"TotalRecibo"}
Dim CamposBusquedaAlfabeticos() As String = {"Tomador", "NumeroPoliza", "Matricula", "CodigoRecibo", "CIFTomador"}
Dim parametros() As Object = Nothing
Dim BusquedaRapida As Boolean = False
TextoBusqueda = TextoBusqueda.Trim
If TextoBusqueda <> "" AndAlso TextoBusqueda.Contains(" ") = False Then
BusquedaRapida = True
End If
Dim rs As New List(Of vp_recibosextendidos)
Dim rlas As New List(Of vp_liquidacionesagentesrecibos)
Dim rlcs As New List(Of vp_liquidacionescompaniasrecibos)
Dim rlcds As New List(Of vp_liquidacionescompaniasrecibos_devueltos)
Do
If BusquedaRapida Then
If TextoBusqueda.Contains("/") Then
rs = Me.vp_recibosextendidos.Where(Function(x) x.CodigoRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
Else
rs = Me.vp_recibosextendidos.Where(Function(x) x.NumeroRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
End If
Else
Dim iqrs As IQueryable(Of vp_recibosextendidos)
If IncluirBajas Then
iqrs = Me.vp_recibosextendidos.AsQueryable
Else
Dim hoy = Now.Date
iqrs = Me.vp_recibosextendidos.Where(Function(x) x.FechaBaja Is Nothing And x.FechaVencimiento >= hoy)
End If
If FechaInicio.HasValue Then
iqrs = iqrs.Where(Function(x) x.FechaEfecto >= FechaInicio)
End If
If FechaFin.HasValue Then
iqrs = iqrs.Where(Function(x) x.FechaEfecto <= FechaFin)
End If
If TextoBusqueda <> "" Then
Dim ExpresionBusqueda = tsWPF.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Nothing, CamposBusquedaDobles, CamposBusquedaAlfabeticos, Nothing, parametros)
iqrs = iqrs.Where(ExpresionBusqueda, parametros)
End If
rs = iqrs.ToList
End If
If rs.Count = 0 AndAlso BusquedaRapida Then
BusquedaRapida = False
Else
Exit Do
End If
Loop
If rs.Count = 0 Then
Return New List(Of ve_recibos)
Else
If BusquedaRapida Then
If TextoBusqueda.Contains("/") Then
' rs = Me.vp_recibosextendidos.Where(Function(x) x.CodigoRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
rlas = Me.vp_liquidacionesagentesrecibos.Where(Function(x) x.CodigoRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
rlcs = Me.vp_liquidacionescompaniasrecibos.Where(Function(x) x.CodigoRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
rlcds = Me.vp_liquidacionescompaniasrecibos_devueltos.Where(Function(x) x.CodigoRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
Else
' rs = Me.vp_recibosextendidos.Where(Function(x) x.NumeroRecibo.Contains(TextoBusqueda) OrElse x.NumeroPoliza.Contains(TextoBusqueda) OrElse x.Tomador.Contains(TextoBusqueda) OrElse x.Matricula.Contains("Matricula") OrElse x.CIFTomador.Contains("CIFTomador")).ToList
rlas = Me.vp_liquidacionesagentesrecibos.Where(Function(x) x.NumeroRecibo = TextoBusqueda OrElse x.NumeroPoliza = TextoBusqueda OrElse x.CodigoRecibo = TextoBusqueda).ToList
rlcs = Me.vp_liquidacionescompaniasrecibos.Where(Function(x) x.NumeroRecibo = TextoBusqueda OrElse x.NumeroPoliza = TextoBusqueda OrElse x.CodigoRecibo = TextoBusqueda).ToList
rlcds = Me.vp_liquidacionescompaniasrecibos_devueltos.Where(Function(x) x.NumeroRecibo = TextoBusqueda OrElse x.NumeroPoliza = TextoBusqueda OrElse x.CodigoRecibo = TextoBusqueda).ToList
End If
Else
Dim iqrlas As IQueryable(Of vp_liquidacionesagentesrecibos)
If IncluirBajas Then
iqrlas = Me.vp_liquidacionesagentesrecibos.AsQueryable
Else
Dim hoy = Now.Date
iqrlas = Me.vp_liquidacionesagentesrecibos.Where(Function(x) x.FechaBaja Is Nothing And x.FechaVencimiento >= hoy)
End If
If FechaInicio.HasValue Then
iqrlas = iqrlas.Where(Function(x) x.FechaEfecto >= FechaInicio)
End If
If FechaFin.HasValue Then
iqrlas = iqrlas.Where(Function(x) x.FechaEfecto <= FechaFin)
End If
If TextoBusqueda <> "" Then
Dim ExpresionBusqueda = tsWPF.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Nothing, CamposBusquedaDobles, CamposBusquedaAlfabeticos, Nothing, parametros)
iqrlas = iqrlas.Where(ExpresionBusqueda, parametros)
End If
rlas = iqrlas.ToList
Dim iqrlcs As IQueryable(Of vp_liquidacionescompaniasrecibos)
If IncluirBajas Then
iqrlcs = Me.vp_liquidacionescompaniasrecibos.AsQueryable
Else
Dim hoy = Now.Date
iqrlcs = Me.vp_liquidacionescompaniasrecibos.Where(Function(x) x.FechaBaja Is Nothing And x.FechaVencimiento >= hoy)
End If
If FechaInicio.HasValue Then
iqrlcs = iqrlcs.Where(Function(x) x.FechaEfecto >= FechaInicio)
End If
If FechaFin.HasValue Then
iqrlcs = iqrlcs.Where(Function(x) x.FechaEfecto <= FechaFin)
End If
If TextoBusqueda <> "" Then
Dim ExpresionBusqueda = tsWPF.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Nothing, CamposBusquedaDobles, CamposBusquedaAlfabeticos, Nothing, parametros)
iqrlcs = iqrlcs.Where(ExpresionBusqueda, parametros)
End If
rlcs = iqrlcs.ToList
Dim iqrlcds As IQueryable(Of vp_liquidacionescompaniasrecibos_devueltos)
If IncluirBajas Then
iqrlcds = Me.vp_liquidacionescompaniasrecibos_devueltos.AsQueryable
Else
Dim hoy = Now.Date
iqrlcds = Me.vp_liquidacionescompaniasrecibos_devueltos.Where(Function(x) x.FechaBaja Is Nothing And x.FechaVencimiento >= hoy)
End If
If FechaInicio.HasValue Then
iqrlcds = iqrlcds.Where(Function(x) x.FechaEfecto >= FechaInicio)
End If
If FechaFin.HasValue Then
iqrlcds = iqrlcds.Where(Function(x) x.FechaEfecto <= FechaFin)
End If
If TextoBusqueda <> "" Then
Dim ExpresionBusqueda = tsWPF.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Nothing, CamposBusquedaDobles, CamposBusquedaAlfabeticos, Nothing, parametros)
iqrlcds = iqrlcds.Where(ExpresionBusqueda, parametros)
End If
rlcds = iqrlcds.ToList
End If
End If
Dim recs = From x In rs
Group Join vlc In rlcs On vlc.idRecibo Equals x.idRecibo Into glqc = Group From lqc In glqc.DefaultIfEmpty
Group Join vlcd In rlcds On vlcd.idRecibo Equals x.idRecibo Into glqcd = Group From lqcd In glqcd.DefaultIfEmpty
Group Join vla In rlas On vla.idRecibo Equals x.idRecibo Into glqa = Group From lqa In glqa.DefaultIfEmpty
Select New ve_recibos With {
.idRecibo = x.idRecibo,
.idPoliza = x.idPoliza,
.FechaFacturacion = x.FechaFacturacion,
.FechaPago = x.FechaPago,
.CodigoRecibo = x.CodigoRecibo,
.Tomador = x.Tomador,
.CIFTomador = x.CIFTomador,
.Telefono1Tomador = x.Telefono1Tomador,
.Telefono2Tomador = x.Telefono2Tomador,
.NumeroPoliza = x.NumeroPoliza,
.Matricula = x.Matricula,
.FechaEfecto = x.FechaEfecto,
.FechaRecepcionCia = x.FechaRecepcionCia,
.FechaVencimiento = x.FechaVencimiento,
.FechaRemesa = If(x.idRemesa.HasValue, x.FechaRemesa, Nothing),
.Compania = x.Compania,
.Agente = x.Agente,
.SubAgente = x.SubAgente,
.Ramo = x.Ramo,
.FechaExpedicion = x.FechaExpedicion,
.BienesAsegurados = x.BienesAsegurados,
.FechaBaja = x.FechaBaja,
.FechaDevolucionBanco = x.FechaDevolucionBanco,
.CausaBaja = x.CausaBaja,
.TipoRecibo = x.TipoRecibo,
.TipoPago = x.TipoPago,
.PrimaNeta = x.PrimaNeta,
.BonificacionORecargo = x.BonificacionORecargo,
.Consorcio = x.Consorcio,
.Impuesto = x.Impuesto,
.RecargoExterno = x.RecargoExterno,
.TotalRecibo = x.TotalRecibo,
.ComisionReciboPrimaNeta = x.ComisionReciboPrimaNeta,
.PorcentajeReciboPrimaNeta = x.PorcentajeReciboPrimaNeta,
.TotalComision = x.TotalComision,
.SobreComision = x.Sobrecomision,
.ComisionPrevista = x.ComisionPrevista,
.PorcentajeComisionAgente = x.PorcentajeComisionAgente,
.ComisionAgente = x.ComisionAgente,
.ComisionAsegasaPrimaNeta = x.ComisionAsegasaPrimaNeta,
.AsegasaRecargoExterno = x.AsegasaRecargoExterno,
.AsegasaComisionConsorcio = x.AsegasaComisionConsorcio,
.AsegasaComisionTotal = x.AsegasaComisionTotal,
.idSituacion = x.idSituacion,
.Observaciones = x.Observaciones,
.ObservacionesPoliza = x.ObservacionesPoliza,
.FechaLiquidacionCia = If(lqc Is Nothing, Nothing, lqc.FechaLiquidacionCia),
.FechaLiquidacionCiaDevuelto = If(lqcd Is Nothing, Nothing, lqcd.FechaLiquidacionDevueltoCia),
.FechaLiquidacionAgente = If(lqa Is Nothing, Nothing, lqa.FechaLiquidacionAgente)}
Dim lr = recs.ToList
Return lr
End Function
End Class