añadido tercera estadistica

This commit is contained in:
2025-05-31 01:06:22 -03:00
parent 616c9503bc
commit e5d17c3a38
5 changed files with 135 additions and 20 deletions

View File

@@ -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<InformePagos> 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)
{

View File

@@ -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;}
}

View File

@@ -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
</button>
</h2>
<div
@@ -167,6 +176,9 @@
/>Buscar</button
>
</div>
<p class="text-muted">
Todos los Alquileres de un año mostrados por mes
</p>
<table class="table table-hover">
<thead>
<tr>
@@ -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
</button>
</h2>
<div class="accordion-collapse collapse" id="c3"
data-bs-parent="#accordionExample"
data-bs-parent="#accordionExample"
>
<div class="accordion-body d-flex">
<div>
<div class="accordion-body row">
<div class="col">
<div class="d-flex input-group">
<input
class="form-control"
type="number"
bind:value={yearr}
/>
<button
class="btn btn-primary"
onclick={() => getIngresos(yearr)}
><img
src="/zoom.svg"
alt="lupa"
aria-label="Lupa"
/>Buscar</button
>
</div>
<p class="text-muted">
Todos los canones ya sean pagados, Pagados Atrasados o Sin Realizar
</p>
{#if ingresos.length == 0}
<div class="d-flex justify-content-center align-items-center mt-3">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Cargando...</span>
</div>
</div>
{:else}
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Mes</th>
<th>Ingreso AR$</th>
<th>Ingreso US$</th>
<th>Pagos Realizados</th>
<th>Pagos Atrasados</th>
<th>Pagos Sin Realizar</th>
</tr>
</thead>
<tbody>
{#each ingresos as i }
<tr>
{#each ingresos as i }
<tr>
<td>{i.mes}</td>
<td>{i.ingresoAr}</td>
<td>{i.ingresoUs}</td>
<td>{i.realizados}</td>
<td>{i.atrasados}</td>
<td>{i.sin_realizar}</td>
</tr>
{/each}
</tbody>
</table>
{/if}
</div>
<div>
<div class="col">
{#if chartingresos != null}
<FChart
chartData={chartingresos}
typec="pie"
typec="line"
/>
{/if}
</div>

View File

@@ -245,6 +245,7 @@ export type ClientePanel = {
export type IngresosDto = {
mes:number,
ingresoAr:number,
ingresoUs:number
realizados:number,
atrasados:number,
sin_realizar:number
}

View File

@@ -4,6 +4,46 @@ using Microsoft.EntityFrameworkCore;
namespace Modelo;
public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
public (ChartData, List<InformePagos>) 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<InformePagos> 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<RepositorioEstadisticas> {
}
}
}