falta que se actualize numProducto y los infomes
This commit is contained in:
@@ -10,21 +10,24 @@ namespace Controladora
|
||||
{
|
||||
if (t == null) return "La Factura es nula, fallo la carga";
|
||||
|
||||
if (RepositorioFactura.Instance.ExistePorId(t.Id))
|
||||
{
|
||||
return $"La Factura con el ID {t.Id} ya existe";
|
||||
}
|
||||
if (RepositorioFactura.Instance.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";
|
||||
|
||||
// Verificar si el cliente está seleccionado
|
||||
if (t.Cliente == null || t.Cliente.Cuit == 0)
|
||||
string checkstock = "";
|
||||
foreach (var detalle in t.MostrarDetalles())
|
||||
{
|
||||
return "Debe seleccionar un cliente antes de agregar la factura";
|
||||
if (detalle.Cantidad > ControladoraLotes.Instance.MostrarStockDeProducto(detalle.Producto))
|
||||
{
|
||||
checkstock += $"No hay existencias en stock para realizar la venta de {detalle.Producto.Nombre}\n";
|
||||
}
|
||||
}
|
||||
if (checkstock != "") return checkstock;
|
||||
|
||||
try
|
||||
{
|
||||
bool resultado = RepositorioFactura.Instance.Add(t);
|
||||
return resultado ?
|
||||
string resultadolote = ControladoraLotes.Instance.DisminuirStock(t.MostrarDetalles());
|
||||
return (resultado && (resultadolote == "Se Descontaron los productos")) ?
|
||||
$"La Factura con el ID {t.Id} se cargó correctamente" :
|
||||
$"Falló la carga de la Factura con el ID {t.Id}";
|
||||
}
|
||||
@@ -35,24 +38,6 @@ namespace Controladora
|
||||
}
|
||||
}
|
||||
|
||||
public string Eliminar(Factura t)
|
||||
{
|
||||
if (t == null) return "La Factura es nula, fallo la carga";
|
||||
|
||||
return (RepositorioFactura.Instance.Del(t)) ?
|
||||
$"La Factura con el ID {t.Id} se eliminó correctamente" :
|
||||
$"Falló la eliminación de la Factura con el ID {t.Id}";
|
||||
}
|
||||
|
||||
public string Modificar(Factura t)
|
||||
{
|
||||
if (t == null) return "La Factura es nula, fallo la carga";
|
||||
|
||||
return (RepositorioFactura.Instance.Mod(t)) ?
|
||||
$"La Factura con el ID {t.Id} se modificó correctamente" :
|
||||
$"Falló la modificación de la Factura con el ID {t.Id}";
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Factura> Listar()
|
||||
{
|
||||
return RepositorioFactura.Instance.Listar();
|
||||
@@ -65,6 +50,21 @@ namespace Controladora
|
||||
return facturaalistar.MostrarDetalles();
|
||||
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Producto> ListarProductos()
|
||||
{
|
||||
return RepositorioProductos.Instance.Listar()
|
||||
.Where(x => x.Habilitado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Cliente> ListarClientes()
|
||||
{
|
||||
return RepositorioClientes.Instance.Listar().Where(x => x.Habilitado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
Controladora/ControladoraInformes.cs
Normal file
42
Controladora/ControladoraInformes.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Informes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Controladora
|
||||
{
|
||||
public class ControladoraInformes : Singleton<ControladoraInformes>
|
||||
{
|
||||
const string configpath = "settings.json";
|
||||
|
||||
public void GuardarConfig(ConfigEmail config)
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(configpath, json);
|
||||
|
||||
}
|
||||
catch (IOException ex) { throw; }
|
||||
}
|
||||
|
||||
public ConfigEmail RecuperarConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(configpath))
|
||||
{
|
||||
string json = JsonSerializer.Serialize(new ConfigEmail { EmailAddr = "", EmailPass = "", EmailTarget = new List<String>() }, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(configpath, json);
|
||||
}
|
||||
}
|
||||
catch (IOException ex) { throw; }
|
||||
|
||||
string jsonString = File.ReadAllText(configpath);
|
||||
return JsonSerializer.Deserialize<ConfigEmail>(jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace Controladora
|
||||
{
|
||||
public class ControladoraLotes : Singleton<ControladoraLotes>
|
||||
{
|
||||
/*
|
||||
public string Añadir(Lote t)
|
||||
{
|
||||
if (t == null) return "El Lote es nulo, falló la carga";
|
||||
@@ -64,21 +65,39 @@ namespace Controladora
|
||||
return $"Ocurrió un error inesperado: {ex.Message}";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*public ReadOnlyCollection<Lote> ListarPorFacturaId(int facturaId)
|
||||
public string DisminuirStock(ReadOnlyCollection<DetalleFactura> detalleFactura)
|
||||
{
|
||||
try
|
||||
var ret = false;
|
||||
foreach (var detalle in detalleFactura)
|
||||
{
|
||||
var lotes = RepositorioLote.Instance.Listar();
|
||||
var lotesPorFactura = lotes.Where(lote => lote.Id == facturaId).ToList();
|
||||
return new ReadOnlyCollection<Lote>(lotesPorFactura);
|
||||
if (detalle == null) return "El detalle es nulo";
|
||||
if (detalle.Producto.Id < 0) return "Esta mal cargada la Id de producto";
|
||||
var productos = RepositorioProductos.Instance.Listar();
|
||||
if (productos.Any(x => x.Id != detalle.Producto.Id)) return "No hay Productos con esa id";
|
||||
ret = RepositorioLote.Instance.DisminuirStock(detalle);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Captura cualquier excepción no prevista
|
||||
throw new InvalidOperationException($"Ocurrió un error inesperado: {ex.Message}");
|
||||
}
|
||||
}*/
|
||||
|
||||
return (ret) ?
|
||||
"Se Descontaron los productos":
|
||||
"Se fallo al diminuir el stock";
|
||||
|
||||
}
|
||||
|
||||
public int MostrarStockDeProducto(Producto producto)
|
||||
{
|
||||
if (producto == null) return -1;
|
||||
if (producto.Id < 0) return -1;
|
||||
var lotes = RepositorioLote.Instance.Listar();
|
||||
if (lotes.Any(x => x.Producto.Id != producto.Id)) return -1; // basicamente no hay productos con esa id
|
||||
|
||||
var CantidadStock = lotes
|
||||
.Where(x => x.Producto.Id == producto.Id)
|
||||
.Sum(x=> x.Cantidad);
|
||||
return CantidadStock;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Lote> Listar()
|
||||
{
|
||||
|
||||
@@ -46,6 +46,41 @@ namespace Controladora
|
||||
return ordenalistar.MostrarDetalles();
|
||||
|
||||
}
|
||||
|
||||
public Presupuesto? MostrarPresupuestoPorId(Presupuesto? presupuesto)
|
||||
{
|
||||
if (presupuesto == null) return null;
|
||||
if (presupuesto.Id < 0) return null;
|
||||
var pres = RepositorioPresupuesto.Instance.Listar().First(x => x.Id == presupuesto.Id);
|
||||
return pres;
|
||||
}
|
||||
|
||||
public object ListarProveedores()
|
||||
{
|
||||
return RepositorioProveedor.Instance.Listar()
|
||||
.Where(x => x.Habilitado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DetallePresupuesto> ListarDetallesDePresupuesto(Presupuesto presupuesto)
|
||||
{
|
||||
Presupuesto pres = RepositorioPresupuesto.Instance.Listar().First(x => x.Id == presupuesto.Id);
|
||||
if (pres == null) return new ReadOnlyCollection<DetallePresupuesto>(new List<DetallePresupuesto>());
|
||||
return pres.MostrarDetalles();
|
||||
}
|
||||
|
||||
public object ListarPresupuestosPorProveedorHabilitados(Proveedor proveedor)
|
||||
{
|
||||
if (proveedor == null) return null;
|
||||
if (proveedor.Cuit < 0) return null;
|
||||
var presupuestos = RepositorioPresupuesto.Instance.Listar()
|
||||
.Where(x => x.Proveedor.Cuit == proveedor.Cuit)
|
||||
.Where(x => x.Habilitado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
return presupuestos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,15 +49,6 @@ namespace Controladora
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Presupuesto> ListarAceptado()
|
||||
{
|
||||
return RepositorioPresupuesto.Instance.Listar()
|
||||
.Where(x => x.Habilitado == true)
|
||||
.Where(x => x.Aceptado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DetallePresupuesto> ListarDetalles(Presupuesto presupuesto)
|
||||
{
|
||||
Presupuesto pres = RepositorioPresupuesto.Instance.Listar().First(x=> x.Id == presupuesto.Id);
|
||||
@@ -66,25 +57,26 @@ namespace Controladora
|
||||
|
||||
}
|
||||
|
||||
public Presupuesto? MostrarPresupuestoPorId(Presupuesto presupuesto)
|
||||
public object ListarProductosPorProveedor(Proveedor proveedor)
|
||||
{
|
||||
if (presupuesto == null) return null;
|
||||
if (presupuesto.Id < 0) return null;
|
||||
var pres = RepositorioPresupuesto.Instance.Listar().First(x => x.Id == presupuesto.Id);
|
||||
return pres;
|
||||
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Presupuesto>? ListarPresupuestosPorProveedor(Proveedor proveedor)
|
||||
{
|
||||
if (proveedor == null) return null;
|
||||
if (proveedor.Cuit < 0) return null;
|
||||
var presupuestos = RepositorioPresupuesto.Instance.Listar()
|
||||
.Where(x => x.Proveedor.Cuit == proveedor.Cuit)
|
||||
if (proveedor == null) return new List<Producto>().AsReadOnly();
|
||||
if (proveedor.Cuit < 0) return new List<Producto>().AsReadOnly();
|
||||
var productos = RepositorioProductos.Instance
|
||||
.Listar()
|
||||
.Where(x => x.ListarProveedores()
|
||||
.Any(x => x.Cuit == proveedor.Cuit))
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
return presupuestos;
|
||||
|
||||
return productos;
|
||||
}
|
||||
|
||||
public object ListarProveedores()
|
||||
{
|
||||
return RepositorioProveedor.Instance.Listar()
|
||||
.Where(x => x.Habilitado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,5 +60,18 @@ namespace Controladora
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Proveedor> ListarProveedores()
|
||||
{
|
||||
return RepositorioProveedor.Instance.Listar()
|
||||
.Where(x => x.Habilitado == true)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Categoria> ListarCategorias()
|
||||
{
|
||||
return RepositorioCategoria.Instance.Listar();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,5 +49,6 @@ namespace Controladora
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,15 +11,18 @@ namespace Controladora
|
||||
return RepositorioRemito.Instance.Listar();
|
||||
}
|
||||
|
||||
public string Añadir(Remito t)
|
||||
public string Añadir(Remito t, OrdenDeCompra orden )
|
||||
{
|
||||
if (t == null) return "El Remito es nulo fallo la carga";
|
||||
if (t.Id < 0) return "El id Esta Mal Cargado";
|
||||
|
||||
var retMarcarOrdenEntregada = RepositorioOrdenDeCompra.Instance.MarcarEntregado(orden);
|
||||
if (retMarcarOrdenEntregada == false) return "La orden Esta Mal Cargada";
|
||||
var retRemito = RepositorioRemito.Instance.Add(t);
|
||||
if (retRemito == false) return "El Remito Esta Mal Cargado";
|
||||
var retLotes = RepositorioLote.Instance.Add(t);
|
||||
|
||||
return (!retLotes) ?
|
||||
return (retLotes) ?
|
||||
$"El remito {t.Id} se cargo correctamente":
|
||||
$"Fallo la carga del remito {t.Id}";
|
||||
|
||||
@@ -40,6 +43,42 @@ namespace Controladora
|
||||
$"Fallo la Eliminacion del remito {t.Id}";
|
||||
*/
|
||||
}
|
||||
|
||||
public object ListarLotes()
|
||||
{
|
||||
return RepositorioLote.Instance.Listar().Where(x => x.Habilitado == true)
|
||||
.ToList().AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<OrdenDeCompra> ListarOrdenesSinEntregar()
|
||||
{
|
||||
return RepositorioOrdenDeCompra.Instance.Listar()
|
||||
.Where(x => x.Entregado == false)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
public object ListarDetallesOrdenesDeCompra(OrdenDeCompra orden)
|
||||
{
|
||||
var ordenalistar = RepositorioOrdenDeCompra.Instance.Listar().First(x => x.Id == orden.Id);
|
||||
if (ordenalistar == null) return new ReadOnlyCollection<DetalleOrdenDeCompra>(new List<DetalleOrdenDeCompra>());
|
||||
return ordenalistar.MostrarDetalles();
|
||||
|
||||
}
|
||||
|
||||
public OrdenDeCompra? MostrarOrdenDeCompraPorId(OrdenDeCompra ordenDeCompra)
|
||||
{
|
||||
if (ordenDeCompra == null) return null;
|
||||
if (ordenDeCompra.Id < 0) return null;
|
||||
return RepositorioOrdenDeCompra.Instance.Listar().First(x => x.Id == ordenDeCompra.Id);
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Lote> ListarLotesPorRemito(Remito rem)
|
||||
{
|
||||
var remalistar = RepositorioRemito.Instance.Listar().First(x => x.Id == rem.Id);
|
||||
if (remalistar == null) return new ReadOnlyCollection<Lote>(new List<Lote>());
|
||||
return remalistar.MostrarLotes();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user