Falta hacer la notificacion nueva
This commit is contained in:
165
Front/src/Componentes/ModalAddGarantes.svelte
Normal file
165
Front/src/Componentes/ModalAddGarantes.svelte
Normal file
@@ -0,0 +1,165 @@
|
||||
<script lang="ts">
|
||||
import type { GaranteDto } from "../types";
|
||||
|
||||
let { onClose, onSubmit, maxGarantes }: {
|
||||
onClose: () => void,
|
||||
onSubmit: (garantes: GaranteDto[]) => void,
|
||||
maxGarantes: number
|
||||
} = $props();
|
||||
|
||||
let cantGarantes: number = $state(0);
|
||||
let garantes: GaranteDto[] = $state([]);
|
||||
let showAddForm: boolean = $state(false);
|
||||
|
||||
// Nuevo garante temporal para el formulario.
|
||||
let newGarante: GaranteDto = $state({
|
||||
Dni: 0,
|
||||
Nombre: "",
|
||||
Apellido: "",
|
||||
Domicilio: "",
|
||||
Celular: "",
|
||||
Domiciliolaboral: ""
|
||||
});
|
||||
|
||||
function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
onSubmit(garantes);
|
||||
onClose();
|
||||
}
|
||||
|
||||
function addGarante() {
|
||||
if (cantGarantes < maxGarantes) {
|
||||
garantes = [...garantes, { ...newGarante }];
|
||||
cantGarantes = garantes.length;
|
||||
resetNewGarante();
|
||||
showAddForm = false;
|
||||
}
|
||||
}
|
||||
|
||||
function resetNewGarante() {
|
||||
newGarante = {
|
||||
Dni: 0,
|
||||
Nombre: "",
|
||||
Apellido: "",
|
||||
Domicilio: "",
|
||||
Celular: "",
|
||||
Domiciliolaboral: ""
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="modal fade show" tabindex="-1" role="dialog" style="display: block; background-color: rgba(0, 0, 0, 0.5);">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Nuevo Alquiler - Garantes</h5>
|
||||
<button class="btn-close" onclick={onClose} aria-label="Close"></button>
|
||||
</div>
|
||||
<form onsubmit={handleSubmit}>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<p>Garantes añadidos: {cantGarantes}/{maxGarantes}</p>
|
||||
<button
|
||||
class="btn btn-success"
|
||||
type="button"
|
||||
onclick={() => (showAddForm = true)}
|
||||
disabled={cantGarantes >= maxGarantes}
|
||||
>
|
||||
Añadir Garante
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Formulario para añadir un garante -->
|
||||
{#if showAddForm}
|
||||
<div class="form-group mt-3">
|
||||
<h6>Añadir Garante</h6>
|
||||
<div class="mb-2">
|
||||
<label>DNI</label>
|
||||
<input type="number" class="form-control" bind:value={newGarante.Dni} required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label>Nombre</label>
|
||||
<input type="text" class="form-control" bind:value={newGarante.Nombre} required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label>Apellido</label>
|
||||
<input type="text" class="form-control" bind:value={newGarante.Apellido} required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label>Domicilio</label>
|
||||
<input type="text" class="form-control" bind:value={newGarante.Domicilio} required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label>Celular</label>
|
||||
<input type="text" class="form-control" bind:value={newGarante.Celular} required />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label>Domicilio Laboral</label>
|
||||
<input type="text" class="form-control" bind:value={newGarante.Domiciliolaboral} required />
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
type="button"
|
||||
onclick={() => (showAddForm = false)}
|
||||
>
|
||||
Cancelar
|
||||
</button>
|
||||
<button class="btn btn-primary" type="button" onclick={addGarante}>
|
||||
Confirmar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Tabla de garantes -->
|
||||
{#if cantGarantes > 0}
|
||||
<div class="form-group mt-3">
|
||||
<label>Lista de Garantes</label>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>DNI</th>
|
||||
<th>Nombre</th>
|
||||
<th>Apellido</th>
|
||||
<th>Domicilio</th>
|
||||
<th>Celular</th>
|
||||
<th>Domicilio Laboral</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each garantes as garante, index}
|
||||
<tr>
|
||||
<td>
|
||||
<input type="number" class="form-control" bind:value={garantes[index].Dni} required />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control" bind:value={garantes[index].Nombre} required />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control" bind:value={garantes[index].Apellido} required />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control" bind:value={garantes[index].Domicilio} required />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control" bind:value={garantes[index].Celular} required />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control" bind:value={garantes[index].Domiciliolaboral} required />
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="modal-footer d-flex justify-content-between">
|
||||
<button type="button" class="btn btn-secondary" onclick={onClose}>Cancelar</button>
|
||||
<button type="submit" class="btn btn-primary">Confirmar</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
50
Front/src/Componentes/ModalPrecontrato.svelte
Normal file
50
Front/src/Componentes/ModalPrecontrato.svelte
Normal file
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
let { onClose, onSubmit } : {
|
||||
onClose: () => void,
|
||||
onSubmit: (data: { opcionVenta: boolean; cantGarantes: number; mesesHastaAumento: number }) => void
|
||||
} = $props();
|
||||
|
||||
let opcionVenta: boolean = $state(false);
|
||||
let cantGarantes: number = $state(0);
|
||||
let mesesHastaAumento: number = $state(0);
|
||||
|
||||
function handleSubmit(e:Event) {
|
||||
e.preventDefault();
|
||||
onSubmit({ opcionVenta, cantGarantes, mesesHastaAumento });
|
||||
onClose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="modal fade show" tabindex="-1" role="dialog" style="display: block; background-color: rgba(0, 0, 0, 0.5);">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Nuevo Alquiler</h5>
|
||||
<button class="btn-close" onclick={onClose} aria-label="Close"></button>
|
||||
</div>
|
||||
<form onsubmit={handleSubmit}>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" bind:checked={opcionVenta} id="opcionVenta" />
|
||||
<label class="form-check-label" for="opcionVenta">Seleccionar Opcion de Venta</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="cantGarantes">Cantidad de Garantes</label>
|
||||
<input type="number" class="form-control" id="cantGarantes" bind:value={cantGarantes} min="0" required />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="mesesHastaAumento">Meses Hasta Aumento</label>
|
||||
<input type="number" class="form-control" id="mesesHastaAumento" bind:value={mesesHastaAumento} min="0" required />
|
||||
</div>
|
||||
<div class="modal-footer d-flex justify-content-between">
|
||||
<button type="button" class="btn btn-secondary" onclick={onClose}>Cancelar</button>
|
||||
<button type="submit" class="btn btn-primary">Confirmar</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,23 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { MensajeDto } from "../types";
|
||||
import type { GaranteDto, MensajeDto } from "../types";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalConfirm from "../Componentes/ModalConfirm.svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import { text } from "@sveltejs/kit";
|
||||
import ModalPrecontrato from "../Componentes/ModalPrecontrato.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import ModalAddGarantes from "../Componentes/ModalAddGarantes.svelte";
|
||||
|
||||
const token = sessionStorage.getItem("token");
|
||||
let mensajes: MensajeDto[] = $state([]);
|
||||
let showspinner:boolean =$state(false);
|
||||
let mostrarleidos: boolean = $state(false);
|
||||
let modaldata:string =$state("");
|
||||
let Selmens: MensajeDto;
|
||||
let Selmens: MensajeDto = $state({accion: "",receptor:"", fecha: Date.UTC, mensaje:"", propiedad:0, remitente:""});
|
||||
|
||||
let show:boolean = $state(false);
|
||||
let title:string = $state("");
|
||||
let message:string = $state("");
|
||||
let setCantGarantes = $state(0);
|
||||
|
||||
onMount(async () => {
|
||||
SinLeer();
|
||||
@@ -70,12 +72,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setModalConfirm(men:MensajeDto){
|
||||
Selmens = men;
|
||||
message = "${}"
|
||||
show = true;
|
||||
|
||||
}
|
||||
|
||||
async function marcarleido( fecha: Date, email: string, men:MensajeDto ) {
|
||||
show = true;
|
||||
@@ -92,7 +89,12 @@
|
||||
if (responce.ok) {
|
||||
let data = await responce.json();
|
||||
modaldata = data.message;
|
||||
mensajes = mensajes.filter(m => m !== men);
|
||||
|
||||
if (mostrarleidos) {
|
||||
Leidos();
|
||||
} else {
|
||||
SinLeer();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let dataerror = await responce.json();
|
||||
@@ -102,12 +104,89 @@
|
||||
}
|
||||
}
|
||||
|
||||
function abrirModal(mensaje: MensajeDto) {
|
||||
if (mensaje.accion === "Nuevo Alquiler") {
|
||||
Selmens = { ...mensaje };
|
||||
return;
|
||||
}
|
||||
|
||||
function abrirModal(mensaje: MensajeDto) {
|
||||
Selmens = mensaje;
|
||||
title = "Confirmar proceso de alquiler";
|
||||
message ="Aceptar este proceso eliminará la propiedad del menú de búsqueda. Se informará al inquilino que debe pasar los datos de sus garantías. ¿Desea continuar?";
|
||||
show = true;
|
||||
if (mensaje.accion === "Carge Garantes") {
|
||||
Selmens = { ...mensaje };
|
||||
setCantGarantes = Number(Selmens.mensaje.split(" ").reverse()[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje2(data: {opcionVenta:boolean, cantGarantes:number, mesesHastaAumento:number}) {
|
||||
if (data.opcionVenta == null || data.cantGarantes <=0 || data.mesesHastaAumento<=0) {
|
||||
modaldata = "Estan mal cargados los datos del form";
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let fecha = Selmens.fecha.toString();
|
||||
const datata = {
|
||||
tieneopcionventa: data.opcionVenta,
|
||||
mesesHastaAumento: data.mesesHastaAumento,
|
||||
cantidadGarantes: data.cantGarantes,
|
||||
idPropiedad: Selmens.propiedad,
|
||||
fechaprimernotificacion: fecha,
|
||||
emailInquilino: localStorage.getItem("email"),
|
||||
emailPropietario: Selmens.receptor,
|
||||
};
|
||||
|
||||
let responce = await fetch($urlG+"/api/contratos/precontrato", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(datata),
|
||||
});
|
||||
if(responce.ok) {
|
||||
let dataaa = await responce.json();
|
||||
modaldata = dataaa.message;
|
||||
if (mostrarleidos) {
|
||||
Leidos();
|
||||
} else {
|
||||
SinLeer();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let dataaa = await responce.json();
|
||||
modaldata = dataaa.message;
|
||||
return;
|
||||
} catch (e) {
|
||||
modaldata = "fallo al intentar conectar con el servidor: "+e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje3(garantes: GaranteDto[]) {
|
||||
try {
|
||||
let dat = {
|
||||
emailInquilino: localStorage.getItem("email") || "",
|
||||
idpropiedad: Selmens.propiedad,
|
||||
fecha: Selmens.fecha,
|
||||
garantes: garantes
|
||||
}
|
||||
|
||||
let responce = await fetch($urlG+"/api/contratos/addGarantes", {
|
||||
method : "PUT",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(dat),
|
||||
});
|
||||
|
||||
if (responce.ok){
|
||||
let data = await responce.json();
|
||||
|
||||
}
|
||||
} catch {
|
||||
modaldata = "no se pudo comunicar con el Servidor";
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -118,13 +197,20 @@
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")} />
|
||||
{/if}
|
||||
|
||||
<ModalConfirm
|
||||
<!--
|
||||
<ModalConfirm
|
||||
{show}
|
||||
{title}
|
||||
{message}
|
||||
onCancel={() => (show = false)}
|
||||
onConfirm={()=>1+1}
|
||||
/>
|
||||
/>
|
||||
-->
|
||||
{#if Selmens.accion == "Nuevo Alquiler" }
|
||||
<ModalPrecontrato onClose={() => (Selmens.accion = "")} onSubmit={handleEnviarmensaje2} />
|
||||
{:else if Selmens.accion == "Carge Garantes"}
|
||||
<ModalAddGarantes maxGarantes={setCantGarantes} onClose={() => (Selmens.accion = "")} onSubmit={handleEnviarmensaje3}/>
|
||||
{/if}
|
||||
<div class="container">
|
||||
<br>
|
||||
<BarraHorizontalConTexto text="Notificaciones"/>
|
||||
@@ -148,6 +234,7 @@
|
||||
<tr>
|
||||
<th>Remitente</th>
|
||||
<th>Accion</th>
|
||||
<th>Receptor</th>
|
||||
<th>Mensaje</th>
|
||||
<th>Fecha</th>
|
||||
<th>Propiedad</th>
|
||||
@@ -169,18 +256,29 @@
|
||||
<tr>
|
||||
<td>{men.remitente}</td>
|
||||
<td>{men.accion}</td>
|
||||
<td>{men.receptor}</td>
|
||||
<td>{men.mensaje}</td>
|
||||
<td>{men.fecha}</td>
|
||||
<td>{men.propiedad}</td>
|
||||
|
||||
{#if mostrarleidos == false}
|
||||
<td>
|
||||
<button
|
||||
class="btn btn-outline-primary btn-sm"
|
||||
onclick={() => abrirModal(men)}
|
||||
>
|
||||
Expandir
|
||||
</button>
|
||||
<div class="d-flex">
|
||||
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
onclick={() => abrirModal(men)}
|
||||
>
|
||||
Expandir
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-outline-danger"
|
||||
onclick={() => marcarleido(men.fecha, localStorage.getItem("email")|| "", men)}
|
||||
>
|
||||
Marcar Leido
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
{/if}
|
||||
</tr>
|
||||
|
||||
12
Front/src/types.d.ts
vendored
12
Front/src/types.d.ts
vendored
@@ -58,8 +58,18 @@ export type Propiedad = {
|
||||
export type MensajeDto = {
|
||||
remitente: string,
|
||||
accion: string,
|
||||
receptor: string,
|
||||
mensaje: string,
|
||||
fecha: Date,
|
||||
propiedad: string,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export type GaranteDto = {
|
||||
Dni: number;
|
||||
Nombre: string;
|
||||
Apellido: string;
|
||||
Domicilio: string;
|
||||
Celular: string;
|
||||
Domiciliolaboral: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user