101 lines
3.6 KiB
C#
101 lines
3.6 KiB
C#
using Entidades;
|
|
using Entidades.Informes;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Modelo;
|
|
public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
|
|
public ChartData? ObtenerDataIniciadosPorAño(int year){
|
|
var con = Context;
|
|
var contratosPorMes = con.Contratos
|
|
.Where(c => c.Habilitado == 1 && c.Fechainicio.Year == year)
|
|
.GroupBy(c => c.Fechainicio.Month)
|
|
.Select(g => new { Mes = g.Key, Cantidad = g.Count() })
|
|
.OrderBy(x => x.Mes).ToList();
|
|
|
|
if (!contratosPorMes.Any()) return null;
|
|
|
|
var data = new ChartData();
|
|
data.Labels = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
|
|
|
|
List<string> ddd = new List<string>(["0","0","0","0","0","0","0","0","0","0","0","0"]);
|
|
foreach (var contrato in contratosPorMes) {
|
|
ddd[contrato.Mes-1] = contrato.Cantidad.ToString();
|
|
}
|
|
|
|
Dataset dd = new();
|
|
dd.Data = ddd;
|
|
dd.Label = $"Alquileres por Mes del año {year}";
|
|
data.Datasets.Add(dd);
|
|
return data;
|
|
}
|
|
|
|
public ChartData? ObtenerDataDuracionContratos() {
|
|
var con = Context;
|
|
var meses = con.Contratos.Where(x=>x.Habilitado ==1)
|
|
.GroupBy(x=>x.MesesDurationContrato).Select(g=> new {Duracion = g.Key, Cantidad = g.Count()});
|
|
if(!meses.Any()) return null;
|
|
|
|
var data = new ChartData();
|
|
Dataset dd = new();
|
|
|
|
foreach (var mes in meses){
|
|
data.Labels.Add(mes.Duracion.ToString());
|
|
dd.Data.Add(mes.Cantidad.ToString());
|
|
}
|
|
dd.Label="Duracion Contratos";
|
|
data.Datasets.Add(dd);
|
|
return data;
|
|
}
|
|
|
|
public ChartData? ObtenerDatosPagosContrato(long idcontrato) {
|
|
var con = Context;
|
|
var cont = con.Contratos.Include(c=>c.Idcanons).ThenInclude(x=>x.IdreciboNavigation)
|
|
.Where(x=>x.Habilitado==1)
|
|
.FirstOrDefault(x=>x.Id == idcontrato);
|
|
if(cont==null)return null;
|
|
|
|
var data = new ChartData();
|
|
data.Labels= ["Pago", "Sin Pagar", "Pago Atrasado"];
|
|
|
|
Dataset d1 = new();
|
|
d1.Label="Estadistica Pagos";
|
|
|
|
var l = new List<string>(["0","0","0"]);
|
|
|
|
l[0] = cont.Idcanons.Where(x=>x.Pagado == 1Lu && x.IdreciboNavigation != null && x.IdreciboNavigation.Fecha <= x.Fecha)
|
|
.Count().ToString();
|
|
|
|
l[1] = cont.Idcanons.Where(x=>x.Pagado==0).Count().ToString();
|
|
|
|
l[2] = cont.Idcanons.Where(x=>x.Pagado == 1Lu && x.IdreciboNavigation != null && x.IdreciboNavigation.Fecha > x.Fecha)
|
|
.Count().ToString();
|
|
d1.Data.AddRange(l);
|
|
data.Datasets.Add(d1);
|
|
|
|
return data;
|
|
}
|
|
|
|
public IQueryable<Contrato> TablaObtenerContratosIniciadosPorAño(int year) {
|
|
var con = Context;
|
|
var contratosPorMes = con.Contratos.Include(x=>x.IddivisaNavigation).Include(x=>x.IdpropiedadNavigation)
|
|
.Where(c => c.Habilitado == 1 && c.Fechainicio.Year == year);
|
|
return contratosPorMes;
|
|
}
|
|
|
|
public List<InformesMeses> TablaObtenerDataDuracionContratos() {
|
|
var con = Context;
|
|
var meses = con.Contratos.Where(x=>x.Habilitado ==1)
|
|
.GroupBy(x=>x.MesesDurationContrato).Select(g=> new {Duracion = g.Key, Cantidad = g.Count()});
|
|
|
|
List<InformesMeses> l = new();
|
|
foreach (var mes in meses){
|
|
l.Add(new InformesMeses{
|
|
Meses = mes.Duracion,
|
|
Repes = mes.Cantidad
|
|
});
|
|
}
|
|
return l;
|
|
|
|
}
|
|
|
|
} |