falta interfaz venta
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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(precontrato, notificacion);
|
||||
} else {
|
||||
Venta v = new Venta{
|
||||
Idestado = 1,
|
||||
Iddivisa = dto.iddivisa,
|
||||
Monto = dto.MontoOpcion,
|
||||
};
|
||||
ret = RepositorioContratos.Singleton.CargaPrecontratoOpcionVenta(precontrato, notificacion, v);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, DateTime.Parse(dto.fechaprimernotificacion));
|
||||
}
|
||||
@@ -816,6 +828,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,42 @@
|
||||
using AlquilaFacil.Builder;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class VentaController:ControllerBase {
|
||||
[HttpPost("/api/ventas/ejercerOpcionVenta")]
|
||||
public IActionResult EjercerOpcionVenta(long idcontrato) {
|
||||
|
||||
[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);
|
||||
|
||||
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 IActionResult SubirRecibo([FromForm]IFormFile file, long idventa ) {
|
||||
@@ -27,8 +57,71 @@ public class VentaController:ControllerBase {
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("/api/contrato/tieneopcionventa")]
|
||||
public IActionResult TieneOpcionVenta(long idcontrato) {
|
||||
*/
|
||||
[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});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user