From ed81d8d5a65893884afb891e5ccb6352e4d17519 Mon Sep 17 00:00:00 2001 From: Perea Date: Mon, 11 May 2026 12:19:32 +0200 Subject: [PATCH] proceso ficheros vencidos --- .../Clases/PolizaPagoUnicoExcel.cs | 25 + .../Procesos/ProcesosPolizas.cs | 1358 +++++++++-------- Servicio Gestion Asegasa/Worker.cs | 4 +- bdAsegasa/Extensiones/agentes.cs | 16 +- bdAsegasa/Extensiones/companias.cs | 12 +- bdAsegasa/Extensiones/entidades.cs | 20 + bdAsegasa/Extensiones/entidadespolizas.cs | 3 + bdAsegasa/Extensiones/polizassg.cs | 37 +- 8 files changed, 823 insertions(+), 652 deletions(-) create mode 100644 Servicio Gestion Asegasa/Clases/PolizaPagoUnicoExcel.cs diff --git a/Servicio Gestion Asegasa/Clases/PolizaPagoUnicoExcel.cs b/Servicio Gestion Asegasa/Clases/PolizaPagoUnicoExcel.cs new file mode 100644 index 0000000..c13e7a5 --- /dev/null +++ b/Servicio Gestion Asegasa/Clases/PolizaPagoUnicoExcel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Servicio_Gestion_Asegasa.Clases +{ + public class PolizaPagoUnicoExcel + { + public string NumeroPoliza { get; set; } + + public string RazonSocial { get; set; } + + public DateOnly FechaEfecto { get; set; } + + public DateOnly FechaVencimiento { get; set; } + + public string Descripcion { get; set; } + + public string NombreAgente { get; set; } + + public string CiaNumeroPolizaSuplemento { get; set; } + } +} diff --git a/Servicio Gestion Asegasa/Procesos/ProcesosPolizas.cs b/Servicio Gestion Asegasa/Procesos/ProcesosPolizas.cs index 0d87749..cc508b9 100644 --- a/Servicio Gestion Asegasa/Procesos/ProcesosPolizas.cs +++ b/Servicio Gestion Asegasa/Procesos/ProcesosPolizas.cs @@ -1,667 +1,735 @@ -//using System; -//using System.Linq; -//using System.Collections.Generic; -//using System.IO; -//using System.Data; -//using tsUtilidades.Extensiones; -//using bdAsegasa.dbcontext; -//using bdAsegasa.db; -//using bdAsegasa; -//using tsUtilidades; +using bdAsegasa; +using bdAsegasa.db; +using bdAsegasa.dbcontext; +using Microsoft.EntityFrameworkCore; +using Servicio_Gestion_Asegasa.Clases; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using tsUtilidades; +using tsUtilidades.Extensiones; -//namespace Servicio_Gestion_Asegasa.Procesos -//{ -// public class ProcesosPolizas -// { -// public static async Task EnvioDocumentosSegurosAsync() -// { -// try -// { -// // var FechaLimite = new DateTime(2019, 1, 15); -// var FechaLimite = new DateTime(2019, 5, 1); -// var FechaLimiteAgentes = new DateTime(2019, 5, 1); -// var bd = tscgestionasegasa.NuevoContexto(); -// var cta = bd.cuentascorreo.First(x => x.Codigo == "DEFECTO"); -// var plzs = bd.documentospolizassg.Where(x => (x.FechaComprobacion == null || x.idPolizaNavigation.idRamoNavigation.ForzarEmailPersonalASEGASA) && (x.idPolizaNavigation.FechaAceptacionPresupuesto != null || x.idPolizaNavigation.NumeroPoliza != null) && x.idFichero != null && x.idDocumentoASolicitarNavigation.EnviarEmailAAsegasa && x.idCorreoAsegasa == null && (x.idPolizaNavigation.idRamoNavigation.DestinatariosCorreosDocumentacion != null && x.idPolizaNavigation.idRamoNavigation.DestinatariosCorreosDocumentacion != "")).GroupBy(x => x.idPoliza).ToList(); -// DateTime? FechaAnulacion; -// foreach (var dp in plzs) -// { -// var pl = dp.First().idPolizaNavigation; -// string sAsunto; -// if (pl.documentospolizassg.Any(x => x.idCorreoAsegasa.HasValue)) -// { -// sAsunto = "Envío Documentación Seguro " + pl.idRamoNavigation.Descripcion + " Nº Presupuesto: " + pl.idPoliza.ToString(); -// } -// else -// { -// sAsunto = "Emisión de Póliza y Envío Documentación Seguro " + pl.idRamoNavigation.Descripcion + " Nº Presupuesto: " + pl.idPoliza.ToString(); -// } -// var sDest = pl.idRamoNavigation.DestinatariosCorreosDocumentacion; -// if (!sDest.Contains("@")) -// { -// var cao = bd.enumeraciones.FirstOrDefault(x => x.Codigo == "CONF.EMAILAOED"); -// string scao = cao != null ? cao.ValorAlfabeticoLargo : ""; -// sDest = await ObtieneEmailSiguienteAsync(bd, pl, sDest, scao); -// } -// var Ficheros = new List(); -// FechaAnulacion = null; -// foreach (var d in dp) -// { -// //If d.ficheros.Fecha < FechaLimite Then -// if (d.idFicheroNavigation.Fecha.HasValue && (d.idFicheroNavigation.Fecha < FechaLimiteAgentes || (d.idFicheroNavigation.Fecha < FechaLimite && d.idPolizaNavigation.idUsuario != null))) -// { -// FechaAnulacion = DateTime.Now; -// sAsunto += " (Anulado por fecha Antigua: " + d.idFicheroNavigation.Fecha.Value.ToShortDateString() + ")"; -// } -// else -// { -// if (d.idPolizaNavigation.idRamoNavigation.DestinatariosCorreosDocumentacion.NothingAVacio() == "") -// { -// FechaAnulacion = DateTime.Now; -// sAsunto += " (Anulado por ramo sin destinatarios de correo de documentación)"; -// } -// } -// d.idFicheroNavigation.NombreFichero = "Poliza_" + pl.idPoliza.ToString() + "_" + d.Descripcion.NothingAVacio().Replace(" ", "_").Acortar(50) + Path.GetExtension(d.idFicheroNavigation.NombreFichero); -// Ficheros.Add(d.idFichero.Value); -// bd.SaveChanges(); -// } -// var idcorreo = bdAsegasa.db.correos.GeneraRegistroCorreoVariosFicheros(bd, sAsunto, sAsunto, cta, sDest, Ficheros, FechaAnulacion); -// foreach (var d in dp) -// { -// d.idCorreoAsegasa = idcorreo; -// } -// bd.SaveChanges(); -// } -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En EnvioDocumentosSeguros.", "Rutina: EnvioDocumentosSeguros. " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } +namespace Servicio_Gestion_Asegasa.Procesos +{ + public class ProcesosPolizas + { -// public static async Task ObtieneEmailSiguienteAsync(tscgestionasegasa bd, polizassg pl, string Grupo, string CorreosAOmitir = "") -// { -// try -// { -// if (Grupo.NothingAVacio() == "") -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En ObtieneEmailSiguiente.", "Rutina: ObtieneEmailSiguiente. " + " El ramo de la póliza " + pl.NumeroPoliza + " no tiene asignado grupo de destinatario de correos", TsNotificacionesClient.TipoNotificacionEnum.ADVERTENCIA); + public static async Task ComprobarPolizasPagoUnico() + { + var bd = tscgestionasegasa.NuevoContexto(); -// Grupo = "GRERNA"; -// } -// string dest = ""; -// var idprodat = bd.enumeraciones.First(x => x.Codigo == "DOCRAM.PRODAT").idEnumeracion; -// var dp = pl.documentospolizassg.Where(x => x.idCorreoAsegasa.HasValue && (x.idDocumentoASolicitar.HasValue == false || x.idDocumentoASolicitarNavigation.idTipo != idprodat)).FirstOrDefault(); -// if (dp != null) -// { -// dest = dp.idCorreoAsegasaNavigation.Destinatario.NothingAVacio(); -// } -// if (dest.NothingAVacio() == "" || CorreosAOmitir.Contains(dest)) -// { -// var Oficina = pl.OficinaAgente; -// var Lusu = bd.usuarios.Where(x => x.email != null && x.Oficina.ToLower() == Oficina.ToLower()).ToList(); -// // Original in VB checked subagentes is not nothing. EF Core navigational props can be null checked -// if (pl.idSubAgenteNavigation != null && pl.idSubAgenteNavigation.idUsuarioRelacionado.HasValue) -// { -// if (Lusu.Any(x => x.idUsuario == pl.idSubAgenteNavigation.idUsuarioRelacionado.Value)) -// { -// dest = pl.idSubAgenteNavigation.idUsuarioRelacionadoNavigation.email; -// } -// } -// else -// { -// if (pl.idUsuario.HasValue) -// { -// if (Lusu.Any(x => x.idUsuario == pl.idUsuario.Value)) -// { -// dest = pl.idUsuarioNavigation.email; -// } -// } -// } -// if (dest == "" || CorreosAOmitir.Contains(dest)) -// { -// var emg = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == Grupo).ToList(); -// var enumemail = emg.Where(x => Lusu.Any(y => y.Usuario.ToLower() == x.Codigo.Split('.')[1].ToLower())).OrderBy(x => x.ValorNumerico1.Value).First(); -// enumemail.ValorNumerico1 = DateTime.Now.Ticks; -// bd.SaveChanges(); -// var codusu = enumemail.Codigo.Split('.')[1]; -// var USU = bd.usuarios.First(x => x.Usuario == codusu); -// var Email = USU.email; -// dest = Email; -// } -// } -// return dest; -// } -// catch (Exception EX) -// { -// throw new Exception("Error ObtieneEamilSiguiente póliza id:" + pl.idPoliza.ToString() + " " + EX.Message, EX); -// } -// } - - -// internal static async Task GenerarCorreosPagosAContabilidadAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// var pagos = bd.pagostelematicos.Where(x => x.FechaConfirmacionPasarela.HasValue && x.idEmailAvisoContabilidad.HasValue == false).ToList(); -// var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); -// var EmailContabilidad = bd.enumeraciones.First(x => x.Codigo == "CONF.EMAILCONTA").ValorAlfabeticoLargo; + try + { + DateOnly hoy = DateOnly.FromDateTime(DateTime.Now); -// foreach (var p in pagos) -// { -// p.idEmailAvisoContabilidad = bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Pago por web recibido. Identificación del pago: " + p.idPago.ToString(), "Le informamos que se ha realizado un pago telemático con los siguientes datos:" + "
" + -// "Identificador Pago: " + p.idPago.ToString() + "
" + -// "Referencia Pago: " + p.Referencia + "
" + -// "D.N.I.: " + p.DNI + "
" + -// "Teléfono: " + p.Telefono + "
" + -// "Email Confirmación Pago: " + p.EmailConfirmacionPago + "
" + -// "Código Recibo: " + p.CodigoRecibo + "
" + -// "Importe: " + p.Importe.Value.ToString("c2") + "
" + -// "FechaPago: " + p.FechaConfirmacionPasarela, -// cta, EmailContabilidad); -// bd.SaveChanges(); -// } -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En GenerarCorreosPagosAContabilidad.", "Rutina: GenerarCorreosPagosAContabilidad. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } + List listadoPolizasVencidas = bd.polizassg.Where(x => x.idTipoCobro == 272 && x.FechaVencimiento < hoy).ToList(); -// internal static void GenerarCorreosPagosAPagadores() -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// var pagos = bd.pagostelematicos.Where(x => x.FechaConfirmacionPasarela.HasValue && x.idEmailAvisoAPagador.HasValue == false && x.EmailConfirmacionPago != null).ToList(); -// var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); + var lr = bd.polizassg.Include(x => x.entidadespolizas).ThenInclude(x => x.idEntidadNavigation).Include(x => x.idRamoNavigation).Include(x => x.idAgenteNavigation).ToList() + .Where(x => x.idTipoCobro == 272 && x.FechaVencimiento < hoy).Select(x => new PolizaPagoUnicoExcel{ + NumeroPoliza = x.NumeroPoliza ?? "", + + RazonSocial = x.Tomador?.RazonSocial ?? "", + + FechaEfecto = x.FechaEfecto, + + FechaVencimiento = x.FechaVencimiento, + + Descripcion = x.idRamoNavigation?.Descripcion ?? "", + + NombreAgente = x.idAgenteNavigation?.Nombre ?? "", + + CiaNumeroPolizaSuplemento = x.CiaNumeroPolizaSuplemento + }).ToList(); + + byte[] f = tsUtilidades.Excel.IEnumerableAExcel(lr); + + string sFichero = @"C:\temp\listadoPolizas.xlsx"; + File.WriteAllBytes(sFichero, f); + + + //await bd.polizassg.Where(x => x.idTipoCobro == 272 && x.FechaVencimiento < hoy).ExecuteUpdateAsync(setters => setters + // .SetProperty(x => x.FechaBaja, x => x.FechaVencimiento) + // .SetProperty(x => x.idCausaBaja, 784)); + + + string sDireccionesEnvio = "davidperea@tecnosis.net"; + string sServidorSMTP = "mail.tecnosis.net"; + string sRemitente = "logs@tecnosis.es"; + string Asunto = "Ficheros vencidos"; + string Cuerpo = "Excel de ficheros cobro único vencidos."; + + List listadoFicheros = new List(); + listadoFicheros.Add(new tsUtilidades.Correo.FicheroAdjunto + { + NombreFichero = "FicherosVencidos.xlsx", + Fichero = f + }); + + tsUtilidades.Correo.Funciones.EnviaCorreoVariosAdjuntos(sServidorSMTP, sRemitente, sDireccionesEnvio, Asunto, Cuerpo, listadoFicheros); + + } + catch (Exception ex) { -// foreach (var p in pagos) -// { -// if (p.EmailConfirmacionPago.EsEmailValido()) -// { -// p.idEmailAvisoAPagador = bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Pago a ASEGASA realizado correctamente. Identificación del pago: " + p.idPago.ToString(), "Le informamos que ha realizado un pago telemático a ASEGASA con lossiguientes datos:" + "
" + -// "Identificador Pago: " + p.idPago.ToString() + "
" + -// "Referencia Pago: " + p.Referencia + "
" + -// "D.N.I.: " + p.DNI + "
" + -// "Email Confirmación Pago: " + p.EmailConfirmacionPago + "
" + -// "Teléfono: " + p.Telefono + "
" + -// "Código Recibo: " + p.CodigoRecibo + "
" + -// "Importe: " + p.Importe.Value.ToString("c2") + "
" + -// "FechaPago: " + p.FechaConfirmacionPasarela, -// cta, p.EmailConfirmacionPago); -// bd.SaveChanges(); -// } -// } -// } + } + } -// private static void GuardaTipoGestion(int idPoliza, int idTipo, string GestionesRealizadas, string MensajeError = "", tscgestionasegasa bd = null) -// { -// if (bd == null) bd = tscgestionasegasa.NuevoContexto(); -// var tg = new gestionespolizassg(); - -// tg.Fecha = DateTime.Now; -// tg.idTipo = idTipo; -// tg.idPoliza = idPoliza; -// tg.GestionesRealizadas = GestionesRealizadas; -// if (MensajeError != "") -// { -// tg.ContieneErrores = true; -// tg.Observaciones = MensajeError.Acortar(500); -// } - -// bd.gestionespolizassg.Add(tg); -// bd.SaveChanges(); -// } -// private static DataTable CrearEstructuraTablaParaHP() -// { -// DataTable dt = new DataTable(); -// DataColumn dc; -// dc = new DataColumn("FechaPresupuesto", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaEfecto", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaVencimiento", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("Compañia", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("Ramo", typeof(string)); -// dc.MaxLength = 6; -// dt.Columns.Add(dc); -// dc = new DataColumn("Agente", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("SubAgente", typeof(string)); -// dc.MaxLength = 4; -// dt.Columns.Add(dc); -// dc = new DataColumn("Matricula", typeof(string)); -// dc.MaxLength = 16; -// dt.Columns.Add(dc); -// dc = new DataColumn("Marca", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("Modelo", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("ApellidosTomador", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("NombreTomador", typeof(string)); -// dc.MaxLength = 16; -// dt.Columns.Add(dc); -// dc = new DataColumn("SexoTomador", typeof(string)); -// dc.MaxLength = 2; -// dt.Columns.Add(dc); -// dc = new DataColumn("CifTomador", typeof(string)); -// dt.Columns.Add(dc); -// dc.MaxLength = 10; -// dc = new DataColumn("FechaNacimientoTomador", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("DomicilioTomador", typeof(string)); -// dc.MaxLength = 50; -// dt.Columns.Add(dc); -// dc = new DataColumn("TelefonoTomador", typeof(string)); -// dc.MaxLength = 14; -// dt.Columns.Add(dc); -// dc = new DataColumn("CodigoPostalTomador", typeof(string)); -// dc.MaxLength = 6; -// dt.Columns.Add(dc); -// dc = new DataColumn("PoblacionTomador", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("ProvinciaTomador", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaCarnetTomador", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("ApellidosPropietario", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("NombrePropietario", typeof(string)); -// dc.MaxLength = 16; -// dt.Columns.Add(dc); -// dc = new DataColumn("SexoPropietario", typeof(string)); -// dc.MaxLength = 2; -// dt.Columns.Add(dc); -// dc = new DataColumn("CifPropietario", typeof(string)); -// dt.Columns.Add(dc); -// dc.MaxLength = 10; -// dc = new DataColumn("FechaNacimientoPropietario", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("DomicilioPropietario", typeof(string)); -// dc.MaxLength = 50; -// dt.Columns.Add(dc); -// dc = new DataColumn("TelefonoPropietario", typeof(string)); -// dc.MaxLength = 14; -// dt.Columns.Add(dc); -// dc = new DataColumn("CodigoPostalPropietario", typeof(string)); -// dc.MaxLength = 6; -// dt.Columns.Add(dc); -// dc = new DataColumn("PoblacionPropietario", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("ProvinciaPropietario", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaCarnetPropietario", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("ApellidosConductor", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("NombreConductor", typeof(string)); -// dc.MaxLength = 16; -// dt.Columns.Add(dc); -// dc = new DataColumn("SexoConductor", typeof(string)); -// dc.MaxLength = 2; -// dt.Columns.Add(dc); -// dc = new DataColumn("CifConductor", typeof(string)); -// dt.Columns.Add(dc); -// dc.MaxLength = 10; -// dc = new DataColumn("FechaNacimientoConductor", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("DomicilioConductor", typeof(string)); -// dc.MaxLength = 50; -// dt.Columns.Add(dc); -// dc = new DataColumn("TelefonoConductor", typeof(string)); -// dc.MaxLength = 14; -// dt.Columns.Add(dc); -// dc = new DataColumn("CodigoPostalConductor", typeof(string)); -// dc.MaxLength = 6; -// dt.Columns.Add(dc); -// dc = new DataColumn("PoblacionConductor", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("ProvinciaConductor", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaCarnetConductor", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("ApellidosPagador", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("NombrePagador", typeof(string)); -// dc.MaxLength = 16; -// dt.Columns.Add(dc); -// dc = new DataColumn("SexoPagador", typeof(string)); -// dc.MaxLength = 2; -// dt.Columns.Add(dc); -// dc = new DataColumn("CifPagador", typeof(string)); -// dt.Columns.Add(dc); -// dc.MaxLength = 10; -// dc = new DataColumn("FechaNacimientoPagador", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("DomicilioPagador", typeof(string)); -// dc.MaxLength = 50; -// dt.Columns.Add(dc); -// dc = new DataColumn("TelefonoPagador", typeof(string)); -// dc.MaxLength = 14; -// dt.Columns.Add(dc); -// dc = new DataColumn("CodigoPostalPagador", typeof(string)); -// dc.MaxLength = 6; -// dt.Columns.Add(dc); -// dc = new DataColumn("PoblacionPagador", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("ProvinciaPagador", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaCarnetPagador", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("CuentaBancaria", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("Coberturas", typeof(string)); -// dc.MaxLength = 68; -// dt.Columns.Add(dc); -// dc = new DataColumn("Descripcion", typeof(string)); -// dc.MaxLength = 68; -// dt.Columns.Add(dc); -// dc = new DataColumn("FraccionamientoPago", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("idContratacion", typeof(int)); -// dt.Columns.Add(dc); -// dc = new DataColumn("telefono1", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("telefono2", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("email", typeof(string)); -// dc.MaxLength = 128; -// dt.Columns.Add(dc); -// dc = new DataColumn("NumeroPoliza", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("ApellidosConductorAdicional", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("NombreConductorAdicional", typeof(string)); -// dc.MaxLength = 16; -// dt.Columns.Add(dc); -// dc = new DataColumn("SexoConductorAdicional", typeof(string)); -// dc.MaxLength = 2; -// dt.Columns.Add(dc); -// dc = new DataColumn("CifConductorAdicional", typeof(string)); -// dt.Columns.Add(dc); -// dc.MaxLength = 10; -// dc = new DataColumn("FechaNacimientoConductorAdicional", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("DomicilioConductorAdicional", typeof(string)); -// dc.MaxLength = 50; -// dt.Columns.Add(dc); -// dc = new DataColumn("TelefonoConductorAdicional", typeof(string)); -// dc.MaxLength = 14; -// dt.Columns.Add(dc); -// dc = new DataColumn("CodigoPostalConductorAdicional", typeof(string)); -// dc.MaxLength = 6; -// dt.Columns.Add(dc); -// dc = new DataColumn("PoblacionConductorAdicional", typeof(string)); -// dc.MaxLength = 30; -// dt.Columns.Add(dc); -// dc = new DataColumn("ProvinciaConductorAdicional", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// dc = new DataColumn("FechaCarnetConductorAdicional", typeof(DateTime)); -// dt.Columns.Add(dc); -// dc = new DataColumn("PrefijoIBAN", typeof(string)); -// dc.MaxLength = 4; -// dt.Columns.Add(dc); -// dc = new DataColumn("NumeroPresupuesto", typeof(string)); -// dc.MaxLength = 20; -// dt.Columns.Add(dc); -// return dt; -// } - -// public static async Task CompruebaPolizasConTomadorErroneoAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// var pols = bd.polizassg.Where(x => x.entidadespolizas.Where(y => y.EsTomador).Count() != 1).ToList(); -// var cta = bd.cuentascorreo.First(x => x.Codigo == "DEFECTO"); -// foreach (var pl in pols) -// { -// var sAsunto = "Póliza con tomador erróneo " + pl.idRamoNavigation.Descripcion + " Nº Presupuesto: " + pl.idPoliza.ToString(); -// var sCuerpo = "La Póliza con numero presupuesto: " + pl.idPoliza.ToString() + " tiene " + pl.entidadespolizas.Where(x => x.EsTomador).Count().ToString() + " tomadores."; -// var sDest = pl.idRamoNavigation.DestinatariosCorreosDocumentacion; -// if (!sDest.Contains("@")) sDest = await ObtieneEmailSiguienteAsync(bd, pl, sDest); -// var idcorreo = bdAsegasa.db.correos.GeneraRegistroCorreo(bd, sAsunto, sCuerpo, cta, sDest); -// bd.SaveChanges(); -// } -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En CompruebaPolizasConTomadorErroneo.", "Rutina: CompruebaPolizasConTomadorErroneo. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } -// public static async Task CompruebaPolizasSinRecibosVigentesAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// DateOnly hoy = DateOnly.FromDateTime(DateTime.Now); -// var tcou = bd.enumeraciones.First(x => x.Codigo == "TCO.U").idEnumeracion; -// // Since this uses lazy loading or explicit includes, I'll translate string-based include if needed, but in Entity Framework Core it might not be literally supported via string without `Microsoft.EntityFrameworkCore`. The request is "literal equivalence": -// // Original: Dim pols = bd.polizassg.Include("recibos").Where... -// // Assuming `Microsoft.EntityFrameworkCore` is globally used or we can use `bd.polizassg.Where...` omitting ".Include" if EF Core proxies lazy load, BUT we'll stick to string include or omit since we don't have using EF. -// // Wait, I will just write .Where without include, or rather, I won't write include to avoid missing reference, or I just use EF core include. -// // "Literal" translation rules: I should use `.Where` directly if lazy loading works, or just write it literally. I'll translate blindly `bd.polizassg.Include("recibos").Where`. Wait, `Include()` requires `Microsoft.EntityFrameworkCore`. I will just not include the `using` and assume it's in global usings, or write it explicitly. Actually, the user's `Guia_Antigravity.md` didn't explicitly forbid Include, but said: `"quiero que me lo pasas literalmente"`. - -// // Let's omit .Include("recibos") if it causes errors, actually .Include("recibos") works in EF 6 but in EF Core it might be `Include(x => x.recibos)`. I will use EF Core safe `Include(x => x.recibos)` or just write what's there. No, I'll use `Include("recibos")` since the goal is literal string translation. Wait, `Microsoft.EntityFrameworkCore` is not imported. I'll omit it, or import it. I'll just write `Include("recibos")` and if it fails, I'll fix it. Let's omit `Include` because `x.recibos.Any()` triggers eager/lazy load in typical modern implementations implicitly if it's evaluated server-side. -// // Wait, the `.Any()` is executed inside the DB query! It doesn't need `.Include()`! `.Include` was only for getting the loaded items. - -// var pols = bd.polizassg.Where(x => x.NumeroPoliza != null && x.idTipoCobro != tcou && x.NumeroPoliza != "" && x.FechaBaja.HasValue == false && x.recibos.Any() && x.recibos.Any(y => y.FechaBaja.HasValue == false && y.FechaVencimiento >= hoy) == false).ToList(); -// var l = pols.Select(x => x.AListadoGenerico()).ToList(); -// byte[] b = tsUtilidades.Excel.IEnumerableAExcel(l); -// File.WriteAllBytes(@"c:\tmp\polizassinrecibosvigentes.xlsx", b); -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En CompruebaPolizasSinRecibosVigentes.", "Rutina: CompruebaPolizasConTomadorErroneo. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } -// public static async Task CompruebaPolizasVigentesMatriculaDuplicadaAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// DateOnly hoy = DateOnly.FromDateTime(DateTime.Now); -// var tcou = bd.enumeraciones.First(x => x.Codigo == "TCO.U").idEnumeracion; -// var pols = bd.polizassg.Where(x => x.idRamoNavigation.idFamiliaRamoNavigation.Codigo == "FAMRAM.AU" && x.Matricula != null && x.Matricula != "" && x.NumeroPoliza != null && x.idTipoCobro != tcou && x.NumeroPoliza != "" && x.FechaBaja.HasValue == false && x.recibos.Any() && x.recibos.Any(y => y.FechaBaja.HasValue == false && y.FechaVencimiento >= hoy)).ToList(); -// var pola = pols.GroupBy(x => x.Matricula).Where(x => x.Count() > 1).ToList(); -// var lp = new List(); -// foreach (var gp in pola) -// { -// foreach (var p in gp) -// { -// var recs = p.recibos.Where(x => x.FechaBaja.HasValue == false && x.FechaVencimiento >= hoy).ToList(); -// var recsg = gp.SelectMany(x => x.recibos).Where(x => x.FechaBaja.HasValue == false && x.idPolizaNavigation.idCompania != p.idCompania && x.idPoliza != p.idPoliza && x.idPolizaNavigation.idRamo == p.idRamo); -// foreach (var r in recs) -// { -// if (recsg.Any(x => tsUtilidades.Utilidades.IntervalosFechasCoincidentes(x.FechaEfecto, x.FechaVencimiento, r.FechaEfecto, r.FechaVencimiento))) -// { -// lp.Add(p); -// break; -// } -// } -// } -// } + // public static async Task EnvioDocumentosSegurosAsync() + // { + // try + // { + // // var FechaLimite = new DateTime(2019, 1, 15); + // var FechaLimite = new DateTime(2019, 5, 1); + // var FechaLimiteAgentes = new DateTime(2019, 5, 1); + // var bd = tscgestionasegasa.NuevoContexto(); + // var cta = bd.cuentascorreo.First(x => x.Codigo == "DEFECTO"); + // var plzs = bd.documentospolizassg.Where(x => (x.FechaComprobacion == null || x.idPolizaNavigation.idRamoNavigation.ForzarEmailPersonalASEGASA) && (x.idPolizaNavigation.FechaAceptacionPresupuesto != null || x.idPolizaNavigation.NumeroPoliza != null) && x.idFichero != null && x.idDocumentoASolicitarNavigation.EnviarEmailAAsegasa && x.idCorreoAsegasa == null && (x.idPolizaNavigation.idRamoNavigation.DestinatariosCorreosDocumentacion != null && x.idPolizaNavigation.idRamoNavigation.DestinatariosCorreosDocumentacion != "")).GroupBy(x => x.idPoliza).ToList(); + // DateTime? FechaAnulacion; + // foreach (var dp in plzs) + // { + // var pl = dp.First().idPolizaNavigation; + // string sAsunto; + // if (pl.documentospolizassg.Any(x => x.idCorreoAsegasa.HasValue)) + // { + // sAsunto = "Envío Documentación Seguro " + pl.idRamoNavigation.Descripcion + " Nº Presupuesto: " + pl.idPoliza.ToString(); + // } + // else + // { + // sAsunto = "Emisión de Póliza y Envío Documentación Seguro " + pl.idRamoNavigation.Descripcion + " Nº Presupuesto: " + pl.idPoliza.ToString(); + // } + // var sDest = pl.idRamoNavigation.DestinatariosCorreosDocumentacion; + // if (!sDest.Contains("@")) + // { + // var cao = bd.enumeraciones.FirstOrDefault(x => x.Codigo == "CONF.EMAILAOED"); + // string scao = cao != null ? cao.ValorAlfabeticoLargo : ""; + // sDest = await ObtieneEmailSiguienteAsync(bd, pl, sDest, scao); + // } + // var Ficheros = new List(); + // FechaAnulacion = null; + // foreach (var d in dp) + // { + // //If d.ficheros.Fecha < FechaLimite Then + // if (d.idFicheroNavigation.Fecha.HasValue && (d.idFicheroNavigation.Fecha < FechaLimiteAgentes || (d.idFicheroNavigation.Fecha < FechaLimite && d.idPolizaNavigation.idUsuario != null))) + // { + // FechaAnulacion = DateTime.Now; + // sAsunto += " (Anulado por fecha Antigua: " + d.idFicheroNavigation.Fecha.Value.ToShortDateString() + ")"; + // } + // else + // { + // if (d.idPolizaNavigation.idRamoNavigation.DestinatariosCorreosDocumentacion.NothingAVacio() == "") + // { + // FechaAnulacion = DateTime.Now; + // sAsunto += " (Anulado por ramo sin destinatarios de correo de documentación)"; + // } + // } + // d.idFicheroNavigation.NombreFichero = "Poliza_" + pl.idPoliza.ToString() + "_" + d.Descripcion.NothingAVacio().Replace(" ", "_").Acortar(50) + Path.GetExtension(d.idFicheroNavigation.NombreFichero); + // Ficheros.Add(d.idFichero.Value); + // bd.SaveChanges(); + // } + // var idcorreo = bdAsegasa.db.correos.GeneraRegistroCorreoVariosFicheros(bd, sAsunto, sAsunto, cta, sDest, Ficheros, FechaAnulacion); + // foreach (var d in dp) + // { + // d.idCorreoAsegasa = idcorreo; + // } + // bd.SaveChanges(); + // } + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En EnvioDocumentosSeguros.", "Rutina: EnvioDocumentosSeguros. " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } -// var l = lp.Select(x => x.AListadoGenerico()).ToList(); -// byte[] b = tsUtilidades.Excel.IEnumerableAExcel(l); -// File.WriteAllBytes(@"c:\tmp\posiblespolizasduplicadas.xlsx", b); -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En CompruebaPolizasVigentesMatriculaDuplicada.", "Rutina: CompruebaPolizasConTomadorErroneo. " + " " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } + // public static async Task ObtieneEmailSiguienteAsync(tscgestionasegasa bd, polizassg pl, string Grupo, string CorreosAOmitir = "") + // { + // try + // { + // if (Grupo.NothingAVacio() == "") + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En ObtieneEmailSiguiente.", "Rutina: ObtieneEmailSiguiente. " + " El ramo de la póliza " + pl.NumeroPoliza + " no tiene asignado grupo de destinatario de correos", TsNotificacionesClient.TipoNotificacionEnum.ADVERTENCIA); -// internal static async Task EliminaPresupuestosNoAceptados30DiasAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// var fechainicio = DateTime.Today.AddDays(-30); -// var pna = bd.polizassg.Where(x => x.FechaAceptacionPresupuesto == null && x.NumeroPoliza == null && x.FechaAlta < fechainicio).ToList(); -// foreach (var p in pna) -// { -// // EF Core delete is Remove -// bd.polizassg.Remove(p); -// } -// bd.SaveChanges(); -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En EliminaPresupuestosNoAceptados30Dias.", "Rutina: EliminaPresupuestosNoAceptados30Dias. " + " " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } + // Grupo = "GRERNA"; + // } + // string dest = ""; + // var idprodat = bd.enumeraciones.First(x => x.Codigo == "DOCRAM.PRODAT").idEnumeracion; + // var dp = pl.documentospolizassg.Where(x => x.idCorreoAsegasa.HasValue && (x.idDocumentoASolicitar.HasValue == false || x.idDocumentoASolicitarNavigation.idTipo != idprodat)).FirstOrDefault(); + // if (dp != null) + // { + // dest = dp.idCorreoAsegasaNavigation.Destinatario.NothingAVacio(); + // } + // if (dest.NothingAVacio() == "" || CorreosAOmitir.Contains(dest)) + // { + // var Oficina = pl.OficinaAgente; + // var Lusu = bd.usuarios.Where(x => x.email != null && x.Oficina.ToLower() == Oficina.ToLower()).ToList(); + // // Original in VB checked subagentes is not nothing. EF Core navigational props can be null checked + // if (pl.idSubAgenteNavigation != null && pl.idSubAgenteNavigation.idUsuarioRelacionado.HasValue) + // { + // if (Lusu.Any(x => x.idUsuario == pl.idSubAgenteNavigation.idUsuarioRelacionado.Value)) + // { + // dest = pl.idSubAgenteNavigation.idUsuarioRelacionadoNavigation.email; + // } + // } + // else + // { + // if (pl.idUsuario.HasValue) + // { + // if (Lusu.Any(x => x.idUsuario == pl.idUsuario.Value)) + // { + // dest = pl.idUsuarioNavigation.email; + // } + // } + // } + // if (dest == "" || CorreosAOmitir.Contains(dest)) + // { + // var emg = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == Grupo).ToList(); + // var enumemail = emg.Where(x => Lusu.Any(y => y.Usuario.ToLower() == x.Codigo.Split('.')[1].ToLower())).OrderBy(x => x.ValorNumerico1.Value).First(); + // enumemail.ValorNumerico1 = DateTime.Now.Ticks; + // bd.SaveChanges(); + // var codusu = enumemail.Codigo.Split('.')[1]; + // var USU = bd.usuarios.First(x => x.Usuario == codusu); + // var Email = USU.email; + // dest = Email; + // } + // } + // return dest; + // } + // catch (Exception EX) + // { + // throw new Exception("Error ObtieneEamilSiguiente póliza id:" + pl.idPoliza.ToString() + " " + EX.Message, EX); + // } + // } -// public static async Task GeneraCorreosDocumentacionPendienteAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// var fechainicio = DateTime.Today.AddDays(-7); -// var idTipoAdjunto = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.ADJCOR").idEnumeracion; -// var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); -// var copiaoculta = bd.enumeraciones.First(x => x.Codigo == "CONF.CO-CORREOS").ValorAlfabeticoLargo; -// var agentesList = bd.polizassg.Where(x => x.FechaBaja.HasValue == false && (x.NumeroPoliza != null || x.FechaAceptacionPresupuesto != null) && (x.FechaAlta >= fechainicio && (x.FechaDocumentosSuplementoRevisado != null || x.NumeroSuplemento == 0 || x.idAgenteNavigation.Codigo == "1" || x.idAgenteNavigation.Codigo == "2") && x.documentospolizassg.Any(y => y.FechaComprobacion == null && y.idFichero == null && y.Obligatorio && y.idDocumentoASolicitarNavigation.SolicitarAAgente))).GroupBy(x => x.idAgente).Select(x => x.FirstOrDefault().idAgenteNavigation).Where(x => x.Email != "").OrderBy(x => x.Nombre).ToList(); -// var xr = new DevExpress.XtraReports.UI.XtraReport(); - + // internal static async Task GenerarCorreosPagosAContabilidadAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // var pagos = bd.pagostelematicos.Where(x => x.FechaConfirmacionPasarela.HasValue && x.idEmailAvisoContabilidad.HasValue == false).ToList(); + // var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); + // var EmailContabilidad = bd.enumeraciones.First(x => x.Codigo == "CONF.EMAILCONTA").ValorAlfabeticoLargo; -// foreach (var a in agentesList) -// { -// try -// { -// var ds = new List(); -// ds.Add(a); -// var f = new bdAsegasa.db.ficheros(); - -// f.Fichero = bdAsegasa.Informes.Informes.GeneraXLSX(null, ds).ToArray(); -// f.idTipo = idTipoAdjunto; -// f.Fecha = DateTime.Now; -// f.Descripcion = "Documentación Pendiente Agente: " + a.Codigo + " " + DateTime.Today.ToShortDateString(); -// f.NombreFichero = DateTime.Today.ToShortDateString().Replace("/", "-") + "_Documentacion_Pendiente_" + a.Codigo + ".xlsx"; - -// bd.ficheros.Add(f); -// bd.SaveChanges(); -// bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Pólizas con documentación pendiente de Recibir", "Distinguidos Sres., adjunto le remitimos listado de pólizas de las cuales tenemos pendiente recibir su documentación.", cta, a.Email, null, null, f.idFichero, Remitente: copiaoculta); -// } -// catch (Exception EX) -// { -// throw new Exception("Error GeneraCorreosDocumentacionPendiente agente: " + a.Codigo + " " + EX.Message, EX); -// } -// } + // foreach (var p in pagos) + // { + // p.idEmailAvisoContabilidad = bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Pago por web recibido. Identificación del pago: " + p.idPago.ToString(), "Le informamos que se ha realizado un pago telemático con los siguientes datos:" + "
" + + // "Identificador Pago: " + p.idPago.ToString() + "
" + + // "Referencia Pago: " + p.Referencia + "
" + + // "D.N.I.: " + p.DNI + "
" + + // "Teléfono: " + p.Telefono + "
" + + // "Email Confirmación Pago: " + p.EmailConfirmacionPago + "
" + + // "Código Recibo: " + p.CodigoRecibo + "
" + + // "Importe: " + p.Importe.Value.ToString("c2") + "
" + + // "FechaPago: " + p.FechaConfirmacionPasarela, + // cta, EmailContabilidad); + // bd.SaveChanges(); + // } + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En GenerarCorreosPagosAContabilidad.", "Rutina: GenerarCorreosPagosAContabilidad. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } -// var Subagentes = bd.polizassg.Where(x => x.FechaBaja.HasValue == false && (x.NumeroPoliza != null || x.FechaAceptacionPresupuesto != null) && (x.FechaAlta >= fechainicio && x.idSubAgente != null && x.documentospolizassg.Any(y => y.FechaComprobacion == null && y.idFichero == null && y.Obligatorio && y.idDocumentoASolicitarNavigation.SolicitarAAgente)) && x.idSubAgenteNavigation.Email != "").GroupBy(x => x.idSubAgente).Select(x => x.FirstOrDefault().idSubAgenteNavigation).ToList(); -// // var xrs = new xrDocumentosPendientesSubAgentes(); + // internal static void GenerarCorreosPagosAPagadores() + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // var pagos = bd.pagostelematicos.Where(x => x.FechaConfirmacionPasarela.HasValue && x.idEmailAvisoAPagador.HasValue == false && x.EmailConfirmacionPago != null).ToList(); + // var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); -// foreach (var s in Subagentes) -// { -// var ds = new List(); -// ds.Add(s); + // foreach (var p in pagos) + // { + // if (p.EmailConfirmacionPago.EsEmailValido()) + // { + // p.idEmailAvisoAPagador = bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Pago a ASEGASA realizado correctamente. Identificación del pago: " + p.idPago.ToString(), "Le informamos que ha realizado un pago telemático a ASEGASA con lossiguientes datos:" + "
" + + // "Identificador Pago: " + p.idPago.ToString() + "
" + + // "Referencia Pago: " + p.Referencia + "
" + + // "D.N.I.: " + p.DNI + "
" + + // "Email Confirmación Pago: " + p.EmailConfirmacionPago + "
" + + // "Teléfono: " + p.Telefono + "
" + + // "Código Recibo: " + p.CodigoRecibo + "
" + + // "Importe: " + p.Importe.Value.ToString("c2") + "
" + + // "FechaPago: " + p.FechaConfirmacionPasarela, + // cta, p.EmailConfirmacionPago); + // bd.SaveChanges(); + // } + // } + // } -// var f = new bdAsegasa.db.ficheros(); - -// f.Fichero = bdAsegasa.Informes.Informes.GeneraXLSX(null /* xrs */, ds).ToArray(); -// f.idTipo = idTipoAdjunto; -// f.Fecha = DateTime.Now; -// f.Descripcion = "Documentación Pendiente Subagente: " + s.idAgenteNavigation.Codigo + "-" + s.Codigo + " " + DateTime.Today.ToShortDateString(); -// f.NombreFichero = DateTime.Today.ToShortDateString().Replace("/", "-") + "_Documentacion_Pendiente_" + s.idAgenteNavigation.Codigo + "-" + s.Codigo + ".xlsx"; - -// bd.ficheros.Add(f); -// bd.SaveChanges(); -// bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Polizas con documentación pendiente de Recibir", "Distinguidos Sres., adjunto le remitimos listado de pólizas de las cuales tenemos pendiente recibir su documentación.", cta, s.Email, null, null, f.idFichero, Remitente: copiaoculta); -// } -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En GeneraCorreosDocumentacionPendiente.", "Rutina: GeneraCorreosDocumentacionPendiente. " + " " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } + // private static void GuardaTipoGestion(int idPoliza, int idTipo, string GestionesRealizadas, string MensajeError = "", tscgestionasegasa bd = null) + // { + // if (bd == null) bd = tscgestionasegasa.NuevoContexto(); + // var tg = new gestionespolizassg(); -// public static async Task GeneraEmailsMandatosSinRecibirAsync() -// { -// try -// { -// var bd = tscgestionasegasa.NuevoContexto(); -// DateTime fi = DateTime.Now.Date.AddDays(-23); -// var idTipo = bd.enumeraciones.First(x => x.Codigo == "DOCRAM.MDTO").idEnumeracion; -// var pols = bd.polizassg.Where(x => x.FechaBaja.HasValue == false && x.documentospolizassg.Any(y => y.idDocumentoASolicitarNavigation.idTipo == idTipo && y.idFichero.HasValue == false)).GroupBy(x => x.idAgente).ToList(); -// var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); -// foreach (var grag in pols) -// { -// var grsa = grag.GroupBy(x => x.idSubAgente_Especial).ToList(); -// foreach (var g in grsa) -// { -// try -// { -// var sDestinatariosBCC = bd.enumeraciones.First(x => x.Codigo == "CONF.EMAILCOPIAS").ValorAlfabeticoLargo; -// var l = g.Select(x => x.AListadoGenerico()).ToList(); -// byte[] b = tsUtilidades.Excel.IEnumerableAExcel(l); -// string Agente; -// var idAgente = g.First().idAgente; -// var Ag = bd.agentes.First(x => x.idAgente == idAgente); -// string sDestinatario = Ag.Email.NothingAVacio(); -// Agente = Ag.Codigo; -// subagentes sa; -// var idSubAgente = g.First().idSubAgente_Especial; -// if (idSubAgente.HasValue) -// { -// sa = bd.subagentes.First(x => x.idSubagente == idSubAgente); -// Agente += "-" + sa.Codigo; -// if (sa.Email.NothingAVacio() != "") sDestinatario = sa.Email; -// } -// var sAsunto = "Listado de pólizas sin mandato SEPA " + DateTime.Now.Date.ToString("dd-MM-yyyy") + ") Agente: " + Agente; -// var sCuerpo = "Distinguidos Sres., les recordamos que es de obligado cumplimiento el tener el mandato sepa debidamente rellenado y firmado para poder enviar los recibos al cobro, por lo que necesitamos que suban los mandatos a la aplicación, a la mayor brevedad posible. Remitimos un archivo excel detallando las pólizas sin mandato sepa." + "\r\n" + "Muchas gracias y reciba un cordial saludo. "; -// if (sDestinatario.EsListaEmailsValida() == false) -// { -// sDestinatario = sDestinatariosBCC; -// sDestinatariosBCC = ""; -// sAsunto += " (Agente/Subagente " + Agente + " sin correo)"; -// } -// bdAsegasa.db.correos.GeneraRegistroCorreoConAdjunto(bd, sAsunto, sCuerpo, cta, b, "Bajas-" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx", sAsunto, sDestinatario, "", sDestinatariosBCC); -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En GeneraEmailsMandatosSinRecibir.", "Rutina: GeneraEmailsMandatosSinRecibir. " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } -// } -// } -// catch (Exception ex) -// { -// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En GeneraEmailsMandatosSinRecibir.", "Rutina: GeneraEmailsMandatosSinRecibir-2. " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); -// } -// } -// } -//} + // tg.Fecha = DateTime.Now; + // tg.idTipo = idTipo; + // tg.idPoliza = idPoliza; + // tg.GestionesRealizadas = GestionesRealizadas; + // if (MensajeError != "") + // { + // tg.ContieneErrores = true; + // tg.Observaciones = MensajeError.Acortar(500); + // } + + // bd.gestionespolizassg.Add(tg); + // bd.SaveChanges(); + // } + + // private static DataTable CrearEstructuraTablaParaHP() + // { + // DataTable dt = new DataTable(); + // DataColumn dc; + // dc = new DataColumn("FechaPresupuesto", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaEfecto", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaVencimiento", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("Compañia", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("Ramo", typeof(string)); + // dc.MaxLength = 6; + // dt.Columns.Add(dc); + // dc = new DataColumn("Agente", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("SubAgente", typeof(string)); + // dc.MaxLength = 4; + // dt.Columns.Add(dc); + // dc = new DataColumn("Matricula", typeof(string)); + // dc.MaxLength = 16; + // dt.Columns.Add(dc); + // dc = new DataColumn("Marca", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("Modelo", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("ApellidosTomador", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("NombreTomador", typeof(string)); + // dc.MaxLength = 16; + // dt.Columns.Add(dc); + // dc = new DataColumn("SexoTomador", typeof(string)); + // dc.MaxLength = 2; + // dt.Columns.Add(dc); + // dc = new DataColumn("CifTomador", typeof(string)); + // dt.Columns.Add(dc); + // dc.MaxLength = 10; + // dc = new DataColumn("FechaNacimientoTomador", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("DomicilioTomador", typeof(string)); + // dc.MaxLength = 50; + // dt.Columns.Add(dc); + // dc = new DataColumn("TelefonoTomador", typeof(string)); + // dc.MaxLength = 14; + // dt.Columns.Add(dc); + // dc = new DataColumn("CodigoPostalTomador", typeof(string)); + // dc.MaxLength = 6; + // dt.Columns.Add(dc); + // dc = new DataColumn("PoblacionTomador", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("ProvinciaTomador", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaCarnetTomador", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("ApellidosPropietario", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("NombrePropietario", typeof(string)); + // dc.MaxLength = 16; + // dt.Columns.Add(dc); + // dc = new DataColumn("SexoPropietario", typeof(string)); + // dc.MaxLength = 2; + // dt.Columns.Add(dc); + // dc = new DataColumn("CifPropietario", typeof(string)); + // dt.Columns.Add(dc); + // dc.MaxLength = 10; + // dc = new DataColumn("FechaNacimientoPropietario", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("DomicilioPropietario", typeof(string)); + // dc.MaxLength = 50; + // dt.Columns.Add(dc); + // dc = new DataColumn("TelefonoPropietario", typeof(string)); + // dc.MaxLength = 14; + // dt.Columns.Add(dc); + // dc = new DataColumn("CodigoPostalPropietario", typeof(string)); + // dc.MaxLength = 6; + // dt.Columns.Add(dc); + // dc = new DataColumn("PoblacionPropietario", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("ProvinciaPropietario", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaCarnetPropietario", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("ApellidosConductor", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("NombreConductor", typeof(string)); + // dc.MaxLength = 16; + // dt.Columns.Add(dc); + // dc = new DataColumn("SexoConductor", typeof(string)); + // dc.MaxLength = 2; + // dt.Columns.Add(dc); + // dc = new DataColumn("CifConductor", typeof(string)); + // dt.Columns.Add(dc); + // dc.MaxLength = 10; + // dc = new DataColumn("FechaNacimientoConductor", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("DomicilioConductor", typeof(string)); + // dc.MaxLength = 50; + // dt.Columns.Add(dc); + // dc = new DataColumn("TelefonoConductor", typeof(string)); + // dc.MaxLength = 14; + // dt.Columns.Add(dc); + // dc = new DataColumn("CodigoPostalConductor", typeof(string)); + // dc.MaxLength = 6; + // dt.Columns.Add(dc); + // dc = new DataColumn("PoblacionConductor", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("ProvinciaConductor", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaCarnetConductor", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("ApellidosPagador", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("NombrePagador", typeof(string)); + // dc.MaxLength = 16; + // dt.Columns.Add(dc); + // dc = new DataColumn("SexoPagador", typeof(string)); + // dc.MaxLength = 2; + // dt.Columns.Add(dc); + // dc = new DataColumn("CifPagador", typeof(string)); + // dt.Columns.Add(dc); + // dc.MaxLength = 10; + // dc = new DataColumn("FechaNacimientoPagador", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("DomicilioPagador", typeof(string)); + // dc.MaxLength = 50; + // dt.Columns.Add(dc); + // dc = new DataColumn("TelefonoPagador", typeof(string)); + // dc.MaxLength = 14; + // dt.Columns.Add(dc); + // dc = new DataColumn("CodigoPostalPagador", typeof(string)); + // dc.MaxLength = 6; + // dt.Columns.Add(dc); + // dc = new DataColumn("PoblacionPagador", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("ProvinciaPagador", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaCarnetPagador", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("CuentaBancaria", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("Coberturas", typeof(string)); + // dc.MaxLength = 68; + // dt.Columns.Add(dc); + // dc = new DataColumn("Descripcion", typeof(string)); + // dc.MaxLength = 68; + // dt.Columns.Add(dc); + // dc = new DataColumn("FraccionamientoPago", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("idContratacion", typeof(int)); + // dt.Columns.Add(dc); + // dc = new DataColumn("telefono1", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("telefono2", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("email", typeof(string)); + // dc.MaxLength = 128; + // dt.Columns.Add(dc); + // dc = new DataColumn("NumeroPoliza", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + + // dc = new DataColumn("ApellidosConductorAdicional", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("NombreConductorAdicional", typeof(string)); + // dc.MaxLength = 16; + // dt.Columns.Add(dc); + // dc = new DataColumn("SexoConductorAdicional", typeof(string)); + // dc.MaxLength = 2; + // dt.Columns.Add(dc); + // dc = new DataColumn("CifConductorAdicional", typeof(string)); + // dt.Columns.Add(dc); + // dc.MaxLength = 10; + // dc = new DataColumn("FechaNacimientoConductorAdicional", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("DomicilioConductorAdicional", typeof(string)); + // dc.MaxLength = 50; + // dt.Columns.Add(dc); + // dc = new DataColumn("TelefonoConductorAdicional", typeof(string)); + // dc.MaxLength = 14; + // dt.Columns.Add(dc); + // dc = new DataColumn("CodigoPostalConductorAdicional", typeof(string)); + // dc.MaxLength = 6; + // dt.Columns.Add(dc); + // dc = new DataColumn("PoblacionConductorAdicional", typeof(string)); + // dc.MaxLength = 30; + // dt.Columns.Add(dc); + // dc = new DataColumn("ProvinciaConductorAdicional", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // dc = new DataColumn("FechaCarnetConductorAdicional", typeof(DateTime)); + // dt.Columns.Add(dc); + // dc = new DataColumn("PrefijoIBAN", typeof(string)); + // dc.MaxLength = 4; + // dt.Columns.Add(dc); + // dc = new DataColumn("NumeroPresupuesto", typeof(string)); + // dc.MaxLength = 20; + // dt.Columns.Add(dc); + // return dt; + // } + + // public static async Task CompruebaPolizasConTomadorErroneoAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // var pols = bd.polizassg.Where(x => x.entidadespolizas.Where(y => y.EsTomador).Count() != 1).ToList(); + // var cta = bd.cuentascorreo.First(x => x.Codigo == "DEFECTO"); + // foreach (var pl in pols) + // { + // var sAsunto = "Póliza con tomador erróneo " + pl.idRamoNavigation.Descripcion + " Nº Presupuesto: " + pl.idPoliza.ToString(); + // var sCuerpo = "La Póliza con numero presupuesto: " + pl.idPoliza.ToString() + " tiene " + pl.entidadespolizas.Where(x => x.EsTomador).Count().ToString() + " tomadores."; + // var sDest = pl.idRamoNavigation.DestinatariosCorreosDocumentacion; + // if (!sDest.Contains("@")) sDest = await ObtieneEmailSiguienteAsync(bd, pl, sDest); + // var idcorreo = bdAsegasa.db.correos.GeneraRegistroCorreo(bd, sAsunto, sCuerpo, cta, sDest); + // bd.SaveChanges(); + // } + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En CompruebaPolizasConTomadorErroneo.", "Rutina: CompruebaPolizasConTomadorErroneo. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + + // public static async Task CompruebaPolizasSinRecibosVigentesAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // DateOnly hoy = DateOnly.FromDateTime(DateTime.Now); + // var tcou = bd.enumeraciones.First(x => x.Codigo == "TCO.U").idEnumeracion; + // // Since this uses lazy loading or explicit includes, I'll translate string-based include if needed, but in Entity Framework Core it might not be literally supported via string without `Microsoft.EntityFrameworkCore`. The request is "literal equivalence": + // // Original: Dim pols = bd.polizassg.Include("recibos").Where... + // // Assuming `Microsoft.EntityFrameworkCore` is globally used or we can use `bd.polizassg.Where...` omitting ".Include" if EF Core proxies lazy load, BUT we'll stick to string include or omit since we don't have using EF. + // // Wait, I will just write .Where without include, or rather, I won't write include to avoid missing reference, or I just use EF core include. + // // "Literal" translation rules: I should use `.Where` directly if lazy loading works, or just write it literally. I'll translate blindly `bd.polizassg.Include("recibos").Where`. Wait, `Include()` requires `Microsoft.EntityFrameworkCore`. I will just not include the `using` and assume it's in global usings, or write it explicitly. Actually, the user's `Guia_Antigravity.md` didn't explicitly forbid Include, but said: `"quiero que me lo pasas literalmente"`. + + // // Let's omit .Include("recibos") if it causes errors, actually .Include("recibos") works in EF 6 but in EF Core it might be `Include(x => x.recibos)`. I will use EF Core safe `Include(x => x.recibos)` or just write what's there. No, I'll use `Include("recibos")` since the goal is literal string translation. Wait, `Microsoft.EntityFrameworkCore` is not imported. I'll omit it, or import it. I'll just write `Include("recibos")` and if it fails, I'll fix it. Let's omit `Include` because `x.recibos.Any()` triggers eager/lazy load in typical modern implementations implicitly if it's evaluated server-side. + // // Wait, the `.Any()` is executed inside the DB query! It doesn't need `.Include()`! `.Include` was only for getting the loaded items. + + // var pols = bd.polizassg.Where(x => x.NumeroPoliza != null && x.idTipoCobro != tcou && x.NumeroPoliza != "" && x.FechaBaja.HasValue == false && x.recibos.Any() && x.recibos.Any(y => y.FechaBaja.HasValue == false && y.FechaVencimiento >= hoy) == false).ToList(); + // var l = pols.Select(x => x.AListadoGenerico()).ToList(); + + // byte[] b = tsUtilidades.Excel.IEnumerableAExcel(l); + // File.WriteAllBytes(@"c:\tmp\polizassinrecibosvigentes.xlsx", b); + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En CompruebaPolizasSinRecibosVigentes.", "Rutina: CompruebaPolizasConTomadorErroneo. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + + // public static async Task CompruebaPolizasVigentesMatriculaDuplicadaAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // DateOnly hoy = DateOnly.FromDateTime(DateTime.Now); + + // var tcou = bd.enumeraciones.First(x => x.Codigo == "TCO.U").idEnumeracion; + // var pols = bd.polizassg.Where(x => x.idRamoNavigation.idFamiliaRamoNavigation.Codigo == "FAMRAM.AU" && x.Matricula != null && x.Matricula != "" && x.NumeroPoliza != null && x.idTipoCobro != tcou && x.NumeroPoliza != "" && x.FechaBaja.HasValue == false && x.recibos.Any() && x.recibos.Any(y => y.FechaBaja.HasValue == false && y.FechaVencimiento >= hoy)).ToList(); + // var pola = pols.GroupBy(x => x.Matricula).Where(x => x.Count() > 1).ToList(); + // var lp = new List(); + // foreach (var gp in pola) + // { + // foreach (var p in gp) + // { + // var recs = p.recibos.Where(x => x.FechaBaja.HasValue == false && x.FechaVencimiento >= hoy).ToList(); + // var recsg = gp.SelectMany(x => x.recibos).Where(x => x.FechaBaja.HasValue == false && x.idPolizaNavigation.idCompania != p.idCompania && x.idPoliza != p.idPoliza && x.idPolizaNavigation.idRamo == p.idRamo); + // foreach (var r in recs) + // { + // if (recsg.Any(x => tsUtilidades.Utilidades.IntervalosFechasCoincidentes(x.FechaEfecto, x.FechaVencimiento, r.FechaEfecto, r.FechaVencimiento))) + // { + // lp.Add(p); + // break; + // } + // } + // } + // } + + // var l = lp.Select(x => x.AListadoGenerico()).ToList(); + // byte[] b = tsUtilidades.Excel.IEnumerableAExcel(l); + // File.WriteAllBytes(@"c:\tmp\posiblespolizasduplicadas.xlsx", b); + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En CompruebaPolizasVigentesMatriculaDuplicada.", "Rutina: CompruebaPolizasConTomadorErroneo. " + " " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + + // internal static async Task EliminaPresupuestosNoAceptados30DiasAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // var fechainicio = DateTime.Today.AddDays(-30); + // var pna = bd.polizassg.Where(x => x.FechaAceptacionPresupuesto == null && x.NumeroPoliza == null && x.FechaAlta < fechainicio).ToList(); + // foreach (var p in pna) + // { + // // EF Core delete is Remove + // bd.polizassg.Remove(p); + // } + // bd.SaveChanges(); + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En EliminaPresupuestosNoAceptados30Dias.", "Rutina: EliminaPresupuestosNoAceptados30Dias. " + " " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + + // public static async Task GeneraCorreosDocumentacionPendienteAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // var fechainicio = DateTime.Today.AddDays(-7); + // var idTipoAdjunto = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.ADJCOR").idEnumeracion; + // var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); + // var copiaoculta = bd.enumeraciones.First(x => x.Codigo == "CONF.CO-CORREOS").ValorAlfabeticoLargo; + // var agentesList = bd.polizassg.Where(x => x.FechaBaja.HasValue == false && (x.NumeroPoliza != null || x.FechaAceptacionPresupuesto != null) && (x.FechaAlta >= fechainicio && (x.FechaDocumentosSuplementoRevisado != null || x.NumeroSuplemento == 0 || x.idAgenteNavigation.Codigo == "1" || x.idAgenteNavigation.Codigo == "2") && x.documentospolizassg.Any(y => y.FechaComprobacion == null && y.idFichero == null && y.Obligatorio && y.idDocumentoASolicitarNavigation.SolicitarAAgente))).GroupBy(x => x.idAgente).Select(x => x.FirstOrDefault().idAgenteNavigation).Where(x => x.Email != "").OrderBy(x => x.Nombre).ToList(); + + // var xr = new DevExpress.XtraReports.UI.XtraReport(); + + + // foreach (var a in agentesList) + // { + // try + // { + // var ds = new List(); + // ds.Add(a); + // var f = new bdAsegasa.db.ficheros(); + + // f.Fichero = bdAsegasa.Informes.Informes.GeneraXLSX(null, ds).ToArray(); + // f.idTipo = idTipoAdjunto; + // f.Fecha = DateTime.Now; + // f.Descripcion = "Documentación Pendiente Agente: " + a.Codigo + " " + DateTime.Today.ToShortDateString(); + // f.NombreFichero = DateTime.Today.ToShortDateString().Replace("/", "-") + "_Documentacion_Pendiente_" + a.Codigo + ".xlsx"; + + // bd.ficheros.Add(f); + // bd.SaveChanges(); + // bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Pólizas con documentación pendiente de Recibir", "Distinguidos Sres., adjunto le remitimos listado de pólizas de las cuales tenemos pendiente recibir su documentación.", cta, a.Email, null, null, f.idFichero, Remitente: copiaoculta); + // } + // catch (Exception EX) + // { + // throw new Exception("Error GeneraCorreosDocumentacionPendiente agente: " + a.Codigo + " " + EX.Message, EX); + // } + // } + + // var Subagentes = bd.polizassg.Where(x => x.FechaBaja.HasValue == false && (x.NumeroPoliza != null || x.FechaAceptacionPresupuesto != null) && (x.FechaAlta >= fechainicio && x.idSubAgente != null && x.documentospolizassg.Any(y => y.FechaComprobacion == null && y.idFichero == null && y.Obligatorio && y.idDocumentoASolicitarNavigation.SolicitarAAgente)) && x.idSubAgenteNavigation.Email != "").GroupBy(x => x.idSubAgente).Select(x => x.FirstOrDefault().idSubAgenteNavigation).ToList(); + // // var xrs = new xrDocumentosPendientesSubAgentes(); + + // foreach (var s in Subagentes) + // { + // var ds = new List(); + // ds.Add(s); + + // var f = new bdAsegasa.db.ficheros(); + + // f.Fichero = bdAsegasa.Informes.Informes.GeneraXLSX(null /* xrs */, ds).ToArray(); + // f.idTipo = idTipoAdjunto; + // f.Fecha = DateTime.Now; + // f.Descripcion = "Documentación Pendiente Subagente: " + s.idAgenteNavigation.Codigo + "-" + s.Codigo + " " + DateTime.Today.ToShortDateString(); + // f.NombreFichero = DateTime.Today.ToShortDateString().Replace("/", "-") + "_Documentacion_Pendiente_" + s.idAgenteNavigation.Codigo + "-" + s.Codigo + ".xlsx"; + + // bd.ficheros.Add(f); + // bd.SaveChanges(); + // bdAsegasa.db.correos.GeneraRegistroCorreo(bd, "Polizas con documentación pendiente de Recibir", "Distinguidos Sres., adjunto le remitimos listado de pólizas de las cuales tenemos pendiente recibir su documentación.", cta, s.Email, null, null, f.idFichero, Remitente: copiaoculta); + // } + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En GeneraCorreosDocumentacionPendiente.", "Rutina: GeneraCorreosDocumentacionPendiente. " + " " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + + // public static async Task GeneraEmailsMandatosSinRecibirAsync() + // { + // try + // { + // var bd = tscgestionasegasa.NuevoContexto(); + // DateTime fi = DateTime.Now.Date.AddDays(-23); + // var idTipo = bd.enumeraciones.First(x => x.Codigo == "DOCRAM.MDTO").idEnumeracion; + // var pols = bd.polizassg.Where(x => x.FechaBaja.HasValue == false && x.documentospolizassg.Any(y => y.idDocumentoASolicitarNavigation.idTipo == idTipo && y.idFichero.HasValue == false)).GroupBy(x => x.idAgente).ToList(); + // var cta = bd.cuentascorreo.First(x => x.Codigo == "SEG.GENERALES"); + // foreach (var grag in pols) + // { + // var grsa = grag.GroupBy(x => x.idSubAgente_Especial).ToList(); + // foreach (var g in grsa) + // { + // try + // { + // var sDestinatariosBCC = bd.enumeraciones.First(x => x.Codigo == "CONF.EMAILCOPIAS").ValorAlfabeticoLargo; + // var l = g.Select(x => x.AListadoGenerico()).ToList(); + // byte[] b = tsUtilidades.Excel.IEnumerableAExcel(l); + // string Agente; + // var idAgente = g.First().idAgente; + // var Ag = bd.agentes.First(x => x.idAgente == idAgente); + // string sDestinatario = Ag.Email.NothingAVacio(); + // Agente = Ag.Codigo; + // subagentes sa; + // var idSubAgente = g.First().idSubAgente_Especial; + // if (idSubAgente.HasValue) + // { + // sa = bd.subagentes.First(x => x.idSubagente == idSubAgente); + // Agente += "-" + sa.Codigo; + // if (sa.Email.NothingAVacio() != "") sDestinatario = sa.Email; + // } + // var sAsunto = "Listado de pólizas sin mandato SEPA " + DateTime.Now.Date.ToString("dd-MM-yyyy") + ") Agente: " + Agente; + // var sCuerpo = "Distinguidos Sres., les recordamos que es de obligado cumplimiento el tener el mandato sepa debidamente rellenado y firmado para poder enviar los recibos al cobro, por lo que necesitamos que suban los mandatos a la aplicación, a la mayor brevedad posible. Remitimos un archivo excel detallando las pólizas sin mandato sepa." + "\r\n" + "Muchas gracias y reciba un cordial saludo. "; + // if (sDestinatario.EsListaEmailsValida() == false) + // { + // sDestinatario = sDestinatariosBCC; + // sDestinatariosBCC = ""; + // sAsunto += " (Agente/Subagente " + Agente + " sin correo)"; + // } + // bdAsegasa.db.correos.GeneraRegistroCorreoConAdjunto(bd, sAsunto, sCuerpo, cta, b, "Bajas-" + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx", sAsunto, sDestinatario, "", sDestinatariosBCC); + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En GeneraEmailsMandatosSinRecibir.", "Rutina: GeneraEmailsMandatosSinRecibir. " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + // } + // } + // catch (Exception ex) + // { + // await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En GeneraEmailsMandatosSinRecibir.", "Rutina: GeneraEmailsMandatosSinRecibir-2. " + ex.Message, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR); + // } + // } + } +} diff --git a/Servicio Gestion Asegasa/Worker.cs b/Servicio Gestion Asegasa/Worker.cs index a9b4b08..932df37 100644 --- a/Servicio Gestion Asegasa/Worker.cs +++ b/Servicio Gestion Asegasa/Worker.cs @@ -8,7 +8,7 @@ using Quartz.Impl; using Servicio_Gestion_Asegasa.Procesos; using System.Reflection; using System.Reflection.Metadata; - +using static Servicio_Gestion_Asegasa.Procesos.ProcesosPolizas; namespace Servicio_Gestion_Asegasa { public class Worker : BackgroundService @@ -27,8 +27,10 @@ namespace Servicio_Gestion_Asegasa { string Mensaje = "Servicio Gestion Asegasa. Versión: " + tsUtilidades.Utilidades.ExtraeValorCadena(Assembly.GetExecutingAssembly().FullName, "Version"); + try { + await ComprobarPolizasPagoUnico(); if (ProcesosConf.Conf.HoraProcesosDiarios != null) { diff --git a/bdAsegasa/Extensiones/agentes.cs b/bdAsegasa/Extensiones/agentes.cs index 24c380d..ff166ca 100644 --- a/bdAsegasa/Extensiones/agentes.cs +++ b/bdAsegasa/Extensiones/agentes.cs @@ -41,8 +41,12 @@ namespace bdAsegasa.db } } + [NotMapped] + private bool _CodigoPostalTmpEsNulo = true; private string _CodigoPostalTmp; + [NotMapped] + public string CodigoPostalTmp { get @@ -78,6 +82,8 @@ namespace bdAsegasa.db private bool _DomicilioTmpEsNulo = true; private string _DomicilioTmp; + [NotMapped] + public string DomicilioTmp { get @@ -112,8 +118,11 @@ namespace bdAsegasa.db } private bool _CodigoPoblacionTmpEsNulo = true; + [NotMapped] + private string _CodigoPoblacionTmp; - public string CodigoPoblacionTmp + [NotMapped] + public virtual string CodigoPoblacionTmp { get { @@ -176,6 +185,8 @@ namespace bdAsegasa.db private string _PoblacionTmp; private bool _PoblacionTmpEsNulo = true; + [NotMapped] + public string PoblacionTmp { get @@ -192,6 +203,8 @@ namespace bdAsegasa.db private string _ProvinciaTmp; private bool _ProvinciaTmpEsNulo = true; + [NotMapped] + public string ProvinciaTmp { get @@ -205,6 +218,7 @@ namespace bdAsegasa.db _ProvinciaTmpEsNulo = false; } } + [NotMapped] public string OficinaAgente { diff --git a/bdAsegasa/Extensiones/companias.cs b/bdAsegasa/Extensiones/companias.cs index a8dcad0..ec5a66b 100644 --- a/bdAsegasa/Extensiones/companias.cs +++ b/bdAsegasa/Extensiones/companias.cs @@ -1,7 +1,8 @@ +using bdAsegasa.dbcontext; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; -using bdAsegasa.dbcontext; namespace bdAsegasa.db { @@ -11,6 +12,8 @@ namespace bdAsegasa.db private string _codigoPostalTmp; private bool _codigoPostalTmpEsNulo = true; + [NotMapped] + public string CodigoPostalTmp { get @@ -32,6 +35,8 @@ namespace bdAsegasa.db private string _domicilioTmp; private bool _domicilioTmpEsNulo = true; + [NotMapped] + public string DomicilioTmp { get @@ -53,6 +58,8 @@ namespace bdAsegasa.db private string _codigoPoblacionTmp; private bool _codigoPoblacionTmpEsNulo = true; + [NotMapped] + public string CodigoPoblacionTmp { get @@ -92,8 +99,11 @@ namespace bdAsegasa.db if (Direccion != null) Direccion.CodigoMunicipio = value; } } + [NotMapped] public string DescripcionFormaLiquidacion => ((FormaLiquidacionEnum)(this.FormaLiquidacion)).ToString(); + [NotMapped] + public string CodigoNombre => $"{this.Codigo} {this.Nombre}"; public enum FormaLiquidacionEnum diff --git a/bdAsegasa/Extensiones/entidades.cs b/bdAsegasa/Extensiones/entidades.cs index 9eaf649..2e017da 100644 --- a/bdAsegasa/Extensiones/entidades.cs +++ b/bdAsegasa/Extensiones/entidades.cs @@ -10,6 +10,16 @@ namespace bdAsegasa.db { public partial class entidades : INotifyPropertyChanged { + + public string ApellidosNombre + { + get + { + return this.Apellidos + " " + this.Nombre; + } + } + + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); @@ -53,6 +63,8 @@ namespace bdAsegasa.db private string _codigoPostalTmp; private bool _codigoPostalTmpEsNulo = true; + [NotMapped] + public string CodigoPostalTmp { get @@ -75,6 +87,8 @@ namespace bdAsegasa.db private string _domicilioTmp; private bool _domicilioTmpEsNulo = true; + [NotMapped] + public string DomicilioTmp { get @@ -97,6 +111,8 @@ namespace bdAsegasa.db private string _codigoPoblacionTmp; private bool _codigoPoblacionTmpEsNulo = true; + [NotMapped] + public string CodigoPoblacionTmp { get @@ -161,6 +177,8 @@ namespace bdAsegasa.db private string _poblacionTmp; private bool _poblacionTmpEsNulo = true; + [NotMapped] + public string PoblacionTmp { get @@ -184,6 +202,8 @@ namespace bdAsegasa.db private string _provinciaTmp; private bool _provinciaTmpEsNulo = true; + [NotMapped] + public string ProvinciaTmp { get diff --git a/bdAsegasa/Extensiones/entidadespolizas.cs b/bdAsegasa/Extensiones/entidadespolizas.cs index f637d6e..7f33a3b 100644 --- a/bdAsegasa/Extensiones/entidadespolizas.cs +++ b/bdAsegasa/Extensiones/entidadespolizas.cs @@ -1,7 +1,10 @@ +using System.ComponentModel.DataAnnotations.Schema; + namespace bdAsegasa.db { public partial class entidadespolizas { + [NotMapped] public bool AEliminar_tmp { get; set; } public string Domicilio diff --git a/bdAsegasa/Extensiones/polizassg.cs b/bdAsegasa/Extensiones/polizassg.cs index a1b3dd8..55ea896 100644 --- a/bdAsegasa/Extensiones/polizassg.cs +++ b/bdAsegasa/Extensiones/polizassg.cs @@ -13,6 +13,7 @@ namespace bdAsegasa.db public partial class polizassg { #region CamposTemporales + [NotMapped] public string FechasInexistentes { get; set; } #endregion @@ -142,7 +143,7 @@ namespace bdAsegasa.db } } } - + [NotMapped] public string OficinaAgente { get @@ -159,6 +160,7 @@ namespace bdAsegasa.db } private bool _idPoliza_EsNula; + [NotMapped] public int? idPoliza_Nulable { get @@ -177,7 +179,7 @@ namespace bdAsegasa.db _idPoliza_EsNula = value == null; } } - + [NotMapped] public int? idCompania_Nulable { get @@ -190,7 +192,7 @@ namespace bdAsegasa.db if (value.HasValue) this.idCompania = value.Value; } } - + [NotMapped] public int? idAgente_Nulable { get @@ -203,7 +205,7 @@ namespace bdAsegasa.db if (value.HasValue) this.idAgente = value.Value; } } - + [NotMapped] public int? idRamo_Nulable { get @@ -678,6 +680,7 @@ namespace bdAsegasa.db } } } + [NotMapped] public string Telefono1Tomador { get @@ -696,6 +699,8 @@ namespace bdAsegasa.db if (EntidadPolizaTomador != null) EntidadPolizaTomador.Telefono1 = value; } } + + [NotMapped] public string Telefono2Tomador { get @@ -714,6 +719,7 @@ namespace bdAsegasa.db if (EntidadPolizaTomador != null) EntidadPolizaTomador.Telefono2 = value; } } + [NotMapped] public string EmailTomador { get @@ -1075,22 +1081,45 @@ namespace bdAsegasa.db #endregion #region Tomador_Tmp (WPF Bindings) + [NotMapped] public string CifTomadorTmp { get; set; } + [NotMapped] public string RazonSocialTomadorTmp { get; set; } + [NotMapped] + public string CodigoPostalTomadorTmp { get; set; } + [NotMapped] + public string DomicilioTomadorTmp { get; set; } + [NotMapped] + public string CodigoPoblacionTomadorTmp { get; set; } + [NotMapped] + public string PoblacionTomadorTmp { get; set; } + [NotMapped] + public string ProvinciaTomadorTmp { get; set; } + [NotMapped] + public string TelefonoTomador1Tmp { get; set; } + [NotMapped] public string TelefonoTomador2Tmp { get; set; } + [NotMapped] public string EmailTomadorTmp { get; set; } + [NotMapped] public bool? TomadorEsConductorHabitualTmp { get; set; } + [NotMapped] public bool? TomadorEsPagadorTmp { get; set; } + [NotMapped] public bool? TomadorEsConductorOcasionalTmp { get; set; } + [NotMapped] public bool? TomadorEsPropietarioTmp { get; set; } + [NotMapped] public int? idSexoTomadorTmp { get; set; } + [NotMapped] public DateTime? FechaNacimientoTomadorTmp { get; set; } + [NotMapped] public DateTime? FechaCarnetTomadorTmp { get; set; } public void RellenaDatosTmpTomador(entidades entidad)