agregado procesos y bd clases
This commit is contained in:
541
chunk_imports1.txt
Normal file
541
chunk_imports1.txt
Normal file
@@ -0,0 +1,541 @@
|
||||
Public Shared Sub ImportaRecibosPatriaHispana(bd As bdGestionAsegasa.gestionasegasaEntities, Lrai As List(Of ReciboAIncorporar), ByRef iNumfic As Integer, NumTotFics As Integer, Ficheros As List(Of ficheroscompanias), Busqueda As String, MostrarProgreso As Boolean, GuardarCambios As Boolean, MarcarFicheros As Boolean, Optional ByRef ListadoRecibosDuplicados As List(Of String) = Nothing)
|
||||
Try
|
||||
If MostrarProgreso Then
|
||||
' DXSplashScreen.Show(Of SplashScreenTecnosis)()
|
||||
DXSplashScreen.SetState("Incorporando recibos de PATRIA HISPANA ...")
|
||||
End If
|
||||
' Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN()
|
||||
Dim cia = bd.companias.First(Function(x) x.Codigo = "0037")
|
||||
' Dim TipoRecibo As Integer = bdGestionAsegasa.ficheroscompanias.TipoFicheroCompania.RECIBOS_EIAC
|
||||
' Dim lrai As New List(Of bdGestionAsegasa.ReciboAIncorporar)
|
||||
' Dim FICS = bd.ficheroscompanias.Where(Function(x) x.FechaProcesado Is Nothing And x.FechaError Is Nothing And x.idCompania = cia.idCompania And x.Tipo = TipoRecibo).OrderBy(Function(x) x.FechaCreacion).ToList
|
||||
If Ficheros.Count > 0 Then
|
||||
Dim ldur = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "DUR").ToList
|
||||
' Dim idTipoPagoCIA = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.CIA").idEnumeracion
|
||||
Dim TiposRecibos = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "TRC").ToList
|
||||
Dim pols = bd.polizassg.Include("entidadespolizas.entidades").Where(Function(x) x.idCompania = cia.idCompania).ToList
|
||||
Dim recs = bd.recibos.Where(Function(x) x.polizassg.idCompania = cia.idCompania).Select(Function(x) New With {.idRecibo = x.idRecibo, .Codigorecibo = x.CodigoRecibo, .NumeroRecibo = x.NumeroRecibo, .idPoliza = x.idPoliza, .NumeroPoliza = x.polizassg.NumeroPoliza, .NumeroSuplemento = x.polizassg.NumeroSuplemento, .FechaEfecto = x.FechaEfecto, .FechaVencimiento = x.FechaVencimiento, .FechaBaja = x.FechaBaja, .FechaFacturacion = x.FechaFacturacion}).ToList
|
||||
Dim agentes = bd.agentes.ToList
|
||||
Dim subagentes = bd.subagentes.ToList
|
||||
Dim ramos = bd.ramos.ToList
|
||||
Dim comsCia = bd.comisionescompanias.Where(Function(x) x.idCompania = cia.idCompania).ToList
|
||||
Dim comsAge = bd.comisionesagentes.ToList
|
||||
' Dim iNumfic = 0
|
||||
' Dim iNumfics = Ficheros.Count
|
||||
' Dim recsai As New List(Of recibos)
|
||||
|
||||
For Each f In Ficheros
|
||||
If MostrarProgreso Then
|
||||
DXSplashScreen.SetState("Comprobando " & f.NombreFichero)
|
||||
End If
|
||||
iNumfic += 1
|
||||
Try
|
||||
|
||||
'Catch ex As Exception
|
||||
|
||||
'End Try
|
||||
' Dim DatosEIAC As ProcesosEIAC_V5.ProcesosEIAC = tsl5.Utilidades.Deserializa(f.Fichero, GetType(ProcesosEIAC_V5.ProcesosEIAC))
|
||||
Dim iNumrec As Integer = 0
|
||||
' If DatosEIAC.Objetos IsNot Nothing AndAlso DatosEIAC.Objetos.Items IsNot Nothing Then
|
||||
|
||||
' Dim lrecibos = DatosEIAC.Objetos.Items.Where(Function(x) x.GetType Is GetType(bdGestionAsegasa.tipo_recibo)).Cast(Of bdGestionAsegasa.tipo_recibo)
|
||||
' Dim iNumRecs = lrecibos.Count
|
||||
|
||||
Dim clsReader As System.IO.TextReader = New StreamReader(New MemoryStream(f.Fichero))
|
||||
Dim sLine As String = clsReader.ReadLine
|
||||
Do Until sLine Is Nothing
|
||||
|
||||
|
||||
Dim npo = sLine.Substring(7, 7)
|
||||
Dim nre = sLine.Substring(14, 9)
|
||||
Dim Pne = CDbl(sLine.Substring(29, 11)) / 100
|
||||
Dim Pnerc = Pne
|
||||
Dim Bon = 0
|
||||
Dim Con = CDbl(sLine.Substring(40, 9)) / 100
|
||||
Dim Conrc = Con
|
||||
Dim Ipu = CDbl(sLine.Substring(49, 9)) / 100
|
||||
Dim Ipurc = Ipu
|
||||
' Dim Fecoc As Date
|
||||
Dim Tipp As String = ""
|
||||
Dim Pneom As Double = 0
|
||||
Dim Conom As Double = 0
|
||||
Dim Ipuom As Double = 0
|
||||
Dim Pneoc As Double = 0
|
||||
Dim Conoc As Double = 0
|
||||
Dim Ipuoc As Double = 0
|
||||
Dim Fef As Date
|
||||
Dim Fve As Date
|
||||
Dim Imp = Pne + Con + Ipu
|
||||
|
||||
|
||||
If sLine.Trim.Length <= 200 Then
|
||||
Fef = New Date(CInt(sLine.Substring(82, 4)), CInt(sLine.Substring(80, 2)), CInt(sLine.Substring(78, 2))) ' Recibo.DatosRecibo.Fechas.FechaEfectoActual
|
||||
Fve = New Date(CInt(sLine.Substring(90, 4)), CInt(sLine.Substring(88, 2)), CInt(sLine.Substring(86, 2))) ' Recibo.DatosRecibo.Fechas.FechaVencimi
|
||||
' Fecoc = Fef
|
||||
Tipp = sLine.Substring(94, 1)
|
||||
Else
|
||||
Fef = New Date(CInt(sLine.Substring(93, 4)), CInt(sLine.Substring(91, 2)), CInt(sLine.Substring(89, 2))) ' Recibo.DatosRecibo.Fechas.FechaEfectoActual
|
||||
Fve = New Date(CInt(sLine.Substring(101, 4)), CInt(sLine.Substring(99, 2)), CInt(sLine.Substring(97, 2))) ' Recibo.DatosRecibo.Fechas.FechaVencimiento
|
||||
' Fecoc = New Date(CInt(sLine.Substring(234, 4)), CInt(sLine.Substring(230, 2)), CInt(sLine.Substring(228, 2)))
|
||||
Pneom = CDbl(sLine.Substring(105, 11)) / 100
|
||||
Conom = CDbl(sLine.Substring(116, 9)) / 100
|
||||
Ipuom = CDbl(sLine.Substring(125, 9)) / 100
|
||||
Pneoc = CDbl(sLine.Substring(181, 11)) / 100
|
||||
Conoc = CDbl(sLine.Substring(192, 9)) / 100
|
||||
Ipuoc = CDbl(sLine.Substring(201, 9)) / 100
|
||||
Pne = Pnerc + Pneom + Pneoc
|
||||
Con = Conrc + Conom + Conoc
|
||||
Ipu = Ipurc + Ipuom + Ipuoc
|
||||
Imp = Pne + Con + Ipu
|
||||
Tipp = sLine.Substring(248, 1)
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
' For Each Recibo In lrecibos
|
||||
Dim bIncluir As Boolean = False
|
||||
If f.idFichero = 2584 Then Debug.WriteLine("aqui")
|
||||
If Busqueda <> "" Then
|
||||
If npo.Contains(Busqueda) Or nre.Contains(Busqueda) Then
|
||||
bIncluir = True
|
||||
End If
|
||||
Else
|
||||
bIncluir = True
|
||||
End If
|
||||
If bIncluir Then
|
||||
Try
|
||||
iNumrec += 1
|
||||
Dim cre = cia.Codigo & "/" & nre
|
||||
Dim ir As bdGestionAsegasa.ReciboAIncorporar
|
||||
ir = Lrai.FirstOrDefault(Function(x) x.Código_Recibo = cre And x.Correcto)
|
||||
If ir Is Nothing Then
|
||||
ir = New bdGestionAsegasa.ReciboAIncorporar
|
||||
Lrai.Add(ir)
|
||||
End If
|
||||
ir.Correcto = False
|
||||
ir.Fecha_Efecto = Fef
|
||||
ir.Fecha_Vencimiento = Fve
|
||||
ir.Número_Fichero = f.idFichero
|
||||
ir.Fecha_Fichero = f.FechaCreacion
|
||||
ir.Fecha_Procesado = f.FechaProcesado
|
||||
ir.Usuario_Procesado = If(f.usuarios IsNot Nothing, f.usuarios.Nombre, "")
|
||||
ir.Código_Cia = f.companias.Codigo
|
||||
ir.idCompañia = f.idCompania
|
||||
ir.Código_Recibo = cre
|
||||
If MostrarProgreso Then DXSplashScreen.SetState("Incorporando Recibos. Fichero (" & iNumfic.ToString & "/" & NumTotFics.ToString & "). " & "Recibo (" & iNumrec.ToString & "): " & ir.Código_Recibo)
|
||||
Dim pol As polizassg
|
||||
|
||||
pol = pols.Where(Function(x) x.NumeroPoliza = npo And x.FechaBaja.HasValue = False And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
||||
If pol Is Nothing Then
|
||||
If npo.Substring(0, 1) = "0" Then
|
||||
npo = npo.Substring(1)
|
||||
pol = pols.Where(Function(x) x.NumeroPoliza = npo And x.FechaBaja.HasValue = False And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
||||
End If
|
||||
End If
|
||||
If pol Is Nothing Then pol = pols.Where(Function(x) x.NumeroPoliza = npo And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
||||
ir.Número_Póliza = npo
|
||||
|
||||
Dim idTipoRecibo As Integer
|
||||
|
||||
|
||||
If Imp < 0 Then
|
||||
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CX").idEnumeracion
|
||||
Else
|
||||
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.C").idEnumeracion
|
||||
End If
|
||||
ir.Tipo = TiposRecibos.First(Function(X) X.idEnumeracion = idTipoRecibo).Descripcion
|
||||
|
||||
If pol IsNot Nothing Then
|
||||
ir.Observaciones = pol.Observaciones
|
||||
ir.Tipo_Pago = pol.TipoPago
|
||||
ir.Forma_Pago_Recibida = "DESCONOCIDA"
|
||||
ir.Situacion_Recibo = "DESCONOCIDA"
|
||||
If Not Lrai.Any(Function(x) x.Código_Recibo = ir.Código_Recibo And x.Correcto) Then
|
||||
Dim Rec = recs.Where(Function(x) x.Codigorecibo = ir.Código_Recibo).FirstOrDefault
|
||||
If Rec Is Nothing Then
|
||||
If ir.Fecha_Efecto.AddMonths(1) > Today Then
|
||||
Dim recant = recs.FirstOrDefault(Function(X) X.idPoliza = pol.idPoliza And X.FechaEfecto = ir.Fecha_Efecto And X.FechaVencimiento = ir.Fecha_Vencimiento And X.Codigorecibo <> ir.Código_Recibo)
|
||||
Dim recantFichs = Lrai.Where(Function(x) x.Poliza IsNot Nothing).FirstOrDefault(Function(x) x.Poliza.idPoliza = pol.idPoliza And x.Fecha_Efecto = ir.Fecha_Efecto And x.Fecha_Vencimiento = ir.Fecha_Vencimiento And x.Código_Recibo <> ir.Código_Recibo)
|
||||
If (recant Is Nothing AndAlso recantFichs Is Nothing) OrElse (recant IsNot Nothing AndAlso (recant.FechaEfecto.AddMonths(1) > Date.Today And nre.Contains(recant.NumeroRecibo) = False)) Then
|
||||
If Imp <> 0 Then
|
||||
ir.Mensaje = "Recibo Correcto"
|
||||
Else
|
||||
ir.Mensaje = "Recibo con Prima Neta = 0"
|
||||
End If
|
||||
ir.Correcto = True
|
||||
ir.Corregible = True
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
If recant IsNot Nothing Then
|
||||
If recant.FechaFacturacion.HasValue Then
|
||||
ir.Mensaje = "Existe otro recibo facturado de la misma póliza con el mismo efecto y vencimiento (" & recant.Codigorecibo & ")"
|
||||
Else
|
||||
ir.Mensaje = "Existe otro recibo de la misma póliza con el mismo efecto y vencimiento (" & recant.Codigorecibo & ")"
|
||||
If ListadoRecibosDuplicados IsNot Nothing Then ListadoRecibosDuplicados.Add(recant.Codigorecibo)
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = True
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
If recant Is Nothing Then
|
||||
ir.Mensaje = "Existe otro recibo de la misma póliza con el mismo efecto y vencimiento en otro fichero (F.Efecto Anterior a un Mes) (" & recantFichs.Código_Recibo & ")"
|
||||
Else
|
||||
ir.Mensaje = "Existe otro recibo de la misma póliza con el mismo efecto y vencimiento (F.Efecto Anterior a un Mes) (" & recant.Codigorecibo & ")"
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = True
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
ir.Mensaje = "Recibo Con fecha de efecto anterior a la permitida."
|
||||
End If
|
||||
Else
|
||||
If Now.Subtract(Rec.FechaEfecto).TotalDays > 365 Then
|
||||
ir.Mensaje = "Recibo ya existente (Anterior a un año)"
|
||||
Else
|
||||
ir.Mensaje = "Recibo ya existente"
|
||||
End If
|
||||
ir.Correcto = False
|
||||
ir.Corregible = False
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
End If
|
||||
Else
|
||||
' ir.Correcto = False
|
||||
' ir.Corregible = False
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False, True)
|
||||
' ir.Mensaje = "Recibo Duplicado en el fichero"
|
||||
End If
|
||||
ir.Tomador = pol.Tomador.RazonSocial
|
||||
ir.Matrícula = pol.Matricula
|
||||
ir.Bienes_Asegurados = pol.BienesAsegurados
|
||||
ir.Agente = agentes.First(Function(x) x.idAgente = pol.idAgente).Nombre
|
||||
ir.Subagente = If(pol.idSubAgente.HasValue = False, "", subagentes.First(Function(x) x.idSubagente = pol.idSubAgente.Value).Nombre)
|
||||
ir.Ramo = ramos.First(Function(x) x.idRamo = pol.idRamo).Descripcion
|
||||
ir.IBAN = pol.IBAN
|
||||
|
||||
ir.Comisión = ir.Comisión_Prevista_ASEGASA
|
||||
ir.Sobrecomisión = 0
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = False
|
||||
ir.Mensaje = "Póliza no encontrada"
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Throw New Exception("Error Incorporando Recibo: " & nre & " Póliza: " & npo, ex)
|
||||
End Try
|
||||
End If
|
||||
sLine = clsReader.ReadLine
|
||||
Loop
|
||||
' End If
|
||||
Catch ex As Exception
|
||||
Throw New Exception("Error Incorporando " & f.NombreFichero & " Compañia: " & "0037", ex)
|
||||
End Try
|
||||
Next
|
||||
If GuardarCambios Then
|
||||
Dim rcc = Lrai.Where(Function(x) x.Correcto).ToList
|
||||
Dim rnp = Lrai.Where(Function(x) x.Correcto = False).ToList
|
||||
' Dim raa = lrai.Where(Function(x) x.Actualizado).ToList
|
||||
If MarcarFicheros Then
|
||||
GuardaRecibosEIAC(bd, Lrai, Nothing, Nothing, Nothing, MostrarProgreso, Ficheros, comsCia, comsAge, ldur)
|
||||
Else
|
||||
GuardaRecibosEIAC(bd, Lrai, Nothing, Nothing, Nothing, MostrarProgreso, Nothing, comsCia, comsAge, ldur)
|
||||
End If
|
||||
GeneraEmailRecibosIncorporados(Lrai, Nothing, rnp, Nothing, Nothing)
|
||||
End If
|
||||
End If
|
||||
'If MostrarProgreso Then
|
||||
' DXSplashScreen.Close()
|
||||
'End If
|
||||
' Return lrai
|
||||
Catch EX As Exception
|
||||
If MostrarProgreso AndAlso DXSplashScreen.IsActive Then DXSplashScreen.Close()
|
||||
Throw New Exception(EX.Message, EX) ' bdGestionAsegasa.Utilidades.AñadeLog(TipoLog.Fallo, "En ImportaRecibosEIAC " & Compañia, EX.Message, EX)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Shared Sub ImportaRecibosPrevisionMallorquina(bd As bdGestionAsegasa.gestionasegasaEntities, Lrai As List(Of ReciboAIncorporar), ByRef iNumfic As Integer, NumTotFics As Integer, Ficheros As List(Of ficheroscompanias), Busqueda As String, MostrarProgreso As Boolean, GuardarCambios As Boolean, MarcarFicheros As Boolean, Optional ByRef ListadoRecibosDuplicados As List(Of String) = Nothing)
|
||||
Try
|
||||
If MostrarProgreso Then
|
||||
' DXSplashScreen.Show(Of SplashScreenTecnosis)()
|
||||
DXSplashScreen.SetState("Incorporando recibos de PREVISION MALLORQUINA ...")
|
||||
End If
|
||||
Dim cia = bd.companias.First(Function(x) x.Codigo = "0024")
|
||||
If Ficheros.Count > 0 Then
|
||||
Dim ldur = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "DUR").ToList
|
||||
Dim idTipoPagoCIA = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.CIA").idEnumeracion
|
||||
Dim TiposRecibos = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "TRC").ToList
|
||||
Dim pols = bd.polizassg.Include("entidadespolizas.entidades").Where(Function(x) x.idCompania = cia.idCompania).ToList
|
||||
Dim recs = bd.recibos.Where(Function(x) x.polizassg.idCompania = cia.idCompania).Select(Function(x) New With {.idRecibo = x.idRecibo, .Codigorecibo = x.CodigoRecibo, .NumeroRecibo = x.NumeroRecibo, .idPoliza = x.idPoliza, .NumeroPoliza = x.polizassg.NumeroPoliza, .NumeroSuplemento = x.polizassg.NumeroSuplemento, .FechaEfecto = x.FechaEfecto, .FechaVencimiento = x.FechaVencimiento, .FechaBaja = x.FechaBaja, .FechaFacturacion = x.FechaFacturacion}).ToList
|
||||
Dim agentes = bd.agentes.ToList
|
||||
Dim subagentes = bd.subagentes.ToList
|
||||
Dim ramos = bd.ramos.ToList
|
||||
Dim comsCia = bd.comisionescompanias.Where(Function(x) x.idCompania = cia.idCompania).ToList
|
||||
Dim comsAge = bd.comisionesagentes.ToList
|
||||
|
||||
For Each f In Ficheros
|
||||
If MostrarProgreso Then
|
||||
DXSplashScreen.SetState("Comprobando " & f.NombreFichero)
|
||||
End If
|
||||
iNumfic += 1
|
||||
Try
|
||||
Dim iNumrec As Integer = 0
|
||||
Dim wb As New Workbook
|
||||
wb.LoadDocument(f.Fichero, DevExpress.Spreadsheet.DocumentFormat.Xlsx)
|
||||
Dim i As Integer = 2
|
||||
If wb.Worksheets(0).Cells("A3").Value.ToString = "Mediador" Then i = 4
|
||||
Do Until wb.Worksheets(0).Cells("A" & i.ToString).Value.ToString = ""
|
||||
Dim npo = wb.Worksheets(0).Cells("D" & i.ToString).Value.ToString.Replace("'", "").Trim
|
||||
Dim nre = wb.Worksheets(0).Cells("N" & i.ToString).Value.ToString.Replace("'", "").Trim
|
||||
Dim Pne = wb.Worksheets(0).Cells("J" & i.ToString).Value.NumericValue
|
||||
Dim Pnerc = Pne
|
||||
Dim Bon = 0
|
||||
Dim Con = wb.Worksheets(0).Cells("K" & i.ToString).Value.NumericValue
|
||||
' Dim Conrc = Con
|
||||
Dim Ipu = 0
|
||||
Dim Ipurc = Ipu
|
||||
Dim Pneom As Double = 0
|
||||
Dim Conom As Double = 0
|
||||
Dim Ipuom As Double = 0
|
||||
Dim Pneoc As Double = 0
|
||||
Dim Conoc As Double = 0
|
||||
Dim Ipuoc As Double = 0
|
||||
Dim Fef As Date
|
||||
Dim Fve As Date
|
||||
Dim Imp = Pne + Con + Ipu
|
||||
Fef = tsl5.Extensiones.StringExtensions.FechaStringADate(wb.Worksheets(0).Cells("F" & i.ToString).Value.ToString, False)
|
||||
Fve = Fef.AddYears(1)
|
||||
Dim bIncluir As Boolean = False
|
||||
If f.idFichero = 2584 Then Debug.WriteLine("aqui")
|
||||
If Busqueda <> "" Then
|
||||
If npo.Contains(Busqueda) Or nre.Contains(Busqueda) Then
|
||||
bIncluir = True
|
||||
End If
|
||||
Else
|
||||
bIncluir = True
|
||||
End If
|
||||
If bIncluir Then
|
||||
Try
|
||||
iNumrec += 1
|
||||
Dim ir As New bdGestionAsegasa.ReciboAIncorporar
|
||||
Lrai.Add(ir)
|
||||
ir.Correcto = False
|
||||
ir.Fecha_Efecto = Fef
|
||||
ir.Fecha_Vencimiento = Fve
|
||||
ir.Número_Fichero = f.idFichero
|
||||
ir.Fecha_Fichero = f.FechaCreacion
|
||||
ir.Fecha_Procesado = f.FechaProcesado
|
||||
ir.Usuario_Procesado = If(f.usuarios IsNot Nothing, f.usuarios.Nombre, "")
|
||||
ir.Código_Cia = f.companias.Codigo
|
||||
ir.idCompañia = f.idCompania
|
||||
ir.Código_Recibo = cia.Codigo & "/" & nre
|
||||
If MostrarProgreso Then DXSplashScreen.SetState("Incorporando Recibos. Fichero (" & iNumfic.ToString & "/" & NumTotFics.ToString & "). " & "Recibo (" & iNumrec.ToString & "): " & ir.Código_Recibo)
|
||||
Dim pol As polizassg
|
||||
pol = pols.Where(Function(x) x.NumeroPoliza = npo And x.FechaBaja.HasValue = False And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
||||
If pol Is Nothing Then
|
||||
If npo.Substring(0, 1) = "0" Then
|
||||
npo = npo.Substring(1)
|
||||
pol = pols.Where(Function(x) x.NumeroPoliza = npo And x.FechaBaja.HasValue = False And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
||||
End If
|
||||
End If
|
||||
If pol Is Nothing Then pol = pols.Where(Function(x) x.NumeroPoliza = npo And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
||||
ir.Número_Póliza = npo
|
||||
|
||||
Dim idTipoRecibo As Integer
|
||||
|
||||
|
||||
If Imp < 0 Then
|
||||
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CX").idEnumeracion
|
||||
Else
|
||||
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.C").idEnumeracion
|
||||
End If
|
||||
ir.Tipo = TiposRecibos.First(Function(X) X.idEnumeracion = idTipoRecibo).Descripcion
|
||||
|
||||
If pol IsNot Nothing Then
|
||||
ir.Observaciones = pol.Observaciones
|
||||
' columna n fecha de pago y tipo de pago siempre cia
|
||||
' If r.Situacion_Recibo = "COBRADO" AndAlso r.Forma_Pago_Recibida = "CUENTA BANCARIA" AndAlso r.Fecha_Situacion.HasValue Then
|
||||
ir.Tipo_Pago = idTipoPagoCIA
|
||||
pol.idTipoPago = idTipoPagoCIA
|
||||
ir.Forma_Pago_Recibida = "CUENTA BANCARIA"
|
||||
ir.Situacion_Recibo = "COBRADO"
|
||||
ir.Fecha_Situacion = Now
|
||||
If Not Lrai.Any(Function(x) x.Código_Recibo = ir.Código_Recibo And x.Correcto) Then
|
||||
Dim Rec = recs.Where(Function(x) x.Codigorecibo = ir.Código_Recibo).FirstOrDefault
|
||||
If Rec Is Nothing Then
|
||||
If ir.Fecha_Efecto.AddMonths(1) > Today Then
|
||||
Dim recant = recs.FirstOrDefault(Function(X) X.idPoliza = pol.idPoliza And X.FechaEfecto = ir.Fecha_Efecto And X.FechaVencimiento = ir.Fecha_Vencimiento And X.Codigorecibo <> ir.Código_Recibo)
|
||||
Dim recantFichs = Lrai.Where(Function(x) x.Poliza IsNot Nothing).FirstOrDefault(Function(x) x.Poliza.idPoliza = pol.idPoliza And x.Fecha_Efecto = ir.Fecha_Efecto And x.Fecha_Vencimiento = ir.Fecha_Vencimiento And x.Código_Recibo <> ir.Código_Recibo)
|
||||
If (recant Is Nothing AndAlso recantFichs Is Nothing) OrElse (recant IsNot Nothing AndAlso (recant.FechaEfecto.AddMonths(1) > Date.Today And nre.Contains(recant.NumeroRecibo) = False)) Then
|
||||
If Imp <> 0 Then
|
||||
ir.Mensaje = "Recibo Correcto"
|
||||
Else
|
||||
ir.Mensaje = "Recibo con Prima Neta = 0"
|
||||
End If
|
||||
ir.Correcto = True
|
||||
ir.Corregible = True
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
If recant IsNot Nothing Then
|
||||
If recant.FechaFacturacion.HasValue Then
|
||||
ir.Mensaje = "Existe otro recibo facturado de la misma póliza con el mismo efecto y vencimiento (" & recant.Codigorecibo & ")"
|
||||
Else
|
||||
ir.Mensaje = "Existe otro recibo de la misma póliza con el mismo efecto y vencimiento (" & recant.Codigorecibo & ")"
|
||||
If ListadoRecibosDuplicados IsNot Nothing Then ListadoRecibosDuplicados.Add(recant.Codigorecibo)
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = True
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
If recant Is Nothing Then
|
||||
ir.Mensaje = "Existe otro recibo de la misma póliza con el mismo efecto y vencimiento en otro fichero (F.Efecto Anterior a un Mes) (" & recantFichs.Código_Recibo & ")"
|
||||
Else
|
||||
ir.Mensaje = "Existe otro recibo de la misma póliza con el mismo efecto y vencimiento (F.Efecto Anterior a un Mes) (" & recant.Codigorecibo & ")"
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = True
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
ir.Mensaje = "Recibo Con fecha de efecto anterior a la permitida."
|
||||
End If
|
||||
Else
|
||||
If Now.Subtract(Rec.FechaEfecto).TotalDays > 365 Then
|
||||
ir.Mensaje = "Recibo ya existente (Anterior a un año)"
|
||||
Else
|
||||
ir.Mensaje = "Recibo ya existente"
|
||||
End If
|
||||
ir.Correcto = False
|
||||
ir.Corregible = False
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
End If
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = False
|
||||
RellenaDatosRecibo(cia.Codigo, ir, f, pol, 0, comsCia, comsAge, TiposRecibos, idTipoRecibo, Pne, 0, Imp, False, False)
|
||||
ir.Mensaje = "Recibo Duplicado en el fichero"
|
||||
End If
|
||||
ir.Tomador = pol.Tomador.RazonSocial
|
||||
ir.Matrícula = pol.Matricula
|
||||
ir.Bienes_Asegurados = pol.BienesAsegurados
|
||||
ir.Agente = agentes.First(Function(x) x.idAgente = pol.idAgente).Nombre
|
||||
ir.Subagente = If(pol.idSubAgente.HasValue = False, "", subagentes.First(Function(x) x.idSubagente = pol.idSubAgente.Value).Nombre)
|
||||
ir.Ramo = ramos.First(Function(x) x.idRamo = pol.idRamo).Descripcion
|
||||
ir.IBAN = pol.IBAN
|
||||
|
||||
ir.Comisión = ir.Comisión_Prevista_ASEGASA
|
||||
ir.Sobrecomisión = 0
|
||||
Else
|
||||
ir.Correcto = False
|
||||
ir.Corregible = False
|
||||
ir.Mensaje = "Póliza no encontrada"
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Throw New Exception("Error Incorporando Recibo: " & nre & " Póliza: " & npo, ex)
|
||||
End Try
|
||||
End If
|
||||
i += 1
|
||||
Loop
|
||||
Catch ex As Exception
|
||||
Throw New Exception("Error Incorporando " & f.NombreFichero & " Compañia: " & "0024", ex)
|
||||
End Try
|
||||
Next
|
||||
If GuardarCambios Then
|
||||
Dim rcc = Lrai.Where(Function(x) x.Correcto).ToList
|
||||
Dim rnp = Lrai.Where(Function(x) x.Correcto = False).ToList
|
||||
If MarcarFicheros Then
|
||||
GuardaRecibosEIAC(bd, Lrai, Nothing, Nothing, Nothing, MostrarProgreso, Ficheros, comsCia, comsAge, ldur)
|
||||
Else
|
||||
GuardaRecibosEIAC(bd, Lrai, Nothing, Nothing, Nothing, MostrarProgreso, Nothing, comsCia, comsAge, ldur)
|
||||
End If
|
||||
GeneraEmailRecibosIncorporados(Lrai, Nothing, rnp, Nothing, Nothing)
|
||||
End If
|
||||
End If
|
||||
'If MostrarProgreso Then
|
||||
' DXSplashScreen.Close()
|
||||
'End If
|
||||
Catch EX As Exception
|
||||
If MostrarProgreso AndAlso DXSplashScreen.IsActive Then DXSplashScreen.Close()
|
||||
Throw New Exception(EX.Message, EX)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Shared Function ImportaRecibosFicsCias(bd As bdGestionAsegasa.gestionasegasaEntities, Ficheros As List(Of ficheroscompanias), Busqueda As String, MostrarProgreso As Boolean, GuardarCambios As Boolean, MarcarFicheros As Boolean, Optional ByRef ListadoRecibosDuplicados As List(Of String) = Nothing, Optional ByRef ListadoRecibosAnulados As List(Of String) = Nothing, Optional ByRef ListadoRecibosActualizados As List(Of String) = Nothing) As List(Of ReciboAIncorporar)
|
||||
Try
|
||||
If MostrarProgreso Then
|
||||
DXSplashScreen.Show(Of SplashScreenTecnosis)()
|
||||
DXSplashScreen.SetState("Incorporando recibos EIAC ...")
|
||||
End If
|
||||
' Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN()
|
||||
' Dim cia = bd.companias.First(Function(x) x.Codigo = Compañia)
|
||||
Dim lrai As New List(Of bdGestionAsegasa.ReciboAIncorporar)
|
||||
If Ficheros.Count > 0 Then
|
||||
Dim ficsag = Ficheros.GroupBy(Function(x) x.idCompania).ToList
|
||||
Dim ldur = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "DUR").ToList
|
||||
' Dim idTipoPagoCIA = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.CIA").idEnumeracion
|
||||
' Dim idTipoPagoFAE = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.CIA").idEnumeracion
|
||||
Dim TiposRecibos = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "TRC").ToList
|
||||
Dim agentes = bd.agentes.ToList
|
||||
Dim subagentes = bd.subagentes.ToList
|
||||
Dim ramos = bd.ramos.ToList
|
||||
Dim comsCiat = bd.comisionescompanias.ToList
|
||||
Dim comsAge = bd.comisionesagentes.ToList
|
||||
|
||||
Dim iNumFic As Integer = 0
|
||||
For Each grf In ficsag
|
||||
Dim idCompania = grf.First.idCompania
|
||||
Dim comsCia = bd.comisionescompanias.Where(Function(x) x.idCompania = idCompania).ToList
|
||||
Dim CodCia = grf.First.companias.Codigo
|
||||
Select Case CodCia
|
||||
Case "0037"
|
||||
ImportaRecibosPatriaHispana(bd, lrai, iNumFic, Ficheros.Count, grf.ToList, Busqueda, True, False, False, ListadoRecibosDuplicados)
|
||||
Case "0024"
|
||||
ImportaRecibosPrevisionMallorquina(bd, lrai, iNumFic, Ficheros.Count, grf.ToList, Busqueda, True, False, False, ListadoRecibosDuplicados)
|
||||
Case Else
|
||||
Dim pols = bd.polizassg.Include("entidadespolizas.entidades").Include("companias").Where(Function(x) x.idCompania = idCompania AndAlso x.NumeroPoliza IsNot Nothing).ToList
|
||||
Dim recs = ReciboReducido.ListadoReciboReducido(bd.recibos.Where(Function(x) x.polizassg.idCompania = idCompania))
|
||||
For Each f In grf
|
||||
iNumFic += 1
|
||||
Select Case f.Version.NothingAVacio
|
||||
Case "6.0"
|
||||
ImportaRecibosEIAC_V6(bd, f, iNumFic, Ficheros.Count, agentes, subagentes, ramos, comsCia, comsAge, pols, recs, TiposRecibos, lrai, Busqueda, MostrarProgreso, GuardarCambios, MarcarFicheros, ListadoRecibosDuplicados, ListadoRecibosAnulados)
|
||||
Case Else
|
||||
ImportaRecibosEIAC_V5(bd, f, iNumFic, Ficheros.Count, agentes, subagentes, ramos, comsCia, comsAge, pols, recs, TiposRecibos, lrai, Busqueda, MostrarProgreso, GuardarCambios, MarcarFicheros, ListadoRecibosDuplicados, ListadoRecibosAnulados)
|
||||
End Select
|
||||
Next
|
||||
End Select
|
||||
Next
|
||||
If GuardarCambios Then
|
||||
Dim rcc, rca, rnp, raa, rpec As List(Of ReciboAIncorporar)
|
||||
rcc = lrai.Where(Function(x) x.Correcto).ToList
|
||||
raa = lrai.Where(Function(x) x.Actualizado And x.Fecha_Procesado.HasValue = False).ToList
|
||||
rpec = lrai.Where(Function(x) x.PagadoEnCia And x.Fecha_Procesado.HasValue = False).ToList
|
||||
If ListadoRecibosAnulados IsNot Nothing Then
|
||||
Dim lra = ListadoRecibosAnulados
|
||||
rca = lrai.Where(Function(x) lra.Contains(x.Código_Recibo)).ToList
|
||||
rnp = lrai.Where(Function(x) x.Correcto = False And lra.Contains(x.Código_Recibo) = False).ToList
|
||||
Else
|
||||
rca = Nothing
|
||||
rnp = lrai.Where(Function(x) x.Correcto = False).ToList
|
||||
End If
|
||||
If MarcarFicheros Then
|
||||
GuardaRecibosEIAC(bd, rcc, ListadoRecibosAnulados, raa, rpec, MostrarProgreso, Ficheros, comsCiat, comsAge, ldur)
|
||||
Else
|
||||
GuardaRecibosEIAC(bd, rcc, ListadoRecibosAnulados, raa, rpec, MostrarProgreso, Nothing, comsCiat, comsAge, ldur)
|
||||
End If
|
||||
GeneraEmailRecibosIncorporados(rcc, rca, rnp, raa, rpec)
|
||||
End If
|
||||
End If
|
||||
If MostrarProgreso Then
|
||||
DXSplashScreen.Close()
|
||||
End If
|
||||
Return lrai
|
||||
Catch EX As Exception
|
||||
If MostrarProgreso AndAlso DXSplashScreen.IsActive Then DXSplashScreen.Close()
|
||||
Throw New Exception(EX.Message, EX) ' bdGestionAsegasa.Utilidades.AñadeLog(TipoLog.Fallo, "En ImportaRecibosEIAC " & Compañia, EX.Message, EX)
|
||||
End Try
|
||||
End Function
|
||||
Reference in New Issue
Block a user