620 lines
39 KiB
C#
620 lines
39 KiB
C#
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Diagnostics;
|
|
//using System.IO;
|
|
//using System.Linq;
|
|
//using System.Text;
|
|
//using bdAsegasa;
|
|
//using bdAsegasa.db;
|
|
|
|
//namespace Servicio_Gestion_Asegasa.Procesos
|
|
//{
|
|
// public class ProcesosTractoresAxa
|
|
// {
|
|
// public static int GenerarYGuardarEnBdCsvTractoresAxa(tscgestionasegasa bd)
|
|
// {
|
|
// int resultadoGuardarCambios = 0;
|
|
// try
|
|
// {
|
|
// var listaAltas = new List<polizassg>();
|
|
// var listaAltasFiltradasPorFecha = new List<polizassg>();
|
|
// int idRamoTractores = bd.ramos.First(x => x.Codigo == "1-1").idRamo;
|
|
// int idRamoRemolques = bd.ramos.First(x => x.Codigo == "1-1-1").idRamo;
|
|
// int idCiaAXA = bd.companias.First(x => x.Codigo == "0027").idCompania;
|
|
// int idTipoGestionPoliza = bd.enumeraciones.First(x => x.Codigo == "TGP.CSVAXA").idEnumeracion;
|
|
// int idTipoFicheroCSV = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.CSVAXA").idEnumeracion;
|
|
|
|
// ficheros lineaFichero;
|
|
// gestionesvarias lineaGestionesVarias;
|
|
|
|
// DateTime dHoy = DateTime.Today;
|
|
// DateTime dAyer = DateTime.Today.AddDays(-1);
|
|
|
|
// try
|
|
// {
|
|
// listaAltas = bd.polizassg.Where(x =>
|
|
// (x.idRamoNavigation.idRamo == idRamoTractores || x.idRamoNavigation.idRamo == idRamoRemolques) &&
|
|
// x.idCompania == idCiaAXA &&
|
|
// x.FechaAceptacionPresupuesto.HasValue &&
|
|
// !x.FechaBaja.HasValue &&
|
|
// !x.gestionespolizassg.Any(y => y.idTipo == idTipoGestionPoliza) &&
|
|
// x.idOrigenPresupuesto == (int)bdAsegasa.db.polizassg.TiposPresupuestos.TRACTORES
|
|
// ).ToList();
|
|
|
|
// listaAltasFiltradasPorFecha = listaAltas.Where(x => x.FechaAlta.HasValue && x.FechaAlta.Value.Date < dHoy).ToList();
|
|
|
|
// Debug.WriteLine("listaAltas: {0}", listaAltas.Count);
|
|
// Debug.WriteLine("listaAltasFiltradasPorFecha: {0}", listaAltasFiltradasPorFecha.Count);
|
|
// foreach (var item in listaAltasFiltradasPorFecha)
|
|
// {
|
|
// Debug.WriteLine($"({item.idPoliza},{item.NumeroPoliza},{item.Matricula})");
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Debug.Write(ex.ToString());
|
|
// tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En {System.Reflection.MethodBase.GetCurrentMethod()}",
|
|
// $"En método {System.Reflection.MethodBase.GetCurrentMethod()}. {Environment.MachineName} {ex.ToString()}",tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
|
|
// if (listaAltasFiltradasPorFecha.Count > 0)
|
|
// {
|
|
// lineaFichero = new ficheros
|
|
// {
|
|
// Descripcion = $"{bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.DescripcionFicheroCSV").ValorAlfabeticoLargo} {dAyer:yyyy-MM-dd}",
|
|
// Fecha = DateTime.Now,
|
|
// idTipo = idTipoFicheroCSV,
|
|
// NombreFichero = $"{bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.NombreFicheroCSV").ValorAlfabeticoLargo}{dAyer:yyyy-MM-dd}.csv"
|
|
// };
|
|
|
|
// bd.ficheros.Add(lineaFichero);
|
|
|
|
// lineaGestionesVarias = new gestionesvarias
|
|
// {
|
|
// Descripción = lineaFichero.NombreFichero,
|
|
// idTipo = idTipoGestionPoliza,
|
|
// idFicheroNavigation = lineaFichero,
|
|
// FechaCreacion = DateTime.Now
|
|
// };
|
|
|
|
// bd.gestionesvarias.Add(lineaGestionesVarias);
|
|
|
|
// byte[] archivoCSV = GenerarCsvTractoresAxa(bd, listaAltasFiltradasPorFecha, lineaGestionesVarias);
|
|
|
|
// lineaFichero.Fichero = archivoCSV;
|
|
// resultadoGuardarCambios = bd.SaveChanges();
|
|
|
|
// if (resultadoGuardarCambios > 0)
|
|
// {
|
|
// try
|
|
// {
|
|
// var mensaje = new StringBuilder();
|
|
// mensaje.AppendFormat("Se ha generado un archivo CSV con altas de tractores y/o remolques para AXA.```idFichero: {1}{0}NombreFichero: {2}{0}idGestion: {3}{0}Servidor: {4}```",
|
|
// Environment.NewLine, lineaFichero.idFichero, lineaFichero.NombreFichero, lineaGestionesVarias.idGestion, Environment.MachineName);
|
|
// }
|
|
// catch
|
|
// {
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Debug.WriteLine("No hay líneas o se produjo excepción.");
|
|
// Debug.WriteLine(ex.ToString());
|
|
// tsUtilidades.TsNotificacionesClient.RegistrarAsync( $"En {System.Reflection.MethodBase.GetCurrentMethod()}",
|
|
// $"En método {System.Reflection.MethodBase.GetCurrentMethod()}. {Environment.MachineName} {ex.ToString()}",tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// return resultadoGuardarCambios;
|
|
// }
|
|
|
|
// public static byte[] GenerarCsvTractoresAxa(tscgestionasegasa bd, List<polizassg> listaPolizas, gestionesvarias lineaGestionesVarias = null)
|
|
// {
|
|
// byte[] archivoCSV = null;
|
|
// int idTipoGestionPoliza = bd.enumeraciones.First(x => x.Codigo == "TGP.CSVAXA").idEnumeracion;
|
|
// string sDescripcionGestion = bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.DescripcionGestion").ValorAlfabeticoLargo;
|
|
// string nombreArchivoTemporal = Path.GetTempFileName();
|
|
|
|
// // Usar ANSI/ISO encoding
|
|
// Encoding iso = Encoding.GetEncoding("iso-8859-1");
|
|
|
|
// using (var sw = new StreamWriter(File.Open(nombreArchivoTemporal, FileMode.Create), iso))
|
|
// {
|
|
// sw.WriteLine("Código Marca;Código Modelo;Código Versión;Medofi;Fecha de Efecto;Hora de Fecha Efecto;CAMPAÑA;Producto;Nº Póliza Reservado;Fecha entrada en Delegación;Duración;Plan de cobro;Canal de cobro;Fecha Vto.;NIF, CIF, OTROS;Nº de NIF ó CIF;Primer apellido si es Empresa, no cumplimentar;Segundo apellido si es Empresa, no cumplimentar;Nombre;Fecha Nacimiento;Estado Civil;SEXO;C.P.;Población;Tipo Vía;Nombre Vía;Numero vía;Resto Vía;Propietario;Nombre propietario;Apellido 1 propietario;Apellido 2 propietario;Nif/Cif propietario;Conductor Titular;Nombre Conductor;1º Apellido Conductor;2º Apellido Conductor;Fecha nacimiento conductor DDMMAAAA;Nif, Cif, Otros;NIF Conductor;SEXO;Fecha carnét DDMMAAAA;Conductor Autorizado 1;Nombre Conductor;1º Apellido Conductor;2º Apellido Conductor;Fecha nto. Conductor DDMMAAAA;NIF Conductor;SEXO;Fecha carnet DDMMAAAA;Conductor Autorizado 2;Nombre Conductor;1º Apellido Conductor;2º Apellido Conductor;Fecha nto. Conductor DDMMAAAA;NIF Conductor;SEXO;Fecha carnet DDMMAAAA;Permiso retirado (fijo);Uso Vehículo (según tabla);Accesorios;Tipo de Accesorios;Descripción (Detallar los accesorios separados por comas);Valor Accesorios (valor total);Peso en Toneladas;Literal de Marca;Literal de Modelo;Literal de Versión;Valor (fijo);Valor LUNAS;Matrícula;Fecha 1ª Matriculación DDMMAAAA;C.P. circulación (poner el CP del conductor);Alarma (fijo);Garaje (fijo);KM recorridos (fijo);Combinación de Garantías;Combinación de Accidentes;Kit RC Explotación Agrícola;PRIMA TOTAL;Nº PîLIZA EMITIDA;PNETA EMITIDA;PTOTAL EMITIDA");
|
|
// foreach (var linea in listaPolizas)
|
|
// {
|
|
// int idTipoFicheroPresupuesto = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.PRESUPUESTO").idEnumeracion;
|
|
// if (linea.idFicheroPresupuestoNavigation?.idTipo == idTipoFicheroPresupuesto &&
|
|
// linea.idFicheroPresupuestoNavigation?.NombreFichero?.Trim().ToUpper() == "TRACTORES.XML" &&
|
|
// !string.IsNullOrWhiteSpace(linea.NumeroPoliza))
|
|
// {
|
|
// string lineaCSV = "";
|
|
// bool lineaCsvCorrecta = false;
|
|
// try
|
|
// {
|
|
// lineaCSV = ComponerLineaCsv(linea, bd);
|
|
// lineaCsvCorrecta = true;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// string asunto = $"No se ha podido generar una línea del CSV de TractoresAXA; idPoliza = {linea.idPoliza}; Máquina = {Environment.MachineName}";
|
|
// string cuerpo = $"No se ha podido generar una línea del CSV de TractoresAXA; idPoliza = {linea.idPoliza}\r\n" +
|
|
// $"Esto podría significar que falta algún dato en esta póliza.\r\n" +
|
|
// $"En método {System.Reflection.MethodBase.GetCurrentMethod()}.\r\n{Environment.MachineName} {ex.ToString()}";
|
|
// tsUtilidades.TsNotificacionesClient.RegistrarAsync(asunto, cuerpo, tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
|
|
// if (lineaCsvCorrecta)
|
|
// {
|
|
// sw.WriteLine(lineaCSV);
|
|
// if (lineaGestionesVarias != null && !string.IsNullOrWhiteSpace(lineaGestionesVarias.Descripción))
|
|
// {
|
|
// linea.gestionespolizassg.Add(new gestionespolizassg
|
|
// {
|
|
// idPoliza = linea.idPoliza,
|
|
// idTipo = idTipoGestionPoliza,
|
|
// Fecha = DateTime.Now,
|
|
// GestionesRealizadas = sDescripcionGestion,
|
|
// idGestionVariasNavigation = lineaGestionesVarias
|
|
// });
|
|
// }
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// string cadenaError = $"Advertencia: el fichero no es de tipo \"TIPFIC.PRESUPUESTO\" o no se llama \"tractores.xml\", o no hay número de póliza; idPoliza = {linea.idPoliza}";
|
|
// Console.WriteLine(cadenaError);
|
|
// tsUtilidades.TsNotificacionesClient.RegistrarAsync( $"En {System.Reflection.MethodBase.GetCurrentMethod()}",
|
|
// $"En método {System.Reflection.MethodBase.GetCurrentMethod()}. {Environment.MachineName} {cadenaError}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// if (NumeroDeLineasEnElArchivoCSV(nombreArchivoTemporal) <= 1)
|
|
// {
|
|
// throw new Exception("El archivo CSV que se ha generado solamente tiene la línea de la cabecera, es decir, no lleva información de ninguna póliza, por lo cual no tiene sentido mandarlo.");
|
|
// }
|
|
|
|
// archivoCSV = File.ReadAllBytes(nombreArchivoTemporal);
|
|
// try
|
|
// {
|
|
// File.Delete(nombreArchivoTemporal);
|
|
// }
|
|
// catch
|
|
// {
|
|
// // Nada, a propósito
|
|
// }
|
|
|
|
// return archivoCSV;
|
|
// }
|
|
|
|
// public static byte[] GenerarCsvTractoresAxa(tscgestionasegasa bd, string cadenaListaPolizas = null)
|
|
// {
|
|
// byte[] archivoCSV = null;
|
|
// var listaPolizas = new List<polizassg>();
|
|
// int idRamoTractores = bd.ramos.Where(x => x.Codigo == "1-1").Select(x => x.idRamo).FirstOrDefault();
|
|
// int idRamoRemolques = bd.ramos.Where(x => x.Codigo == "1-1-1").Select(x => x.idRamo).FirstOrDefault();
|
|
// int idCiaAXA = bd.companias.Where(x => x.Codigo == "0027").Select(x => x.idCompania).FirstOrDefault();
|
|
|
|
// var listaCadenasSeparadasPorComas = cadenaListaPolizas.Split(',').ToList();
|
|
// foreach (var x in listaCadenasSeparadasPorComas)
|
|
// {
|
|
// if (x.Contains("-"))
|
|
// {
|
|
// var subListaRangos = x.Split('-').ToList();
|
|
// if (subListaRangos.Count == 2)
|
|
// {
|
|
// uint iRangoDesde = uint.Parse(subListaRangos.First().Trim());
|
|
// uint iRangoHasta = uint.Parse(subListaRangos.Last().Trim());
|
|
|
|
// var results = bd.polizassg.Where(y =>
|
|
// (y.idRamoNavigation.idRamo == idRamoTractores || y.idRamoNavigation.idRamo == idRamoRemolques) &&
|
|
// y.idCompania == idCiaAXA &&
|
|
// y.idOrigenPresupuesto == (int)bdAsegasa.db.polizassg.TiposPresupuestos.TRACTORES &&
|
|
// (Convert.ToUInt32(y.NumeroPoliza) >= iRangoDesde && Convert.ToUInt32(y.NumeroPoliza) <= iRangoHasta)
|
|
// ).OrderBy(y => y.NumeroPoliza).ToList();
|
|
|
|
// listaPolizas.AddRange(results);
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new FormatException($"Error con el formato de los rangos de números de pólizas especificados: {cadenaListaPolizas}");
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// string sNumeroPoliza = x.Trim();
|
|
// var temp = bd.polizassg.First(y => y.NumeroPoliza == sNumeroPoliza);
|
|
// listaPolizas.Add(temp);
|
|
// }
|
|
// }
|
|
|
|
// foreach (var poliza in listaPolizas)
|
|
// {
|
|
// Debug.WriteLine($"[{poliza.idPoliza},{poliza.NumeroPoliza},{poliza.Matricula}]");
|
|
// }
|
|
|
|
// archivoCSV = GenerarCsvTractoresAxa(bd, listaPolizas);
|
|
// return archivoCSV;
|
|
// }
|
|
|
|
// public static byte[] GenerarCsvTractoresAxa(tscgestionasegasa bd, DateTime fechaDesde, DateTime fechaHasta)
|
|
// {
|
|
// byte[] archivoCSV = null;
|
|
// int idRamoTractores = bd.ramos.Where(x => x.Codigo == "1-1").Select(x => x.idRamo).FirstOrDefault();
|
|
// int idRamoRemolques = bd.ramos.Where(x => x.Codigo == "1-1-1").Select(x => x.idRamo).FirstOrDefault();
|
|
// int idCiaAXA = bd.companias.Where(x => x.Codigo == "0027").Select(x => x.idCompania).FirstOrDefault();
|
|
|
|
// var listaAltas = bd.polizassg.Where(x =>
|
|
// (x.idRamoNavigation.idRamo == idRamoTractores || x.idRamoNavigation.idRamo == idRamoRemolques) &&
|
|
// x.idCompania == idCiaAXA &&
|
|
// x.idOrigenPresupuesto == (int)bdAsegasa.db.polizassg.TiposPresupuestos.TRACTORES
|
|
// ).ToList();
|
|
|
|
// var listaAltasFiltradasPorFecha = listaAltas.Where(x =>
|
|
// x.FechaAlta.HasValue && x.FechaAlta.Value.Date <= fechaHasta &&
|
|
// x.FechaAlta.HasValue && x.FechaAlta.Value.Date >= fechaDesde
|
|
// ).ToList();
|
|
|
|
// archivoCSV = GenerarCsvTractoresAxa(bd, listaAltasFiltradasPorFecha);
|
|
// return archivoCSV;
|
|
// }
|
|
|
|
// private static string ComponerLineaCsv(polizassg poliza, tscgestionasegasa bd)
|
|
// {
|
|
// var sb = new StringBuilder();
|
|
// try
|
|
// {
|
|
// var listaDatosFaltantes = new List<string>();
|
|
|
|
// // Assuming poliza.Tractores is available dynamically or strongly typed via partial
|
|
// dynamic pTractores = ((dynamic)poliza).Tractores;
|
|
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TipoVehiculo)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TipoVehiculo");
|
|
// if (string.IsNullOrWhiteSpace((poliza.FechaEfecto).ToString("ddMMyyyy"))) listaDatosFaltantes.Add("poliza.FechaEfecto");
|
|
// if (string.IsNullOrWhiteSpace(((string)poliza.Tomador.CIF)?.Trim())) listaDatosFaltantes.Add("poliza.Tomador.CIF");
|
|
|
|
// if (ObtenerTipoDocumentoTractoresAxa((string)poliza.Tomador.CIF) != bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.tipoDoc.PersJuridicaCIF").ValorAlfabeticoLargo)
|
|
// {
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorApellido1)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorApellido1");
|
|
// }
|
|
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorNombre)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorNombre");
|
|
// if (string.IsNullOrWhiteSpace(((DateTime)pTractores.TomadorFechaNacimiento).ToString("ddMMyyyy"))) listaDatosFaltantes.Add("poliza.Tractores.TomadorFechaNacimiento");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.EstadoCivil)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.EstadoCivil");
|
|
|
|
// if (ObtenerTipoDocumentoTractoresAxa((string)poliza.Tomador.CIF) != bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.tipoDoc.PersJuridicaCIF").ValorAlfabeticoLargo)
|
|
// {
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorSexo?.ToString()))) listaDatosFaltantes.Add("poliza.Tractores.TomadorSexo");
|
|
// }
|
|
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorCodigoPostal)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorCodigoPostal");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorPoblacion)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorPoblacion");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorVia)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorVia");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorNombreVia)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorNombreVia");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorNumeroVia)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorNumeroVia");
|
|
|
|
// if (poliza.Propietario != null)
|
|
// {
|
|
// if (ObtenerTipoDocumentoTractoresAxa((string)poliza.Propietario.CIF) != bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.tipoDoc.PersJuridicaCIF").ValorAlfabeticoLargo)
|
|
// {
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.PropietarioSexo?.ToString()))) listaDatosFaltantes.Add("poliza.Tractores.PropietarioSexo");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.PropietarioApellido1)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.PropietarioApellido1");
|
|
// }
|
|
// if (poliza.Propietario.idEntidad != poliza.Tomador.idEntidad)
|
|
// {
|
|
// if (string.IsNullOrWhiteSpace(((string)poliza.Propietario.Nombre)?.Trim()) && (ObtenerTipoDocumentoTractoresAxa((string)poliza.Propietario.CIF) != bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.tipoDoc.PersJuridicaCIF").ValorAlfabeticoLargo))
|
|
// {
|
|
// listaDatosFaltantes.Add("poliza.propietario.nombre");
|
|
// }
|
|
// if (string.IsNullOrWhiteSpace(((string)poliza.Propietario.CIF)?.Trim())) listaDatosFaltantes.Add("poliza.Propietario.CIF");
|
|
// }
|
|
// }
|
|
|
|
// if (poliza.Conductor == null || poliza.Conductor.idEntidad == poliza.Tomador.idEntidad)
|
|
// {
|
|
// DateTime fechaPermiso = (DateTime)pTractores.FechaPermisoConduccion;
|
|
// if (!(fechaPermiso > DateTime.MinValue && fechaPermiso < DateTime.MaxValue))
|
|
// {
|
|
// listaDatosFaltantes.Add("poliza.Tractores.FechaPermisoConduccion");
|
|
// }
|
|
// if (string.IsNullOrWhiteSpace(fechaPermiso.ToString("ddMMyyyy"))) listaDatosFaltantes.Add("poliza.Tractores.FechaPermisoConduccion");
|
|
// }
|
|
// else
|
|
// {
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.ConductorNombre)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.ConductorNombre");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.ConductorApellido1)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.ConductorApellido1");
|
|
// if (string.IsNullOrWhiteSpace(((DateTime)pTractores.ConductorFechaNacimiento).ToString("ddMMyyyy"))) listaDatosFaltantes.Add("poliza.Tractores.ConductorFechaNacimiento");
|
|
// if (string.IsNullOrWhiteSpace(((string)poliza.Conductor.CIF)?.Trim())) listaDatosFaltantes.Add("poliza.Conductor.CIF");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.ConductorSexo?.ToString()))) listaDatosFaltantes.Add("poliza.Tractores.ConductorSexo");
|
|
// if (string.IsNullOrWhiteSpace(((DateTime)pTractores.FechaPermisoConduccion).ToString("ddMMyyyy"))) listaDatosFaltantes.Add("poliza.Tractores.FechaPermisoConduccion");
|
|
// }
|
|
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.UsoVehiculo)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.UsoVehiculo");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.Peso?.ToString())?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.Peso");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.Marca)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.Marca");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.Modelo)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.Modelo");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.Version)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.Version");
|
|
// if (string.IsNullOrWhiteSpace(poliza.Matricula?.ToUpper().Trim())) listaDatosFaltantes.Add("poliza.Matricula");
|
|
// if (string.IsNullOrWhiteSpace(((DateTime)pTractores.FechaPrimeraMatriculacion).ToString("ddMMyyyy"))) listaDatosFaltantes.Add("poliza.Tractores.FechaPrimeraMatriculacion");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.TomadorCodigoPostal)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.TomadorCodigoPostal");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.CombinacionAccidentes)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.CombinacionAccidentes");
|
|
// if (string.IsNullOrWhiteSpace(((string)pTractores.PrimaTotal)?.Trim())) listaDatosFaltantes.Add("poliza.Tractores.PrimaTotal");
|
|
|
|
// if (listaDatosFaltantes.Count > 0)
|
|
// {
|
|
// var sbDatosFaltantes = new StringBuilder();
|
|
// foreach (var l in listaDatosFaltantes)
|
|
// {
|
|
// sbDatosFaltantes.AppendFormat("{0}, ", l);
|
|
// }
|
|
// throw new Exception($"No se puede componer esta línea del CSV porque faltan datos en la póliza idPoliza = {poliza.idPoliza}; Lista de datos faltantes: {sbDatosFaltantes.ToString().TrimEnd(',', ' ')}");
|
|
// }
|
|
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TipoVehiculo).Trim());
|
|
// sb.AppendFormat("=\"{0}\";", "001");
|
|
// sb.AppendFormat("=\"{0}\";", "001");
|
|
// sb.AppendFormat("{0};", "674392");
|
|
// sb.AppendFormat("=\"{0}\";", (poliza.FechaEfecto).ToString("ddMMyyyy"));
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "8184");
|
|
// sb.AppendFormat("{0};", poliza.NumeroPoliza?.Trim());
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "Anual Renovable");
|
|
// sb.AppendFormat("{0};", "Anual");
|
|
// sb.AppendFormat("{0};", "Mediador");
|
|
// sb.AppendFormat("{0};", "");
|
|
|
|
// sb.AppendFormat("{0};", ObtenerTipoDocumentoTractoresAxa((string)poliza.Tomador.CIF));
|
|
// sb.AppendFormat("{0};", ((string)poliza.Tomador.CIF).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorApellido1)?.Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorApellido2)?.Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorNombre)?.Trim());
|
|
// sb.AppendFormat("=\"{0}\";", ((DateTime)pTractores.TomadorFechaNacimiento).ToString("ddMMyyyy"));
|
|
// sb.AppendFormat("{0};", ((string)pTractores.EstadoCivil).Trim());
|
|
|
|
// if (ObtenerTipoDocumentoTractoresAxa((string)poliza.Tomador.CIF) == bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.tipoDoc.PersJuridicaCIF").ValorAlfabeticoLargo)
|
|
// {
|
|
// sb.AppendFormat("{0};", bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.sexo.SinInformar").ValorAlfabetico1);
|
|
// }
|
|
// else
|
|
// {
|
|
// sb.AppendFormat("{0};", ObtenerSexoTractoresAxa(((object)pTractores.TomadorSexo)?.ToString(), bd));
|
|
// }
|
|
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorCodigoPostal).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorPoblacion).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorVia).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorNombreVia).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorNumeroVia).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.TomadorRestoVia)?.Trim() ?? "");
|
|
|
|
// if (poliza.Propietario == null || poliza.Propietario.idEntidad == poliza.Tomador.idEntidad)
|
|
// {
|
|
// sb.AppendFormat("{0};", "El Tomador");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// }
|
|
// else
|
|
// {
|
|
// if (ObtenerTipoDocumentoTractoresAxa((string)poliza.Propietario.CIF) != bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.tipoDoc.PersJuridicaCIF").ValorAlfabeticoLargo)
|
|
// {
|
|
// sb.AppendFormat("{0};", "Otra persona distinta del Tomador");
|
|
// sb.AppendFormat("{0};", ((string)poliza.Propietario.Nombre).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.PropietarioApellido1).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.PropietarioApellido2)?.Trim() ?? "");
|
|
// sb.AppendFormat("{0};", ((string)poliza.Propietario.CIF).Trim());
|
|
// }
|
|
// else
|
|
// {
|
|
// sb.AppendFormat("{0};", "Otra persona distinta del Tomador");
|
|
// sb.AppendFormat("{0};", ((string)poliza.Propietario.Nombre).Trim());
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", ((string)poliza.Propietario.CIF).Trim());
|
|
// }
|
|
// }
|
|
|
|
// if (poliza.Conductor== null || poliza.Conductor.idEntidad == poliza.Tomador.idEntidad)
|
|
// {
|
|
// sb.AppendFormat("{0};", "El Tomador");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("=\"{0}\";", ((DateTime)pTractores.FechaPermisoConduccion).ToString("ddMMyyyy"));
|
|
// }
|
|
// else
|
|
// {
|
|
// sb.AppendFormat("{0};", "Es otra persona");
|
|
// sb.AppendFormat("{0};", ((string)pTractores.ConductorNombre).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.ConductorApellido1).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.ConductorApellido2)?.Trim() ?? "");
|
|
// sb.AppendFormat("=\"{0}\";", ((DateTime)pTractores.ConductorFechaNacimiento).ToString("ddMMyyyy"));
|
|
// sb.AppendFormat("{0};", ObtenerTipoDocumentoTractoresAxa((string)poliza.Conductor.CIF));
|
|
// sb.AppendFormat("{0};", ((string)poliza.Conductor.CIF).Trim());
|
|
// sb.AppendFormat("{0};", ObtenerSexoTractoresAxa(((object)pTractores.ConductorSexo)?.ToString(), bd));
|
|
// sb.AppendFormat("=\"{0}\";", ((DateTime)pTractores.FechaPermisoConduccion).ToString("ddMMyyyy"));
|
|
// }
|
|
|
|
// sb.AppendFormat("{0};", "No se declara");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
|
|
// sb.AppendFormat("{0};", "No se declara");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
|
|
// sb.AppendFormat("{0};", "No");
|
|
// sb.AppendFormat("{0};", ((string)pTractores.UsoVehiculo).Trim());
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", ((object)pTractores.Peso).ToString().Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.Marca).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.Modelo).Trim());
|
|
// sb.AppendFormat("{0};", ((string)pTractores.Version).Trim());
|
|
// sb.AppendFormat("{0};", "35.000");
|
|
// sb.AppendFormat("=\"{0}\";", "0,00");
|
|
// sb.AppendFormat("{0};", poliza.Matricula.ToUpper().Trim());
|
|
// sb.AppendFormat("=\"{0}\";", ((DateTime)pTractores.FechaPrimeraMatriculacion).ToString("ddMMyyyy"));
|
|
// sb.AppendFormat("=\"{0}\";", ((string)pTractores.TomadorCodigoPostal).Trim());
|
|
// sb.AppendFormat("{0};", "NO");
|
|
// sb.AppendFormat("{0};", "NO");
|
|
// sb.AppendFormat("{0};", "Sin definir");
|
|
// sb.AppendFormat("{0};", "Terceros sin Asistencia");
|
|
// sb.AppendFormat("{0};", ((string)pTractores.CombinacionAccidentes).Trim());
|
|
// sb.AppendFormat("{0};", "Si");
|
|
// sb.AppendFormat("{0};", ((string)pTractores.PrimaTotal).Trim());
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0};", "");
|
|
// sb.AppendFormat("{0}", "");
|
|
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw new Exception(ex.Message, ex);
|
|
// }
|
|
// return sb.ToString();
|
|
// }
|
|
|
|
// public static int PrepararCorreosCsvTractoresAxa(tscgestionasegasa bd)
|
|
// {
|
|
// const bool danmundebug = false;
|
|
// int resultadoGuardarCambios = 0;
|
|
// try
|
|
// {
|
|
// DateTime dHoy = DateTime.Today;
|
|
// DateTime dAyer = DateTime.Today.AddDays(-1);
|
|
// int idTipoGestionPoliza = bd.enumeraciones.First(x => x.Codigo == "TGP.CSVAXA").idEnumeracion;
|
|
// int idTipoFicheroCSV = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.CSVAXA").idEnumeracion;
|
|
|
|
// var lineasPendientesCorreoCsv = bd.gestionesvarias
|
|
// .Where(x => x.idTipo == idTipoGestionPoliza && !x.FechaProcesado.HasValue)
|
|
// .ToList();
|
|
|
|
// foreach (var linea in lineasPendientesCorreoCsv)
|
|
// {
|
|
// var listaDestinatarios = bd.enumeraciones
|
|
// .Where(x => x.Codigo.StartsWith("AXATRACTORES.email.destinatario"))
|
|
// .Select(x => x.ValorAlfabeticoLargo.Trim())
|
|
// .ToList();
|
|
|
|
// string asunto = $"{bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.email.asunto").ValorAlfabeticoLargo.Trim()} {linea.idFicheroNavigation?.Descripcion?.Split(' ').Last()}";
|
|
// string cuerpo = $"{bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.email.cuerpo").ValorAlfabeticoLargo.Trim()} {linea.idFicheroNavigation?.Descripcion?.Split(' ').Last()}";
|
|
|
|
// var cuentaCorreo = bd.cuentascorreo.First(x => x.Codigo == "CSVAXA");
|
|
|
|
// foreach (var destinatario in listaDestinatarios)
|
|
// {
|
|
// // Use GeneraRegistroCorreo using the proper signature defined in bdAsegasa
|
|
// // The VB is calling `bdGestionAsegasa.correos.GeneraRegistroCorreo(bd, asunto, cuerpo, cuentaCorreo, destinatario,,, linea.idFichero)`.
|
|
// bdAsegasa.db.correos.GeneraRegistroCorreo(bd, asunto, cuerpo, cuentaCorreo, destinatario, null, null, linea.idFichero);
|
|
// }
|
|
|
|
// linea.FechaProcesado = DateTime.Now;
|
|
// if (!danmundebug) resultadoGuardarCambios += bd.SaveChanges();
|
|
|
|
// if (resultadoGuardarCambios > 0)
|
|
// {
|
|
// try
|
|
// {
|
|
// var mensaje = new StringBuilder();
|
|
// mensaje.AppendFormat("Se ha generado un email para AXA conteniendo el archivo CSV con altas de tractores y/o remolques para AXA.```Asunto: {1}{0}Servidor: {2}```",
|
|
// Environment.NewLine, asunto, Environment.MachineName);
|
|
// }
|
|
// catch { }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Debug.WriteLine("No hay líneas o se produjo excepción.");
|
|
// _ = tsUtilidades.TsNotificacionesClient.RegistrarAsync($"En {System.Reflection.MethodBase.GetCurrentMethod()}",
|
|
// $"En método {System.Reflection.MethodBase.GetCurrentMethod()}. {Environment.MachineName} {ex.ToString()}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// return resultadoGuardarCambios;
|
|
// }
|
|
|
|
// public static bool YaSeEnvioCsvParaAyer(tscgestionasegasa bd)
|
|
// {
|
|
// int idTipoGestionPoliza = bd.enumeraciones.First(x => x.Codigo == "TGP.CSVAXA").idEnumeracion;
|
|
// DateTime dAyer = DateTime.Today.AddDays(-1);
|
|
// string sDescripcion = $"{bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.NombreFicheroCSV").ValorAlfabeticoLargo}{dAyer:yyyy-MM-dd}.csv";
|
|
|
|
// return bd.gestionesvarias.Any(x => x.idTipo == idTipoGestionPoliza && x.FechaProcesado.HasValue && x.Descripción == sDescripcion);
|
|
// }
|
|
|
|
// public static bool YaSeEnvioCsvParaHoy(tscgestionasegasa bd)
|
|
// {
|
|
// int idTipoGestionPoliza = bd.enumeraciones.First(x => x.Codigo == "TGP.CSVAXA").idEnumeracion;
|
|
// string sDescripcion = $"{bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.NombreFicheroCSV").ValorAlfabeticoLargo}{DateTime.Today:yyyy-MM-dd}.csv";
|
|
|
|
// return bd.gestionesvarias.Any(x => x.idTipo == idTipoGestionPoliza && x.FechaProcesado.HasValue && x.Descripción == sDescripcion);
|
|
// }
|
|
|
|
// public static int NumeroDeLineasEnElArchivoCSV(string rutaArchivoCSV)
|
|
// {
|
|
// return File.ReadLines(rutaArchivoCSV).Count();
|
|
// }
|
|
|
|
// private static int ComprobarCuantosNumerosReservadosQuedanDisponibles(int nActual, enumeraciones inicio, enumeraciones fin)
|
|
// {
|
|
|
|
|
|
// if(fin.ValorNumerico1 != null)
|
|
// {
|
|
|
|
// }
|
|
// return (int)(fin.ValorNumerico1 ?? 0) - nActual;
|
|
// }
|
|
|
|
// private static string ObtenerTipoDocumentoTractoresAxa(string numeroDocumento)
|
|
// {
|
|
// // Assuming string extension TipoDocumentoIdentidad mapped inside C# as tsUtilidades.Mobiles.Validaciones.ObtenerTipo(numeroDocumento)
|
|
// // The enum `tsl5.ValidarDocumentoIdentidad.TiposDocumentosEnum.CIF` translates to some util module enum.
|
|
// // Simplified CIF check based on letter if no tsUtilidades available, but we use the library.
|
|
// // If it starts with typical CIF letters A B C D E F G H J N P Q R S U V W
|
|
// var initChar = char.ToUpperInvariant(numeroDocumento.FirstOrDefault());
|
|
// string cifLetters = "ABCDEFGHJNPQRSUVW";
|
|
// if (cifLetters.Contains(initChar))
|
|
// {
|
|
// return "CIF";
|
|
// }
|
|
// return "NIF";
|
|
// }
|
|
|
|
// private static string ObtenerSexoTractoresAxa(string cadenaSexo, tscgestionasegasa bd)
|
|
// {
|
|
// string resultado = bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.sexo.SinInformar").ValorAlfabetico1;
|
|
// string axaHombre = bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.sexo.Hombre").ValorAlfabetico1;
|
|
// string axaMujer = bd.enumeraciones.First(x => x.Codigo == "AXATRACTORES.sexo.Mujer").ValorAlfabetico1;
|
|
|
|
// string idEnumSexoHombre = bd.enumeraciones.First(x => x.Codigo == "SEXO.HOMBRE").idEnumeracion.ToString();
|
|
// string idEnumSexoMujer = bd.enumeraciones.First(x => x.Codigo == "SEXO.MUJER").idEnumeracion.ToString();
|
|
|
|
// if (cadenaSexo == idEnumSexoHombre) resultado = axaHombre;
|
|
// if (cadenaSexo == idEnumSexoMujer) resultado = axaMujer;
|
|
|
|
// return resultado;
|
|
// }
|
|
// }
|
|
//}
|