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

277 lines
20 KiB
VB.net

Imports bdGestionAsegasa
Imports bdGestionAsegasa.polizassg
Imports tsl5
Imports tsl5.Extensiones
Imports bdGestionAsegasa.Utilidades
Imports DevExpress.Spreadsheet
Imports tsl5.Enumeraciones
Imports System.Security
Imports bdGestionAsegasa.siniestros_eiac
Public Class ProcesosSiniestros
Public Shared Sub IncorporaSiniestrosEIACV6()
Try
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN()
Dim ltpa = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "TIPP").ToList
Dim tipo As Integer = bdGestionAsegasa.ficheroscompanias.TipoFicheroCompania.SINIESTROS_EIAC
Dim ficspen = bd.ficheroscompanias.Where(Function(x) x.FechaProcesado Is Nothing AndAlso x.FechaError Is Nothing AndAlso x.Tipo = bdGestionAsegasa.ficheroscompanias.TipoFicheroCompania.SINIESTROS_EIAC AndAlso x.Version = "6.0").OrderBy(Function(x) x.idFichero).ToList
For Each f In ficspen
Try
Dim DatosEIAC As ProcesosEIAC_V6.ProcesosEIAC = tsl5.Utilidades.Deserializa(f.Fichero, GetType(ProcesosEIAC_V6.ProcesosEIAC), True)
If DatosEIAC.Objetos IsNot Nothing AndAlso DatosEIAC.Objetos.Items IsNot Nothing Then
Dim lSins = DatosEIAC.Objetos.Items.Where(Function(x) x.GetType Is GetType(ProcesosEIAC_V6.tipo_siniestro)).Cast(Of ProcesosEIAC_V6.tipo_siniestro)
For Each s In lSins
Dim sins As List(Of siniestros) = Nothing
Dim seiac = bd.siniestros_eiac.FirstOrDefault(Function(x) x.idSiniestroEntidad = s.DatosSiniestro.IdSiniestroEntidad)
If seiac Is Nothing Then
seiac = New siniestros_eiac
seiac.idSiniestroEntidad = s.DatosSiniestro.IdSiniestroEntidad
seiac.idFicheroCompania = f.idFichero
seiac.idCompania = f.idCompania
bd.siniestros_eiac.AddObject(seiac)
End If
With seiac
.NumeroPoliza = s.DatosPoliza.IdPoliza
Dim pol = bd.polizassg.Where(Function(x) x.NumeroPoliza = .NumeroPoliza AndAlso x.idCompania = .idCompania).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
If pol IsNot Nothing Then .idPoliza = pol.idPoliza
.NumeroSuplemento = s.DatosPoliza.NumeroSuplemento
.FechaDeclaracion = s.DatosSiniestro.FechaDeclaracion
.FechaOcurrencia = s.DatosSiniestro.FechaOcurrencia
.PosicionSiniestro = bdGestionAsegasa.siniestros_eiac.ObtienePosicionSiniestroV6(s.DatosSiniestro.PosicionSiniestro)
.DescripcionSiniestro = s.DatosSiniestro.DescripcionSiniestro.Acortar(2048)
.TipologiaSiniestro = s.DatosSiniestro.TipologiaSiniestro
.ImporteIndemnizacion = s.DatosSiniestro.ImporteIndemnizacion
.ImporteReserva = s.DatosSiniestro.ImporteReserva
If s.DatosSiniestro.LugarSiniestro IsNot Nothing Then
If seiac.direcciones Is Nothing Then
seiac.direcciones = New direcciones
End If
seiac.direcciones.Direccion = s.DatosSiniestro.LugarSiniestro.ClaseVia & " " & s.DatosSiniestro.LugarSiniestro.NombreVia & " " & s.DatosSiniestro.LugarSiniestro.OtrosDatosVia
seiac.direcciones.CodigoPostal = s.DatosSiniestro.LugarSiniestro.CodigoPostal
Dim codmun = bd.ObtieneCodigoMunicipioMasCoincidente(seiac.direcciones.CodigoPostal, s.DatosSiniestro.LugarSiniestro.Poblacion, True)
If codmun = "" Then
seiac.direcciones.Direccion &= " " & s.DatosSiniestro.LugarSiniestro.Poblacion
Else
seiac.direcciones.CodigoMunicipio = codmun
End If
seiac.direcciones.Direccion = seiac.direcciones.Direccion.Acortar(200)
End If
If s.DatosSiniestro.SituacionesSiniestro IsNot Nothing Then
Dim yaincorporados As New List(Of Integer)
For Each sit In s.DatosSiniestro.SituacionesSiniestro
Dim NumeroOrden As Integer = sit.NumeroOrden
If NumeroOrden = 0 Then NumeroOrden = sit.GetHashCode
If yaincorporados.Contains(NumeroOrden) = False Then
Dim est = seiac.estadossiniestros_eiac.FirstOrDefault(Function(x) x.NumeroOrden = NumeroOrden)
If est Is Nothing Then
est = New estadossiniestros_eiac
est.NumeroOrden = NumeroOrden
seiac.estadossiniestros_eiac.Add(est)
End If
est.SituacionSiniestro = bdGestionAsegasa.estadossiniestros_eiac.ObtieneSituacionSiniestroV6(sit.SituacionSiniestro)
est.DescripcionSituacion = sit.DescripcionSituacion.Acortar(45)
yaincorporados.Add(NumeroOrden)
End If
Next
End If
If s.DatosSiniestro.PagosSiniestro IsNot Nothing Then
Dim yaincorporados As New List(Of Integer)
For Each pag In s.DatosSiniestro.PagosSiniestro
Dim NumeroOrden As Integer = pag.NumeroOrden
If NumeroOrden = 0 Then NumeroOrden = pag.GetHashCode
If yaincorporados.Contains(NumeroOrden) = False Then
Dim ps = seiac.pagossiniestros_eiac.FirstOrDefault(Function(x) x.NumeroOrden = NumeroOrden)
If ps Is Nothing Then
ps = New pagossiniestros_eiac
ps.NumeroOrden = NumeroOrden
seiac.pagossiniestros_eiac.Add(ps)
End If
ps.FechaPago = pag.FechaPago
ps.FechaLiquidacion = pag.FechaLiquidacion
ps.ImportePago = ps.ImportePago
ps.DescripcionPago = ps.DescripcionPago.Acortar(255)
ps.idTipoPago = bdGestionAsegasa.siniestros_eiac.ObtenerTipoPagoV6(pag.FormaPago, ltpa)
If pag.FormaPago IsNot Nothing AndAlso pag.FormaPago.DatosCuentaCorriente IsNot Nothing Then
ps.IBAN = pag.FormaPago.DatosCuentaCorriente.IBAN
End If
yaincorporados.Add(NumeroOrden)
End If
Next
End If
If s.DatosSiniestro.AccionesSiniestro IsNot Nothing Then
Dim yaincorporados As New List(Of Integer)
For Each accs In s.DatosSiniestro.AccionesSiniestro
Dim NumeroOrden As Integer = accs.NumeroOrden
If NumeroOrden = 0 Then NumeroOrden = accs.GetHashCode
If yaincorporados.Contains(NumeroOrden) = False Then
Dim acs = seiac.accionessiniestros_eiac.FirstOrDefault(Function(x) x.NumeroOrden = NumeroOrden)
If acs Is Nothing Then
acs = New accionessiniestros_eiac
acs.NumeroOrden = NumeroOrden
seiac.accionessiniestros_eiac.Add(acs)
End If
acs.AccionSiniestro = bdGestionAsegasa.accionessiniestros_eiac.ObtieneAccionSiniestroV6(accs.AccionSiniestro)
acs.FechaAccion = accs.FechaAccion
acs.DescripcionAccion = accs.DescripcionAccion
acs.SituacionAccion = bdGestionAsegasa.accionessiniestros_eiac.ObtieneSituacionAccionV6(accs.SituacionAccion)
yaincorporados.Add(NumeroOrden)
End If
Next
End If
If s.DatosSiniestro.Expedientes IsNot Nothing Then
Dim yaincorporados As New List(Of String)
For Each exp In s.DatosSiniestro.Expedientes
Dim NumeroExpediente As String = exp.NumeroExpediente
If NumeroExpediente.NothingAVacio = "" Then NumeroExpediente = exp.GetHashCode.ToString
If yaincorporados.Contains(NumeroExpediente) = False Then
Dim ep = seiac.expedientessiniestros_eiac.FirstOrDefault(Function(x) x.NumeroExpediente = NumeroExpediente)
If ep Is Nothing Then
ep = New expedientessiniestros_eiac
ep.NumeroExpediente = NumeroExpediente
seiac.expedientessiniestros_eiac.Add(ep)
End If
ep.EstadoExpediente = bdGestionAsegasa.expedientessiniestros_eiac.ObtieneEstadoExpedienteV6(exp.EstadoExpediente)
ep.ImporteReserva = exp.ImporteReserva
ep.TotalPagos = exp.TotalPagos
ep.TotalRecobros = exp.TotalRecobros
ep.FechaInicio = exp.FechaInicio
ep.FechaFin = exp.FechaFin
ep.NumeroOrden = exp.NumeroOrden
yaincorporados.Add(NumeroExpediente)
End If
Next
End If
If .siniestros Is Nothing Then
Dim fi = .FechaOcurrencia.AddDays(-5)
Dim ff = .FechaOcurrencia.AddDays(5)
sins = bd.siniestros.Where(Function(x) x.polizassg.NumeroPoliza = .NumeroPoliza AndAlso x.FechaAccidente.HasValue AndAlso x.FechaAccidente.Value >= fi AndAlso x.FechaAccidente.Value <= ff).ToList
If sins.Count = 1 Then
.siniestros = sins(0)
End If
End If
End With
Dim bModificados As Boolean = False
If bd.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count > 0 Then
bModificados = True
seiac.SituacionAsegasa = SituacionAsegasaENUM.NUEVO
seiac.FechaSituacion = Now
Else
Dim prmods = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified)
If prmods.Count > 0 Then
For Each pr In prmods
Dim original = pr.OriginalValues
Dim nuevosvalores = pr.CurrentValues
For i = 0 To original.FieldCount - 1
If original.GetValue(i).GetHashCode <> nuevosvalores.GetValue(i).GetHashCode Then
bModificados = True
Exit For
End If
Next
If bModificados Then Exit For
Next
End If
End If
If bModificados Then
If seiac.SituacionAsegasa.HasValue = False AndAlso seiac.SituacionAsegasa.Value <> seiac.SituacionAsegasa = SituacionAsegasaENUM.DESCARTADO Then
seiac.SituacionAsegasa = SituacionAsegasaENUM.MODIFICADO
seiac.FechaSituacion = Now
End If
Dim nact As New actualizacionessiniestros_eiac
With nact
.siniestros_eiac = seiac
.Fecha = Now
.idFicheroCompania = f.idFichero
End With
bd.actualizacionessiniestros_eiac.AddObject(nact)
If seiac.SituacionAsegasa.Value <> seiac.SituacionAsegasa = SituacionAsegasaENUM.DESCARTADO Then
If seiac.idPoliza.HasValue = False Then
seiac.SituacionAsegasa = SituacionAsegasaENUM.POLIZA_NO_ENCONTRADA
Else
If sins.Count = 0 Then
seiac.SituacionAsegasa = SituacionAsegasaENUM.SINIESTRO_NO_ENCONTRADO
ElseIf sins.Count > 1 Then
seiac.SituacionAsegasa = SituacionAsegasaENUM.VARIOS_SINIESTROS_POSIBLES
End If
End If
End If
bd.SaveChanges()
End If
Next
End If
f.FechaProcesado = Now
bd.SaveChanges()
Catch ex As Exception
f.FechaError = Now
bd.SaveChanges()
Call AñadeLog(tsl5.Enumeraciones.TipoLog.Fallo, "En IncorporaSiniestrosEIACV6.", "Rutina: IncorporaSiniestrosEIACV6. Fichero:" & f.NombreFichero & " " & gestionasegasaEntities.bdga.Servidor & " " & ex.Message, ex)
End Try
Next
Catch ex As Exception
Call AñadeLog(tsl5.Enumeraciones.TipoLog.Fallo, "En IncorporaSiniestrosEIACV6.", "Rutina: IncorporaSiniestrosEIACV6. " & gestionasegasaEntities.bdga.Servidor & " " & ex.Message, ex)
End Try
End Sub
Public Shared Sub IncorporaExpSiniestrosEIACV6()
Try
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN()
Dim ltpa = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "TIPP").ToList
Dim tipo As Integer = bdGestionAsegasa.ficheroscompanias.TipoFicheroCompania.SINIESTROS_EIAC
Dim ficspen = bd.ficheroscompanias.Where(Function(x) x.Tipo = bdGestionAsegasa.ficheroscompanias.TipoFicheroCompania.SINIESTROS_EIAC AndAlso x.Version = "6.0").OrderBy(Function(x) x.idFichero).ToList
For Each f In ficspen
Try
Dim DatosEIAC As ProcesosEIAC_V6.ProcesosEIAC = tsl5.Utilidades.Deserializa(f.Fichero, GetType(ProcesosEIAC_V6.ProcesosEIAC), True)
If DatosEIAC.Objetos IsNot Nothing AndAlso DatosEIAC.Objetos.Items IsNot Nothing Then
Dim lSins = DatosEIAC.Objetos.Items.Where(Function(x) x.GetType Is GetType(ProcesosEIAC_V6.tipo_siniestro)).Cast(Of ProcesosEIAC_V6.tipo_siniestro)
For Each s In lSins
Dim sins As List(Of siniestros) = Nothing
Dim seiac = bd.siniestros_eiac.FirstOrDefault(Function(x) x.idSiniestroEntidad = s.DatosSiniestro.IdSiniestroEntidad)
If seiac IsNot Nothing Then
If s.DatosSiniestro.Expedientes IsNot Nothing Then
Dim yaincorporados As New List(Of String)
For Each exp In s.DatosSiniestro.Expedientes
Dim NumeroExpediente As String = exp.NumeroExpediente
If NumeroExpediente.NothingAVacio = "" Then NumeroExpediente = exp.GetHashCode.ToString
If yaincorporados.Contains(NumeroExpediente) = False Then
Dim ep = seiac.expedientessiniestros_eiac.FirstOrDefault(Function(x) x.NumeroExpediente = NumeroExpediente)
If ep Is Nothing Then
ep = New expedientessiniestros_eiac
ep.NumeroExpediente = NumeroExpediente
seiac.expedientessiniestros_eiac.Add(ep)
End If
ep.EstadoExpediente = bdGestionAsegasa.expedientessiniestros_eiac.ObtieneEstadoExpedienteV6(exp.EstadoExpediente)
ep.ImporteReserva = exp.ImporteReserva
ep.TotalPagos = exp.TotalPagos
ep.TotalRecobros = exp.TotalRecobros
ep.FechaInicio = exp.FechaInicio
ep.FechaFin = exp.FechaFin
ep.NumeroOrden = exp.NumeroOrden
yaincorporados.Add(NumeroExpediente)
End If
Next
bd.SaveChanges()
End If
End If
Next
End If
' f.FechaProcesado = Now
bd.SaveChanges()
Catch ex As Exception
f.FechaError = Now
bd.SaveChanges()
Call AñadeLog(tsl5.Enumeraciones.TipoLog.Fallo, "En IncorporaSiniestrosEIACV6.", "Rutina: IncorporaSiniestrosEIACV6. Fichero:" & f.NombreFichero & " " & gestionasegasaEntities.bdga.Servidor & " " & ex.Message, ex)
End Try
Next
Catch ex As Exception
Call AñadeLog(tsl5.Enumeraciones.TipoLog.Fallo, "En IncorporaSiniestrosEIACV6.", "Rutina: IncorporaSiniestrosEIACV6. " & gestionasegasaEntities.bdga.Servidor & " " & ex.Message, ex)
End Try
End Sub
End Class