\ No newline at end of file
diff --git a/Front/src/paginas/ContratoInquilino.svelte b/Front/src/paginas/ContratoInquilino.svelte
index 9c6cac3..7e70dfc 100644
--- a/Front/src/paginas/ContratoInquilino.svelte
+++ b/Front/src/paginas/ContratoInquilino.svelte
@@ -4,12 +4,12 @@
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
import {urlG} from "../stores/urlStore";
import type { CanonDto, ContratoDto, ContratoPropiedadDto, GaranteDto2 } from "../types";
-
+ import ModalPedirDoc from "../Componentes/ModalPedirDoc.svelte";
let token:string = sessionStorage.getItem("token")||"";
- let interes:number = $state(0);
-
+ let selMod:any =$state();
+ let showmodal:boolean = $state(false);
let canons:CanonDto[] = $state([]);
let garantes: GaranteDto2[] = $state([]);
let prop:ContratoPropiedadDto = $state({
@@ -72,13 +72,30 @@
const qs = window.location.search;
const par = new URLSearchParams(qs);
contratoid = par.get("id")||"";
- }
-
-
- function submitnuevosCanones() {
+ }
- }
- async function verContrato() {
+ async function refreshCanon() {
+ try {
+ const ret = await fetch($urlG+"/api/contratos/canon?id="+contratoid, {
+ method: "GET",
+ headers: {
+ "Auth": String(token),
+ }
+ });
+ if (!ret.ok){
+ let data = await ret.json();
+ modaldata = data.message;
+ return;
+ }
+ let data = await ret.json();
+ canons = data;
+ return;
+ } catch {
+ modaldata = "No se pudo obtener la lista de canones actualizada";
+ }
+ }
+
+ async function verContrato() {
if (prop.id <= 0) {
modaldata = "no hay contratos con id 0 o menor";
return;
@@ -105,6 +122,58 @@
modaldata= "fallo intentar hacer la request";
}
}
+
+ async function realizarpago(mes: Date) {
+ try {
+ const ret = await fetch($urlG+"/api/contratos/realizarPago", {
+ method: "POST",
+ headers: {
+ "Auth": String(token),
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({idcontrato:contratoid, fecha:mes}),
+ });
+ let data = await ret.json();
+ modaldata = data.message;
+ if (ret.ok){
+ refreshCanon()
+ return;
+ }
+ } catch {
+ modaldata = "Fallo al intentar hacer la request";
+ }
+ }
+
+
+ function generarTiket(mod) {
+ selMod = mod;
+ showmodal =true;
+ }
+
+ async function pedirdocumento(op:boolean) {
+ try {
+ const ret = await fetch($urlG+"/api/contrato/GenerarRecibo?html="+op, {
+ method: "POST",
+ headers: {
+ "Auth": String(token),
+ "Content-Type": "application/json",
+ },
+
+ body: JSON.stringify({fecha: selMod.mes, idcontrato: contratoid})
+ });
+ if (!ret.ok) {
+ let blob = await ret.json();
+ modaldata=blob.message;
+ return;
+ }
+ let blob = await ret.blob();
+ const blobUrl = URL.createObjectURL(blob);
+ window.open(blobUrl, '_blank');
+ setTimeout(() => URL.revokeObjectURL(blobUrl), 100000);
+ } catch {
+ modaldata = "Fallo al intentar hacer la request";
+ }
+ }
@@ -112,6 +181,11 @@
{#if modaldata}
!!(modaldata = "")}/>
{/if}
+
+{#if showmodal}
+ showmodal=false} onSubmit={pedirdocumento} />
+{/if}
+
@@ -219,10 +293,10 @@
Pago: {canon.pago ? "Sí" : "No"}
diff --git a/Front/src/paginas/ContratosPropietario.svelte b/Front/src/paginas/ContratosPropietario.svelte
index 0ecff7d..68d5b39 100644
--- a/Front/src/paginas/ContratosPropietario.svelte
+++ b/Front/src/paginas/ContratosPropietario.svelte
@@ -75,8 +75,24 @@
contratoid = par.get("id")||"";
}
- function submitnuevosCanones() {
-
+ async function submitnuevosCanones() {
+ try {
+ const ret = await fetch($urlG+"/api/contratos/crearcanons",{
+ method: "POST",
+ headers: {
+ "Auth" : String(token),
+ },
+ body: JSON.stringify({idcontrato: contratoid, aumento: interes})
+ });
+
+ let data = await ret.json();
+ modaldata = data.message;
+ if (ret.ok) {
+ refreshCanon();
+ }
+ } catch {
+ modaldata = "Fallo al intentar alcanzar el servidor";
+ }
}
async function verContrato() {
@@ -106,6 +122,53 @@
modaldata= "fallo intentar hacer la request";
}
}
+
+ async function refreshCanon() {
+ try {
+ const ret = await fetch($urlG+"/api/contratos/canon?id="+contratoid, {
+ method: "GET",
+ headers: {
+ "Auth": String(token),
+ }
+ });
+ if (!ret.ok){
+ let data = await ret.json();
+ modaldata = data.message;
+ return;
+ }
+ let data = await ret.json();
+ canons = data;
+ return;
+ } catch {
+ modaldata = "No se pudo obtener la lista de canones actualizada";
+ }
+ }
+
+
+ async function marcarPago(mes: Date) {
+ try {
+ const ret = await fetch($urlG+"/api/contratos/marcarPago", {
+ method: "POST",
+ headers: {
+ "Auth": String(token),
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({idcontrato:contratoid, fecha:mes}),
+ });
+ let data = await ret.json();
+ modaldata = data.message;
+ if (ret.ok){
+ refreshCanon()
+ return;
+ }
+ } catch {
+ modaldata = "Fallo al intentar hacer la request";
+ }
+ }
+
+ async function generarTiket(mes: Date) { //WIP
+
+ }
@@ -114,7 +177,6 @@
!!(modaldata = "")}/>
{/if}
-
@@ -222,10 +284,10 @@
Pago: {canon.pago ? "Sí" : "No"}
diff --git a/Modelo/RepositorioCanons.cs b/Modelo/RepositorioCanons.cs
index 1660cdb..0a1699c 100644
--- a/Modelo/RepositorioCanons.cs
+++ b/Modelo/RepositorioCanons.cs
@@ -1,5 +1,6 @@
using Entidades;
using Microsoft.EntityFrameworkCore;
+using Org.BouncyCastle.Math.EC.Rfc7748;
namespace Modelo;
@@ -14,17 +15,13 @@ public class RepositorioCanons: RepositorioBase {
var con = Context;
Canon? cc = null;
- var c = con.Canons.FirstOrDefault(x => x.Idrecibo == null &&
- x.Fecha == f );
+ var c = con.Contratos.Include(x=>x.Idcanons).ThenInclude(x=>x.IdreciboNavigation).FirstOrDefault(x => x.Id == idcont);
if (c == null) return null;
- //no deberia de tener que usar un foreach pero entity por algun motivo mapeo
- //la entidad como muchos a muchos. no hay forma de que un canon tenga multiples
- //contratos por como lo codifique pero igualmente
- foreach (var i in c.Idcontratos) {
- foreach (var j in i.Idcanons) {
- if (j.Fecha == f) {
- cc = j;
- }
+
+ foreach (var j in c.Idcanons) {
+ if (j.Fecha == f) {
+ cc = j;
+ break;
}
}
return cc;
@@ -52,6 +49,10 @@ public class RepositorioCanons: RepositorioBase {
if (cont == null) return false;
int exist = cont.Idcanons.Count();
+ Canon? d = cont.Idcanons.OrderByDescending(x=>x.Fecha).FirstOrDefault();
+ if (d == null) return false;
+
+
if (exist+cont.MesesHastaAumento >= cont.MesesDurationContrato){
exist = cont.MesesDurationContrato-exist;
} else{
@@ -62,8 +63,14 @@ public class RepositorioCanons: RepositorioBase {
for (int i = 0; i < exist; i++){
Canon c = new Canon{
- Fecha
+ Fecha = d.Fecha.AddMonths(i==0?1:i+1),
+ Id = con.Canons.Count()+i+1,
+ Monto = cont.Monto,
+ Pagado = 0,
};
+ con.Canons.Add(c);
+ cont.Idcanons.Add(c);
}
+ return Guardar(con);
}
}
\ No newline at end of file