añadido tercera estadistica
This commit is contained in:
@@ -7,6 +7,21 @@ namespace AlquilaFacil.Controllers;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class EstadisticaController : ControllerBase
|
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")]
|
[HttpGet("api/stats/alquileresIniciados")]
|
||||||
public IActionResult alquileresIniciadosEsteAño([FromHeader(Name = "Auth")] string Auth, int year)
|
public IActionResult alquileresIniciadosEsteAño([FromHeader(Name = "Auth")] string Auth, int year)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;}
|
||||||
|
}
|
||||||
@@ -98,11 +98,17 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nombresMeses = [
|
||||||
|
"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
|
||||||
|
"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
|
||||||
|
];
|
||||||
|
|
||||||
let ingresos: IngresosDto[] = $state([]);
|
let ingresos: IngresosDto[] = $state([]);
|
||||||
let chartingresos: ChartData | null = $state(null);
|
let chartingresos: ChartData | null = $state(null);
|
||||||
async function getIngresos() {
|
let yearr:number = $state(0);
|
||||||
|
async function getIngresos(year:number) {
|
||||||
try{
|
try{
|
||||||
const req = await fetch($urlG+"", {
|
const req = await fetch($urlG+"/api/stats/Pagos?year="+year, {
|
||||||
method:"GET",
|
method:"GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": token || "",
|
"Auth": token || "",
|
||||||
@@ -110,7 +116,10 @@
|
|||||||
});
|
});
|
||||||
const data = await req.json();
|
const data = await req.json();
|
||||||
if (req.ok){
|
if (req.ok){
|
||||||
ingresos = data.tabla;
|
ingresos = data.tabla.map(item => ({
|
||||||
|
...item,
|
||||||
|
mes: nombresMeses[Number(item.mes) - 1]
|
||||||
|
}));
|
||||||
chartingresos = data.chart;
|
chartingresos = data.chart;
|
||||||
} else {
|
} else {
|
||||||
modaldata = data.message;
|
modaldata = data.message;
|
||||||
@@ -141,7 +150,7 @@
|
|||||||
aria-expanded="true"
|
aria-expanded="true"
|
||||||
aria-controls="c1"
|
aria-controls="c1"
|
||||||
>
|
>
|
||||||
Alquileres en el ultimo año
|
Alquileres Por Mes
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div
|
<div
|
||||||
@@ -167,6 +176,9 @@
|
|||||||
/>Buscar</button
|
/>Buscar</button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="text-muted">
|
||||||
|
Todos los Alquileres de un año mostrados por mes
|
||||||
|
</p>
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -279,39 +291,77 @@
|
|||||||
data-bs-target="#c3"
|
data-bs-target="#c3"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
aria-controls="c3"
|
aria-controls="c3"
|
||||||
>
|
onclick={async ()=> {
|
||||||
Ingresos
|
if (yearr ==0){
|
||||||
|
yearr = new Date().getFullYear();
|
||||||
|
getIngresos(yearr);
|
||||||
|
|
||||||
|
} else if (yearr != 0){
|
||||||
|
yearr = 0;
|
||||||
|
}}}
|
||||||
|
>
|
||||||
|
Estado Pagos por Mes
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="accordion-collapse collapse" id="c3"
|
<div class="accordion-collapse collapse" id="c3"
|
||||||
data-bs-parent="#accordionExample"
|
data-bs-parent="#accordionExample"
|
||||||
>
|
>
|
||||||
<div class="accordion-body d-flex">
|
<div class="accordion-body row">
|
||||||
<div>
|
<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">
|
<table class="table table-striped table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Mes</th>
|
<th>Mes</th>
|
||||||
<th>Ingreso AR$</th>
|
<th>Pagos Realizados</th>
|
||||||
<th>Ingreso US$</th>
|
<th>Pagos Atrasados</th>
|
||||||
|
<th>Pagos Sin Realizar</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each ingresos as i }
|
{#each ingresos as i }
|
||||||
<tr>
|
<tr>
|
||||||
<td>{i.mes}</td>
|
<td>{i.mes}</td>
|
||||||
<td>{i.ingresoAr}</td>
|
<td>{i.realizados}</td>
|
||||||
<td>{i.ingresoUs}</td>
|
<td>{i.atrasados}</td>
|
||||||
|
<td>{i.sin_realizar}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="col">
|
||||||
{#if chartingresos != null}
|
{#if chartingresos != null}
|
||||||
<FChart
|
<FChart
|
||||||
chartData={chartingresos}
|
chartData={chartingresos}
|
||||||
typec="pie"
|
typec="line"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Vendored
+3
-2
@@ -245,6 +245,7 @@ export type ClientePanel = {
|
|||||||
|
|
||||||
export type IngresosDto = {
|
export type IngresosDto = {
|
||||||
mes:number,
|
mes:number,
|
||||||
ingresoAr:number,
|
realizados:number,
|
||||||
ingresoUs:number
|
atrasados:number,
|
||||||
|
sin_realizar:number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,46 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Modelo;
|
namespace Modelo;
|
||||||
public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
|
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){
|
public ChartData? ObtenerDataIniciadosPorAño(int year){
|
||||||
var con = Context;
|
var con = Context;
|
||||||
var contratosPorMes = con.Contratos
|
var contratosPorMes = con.Contratos
|
||||||
|
|||||||
Reference in New Issue
Block a user