diff --git a/Aspnet/Controllers/EstadisticaController.cs b/Aspnet/Controllers/EstadisticaController.cs index e35caa3..1f53f9c 100644 --- a/Aspnet/Controllers/EstadisticaController.cs +++ b/Aspnet/Controllers/EstadisticaController.cs @@ -7,6 +7,21 @@ namespace AlquilaFacil.Controllers; [ApiController] public class EstadisticaController : ControllerBase { + [HttpGet("/api/stats/Pagos")] + public IActionResult EstadisticasPagos([FromHeader(Name ="Auth")] string Auth, int year){ + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 6); + if (validacion1 == false) return Unauthorized(); + + ChartData stats; + List tabla; + + (stats, tabla) = RepositorioEstadisticas.Singleton.InformePagos(year); + + return Ok(new { chart = stats, tabla = tabla}); + } + + [HttpGet("api/stats/alquileresIniciados")] public IActionResult alquileresIniciadosEsteAño([FromHeader(Name = "Auth")] string Auth, int year) { diff --git a/Entidades/Informes/InformePagos.cs b/Entidades/Informes/InformePagos.cs new file mode 100644 index 0000000..fd47743 --- /dev/null +++ b/Entidades/Informes/InformePagos.cs @@ -0,0 +1,9 @@ +namespace Entidades.Informes; + +public class InformePagos +{ + public int Mes { get; set; } + public int Realizados { get; set; } + public int Atrasados {get;set;} + public int Sin_realizar {get;set;} +} diff --git a/Front/src/paginas/Informes.svelte b/Front/src/paginas/Informes.svelte index 15ca489..8d289dc 100644 --- a/Front/src/paginas/Informes.svelte +++ b/Front/src/paginas/Informes.svelte @@ -98,11 +98,17 @@ }); } +const nombresMeses = [ + "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", + "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" +]; + let ingresos: IngresosDto[] = $state([]); let chartingresos: ChartData | null = $state(null); - async function getIngresos() { + let yearr:number = $state(0); + async function getIngresos(year:number) { try{ - const req = await fetch($urlG+"", { + const req = await fetch($urlG+"/api/stats/Pagos?year="+year, { method:"GET", headers: { "Auth": token || "", @@ -110,7 +116,10 @@ }); const data = await req.json(); if (req.ok){ - ingresos = data.tabla; + ingresos = data.tabla.map(item => ({ + ...item, + mes: nombresMeses[Number(item.mes) - 1] + })); chartingresos = data.chart; } else { modaldata = data.message; @@ -141,7 +150,7 @@ aria-expanded="true" aria-controls="c1" > - Alquileres en el ultimo año + Alquileres Por Mes
Buscar
+

+ Todos los Alquileres de un año mostrados por mes +

@@ -279,39 +291,77 @@ data-bs-target="#c3" aria-expanded="false" aria-controls="c3" - > - Ingresos + onclick={async ()=> { + if (yearr ==0){ + yearr = new Date().getFullYear(); + getIngresos(yearr); + + } else if (yearr != 0){ + yearr = 0; + }}} + > + Estado Pagos por Mes
-
-
+
+
+ +
+ + +
+

+ Todos los canones ya sean pagados, Pagados Atrasados o Sin Realizar +

+ {#if ingresos.length == 0} +
+
+ Cargando... +
+
+ {:else}
- - + + + - {#each ingresos as i } - + {#each ingresos as i } + - - + + + {/each}
MesIngreso AR$Ingreso US$Pagos RealizadosPagos AtrasadosPagos Sin Realizar
{i.mes}{i.ingresoAr}{i.ingresoUs}{i.realizados}{i.atrasados}{i.sin_realizar}
+ {/if} -
+
{#if chartingresos != null} {/if}
diff --git a/Front/src/types.d.ts b/Front/src/types.d.ts index 28cdf7f..771b839 100644 --- a/Front/src/types.d.ts +++ b/Front/src/types.d.ts @@ -245,6 +245,7 @@ export type ClientePanel = { export type IngresosDto = { mes:number, - ingresoAr:number, - ingresoUs:number + realizados:number, + atrasados:number, + sin_realizar:number } diff --git a/Modelo/RepositorioEstadisticas.cs b/Modelo/RepositorioEstadisticas.cs index c9ed217..f6cd96d 100644 --- a/Modelo/RepositorioEstadisticas.cs +++ b/Modelo/RepositorioEstadisticas.cs @@ -4,6 +4,46 @@ using Microsoft.EntityFrameworkCore; namespace Modelo; public class RepositorioEstadisticas: RepositorioBase { + + + public (ChartData, List) InformePagos(int year) + { + var con = Context; + + ChartData data = new(); + data.Labels = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]; + + var can = con.Canons.Where(x => x.Fecha.Year == year) + .Include(x=>x.IdreciboNavigation) + .GroupBy(x => x.Fecha.Month) + .Select(x=> new InformePagos{Mes = x.Key, + Realizados = x.Count(x=> x.Pagado == 1 && x.IdreciboNavigation.Fecha <= x.Fecha), + Atrasados = x.Count(x=> x.Pagado == 1 && x.IdreciboNavigation.Fecha > x.Fecha), + Sin_realizar = x.Count(x=> x.Pagado == 0)}); + + List lst = can.ToList(); + + data.Datasets.Add(new Dataset + { + Label = "Realizados", + Data = lst.Select(x => x.Realizados.ToString()).ToList() + }); + + data.Datasets.Add(new Dataset + { + Label = "Atrasados", + Data = lst.Select(x => x.Atrasados.ToString()).ToList() + }); + + data.Datasets.Add(new Dataset + { + Label = "Sin_realizar", + Data = lst.Select(x => x.Sin_realizar.ToString()).ToList() + }); + + return (data, lst); + } + public ChartData? ObtenerDataIniciadosPorAño(int year){ var con = Context; var contratosPorMes = con.Contratos @@ -98,4 +138,4 @@ public class RepositorioEstadisticas: RepositorioBase { } -} \ No newline at end of file +}