carga de contratos por admin funcional
This commit is contained in:
@@ -5,6 +5,54 @@ using Microsoft.EntityFrameworkCore;
|
||||
namespace Modelo;
|
||||
public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
|
||||
public bool GenerarCanones(long id = 0, long dni=0){
|
||||
if (id == 0) return false;
|
||||
var con = Context;
|
||||
|
||||
var cont = con.Contratos.Include(x=>x.IdpropiedadNavigation).FirstOrDefault(x=>x.Id == id && x.Cancelado == 0 && x.Habilitado == 0);
|
||||
if (cont == null) return false;
|
||||
|
||||
cont.Habilitado = 1;
|
||||
cont.Fechainicio = DateTime.Now;
|
||||
var fecha = cont.Fechainicio;
|
||||
cont.IdpropiedadNavigation.Monto = cont.Monto;
|
||||
if (cont.MesesDurationContrato < cont.MesesHastaAumento)
|
||||
{
|
||||
for (int i = 0; i < cont.MesesDurationContrato; i++)
|
||||
{
|
||||
Canon can = new Canon
|
||||
{
|
||||
Fecha = fecha.AddMonths(i),
|
||||
Monto = cont.IdpropiedadNavigation.Monto,
|
||||
Pagado = 0,
|
||||
};
|
||||
can.Id = (con.Canons.Any() ? con.Canons.Count() : 0) + 1 + i;
|
||||
|
||||
|
||||
con.Canons.Add(can);
|
||||
cont.Idcanons.Add(can);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < cont.MesesHastaAumento; i++)
|
||||
{
|
||||
Canon can = new Canon
|
||||
{
|
||||
Fecha = fecha.AddMonths(i),
|
||||
Monto = cont.IdpropiedadNavigation.Monto,
|
||||
Pagado = 0,
|
||||
};
|
||||
can.Id = (con.Canons.Any() ? con.Canons.Count() : 0) + 1 + i;
|
||||
|
||||
|
||||
con.Canons.Add(can);
|
||||
cont.Idcanons.Add(can);
|
||||
}
|
||||
}
|
||||
// GenerarLog(con, dni, "Creacion de Canones");
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool AdminCargaContrato(Contrato? cont, long dni){
|
||||
if (cont == null) return false;
|
||||
@@ -13,6 +61,10 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
|
||||
cont.Id = (con.Contratos.Any() ? con.Contratos.Max(x => x.Id) : 0) + 1;
|
||||
|
||||
foreach(Garante g in cont.Idgarantes){
|
||||
g.Id = (con.Garantes.Any()?con.Garantes.Max(x=>x.Id): 0) + 1;
|
||||
}
|
||||
|
||||
if (cont.IdventaNavigation != null){
|
||||
cont.IdventaNavigation.Id = (con.Ventas.Any()?con.Ventas.Count():0)+1;
|
||||
con.Ventas.Add(cont.IdventaNavigation);
|
||||
@@ -125,13 +177,15 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
return contr;
|
||||
}
|
||||
|
||||
public bool AddUrl(long id, string nuevoNombreArchivo, long dni) {
|
||||
public bool AddUrl(long id, string nuevoNombreArchivo, long dni =0) {
|
||||
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");
|
||||
if (dni != 0 ){
|
||||
GenerarLog(con, dni, $"Añadido contrato");
|
||||
}
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user