313 lines
11 KiB
Svelte
313 lines
11 KiB
Svelte
<script lang="ts">
|
|
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
|
import { onMount } from "svelte";
|
|
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 selMod:any =$state();
|
|
let showmodal:boolean = $state(false);
|
|
let canons:CanonDto[] = $state([]);
|
|
let garantes: GaranteDto2[] = $state([]);
|
|
let prop:ContratoPropiedadDto = $state({
|
|
estado:"",
|
|
fechainicio:"",
|
|
id:0,
|
|
inquilino:"",
|
|
propietario:"",
|
|
tipoPropiedad:"",
|
|
ubicacion:"",
|
|
habitaciones:0,
|
|
piso:0,
|
|
letra:"",
|
|
mesesAumento:0,
|
|
mesesDuracion:0,
|
|
});
|
|
|
|
let modaldata:string = $state("");
|
|
let contratoid:string = $state("");
|
|
|
|
onMount(()=>{
|
|
getparams();
|
|
obtenerDatosACargar();
|
|
});
|
|
|
|
async function obtenerDatosACargar() {
|
|
try {
|
|
const respPropiedad = fetch($urlG+"/api/contrato/inquilino?id="+contratoid, {
|
|
method: "GET",
|
|
headers: {
|
|
"Auth": String(token),
|
|
}
|
|
});
|
|
const respgarantes = fetch($urlG+"/api/contratos/garantes?idcontrato="+contratoid, {
|
|
method: "GET",
|
|
headers: {
|
|
"Auth": String(token),
|
|
}
|
|
});
|
|
const respCanons = fetch($urlG+"/api/contratos/canon?id="+contratoid, {
|
|
method: "GET",
|
|
headers: {
|
|
"Auth": String(token),
|
|
}
|
|
});
|
|
const [p, g, c] = await Promise.all([respPropiedad, respgarantes, respCanons]);
|
|
|
|
const datosPropiedad = await p.json();
|
|
const datosGarantes = await g.json();
|
|
const datosCanons = await c.json();
|
|
prop = datosPropiedad;
|
|
garantes = datosGarantes;
|
|
canons = datosCanons;
|
|
} catch {
|
|
modaldata = "Fallo hacer las request";
|
|
}
|
|
}
|
|
|
|
function getparams(){
|
|
const qs = window.location.search;
|
|
const par = new URLSearchParams(qs);
|
|
contratoid = par.get("id")||"";
|
|
}
|
|
|
|
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;
|
|
}
|
|
try {
|
|
const resp = await fetch ($urlG+"/api/contrato/DocumentoFinal?idcontrato="+prop.id, {
|
|
method: "GET",
|
|
headers: {
|
|
"Auth": String(token),
|
|
}
|
|
});
|
|
|
|
if (!resp.ok) {
|
|
let blob = await resp.json();
|
|
modaldata=blob.message;
|
|
return;
|
|
}
|
|
|
|
let blob = await resp.blob();
|
|
const blobUrl = URL.createObjectURL(blob);
|
|
window.open(blobUrl, '_blank');
|
|
setTimeout(() => URL.revokeObjectURL(blobUrl), 100000);
|
|
} catch {
|
|
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";
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<NavBarAutocompletable/>
|
|
|
|
{#if modaldata}
|
|
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")}/>
|
|
{/if}
|
|
|
|
{#if showmodal}
|
|
<ModalPedirDoc onClose={()=>showmodal=false} onSubmit={pedirdocumento} />
|
|
{/if}
|
|
|
|
<div class="container-fluid mt-4 d-flex">
|
|
<div class="col-md-4 me-4">
|
|
<div class="card">
|
|
<div class="card-header text-center">Propiedad</div>
|
|
<div class="card-body">
|
|
<p><b>Tipo:</b> {prop.tipoPropiedad}</p>
|
|
<p><b>Ubicación:</b> {prop.ubicacion}</p>
|
|
<p><b>Propietario:</b> {prop.propietario}</p>
|
|
<p><b>Inquilino:</b> {prop.inquilino}</p>
|
|
<p><b>Habitaciones:</b> {prop.habitaciones}</p>
|
|
<p><b>Piso:</b> {prop.piso}</p>
|
|
<p><b>Letra:</b> {prop.letra}</p>
|
|
<p><b>Fecha Inicio:</b> {String(prop.fechainicio).split("T")[0]}</p>
|
|
<p><b>Estado:</b> {prop.estado}</p>
|
|
<button class="btn btn-secondary" onclick={verContrato}>
|
|
Ver Contrato
|
|
</button>
|
|
</div>
|
|
<div class="card-footer text-center">
|
|
IdContrato: {prop.id}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col d-flex flex-column">
|
|
<div class="accordion mb-4" id="accordionExample">
|
|
<div class="accordion-item">
|
|
<h2 class="accordion-header" id="headingOne">
|
|
<button
|
|
class="accordion-button"
|
|
type="button"
|
|
data-bs-toggle="collapse"
|
|
data-bs-target="#collapseOne"
|
|
aria-expanded="true"
|
|
aria-controls="collapseOne"
|
|
>
|
|
Garantes
|
|
</button>
|
|
</h2>
|
|
<div
|
|
id="collapseOne"
|
|
class="accordion-collapse collapse show"
|
|
aria-labelledby="headingOne"
|
|
data-bs-parent="#accordionExample"
|
|
>
|
|
<div class="accordion-body">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Dni</th>
|
|
<th>Nombre</th>
|
|
<th>Apellido</th>
|
|
<th>Domicilio</th>
|
|
<th>Dom. Laboral</th>
|
|
<th>Celular</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{#each garantes as g}
|
|
<tr>
|
|
<td>{g.dni}</td>
|
|
<td>{g.nombre}</td>
|
|
<td>{g.apellido}</td>
|
|
<td>{g.domicilio}</td>
|
|
<td>{g.domiciliolaboral}</td>
|
|
<td>{g.celular}</td>
|
|
</tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="accordion-item">
|
|
<h2 class="accordion-header" id="headingTwo">
|
|
<button
|
|
class="accordion-button collapsed"
|
|
type="button"
|
|
data-bs-toggle="collapse"
|
|
data-bs-target="#collapseTwo"
|
|
aria-expanded="false"
|
|
aria-controls="collapseTwo"
|
|
>
|
|
Canons
|
|
</button>
|
|
</h2>
|
|
<div
|
|
id="collapseTwo"
|
|
class="accordion-collapse collapse"
|
|
aria-labelledby="headingTwo"
|
|
data-bs-parent="#accordionExample"
|
|
>
|
|
<div class="accordion-body">
|
|
<div class="row">
|
|
{#each canons as canon}
|
|
<div class="col-6 mb-3">
|
|
<div class="card">
|
|
<div class="card-header text-center">
|
|
{canon.mesNum}/{prop.mesesDuracion}
|
|
</div>
|
|
<div class="card-body">
|
|
<p><strong>Mes:</strong> {String(canon.mes).split("T")[0]}</p>
|
|
<p><strong>Monto:</strong> {canon.monto}</p>
|
|
<p><strong>Divisa:</strong> {canon.divisa}</p>
|
|
<p><strong>Pago:</strong> {canon.pago ? "Sí" : "No"}</p>
|
|
</div>
|
|
<div class="card-footer d-flex justify-content-between">
|
|
<button class="btn btn-primary btn-xs" disabled={canon.pago} onclick={()=>realizarpago(canon.mes)}>
|
|
Pagar
|
|
</button>
|
|
<button class="btn btn-info btn-xs" disabled={!canon.pago} onclick={()=> generarTiket(canon)}>
|
|
Generar Tiket
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{/each}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|