dev #56
25
Aspnet/Builder/DtoBuilder/OpcionVentaDtoBuilder.cs
Normal file
25
Aspnet/Builder/DtoBuilder/OpcionVentaDtoBuilder.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Entidades.Dto;
|
||||
|
||||
namespace AlquilaFacil.Builder;
|
||||
public class OpcionVentaDtoBuilder: Builder<OpcionVentaDto>{
|
||||
public OpcionVentaDtoBuilder SetId(long id) {
|
||||
data.Id = id;
|
||||
return this;
|
||||
}
|
||||
public OpcionVentaDtoBuilder SetMonto(decimal monto) {
|
||||
data.Monto = monto;
|
||||
return this;
|
||||
}
|
||||
public OpcionVentaDtoBuilder SetDivisa(string divisa) {
|
||||
data.Divisa = divisa;
|
||||
return this;
|
||||
}
|
||||
public OpcionVentaDtoBuilder SetEnOrden(bool v) {
|
||||
data.EnOrden = v;
|
||||
return this;
|
||||
}
|
||||
public OpcionVentaDtoBuilder SetFueEjercido(int idestado) {
|
||||
data.FueEjercido = idestado==1?false:true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
41
Aspnet/Builder/DtoBuilder/VentasDtoBuilder.cs
Normal file
41
Aspnet/Builder/DtoBuilder/VentasDtoBuilder.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Entidades.Dto;
|
||||
|
||||
namespace AlquilaFacil.Builder;
|
||||
public class VentasDtoBuilder: Builder<VentasDto> {
|
||||
public VentasDtoBuilder SetId(long id) {
|
||||
data.Id = id;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetMonto(decimal monto) {
|
||||
data.Monto = monto;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetDivisa(string divisa) {
|
||||
data.Divisa = divisa;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetUbicacion(string ubicacion) {
|
||||
data.Ubicacion = ubicacion;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetNombreVendedor(string nombre) {
|
||||
data.NombreVendedor = nombre;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetIdVendedor(long idVendedor) {
|
||||
data.IdVendedor = idVendedor;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetNombreComprador(string nombre) {
|
||||
data.NombreComprador = nombre;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetIdComprador(long Id) {
|
||||
data.IdComprador = Id;
|
||||
return this;
|
||||
}
|
||||
public VentasDtoBuilder SetEstado(string estado) {
|
||||
data.Estado = estado;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,9 @@ public class PrecontratoBuilder : Builder<Contrato> {
|
||||
data.MesesDurationContrato = mesesDuracionContrato;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PrecontratoBuilder SetOpcionVenta(bool tieneOpcionVenta){
|
||||
data.Tieneopcionventa = tieneOpcionVenta == false?0Lu:1Lu;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,217 @@ using Entidades;
|
||||
using System.Linq.Expressions;
|
||||
using AlquilaFacil.StrategyBusquedaAdmin;
|
||||
using System.Diagnostics;
|
||||
using AlquilaFacil.Builder;
|
||||
using Minio.DataModel.Args;
|
||||
using Minio;
|
||||
using AlquilaFacil.Config;
|
||||
using System.Text.Json;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class AdminController: ControllerBase
|
||||
{
|
||||
|
||||
[HttpGet("api/contratos/controlPagos")]
|
||||
public IActionResult obtenerContratosInpagos([FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 14);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
var contratos = RepositorioContratos.Singleton.ObtenerContratosInpagos();
|
||||
|
||||
List<ContratoDto> dtos = new();
|
||||
foreach (var i in contratos) {
|
||||
if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null
|
||||
|| i.DnipropietarioNavigation == null) continue;
|
||||
|
||||
var cont = new ContratoDtoBuilder()
|
||||
.SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}")
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}")
|
||||
.SetId(i.Id)
|
||||
.SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion)
|
||||
.SetFechaInicio(i.Fechainicio)
|
||||
.SetEstado(i.Habilitado, i.Cancelado)
|
||||
.Build();
|
||||
dtos.Add(cont);
|
||||
}
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
||||
[HttpGet("api/contratos/controlPagos/propiedad")]
|
||||
public IActionResult obtenerPropiedad([FromHeader(Name = "Auth")] string Auth, int id = 0) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Admin");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (id <= 0) return BadRequest(new { message = "No hay propiedades con id igual o menor a 0"});
|
||||
var i = RepositorioContratos.Singleton.ObtenerContratoPorId(id);
|
||||
if (i == null || i.DniinquilinoNavigation == null ||
|
||||
i.IdpropiedadNavigation == null || i.DnipropietarioNavigation == null)return BadRequest(new { message = "Fallo la query"});
|
||||
|
||||
var cont = new ContratoPropiedadDtoBuilder()
|
||||
.SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}")
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetId(i.Id)
|
||||
.SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}")
|
||||
.SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion)
|
||||
.SetFechaInicio(i.Fechainicio)
|
||||
.SetEstado(i.Habilitado, i.Cancelado)
|
||||
.SetHabitaciones(i.IdpropiedadNavigation.Canthabitaciones)
|
||||
.SetPiso(i.IdpropiedadNavigation.Piso??0)
|
||||
.SetLetra(i.IdpropiedadNavigation.Letra??"")
|
||||
.SetMesesAumento(i.MesesHastaAumento)
|
||||
.SetMesesDuracion(i.MesesDurationContrato)
|
||||
.Build();
|
||||
|
||||
return Ok(cont);
|
||||
}
|
||||
|
||||
private readonly IMinioClient mc;
|
||||
public AdminController(IMinioClient minioClient) {
|
||||
mc = minioClient;
|
||||
if (mc == null){
|
||||
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json"))?? null;
|
||||
if (mcon == null) throw new Exception();
|
||||
|
||||
mc = new MinioClient().WithCredentials(mcon.usr, mcon.scrt)
|
||||
.WithEndpoint("192.168.1.11:9000")
|
||||
.WithSSL(false)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
[HttpGet("/api/admin/contrato/verDocumento")]
|
||||
public IActionResult verDocumento([FromHeader(Name = "Auth")] string Auth, int idcontrato = 0){
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Admin");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"});
|
||||
|
||||
Contrato? contr = RepositorioContratos.Singleton.ObtenerContratoPorId(idcontrato);
|
||||
|
||||
try{
|
||||
var memstream = new MemoryStream();
|
||||
|
||||
var goa = new GetObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(contr.UrlContrato)
|
||||
.WithCallbackStream(stream => {
|
||||
memstream.Position=0;
|
||||
stream.CopyTo(memstream);
|
||||
});
|
||||
|
||||
mc.GetObjectAsync(goa).Wait();
|
||||
memstream.Position = 0;
|
||||
|
||||
if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" });
|
||||
|
||||
return File(memstream, "application/pdf", contr.UrlContrato);
|
||||
|
||||
} catch (Exception e){
|
||||
Console.Error.WriteLine(e);
|
||||
return BadRequest(new { message = "Fallo al intentar obtener el archivo del almacenamiento o este no existe"});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("api/admin/contrato/canons")]
|
||||
public IActionResult ObtenerCanones([FromHeader(Name="Auth")]string Auth, int id = 0){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Admin");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
var cont = RepositorioContratos.Singleton.ObtenerContratoPorId(id);
|
||||
if (cont == null) return BadRequest(new { message = "No existe el contrato"});
|
||||
|
||||
var list = RepositorioCanons.Singleton.ObtenerCanonsPorContrato(id);
|
||||
if (list == null) return BadRequest(new { message = "No hay contrato por esa id"});
|
||||
|
||||
DateTime date = DateTime.Now;
|
||||
bool ret =list.Any(x=>x.Pagado ==0 && date > x.Fecha);
|
||||
if (ret == true) return BadRequest(new { message = "Este contrato no tiene canones vencidos"});
|
||||
|
||||
string divisa ="";
|
||||
if (cont.Iddivisa == 0) divisa = "AR$"; else if (cont.Iddivisa == 1) divisa = "US$";
|
||||
|
||||
List<CanonDto> d = new();
|
||||
|
||||
foreach (var i in list) {
|
||||
var c = new CanonDtoBuilder()
|
||||
.SetId(i.Id)
|
||||
.SetPago(i.Idrecibo==null?false:true)
|
||||
.SetDivisa(divisa==""?"Ugh esta mal cargado la divisa en el contrato":divisa)
|
||||
.SetMes(i.Fecha)
|
||||
.SetMesNum(int.Parse((i.Fecha.Month - cont.Fechainicio.Month).ToString()) + 1)
|
||||
.SetMonto(i.Monto)
|
||||
.Build();
|
||||
d.Add(c);
|
||||
}
|
||||
|
||||
return Ok(d);
|
||||
}
|
||||
|
||||
[HttpPost("api/admin/contrato/marcarPago")]
|
||||
public IActionResult realizarPago([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Admin");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (dto.Idcontrato<=0) return BadRequest(new { message = "No puede existir un contrato con id 0 o menor"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null)return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.Idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"});
|
||||
|
||||
Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato);
|
||||
if (c == null) return BadRequest(new { message = "no hay un canon por esa id"});
|
||||
|
||||
Recibo re = new Recibo{
|
||||
Monto = c.Monto,
|
||||
Fecha = DateTime.Now,
|
||||
};
|
||||
|
||||
bool ret = RepositorioCanons.Singleton.SetRecibo(c, re, cli.Dni, "Admin Marca Recibo Como Pago");
|
||||
return ret ?
|
||||
Ok(new { message = "Se guardo correctamente"}):BadRequest(new { message = "No se pudo guardar"});
|
||||
}
|
||||
|
||||
[HttpPost("api/admin/notificarInquilino")]
|
||||
public IActionResult NotificarInquilino([FromHeader(Name ="Auth")]string Auth, NotificarAdmin data){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Admin");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null)return Unauthorized();
|
||||
|
||||
if (data.Mensaje == "") return BadRequest(new {message = "El campo Mensaje esta vacio"});
|
||||
if (data.Idcontrato <= 0) return BadRequest(new {message = "La id de contrato no puede ser 0 o menor"});
|
||||
if (data.Idcanon <= 0) return BadRequest(new {message = "La id de contrato no puede ser 0 o menor"});
|
||||
|
||||
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(data.Idcontrato);
|
||||
if (cont == null || cont.DniinquilinoNavigation == null || cont.DnipropietarioNavigation == null || cont.IdpropiedadNavigation == null) return BadRequest(new { message = "no hay un contrato por esa id"});
|
||||
|
||||
Canon? can = RepositorioCanons.Singleton.ObtenerCanonPorId(data.Idcanon);
|
||||
if (can == null)return BadRequest(new { message = "No existe un canon por esa id"});
|
||||
|
||||
var n = new NotificacioneBuilder()
|
||||
.SetAccion("Notificacion Inquilino")
|
||||
.SetMensaje(data.Mensaje)
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(cont.DniinquilinoNavigation.Dni)
|
||||
.SetDniremitente(cont.DnipropietarioNavigation.Dni)
|
||||
.SetIdpropiedad(cont.IdpropiedadNavigation.Id)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
var ret = RepositorioNotificaciones.Singleton.AltaNotificacion(n, cli.Dni);
|
||||
return ret?
|
||||
Ok(new { message = "se envio el aviso" }):BadRequest(new { message = "Fallo al intentar enviar el aviso" });
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("api/admin/clientes")]
|
||||
public IActionResult GetClientes([FromHeader(Name ="Auth")]string Auth){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -21,6 +227,46 @@ public class AdminController: ControllerBase
|
||||
return Ok(list);
|
||||
}
|
||||
|
||||
[HttpGet("api/admin/cliente")]
|
||||
public IActionResult ObtenerCliente([FromHeader(Name ="Auth")]string Auth, long dni = 0){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
if (dni <= 0) return BadRequest(new { message = "No puede haber un dni 0 o menor"});
|
||||
|
||||
Cliente? cambio = RepositorioUsuarios.Singleton.ObtenerClientePorDni(dni);
|
||||
if (cambio == null) BadRequest(new { message = "no hay un cliente por ese dni"});
|
||||
|
||||
UpdateUsuarioAdmin a = new UpdateUsuarioAdmin{
|
||||
Apellido = cambio.Apellido,
|
||||
Celular = cambio.Celular,
|
||||
Domicilio = cambio.Domicilio,
|
||||
Nombre = cambio.Nombre,
|
||||
};
|
||||
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
[HttpPatch("api/admin/cliente")]
|
||||
public IActionResult PatchCliente([FromHeader(Name ="Auth")]string Auth, [FromBody]UpdateUsuarioAdmin dto, [FromQuery]long dni=0){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
if (dni <= 0) return BadRequest(new { message = "No puede haber un dni 0 o menor"});
|
||||
|
||||
var validacion2 = checkdto(dto);
|
||||
if (validacion2 != "") return BadRequest(new { message = validacion2});
|
||||
|
||||
Cliente?cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
bool ret = RepositorioUsuarios.Singleton.PatchUsuario(dto, dni, cli.Dni);
|
||||
|
||||
return ret?
|
||||
Ok(new { message = "Se actualizaron los datos"}):
|
||||
BadRequest(new { message = "Fallo al guardar los datos"});
|
||||
}
|
||||
|
||||
[HttpGet("api/admin/clientes/grupo")]
|
||||
public IActionResult GetGruposByCliente([FromHeader(Name ="Auth")]string Auth, [FromQuery]long Dni){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -38,12 +284,15 @@ public class AdminController: ControllerBase
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||
|
||||
if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" });
|
||||
|
||||
var ret = RepositorioUsuarios.Singleton.CheckGrupo(data.email, data.grupo);
|
||||
if (ret) return BadRequest(new { message = $"El usuario ya pertenece al grupo {data.grupo}"});
|
||||
|
||||
var ret2 = RepositorioUsuarios.Singleton.AñadirClienteAGrupo(data.email, data.grupo);
|
||||
var ret2 = RepositorioUsuarios.Singleton.AñadirClienteAGrupo(data.email, data.grupo, cli.Dni);
|
||||
|
||||
return ret2 ? Ok(new {message = "Se Añadio al Grupo"}): BadRequest(new { message = "Fallo al añadirse al Grupo" });
|
||||
}
|
||||
@@ -54,6 +303,10 @@ public class AdminController: ControllerBase
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||
|
||||
|
||||
if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" });
|
||||
|
||||
//una ward para que no me bloquee a mi mismo de tener acceso a admin
|
||||
@@ -74,7 +327,7 @@ public class AdminController: ControllerBase
|
||||
if ( ret5 == null || ret5.Where(x=>x.Habilitado == 0).Count() > 0) return BadRequest(new { message = "Aun tenes alquileres pendientes o fallo al intentar obtener la lista de alquileres, no se puede dar de baja"});
|
||||
}
|
||||
|
||||
var ret2 = RepositorioUsuarios.Singleton.EliminarClienteAGrupo(data.email, data.grupo);
|
||||
var ret2 = RepositorioUsuarios.Singleton.EliminarClienteAGrupo(data.email, data.grupo, cli.Dni);
|
||||
return ret2 ? Ok(new {message = $"Se elimino del Grupo: {data.grupo}"}): BadRequest(new { message = "Fallo al añadirse al Grupo" });
|
||||
}
|
||||
|
||||
@@ -117,8 +370,11 @@ public class AdminController: ControllerBase
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (id <= 0) return BadRequest(new { message = "Falto indicar id Propiedad"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id);
|
||||
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id, cli.Dni);
|
||||
return ret ?
|
||||
Ok(new {message = "Se cambio el estado de la propiedad"}): BadRequest(new { message = "No se pudo dar de baja"});
|
||||
}
|
||||
@@ -149,4 +405,13 @@ public class AdminController: ControllerBase
|
||||
int ret = RepositorioPropiedades.Singleton.CuantasPaginasBusqueda(cantidadHabitaciones, servicios, tipoPropiedad, 0);
|
||||
return Ok(new { message = ret});
|
||||
}
|
||||
|
||||
private string checkdto(UpdateUsuarioAdmin d){
|
||||
string ret ="";
|
||||
if (d.Nombre=="") ret+="Campo Nombre vacio\n";
|
||||
if (d.Apellido=="") ret+="Campo Apellido vacio\n";
|
||||
if (d.Celular=="") ret+="Campo Celular vacio\n";
|
||||
if (d.Domicilio=="")ret+="Campo Domicilio vacio\n";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,10 @@ public class ContratoController: ControllerBase {
|
||||
|
||||
Recibo re = new Recibo{
|
||||
Monto = c.Monto,
|
||||
Fecha = c.Fecha,
|
||||
Fecha = DateTime.Now,
|
||||
};
|
||||
|
||||
bool ret = RepositorioCanons.Singleton.SetRecibo(c, re);
|
||||
bool ret = RepositorioCanons.Singleton.SetRecibo(c, re, cli.Dni);
|
||||
return ret ?
|
||||
Ok(new { message = "Se guardo correctamente"}):BadRequest(new { message = "No se pudo guardar"});
|
||||
|
||||
@@ -111,10 +111,10 @@ public class ContratoController: ControllerBase {
|
||||
|
||||
Recibo re = new Recibo{
|
||||
Monto = c.Monto,
|
||||
Fecha = c.Fecha,
|
||||
Fecha = DateTime.Now,
|
||||
};
|
||||
|
||||
bool ret = RepositorioCanons.Singleton.SetRecibo(c, re);
|
||||
bool ret = RepositorioCanons.Singleton.SetRecibo(c, re, cli.Dni);
|
||||
return ret ?
|
||||
Ok(new { message = "Se guardo correctamente"}):BadRequest(new { message = "No se pudo guardar"});
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class ContratoController: ControllerBase {
|
||||
if (cont == null) return BadRequest(new { message = "no hay un contrato por esa id"});
|
||||
if (cli.Dni != cont.Dnipropietario) return BadRequest(new {message = "No sos el propietario o intenta volviendote a logear"});
|
||||
|
||||
var ret = RepositorioCanons.Singleton.CrearCanons(dto.aumento, dto.idcontrato);
|
||||
var ret = RepositorioCanons.Singleton.CrearCanons(dto.aumento, dto.idcontrato, cli.Dni);
|
||||
return ret ?
|
||||
Ok(new { message = "Se crearon los canons correctamente"}):BadRequest(new { message = "No se pudo guardar"});
|
||||
}
|
||||
@@ -336,6 +336,7 @@ public class ContratoController: ControllerBase {
|
||||
.SetPropiedad(p.Id)
|
||||
.SetFecha(DateTime.Parse(dto.fechaprimernotificacion))
|
||||
.SetMesesDuracion(dto.MesesDuracionContrato)
|
||||
.SetOpcionVenta(dto.TieneOpcionVenta)
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -349,7 +350,18 @@ public class ContratoController: ControllerBase {
|
||||
.SetMensaje($"El propietario {propi.Nombre} {propi.Apellido} te requiere que carges informacion de {dto.CantidadGarantes} Garantes")
|
||||
.Build();
|
||||
|
||||
var ret = RepositorioContratos.Singleton.CargaPrecontrato(precontrato, notificacion);
|
||||
bool ret;
|
||||
if (dto.TieneOpcionVenta==false){
|
||||
ret = RepositorioContratos.Singleton.CargaPrecontrato(cli.Dni, precontrato, notificacion);
|
||||
} else {
|
||||
Venta v = new Venta{
|
||||
Idestado = 1,
|
||||
Iddivisa = dto.iddivisa,
|
||||
Monto = dto.MontoOpcion,
|
||||
};
|
||||
ret = RepositorioContratos.Singleton.CargaPrecontratoOpcionVenta(precontrato, notificacion, v, cli.Dni);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, DateTime.Parse(dto.fechaprimernotificacion));
|
||||
}
|
||||
@@ -399,7 +411,7 @@ public class ContratoController: ControllerBase {
|
||||
var contr = RepositorioContratos.Singleton.ObtenerContrato(dto.EmailInquilino, dto.Idpropiedad);
|
||||
if (contr == null) return BadRequest(new { message = "No existe el contrato o ya fue activado"});
|
||||
|
||||
var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad);
|
||||
var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad, cli.Dni);
|
||||
if (ret) {
|
||||
Console.WriteLine(dto.fecha);
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.fecha);
|
||||
@@ -428,6 +440,9 @@ public class ContratoController: ControllerBase {
|
||||
var validacion2 = ValidarCancelarDto(dto);
|
||||
if (validacion2 != "") return BadRequest(new {message = validacion2});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli==null) return Unauthorized();
|
||||
|
||||
Cliente? pro = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(dto.EmailPropietario);
|
||||
if (pro == null) return BadRequest(new {message = "No Existe Usuario con ese email"});
|
||||
if (pro.Token != Auth) return BadRequest(new {message = "El token de auth no corresponde al token el usuario propietario"});
|
||||
@@ -439,10 +454,10 @@ public class ContratoController: ControllerBase {
|
||||
var inq = RepositorioInquilinos.Singleton.ObtenerInquilinoPorEmail(dto.EmailInquilino);
|
||||
if (inq == null) return BadRequest(new {message = "No hay un inquilino por ese email"});
|
||||
|
||||
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.EmailInquilino, dto.idpropiedad);
|
||||
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.EmailInquilino, dto.idpropiedad, cli.Dni);
|
||||
if (ret) {
|
||||
prop.Idestado = 1;
|
||||
ret = RepositorioPropiedades.Singleton.PatchPropiedad(prop);
|
||||
ret = RepositorioPropiedades.Singleton.PatchPropiedad(prop, pro.Dni);
|
||||
if (ret){
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(pro.Dni, dto.fecha);
|
||||
var noti = new NotificacioneBuilder()
|
||||
@@ -537,7 +552,7 @@ public class ContratoController: ControllerBase {
|
||||
bool ret = await subirContrato(contrato, nuevoNombreArchivo);
|
||||
if(ret == false) return BadRequest(new {message = "No se pudo subir el archivo"});
|
||||
|
||||
ret = RepositorioContratos.Singleton.AddUrl(contr.Id, nuevoNombreArchivo);
|
||||
ret = RepositorioContratos.Singleton.AddUrl(contr.Id, nuevoNombreArchivo, cli.Dni);
|
||||
if (ret == false) return BadRequest(new { message = "No se pudo guardar la url del contrato" });
|
||||
|
||||
var noti = new NotificacioneBuilder()
|
||||
@@ -658,7 +673,7 @@ public class ContratoController: ControllerBase {
|
||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||
if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"});
|
||||
|
||||
bool ret = RepositorioContratos.Singleton.AceptarContrato(dto.Idcontrato);
|
||||
bool ret = RepositorioContratos.Singleton.AceptarContrato(dto.Idcontrato, cli.Dni);
|
||||
if (ret == false) return BadRequest(new { message ="fallo al aceptar el contrato"});
|
||||
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||
@@ -695,7 +710,7 @@ public class ContratoController: ControllerBase {
|
||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||
if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"});
|
||||
|
||||
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.Idcontrato);
|
||||
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.Idcontrato, cli.Dni);
|
||||
if (ret == false) return BadRequest(new {message = "Fallo al intentar cancelar el precontrato"});
|
||||
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||
@@ -816,6 +831,7 @@ public class ContratoController: ControllerBase {
|
||||
if (dto.MesesHastaAumento <= 0) ret += "No puede tener 0 o menos meses hasta el aumento\n";
|
||||
if (dto.MesesDuracionContrato <= 0) ret += "No puede tener 0 o menos meses de duracion\n";
|
||||
if (dto.MesesDuracionContrato < dto.MesesHastaAumento) ret += "el tiempo hasta aumento no puede ser mayor de \n";
|
||||
if (dto.TieneOpcionVenta == true && dto.MontoOpcion <=0) ret +="No puede tener un monto de venta negativo o 0";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ public class DefectoController: ControllerBase {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli =RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
string r = ValidarDto(data);
|
||||
if (r != "") return BadRequest(new { message = r });
|
||||
|
||||
@@ -65,7 +68,7 @@ public class DefectoController: ControllerBase {
|
||||
Idestado = 1,
|
||||
|
||||
};
|
||||
var b = RepositorioDefectos.Singleton.AltaDefecto(defecto);
|
||||
var b = RepositorioDefectos.Singleton.AltaDefecto(defecto, cli.Dni);
|
||||
return b ?Ok(new { message = "Se cargo el Defecto en el sistema"}):BadRequest(new { message ="No se pudo cargar el defecto en el sistema"});
|
||||
}
|
||||
|
||||
@@ -86,8 +89,11 @@ public class DefectoController: ControllerBase {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli==null) return Unauthorized();
|
||||
|
||||
if (iddefecto<=0) return BadRequest(new { message = "No hay canones con id 0 o menor"});
|
||||
bool ret = RepositorioDefectos.Singleton.MarcarPago(iddefecto);
|
||||
bool ret = RepositorioDefectos.Singleton.MarcarPago(iddefecto, cli.Dni);
|
||||
|
||||
return ret ?
|
||||
Ok(new { message = "Se marco como pagado" }):BadRequest(new { message = "Fallo el acceso a la base de datos o no se encontro el defecto" });
|
||||
|
||||
@@ -17,6 +17,19 @@ public class EstadisticaController: ControllerBase {
|
||||
var a = RepositorioEstadisticas.Singleton.ObtenerDataIniciadosPorAño(year);
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
[HttpGet("api/contrato/stats")]
|
||||
public IActionResult ObtenerMesesPagos([FromHeader(Name ="Auth")]string Auth, long idcontrato=0){
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (idcontrato<=0) return BadRequest(new {message = "No puede tener un id contrato menor o igual a 0"});
|
||||
|
||||
var ret = RepositorioEstadisticas.Singleton.ObtenerDatosPagosContrato(idcontrato);
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpGet("api/tabla/alquileresIniciados")]
|
||||
public IActionResult tablaalquileresIniciadosEsteAño([FromHeader(Name ="Auth")]string Auth, int year) {
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#if DEBUG
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class GruposController: ControllerBase {
|
||||
[HttpPost("api/admin/grupos")]
|
||||
public IActionResult CrearGrupo([FromBody] AdminGrupo grupo, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (!string.IsNullOrEmpty(Auth)) return BadRequest();
|
||||
var ret2 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
||||
if (ret2 == false) return BadRequest(ret2);
|
||||
|
||||
if (String.IsNullOrEmpty(grupo.descripcion)) return BadRequest();
|
||||
|
||||
bool ret = RepositorioGrupos.Singleton.CrearGrupo(grupo.descripcion);
|
||||
return (ret) ? Ok(ret) : BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
public record AdminGrupo(string descripcion);
|
||||
#endif
|
||||
62
Aspnet/Controllers/LogsController.cs
Normal file
62
Aspnet/Controllers/LogsController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class LogsController: ControllerBase {
|
||||
|
||||
[HttpGet("/api/Logs")]
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, int pag=1) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
if (pag<=0) return BadRequest(new { message = "no puede haber una pagina 0 o menor"});
|
||||
|
||||
pag-=1;
|
||||
|
||||
var l = RepositorioLogs.Singleton.ObtenerLogsPaginado(pag);
|
||||
List<LogDto> ll = new();
|
||||
foreach (var i in l) {
|
||||
ll.Add(new LogDto{
|
||||
Fecha = i.Fecha,
|
||||
Accion = i.Accion,
|
||||
Dniusuario = i.Dniusuario,
|
||||
});
|
||||
}
|
||||
return Ok(ll);
|
||||
}
|
||||
|
||||
[HttpGet("/api/Logs/detalle")]
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, [FromQuery]DateTime fecha, [FromQuery]long idusuario) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
if (idusuario<=0) return BadRequest(new { message = "no puede haber un id 0 o menor"});
|
||||
|
||||
var l = RepositorioLogs.Singleton.ObtenerDetallesLogs(fecha, idusuario);
|
||||
List<LogDetalleDto> ll = new();
|
||||
foreach (var i in l) {
|
||||
ll.Add(new LogDetalleDto{
|
||||
Fecha = i.Fecha,
|
||||
Dniusuario = i.Dniusuario,
|
||||
NombreTabla = i.NombreTabla,
|
||||
Columna = i.Columna,
|
||||
ValorAnterior = i.ValorAnterior,
|
||||
ValorNuevo = i.ValorNuevo,
|
||||
});
|
||||
}
|
||||
return Ok(ll);
|
||||
}
|
||||
|
||||
[HttpGet("/api/Logs/cantPag")]
|
||||
public IActionResult cantidadPaginas([FromHeader(Name = "Auth")] string Auth){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
int c = RepositorioLogs.Singleton.ObtenerCantidadPaginas();
|
||||
return Ok(c);
|
||||
}
|
||||
}
|
||||
@@ -121,4 +121,38 @@ public class NotificacionesController: ControllerBase {
|
||||
return ret?
|
||||
Ok(new { message = "se envio el aviso" }):BadRequest(new { message = "Fallo al intentar enviar el aviso" });
|
||||
}
|
||||
|
||||
[HttpPost("api/notificar/ConsultaCompra")]
|
||||
public IActionResult EnviarConsultaCompra([FromHeader(Name ="Auth")]string Auth, AltaNotificacionDto dto) {
|
||||
if (String.IsNullOrWhiteSpace(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.Accion == "") return BadRequest(new{message = "El campo Accion esta vacio"});
|
||||
if (dto.Mensaje == "") return BadRequest(new {message = "El campo Mensaje esta vacio"});
|
||||
|
||||
Cliente?cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.Propiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No hay una propiedad con id 0 o menor"});
|
||||
|
||||
var n = new NotificacioneBuilder()
|
||||
.SetAccion("Consulta Compra")
|
||||
.SetMensaje(dto.Mensaje)
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(prop.Dnipropietario??0)
|
||||
.SetDniremitente(cli.Dni)
|
||||
.SetIdpropiedad(prop.Id)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
var ret2= RepositorioNotificaciones.Singleton.AltaNotificacion(n, cli.Dni);
|
||||
return ret2?
|
||||
Ok(new { message = "se envio el aviso" }):BadRequest(new { message = "Fallo al intentar enviar el aviso" });
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#if DEBUG
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class PermisosController: ControllerBase {
|
||||
[HttpPost("api/admin/permisos")]
|
||||
public IActionResult CrearPermisos([FromBody] AdminPermiso permiso, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (!string.IsNullOrEmpty(Auth)) return BadRequest();
|
||||
var ret2 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 11);
|
||||
if (ret2 == false) return BadRequest(ret2);
|
||||
|
||||
if (String.IsNullOrEmpty(permiso.descripcion)) return BadRequest();
|
||||
|
||||
bool ret = RepositorioPermisos.Singleton.CrearPermiso(permiso.descripcion);
|
||||
return (ret) ? Ok(ret) : BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
public record AdminPermiso(string descripcion);
|
||||
#endif
|
||||
@@ -25,6 +25,72 @@ public class PropiedadesController: ControllerBase {
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpGet("/api/propiedades/Venta")]
|
||||
public IActionResult ObtenerPropiedadesParaVenta([FromHeader(Name = "Auth")] string Auth, int pag = 0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (pag<=0) return BadRequest(new { message = "no existe una pagina 0"});
|
||||
|
||||
pag-=1;
|
||||
|
||||
var props = RepositorioPropiedades.Singleton.ObtenerPropiedadesEnVenta(pag);
|
||||
if (props == null) return BadRequest(new { message = "no tengo claro que fallo creo que no existen propiedades en venta"});
|
||||
|
||||
List<PropiedadesVentaDto> l = new();
|
||||
|
||||
foreach (var i in props) {
|
||||
var p = new PropiedadesVentaDto{
|
||||
Id = i.Id,
|
||||
Ubicacion = i.Ubicacion,
|
||||
Canthabitaciones = i.Canthabitaciones,
|
||||
Divisa = i.IddivisaNavigation.Signo,
|
||||
Letra = i.Letra??"",
|
||||
Monto = i.Monto,
|
||||
Piso = i.Piso??0,
|
||||
Servicios =string.Join(", ", i.IdServicios.Select(s => s.Descripcion)),
|
||||
Tipo = i.IdtipropiedadNavigation.Descripcion,
|
||||
};
|
||||
l.Add(p);
|
||||
}
|
||||
|
||||
int cantpag = RepositorioPropiedades.Singleton.ObtenerPaginasDePropiedadesEnVenta();
|
||||
|
||||
return Ok(new { propiedades = l, cantpaginas = cantpag});
|
||||
}
|
||||
|
||||
[HttpGet("api/propiedades/Venta/Propietario")]
|
||||
public IActionResult ObtenerPropiedadesVentaDePropietario( [FromHeader(Name = "Auth")] string Auth){
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var props = RepositorioPropiedades.Singleton.ObtenerPropiedadesAVentaPorDni(cli.Dni);
|
||||
List<PropiedadesDto> ll = new();
|
||||
|
||||
foreach (var i in props) {
|
||||
var a = new PropiedadesDto {
|
||||
id = i.Id,
|
||||
Ubicacion = i.Ubicacion,
|
||||
canthabitaciones = i.Canthabitaciones,
|
||||
Iddivisa = i.Iddivisa,
|
||||
letra = i.Letra??"",
|
||||
Monto = (int)i.Monto, //mmmm
|
||||
piso = i.Piso??0,
|
||||
Servicios = string.Join(", ", i.IdServicios.Select(x => x.Descripcion)),
|
||||
Tipo = i.IdtipropiedadNavigation.Descripcion,
|
||||
};
|
||||
ll.Add(a);
|
||||
}
|
||||
return Ok(ll);
|
||||
}
|
||||
|
||||
[HttpGet("api/propiedad")]
|
||||
public IActionResult ObtenerPropiedadPorId(int Id, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -146,7 +212,7 @@ public class PropiedadesController: ControllerBase {
|
||||
Iddivisa = propiedad.Iddivisa,
|
||||
};
|
||||
|
||||
bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop);
|
||||
bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop, cli.Dni);
|
||||
return (ret)?
|
||||
Ok(new {message = "Fue modificado Correctamente"}):
|
||||
BadRequest(new {message = "Fallo al modificar la base de datos"});
|
||||
@@ -203,11 +269,13 @@ public class PropiedadesController: ControllerBase {
|
||||
if (servicio.idServicios.Count() < 1) return BadRequest(new {message ="Falta añadir servicios"});
|
||||
if (servicio.idServicios.Any(x => x<= 0)) return BadRequest(new {message ="No tienen haber ids negativas o cero de servicio"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
|
||||
var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(servicio.propiedadid);
|
||||
|
||||
var repetidos = serv.Intersect(servicio.idServicios);
|
||||
|
||||
bool ret = RepositorioPropiedades.Singleton.BajaServiciosAPropiedad(servicio.propiedadid, servicio.idServicios);
|
||||
bool ret = RepositorioPropiedades.Singleton.BajaServiciosAPropiedad(servicio.propiedadid, servicio.idServicios, cli.Dni);
|
||||
|
||||
return ret ?
|
||||
Ok(new {message ="Se Eliminaron los servicios seleccionados de la propiedad"}) : BadRequest(new {message ="Fallo al eliminarse los servicios de la propiedad"});
|
||||
|
||||
460
Aspnet/Controllers/VentaController.cs
Normal file
460
Aspnet/Controllers/VentaController.cs
Normal file
@@ -0,0 +1,460 @@
|
||||
using System.Configuration;
|
||||
using System.Formats.Asn1;
|
||||
using System.Text.Json;
|
||||
using AlquilaFacil.Builder;
|
||||
using AlquilaFacil.Config;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minio;
|
||||
using Minio.DataModel.Args;
|
||||
using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class VentaController:ControllerBase {
|
||||
|
||||
[HttpPost("api/venta/AceptarConsultaVenta")]
|
||||
public IActionResult AceptarConsultaVenta([FromHeader(Name="Auth")]string Auth, NotificacionMarcarLeidoDto dto) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
if (dto.Email == "") return BadRequest(new { message = "Falta dato Email"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) Unauthorized();
|
||||
if (cli.Email != dto.Email) return BadRequest(new {message = "El token de autorizacion no corresponde a tu usuario"});
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||
|
||||
Notificacione? n = RepositorioNotificaciones.Singleton.ObtenerNotificacionPorKeys(cli.Dni, dto.Fecha);
|
||||
if (n == null) return BadRequest(new { message = "No se encuentra la notificacion"});
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(n.Idpropiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No se encuentra una propiedad por ese id"});
|
||||
Venta? v = new Venta{
|
||||
Fechainicio = DateTime.Now,
|
||||
IdVendedor = prop.Dnipropietario,
|
||||
IdComprador = n.Dniremitente,
|
||||
Monto = prop.Monto,
|
||||
Idpropiedad = prop.Id,
|
||||
Iddivisa = prop.Iddivisa,
|
||||
Idestado = 2,
|
||||
|
||||
};
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.IniciarVenta(v, cli.Dni);
|
||||
if (ret){
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion("Notificacion")
|
||||
.SetMensaje("Debe Realizar el pago para que se registre el traspaso de la propiedad")
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(n.Dniremitente)
|
||||
.SetDniremitente(n.Dnicliente)
|
||||
.SetIdpropiedad(n.Idpropiedad)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
}
|
||||
return ret?
|
||||
Ok(new { message = "Se inicio la venta"}):BadRequest(new { message ="fallo al iniciar la venta"});
|
||||
}
|
||||
|
||||
[HttpPost("api/venta/CancelarConsultaVenta")]
|
||||
public IActionResult CancelarConsultaVenta([FromHeader(Name="Auth")]string Auth, NotificacionMarcarLeidoDto dto) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (dto.Email == "") return BadRequest(new { message = "Falta dato Email"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) Unauthorized();
|
||||
if (cli.Email != dto.Email) return BadRequest(new {message = "El token de autorizacion no corresponde a tu usuario"});
|
||||
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||
Notificacione? n = RepositorioNotificaciones.Singleton.ObtenerNotificacionPorKeys(cli.Dni, dto.Fecha);
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion("Notificacion")
|
||||
.SetMensaje("El propietario no quiere vender")
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(n.Dniremitente)
|
||||
.SetDniremitente(n.Dnicliente)
|
||||
.SetIdpropiedad(n.Idpropiedad)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
|
||||
var ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
return ret ?
|
||||
Ok(new{message = "Se Envio una notificacion"}):BadRequest(new{message = "Fallo al Descartar Consulta"});
|
||||
}
|
||||
|
||||
[HttpGet("/api/propiedad/EstaALaVenta")]
|
||||
public IActionResult EstaALaVenta([FromHeader(Name="Auth")]string Auth, int idprop=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
if (idprop<=0) return BadRequest(new { message = "No hay propiedades con id 0 o menor"});
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(idprop);
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id"});
|
||||
return Ok(new { EstaAVenta = prop.Idestado ==4?true:false});
|
||||
}
|
||||
|
||||
[HttpPut("/api/propiedad/setPropiedadAVenta")]
|
||||
public IActionResult setPropiedadAVenta([FromHeader(Name="Auth")]string Auth, SetVentaDto dto) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (dto.iddivisa != 0 && dto.iddivisa!=1) return BadRequest(new { message = "no hay una divisa por esa id"});
|
||||
if (dto.idpropiedad<=0) return BadRequest(new { message = "No hay propiedades con id 0 o menor"});
|
||||
if (dto.monto<1) return BadRequest(new { message = "No se pueden hacer ventas por montos menores a 1"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.idpropiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id"});
|
||||
|
||||
if (cli.Dni != prop.Dnipropietario) return Unauthorized();
|
||||
|
||||
var ret = RepositorioVentas.Singleton.SetVenta(prop.Id, dto.monto, dto.iddivisa, cli.Dni);
|
||||
return ret?
|
||||
Ok(new { message = "Se puso la propiedad de venta"}) : BadRequest(new { message = "No se pudo poner a la Venta"});
|
||||
}
|
||||
|
||||
[HttpPut("/api/propiedad/unsetPropiedadAVenta")]
|
||||
public IActionResult unsetPropiedadAVenta([FromHeader(Name="Auth")]string Auth, SetVentaDto dto) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (dto.iddivisa != 0 && dto.iddivisa!=1) return BadRequest(new { message = "no hay una divisa por esa id"});
|
||||
if (dto.idpropiedad<=0) return BadRequest(new { message = "No hay propiedades con id 0 o menor"});
|
||||
if (dto.monto<1) return BadRequest(new { message = "No se pueden hacer ventas por montos menores a 1"});
|
||||
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.idpropiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id"});
|
||||
|
||||
if (cli.Dni != prop.Dnipropietario) return Unauthorized();
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.UnSetVenta(prop.Id, dto.monto, dto.iddivisa, cli.Dni);
|
||||
|
||||
return ret?
|
||||
Ok(new { message = "Se Bajo la propiedad de venta"}) : BadRequest(new { message = "No se pudo Bajar de venta"});
|
||||
}
|
||||
|
||||
[HttpPost("/api/ventas/ejercerOpcionVenta")]
|
||||
public IActionResult EjercerOpcionVenta([FromHeader(Name="Auth")]string Auth, [FromQuery]long idcontrato=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
if (idcontrato <= 0) return BadRequest(new { message = "No pueden hacer cotratos con id 0 o menor"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioVentas.Singleton.ObtenerVentaPorContrato(idcontrato);
|
||||
if (cont == null || cont.IdventaNavigation == null) return BadRequest(new { message = "no hay un contrato por esa id"});
|
||||
if (cont.Tieneopcionventa == 0) return BadRequest(new { message = "No tiene opcion de venta"});
|
||||
if (puedeEjercer(cont) == false) return BadRequest(new { message = "No cumple con los requisitos para ejercer la opcion de compra"});
|
||||
|
||||
Venta venta = cont.IdventaNavigation;
|
||||
venta.IdVendedor = cont.Dnipropietario;
|
||||
venta.IdComprador = cont.Dniinquilino;
|
||||
venta.Idpropiedad = cont.Idpropiedad;
|
||||
venta.Fechainicio = DateTime.Now;
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.PatchVenta(venta, cli.Dni);
|
||||
|
||||
return ret?
|
||||
Ok(new { message = "Se ejercio la opcion de venta"}):
|
||||
BadRequest(new { message = "No se pude ejercer la opcion de venta"});
|
||||
}
|
||||
|
||||
[HttpPost("/api/ventas/subirReciboPago")]
|
||||
public async Task<IActionResult> SubirRecibo([FromHeader(Name="Auth")]string Auth, IFormFile file, long idventa ) {
|
||||
if (String.IsNullOrWhiteSpace(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 (idventa <=0) return BadRequest(new { message = "Las id 0 o menor no son validas" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Venta? venta = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (venta == null) return BadRequest(new { message = "no hay una venta por esa id"});
|
||||
|
||||
if (cli.Dni !=venta.IdComprador && cli.Dni != venta.IdVendedor) return Unauthorized();
|
||||
|
||||
if (file == null) return BadRequest(new { message = "Debe subir un archivo." });
|
||||
if (file.ContentType != "application/pdf") return BadRequest(new { message = "El archivo debe ser un documento PDF." });
|
||||
if (!Path.GetExtension(file.FileName).Equals(".pdf", StringComparison.OrdinalIgnoreCase)) return BadRequest(new { message = "El archivo debe tener la extensión .pdf." });
|
||||
|
||||
string nuevoNombreArchivo = $"id:{venta.Id}-comprador:{venta.IdComprador}-vendedor:{venta.IdVendedor}-idprop:{venta.Idpropiedad}.pdf";
|
||||
bool ret = await subirContrato(file, nuevoNombreArchivo);
|
||||
if(ret == false) return BadRequest(new {message = "No se pudo subir el archivo"});
|
||||
|
||||
ret = RepositorioVentas.Singleton.SetUrlRecibo(venta.Id, nuevoNombreArchivo, cli.Dni);
|
||||
if (ret == false) return BadRequest(new { message = "no se pudo guardar el nombre del archivo subido"});
|
||||
|
||||
return Ok(new { message = "Se Subio el Recibo"});
|
||||
|
||||
}
|
||||
private readonly IMinioClient mc;
|
||||
public VentaController(IMinioClient minioClient) {
|
||||
mc = minioClient;
|
||||
if (mc == null){
|
||||
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json"))?? null;
|
||||
if (mcon == null) throw new Exception();
|
||||
|
||||
mc = new MinioClient().WithCredentials(mcon.usr, mcon.scrt)
|
||||
.WithEndpoint("192.168.1.11:9000")
|
||||
.WithSSL(false)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
private async Task<bool> subirContrato(IFormFile f, string flname) {
|
||||
try {
|
||||
var buck = new BucketExistsArgs().WithBucket("alquilafacil");
|
||||
bool encontrado = await mc.BucketExistsAsync(buck).ConfigureAwait(false);
|
||||
|
||||
if(!encontrado){
|
||||
var mb = new MakeBucketArgs().WithBucket("alquilafacil");
|
||||
await mc.MakeBucketAsync(mb).ConfigureAwait(false);
|
||||
}
|
||||
using (var stream = new MemoryStream()){
|
||||
await f.CopyToAsync(stream);
|
||||
stream.Position=0;
|
||||
PutObjectArgs putbj = new PutObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(flname)
|
||||
.WithStreamData(stream)
|
||||
.WithContentType("application/pdf")
|
||||
.WithObjectSize(stream.Length);
|
||||
await mc.PutObjectAsync(putbj);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e ) {
|
||||
Console.Error.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("/api/ventas/verRecibo")]
|
||||
public IActionResult verRecibo([FromHeader(Name="Auth")]string Auth, long idventa=0){
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Venta? venta = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (venta == null) return BadRequest(new { message = "no hay una venta con esa id"});
|
||||
if (cli.Dni != venta.IdComprador && cli.Dni != venta.IdVendedor) return Unauthorized();
|
||||
|
||||
try{
|
||||
var memstream = new MemoryStream();
|
||||
|
||||
var goa = new GetObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(venta.UrlRecibo)
|
||||
.WithCallbackStream(stream => {
|
||||
memstream.Position=0;
|
||||
stream.CopyTo(memstream);
|
||||
});
|
||||
|
||||
mc.GetObjectAsync(goa).Wait();
|
||||
memstream.Position = 0;
|
||||
|
||||
if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" });
|
||||
|
||||
return File(memstream, "application/pdf", venta.UrlRecibo);
|
||||
|
||||
} catch (Exception e){
|
||||
Console.Error.WriteLine(e);
|
||||
return BadRequest(new { message = "Fallo al intentar obtener el archivo del almacenamiento o este no existe"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("/api/ventas/propietarioverifica")]
|
||||
public IActionResult PropietarioVerifica([FromHeader(Name="Auth")]string Auth, long idventa=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ventas = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (ventas == null) return BadRequest(new { message ="No hay una venta con ese id"});
|
||||
if (ventas.IdVendedor != cli.Dni) return Unauthorized();
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.EfectuarVenta(idventa);
|
||||
return ret ? Ok(new { message = "Se traspaso la propiedad"}): BadRequest(new { message = ""});
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("/api/venta")]
|
||||
public IActionResult ObtenerVenta([FromHeader(Name="Auth")]string Auth, long idventa=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ventas = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (ventas == null) return BadRequest(new { message ="No hay una venta con ese id"});
|
||||
if (ventas.IdVendedor !=cli.Dni && ventas.IdComprador != cli.Dni) return Unauthorized();
|
||||
|
||||
var v = new VentasDtoBuilder()
|
||||
.SetId(ventas.Id)
|
||||
.SetMonto(ventas.Monto)
|
||||
.SetDivisa(ventas.IddivisaNavigation.Signo)
|
||||
.SetUbicacion(ventas.IdpropiedadNavigation.Ubicacion)
|
||||
.SetNombreVendedor($"{ventas.IdVendedorNavigation.Nombre} {ventas.IdVendedorNavigation.Apellido}")
|
||||
.SetIdVendedor(ventas.IdVendedor??0)
|
||||
.SetNombreComprador($"{ventas.IdCompradorNavigation.Nombre} {ventas.IdCompradorNavigation.Apellido}")
|
||||
.SetIdComprador(ventas.IdComprador??0)
|
||||
.SetEstado(ventas.IdestadoNavigation.Descripcion??"")
|
||||
.Build();
|
||||
|
||||
return Ok(new { data = v, iscomprador = (ventas.IdComprador==cli.Dni)?true:false,
|
||||
necesitaRecibo = ventas.UrlRecibo==null?true:false});
|
||||
}
|
||||
|
||||
[HttpGet("/api/ventas")]
|
||||
public IActionResult ObtenerVentas([FromHeader(Name="Auth")]string Auth) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ventas = RepositorioVentas.Singleton.ObtenerVentasPorDni(cli.Dni);
|
||||
if (ventas == null) return BadRequest(new { message ="no estas involucrado en ninguna venta o compra"});
|
||||
|
||||
List<VentasDto> lista = new();
|
||||
foreach (var i in ventas) {
|
||||
var v = new VentasDtoBuilder()
|
||||
.SetId(i.Id)
|
||||
.SetMonto(i.Monto)
|
||||
.SetDivisa(i.IddivisaNavigation.Signo)
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetNombreVendedor($"{i.IdVendedorNavigation.Nombre} {i.IdVendedorNavigation.Apellido}")
|
||||
.SetIdVendedor(i.IdVendedor??0)
|
||||
.SetNombreComprador($"{i.IdCompradorNavigation.Nombre} {i.IdCompradorNavigation.Apellido}")
|
||||
.SetIdComprador(i.IdComprador??0)
|
||||
.SetEstado(i.IdestadoNavigation.Descripcion??"")
|
||||
.Build();
|
||||
lista.Add(v);
|
||||
}
|
||||
return Ok(lista);
|
||||
}
|
||||
|
||||
[HttpGet("/api/opcionventa")]
|
||||
public IActionResult ObtenerDto([FromHeader(Name="Auth")]string Auth, long idcontrato=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idcontrato == 0) return BadRequest(new { message = "No existen contatos validos para la id 0"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioVentas.Singleton.ObtenerVentaPorContrato(idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"});
|
||||
|
||||
var dto = new OpcionVentaDtoBuilder()
|
||||
.SetId(cont.Idventa??0)
|
||||
.SetMonto(cont.IdventaNavigation.Monto)
|
||||
.SetDivisa(cont.IdventaNavigation.IddivisaNavigation.Signo)
|
||||
.SetEnOrden(puedeEjercer(cont))
|
||||
.SetFueEjercido(cont.IdventaNavigation.Idestado??0)
|
||||
.Build();
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
|
||||
private bool puedeEjercer(Contrato c) {
|
||||
bool ret = c.Idcanons.All(x => x.Pagado == 1);
|
||||
|
||||
if (ret) {
|
||||
var canonConFechaMasTardia = c.Idcanons.OrderByDescending(x => x.Fecha).FirstOrDefault();
|
||||
|
||||
if (canonConFechaMasTardia != null && canonConFechaMasTardia.Fecha.Year >= DateTime.Now.Year
|
||||
&& canonConFechaMasTardia.Fecha.Month >= DateTime.Now.Month) {
|
||||
ret = true;
|
||||
}else{
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
[HttpGet("/api/contrato/tieneopcionventa")]
|
||||
public IActionResult TieneOpcionVenta([FromHeader(Name="Auth")]string Auth, long idcontrato=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
if (idcontrato == 0) return BadRequest(new { message = "No existen contatos validos para la id 0"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"});
|
||||
if (cont.Dniinquilino !=cli.Dni && cont.Dnipropietario != cli.Dni) return Unauthorized();
|
||||
|
||||
return Ok( new { message = cont.Tieneopcionventa});
|
||||
}
|
||||
}
|
||||
6
Entidades/Admin/NotificarAdmin.cs
Normal file
6
Entidades/Admin/NotificarAdmin.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Entidades.Admin;
|
||||
public class NotificarAdmin {
|
||||
public string Mensaje { get; set; }="";
|
||||
public long Idcontrato{get;set;}
|
||||
public long Idcanon {get; set;}
|
||||
}
|
||||
8
Entidades/Admin/UpdateUsuarioAdmin.cs
Normal file
8
Entidades/Admin/UpdateUsuarioAdmin.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Entidades.Admin;
|
||||
public class UpdateUsuarioAdmin {
|
||||
public string Nombre { get; set; } = null!;
|
||||
public string Apellido { get; set; } = null!;
|
||||
public string Domicilio { get; set; } = null!;
|
||||
public string Celular { get; set; } = null!;
|
||||
|
||||
}
|
||||
@@ -35,6 +35,10 @@ public partial class AlquilaFacilContext : DbContext
|
||||
|
||||
public virtual DbSet<Grupo> Grupos { get; set; }
|
||||
|
||||
public virtual DbSet<Log> Logs { get; set; }
|
||||
|
||||
public virtual DbSet<LogDetalle> LogDetalles { get; set; }
|
||||
|
||||
public virtual DbSet<Notificacione> Notificaciones { get; set; }
|
||||
|
||||
public virtual DbSet<Permiso> Permisos { get; set; }
|
||||
@@ -324,7 +328,7 @@ public partial class AlquilaFacilContext : DbContext
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Descripcion)
|
||||
.HasMaxLength(11)
|
||||
.HasMaxLength(30)
|
||||
.HasColumnName("descripcion");
|
||||
});
|
||||
|
||||
@@ -417,6 +421,62 @@ public partial class AlquilaFacilContext : DbContext
|
||||
.HasColumnName("nombre");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Log>(entity =>
|
||||
{
|
||||
entity.HasKey(e => new { e.Fecha, e.Dniusuario }).HasName("PRIMARY");
|
||||
|
||||
entity.ToTable("Log");
|
||||
|
||||
entity.HasIndex(e => e.Dniusuario, "fk_log_clientes");
|
||||
|
||||
entity.Property(e => e.Fecha)
|
||||
.HasColumnType("datetime")
|
||||
.HasColumnName("fecha");
|
||||
entity.Property(e => e.Dniusuario)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("dniusuario");
|
||||
entity.Property(e => e.Accion)
|
||||
.HasMaxLength(255)
|
||||
.HasColumnName("accion");
|
||||
|
||||
entity.HasOne(d => d.DniusuarioNavigation).WithMany(p => p.Logs)
|
||||
.HasForeignKey(d => d.Dniusuario)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("fk_log_clientes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<LogDetalle>(entity =>
|
||||
{
|
||||
entity.HasKey(e => new { e.Id, e.Fecha, e.Dniusuario, e.NombreTabla, e.Columna }).HasName("PRIMARY");
|
||||
|
||||
entity.ToTable("LogDetalle");
|
||||
|
||||
entity.HasIndex(e => new { e.Fecha, e.Dniusuario }, "LogDetalle_ibfk_1");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Fecha)
|
||||
.HasColumnType("datetime")
|
||||
.HasColumnName("fecha");
|
||||
entity.Property(e => e.Dniusuario)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("dniusuario");
|
||||
entity.Property(e => e.NombreTabla).HasColumnName("nombreTabla");
|
||||
entity.Property(e => e.Columna).HasColumnName("columna");
|
||||
entity.Property(e => e.ValorAnterior)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("valorAnterior");
|
||||
entity.Property(e => e.ValorNuevo)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("valorNuevo");
|
||||
|
||||
entity.HasOne(d => d.Log).WithMany(p => p.LogDetalles)
|
||||
.HasForeignKey(d => new { d.Fecha, d.Dniusuario })
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("LogDetalle_ibfk_1");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Notificacione>(entity =>
|
||||
{
|
||||
entity.HasKey(e => new { e.Dnicliente, e.Fecha }).HasName("PRIMARY");
|
||||
@@ -670,6 +730,9 @@ public partial class AlquilaFacilContext : DbContext
|
||||
entity.Property(e => e.Monto)
|
||||
.HasPrecision(12)
|
||||
.HasColumnName("monto");
|
||||
entity.Property(e => e.UrlRecibo)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("urlRecibo");
|
||||
|
||||
entity.HasOne(d => d.IdCompradorNavigation).WithMany(p => p.VentaIdCompradorNavigations)
|
||||
.HasForeignKey(d => d.IdComprador)
|
||||
|
||||
@@ -27,6 +27,8 @@ public partial class Cliente
|
||||
|
||||
public virtual ICollection<Contrato> ContratoDnipropietarioNavigations { get; set; } = new List<Contrato>();
|
||||
|
||||
public virtual ICollection<Log> Logs { get; set; } = new List<Log>();
|
||||
|
||||
public virtual ICollection<Notificacione> NotificacioneDniclienteNavigations { get; set; } = new List<Notificacione>();
|
||||
|
||||
public virtual ICollection<Notificacione> NotificacioneDniremitenteNavigations { get; set; } = new List<Notificacione>();
|
||||
|
||||
8
Entidades/Dto/OpcionVentaDto.cs
Normal file
8
Entidades/Dto/OpcionVentaDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Entidades.Dto;
|
||||
public class OpcionVentaDto{
|
||||
public long Id { get; set;}
|
||||
public decimal Monto { get; set;}
|
||||
public string Divisa { get; set;} ="";
|
||||
public bool EnOrden { get; set;}
|
||||
public bool FueEjercido { get; set; }
|
||||
}
|
||||
@@ -8,4 +8,6 @@ public class PrecontratoDto {
|
||||
public bool TieneOpcionVenta { get; set; }
|
||||
public string fechaprimernotificacion { get; set; } = "";
|
||||
public int MesesDuracionContrato { get; set; }
|
||||
public Decimal MontoOpcion {get; set; }
|
||||
public int iddivisa { get; set; }
|
||||
}
|
||||
12
Entidades/Dto/PropiedadesVentaDto.cs
Normal file
12
Entidades/Dto/PropiedadesVentaDto.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Entidades.Dto;
|
||||
public class PropiedadesVentaDto {
|
||||
public int Id { get; set; }
|
||||
public string Ubicacion { get; set; } = "";
|
||||
public int Canthabitaciones { get; set; }
|
||||
public int Piso { get; set; }
|
||||
public string Letra { get; set; } = "";
|
||||
public string Tipo { get; set; } = "";
|
||||
public string? Servicios {get;set;} = "";
|
||||
public decimal Monto { get; set; }
|
||||
public string Divisa { get; set; }="";
|
||||
}
|
||||
6
Entidades/Dto/SetVentaDto.cs
Normal file
6
Entidades/Dto/SetVentaDto.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Entidades.Dto;
|
||||
public class SetVentaDto {
|
||||
public int idpropiedad {get; set;}
|
||||
public decimal monto {get; set;}
|
||||
public int iddivisa {get; set;}
|
||||
}
|
||||
12
Entidades/Dto/VentasDto.cs
Normal file
12
Entidades/Dto/VentasDto.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Entidades.Dto;
|
||||
public class VentasDto {
|
||||
public long Id { get; set; }
|
||||
public decimal Monto { get; set; }
|
||||
public string Divisa { get; set; }="";
|
||||
public string Ubicacion { get; set; }="";
|
||||
public string NombreVendedor { get; set; }="";
|
||||
public long IdVendedor { get; set; }
|
||||
public string NombreComprador { get; set; }="";
|
||||
public long IdComprador { get; set; }
|
||||
public string Estado { get; set; }="";
|
||||
}
|
||||
17
Entidades/Log.cs
Normal file
17
Entidades/Log.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Entidades;
|
||||
|
||||
public partial class Log
|
||||
{
|
||||
public DateTime Fecha { get; set; }
|
||||
|
||||
public long Dniusuario { get; set; }
|
||||
|
||||
public string Accion { get; set; } = null!;
|
||||
|
||||
public virtual Cliente DniusuarioNavigation { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<LogDetalle> LogDetalles { get; set; } = new List<LogDetalle>();
|
||||
}
|
||||
23
Entidades/Logdetalle.cs
Normal file
23
Entidades/Logdetalle.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Entidades;
|
||||
|
||||
public partial class LogDetalle
|
||||
{
|
||||
public DateTime Fecha { get; set; }
|
||||
|
||||
public long Dniusuario { get; set; }
|
||||
|
||||
public string NombreTabla { get; set; } = null!;
|
||||
|
||||
public string Columna { get; set; } = null!;
|
||||
|
||||
public string? ValorAnterior { get; set; }
|
||||
|
||||
public string? ValorNuevo { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public virtual Log Log { get; set; } = null!;
|
||||
}
|
||||
9
Entidades/Logs/LogDetalleDto.cs
Normal file
9
Entidades/Logs/LogDetalleDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Entidades.Dto;
|
||||
public class LogDetalleDto {
|
||||
public DateTime Fecha { get; set; }
|
||||
public long Dniusuario { get; set; }
|
||||
public string NombreTabla { get; set; } = null!;
|
||||
public string Columna { get; set; } = null!;
|
||||
public string? ValorAnterior { get; set; }
|
||||
public string? ValorNuevo { get; set; }
|
||||
}
|
||||
7
Entidades/Logs/LogDto.cs
Normal file
7
Entidades/Logs/LogDto.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Entidades.Dto;
|
||||
public class LogDto {
|
||||
public DateTime Fecha { get; set; }
|
||||
public long Dniusuario { get; set; }
|
||||
public string Accion { get; set; } = null!;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,14 @@ public partial class Venta
|
||||
|
||||
public int? Idpropiedad { get; set; }
|
||||
|
||||
public DateTime Fechainicio { get; set; }
|
||||
public DateTime? Fechainicio { get; set; }
|
||||
|
||||
public DateTime? Fechafinal { get; set; }
|
||||
|
||||
public int Iddivisa { get; set; }
|
||||
|
||||
public string? UrlRecibo { get; set; }
|
||||
|
||||
public virtual ICollection<Contrato> Contratos { get; set; } = new List<Contrato>();
|
||||
|
||||
public virtual Cliente? IdCompradorNavigation { get; set; }
|
||||
|
||||
@@ -21,7 +21,14 @@
|
||||
import ControlAlquileresPropietario from "./paginas/ControlAlquileresPropietario.svelte";
|
||||
import ContratosPropietario from "./paginas/ContratosPropietario.svelte";
|
||||
import ContratoInquilino from "./paginas/ContratoInquilino.svelte";
|
||||
import Informes from "./paginas/Informes.svelte";
|
||||
import Informes from "./paginas/Informes.svelte";
|
||||
import CompraYVentas from "./paginas/CompraYVenta.svelte";
|
||||
import Ventas from "./paginas/Ventas.svelte";
|
||||
import VerLogs from "./paginas/VerLogs.svelte";
|
||||
import ControlPagos from "./paginas/ControlPagos.svelte";
|
||||
import ContratoAdmin from "./paginas/ContratoAdmin.svelte";
|
||||
import BuscarVentas from "./paginas/BuscarVentas.svelte";
|
||||
import MisPropiedadesEnVenta from "./paginas/MisPropiedadesEnVenta.svelte";
|
||||
</script>
|
||||
|
||||
<Router>
|
||||
@@ -70,6 +77,11 @@
|
||||
<ProteRoute componente={Informes}/>
|
||||
</Route>
|
||||
|
||||
<!--Ver Logs-->
|
||||
<Route path="/accion/7">
|
||||
<ProteRoute componente={VerLogs}/>
|
||||
</Route>
|
||||
|
||||
<!--Administrar Propiedades Dadas de Baja-->
|
||||
<Route path="/accion/8">
|
||||
<ProteRoute componente={MisPropiedadesDeBaja}/>
|
||||
@@ -95,6 +107,31 @@
|
||||
<ProteRoute componente={ControlAlquileresPropietario}/>
|
||||
</Route>
|
||||
|
||||
<!-- Compra y Ventas -->
|
||||
<Route path="/accion/13">
|
||||
<ProteRoute componente={CompraYVentas}/>
|
||||
</Route>
|
||||
|
||||
<!-- Control Pago Contratos Incumplidos -->
|
||||
<Route path="/accion/14">
|
||||
<ProteRoute componente={ControlPagos}/>
|
||||
</Route>
|
||||
|
||||
<!-- VerPropiedadesEnVenta -->
|
||||
<Route path="/accion/15">
|
||||
<ProteRoute componente={MisPropiedadesEnVenta}/>
|
||||
</Route>
|
||||
|
||||
<!-- Buscar Ventas -->
|
||||
<Route path="/accion/16">
|
||||
<ProteRoute componente={BuscarVentas}/>
|
||||
</Route>
|
||||
|
||||
<!-- Pagina Ventas -->
|
||||
<Route path="/Ventas">
|
||||
<ProteRoute componente={Ventas}/>
|
||||
</Route>
|
||||
|
||||
<!--Paginas info Grupo-->
|
||||
<Route path="/grupo/Inquilino">
|
||||
<ProteRoute componente={FrontInquilino}/>
|
||||
@@ -123,6 +160,10 @@
|
||||
<Route path="/inquilino/contratos">
|
||||
<ProteRoute componente={ContratoInquilino}/>
|
||||
</Route>
|
||||
|
||||
|
||||
<!--Contratos Admin-->
|
||||
<Route path="/admin/contratos">
|
||||
<ProteRoute componente={ContratoAdmin}/>
|
||||
</Route>
|
||||
</Router>
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
id="danioUso"
|
||||
class="form-check-input"
|
||||
bind:group={formData.pagainquilino}
|
||||
value="0"
|
||||
value="1"
|
||||
required
|
||||
/>
|
||||
<label for="danioUso" class="form-check-label">Daño por uso</label>
|
||||
@@ -70,7 +70,7 @@
|
||||
id="danioEstructural"
|
||||
class="form-check-input"
|
||||
bind:group={formData.pagainquilino}
|
||||
value="1"
|
||||
value="0"
|
||||
/>
|
||||
<label for="danioEstructural" class="form-check-label">Daño Estructural</label>
|
||||
</div>
|
||||
|
||||
63
Front/src/Componentes/ModalLogs.svelte
Normal file
63
Front/src/Componentes/ModalLogs.svelte
Normal file
@@ -0,0 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import type { LogDetalleDto, LogDto } from "../types";
|
||||
|
||||
let {onClose, log}: {onClose: ()=>boolean, log:LogDto} = $props();
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
|
||||
let detalles: LogDetalleDto[] = $state([]);
|
||||
async function obtenerDetalles() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/Logs/detalle?fecha="+log.fecha+"&idusuario="+log.dniusuario, {
|
||||
method:"GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
detalles = data;
|
||||
return;
|
||||
}
|
||||
}catch{}
|
||||
}
|
||||
onMount(()=>{
|
||||
obtenerDetalles();
|
||||
});
|
||||
</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">
|
||||
<h1 class="modal-title fs-5" id="exampleModalLabel">Detalles Log</h1>
|
||||
<button class="btn-close" onclick={onClose} aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table table-striped" style="table-layout: fixed; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="word-wrap: break-word;">Fecha</th>
|
||||
<th style="word-wrap: break-word;">Tabla</th>
|
||||
<th style="word-wrap: break-word;">Columna</th>
|
||||
<th style="word-wrap: break-word;">Valor Viejo</th>
|
||||
<th style="word-wrap: break-word;">Valor Nuevo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each detalles as d}
|
||||
<tr>
|
||||
<td style="word-wrap: break-word;">{d.fecha}</td>
|
||||
<td style="word-wrap: break-word;">{d.nombreTabla}</td>
|
||||
<td style="word-wrap: break-word;">{d.columna}</td>
|
||||
<td style="word-wrap: break-word;">{d.valorAnterior}</td>
|
||||
<td style="word-wrap: break-word;">{d.valorNuevo}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
54
Front/src/Componentes/ModalModificarPropietarios.svelte
Normal file
54
Front/src/Componentes/ModalModificarPropietarios.svelte
Normal file
@@ -0,0 +1,54 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import type { UpdateCliente } from "../types";
|
||||
|
||||
|
||||
let {onCancel, onConfirm, datos}: {onCancel:()=>void, onConfirm:(a:UpdateCliente)=>void, datos:UpdateCliente} = $props();
|
||||
|
||||
let cli:UpdateCliente|any = $state({});
|
||||
onMount(()=>{
|
||||
cli.nombre = datos.nombre;
|
||||
cli.dni = datos.dni;
|
||||
cli.apellido = datos.apellido;
|
||||
cli.domicilio = datos.domicilio;
|
||||
cli.celular = datos.celular;
|
||||
})
|
||||
|
||||
function handleConfirm(e: Event) {
|
||||
e.preventDefault();
|
||||
onConfirm(cli);
|
||||
onCancel();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="modal fade show d-block" tabindex="-1" style="background-color: rgba(0,0,0,0.5);">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Modificar Datos Cliente</h5>
|
||||
<button type="button" class="btn-close" aria-label="Close" onclick={onCancel}></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="mb-3">
|
||||
<label for="nombre" class="form-label">Nombre</label>
|
||||
<input type="text" id="nombre" class="form-control" bind:value={cli.nombre} required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="apellido" class="form-label">Apellido</label>
|
||||
<input type="text" id="apellido" class="form-control" bind:value={cli.apellido} required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="domicilio" class="form-label">Domicilio</label>
|
||||
<input type="text" id="domicilio" class="form-control" bind:value={cli.domicilio} required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="celular" class="form-label">Celular</label>
|
||||
<input type="tel" id="celular" class="form-control" bind:value={cli.celular} required />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" onclick={(e)=>handleConfirm(e)}>Guardar</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,16 +1,19 @@
|
||||
<script lang="ts">
|
||||
let { onClose, onSubmit } : {
|
||||
onClose: () => void,
|
||||
onSubmit: (data: { opcionVenta: boolean; cantGarantes: number; mesesHastaAumento: number, mesesDuracionContrato:number }) => void
|
||||
onSubmit: (data: { opcionVenta: boolean; cantGarantes: number; mesesHastaAumento: number, mesesDuracionContrato:number, montoOpcion:number, iddivisa:number }) => void
|
||||
} = $props();
|
||||
|
||||
let opcionVenta: boolean = $state(false);
|
||||
let cantGarantes: number = $state(0);
|
||||
let mesesHastaAumento: number = $state(0);
|
||||
let mesesDuracionContrato:number =$state(0);
|
||||
let montoOpcion:number=$state(0);
|
||||
let iddivisa:number=$state(0);
|
||||
|
||||
function handleSubmit(e:Event) {
|
||||
e.preventDefault();
|
||||
onSubmit({ opcionVenta, cantGarantes, mesesHastaAumento, mesesDuracionContrato });
|
||||
onSubmit({ opcionVenta, cantGarantes, mesesHastaAumento, mesesDuracionContrato, montoOpcion, iddivisa });
|
||||
onClose();
|
||||
}
|
||||
</script>
|
||||
@@ -25,11 +28,23 @@
|
||||
<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>
|
||||
{#if opcionVenta}
|
||||
<div class="form-group">
|
||||
<label for="montoOpcion">Definir monto</label>
|
||||
<input type="number" class="form-control" bind:value={montoOpcion} id="montoOpcion">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iddivisa">Seleccionar Divisa</label>
|
||||
<select class="form-select" bind:value={iddivisa} id="iddivisa">
|
||||
<option value="0">AR$</option>
|
||||
<option value="1">US$</option>
|
||||
</select>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="cantGarantes">Cantidad de Garantes</label>
|
||||
|
||||
55
Front/src/Componentes/ModalPublicarPropiedadParaVenta.svelte
Normal file
55
Front/src/Componentes/ModalPublicarPropiedadParaVenta.svelte
Normal file
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import type { PatchPropiedad, setVenta } from "../types";
|
||||
|
||||
let {onClose, onConfirm, title = "Publicar para venta", btntext = "Publicar a la venta"
|
||||
} : {
|
||||
onClose:()=>void, onConfirm:(data:setVenta)=>void, title:string, btntext:string
|
||||
} = $props();
|
||||
|
||||
let data:setVenta = $state({iddivisa:0, idpropiedad:0, monto:0});
|
||||
let monto:number = $state(0);
|
||||
|
||||
function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
onConfirm(data);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">{title}</h5>
|
||||
<button type="button" class="btn-close" onclick={onClose} aria-label="Cerrar"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="number"
|
||||
id="monto"
|
||||
class="form-control"
|
||||
bind:value={data.monto}
|
||||
placeholder="0"
|
||||
required
|
||||
/>
|
||||
<label for="monto">Monto</label>
|
||||
</div>
|
||||
|
||||
<label for="divisa">divisa</label>
|
||||
<select id="divisa" class="form-select">
|
||||
<option value="0" selected>AR$</option>
|
||||
<option value="1">US$</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" onclick={(e)=> handleSubmit(e)}>{btntext}</button>
|
||||
|
||||
<button class="btn btn-secondary ms-auto" onclick={onClose}>Cerrar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { Navbar, NavbarBrand, NavbarToggler, NavItem, Nav, NavLink, Collapse } from "@sveltestrap/sveltestrap";
|
||||
|
||||
let isOpen:boolean = false;
|
||||
let isOpen:boolean =$state(false);
|
||||
let theme = $state(localStorage.getItem("theme") ?? "light");
|
||||
const toggleTheme = () => {
|
||||
theme = theme === "light" ? "dark" : "light";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
|
||||
let {currentPag,
|
||||
cantpag,
|
||||
@@ -10,17 +9,10 @@
|
||||
cantpag: number,
|
||||
queryPag: (a:number) => void} = $props();
|
||||
|
||||
|
||||
const token = sessionStorage.getItem("token");
|
||||
|
||||
onMount(async () => {
|
||||
|
||||
});
|
||||
|
||||
let array = $derived.by(()=> Array.from({ length: cantpag }, (_, i) => i + 1));
|
||||
</script>
|
||||
|
||||
{#if cantpag>1}
|
||||
{#if cantpag>0}
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination">
|
||||
{#each array as num }
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
let { id, ubicacion, tipo, letra, piso,canthabitaciones, servicios, btnbaja = "Baja", monto, iddivisa = 0 } = $props();
|
||||
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalPublicarPropiedadParaVenta from "./ModalPublicarPropiedadParaVenta.svelte";
|
||||
import type { setVenta } from "../types";
|
||||
|
||||
let modal: boolean = $state(false);
|
||||
let modalpayload: string = $state("");
|
||||
|
||||
let modificar: boolean = $state(false);
|
||||
|
||||
let showPublicarVenta: boolean = $state(false);
|
||||
|
||||
function setmod(){
|
||||
modificar = !modificar;
|
||||
}
|
||||
@@ -35,6 +38,32 @@
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function setventa() {
|
||||
showPublicarVenta = true;
|
||||
}
|
||||
async function sendMod(data:setVenta) {
|
||||
data.idpropiedad = id;
|
||||
try {
|
||||
const responce = await fetch(String($urlG)+"/api/propiedad/setPropiedadAVenta", {
|
||||
method: "PUT",
|
||||
headers:{
|
||||
'Auth' : String(sessionStorage.getItem("token")),
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if(responce.ok){
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
const json = await responce.json();
|
||||
modalpayload = json.message;
|
||||
modal = true;
|
||||
}catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<tr in:fade>
|
||||
@@ -53,9 +82,10 @@
|
||||
{/if}
|
||||
</td>
|
||||
<td>{monto}</td>
|
||||
<td class="text-end">
|
||||
<button class="btn btn-outline-secondary btn-sm" onclick={()=> setmod()}>Modificar</button>
|
||||
<button class="btn btn-outline-danger btn-sm" onclick={() => BajaPropiedad()}>{btnbaja}</button>
|
||||
<td class="d-flex justify-content-between gap-2">
|
||||
<button class="btn btn-secondary btn-sm" onclick={()=> setmod()}>Modificar</button>
|
||||
<button class="btn btn-secondary btn-sm" onclick={()=> setventa()}>Publicar a venta</button>
|
||||
<button class="btn btn-danger btn-sm" onclick={() => BajaPropiedad()}>{btnbaja}</button>
|
||||
</td>
|
||||
</tr>
|
||||
{#if modal}
|
||||
@@ -68,3 +98,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
|
||||
{#if showPublicarVenta}
|
||||
<ModalPublicarPropiedadParaVenta onClose={()=>!!(showPublicarVenta = false)} onConfirm={sendMod}/>
|
||||
{/if}
|
||||
@@ -1,11 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { Cliente, Grupo } from "../types";
|
||||
import type { Cliente, Grupo, UpdateCliente } from "../types";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import { fade, fly } from "svelte/transition";
|
||||
import ModalModificarPropietarios from "../Componentes/ModalModificarPropietarios.svelte";
|
||||
import { CardLink } from "@sveltestrap/sveltestrap";
|
||||
|
||||
let Clientes: Cliente[] = $state([]);
|
||||
let Grupos:any[] = $state([]);
|
||||
@@ -16,7 +18,10 @@
|
||||
let grupo:string = $state("");
|
||||
let SelCliente: Cliente = $state(null);
|
||||
|
||||
onMount(async () => {
|
||||
onMount(() => {
|
||||
cargaUsuarios();
|
||||
});
|
||||
async function cargaUsuarios(){
|
||||
try{
|
||||
const response = await fetch($urlG+"/api/admin/clientes", {
|
||||
method: "GET",
|
||||
@@ -34,8 +39,7 @@
|
||||
modaldata = "fallo al intentar obtener la lista de clientes";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
async function cargaGrupos(cli: Cliente){
|
||||
try {
|
||||
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+cli.dni, {
|
||||
@@ -140,6 +144,59 @@
|
||||
modaldata = "Falla la conexion al servidor";
|
||||
}
|
||||
}
|
||||
|
||||
let showModificarCliente:boolean = $state(false);
|
||||
let datoscli:UpdateCliente = $state({dni:0, apellido:"", celular:"", domicilio:"", nombre:""});
|
||||
|
||||
async function abrirModalModificarCliente(e: Event, cli: Cliente) {
|
||||
e.stopPropagation();
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/admin/cliente?dni="+cli.dni, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token||"",
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok){
|
||||
datoscli = data;
|
||||
datoscli.dni = cli.dni;
|
||||
showModificarCliente = true;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "Falla la conexion al servidor";
|
||||
}
|
||||
}
|
||||
|
||||
async function patchCliente(a:UpdateCliente) {
|
||||
if (a.apellido =="" || a.celular=="" || a.domicilio=="" || a.nombre==""){
|
||||
modaldata = "Hay campos vacios";
|
||||
return;
|
||||
}
|
||||
let dto ={
|
||||
apellido: a.apellido,
|
||||
celular: a.celular,
|
||||
domicilio: a.domicilio,
|
||||
nombre: a.nombre,
|
||||
}
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/admin/cliente?dni="+a.dni, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Auth": token||"",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(dto),
|
||||
});
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
if (r.ok) cargaUsuarios();
|
||||
}catch{
|
||||
modaldata = "Falla la conexion al servidor";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
@@ -148,13 +205,18 @@
|
||||
<ModalEstatico payload={modaldata} close={()=> !!(modaldata = "")}/>
|
||||
{/if}
|
||||
|
||||
{#if showModificarCliente}
|
||||
<ModalModificarPropietarios datos={datoscli} onCancel={()=>!!(showModificarCliente = false)}
|
||||
onConfirm={patchCliente}/>
|
||||
{/if}
|
||||
|
||||
<div class="content-fluid align-items-start">
|
||||
<div class="row">
|
||||
<div class="col" style="padding-right: 2px;">
|
||||
<div class="col ms-2">
|
||||
<BarraHorizontalConTexto text="Clientes"/>
|
||||
|
||||
<div style="height:70vh; overflow-y: auto; max-width: 100%">
|
||||
<table class="table table-responsive table-sm table-striped table-hover table-bordered">
|
||||
<table class="table table-responsive table-striped table-hover table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Dni</th>
|
||||
@@ -171,14 +233,17 @@
|
||||
<td>{cli.email}</td>
|
||||
<td>
|
||||
{#if cli.habilitado}
|
||||
<button class="btn btn-outline-warning" onclick={(e) => bajaCliente(e, cli)}>
|
||||
<button class="btn btn-warning" onclick={(e) => bajaCliente(e, cli)}>
|
||||
Baja
|
||||
</button>
|
||||
{:else}
|
||||
<button class="btn btn-outline-success" onclick={(e) => bajaCliente(e, cli)}>
|
||||
<button class="btn btn-success" onclick={(e) => bajaCliente(e, cli)}>
|
||||
Alta
|
||||
</button>
|
||||
{/if}
|
||||
<button class="btn btn-secondary" onclick={(e)=>abrirModalModificarCliente(e, cli)}>
|
||||
Modificar
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
@@ -186,7 +251,7 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col"style="padding-left: 2px;">
|
||||
<div class="col me-2 ps-0">
|
||||
<BarraHorizontalConTexto text="Grupos del Cliente Seleccionado"/>
|
||||
<table class="table table-striped table-responsive table-sm table-bordered">
|
||||
<thead>
|
||||
@@ -208,11 +273,11 @@
|
||||
{/each}
|
||||
{:else if SelCliente != null}
|
||||
<tr>
|
||||
<td colspan="2">Este Cliente no tiene Grupos</td>
|
||||
<td colspan="3">Este Cliente no tiene Grupos</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr>
|
||||
<td colspan="2">Seleccione un cliente para ver sus grupos</td>
|
||||
<td colspan="3">Seleccione un cliente para ver sus grupos</td>
|
||||
</tr>
|
||||
{/if}
|
||||
</tbody>
|
||||
|
||||
148
Front/src/paginas/BuscarVentas.svelte
Normal file
148
Front/src/paginas/BuscarVentas.svelte
Normal file
@@ -0,0 +1,148 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { PropiedadDto, PropiedadVentaDto } from "../types";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import BotonVolverArriba from "../Componentes/BotonVolverArriba.svelte";
|
||||
import { fade } from "svelte/transition";
|
||||
import ModalConfirm from "../Componentes/ModalConfirm.svelte";
|
||||
import PaginacionStepper from "../Componentes/PaginacionStepper.svelte";
|
||||
|
||||
let token = sessionStorage.getItem("token")||"";
|
||||
|
||||
let propiedades:PropiedadVentaDto[]|null = $state(null);
|
||||
let pag:number = $state(1);
|
||||
let cantpag:number = $state(0);
|
||||
let message:string = "Esto le enviará una notificacion al propietario";
|
||||
let show:boolean = $state(false);
|
||||
|
||||
|
||||
let showButton:boolean = $state(false);
|
||||
let modaldata:string = $state("");
|
||||
|
||||
|
||||
onMount(()=>{
|
||||
obtenerpropiedades();
|
||||
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => window.removeEventListener("scroll", handleScroll);
|
||||
});
|
||||
|
||||
const handleScroll = () => {
|
||||
showButton = window.scrollY > 100;
|
||||
};
|
||||
|
||||
async function obtenerpropiedades() {
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/propiedades/Venta?pag="+pag, {
|
||||
method:"GET",
|
||||
headers: {
|
||||
"Auth": token
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if(r.ok){
|
||||
propiedades = data.propiedades;
|
||||
cantpag = data.cantpaginas;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "Fallo al hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
let selp: PropiedadVentaDto|any = $state();
|
||||
function Consultar(p:PropiedadVentaDto) {
|
||||
selp = p;
|
||||
show = true;
|
||||
}
|
||||
|
||||
async function handleConfirm() {
|
||||
const remitente = localStorage.getItem("email");
|
||||
const accion = "Consulta Compra";
|
||||
let mensaje = "el usuario con email: "+remitente+" quiere comprar la propiedad situada en: "+selp.ubicacion;
|
||||
const propiedad = selp.id;
|
||||
try {
|
||||
const responce = await fetch($urlG+"/api/notificar/ConsultaCompra", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body : JSON.stringify({remitente, accion, mensaje, propiedad})
|
||||
});
|
||||
let data = await responce.json();
|
||||
modaldata = data.message;
|
||||
|
||||
} catch {
|
||||
modaldata = "Fallo al hacer la request";
|
||||
}
|
||||
|
||||
show=!show;
|
||||
}
|
||||
|
||||
async function queryPag(a:number) {
|
||||
pag= a;
|
||||
obtenerpropiedades();
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
<div class="container-fluid mt-2">
|
||||
<BarraHorizontalConTexto text="Venta Propiedades"/>
|
||||
<div class="row">
|
||||
{#if propiedades == null}
|
||||
<div class="position-absolute start-50 top-50">
|
||||
<div class="spinner-border" role="status">
|
||||
</div>
|
||||
Cargando...
|
||||
</div>
|
||||
{:else if propiedades.length <= 0}
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
No hay Propiedades a la Venta.
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
{#each propiedades as p}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<ModalConfirm {show} {message} title="Consulta" onConfirm={handleConfirm} onCancel={()=>show=false}/>
|
||||
<div class="card text-center border shadow-sm">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0">{p.tipo}</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="card-img-top mb-3">
|
||||
<i class="bi bi-building" style="font-size: 3rem;"></i>
|
||||
</div>
|
||||
<h6 class="card-title">{p.ubicacion}</h6>
|
||||
<p class="card-text">
|
||||
<strong>Habitaciones:</strong> {p.canthabitaciones}<br>
|
||||
<strong>Piso:</strong> {p.piso || "N/A"}<br>
|
||||
<strong>Letra:</strong> {p.letra || "N/A"}<br>
|
||||
<strong>Servicios:</strong> {p.servicios || "Sin servicios especificados"}<br>
|
||||
<strong>Monto:</strong>
|
||||
{p.divisa} {p.monto}<br>
|
||||
</p>
|
||||
<button class="btn btn-primary" onclick={()=>Consultar(p)}>Consultar Compra</button>
|
||||
</div>
|
||||
<div class="card-footer text-muted">
|
||||
ID Propiedad: {p.id}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
<div class="d-flex justify-content-center">
|
||||
<PaginacionStepper currentPag={pag} {cantpag} {queryPag}/>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{#if showButton }
|
||||
<div transition:fade={{duration:100}}>
|
||||
<BotonVolverArriba/>
|
||||
</div>
|
||||
{/if}
|
||||
75
Front/src/paginas/CompraYVenta.svelte
Normal file
75
Front/src/paginas/CompraYVenta.svelte
Normal file
@@ -0,0 +1,75 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { VentasDto } from "../types";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import Ventas from "./Ventas.svelte";
|
||||
import { navigate } from "svelte-routing";
|
||||
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
let modaldata:string = $state("");
|
||||
|
||||
let ventas:VentasDto[] = $state([]);
|
||||
|
||||
onMount(()=>{
|
||||
obtenerVentas();
|
||||
});
|
||||
|
||||
async function obtenerVentas() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/ventas", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (!r.ok){
|
||||
modaldata = data;
|
||||
return;
|
||||
}
|
||||
ventas = data;
|
||||
}catch{
|
||||
modaldata = "Fallo al hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata}
|
||||
<ModalEstatico payload={modaldata} close={()=> !!(modaldata = "")} />
|
||||
{/if}
|
||||
|
||||
<div class="container-fluid mt-3">
|
||||
<div class="row">
|
||||
{#each ventas as venta (venta.id)}
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5>{venta.nombreVendedor} → {venta.nombreComprador}</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
<strong>Monto:</strong> {venta.monto} {venta.divisa}<br>
|
||||
<strong>Ubicación:</strong> {venta.ubicacion}<br>
|
||||
<strong>Estado:</strong> {venta.estado}
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-footer d-flex justify-content-center">
|
||||
<button class="btn btn-secondary" onclick={()=>navigate("/Ventas?idventa="+venta.id)}>Ver</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.card {
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
</style>
|
||||
316
Front/src/paginas/ContratoAdmin.svelte
Normal file
316
Front/src/paginas/ContratoAdmin.svelte
Normal file
@@ -0,0 +1,316 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import type { CanonDto, ContratoPropiedadDto, GaranteDto2, PropiedadDto } from "../types";
|
||||
import ModalNotificacion from "../Componentes/ModalNotificacion.svelte";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
|
||||
let canons:CanonDto[] = $state([]);
|
||||
let contratoid:string = $state("");
|
||||
let modaldata:string = $state("");
|
||||
let garantes: GaranteDto2[] = $state([]);
|
||||
let shownotif:boolean = $state(false);
|
||||
let idcanon:number = $state(0);
|
||||
|
||||
let prop:ContratoPropiedadDto = $state({
|
||||
estado:"",
|
||||
fechainicio:"",
|
||||
id:0,
|
||||
inquilino:"",
|
||||
propietario:"",
|
||||
tipoPropiedad:"",
|
||||
ubicacion:"",
|
||||
habitaciones:0,
|
||||
piso:0,
|
||||
letra:"",
|
||||
mesesAumento:0,
|
||||
mesesDuracion:0,
|
||||
});
|
||||
|
||||
onMount(()=>{
|
||||
getparams();
|
||||
obtenerDatosACargar();
|
||||
|
||||
});
|
||||
|
||||
async function refreshCanon() {
|
||||
try {
|
||||
const ret = await fetch($urlG+"/api/admin/contrato/canons?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 obtenerDatosACargar() {
|
||||
try {
|
||||
const respPropiedad = fetch($urlG+"/api/contratos/controlPagos/propiedad?id="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
const respCanons = fetch($urlG+"/api/admin/contrato/canons?id="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
|
||||
const [p, c] = await Promise.all([respPropiedad, respCanons]);
|
||||
|
||||
const datosPropiedad = await p.json();
|
||||
const datosCanons = await c.json();
|
||||
|
||||
if(!(await respCanons).ok){
|
||||
modaldata = datosCanons.message;
|
||||
return;
|
||||
}
|
||||
|
||||
prop = datosPropiedad;
|
||||
canons = datosCanons;
|
||||
|
||||
} catch {
|
||||
modaldata = "Fallo hacer las request";
|
||||
}
|
||||
}
|
||||
|
||||
function getparams(){
|
||||
const qs = window.location.search;
|
||||
const par = new URLSearchParams(qs);
|
||||
contratoid = par.get("id")||"";
|
||||
}
|
||||
|
||||
function abrirModalNotif(id:number) {
|
||||
idcanon = id;
|
||||
shownotif = true;
|
||||
}
|
||||
|
||||
async function verContrato() {
|
||||
if (prop.id <= 0) {
|
||||
modaldata = "no hay contratos con id 0 o menor";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const resp = await fetch ($urlG+"/api/admin/contrato/verDocumento?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 notificar(mes: Date) {
|
||||
|
||||
}
|
||||
|
||||
async function realizarpago(mes: Date) {
|
||||
try {
|
||||
const ret = await fetch($urlG+"/api/admin/contrato/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 EscribirNotificacion(message:string) {
|
||||
if (message =="") {
|
||||
modaldata = "no se puede enviar un mensaje vacio";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/admin/notificarInquilino", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
mensaje: message,
|
||||
idcontrato: prop.id,
|
||||
idcanon: idcanon,
|
||||
})
|
||||
});
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata ="No se pudo enviar el mensaje";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata}
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")}/>
|
||||
{/if}
|
||||
|
||||
{#if shownotif}
|
||||
<ModalNotificacion onCancel={()=>shownotif = false} onConfirm={EscribirNotificacion}/>
|
||||
{/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 collapsed"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#collapseOne"
|
||||
aria-expanded="false"
|
||||
aria-controls="collapseOne"
|
||||
>
|
||||
Garantes
|
||||
</button>
|
||||
</h2>
|
||||
<div
|
||||
id="collapseOne"
|
||||
class="accordion-collapse collapse"
|
||||
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"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#collapseTwo"
|
||||
aria-expanded="true"
|
||||
aria-controls="collapseTwo"
|
||||
>
|
||||
Canons
|
||||
</button>
|
||||
</h2>
|
||||
<div
|
||||
id="collapseTwo"
|
||||
class="accordion-collapse collapse show"
|
||||
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" disabled={canon.pago} onclick={()=>realizarpago(canon.mes)}>
|
||||
Pagar
|
||||
</button>
|
||||
<button class="btn btn-warning" disabled={canon.pago} onclick={()=>abrirModalNotif(canon.id)}>
|
||||
Informar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3,9 +3,10 @@
|
||||
import { onMount } from "svelte";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import type { AltaDefectoDto, CanonDto, ContratoDto, ContratoPropiedadDto, DefectoDto, GaranteDto2 } from "../types";
|
||||
import type { AltaDefectoDto, CanonDto, ContratoDto, ContratoPropiedadDto, DefectoDto, GaranteDto2, OpcionVentaDto } from "../types";
|
||||
import ModalPedirDoc from "../Componentes/ModalPedirDoc.svelte";
|
||||
import FormAltaDefecto from "../Componentes/FormAltaDefecto.svelte";
|
||||
import { navigate } from "svelte-routing";
|
||||
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
|
||||
@@ -29,14 +30,62 @@
|
||||
});
|
||||
let defectos:DefectoDto[] = $state([]);
|
||||
|
||||
let TieneOpcionVenta:boolean =$state(false);
|
||||
let dtoVenta:OpcionVentaDto =$state({divisa:"", id:0, monto:0, enOrden:false, fueEjercido:false});
|
||||
|
||||
let modaldata:string = $state("");
|
||||
let contratoid:string = $state("");
|
||||
|
||||
onMount(()=>{
|
||||
getparams();
|
||||
obtenerDatosACargar();
|
||||
opcionVenta();
|
||||
});
|
||||
|
||||
async function opcionVenta() {
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/contrato/tieneopcionventa?idcontrato="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
if (r.ok){
|
||||
let data = await r.json();
|
||||
TieneOpcionVenta = data.message;
|
||||
if (TieneOpcionVenta){
|
||||
ObtenerOpcionVentaDto();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
return;
|
||||
}catch {
|
||||
modaldata = "Fallo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function ObtenerOpcionVentaDto() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/opcionventa?idcontrato="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
if (r.ok) {
|
||||
let data = await r.json();
|
||||
dtoVenta = data;
|
||||
return
|
||||
}
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
}catch{
|
||||
modaldata = "Fallo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function obtenerDatosACargar() {
|
||||
try {
|
||||
const respPropiedad = fetch($urlG+"/api/contrato/inquilino?id="+contratoid, {
|
||||
@@ -223,6 +272,25 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function ejercerOpcionVenta() {
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/ventas/ejercerOpcionVenta?idcontrato="+contratoid, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
modaldata =data.message;
|
||||
if(r.ok){
|
||||
opcionVenta();
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
modaldata = "Fallo al intentar hacer la request";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
@@ -374,8 +442,10 @@
|
||||
class="accordion-collapse collapse"
|
||||
aria-labelledby="ht"
|
||||
data-bs-parent="#accordionExample"
|
||||
>
|
||||
>
|
||||
|
||||
<div class="accordion-body">
|
||||
{#if prop.estado != "Terminado"}
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Notificar Defecto en Propiedad
|
||||
@@ -384,10 +454,11 @@
|
||||
<FormAltaDefecto onConfirm={cargarDefecto} idcontrato={prop.id} />
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
{/if}
|
||||
<table class="table table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -419,6 +490,55 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if TieneOpcionVenta}
|
||||
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="hq">
|
||||
<button
|
||||
class="accordion-button collapsed"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#cq"
|
||||
aria-expanded="false"
|
||||
aria-controls="cq"
|
||||
>
|
||||
Opcion Venta
|
||||
</button>
|
||||
</h2>
|
||||
<div
|
||||
id="cq"
|
||||
class="accordion-collapse collapse"
|
||||
aria-labelledby="hq"
|
||||
data-bs-parent="#accordionExample"
|
||||
>
|
||||
<div class="accordion-body">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Datos Opcion Venta
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<b>Monto</b>: {dtoVenta.divisa} {dtoVenta.monto}.
|
||||
|
||||
<p class="mt-2 text-muted">
|
||||
Para poder ejercer la opcion de venta necesitas estar en el mismo mes que el ultimo pago y haber pagado todos los canones
|
||||
</p>
|
||||
<div class="d-flex justify-content-between">
|
||||
<button class="btn btn-primary" disabled={dtoVenta.enOrden==false || dtoVenta.fueEjercido == true} onclick={()=>ejercerOpcionVenta()}>
|
||||
Ejercer
|
||||
</button>
|
||||
{#if dtoVenta.fueEjercido}
|
||||
<button class="btn btn-secondary" onclick={()=>navigate("/Ventas?idventa="+dtoVenta.id)}>
|
||||
Ir a la pagina de la Venta
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-center">IdOpcionVenta: {dtoVenta.id}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import type { CanonDto, ContratoDto, ContratoPropiedadDto, DefectoDto, GaranteDto2 } from "../types";
|
||||
import type { CanonDto, ChartData, ContratoDto, ContratoPropiedadDto, DefectoDto, GaranteDto2, OpcionVentaDto } from "../types";
|
||||
import ModalConfirm from "../Componentes/ModalConfirm.svelte";
|
||||
import ModalPedirDoc from "../Componentes/ModalPedirDoc.svelte";
|
||||
import ModalNotificacion from "../Componentes/ModalNotificacion.svelte";
|
||||
|
||||
import { navigate } from "svelte-routing";
|
||||
import FChart from "../Componentes/Estadisticas/fChart.svelte";
|
||||
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
|
||||
@@ -15,6 +16,7 @@
|
||||
let selMod:any =$state();
|
||||
let showmodal:boolean = $state(false);
|
||||
let shownotif:boolean = $state(false);
|
||||
let chartData:ChartData|any = $state();
|
||||
|
||||
let max:number=$state(0);
|
||||
|
||||
@@ -35,6 +37,8 @@
|
||||
mesesDuracion:0,
|
||||
});
|
||||
let defectos:DefectoDto[] = $state([]);
|
||||
let TieneOpcionVenta:boolean =$state(false);
|
||||
let dtoVenta:OpcionVentaDto =$state({divisa:"", id:0, monto:0, enOrden:false, fueEjercido:false});
|
||||
|
||||
let modaldata:string = $state("");
|
||||
let contratoid:string = $state("");
|
||||
@@ -43,7 +47,71 @@
|
||||
getparams();
|
||||
await obtenerDatosACargar();
|
||||
max = canons.at(-1).mesNum||0;
|
||||
opcionVenta();
|
||||
await setChartData();
|
||||
});
|
||||
async function setChartData() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/contrato/stats?idcontrato="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok){
|
||||
chartData = data;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
}catch{
|
||||
modaldata = "no se pudo obtener el chartdata";
|
||||
}
|
||||
}
|
||||
|
||||
async function opcionVenta() {
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/contrato/tieneopcionventa?idcontrato="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
if (r.ok){
|
||||
let data = await r.json();
|
||||
TieneOpcionVenta = data.message;
|
||||
if (TieneOpcionVenta){
|
||||
ObtenerOpcionVentaDto();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
return;
|
||||
}catch {
|
||||
modaldata = "Fallo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function ObtenerOpcionVentaDto() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/opcionventa?idcontrato="+contratoid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
if (r.ok) {
|
||||
let data = await r.json();
|
||||
dtoVenta = data;
|
||||
return
|
||||
}
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
}catch{
|
||||
modaldata = "Fallo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function obtenerDatosACargar() {
|
||||
try {
|
||||
@@ -260,7 +328,6 @@
|
||||
if (r.ok) {
|
||||
refreshDefectos();
|
||||
}
|
||||
|
||||
}catch {
|
||||
modaldata = "No se pudo marcar como pago";
|
||||
}
|
||||
@@ -281,6 +348,35 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generarCSVEstadistica() {
|
||||
let contenido = ["Categorias", ...chartData.datasets.map((d: { label: any; }) => d.label)].join(",") + "\n";
|
||||
|
||||
chartData.labels.forEach((label: any, index: string | number) => {
|
||||
let fila = [label, ...chartData.datasets.map((d: { data: { [x: string]: any; }; }) => d.data[index])].join(",");
|
||||
contenido += fila + "\n";
|
||||
});
|
||||
|
||||
contenido += "\n";
|
||||
|
||||
|
||||
if (canons.length > 0) {
|
||||
contenido += "ID,Mes Num,Mes,Monto,Divisa,Pago\n";
|
||||
canons.forEach(c => {
|
||||
let fila = [c.id, c.mesNum, String(c.mes).split("T")[0], c.monto, c.divisa, c.pago ? "Sí" : "No"].join(",");
|
||||
contenido += fila + "\n";
|
||||
});
|
||||
}
|
||||
|
||||
let blob = new Blob([contenido], { type: "text/csv" });
|
||||
let url = URL.createObjectURL(blob);
|
||||
let a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "chart_data.csv";
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
@@ -375,6 +471,30 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="h6">
|
||||
<button class="accordion-button collapsed"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#c6"
|
||||
aria-expanded="false"
|
||||
aria-controls="c6">
|
||||
Estadisticas
|
||||
</button>
|
||||
</h2>
|
||||
<div id="c6" class="accordion-collapse collapse"
|
||||
data-bs-parent="#accordionExample">
|
||||
<div class="accordion-body d-flex justify-content-center" >
|
||||
<div style="width: 500px; height: auto;">
|
||||
{#if chartData != null}
|
||||
<FChart {chartData} typec="doughnut" />
|
||||
{/if}
|
||||
<button class="btn btn-secondary mt-2" onclick={generarCSVEstadistica}>
|
||||
Exportar CSV
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingTwo">
|
||||
<button
|
||||
@@ -420,7 +540,6 @@
|
||||
</div>
|
||||
{/each}
|
||||
{#if max < prop.mesesDuracion}
|
||||
{$inspect(max)}
|
||||
<div class="card">
|
||||
<div class="card-header text-center">
|
||||
Definir el interés para los siguientes Canones
|
||||
@@ -511,6 +630,50 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if TieneOpcionVenta}
|
||||
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="hq">
|
||||
<button
|
||||
class="accordion-button collapsed"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#cq"
|
||||
aria-expanded="false"
|
||||
aria-controls="cq"
|
||||
>
|
||||
Opcion Venta
|
||||
</button>
|
||||
</h2>
|
||||
<div
|
||||
id="cq"
|
||||
class="accordion-collapse collapse"
|
||||
aria-labelledby="hq"
|
||||
data-bs-parent="#accordionExample"
|
||||
>
|
||||
<div class="accordion-body">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Datos Opcion Venta
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<b>Monto</b>: {dtoVenta.divisa} {dtoVenta.monto}.
|
||||
|
||||
<p class="mt-2 text-muted">
|
||||
Para que el inquilino pueda ejercer la opcion de venta necesitas estar en el mismo mes que el ultimo pago y haber pagado todos los canones
|
||||
</p>
|
||||
<div class="d-flex">
|
||||
<button class="btn btn-primary" disabled={!dtoVenta.fueEjercido} onclick={()=>navigate("/Ventas?idventa="+dtoVenta.id)}>
|
||||
Ir a la pagina de la Venta
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-center">IdOpcionVenta: {dtoVenta.id}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
93
Front/src/paginas/ControlPagos.svelte
Normal file
93
Front/src/paginas/ControlPagos.svelte
Normal file
@@ -0,0 +1,93 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { ContratoDto } from "../types";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import { navigate } from "svelte-routing";
|
||||
|
||||
let token: string = sessionStorage.getItem("token")|| "";
|
||||
let alquileres:ContratoDto[]| null = $state(null);
|
||||
let modaldata:string = $state("");
|
||||
|
||||
onMount(()=>{
|
||||
obtenerContratosAdmin();
|
||||
});
|
||||
async function obtenerContratosAdmin() {
|
||||
try{
|
||||
const responce = await fetch($urlG+"/api/contratos/controlPagos", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
},
|
||||
});
|
||||
if (responce.ok){
|
||||
let data = await responce.json();
|
||||
alquileres = data;
|
||||
return;
|
||||
}
|
||||
|
||||
let data = await responce.json();
|
||||
modaldata = data.message;
|
||||
|
||||
}catch{
|
||||
modaldata = "fallo al intentar hacer la request";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata }
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata="")}/>
|
||||
{/if}
|
||||
|
||||
<div class="container-fluid mt-2">
|
||||
<BarraHorizontalConTexto text="Control de Pagos" />
|
||||
<div class="text-center">
|
||||
Lista de contratos que tienen canones atrasados
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row g-3">
|
||||
{#if alquileres == null}
|
||||
<div class="d-flex justify-content-center">
|
||||
<div class="spinner-border" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
{#if alquileres.length == 0}
|
||||
<h1 class=" d-flex justify-content-center">
|
||||
No hay Alquileres que deban meses
|
||||
</h1>
|
||||
{/if}
|
||||
{#each alquileres as alquiler}
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0 text-center">{alquiler.tipoPropiedad}</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h6 class="card-subtitle mb-2 text-muted">{alquiler.ubicacion}</h6>
|
||||
<p class="card-text">
|
||||
<strong>Fecha de inicio:</strong> {new Date(alquiler.fechainicio).toLocaleDateString()}<br />
|
||||
<strong>Inquilino:</strong> {alquiler.inquilino}<br />
|
||||
<strong>Propietario:</strong> {alquiler.propietario}<br>
|
||||
<strong>Id Propiedad: </strong>{alquiler.id}
|
||||
</p>
|
||||
<div class="d-flex justify-content-center">
|
||||
<button class="btn btn-primary" onclick={()=>navigate("/admin/contratos?id="+alquiler.id)}>
|
||||
Ver
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<strong>Estado:</strong> {alquiler.estado}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,21 +2,19 @@
|
||||
import { onMount } from "svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import { Chart } from "chart.js";
|
||||
import FChart from "../Componentes/Estadisticas/fChart.svelte";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import type { ChartData } from "../types";
|
||||
import { text } from "@sveltejs/kit";
|
||||
|
||||
let token = sessionStorage.getItem("token")||"";
|
||||
let y = $state(2025);
|
||||
|
||||
let cdata:ChartData|any = $state();
|
||||
let aldata:{id:number, ubicacion:string, divisa:string}|any = $state();
|
||||
let aldata:{id:number, ubicacion:string, divisa:string}[]= $state([]);
|
||||
|
||||
let chartMesesDuracion:ChartData|any = $state();
|
||||
let tablaMesesDuracion:{meses:number, repes:number, semaforizacion:string}|any = $state();
|
||||
let tablaMesesDuracion:{meses:number, repes:number, semaforizacion:string}[] = $state([]);
|
||||
|
||||
let modaldata:string = $state("");
|
||||
|
||||
@@ -74,6 +72,18 @@
|
||||
modaldata="Fallo al intentar alcanzar el servidor";
|
||||
}
|
||||
}
|
||||
|
||||
function toggleModoDaltonico() {
|
||||
if (tablaMesesDuracion== null) return;
|
||||
|
||||
tablaMesesDuracion.forEach(item => {
|
||||
if (item.semaforizacion === '🟢') {
|
||||
item.semaforizacion = '🔵';
|
||||
} else if (item.semaforizacion === '🔵') {
|
||||
item.semaforizacion = '🟢';
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if modaldata}
|
||||
@@ -103,7 +113,7 @@
|
||||
<div class="col">
|
||||
<div class="d-flex input-group">
|
||||
<input class="form-control" type="number" bind:value={y}>
|
||||
<button class="btn btn-primary" onclick={()=>dataAlquileresporAño(y)}><img src="/zoom.svg" aria-label="Lupa"></button>
|
||||
<button class="btn btn-primary" onclick={()=>dataAlquileresporAño(y)}><img src="/zoom.svg" alt="lupa" aria-label="Lupa">Buscar</button>
|
||||
</div>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
@@ -154,6 +164,7 @@
|
||||
<div class="accordion-body row">
|
||||
<div class="col">
|
||||
<p class="text-muted">Objetivo: <i>Mide la longitud de los contratos en meses y cuantos hay por cada longitud. por lo menos 2.</i></p>
|
||||
<input class="form-check-input" type="checkbox" onclick={toggleModoDaltonico}> Activar Modo Daltónico
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
155
Front/src/paginas/MisPropiedadesEnVenta.svelte
Normal file
155
Front/src/paginas/MisPropiedadesEnVenta.svelte
Normal file
@@ -0,0 +1,155 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { PropiedadDto, setVenta } from "../types";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import { fade } from "svelte/transition";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import ModalPublicarPropiedadParaVenta from "../Componentes/ModalPublicarPropiedadParaVenta.svelte";
|
||||
import ModificarPropiedadForm from "../Componentes/modificarPropiedadForm.svelte";
|
||||
|
||||
let token = sessionStorage.getItem("token")||"";
|
||||
|
||||
let modaldata:string =$state("");
|
||||
let propiedades:PropiedadDto[]|null = $state(null);
|
||||
let modificar:boolean = $state(false);
|
||||
let selprop:PropiedadDto = $state({canthabitaciones:0, id:0, iddivisa:0, letra:"", monto:0, piso:"", servicios:"", tipo:"", ubicacion:""});
|
||||
|
||||
onMount(()=>{
|
||||
obtenerpropiedadesenventa();
|
||||
});
|
||||
|
||||
async function obtenerpropiedadesenventa() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/propiedades/Venta/Propietario", {
|
||||
method:"GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
},
|
||||
});
|
||||
|
||||
if (r.ok) {
|
||||
let data = await r.json();
|
||||
propiedades =data;
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
modaldata= "Fallo la request"
|
||||
}
|
||||
}
|
||||
|
||||
function setmod(p:PropiedadDto) {
|
||||
if (modificar == false) selprop = p;
|
||||
modificar =! modificar;
|
||||
|
||||
}
|
||||
|
||||
let showBajaVenta:boolean = $state(false);
|
||||
|
||||
function unsetventa(p:PropiedadDto) {
|
||||
selprop = p;
|
||||
showBajaVenta= true;
|
||||
}
|
||||
|
||||
|
||||
async function submitBajaVenta(data:setVenta) {
|
||||
data.idpropiedad = selprop.id;
|
||||
try {
|
||||
const responce = await fetch(String($urlG)+"/api/propiedad/unsetPropiedadAVenta", {
|
||||
method: "PUT",
|
||||
headers:{
|
||||
'Auth' : String(sessionStorage.getItem("token")),
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if(responce.ok){
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
const json = await responce.json();
|
||||
modaldata = json.message;
|
||||
}catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata}
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")}/>
|
||||
{/if}
|
||||
|
||||
{#if showBajaVenta}
|
||||
<ModalPublicarPropiedadParaVenta btntext="Bajar de Venta" title="Bajar de venta" onClose={()=>!!(showBajaVenta=false)} onConfirm={submitBajaVenta}/>
|
||||
{/if}
|
||||
|
||||
<div class="container-fluid table-responsive mt-2">
|
||||
<BarraHorizontalConTexto text="Propiedades En Venta"/>
|
||||
<table class="container-fluid table-responsive table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>ubicacion</th>
|
||||
<th>Habitaciones</th>
|
||||
<th>Letra</th>
|
||||
<th>Piso</th>
|
||||
<th>Tipo</th>
|
||||
<th>Servicios</th>
|
||||
<th>Divisa</th>
|
||||
<th>Monto</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{#if propiedades == null}
|
||||
<tr>
|
||||
<td colspan="10">
|
||||
<div class="spinner-border" role="status"></div>
|
||||
<span>Cargando...</span>
|
||||
</td>
|
||||
</tr>
|
||||
{:else if propiedades.length <=0}
|
||||
<tr>
|
||||
<td colspan="10">No hay propiedades en venta para este usuario</td>
|
||||
</tr>
|
||||
{:else}
|
||||
{#each propiedades as p}
|
||||
<tr in:fade>
|
||||
<td>{p.id}</td>
|
||||
<td>{p.ubicacion}</td>
|
||||
<td>{p.canthabitaciones}</td>
|
||||
<td>{p.letra}</td>
|
||||
<td>{p.piso}</td>
|
||||
<td>{p.tipo}</td>
|
||||
<td>{p.servicios}</td>
|
||||
<td>
|
||||
{#if p.iddivisa == 0}
|
||||
AR$
|
||||
{:else}
|
||||
US$
|
||||
{/if}
|
||||
</td>
|
||||
<td>{p.monto}</td>
|
||||
<td class="d-flex justify-content-between gap-2">
|
||||
<button class="btn btn-secondary btn-sm" onclick={()=> setmod(p)}>Modificar</button>
|
||||
<button class="btn btn-secondary btn-sm" onclick={()=> unsetventa(p)}>Bajar de venta</button>
|
||||
</td>
|
||||
</tr>
|
||||
{#if modificar}
|
||||
<tr transition:fade={{duration:100}}>
|
||||
<td colspan="10">
|
||||
<ModificarPropiedadForm id={selprop.id} ubicacion={selprop.ubicacion}
|
||||
canthabitaciones={selprop.canthabitaciones} letra={selprop.letra} piso={selprop.piso}
|
||||
tipo={selprop.tipo} servicios={selprop.servicios} monto={selprop.monto} iddivisa={selprop.iddivisa}/>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -13,6 +13,7 @@
|
||||
import ModalVeryAceptarContrato from "../Componentes/ModalVeryAceptarContrato.svelte";
|
||||
import { getRequest } from "@sveltejs/kit/node";
|
||||
import { json } from "@sveltejs/kit";
|
||||
import { Accordion } from "@sveltestrap/sveltestrap";
|
||||
|
||||
const token = sessionStorage.getItem("token");
|
||||
let mensajes: MensajeDto[] = $state([]);
|
||||
@@ -135,6 +136,18 @@
|
||||
Selmens = {...mensaje};
|
||||
return;
|
||||
}
|
||||
|
||||
if (mensaje.accion === "Consulta Compra") {
|
||||
Selmens = {...mensaje};
|
||||
showConsultaCompra = true;
|
||||
messageConsultaCompra = mensaje.mensaje+". Al darle aceptar se baja la propiedad de la pagina de busqueda para venta, y dandole a Cancelar se envia una notificacion al potencial comprador de que no esta a la venta";
|
||||
return;
|
||||
}
|
||||
|
||||
if (mensaje.accion === "Notificacion") {
|
||||
Selmens = {...mensaje};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function obtenerListaGarantes(idcontrato: number) {
|
||||
@@ -161,7 +174,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje2(data: {opcionVenta:boolean, cantGarantes:number, mesesHastaAumento:number, mesesDuracionContrato:number}) {
|
||||
async function handleEnviarmensaje2(data: {opcionVenta:boolean, cantGarantes:number,
|
||||
mesesHastaAumento:number, mesesDuracionContrato:number, montoOpcion:number, iddivisa:number}) {
|
||||
if (data.opcionVenta == null || data.cantGarantes <=0 || data.mesesHastaAumento<=0 || data.mesesDuracionContrato <=0) {
|
||||
modaldata = "Estan mal cargados los datos del form";
|
||||
return;
|
||||
@@ -177,7 +191,9 @@
|
||||
fechaprimernotificacion: fecha,
|
||||
emailInquilino: Selmens.remitente,
|
||||
emailPropietario: Selmens.receptor,
|
||||
mesesDuracionContrato: data.mesesDuracionContrato
|
||||
mesesDuracionContrato: data.mesesDuracionContrato,
|
||||
montoOpcion: data.montoOpcion,
|
||||
iddivisa: data.iddivisa
|
||||
};
|
||||
|
||||
let responce = await fetch($urlG+"/api/contratos/precontrato", {
|
||||
@@ -411,6 +427,50 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let showConsultaCompra:boolean = $state(false);
|
||||
let messageConsultaCompra:string = $state("");
|
||||
async function handleAceptarConsultaVenta() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/venta/AceptarConsultaVenta", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": token||"",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({fecha: Selmens.fecha, email: localStorage.getItem("email")||""})
|
||||
});
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
if (r.ok){
|
||||
SinLeer();
|
||||
}
|
||||
}catch{
|
||||
modaldata= "Fallo al hacer la request";
|
||||
}
|
||||
showConsultaCompra = false; Selmens.accion = "";
|
||||
|
||||
}
|
||||
async function handleCancepConsultaVenta() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/venta/CancelarConsultaVenta", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": token||"",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({fecha: Selmens.fecha, email: localStorage.getItem("email")||""})
|
||||
});
|
||||
let data = await r.json();
|
||||
modaldata = data.message;
|
||||
if (r.ok){
|
||||
SinLeer();
|
||||
}
|
||||
}catch{
|
||||
modaldata= "Fallo al hacer la request";
|
||||
}
|
||||
showConsultaCompra = false; Selmens.accion = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
@@ -427,11 +487,14 @@
|
||||
<ModalCheckYContrato {garantes} men={Selmens} onCancel={handleCancelPrecontrato} onClose={() => (Selmens.accion = "")} onConfirm={handleEnviarmensaje4}/>
|
||||
{:else if Selmens.accion == "Aceptar Contrato"}
|
||||
<ModalVeryAceptarContrato onClose={() => (Selmens.accion = "")} onConfirm={handleAceptarContrato} onCancel={handlerechazarcontrato} getContrato={ObtenerContrato} men={Selmens}/>
|
||||
{:else if Selmens.accion == "Notificacion Inquilino"}
|
||||
{:else if Selmens.accion == "Notificacion Inquilino" || Selmens.accion == "Notificacion"}
|
||||
<ModalEstatico payload={Selmens.mensaje} close={()=> !!(Selmens.accion = "") }/>
|
||||
{:else if Selmens.accion == "Consulta Compra"}
|
||||
<ModalConfirm title="Potencial Comprador Consulta si Vendes la propiedad" show={showConsultaCompra} message={messageConsultaCompra} onConfirm={handleAceptarConsultaVenta}
|
||||
onCancel={handleCancepConsultaVenta} />
|
||||
{/if}
|
||||
|
||||
<div class="container">
|
||||
<div class="container-fluid">
|
||||
<br>
|
||||
<BarraHorizontalConTexto text="Notificaciones"/>
|
||||
<br>
|
||||
@@ -490,7 +553,7 @@
|
||||
</button>
|
||||
{/if}
|
||||
{#if (men.accion === "ContratoCancelado" || men.accion === "Rechazo Contrato" ||
|
||||
men.accion === "Aceptado Contrato" || men.accion === "Notificacion Inquilino"
|
||||
men.accion === "Aceptado Contrato" || men.accion === "Notificacion Inquilino" || men.accion == "Notificacion"
|
||||
) && mostrarleidos == false}
|
||||
<button
|
||||
class="btn btn-outline-danger btn-sm"
|
||||
|
||||
263
Front/src/paginas/Ventas.svelte
Normal file
263
Front/src/paginas/Ventas.svelte
Normal file
@@ -0,0 +1,263 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { VentasDto } from "../types";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
|
||||
let modaldata:string = $state("");
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
let file: File| null =$state(null);
|
||||
|
||||
let venta: VentasDto|any = $state({divisa:""});
|
||||
let ventaid:string = $state("");
|
||||
let escomprador:boolean = $state(true);
|
||||
let necesitaRecibo:boolean = $state(false);
|
||||
let checkAceptaRecibo:boolean = $state(false);
|
||||
|
||||
onMount(()=>{
|
||||
setQueryparam();
|
||||
obtenerVenta();
|
||||
});
|
||||
|
||||
async function obtenerVenta() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/venta?idventa="+ventaid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token
|
||||
}
|
||||
});
|
||||
let d = await r.json();
|
||||
if (r.ok) {
|
||||
venta = d.data;
|
||||
escomprador = d.iscomprador;
|
||||
necesitaRecibo = d.necesitaRecibo;
|
||||
return;
|
||||
}
|
||||
modaldata = d.message;
|
||||
} catch {
|
||||
modaldata = "Fallo al hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
function setQueryparam() {
|
||||
const qs = window.location.search;
|
||||
const par = new URLSearchParams(qs);
|
||||
ventaid = par.get("idventa")||"";
|
||||
}
|
||||
|
||||
function handleComprobateFile(e:Event){
|
||||
const input = e.target as HTMLInputElement;
|
||||
if (input.files && input.files.length > 0 ) {
|
||||
file = input.files[0];
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubirComprobante(e:Event) {
|
||||
e.preventDefault();
|
||||
if(file == null) {
|
||||
modaldata = "No se seleciono un pdf";
|
||||
return;
|
||||
}
|
||||
let formdata = new FormData();
|
||||
formdata.append("file", file);
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/ventas/subirReciboPago?idventa="+ventaid, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": token
|
||||
},
|
||||
body: formdata,
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
obtenerVenta();
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "Fallo al hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function verComprobante() {
|
||||
try {
|
||||
const responce = await fetch($urlG+"/api/ventas/verRecibo?idventa="+ventaid, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
}
|
||||
});
|
||||
if (!responce.ok) {
|
||||
modaldata="Error al obtener el archivo";
|
||||
return;
|
||||
}
|
||||
|
||||
let blob = await responce.blob();
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
window.open(blobUrl, '_blank');
|
||||
setTimeout(() => URL.revokeObjectURL(blobUrl), 100000);
|
||||
} catch {
|
||||
modaldata = "Fallo al intentar conectarse al servidor";
|
||||
}
|
||||
}
|
||||
|
||||
async function aceptarRecibo() {
|
||||
try {
|
||||
const r = await fetch($urlG+"/api/ventas/propietarioverifica?idventa="+ventaid, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": token
|
||||
},
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
obtenerVenta();
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "Fallo al hacer la request";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata}
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata ="")} />
|
||||
{/if}
|
||||
|
||||
<div class="container-fluid mt-4 d-flex">
|
||||
<div class="col-md-4 me-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Datos Venta
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<b>Monto: </b> {venta.divisa} {venta.monto}<br>
|
||||
<b>Ubicación: </b> {venta.ubicacion}<br>
|
||||
<b>Vendedor: </b> {venta.nombreVendedor} <br>
|
||||
<b>Comprador: </b> {venta.nombreComprador} <br>
|
||||
<b>Estado: </b> {venta.estado} <br>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
VentaID: {venta.id}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="accordion" id="accordion">
|
||||
{#if escomprador}
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="h1">
|
||||
<button class="btn accordion-button"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#c1"
|
||||
aria-expanded="true"
|
||||
aria-controls="c1">
|
||||
Subir Comprobante de Pago
|
||||
</button>
|
||||
</h2>
|
||||
<div class="accordion-collapse collapse show"
|
||||
data-bs-parent="#accordion" id="c1"
|
||||
>
|
||||
<div class="accordion-body">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Suba su Comprobante de pago
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<label for="comprobante" class="form-label">El comprobante debe estar en formato pdf</label>
|
||||
<input disabled={!necesitaRecibo} class="form-control" type="file" name="comprobante" id="comprobante"
|
||||
onchange={handleComprobateFile}>
|
||||
<div class="d-flex justify-content-between">
|
||||
<button disabled={!necesitaRecibo} class="btn btn-primary mt-2" type="submit" onclick={(e)=>handleSubirComprobante(e)}>Subir</button>
|
||||
</div>
|
||||
</form>
|
||||
<button disabled={necesitaRecibo} class="btn btn-primary mt-2" type="submit" onclick={verComprobante}>Ver</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="h2">
|
||||
<button class="btn accordion-button"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#c2"
|
||||
aria-expanded="true"
|
||||
aria-controls="c2">
|
||||
Ver Comprobante de Pago
|
||||
</button>
|
||||
</h2>
|
||||
<div class="accordion-collapse collapse show"
|
||||
data-bs-parent="#accordion" id="c2"
|
||||
>
|
||||
<div class="accordion-body">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Vea el comprobante de pago
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{#if necesitaRecibo}
|
||||
<p>El boton estará habilitado cuando el comprador suba el recibo</p>
|
||||
{/if}
|
||||
<button disabled={necesitaRecibo} class="btn btn-primary mt-1" type="submit" onclick={verComprobante}>Ver</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if !necesitaRecibo && venta.estado !="Vendido"}
|
||||
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="h3">
|
||||
<button class="btn accordion-button"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#c3"
|
||||
aria-expanded="true"
|
||||
aria-controls="c3">
|
||||
Aceptar comprobante de pago
|
||||
</button>
|
||||
</h2>
|
||||
<div class="accordion-collapse collapse"
|
||||
data-bs-parent="#accordion" id="c3"
|
||||
>
|
||||
<div class="accordion-body">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<button disabled={necesitaRecibo} class="btn btn-primary mt-1" type="submit" onclick={verComprobante}>
|
||||
Ver comprobante
|
||||
</button>
|
||||
<hr>
|
||||
<input disabled={checkAceptaRecibo} type="checkbox" class="form-check-input" name="check" id="check" bind:checked={checkAceptaRecibo}>
|
||||
<label for="check">Acepto el comprobante</label>
|
||||
{#if checkAceptaRecibo}
|
||||
<hr>
|
||||
<div class="row align-items-center">
|
||||
<div class="col-3">
|
||||
<button class="btn btn-primary" onclick={aceptarRecibo}>
|
||||
Aceptar
|
||||
</button>
|
||||
</div>
|
||||
<div class="col">
|
||||
<p class="text-muted mb-0">Al darle al botón se va a iniciar el proceso de traspaso de la propiedad</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
111
Front/src/paginas/VerLogs.svelte
Normal file
111
Front/src/paginas/VerLogs.svelte
Normal file
@@ -0,0 +1,111 @@
|
||||
<script lang="ts">
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { LogDetalleDto, LogDto } from "../types";
|
||||
import { onMount } from "svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import ModalLogs from "../Componentes/ModalLogs.svelte";
|
||||
import PaginacionStepper from "../Componentes/PaginacionStepper.svelte";
|
||||
|
||||
let Logs: LogDto[] = $state([]);
|
||||
let pagina:number = $state(1);
|
||||
let token:string = sessionStorage.getItem("token")||"";
|
||||
let modaldata:string = $state("");
|
||||
let showmodal:boolean =$state(false);
|
||||
let ll:LogDto|any = $state({});
|
||||
let cantpag:number = $state(0);
|
||||
|
||||
onMount(()=>{
|
||||
obtenerLogs();
|
||||
obtenerPaginas();
|
||||
});
|
||||
|
||||
async function obtenerPaginas() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/Logs/cantPag", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
cantpag = data;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "no se pudo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
async function obtenerLogs() {
|
||||
try{
|
||||
const r = await fetch($urlG+"/api/Logs?pag="+pagina, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": token,
|
||||
}
|
||||
});
|
||||
let data = await r.json();
|
||||
if (r.ok) {
|
||||
Logs = data;
|
||||
return;
|
||||
}
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "no se pudo hacer la request";
|
||||
}
|
||||
}
|
||||
|
||||
function prepararModal(l: LogDto) {
|
||||
ll = l;
|
||||
showmodal = true;
|
||||
}
|
||||
function queryPag(a:number) {
|
||||
pagina = a;
|
||||
obtenerLogs();
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
{#if modaldata}
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")}/>
|
||||
{/if}
|
||||
|
||||
{#if showmodal}
|
||||
<ModalLogs onClose={()=>!!(showmodal=!showmodal)} log={ll}/>
|
||||
{/if}
|
||||
|
||||
<div class="container-fluid mt-2">
|
||||
<BarraHorizontalConTexto text={"Logs"}/>
|
||||
<table class="table table-responsive table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Fecha</th>
|
||||
<th>Id Usuario</th>
|
||||
<th>Accion</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Logs as l}
|
||||
<tr>
|
||||
<td>{l.fecha}</td>
|
||||
<td>{l.dniusuario}</td>
|
||||
<td>{l.accion}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary" onclick={()=>prepararModal(l)}>
|
||||
Ver
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-flex justify-content-center">
|
||||
<PaginacionStepper currentPag={pagina} {cantpag} {queryPag}/>
|
||||
</div>
|
||||
</div>
|
||||
74
Front/src/types.d.ts
vendored
74
Front/src/types.d.ts
vendored
@@ -10,6 +10,18 @@ export type PropiedadDto = {
|
||||
iddivisa: number
|
||||
}
|
||||
|
||||
export type PropiedadVentaDto = {
|
||||
id: number,
|
||||
ubicacion: string,
|
||||
tipo: string,
|
||||
piso: string | null,
|
||||
letra: string | null,
|
||||
canthabitaciones: number,
|
||||
servicios: string,
|
||||
monto: number,
|
||||
divisa: string
|
||||
}
|
||||
|
||||
export type AdminParametrosBusqueda = {
|
||||
cantidadhabitaciones: number=0,
|
||||
tipopropiedad: number=0,
|
||||
@@ -144,4 +156,66 @@ export type ChartData = {
|
||||
label: string,
|
||||
data:string[],
|
||||
}]
|
||||
}
|
||||
|
||||
export type OpcionVentaDto = {
|
||||
id:number,
|
||||
monto:number,
|
||||
divisa:string,
|
||||
enOrden:boolean,
|
||||
fueEjercido:boolean
|
||||
}
|
||||
|
||||
export type VentasDto = {
|
||||
id:number,
|
||||
monto:numver,
|
||||
divisa:string,
|
||||
ubicacion:string,
|
||||
nombreVendedor:string,
|
||||
idVendedor:number,
|
||||
nombreComprador:string,
|
||||
idComprador:number,
|
||||
estado:string,
|
||||
}
|
||||
|
||||
export type LogDto = {
|
||||
fecha:Date,
|
||||
dniusuario:number,
|
||||
accion:string
|
||||
}
|
||||
|
||||
export type LogDetalleDto = {
|
||||
fecha:Date,
|
||||
dniusuario:number,
|
||||
nombreTabla:string,
|
||||
columna:string,
|
||||
valorAnterior:string,
|
||||
valorNuevo:string
|
||||
}
|
||||
|
||||
export type UpdateCliente = {
|
||||
dni:number,
|
||||
nombre:string,
|
||||
apellido:string,
|
||||
domicilio:string,
|
||||
celular:string,
|
||||
}
|
||||
|
||||
export type setVenta = {
|
||||
idpropiedad:number,
|
||||
monto:number,
|
||||
iddivisa:number,
|
||||
}
|
||||
|
||||
export type PatchPropiedad = {
|
||||
id:number,
|
||||
ubicacion:string,
|
||||
canthabitaciones:number,
|
||||
piso:number,
|
||||
letra:string,
|
||||
email:string,
|
||||
tipo:number,
|
||||
servicios: string[],
|
||||
monto:number,
|
||||
iddivisa:number
|
||||
}
|
||||
119
Modelo/Facade/AuditoriaFacade.cs
Normal file
119
Modelo/Facade/AuditoriaFacade.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo.Facade;
|
||||
public class AuditoriaFacade {
|
||||
private readonly AlquilaFacilContext _context;
|
||||
private readonly FiltroCambios _filtradoDeCambios=new();
|
||||
private readonly ValidadorDeCambios _validadorDeCambios=new();
|
||||
private readonly PersistenciaLog _persistenciaDeLog=new();
|
||||
|
||||
public AuditoriaFacade(AlquilaFacilContext context) {
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void GenerarLog(long dniUsuario, string v) {
|
||||
var cambios = _filtradoDeCambios.FiltrarCambios(_context.ChangeTracker.Entries());
|
||||
|
||||
var fechaActual = DateTime.Now;
|
||||
|
||||
var log = new Log{
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
Accion = v
|
||||
};
|
||||
|
||||
log.LogDetalles = ProcesarCambios(cambios, fechaActual, dniUsuario);
|
||||
|
||||
_persistenciaDeLog.GuardarLog(log, log.LogDetalles);
|
||||
}
|
||||
|
||||
private List<LogDetalle> ProcesarCambios(IEnumerable<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> cambios,
|
||||
DateTime fechaActual, long dniUsuario) {
|
||||
|
||||
var logDetalles = new List<LogDetalle>();
|
||||
foreach (var cambio in cambios) {
|
||||
var nombreTabla = cambio.Entity.GetType().Name;
|
||||
Console.WriteLine($"Entidad: {cambio.Entity.GetType().Name}, Estado: {cambio.State}");
|
||||
|
||||
switch (cambio.State) {
|
||||
case EntityState.Modified:
|
||||
foreach (var propiedad in cambio.OriginalValues.Properties) {
|
||||
if (propiedad.Name == "Token") break;
|
||||
var valorAnterior = cambio.OriginalValues[propiedad]?.ToString();
|
||||
var valorNuevo = cambio.CurrentValues[propiedad]?.ToString();
|
||||
|
||||
if (_validadorDeCambios.ValidarCambio(valorAnterior??"", valorNuevo??"")) {
|
||||
if (!_context.LogDetalles.Any(ld =>
|
||||
ld.Fecha == fechaActual &&
|
||||
ld.Dniusuario == dniUsuario &&
|
||||
ld.NombreTabla == nombreTabla &&
|
||||
ld.Columna == propiedad.Name))
|
||||
{
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = valorAnterior,
|
||||
ValorNuevo = valorNuevo
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EntityState.Added:
|
||||
foreach (var propiedad in cambio.CurrentValues.Properties) {
|
||||
if (propiedad.Name == "Token") break;
|
||||
var valorNuevo = cambio.CurrentValues[propiedad]?.ToString();
|
||||
|
||||
if (!_context.LogDetalles.Any(ld =>
|
||||
ld.Fecha == fechaActual &&
|
||||
ld.Dniusuario == dniUsuario &&
|
||||
ld.NombreTabla == nombreTabla &&
|
||||
ld.Columna == propiedad.Name))
|
||||
{
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = null,
|
||||
ValorNuevo = valorNuevo
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EntityState.Deleted:
|
||||
foreach (var propiedad in cambio.OriginalValues.Properties) {
|
||||
if (propiedad.Name == "Token") break;
|
||||
var valorAnterior = cambio.OriginalValues[propiedad]?.ToString();
|
||||
|
||||
if (!_context.LogDetalles.Any(ld =>
|
||||
ld.Fecha == fechaActual &&
|
||||
ld.Dniusuario == dniUsuario &&
|
||||
ld.NombreTabla == nombreTabla &&
|
||||
ld.Columna == propiedad.Name))
|
||||
{
|
||||
logDetalles.Add(new LogDetalle {
|
||||
Fecha = fechaActual,
|
||||
Dniusuario = dniUsuario,
|
||||
NombreTabla = nombreTabla,
|
||||
Columna = propiedad.Name,
|
||||
ValorAnterior = valorAnterior,
|
||||
ValorNuevo = null
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Console.WriteLine($"Estado no manejado: {cambio.State}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return logDetalles;
|
||||
}
|
||||
}
|
||||
6
Modelo/Facade/FiltroCambios.cs
Normal file
6
Modelo/Facade/FiltroCambios.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Modelo.Facade;
|
||||
public class FiltroCambios {
|
||||
public IEnumerable<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> FiltrarCambios(IEnumerable<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry> cambios) {
|
||||
return cambios.Where(c => c.Entity.GetType().Name != "EntidadExcluida");
|
||||
}
|
||||
}
|
||||
16
Modelo/Facade/PersistenciaLog.cs
Normal file
16
Modelo/Facade/PersistenciaLog.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Entidades;
|
||||
namespace Modelo.Facade;
|
||||
public class PersistenciaLog {
|
||||
private AlquilaFacilContext _context {get{return new AlquilaFacilContext();}}
|
||||
public void GuardarLog(Log log, IEnumerable<LogDetalle> detalles) {
|
||||
var con = _context;
|
||||
int j = 1;
|
||||
foreach (var i in log.LogDetalles) {
|
||||
i.Id = j;
|
||||
j++;
|
||||
}
|
||||
con.Logs.Add(log);
|
||||
//con.LogDetalles.AddRange(detalles);
|
||||
con.SaveChanges();
|
||||
}
|
||||
}
|
||||
6
Modelo/Facade/ValidadorCambios.cs
Normal file
6
Modelo/Facade/ValidadorCambios.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Modelo.Facade;
|
||||
public class ValidadorDeCambios {
|
||||
public bool ValidarCambio(string valorAnterior, string valorNuevo) {
|
||||
return !string.IsNullOrEmpty(valorNuevo) && valorAnterior != valorNuevo;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Modelo.Facade;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
@@ -9,6 +11,12 @@ public abstract class RepositorioBase<S>
|
||||
private static readonly S instance = new();
|
||||
public static S Singleton { get { return instance; }}
|
||||
|
||||
public void GenerarLog(AlquilaFacilContext context, long dni, string accion) {
|
||||
var Auditoria = new AuditoriaFacade(context);
|
||||
|
||||
Auditoria.GenerarLog(dni, accion??"");
|
||||
return;
|
||||
}
|
||||
public bool Guardar(AlquilaFacilContext context) {
|
||||
bool ret = false;
|
||||
try
|
||||
|
||||
@@ -27,7 +27,13 @@ public class RepositorioCanons: RepositorioBase<RepositorioCanons> {
|
||||
return cc;
|
||||
}
|
||||
|
||||
public bool SetRecibo(Canon c, Recibo re) {
|
||||
public Canon? ObtenerCanonPorId(long id){
|
||||
var con = Context;
|
||||
var cnn = con.Canons.FirstOrDefault(x=>x.Id == id);
|
||||
return cnn;
|
||||
}
|
||||
|
||||
public bool SetRecibo(Canon c, Recibo re, long dni, string mensaje= "Set Recibo") {
|
||||
var con = Context;
|
||||
var cc = con.Canons
|
||||
.Include(x=>x.Idcontratos)
|
||||
@@ -51,10 +57,12 @@ public class RepositorioCanons: RepositorioBase<RepositorioCanons> {
|
||||
ccc.IdpropiedadNavigation.Idestado = 3;
|
||||
}
|
||||
|
||||
GenerarLog(con, dni, mensaje);
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool CrearCanons(decimal aumento, long idcontrato) {
|
||||
public bool CrearCanons(decimal aumento, long idcontrato, long dni) {
|
||||
var con = Context;
|
||||
|
||||
aumento/=100;
|
||||
@@ -86,6 +94,8 @@ public class RepositorioCanons: RepositorioBase<RepositorioCanons> {
|
||||
con.Canons.Add(c);
|
||||
cont.Idcanons.Add(c);
|
||||
}
|
||||
GenerarLog(con, dni, $"Crear Canones");
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
}
|
||||
}
|
||||
|
||||
public bool CargaPrecontrato(Contrato? c = null, Notificacione? n = null) {
|
||||
public bool CargaPrecontrato(long dni, Contrato? c = null, Notificacione? n = null) {
|
||||
if (c == null || c.Habilitado == 1) return false;
|
||||
if (n == null) return false;
|
||||
var con = Context;
|
||||
@@ -29,10 +29,10 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
|
||||
con.Contratos.Add(c);
|
||||
con.Notificaciones.Add(n);
|
||||
|
||||
GenerarLog(con, dni, $"CargaPrecontrato");
|
||||
return Guardar(con);
|
||||
}
|
||||
public bool CargaGarantes(List<Garante> gar, string emailInquilino, int idpropiedad) {
|
||||
public bool CargaGarantes(List<Garante> gar, string emailInquilino, int idpropiedad, long dni) {
|
||||
var con = Context;
|
||||
Contrato? contr = con.Contratos.Include(x=>x.DniinquilinoNavigation).Include(x=>x.Idgarantes)
|
||||
.FirstOrDefault(x=>x.Idpropiedad == idpropiedad &&
|
||||
@@ -48,7 +48,7 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
con.Garantes.Add(i);
|
||||
contr.Idgarantes.Add(i);
|
||||
}
|
||||
|
||||
GenerarLog(con, dni, $"Alta Garantes");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
|
||||
}
|
||||
|
||||
public bool CancelarPrecontrato(string emailInquilino, int idpropiedad) {
|
||||
public bool CancelarPrecontrato(string emailInquilino, int idpropiedad, long dni) {
|
||||
var con = Context;
|
||||
Contrato? contr = con.Contratos.Include(x=>x.DniinquilinoNavigation)
|
||||
.FirstOrDefault(x=>x.Idpropiedad == idpropiedad &&
|
||||
@@ -86,6 +86,7 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
if (contr == null || contr.IdpropiedadNavigation == null) return false;
|
||||
contr.Cancelado = 1;
|
||||
contr.IdpropiedadNavigation.Idestado = 1;
|
||||
GenerarLog(con, dni, $"Cancelar Precontrato");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -101,16 +102,17 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
return contr;
|
||||
}
|
||||
|
||||
public bool AddUrl(long id, string nuevoNombreArchivo) {
|
||||
public bool AddUrl(long id, string nuevoNombreArchivo, long dni) {
|
||||
var con = Context;
|
||||
Contrato? contrato = con.Contratos
|
||||
.FirstOrDefault(x=>x.Id == id);
|
||||
if (contrato == null) return false;
|
||||
contrato.UrlContrato = nuevoNombreArchivo;
|
||||
GenerarLog(con, dni, $"Añadido contrato");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool AceptarContrato(long idcontrato) {
|
||||
public bool AceptarContrato(long idcontrato, long dni) {
|
||||
var con = Context;
|
||||
Contrato? cont = con.Contratos
|
||||
.Include(x=>x.Idcanons)
|
||||
@@ -151,15 +153,18 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
cont.Idcanons.Add(can);
|
||||
}
|
||||
}
|
||||
GenerarLog(con, dni, $"Aceptado contrato");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool CancelarPrecontrato(long idcontrato) {
|
||||
public bool CancelarPrecontrato(long idcontrato, long dni) {
|
||||
var con = Context;
|
||||
Contrato? cont = con.Contratos.Include(x=>x.IdpropiedadNavigation).FirstOrDefault(x=>x.Id ==idcontrato && x.Habilitado ==0);
|
||||
if (cont == null|| cont.IdpropiedadNavigation==null) return false;
|
||||
cont.Cancelado = 1;
|
||||
cont.IdpropiedadNavigation.Idestado = 1;
|
||||
GenerarLog(con, dni, $"Cancelar Precontrato");
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -201,4 +206,53 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
var con = Context;
|
||||
return con.Contratos.Where(x=>x.Fechainicio.Year == year).Any();
|
||||
}
|
||||
|
||||
public bool SetOpcionVenta(Venta v, long idcontrato) {
|
||||
var con = Context;
|
||||
var cont = con.Contratos.Include(x=>x.IdventaNavigation).FirstOrDefault(x=>x.Id == idcontrato);
|
||||
if (cont != null) return false;
|
||||
|
||||
v.Id = (con.Ventas.Any()?con.Ventas.Count():0)+1;
|
||||
|
||||
cont.IdventaNavigation = v;
|
||||
con.Ventas.Add(v);
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool CargaPrecontratoOpcionVenta(Contrato c, Notificacione n, Venta v, long dni) {
|
||||
if (c == null || c.Habilitado == 1) return false;
|
||||
if (n == null) return false;
|
||||
var con = Context;
|
||||
|
||||
var prop = con.Propiedades.FirstOrDefault(x=>x.Id==c.Idpropiedad);
|
||||
if (prop == null) return false;
|
||||
prop.Idestado = 2;
|
||||
|
||||
c.Iddivisa = prop.Iddivisa;
|
||||
c.Id = (con.Contratos.Any() ? con.Contratos.Max(x => x.Id) : 0) + 1;
|
||||
c.Monto = prop.Monto;
|
||||
|
||||
v.Id = (con.Ventas.Any()?con.Ventas.Count():0)+1;
|
||||
c.Idventa = v.Id;
|
||||
|
||||
con.Ventas.Add(v);
|
||||
con.Contratos.Add(c);
|
||||
con.Notificaciones.Add(n);
|
||||
GenerarLog(con, dni, $"Carga Precontrato con opcion venta");
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public IQueryable<Contrato> ObtenerContratosInpagos() {
|
||||
var con = Context;
|
||||
DateTime d = DateTime.Now;
|
||||
var l = con.Contratos
|
||||
.Include(x=>x.DniinquilinoNavigation)
|
||||
.Include(x=>x.DnipropietarioNavigation)
|
||||
.Include(x=>x.IdpropiedadNavigation)
|
||||
.ThenInclude(x=>x.IdtipropiedadNavigation)
|
||||
.Include(x=>x.Idcanons)
|
||||
.Where(x=>x.Idcanons.Any(x=>x.Pagado ==0 && d > x.Fecha));
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,20 @@ using Microsoft.EntityFrameworkCore;
|
||||
namespace Modelo;
|
||||
|
||||
public class RepositorioDefectos: RepositorioBase<RepositorioDefectos> {
|
||||
public bool AltaDefecto(Defecto defecto){
|
||||
public bool AltaDefecto(Defecto defecto, long dni){
|
||||
var con = Context;
|
||||
defecto.Id = con.Defectos.Any()? con.Defectos.Count()+1 : 1;
|
||||
con.Defectos.Add(defecto);
|
||||
GenerarLog(con, dni, $"Alta Defecto: {defecto.Id}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool MarcarPago(long iddefecto){
|
||||
public bool MarcarPago(long iddefecto, long dni){
|
||||
var con = Context;
|
||||
var d = con.Defectos.FirstOrDefault(x=>x.Id == iddefecto);
|
||||
if (d == null)return false;
|
||||
d.Idestado = 2;
|
||||
GenerarLog(con, dni, $"Marcado Pago Defecto: {iddefecto}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,34 @@ public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
|
||||
return data;
|
||||
}
|
||||
|
||||
public ChartData? ObtenerDatosPagosContrato(long idcontrato) {
|
||||
var con = Context;
|
||||
var cont = con.Contratos.Include(c=>c.Idcanons).ThenInclude(x=>x.IdreciboNavigation)
|
||||
.Where(x=>x.Habilitado==1)
|
||||
.FirstOrDefault(x=>x.Id == idcontrato);
|
||||
if(cont==null)return null;
|
||||
|
||||
var data = new ChartData();
|
||||
data.Labels= ["Pago", "Sin Pagar", "Pago Atrasado"];
|
||||
|
||||
Dataset d1 = new();
|
||||
d1.Label="Estadistica Pagos";
|
||||
|
||||
var l = new List<string>(["0","0","0"]);
|
||||
|
||||
l[0] = cont.Idcanons.Where(x=>x.Pagado == 1Lu && x.IdreciboNavigation != null && x.IdreciboNavigation.Fecha <= x.Fecha)
|
||||
.Count().ToString();
|
||||
|
||||
l[1] = cont.Idcanons.Where(x=>x.Pagado==0).Count().ToString();
|
||||
|
||||
l[2] = cont.Idcanons.Where(x=>x.Pagado == 1Lu && x.IdreciboNavigation != null && x.IdreciboNavigation.Fecha > x.Fecha)
|
||||
.Count().ToString();
|
||||
d1.Data.AddRange(l);
|
||||
data.Datasets.Add(d1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public IQueryable<Contrato> TablaObtenerContratosIniciadosPorAño(int year) {
|
||||
var con = Context;
|
||||
var contratosPorMes = con.Contratos.Include(x=>x.IddivisaNavigation).Include(x=>x.IdpropiedadNavigation)
|
||||
@@ -69,4 +97,5 @@ public class RepositorioEstadisticas: RepositorioBase<RepositorioEstadisticas> {
|
||||
return l;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,19 +4,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
public class RepositorioGrupos: RepositorioBase<RepositorioGrupos> {
|
||||
public bool CrearGrupo(string descripcion)
|
||||
{
|
||||
var con = Context;
|
||||
|
||||
int mx = con.Grupos.Max(grupo => grupo.Id);
|
||||
Grupo gru = new Grupo{
|
||||
Id = mx+1,
|
||||
Nombre = descripcion,
|
||||
};
|
||||
con.Grupos.Add(gru);
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public IQueryable<Permiso> ListarPermisosDeGrupo(string grupo) {
|
||||
var con = Context;
|
||||
|
||||
29
Modelo/RepositorioLogs.cs
Normal file
29
Modelo/RepositorioLogs.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Linq;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
public class RepositorioLogs: RepositorioBase<RepositorioLogs> {
|
||||
public int ObtenerCantidadPaginas() {
|
||||
var con = Context;
|
||||
float a = con.Logs.Count()/10f;
|
||||
int b = (int)a;
|
||||
if (b != a){
|
||||
b++;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public IOrderedEnumerable<LogDetalle> ObtenerDetallesLogs(DateTime fecha, long idusuario) {
|
||||
var con = Context;
|
||||
var d = con.Logs.Include(x=>x.LogDetalles)
|
||||
.FirstOrDefault(x => x.Fecha == fecha && x.Dniusuario == idusuario);
|
||||
return d.LogDetalles.OrderBy(x=>x.Id);
|
||||
}
|
||||
|
||||
public IQueryable<Log>? ObtenerLogsPaginado(int pag) {
|
||||
var con = Context;
|
||||
var l = con.Logs.OrderByDescending(x=>x.Fecha).Skip(10*pag).Take(10);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,13 @@ public class RepositorioNotificaciones : RepositorioBase<RepositorioNotificacion
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool AltaNotificacion(Notificacione n) {
|
||||
public bool AltaNotificacion(Notificacione n, long dni=0) {
|
||||
var con = Context;
|
||||
|
||||
con.Notificaciones.Add(n);
|
||||
if (dni !=0){
|
||||
GenerarLog(con, dni, "Se envio un informe");
|
||||
}
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -43,4 +46,10 @@ public class RepositorioNotificaciones : RepositorioBase<RepositorioNotificacion
|
||||
bool hay = con.Notificaciones.Where(x=>x.Leido == false && x.Dnicliente == dni).Any();
|
||||
return hay;
|
||||
}
|
||||
|
||||
public Notificacione? ObtenerNotificacionPorKeys(long dni, DateTime? fecha) {
|
||||
var con = Context;
|
||||
var n = con.Notificaciones.FirstOrDefault(x => x.Dnicliente ==dni && x.Fecha == fecha);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
@@ -49,18 +49,4 @@ public class RepositorioPermisos: RepositorioBase<RepositorioPermisos> {
|
||||
|
||||
return tienePermiso;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
public bool CrearPermiso(string descripcion) {
|
||||
var con = Context;
|
||||
int mx = con.Permisos.Max(x => x.Id);
|
||||
|
||||
Permiso per = new Permiso{
|
||||
Id = mx+1,
|
||||
Descripcion = descripcion
|
||||
};
|
||||
con.Permisos.Add(per);
|
||||
return Guardar(con);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
||||
return (int)filasInsertadasParam.Value == 1? true: false;
|
||||
}
|
||||
|
||||
public bool PatchPropiedad(Propiedade prop) {
|
||||
public bool PatchPropiedad(Propiedade prop, long dni) {
|
||||
var con = Context;
|
||||
Propiedade? propi = con.Propiedades.Include(x=>x.IdServicios).FirstOrDefault(x=>x.Id == prop.Id);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
||||
if (servi == null) return false;
|
||||
propi.IdServicios.Add(servi);
|
||||
}
|
||||
|
||||
GenerarLog(con, dni, $"Se modificó: {prop.Id}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -156,23 +156,23 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
||||
}else{
|
||||
prop.Idestado = 1;
|
||||
}
|
||||
|
||||
GenerarLog(con, cli.Dni, $"Baja propiedad: {prop.Id}");
|
||||
return Guardar(con);
|
||||
|
||||
}
|
||||
|
||||
public bool BajaPropiedad(int id) {
|
||||
public bool BajaPropiedad(int id, long dni) {
|
||||
var con = Context;
|
||||
Propiedade? prop = con.Propiedades.FirstOrDefault(x=>x.Id == id);
|
||||
|
||||
if (prop == null||prop.Dnipropietario == 0) return false;
|
||||
|
||||
prop.Idestado = prop.Idestado == 3 ? 1 : 3;
|
||||
|
||||
GenerarLog(con, dni, $"Baja propiedad: {prop.Id}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool BajaServiciosAPropiedad(int idprop, List<int> idserv) {
|
||||
public bool BajaServiciosAPropiedad(int idprop, List<int> idserv, long dni) {
|
||||
var con = Context;
|
||||
Propiedade? prop = con.Propiedades.Include(x=>x.IdServicios).FirstOrDefault(x => x.Id == idprop);
|
||||
if (prop == null) return false;
|
||||
@@ -186,7 +186,7 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
||||
prop.IdServicios.Remove(servicio);
|
||||
}
|
||||
}
|
||||
|
||||
GenerarLog(con, dni, $"Baja servicios a propiedad: {prop.Id}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -611,4 +611,27 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
||||
|
||||
return (int)Math.Ceiling((double)totalRegistros / registrosPorPagina);
|
||||
}
|
||||
|
||||
public IQueryable<Propiedade>? ObtenerPropiedadesEnVenta(int pag){
|
||||
var con = Context;
|
||||
|
||||
var props = con.Propiedades.Include(x=>x.IdServicios).Include(x=>x.IddivisaNavigation)
|
||||
.Include(c=>c.IdtipropiedadNavigation)
|
||||
.Where(x=>x.Idestado ==4 && !x.Venta.Any(x=>x.Idestado ==2))
|
||||
.Skip(pag*10).Take(10);
|
||||
return props;
|
||||
}
|
||||
public int ObtenerPaginasDePropiedadesEnVenta(){
|
||||
var con = Context;
|
||||
|
||||
var props = con.Propiedades.Where(x=>x.Idestado ==4 && !x.Venta.Any(x=>x.Idestado ==2)).Count();
|
||||
return (int)Math.Ceiling((double)props / 10);
|
||||
}
|
||||
|
||||
public IQueryable<Propiedade> ObtenerPropiedadesAVentaPorDni(long dni) {
|
||||
var con = Context;
|
||||
var l = con.Propiedades.Include(x=>x.IdServicios).Include(x=>x.IdtipropiedadNavigation)
|
||||
.Where(x=>x.Dnipropietario == dni && x.Idestado ==4);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Text;
|
||||
using Entidades.Dto;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Entidades.Admin;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
@@ -28,6 +29,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
if (cli.Dni == 0) return false;
|
||||
|
||||
cli.Idgrupos.Add(grupo);
|
||||
GenerarLog(con, cli.Dni, $"Alta Inquilino: {cli.Dni}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
if (cli.Dni == 0) return false;
|
||||
|
||||
cli.Idgrupos.Add(grupo);
|
||||
GenerarLog(con, cli.Dni, $"Alta Propietario: {cli.Dni}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -67,7 +70,8 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
|
||||
|
||||
public bool CheckUsuario(LoginDto logindto) {
|
||||
|
||||
if (logindto.Contraseña ==null)return false;
|
||||
|
||||
string Contraseña = HacerHash(logindto.Contraseña);
|
||||
|
||||
Cliente? usu = Context.Clientes.FirstOrDefault(a => a.Email == logindto.Email);
|
||||
@@ -126,7 +130,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool AñadirClienteAGrupo(string email, string grupo) {
|
||||
public bool AñadirClienteAGrupo(string email, string grupo, long dni) {
|
||||
var con = Context;
|
||||
|
||||
var cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Email == email);
|
||||
@@ -137,10 +141,11 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
}
|
||||
|
||||
cli.Idgrupos.Add(gru);
|
||||
GenerarLog(con, dni, $"Añadir grupo: {gru.Nombre}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool EliminarClienteAGrupo(string email, string grupo) {
|
||||
public bool EliminarClienteAGrupo(string email, string grupo, long dniresponsable) {
|
||||
var con = Context;
|
||||
|
||||
var cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Email == email);
|
||||
@@ -150,6 +155,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
return false;
|
||||
}
|
||||
cli.Idgrupos.Remove(gru);
|
||||
GenerarLog(con, dniresponsable, $"Eliminar de grupo: {gru.Nombre}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -164,7 +170,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
} else {
|
||||
cli.Habilitado = 0;
|
||||
}
|
||||
|
||||
GenerarLog(con, cli.Dni, $"Baja cliente id: {cli.Dni}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
@@ -181,4 +187,18 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
if (cli == null|| cli.Dni == 0) return null;
|
||||
return cli;
|
||||
}
|
||||
|
||||
public bool PatchUsuario(UpdateUsuarioAdmin dto, long dni, long responsabledni) {
|
||||
var con = Context;
|
||||
var usu = con.Clientes.FirstOrDefault(x=>x.Dni ==dni);
|
||||
if (usu == null) return false;
|
||||
|
||||
usu.Nombre = dto.Nombre;
|
||||
usu.Apellido = dto.Apellido;
|
||||
usu.Celular = dto.Celular;
|
||||
usu.Domicilio = dto.Domicilio;
|
||||
|
||||
GenerarLog(con, responsabledni, "Patch Usuario");
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
|
||||
113
Modelo/RepositorioVentas.cs
Normal file
113
Modelo/RepositorioVentas.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
public class RepositorioVentas: RepositorioBase<RepositorioVentas> {
|
||||
public bool EfectuarVenta(long idventa) {
|
||||
var con = Context;
|
||||
var vent = con.Ventas.Include(x=>x.IdpropiedadNavigation).FirstOrDefault(x => x.Id == idventa);
|
||||
if (vent == null||vent.Idestado != 2) return false;
|
||||
|
||||
vent.IdpropiedadNavigation.Dnipropietario = vent.IdComprador;
|
||||
|
||||
vent.IdpropiedadNavigation.Idestado=3;
|
||||
vent.Idestado=3;
|
||||
vent.Fechafinal = DateTime.Now;
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool IniciarVenta(Venta v, long dni) {
|
||||
var con = Context;
|
||||
v.Id = (con.Ventas.Any()?con.Ventas.Count():0)+1;
|
||||
|
||||
con.Ventas.Add(v);
|
||||
GenerarLog(con, dni, "Alta Venta espera recibo");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public Contrato? ObtenerVentaPorContrato(long idcontrato) {
|
||||
var con = Context;
|
||||
var c = con.Contratos.Include(x=>x.Idcanons).Include(x=>x.IdventaNavigation).ThenInclude(x=>x.IddivisaNavigation)
|
||||
.FirstOrDefault(x=>x.Id == idcontrato);
|
||||
if (c == null || c.IdventaNavigation == null) return null;
|
||||
return c;
|
||||
}
|
||||
|
||||
public Venta? ObtenerVentaPorId(long idventa) {
|
||||
var con = Context;
|
||||
var vent = con.Ventas
|
||||
.Include(x=>x.IddivisaNavigation)
|
||||
.Include(x=>x.IdestadoNavigation)
|
||||
.Include(x=>x.IdVendedorNavigation)
|
||||
.Include(x=>x.IdCompradorNavigation)
|
||||
.Include(x=>x.IdpropiedadNavigation)
|
||||
.Where(x=>x.Idestado != 1)
|
||||
.FirstOrDefault(x=>x.Id == idventa);
|
||||
if (vent == null) return null;
|
||||
return vent;
|
||||
}
|
||||
|
||||
public IQueryable<Venta>? ObtenerVentasPorDni(long dni) {
|
||||
var con = Context;
|
||||
var venta = con.Ventas
|
||||
.Include(x=>x.IddivisaNavigation)
|
||||
.Include(x=>x.IdestadoNavigation)
|
||||
.Include(x=>x.IdVendedorNavigation)
|
||||
.Include(x=>x.IdCompradorNavigation)
|
||||
.Include(x=>x.IdpropiedadNavigation)
|
||||
.Where(x=>(x.IdComprador == dni || x.IdVendedor == dni) && x.Idestado!=1 )
|
||||
.Distinct();
|
||||
return venta;
|
||||
}
|
||||
|
||||
public bool PatchVenta(Venta venta, long dni) {
|
||||
var con = Context;
|
||||
var a = con.Ventas.FirstOrDefault(x=>x.Id == venta.Id);
|
||||
|
||||
a.IdVendedor = venta.IdVendedor;
|
||||
a.IdComprador = venta.IdComprador;
|
||||
a.Idpropiedad = venta.Idpropiedad;
|
||||
a.Fechainicio = venta.Fechainicio;
|
||||
a.Idestado=2;
|
||||
GenerarLog(con, dni, $"Se Ejercio la opcion de venta para la propiedad: {venta.Idpropiedad}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool SetUrlRecibo(long id, string nuevoNombreArchivo, long dni) {
|
||||
var con = Context;
|
||||
var venta = con.Ventas.FirstOrDefault(x=>x.Id == id);
|
||||
if (venta==null) return false;
|
||||
venta.UrlRecibo = nuevoNombreArchivo;
|
||||
GenerarLog(con, dni, $"Se seteo el recibo con nombre: {nuevoNombreArchivo}");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool SetVenta(int idpropiedad, decimal monto, int iddivisa, long dni) {
|
||||
var con = Context;
|
||||
Propiedade? cont = con.Propiedades.Include(x=>x.Contratos).FirstOrDefault(x=>x.Id == idpropiedad);
|
||||
if (cont==null) return false;
|
||||
if (cont.Idestado == 2 || cont.Idestado == 4) return false;
|
||||
if (cont.Contratos.Any(x=>x.Habilitado == 1 && x.Cancelado == 0)) return false;
|
||||
|
||||
cont.Monto = monto;
|
||||
cont.Iddivisa = iddivisa;
|
||||
cont.Idestado = 4;
|
||||
GenerarLog(con, dni, "Se puso la propiedad de venta");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool UnSetVenta(int id, decimal monto, int iddivisa, long dni) {
|
||||
var con = Context;
|
||||
Propiedade? cont = con.Propiedades.Include(x=>x.Venta).Include(x=>x.Contratos).FirstOrDefault(x=>x.Id == id);
|
||||
if (cont==null) return false;
|
||||
if (cont.Idestado != 4) return false;
|
||||
if (cont.Contratos.Any(x=>x.Habilitado == 1 && x.Cancelado == 0)) return false;
|
||||
if (cont.Venta.Any(x=>x.Idestado == 2)) return false;
|
||||
|
||||
cont.Monto = monto;
|
||||
cont.Iddivisa = iddivisa;
|
||||
cont.Idestado = 3;
|
||||
GenerarLog(con, dni, "Se Bajo la propiedad de venta");
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user