332 lines
12 KiB
C#
332 lines
12 KiB
C#
using bdAsegasa.dbcontext;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace bdAsegasa.db
|
|
{
|
|
public partial class entidades : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
public bool UltimoReciboDevueltoFaltaPago(string codigoRamo)
|
|
{
|
|
if (this.idEntidad == 0) return false;
|
|
using (var bd = tscgestionasegasa.NuevoContexto())
|
|
{
|
|
var ramo = bd.ramos.FirstOrDefault(x => x.Codigo == codigoRamo);
|
|
if (ramo == null) return false;
|
|
|
|
var idfp = bd.enumeraciones.FirstOrDefault(x => x.Codigo == "CABA.FP")?.idEnumeracion;
|
|
if (!idfp.HasValue) return false;
|
|
|
|
var rec = bd.entidadespolizas
|
|
.Where(x => x.idEntidad == this.idEntidad)
|
|
.Select(x => x.idPolizaNavigation)
|
|
.Where(x => x.idRamo == ramo.idRamo)
|
|
.SelectMany(x => x.recibos)
|
|
.OrderByDescending(x => x.FechaEfecto)
|
|
.FirstOrDefault();
|
|
|
|
return rec?.idCausaBaja == idfp;
|
|
}
|
|
}
|
|
|
|
public string Sexo => this.idSexoNavigation?.Descripcion ?? "* Desconocido *";
|
|
|
|
public direcciones DireccionPrincipal
|
|
{
|
|
get
|
|
{
|
|
if (this.idDireccionPrincipal.HasValue && this.idDireccionPrincipal.Value > 0)
|
|
{
|
|
return this.direcciones.FirstOrDefault(x => x.idDireccion == this.idDireccionPrincipal.Value);
|
|
}
|
|
var correo = this.direcciones.FirstOrDefault(x => x.idTipoNavigation?.Codigo == "TIPDIR.CORREO");
|
|
return correo ?? this.direcciones.FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
private string _codigoPostalTmp;
|
|
private bool _codigoPostalTmpEsNulo = true;
|
|
public string CodigoPostalTmp
|
|
{
|
|
get
|
|
{
|
|
if (_codigoPostalTmpEsNulo)
|
|
{
|
|
_codigoPostalTmp = DireccionPrincipal?.CodigoPostal ?? "";
|
|
_codigoPostalTmpEsNulo = false;
|
|
}
|
|
return _codigoPostalTmp;
|
|
}
|
|
set
|
|
{
|
|
_codigoPostalTmp = value;
|
|
_codigoPostalTmpEsNulo = false;
|
|
if (DireccionPrincipal != null) DireccionPrincipal.CodigoPostal = value;
|
|
OnPropertyChanged(nameof(CodigoPostalTmp));
|
|
}
|
|
}
|
|
|
|
private string _domicilioTmp;
|
|
private bool _domicilioTmpEsNulo = true;
|
|
public string DomicilioTmp
|
|
{
|
|
get
|
|
{
|
|
if (_domicilioTmpEsNulo)
|
|
{
|
|
_domicilioTmp = DireccionPrincipal?.Direccion ?? "";
|
|
_domicilioTmpEsNulo = false;
|
|
}
|
|
return _domicilioTmp;
|
|
}
|
|
set
|
|
{
|
|
_domicilioTmp = value;
|
|
_domicilioTmpEsNulo = false;
|
|
if (DireccionPrincipal != null) DireccionPrincipal.Direccion = value;
|
|
OnPropertyChanged(nameof(DomicilioTmp));
|
|
}
|
|
}
|
|
|
|
private string _codigoPoblacionTmp;
|
|
private bool _codigoPoblacionTmpEsNulo = true;
|
|
public string CodigoPoblacionTmp
|
|
{
|
|
get
|
|
{
|
|
if (_codigoPoblacionTmpEsNulo)
|
|
{
|
|
if (DireccionPrincipal == null || DireccionPrincipal.CodigoMunicipioNavigation == null)
|
|
{
|
|
if (DireccionPrincipal != null && DireccionPrincipal.CodigoMunicipioNavigation == null)
|
|
{
|
|
if (!string.IsNullOrEmpty(DireccionPrincipal.CodigoPostal))
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
var pob = bd.codigospostales.FirstOrDefault(x => x.CodigoPostal == DireccionPrincipal.CodigoPostal);
|
|
if (pob == null)
|
|
{
|
|
return "CP.ERRONEO";
|
|
}
|
|
else
|
|
{
|
|
DireccionPrincipal.CodigoMunicipio = pob.CodigoMunicipio;
|
|
_codigoPoblacionTmp = pob.CodigoMunicipio;
|
|
_codigoPoblacionTmpEsNulo = false;
|
|
return _codigoPoblacionTmp;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_codigoPoblacionTmp = DireccionPrincipal.CodigoMunicipio;
|
|
_codigoPoblacionTmpEsNulo = false;
|
|
return DireccionPrincipal.CodigoMunicipio;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return _codigoPoblacionTmp;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
_codigoPoblacionTmp = value;
|
|
_codigoPoblacionTmpEsNulo = false;
|
|
if (DireccionPrincipal != null) DireccionPrincipal.CodigoMunicipio = value;
|
|
OnPropertyChanged(nameof(CodigoPoblacionTmp));
|
|
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
var mun = bd.municipios.FirstOrDefault(x => x.CodigoMunicipio == _codigoPoblacionTmp);
|
|
ProvinciaTmp = mun?.CodigoProvinciaNavigation?.Nombre ?? "";
|
|
PoblacionTmp = mun?.Nombre ?? "";
|
|
}
|
|
}
|
|
|
|
private string _poblacionTmp;
|
|
private bool _poblacionTmpEsNulo = true;
|
|
public string PoblacionTmp
|
|
{
|
|
get
|
|
{
|
|
if (_poblacionTmpEsNulo)
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
var mun = bd.municipios.FirstOrDefault(x => x.CodigoMunicipio == CodigoPoblacionTmp);
|
|
_poblacionTmp = mun?.Nombre ?? "";
|
|
_poblacionTmpEsNulo = false;
|
|
}
|
|
return _poblacionTmp;
|
|
}
|
|
set
|
|
{
|
|
_poblacionTmp = value;
|
|
_poblacionTmpEsNulo = false;
|
|
OnPropertyChanged(nameof(PoblacionTmp));
|
|
}
|
|
}
|
|
|
|
private string _provinciaTmp;
|
|
private bool _provinciaTmpEsNulo = true;
|
|
public string ProvinciaTmp
|
|
{
|
|
get
|
|
{
|
|
if (_provinciaTmpEsNulo)
|
|
{
|
|
using var bd = bdAsegasa.tscgestionasegasa.NuevoContexto();
|
|
var mun = bd.municipios.FirstOrDefault(x => x.CodigoMunicipio == CodigoPoblacionTmp);
|
|
_provinciaTmp = mun?.CodigoProvinciaNavigation?.Nombre ?? "";
|
|
_provinciaTmpEsNulo = false;
|
|
}
|
|
return _provinciaTmp;
|
|
}
|
|
set
|
|
{
|
|
_provinciaTmp = value;
|
|
_provinciaTmpEsNulo = false;
|
|
OnPropertyChanged(nameof(ProvinciaTmp));
|
|
}
|
|
}
|
|
|
|
public string FechaNacimientoSinHora => this.FechaNacimiento?.ToString("dd/MM/yyyy") ?? "";
|
|
public string FechaExpCarnetSinHora => this.FechaExpedicionCarnet?.ToString("dd/MM/yyyy") ?? "";
|
|
|
|
public static void GuardandoCambios(tscgestionasegasa bd, string aplicacion)
|
|
{
|
|
var modifiedEnts = bd.ChangeTracker.Entries<entidades>()
|
|
.Where(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Modified);
|
|
|
|
foreach (var entry in modifiedEnts)
|
|
{
|
|
var ent = entry.Entity;
|
|
if (!string.IsNullOrEmpty(ent.CIF))
|
|
{
|
|
ent.CIF = Regex.Replace(ent.CIF, "[^a-zA-Z0-9]", "").ToUpper();
|
|
}
|
|
// Legacy logging logic can be implemented here if needed
|
|
}
|
|
}
|
|
|
|
public virtual List<EntidadRelacionada> RelacionesEntreEntidades
|
|
{
|
|
get
|
|
{
|
|
var entsh = this.entidadesrelacionadasidEntidadPadreNavigation.Select(x => new EntidadRelacionada {
|
|
RazonSocial = x.idEntidadHijoNavigation.RazonSocial,
|
|
TipoRelacion = EntidadRelacionada.TipoRelacionEntidadEnum.ES_HIJA,
|
|
CIF = x.idEntidadHijoNavigation.CIF,
|
|
EntRel = x
|
|
}).ToList();
|
|
|
|
var entsp = this.entidadesrelacionadasidEntidadHijoNavigation.Select(x => new EntidadRelacionada {
|
|
RazonSocial = x.idEntidadPadreNavigation.RazonSocial,
|
|
TipoRelacion = EntidadRelacionada.TipoRelacionEntidadEnum.ES_PADRE,
|
|
CIF = x.idEntidadPadreNavigation.CIF,
|
|
EntRel = x
|
|
}).ToList();
|
|
|
|
return entsh.Union(entsp).OrderBy(x => x.RazonSocial).ToList();
|
|
}
|
|
}
|
|
|
|
[NotMapped]
|
|
public class EntidadRelacionada
|
|
{
|
|
public int idEntidad { get; set; }
|
|
public string CIF { get; set; }
|
|
public TipoRelacionEntidadEnum TipoRelacion { get; set; }
|
|
public string DescripcionTipoRelacion => TipoRelacion.ToString().Replace("_", " ");
|
|
public string RazonSocial { get; set; }
|
|
public enum TipoRelacionEntidadEnum { ES_HIJA, ES_PADRE }
|
|
public virtual entidadesrelacionadas EntRel { get; set; }
|
|
}
|
|
}
|
|
|
|
public class ve_entidades
|
|
{
|
|
public int idEntidad { get; set; }
|
|
public string CIF { get; set; }
|
|
public string RazonSocial { get; set; }
|
|
public DateOnly? FechaNacimiento { get; set; }
|
|
public string Direccion { get; set; }
|
|
public string Poblacion { get; set; }
|
|
public string Provincia { get; set; }
|
|
public string Telefono1 { get; set; }
|
|
public string email { get; set; }
|
|
public bool EsTaller { get; set; }
|
|
public bool EsClienteSG { get; set; }
|
|
public bool EsClienteSA { get; set; }
|
|
public bool EsContrarioSiniestro { get; set; }
|
|
|
|
public string PoblacionYProvincia
|
|
{
|
|
get
|
|
{
|
|
if (this.Provincia == this.Poblacion)
|
|
{
|
|
return this.Poblacion;
|
|
}
|
|
else
|
|
{
|
|
return this.Poblacion + " (" + this.Provincia + ")";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ve_entidades_venta_cruzada
|
|
{
|
|
public int idEntidad { get; set; }
|
|
public string CIF { get; set; }
|
|
public string RazonSocial { get; set; }
|
|
public string Telefono1 { get; set; }
|
|
public string Telefono2 { get; set; }
|
|
public DateOnly? FechaNacimientoTomador { get; set; }
|
|
public string TelefonoMovilValido { get; set; }
|
|
public string Email { get; set; }
|
|
public int NumeroPolizas { get; set; }
|
|
public int idAgente { get; set; }
|
|
public string Agente { get; set; }
|
|
public int? idSubagente { get; set; }
|
|
public string SubAgente { get; set; }
|
|
public string TlfAgente { get; set; }
|
|
public string EmailAgente { get; set; }
|
|
public string TlfSubAgente { get; set; }
|
|
public string EmailSubAgente { get; set; }
|
|
public int NumeroCorreosVentaCruzada { get; set; }
|
|
public string Compañías { get; set; }
|
|
|
|
public string TelefonoSubAgenteAgente
|
|
{
|
|
get
|
|
{
|
|
if (!string.IsNullOrEmpty(TlfSubAgente))
|
|
{
|
|
return TlfSubAgente;
|
|
}
|
|
else
|
|
{
|
|
return TlfAgente;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|