313 lines
11 KiB
C#
313 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using tsUtilidades.Extensiones;
|
|
using tsUtilidades.Enumeraciones;
|
|
using System.ComponentModel.DataAnnotations.Schema; // Assuming enums might be here
|
|
|
|
namespace bdAsegasa.db
|
|
{
|
|
public partial class agentes
|
|
{
|
|
public string NombreYCodigo
|
|
{
|
|
get
|
|
{
|
|
return Nombre + " - " + Codigo;
|
|
}
|
|
}
|
|
|
|
public string CodigoYNombre
|
|
{
|
|
get
|
|
{
|
|
return Codigo + " - " + Nombre;
|
|
}
|
|
}
|
|
|
|
public virtual direcciones Direccion
|
|
{
|
|
get
|
|
{
|
|
if (this.idDireccion.HasValue && this.idDireccion.Value > 0)
|
|
{
|
|
return this.idDireccionNavigation;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _CodigoPostalTmpEsNulo = true;
|
|
private string _CodigoPostalTmp;
|
|
public string CodigoPostalTmp
|
|
{
|
|
get
|
|
{
|
|
if (_CodigoPostalTmpEsNulo)
|
|
{
|
|
if (Direccion == null)
|
|
{
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
_CodigoPostalTmp = Direccion.CodigoPostal;
|
|
_CodigoPostalTmpEsNulo = false;
|
|
return Direccion.CodigoPostal;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return _CodigoPostalTmp;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
_CodigoPostalTmp = value;
|
|
_CodigoPostalTmpEsNulo = false;
|
|
if (Direccion != null)
|
|
{
|
|
Direccion.CodigoPostal = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _DomicilioTmpEsNulo = true;
|
|
private string _DomicilioTmp;
|
|
public string DomicilioTmp
|
|
{
|
|
get
|
|
{
|
|
if (_DomicilioTmpEsNulo)
|
|
{
|
|
if (Direccion == null)
|
|
{
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
_DomicilioTmp = Direccion.Direccion;
|
|
_DomicilioTmpEsNulo = false;
|
|
return Direccion.Direccion;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return _DomicilioTmp;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
_DomicilioTmp = value;
|
|
_DomicilioTmpEsNulo = false;
|
|
if (Direccion != null)
|
|
{
|
|
Direccion.Direccion = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _CodigoPoblacionTmpEsNulo = true;
|
|
private string _CodigoPoblacionTmp;
|
|
public string CodigoPoblacionTmp
|
|
{
|
|
get
|
|
{
|
|
if (_CodigoPoblacionTmpEsNulo)
|
|
{
|
|
if (Direccion == null || Direccion.CodigoMunicipio == null) // In VB it was Direccion.municipios Is Nothing, which usually checks the foreign key or nav property. We use the key or check the DB.
|
|
{
|
|
if (Direccion != null && Direccion.CodigoMunicipioNavigation == null) // Try to get navigation property
|
|
{
|
|
if ((Direccion.CodigoPostal ?? "") != "")
|
|
{
|
|
var bd = tscgestionasegasa.NuevoContexto();
|
|
var pob = bd.codigospostales.FirstOrDefault(x => x.CodigoPostal == Direccion.CodigoPostal);
|
|
if (pob == null)
|
|
{
|
|
return "CP.ERRONEO";
|
|
}
|
|
else
|
|
{
|
|
Direccion.CodigoMunicipio = pob.CodigoMunicipio;
|
|
_CodigoPoblacionTmp = pob.CodigoMunicipio;
|
|
_CodigoPoblacionTmpEsNulo = false;
|
|
return _CodigoPoblacionTmp;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_CodigoPoblacionTmp = Direccion.CodigoMunicipio;
|
|
_CodigoPoblacionTmpEsNulo = false;
|
|
return Direccion.CodigoMunicipio;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return _CodigoPoblacionTmp;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
_CodigoPoblacionTmp = value;
|
|
_CodigoPoblacionTmpEsNulo = false;
|
|
if (Direccion != null)
|
|
{
|
|
Direccion.CodigoMunicipio = value;
|
|
}
|
|
ProvinciaTmp = municipios.ObtieneProvincia(_CodigoPoblacionTmp);
|
|
PoblacionTmp = municipios.ObtienePoblacion(_CodigoPoblacionTmp);
|
|
}
|
|
}
|
|
|
|
private string _PoblacionTmp;
|
|
private bool _PoblacionTmpEsNulo = true;
|
|
public string PoblacionTmp
|
|
{
|
|
get
|
|
{
|
|
if (_PoblacionTmpEsNulo) _PoblacionTmp = municipios.ObtienePoblacion(CodigoPoblacionTmp);
|
|
return _PoblacionTmp;
|
|
}
|
|
set
|
|
{
|
|
_PoblacionTmp = value;
|
|
_PoblacionTmpEsNulo = false;
|
|
}
|
|
}
|
|
|
|
private string _ProvinciaTmp;
|
|
private bool _ProvinciaTmpEsNulo = true;
|
|
public string ProvinciaTmp
|
|
{
|
|
get
|
|
{
|
|
if (_ProvinciaTmpEsNulo) _ProvinciaTmp = municipios.ObtieneProvincia(CodigoPoblacionTmp);
|
|
return _ProvinciaTmp;
|
|
}
|
|
set
|
|
{
|
|
_ProvinciaTmp = value;
|
|
_ProvinciaTmpEsNulo = false;
|
|
}
|
|
}
|
|
|
|
public string OficinaAgente
|
|
{
|
|
get
|
|
{
|
|
if (this.Codigo != "000029013008" && (this.Codigo.StartsWith("2") || this.Codigo.StartsWith("000004") || this.Codigo.StartsWith("000018") || this.Codigo.StartsWith("000023") || this.Codigo.StartsWith("000029") || this.Codigo.StartsWith("100029")))
|
|
{
|
|
return "Antequera";
|
|
}
|
|
else
|
|
{
|
|
return "Sevilla";
|
|
}
|
|
}
|
|
}
|
|
|
|
[NotMapped]
|
|
public virtual List<polizassg> PolizasConDocumentosPendientes
|
|
{
|
|
get
|
|
{
|
|
return this.polizassg.Where(x =>
|
|
(x.NumeroPoliza != null || x.FechaAceptacionPresupuesto.HasValue) &&
|
|
(x.FechaDocumentosSuplementoRevisado != null || x.NumeroSuplemento == 0 || x.idAgenteNavigation.Codigo == "1" || x.idAgenteNavigation.Codigo == "2") &&
|
|
x.documentospolizassg.Any(y => y.Obligatorio && y.FechaComprobacion == null && y.idFichero == null)
|
|
).ToList();
|
|
}
|
|
}
|
|
[NotMapped]
|
|
public virtual List<polizassg> PolizasConDocumentosPendientes7Dias
|
|
{
|
|
get
|
|
{
|
|
DateTime FechaInicio = DateTime.Today.AddDays(-7);
|
|
return this.polizassg.Where(x =>
|
|
x.FechaBaja.HasValue == false &&
|
|
(x.NumeroPoliza != null || x.FechaAceptacionPresupuesto != null) &&
|
|
(x.FechaAlta >= new DateTime(FechaInicio.Year, FechaInicio.Month, FechaInicio.Day) &&
|
|
(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 == null || y.idDocumentoASolicitarNavigation.SolicitarAAgente)))
|
|
).ToList();
|
|
}
|
|
}
|
|
|
|
public static bool CambiaCarteraAgente(string AgenteAnterior, string AgenteNuevo)
|
|
{
|
|
var bd = tscgestionasegasa.NuevoContexto();
|
|
var idnueage = bd.agentes.First(x => x.Codigo == AgenteNuevo).idAgente;
|
|
|
|
var recs = bd.recibos.Where(x => x.liquidacionesagenterecibos.Any() == false && x.idAgenteNavigation.Codigo == AgenteAnterior).ToList();
|
|
|
|
int tge = (int)TipoGestionEnum.CAMBIO_CARTERA_AGENTE;
|
|
|
|
foreach (var r in recs)
|
|
{
|
|
r.idAgente = idnueage;
|
|
var tg = new gestionesrecibos
|
|
{
|
|
idRecibo = r.idRecibo,
|
|
FormaComunicacion = (int)FormaComunicacionEnum.POR_EMAIL, // Used to be just 4
|
|
Tipo = tge,
|
|
GestionesRealizadas = TipoGestionEnum.CAMBIO_CARTERA_AGENTE.ToString().Replace("_", " "),
|
|
Fecha = DateTime.Now,
|
|
idCorreo = null,
|
|
Observaciones = "Cambio Cartera Agente del " + AgenteAnterior + " al " + AgenteNuevo
|
|
};
|
|
bd.gestionesrecibos.Add(tg);
|
|
}
|
|
bd.SaveChanges();
|
|
|
|
var tgp = bd.enumeraciones.First(x => x.Codigo == "TGP.CAMCARAG");
|
|
var idtgp = tgp.idEnumeracion;
|
|
|
|
var pols = bd.polizassg.Where(x => x.idAgenteNavigation.Codigo == AgenteAnterior && x.FechaBaja.HasValue == false);
|
|
foreach (var p in pols)
|
|
{
|
|
p.idAgente = idnueage;
|
|
var tg = new gestionespolizassg
|
|
{
|
|
idPoliza = p.idPoliza,
|
|
idTipo = idtgp,
|
|
GestionesRealizadas = tgp.Descripcion,
|
|
Fecha = DateTime.Now,
|
|
Observaciones = "Cambio Cartera Agente del " + AgenteAnterior + " al " + AgenteNuevo
|
|
};
|
|
bd.gestionespolizassg.Add(tg);
|
|
}
|
|
bd.SaveChanges();
|
|
|
|
var ageant = bd.agentes.First(x => x.Codigo == AgenteAnterior);
|
|
bool bbaja;
|
|
if (ageant.FechaBaja.HasValue == false)
|
|
{
|
|
ageant.FechaBaja = new DateOnly(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
|
|
bbaja = true;
|
|
}
|
|
else
|
|
{
|
|
bbaja = false;
|
|
}
|
|
bd.SaveChanges();
|
|
return bbaja;
|
|
}
|
|
}
|
|
}
|