estadisticas
This commit is contained in:
@@ -196,4 +196,9 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
.FirstOrDefault(x=>x.Id == idcontrato);
|
||||
return l;
|
||||
}
|
||||
|
||||
public bool HayContratosEnAño(int year) {
|
||||
var con = Context;
|
||||
return con.Contratos.Where(x=>x.Fechainicio.Year == year).Any();
|
||||
}
|
||||
}
|
||||
|
||||
72
Modelo/RepositorioEstadisticas.cs
Normal file
72
Modelo/RepositorioEstadisticas.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
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 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;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user