20260129 - 01

This commit is contained in:
2026-01-29 13:04:08 +01:00
parent a222729a6a
commit e043d4bdee
39 changed files with 7528 additions and 67 deletions

View File

@@ -0,0 +1,188 @@
using System;
using System.Linq;
using static bdGrupoSanchoToro.db.productos;
namespace bdGrupoSanchoToro.db
{
public partial class detallesalbaranes
{
//public albaranes albaranes
//{
// get
// {
// return this.idAlbaranNavigation;
// }
//}
public string NumeroAlbaran
{
get
{
return this.idAlbaranNavigation.NumeroAlbaran;
}
}
public DateOnly FechaAlbaran
{
get
{
return this.idAlbaranNavigation.Fecha;
}
}
public string AlmacenOrigen
{
get
{
if (this.idAlbaranNavigation.idAlmacenOrigen.HasValue)
{
return this.idAlbaranNavigation.idAlmacenOrigenNavigation.Descripcion;
}
else
{
return "";
}
}
}
public string AlmacenDestino
{
get
{
if (idAlbaranNavigation.idAlmacenDestino.HasValue)
{
return idAlbaranNavigation.idAlmacenDestinoNavigation.Descripcion;
}
else
{
return "";
}
}
}
public string Entidad
{
get
{
return this.idAlbaranNavigation.Entidad;
}
}
public void ActualizaProducto(bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext bd, int Factor)
{
try
{
var pr = bd.productos.First(x => x.idProducto == this.idProducto);
if (pr.Tipo != (int)TipoProductoEnum.SERVICIO )
{
var almo = this.idAlbaranNavigation.idAlmacenOrigen.HasValue ? bd.almacenes.First(x => x.idAlmacen== idAlbaranNavigation.idAlmacenOrigen) : (almacenes)null;
var almd = this.idAlbaranNavigation.idAlmacenDestino.HasValue ? bd.almacenes.First(x => x.idAlmacen == this.idAlbaranNavigation.idAlmacenDestino) : (almacenes)null;
switch ((albaranes.TipoAlbaranEnum)this.idAlbaranNavigation.Tipo)
{
case albaranes.TipoAlbaranEnum.COMPRA:
case albaranes.TipoAlbaranEnum.STOCK_INICIAL_O_FABRICACION:
{
this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto);
pr.UnidadesInicialesOFabricadas += this.Cantidad * (double)Factor;
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, true, Factor);
break;
}
case albaranes.TipoAlbaranEnum.CAMBIO_ALMACEN:
{
this.ActStockPorAlmacen(bd, Factor * -1, almo.idAlmacen, pr.idProducto);
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almo.Tipo, false, Factor * -1);
this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto);
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, false, Factor);
break;
}
case albaranes.TipoAlbaranEnum.ENTREGA:
{
this.ActStockPorAlmacen(bd, Factor * -1, almo.idAlmacen, pr.idProducto);
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almo.Tipo, this.EsVenta, Factor * -1);
if (this.EsVenta == false)
{
pr.UnidadesAlquiladas += this.Cantidad * (double)Factor;
}
else
{
pr.UnidadesVendidas += this.Cantidad * (double)Factor;
}
break;
}
case albaranes.TipoAlbaranEnum.RECOGIDA:
{
this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto);
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, false, Factor);
pr.UnidadesAlquiladas += this.Cantidad * (double)Factor * (double)-1;
break;
}
case albaranes.TipoAlbaranEnum.SUBALQUILER:
{
this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto);
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, true, Factor);
pr.UnidadesSubAlquiladas += this.Cantidad * (double)Factor;
break;
}
case albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER:
{
this.ActStockPorAlmacen(bd, Factor * -1, almo.idAlmacen, pr.idProducto);
this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almo.Tipo, true, Factor * -1);
pr.UnidadesSubAlquiladas += this.Cantidad * (double)Factor * (double)-1;
break;
}
}
// bd.SaveChanges()
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
private void ActStockPorAlmacen(bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext bd, int Factor, int idAlmacen, int idProducto)
{
try
{
var st = bd.stocks.FirstOrDefault(x => x.idProducto == idProducto && x.idAlmacen == idAlmacen);
if (st is null)
{
st = new stocks();
st.idProducto = idProducto;
st.idAlmacen = idAlmacen;
st.Unidades = 0d;
bd.stocks.Add(st);
}
st.Unidades += this.Cantidad * (double)Factor;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
private void ActStockGlobal(productos pr, almacenes.TipoAlmacenEnum TipoAlmacen, bool ActTotalUnidades, int Factor)
{
try
{
switch (TipoAlmacen)
{
// Case almacenes.TipoAlmacenEnum.ALMACEN
case almacenes.TipoAlmacenEnum.TALLER_REPARACIONES:
{
pr.UnidadesAveriadas += this.Cantidad * (double)Factor;
break;
}
case almacenes.TipoAlmacenEnum.UNIDADES_DESCARTADAS:
{
pr.UnidadesDesechadas += this.Cantidad * (double)Factor;
break;
}
}
if (ActTotalUnidades)
pr.TotalUnidades += this.Cantidad * (double)Factor;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
}
}