agregado procesos y bd clases
This commit is contained in:
667
Servicio Gestion Asegasa/Procesos/ProcesosPolizas.cs
Normal file
667
Servicio Gestion Asegasa/Procesos/ProcesosPolizas.cs
Normal file
@@ -0,0 +1,667 @@
|
||||
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;
|
||||
|
||||
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<int>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> 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);
|
||||
|
||||
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;
|
||||
|
||||
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:" + " <br />" +
|
||||
"Identificador Pago: " + p.idPago.ToString() + " <br />" +
|
||||
"Referencia Pago: " + p.Referencia + " <br />" +
|
||||
"D.N.I.: " + p.DNI + " <br />" +
|
||||
"Teléfono: " + p.Telefono + " <br />" +
|
||||
"Email Confirmación Pago: " + p.EmailConfirmacionPago + " <br />" +
|
||||
"Código Recibo: " + p.CodigoRecibo + " <br />" +
|
||||
"Importe: " + p.Importe.Value.ToString("c2") + " <br />" +
|
||||
"FechaPago: " + p.FechaConfirmacionPasarela,
|
||||
cta, EmailContabilidad);
|
||||
bd.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En GenerarCorreosPagosAContabilidad.", "Rutina: GenerarCorreosPagosAContabilidad. " + " " + ex.Message, TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
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 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:" + " <br />" +
|
||||
"Identificador Pago: " + p.idPago.ToString() + " <br />" +
|
||||
"Referencia Pago: " + p.Referencia + " <br />" +
|
||||
"D.N.I.: " + p.DNI + " <br />" +
|
||||
"Email Confirmación Pago: " + p.EmailConfirmacionPago + " <br />" +
|
||||
"Teléfono: " + p.Telefono + " <br />" +
|
||||
"Código Recibo: " + p.CodigoRecibo + " <br />" +
|
||||
"Importe: " + p.Importe.Value.ToString("c2") + " <br />" +
|
||||
"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<polizassg>();
|
||||
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<agentes>();
|
||||
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<subagentes>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user