solucionado tema de que no salian datos en meses antiguos
This commit is contained in:
@@ -5,44 +5,59 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
namespace Modelo;
|
namespace Modelo;
|
||||||
public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
|
public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
|
||||||
|
|
||||||
|
public (ChartData, List<InformePagos>) InformePagos(int year) {
|
||||||
public (ChartData, List<InformePagos>) InformePagos(int year)
|
|
||||||
{
|
|
||||||
var con = Context;
|
var con = Context;
|
||||||
|
|
||||||
ChartData data = new();
|
ChartData data = new();
|
||||||
data.Labels = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
|
List<string> meses = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
|
||||||
|
data.Labels = meses;
|
||||||
|
|
||||||
var can = con.Canons.Where(x => x.Fecha.Year == year)
|
var canonData = con.Canons.Where(x => x.Fecha.Year == year)
|
||||||
.Include(x=>x.IdreciboNavigation)
|
.Include(x => x.IdreciboNavigation)
|
||||||
.GroupBy(x => x.Fecha.Month)
|
.Select(x => new {
|
||||||
.Select(x=> new InformePagos{Mes = x.Key,
|
Mes = x.Fecha.Month,
|
||||||
Realizados = x.Count(x=> x.Pagado == 1 && x.IdreciboNavigation.Fecha <= x.Fecha),
|
Pagado = x.Pagado,
|
||||||
Atrasados = x.Count(x=> x.Pagado == 1 && x.IdreciboNavigation.Fecha > x.Fecha),
|
CanonFecha = x.Fecha,
|
||||||
Sin_realizar = x.Count(x=> x.Pagado == 0)});
|
ReciboFecha = x.IdreciboNavigation != null ? x.IdreciboNavigation.Fecha : (DateTime?)null
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
List<InformePagos> lst = can.ToList();
|
var groupedData = canonData
|
||||||
|
.GroupBy(x => x.Mes)
|
||||||
|
.Select(g => new InformePagos {
|
||||||
|
Mes = g.Key,
|
||||||
|
Realizados = g.Count(x => x.Pagado == 1 && x.ReciboFecha.HasValue && x.ReciboFecha <= x.CanonFecha),
|
||||||
|
Atrasados = g.Count(x => x.Pagado == 1 && x.ReciboFecha.HasValue && x.ReciboFecha > x.CanonFecha),
|
||||||
|
Sin_realizar = g.Count(x => x.Pagado == 0)
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
data.Datasets.Add(new Dataset
|
List<InformePagos> lst = Enumerable.Range(1, 12)
|
||||||
{
|
.Select(mes => groupedData.FirstOrDefault(x => x.Mes == mes) ?? new InformePagos {
|
||||||
|
Mes = mes,
|
||||||
|
Realizados = 0,
|
||||||
|
Atrasados = 0,
|
||||||
|
Sin_realizar = 0
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
data.Datasets.Add(new Dataset {
|
||||||
Label = "Realizados",
|
Label = "Realizados",
|
||||||
Data = lst.Select(x => x.Realizados.ToString()).ToList()
|
Data = lst.Select(x => x.Realizados.ToString()).ToList()
|
||||||
});
|
});
|
||||||
|
|
||||||
data.Datasets.Add(new Dataset
|
data.Datasets.Add(new Dataset {
|
||||||
{
|
|
||||||
Label = "Atrasados",
|
Label = "Atrasados",
|
||||||
Data = lst.Select(x => x.Atrasados.ToString()).ToList()
|
Data = lst.Select(x => x.Atrasados.ToString()).ToList()
|
||||||
});
|
});
|
||||||
|
|
||||||
data.Datasets.Add(new Dataset
|
data.Datasets.Add(new Dataset {
|
||||||
{
|
|
||||||
Label = "Sin_realizar",
|
Label = "Sin_realizar",
|
||||||
Data = lst.Select(x => x.Sin_realizar.ToString()).ToList()
|
Data = lst.Select(x => x.Sin_realizar.ToString()).ToList()
|
||||||
});
|
});
|
||||||
|
|
||||||
return (data, lst);
|
return (data, lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChartData? ObtenerDataIniciadosPorAño(int year){
|
public ChartData? ObtenerDataIniciadosPorAño(int year){
|
||||||
var con = Context;
|
var con = Context;
|
||||||
|
|||||||
Reference in New Issue
Block a user