más cambios ahora funciona el tema de las facturas pero no el emailer
This commit is contained in:
@@ -12,16 +12,10 @@ namespace Controladora
|
||||
repositorioFacturas = new(new Context());
|
||||
}
|
||||
|
||||
private bool ExistePorId(int id)
|
||||
{
|
||||
var fac = repositorioFacturas.ObtenerPorId(id);
|
||||
return (fac.Id == id);
|
||||
}
|
||||
public string Añadir(Factura t)
|
||||
{
|
||||
if (t == null) return "La Factura es nula, fallo la carga";
|
||||
|
||||
if (ExistePorId(t.Id)) return $"La Factura con el ID {t.Id} ya existe";
|
||||
if (t.Cliente == null || t.Cliente.Cuit == 0) return "Debe seleccionar un cliente antes de agregar la factura";
|
||||
|
||||
string checkstock = "";
|
||||
@@ -41,7 +35,8 @@ namespace Controladora
|
||||
{
|
||||
repositorioFacturas.Add(t);
|
||||
bool resultado = repositorioFacturas.Guardar();
|
||||
string resultadolote = ControladoraLotes.Instance.DisminuirStock(t.MostrarDetalles());
|
||||
t = ObtenerPorId(t);
|
||||
string resultadolote = ControladoraLotes.Instance.DisminuirStock(t);
|
||||
|
||||
// Convierte ReadOnlyCollection a List
|
||||
var detallesList = new List<DetalleFactura>(t.MostrarDetalles());
|
||||
@@ -78,6 +73,11 @@ namespace Controladora
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
public Factura ObtenerPorId(Factura fac)
|
||||
{
|
||||
return repositorioFacturas.ObtenerPorId(fac);
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DetalleFactura> ListarDetallesFactura(Factura factura)
|
||||
{
|
||||
Factura facturaalistar = ControladoraFacturas.Instance.Listar().First(x => x.Id == factura.Id);
|
||||
|
||||
@@ -18,18 +18,17 @@ namespace Controladora
|
||||
repositorioLotes = new(new Context());
|
||||
}
|
||||
|
||||
public string DisminuirStock(ReadOnlyCollection<DetalleFactura> detalleFactura)
|
||||
public string DisminuirStock(Factura factura)
|
||||
{
|
||||
var ret = false;
|
||||
foreach (var detalle in detalleFactura)
|
||||
foreach (var detalle in factura.Detalles)
|
||||
{
|
||||
if (detalle == null) return "El detalle es nulo";
|
||||
if (detalle.Producto.Id < 0) return "Esta mal cargada la Id de producto";
|
||||
var productos = ControladoraProductos.Instance.Listar();
|
||||
if (!productos.Any(x => x.Id == detalle.Producto.Id)) return "No hay Productos con esa id";
|
||||
ret = repositorioLotes.DisminuirStock(detalle);
|
||||
|
||||
}
|
||||
var ret = repositorioLotes.DisminuirStock(factura);
|
||||
repositorioLotes.Guardar();
|
||||
return (ret) ?
|
||||
"Se Descontaron los productos":
|
||||
|
||||
Reference in New Issue
Block a user