falta soporte para el menu de propietario de mostrar los archivos
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.7" />
|
||||
<PackageReference Include="minio" Version="6.0.3" />
|
||||
<PackageReference Include="QuestPDF" Version="2024.12.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Net;
|
||||
using System.Text.Json;
|
||||
using AlquilaFacil.Builder;
|
||||
using AlquilaFacil.Config;
|
||||
using AlquilaFacil.Facade;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -16,6 +17,51 @@ namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class ContratoController: ControllerBase {
|
||||
|
||||
[HttpPost("api/contrato/GenerarRecibo")]
|
||||
public ActionResult GenerarRecibo([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto, bool html= true) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.Idcontrato <= 0) return BadRequest(new { message = "No puede tener un contrato con id 0 o menor"});
|
||||
|
||||
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.Idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por ese id"});
|
||||
|
||||
if (cont.DniinquilinoNavigation == null || cont.DnipropietarioNavigation == null || cont.IdpropiedadNavigation == null ||
|
||||
cont.IdpropiedadNavigation.IdtipropiedadNavigation == null) return BadRequest(new { message = "comunicate con el admin esta mal cargado el contratod de alguina forma"});
|
||||
|
||||
Canon? can = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato);
|
||||
if (can == null) return BadRequest(new { message = "no hay un canon para ese contrato con esa fecha"});
|
||||
if (can.IdreciboNavigation == null) return BadRequest(new { message = "No hay un recibo para ese canon"});
|
||||
|
||||
var cdb = new ContratoDtoBuilder()
|
||||
.SetInquilino($"{cont.DniinquilinoNavigation.Nombre} {cont.DniinquilinoNavigation.Apellido}")
|
||||
.SetUbicacion(cont.IdpropiedadNavigation.Ubicacion)
|
||||
.SetPropietario($"{cont.DnipropietarioNavigation.Nombre} {cont.DnipropietarioNavigation.Apellido}")
|
||||
.SetId(cont.Id)
|
||||
.SetTipo(cont.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion)
|
||||
.SetFechaInicio(cont.Fechainicio)
|
||||
.SetEstado(cont.Habilitado, cont.Cancelado)
|
||||
.Build();
|
||||
|
||||
var dof = new DocumentoFacade();
|
||||
MemoryStream? memstr = new();
|
||||
if (html){
|
||||
dof.GenerarHtml(cdb, can.IdreciboNavigation, memstr);
|
||||
return File(memstr, "text/html", "Recibo.html");
|
||||
} else {
|
||||
dof.GenerarPdf (cdb, can.IdreciboNavigation, memstr);
|
||||
return File(memstr, "application/pdf", "Recibo.pdf");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HttpPost("api/contratos/marcarPago")]
|
||||
public IActionResult marcarPago([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -73,7 +119,7 @@ public class ContratoController: ControllerBase {
|
||||
Ok(new { message = "Se guardo correctamente"}):BadRequest(new { message = "No se pudo guardar"});
|
||||
}
|
||||
|
||||
[HttpPost("api/contratos/crearcanons")] //WIP
|
||||
[HttpPost("api/contratos/crearcanons")]
|
||||
public IActionResult crearCanons([FromHeader(Name="Auth")]string Auth, CrearCanonsDto dto){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
@@ -81,7 +127,7 @@ public class ContratoController: ControllerBase {
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
if (dto.aumento <=Decimal.Zero || dto.idcontrato <=0) return BadRequest(new { message ="estan mal cargados los datos"});
|
||||
if (dto.idcontrato <=0) return BadRequest(new { message ="estan mal cargados los datos"});
|
||||
|
||||
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "no hay un contrato por esa id"});
|
||||
|
||||
24
Aspnet/Facade/DocumentoFacade.cs
Normal file
24
Aspnet/Facade/DocumentoFacade.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Runtime;
|
||||
using System.Text;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
|
||||
namespace AlquilaFacil.Facade;
|
||||
|
||||
public class DocumentoFacade {
|
||||
private readonly DocumentoGeneradorHtml d1 = new();
|
||||
private readonly DocumentoGeneradorPdf d2 = new();
|
||||
|
||||
public void GenerarHtml(ContratoDto cd, Recibo r, MemoryStream memoryStream) {
|
||||
string str = d1.GenerarHTML(cd, r);
|
||||
StreamWriter writer = new StreamWriter(memoryStream, Encoding.UTF8);
|
||||
writer.WriteAsync(str).Wait();
|
||||
writer.FlushAsync().Wait();
|
||||
memoryStream.Position = 0;
|
||||
}
|
||||
public void GenerarPdf(ContratoDto cd, Recibo r, MemoryStream memoryStream) {
|
||||
var mem = d2.GenerarPdf(cd, r);
|
||||
mem.CopyToAsync(memoryStream).Wait();
|
||||
memoryStream.Position = 0;
|
||||
}
|
||||
}
|
||||
45
Aspnet/Facade/DocumentoGeneradorHtml.cs
Normal file
45
Aspnet/Facade/DocumentoGeneradorHtml.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Routing.Template;
|
||||
|
||||
namespace AlquilaFacil.Facade;
|
||||
public class DocumentoGeneradorHtml {
|
||||
public string GenerarHTML(ContratoDto cd, Recibo r) {
|
||||
string tmpl =$"""
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<div class="card">
|
||||
<div class="card-header text-white bg-primary">
|
||||
AlquilaFácil
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Detalles</h5>
|
||||
<p class="card-text">
|
||||
<strong>ID:</strong> {cd.id}<br>
|
||||
<strong>Ubicación:</strong> {cd.Ubicacion}<br>
|
||||
<strong>Tipo de Propiedad:</strong> {cd.TipoPropiedad}<br>
|
||||
<strong>Fecha de Inicio:</strong> {cd.Fechainicio}<br>
|
||||
<strong>Inquilino:</strong> {cd.Inquilino}<br>
|
||||
<strong>Propietario:</strong> {cd.Propietario}<br>
|
||||
</p>
|
||||
<hr>
|
||||
<h5 class="card-title">Detalles del Recibo</h5>
|
||||
<p class="card-text">
|
||||
<strong>ID del Recibo:</strong> {r.Id}<br>
|
||||
<strong>Fecha:</strong> {r.Fecha}<br>
|
||||
<strong>Monto:</strong> {r.Monto}<br>
|
||||
<h2><b>PAGO</b></h2>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""; return tmpl;
|
||||
}
|
||||
}
|
||||
67
Aspnet/Facade/DocumentoGeneradorPdf.cs
Normal file
67
Aspnet/Facade/DocumentoGeneradorPdf.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Helpers;
|
||||
using QuestPDF.Infrastructure;
|
||||
using System.IO;
|
||||
|
||||
namespace AlquilaFacil.Facade;
|
||||
public class DocumentoGeneradorPdf {
|
||||
public MemoryStream GenerarPdf(ContratoDto cd, Recibo r)
|
||||
{
|
||||
var pdfStream = new MemoryStream();
|
||||
QuestPDF.Settings.License = LicenseType.Community;
|
||||
Document.Create(container =>
|
||||
{
|
||||
container.Page(page =>
|
||||
{
|
||||
page.Size(PageSizes.A4);
|
||||
page.Margin(2, Unit.Centimetre);
|
||||
page.Header().Text("AlquilaFácil").FontSize(20).SemiBold().FontColor(Colors.White);
|
||||
page.Content().Column(column =>
|
||||
{
|
||||
column.Spacing(10);
|
||||
|
||||
column.Item().Border(1).Padding(10).Column(card =>
|
||||
{
|
||||
card.Item().Row(row =>
|
||||
{
|
||||
row.RelativeItem().Text("Detalles").FontSize(16).SemiBold();
|
||||
});
|
||||
|
||||
card.Item().Column(body =>
|
||||
{
|
||||
body.Spacing(5);
|
||||
body.Item().Text($"ID: {cd.id}").FontSize(12).Bold();
|
||||
body.Item().Text($"Ubicación: {cd.Ubicacion}").FontSize(12);
|
||||
body.Item().Text($"Tipo de Propiedad: {cd.TipoPropiedad}").FontSize(12);
|
||||
body.Item().Text($"Fecha de Inicio: {cd.Fechainicio}").FontSize(12);
|
||||
body.Item().Text($"Inquilino: {cd.Inquilino}").FontSize(12);
|
||||
body.Item().Text($"Propietario: {cd.Propietario}").FontSize(12);
|
||||
});
|
||||
});
|
||||
|
||||
column.Item().Border(1).Padding(10).Column(card =>
|
||||
{
|
||||
card.Item().Row(row =>
|
||||
{
|
||||
row.RelativeItem().Text("Detalles del Recibo").FontSize(16).SemiBold();
|
||||
});
|
||||
|
||||
card.Item().Column(body =>
|
||||
{
|
||||
body.Spacing(5);
|
||||
body.Item().Text($"ID del Recibo: {r.Id}").FontSize(12).Bold();
|
||||
body.Item().Text($"Fecha: {r.Fecha}").FontSize(12);
|
||||
body.Item().Text($"Monto: {r.Monto}").FontSize(12);
|
||||
body.Item().AlignCenter().Text("PAGO").FontSize(20).Bold();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}).GeneratePdf(pdfStream);
|
||||
|
||||
pdfStream.Position = 0;
|
||||
return pdfStream;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user