agregado procesos y bd clases

This commit is contained in:
2026-04-28 11:52:16 +02:00
parent 59a774c397
commit cd2e8b8530
251 changed files with 56881 additions and 49 deletions

View File

@@ -0,0 +1,197 @@
using bdAsegasa.dbcontext;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
namespace bdAsegasa.Informes
{
public class CarteraPerdida
{
public static byte[] GeneraExcelCarteraPerdidaEF(DateOnly fi, DateOnly ff)
{
try
{
var bd = tscgestionasegasa.NuevoContexto();
var fai = fi.AddYears(-1);
var faf = ff.AddYears(-1);
var idLiquidacion = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.LIQUIDACION").idEnumeracion;
var idLiquidacioncia = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.PGDO.CIA").idEnumeracion;
var iddevuelto = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.DEVUELTO").idEnumeracion;
var idDescobro = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.DESCOBRO").idEnumeracion;
var idCabaPGO = bd.enumeraciones.First(x => x.Codigo == "CABA.PGO").idEnumeracion;
var idCabaFP = bd.enumeraciones.First(x => x.Codigo == "CABA.FP").idEnumeracion;
var idTrex = bd.enumeraciones.First(x => x.Codigo == "TRC.EX").idEnumeracion;
var idTrcx = bd.enumeraciones.First(x => x.Codigo == "TRC.CX").idEnumeracion;
var idDuru = bd.enumeraciones.First(x => x.Codigo == "DUR.U").idEnumeracion;
var lr = new List<ReciboCarteraPerdida>();
var ps = bd.polizassg.Select(x => new { idpoliza = x.idPoliza, idDuracion = x.idDuracion, idCausaBaja = x.idCausaBaja, FechaBaja = x.FechaBaja, NumeroPoliza = x.NumeroPoliza, idCompania = x.idCompania, NumeroSuplemento = x.NumeroSuplemento, FechaVencimiento = x.FechaVencimiento }).ToList();
var POLS = ps.Where(p => p.NumeroPoliza != null)
.GroupBy(p => new { p.NumeroPoliza, p.idCompania })
.Select(g => g.OrderByDescending(Y => Y.NumeroSuplemento).FirstOrDefault())
.Where(X => X.FechaBaja.HasValue == false || (X.idCausaBaja.HasValue && X.idCausaBaja == idCabaFP))
.ToList();
var recsex = bd.vf_recibosextendidos.Where(x => x.FechaEfecto >= fai && x.FechaEfecto <= faf && x.idTipo != idTrex && x.idTipo != idTrcx && x.idDuracion != idDuru)
.Select(x => new { idRecibo = x.idRecibo, Tomador = x.Tomador }).ToList();
var recsant = bd.recibos.Where(x => x.FechaEfecto >= fai && x.FechaEfecto <= faf && x.idTipo != idTrex && x.idTipo != idTrcx && x.idPolizaNavigation.idDuracion != idDuru &&
(x.liquidacionescompaniasrecibos.Any(y => y.idLiquidacionCiaNavigation.idTipoLiquidacion == idLiquidacion || y.idLiquidacionCiaNavigation.idTipoLiquidacion == idLiquidacioncia) ||
(x.liquidacionescompaniasrecibos.Any(y => y.idLiquidacionCiaNavigation.idTipoLiquidacion == iddevuelto && x.idCausaBaja == idCabaPGO))))
.Select(x => new ReciboCarteraPerdida
{
NumeroPoliza = x.idPolizaNavigation.NumeroPoliza,
idRecibo = x.idRecibo.ToString(),
idCompañia = x.idPolizaNavigation.idCompania,
Compañía = x.idPolizaNavigation.idCompaniaNavigation.Nombre,
Ramo = x.idPolizaNavigation.idRamoNavigation.Descripcion,
FechaEfecto = new DateTime(x.FechaEfecto.Year, x.FechaEfecto.Month, x.FechaEfecto.Day),
Observaciones = x.idPolizaNavigation.Observaciones
}).ToList();
var recs = bd.recibos.Where(x => x.FechaEfecto >= fi && x.FechaEfecto <= ff && x.TotalRecibo > 0 && x.idPolizaNavigation.idDuracion != idDuru)
.Select(x => new ReciboCarteraPerdida
{
NumeroPoliza = x.idPolizaNavigation.NumeroPoliza,
idRecibo = x.idRecibo.ToString(),
idCompañia = x.idPolizaNavigation.idCompania,
Compañía = x.idPolizaNavigation.idCompaniaNavigation.Nombre,
Ramo = x.idPolizaNavigation.idRamoNavigation.Descripcion,
FechaEfecto = new DateTime(x.FechaEfecto.Year, x.FechaEfecto.Month, x.FechaEfecto.Day),
Observaciones = x.idPolizaNavigation.Observaciones
}).ToList();
var flim = DateOnly.FromDateTime(DateTime.Now).AddYears(-1);
foreach (var r in recsant)
{
if (lr.Any(X => X.NumeroPoliza == r.NumeroPoliza && X.idCompañia == r.idCompañia) == false &&
recs.Any(x => x.NumeroPoliza == r.NumeroPoliza && x.idCompañia == r.idCompañia) == false &&
POLS.Any(x => x.NumeroPoliza == r.NumeroPoliza && x.idCompania == r.idCompañia && !(x.idDuracion == idDuru && x.FechaVencimiento < flim)))
{
r.Tomador = recsex.First(x => x.idRecibo.ToString() == r.idRecibo).Tomador;
lr.Add(r);
}
}
if (lr.Count > 0)
{
var lrd = lr.OrderBy(x => x.Compañía).ThenBy(x => x.Ramo).Select(x => new { x.NumeroPoliza, x.Compañía, x.Ramo, x.Tomador, FechaEfectoUltimoRecibo = x.FechaEfecto, x.Observaciones }).ToList();
byte[] b = tsUtilidades.Excel.IEnumerableAExcel(lrd);
return b;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
public static byte[] GeneraExcelCarteraPerdida(DateTime fi)
{
try
{
var bd = tscgestionasegasa.NuevoContexto();
var idLiquidacion = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.LIQUIDACION").idEnumeracion;
var idLiquidacioncia = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.PGDO.CIA").idEnumeracion;
var fiDate = DateOnly.FromDateTime(fi);
var iddevuelto = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.DEVUELTO").idEnumeracion;
var idDescobro = bd.enumeraciones.First(x => x.Codigo == "TIPLIQ.DESCOBRO").idEnumeracion;
var idTrex = bd.enumeraciones.First(x => x.Codigo == "TRC.EX").idEnumeracion;
var idTrcx = bd.enumeraciones.First(x => x.Codigo == "TRC.CX").idEnumeracion;
var idDuru = bd.enumeraciones.First(x => x.Codigo == "DUR.U").idEnumeracion;
var lr = new List<ReciboCarteraPerdida>();
var ps = bd.polizassg.Select(x => new { idpoliza = x.idPoliza, idDuracion = x.idDuracion, idCausaBaja = x.idCausaBaja, FechaBaja = x.FechaBaja, NumeroPoliza = x.NumeroPoliza, idCompania = x.idCompania, NumeroSuplemento = x.NumeroSuplemento, FechaVencimiento = x.FechaVencimiento }).ToList();
var POLS = ps.Where(p => p.NumeroPoliza != null)
.GroupBy(p => new { p.NumeroPoliza, p.idCompania })
.Select(g => g.OrderByDescending(Y => Y.NumeroSuplemento).FirstOrDefault())
.Where(X => X.FechaBaja.HasValue == false).ToList();
var recsex = bd.vf_recibosextendidos.Where(x => x.FechaEfecto >= fiDate && x.idTipo != idTrex && x.idTipo != idTrcx && x.idDuracion != idDuru)
.Select(x => new { idRecibo = x.idRecibo, Tomador = x.Tomador, NumeroPoliza = x.NumeroPoliza, idCompania = x.idCompania, FechaVencimiento = x.FechaVencimiento }).ToList();
var recsant = bd.recibos.Where(x => x.FechaEfecto >= fiDate && x.FechaVencimiento <= DateOnly.FromDateTime(DateTime.Today) && x.idTipo != idTrex && x.idTipo != idTrcx && x.idPolizaNavigation.idDuracion != idDuru)
.Select(x => new ReciboCarteraPerdida
{
NumeroPoliza = x.idPolizaNavigation.NumeroPoliza,
idRecibo = x.idRecibo.ToString(),
idCompañia = x.idPolizaNavigation.idCompania,
Compañía = x.idPolizaNavigation.idCompaniaNavigation.Nombre,
Ramo = x.idPolizaNavigation.idRamoNavigation.Descripcion,
FechaEfecto = new DateTime(x.FechaEfecto.Year, x.FechaEfecto.Month, x.FechaEfecto.Day),
FechaVencimiento = new DateTime(x.FechaVencimiento.Year, x.FechaVencimiento.Month, x.FechaVencimiento.Day),
Observaciones = x.idPolizaNavigation.Observaciones
}).ToList();
DateOnly DentroUnMes = DateOnly.FromDateTime( fi.AddMonths(13));
var recs = bd.recibos.Where(x => x.FechaVencimiento >= DentroUnMes && x.TotalRecibo > 0 && x.idPolizaNavigation.idDuracion != idDuru)
.Select(x => new ReciboCarteraPerdida
{
NumeroPoliza = x.idPolizaNavigation.NumeroPoliza,
idRecibo = x.idRecibo.ToString(),
idCompañia = x.idPolizaNavigation.idCompania,
Compañía = x.idPolizaNavigation.idCompaniaNavigation.Nombre,
Ramo = x.idPolizaNavigation.idRamoNavigation.Descripcion,
FechaEfecto = new DateTime(x.FechaEfecto.Year, x.FechaEfecto.Month, x.FechaEfecto.Day),
Observaciones = x.idPolizaNavigation.Observaciones
}).ToList();
var flimduru = fi.AddYears(-1);
foreach (var r in recsant)
{
if (lr.Any(X => X.NumeroPoliza == r.NumeroPoliza && X.idCompañia == r.idCompañia) == false &&
recs.Any(x => x.NumeroPoliza == r.NumeroPoliza && x.idCompañia == r.idCompañia) == false &&
POLS.Any(x => x.NumeroPoliza == r.NumeroPoliza && x.idCompania == r.idCompañia && !(x.idDuracion == idDuru && x.FechaVencimiento < DateOnly.FromDateTime(flimduru))))
{
if (recsex.Any(x => x.NumeroPoliza == r.NumeroPoliza && x.idCompania == r.idCompañia && x.idRecibo.ToString() != r.idRecibo && x.FechaVencimiento > DateOnly.FromDateTime(r.FechaVencimiento.Value)) == false)
{
r.Tomador = recsex.First(x => x.idRecibo.ToString() == r.idRecibo).Tomador;
lr.Add(r);
}
}
}
if (lr.Count > 0)
{
var lrd = lr.OrderBy(x => x.Compañía).ThenBy(x => x.Ramo).Select(x => new { x.NumeroPoliza, x.Compañía, x.Ramo, x.Tomador, FechaEfectoUltimoRecibo = x.FechaEfecto, x.Observaciones }).ToList();
byte[] b = tsUtilidades.Excel.IEnumerableAExcel(lrd);
return b;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
private class ReciboCarteraPerdida
{
public string idRecibo { get; set; }
public string NumeroPoliza { get; set; }
public int? idCompañia { get; set; }
public string Compañía { get; set; }
public string Ramo { get; set; }
public string Tomador { get; set; }
public DateTime? FechaEfecto { get; set; }
public DateTime? FechaVencimiento { get; set; }
public string Observaciones { get; set; }
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
namespace bdAsegasa.Informes
{
public class CartillaSeguroGenerales
{
public string Rso { get; set; }
public string Cif { get; set; }
public List<PolizaGeneral> PolizasEntidad { get; set; }
public int NumDePolizas { get; set; }
public double TotalPagados { get; set; }
public double TotalAnulados { get; set; }
public double TotalCia { get; set; }
public double TotalPendiente { get; set; }
public string Cia { get; set; }
}
public class SiniestroGeneral
{
public int IdSiniestro { get; set; }
public string RefCompania { get; set; }
public string DescripcionSiniestro { get; set; }
public string DanoCliente { get; set; }
public string DanoContrario { get; set; }
public string Culpabilidad { get; set; }
public string FechaSiniestro { get; set; }
}
public class PolizaGeneral
{
public string NumeroPoliza { get; set; }
public string Ramo { get; set; }
public string Compañia { get; set; }
public List<ReciboPoliza> RecibosPolizas { get; set; }
public List<SiniestroGeneral> SiniestrosEntidad { get; set; }
}
public class ReciboPoliza
{
public DateTime FechaEfecto { get; set; }
public DateTime? FechaVencimiento { get; set; }
public double Importe { get; set; }
public string Matricula { get; set; }
public string Duracion { get; set; }
public string TipoPago { get; set; }
public string FechaPago { get; set; }
public string CausaBaja { get; set; }
public string FechaBaja { get; set; }
public string BienesAsegurados { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
namespace bdAsegasa.Informes
{
public class CombinacionCorrespondenciaPagosTelematicos
{
public string NumeroOperacion { get; set; }
public string FechaOperacion { get; set; }
public string Importe { get; set; }
public string Referencia { get; set; }
public string RazonSocial { get; set; }
public string DNI { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using bdAsegasa.db;
namespace bdAsegasa.Informes
{
public class DetallesPoliza
{
public string NumeroPropuesta { get; set; }
public string Compania { get; set; }
public string NumeroPoliza { get; set; }
public string NumeroSuplemento { get; set; }
public string FechaEnvioCompania { get; set; }
public string FechaRecibidoCompania { get; set; }
public string Duracion { get; set; }
public string FechaEfecto { get; set; }
public string FechaVencimiento { get; set; }
public string FechaBaja { get; set; }
public string CausaBaja { get; set; }
public string Ramo { get; set; }
public string Agente { get; set; }
public string SubAgente { get; set; }
public string BienesAsegurados { get; set; }
public string Matricula { get; set; }
public string Coberturas { get; set; }
public string Garantias { get; set; }
public string DescripcionSumplemento { get; set; }
public string FechaAceptacionPropuesta { get; set; }
public string SuplementoRechazdoPorCompania { get; set; }
public string Observaciones { get; set; }
public string Usuario { get; set; }
public string FechaAlta { get; set; }
public string TipoPago { get; set; }
public string IBAN { get; set; }
public string FechaMandato { get; set; }
public string TipoCobro { get; set; }
public string Directorio { get; set; }
public List<entidades> Tomador { get; set; }
public List<entidades> OtroAsegurado { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace bdAsegasa.Informes
{
public class DifPolSup
{
public string Compania { get; set; }
public string TomadorActual { get; set; }
public string NumPoliza { get; set; }
public string NumPropuesta { get; set; }
public string Ramo { get; set; }
public string Matricula { get; set; }
public string NumSuplemento { get; set; }
public List<Modificacion> ModEnPoliza { get; set; }
public List<Modificacion> ModEnAsegurados { get; set; }
public string Aclaracion1 { get; set; }
public string Aclaracion2 { get; set; }
}
public class Modificacion
{
public string Concepto { get; set; }
public string ValorNuevo { get; set; }
}
}

View File

@@ -0,0 +1,105 @@
using bdAsegasa.db;
using bdAsegasa.dbcontext;
using DevExpress.XtraReports.UI;
using Microsoft.EntityFrameworkCore;
using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using tsEFCore8;
using tsUtilidades;
using static Google.Protobuf.WellKnownTypes.FieldMask;
namespace bdAsegasa.Informes
{
public class Informes
{
public static void ImprimeInforme(XtraReport xr, object Datos, bool ImpresoraPredeterminada)
{
foreach (DevExpress.XtraReports.Parameters.Parameter pr in xr.Parameters)
{
pr.Visible = false;
}
xr.DataSource = Datos;
xr.CreateDocument(true);
if (ImpresoraPredeterminada)
{
xr.Print();
}
else
{
xr.Print();
}
}
public static MemoryStream GeneraXLSX(XtraReport xr, object Datos)
{
MemoryStream ms = new MemoryStream();
foreach (DevExpress.XtraReports.Parameters.Parameter pr in xr.Parameters)
{
pr.Visible = false;
}
xr.DataSource = Datos;
xr.CreateDocument(true);
xr.ExportToXlsx(ms);
return ms;
}
public static MemoryStream GeneraPDF(bdAsegasa.tscgestionasegasa bd, int idPlantilla, object Datasource)
{
try
{
if (idPlantilla == 0)
throw new Exception("Seleccione primero la plantilla a imprimir");
XtraReport xr = new XtraReport();
var plantillas = bd.plantillas.ToList();
var pl = plantillas.Where(x => x.idPlantilla == idPlantilla).First();
string s = Encoding.UTF8.GetString(pl.idFicheroNavigation.Fichero);
using (MemoryStream tempMs = new MemoryStream())
{
using (StreamWriter sw = new StreamWriter(tempMs, Encoding.UTF8, 1024, true))
{
sw.Write(s);
sw.Flush();
tempMs.Position = 0;
xr = XtraReport.FromStream(tempMs, true);
}
}
try
{
var pr = xr.Parameters.Cast<DevExpress.XtraReports.Parameters.Parameter>().FirstOrDefault(p => p.Name == "Fecha");
if (pr != null)
{
pr.Value = DateTime.Now;
pr.Visible = false;
}
}
catch
{
// Ignorar si el par<61>metro no existe
}
xr.DataSource = Datasource;
xr.CreateDocument(true);
MemoryStream ms = new MemoryStream();
xr.ExportToPdf(ms);
ms.Position = 0; // Importante para que quien reciba el stream pueda leerlo desde el inicio
return ms;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace bdAsegasa.Informes
{
public class InformesAgrarios
{
public List<LinInformesAgrarios> DatosLineas { get; set; }
}
public class LinInformesAgrarios
{
public string CodLinea { get; set; }
public string GruLinea { get; set; }
public string DesLinea { get; set; }
public string Compania { get; set; }
public int NumPolizas { get; set; }
public double PrimaNetaCalculo { get; set; }
public double ComAsegasa { get; set; }
public double ComAgentes { get; set; }
public double ComAsegasaPrev { get; set; }
public double ComAgentesPrev { get; set; }
public double TotComCob { get; set; }
public double TotComPrev { get; set; }
}
}