3873 lines
247 KiB
VB.net
3873 lines
247 KiB
VB.net
Imports System.Data.Objects
|
|
Imports System.Globalization
|
|
Imports System.IO
|
|
Imports AccesoWSZurichDocumentos
|
|
Imports DevExpress.Spreadsheet
|
|
Imports DevExpress.Xpf.Core
|
|
Imports ProcesosEIAC_V6
|
|
Imports tsl5.Extensiones
|
|
Imports tsWPF
|
|
|
|
|
|
Partial Public Class recibos
|
|
#Region "Contabilidad"
|
|
Public ReadOnly Property Tomador As String
|
|
Get
|
|
If Me.polizassg IsNot Nothing Then
|
|
Return Me.polizassg.Tomador.RazonSocial
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property LiquidoCia As Double
|
|
Get
|
|
Return Math.Round(Me.TotalRecibo.Value - Me.TotalComision.Value, 2, MidpointRounding.AwayFromZero)
|
|
End Get
|
|
End Property
|
|
'Public ReadOnly Property FechaLimiteRemesaPago As Date?
|
|
' Get
|
|
' If Me.idRemesa.HasValue Then
|
|
' Dim excr = Me.polizassg.companias.excepcionesciasramos.FirstOrDefault(Function(x) x.idRamo = Me.polizassg.idRamo)
|
|
' If excr Is Nothing Then
|
|
' Return Me.remesas.Fecha.Value.AddDays(Me.polizassg.companias.PlazoRetornoComision * -1)
|
|
' Else
|
|
' Return Me.remesas.Fecha.Value.AddDays(excr.NumeroDiasRemesaPago * -1)
|
|
' End If
|
|
' Else
|
|
' Return Nothing
|
|
' End If
|
|
' End Get
|
|
'End Property
|
|
|
|
Public ReadOnly Property NumeroDiasRemesaPago As Integer
|
|
Get
|
|
If Me.idRemesa.HasValue Then
|
|
Dim excr = Me.polizassg.companias.excepcionesciasramos.FirstOrDefault(Function(x) x.idRamo = Me.polizassg.idRamo)
|
|
If excr Is Nothing Then
|
|
Return Me.polizassg.companias.PlazoRetornoComision
|
|
Else
|
|
Return excr.NumeroDiasRemesaPago
|
|
End If
|
|
Else
|
|
Return 0
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
|
|
Public ReadOnly Property FechaAsientoDevueltoBancoEspecial As Date?
|
|
Get
|
|
If Me.asientos IsNot Nothing Then
|
|
Return Me.asientos.Fecha
|
|
Else
|
|
Return FechaAsientoDevueltoBanco
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property FechaFacturacionEspecial As Date?
|
|
Get
|
|
If Me.asientos1 IsNot Nothing Then
|
|
Return Me.asientos1.Fecha
|
|
Else
|
|
Return Me.FechaFacturacion
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
#Region "LiquidacionesCIAS"
|
|
Public ReadOnly Property PrimeraLiquidacionCia As liquidacionescompaniasrecibos
|
|
Get
|
|
Return Me.liquidacionescompaniasrecibos.FirstOrDefault(Function(x) x.liquidacionescompanias.enumeraciones.Codigo = "TIPLIQ.LIQUIDACION")
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property PrimerDescobroACia As liquidacionescompaniasrecibos
|
|
Get
|
|
Return Me.liquidacionescompaniasrecibos.FirstOrDefault(Function(x) x.liquidacionescompanias.enumeraciones.Codigo = "TIPLIQ.DESCOBRO")
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property PrimeraDevolucionCia As liquidacionescompaniasrecibos
|
|
Get
|
|
Return Me.liquidacionescompaniasrecibos.FirstOrDefault(Function(x) x.liquidacionescompanias.enumeraciones.Codigo = "TIPLIQ.DEVUELTO")
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property idAsientoLiquidacionCia As Integer?
|
|
Get
|
|
If PrimeraLiquidacionCia IsNot Nothing Then
|
|
If PrimeraLiquidacionCia.liquidacionescompanias.idPagoLiquidacionCia.HasValue Then
|
|
Return PrimeraLiquidacionCia.liquidacionescompanias.pagosliquidacionescias.idAsiento
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property idAsientoDescobroCia As Integer?
|
|
Get
|
|
If PrimerDescobroACia IsNot Nothing Then
|
|
Return PrimerDescobroACia.liquidacionescompanias.idAsiento
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property FechaAsientoLiquidacionCia As Date?
|
|
Get
|
|
If PrimeraLiquidacionCia IsNot Nothing Then
|
|
If PrimeraLiquidacionCia.liquidacionescompanias.idPagoLiquidacionCia.HasValue Then
|
|
If PrimeraLiquidacionCia.liquidacionescompanias.pagosliquidacionescias.idAsiento.HasValue Then
|
|
Return PrimeraLiquidacionCia.liquidacionescompanias.pagosliquidacionescias.asientos.Fecha
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property idAsientoDevueltoCia As Integer?
|
|
Get
|
|
If PrimeraDevolucionCia IsNot Nothing Then
|
|
Return PrimeraDevolucionCia.liquidacionescompanias.idAsiento
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property FechaAsientoDevueltoCia As Date?
|
|
Get
|
|
If PrimeraDevolucionCia IsNot Nothing Then
|
|
Return PrimeraDevolucionCia.liquidacionescompanias.Fecha
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property FechaAsientoDescobroCia As Date?
|
|
Get
|
|
If PrimerDescobroACia IsNot Nothing Then
|
|
Return PrimerDescobroACia.liquidacionescompanias.Fecha
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
#Region "LiquidacionesAgentes"
|
|
Public ReadOnly Property PrimeraLiquidacionAgente As liquidacionesagenterecibos
|
|
Get
|
|
Return Me.liquidacionesagenterecibos.FirstOrDefault(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.LIQUIDACION")
|
|
End Get
|
|
End Property
|
|
|
|
'Public ReadOnly Property PrimerDescobroAAgente As liquidacionesagenterecibos
|
|
' Get
|
|
' Return Me.liquidacionesagenterecibos.FirstOrDefault(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.RETCOM")
|
|
' End Get
|
|
'End Property
|
|
|
|
|
|
|
|
Public ReadOnly Property idAsientoLiquidacionAgente As Integer?
|
|
Get
|
|
If PrimeraLiquidacionAgente IsNot Nothing Then
|
|
Return PrimeraLiquidacionAgente.liquidacionesagentes.idAsiento
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
'Public ReadOnly Property idAsientoDescobroAgente As Integer?
|
|
' Get
|
|
' If PrimerDescobroAAgente IsNot Nothing Then
|
|
' Return PrimerDescobroAAgente.liquidacionesagentes.idAsiento
|
|
' Else
|
|
' Return Nothing
|
|
' End If
|
|
' End Get
|
|
'End Property
|
|
|
|
Public ReadOnly Property FechaAsientoLiquidacionAgente As Date?
|
|
Get
|
|
If PrimeraLiquidacionAgente IsNot Nothing Then
|
|
Return PrimeraLiquidacionAgente.liquidacionesagentes.Fecha
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property FechaAsientoDescobroAgente As Date?
|
|
Get
|
|
If Me.regularizacionespagosagentes.Any Then
|
|
Return Me.regularizacionespagosagentes.OrderByDescending(Function(x) x.FechaCreacion).First.FechaCreacion
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
Public ReadOnly Property FechaAsientoRemesa As Date?
|
|
Get
|
|
If Me.remesas IsNot Nothing Then
|
|
If Me.remesas.asientos IsNot Nothing Then
|
|
Return Me.remesas.asientos.Fecha
|
|
Else
|
|
'Return Me.remesas.Fecha
|
|
Return Nothing
|
|
End If
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property idAsientoRemesaOContado As Integer?
|
|
Get
|
|
If Me.remesas IsNot Nothing Then
|
|
Return Me.remesas.idAsiento
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property FechaRemesa As Date
|
|
Get
|
|
If Me.remesas IsNot Nothing Then
|
|
Return Me.remesas.Fecha
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public Shared Function ContabilizaRecibosPagoAG() As Integer
|
|
Try
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN()
|
|
Dim idtippag = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.AG").idEnumeracion
|
|
Dim idSitPag = bd.enumeraciones.First(Function(X) X.Codigo = "SITR.PA").idEnumeracion
|
|
Dim Lag = bd.enumeraciones.Where(Function(x) x.gruposenumeraciones.Grupo = "LAPADFE").Select(Function(x) x.ValorAlfabetico1).ToList
|
|
Dim ListaAgentesDespuesFechaEfecto = bd.agentes.Where(Function(x) Lag.Contains(x.Codigo)).Select(Function(x) x.idAgente).ToList
|
|
Dim recsdfe = bd.vf_recibosextendidos.Where(Function(x) ListaAgentesDespuesFechaEfecto.Contains(x.idAgente) AndAlso x.idTipoPago = idtippag AndAlso x.FechaBaja.HasValue = False AndAlso x.FechaPago.HasValue = False AndAlso x.idRemesa.HasValue = False AndAlso Today >= x.FechaEfecto).ToList
|
|
Dim recs = recsdfe.Union(bd.vf_recibosextendidos.Where(Function(x) ListaAgentesDespuesFechaEfecto.Contains(x.idAgente) = False AndAlso x.idTipoPago = idtippag AndAlso x.FechaBaja.HasValue = False AndAlso x.FechaPago.HasValue = False AndAlso x.idRemesa.HasValue = False).ToList).ToList
|
|
|
|
' Dim recs = bd.recibos.Include("polizassg.companias").Where(Function(x) x.FechaPago.HasValue = False And x.FechaBaja.HasValue = False And x.idTipoPago = idtippag).ToList.Where(Function(r) r.idTipoPago = idtippag OrElse r.idRemesa.HasValue AndAlso Now.Date.Subtract(r.remesas.Fecha.Value.Date).TotalDays >= r.polizassg.companias.PlazoRetornoComision.Value).ToList
|
|
Dim lrp As New List(Of bdGestionAsegasa.recibos)
|
|
Dim NumeroAgrupamientos As Integer = 0
|
|
If recs.Count > 0 Then
|
|
Dim Cont = bd.enumeraciones.First(Function(x) x.Codigo = "CONT.NUMGEN")
|
|
Cont.ValorNumerico1 += 1
|
|
bd.SaveChanges()
|
|
|
|
Dim ej = bd.ejercicioscontables.First(Function(x) x.FechaInicio <= Today And x.FechaFin >= Today)
|
|
Dim recsagag = recs.GroupBy(Function(x) x.CodigoAgente).OrderBy(Function(x) x.FirstOrDefault.CodigoAgente).ToList
|
|
NumeroAgrupamientos = recsagag.Count
|
|
Dim Conceps = bd.conceptosapuntes.ToList
|
|
For Each rag In recsagag
|
|
Dim idagente = rag.First.CodigoAgente
|
|
Dim agente = bd.agentes.First(Function(x) x.Codigo = idagente)
|
|
Dim Cta2 As String = agente.CuentaContableR
|
|
If bd.cuentas.Any(Function(x) x.NumeroCuenta = Cta2 And x.idEjercicio = ej.idEjercicio) = False Then bdGestionAsegasa.cuentas.CreaCuenta(bd, ej.idEjercicio, Cta2, rag.First.Agente)
|
|
|
|
Dim na As New bdGestionAsegasa.asientos
|
|
bd.asientos.AddObject(na)
|
|
With na
|
|
.Fecha = Today
|
|
.idEjercicio = ej.idEjercicio
|
|
.Tipo = bdGestionAsegasa.asientos.TipoAsiento.NORMAL
|
|
.FechaIntroduccion = Now
|
|
If bdGestionAsegasa.Utilidades.dsc.idUsuario > 0 Then .idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario
|
|
End With
|
|
|
|
Dim recsag = rag.ToList.GroupBy(Function(x) x.CodigoCia).OrderBy(Function(x) x.First.CodigoCia)
|
|
For Each g In recsag
|
|
Dim Cta1 As String = "4400" & g.First.CodigoCia
|
|
If bd.cuentas.Any(Function(x) x.NumeroCuenta = Cta1 And x.idEjercicio = ej.idEjercicio) = False Then bdGestionAsegasa.cuentas.CreaCuenta(bd, ej.idEjercicio, Cta1, "RBOS A COBRAR " & g.First.Compania)
|
|
Next
|
|
|
|
For Each g In recsag
|
|
Dim nap1 As New bdGestionAsegasa.apuntes
|
|
With nap1
|
|
.asientos = na
|
|
Dim Cta As String = "4400" & g.First.CodigoCia
|
|
.idCuenta = bd.cuentas.First(Function(x) x.NumeroCuenta = Cta And x.idEjercicio = ej.idEjercicio).idCuenta
|
|
.Haber = Math.Round(g.Sum(Function(x) x.TotalRecibo.Value), 2, MidpointRounding.AwayFromZero)
|
|
.Debe = 0
|
|
.Concepto = (g.First.Agente & " " & g.First.Compania).Acortar(200)
|
|
.idConcepto = Conceps.First(Function(x) x.Codigo = "001").idConcepto
|
|
' .NumeroDocumento = remesa.idRemesa.ToString
|
|
End With
|
|
na.apuntes.Add(nap1)
|
|
Next
|
|
Dim Cta3 As String = agente.CuentaContableR
|
|
Dim idCta3 = bd.cuentas.First(Function(x) x.NumeroCuenta = Cta3 And x.idEjercicio = ej.idEjercicio).idCuenta
|
|
For Each r In rag
|
|
Dim nap2 As New bdGestionAsegasa.apuntes
|
|
With nap2
|
|
.asientos = na
|
|
.idCuenta = idCta3
|
|
.Debe = Math.Round(r.TotalRecibo.Value, 2, MidpointRounding.AwayFromZero) ' Math.Round(rag.Sum(Function(x) x.TotalRecibo.Value), 2, MidpointRounding.AwayFromZero)
|
|
.Haber = 0
|
|
.Concepto = agente.Nombre & " Rec.:" & r.CodigoRecibo
|
|
.idConcepto = Conceps.First(Function(X) X.Codigo = "001").idConcepto
|
|
' .NumeroDocumento = remesa.idRemesa.ToString
|
|
End With
|
|
na.apuntes.Add(nap2)
|
|
na.Importe = Math.Round(na.apuntes.Sum(Function(x) x.Debe), 2, MidpointRounding.AwayFromZero)
|
|
Next
|
|
' bd.SaveChanges()
|
|
Next
|
|
For Each v_r In recs
|
|
Dim r = bd.recibos.First(Function(x) x.idRecibo = v_r.idRecibo)
|
|
r.FechaPago = Now
|
|
r.idSituacion = idSitPag
|
|
lrp.Add(r)
|
|
'Dim reg As New registrosactualizados
|
|
'With reg
|
|
' .Tipo = "RECIBOS"
|
|
' .idAplicacion = r.idRecibo
|
|
' .MacroAct = "EFPAGMYSQL"
|
|
' .NumeroGeneracion = Cont.ValorNumerico1
|
|
' ' .FechaCreacion = Ahora
|
|
'End With
|
|
'bd.registrosactualizados.AddObject(reg)
|
|
Next
|
|
bd.GuardarCambios()
|
|
bd.ExecuteStoreCommand("UPDATE registrosactualizados SET FechaCreacion=Now() where FechaCreacion Is null and NumeroGeneracion=" & Cont.ValorNumerico1.ToString & ";")
|
|
End If
|
|
|
|
Dim sDestinatarios = bd.enumeraciones.First(Function(X) X.Codigo = "CONF.EMAILCONTA").ValorAlfabeticoLargo
|
|
Dim ctac = bd.cuentascorreo.First(Function(x) x.Codigo = "SEG.GENERALES")
|
|
|
|
If lrp.Count > 0 Then
|
|
Dim lr = lrp.Select(Function(x) New With {.CodigoRecibo = x.CodigoRecibo, .NumeroPoliza = x.polizassg.NumeroPoliza, .NumeroSuplemento = x.polizassg.NumeroSuplemento, .Tomador = x.polizassg.Tomador.RazonSocial, .BienesAsegurados = x.polizassg.BienesAsegurados, .Ramo = x.polizassg.ramos.Descripcion, .Compañia = x.polizassg.companias.Nombre, .Agente = x.agentes.Nombre}).ToList
|
|
Dim f = tsWPF.Utilidades.Varias.IEnumerableAExcel(lr)
|
|
bdGestionAsegasa.correos.GeneraRegistroCorreoConAdjunto(bd, "Se han marcado " & recs.Count.ToString & " Recibos (Tipo Pago Agente) como Pagados y se ha generado su apunte contable", "Adjunto le remitimos listado de recibos marcados como pagados (Tipo Pago Agente)", ctac, f, "PagosAG-" & Now.ToString("yyyy-MM-dd") & ".xlsx", "Listado Recibos Pagado (Tipo Pago AG) " & Now.ToString("yyyy-MM-dd"), sDestinatarios,, "sevilla@tecnosis.net")
|
|
End If
|
|
Return NumeroAgrupamientos
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Function
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
#Region "Comisiones"
|
|
Public ReadOnly Property PorcentajeComisionRecargoExterno As Double
|
|
Get
|
|
Return If(Me.RecargoExterno.HasValue = False OrElse Me.RecargoExterno = 0 OrElse Me.AsegasaRecargoExterno.HasValue = False OrElse Me.AsegasaRecargoExterno.Value = 0, 0, Math.Round(Me.AsegasaRecargoExterno.Value * 100 / Me.RecargoExterno.Value, 2, MidpointRounding.AwayFromZero))
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property PorcentajeComisionConsorcio As Double
|
|
Get
|
|
Return If(Me.Consorcio.HasValue = False OrElse Me.Consorcio = 0 OrElse Me.AsegasaComisionConsorcio.HasValue = False OrElse Me.AsegasaComisionConsorcio.Value = 0, 0, Math.Round(Me.AsegasaComisionConsorcio.Value * 100 / Me.Consorcio.Value, 2, MidpointRounding.AwayFromZero))
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property PorcentajeComisionAsegasa As Double
|
|
Get
|
|
Return If(Me.TotalComision.HasValue = False OrElse Me.TotalComision = 0 OrElse Me.AsegasaComisionTotal.HasValue = False, 0, Math.Round(Me.AsegasaComisionTotal.Value * 100 / Me.TotalComision.Value, 2, MidpointRounding.AwayFromZero))
|
|
End Get
|
|
End Property
|
|
|
|
|
|
Public Function ObtieneDatosComisiones() As List(Of DatoComision)
|
|
Try
|
|
Dim ldcs As New List(Of DatoComision)
|
|
Dim dc As New DatoComision
|
|
With dc
|
|
.Concepto = "Prima Neta"
|
|
.Base = Math.Round(PrimaNeta.Value + BonificacionORecargo.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Porcentaje = Math.Round(PorcentajeReciboPrimaNeta.Value, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionBruta = Math.Round(ComisionReciboPrimaNeta.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Sobrecomision = Math.Round(Sobrecomision.NothingA0, 2, MidpointRounding.AwayFromZero)
|
|
.TotalComision = Math.Round(TotalComision.Value, 2, MidpointRounding.AwayFromZero)
|
|
.PorcentajeComisionPrevista = Math.Round(PorcentajeComisionPrevista.Value, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionPrevista = Math.Round(ComisionPrevista.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Diferencia = Math.Round(.ComisionBruta - ComisionPrevista.Value, 2, MidpointRounding.AwayFromZero)
|
|
End With
|
|
ldcs.Add(dc)
|
|
|
|
Dim dcre As New DatoComision
|
|
With dcre
|
|
.Concepto = "Recargos Externos"
|
|
.Base = Math.Round(RecargoExterno.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Porcentaje = Math.Round(PorcentajeComisionRecargoExterno, 2, MidpointRounding.AwayFromZero)
|
|
.Sobrecomision = 0
|
|
.TotalComision = Math.Round(AsegasaRecargoExterno.Value, 2, MidpointRounding.AwayFromZero)
|
|
' .ComisionBruta = Math.Round(.TotalComision - .Sobrecomision, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionBruta = Math.Round(.TotalComision, 2, MidpointRounding.AwayFromZero)
|
|
.PorcentajeComisionPrevista = .Porcentaje
|
|
.ComisionPrevista = .TotalComision
|
|
.Diferencia = Math.Round(.TotalComision - .ComisionPrevista, 2, MidpointRounding.AwayFromZero)
|
|
End With
|
|
ldcs.Add(dcre)
|
|
Dim dcco As New DatoComision
|
|
With dcco
|
|
.Concepto = "Consorcio"
|
|
.Base = Math.Round(Consorcio.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Porcentaje = Math.Round(PorcentajeComisionConsorcio, 2, MidpointRounding.AwayFromZero)
|
|
.Sobrecomision = 0
|
|
.TotalComision = Math.Round(AsegasaComisionConsorcio.Value, 2, MidpointRounding.AwayFromZero)
|
|
' .ComisionBruta = Math.Round(.TotalComision - .Sobrecomision, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionBruta = Math.Round(.TotalComision, 2, MidpointRounding.AwayFromZero)
|
|
.PorcentajeComisionPrevista = .Porcentaje
|
|
.ComisionPrevista = .TotalComision
|
|
.Diferencia = Math.Round(.TotalComision - .ComisionPrevista, 2, MidpointRounding.AwayFromZero)
|
|
End With
|
|
ldcs.Add(dcco)
|
|
Dim dcag As New DatoComision
|
|
With dcag
|
|
.Concepto = "AGENTE"
|
|
.Base = Math.Round(BaseComisionAgente.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Porcentaje = Math.Round(PorcentajeComisionAgente.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Sobrecomision = 0
|
|
.TotalComision = Math.Round(ComisionAgente.Value, 2, MidpointRounding.AwayFromZero)
|
|
' .ComisionBruta = Math.Round(.TotalComision - .Sobrecomision, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionBruta = Math.Round(.TotalComision, 2, MidpointRounding.AwayFromZero)
|
|
.PorcentajeComisionPrevista = .Porcentaje
|
|
.ComisionPrevista = .TotalComision
|
|
.Diferencia = Math.Round(.TotalComision - .ComisionPrevista, 2, MidpointRounding.AwayFromZero)
|
|
End With
|
|
ldcs.Add(dcag)
|
|
Dim dcAS As New DatoComision
|
|
With dcAS
|
|
.Concepto = "ASEGASA"
|
|
.Base = Math.Round(TotalComision.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Porcentaje = Math.Round(PorcentajeComisionAsegasa, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionBruta = Math.Round(AsegasaComisionTotal.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Sobrecomision = Math.Round(Sobrecomision.NothingA0, 2, MidpointRounding.AwayFromZero)
|
|
.TotalComision = Math.Round(AsegasaComisionTotal.Value + Sobrecomision.NothingA0, 2, MidpointRounding.AwayFromZero)
|
|
.PorcentajeComisionPrevista = .Porcentaje
|
|
.ComisionPrevista = .TotalComision
|
|
.Diferencia = Math.Round(.ComisionBruta - .ComisionPrevista, 2, MidpointRounding.AwayFromZero)
|
|
End With
|
|
ldcs.Add(dcAS)
|
|
Return ldcs
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Function
|
|
|
|
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
|
|
#End Region
|
|
Public Property BloquearFacturacion As Boolean
|
|
Get
|
|
If Utilidades.idSitr1.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Utilidades.idSitr1 = bd.enumeraciones.First(Function(x) x.Codigo = "SITR.1").idEnumeracion
|
|
End If
|
|
Return If(Me.idSituacion.HasValue = False, False, (Me.idSituacion.Value = Utilidades.idSitr1))
|
|
End Get
|
|
Set(value As Boolean)
|
|
If Utilidades.idSitr1.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Utilidades.idSitr1 = bd.enumeraciones.First(Function(x) x.Codigo = "SITR.1").idEnumeracion
|
|
End If
|
|
If value Then
|
|
Me.idSituacion = Utilidades.idSitr1
|
|
Else
|
|
Me.idSituacion = Nothing
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Public Property idAgente_Nulable As Integer?
|
|
Get
|
|
If Me.idAgente = 0 Then
|
|
Return Nothing
|
|
Else
|
|
Return Me.idAgente
|
|
End If
|
|
End Get
|
|
Set(value As Integer?)
|
|
If value.HasValue Then Me.idAgente = value.Value
|
|
OnPropertyChanged("idCliente_Nulable")
|
|
End Set
|
|
End Property
|
|
|
|
Friend Shared Sub GuardandoCambios(bd As bdGestionAsegasa.gestionasegasaEntities, Aplicacion As String)
|
|
Dim recs As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
Dim pols As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
Dim ents As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
Dim eps As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
Dim dirs As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
Dim docsp As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
Dim gests As IEnumerable(Of ObjectStateEntry) = Nothing
|
|
recs = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "recibos")
|
|
pols = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "polizassg")
|
|
eps = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "entidadespolizas")
|
|
ents = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "entidades")
|
|
dirs = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "direcciones")
|
|
docsp = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "documentospolizassg")
|
|
gests = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Where(Function(x) x.EntitySet.Name.ToLower = "gestionespolizassg")
|
|
|
|
Try
|
|
|
|
Dim bdtmp = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN
|
|
Dim su = If(bd.Aplicacion IsNot Nothing, bd.Aplicacion.ModoSuperUsuario, False)
|
|
For Each m In recs
|
|
Dim ra = DirectCast(m.Entity, recibos)
|
|
Dim reant = bdtmp.recibos.First(Function(x) x.idRecibo = ra.idRecibo)
|
|
Dim lrec = bdGestionAsegasa.logs.GeneraLog(bdtmp, "RECIBOS", reant.idRecibo, Nothing, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(reant), su, Aplicacion)
|
|
Dim polant = bdtmp.polizassg.First(Function(x) x.idPoliza = reant.idPoliza)
|
|
If reant.idRemesa.HasValue Then bdGestionAsegasa.logs.GeneraLog(bdtmp, "REMESAS", reant.idRemesa, lrec, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(reant.remesas), su, Aplicacion)
|
|
If reant.asientos IsNot Nothing Then bdGestionAsegasa.logs.GeneraLog(bdtmp, "ASIENTODEVUELTOBANCO", reant.idRecibo, lrec, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(reant.asientos), su, Aplicacion)
|
|
If reant.asientos1 IsNot Nothing Then bdGestionAsegasa.logs.GeneraLog(bdtmp, "ASIENTOFACTURACION", reant.idRecibo, lrec, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(reant.asientos1), su, Aplicacion)
|
|
Dim lr = bdGestionAsegasa.logs.GeneraLog(bdtmp, "POLIZASSG", reant.idPoliza, lrec, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(polant), su, Aplicacion)
|
|
|
|
Dim lep = polant.entidadespolizas.ToList
|
|
bdGestionAsegasa.logs.GeneraLog(bdtmp, "ENTIDADESPOLIZAS", reant.idPoliza, lrec, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(lep), su, Aplicacion)
|
|
For Each ent In lep
|
|
Dim lrent = bdGestionAsegasa.logs.GeneraLog(bdtmp, "ENTIDADES", ent.idEntidad, lr, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(ent.entidades), su, Aplicacion)
|
|
If ent.entidades.direcciones1 IsNot Nothing Then bdGestionAsegasa.logs.GeneraLog(bdtmp, "DIRECCIONES", ent.entidades.direcciones1.idDireccion, lrent, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(ent.entidades.direcciones1), su, Aplicacion)
|
|
Next
|
|
Dim ges = reant.gestionesrecibos.ToList
|
|
bdGestionAsegasa.logs.GeneraLog(bdtmp, "GESTIONESRECIBOS", reant.idRecibo, lrec, "REGISTRO_COMPLETO", tsl5.Utilidades.Serializar(ges), su, Aplicacion)
|
|
Next
|
|
Catch ex As Exception
|
|
Dim sListaCambios As String = ""
|
|
If pols IsNot Nothing Then
|
|
For Each m In pols
|
|
Dim ra = DirectCast(m.Entity, polizassg)
|
|
sListaCambios &= "polizassg idPoliza:" & ra.idPoliza & "; "
|
|
Next
|
|
End If
|
|
sListaCambios = sListaCambios.Trim.TrimEnd(";") & vbCrLf
|
|
If ents IsNot Nothing Then
|
|
For Each m In ents
|
|
Dim ra = DirectCast(m.Entity, entidades)
|
|
sListaCambios &= "entidades idEntidad:" & ra.idEntidad & "; "
|
|
Next
|
|
End If
|
|
sListaCambios = sListaCambios.Trim.TrimEnd(";") & vbCrLf
|
|
If eps IsNot Nothing Then
|
|
For Each m In eps
|
|
Dim ra = DirectCast(m.Entity, entidadespolizas)
|
|
sListaCambios &= "entidadespoliza idEntidadPoliza:" & ra.idEntidadPoliza & "; "
|
|
Next
|
|
End If
|
|
sListaCambios = sListaCambios.Trim.TrimEnd(";") & vbCrLf
|
|
If dirs IsNot Nothing Then
|
|
For Each m In dirs
|
|
Dim ra = DirectCast(m.Entity, direcciones)
|
|
sListaCambios &= "direcciones idDireccion:" & ra.idDireccion & "; "
|
|
Next
|
|
End If
|
|
If docsp IsNot Nothing Then
|
|
For Each m In docsp
|
|
Dim ra = DirectCast(m.Entity, documentospolizassg)
|
|
sListaCambios &= "documentos idDocumento:" & ra.idDocumento & "; "
|
|
Next
|
|
End If
|
|
If gests IsNot Nothing Then
|
|
For Each m In dirs
|
|
Dim ra = DirectCast(m.Entity, gestionespolizassg)
|
|
sListaCambios &= "direcciones idGestionPoliza:" & ra.idGestionPoliza & "; "
|
|
Next
|
|
End If
|
|
Call Utilidades.AñadeLog(tsl5.Enumeraciones.TipoLog.Fallo, "En GuardandoCambios", ex.Message & vbCrLf & sListaCambios, ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Public ReadOnly Property NombreSubAgente As String
|
|
Get
|
|
If Me.idSubagente.HasValue Then
|
|
Return subagentes.ListaSubAgentes.First(Function(x) x.idSubagente = Me.idSubagente).Nombre
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public Sub RefrescaNombreSubAgente()
|
|
Me.OnPropertyChanged("NombreSubAgente")
|
|
End Sub
|
|
|
|
Private Shared _idCabaSUPL As Integer?
|
|
Public Shared Function idCabaSUPL() As Integer
|
|
If _idCabaSUPL.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
_idCabaSUPL = bd.enumeraciones.First(Function(x) x.Codigo = "CABA.SUPL").idEnumeracion
|
|
End If
|
|
Return _idCabaSUPL
|
|
End Function
|
|
|
|
Private Shared _idCabaFP As Integer?
|
|
Public Shared Function idCabaFP() As Integer
|
|
If _idCabaFP.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
_idCabaFP = bd.enumeraciones.First(Function(x) x.Codigo = "CABA.FP").idEnumeracion
|
|
End If
|
|
Return _idCabaFP
|
|
End Function
|
|
Private Shared _idCabaCIE As Integer?
|
|
Public Shared Function idCabaCIE() As Integer
|
|
If _idCabaCIE.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
_idCabaCIE = bd.enumeraciones.First(Function(x) x.Codigo = "CABA.CIE").idEnumeracion
|
|
End If
|
|
Return _idCabaCIE
|
|
End Function
|
|
|
|
Private Shared ListadoBancos As List(Of bancos)
|
|
Private Shared _idTippba As Integer?
|
|
Private Shared _idTippCIA As Integer?
|
|
Private Shared _idTippFAE As Integer?
|
|
Private Sub RellenaListadoBancos()
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
ListadoBancos = bd.bancos.ToList
|
|
End Sub
|
|
Public Shared Function idTippBA() As Integer
|
|
If _idTippba.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
_idTippba = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.BA").idEnumeracion
|
|
End If
|
|
Return _idTippba
|
|
End Function
|
|
|
|
Public Shared Function idtippCIA() As Integer
|
|
If _idTippCIA.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
_idTippCIA = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.CIA").idEnumeracion
|
|
End If
|
|
Return _idTippCIA
|
|
End Function
|
|
Public Shared Function idtippFAE() As Integer
|
|
If _idTippFAE.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
_idTippFAE = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.FAE").idEnumeracion
|
|
End If
|
|
Return _idTippFAE
|
|
End Function
|
|
|
|
Public ReadOnly Property DiferenciaComision As Double
|
|
Get
|
|
Dim cp As Double = If(Me.ComisionPrevistaAsegasa.HasValue, Me.ComisionPrevistaAsegasa.Value, 0)
|
|
If cp = 0 Then cp = If(Me.ComisionPrevista.HasValue, Me.ComisionPrevista.Value, 0)
|
|
Dim c As Double = If(Me.ComisionReciboPrimaNeta.HasValue, Me.ComisionReciboPrimaNeta.Value, 0)
|
|
Return c - cp
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property DiferenciaComisionAgente As Double
|
|
Get
|
|
Dim cp As Double = If(Me.ComisionPrevista.HasValue, Me.ComisionPrevista.Value, 0)
|
|
Dim c As Double = If(Me.ComisionReciboPrimaNeta.HasValue, Me.ComisionReciboPrimaNeta.Value, 0)
|
|
Return c - cp
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property idSubAgente_Especial As Integer?
|
|
Get
|
|
If Me.idSubagente.HasValue AndAlso Me.agentes.Codigo = "000047002186" Then
|
|
Dim bd As gestionasegasaEntities = Me.ObtieneContexto
|
|
Dim Codigo = Me.subagentes.Codigo.Substring(0, 2) & "00"
|
|
Dim subage = bd.subagentes.FirstOrDefault(Function(x) x.idAgente = Me.idAgente And x.Codigo = Codigo)
|
|
If subage IsNot Nothing Then
|
|
Return subage.idSubagente
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
Else
|
|
Return idSubagente
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property Banco As String
|
|
Get
|
|
If ListadoBancos Is Nothing Then RellenaListadoBancos()
|
|
If Me.IBAN.NothingAVacio <> "" Then
|
|
If Me.IBAN.Length <> 24 Then
|
|
Return "** IBAN ERRONEO **"
|
|
Else
|
|
Dim codban = Me.IBAN.Substring(4, 4)
|
|
Dim b = ListadoBancos.FirstOrDefault(Function(x) x.Codigo = codban)
|
|
If b IsNot Nothing Then
|
|
Return b.Nombre
|
|
Else
|
|
Return ""
|
|
End If
|
|
End If
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property IBAN_Parcial As String
|
|
Get
|
|
If Me.IBAN.NothingAVacio.Length <> 24 Then
|
|
Return "** IBAN ERRONEO **"
|
|
Else
|
|
Return Me.IBAN.Substring(0, 10) & "XXXXXXXX" & Me.IBAN.Substring(18)
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property IBANCorrecto As Boolean
|
|
Get
|
|
If Me.idTipoPago = idTippBA() Then
|
|
Return tsl5.Bancos.Genericas.IBANCorrecto(Me.IBAN)
|
|
Else
|
|
Return True
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
|
|
|
|
Public ReadOnly Property OficinaAgente As String
|
|
Get
|
|
If Me.agentes IsNot Nothing Then
|
|
Return Me.agentes.OficinaAgente
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property DescripcionSuplemento As String
|
|
Get
|
|
If Me.polizassg.recibos.Any Then
|
|
If Me.polizassg.recibos.OrderBy(Function(x) x.FechaEfecto).First.idRecibo = Me.idRecibo Then
|
|
Return Me.polizassg.DescripcionSuplemento
|
|
Else
|
|
Return ""
|
|
End If
|
|
Else
|
|
Return Me.polizassg.DescripcionSuplemento
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public Property FormaComunicacionTMP As FormaComunicacionEnum
|
|
Public ReadOnly Property DescripcionFormaComunicacion As String
|
|
Get
|
|
Return FormaComunicacionTMP.ToString.Replace("_", " ")
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property DescripcionFormaPago As String
|
|
Get
|
|
If Me.idTipoPago.HasValue Then
|
|
Return Me.enumeraciones2.Descripcion
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
|
|
Public ReadOnly Property Estado As EstadoRecibo
|
|
Get
|
|
Dim est As EstadoRecibo = EstadoRecibo.PENDIENTE
|
|
If Me.idRemesa.HasValue Then est = EstadoRecibo.REMESADO
|
|
If Me.idTipoPago = gestionasegasaEntities.TipoPagoCia OrElse Me.idTipoPago = gestionasegasaEntities.TipoPagoFAE Then est = EstadoRecibo.GESTION_COBRO_CIA
|
|
If Me.FechaLiquidacionAgente.HasValue Then est = EstadoRecibo.LIQUIDADO
|
|
If Me.FechaBaja.HasValue Then est = EstadoRecibo.BAJA
|
|
If Me.FechaDevolucionBanco.HasValue Then est = EstadoRecibo.DEVUELTO_BANCO
|
|
' If Me.FechaDevolucionCompania.HasValue Then est = EstadoRecibo.DEVUELTO_CIA
|
|
Return est
|
|
End Get
|
|
End Property
|
|
|
|
|
|
|
|
Public ReadOnly Property NombreBanco As String
|
|
Get
|
|
If Me.IBAN.NothingAVacio <> "" Then
|
|
If IBAN.Length = 24 Then 'IBAN.Length <> 24 Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto()
|
|
Dim banco = bd.bancos.Where(Function(x) x.Codigo = IBAN.Substring(4, 4))
|
|
If banco.Any Then
|
|
Return banco.First.Nombre
|
|
Else
|
|
Return "** DESCONOCIDO **"
|
|
End If
|
|
Else
|
|
Return "** IBAN ERRONEO **"
|
|
End If
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property idLiquidacionAgente As Integer
|
|
Get
|
|
If Me.liquidacionesagenterecibos.Any(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.LIQUIDACION") Then
|
|
Return Me.liquidacionesagenterecibos.Where(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.LIQUIDACION").OrderByDescending(Function(x) x.liquidacionesagentes.Fecha).First.liquidacionesagentes.idLiquidacionAgente
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property FechaLiquidacionAgente As Date?
|
|
Get
|
|
If Me.liquidacionesagenterecibos.Any(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.LIQUIDACION") Then
|
|
Return Me.liquidacionesagenterecibos.Where(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.LIQUIDACION").OrderByDescending(Function(x) x.liquidacionesagentes.Fecha).First.liquidacionesagentes.Fecha
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property CausaDevolucion As String
|
|
Get
|
|
If Me.enumeraciones4 IsNot Nothing Then
|
|
Return Me.enumeraciones4.Descripcion
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property TipoRecibo As String
|
|
Get
|
|
If Me.enumeraciones1 IsNot Nothing Then
|
|
Return Me.enumeraciones1.Descripcion
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property CausaBaja As String
|
|
Get
|
|
If Me.enumeraciones3 IsNot Nothing Then
|
|
Return Me.enumeraciones3.Descripcion
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property TipoPago As String
|
|
Get
|
|
If Me.enumeraciones2 IsNot Nothing Then
|
|
Return Me.enumeraciones2.Descripcion
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property CamposAComprobar As String
|
|
Get
|
|
Dim sFechaBaja As String = If(Me.FechaBaja.HasValue, Me.FechaBaja.Value.ToString("yyyyMMdd"), "0")
|
|
Dim sFechaPago As String = If(Me.FechaPago.HasValue, Me.FechaPago.Value.ToString("yyyyMMdd"), "0")
|
|
Dim sFechaRemesa As String = If(Me.idRemesa.HasValue, Me.remesas.Fecha.Value.ToString("yyyyMMdd"), "0")
|
|
Dim sNumeroRemesa As String = If(Me.idRemesa.HasValue, Me.remesas.idRemesa.ToString, "")
|
|
Return (Me.CodigoRecibo & "|" & sFechaBaja & "|" & sFechaPago & "|" & sFechaRemesa & "|" & sNumeroRemesa)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property LimiteEfectoSobrePasadoFechaBaja As Boolean
|
|
Get
|
|
Dim DiasLimite As Integer
|
|
If Me.TipoRecibo.Contains("CARTERA") Then
|
|
DiasLimite = Me.polizassg.companias.NumeroDiasLimiteFBCartera
|
|
Else
|
|
DiasLimite = Me.polizassg.companias.NumeroDiasLimiteFBEmision
|
|
End If
|
|
Return Me.FechaEfecto < Today.AddDays(DiasLimite)
|
|
End Get
|
|
End Property
|
|
Public Enum TipoOrigenRecibo
|
|
OTROS = 0
|
|
IMPORTACION_EIAC = 1
|
|
End Enum
|
|
Public Enum EstadoRecibo
|
|
PENDIENTE = 0 'NEGRO
|
|
REMESADO = 1 ' AZUL
|
|
GESTION_COBRO_CIA = 2 'VERDE
|
|
DEVUELTO_BANCO = 3 'NARANJA
|
|
BAJA = 4 'MARRON
|
|
' DEVUELTO_CIA = 5 'ROJO
|
|
LIQUIDADO = 6 ' VIOLETA
|
|
End Enum
|
|
|
|
|
|
#Region "CartasAvisos"
|
|
Public Shared Function ObtieneRecibosAvisoImperativoLegal(Optional bd As bdGestionAsegasa.gestionasegasaEntities = Nothing, Optional RecibosSinComunicacion As List(Of String) = Nothing) As List(Of recibos)
|
|
|
|
If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Dim tgsms As Integer = FormaComunicacionEnum.POR_SMS
|
|
Dim tgcarta As Integer = FormaComunicacionEnum.POR_CARTA
|
|
Dim tgsa As Integer = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO
|
|
Dim tgsn As Integer = FormaComunicacionEnum.NINGUNA
|
|
Dim TipoCarta As Integer = TipoGestionEnum.AVISO_IMPERATIVO_LEGAL
|
|
|
|
|
|
'Dim idTre = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.E").idEnumeracion
|
|
'Dim idTres = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.ES").idEnumeracion
|
|
Dim idTrex = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.EX").idEnumeracion
|
|
'Dim idTrc = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.C").idEnumeracion
|
|
'Dim idTrcs = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.CS").idEnumeracion
|
|
Dim idTrcx = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.CX").idEnumeracion
|
|
Dim idtippba = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.BA").idEnumeracion
|
|
Dim idtipcia = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.CIA").idEnumeracion
|
|
Dim idtipFAE = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.FAE").idEnumeracion
|
|
' Dim idtippe = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.PE").idEnumeracion
|
|
Dim idtipag = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.AG").idEnumeracion
|
|
' Dim idtipag = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.AG").idEnumeracion
|
|
|
|
Dim TipoRemesa = TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO
|
|
|
|
Dim FechaLimite = Today.AddDays(-15)
|
|
Dim feflim = Today.AddDays(-10)
|
|
' Dim FechaEfectoLimite = Today.AddDays(25)
|
|
Dim FechaEfectoLimite = Today.AddDays(30)
|
|
'Dim rs = bd.recibos.
|
|
' Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones3").
|
|
' Where(Function(x) x.PrimaNeta.Value > 0 And x.FechaPago.HasValue = False And
|
|
' x.FechaBaja.HasValue = False And x.idTipoPago <> idtippba And x.idTipoPago <> idtipag And x.idTipoPago <> idtipcia And x.idTipo <> idTrex And x.idTipo <> idTrcx _
|
|
' And Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCarta) _
|
|
' And x.gestionesrecibos.Any(Function(y) y.Tipo = TipoRemesa And y.Fecha <= FechaLimite) _
|
|
' And x.FechaEfecto > feflim).ToList
|
|
Dim rsco = bd.recibos.
|
|
Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones3").
|
|
Where(Function(x) x.PrimaNeta.Value > 0 AndAlso x.FechaPago.HasValue = False And
|
|
x.FechaBaja.HasValue = False AndAlso x.idTipoPago <> idtippba And x.idTipoPago <> idtipag AndAlso x.idTipoPago <> idtipcia AndAlso x.idTipoPago <> idtipFAE AndAlso x.idTipo <> idTrex AndAlso x.idTipo <> idTrcx _
|
|
AndAlso Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCarta) _
|
|
AndAlso x.gestionesrecibos.Any(Function(y) y.Tipo = TipoRemesa And y.Fecha <= FechaLimite) _
|
|
AndAlso x.FechaEfecto < feflim AndAlso FechaEfectoLimite >= x.FechaEfecto).ToList.Where(Function(x) x.BloquearFacturacion = False).ToList
|
|
|
|
Dim rsba = bd.recibos.
|
|
Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones3").
|
|
Where(Function(x) x.PrimaNeta.Value > 0 AndAlso x.FechaPago.HasValue = False AndAlso x.FechaDevolucionBanco.HasValue AndAlso
|
|
x.FechaBaja.HasValue = False AndAlso x.idTipoPago = idtippba And x.idTipo <> idTrex AndAlso x.idTipo <> idTrcx _
|
|
AndAlso Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCarta) _
|
|
AndAlso x.gestionesrecibos.Any(Function(y) y.Tipo = TipoRemesa AndAlso y.Fecha <= FechaLimite) _
|
|
AndAlso x.FechaEfecto < feflim AndAlso FechaEfectoLimite >= x.FechaEfecto).ToList.Where(Function(x) x.BloquearFacturacion = False).ToList
|
|
|
|
Dim rs = rsco.Union(rsba).ToList
|
|
|
|
Dim lr = rs.Select(Function(x) New With {.CodigoRecibo = x.CodigoRecibo, .NumeroPoliza = x.polizassg.NumeroPoliza, .NumeroSuplemento = x.polizassg.NumeroSuplemento, .FechaEfecto = x.FechaEfecto, .TipoPago = x.TipoPago, .FechaDevolucionBanco = x.FechaDevolucionBanco, .Tomador = x.polizassg.Tomador.RazonSocial, .BienesAsegurados = x.polizassg.BienesAsegurados, .Ramo = x.polizassg.ramos.Descripcion, .Compañia = x.polizassg.companias.Nombre, .Agente = x.agentes.Nombre}).ToList
|
|
'Dim f = tsWPF.Utilidades.Varias.IEnumerableAExcel(lr)
|
|
'IO.File.WriteAllBytes("c:\tmp\recibosimperativo.xlsx", f)
|
|
|
|
|
|
For Each r In rs
|
|
If RecibosSinComunicacion IsNot Nothing AndAlso RecibosSinComunicacion.Contains(r.CodigoRecibo) Then
|
|
r.FormaComunicacionTMP = tgsn
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido Or r.polizassg.EntidadPolizaTomador.Telefono2.EsNumeroTelefonoMovilEspañolValido Then
|
|
r.FormaComunicacionTMP = tgsms
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador.direcciones IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.CodigoPostal.NothingAVacio <> "" AndAlso r.polizassg.EntidadPolizaTomador.direcciones.municipios IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.Direccion.NothingAVacio <> "" Then
|
|
r.FormaComunicacionTMP = tgcarta
|
|
Else
|
|
r.FormaComunicacionTMP = tgsa
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
Return rs
|
|
End Function
|
|
|
|
Public Shared Function ObtieneRecibosCartaRemesa(Optional bd As bdGestionAsegasa.gestionasegasaEntities = Nothing) As List(Of recibos)
|
|
Try
|
|
If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Dim tgninguna As Integer = FormaComunicacionEnum.NINGUNA
|
|
Dim tgsms As Integer = FormaComunicacionEnum.POR_SMS
|
|
Dim tgcarta As Integer = FormaComunicacionEnum.POR_CARTA
|
|
Dim tgsa As Integer = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO
|
|
' Dim idRamo17 = bd.ramos.First(Function(x) x.Codigo = "17").idRamo
|
|
Dim idTre = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.E").idEnumeracion
|
|
Dim idTres = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.ES").idEnumeracion
|
|
Dim idTrex = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.EX").idEnumeracion
|
|
Dim idTrc = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.C").idEnumeracion
|
|
Dim idTrcs = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.CS").idEnumeracion
|
|
Dim idTrcx = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.CX").idEnumeracion
|
|
Dim idtippba = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.BA").idEnumeracion
|
|
Dim idtipcia = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.CIA").idEnumeracion
|
|
Dim idtipFAE = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.FAE").idEnumeracion
|
|
Dim idtipag = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.AG").idEnumeracion
|
|
Dim ahora = bdGestionAsegasa.Utilidades.AhoraMysql(bd)
|
|
Dim FecLim = ahora.Date.AddDays(20)
|
|
Dim TipoCartaRemesa As Integer = TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO
|
|
Dim rs = bd.recibos.Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones2").Include("enumeraciones3") _
|
|
.Where(Function(x) x.FechaPago.HasValue = False AndAlso x.FechaCartaRemesaCobroDirecto Is Nothing AndAlso Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCartaRemesa) AndAlso
|
|
x.FechaBaja Is Nothing AndAlso x.TotalRecibo > 0 And
|
|
(x.idTipoPago <> idtipcia AndAlso x.idTipoPago <> idtipFAE AndAlso x.idTipoPago <> idtipag) AndAlso
|
|
x.FechaEfecto < FecLim).ToList.Where(Function(x) x.BloquearFacturacion = False).ToList
|
|
|
|
' Dim rs = bd.recibos.Where(Function(x) x.idRecibo = 429451).ToList
|
|
For Each r In rs
|
|
Try
|
|
If r.FechaEfecto < ahora.AddDays(-20) Or r.FechaPago.HasValue Or r.idRemesa.HasValue Then
|
|
If Not (r.idRemesa.HasValue AndAlso Today.Subtract(r.remesas.Fecha.Value.Date).TotalDays > 0) AndAlso (r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido Or r.polizassg.EntidadPolizaTomador.Telefono2.EsNumeroTelefonoMovilEspañolValido) Then
|
|
r.FormaComunicacionTMP = tgsms
|
|
Else
|
|
r.FormaComunicacionTMP = tgninguna
|
|
End If
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador Is Nothing Then
|
|
r.FormaComunicacionTMP = tgsa
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido Or r.polizassg.EntidadPolizaTomador.Telefono2.EsNumeroTelefonoMovilEspañolValido Then
|
|
r.FormaComunicacionTMP = tgsms
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.CodigoPostal.NothingAVacio <> "" AndAlso r.polizassg.EntidadPolizaTomador.direcciones.municipios IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.Direccion.NothingAVacio <> "" Then
|
|
r.FormaComunicacionTMP = tgcarta
|
|
Else
|
|
r.FormaComunicacionTMP = tgsa
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
Next
|
|
Return rs
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Function
|
|
Public Shared Function ObtieneRecibosCartaBaja(Optional bd As bdGestionAsegasa.gestionasegasaEntities = Nothing, Optional RecibosSinComunicacion As List(Of String) = Nothing) As List(Of recibos)
|
|
If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Dim tgsms As Integer = FormaComunicacionEnum.POR_SMS
|
|
Dim tgcarta As Integer = FormaComunicacionEnum.POR_CARTA
|
|
Dim tgsa As Integer = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO
|
|
Dim tgsn As Integer = FormaComunicacionEnum.NINGUNA
|
|
Dim TipoCarta As Integer = TipoGestionEnum.AVISO_POLIZA_DE_BAJA
|
|
|
|
Dim Cabas = bd.enumeraciones.Where(Function(x) x.Codigo = "CABA.CIA" Or x.Codigo = "CABA.ASEG" Or x.Codigo = "CABA.AGEN" Or x.Codigo = "CABA.VTA" Or x.Codigo = "CABA.BJA" Or x.Codigo = "CABA.ASFP" Or x.Codigo = "CABA.SIN").Select(Function(x) x.idEnumeracion).ToList
|
|
Dim FechaInicio As New Date(2019, 12, 31)
|
|
Dim rs = bd.recibos.Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones3").Where(Function(x) x.FechaBaja.HasValue AndAlso x.FechaBaja > FechaInicio AndAlso Cabas.Contains(x.idCausaBaja) AndAlso Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCarta)).ToList.Where(Function(x) x.BloquearFacturacion = False).ToList
|
|
For Each r In rs
|
|
If RecibosSinComunicacion IsNot Nothing AndAlso RecibosSinComunicacion.Contains(r.CodigoRecibo) Then
|
|
r.FormaComunicacionTMP = tgsn
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido Or r.polizassg.EntidadPolizaTomador.Telefono2.EsNumeroTelefonoMovilEspañolValido Then
|
|
r.FormaComunicacionTMP = tgsms
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador.direcciones IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.CodigoPostal.NothingAVacio <> "" AndAlso r.polizassg.EntidadPolizaTomador.direcciones.municipios IsNot Nothing And r.polizassg.EntidadPolizaTomador.direcciones.Direccion.NothingAVacio <> "" Then
|
|
r.FormaComunicacionTMP = tgcarta
|
|
Else
|
|
r.FormaComunicacionTMP = tgsa
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
Return rs
|
|
End Function
|
|
Public Shared Function ObtieneRecibosComunicacionDevueltoBanco(Optional bd As bdGestionAsegasa.gestionasegasaEntities = Nothing) As List(Of recibos)
|
|
If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Dim tgsms As Integer = FormaComunicacionEnum.POR_SMS
|
|
Dim tgcarta As Integer = FormaComunicacionEnum.POR_CARTA
|
|
Dim tgsa As Integer = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO
|
|
Dim TipoCarta As Integer = TipoGestionEnum.AVISO_RECIBO_DEVUELTO_BANCO
|
|
' Dim idTipoContDev As Integer = TipoGestionEnum.CONTABILIZACIÓN_DEVOLUCIÓN_BANCO_SISTEMA_HP
|
|
|
|
|
|
Dim idTrex = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.EX").idEnumeracion
|
|
Dim idTrcx = bd.enumeraciones.First(Function(X) X.Codigo = "TRC.CX").idEnumeracion
|
|
Dim idtippba = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.BA").idEnumeracion
|
|
|
|
|
|
' Dim rs = bd.recibos.Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones3").Where(Function(x) x.FechaBaja.HasValue = False And x.FechaCartaDevuelto.HasValue = False And x.FechaDevolucionBanco.HasValue And x.idTipoPago = idtippba And x.idTipo <> idTrex And x.idTipo <> idTrcx And Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCarta) And (x.idAsientoDevueltoBanco.HasValue Or x.gestionesrecibos.Any(Function(y) y.Tipo = idTipoContDev))).ToList
|
|
Dim rs = bd.recibos.Include("agentes").Include("subagentes").Include("polizassg.entidadespolizas.entidades").Include("polizassg.ramos").Include("polizassg.companias").Include("enumeraciones1").Include("enumeraciones3").Where(Function(x) x.FechaBaja.HasValue = False AndAlso x.FechaCartaDevuelto.HasValue = False AndAlso x.FechaDevolucionBanco.HasValue AndAlso x.idTipoPago = idtippba AndAlso x.idTipo <> idTrex And x.idTipo <> idTrcx And Not x.gestionesrecibos.Any(Function(y) y.Tipo = TipoCarta) And (x.idAsientoDevueltoBanco.HasValue Or x.FechaAsientoDevueltoBanco.HasValue)).ToList.Where(Function(x) x.BloquearFacturacion = False).ToList
|
|
For Each r In rs
|
|
If r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido Or r.polizassg.EntidadPolizaTomador.Telefono2.EsNumeroTelefonoMovilEspañolValido Then
|
|
r.FormaComunicacionTMP = tgsms
|
|
Else
|
|
If r.polizassg.EntidadPolizaTomador.direcciones IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.CodigoPostal.NothingAVacio <> "" AndAlso r.polizassg.EntidadPolizaTomador.direcciones.municipios IsNot Nothing AndAlso r.polizassg.EntidadPolizaTomador.direcciones.Direccion.NothingAVacio <> "" Then
|
|
r.FormaComunicacionTMP = tgcarta
|
|
Else
|
|
r.FormaComunicacionTMP = tgsa
|
|
End If
|
|
End If
|
|
Next
|
|
Return rs
|
|
End Function
|
|
|
|
Public Delegate Sub DelegadoProgreso(Mensaje As String)
|
|
Public Shared Sub GeneraAvisoRemesa(lr As List(Of recibos), Optional bd As bdGestionAsegasa.gestionasegasaEntities = Nothing, Optional Progreso As DelegadoProgreso = Nothing)
|
|
Try
|
|
If Progreso IsNot Nothing Then Progreso("Generando Comunicaciones ...")
|
|
If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
lr = lr.Where(Function(x) x.IBANCorrecto).ToList
|
|
Dim cr_cb_cl = bd.plantillas.First(Function(x) x.Codigo = "CR.CB.CL")
|
|
Dim cr_cb_sl = bd.plantillas.First(Function(x) x.Codigo = "CR.CB.SL")
|
|
Dim cr_cd_cl = bd.plantillas.First(Function(x) x.Codigo = "CR.CD.CL")
|
|
Dim cr_cd_sl = bd.plantillas.First(Function(x) x.Codigo = "CR.CD.SL")
|
|
Dim cr_cpe_cl = bd.plantillas.First(Function(x) x.Codigo = "CR.CPE.CL")
|
|
Dim cr_cpe_sl = bd.plantillas.First(Function(x) x.Codigo = "CR.CPE.SL")
|
|
Dim desconf = bd.enumeraciones.First(Function(x) x.Codigo = "CONF.CTAITSOFT").ValorAlfabetico3
|
|
|
|
|
|
Dim cta = bd.cuentascorreo.First(Function(x) x.Codigo = "SEG.GENERALES")
|
|
Dim idtippba = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.BA").idEnumeracion
|
|
Dim idtipppe = bd.enumeraciones.First(Function(X) X.Codigo = "TIPP.PE").idEnumeracion
|
|
Dim PdfsAUnir As New List(Of Byte())
|
|
Dim i As Integer = 0
|
|
Dim iNumMensaje As Integer = 0
|
|
Dim iNumcorreo As Integer = 0
|
|
Dim idTipoFichero = bd.enumeraciones.First(Function(X) X.Codigo = "TIPFIC.CAR").idEnumeracion 'CARTA DE AVISO DE REMESA
|
|
Dim idUsuario As Integer? = Nothing
|
|
If bdGestionAsegasa.Utilidades.dsc.idUsuario > 0 Then idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario
|
|
For Each r In lr
|
|
i += 1
|
|
' DXSplashScreen.SetState("Generando Comunicación " & i.ToString & " de " & lr.Count.ToString)
|
|
If Progreso IsNot Nothing Then Progreso("Generando Comunicación " & i.ToString & " de " & lr.Count.ToString)
|
|
Dim msg As mensajes = Nothing
|
|
Dim f As ficheros = Nothing
|
|
Dim b() As Byte = Nothing
|
|
If r.FormaComunicacionTMP <> FormaComunicacionEnum.NINGUNA Then
|
|
Dim pl As plantillas
|
|
If r.FormaComunicacionTMP = FormaComunicacionEnum.POR_CARTA Then
|
|
Select Case r.idTipoPago
|
|
Case idtippba
|
|
pl = cr_cb_sl
|
|
Case idtipppe
|
|
pl = cr_cpe_sl
|
|
Case Else
|
|
pl = cr_cd_sl
|
|
End Select
|
|
Else
|
|
Select Case r.idTipoPago
|
|
Case idtippba
|
|
pl = cr_cb_cl
|
|
Case idtipppe
|
|
pl = cr_cpe_cl
|
|
Case Else
|
|
pl = cr_cd_cl
|
|
End Select
|
|
End If
|
|
Dim ds As New List(Of recibos)
|
|
ds.Add(r)
|
|
Dim cc = CombinacionCorrespondencia.Utilidades.ObtieneCCRecibos(ds)
|
|
b = CombinacionCorrespondencia.Utilidades.FusionaPlantillaENPDF(pl.Plantilla, cc)
|
|
|
|
f = New ficheros With {.idTipo = idTipoFichero, .NombreFichero = "car-" & r.idRecibo & ".pdf", .Descripcion = "Carta aviso remesa", .Fecha = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .Fichero = b}
|
|
bd.ficheros.AddObject(f)
|
|
bd.GuardarCambios()
|
|
End If
|
|
If r.FormaComunicacionTMP = FormaComunicacionEnum.POR_SMS Then
|
|
iNumMensaje += 1
|
|
Dim sUrl = ". Url descarga: http://f.asegasa.es/?" & f.idFicheroEnc
|
|
Dim smensaje As String = ("Proximo cobro de su poliza " & r.polizassg.NumeroPoliza & r.polizassg.ramos.Descripcion).Acortar(160 - sUrl.Length - 1) & sUrl
|
|
msg = New mensajes With {.Aplicacion = "RECIBOS", .idAplicacion = r.idRecibo, .Cuenta = "ITSOFT", .Destinatario = If(r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido, r.polizassg.EntidadPolizaTomador.Telefono1, r.polizassg.EntidadPolizaTomador.Telefono2), .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idUsuario = idUsuario, .Mensaje = smensaje}
|
|
bd.mensajes.AddObject(msg)
|
|
If iNumMensaje = 1 Then
|
|
'
|
|
' mensaje de prueba para manuel navarro
|
|
'
|
|
' Dim msgpr As New mensajes With {.Aplicacion = "RECIBOS", .idAplicacion = r.idRecibo, .Cuenta = "ITSOFT", .Destinatario = "657894321", .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario, .Mensaje = smensaje}
|
|
Dim msgpr As New mensajes With {.Aplicacion = "RECIBOS", .idAplicacion = r.idRecibo, .Cuenta = "ITSOFT", .Destinatario = desconf, .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idUsuario = idUsuario, .Mensaje = smensaje}
|
|
bd.mensajes.AddObject(msgpr)
|
|
'
|
|
'
|
|
'
|
|
End If
|
|
bd.GuardarCambios()
|
|
Else
|
|
If r.FormaComunicacionTMP <> FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO And r.FormaComunicacionTMP <> FormaComunicacionEnum.NINGUNA Then PdfsAUnir.Add(b)
|
|
End If
|
|
Dim tg As New gestionesrecibos
|
|
With tg
|
|
.idRecibo = r.idRecibo
|
|
.FormaComunicacion = r.FormaComunicacionTMP
|
|
.Tipo = TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO
|
|
.GestionesRealizadas = TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO.ToString.Replace("_", " ") & " (" & r.DescripcionFormaComunicacion & ")"
|
|
.Fecha = bdGestionAsegasa.Utilidades.AhoraMysql(bd)
|
|
.idUsuario = idUsuario
|
|
If f IsNot Nothing Then .idFichero = f.idFichero
|
|
If msg IsNot Nothing Then .idMensaje = msg.idMensaje
|
|
End With
|
|
bd.gestionesrecibos.AddObject(tg)
|
|
bd.GuardarCambios()
|
|
If r.FormaComunicacionTMP <> FormaComunicacionEnum.NINGUNA AndAlso r.polizassg.EntidadPolizaTomador.Email.EsEmailValido Then
|
|
iNumcorreo += 1
|
|
tg.idCorreo = bdGestionAsegasa.correos.GeneraRegistroCorreo(bd, "Aviso de remesa de su poliza " & r.polizassg.NumeroPoliza, "Con el presente correo le adjuntamos enlace de descarga del documento con los detalles de la remesa/cobro directo de su póliza " & r.polizassg.NumeroPoliza & "<br /><br />Url descarga: <a href=" & Chr(34) & "http://f.asegasa.es/?" & f.idFicheroEnc & Chr(34) & ">Pulse aquí</a>", cta, r.polizassg.EntidadPolizaTomador.Email)
|
|
If iNumcorreo = 1 Then
|
|
'
|
|
' Mensaje de prueba para Manuel Navarro
|
|
'
|
|
bdGestionAsegasa.correos.GeneraRegistroCorreo(bd, "Aviso de remesa de su poliza " & r.polizassg.NumeroPoliza, "Con el presente correo le adjuntamos enlace de descarga del documento con los detalles de la remesa/cobro directo de su póliza " & r.polizassg.NumeroPoliza & "<br /><br />Url descarga: <a href=" & Chr(34) & "http://f.asegasa.es/?" & f.idFicheroEnc & Chr(34) & ">Pulse aquí</a>", cta, "jaimehidalgo@asegasa.es")
|
|
'
|
|
'
|
|
'
|
|
End If
|
|
bd.GuardarCambios()
|
|
End If
|
|
Next
|
|
If PdfsAUnir.Count > 0 Then
|
|
Dim b = TSpdfUtils.pdf.UnePdfs(PdfsAUnir.Select(Function(x) New MemoryStream(x)).ToArray,,,, False)
|
|
|
|
Dim AsuntoEC = "Adjunto le remitimos cartas de AVISO REMESA correspondientes al día " & Today.ToString("dd/MM/yyyy") & " para su envío. Un saludo."
|
|
EnviaCorreoEmpresaCartas(bd, b, AsuntoEC, "AVISO REMESA", cta)
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Sub
|
|
Public Shared Sub GeneraAviso(lr As List(Of recibos), Tipo As TipoGeneracionEnum, Asunto As String, Cuerpo As String, Optional bd As bdGestionAsegasa.gestionasegasaEntities = Nothing, Optional Progreso As DelegadoProgreso = Nothing)
|
|
Try
|
|
If Progreso IsNot Nothing Then Progreso("Generando Comunicaciones ...")
|
|
If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
|
|
Dim cta = bd.cuentascorreo.First(Function(x) x.Codigo = "SEG.GENERALES")
|
|
Dim desconf = bd.enumeraciones.First(Function(x) x.Codigo = "CONF.CTAITSOFT").ValorAlfabetico3
|
|
|
|
Dim sTipo As String = CInt(Tipo).ToString
|
|
|
|
Dim c_cl = bd.plantillas.First(Function(x) x.Codigo = "C.CL." & sTipo)
|
|
Dim c_sl = bd.plantillas.First(Function(x) x.Codigo = "C.SL." & sTipo)
|
|
Dim PdfsAUnir As New List(Of Byte())
|
|
Dim i As Integer = 0
|
|
Dim iNumMensaje As Integer = 0
|
|
Dim iNumcorreo As Integer = 0
|
|
Dim idUsuario As Integer? = Nothing
|
|
If bdGestionAsegasa.Utilidades.dsc.idUsuario > 0 Then idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario
|
|
Dim sFicEnc As String
|
|
For Each r In lr
|
|
|
|
Dim tg As New gestionesrecibos
|
|
Dim AsuntoReemplazado = Asunto.Replace("%POLIZAYRAMO%", r.polizassg.NumeroPoliza & " " & r.polizassg.ramos.Descripcion).Replace("%POLIZA%", r.polizassg.NumeroPoliza).Replace("%RECIBO%", r.NumeroRecibo)
|
|
Dim CuerpoReemplazado = Cuerpo.Replace("%POLIZAYRAMO%", r.polizassg.NumeroPoliza & " " & r.polizassg.ramos.Descripcion).Replace("%POLIZA%", r.polizassg.NumeroPoliza).Replace("%RECIBO%", r.NumeroRecibo)
|
|
|
|
i += 1
|
|
If Not (r.FormaComunicacionTMP = FormaComunicacionEnum.NINGUNA Or r.FormaComunicacionTMP = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO) Then
|
|
If Progreso IsNot Nothing Then Progreso("Generando Comunicación " & Tipo.ToString.Replace("_", " ") & " " & i.ToString & " de " & lr.Count.ToString)
|
|
Dim pl As plantillas
|
|
If r.FormaComunicacionTMP = FormaComunicacionEnum.POR_SMS Then
|
|
pl = c_cl
|
|
Else
|
|
pl = c_sl
|
|
End If
|
|
Dim ds As New List(Of recibos)
|
|
ds.Add(r)
|
|
Dim cc = CombinacionCorrespondencia.Utilidades.ObtieneCCRecibos(ds)
|
|
Dim b = CombinacionCorrespondencia.Utilidades.FusionaPlantillaENPDF(pl.Plantilla, cc)
|
|
Dim idTipoFichero = bd.enumeraciones.First(Function(X) X.Codigo = "TIPFIC.CAB").idEnumeracion 'CARTA DE AVISO DE BAJA
|
|
Dim f As New ficheros With {.idTipo = idTipoFichero, .NombreFichero = "cab-" & r.idRecibo & ".pdf", .Descripcion = "Carta aviso de baja", .Fecha = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .Fichero = b}
|
|
bd.ficheros.AddObject(f)
|
|
bd.GuardarCambios()
|
|
|
|
tg.idFichero = f.idFichero
|
|
sFicEnc = f.idFicheroEnc
|
|
|
|
If r.FormaComunicacionTMP = FormaComunicacionEnum.POR_SMS Then
|
|
iNumMensaje += 1
|
|
Dim sUrl = ". Url descarga: http://f.asegasa.es/?" & sFicEnc
|
|
Dim smensaje As String = AsuntoReemplazado.Acortar(160 - sUrl.Length) & sUrl
|
|
Dim msg As New mensajes With {.Aplicacion = "RECIBOS", .idAplicacion = r.idRecibo, .Cuenta = "ITSOFT", .Destinatario = If(r.polizassg.EntidadPolizaTomador.Telefono1.EsNumeroTelefonoMovilEspañolValido, r.polizassg.EntidadPolizaTomador.Telefono1, r.polizassg.EntidadPolizaTomador.Telefono2), .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idUsuario = idUsuario, .Mensaje = smensaje}
|
|
bd.mensajes.AddObject(msg)
|
|
If iNumMensaje = 1 Then
|
|
Dim msgpr As New mensajes With {.Aplicacion = "RECIBOS", .idAplicacion = r.idRecibo, .Cuenta = "ITSOFT", .Destinatario = desconf, .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idUsuario = idUsuario, .Mensaje = smensaje}
|
|
bd.mensajes.AddObject(msgpr)
|
|
End If
|
|
bd.GuardarCambios()
|
|
tg.idMensaje = msg.idMensaje
|
|
Else
|
|
PdfsAUnir.Add(b)
|
|
End If
|
|
End If
|
|
With tg
|
|
.idRecibo = r.idRecibo
|
|
.FormaComunicacion = r.FormaComunicacionTMP
|
|
.Tipo = Tipo
|
|
.GestionesRealizadas = Tipo.ToString.Replace("_", " ") & " " & r.DescripcionFormaComunicacion
|
|
.Fecha = bdGestionAsegasa.Utilidades.AhoraMysql(bd)
|
|
.idUsuario = idUsuario
|
|
End With
|
|
bd.gestionesrecibos.AddObject(tg)
|
|
bd.GuardarCambios()
|
|
If Not (r.FormaComunicacionTMP = FormaComunicacionEnum.NINGUNA Or r.FormaComunicacionTMP = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO) Then
|
|
If r.polizassg.EntidadPolizaTomador.Email.EsEmailValido Then
|
|
iNumcorreo += 1
|
|
tg.idCorreo = bdGestionAsegasa.correos.GeneraRegistroCorreo(bd, AsuntoReemplazado, CuerpoReemplazado & "<br /><br />Url descarga: <a href=" & Chr(34) & "http://f.asegasa.es/?" & sFicEnc & Chr(34) & ">Pulse aquí</a>", cta, r.polizassg.EntidadPolizaTomador.Email)
|
|
If iNumcorreo = 1 Then
|
|
'
|
|
' Mensaje de prueba para Manuel Navarro
|
|
'
|
|
bdGestionAsegasa.correos.GeneraRegistroCorreo(bd, AsuntoReemplazado, CuerpoReemplazado & "<br /><br />Url descarga: <a href=" & Chr(34) & "http://f.asegasa.es/?" & sFicEnc & Chr(34) & ">Pulse aquí</a>", cta, "jaimehidalgo@asegasa.es")
|
|
'
|
|
'
|
|
'
|
|
End If
|
|
bd.GuardarCambios()
|
|
End If
|
|
End If
|
|
Next
|
|
If PdfsAUnir.Count > 0 Then
|
|
Dim b = TSpdfUtils.pdf.UnePdfs(PdfsAUnir.Select(Function(x) New MemoryStream(x)).ToArray, ,,, False)
|
|
Dim AsuntoEC = "Adjunto le remitimos cartas de " & Tipo.ToString.Replace("_", " ") & " correspondientes al día " & Today.ToString("dd/MM/yyyy") & " para su envío. Un saludo."
|
|
EnviaCorreoEmpresaCartas(bd, b, AsuntoEC, Tipo.ToString, cta)
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Sub
|
|
Private Shared Sub EnviaCorreoEmpresaCartas(bd As bdGestionAsegasa.gestionasegasaEntities, Fichero As Byte(), Asunto As String, TipoFichero As String, cta As cuentascorreo)
|
|
Dim corcar = bd.enumeraciones.First(Function(x) x.Codigo = "CONF.EMAILEMPCAR")
|
|
Dim sCorreoCartas = corcar.ValorAlfabetico1
|
|
Dim scorreocartascopia = corcar.ValorAlfabetico2
|
|
bdGestionAsegasa.correos.GeneraRegistroCorreoConAdjunto(bd, Asunto, Asunto, cta, Fichero, TipoFichero & "_" & Now.ToString("yyyy-MM-dd") & ".pdf", Asunto, sCorreoCartas, scorreocartascopia)
|
|
|
|
End Sub
|
|
|
|
Public Enum TipoGeneracionEnum
|
|
AVISO_REMESA_O_COBRO_DIRECTO = 1
|
|
AVISO_BAJA_POLIZA = 2
|
|
COMUNICACIÓN_DEVUELTO_BANCO = 3
|
|
AVISO_IMPERATIVO_LEGAL = 4
|
|
EMAIL_A_AGENTE_FALTAN_DATOS_ASEGURADOS = 5
|
|
End Enum
|
|
|
|
#End Region
|
|
#Region "Procesos"
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
Public Shared Sub ImportaRecibosEIAC_V5(bd As bdGestionAsegasa.gestionasegasaEntities, F As ficheroscompanias, iNumfic As Integer, inumfics As Integer, Agentes As List(Of agentes), SubAgentes As List(Of subagentes), Ramos As List(Of ramos), Comscia As List(Of comisionescompanias), ComsAge As List(Of comisionesagentes), Pols As List(Of polizassg), Recs As List(Of ReciboReducido), TiposRecibos As List(Of enumeraciones), ByRef Lrai As List(Of ReciboAIncorporar), 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)
|
|
Try
|
|
' Dim idTippcia = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.CIA").idEnumeracion
|
|
|
|
|
|
If MostrarProgreso Then
|
|
DXSplashScreen.SetState("Comprobando " & F.NombreFichero)
|
|
End If
|
|
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(ProcesosEIAC_V5.tipo_recibo)).Cast(Of ProcesosEIAC_V5.tipo_recibo)
|
|
Dim iNumRecs = lrecibos.Count
|
|
For Each Recibo In lrecibos
|
|
Dim Cia = F.companias
|
|
'If Cia.Codigo = "0008" AndAlso Recibo.DatosPoliza.IdPoliza.Replace("-", "").StartsWith("UVG") = False Then
|
|
' Cia = bd.companias.First(Function(x) x.Codigo = "0025")
|
|
'End If
|
|
|
|
Dim bIncluir As Boolean = False
|
|
If F.idFichero = 2584 Then Debug.WriteLine("aqui")
|
|
If Busqueda <> "" Then
|
|
If Recibo.DatosPoliza.IdPoliza.Contains(Busqueda) Or Recibo.DatosRecibo.IdRecibo.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 = Recibo.DatosRecibo.Fechas.FechaEfectoActual
|
|
ir.Fecha_Vencimiento = Recibo.DatosRecibo.Fechas.FechaVencimiento
|
|
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 = Cia.Codigo
|
|
ir.idCompañia = F.idCompania
|
|
ir.Fecha_Procesado = F.FechaProcesado
|
|
Dim sobrecomision As Double = 0
|
|
|
|
Dim ImporteComision As Double = 0
|
|
Dim ImporteComisionIncremental As Double = 0
|
|
If Cia.Codigo = "0027" Then
|
|
' Dim OtrasComisiones = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "Tipo Comisión" And x.DescripcionDato = "Comisión Directa Normalizada").ToList
|
|
Dim OtrasComisiones = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "Tipo Comisión" And x.DescripcionDato = "Comisión Directa Mínima").ToList
|
|
If OtrasComisiones.Count > 0 Then
|
|
For Each Comision In OtrasComisiones
|
|
ImporteComision = ImporteComision + Double.Parse(Comision.ValorSubdato, CultureInfo.InvariantCulture)
|
|
Next
|
|
End If
|
|
Dim ComisionesIncrementales = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "Tipo Comisión" And x.DescripcionDato = "Comisión Directa Incremental").ToList
|
|
If ComisionesIncrementales.Count > 0 Then
|
|
For Each Comision In ComisionesIncrementales
|
|
ImporteComisionIncremental = ImporteComisionIncremental + Double.Parse(Comision.ValorSubdato, CultureInfo.InvariantCulture)
|
|
Next
|
|
End If
|
|
End If
|
|
If Cia.Codigo = "0008" Then
|
|
Dim ComisionesIncrementales = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "ComisionAdicME").ToList
|
|
If ComisionesIncrementales.Count > 0 Then
|
|
For Each Comision In ComisionesIncrementales
|
|
ImporteComisionIncremental = ImporteComisionIncremental + Double.Parse(Comision.ValorSubdato, CultureInfo.InvariantCulture)
|
|
Next
|
|
End If
|
|
End If
|
|
If ImporteComision = 0 Then
|
|
Dim DatosComision = Recibo.DatosRecibo.DatosComisiones
|
|
For Each Comision In DatosComision
|
|
ImporteComision = ImporteComision + Comision.ComisionBruta
|
|
Next
|
|
If Cia.Codigo = "0008" Then
|
|
ImporteComision -= ImporteComisionIncremental
|
|
End If
|
|
End If
|
|
|
|
|
|
ir.Comisión = ImporteComision
|
|
ir.Sobrecomisión = ImporteComisionIncremental
|
|
|
|
Select Case Cia.Codigo
|
|
Case "0009" ' SANITAS
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
If ir.Número_Póliza.Contains("/") Then ir.Número_Póliza = ir.Número_Póliza.Split("/")(1)
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.Split("/").Last
|
|
Case "0017" 'CASER
|
|
'ir.Número_Póliza = If(Recibo.DatosPoliza.IdAplicacion.NothingAVacio = "", Recibo.DatosPoliza.IdPoliza, Recibo.DatosPoliza.IdAplicacion)
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza.NothingAVacio & Recibo.DatosPoliza.IdAplicacion.NothingAVacio
|
|
If Pols.Any(Function(x) x.NumeroPoliza = ir.Número_Póliza) = False Then
|
|
ir.Número_Póliza = ir.Número_Póliza.AcortarPorLaIzquierda(8)
|
|
If Pols.Any(Function(x) x.NumeroPoliza = ir.Número_Póliza) = False Then ' and pols.Any(Function(x) x.NumeroPoliza = Recibo.DatosPoliza.IdPoliza) Then
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
End If
|
|
End If
|
|
If F.NombreFichero.EndsWith("V2.xml") Then
|
|
If Recibo.DatosRecibo.IdRecibo.Length < 25 Then
|
|
ir.Código_Recibo = Cia.Codigo & "/E-" & Recibo.DatosRecibo.IdRecibo
|
|
Else
|
|
ir.Código_Recibo = Cia.Codigo & "/E-" & Recibo.DatosRecibo.IdRecibo.Substring(16, 7)
|
|
End If
|
|
Else
|
|
If Recibo.DatosRecibo.IdRecibo.Length < 25 Then
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Else
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.Substring(16, 7)
|
|
End If
|
|
End If
|
|
Case "0027" 'AXA
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Dim CodigoAcortado = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.AcortarPorLaIzquierda(8)
|
|
Dim Recexi = Recs.Where(Function(x) x.CodigoRecibo = CodigoAcortado).FirstOrDefault
|
|
If Recexi IsNot Nothing AndAlso Now.Subtract(Recexi.FechaEfecto).TotalDays < 365 Then ir.Código_Recibo = CodigoAcortado
|
|
If ir.Fecha_Efecto > New Date(2020, 9, 3) And ir.Fecha_Efecto < New Date(2021, 12, 31) Then sobrecomision = 6.33
|
|
Case "0008" 'GENERALI
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza.Replace("-", "")
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Case "0013"
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza.AcortarPorLaIzquierda(11)
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Case "0002"
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
If Recibo.DatosRecibo.IdRecibo.Contains("-") Then
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.Split("-")(0)
|
|
Else
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
End If
|
|
Case Else
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
End Select
|
|
If MostrarProgreso Then DXSplashScreen.SetState("Incorporando Recibos. Fichero (" & iNumfic.ToString & "/" & inumfics.ToString & "). " & "Recibo (" & iNumrec.ToString & "/" & iNumRecs.ToString & "): " & ir.Código_Recibo)
|
|
Dim pol As polizassg
|
|
' If Recibo.DatosRecibo.ClaseRecibo = claves_claserecibo.CA Then
|
|
'If ir.Número_Póliza = "00075928887" Then Debug.WriteLine("aqui")
|
|
pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza 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 pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza And x.companias.Codigo = Cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
If pol Is Nothing AndAlso Cia.Codigo = "0021" Then
|
|
Dim nptmp = "0" & ir.Número_Póliza
|
|
pol = Pols.Where(Function(x) x.NumeroPoliza = nptmp And x.FechaBaja.HasValue = False And x.companias.Codigo = Cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
If pol IsNot Nothing Then ir.Número_Póliza = nptmp
|
|
End If
|
|
|
|
If pol Is Nothing AndAlso Cia.Codigo = "0030" AndAlso Recibo.DatosRecibo.OtrosDatos IsNot Nothing Then
|
|
Dim odPolizaTron = Recibo.DatosRecibo.OtrosDatos.FirstOrDefault(Function(x) x.DescripcionDato = "POLIZA TRON")
|
|
If odPolizaTron IsNot Nothing Then
|
|
ir.Número_Póliza = odPolizaTron.ValorSubdato
|
|
pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza 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 pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza And x.companias.Codigo = Cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
End If
|
|
End If
|
|
' Else
|
|
' pol = pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza 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 pol = pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
' End If
|
|
|
|
Dim idTipoRecibo As Integer
|
|
If pol IsNot Nothing Then
|
|
ir.Observaciones = pol.Observaciones
|
|
ir.Tipo_Pago = pol.TipoPago
|
|
Try
|
|
ir.Forma_Pago_Recibida = ObtieneFormaPagoEIAC(Recibo.DatosRecibo.GestionCobro.DatosFormaPago.ClaseFormaPago.ToString)
|
|
Catch ex As Exception
|
|
ir.Forma_Pago_Recibida = "DESCONOCIDA"
|
|
End Try
|
|
Try
|
|
ir.Situacion_Recibo = ObtieneSituacionReciboEIAC(Recibo.DatosRecibo.SituacionRecibo.ToString)
|
|
Catch ex As Exception
|
|
ir.Situacion_Recibo = "DESCONOCIDA"
|
|
End Try
|
|
Try
|
|
ir.Fecha_Situacion = Recibo.DatosRecibo.Fechas.FechaSituacion
|
|
Catch EX As Exception
|
|
End Try
|
|
Select Case Recibo.DatosRecibo.ClaseRecibo
|
|
Case ProcesosEIAC_V5.claves_claserecibo.NP
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal < 0 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.EX").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.E").idEnumeracion
|
|
End If
|
|
Case ProcesosEIAC_V5.claves_claserecibo.EX
|
|
If Recs.Where(Function(X) X.idPoliza = pol.idPoliza And X.CodigoRecibo <> ir.Código_Recibo).Count > 1 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CX").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.EX").idEnumeracion
|
|
End If
|
|
Case ProcesosEIAC_V5.claves_claserecibo.SU
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal < 0 Then
|
|
If Recs.Where(Function(X) X.idPoliza = pol.idPoliza And X.CodigoRecibo <> ir.Código_Recibo).Count > 1 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CX").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.EX").idEnumeracion
|
|
End If
|
|
Else
|
|
If Recs.Where(Function(X) X.idPoliza = pol.idPoliza And X.CodigoRecibo <> ir.Código_Recibo).Count > 1 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CS").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.ES").idEnumeracion
|
|
End If
|
|
End If
|
|
Case Else
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal < 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
|
|
End Select
|
|
ir.Tipo = TiposRecibos.First(Function(X) X.idEnumeracion = idTipoRecibo).Descripcion
|
|
Else
|
|
ir.Tipo = Recibo.DatosRecibo.ClaseRecibo.ToString
|
|
End If
|
|
Dim Consorcio As Double = 0
|
|
Try
|
|
Dim dc = Recibo.DatosRecibo.DatosImportes.Importes.DatosCargos.FirstOrDefault(Function(x) x.ClaseCargo = ProcesosEIAC_V5.claves_cargo.CO)
|
|
If dc IsNot Nothing Then Consorcio = dc.Importe
|
|
Catch
|
|
End Try
|
|
If pol IsNot Nothing Then RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Consorcio, Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
'If Recibo.DatosRecibo.SituacionRecibo <> ProcesosEIAC_V5.claves_situacionrecibo.AN OrElse Recibo.DatosRecibo.MovimientosRecibo.Any(Function(x) x.ClaseMovimiento = ProcesosEIAC_V5.claves_clasemovimientorecibo.AN) = False Then
|
|
|
|
If ListadoRecibosAnulados Is Nothing OrElse ListadoRecibosAnulados.Contains(ir.Código_Recibo) = False OrElse ((Recibo.DatosRecibo.SituacionRecibo <> ProcesosEIAC_V6.claves_situacionrecibo.AN AndAlso Recibo.DatosRecibo.SituacionRecibo <> ProcesosEIAC_V6.claves_situacionrecibo.DE) OrElse Recibo.DatosRecibo.MovimientosRecibo.Any(Function(x) x.ClaseMovimiento = ProcesosEIAC_V6.claves_clasemovimientorecibo.AN OrElse x.ClaseMovimiento = ProcesosEIAC_V6.claves_clasemovimientorecibo.DE) = False) Then
|
|
If pol IsNot Nothing Then
|
|
|
|
Dim recenfic = Lrai.FirstOrDefault(Function(x) x.Código_Recibo = ir.Código_Recibo And x.Correcto)
|
|
|
|
If recenfic Is Nothing AndAlso Cia.Codigo = "0045" AndAlso ir.Código_Recibo.Length = 7 Then
|
|
Dim nretmp = "0" & ir.Código_Recibo
|
|
recenfic = Lrai.FirstOrDefault(Function(x) x.Código_Recibo = nretmp And x.Correcto)
|
|
If recenfic IsNot Nothing Then ir.Código_Recibo = nretmp
|
|
End If
|
|
|
|
|
|
Dim ReciboActualDup As Boolean = False
|
|
If recenfic IsNot Nothing Then
|
|
If recenfic.Fecha_Situacion.Value <= ir.Fecha_Situacion.Value Then
|
|
If recenfic.Total_Recibo = ir.Total_Recibo Then
|
|
recenfic.Correcto = False
|
|
recenfic.Corregible = False
|
|
recenfic.Mensaje = "Recibo actualizado en Posteriores Entradas"
|
|
Else
|
|
ReciboActualDup = True
|
|
recenfic.Mensaje = "Recibo duplicado en ficheros con importes diferentes"
|
|
ir.Mensaje = "Recibo duplicado en ficheros con importes diferentes"
|
|
End If
|
|
Else
|
|
ReciboActualDup = True
|
|
End If
|
|
End If
|
|
|
|
|
|
'If Not Lrai.Any(Function(x) x.Código_Recibo = ir.Código_Recibo And x.Correcto) Then
|
|
If Not ReciboActualDup Then
|
|
Dim Rec = Recs.Where(Function(x) x.CodigoRecibo = ir.Código_Recibo).FirstOrDefault
|
|
If Rec IsNot Nothing AndAlso Cia.Codigo = "0017" AndAlso Rec.NumeroPoliza <> ir.Número_Póliza AndAlso Rec.FechaVencimiento < Today Then
|
|
Rec.CodigoRecibo = ReciboAHistoricoCaser(Rec.CodigoRecibo)
|
|
Rec.NumeroRecibo = Rec.CodigoRecibo.Split("/")(1)
|
|
Rec = Nothing
|
|
End If
|
|
|
|
If Rec Is Nothing AndAlso Cia.Codigo = "0045" AndAlso ir.Código_Recibo.Length = 7 Then
|
|
Dim nretmp = "0" & ir.Código_Recibo
|
|
Rec = Recs.Where(Function(x) x.CodigoRecibo = nretmp).FirstOrDefault
|
|
If Rec IsNot Nothing Then ir.Código_Recibo = nretmp
|
|
End If
|
|
|
|
If Rec Is Nothing Then
|
|
If ir.Fecha_Efecto.AddMonths(1) > Today OrElse Cia.Codigo <> "0025" 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 Recibo.DatosRecibo.IdRecibo.ToString.Contains(recant.NumeroRecibo) = False)) Then
|
|
If Not (ir.Número_Póliza = "41383910" And Cia.Codigo = "0027") Then
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta <> 0 Then
|
|
If pol.FechaBaja.HasValue Then
|
|
ir.Mensaje = "Recibo Correcto (Póliza de Baja)"
|
|
Else
|
|
ir.Mensaje = "Recibo Correcto"
|
|
End If
|
|
ir.Correcto = True
|
|
ir.Corregible = True
|
|
Else
|
|
ir.Mensaje = "Recibo con Prima Neta = 0"
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
End If
|
|
|
|
'RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
If ir.Correcto AndAlso recant IsNot Nothing Then
|
|
'If Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta <> 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, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V5.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V5.claves_clasegestion.CO)
|
|
'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
|
|
ElseIf ir.Correcto Then
|
|
If ir.Gestionado_Por_Cia AndAlso (ir.Poliza.idTipoPago <> bdGestionAsegasa.recibos.idtippCIA OrElse ir.Poliza.idTipoPago <> bdGestionAsegasa.recibos.idtippFAE) Then
|
|
ir.Mensaje = "Recibo Gestionado por cía. Se actualizará la póliza a Gestionada por la compañía"
|
|
Else
|
|
If ir.Gestionado_Por_Cia = False AndAlso (ir.Poliza.idTipoPago = bdGestionAsegasa.recibos.idtippCIA OrElse ir.Poliza.idTipoPago = bdGestionAsegasa.recibos.idtippFAE) Then
|
|
ir.Mensaje = "Recibo NO Gestionado por CÍA. Se actualizará la póliza a cobro por banco"
|
|
End If
|
|
End If
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = True
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V5.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V5.claves_clasegestion.CO)
|
|
ir.Mensaje = "RECIBO DE PÓLIZA ESPECIAL"
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = True
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V5.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V5.claves_clasegestion.CO)
|
|
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
|
|
If recant.FechaFacturacion.HasValue Then
|
|
ir.Mensaje = "Existe otro recibo facturado de la misma póliza con el mismo efecto y vencimiento (F.Efecto Anterior a un Mes) (" & recant.CodigoRecibo & ")"
|
|
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 & ")"
|
|
If ListadoRecibosDuplicados IsNot Nothing Then ListadoRecibosDuplicados.Add(recant.CodigoRecibo)
|
|
End If
|
|
End If
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = True
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V5.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V5.claves_clasegestion.CO)
|
|
ir.Mensaje = "Recibo Con fecha de efecto anterior a la permitida."
|
|
End If
|
|
Else
|
|
If Rec.idCausaBaja = idCabaFP() AndAlso ir.Situacion_Recibo = "COBRADO" Then
|
|
ir.Mensaje = "Actualización de causa de baja de recibo ya existente (Recibo de baja por FP a Recibo de baja por cobro en CIA)"
|
|
ir.PagadoEnCia = True
|
|
Else
|
|
If Rec.FechaPago.HasValue = False And Rec.idTipoPago = idtippCIA() And ir.Situacion_Recibo = "COBRADO" Then
|
|
ir.Mensaje = "Actualización de recibo ya existente (Recibo con cobro a cía pagado)"
|
|
ir.Actualizado = True
|
|
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
|
|
End If
|
|
End If
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V5.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V5.claves_clasegestion.CO)
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
If ir.Mensaje = "" Then
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V5.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V5.claves_clasegestion.CO)
|
|
If ir.Situacion_Recibo = "COBRADO" And ir.Tipo_Pago = "GESTIONADO POR LA COMPAÑÍA" And ir.Fecha_Situacion.HasValue Then
|
|
ir.Mensaje = "Actualización de recibo (Recibo con cobro a cía pagado)"
|
|
ir.Actualizado = True
|
|
Else
|
|
ir.Mensaje = "Recibo Duplicado en el fichero"
|
|
End If
|
|
End If
|
|
End If
|
|
If pol.Tomador Is Nothing Then
|
|
ir.Tomador = "* NO ASIGNADO EN PÓLIZA *"
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
ir.Mensaje = "TOMADOR NO ASIGNADO EN PÓLIZA"
|
|
Else
|
|
ir.Tomador = pol.Tomador.RazonSocial
|
|
End If
|
|
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.Total_Recibo = Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
|
|
ir.Mensaje = "Póliza no encontrada"
|
|
End If
|
|
Else
|
|
Dim Rec = Recs.Where(Function(x) x.CodigoRecibo = ir.Código_Recibo).FirstOrDefault
|
|
|
|
If Rec Is Nothing AndAlso Cia.Codigo = "0045" AndAlso ir.Código_Recibo.Length = 7 Then
|
|
Dim nretmp = "0" & ir.Código_Recibo
|
|
Rec = Recs.Where(Function(x) x.CodigoRecibo = nretmp).FirstOrDefault
|
|
If Rec IsNot Nothing Then ir.Código_Recibo = nretmp
|
|
End If
|
|
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
Dim anulacion = Recibo.DatosRecibo.MovimientosRecibo.FirstOrDefault(Function(x) x.ClaseMovimiento = ProcesosEIAC_V5.claves_clasemovimientorecibo.AN)
|
|
Dim MotivoAnulacion As String = ""
|
|
If ListadoRecibosAnulados IsNot Nothing AndAlso ListadoRecibosAnulados.Contains(ir.Código_Recibo) Then
|
|
MotivoAnulacion = "Recibo Anulado (No existente en Asegasa y anulado previamente)"
|
|
Else
|
|
If anulacion IsNot Nothing AndAlso anulacion.Anulacion IsNot Nothing Then
|
|
MotivoAnulacion = anulacion.Anulacion.DescripcionMotivo
|
|
Else
|
|
If Recibo.DatosRecibo.SituacionRecibo = ProcesosEIAC_V6.claves_situacionrecibo.DE Then
|
|
MotivoAnulacion = "Devolución en Cía"
|
|
Else
|
|
MotivoAnulacion = "Desconocida"
|
|
End If
|
|
|
|
End If
|
|
If Rec Is Nothing Then
|
|
|
|
ir.Mensaje = "Recibo Anulado (No existente en Asegasa). Causa: " & MotivoAnulacion
|
|
Else
|
|
If Rec.FechaBaja.HasValue Then
|
|
ir.Mensaje = "Recibo Anulado (En Asegasa y en Compañía). Causa: " & MotivoAnulacion
|
|
Else
|
|
If Rec.FechaFacturacion.HasValue Then
|
|
ir.Mensaje = "Recibo Anulado (En vigor y facturado en Asegasa. NO SE ANULARÁ EN ASEGASA). Causa: " & MotivoAnulacion
|
|
Else
|
|
ir.Mensaje = "Recibo Anulado (En vigor en Asegasa). Causa: " & MotivoAnulacion
|
|
End If
|
|
End If
|
|
End If
|
|
ir.Anulado = True
|
|
If ListadoRecibosAnulados IsNot Nothing AndAlso ListadoRecibosAnulados.Contains(ir.Código_Recibo) = False AndAlso
|
|
(Rec Is Nothing OrElse
|
|
(Rec.FechaBaja.HasValue = False AndAlso
|
|
(Rec.FechaFacturacion.HasValue = False OrElse Rec.FechaPago.HasValue = False AndAlso Rec.idTipoPago <> idTippBA()) AndAlso
|
|
F.FechaProcesado.HasValue = False)) Then ListadoRecibosAnulados.Add(ir.Código_Recibo)
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
Throw New Exception("Error Incorporando Recibo: " & Recibo.DatosRecibo.IdRecibo & " Póliza: " & Recibo.DatosPoliza.IdPoliza, ex)
|
|
End Try
|
|
End If
|
|
Next
|
|
End If
|
|
Catch ex As Exception
|
|
Throw New Exception("Error Incorporando " & F.NombreFichero & " Compañia: " & F.companias.Nombre, ex)
|
|
End Try
|
|
End Sub
|
|
Public Shared Sub ImportaRecibosEIAC_V6(bd As bdGestionAsegasa.gestionasegasaEntities, F As ficheroscompanias, iNumfic As Integer, inumfics As Integer, Agentes As List(Of agentes), SubAgentes As List(Of subagentes), Ramos As List(Of ramos), Comscia As List(Of comisionescompanias), ComsAge As List(Of comisionesagentes), Pols As List(Of polizassg), Recs As List(Of ReciboReducido), TiposRecibos As List(Of enumeraciones), ByRef Lrai As List(Of ReciboAIncorporar), 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)
|
|
Try
|
|
' Dim idTippcia = bd.enumeraciones.First(Function(x) x.Codigo = "TIPP.CIA").idEnumeracion
|
|
If MostrarProgreso Then
|
|
DXSplashScreen.SetState("Comprobando " & F.NombreFichero)
|
|
End If
|
|
Dim DatosEIAC As ProcesosEIAC_V6.ProcesosEIAC = tsl5.Utilidades.Deserializa(F.Fichero, GetType(ProcesosEIAC_V6.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(ProcesosEIAC_V6.tipo_recibo)).Cast(Of ProcesosEIAC_V6.tipo_recibo)
|
|
Dim iNumRecs = lrecibos.Count
|
|
For Each Recibo In lrecibos
|
|
Dim Cia = F.companias
|
|
'If Cia.Codigo = "0008" AndAlso Recibo.DatosPoliza.IdPoliza.Replace("-", "").StartsWith("UVG") = False Then
|
|
' Cia = bd.companias.First(Function(x) x.Codigo = "0025")
|
|
'End If
|
|
'If Cia.Codigo = "0025" AndAlso Recibo.DatosPoliza.IdPoliza.Replace("-", "").StartsWith("UVG") Then
|
|
' Cia = bd.companias.First(Function(x) x.Codigo = "0008")
|
|
'End If
|
|
|
|
Dim bIncluir As Boolean = False
|
|
' If F.idFichero = 2584 Then Debug.WriteLine("aqui")
|
|
If Busqueda <> "" Then
|
|
If Recibo.DatosPoliza.IdPoliza.Contains(Busqueda) Or Recibo.DatosRecibo.IdRecibo.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.Actualizado = False
|
|
ir.Fecha_Efecto = Recibo.DatosRecibo.Fechas.FechaEfectoActual
|
|
ir.Fecha_Vencimiento = Recibo.DatosRecibo.Fechas.FechaVencimiento
|
|
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 = Cia.Codigo
|
|
ir.idCompañia = Cia.idCompania
|
|
ir.Fecha_Procesado = F.FechaProcesado
|
|
Dim sobrecomision As Double = 0
|
|
|
|
Dim ImporteComision As Double = 0
|
|
Dim ImporteComisionIncremental As Double = 0
|
|
If Cia.Codigo = "0027" Then
|
|
' Dim OtrasComisiones = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "Tipo Comisión" And x.DescripcionDato = "Comisión Directa Normalizada").ToList
|
|
Dim OtrasComisiones = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "Tipo Comisión" And x.DescripcionDato = "Comisión Directa Mínima").ToList
|
|
If OtrasComisiones.Count > 0 Then
|
|
For Each Comision In OtrasComisiones
|
|
ImporteComision = ImporteComision + Double.Parse(Comision.ValorSubdato, CultureInfo.InvariantCulture)
|
|
Next
|
|
End If
|
|
Dim ComisionesIncrementales = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "Tipo Comisión" And x.DescripcionDato = "Comisión Directa Incremental").ToList
|
|
If ComisionesIncrementales.Count > 0 Then
|
|
For Each Comision In ComisionesIncrementales
|
|
ImporteComisionIncremental = ImporteComisionIncremental + Double.Parse(Comision.ValorSubdato, CultureInfo.InvariantCulture)
|
|
Next
|
|
End If
|
|
End If
|
|
If Cia.Codigo = "0008" Then
|
|
Dim ComisionesIncrementales = Recibo.DatosRecibo.OtrosDatos.Where(Function(x) x.IdDato = "ComisionAdicME").ToList
|
|
If ComisionesIncrementales.Count > 0 Then
|
|
For Each Comision In ComisionesIncrementales
|
|
ImporteComisionIncremental = ImporteComisionIncremental + Double.Parse(Comision.ValorSubdato, CultureInfo.InvariantCulture)
|
|
Next
|
|
End If
|
|
End If
|
|
If ImporteComision = 0 Then
|
|
Dim DatosComision = Recibo.DatosRecibo.DatosComisiones
|
|
For Each Comision In DatosComision
|
|
ImporteComision = ImporteComision + Comision.ComisionBruta
|
|
Next
|
|
If Cia.Codigo = "0008" Then
|
|
ImporteComision -= ImporteComisionIncremental
|
|
End If
|
|
End If
|
|
|
|
|
|
ir.Comisión = ImporteComision
|
|
ir.Sobrecomisión = ImporteComisionIncremental
|
|
|
|
Select Case Cia.Codigo
|
|
Case "0009" ' SANITAS
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
If ir.Número_Póliza.Contains("/") Then ir.Número_Póliza = ir.Número_Póliza.Split("/")(1)
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.Split("/").Last
|
|
Case "0017" 'CASER
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza.NothingAVacio & Recibo.DatosPoliza.IdAplicacion.NothingAVacio
|
|
'ir.Número_Póliza = If(Recibo.DatosPoliza.IdAplicacion.NothingAVacio = "", Recibo.DatosPoliza.IdPoliza, Recibo.DatosPoliza.IdAplicacion)
|
|
If Pols.Any(Function(x) x.NumeroPoliza = ir.Número_Póliza) = False Then
|
|
ir.Número_Póliza = ir.Número_Póliza.AcortarPorLaIzquierda(8)
|
|
If Pols.Any(Function(x) x.NumeroPoliza = ir.Número_Póliza) = False Then ' and pols.Any(Function(x) x.NumeroPoliza = Recibo.DatosPoliza.IdPoliza) Then
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
End If
|
|
End If
|
|
If F.NombreFichero.EndsWith("V2.xml") Then
|
|
If Recibo.DatosRecibo.IdRecibo.Length < 25 Then
|
|
ir.Código_Recibo = Cia.Codigo & "/E-" & Recibo.DatosRecibo.IdRecibo
|
|
Else
|
|
ir.Código_Recibo = Cia.Codigo & "/E-" & Recibo.DatosRecibo.IdRecibo.Substring(16, 7)
|
|
End If
|
|
Else
|
|
If Recibo.DatosRecibo.IdRecibo.Length < 25 Then
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Else
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.Substring(16, 7)
|
|
End If
|
|
End If
|
|
Case "0027" 'AXA
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Dim CodigoAcortado = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.AcortarPorLaIzquierda(8)
|
|
Dim Recexi = Recs.Where(Function(x) x.CodigoRecibo = CodigoAcortado).FirstOrDefault
|
|
If Recexi IsNot Nothing AndAlso Now.Subtract(Recexi.FechaEfecto).TotalDays < 365 Then ir.Código_Recibo = CodigoAcortado
|
|
If ir.Fecha_Efecto > New Date(2020, 9, 3) And ir.Fecha_Efecto < New Date(2021, 12, 31) Then sobrecomision = 6.33
|
|
Case "0008" 'GENERALI
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza.Replace("-", "")
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Case "0013"
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza.AcortarPorLaIzquierda(11)
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
Case "0002"
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
If Recibo.DatosRecibo.IdRecibo.Contains("-") Then
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo.Split("-")(0)
|
|
Else
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
End If
|
|
Case Else
|
|
ir.Número_Póliza = Recibo.DatosPoliza.IdPoliza
|
|
ir.Código_Recibo = Cia.Codigo & "/" & Recibo.DatosRecibo.IdRecibo
|
|
End Select
|
|
If MostrarProgreso Then DXSplashScreen.SetState("Incorporando Recibos Fichero (" & iNumfic.ToString & "/" & inumfics.ToString & "). " & "Recibo (" & iNumrec.ToString & "/" & iNumRecs.ToString & "): " & ir.Código_Recibo)
|
|
|
|
' If MostrarProgreso Then DXSplashScreen.SetState("Fichero (" & iNumfic.ToString & "/" & inumfics.ToString & "). " & "Recibo (" & iNumrec.ToString & "/" & iNumRecs.ToString & "): " & ir.Código_Recibo)
|
|
Dim pol As polizassg
|
|
' If Recibo.DatosRecibo.ClaseRecibo = claves_claserecibo.CA Then
|
|
' If ir.Número_Póliza = "00137745550" Then Debug.WriteLine("aqui")
|
|
' Dim kk = Pols.Where(Function(x) x.NumeroPoliza IsNot Nothing AndAlso x.NumeroPoliza.Contains("13774555")).FirstOrDefault
|
|
pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza 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 pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza And x.companias.Codigo = Cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
If pol Is Nothing AndAlso Cia.Codigo = "0021" Then
|
|
Dim nptmp = "0" & ir.Número_Póliza
|
|
pol = Pols.Where(Function(x) x.NumeroPoliza = nptmp And x.FechaBaja.HasValue = False And x.companias.Codigo = Cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
If pol IsNot Nothing Then ir.Número_Póliza = nptmp
|
|
End If
|
|
If pol Is Nothing AndAlso Cia.Codigo = "0030" AndAlso Recibo.DatosRecibo.OtrosDatos IsNot Nothing Then
|
|
Dim odPolizaTron = Recibo.DatosRecibo.OtrosDatos.FirstOrDefault(Function(x) x.DescripcionDato = "POLIZA TRON")
|
|
If odPolizaTron IsNot Nothing Then
|
|
ir.Número_Póliza = odPolizaTron.ValorSubdato
|
|
pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza 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 pol = Pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza And x.companias.Codigo = Cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
End If
|
|
End If
|
|
' Else
|
|
' pol = pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza 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 pol = pols.Where(Function(x) x.NumeroPoliza = ir.Número_Póliza And x.companias.Codigo = cia.Codigo And x.RechazoSuplemento = False).OrderByDescending(Function(x) x.NumeroSuplemento).FirstOrDefault
|
|
' End If
|
|
|
|
Dim idTipoRecibo As Integer
|
|
If pol IsNot Nothing Then
|
|
ir.Observaciones = pol.Observaciones
|
|
ir.Tipo_Pago = pol.TipoPago
|
|
Try
|
|
ir.Forma_Pago_Recibida = ObtieneFormaPagoEIAC(Recibo.DatosRecibo.GestionCobro.DatosFormaPago.ClaseFormaPago.ToString)
|
|
Catch ex As Exception
|
|
ir.Forma_Pago_Recibida = "DESCONOCIDA"
|
|
End Try
|
|
Try
|
|
ir.Situacion_Recibo = ObtieneSituacionReciboEIAC(Recibo.DatosRecibo.SituacionRecibo.ToString)
|
|
Catch ex As Exception
|
|
ir.Situacion_Recibo = "DESCONOCIDA"
|
|
End Try
|
|
Try
|
|
ir.Fecha_Situacion = Recibo.DatosRecibo.Fechas.FechaSituacion
|
|
Catch EX As Exception
|
|
End Try
|
|
Select Case Recibo.DatosRecibo.ClaseRecibo
|
|
Case ProcesosEIAC_V6.claves_claserecibo.NP
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal < 0 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.EX").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.E").idEnumeracion
|
|
End If
|
|
Case ProcesosEIAC_V6.claves_claserecibo.EX
|
|
If Recs.Where(Function(X) X.idPoliza = pol.idPoliza And X.CodigoRecibo <> ir.Código_Recibo).Count > 1 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CX").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.EX").idEnumeracion
|
|
End If
|
|
Case ProcesosEIAC_V6.claves_claserecibo.SU
|
|
If Recs.Where(Function(X) X.idPoliza = pol.idPoliza And X.CodigoRecibo <> ir.Código_Recibo).Count > 1 Then
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.CS").idEnumeracion
|
|
Else
|
|
idTipoRecibo = TiposRecibos.First(Function(x) x.Codigo = "TRC.ES").idEnumeracion
|
|
End If
|
|
Case Else
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal < 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
|
|
End Select
|
|
ir.Tipo = TiposRecibos.First(Function(X) X.idEnumeracion = idTipoRecibo).Descripcion
|
|
Else
|
|
ir.Tipo = Recibo.DatosRecibo.ClaseRecibo.ToString
|
|
End If
|
|
|
|
Dim Consorcio As Double = 0
|
|
Try
|
|
Dim dc = Recibo.DatosRecibo.DatosImportes.Importes.DatosCargos.Where(Function(x) x.ClaseCargo = ProcesosEIAC_V6.claves_cargo.REDD Or
|
|
x.ClaseCargo = ProcesosEIAC_V6.claves_cargo.REPB Or
|
|
x.ClaseCargo = ProcesosEIAC_V6.claves_cargo.RSOA Or
|
|
x.ClaseCargo = ProcesosEIAC_V6.claves_cargo.RDM).ToList
|
|
If dc IsNot Nothing Then Consorcio = dc.Sum(Function(x) x.Importe)
|
|
Catch
|
|
End Try
|
|
If pol IsNot Nothing Then RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Consorcio, Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
' If Recibo.DatosRecibo.SituacionRecibo <> ProcesosEIAC_V6.claves_situacionrecibo.AN OrElse Recibo.DatosRecibo.MovimientosRecibo.Any(Function(x) x.ClaseMovimiento = ProcesosEIAC_V6.claves_clasemovimientorecibo.AN) = False Then
|
|
If ListadoRecibosAnulados Is Nothing OrElse ListadoRecibosAnulados.Contains(ir.Código_Recibo) = False OrElse ((Recibo.DatosRecibo.SituacionRecibo <> ProcesosEIAC_V6.claves_situacionrecibo.AN AndAlso Recibo.DatosRecibo.SituacionRecibo <> ProcesosEIAC_V6.claves_situacionrecibo.DE) OrElse Recibo.DatosRecibo.MovimientosRecibo.Any(Function(x) x.ClaseMovimiento = ProcesosEIAC_V6.claves_clasemovimientorecibo.AN OrElse x.ClaseMovimiento = ProcesosEIAC_V6.claves_clasemovimientorecibo.DE) = False) Then
|
|
If pol IsNot Nothing Then
|
|
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Consorcio, Recibo.DatosRecibo.DatosImportes.Importes.PrimaTotal, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
Dim recenfic = Lrai.FirstOrDefault(Function(x) x.Código_Recibo = ir.Código_Recibo And x.Correcto)
|
|
|
|
If recenfic Is Nothing AndAlso Cia.Codigo = "0045" AndAlso ir.Código_Recibo.Length = 7 Then
|
|
Dim nretmp = "0" & ir.Código_Recibo
|
|
recenfic = Lrai.FirstOrDefault(Function(x) x.Código_Recibo = nretmp And x.Correcto)
|
|
If recenfic IsNot Nothing Then ir.Código_Recibo = nretmp
|
|
End If
|
|
|
|
|
|
Dim ReciboActualDup As Boolean = False
|
|
If recenfic IsNot Nothing Then
|
|
If recenfic.Fecha_Situacion.Value <= ir.Fecha_Situacion.Value Then
|
|
If recenfic.Total_Recibo = ir.Total_Recibo Then
|
|
recenfic.Correcto = False
|
|
recenfic.Corregible = False
|
|
recenfic.Mensaje = "Recibo actualizado en Posteriores Entradas"
|
|
Else
|
|
ReciboActualDup = True
|
|
recenfic.Mensaje = "Recibo duplicado con ficheros con importes diferentes"
|
|
ir.Mensaje = "Recibo duplicado en ficheros con importes diferentes"
|
|
End If
|
|
Else
|
|
ReciboActualDup = True
|
|
End If
|
|
End If
|
|
|
|
|
|
'If Not Lrai.Any(Function(x) x.Código_Recibo = ir.Código_Recibo And x.Correcto) Then
|
|
If Not ReciboActualDup Then
|
|
Dim Rec = Recs.Where(Function(x) x.CodigoRecibo = ir.Código_Recibo).FirstOrDefault
|
|
If Rec IsNot Nothing AndAlso Cia.Codigo = "0017" AndAlso Rec.NumeroPoliza <> ir.Número_Póliza AndAlso Rec.FechaVencimiento < Today Then
|
|
Rec.CodigoRecibo = ReciboAHistoricoCaser(Rec.CodigoRecibo)
|
|
Rec.NumeroRecibo = Rec.CodigoRecibo.Split("/")(1)
|
|
Rec = Nothing
|
|
End If
|
|
|
|
If Rec Is Nothing AndAlso Cia.Codigo = "0045" AndAlso ir.Código_Recibo.Length = 7 Then
|
|
Dim nretmp = "0" & ir.Código_Recibo
|
|
Rec = Recs.Where(Function(x) x.CodigoRecibo = nretmp).FirstOrDefault
|
|
If Rec IsNot Nothing Then ir.Código_Recibo = nretmp
|
|
End If
|
|
|
|
If Rec Is Nothing Then
|
|
If ir.Fecha_Efecto.AddMonths(1) > Today OrElse Cia.Codigo <> "0025" 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 Recibo.DatosRecibo.IdRecibo.ToString.Contains(recant.NumeroRecibo) = False)) Then
|
|
If Not (ir.Número_Póliza = "41383910" And Cia.Codigo = "0027") Then
|
|
If Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta <> 0 Then
|
|
If pol.FechaBaja.HasValue Then
|
|
ir.Mensaje = "Recibo Correcto (Póliza de Baja)"
|
|
Else
|
|
ir.Mensaje = "Recibo Correcto"
|
|
End If
|
|
ir.Corregible = True
|
|
ir.Correcto = True
|
|
Else
|
|
ir.Mensaje = "Recibo con Prima Neta = 0"
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
End If
|
|
|
|
'RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
If ir.Correcto AndAlso 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
|
|
ElseIf ir.Correcto Then
|
|
If ir.Gestionado_Por_Cia AndAlso (ir.Poliza.idTipoPago <> bdGestionAsegasa.recibos.idtippCIA OrElse ir.Poliza.idTipoPago <> bdGestionAsegasa.recibos.idtippFAE) Then
|
|
ir.Mensaje = "Recibo Gestionado por cía. Se actualizará la póliza a Gestionada por la compañía"
|
|
Else
|
|
If ir.Gestionado_Por_Cia = False AndAlso (ir.Poliza.idTipoPago = bdGestionAsegasa.recibos.idtippCIA OrElse ir.Poliza.idTipoPago = bdGestionAsegasa.recibos.idtippFAE) Then
|
|
ir.Mensaje = "Recibo NO Gestionado por CÍA. Se actualizará la póliza a cobro por banco"
|
|
End If
|
|
End If
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = True
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
ir.Mensaje = "RECIBO DE PÓLIZA ESPECIAL"
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = True
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
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
|
|
If recant.FechaFacturacion.HasValue Then
|
|
ir.Mensaje = "Existe otro recibo facturado de la misma póliza con el mismo efecto y vencimiento (F.Efecto Anterior a un Mes) (" & recant.CodigoRecibo & ")"
|
|
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 & ")"
|
|
If ListadoRecibosDuplicados IsNot Nothing Then ListadoRecibosDuplicados.Add(recant.CodigoRecibo)
|
|
End If
|
|
End If
|
|
End If
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = True
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
ir.Mensaje = "Recibo Con fecha de efecto anterior a la permitida."
|
|
End If
|
|
Else
|
|
If Rec.idCausaBaja = idCabaFP() AndAlso ir.Situacion_Recibo = "COBRADO" Then
|
|
ir.Mensaje = "Actualización de causa de baja de recibo ya existente (Recibo de baja por FP a Recibo de baja por cobro en CIA)"
|
|
ir.PagadoEnCia = True
|
|
Else
|
|
If Rec.FechaPago.HasValue = False And Rec.idTipoPago = idtippCIA() And ir.Situacion_Recibo = "COBRADO" Then
|
|
ir.Mensaje = "Actualización de recibo ya existente (Recibo con cobro a cía pagado)"
|
|
ir.Actualizado = True
|
|
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
|
|
End If
|
|
End If
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
End If
|
|
Else
|
|
' aqui
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
If ir.Mensaje = "" Then
|
|
' RellenaDatosRecibo(Cia.Codigo, ir, F, pol, sobrecomision, Comscia, ComsAge, TiposRecibos, idTipoRecibo, Recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta, Recibo.DatosRecibo.ClaseRecibo = ProcesosEIAC_V6.claves_claserecibo.NP, Recibo.DatosRecibo.GestionCobro.ClaseGestion = ProcesosEIAC_V6.claves_clasegestion.CO)
|
|
If ir.Situacion_Recibo = "COBRADO" And ir.Tipo_Pago = "GESTIONADO POR LA COMPAÑÍA" And ir.Fecha_Situacion.HasValue Then
|
|
ir.Mensaje = "Actualización de recibo (Recibo con cobro a cía pagado)"
|
|
ir.Actualizado = True
|
|
Else
|
|
ir.Mensaje = "Recibo Duplicado en el fichero"
|
|
End If
|
|
End If
|
|
End If
|
|
If pol.Tomador Is Nothing Then
|
|
ir.Tomador = "* NO ASIGNADO EN PÓLIZA *"
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
ir.Mensaje = "TOMADOR NO ASIGNADO EN PÓLIZA"
|
|
Else
|
|
ir.Tomador = pol.Tomador.RazonSocial
|
|
End If
|
|
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
|
|
|
|
Else
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
|
|
ir.Mensaje = "Póliza no encontrada"
|
|
End If
|
|
Else
|
|
Dim Rec = Recs.Where(Function(x) x.CodigoRecibo = ir.Código_Recibo).FirstOrDefault
|
|
|
|
If Rec Is Nothing AndAlso Cia.Codigo = "0045" AndAlso ir.Código_Recibo.Length = 7 Then
|
|
Dim nretmp = "0" & ir.Código_Recibo
|
|
Rec = Recs.Where(Function(x) x.CodigoRecibo = nretmp).FirstOrDefault
|
|
If Rec IsNot Nothing Then ir.Código_Recibo = nretmp
|
|
End If
|
|
|
|
|
|
ir.Correcto = False
|
|
ir.Corregible = False
|
|
Dim anulacion = Recibo.DatosRecibo.MovimientosRecibo.FirstOrDefault(Function(x) x.ClaseMovimiento = ProcesosEIAC_V6.claves_clasemovimientorecibo.AN)
|
|
Dim MotivoAnulacion As String = ""
|
|
If ListadoRecibosAnulados IsNot Nothing AndAlso ListadoRecibosAnulados.Contains(ir.Código_Recibo) Then
|
|
MotivoAnulacion = "Recibo Anulado (No existente en Asegasa y anulado previamente)"
|
|
Else
|
|
If anulacion IsNot Nothing AndAlso anulacion.Anulacion IsNot Nothing Then
|
|
MotivoAnulacion = anulacion.Anulacion.DescripcionMotivo
|
|
Else
|
|
If Recibo.DatosRecibo.SituacionRecibo = ProcesosEIAC_V6.claves_situacionrecibo.DE Then
|
|
MotivoAnulacion = "Devolución en Cía"
|
|
Else
|
|
MotivoAnulacion = "Desconocida"
|
|
End If
|
|
End If
|
|
If Rec Is Nothing Then
|
|
ir.Mensaje = "Recibo Anulado (No existente en Asegasa). Causa: " & MotivoAnulacion
|
|
Else
|
|
If Rec.FechaBaja.HasValue Then
|
|
ir.Mensaje = "Recibo Anulado (En Asegasa y en Compañía). Causa: " & MotivoAnulacion
|
|
Else
|
|
If Rec.FechaFacturacion.HasValue Then
|
|
ir.Mensaje = "Recibo Anulado (En vigor y facturado en Asegasa. NO SE ANULARÁ EN ASEGASA). Causa: " & MotivoAnulacion
|
|
Else
|
|
ir.Mensaje = "Recibo Anulado (En vigor en Asegasa). Causa: " & MotivoAnulacion
|
|
End If
|
|
End If
|
|
End If
|
|
ir.Anulado = True
|
|
If ListadoRecibosAnulados IsNot Nothing AndAlso ListadoRecibosAnulados.Contains(ir.Código_Recibo) = False AndAlso
|
|
(Rec Is Nothing OrElse
|
|
(Rec.FechaBaja.HasValue = False AndAlso
|
|
(Rec.FechaFacturacion.HasValue = False OrElse Rec.FechaPago.HasValue = False AndAlso Rec.idTipoPago <> idTippBA()) AndAlso
|
|
F.FechaProcesado.HasValue = False)) Then ListadoRecibosAnulados.Add(ir.Código_Recibo)
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
Throw New Exception("Error Incorporando Recibo: " & Recibo.DatosRecibo.IdRecibo & " Póliza: " & Recibo.DatosPoliza.IdPoliza, ex)
|
|
End Try
|
|
End If
|
|
Next
|
|
End If
|
|
Catch ex As Exception
|
|
Throw New Exception("Error Incorporando " & F.NombreFichero & " Compañia: " & F.companias.Nombre, ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Shared Function ReciboAHistoricoCaser(codigoRecibo As String) As String
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Dim r = bd.recibos.First(Function(x) x.CodigoRecibo = codigoRecibo)
|
|
Dim idCaser = bd.companias.First(Function(x) x.Codigo = "0017").idCompania
|
|
Dim i As Integer = 0
|
|
If r.NumeroRecibo.EndsWith(".") Then r.NumeroRecibo = r.NumeroRecibo.TrimEnd(".")
|
|
Dim sNuevoRecibo As String = r.NumeroRecibo & "-H"
|
|
Do Until bd.recibos.FirstOrDefault(Function(x) x.NumeroRecibo = sNuevoRecibo AndAlso x.polizassg.idCompania = idCaser) Is Nothing
|
|
i += 1
|
|
sNuevoRecibo = r.NumeroRecibo & "-H" & i.ToString
|
|
Loop
|
|
r.NumeroRecibo = sNuevoRecibo
|
|
r.CodigoRecibo = "0017/" & sNuevoRecibo
|
|
bd.SaveChanges()
|
|
Return r.CodigoRecibo
|
|
End Function
|
|
|
|
Private Shared Function ObtieneFormaPagoEIAC(claseFormaPago As String) As String
|
|
Select Case claseFormaPago
|
|
Case "CH"
|
|
Return "CHEQUE"
|
|
Case "CC"
|
|
Return "CUENTA BANCARIA"
|
|
Case "IN"
|
|
Return "INGRESO O TRANSFERENCIA"
|
|
Case "OF"
|
|
Return "OFICINA, EFECTIVO O GESTIÓN DELEGADA"
|
|
Case "TA"
|
|
Return "TARJETA"
|
|
Case "PC"
|
|
Return "POR CUENTA DE COMPAÑÍA"
|
|
Case Else
|
|
Return "DESCONOCIDO"
|
|
End Select
|
|
End Function
|
|
Private Shared Function ObtieneSituacionReciboEIAC(Situacion As String) As String
|
|
Select Case Situacion
|
|
Case "PE"
|
|
Return "PENDIENTE"
|
|
Case "CO"
|
|
Return "COBRADO"
|
|
Case "DE"
|
|
Return "DEVUELTO"
|
|
Case "AN"
|
|
Return "ANULADO"
|
|
Case "LI"
|
|
Return "LIQUIDADO"
|
|
Case "RE"
|
|
Return "REHABILITADO"
|
|
Case Else
|
|
Return "DESCONOCIDO"
|
|
End Select
|
|
End Function
|
|
|
|
|
|
Private Shared Sub RellenaDatosRecibo(CodigoCia As String, Rec As ReciboAIncorporar, f As ficheroscompanias, pol As polizassg, sobrecomision As Double, comscia As List(Of comisionescompanias), comsage As List(Of comisionesagentes), TiposRecibos As List(Of enumeraciones), idTipo As Integer, PrimaNeta As Double, Consorcio As Double, TotalRecibo As Double, EsProduccion As Boolean, GestionadoPorCia As Boolean, Optional Sumar As Boolean = False)
|
|
Try
|
|
' Dim idCABASUPL = bd.enumeraciones.First(Function(X) X.Codigo = "CABA.SUPL").idEnumeracion
|
|
With Rec
|
|
If CodigoCia = "0024" Then
|
|
.Gestionado_Por_Cia = True
|
|
Else
|
|
.Gestionado_Por_Cia = (CodigoCia <> "0030" OrElse pol.ramos.Codigo.StartsWith("2-")) AndAlso GestionadoPorCia
|
|
End If
|
|
|
|
'If CodigoCia = "0024" OrElse (CodigoCia = "0045" AndAlso pol.ramos.enumeraciones.Codigo = "FAMRAM.AS") Then
|
|
' .Gestionado_Por_Cia = True
|
|
'Else
|
|
' .Gestionado_Por_Cia = CodigoCia <> "0045" AndAlso (CodigoCia <> "0030" OrElse pol.ramos.Codigo.StartsWith("2-")) AndAlso GestionadoPorCia
|
|
'End If
|
|
.Es_Produccion = EsProduccion
|
|
.Prima_Neta = PrimaNeta
|
|
|
|
.idFicheroCompania = f.idFichero
|
|
.Poliza = pol
|
|
' .ReciboEIAC = recibo
|
|
.idTipoRecibo = idTipo
|
|
|
|
If pol.idTipoPago.HasValue = False Then .Mensaje = "Tipo de pago no asignado en la póliza"
|
|
.IBAN = pol.IBAN
|
|
'
|
|
' COMISIONES
|
|
'
|
|
Dim comcia = comscia.FirstOrDefault(Function(x) x.idRamo.HasValue AndAlso x.idRamo = pol.idRamo AndAlso (x.FechaInicioCampana.HasValue = False OrElse x.FechaInicioCampana <= Rec.Fecha_Efecto) And (x.FechaFinCampana.HasValue = False OrElse x.FechaFinCampana >= Rec.Fecha_Efecto))
|
|
Dim PCE As Double = 0
|
|
Dim PCC As Double = 0
|
|
If comcia IsNot Nothing Then
|
|
PCE = If(comcia.PorcentajeComisionEmision.HasValue, comcia.PorcentajeComisionEmision.Value, 0)
|
|
PCC = If(comcia.PorcentajeComisionCartera.HasValue, comcia.PorcentajeComisionCartera.Value, 0)
|
|
End If
|
|
|
|
Dim ComisionPrevista As Double = 0
|
|
Dim ComisionPrevistaAsegasa As Double = 0
|
|
' Dim primaneta = recibo.DatosRecibo.DatosImportes.Importes.PrimaNeta
|
|
|
|
If EsProduccion Then
|
|
ComisionPrevista = Math.Round(PrimaNeta * PCE / 100, 2, MidpointRounding.AwayFromZero)
|
|
ComisionPrevistaAsegasa = Math.Round((PrimaNeta * PCE / 100) + sobrecomision, 2, MidpointRounding.AwayFromZero)
|
|
Else
|
|
ComisionPrevista = Math.Round(PrimaNeta * PCC / 100, 2, MidpointRounding.AwayFromZero)
|
|
ComisionPrevistaAsegasa = Math.Round((PrimaNeta * PCC / 100) + sobrecomision, 2, MidpointRounding.AwayFromZero)
|
|
End If
|
|
Dim DiferenciaComision As Double
|
|
Dim DiferenciaComisionAgente As Double
|
|
If CodigoCia = "0037" Or CodigoCia = "0024" Then
|
|
DiferenciaComision = 0
|
|
DiferenciaComisionAgente = 0
|
|
Else
|
|
DiferenciaComision = .Comisión.Value + .Sobrecomisión - ComisionPrevistaAsegasa
|
|
DiferenciaComisionAgente = .Comisión.Value + .Sobrecomisión - ComisionPrevista
|
|
End If
|
|
|
|
|
|
.Comisión_Prevista_Agente = If(Sumar AndAlso .Comisión_Prevista_Agente.HasValue, .Comisión_Prevista_Agente.Value, 0) + ComisionPrevista
|
|
.Comisión_Prevista_ASEGASA = If(Sumar AndAlso .Comisión_Prevista_ASEGASA.HasValue, .Comisión_Prevista_ASEGASA.Value, 0) + ComisionPrevistaAsegasa
|
|
.Diferencia_Comisión = DiferenciaComision
|
|
|
|
If Math.Abs(DiferenciaComision) > 0.05 Then
|
|
If .Mensaje = "Recibo Correcto" Then
|
|
If comcia Is Nothing Then
|
|
.Mensaje = "No existe comisión para el ramo en esta compañía"
|
|
.Correcto = False
|
|
Else
|
|
If Math.Abs(DiferenciaComisionAgente) > 0.05 Then
|
|
.Mensaje = "Comisión Recibida distinta a la prevista"
|
|
Else
|
|
.Mensaje = "Comisión Recibida distinta a la prevista, pero correcta sin sobrecosto"
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
Dim comage = comsage.FirstOrDefault(Function(x) x.idAgente = pol.idAgente And (x.idCompania.HasValue AndAlso x.idCompania = pol.idCompania) And (x.idRamo.HasValue AndAlso x.idRamo = pol.idRamo))
|
|
Dim Pca As Double = 0
|
|
If comage Is Nothing Then
|
|
comage = comsage.FirstOrDefault(Function(x) x.idAgente = pol.idAgente And x.idCompania.HasValue = False And (x.idRamo.HasValue AndAlso x.idRamo = pol.idRamo))
|
|
If comage Is Nothing Then
|
|
comage = comsage.FirstOrDefault(Function(x) x.idAgente = pol.idAgente And x.idRamo.HasValue = False And (x.idCompania.HasValue AndAlso x.idCompania = pol.idCompania))
|
|
End If
|
|
End If
|
|
If comage IsNot Nothing Then
|
|
If PrimaNeta <= comage.Limite.Value Then
|
|
Pca = comage.ComisionMenorIgualLimiteEmision
|
|
Else
|
|
Pca = comage.ComisionMayorLimiteEmision
|
|
End If
|
|
Else
|
|
If PrimaNeta <= pol.agentes.LimiteCondicionesGenerales.Value Then
|
|
Pca = pol.agentes.ComisionMenorIgualLimiteEmision
|
|
Else
|
|
Pca = pol.agentes.ComisionMayorLimiteEmision
|
|
End If
|
|
End If
|
|
If Pca >= 73 Then
|
|
.Mensaje = "Comisión al agente >=73% errónea se le recalculará sin comisión al agente, revise las comisión de este agente."
|
|
Pca = 0
|
|
End If
|
|
If pol.FechaBaja.HasValue AndAlso pol.idCausaBaja <> idCabaSUPL() Then
|
|
.Mensaje = "La póliza está dada de baja por " & pol.CausaBaja
|
|
'Else
|
|
' If idTipo = TiposRecibos.First(Function(x) x.Codigo = "TRC.C").idEnumeracion And pol.FechaReciboCompania.HasValue = False Then
|
|
' .Mensaje = "La póliza no tiene fecha recibo de compañía"
|
|
' End If
|
|
End If
|
|
' If pol.FechaReciboCompania.HasValue = False Then pol.FechaReciboCompania = Now
|
|
.Consorcio = If(Sumar, .Consorcio + Consorcio, Consorcio)
|
|
.Total_Recibo = If(Sumar, .Total_Recibo + TotalRecibo, TotalRecibo)
|
|
End With
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
Public Shared Sub ImportaMovimientosRecibosEIAC_V6(bd As bdGestionAsegasa.gestionasegasaEntities, F As ficheroscompanias, iNumfic As Integer)
|
|
Dim DatosEIAC As ProcesosEIAC_V6.ProcesosEIAC = tsl5.Utilidades.Deserializa(F.Fichero, GetType(ProcesosEIAC_V6.ProcesosEIAC))
|
|
Dim iNumrec As Integer = 0
|
|
If DatosEIAC.Objetos IsNot Nothing AndAlso DatosEIAC.Objetos.Items IsNot Nothing Then
|
|
Dim lMovimientos = DatosEIAC.Objetos.Items.Where(Function(x) x.GetType Is GetType(ProcesosEIAC_V6.tipo_movimientorecibo)).Cast(Of ProcesosEIAC_V6.tipo_movimientorecibo)
|
|
For Each m In lMovimientos
|
|
Select Case m.ClaseMovimiento
|
|
Case claves_clasemovimientorecibo.AE '"AE" ' Anulación de extorno
|
|
Case claves_clasemovimientorecibo.AN 'Anulación
|
|
Case claves_clasemovimientorecibo.CO 'Cobro
|
|
Case claves_clasemovimientorecibo.DE 'Devolución
|
|
Case claves_clasemovimientorecibo.DL 'Devolución Liquidación
|
|
Case claves_clasemovimientorecibo.EM 'Emisión
|
|
Case claves_clasemovimientorecibo.EX 'Pago de extorno
|
|
Case claves_clasemovimientorecibo.LI 'Liquidación
|
|
End Select
|
|
Next
|
|
End If
|
|
End Sub
|
|
|
|
'Private Shared Function SeleccionaDuracion(fechaEfecto As Date, fechaVencimiento As Date, ldur As List(Of enumeraciones)) As Integer
|
|
' Dim difdias = fechaVencimiento.Subtract(fechaEfecto).TotalDays
|
|
' Select Case difdias
|
|
' Case < 5
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.U").idEnumeracion
|
|
' Case < 33
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.M").idEnumeracion
|
|
' Case < 66
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.B").idEnumeracion
|
|
' Case < 96
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.T").idEnumeracion
|
|
' Case < 190
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.S").idEnumeracion
|
|
' Case < 368
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.A").idEnumeracion
|
|
' Case Else
|
|
' Return ldur.First(Function(x) x.Codigo = "DUR.D").idEnumeracion
|
|
' End Select
|
|
'End Function
|
|
|
|
|
|
|
|
Public Shared Sub GuardaRecibosEIAC(bd As bdGestionAsegasa.gestionasegasaEntities, rai As List(Of ReciboAIncorporar), RecibosAAnular As List(Of String), RecibosAActualizar As List(Of ReciboAIncorporar), RecibosPagadosEnCIA As List(Of ReciboAIncorporar), MostrarProgreso As Boolean, FicherosAMarcar As List(Of ficheroscompanias), ComsCia As List(Of comisionescompanias), comsAge As List(Of comisionesagentes), lDur As List(Of enumeraciones))
|
|
If MostrarProgreso Then
|
|
DXSplashScreen.Show(Of SplashScreenTecnosis)()
|
|
DXSplashScreen.SetState("Guardando recibos, por favor espere ...")
|
|
End If
|
|
Dim Ahora = tsl5.bbdd.AhoraMysql(bd)
|
|
rai = rai.Where(Function(x) x.Correcto).ToList
|
|
Dim Tippc = bd.enumeraciones.First(Function(x) x.Codigo = "TRC.C").idEnumeracion
|
|
For Each r In rai
|
|
Dim rec As New recibos
|
|
bd.recibos.AddObject(rec)
|
|
With rec
|
|
.idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario
|
|
.FechaModificacion = Now
|
|
.idFicheroCompania = r.idFicheroCompania
|
|
.polizassg = r.Poliza
|
|
.CodigoRecibo = r.Código_Recibo
|
|
.NumeroRecibo = r.Código_Recibo.Split("/")(1)
|
|
.FechaRecepcionCia = Now
|
|
.FechaEfecto = r.Fecha_Efecto
|
|
.FechaVencimiento = r.Fecha_Vencimiento
|
|
' .idDuracion = SeleccionaDuracion(.FechaEfecto, .FechaVencimiento, lDur)
|
|
.idTipoPago = r.Poliza.idTipoPago
|
|
'If r.ReciboEIAC.DatosRecibo.GestionCobro.ClaseGestion = claves_clasegestion.CO Then .idTipoPago = idTipoPagoCia
|
|
If r.Gestionado_Por_Cia Then
|
|
If .idTipoPago <> bdGestionAsegasa.recibos.idtippCIA AndAlso .idTipoPago <> bdGestionAsegasa.recibos.idtippFAE Then
|
|
.idTipoPago = bdGestionAsegasa.recibos.idtippCIA
|
|
.polizassg.idTipoPago = bdGestionAsegasa.recibos.idtippCIA
|
|
End If
|
|
Else
|
|
If .idTipoPago = bdGestionAsegasa.recibos.idtippCIA OrElse .idTipoPago = bdGestionAsegasa.recibos.idtippFAE Then
|
|
.idTipoPago = bdGestionAsegasa.recibos.idTippBA
|
|
.polizassg.idTipoPago = bdGestionAsegasa.recibos.idTippBA
|
|
End If
|
|
End If
|
|
.IBAN = r.Poliza.IBAN
|
|
If r.Poliza.FechaBaja.HasValue Then
|
|
If r.Poliza.idCausaBaja.HasValue AndAlso r.Poliza.idCausaBaja.Value <> idCabaSUPL() Then
|
|
If r.Poliza.idCausaBaja.Value = idCabaFP() Or r.Poliza.idCausaBaja.Value = idCabaCIE() Then
|
|
.polizassg.FechaBaja = Nothing
|
|
.polizassg.idCausaBaja = Nothing
|
|
Else
|
|
.FechaBaja = r.Poliza.FechaBaja
|
|
.idCausaBaja = r.Poliza.idCausaBaja
|
|
End If
|
|
End If
|
|
End If
|
|
.FechaExpedicion = Now
|
|
.idAgente = r.Poliza.idAgente
|
|
.idSubagente = r.Poliza.idSubAgente
|
|
'.PrimaNeta = r.ReciboEIAC.DatosRecibo.DatosImportes.Importes.PrimaNeta
|
|
.PrimaNeta = r.Prima_Neta
|
|
|
|
.Consorcio = r.Consorcio
|
|
'.TotalRecibo = r.ReciboEIAC.DatosRecibo.DatosImportes.Importes.PrimaTotal
|
|
.TotalRecibo = r.Total_Recibo
|
|
If r.Poliza.companias.Codigo <> "0030" Then
|
|
.BonificacionORecargo = 0
|
|
.Impuesto = Math.Round(.TotalRecibo.Value - .PrimaNeta.Value - .Consorcio.Value, 2, MidpointRounding.AwayFromZero)
|
|
Else
|
|
.BonificacionORecargo = Math.Round(.TotalRecibo.Value - .PrimaNeta.Value - .Consorcio.Value, 2, MidpointRounding.AwayFromZero)
|
|
.Impuesto = 0
|
|
End If
|
|
|
|
.RecargoExterno = 0
|
|
.AsegasaRecargoExterno = 0
|
|
.idTipo = r.idTipoRecibo
|
|
'
|
|
' COMISIONES
|
|
'
|
|
.AsegasaComisionConsorcio = 0
|
|
Dim comcia = ComsCia.FirstOrDefault(Function(x) x.idCompania = r.idCompañia And x.idRamo = r.Poliza.idRamo And (x.FechaInicioCampana.HasValue = False OrElse x.FechaInicioCampana <= .FechaEfecto) And (x.FechaFinCampana.HasValue = False OrElse x.FechaFinCampana >= .FechaEfecto))
|
|
Dim PCE As Double = 0
|
|
Dim PCC As Double = 0
|
|
If comcia IsNot Nothing Then
|
|
PCE = comcia.PorcentajeComisionEmision.Value
|
|
PCC = comcia.PorcentajeComisionCartera.Value
|
|
End If
|
|
.ComisionPrevista = 0
|
|
|
|
|
|
'If r.ReciboEIAC.DatosRecibo.ClaseRecibo = claves_claserecibo.NP Then
|
|
If r.Es_Produccion Then
|
|
.PorcentajeComisionPrevista = PCE
|
|
.ComisionPrevista = Math.Round((.PrimaNeta.Value + .BonificacionORecargo.Value) * .PorcentajeComisionPrevista.Value / 100, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionPrevistaAsegasa = Math.Round(((.PrimaNeta.Value + .BonificacionORecargo.Value) * .PorcentajeComisionPrevista.Value / 100) + r.Sobrecomisión, 2, MidpointRounding.AwayFromZero)
|
|
Else
|
|
.PorcentajeComisionPrevista = PCC
|
|
.ComisionPrevista = Math.Round((.PrimaNeta.Value + .BonificacionORecargo.Value) * .PorcentajeComisionPrevista.Value / 100, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionPrevistaAsegasa = Math.Round(((.PrimaNeta.Value + .BonificacionORecargo.Value) * .PorcentajeComisionPrevista.Value / 100) + r.Sobrecomisión, 2, MidpointRounding.AwayFromZero)
|
|
End If
|
|
|
|
.Sobrecomision = r.Sobrecomisión
|
|
.ComisionReciboPrimaNeta = r.Comisión
|
|
.PorcentajeReciboPrimaNeta = If(.PrimaNeta.Value + .BonificacionORecargo.Value = 0, 0, Math.Round(.ComisionReciboPrimaNeta.Value / (.PrimaNeta.Value + .BonificacionORecargo.Value) * 100, 2, MidpointRounding.AwayFromZero))
|
|
|
|
|
|
|
|
.BaseComisionAgente = If(.ComisionReciboPrimaNeta.Value < 0, .ComisionReciboPrimaNeta, Math.Min(.ComisionPrevista.Value, .ComisionReciboPrimaNeta.Value))
|
|
If .BaseComisionAgente = 0 Then .BaseComisionAgente = .ComisionReciboPrimaNeta
|
|
.PorcentajeBaseComisionAgente = If(.PrimaNeta.Value + .BonificacionORecargo.Value = 0, 0, Math.Round(.BaseComisionAgente.Value / (.PrimaNeta.Value + .BonificacionORecargo.Value) * 100, 2, MidpointRounding.AwayFromZero))
|
|
'.TotalComision = .ComisionReciboPrimaNeta
|
|
.TotalComision = .ComisionReciboPrimaNeta + .Sobrecomision
|
|
Dim comage = comsAge.FirstOrDefault(Function(x) x.idAgente = r.Poliza.idAgente And (x.idCompania.HasValue AndAlso x.idCompania = r.Poliza.idCompania) And (x.idRamo.HasValue AndAlso x.idRamo = r.Poliza.idRamo))
|
|
Dim Pca As Double = 0
|
|
If comage Is Nothing Then
|
|
comage = comsAge.FirstOrDefault(Function(x) x.idAgente = r.Poliza.idAgente And x.idCompania.HasValue = False And (x.idRamo.HasValue AndAlso x.idRamo = r.Poliza.idRamo))
|
|
If comage Is Nothing Then
|
|
comage = comsAge.FirstOrDefault(Function(x) x.idAgente = r.Poliza.idAgente And x.idRamo.HasValue = False And (x.idCompania.HasValue AndAlso x.idCompania = r.Poliza.idCompania))
|
|
End If
|
|
End If
|
|
If comage IsNot Nothing Then
|
|
If .PrimaNeta.Value <= comage.Limite.Value Then
|
|
Pca = comage.ComisionMenorIgualLimiteEmision
|
|
Else
|
|
Pca = comage.ComisionMayorLimiteEmision
|
|
End If
|
|
Else
|
|
If .PrimaNeta.Value <= r.Poliza.agentes.LimiteCondicionesGenerales.Value Then
|
|
Pca = r.Poliza.agentes.ComisionMenorIgualLimiteEmision
|
|
Else
|
|
Pca = r.Poliza.agentes.ComisionMayorLimiteEmision
|
|
End If
|
|
End If
|
|
|
|
.PorcentajeComisionAgente = Pca
|
|
.ComisionAgente = Math.Round(.BaseComisionAgente.Value * .PorcentajeComisionAgente.Value / 100, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionAsegasaPrimaNeta = .ComisionReciboPrimaNeta.Value - .ComisionAgente.Value
|
|
.AsegasaComisionTotal = .ComisionAsegasaPrimaNeta.Value
|
|
If r.Poliza.FechaReciboCompania.HasValue = False Then r.Poliza.FechaReciboCompania = Now
|
|
If r.Poliza.companias.Codigo = "0002" And r.idTipoRecibo <> Tippc Then
|
|
' .BloquearFacturacion = True
|
|
.Observaciones = r.Poliza.Observaciones
|
|
End If
|
|
End With
|
|
bd.SaveChanges()
|
|
|
|
If r.Situacion_Recibo = "COBRADO" AndAlso r.Forma_Pago_Recibida = "CUENTA BANCARIA" AndAlso r.Fecha_Situacion.HasValue Then
|
|
rec.polizassg.idTipoPago = bdGestionAsegasa.recibos.idtippCIA
|
|
rec.idTipoPago = bdGestionAsegasa.recibos.idtippCIA
|
|
rec.FechaPago = r.Fecha_Situacion
|
|
Dim asiento = asientos.GeneraAsientoReciboPagadoEnCia(bd, rec)
|
|
End If
|
|
'Dim reg As New registrosactualizados
|
|
'With reg
|
|
' .Tipo = "RECIBOS"
|
|
' .idAplicacion = rec.idRecibo
|
|
' .MacroAct = "CREARECMYSQL"
|
|
' .idFicheroCompania = r.idFicheroCompania
|
|
' .FechaCreacion = Ahora
|
|
'End With
|
|
'bd.registrosactualizados.AddObject(reg)
|
|
bd.SaveChanges()
|
|
Next
|
|
bd.SaveChanges()
|
|
|
|
If RecibosAAnular IsNot Nothing Then
|
|
Dim idcabaCIE = bd.enumeraciones.First(Function(X) X.Codigo = "CABA.CIE").idEnumeracion
|
|
For Each r In RecibosAAnular
|
|
Dim rec = bd.recibos.FirstOrDefault(Function(x) x.CodigoRecibo = r)
|
|
If rec IsNot Nothing Then
|
|
rec.FechaBaja = Now
|
|
rec.idCausaBaja = idcabaCIE
|
|
If rec.idTipoPago = bdGestionAsegasa.recibos.idtippCIA OrElse rec.idTipoPago = bdGestionAsegasa.recibos.idtippFAE Then
|
|
rec.FechaPago = Nothing
|
|
If rec.liquidacionesagenterecibos.Any(Function(x) x.liquidacionesagentes.enumeraciones.Codigo = "TIPLIQAG.LIQUIDACION") And Not rec.regularizacionespagosagentes.Any(Function(x) x.Tipo = bdGestionAsegasa.regularizacionespagosagentes.TipoRegularizacion.DESCOBRO_RECIBO) Then
|
|
Dim nr = rec.regularizacionespagosagentes.FirstOrDefault(Function(x) x.idLiquidacionAgente.HasValue = False)
|
|
If nr Is Nothing Then
|
|
nr = New regularizacionespagosagentes
|
|
bd.regularizacionespagosagentes.AddObject(nr)
|
|
End If
|
|
With nr
|
|
.idRecibo = rec.idRecibo
|
|
.Importe = rec.ComisionAgente
|
|
.idLiquidacionARRelacionada = Nothing
|
|
.Tipo = bdGestionAsegasa.regularizacionespagosagentes.TipoRegularizacion.DESCOBRO_RECIBO
|
|
.Concepto = "RECIBO " & rec.CodigoRecibo & " DESCOBRO AUTOMÁTICO EIAC"
|
|
.FechaCreacion = tsl5.bbdd.AhoraMysql(bd)
|
|
.idAgente = rec.idAgente
|
|
End With
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
bd.SaveChanges()
|
|
End If
|
|
|
|
If RecibosAActualizar IsNot Nothing Then
|
|
' Dim idcabaCIE = bd.enumeraciones.First(Function(X) X.Codigo = "CABA.CIE").idEnumeracion
|
|
For Each r In RecibosAActualizar
|
|
Dim rec = bd.recibos.FirstOrDefault(Function(x) x.CodigoRecibo = r.Código_Recibo)
|
|
rec.FechaPago = r.Fecha_Situacion
|
|
Next
|
|
bd.SaveChanges()
|
|
End If
|
|
If RecibosPagadosEnCIA IsNot Nothing Then
|
|
Dim idcabaPGO = bd.enumeraciones.First(Function(X) X.Codigo = "CABA.PGO").idEnumeracion
|
|
For Each r In RecibosPagadosEnCIA
|
|
Dim rec = bd.recibos.FirstOrDefault(Function(x) x.CodigoRecibo = r.Código_Recibo)
|
|
rec.FechaPago = r.Fecha_Situacion
|
|
rec.idCausaBaja = idcabaPGO
|
|
rec.polizassg.idCausaBaja = Nothing
|
|
rec.polizassg.FechaBaja = Nothing
|
|
Next
|
|
bd.SaveChanges()
|
|
End If
|
|
|
|
|
|
If FicherosAMarcar IsNot Nothing Then
|
|
For Each fic In FicherosAMarcar
|
|
fic.ProcesadoSinRecibosCorrectos = Not rai.Any(Function(x) x.idFicheroCompania = fic.idFichero)
|
|
fic.FechaProcesado = Now
|
|
fic.idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario
|
|
bd.SaveChanges()
|
|
Next
|
|
End If
|
|
If MostrarProgreso Then
|
|
DXSplashScreen.Close()
|
|
End If
|
|
End Sub
|
|
|
|
Public Shared Sub RecalculaDatosEconomicos(bd As bdGestionAsegasa.gestionasegasaEntities, Recibo As recibos, Optional RecalculaTotalComision As Boolean = True)
|
|
With Recibo
|
|
Try
|
|
|
|
.AsegasaComisionConsorcio = 0
|
|
Dim comcia = bd.comisionescompanias.FirstOrDefault(Function(x) x.idCompania = Recibo.polizassg.idCompania And x.idRamo = Recibo.polizassg.idRamo And (x.FechaInicioCampana.HasValue = False OrElse x.FechaInicioCampana <= .FechaEfecto) And (x.FechaFinCampana.HasValue = False OrElse x.FechaFinCampana >= .FechaEfecto))
|
|
|
|
.ComisionPrevista = 0
|
|
If .Sobrecomision.HasValue = False Then .Sobrecomision = 0
|
|
Dim Claserecibo As Integer = 0
|
|
If Recibo.idTipo > 0 Then Claserecibo = bd.enumeraciones.First(Function(x) x.idEnumeracion = Recibo.idTipo).ValorNumerico1
|
|
|
|
If Claserecibo = 0 Then
|
|
.PorcentajeComisionPrevista = If(comcia Is Nothing, 0, comcia.PorcentajeComisionEmision)
|
|
.PorcentajeReciboPrimaNeta = .PorcentajeComisionPrevista
|
|
Else
|
|
.PorcentajeComisionPrevista = If(comcia Is Nothing, 0, comcia.PorcentajeComisionCartera)
|
|
.PorcentajeReciboPrimaNeta = .PorcentajeComisionPrevista
|
|
End If
|
|
.ComisionPrevista = Math.Round((.PrimaNeta.Value + .BonificacionORecargo.Value) * (.PorcentajeReciboPrimaNeta.Value) / 100, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionPrevistaAsegasa = Math.Round(((.PrimaNeta.Value + .BonificacionORecargo.Value) * .PorcentajeReciboPrimaNeta.Value / 100) + Recibo.Sobrecomision.Value, 2, MidpointRounding.AwayFromZero)
|
|
|
|
If RecalculaTotalComision Then
|
|
.ComisionReciboPrimaNeta = .ComisionPrevista
|
|
.TotalComision = .ComisionReciboPrimaNeta + .Sobrecomision
|
|
Else
|
|
.ComisionReciboPrimaNeta = .TotalComision - .Sobrecomision
|
|
End If
|
|
.BaseComisionAgente = If(.ComisionReciboPrimaNeta.Value < 0, .ComisionReciboPrimaNeta.Value, Math.Min(.TotalComision.Value, Math.Min(.ComisionPrevista.Value, .ComisionReciboPrimaNeta.Value)))
|
|
.PorcentajeBaseComisionAgente = If(.PrimaNeta.Value = 0, 0, Math.Round(.BaseComisionAgente.Value / .PrimaNeta.Value * 100, 2, MidpointRounding.AwayFromZero))
|
|
RecalculaComisiones(bd, Recibo)
|
|
.TotalRecibo = Math.Round(.PrimaNeta.Value + .BonificacionORecargo.Value + .Consorcio.Value + .Impuesto.Value + .RecargoExterno.Value, 2, MidpointRounding.AwayFromZero)
|
|
Catch EX As Exception
|
|
Throw New Exception(EX.Message, EX)
|
|
End Try
|
|
End With
|
|
End Sub
|
|
Public Shared Sub RecalculaComisiones(bd As bdGestionAsegasa.gestionasegasaEntities, Recibo As recibos)
|
|
Try
|
|
With Recibo
|
|
Dim Pca As Double = 0
|
|
If Recibo.idAgente.HasValue AndAlso Recibo.idAgente.Value > 0 Then
|
|
Dim comage = bd.comisionesagentes.FirstOrDefault(Function(x) x.idAgente = Recibo.idAgente And (x.idCompania.HasValue AndAlso x.idCompania = Recibo.polizassg.idCompania) And (x.idRamo.HasValue AndAlso x.idRamo = Recibo.polizassg.idRamo))
|
|
If comage Is Nothing Then
|
|
comage = bd.comisionesagentes.FirstOrDefault(Function(x) x.idAgente = Recibo.idAgente And x.idCompania.HasValue = False And (x.idRamo.HasValue AndAlso x.idRamo = Recibo.polizassg.idRamo))
|
|
If comage Is Nothing Then
|
|
comage = bd.comisionesagentes.FirstOrDefault(Function(x) x.idAgente = Recibo.idAgente And x.idRamo.HasValue = False And (x.idCompania.HasValue AndAlso x.idCompania = Recibo.polizassg.idCompania))
|
|
End If
|
|
End If
|
|
If comage IsNot Nothing Then
|
|
If .PrimaNeta.Value <= comage.Limite.Value Then
|
|
Pca = comage.ComisionMenorIgualLimiteEmision
|
|
Else
|
|
Pca = comage.ComisionMayorLimiteEmision
|
|
End If
|
|
Else
|
|
If .PrimaNeta.Value <= Recibo.agentes.LimiteCondicionesGenerales.Value Then
|
|
Pca = Recibo.agentes.ComisionMenorIgualLimiteEmision
|
|
Else
|
|
Pca = Recibo.agentes.ComisionMayorLimiteEmision
|
|
End If
|
|
End If
|
|
End If
|
|
.PorcentajeComisionAgente = Pca
|
|
.ComisionAgente = Math.Round(.BaseComisionAgente.Value * .PorcentajeComisionAgente.Value / 100, 2, MidpointRounding.AwayFromZero)
|
|
.ComisionAsegasaPrimaNeta = .ComisionReciboPrimaNeta.Value - .ComisionAgente.Value
|
|
.AsegasaComisionTotal = .ComisionAsegasaPrimaNeta.Value + .AsegasaComisionConsorcio + .AsegasaRecargoExterno
|
|
End With
|
|
Catch ex As Exception
|
|
Throw New Exception(ex.Message, ex)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
Public Shared Sub GeneraEmailRecibosIncorporados(recsc As List(Of ReciboAIncorporar), recsa As List(Of ReciboAIncorporar), recsnp As List(Of ReciboAIncorporar), recsact As List(Of ReciboAIncorporar), RecsPagsEnCia As List(Of ReciboAIncorporar))
|
|
Try
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContextoCN()
|
|
Dim cta = bd.cuentascorreo.First(Function(x) x.Codigo = "SEG.GENERALES")
|
|
Dim sDestinatario = bd.usuarios.First(Function(x) x.idUsuario = bdGestionAsegasa.Utilidades.dsc.idUsuario).email.NothingAVacio
|
|
|
|
If sDestinatario = "" Then sDestinatario = cta.Remitente
|
|
Dim sAsunto = "Información de incorporación/anulación/actualización de recibos (" & Now.ToString("dd-MM-yyyy") & ")"
|
|
Dim Listados As New List(Of List(Of ListadoRecibosIncorporados))
|
|
Dim NombreTablas As New List(Of String)
|
|
If recsc.Count > 0 Then
|
|
Listados.Add(recsc.Select(Function(x) New ListadoRecibosIncorporados(x)).ToList)
|
|
NombreTablas.Add("Recibos_Incorporados")
|
|
End If
|
|
If recsa.Count > 0 Then
|
|
Listados.Add(recsa.Select(Function(x) New ListadoRecibosIncorporados(x)).ToList)
|
|
NombreTablas.Add("Recibos_Anulados")
|
|
End If
|
|
If recsnp.Count > 0 Then
|
|
Listados.Add(recsnp.Select(Function(x) New ListadoRecibosIncorporados(x)).ToList)
|
|
NombreTablas.Add("Recibos_No_Procesados")
|
|
End If
|
|
If recsact.Count > 0 Then
|
|
Listados.Add(recsact.Select(Function(x) New ListadoRecibosIncorporados(x)).ToList)
|
|
NombreTablas.Add("Recibos_Actualizados")
|
|
End If
|
|
If RecsPagsEnCia.Count > 0 Then
|
|
Listados.Add(RecsPagsEnCia.Select(Function(x) New ListadoRecibosIncorporados(x)).ToList)
|
|
NombreTablas.Add("Recibos_Pagados_En_Cia")
|
|
End If
|
|
|
|
|
|
Dim b() As Byte = tsWPF.Utilidades.Varias.ListaIEnumerableAExcel(Listados, NombreTablas)
|
|
Dim wb As New Workbook
|
|
wb.LoadDocument(b)
|
|
|
|
If recsc.Count > 0 Then
|
|
Dim ws = wb.Worksheets("Recibos_Incorporados")
|
|
ws.Rows.Insert(0, 2)
|
|
ws.MergeCells(ws.Range("A1:U1"))
|
|
ws.Cells("A1").FillColor = System.Drawing.Color.LightSalmon
|
|
ws.Cells("A1").Font.Bold = True
|
|
ws.Cells("A1").Font.UnderlineType = UnderlineType.Single
|
|
ws.Cells("A1").SetValue("Información de recibos incorporados (" & Now.ToString("dd-MM-yyyy") & ")")
|
|
End If
|
|
If recsa.Count > 0 Then
|
|
Dim ws = wb.Worksheets("Recibos_Anulados")
|
|
ws.Rows.Insert(0, 2)
|
|
ws.MergeCells(ws.Range("A1:U1"))
|
|
ws.Cells("A1").FillColor = System.Drawing.Color.LightSalmon
|
|
ws.Cells("A1").Font.Bold = True
|
|
ws.Cells("A1").Font.UnderlineType = UnderlineType.Single
|
|
ws.Cells("A1").SetValue("Información de recibos anulados (" & Now.ToString("dd-MM-yyyy") & ")")
|
|
End If
|
|
If recsnp.Count > 0 Then
|
|
Dim ws = wb.Worksheets("Recibos_No_Procesados")
|
|
ws.Rows.Insert(0, 2)
|
|
ws.MergeCells(ws.Range("A1:U1"))
|
|
ws.Cells("A1").FillColor = System.Drawing.Color.LightSalmon
|
|
ws.Cells("A1").Font.Bold = True
|
|
ws.Cells("A1").Font.UnderlineType = UnderlineType.Single
|
|
ws.Cells("A1").SetValue("Información de recibos no procesados (" & Now.ToString("dd-MM-yyyy") & ")")
|
|
End If
|
|
If recsact.Count > 0 Then
|
|
Dim ws = wb.Worksheets("Recibos_Actualizados")
|
|
ws.Rows.Insert(0, 2)
|
|
ws.MergeCells(ws.Range("A1:U1"))
|
|
ws.Cells("A1").FillColor = System.Drawing.Color.LightSalmon
|
|
ws.Cells("A1").Font.Bold = True
|
|
ws.Cells("A1").Font.UnderlineType = UnderlineType.Single
|
|
ws.Cells("A1").SetValue("Información de recibos actualizados (fecha pago y cobro cía) (" & Now.ToString("dd-MM-yyyy") & ")")
|
|
End If
|
|
If RecsPagsEnCia.Count > 0 Then
|
|
Dim ws = wb.Worksheets("Recibos_Pagados_En_Cia")
|
|
ws.Rows.Insert(0, 2)
|
|
ws.MergeCells(ws.Range("A1:U1"))
|
|
ws.Cells("A1").FillColor = System.Drawing.Color.LightSalmon
|
|
ws.Cells("A1").Font.Bold = True
|
|
ws.Cells("A1").Font.UnderlineType = UnderlineType.Single
|
|
ws.Cells("A1").SetValue("Información de recibos Pagados en Cia (Anteriormente de baja por Falta de pago) (" & Now.ToString("dd-MM-yyyy") & ")")
|
|
End If
|
|
|
|
Dim ms As New MemoryStream()
|
|
wb.SaveDocument(ms, DocumentFormat.Xlsx)
|
|
bdGestionAsegasa.correos.GeneraRegistroCorreoConAdjunto(bd, sAsunto, "Adjunto le remitimos " & sAsunto, cta, ms.ToArray, "Recibos_" & Now.ToString("yyyy-MM-dd") & ".xlsx", sAsunto, sDestinatario)
|
|
Catch EX As Exception
|
|
Throw New Exception(EX.Message, EX) ' bdGestionAsegasa.Utilidades.AñadeLog(TipoLog.Fallo, "En GeneraEmailRecibosIncorporados CIA:" & cia.Codigo, EX.Message, EX)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
#Region "Conversiones"
|
|
Public Function AListadoDevueltos() As ListadoDevueltos
|
|
Return New ListadoDevueltos(Me)
|
|
End Function
|
|
|
|
Public Function AListadoBajas() As ListadoBajas
|
|
Return New ListadoBajas(Me)
|
|
End Function
|
|
Public Function AListadoGestionCobro() As ListadoGestionCobro
|
|
Return New ListadoGestionCobro(Me)
|
|
End Function
|
|
|
|
Public Function AListadoAsegurados() As ListadoAsegurados
|
|
Return New ListadoAsegurados(Me)
|
|
End Function
|
|
|
|
Public Shared Sub ObtieneRecibosZurich()
|
|
'Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
'Dim idCia = bd.companias.First(Function(X) X.Codigo = "0013").idCompania
|
|
'Dim idDP = bd.enumeraciones.First(Function(X) X.Codigo = "TIPFIC.DOCPOL").idEnumeracion
|
|
'Dim tgdr = bdGestionAsegasa.TipoGestionEnum.DESCARGA_RECIBO_DE_CIA
|
|
'Dim recs = bd.recibos.Where(Function(x) x.FechaPago.HasValue AndAlso x.FechaVencimiento > Today AndAlso x.FechaBaja Is Nothing AndAlso x.polizassg.idCompania = idCia AndAlso x.documentospolizassg.Any = False AndAlso x.gestionesrecibos.Any(Function(y) y.Tipo = tgdr) = False).Take(10).ToList
|
|
'For Each r In recs
|
|
' Dim tg As New bdGestionAsegasa.gestionesrecibos
|
|
' With tg
|
|
' .idRecibo = r.idRecibo
|
|
' .Tipo = tgdr
|
|
' .GestionesRealizadas = tgdr.ToString.Replace("_", " ")
|
|
' .Fecha = Now
|
|
' .Observaciones = ""
|
|
' End With
|
|
' bd.gestionesrecibos.AddObject(tg)
|
|
' bd.SaveChanges()
|
|
' Try
|
|
' Dim brecibo = ObtieneDocumentos.ObtenerRecibo(r.NumeroRecibo)
|
|
' Dim dp = New documentospolizassg
|
|
' r.polizassg.documentospolizassg.Add(dp)
|
|
' dp.Descripcion = "RECIBO " & r.NumeroRecibo
|
|
' dp.idDocumentoASolicitar = Nothing
|
|
' dp.Obligatorio = False
|
|
' dp.Fecha = Date.Now
|
|
' Dim f As New ficheros
|
|
' With f
|
|
' .Descripcion = "RECIBO: " & r.NumeroRecibo & " PÓLIZA: " & r.polizassg.NumeroPoliza
|
|
' .Fichero = brecibo
|
|
' .Fecha = Now
|
|
' .NombreFichero = r.NumeroRecibo.ToString & ".pdf"
|
|
' .idAplicacion = r.idRecibo
|
|
' .idTipo = idDP
|
|
' End With
|
|
' dp.ficheros = f
|
|
' Catch ex As Exception
|
|
' Call Utilidades.AñadeLog(tsl5.Enumeraciones.TipoLog.Fallo, "En ObtieneDocumentosPolizas", ex.Message, ex)
|
|
' tg.Observaciones = ex.Message.Acortar(500)
|
|
' End Try
|
|
' bd.SaveChanges()
|
|
'Next
|
|
End Sub
|
|
|
|
|
|
#End Region
|
|
|
|
End Class
|
|
|
|
#Region "Exportaciones"
|
|
Public Class ListadoDevueltos
|
|
Public Sub New(Recibo As recibos)
|
|
NumeroRecibo = Recibo.NumeroRecibo
|
|
NumeroPoliza = Recibo.polizassg.NumeroPolizaSuplementoLargo
|
|
Compañia = Recibo.polizassg.companias.Nombre
|
|
Tomador = Recibo.polizassg.Tomador.RazonSocial
|
|
Teléfono = Recibo.polizassg.Telefono1Tomador
|
|
FechaEfecto = Recibo.FechaEfecto
|
|
PrimaBruta = Recibo.TotalRecibo
|
|
TipoPago = Recibo.TipoPago
|
|
IBAN = Recibo.IBAN
|
|
FechaDevolucion = Recibo.FechaDevolucionBanco
|
|
CausaDevolucion = Recibo.CausaDevolucion
|
|
End Sub
|
|
|
|
Property NumeroRecibo As String
|
|
Property NumeroPoliza As String
|
|
Property Compañia As String
|
|
Property Tomador As String
|
|
Property Teléfono As String
|
|
Property FechaEfecto As Date
|
|
Property PrimaBruta As Double
|
|
Property TipoPago As String
|
|
Property IBAN As String
|
|
Property FechaDevolucion As Date
|
|
Property CausaDevolucion As String
|
|
|
|
End Class
|
|
Public Class ListadoBajas
|
|
Public Sub New(Recibo As recibos)
|
|
NumeroRecibo = Recibo.NumeroRecibo
|
|
NumeroPoliza = Recibo.polizassg.NumeroPolizaSuplementoLargo
|
|
Compañia = Recibo.polizassg.companias.Nombre
|
|
Tomador = Recibo.polizassg.Tomador.RazonSocial
|
|
Teléfono = Recibo.polizassg.Telefono1Tomador
|
|
FechaEfecto = Recibo.FechaEfecto
|
|
PrimaBruta = Recibo.TotalRecibo
|
|
TipoPago = Recibo.TipoPago
|
|
IBAN = Recibo.IBAN
|
|
FechaBaja = Recibo.FechaBaja
|
|
CausaBaja = Recibo.CausaBaja
|
|
PosibleFechaAnulacion = Recibo.FechaBaja
|
|
If PosibleFechaAnulacion.Day > 22 Then
|
|
If PosibleFechaAnulacion.Month = 12 Then
|
|
PosibleFechaAnulacion = New Date(PosibleFechaAnulacion.Year + 1, 1, 22)
|
|
Else
|
|
PosibleFechaAnulacion = New Date(PosibleFechaAnulacion.Year, PosibleFechaAnulacion.Month + 1, 22)
|
|
End If
|
|
Else
|
|
PosibleFechaAnulacion = New Date(PosibleFechaAnulacion.Year, PosibleFechaAnulacion.Month, 22)
|
|
End If
|
|
End Sub
|
|
|
|
Property NumeroRecibo As String
|
|
Property NumeroPoliza As String
|
|
Property Compañia As String
|
|
Property Tomador As String
|
|
Property Teléfono As String
|
|
Property FechaEfecto As Date
|
|
Property PrimaBruta As Double
|
|
Property TipoPago As String
|
|
Property IBAN As String
|
|
Property FechaBaja As Date
|
|
Property CausaBaja As String
|
|
Property PosibleFechaAnulacion As Date
|
|
|
|
|
|
|
|
End Class
|
|
|
|
Public Class ListadoAsegurados
|
|
Public Sub New(Recibo As recibos)
|
|
NumeroPropuesta = Recibo.polizassg.idPoliza
|
|
NumeroPoliza = Recibo.polizassg.NumeroPolizaSuplementoLargo
|
|
NumeroRecibo = Recibo.NumeroRecibo
|
|
CIFTomador = Recibo.polizassg.Tomador.CIF
|
|
Tomador = Recibo.polizassg.Tomador.RazonSocial
|
|
Compañia = Recibo.polizassg.companias.Nombre
|
|
Agente = Recibo.agentes.Nombre
|
|
SubAgente = Recibo.subagentes.Nombre
|
|
Ramo = Recibo.polizassg.ramos.Descripcion
|
|
FechaEfecto = Recibo.FechaEfecto
|
|
Teléfono1 = Recibo.polizassg.Telefono1Tomador
|
|
Teléfono2 = Recibo.polizassg.Telefono1Tomador
|
|
Email = Recibo.polizassg.EmailTomador
|
|
BienesAsegurados = Recibo.polizassg.BienesAsegurados
|
|
Matricula = Recibo.polizassg.Matricula
|
|
End Sub
|
|
Public Sub New(Recibo As vf_recibosextendidos)
|
|
NumeroPropuesta = Recibo.idPoliza
|
|
NumeroPoliza = Recibo.NumeroPolizaSuplementoLargo
|
|
NumeroRecibo = Recibo.NumeroRecibo
|
|
CIFTomador = Recibo.CIFTomador
|
|
Tomador = Recibo.Tomador
|
|
Compañia = Recibo.Compania
|
|
Agente = Recibo.Agente
|
|
SubAgente = Recibo.SubAgente
|
|
Ramo = Recibo.Ramo
|
|
FechaEfecto = Recibo.FechaEfecto
|
|
Teléfono1 = Recibo.Telefono1Tomador
|
|
Teléfono2 = Recibo.Telefono2Tomador
|
|
Email = Recibo.EmailTomador
|
|
BienesAsegurados = Recibo.BienesAsegurados
|
|
Matricula = Recibo.Matricula
|
|
End Sub
|
|
Property NumeroPropuesta As Integer
|
|
Property NumeroPoliza As String
|
|
Property NumeroRecibo As String
|
|
Property CIFTomador As String
|
|
Property Tomador As String
|
|
Property Compañia As String
|
|
Property Agente As String
|
|
Property SubAgente As String
|
|
Property Ramo As String
|
|
Property FechaEfecto As Date
|
|
Property Teléfono1 As String
|
|
Property Teléfono2 As String
|
|
Property Email As String
|
|
Property BienesAsegurados As String
|
|
Property Matricula As String
|
|
End Class
|
|
|
|
|
|
Public Class ListadoGestionCobro
|
|
Public Sub New(Recibo As recibos)
|
|
NumeroRecibo = Recibo.NumeroRecibo
|
|
FechaExpedicion = Recibo.FechaExpedicion
|
|
NumeroPoliza = Recibo.polizassg.NumeroPolizaSuplementoLargo
|
|
Compañia = Recibo.polizassg.companias.Nombre
|
|
Tomador = Recibo.polizassg.Tomador.RazonSocial
|
|
Teléfono = Recibo.polizassg.Telefono1Tomador
|
|
FechaEfecto = Recibo.FechaEfecto
|
|
PrimaBruta = Recibo.TotalRecibo
|
|
TipoPago = Recibo.TipoPago
|
|
IBAN = Recibo.IBAN
|
|
Remesado = If(Recibo.idRemesa.HasValue, "SI", "NO")
|
|
End Sub
|
|
|
|
Property NumeroRecibo As String
|
|
Property FechaExpedicion As Date
|
|
Property NumeroPoliza As String
|
|
Property Compañia As String
|
|
Property Tomador As String
|
|
Property Teléfono As String
|
|
Property FechaEfecto As Date
|
|
Property PrimaBruta As Double
|
|
Property TipoPago As String
|
|
Property IBAN As String
|
|
Property Remesado As String
|
|
|
|
End Class
|
|
|
|
Public Class ListadoRecibosIncorporados
|
|
|
|
Public Sub New()
|
|
|
|
End Sub
|
|
Public Sub New(Rai As ReciboAIncorporar)
|
|
Código_Recibo = Rai.Código_Recibo
|
|
Código_Compañía = Rai.Código_Cia
|
|
Número_Póliza = Rai.Número_Póliza
|
|
Tipo = Rai.Tipo
|
|
Fecha_Efecto = Rai.Fecha_Efecto
|
|
Fecha_Vencimiento = Rai.Fecha_Vencimiento
|
|
Corregible = Rai.Corregible
|
|
Mensaje = Rai.Mensaje
|
|
Tomador = Rai.Tomador
|
|
Matrícula = Rai.Matrícula
|
|
Bienes_Asegurados = Rai.Bienes_Asegurados
|
|
Agente = Rai.Agente
|
|
Subagente = Rai.Subagente
|
|
Ramo = Rai.Ramo
|
|
IBAN = Rai.IBAN
|
|
Total_Recibo = Rai.Total_Recibo
|
|
Comisión = Rai.Comisión
|
|
Sobrecomisión = Rai.Sobrecomisión
|
|
Comisión_Prevista_Agente = Rai.Comisión_Prevista_Agente
|
|
Comisión_Prevista_ASEGASA = Rai.Comisión_Prevista_ASEGASA
|
|
Diferencia_Comisión = Rai.Diferencia_Comisión
|
|
Número_Fichero = Rai.Número_Fichero
|
|
End Sub
|
|
Public Property Código_Recibo As String
|
|
Public Property Código_Compañía As String
|
|
Public Property Número_Póliza As String
|
|
Public Property Tipo As String
|
|
Public Property Fecha_Efecto As Date
|
|
Public Property Fecha_Vencimiento As Date
|
|
Public Property Corregible As Boolean
|
|
Public Property Mensaje As String
|
|
|
|
Public Property Tomador As String
|
|
Public Property Matrícula As String
|
|
Public Property Bienes_Asegurados As String
|
|
Public Property Agente As String
|
|
Public Property Subagente As String
|
|
Public Property Ramo As String
|
|
Public Property IBAN As String
|
|
Public Property Total_Recibo As Double
|
|
Public Property Comisión As Double?
|
|
Public Property Sobrecomisión As Double?
|
|
Public Property Comisión_Prevista_Agente As Double?
|
|
Public Property Comisión_Prevista_ASEGASA As Double?
|
|
Public Property Diferencia_Comisión As Double?
|
|
Public Property Número_Fichero As Integer
|
|
End Class
|
|
Public Class ReciboAIncorporar
|
|
|
|
Public Property Poliza As polizassg
|
|
Public Property idTipoRecibo As Integer
|
|
' Public Property ReciboEIAC As tipo_recibo
|
|
|
|
Public Property Código_Recibo As String
|
|
|
|
Public Property Código_Cia As String
|
|
Public Property Número_Póliza As String
|
|
Public Property Tipo As String
|
|
Public Property Fecha_Efecto As Date
|
|
Public Property Fecha_Vencimiento As Date
|
|
Public Property Actualizado As Boolean
|
|
Public Property PagadoEnCia As Boolean
|
|
Public Property Correcto As Boolean
|
|
Public Property Corregible As Boolean
|
|
Public Property Mensaje As String
|
|
|
|
Public Property Tomador As String
|
|
Public Property Matrícula As String
|
|
Public Property Bienes_Asegurados As String
|
|
Public Property Agente As String
|
|
Public Property Subagente As String
|
|
Public Property Ramo As String
|
|
Public Property IBAN As String
|
|
Public Property Consorcio As Double
|
|
Public Property Total_Recibo As Double
|
|
Public Property Comisión As Double?
|
|
Public Property Sobrecomisión As Double
|
|
Public Property Comisión_Prevista_Agente As Double?
|
|
Public Property Comisión_Prevista_ASEGASA As Double?
|
|
Public Property Diferencia_Comisión As Double?
|
|
Public Property Número_Fichero As Integer
|
|
Public Property Fecha_Fichero As Date
|
|
Public Property Fecha_Procesado As Date?
|
|
Public Property idFicheroCompania As Integer
|
|
|
|
Public Property Gestionado_Por_Cia As Boolean
|
|
Public Property Es_Produccion As Boolean
|
|
Public Property Prima_Neta As Double
|
|
Public Property Tipo_Pago As String
|
|
Public Property Observaciones As String
|
|
Public Property Forma_Pago_Recibida As String
|
|
Public Property Situacion_Recibo As String
|
|
Public Property Fecha_Situacion As Date?
|
|
Public Property Anulado As Boolean
|
|
Public Property idCompañia As Integer
|
|
Public Property Usuario_Procesado As String
|
|
End Class
|
|
|
|
Public Class DatoComision
|
|
Public Property Concepto As String
|
|
Public Property Base As Double
|
|
Public Property Porcentaje As Double
|
|
Public Property ComisionBruta As Double
|
|
Public Property Sobrecomision As Double
|
|
Public Property TotalComision As Double
|
|
Public Property PorcentajeComisionPrevista As Double
|
|
Public Property ComisionPrevista As Double
|
|
Public Property Diferencia As Double
|
|
End Class
|
|
|
|
|
|
Public Class ReciboReducido
|
|
Public Shared Function ListadoReciboReducido(iqRecibos As IQueryable(Of recibos)) As List(Of ReciboReducido)
|
|
Return iqRecibos.Select(Function(x) New ReciboReducido 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, .idCausaBaja = x.idCausaBaja, .FechaFacturacion = x.FechaFacturacion, .idTipoPago = x.idTipoPago, .FechaPago = x.FechaPago}).ToList
|
|
End Function
|
|
Public Sub New()
|
|
End Sub
|
|
Public Sub New(Recibo As recibos)
|
|
idRecibo = Recibo.idRecibo
|
|
CodigoRecibo = Recibo.CodigoRecibo
|
|
NumeroRecibo = Recibo.NumeroRecibo
|
|
idPoliza = Recibo.idPoliza
|
|
NumeroPoliza = Recibo.polizassg.NumeroPoliza
|
|
NumeroSuplemento = Recibo.polizassg.NumeroSuplemento
|
|
FechaEfecto = Recibo.FechaEfecto
|
|
FechaVencimiento = Recibo.FechaVencimiento
|
|
FechaBaja = Recibo.FechaBaja
|
|
FechaFacturacion = Recibo.FechaFacturacion
|
|
FechaPago = Recibo.FechaPago
|
|
idTipoPago = Recibo.idTipoPago
|
|
idCausaBaja = Recibo.idCausaBaja
|
|
End Sub
|
|
Property idRecibo As Integer
|
|
Property CodigoRecibo As String
|
|
Property NumeroRecibo As String
|
|
Property idPoliza As Integer
|
|
Property NumeroPoliza As String
|
|
Property NumeroSuplemento As Integer
|
|
Property FechaEfecto As Date
|
|
Property FechaVencimiento As Date
|
|
Property FechaFacturacion As Date?
|
|
Property idCausaBaja As Integer?
|
|
Property FechaBaja As Date?
|
|
Property FechaPago As Date?
|
|
Property idTipoPago As Integer
|
|
|
|
|
|
|
|
End Class
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
Public Class ve_recibos
|
|
|
|
Public Property idRecibo As Integer
|
|
Public Property idPoliza As Integer
|
|
Public Property FechaFacturacion As Date?
|
|
Public Property FechaPago As Date?
|
|
Public Property CodigoRecibo As String
|
|
Public Property NumeroPoliza As String
|
|
Public Property Tomador As String
|
|
Public Property CIFTomador As String
|
|
Public Property Telefono1Tomador As String
|
|
Public Property Telefono2Tomador As String
|
|
Public Property Matricula As String
|
|
Public Property FechaEfecto As Date
|
|
Public Property FechaRecepcionCia As Date?
|
|
Public Property FechaVencimiento As Date
|
|
Public Property Compania As String
|
|
Public Property Agente As String
|
|
Public Property SubAgente As String
|
|
Public Property Ramo As String
|
|
Public Property FechaExpedicion As Date?
|
|
|
|
Public Property BienesAsegurados As String
|
|
Public Property FechaBaja As Date?
|
|
|
|
Public Property FechaDevolucionBanco As Date?
|
|
|
|
Public Property CausaBaja As String
|
|
Public Property TipoRecibo As String
|
|
Public Property TipoPago As String
|
|
Public Property Oficina As String
|
|
Public Property PrimaNeta As Double?
|
|
Public Property BonificacionORecargo As Double?
|
|
|
|
Public Property Consorcio As Double?
|
|
|
|
Public Property Impuesto As Double?
|
|
|
|
Public Property RecargoExterno As Double?
|
|
|
|
Public Property TotalRecibo As Double?
|
|
|
|
Public Property ComisionReciboPrimaNeta As Double?
|
|
|
|
Public Property PorcentajeReciboPrimaNeta As Double?
|
|
|
|
Public Property TotalComision As Double?
|
|
Public Property SobreComision As Double?
|
|
Public Property PorcentajeComisionAgente As Double?
|
|
Public Property ComisionAgente As Double?
|
|
Public Property ComisionAsegasaPrimaNeta As Double?
|
|
Public Property AsegasaRecargoExterno As Double?
|
|
Public Property AsegasaComisionConsorcio As Double?
|
|
Public Property AsegasaComisionTotal As Double?
|
|
Public Property ComisionPrevista As Double?
|
|
Public ReadOnly Property DiferenciaComision As Double
|
|
Get
|
|
Dim crpn = If(ComisionReciboPrimaNeta.HasValue, ComisionReciboPrimaNeta.Value, 0)
|
|
Dim cp = If(ComisionPrevista.HasValue, ComisionPrevista.Value, 0)
|
|
Return Math.Round(crpn - cp, 2, MidpointRounding.AwayFromZero)
|
|
End Get
|
|
End Property
|
|
Public Property idSituacion As Integer?
|
|
Public Property FechaLiquidacionAgente As Date?
|
|
Public Property FechaLiquidacionCia As Date?
|
|
Public Property FechaLiquidacionCiaDevuelto As Date?
|
|
|
|
Public Property BloquearFacturacion As Boolean
|
|
Get
|
|
If Utilidades.idSitr1.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Utilidades.idSitr1 = bd.enumeraciones.First(Function(x) x.Codigo = "SITR.1").idEnumeracion
|
|
End If
|
|
Return If(Me.idSituacion.HasValue = False, False, (Me.idSituacion.Value = Utilidades.idSitr1))
|
|
End Get
|
|
Set(value As Boolean)
|
|
If Utilidades.idSitr1.HasValue = False Then
|
|
Dim bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto
|
|
Utilidades.idSitr1 = bd.enumeraciones.First(Function(x) x.Codigo = "SITR.1").idEnumeracion
|
|
End If
|
|
If value Then
|
|
Me.idSituacion = Utilidades.idSitr1
|
|
Else
|
|
Me.idSituacion = Nothing
|
|
End If
|
|
End Set
|
|
End Property
|
|
Public ReadOnly Property TelefonoMovilValido As String
|
|
Get
|
|
If Me.Telefono1Tomador.EsNumeroTelefonoMovilEspañolValido Then
|
|
Return Me.Telefono1Tomador
|
|
Else
|
|
If Me.Telefono2Tomador.EsNumeroTelefonoMovilEspañolValido Then
|
|
Return Me.Telefono2Tomador
|
|
Else
|
|
Return ""
|
|
End If
|
|
End If
|
|
End Get
|
|
End Property
|
|
Public Property Observaciones As String
|
|
Public Property ObservacionesPoliza As String
|
|
Public Property FechaRemesa As Date?
|
|
|
|
End Class
|
|
|