20260129 - 01
This commit is contained in:
185
bdGrupoSanchoToro/extensiones/albaranes.cs
Normal file
185
bdGrupoSanchoToro/extensiones/albaranes.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using static bdGrupoSanchoToro.db.almacenes;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
using static tsUtilidades.Extensiones.StringExtensions;
|
||||
using System.Drawing.Imaging;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace bdGrupoSanchoToro.db
|
||||
{
|
||||
|
||||
public partial class albaranes :INotifyPropertyChanged
|
||||
{
|
||||
public municipios? municipios
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.CodigoMunicipioCargaNavigation;
|
||||
}
|
||||
}
|
||||
public municipios? municipios1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.CodigoMunicipioDescargaNavigation;
|
||||
}
|
||||
}
|
||||
public presupuestos? presupuestos
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.idPresupuestoNavigation;
|
||||
}
|
||||
}
|
||||
public entidades? entidades
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.idEntidadNavigation;
|
||||
}
|
||||
}
|
||||
public usuarios usuarios
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.idUsuarioNavigation;
|
||||
}
|
||||
}
|
||||
|
||||
public string Entidad
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.idEntidad.HasValue)
|
||||
{
|
||||
return this.entidades.RazonSocial;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
public string DescripcionTipoAlbaran
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((TipoAlbaranEnum)this.Tipo).ToString().Replace("_", " ");
|
||||
}
|
||||
}
|
||||
public string NumeroAlbaran
|
||||
{
|
||||
get
|
||||
{
|
||||
return albaranes.ObtieneNumeroAlbaran(this.idAlbaran, (PrefijoAlbaranEnum)this.Tipo);
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public static string ObtieneNumeroAlbaran(int idAlbaran, PrefijoAlbaranEnum Tipo)
|
||||
{
|
||||
return Tipo.ToString() + "-" + idAlbaran.ToString().PadLeft(6, '0');
|
||||
}
|
||||
public string Usuario
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.usuarios is null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.usuarios.Nombre;
|
||||
}
|
||||
}
|
||||
}
|
||||
public string PoblacionCarga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Conversions.ToString(municipios.ObtienePoblacion(this.CodigoMunicipioCarga));
|
||||
}
|
||||
}
|
||||
public string PoblacionDescarga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Conversions.ToString(municipios.ObtienePoblacion(this.CodigoMunicipioDescarga));
|
||||
}
|
||||
}
|
||||
|
||||
public string ProvinciaCarga
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.municipios!=null && !string.IsNullOrEmpty(this.CodigoMunicipioCarga.NothingAVacio()))
|
||||
{
|
||||
return this.municipios.provincias.Nombre;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
public string ProvinciaDescarga
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.municipios1 != null && !string.IsNullOrEmpty(this.CodigoMunicipioDescarga.NothingAVacio()))
|
||||
{
|
||||
return this.municipios1.provincias.Nombre;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RefrescaCamposSoloLectura()
|
||||
{
|
||||
this.OnPropertyChanged("PoblacionCarga");
|
||||
this.OnPropertyChanged("PoblacionDescarga");
|
||||
this.OnPropertyChanged("ProvinciaCarga");
|
||||
this.OnPropertyChanged("ProvinciaDescarga");
|
||||
this.OnPropertyChanged("CodigoPostalCarga");
|
||||
this.OnPropertyChanged("CodigoPostalDescarga");
|
||||
}
|
||||
protected void OnPropertyChanged([CallerMemberName] string name = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||
}
|
||||
public enum TipoAlbaranEnum : int
|
||||
{
|
||||
ENTREGA = 0,
|
||||
RECOGIDA = 1,
|
||||
CAMBIO_ALMACEN = 2,
|
||||
SUBALQUILER = 3,
|
||||
DEVOLUCION_SUBALQUILER = 4,
|
||||
STOCK_INICIAL_O_FABRICACION = 100,
|
||||
COMPRA = 101
|
||||
}
|
||||
public enum PrefijoAlbaranEnum : int
|
||||
{
|
||||
AENT = 0,
|
||||
AREC = 1,
|
||||
ACMA = 2,
|
||||
ASBA = 3,
|
||||
ADSA = 4,
|
||||
ASIOF = 100,
|
||||
ACMP = 101
|
||||
}
|
||||
|
||||
public enum TipoImpresionAlbaranEntregaEnum : int
|
||||
{
|
||||
IMPRIMIR_CONTRATO = 0,
|
||||
IMPRIMIR_ALBARAN_NO_VALORADO = 1,
|
||||
IMPRIMIR_ALBARAN_VALORADO = 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
188
bdGrupoSanchoToro/extensiones/detallesalbaranes.cs
Normal file
188
bdGrupoSanchoToro/extensiones/detallesalbaranes.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,8 +46,9 @@ namespace bdGrupoSanchoToro.db
|
||||
GRUA = 0,
|
||||
ELEMENTO_GRUA = 1,
|
||||
REPUESTO =10,
|
||||
OTRO_MATERIAL = 11,
|
||||
MATERIAL_OFICINA = 12,
|
||||
OTROS_PRODUCTOS = 11,
|
||||
CONSUMIBLES =12,
|
||||
MATERIAL_OFICINA = 13,
|
||||
SERVICIO = 99,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user