2363 lines
98 KiB
C#
2363 lines
98 KiB
C#
using bdAsegasa.dbcontext;
|
|
using bdAsegasa.Informes;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using tsEFCore8;
|
|
using tsUtilidades.Enumeraciones;
|
|
using tsUtilidades.Extensiones;
|
|
using static DevExpress.Xpf.Core.HandleDecorator.Helpers.NativeMethods;
|
|
|
|
namespace bdAsegasa.db
|
|
{
|
|
|
|
public partial class recibos
|
|
{
|
|
|
|
// Revisado
|
|
#region Contabilidad
|
|
|
|
public string Tomador
|
|
{
|
|
get
|
|
{
|
|
if (this.idPolizaNavigation != null && this.idPolizaNavigation.Tomador != null)
|
|
{
|
|
return this.idPolizaNavigation.Tomador.RazonSocial;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
public double LiquidoCia
|
|
{
|
|
get
|
|
{
|
|
double total = TotalRecibo ?? 0;
|
|
double comision = TotalComision ?? 0;
|
|
return Math.Round(total - comision, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
|
|
public int NumeroDiasRemesaPago
|
|
{
|
|
get
|
|
{
|
|
if (idRemesa.HasValue && idPolizaNavigation?.idCompaniaNavigation != null)
|
|
{
|
|
var excr = idPolizaNavigation.idCompaniaNavigation.excepcionesciasramos.FirstOrDefault(x => x.idRamo == idPolizaNavigation.idRamo);
|
|
return excr?.NumeroDiasRemesaPago ?? idPolizaNavigation.idCompaniaNavigation.PlazoRetornoComision ?? 0;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public DateOnly? FechaAsientoDevueltoBancoEspecial
|
|
{
|
|
get
|
|
{
|
|
if (idAsientoDevueltoBancoNavigation != null)
|
|
{
|
|
return idAsientoDevueltoBancoNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return FechaAsientoDevueltoBanco;
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateOnly? FechaFacturacionEspecial
|
|
{
|
|
get
|
|
{
|
|
if (idAsientoFacturacionNavigation != null)
|
|
{
|
|
return idAsientoFacturacionNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return FechaFacturacion;
|
|
}
|
|
}
|
|
}
|
|
|
|
#region LiquidacionesCIAS
|
|
public liquidacionescompaniasrecibos PrimeraLiquidacionCia
|
|
{
|
|
get
|
|
{
|
|
return liquidacionescompaniasrecibos.FirstOrDefault(x => x.idLiquidacionCiaNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQ.LIQUIDACION");
|
|
}
|
|
}
|
|
public liquidacionescompaniasrecibos PrimerDescobroACia
|
|
{
|
|
get
|
|
{
|
|
return liquidacionescompaniasrecibos.FirstOrDefault(x => x.idLiquidacionCiaNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQ.DESCOBRO");
|
|
}
|
|
}
|
|
public liquidacionescompaniasrecibos PrimeraDevolucionCia
|
|
{
|
|
get
|
|
{
|
|
return liquidacionescompaniasrecibos.FirstOrDefault(x => x.idLiquidacionCiaNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQ.DEVUELTO");
|
|
}
|
|
}
|
|
|
|
public int? idAsientoLiquidacionCia
|
|
{
|
|
get
|
|
{
|
|
if (PrimeraLiquidacionCia != null && PrimeraLiquidacionCia.idLiquidacionCiaNavigation != null && PrimeraLiquidacionCia.idLiquidacionCiaNavigation.idPagoLiquidacionCiaNavigation != null)
|
|
{
|
|
return PrimeraLiquidacionCia.idLiquidacionCiaNavigation.idPagoLiquidacionCiaNavigation.idAsiento;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public int? idAsientoDescobroCia
|
|
{
|
|
get
|
|
{
|
|
if (PrimerDescobroACia != null && PrimerDescobroACia.idLiquidacionCiaNavigation != null)
|
|
{
|
|
return PrimerDescobroACia.idLiquidacionCiaNavigation.idAsiento;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public DateOnly? FechaAsientoLiquidacionCia
|
|
{
|
|
get
|
|
{
|
|
if (PrimeraLiquidacionCia != null && PrimeraLiquidacionCia.idLiquidacionCiaNavigation != null && PrimeraLiquidacionCia.idLiquidacionCiaNavigation.idPagoLiquidacionCiaNavigation != null && PrimeraLiquidacionCia.idLiquidacionCiaNavigation.idPagoLiquidacionCiaNavigation.idAsientoNavigation != null)
|
|
{
|
|
return PrimeraLiquidacionCia.idLiquidacionCiaNavigation.idPagoLiquidacionCiaNavigation.idAsientoNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public int? idAsientoDevueltoCia
|
|
{
|
|
get
|
|
{
|
|
if (PrimeraDevolucionCia != null && PrimeraDevolucionCia.idLiquidacionCiaNavigation != null)
|
|
{
|
|
return PrimeraDevolucionCia.idLiquidacionCiaNavigation.idAsiento;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public DateOnly? FechaAsientoDevueltoCia
|
|
{
|
|
get
|
|
{
|
|
if (PrimeraDevolucionCia != null )
|
|
{
|
|
return PrimeraDevolucionCia.idLiquidacionCiaNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public DateOnly? FechaAsientoDescobroCia
|
|
{
|
|
get
|
|
{
|
|
if (PrimerDescobroACia != null)
|
|
{
|
|
return PrimerDescobroACia.idLiquidacionCiaNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region LiquidacionesAgentes
|
|
public liquidacionesagenterecibos PrimeraLiquidacionAgente
|
|
{
|
|
get
|
|
{
|
|
return this.liquidacionesagenterecibos
|
|
.FirstOrDefault(x => x.idLiquidacionesAgenteNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQAG.LIQUIDACION");
|
|
}
|
|
}
|
|
|
|
public int? idAsientoLiquidacionAgente
|
|
{
|
|
get
|
|
{
|
|
if (PrimeraLiquidacionAgente != null)
|
|
{
|
|
return PrimeraLiquidacionAgente.idLiquidacionesAgenteNavigation.idAsiento;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateOnly? FechaAsientoLiquidacionAgente
|
|
{
|
|
get
|
|
{
|
|
if (PrimeraLiquidacionAgente != null)
|
|
{
|
|
return PrimeraLiquidacionAgente.idLiquidacionesAgenteNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public DateTime? FechaAsientoDescobroAgente
|
|
{
|
|
get
|
|
{
|
|
if (this.regularizacionespagosagentes.Any())
|
|
{
|
|
return this.regularizacionespagosagentes
|
|
.OrderByDescending(x => x.FechaCreacion)
|
|
.First()
|
|
.FechaCreacion;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
public DateOnly? FechaAsientoRemesa
|
|
{
|
|
get
|
|
{
|
|
if (this.idRemesaNavigation != null)
|
|
{
|
|
if (this.idRemesaNavigation.idAsientoNavigation!= null)
|
|
{
|
|
return this.idRemesaNavigation.idAsientoNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int? idAsientoRemesaOContado
|
|
{
|
|
get
|
|
{
|
|
if (this.idRemesaNavigation != null)
|
|
{
|
|
return this.idRemesaNavigation.idAsiento;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateOnly? FechaRemesa
|
|
{
|
|
get
|
|
{
|
|
if (this.idRemesaNavigation != null)
|
|
{
|
|
return this.idRemesaNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int ContabilizaRecibosPagoAG()
|
|
{
|
|
try
|
|
{
|
|
var hoy = DateOnly.FromDateTime(DateTime.Today);
|
|
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
|
|
var idtippag = bd.enumeraciones.First(x => x.Codigo == "TIPP.AG").idEnumeracion;
|
|
var idSitPag = bd.enumeraciones.First(x => x.Codigo == "SITR.PA").idEnumeracion;
|
|
var Lag = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == "LAPADFE").Select(x => x.ValorAlfabetico1).ToList();
|
|
var ListaAgentesDespuesFechaEfecto = bd.agentes.Where(x => Lag.Contains(x.Codigo)).Select(x => x.idAgente).ToList();
|
|
var recsdfe = bd.vf_recibosextendidos.Where(x => ListaAgentesDespuesFechaEfecto.Contains((int)x.idAgente)
|
|
&& x.idTipoPago == idtippag
|
|
&& !x.FechaBaja.HasValue
|
|
&& !x.FechaPago.HasValue
|
|
&& !x.idRemesa.HasValue
|
|
&& hoy >= x.FechaEfecto)
|
|
.ToList();
|
|
|
|
var recs = recsdfe.Union(bd.vf_recibosextendidos.Where(x => !ListaAgentesDespuesFechaEfecto.Contains((int)x.idAgente)
|
|
&& x.idTipoPago == idtippag
|
|
&& !x.FechaBaja.HasValue
|
|
&& !x.FechaPago.HasValue
|
|
&& !x.idRemesa.HasValue)
|
|
.ToList())
|
|
.ToList();
|
|
|
|
var lrp = new List<bdAsegasa.db.recibos>();
|
|
int NumeroAgrupamientos = 0;
|
|
|
|
if (recs.Count > 0)
|
|
{
|
|
var Cont = bd.enumeraciones.First(x => x.Codigo == "CONT.NUMGEN");
|
|
Cont.ValorNumerico1 += 1;
|
|
bd.SaveChanges();
|
|
|
|
var ej = bd.ejercicioscontables
|
|
.First(x => x.FechaInicio <= hoy && x.FechaFin >= hoy);
|
|
|
|
var recsagag = recs
|
|
.GroupBy(x => x.CodigoAgente)
|
|
.OrderBy(x => x.FirstOrDefault().CodigoAgente)
|
|
.ToList();
|
|
|
|
NumeroAgrupamientos = recsagag.Count;
|
|
|
|
var Conceps = bd.conceptosapuntes.ToList();
|
|
|
|
foreach (var rag in recsagag)
|
|
{
|
|
var idagente = rag.First().CodigoAgente;
|
|
var agente = bd.agentes.First(x => x.Codigo == idagente);
|
|
|
|
string Cta2 = agente.CuentaContableR;
|
|
|
|
if (!bd.cuentas.Any(x => x.NumeroCuenta == Cta2 && x.idEjercicio == ej.idEjercicio))
|
|
{
|
|
bdAsegasa.db.cuentas.CreaCuenta(bd, ej.idEjercicio, Cta2, rag.First().Agente);
|
|
}
|
|
|
|
var na = new bdAsegasa.db.asientos();
|
|
bd.asientos.Add(na);
|
|
|
|
na.Fecha = Utilidades.FechaActualDateOnly();
|
|
na.idEjercicio = ej.idEjercicio;
|
|
na.Tipo = (int)bdAsegasa.db.asientos.TipoAsiento.NORMAL;
|
|
na.FechaIntroduccion = DateTime.Now;
|
|
|
|
if (bdAsegasa.db.Utilidades.dsc.idUsuario > 0)
|
|
na.idUsuario = bdAsegasa.db.Utilidades.dsc.idUsuario;
|
|
|
|
var recsag = rag
|
|
.ToList()
|
|
.GroupBy(x => x.CodigoCia)
|
|
.OrderBy(x => x.First().CodigoCia);
|
|
|
|
foreach (var g in recsag)
|
|
{
|
|
string Cta1 = "4400" + g.First().CodigoCia;
|
|
|
|
if (!bd.cuentas.Any(x => x.NumeroCuenta == Cta1 && x.idEjercicio == ej.idEjercicio))
|
|
{
|
|
bdAsegasa.db.cuentas.CreaCuenta(bd, ej.idEjercicio, Cta1, "RBOS A COBRAR " + g.First().Compania);
|
|
}
|
|
}
|
|
|
|
foreach (var g in recsag)
|
|
{
|
|
var nap1 = new bdAsegasa.db.apuntes();
|
|
|
|
nap1.idAsientoNavigation = na;
|
|
|
|
string Cta = "4400" + g.First().CodigoCia;
|
|
|
|
nap1.idCuenta = bd.cuentas
|
|
.First(x => x.NumeroCuenta == Cta && x.idEjercicio == ej.idEjercicio)
|
|
.idCuenta;
|
|
|
|
nap1.Haber = Math.Round(g.Sum(x => x.TotalRecibo.Value), 2, MidpointRounding.AwayFromZero);
|
|
nap1.Debe = 0;
|
|
nap1.Concepto = (g.First().Agente + " " + g.First().Compania).Acortar(200);
|
|
nap1.idConcepto = Conceps.First(x => x.Codigo == "001").idConcepto;
|
|
|
|
na.apuntes.Add(nap1);
|
|
}
|
|
|
|
string Cta3 = agente.CuentaContableR;
|
|
|
|
var idCta3 = bd.cuentas
|
|
.First(x => x.NumeroCuenta == Cta3 && x.idEjercicio == ej.idEjercicio)
|
|
.idCuenta;
|
|
|
|
foreach (var r in rag)
|
|
{
|
|
var nap2 = new bdAsegasa.db.apuntes();
|
|
|
|
nap2.idAsientoNavigation = na;
|
|
nap2.idCuenta = idCta3;
|
|
nap2.Debe = Math.Round(r.TotalRecibo.Value, 2, MidpointRounding.AwayFromZero);
|
|
nap2.Haber = 0;
|
|
nap2.Concepto = agente.Nombre + " Rec.:" + r.CodigoRecibo;
|
|
nap2.idConcepto = Conceps.First(x => x.Codigo == "001").idConcepto;
|
|
|
|
na.apuntes.Add(nap2);
|
|
|
|
na.Importe = Math.Round(na.apuntes.Sum(x => x.Debe), 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
|
|
foreach (var v_r in recs)
|
|
{
|
|
var r = bd.recibos.First(x => x.idRecibo == v_r.idRecibo);
|
|
|
|
r.FechaPago = Utilidades.FechaActualDateOnly();
|
|
r.idSituacion = idSitPag;
|
|
|
|
lrp.Add(r);
|
|
}
|
|
|
|
bd.GuardarCambios();
|
|
|
|
bd.Database.ExecuteSqlRaw(
|
|
"UPDATE registrosactualizados SET FechaCreacion=Now() where FechaCreacion Is null and NumeroGeneracion="
|
|
+ Cont.ValorNumerico1.ToString() + ";");
|
|
}
|
|
|
|
var sDestinatarios = bd.enumeraciones
|
|
.First(x => x.Codigo == "CONF.EMAILCONTA")
|
|
.ValorAlfabeticoLargo;
|
|
|
|
var ctac = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES");
|
|
|
|
if (lrp.Count > 0)
|
|
{
|
|
var lr = lrp.Select(x => new
|
|
{
|
|
x.CodigoRecibo,
|
|
x.idPolizaNavigation.NumeroPoliza,
|
|
x.idPolizaNavigation.NumeroSuplemento,
|
|
Tomador = x.idPolizaNavigation.Tomador.RazonSocial,
|
|
x.idPolizaNavigation.BienesAsegurados,
|
|
Ramo = x.idPolizaNavigation.idRamoNavigation.Descripcion,
|
|
Compañia = x.idPolizaNavigation.idCompaniaNavigation.Nombre,
|
|
Agente = x.idAgenteNavigation.Nombre
|
|
}).ToList();
|
|
|
|
var f = tsUtilidades.Excel.IEnumerableAExcel(lr);
|
|
|
|
bdAsegasa.db.correos.GeneraRegistroCorreoConAdjunto(
|
|
bd,
|
|
"Se han marcado " + recs.Count + " 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-" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx",
|
|
"Listado Recibos Pagado (Tipo Pago AG) " + DateTime.Now.ToString("yyyy-MM-dd"),
|
|
sDestinatarios,
|
|
null,
|
|
"sevilla@tecnosis.net"
|
|
);
|
|
}
|
|
|
|
return NumeroAgrupamientos;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Comisiones
|
|
|
|
public bool BloquearFacturacion
|
|
{
|
|
get
|
|
{
|
|
if (!Utilidades.idSitr1.HasValue)
|
|
{
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
Utilidades.idSitr1 = bd.enumeraciones
|
|
.First(x => x.Codigo == "SITR.1")
|
|
.idEnumeracion;
|
|
}
|
|
|
|
return !this.idSituacion.HasValue
|
|
? false
|
|
: (this.idSituacion.Value == Utilidades.idSitr1);
|
|
}
|
|
set
|
|
{
|
|
if (!Utilidades.idSitr1.HasValue)
|
|
{
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
Utilidades.idSitr1 = bd.enumeraciones
|
|
.First(x => x.Codigo == "SITR.1")
|
|
.idEnumeracion;
|
|
}
|
|
|
|
if (value)
|
|
{
|
|
this.idSituacion = Utilidades.idSitr1;
|
|
}
|
|
else
|
|
{
|
|
this.idSituacion = null;
|
|
}
|
|
}
|
|
}
|
|
public int? idAgente_Nulable
|
|
{
|
|
get
|
|
{
|
|
if (idAgente == 0) return null;
|
|
return idAgente;
|
|
}
|
|
set
|
|
{
|
|
if (value.HasValue) idAgente = value.Value;
|
|
}
|
|
}
|
|
|
|
internal static void GuardandoCambios(bdAsegasa.tscgestionasegasa bd, string Aplicacion)
|
|
{
|
|
var recs = bd.ChangeTracker.Entries<recibos>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
var pols = bd.ChangeTracker.Entries<polizassg>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
var ents = bd.ChangeTracker.Entries<entidades>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
var eps = bd.ChangeTracker.Entries<entidadespolizas>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
var dirs = bd.ChangeTracker.Entries<direcciones>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
var docsp = bd.ChangeTracker.Entries<documentospolizassg>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
var gests = bd.ChangeTracker.Entries<gestionespolizassg>().Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified).ToList();
|
|
|
|
try
|
|
{
|
|
using var bdtmp = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
bool su = false;
|
|
|
|
foreach (var m in recs)
|
|
{
|
|
var ra = m.Entity;
|
|
var reant = bdtmp.recibos.FirstOrDefault(x => x.idRecibo == ra.idRecibo);
|
|
if (reant == null) continue;
|
|
|
|
int lrec = bdAsegasa.db.logs.GeneraLog( bdtmp, "RECIBOS", reant.idRecibo, null, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar(reant), su, Aplicacion);
|
|
|
|
var polant = bdtmp.polizassg.FirstOrDefault(x => x.idPoliza == reant.idPoliza);
|
|
if (polant == null) continue;
|
|
|
|
if (reant.idRemesa.HasValue)
|
|
{
|
|
bdAsegasa.db.logs.GeneraLog(bdtmp, "REMESAS", reant.idRemesa.Value, lrec, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar((reant.idRemesaNavigation)), su, Aplicacion);
|
|
}
|
|
|
|
int lr = logs.GeneraLog(bdtmp, "POLIZASSG", reant.idPoliza, lrec, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar(polant), su, Aplicacion);
|
|
|
|
var lep = polant.entidadespolizas.ToList();
|
|
|
|
logs.GeneraLog(bdtmp, "ENTIDADESPOLIZAS", reant.idPoliza, lrec, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar(lep), su, Aplicacion);
|
|
|
|
foreach (var ent in lep)
|
|
{
|
|
int lrent = logs.GeneraLog( bdtmp, "ENTIDADES", ent.idEntidad, lr, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar(ent.idEntidadNavigation), su, Aplicacion);
|
|
|
|
if (ent.idEntidadNavigation?.idDireccionPrincipalNavigation != null)
|
|
{
|
|
logs.GeneraLog( bdtmp, "DIRECCIONES", ent.idEntidadNavigation.idDireccionPrincipalNavigation.idDireccion, lrent, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar(ent.idEntidadNavigation.idDireccionPrincipalNavigation), su,Aplicacion);
|
|
}
|
|
}
|
|
|
|
var ges = reant.gestionesrecibos.ToList();
|
|
|
|
logs.GeneraLog(bdtmp, "GESTIONESRECIBOS", reant.idRecibo,lrec, "REGISTRO_COMPLETO", tsUtilidades.Utilidades.serializar(ges), su, Aplicacion);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string sListaCambios = "";
|
|
|
|
if (pols != null)
|
|
{
|
|
foreach (var m in pols)
|
|
{
|
|
var ra = m.Entity;
|
|
sListaCambios += "polizassg idPoliza:" + ra.idPoliza + "; ";
|
|
}
|
|
sListaCambios = sListaCambios.Trim().TrimEnd(';') + Environment.NewLine;
|
|
}
|
|
|
|
if (ents != null)
|
|
{
|
|
foreach (var m in ents)
|
|
{
|
|
var ra = m.Entity;
|
|
sListaCambios += "entidades idEntidad:" + ra.idEntidad + "; ";
|
|
}
|
|
sListaCambios = sListaCambios.Trim().TrimEnd(';') + Environment.NewLine;
|
|
}
|
|
|
|
if (eps != null)
|
|
{
|
|
foreach (var m in eps)
|
|
{
|
|
var ra = m.Entity;
|
|
sListaCambios += "entidadespoliza idEntidadPoliza:" + ra.idEntidadPoliza + "; ";
|
|
}
|
|
sListaCambios = sListaCambios.Trim().TrimEnd(';') + Environment.NewLine;
|
|
}
|
|
|
|
if (dirs != null)
|
|
{
|
|
foreach (var m in dirs)
|
|
{
|
|
var ra = m.Entity;
|
|
sListaCambios += "direcciones idDireccion:" + ra.idDireccion + "; ";
|
|
}
|
|
}
|
|
|
|
if (docsp != null)
|
|
{
|
|
foreach (var m in docsp)
|
|
{
|
|
var ra = m.Entity;
|
|
sListaCambios += "documentos idDocumento:" + ra.idDocumento + "; ";
|
|
}
|
|
}
|
|
|
|
if (gests != null)
|
|
{
|
|
foreach (var m in gests)
|
|
{
|
|
var ra = m.Entity;
|
|
sListaCambios += "gestiones idGestionPoliza:" + ra.idGestionPoliza + "; ";
|
|
}
|
|
}
|
|
tsUtilidades.TsNotificacionesClient.RegistrarAsync( "En GuardandoCambios", ex.Message + sListaCambios, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
}
|
|
}
|
|
public string NombreSubAgente
|
|
{
|
|
get
|
|
{
|
|
if (idSubagente.HasValue && idSubagenteNavigation != null)
|
|
{
|
|
return subagentes.ListaSubAgentes().First(x => x.idSubagente == this.idSubagente).Nombre;
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
public void RefrescaNombreSubAgente()
|
|
{
|
|
}
|
|
|
|
private static int? _idCabaSUPL;
|
|
public static int idCabaSUPL()
|
|
{
|
|
if (!_idCabaSUPL.HasValue)
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
_idCabaSUPL = bd.enumeraciones.First(x => x.Codigo == "CABA.SUPL").idEnumeracion;
|
|
}
|
|
return _idCabaSUPL.Value;
|
|
}
|
|
|
|
private static int? _idCabaFP;
|
|
public static int idCabaFP()
|
|
{
|
|
if (!_idCabaFP.HasValue)
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
_idCabaFP = bd.enumeraciones.First(x => x.Codigo == "CABA.FP").idEnumeracion;
|
|
}
|
|
return _idCabaFP.Value;
|
|
}
|
|
|
|
private static int? _idCabaCIE;
|
|
public static int idCabaCIE()
|
|
{
|
|
if (!_idCabaCIE.HasValue)
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
_idCabaCIE = bd.enumeraciones.First(x => x.Codigo == "CABA.CIE").idEnumeracion;
|
|
}
|
|
return _idCabaCIE.Value;
|
|
}
|
|
|
|
|
|
private static List<bancos> ListadoBancos;
|
|
private static int? _idTippba;
|
|
private static int? _idTippCIA;
|
|
private static int? _idTippFAE;
|
|
private static void RellenaListadoBancos()
|
|
{
|
|
// Obtenemos el contexto (asumiendo que NuevoContexto es una propiedad o método estático)
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
|
|
// Asignamos la lista
|
|
ListadoBancos = bd.bancos.ToList();
|
|
}
|
|
|
|
public static int idTippBA()
|
|
{
|
|
if (!_idTippba.HasValue)
|
|
{
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
_idTippba = bd.enumeraciones.First(x => x.Codigo == "TIPP.BA").idEnumeracion;
|
|
}
|
|
|
|
return _idTippba.Value;
|
|
}
|
|
|
|
public static int idtippCIA()
|
|
{
|
|
if (!_idTippCIA.HasValue)
|
|
{
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
|
|
_idTippCIA = bd.enumeraciones.First(x => x.Codigo == "TIPP.CIA").idEnumeracion;
|
|
}
|
|
|
|
return _idTippCIA.Value;
|
|
}
|
|
|
|
public static int idtippFAE()
|
|
{
|
|
if (!_idTippFAE.HasValue)
|
|
{
|
|
var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
|
|
_idTippFAE = bd.enumeraciones.First(x => x.Codigo == "TIPP.FAE").idEnumeracion;
|
|
}
|
|
|
|
return _idTippFAE.Value;
|
|
}
|
|
|
|
public double DiferenciaComision
|
|
{
|
|
get
|
|
{
|
|
double cp = ComisionPrevistaAsegasa ?? (ComisionPrevista ?? 0);
|
|
double c = TotalComision ?? 0;
|
|
return c - cp;
|
|
}
|
|
}
|
|
public double DiferenciaComisionAgente
|
|
{
|
|
get
|
|
{
|
|
double cp = ComisionPrevista ?? 0;
|
|
double c = ComisionReciboPrimaNeta ?? 0;
|
|
return c - cp;
|
|
}
|
|
}
|
|
|
|
public int? idSubAgente_Especial
|
|
{
|
|
get
|
|
{
|
|
if (idSubagente.HasValue && idAgenteNavigation?.Codigo == "000047002186")
|
|
{
|
|
using var bd = tscgestionasegasa.NuevoContexto();
|
|
var codigo = idSubagenteNavigation.Codigo.Substring(0, 2) + "00";
|
|
var subage = bd.subagentes.FirstOrDefault(x => x.idAgente == idAgente && x.Codigo == codigo);
|
|
if (subage != null) return subage.idSubagente;
|
|
return null;
|
|
}
|
|
return idSubagente;
|
|
}
|
|
}
|
|
|
|
public string Banco
|
|
{
|
|
get
|
|
{
|
|
if (ListadoBancos == null)
|
|
{
|
|
RellenaListadoBancos();
|
|
}
|
|
|
|
// Comprobamos si el IBAN tiene contenido
|
|
// Sustituyo .NothingAVacio por string.IsNullOrWhiteSpace para seguridad en C#
|
|
if (!string.IsNullOrWhiteSpace(this.IBAN))
|
|
{
|
|
if (this.IBAN.Length != 24)
|
|
{
|
|
return "** IBAN ERRONEO **";
|
|
}
|
|
else
|
|
{
|
|
// El código de banco en un IBAN español son los dígitos del 5º al 8º
|
|
string codban = this.IBAN.Substring(4, 4);
|
|
|
|
var b = ListadoBancos.FirstOrDefault(x => x.Codigo == codban);
|
|
|
|
return b != null ? b.Nombre : "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
public string IBAN_Parcial
|
|
{
|
|
get
|
|
{
|
|
if (IBAN != null && IBAN.Length == 24)
|
|
{
|
|
return IBAN.Substring(0, 10) + "XXXXXXXX" + IBAN.Substring(18);
|
|
}
|
|
else
|
|
{
|
|
return "** IBAN ERRONEO **";
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IBANCorrecto
|
|
{
|
|
get
|
|
{
|
|
if (this.idTipoPago == idTippBA())
|
|
{
|
|
return tsUtilidades.Bancos.Genericas.IBANCorrecto(this.IBAN);
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Enums
|
|
public enum TipoOrigenRecibo
|
|
{
|
|
OTROS = 0,
|
|
IMPORTACION_EIAC = 1
|
|
}
|
|
|
|
public enum EstadoRecibo
|
|
{
|
|
PENDIENTE = 0,
|
|
REMESADO = 1,
|
|
GESTION_COBRO_CIA = 2,
|
|
DEVUELTO_BANCO = 3,
|
|
BAJA = 4,
|
|
LIQUIDADO = 6
|
|
}
|
|
|
|
public enum FormaComunicacionEnum
|
|
{
|
|
NINGUNA = 0,
|
|
POR_SMS = 1,
|
|
POR_CARTA = 2,
|
|
SIN_DOMICILIO_NI_TLF_VALIDO = 3
|
|
}
|
|
|
|
public enum TipoGestionEnum
|
|
{
|
|
AVISO_REMESA_O_COBRO_DIRECTO = 1,
|
|
AVISO_IMPERATIVO_LEGAL = 2,
|
|
AVISO_POLIZA_DE_BAJA = 3,
|
|
AVISO_RECIBO_DEVUELTO_BANCO = 4
|
|
}
|
|
|
|
public enum TipoGeneracionEnum
|
|
{
|
|
AVISO_REMESA_O_COBRO_DIRECTO = 1,
|
|
AVISO_BAJA_POLIZA = 2,
|
|
COMUNICACION_DEVUELTO_BANCO = 3,
|
|
AVISO_IMPERATIVO_LEGAL = 4,
|
|
EMAIL_A_AGENTE_FALTAN_DATOS_ASEGURADOS = 5
|
|
}
|
|
#endregion
|
|
|
|
#region Propiedades Calculadas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DateOnly? FechaLiquidacionCiaDevuelto
|
|
{
|
|
get
|
|
{
|
|
return FechaAsientoDevueltoCia;
|
|
}
|
|
}
|
|
|
|
public DateOnly? FechaLiquidacionAgente
|
|
{
|
|
get
|
|
{
|
|
if (this.liquidacionesagenterecibos.Any(x =>
|
|
x.idLiquidacionesAgenteNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQAG.LIQUIDACION"))
|
|
{
|
|
return this.liquidacionesagenterecibos
|
|
.Where(x => x.idLiquidacionesAgenteNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQAG.LIQUIDACION")
|
|
.OrderByDescending(x => x.idLiquidacionesAgenteNavigation.Fecha)
|
|
.First()
|
|
.idLiquidacionesAgenteNavigation.Fecha;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string TipoRecibo
|
|
{
|
|
get
|
|
{
|
|
return idTipoNavigation != null ? idTipoNavigation.Descripcion : "";
|
|
}
|
|
}
|
|
|
|
public string CausaBaja
|
|
{
|
|
get
|
|
{
|
|
return idCausaBajaNavigation != null ? idCausaBajaNavigation.Descripcion : "";
|
|
}
|
|
}
|
|
|
|
public int idLiquidacionAgente
|
|
{
|
|
get
|
|
{
|
|
if (this.liquidacionesagenterecibos.Any(x =>
|
|
x.idLiquidacionesAgenteNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQAG.LIQUIDACION"))
|
|
{
|
|
return this.liquidacionesagenterecibos
|
|
.Where(x => x.idLiquidacionesAgenteNavigation.idTipoLiquidacionNavigation.Codigo == "TIPLIQAG.LIQUIDACION")
|
|
.OrderByDescending(x => x.idLiquidacionesAgenteNavigation.Fecha)
|
|
.First()
|
|
.idLiquidacionesAgenteNavigation.idLiquidacionAgente;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string NombreBanco
|
|
{
|
|
get
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(IBAN))
|
|
{
|
|
if (IBAN.Length == 24)
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
string codBanco = IBAN.Substring(4, 4);
|
|
var banco = bd.bancos.FirstOrDefault(x => x.Codigo == codBanco);
|
|
if (banco != null) return banco.Nombre;
|
|
return "** DESCONOCIDO **";
|
|
}
|
|
return "** IBAN ERRONEO **";
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string CamposAComprobar
|
|
{
|
|
get
|
|
{
|
|
string sFechaBaja = FechaBaja.HasValue ? FechaBaja.Value.ToString("yyyyMMdd") : "0";
|
|
string sFechaPago = FechaPago.HasValue ? FechaPago.Value.ToString("yyyyMMdd") : "0";
|
|
string sFechaRemesa = idRemesa.HasValue && idRemesaNavigation != null ? idRemesaNavigation.Fecha.Value.ToString("yyyyMMdd") : "0";
|
|
string sNumeroRemesa = idRemesa.HasValue ? idRemesa.ToString() : "";
|
|
return $"{CodigoRecibo}|{sFechaBaja}|{sFechaPago}|{sFechaRemesa}|{sNumeroRemesa}";
|
|
}
|
|
}
|
|
|
|
public bool LimiteEfectoSobrePasadoFechaBaja
|
|
{
|
|
get
|
|
{
|
|
int diasLimite = 0;
|
|
if (!string.IsNullOrEmpty(TipoRecibo) && TipoRecibo.Contains("CARTERA"))
|
|
{
|
|
diasLimite = idPolizaNavigation?.idCompaniaNavigation?.NumeroDiasLimiteFBCartera ?? 0;
|
|
}
|
|
else
|
|
{
|
|
diasLimite = idPolizaNavigation?.idCompaniaNavigation?.NumeroDiasLimiteFBEmision ?? 0;
|
|
}
|
|
|
|
if (FechaEfecto != null)
|
|
{
|
|
return FechaEfecto < DateOnly.FromDateTime(DateTime.Today.AddDays(diasLimite));
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
public string DescripcionSuplemento
|
|
{
|
|
get
|
|
{
|
|
// Comprobamos si existen recibos
|
|
if (this.idPolizaNavigation.recibos.Any())
|
|
{
|
|
// Obtenemos el ID del primer recibo según la fecha de efecto
|
|
var idPrimerRecibo = this.idPolizaNavigation.recibos
|
|
.OrderBy(x => x.FechaEfecto)
|
|
.First()
|
|
.idRecibo;
|
|
|
|
// Si el recibo actual es el primero, devolvemos la descripción
|
|
if (idPrimerRecibo == this.idRecibo)
|
|
{
|
|
return this.idPolizaNavigation.DescripcionSuplemento;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Si no hay recibos, devolvemos la descripción por defecto
|
|
return this.idPolizaNavigation.DescripcionSuplemento;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public double PorcentajeComisionRecargoExterno
|
|
{
|
|
get
|
|
{
|
|
if (!RecargoExterno.HasValue || RecargoExterno == 0 || !AsegasaRecargoExterno.HasValue || AsegasaRecargoExterno.Value == 0) return 0;
|
|
return Math.Round(AsegasaRecargoExterno.Value * 100 / RecargoExterno.Value, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
|
|
public double PorcentajeComisionConsorcio
|
|
{
|
|
get
|
|
{
|
|
if (!Consorcio.HasValue || Consorcio == 0 || !AsegasaComisionConsorcio.HasValue || AsegasaComisionConsorcio.Value == 0) return 0;
|
|
return Math.Round(AsegasaComisionConsorcio.Value * 100 / Consorcio.Value, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
|
|
public double PorcentajeComisionAsegasa
|
|
{
|
|
get
|
|
{
|
|
if (!TotalComision.HasValue || TotalComision == 0 || !AsegasaComisionTotal.HasValue) return 0;
|
|
return Math.Round(AsegasaComisionTotal.Value * 100 / TotalComision.Value, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
|
|
public List<DatoComision> ObtieneDatosComisiones()
|
|
{
|
|
try
|
|
{
|
|
var ldcs = new List<DatoComision>();
|
|
|
|
var dc = new DatoComision();
|
|
dc.Concepto = "Prima Neta";
|
|
dc.Base = Math.Round((PrimaNeta ?? 0) + (BonificacionORecargo ?? 0), 2, MidpointRounding.AwayFromZero);
|
|
dc.Porcentaje = Math.Round(PorcentajeReciboPrimaNeta ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dc.ComisionBruta = Math.Round(ComisionReciboPrimaNeta ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dc.Sobrecomision = Math.Round(Sobrecomision ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dc.TotalComision = Math.Round(TotalComision ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dc.PorcentajeComisionPrevista = Math.Round(PorcentajeComisionPrevista ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dc.ComisionPrevista = Math.Round(ComisionPrevista ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dc.Diferencia = Math.Round(dc.ComisionBruta - (ComisionPrevista ?? 0), 2, MidpointRounding.AwayFromZero);
|
|
ldcs.Add(dc);
|
|
|
|
var dcre = new DatoComision();
|
|
dcre.Concepto = "Recargos Externos";
|
|
dcre.Base = Math.Round(RecargoExterno ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcre.Porcentaje = Math.Round(PorcentajeComisionRecargoExterno, 2, MidpointRounding.AwayFromZero);
|
|
dcre.Sobrecomision = 0;
|
|
dcre.TotalComision = Math.Round(AsegasaRecargoExterno ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcre.ComisionBruta = Math.Round(dcre.TotalComision, 2, MidpointRounding.AwayFromZero);
|
|
dcre.PorcentajeComisionPrevista = dcre.Porcentaje;
|
|
dcre.ComisionPrevista = dcre.TotalComision;
|
|
dcre.Diferencia = Math.Round(dcre.TotalComision - dcre.ComisionPrevista, 2, MidpointRounding.AwayFromZero);
|
|
ldcs.Add(dcre);
|
|
|
|
var dcco = new DatoComision();
|
|
dcco.Concepto = "Consorcio";
|
|
dcco.Base = Math.Round(Consorcio ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcco.Porcentaje = Math.Round(PorcentajeComisionConsorcio, 2, MidpointRounding.AwayFromZero);
|
|
dcco.Sobrecomision = 0;
|
|
dcco.TotalComision = Math.Round(AsegasaComisionConsorcio ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcco.ComisionBruta = Math.Round(dcco.TotalComision, 2, MidpointRounding.AwayFromZero);
|
|
dcco.PorcentajeComisionPrevista = dcco.Porcentaje;
|
|
dcco.ComisionPrevista = dcco.TotalComision;
|
|
dcco.Diferencia = Math.Round(dcco.TotalComision - dcco.ComisionPrevista, 2, MidpointRounding.AwayFromZero);
|
|
ldcs.Add(dcco);
|
|
|
|
var dcag = new DatoComision();
|
|
dcag.Concepto = "AGENTE";
|
|
dcag.Base = Math.Round(BaseComisionAgente ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcag.Porcentaje = Math.Round(PorcentajeComisionAgente ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcag.Sobrecomision = 0;
|
|
dcag.TotalComision = Math.Round(ComisionAgente ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcag.ComisionBruta = Math.Round(dcag.TotalComision, 2, MidpointRounding.AwayFromZero);
|
|
dcag.PorcentajeComisionPrevista = dcag.Porcentaje;
|
|
dcag.ComisionPrevista = dcag.TotalComision;
|
|
dcag.Diferencia = Math.Round(dcag.TotalComision - dcag.ComisionPrevista, 2, MidpointRounding.AwayFromZero);
|
|
ldcs.Add(dcag);
|
|
|
|
var dcAS = new DatoComision();
|
|
dcAS.Concepto = "ASEGASA";
|
|
dcAS.Base = Math.Round(TotalComision ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcAS.Porcentaje = Math.Round(PorcentajeComisionAsegasa, 2, MidpointRounding.AwayFromZero);
|
|
dcAS.ComisionBruta = Math.Round(AsegasaComisionTotal ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcAS.Sobrecomision = Math.Round(Sobrecomision ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
dcAS.TotalComision = Math.Round((AsegasaComisionTotal ?? 0) + (Sobrecomision ?? 0), 2, MidpointRounding.AwayFromZero);
|
|
dcAS.PorcentajeComisionPrevista = dcAS.Porcentaje;
|
|
dcAS.ComisionPrevista = dcAS.TotalComision;
|
|
dcAS.Diferencia = Math.Round(dcAS.ComisionBruta - dcAS.ComisionPrevista, 2, MidpointRounding.AwayFromZero);
|
|
ldcs.Add(dcAS);
|
|
|
|
return ldcs;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public EstadoRecibo Estado
|
|
{
|
|
get
|
|
{
|
|
EstadoRecibo est = EstadoRecibo.PENDIENTE;
|
|
if (idRemesa.HasValue) est = EstadoRecibo.REMESADO;
|
|
if (idTipoPago == idtippCIA() || idTipoPago == idtippFAE()) est = EstadoRecibo.GESTION_COBRO_CIA;
|
|
if (FechaUltimaLiquidacionAgente.HasValue) est = EstadoRecibo.LIQUIDADO;
|
|
if (FechaBaja.HasValue) est = EstadoRecibo.BAJA;
|
|
if (FechaDevolucionBanco.HasValue) est = EstadoRecibo.DEVUELTO_BANCO;
|
|
return est;
|
|
}
|
|
}
|
|
|
|
public string CausaDevolucion
|
|
{
|
|
get
|
|
{
|
|
if (idCausaDevolucionNavigation != null)
|
|
{
|
|
return idCausaDevolucionNavigation.Descripcion;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
public string TipoReciboName
|
|
{
|
|
get
|
|
{
|
|
if (idTipoNavigation != null)
|
|
{
|
|
return idTipoNavigation.Descripcion;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
public string CausaBajaName
|
|
{
|
|
get
|
|
{
|
|
if (idCausaBajaNavigation != null)
|
|
{
|
|
return idCausaBajaNavigation.Descripcion;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
public string TipoPago
|
|
{
|
|
get
|
|
{
|
|
if (idTipoPagoNavigation != null)
|
|
{
|
|
return idTipoPagoNavigation.Descripcion;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public FormaComunicacionEnum FormaComunicacionTMP { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string OficinaAgente
|
|
{
|
|
get
|
|
{
|
|
if (this.idAgenteNavigation != null)
|
|
return this.idAgenteNavigation.OficinaAgente;
|
|
else
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string DescripcionFormaComunicacion
|
|
{
|
|
get
|
|
{
|
|
switch (FormaComunicacionTMP)
|
|
{
|
|
case FormaComunicacionEnum.NINGUNA:
|
|
return "NINGUNA";
|
|
case FormaComunicacionEnum.POR_SMS:
|
|
return "SMS";
|
|
case FormaComunicacionEnum.POR_CARTA:
|
|
return "CARTA";
|
|
case FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO:
|
|
return "SIN DOMICILIO NI TLF VALIDO";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region CartasAvisos
|
|
public static List<recibos> ObtieneRecibosAvisoImperativoLegal(tscgestionasegasa? bd = null, List<string>? RecibosSinComunicacion = null)
|
|
{
|
|
if (bd == null) bd = tscgestionasegasa.NuevoContexto();
|
|
|
|
var tgsms = (int)FormaComunicacionEnum.POR_SMS;
|
|
var tgcarta = (int)FormaComunicacionEnum.POR_CARTA;
|
|
var tgsa = (int)FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO;
|
|
var tgsn = (int)FormaComunicacionEnum.NINGUNA;
|
|
var TipoCarta = (int)TipoGestionEnum.AVISO_IMPERATIVO_LEGAL;
|
|
|
|
var idTrex = bd.enumeraciones.First(x => x.Codigo == "TRC.EX").idEnumeracion;
|
|
var idTrcx = bd.enumeraciones.First(x => x.Codigo == "TRC.CX").idEnumeracion;
|
|
var idtippba = bd.enumeraciones.First(x => x.Codigo == "TIPP.BA").idEnumeracion;
|
|
var idtipcia = bd.enumeraciones.First(x => x.Codigo == "TIPP.CIA").idEnumeracion;
|
|
var idtipFAE = bd.enumeraciones.First(x => x.Codigo == "TIPP.FAE").idEnumeracion;
|
|
var idtipag = bd.enumeraciones.First(x => x.Codigo == "TIPP.AG").idEnumeracion;
|
|
|
|
var TipoRemesa = (int)TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO;
|
|
|
|
var FechaLimite = DateTime.Today.AddDays(-15);
|
|
var feflim = DateTime.Today.AddDays(-10);
|
|
var FechaEfectoLimite = DateTime.Today.AddDays(30);
|
|
|
|
var rsco = bd.recibos
|
|
.Include(x => x.idAgenteNavigation)
|
|
.Include(x => x.idSubagenteNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idCompaniaNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idRamoNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.entidadespolizas).ThenInclude(ep => ep.idEntidadNavigation)
|
|
.Include(x => x.idTipoNavigation)
|
|
.Include(x => x.idTipoPagoNavigation)
|
|
.Where(x => (x.PrimaNeta ?? 0) > 0 && !x.FechaPago.HasValue &&
|
|
!x.FechaBaja.HasValue && x.idTipoPago != idtippba && x.idTipoPago != idtipag && x.idTipoPago != idtipcia && x.idTipoPago != idtipFAE && x.idTipo != idTrex && x.idTipo != idTrcx
|
|
&& !x.gestionesrecibos.Any(y => y.Tipo == TipoCarta)
|
|
&& x.gestionesrecibos.Any(y => y.Tipo == TipoRemesa && y.Fecha <= FechaLimite)
|
|
&& x.FechaEfecto < DateOnly.FromDateTime(feflim) && DateOnly.FromDateTime(FechaEfectoLimite) >= x.FechaEfecto)
|
|
.ToList()
|
|
.Where(x => x.BloquearFacturacion == false)
|
|
.ToList();
|
|
|
|
var rsba = bd.recibos
|
|
.Include(x => x.idAgenteNavigation)
|
|
.Include(x => x.idSubagenteNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idCompaniaNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idRamoNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.entidadespolizas).ThenInclude(ep => ep.idEntidadNavigation)
|
|
.Include(x => x.idTipoNavigation)
|
|
.Include(x => x.idTipoPagoNavigation)
|
|
.Where(x => (x.PrimaNeta ?? 0) > 0 && !x.FechaPago.HasValue && x.FechaDevolucionBanco.HasValue &&
|
|
!x.FechaBaja.HasValue && x.idTipoPago == idtippba && x.idTipo != idTrex && x.idTipo != idTrcx
|
|
&& !x.gestionesrecibos.Any(y => y.Tipo == TipoCarta)
|
|
&& x.gestionesrecibos.Any(y => y.Tipo == TipoRemesa && y.Fecha <= FechaLimite)
|
|
&& x.FechaEfecto < DateOnly.FromDateTime(feflim) && DateOnly.FromDateTime(FechaEfectoLimite) >= x.FechaEfecto)
|
|
.ToList()
|
|
.Where(x => x.BloquearFacturacion == false)
|
|
.ToList();
|
|
|
|
var rs = rsco.Union(rsba).ToList();
|
|
|
|
foreach (var r in rs)
|
|
{
|
|
if (RecibosSinComunicacion != null && RecibosSinComunicacion.Contains(r.CodigoRecibo))
|
|
{
|
|
r.FormaComunicacionTMP = FormaComunicacionEnum.NINGUNA;
|
|
}
|
|
else
|
|
{
|
|
var tomador = r.idPolizaNavigation?.Tomador;
|
|
if (tomador != null && (tomador.Telefono1.EsNumeroTelefonoMovilEspañolValido() || tomador.Telefono2.EsNumeroTelefonoMovilEspañolValido()))
|
|
{
|
|
r.FormaComunicacionTMP = FormaComunicacionEnum.POR_SMS;
|
|
}
|
|
else
|
|
{
|
|
var dir = tomador?.direcciones.FirstOrDefault();
|
|
if (dir != null && !string.IsNullOrEmpty(dir.CodigoPostal) && dir.CodigoMunicipioNavigation != null && !string.IsNullOrEmpty(dir.Direccion))
|
|
{
|
|
r.FormaComunicacionTMP = FormaComunicacionEnum.POR_CARTA;
|
|
}
|
|
else
|
|
{
|
|
r.FormaComunicacionTMP = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return rs;
|
|
}
|
|
|
|
public static List<recibos> ObtieneRecibosCartaRemesa(tscgestionasegasa? bd = null)
|
|
{
|
|
try
|
|
{
|
|
if (bd == null) bd = tscgestionasegasa.NuevoContexto();
|
|
var tgninguna = FormaComunicacionEnum.NINGUNA;
|
|
var tgsms = FormaComunicacionEnum.POR_SMS;
|
|
var tgcarta = FormaComunicacionEnum.POR_CARTA;
|
|
var tgsa = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO;
|
|
|
|
var idtippba = bd.enumeraciones.First(x => x.Codigo == "TIPP.BA").idEnumeracion;
|
|
var idtipcia = bd.enumeraciones.First(x => x.Codigo == "TIPP.CIA").idEnumeracion;
|
|
var idtipFAE = bd.enumeraciones.First(x => x.Codigo == "TIPP.FAE").idEnumeracion;
|
|
var idtipag = bd.enumeraciones.First(x => x.Codigo == "TIPP.AG").idEnumeracion;
|
|
|
|
var ahora = Utilidades.AhoraMysql(bd);
|
|
var FecLim = ahora.AddDays(20);
|
|
var TipoCartaRemesa = (int)TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO;
|
|
|
|
var rs = bd.recibos
|
|
.Include(x => x.idAgenteNavigation)
|
|
.Include(x => x.idSubagenteNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idCompaniaNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idRamoNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.entidadespolizas).ThenInclude(ep => ep.idEntidadNavigation)
|
|
.Include(x => x.idTipoNavigation)
|
|
.Include(x => x.idTipoPagoNavigation)
|
|
.Include(x => x.idRemesaNavigation)
|
|
.Where(x => !x.FechaPago.HasValue && !x.FechaCartaRemesaCobroDirecto.HasValue && !x.gestionesrecibos.Any(y => y.Tipo == TipoCartaRemesa) &&
|
|
!x.FechaBaja.HasValue && (x.TotalRecibo ?? 0) > 0 &&
|
|
(x.idTipoPago != idtipcia && x.idTipoPago != idtipFAE && x.idTipoPago != idtipag) &&
|
|
x.FechaEfecto < DateOnly.FromDateTime(FecLim))
|
|
.ToList()
|
|
.Where(x => x.BloquearFacturacion == false)
|
|
.ToList();
|
|
|
|
foreach (var r in rs)
|
|
{
|
|
try
|
|
{
|
|
var tomador = r.idPolizaNavigation?.Tomador;
|
|
if (r.FechaEfecto < DateOnly.FromDateTime(ahora.AddDays(-20)) || r.FechaPago.HasValue || r.idRemesa.HasValue)
|
|
{
|
|
if (!(r.idRemesa.HasValue && r.idRemesaNavigation != null && (DateTime.Today - r.idRemesaNavigation.Fecha.Value.ToDateTime(TimeOnly.MinValue)).TotalDays > 0) &&
|
|
tomador != null && (tomador.Telefono1.EsNumeroTelefonoMovilEspañolValido() || tomador.Telefono2.EsNumeroTelefonoMovilEspañolValido()))
|
|
{
|
|
r.FormaComunicacionTMP = tgsms;
|
|
}
|
|
else
|
|
{
|
|
r.FormaComunicacionTMP = tgninguna;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (tomador == null)
|
|
{
|
|
r.FormaComunicacionTMP = tgsa;
|
|
}
|
|
else
|
|
{
|
|
if (tomador.Telefono1.EsNumeroTelefonoMovilEspañolValido() || tomador.Telefono2.EsNumeroTelefonoMovilEspañolValido())
|
|
{
|
|
r.FormaComunicacionTMP = tgsms;
|
|
}
|
|
else
|
|
{
|
|
var dir = tomador.direcciones.FirstOrDefault();
|
|
if (dir != null && !string.IsNullOrEmpty(dir.CodigoPostal) && dir.CodigoMunicipioNavigation != null && !string.IsNullOrEmpty(dir.Direccion))
|
|
{
|
|
r.FormaComunicacionTMP = tgcarta;
|
|
}
|
|
else
|
|
{
|
|
r.FormaComunicacionTMP = tgsa;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Log or handle error if needed
|
|
}
|
|
}
|
|
return rs;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public static List<recibos> ObtieneRecibosCartaBaja(tscgestionasegasa? bd = null, List<string>? RecibosSinComunicacion = null)
|
|
{
|
|
if (bd == null) bd = tscgestionasegasa.NuevoContexto();
|
|
var tgsms = FormaComunicacionEnum.POR_SMS;
|
|
var tgcarta = FormaComunicacionEnum.POR_CARTA;
|
|
var tgsa = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO;
|
|
var tgsn = FormaComunicacionEnum.NINGUNA;
|
|
var TipoCarta = (int)TipoGestionEnum.AVISO_POLIZA_DE_BAJA;
|
|
|
|
var Cabas = bd.enumeraciones
|
|
.Where(x => x.Codigo == "CABA.CIA" || x.Codigo == "CABA.ASEG" || x.Codigo == "CABA.AGEN" || x.Codigo == "CABA.VTA" || x.Codigo == "CABA.BJA" || x.Codigo == "CABA.ASFP" || x.Codigo == "CABA.SIN")
|
|
.Select(x => x.idEnumeracion)
|
|
.ToList();
|
|
|
|
var FechaInicio = new DateOnly(2019, 12, 31);
|
|
var rs = bd.recibos
|
|
.Include(x => x.idAgenteNavigation)
|
|
.Include(x => x.idSubagenteNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idCompaniaNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idRamoNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.entidadespolizas).ThenInclude(ep => ep.idEntidadNavigation)
|
|
.Include(x => x.idTipoNavigation)
|
|
.Include(x => x.idTipoPagoNavigation)
|
|
.Where(x => x.FechaBaja.HasValue && x.FechaBaja > FechaInicio && x.idCausaBaja.HasValue && Cabas.Contains(x.idCausaBaja.Value) && !x.gestionesrecibos.Any(y => y.Tipo == TipoCarta))
|
|
.ToList()
|
|
.Where(x => x.BloquearFacturacion == false)
|
|
.ToList();
|
|
|
|
foreach (var r in rs)
|
|
{
|
|
if (RecibosSinComunicacion != null && RecibosSinComunicacion.Contains(r.CodigoRecibo))
|
|
{
|
|
r.FormaComunicacionTMP = tgsn;
|
|
}
|
|
else
|
|
{
|
|
var tomador = r.idPolizaNavigation?.Tomador;
|
|
if (tomador != null && (tomador.Telefono1.EsNumeroTelefonoMovilEspañolValido() || tomador.Telefono2.EsNumeroTelefonoMovilEspañolValido()))
|
|
{
|
|
r.FormaComunicacionTMP = tgsms;
|
|
}
|
|
else
|
|
{
|
|
var dir = tomador?.direcciones.FirstOrDefault();
|
|
if (dir != null && !string.IsNullOrEmpty(dir.CodigoPostal) && dir.CodigoMunicipioNavigation != null && !string.IsNullOrEmpty(dir.Direccion))
|
|
{
|
|
r.FormaComunicacionTMP = tgcarta;
|
|
}
|
|
else
|
|
{
|
|
r.FormaComunicacionTMP = tgsa;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return rs;
|
|
}
|
|
|
|
public static List<recibos> ObtieneRecibosComunicacionDevueltoBanco(tscgestionasegasa? bd = null)
|
|
{
|
|
if (bd == null) bd = tscgestionasegasa.NuevoContexto();
|
|
var tgsms = FormaComunicacionEnum.POR_SMS;
|
|
var tgcarta = FormaComunicacionEnum.POR_CARTA;
|
|
var tgsa = FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO;
|
|
var TipoCarta = (int)TipoGestionEnum.AVISO_RECIBO_DEVUELTO_BANCO;
|
|
|
|
var idTrex = bd.enumeraciones.First(x => x.Codigo == "TRC.EX").idEnumeracion;
|
|
var idTrcx = bd.enumeraciones.First(x => x.Codigo == "TRC.CX").idEnumeracion;
|
|
var idtippba = bd.enumeraciones.First(x => x.Codigo == "TIPP.BA").idEnumeracion;
|
|
|
|
var rs = bd.recibos
|
|
.Include(x => x.idAgenteNavigation)
|
|
.Include(x => x.idSubagenteNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idCompaniaNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.idRamoNavigation)
|
|
.Include(x => x.idPolizaNavigation).ThenInclude(p => p.entidadespolizas).ThenInclude(ep => ep.idEntidadNavigation)
|
|
.Include(x => x.idTipoNavigation)
|
|
.Include(x => x.idTipoPagoNavigation)
|
|
.Where(x => !x.FechaBaja.HasValue && !x.FechaCartaDevuelto.HasValue && x.FechaDevolucionBanco.HasValue && x.idTipoPago == idtippba && x.idTipo != idTrex && x.idTipo != idTrcx && !x.gestionesrecibos.Any(y => y.Tipo == TipoCarta) && (x.idAsientoDevueltoBanco.HasValue || x.FechaAsientoDevueltoBanco.HasValue))
|
|
.ToList()
|
|
.Where(x => x.BloquearFacturacion == false)
|
|
.ToList();
|
|
|
|
foreach (var r in rs)
|
|
{
|
|
var tomador = r.idPolizaNavigation?.Tomador;
|
|
if (tomador != null && (tomador.Telefono1.EsNumeroTelefonoMovilEspañolValido() || tomador.Telefono2.EsNumeroTelefonoMovilEspañolValido()))
|
|
{
|
|
r.FormaComunicacionTMP = tgsms;
|
|
}
|
|
else
|
|
{
|
|
var dir = tomador?.direcciones.FirstOrDefault();
|
|
if (dir != null && !string.IsNullOrEmpty(dir.CodigoPostal) && dir.CodigoMunicipioNavigation != null && !string.IsNullOrEmpty(dir.Direccion))
|
|
{
|
|
r.FormaComunicacionTMP = tgcarta;
|
|
}
|
|
else
|
|
{
|
|
r.FormaComunicacionTMP = tgsa;
|
|
}
|
|
}
|
|
}
|
|
return rs;
|
|
}
|
|
|
|
public delegate void DelegadoProgreso(string Mensaje);
|
|
|
|
public static void GeneraAvisoRemesa(List<recibos> lr, tscgestionasegasa? bd = null, DelegadoProgreso? Progreso = null)
|
|
{
|
|
try
|
|
{
|
|
if (Progreso != null) Progreso("Generando Comunicaciones ...");
|
|
if (bd == null) bd = tscgestionasegasa.NuevoContexto();
|
|
|
|
lr = lr.Where(x => x.IBANCorrecto).ToList();
|
|
|
|
var cr_cb_cl = bd.plantillas.First(x => x.Codigo == "CR.CB.CL");
|
|
var cr_cb_sl = bd.plantillas.First(x => x.Codigo == "CR.CB.SL");
|
|
var cr_cd_cl = bd.plantillas.First(x => x.Codigo == "CR.CD.CL");
|
|
var cr_cd_sl = bd.plantillas.First(x => x.Codigo == "CR.CD.SL");
|
|
var cr_cpe_cl = bd.plantillas.First(x => x.Codigo == "CR.CPE.CL");
|
|
var cr_cpe_sl = bd.plantillas.First(x => x.Codigo == "CR.CPE.SL");
|
|
var desconf = bd.enumeraciones.First(x => x.Codigo == "CONF.CTAITSOFT").ValorAlfabetico3;
|
|
|
|
var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES");
|
|
var idtippba = bd.enumeraciones.First(x => x.Codigo == "TIPP.BA").idEnumeracion;
|
|
var idtipppe = bd.enumeraciones.First(x => x.Codigo == "TIPP.PE").idEnumeracion;
|
|
|
|
var PdfsAUnir = new List<byte[]>();
|
|
int i = 0;
|
|
int iNumMensaje = 0;
|
|
int iNumcorreo = 0;
|
|
var idTipoFichero = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.CAR").idEnumeracion;
|
|
|
|
int? idUsuario = null;
|
|
if (idUsuarioLogueado > 0) idUsuario = idUsuarioLogueado;
|
|
|
|
foreach (var r in lr)
|
|
{
|
|
i++;
|
|
if (Progreso != null) Progreso($"Generando Comunicación {i} de {lr.Count}");
|
|
mensajes? msg = null;
|
|
ficheros? f = null;
|
|
byte[]? b = null;
|
|
|
|
if (r.FormaComunicacionTMP != FormaComunicacionEnum.NINGUNA)
|
|
{
|
|
plantillas pl;
|
|
if (r.FormaComunicacionTMP == FormaComunicacionEnum.POR_CARTA)
|
|
{
|
|
if (r.idTipoPago == idtippba) pl = cr_cb_sl;
|
|
else if (r.idTipoPago == idtipppe) pl = cr_cpe_sl;
|
|
else pl = cr_cd_sl;
|
|
}
|
|
else
|
|
{
|
|
if (r.idTipoPago == idtippba) pl = cr_cb_cl;
|
|
else if (r.idTipoPago == idtipppe) pl = cr_cpe_cl;
|
|
else pl = cr_cd_cl;
|
|
}
|
|
|
|
var ds = new List<recibos> { r };
|
|
var cc = bdAsegasa.Informes.Utilidades.ObtieneCCRecibos(ds);
|
|
b = bdAsegasa.Informes.Utilidades.FusionaPlantillaENPDF(pl.Plantilla, cc);
|
|
|
|
f = new ficheros
|
|
{
|
|
idTipo = idTipoFichero,
|
|
NombreFichero = $"car-{r.idRecibo}.pdf",
|
|
Descripcion = "Carta aviso remesa",
|
|
Fecha = Utilidades.AhoraMysql(bd),
|
|
Fichero = b
|
|
};
|
|
bd.ficheros.Add(f);
|
|
bd.SaveChanges();
|
|
}
|
|
|
|
if (r.FormaComunicacionTMP == FormaComunicacionEnum.POR_SMS)
|
|
{
|
|
iNumMensaje++;
|
|
var tomador = r.idPolizaNavigation?.Tomador;
|
|
var sUrl = $". Url descarga: http://f.asegasa.es/?{f?.idFicheroEnc}";
|
|
var smensaje = $"Proximo cobro de su poliza {r.idPolizaNavigation?.NumeroPoliza} {r.idPolizaNavigation?.idRamoNavigation?.Descripcion}".Acortar(160 - sUrl.Length - 1) + sUrl;
|
|
|
|
msg = new mensajes
|
|
{
|
|
Aplicacion = "RECIBOS",
|
|
idAplicacion = r.idRecibo,
|
|
Cuenta = "ITSOFT",
|
|
Destinatario = tomador?.Telefono1.EsNumeroTelefonoMovilEspañolValido() == true ? tomador.Telefono1 : tomador?.Telefono2,
|
|
FechaCreacion = Utilidades.AhoraMysql(bd),
|
|
idUsuario = idUsuario,
|
|
Mensaje = smensaje
|
|
};
|
|
bd.mensajes.Add(msg);
|
|
|
|
if (iNumMensaje == 1)
|
|
{
|
|
var msgpr = new mensajes
|
|
{
|
|
Aplicacion = "RECIBOS",
|
|
idAplicacion = r.idRecibo,
|
|
Cuenta = "ITSOFT",
|
|
Destinatario = desconf,
|
|
FechaCreacion = Utilidades.AhoraMysql(bd),
|
|
idUsuario = idUsuario,
|
|
Mensaje = smensaje
|
|
};
|
|
bd.mensajes.Add(msgpr);
|
|
}
|
|
bd.SaveChanges();
|
|
}
|
|
else if (r.FormaComunicacionTMP != FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO && r.FormaComunicacionTMP != FormaComunicacionEnum.NINGUNA)
|
|
{
|
|
if (b != null) PdfsAUnir.Add(b);
|
|
}
|
|
|
|
var tg = new gestionesrecibos
|
|
{
|
|
idRecibo = r.idRecibo,
|
|
FormaComunicacion = (int)r.FormaComunicacionTMP,
|
|
Tipo = (int)TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO,
|
|
GestionesRealizadas = TipoGestionEnum.AVISO_REMESA_O_COBRO_DIRECTO.ToString().Replace("_", " ") + " (" + r.DescripcionFormaComunicacion + ")",
|
|
Fecha = Utilidades.AhoraMysql(bd),
|
|
idUsuario = idUsuario,
|
|
idFicheroNavigation = f,
|
|
idMensajeNavigation = msg
|
|
};
|
|
bd.gestionesrecibos.Add(tg);
|
|
bd.SaveChanges();
|
|
|
|
var tomadorMail = r.idPolizaNavigation?.Tomador;
|
|
if (r.FormaComunicacionTMP != FormaComunicacionEnum.NINGUNA && tomadorMail != null && tomadorMail.Email.EsEmailValido())
|
|
{
|
|
iNumcorreo++;
|
|
tg.idCorreo = correos.GeneraRegistroCorreo(bd, $"Aviso de remesa de su poliza {r.idPolizaNavigation?.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.idPolizaNavigation?.NumeroPoliza}<br /><br />Url descarga: <a href=\"http://f.asegasa.es/?{f?.idFicheroEnc}\">Pulse aquí</a>", cta, tomadorMail.Email);
|
|
|
|
if (iNumcorreo == 1)
|
|
{
|
|
correos.GeneraRegistroCorreo(bd, $"Aviso de remesa de su poliza {r.idPolizaNavigation?.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.idPolizaNavigation?.NumeroPoliza}<br /><br />Url descarga: <a href=\"http://f.asegasa.es/?{f?.idFicheroEnc}\">Pulse aquí</a>", cta, "jaimehidalgo@asegasa.es");
|
|
}
|
|
bd.SaveChanges();
|
|
}
|
|
}
|
|
|
|
if (PdfsAUnir.Count > 0)
|
|
{
|
|
// Assuming a PDF merging utility exists or using a placeholder
|
|
// byte[] mergedPdf = tsUtilidades.Utilidades.UnePdfs(PdfsAUnir);
|
|
// EnviaCorreoEmpresaCartas(bd, mergedPdf, $"Adjunto le remitimos cartas de AVISO REMESA correspondientes al día {DateTime.Today:dd/MM/yyyy} para su envío. Un saludo.", "AVISO REMESA", cta);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public static void GeneraAviso(List<recibos> lr, TipoGeneracionEnum Tipo, string Asunto, string Cuerpo, tscgestionasegasa? bd = null, DelegadoProgreso? Progreso = null)
|
|
{
|
|
try
|
|
{
|
|
if (Progreso != null) Progreso("Generando Comunicaciones ...");
|
|
if (bd == null) bd = tscgestionasegasa.NuevoContexto();
|
|
|
|
var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES");
|
|
var desconf = bd.enumeraciones.First(x => x.Codigo == "CONF.CTAITSOFT").ValorAlfabetico3;
|
|
|
|
string sTipo = ((int)Tipo).ToString();
|
|
var c_cl = bd.plantillas.First(x => x.Codigo == "C.CL." + sTipo);
|
|
var c_sl = bd.plantillas.First(x => x.Codigo == "C.SL." + sTipo);
|
|
|
|
var PdfsAUnir = new List<byte[]>();
|
|
int i = 0;
|
|
int iNumMensaje = 0;
|
|
int iNumcorreo = 0;
|
|
int? idUsuario = null;
|
|
if (idUsuarioLogueado > 0) idUsuario = idUsuarioLogueado;
|
|
|
|
foreach (var r in lr)
|
|
{
|
|
var tg = new gestionesrecibos();
|
|
var pol = r.idPolizaNavigation;
|
|
var ramo = pol?.idRamoNavigation;
|
|
|
|
var AsuntoReemplazado = Asunto.Replace("%POLIZAYRAMO%", $"{pol?.NumeroPoliza} {ramo?.Descripcion}").Replace("%POLIZA%", pol?.NumeroPoliza).Replace("%RECIBO%", r.NumeroRecibo);
|
|
var CuerpoReemplazado = Cuerpo.Replace("%POLIZAYRAMO%", $"{pol?.NumeroPoliza} {ramo?.Descripcion}").Replace("%POLIZA%", pol?.NumeroPoliza).Replace("%RECIBO%", r.NumeroRecibo);
|
|
|
|
i++;
|
|
string? sFicEnc = null;
|
|
|
|
if (r.FormaComunicacionTMP != FormaComunicacionEnum.NINGUNA && r.FormaComunicacionTMP != FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO)
|
|
{
|
|
if (Progreso != null) Progreso($"Generando Comunicación {Tipo.ToString().Replace("_", " ")} {i} de {lr.Count}");
|
|
|
|
plantillas pl = (r.FormaComunicacionTMP == FormaComunicacionEnum.POR_SMS) ? c_cl : c_sl;
|
|
|
|
var ds = new List<recibos> { r };
|
|
var cc = bdAsegasa.Informes.Utilidades.ObtieneCCRecibos(ds);
|
|
var b = bdAsegasa.Informes.Utilidades.FusionaPlantillaENPDF(pl.Plantilla, cc);
|
|
|
|
var idTipoFichero = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.CAB").idEnumeracion;
|
|
var f = new ficheros
|
|
{
|
|
idTipo = idTipoFichero,
|
|
NombreFichero = $"cab-{r.idRecibo}.pdf",
|
|
Descripcion = "Carta aviso de baja",
|
|
Fecha = Utilidades.AhoraMysql(bd),
|
|
Fichero = b
|
|
};
|
|
bd.ficheros.Add(f);
|
|
bd.SaveChanges();
|
|
|
|
tg.idFichero = f.idFichero;
|
|
sFicEnc = f.idFicheroEnc;
|
|
|
|
if (r.FormaComunicacionTMP == FormaComunicacionEnum.POR_SMS)
|
|
{
|
|
iNumMensaje++;
|
|
var sUrl = $". Url descarga: http://f.asegasa.es/?{sFicEnc}";
|
|
var smensaje = AsuntoReemplazado.Acortar(160 - sUrl.Length) + sUrl;
|
|
var tomador = pol?.Tomador;
|
|
|
|
var msg = new mensajes
|
|
{
|
|
Aplicacion = "RECIBOS",
|
|
idAplicacion = r.idRecibo,
|
|
Cuenta = "ITSOFT",
|
|
Destinatario = tomador?.Telefono1.EsNumeroTelefonoMovilEspañolValido() == true ? tomador.Telefono1 : tomador?.Telefono2,
|
|
FechaCreacion = Utilidades.AhoraMysql(bd),
|
|
idUsuario = idUsuario,
|
|
Mensaje = smensaje
|
|
};
|
|
bd.mensajes.Add(msg);
|
|
|
|
if (iNumMensaje == 1)
|
|
{
|
|
var msgpr = new mensajes
|
|
{
|
|
Aplicacion = "RECIBOS",
|
|
idAplicacion = r.idRecibo,
|
|
Cuenta = "ITSOFT",
|
|
Destinatario = desconf,
|
|
FechaCreacion = Utilidades.AhoraMysql(bd),
|
|
idUsuario = idUsuario,
|
|
Mensaje = smensaje
|
|
};
|
|
bd.mensajes.Add(msgpr);
|
|
}
|
|
bd.SaveChanges();
|
|
tg.idMensaje = msg.idMensaje;
|
|
}
|
|
else
|
|
{
|
|
PdfsAUnir.Add(b);
|
|
}
|
|
}
|
|
|
|
tg.idRecibo = r.idRecibo;
|
|
tg.FormaComunicacion = (int)r.FormaComunicacionTMP;
|
|
tg.Tipo = (int)Tipo;
|
|
tg.GestionesRealizadas = Tipo.ToString().Replace("_", " ") + " " + r.DescripcionFormaComunicacion;
|
|
tg.Fecha = Utilidades.AhoraMysql(bd);
|
|
tg.idUsuario = idUsuario;
|
|
|
|
bd.gestionesrecibos.Add(tg);
|
|
bd.SaveChanges();
|
|
|
|
var tomadorMail = pol?.Tomador;
|
|
if (r.FormaComunicacionTMP != FormaComunicacionEnum.NINGUNA && r.FormaComunicacionTMP != FormaComunicacionEnum.SIN_DOMICILIO_NI_TLF_VALIDO && tomadorMail != null && tomadorMail.Email.EsEmailValido())
|
|
{
|
|
iNumcorreo++;
|
|
tg.idCorreo = correos.GeneraRegistroCorreo(bd, AsuntoReemplazado, CuerpoReemplazado + $"<br /><br />Url descarga: <a href=\"http://f.asegasa.es/?{sFicEnc}\">Pulse aquí</a>", cta, tomadorMail.Email);
|
|
|
|
if (iNumcorreo == 1)
|
|
{
|
|
correos.GeneraRegistroCorreo(bd, AsuntoReemplazado, CuerpoReemplazado + $"<br /><br />Url descarga: <a href=\"http://f.asegasa.es/?{sFicEnc}\">Pulse aquí</a>", cta, "jaimehidalgo@asegasa.es");
|
|
}
|
|
bd.SaveChanges();
|
|
}
|
|
}
|
|
|
|
if (PdfsAUnir.Count > 0)
|
|
{
|
|
// Assuming a PDF merging utility exists or using a placeholder
|
|
// byte[] mergedPdf = tsUtilidades.Utilidades.UnePdfs(PdfsAUnir);
|
|
// EnviaCorreoEmpresaCartas(bd, mergedPdf, $"Adjunto le remitimos cartas de {Tipo.ToString().Replace("_", " ")} correspondientes al día {DateTime.Today:dd/MM/yyyy} para su envío. Un saludo.", Tipo.ToString(), cta);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
private static void EnviaCorreoEmpresaCartas(tscgestionasegasa bd, byte[] Fichero, string Asunto, string TipoFichero, cuentascorreo cta)
|
|
{
|
|
// Placeholder: This should be implemented based on existing email utility patterns
|
|
// bdAsegasa.db.correos.GeneraRegistroCorreoConAdjunto(bd, Asunto, Asunto, cta, "cartas@asegasa.es", Fichero, TipoFichero + ".pdf");
|
|
}
|
|
#endregion
|
|
|
|
private static int idUsuarioLogueado => bdAsegasa.db.Utilidades.dsc?.idUsuario ?? 0;
|
|
|
|
#region Recalculos
|
|
public static void RecalculaDatosEconomicos(tscgestionasegasa bd, recibos Recibo, bool RecalculaTotalComision = true)
|
|
{
|
|
try
|
|
{
|
|
Recibo.AsegasaComisionConsorcio = 0;
|
|
var pol = Recibo.idPolizaNavigation;
|
|
var comcia = bd.comisionescompanias.FirstOrDefault(x => x.idCompania == pol.idCompania && x.idRamo == pol.idRamo &&
|
|
(!x.FechaInicioCampana.HasValue || x.FechaInicioCampana <= Recibo.FechaEfecto) &&
|
|
(!x.FechaFinCampana.HasValue || x.FechaFinCampana >= Recibo.FechaEfecto));
|
|
|
|
Recibo.ComisionPrevista = 0;
|
|
if (!Recibo.Sobrecomision.HasValue) Recibo.Sobrecomision = 0;
|
|
|
|
double claserecibo = Recibo.idTipoNavigation?.ValorNumerico1 ?? 0;
|
|
|
|
if (claserecibo == 0)
|
|
{
|
|
Recibo.PorcentajeComisionPrevista = comcia?.PorcentajeComisionEmision ?? 0;
|
|
Recibo.PorcentajeReciboPrimaNeta = Recibo.PorcentajeComisionPrevista;
|
|
}
|
|
else
|
|
{
|
|
Recibo.PorcentajeComisionPrevista = comcia?.PorcentajeComisionCartera ?? 0;
|
|
Recibo.PorcentajeReciboPrimaNeta = Recibo.PorcentajeComisionPrevista;
|
|
}
|
|
|
|
Recibo.ComisionPrevista = Math.Round((Recibo.PrimaNeta ?? 0 + (Recibo.BonificacionORecargo ?? 0)) * (Recibo.PorcentajeReciboPrimaNeta ?? 0) / 100, 2, MidpointRounding.AwayFromZero);
|
|
Recibo.ComisionPrevistaAsegasa = Math.Round(((Recibo.PrimaNeta ?? 0 + (Recibo.BonificacionORecargo ?? 0)) * (Recibo.PorcentajeReciboPrimaNeta ?? 0) / 100) + (Recibo.Sobrecomision ?? 0), 2, MidpointRounding.AwayFromZero);
|
|
|
|
if (RecalculaTotalComision)
|
|
{
|
|
Recibo.ComisionReciboPrimaNeta = Recibo.ComisionPrevista;
|
|
Recibo.TotalComision = (Recibo.ComisionReciboPrimaNeta ?? 0) + (Recibo.Sobrecomision ?? 0);
|
|
}
|
|
else
|
|
{
|
|
Recibo.ComisionReciboPrimaNeta = (Recibo.TotalComision ?? 0) - (Recibo.Sobrecomision ?? 0);
|
|
}
|
|
|
|
Recibo.BaseComisionAgente = (Recibo.ComisionReciboPrimaNeta ?? 0) < 0 ? Recibo.ComisionReciboPrimaNeta : Math.Min(Recibo.TotalComision ?? 0, Math.Min(Recibo.ComisionPrevista ?? 0, Recibo.ComisionReciboPrimaNeta ?? 0));
|
|
Recibo.PorcentajeBaseComisionAgente = (Recibo.PrimaNeta ?? 0) == 0 ? 0 : Math.Round((Recibo.BaseComisionAgente ?? 0) / (Recibo.PrimaNeta ?? 0) * 100, 2, MidpointRounding.AwayFromZero);
|
|
|
|
RecalculaComisiones(bd, Recibo);
|
|
|
|
Recibo.TotalRecibo = Math.Round((Recibo.PrimaNeta ?? 0) + (Recibo.BonificacionORecargo ?? 0) + (Recibo.Consorcio ?? 0) + (Recibo.Impuesto ?? 0) + (Recibo.RecargoExterno ?? 0), 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public static void RecalculaComisiones(tscgestionasegasa bd, recibos Recibo)
|
|
{
|
|
try
|
|
{
|
|
double pca = 0;
|
|
if (Recibo.idAgente.HasValue && Recibo.idAgente > 0)
|
|
{
|
|
var pol = Recibo.idPolizaNavigation;
|
|
var comage = bd.comisionesagentes.FirstOrDefault(x => x.idAgente == Recibo.idAgente && x.idCompania == pol.idCompania && x.idRamo == pol.idRamo);
|
|
if (comage == null)
|
|
{
|
|
comage = bd.comisionesagentes.FirstOrDefault(x => x.idAgente == Recibo.idAgente && !x.idCompania.HasValue && x.idRamo == pol.idRamo);
|
|
if (comage == null)
|
|
{
|
|
comage = bd.comisionesagentes.FirstOrDefault(x => x.idAgente == Recibo.idAgente && !x.idRamo.HasValue && x.idCompania == pol.idCompania);
|
|
}
|
|
}
|
|
|
|
if (comage != null)
|
|
{
|
|
pca = (Recibo.PrimaNeta ?? 0) <= (comage.Limite ?? 0) ? (comage.ComisionMenorIgualLimiteEmision ?? 0) : (comage.ComisionMayorLimiteEmision ?? 0);
|
|
}
|
|
else if (Recibo.idAgenteNavigation != null)
|
|
{
|
|
pca = (Recibo.PrimaNeta ?? 0) <= (Recibo.idAgenteNavigation.LimiteCondicionesGenerales ?? 0) ? (Recibo.idAgenteNavigation.ComisionMenorIgualLimiteEmision ?? 0) : (Recibo.idAgenteNavigation.ComisionMayorLimiteEmision ?? 0);
|
|
}
|
|
}
|
|
Recibo.PorcentajeComisionAgente = pca;
|
|
Recibo.ComisionAgente = Math.Round((Recibo.BaseComisionAgente ?? 0) * (Recibo.PorcentajeComisionAgente ?? 0) / 100, 2, MidpointRounding.AwayFromZero);
|
|
Recibo.ComisionAsegasaPrimaNeta = (Recibo.ComisionReciboPrimaNeta ?? 0) - (Recibo.ComisionAgente ?? 0);
|
|
Recibo.AsegasaComisionTotal = (Recibo.ComisionAsegasaPrimaNeta ?? 0) + (Recibo.AsegasaComisionConsorcio ?? 0) + (Recibo.AsegasaRecargoExterno ?? 0);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Conversiones
|
|
public ListadoGestionCobro AListadoGestionCobro()
|
|
{
|
|
return new ListadoGestionCobro(this);
|
|
}
|
|
|
|
public ListadoDevueltos AListadoDevueltos()
|
|
{
|
|
return new ListadoDevueltos(this);
|
|
}
|
|
|
|
public ListadoBajas AListadoBajas()
|
|
{
|
|
return new ListadoBajas(this);
|
|
}
|
|
|
|
public ListadoAsegurados AListadoAsegurados()
|
|
{
|
|
return new ListadoAsegurados(this);
|
|
}
|
|
#endregion
|
|
|
|
private static string ReciboAHistoricoCaser(string codigoRecibo)
|
|
{
|
|
using var bd = tscgestionasegasa.NuevoContexto();
|
|
var r = bd.recibos.First(x => x.CodigoRecibo == codigoRecibo);
|
|
var idCaser = bd.companias.First(x => x.Codigo == "0017").idCompania;
|
|
int i = 0;
|
|
if (r.NumeroRecibo.EndsWith("."))
|
|
{
|
|
r.NumeroRecibo = r.NumeroRecibo.TrimEnd('.');
|
|
}
|
|
string sNuevoRecibo = r.NumeroRecibo + "-H";
|
|
while (bd.recibos.FirstOrDefault(x => x.NumeroRecibo == sNuevoRecibo && x.idPolizaNavigation.idCompania == idCaser) != null)
|
|
{
|
|
i++;
|
|
sNuevoRecibo = r.NumeroRecibo + "-H" + i.ToString();
|
|
}
|
|
r.NumeroRecibo = sNuevoRecibo;
|
|
r.CodigoRecibo = "0017/" + sNuevoRecibo;
|
|
bd.SaveChanges();
|
|
return r.CodigoRecibo;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class ListadoGestionCobro
|
|
{
|
|
public ListadoGestionCobro(recibos Recibo)
|
|
{
|
|
NumeroRecibo = Recibo.NumeroRecibo;
|
|
FechaExpedicion = Recibo.FechaExpedicion;
|
|
NumeroPoliza = Recibo.idPolizaNavigation?.NumeroPolizaSuplementoLargo;
|
|
Compañia = Recibo.idPolizaNavigation?.idCompaniaNavigation?.Nombre;
|
|
Tomador = Recibo.idPolizaNavigation?.Tomador?.RazonSocial;
|
|
Teléfono = Recibo.idPolizaNavigation?.Tomador?.Telefono1;
|
|
FechaEfecto = Recibo.FechaEfecto;
|
|
PrimaBruta = Recibo.TotalRecibo ?? 0;
|
|
TipoPago = Recibo.TipoPago;
|
|
IBAN = Recibo.IBAN;
|
|
Remesado = Recibo.idRemesa.HasValue ? "SI" : "NO";
|
|
}
|
|
|
|
public string NumeroRecibo { get; set; }
|
|
public DateOnly? FechaExpedicion { get; set; }
|
|
public string NumeroPoliza { get; set; }
|
|
public string Compañia { get; set; }
|
|
public string Tomador { get; set; }
|
|
public string Teléfono { get; set; }
|
|
public DateOnly? FechaEfecto { get; set; }
|
|
public double PrimaBruta { get; set; }
|
|
public string TipoPago { get; set; }
|
|
public string IBAN { get; set; }
|
|
public string Remesado { get; set; }
|
|
}
|
|
|
|
public class ListadoRecibosIncorporados
|
|
{
|
|
public ListadoRecibosIncorporados() { }
|
|
public ListadoRecibosIncorporados(ReciboAIncorporar Rai)
|
|
{
|
|
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;
|
|
}
|
|
public string Código_Recibo { get; set; }
|
|
public string Código_Compañía { get; set; }
|
|
public string Número_Póliza { get; set; }
|
|
public string Tipo { get; set; }
|
|
public DateOnly Fecha_Efecto { get; set; }
|
|
public DateOnly Fecha_Vencimiento { get; set; }
|
|
public bool Corregible { get; set; }
|
|
public string Mensaje { get; set; }
|
|
public string Tomador { get; set; }
|
|
public string Matrícula { get; set; }
|
|
public string Bienes_Asegurados { get; set; }
|
|
public string Agente { get; set; }
|
|
public string Subagente { get; set; }
|
|
public string Ramo { get; set; }
|
|
public string IBAN { get; set; }
|
|
public double Total_Recibo { get; set; }
|
|
public double? Comisión { get; set; }
|
|
public double? Sobrecomisión { get; set; }
|
|
public double? Comisión_Prevista_Agente { get; set; }
|
|
public double? Comisión_Prevista_ASEGASA { get; set; }
|
|
public double? Diferencia_Comisión { get; set; }
|
|
public int Número_Fichero { get; set; }
|
|
}
|
|
|
|
public class ReciboAIncorporar
|
|
{
|
|
public polizassg Poliza { get; set; }
|
|
public int idTipoRecibo { get; set; }
|
|
public string Código_Recibo { get; set; }
|
|
public string Código_Cia { get; set; }
|
|
public string Número_Póliza { get; set; }
|
|
public string Tipo { get; set; }
|
|
public DateOnly Fecha_Efecto { get; set; }
|
|
public DateOnly Fecha_Vencimiento { get; set; }
|
|
public bool Actualizado { get; set; }
|
|
public bool PagadoEnCia { get; set; }
|
|
public bool Correcto { get; set; }
|
|
public bool Corregible { get; set; }
|
|
public string Mensaje { get; set; }
|
|
public string Tomador { get; set; }
|
|
public string Matrícula { get; set; }
|
|
public string Bienes_Asegurados { get; set; }
|
|
public string Agente { get; set; }
|
|
public string Subagente { get; set; }
|
|
public string Ramo { get; set; }
|
|
public string IBAN { get; set; }
|
|
public double Consorcio { get; set; }
|
|
public double Total_Recibo { get; set; }
|
|
public double? Comisión { get; set; }
|
|
public double Sobrecomisión { get; set; }
|
|
public double? Comisión_Prevista_Agente { get; set; }
|
|
public double? Comisión_Prevista_ASEGASA { get; set; }
|
|
public double? Diferencia_Comisión { get; set; }
|
|
public int Número_Fichero { get; set; }
|
|
public DateOnly Fecha_Fichero { get; set; }
|
|
public DateOnly? Fecha_Procesado { get; set; }
|
|
public int idFicheroCompania { get; set; }
|
|
public bool Gestionado_Por_Cia { get; set; }
|
|
public bool Es_Produccion { get; set; }
|
|
public double Prima_Neta { get; set; }
|
|
}
|
|
|
|
public class DatoComision
|
|
{
|
|
public string Concepto { get; set; }
|
|
public double Base { get; set; }
|
|
public double Porcentaje { get; set; }
|
|
public double ComisionBruta { get; set; }
|
|
public double Sobrecomision { get; set; }
|
|
public double TotalComision { get; set; }
|
|
public double PorcentajeComisionPrevista { get; set; }
|
|
public double ComisionPrevista { get; set; }
|
|
public double Diferencia { get; set; }
|
|
}
|
|
|
|
public class ReciboReducido
|
|
{
|
|
public static List<ReciboReducido> ListadoReciboReducido(IQueryable<recibos> iqRecibos)
|
|
{
|
|
return iqRecibos.Select(x => new ReciboReducido
|
|
{
|
|
idRecibo = x.idRecibo,
|
|
CodigoRecibo = x.CodigoRecibo,
|
|
NumeroRecibo = x.NumeroRecibo,
|
|
idPoliza = x.idPoliza,
|
|
NumeroPoliza = x.idPolizaNavigation.NumeroPoliza,
|
|
NumeroSuplemento = x.idPolizaNavigation.NumeroSuplemento,
|
|
FechaEfecto = x.FechaEfecto,
|
|
FechaVencimiento = x.FechaVencimiento,
|
|
FechaBaja = x.FechaBaja,
|
|
idCausaBaja = x.idCausaBaja,
|
|
FechaFacturacion = x.FechaFacturacion,
|
|
idTipoPago = x.idTipoPago,
|
|
FechaPago = x.FechaPago
|
|
}).ToList();
|
|
}
|
|
|
|
public ReciboReducido() { }
|
|
|
|
public ReciboReducido(recibos Recibo)
|
|
{
|
|
idRecibo = Recibo.idRecibo;
|
|
CodigoRecibo = Recibo.CodigoRecibo;
|
|
NumeroRecibo = Recibo.NumeroRecibo;
|
|
idPoliza = Recibo.idPoliza;
|
|
if (Recibo.idPolizaNavigation != null)
|
|
{
|
|
NumeroPoliza = Recibo.idPolizaNavigation.NumeroPoliza;
|
|
NumeroSuplemento = Recibo.idPolizaNavigation.NumeroSuplemento;
|
|
}
|
|
FechaEfecto = Recibo.FechaEfecto;
|
|
FechaVencimiento = Recibo.FechaVencimiento;
|
|
FechaBaja = Recibo.FechaBaja;
|
|
FechaFacturacion = Recibo.FechaFacturacion;
|
|
FechaPago = Recibo.FechaPago;
|
|
idTipoPago = Recibo.idTipoPago;
|
|
idCausaBaja = Recibo.idCausaBaja;
|
|
}
|
|
|
|
public int idRecibo { get; set; }
|
|
public string CodigoRecibo { get; set; }
|
|
public string NumeroRecibo { get; set; }
|
|
public int? idPoliza { get; set; }
|
|
public string NumeroPoliza { get; set; }
|
|
public int? NumeroSuplemento { get; set; }
|
|
public DateOnly? FechaEfecto { get; set; }
|
|
public DateOnly? FechaVencimiento { get; set; }
|
|
public DateOnly? FechaFacturacion { get; set; }
|
|
public int? idCausaBaja { get; set; }
|
|
public DateOnly? FechaBaja { get; set; }
|
|
public DateOnly? FechaPago { get; set; }
|
|
public int? idTipoPago { get; set; }
|
|
}
|
|
|
|
public class ListadoDevueltos
|
|
{
|
|
public ListadoDevueltos(recibos Recibo)
|
|
{
|
|
NumeroRecibo = Recibo.NumeroRecibo;
|
|
NumeroPoliza = Recibo.idPolizaNavigation?.NumeroPolizaSuplementoLargo;
|
|
Compañia = Recibo.idPolizaNavigation?.idCompaniaNavigation?.Nombre;
|
|
Tomador = Recibo.idPolizaNavigation?.Tomador?.RazonSocial;
|
|
Teléfono = Recibo.idPolizaNavigation?.Tomador?.Telefono1;
|
|
FechaEfecto = Recibo.FechaEfecto;
|
|
PrimaBruta = Recibo.TotalRecibo ?? 0;
|
|
TipoPago = Recibo.TipoPago;
|
|
IBAN = Recibo.IBAN;
|
|
FechaDevolucion = Recibo.FechaDevolucionBanco;
|
|
CausaDevolucion = Recibo.CausaDevolucion;
|
|
}
|
|
|
|
public string NumeroRecibo { get; set; }
|
|
public string NumeroPoliza { get; set; }
|
|
public string Compañia { get; set; }
|
|
public string Tomador { get; set; }
|
|
public string Teléfono { get; set; }
|
|
public DateOnly? FechaEfecto { get; set; }
|
|
public double PrimaBruta { get; set; }
|
|
public string TipoPago { get; set; }
|
|
public string IBAN { get; set; }
|
|
public DateOnly? FechaDevolucion { get; set; }
|
|
public string CausaDevolucion { get; set; }
|
|
}
|
|
|
|
public class ListadoBajas
|
|
{
|
|
public ListadoBajas(recibos Recibo)
|
|
{
|
|
NumeroRecibo = Recibo.NumeroRecibo;
|
|
NumeroPoliza = Recibo.idPolizaNavigation?.NumeroPolizaSuplementoLargo;
|
|
Compañia = Recibo.idPolizaNavigation?.idCompaniaNavigation?.Nombre;
|
|
Tomador = Recibo.idPolizaNavigation?.Tomador?.RazonSocial;
|
|
Teléfono = Recibo.idPolizaNavigation?.Tomador?.Telefono1;
|
|
FechaEfecto = Recibo.FechaEfecto;
|
|
PrimaBruta = Recibo.TotalRecibo ?? 0;
|
|
TipoPago = Recibo.TipoPago;
|
|
IBAN = Recibo.IBAN;
|
|
FechaBaja = Recibo.FechaBaja;
|
|
CausaBaja = Recibo.CausaBaja;
|
|
|
|
PosibleFechaAnulacion = Recibo.FechaBaja;
|
|
if (PosibleFechaAnulacion.HasValue)
|
|
{
|
|
if (PosibleFechaAnulacion.Value.Day > 22)
|
|
{
|
|
if (PosibleFechaAnulacion.Value.Month == 12)
|
|
{
|
|
PosibleFechaAnulacion = new DateOnly(PosibleFechaAnulacion.Value.Year + 1, 1, 22);
|
|
}
|
|
else
|
|
{
|
|
PosibleFechaAnulacion = new DateOnly(PosibleFechaAnulacion.Value.Year, PosibleFechaAnulacion.Value.Month + 1, 22);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PosibleFechaAnulacion = new DateOnly(PosibleFechaAnulacion.Value.Year, PosibleFechaAnulacion.Value.Month, 22);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string NumeroRecibo { get; set; }
|
|
public string NumeroPoliza { get; set; }
|
|
public string Compañia { get; set; }
|
|
public string Tomador { get; set; }
|
|
public string Teléfono { get; set; }
|
|
public DateOnly? FechaEfecto { get; set; }
|
|
public double PrimaBruta { get; set; }
|
|
public string TipoPago { get; set; }
|
|
public string IBAN { get; set; }
|
|
public DateOnly? FechaBaja { get; set; }
|
|
public string CausaBaja { get; set; }
|
|
public DateOnly? PosibleFechaAnulacion { get; set; }
|
|
}
|
|
|
|
public class ListadoAsegurados
|
|
{
|
|
public ListadoAsegurados(recibos Recibo)
|
|
{
|
|
NumeroPropuesta = Recibo.idPoliza;
|
|
NumeroPoliza = Recibo.idPolizaNavigation?.NumeroPolizaSuplementoLargo;
|
|
NumeroRecibo = Recibo.NumeroRecibo;
|
|
CIFTomador = Recibo.idPolizaNavigation?.Tomador?.CIF;
|
|
Tomador = Recibo.idPolizaNavigation?.Tomador?.RazonSocial;
|
|
Compañia = Recibo.idPolizaNavigation?.idCompaniaNavigation?.Nombre;
|
|
Agente = Recibo.idAgenteNavigation?.Nombre;
|
|
SubAgente = Recibo.idSubagenteNavigation?.Nombre;
|
|
Ramo = Recibo.idPolizaNavigation?.idRamoNavigation?.Descripcion;
|
|
FechaEfecto = Recibo.FechaEfecto;
|
|
Teléfono1 = Recibo.idPolizaNavigation?.Tomador?.Telefono1;
|
|
Teléfono2 = Recibo.idPolizaNavigation?.Tomador?.Telefono2;
|
|
Email = Recibo.idPolizaNavigation?.EmailTomador;
|
|
BienesAsegurados = Recibo.idPolizaNavigation?.BienesAsegurados;
|
|
Matricula = Recibo.idPolizaNavigation?.Matricula;
|
|
}
|
|
|
|
public ListadoAsegurados(vf_recibosextendidos Recibo)
|
|
{
|
|
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;
|
|
}
|
|
|
|
public int? NumeroPropuesta { get; set; }
|
|
public string NumeroPoliza { get; set; }
|
|
public string NumeroRecibo { get; set; }
|
|
public string CIFTomador { get; set; }
|
|
public string Tomador { get; set; }
|
|
public string Compañia { get; set; }
|
|
public string Agente { get; set; }
|
|
public string SubAgente { get; set; }
|
|
public string Ramo { get; set; }
|
|
public DateOnly? FechaEfecto { get; set; }
|
|
public string Teléfono1 { get; set; }
|
|
public string Teléfono2 { get; set; }
|
|
public string Email { get; set; }
|
|
public string BienesAsegurados { get; set; }
|
|
public string Matricula { get; set; }
|
|
}
|
|
}
|