From 28e20494aeb86b74a1427b22154e22bb5d5f2719 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 17 Feb 2026 13:47:52 +0100 Subject: [PATCH] cambios 17/02/2026 --- .../Almacen/dxwRecogidaProductos.xaml | 58 + .../Almacen/dxwRecogidaProductos.xaml.vb | 85 ++ .../Almacen/dxwTipoAlbaran.xaml | 47 + .../Almacen/dxwTipoAlbaran.xaml.vb | 59 + .../Almacen/ucAlbaran.xaml.vb | 24 +- .../{ucAlbaranE.xaml => ucAlbaranR.xaml} | 85 +- ...{ucAlbaranE.xaml.vb => ucAlbaranR.xaml.vb} | 303 +++-- .../Almacen/ucAlbaranes.xaml | 8 +- .../Almacen/ucAlbaranes.xaml.vb | 24 +- .../FicherosMaestros/ucProducto.xaml | 455 +++++-- .../FicherosMaestros/ucProducto.xaml.vb | 210 ++-- .../FicherosMaestros/ucProductos.xaml.vb | 35 +- .../Ventas/ucFacturasEmitidas.xaml.vb | 2 +- GestionGrupoSanchoToro/dxwInicio.xaml.vb | 2 +- GestionGrupoSanchoToro/ucEntidad.xaml | 4 +- GestionGrupoSanchoToro/ucEntidad.xaml.bak | 12 +- GestionGrupoSanchoToro/ucEntidad.xaml.vb | 6 +- .../Importaciones/ImportaARTICULOS.cs | 80 ++ .../Importaciones/ImportaCTESGESL.cs | 8 +- .../Importaciones/ImportaGRUASGC.cs | 20 +- .../Importaciones/ImportaGRUASPC.cs | 67 ++ .../Importaciones/ImportaPRODUCTOS.cs | 25 +- .../Importaciones/ImportarTodo.cs | 4 +- bdGrupoSanchoToro/db/albaranes.cs | 4 + bdGrupoSanchoToro/db/desgloseproductos.cs | 31 + bdGrupoSanchoToro/db/detallepresupuesto.cs | 16 + bdGrupoSanchoToro/db/detallesalbaranes.cs | 14 +- bdGrupoSanchoToro/db/empresas.cs | 4 +- bdGrupoSanchoToro/db/entidades.cs | 4 +- bdGrupoSanchoToro/db/facturas.cs | 4 +- bdGrupoSanchoToro/db/modelospermitidos.cs | 29 + bdGrupoSanchoToro/db/municipios.cs | 4 +- bdGrupoSanchoToro/db/{eventos.cs => obras.cs} | 4 +- bdGrupoSanchoToro/db/presupuestos.cs | 12 +- bdGrupoSanchoToro/db/productos.cs | 24 +- bdGrupoSanchoToro/db/usuarios.cs | 6 +- bdGrupoSanchoToro/db/v_albaranesextendidos.cs | 20 +- .../dbcontext/GrupoSanchoToroContext.cs | 268 +++-- bdGrupoSanchoToro/dbcontext/conexion.cs | 2 +- .../dbcontext/tscGrupoSanchoToro.cs | 4 +- bdGrupoSanchoToro/efpt.config.json | 16 +- .../extensiones/DesglosePorEmpresa.cs | 46 + .../extensiones/desgloseproductos.cs | 70 ++ .../extensiones/detallepresupuesto.cs | 99 ++ .../extensiones/detallesalbaranes.cs | 97 +- bdGrupoSanchoToro/extensiones/empresas.cs | 23 + bdGrupoSanchoToro/extensiones/facturas.cs | 20 +- .../extensiones/{eventos.cs => obras.cs} | 2 +- bdGrupoSanchoToro/extensiones/presupuestos.cs | 1070 +++++++++++++++++ bdGrupoSanchoToro/extensiones/productos.cs | 335 +++++- .../extensiones/v_albaranesextendidos.cs | 39 + 51 files changed, 3199 insertions(+), 691 deletions(-) create mode 100644 GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml create mode 100644 GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml.vb create mode 100644 GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml create mode 100644 GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml.vb rename GestionGrupoSanchoToro/Almacen/{ucAlbaranE.xaml => ucAlbaranR.xaml} (80%) rename GestionGrupoSanchoToro/Almacen/{ucAlbaranE.xaml.vb => ucAlbaranR.xaml.vb} (78%) create mode 100644 bdGrupoSanchoToro/Importaciones/ImportaARTICULOS.cs create mode 100644 bdGrupoSanchoToro/Importaciones/ImportaGRUASPC.cs create mode 100644 bdGrupoSanchoToro/db/desgloseproductos.cs create mode 100644 bdGrupoSanchoToro/db/modelospermitidos.cs rename bdGrupoSanchoToro/db/{eventos.cs => obras.cs} (94%) create mode 100644 bdGrupoSanchoToro/extensiones/DesglosePorEmpresa.cs create mode 100644 bdGrupoSanchoToro/extensiones/desgloseproductos.cs create mode 100644 bdGrupoSanchoToro/extensiones/detallepresupuesto.cs create mode 100644 bdGrupoSanchoToro/extensiones/empresas.cs rename bdGrupoSanchoToro/extensiones/{eventos.cs => obras.cs} (96%) create mode 100644 bdGrupoSanchoToro/extensiones/presupuestos.cs create mode 100644 bdGrupoSanchoToro/extensiones/v_albaranesextendidos.cs diff --git a/GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml b/GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml new file mode 100644 index 0000000..a107001 --- /dev/null +++ b/GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml.vb b/GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml.vb new file mode 100644 index 0000000..c8e493c --- /dev/null +++ b/GestionGrupoSanchoToro/Almacen/dxwRecogidaProductos.xaml.vb @@ -0,0 +1,85 @@ +Imports bdGrupoSanchoToro +Imports bdGrupoSanchoToro.db +Imports DevExpress.Xpf.Core + + +Public Class dxwRecogidaProductos + Private _LDetalleActual As Integer() + Public LSeleccionados As List(Of detallesalbaranes) + Private _idEntidad As Integer + Private _bd As tscGrupoSanchoToro + + Private Sub btAceptar_Click(sender As Object, e As RoutedEventArgs) + LSeleccionados = gc.ElementosSeleccionados.Cast(Of detallesalbaranes).ToList + Me.DialogResult = True + Me.Close() + End Sub + + Private Sub btCancelar_Click(sender As Object, e As RoutedEventArgs) + Me.DialogResult = False + Me.Close() + End Sub + + Private Sub dxwRecogidaProductos_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded + Try + Dim ld = _bd.detallesalbaranes.Include(Function(x) x.idAlbaranNavigation).Include(Function(x) x.idAlbaranRecogidaNavigation).Include(Function(x) x.idProductoNavigation) _ + .Where(Function(x) x.idAlbaranNavigation.idEntidad.HasValue AndAlso x.idAlbaranNavigation.idEntidad.Value = _idEntidad AndAlso x.FechaCancelacion.HasValue = False AndAlso x.EsVenta = False AndAlso (x.idAlbaranRecogida.HasValue = False OrElse _LDetalleActual.Contains(x.idDetalle))).ToList() + Me.gc.ItemsSource = ld + + 'For i = 0 To ld.Count + Dim i As Integer + For Each d In ld + If _LDetalleActual.Any(Function(x) x = d.idDetalle) Then + Dim rowHandle As Integer = gc.GetRowHandleByListIndex(i) + gc.SelectItem(rowHandle) + End If + i += 1 + Next + + + Me.gc.View.SearchControl.Focus() + Catch ex As Exception + DXMessageBox.Show(ex.Message, "Error") + Finally + If DXSplashScreen.IsActive Then DXSplashScreen.Close() + End Try + End Sub + + 'Public Sub New(bd As m3alquileresEntities, Existentes As List(Of Integer?)) + Public Sub New(bd As tscGrupoSanchoToro, ListaDetalleActuales As Integer(), idCliente As Integer) + + ' Llamada necesaria para el diseñador. + InitializeComponent() + Comun.EscalaVentana(Me, Me.grid.LayoutTransform) + + 'Me.Height = Math.Min(Comun.dwi.Height, Me.Height * UsuarioActual.Escala.Value) + 'Me.Width = Math.Min(Comun.dwi.Width, Me.Width * UsuarioActual.Escala.Value) + 'Dim scaler = TryCast(Me.grid.LayoutTransform, ScaleTransform) + 'If scaler Is Nothing Then + ' scaler = New ScaleTransform(1.0, 1.0) + ' Me.grid.LayoutTransform = scaler + 'End If + 'scaler.ScaleX = UsuarioActual.Escala.Value + 'scaler.ScaleY = UsuarioActual.Escala.Value + 'scaler.BeginAnimation(ScaleTransform.ScaleXProperty, Nothing) + 'scaler.BeginAnimation(ScaleTransform.ScaleYProperty, Nothing) + + _LDetalleActual = ListaDetalleActuales + _idEntidad = idCliente + _bd = bd + + ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). + + End Sub + + + Private Sub dxw_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles Me.PreviewKeyDown + If e.Key = Key.Enter Then + btAceptar_Click(Nothing, Nothing) + End If + End Sub + + Private Sub tv_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles tv.MouseDoubleClick + btAceptar_Click(Nothing, Nothing) + End Sub +End Class diff --git a/GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml b/GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml new file mode 100644 index 0000000..89078c0 --- /dev/null +++ b/GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml.vb b/GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml.vb new file mode 100644 index 0000000..cc7e439 --- /dev/null +++ b/GestionGrupoSanchoToro/Almacen/dxwTipoAlbaran.xaml.vb @@ -0,0 +1,59 @@ +Imports System.Data.Entity +Imports bdGrupoSanchoToro.db +Imports DevExpress.Xpf.Core +Imports bdGrupoSanchoToro.db.Utilidades +Imports bdGrupoSanchoToro + +Public Class dxwTipoAlbaran + Friend Tipo As albaranes.TipoAlbaranEnum + + + Private Sub btAceptar_Click(sender As Object, e As RoutedEventArgs) + If gc.CurrentItem IsNot Nothing Then + Tipo = DirectCast(gc.CurrentItem, albaranes.TipoAlbaranEnum) + Me.DialogResult = True + Me.Close() + End If + End Sub + + Private Sub btCancelar_Click(sender As Object, e As RoutedEventArgs) + Me.DialogResult = False + Me.Close() + End Sub + + Private Sub dxwproductos_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded + Try + gc.ItemsSource = tsUtilidades.DescripcionValor.EnumADescripcionValor(GetType(bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum)) + Me.gc.View.Focus() + Catch ex As Exception + DXMessageBox.Show(ex.Message, "Error") + Finally + If DXSplashScreen.IsActive Then DXSplashScreen.Close() + End Try + End Sub + + 'Public Sub New(bd As m3academiaEntities, Existentes As List(Of Integer?)) + Public Sub New() + + + ' Llamada necesaria para el diseñador. + InitializeComponent() + Comun.EscalaVentana(Me, Me.grid.LayoutTransform) + + + + ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). + + End Sub + + + Private Sub dxw_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles Me.PreviewKeyDown + If e.Key = Key.Enter Then + btAceptar_Click(Nothing, Nothing) + End If + End Sub + + Private Sub tv_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles tv.MouseDoubleClick + btAceptar_Click(Nothing, Nothing) + End Sub +End Class diff --git a/GestionGrupoSanchoToro/Almacen/ucAlbaran.xaml.vb b/GestionGrupoSanchoToro/Almacen/ucAlbaran.xaml.vb index 11be7b5..02deced 100644 --- a/GestionGrupoSanchoToro/Almacen/ucAlbaran.xaml.vb +++ b/GestionGrupoSanchoToro/Almacen/ucAlbaran.xaml.vb @@ -120,6 +120,8 @@ Public Class ucAlbaran _idAlbaran = Nothing ra.Fecha = DateOnly.FromDateTime(Today) ra.NumeroBultos = 1 + ra.idEmpresa = EmpresaActual.idEmpresa + ra.Tipo = _Tipo NuevoEstado = tsUtilidades.EstadosAplicacion.Nuevo Else ra = bd.albaranes.First(Function(x) x.idAlbaran = _idAlbaran) @@ -182,8 +184,8 @@ Public Class ucAlbaran ' Return "idAlbaranEntrega" ' End Get 'End Property - - Public Sub New(Optional idAlbaran As Integer? = Nothing) + Private _Tipo As TipoAlbaranEnum + Public Sub New(Tipo As albaranes.TipoAlbaranEnum, Optional idAlbaran As Integer? = Nothing) ' Llamada necesaria para el diseñador. InitializeComponent() @@ -584,7 +586,7 @@ Public Class ucAlbaran ' bCancelar = Me.Guardar(Nothing, Nothing,, True, 5) ' End If ' If Not bCancelar Then - ' Dim dxnc = New dxwEnvioCorreo(ra.entidades.Email, ra.entidades.Email2, "", "Producciones Romian, S.L. - Adjunto le remitimos albarán de entrega nº " & ra.NumeroAlbaran, "Distinguidos Sres., " & vbCrLf & "Adjunto le remitimos albarán entrega nº " & ra.NumeroAlbaran, "AlbaranEntrega_" & ra.NumeroAlbaran.Replace("/", "-") & ".pdf") + ' Dim dxnc = New dxwEnvioCorreo(ra.entidades.Email, ra.entidades.Email2, "", "Producciones SanchoToro, S.L. - Adjunto le remitimos albarán de entrega nº " & ra.NumeroAlbaran, "Distinguidos Sres., " & vbCrLf & "Adjunto le remitimos albarán entrega nº " & ra.NumeroAlbaran, "AlbaranEntrega_" & ra.NumeroAlbaran.Replace("/", "-") & ".pdf") ' If dxnc.ShowDialog Then ' Dim cta = bd.cuentascorreo.First(Function(x) x.Codigo = "DEFECTO") ' Dim bAlbaran = GeneraPdfAlbaran(bd, ra) @@ -742,22 +744,26 @@ Public Class ucAlbaran Else ra.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario Dim bdtmp = tscGrupoSanchoToro.NuevoContexto - Select Case Estado Case tsUtilidades.EstadosAplicacion.Nuevo For Each d In ra.detallesalbaranesidAlbaranNavigation d.idAlbaranNavigation = ra - d.ActualizaProducto(bdtmp, 1) + d.ActualizaProducto(bdtmp, ra.Tipo, 1, ra.idEmpresa) Next Case tsUtilidades.EstadosAplicacion.ModificandoRegistro Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaran = ra.idAlbaran).ToList For Each d In das - d.ActualizaProducto(bdtmp, -1) + If d.idAlbaranNavigation Is Nothing Then d.idAlbaranNavigation = ra + d.ActualizaProducto(bdtmp, d.idAlbaranNavigation.Tipo, -1, d.idAlbaranNavigation.idEmpresa) + If d.idAlbaranRecogida.HasValue Then d.ActualizaProducto(bdtmp, d.idAlbaranRecogidaNavigation.Tipo, -1, ra.idEmpresa) Next For Each d In ra.detallesalbaranesidAlbaranNavigation - d.ActualizaProducto(bdtmp, 1) + If d.idAlbaranNavigation Is Nothing Then d.idAlbaranNavigation = ra + d.ActualizaProducto(bdtmp, d.idAlbaranNavigation.Tipo, 1, d.idAlbaranNavigation.idEmpresa) + If d.idAlbaranRecogida.HasValue Then d.ActualizaProducto(bdtmp, d.idAlbaranRecogidaNavigation.Tipo, 1, d.idAlbaranRecogidaNavigation.idEmpresa) Next End Select + bdtmp.GuardarCambios() End If End Sub @@ -765,8 +771,10 @@ Public Class ucAlbaran Dim bdtmp = tscGrupoSanchoToro.NuevoContexto Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaran = ra.idAlbaran).ToList For Each d In das - d.ActualizaProducto(bdtmp, -1) + d.ActualizaProducto(bdtmp, d.idAlbaranNavigation.Tipo, -1, d.idAlbaranNavigation.idEmpresa) + If d.idAlbaranRecogida.HasValue Then d.ActualizaProducto(bdtmp, d.idAlbaranRecogidaNavigation.Tipo, -1, d.idAlbaranRecogidaNavigation.idEmpresa) Next + bdtmp.SaveChanges() End Sub Private Sub btIrAContrato_Click(sender As Object, e As RoutedEventArgs) diff --git a/GestionGrupoSanchoToro/Almacen/ucAlbaranE.xaml b/GestionGrupoSanchoToro/Almacen/ucAlbaranR.xaml similarity index 80% rename from GestionGrupoSanchoToro/Almacen/ucAlbaranE.xaml rename to GestionGrupoSanchoToro/Almacen/ucAlbaranR.xaml index 352b9cf..8520bcb 100644 --- a/GestionGrupoSanchoToro/Almacen/ucAlbaranE.xaml +++ b/GestionGrupoSanchoToro/Almacen/ucAlbaranR.xaml @@ -7,7 +7,7 @@ xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" - xmlns:tsWPF="clr-namespace:tsWPFCore;assembly=tsWPFCore" xmlns:Serialization="clr-namespace:DevExpress.Xpf.LayoutControl.Serialization;assembly=DevExpress.Xpf.LayoutControl.v23.2" x:Class="ucAlbaranE" + xmlns:tsWPF="clr-namespace:tsWPFCore;assembly=tsWPFCore" xmlns:Serialization="clr-namespace:DevExpress.Xpf.LayoutControl.Serialization;assembly=DevExpress.Xpf.LayoutControl.v23.2" x:Class="ucAlbaranR" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="1366"> @@ -30,8 +30,8 @@ - - + + @@ -55,12 +55,12 @@ - + - + @@ -96,6 +96,12 @@ + + + + + + @@ -305,78 +311,27 @@ - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - - - - - - - - + + + diff --git a/GestionGrupoSanchoToro/Almacen/ucAlbaranE.xaml.vb b/GestionGrupoSanchoToro/Almacen/ucAlbaranR.xaml.vb similarity index 78% rename from GestionGrupoSanchoToro/Almacen/ucAlbaranE.xaml.vb rename to GestionGrupoSanchoToro/Almacen/ucAlbaranR.xaml.vb index 9e00174..4d06de3 100644 --- a/GestionGrupoSanchoToro/Almacen/ucAlbaranE.xaml.vb +++ b/GestionGrupoSanchoToro/Almacen/ucAlbaranR.xaml.vb @@ -19,11 +19,11 @@ Imports bdGrupoSanchoToro.db.Utilidades Imports System.Drawing Imports bdGrupoSanchoToro.db.albaranes -Public Class ucAlbaranE +Public Class ucAlbaranR Private bd As tscGrupoSanchoToro Friend _idAlbaran As Nullable(Of Integer) - Private lProductos As List(Of productos) - Private lArticulos As List(Of articulos) + 'Private lProductos As List(Of productos) + 'Private lArticulos As List(Of articulos) Friend idLog As Integer? @@ -35,10 +35,10 @@ Public Class ucAlbaranE Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False) Try - lProductos = bd.productos.OrderBy(Function(x) x.Descripcion).ToList - Dim lProductosAlb = ra.detallesalbaranesidAlbaranNavigation.Select(Function(x) x.idProducto).ToArray - lProductos = lProductos.Where(Function(x) x.FechaBaja Is Nothing OrElse lProductosAlb.Contains(x.idProducto)).ToList - cbProducto.ItemsSource = lProductos + 'lProductos = bd.productos.OrderBy(Function(x) x.Descripcion).ToList + 'Dim lProductosAlb = ra.detallesalbaranesidAlbaranNavigation.Select(Function(x) x.idProducto).ToArray + 'lProductos = lProductos.Where(Function(x) x.FechaBaja Is Nothing OrElse lProductosAlb.Contains(x.idProducto)).ToList + 'cbProducto.ItemsSource = lProductos cbRazonSocial.ItemsSource = bd.entidades.Where(Function(X) X.FechaBaja.HasValue = False OrElse X.idEntidad = ra.idEntidad).ToList.Select(Function(x) New With {x.idEntidad, x.RazonSocial}).OrderBy(Function(x) x.RazonSocial).ToList @@ -51,13 +51,8 @@ Public Class ucAlbaranE Dim Acciones As New List(Of tsWPFCore.Accion) Acciones.Add(New Accion With { .idAccion = 1, - .Descripcion = "GENERA ALBARÁN DE RECOGIDA Y FACTURA RÁPIDA (F10)"}) - Acciones.Add(New Accion With { - .idAccion = 3, - .Descripcion = "GENERA ALBARÁN DE RECOGIDA DE PRODUCTOS PENDIENTES (F11)"}) - Acciones.Add(New Accion With { - .idAccion = 2, - .Descripcion = "ENVIAR ALBARÁN POR CORREO ELECTRÓNICO (F12)"}) + .Descripcion = "AGREGA PRODUCTOS AL ALBARAN F9"}) + Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion @@ -118,6 +113,8 @@ Public Class ucAlbaranE _idAlbaran = Nothing ra.Fecha = DateOnly.FromDateTime(Today) ra.NumeroBultos = 1 + ra.idEmpresa = EmpresaActual.idEmpresa + ra.Tipo = _Tipo NuevoEstado = tsUtilidades.EstadosAplicacion.Nuevo Else ra = bd.albaranes.First(Function(x) x.idAlbaran = _idAlbaran) @@ -127,9 +124,10 @@ Public Class ucAlbaranE If Me.cbTipo.ItemsSource Is Nothing Then cbTipo.ItemsSource = tsUtilidades.DescripcionValor.EnumADescripcionValor(GetType(bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum)) cbAlmacenOrigen.ItemsSource = Comun.ObtieneListaAlmacenes(bd) + cbAlmacenDestino.ItemsSource = Comun.ObtieneListaAlmacenes(bd) End If 'Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idAlbaran AndAlso x.Aplicacion = "albaranes").ToList - gcProductos.ItemsSource = ra.detallesalbaranesidAlbaranNavigation + gcProductos.ItemsSource = ra.detallesalbaranesidAlbaranRecogidaNavigation Me.DataContext = ra Return NuevoEstado Catch ex As Exception @@ -179,11 +177,12 @@ Public Class ucAlbaranE ' Return "idAlbaranEntrega" ' End Get 'End Property - - Public Sub New(Optional idAlbaran As Integer? = Nothing) + Private _Tipo As albaranes.TipoAlbaranEnum + Public Sub New(Tipo As albaranes.TipoAlbaranEnum, Optional idAlbaran As Integer? = Nothing) ' Llamada necesaria para el diseñador. InitializeComponent() + _idAlbaran = idAlbaran ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). @@ -365,38 +364,19 @@ Public Class ucAlbaranE Private Sub ap_EstadoCambiado(EstadoAnterior As tsUtilidades.EstadosAplicacion, EstadoNuevo As tsUtilidades.EstadosAplicacion) Handles Me.EstadoCambiado If idLog.HasValue Then EstableceSoloLectura() - Select Case EstadoNuevo - Case tsUtilidades.EstadosAplicacion.ModificandoRegistro - If ra.Tipo = TipoAlbaranEnum.COMPRA Then - gcEsVenta.ReadOnly = True - Else - gcEsVenta.ReadOnly = False - End If - End Select + 'Select Case EstadoNuevo + ' Case tsUtilidades.EstadosAplicacion.ModificandoRegistro + ' If ra.Tipo = TipoAlbaranEnum.COMPRA Then + ' gcEsVenta.ReadOnly = True + ' Else + ' gcEsVenta.ReadOnly = False + ' End If + 'End Select End Sub - Private Sub BiBuscarProducto_Click(sender As Object, e As RoutedEventArgs) - If tvProductos.ActiveEditor Is Nothing Then - Dispatcher.BeginInvoke(New Action(Sub() tvProductos.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render) - End If - Dim dxw As New dxwProductos(lProductos) - If dxw.ShowDialog Then - Dim dea As detallesalbaranes = gcProductos.CurrentItem - Dim prod = lProductos.First(Function(x) x.idProducto = dxw.idProducto) - If tvProductos.ActiveEditor IsNot Nothing Then - tvProductos.ActiveEditor.EditValue = prod.idProducto - Else - Debug.Write("no") - End If - tvProductos.PostEditor() - tvProductos.CloseEditor() - gcProductos.RefreshRow(tvProductos.FocusedRowHandle) - End If - End Sub - Private Sub BiBuscarCliente_Click(sender As Object, e As RoutedEventArgs) 'If Me.Estado = EstadosAplicacion.Nuevo Then Dim dxw As New dxwEntidades(bd, True, False) @@ -410,16 +390,6 @@ Public Class ucAlbaranE - Private Sub RellenaDatosProducto(dea As detallesalbaranes) - If dea IsNot Nothing AndAlso dea.idProducto <> 0 Then - Dim ae As albaranes = Me.DataContext - Dim pr = lProductos.First(Function(x) x.idProducto = dea.idProducto) - If dea.Cantidad = 0 Then dea.Cantidad = 1 - dea.EsVenta = False - End If - End Sub - - @@ -537,6 +507,34 @@ Public Class ucAlbaranE End Sub Private Sub ucAlbaranEntrega_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion + + + Select Case idAccion + Case 1 'AGREGA PRODUCTOS AL ALBARAN F9 + Dim ldet = ra.detallesalbaranesidAlbaranRecogidaNavigation + Dim ld = ldet.Select(Function(x) x.idDetalle).ToArray + If ra.idEntidad.HasValue Then + Dim dxw As New dxwRecogidaProductos(bd, ld, ra.idEntidad) + If dxw.ShowDialog Then + For Each d In dxw.LSeleccionados + If Not ldet.Any(Function(x) x.idDetalle = d.idDetalle) Then + ldet.Add(d) + End If + Next + Dim ldq = ldet.Except(dxw.LSeleccionados).ToList + For Each d In ldq + ldet.Remove(ldet.First(Function(x) x.idDetalle = d.idDetalle)) + Next + 'Me.gcProductos.ItemsSource = ldet.OrderBy(Function(x) x.idDetalleAlbaran).ToList + ' Me.gcProductos.ItemsSource = ldet.OrderBy(Function(x) x.idProductoNavigation.Descripcion).ThenBy(Function(x) x.idDetalle).ToList + 'ra.detallealbaranentrega.OrderBy(Function(x) x.productos.Descripcion).ThenBy(Function(x) x.idDetalleAlbaran).ToList + gcProductos.RefreshData() + End If + Else + DXMessageBox.Show("Antes seleccione el cliente", "Atención") + End If + End Select + 'Select Case idAccion ' Case 1 ' GENERA ALBARÁN DE RECOGIDA Y FACTURA RAPIDA ' Try @@ -573,7 +571,7 @@ Public Class ucAlbaranE ' bCancelar = Me.Guardar(Nothing, Nothing,, True, 5) ' End If ' If Not bCancelar Then - ' Dim dxnc = New dxwEnvioCorreo(ra.entidades.Email, ra.entidades.Email2, "", "Producciones Romian, S.L. - Adjunto le remitimos albarán de entrega nº " & ra.NumeroAlbaran, "Distinguidos Sres., " & vbCrLf & "Adjunto le remitimos albarán entrega nº " & ra.NumeroAlbaran, "AlbaranEntrega_" & ra.NumeroAlbaran.Replace("/", "-") & ".pdf") + ' Dim dxnc = New dxwEnvioCorreo(ra.entidades.Email, ra.entidades.Email2, "", "Producciones SanchoToro, S.L. - Adjunto le remitimos albarán de entrega nº " & ra.NumeroAlbaran, "Distinguidos Sres., " & vbCrLf & "Adjunto le remitimos albarán entrega nº " & ra.NumeroAlbaran, "AlbaranEntrega_" & ra.NumeroAlbaran.Replace("/", "-") & ".pdf") ' If dxnc.ShowDialog Then ' Dim cta = bd.cuentascorreo.First(Function(x) x.Codigo = "DEFECTO") ' Dim bAlbaran = GeneraPdfAlbaran(bd, ra) @@ -633,42 +631,49 @@ Public Class ucAlbaranE - Private Sub ucAlbaranEntrega_CampoActualizado(sender As Object, e As DataTransferEventArgs) Handles Me.CampoActualizado - Dim pts As PropiedadesTS = sender.parent.propiedadests - If Not pts Is Nothing Then + 'Private Sub ucAlbaranEntrega_CampoActualizado(sender As Object, e As DataTransferEventArgs) Handles Me.CampoActualizado + ' Dim pts As PropiedadesTS = sender.parent.propiedadests + ' If Not pts Is Nothing Then - Select Case pts.NombreCampo.ToLower - Case "tipo" - gcEsVenta.ReadOnly = False - Select Case DirectCast(ra.Tipo, bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum) - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.COMPRA - For Each d In ra.detallesalbaranesidAlbaranNavigation.Where(Function(x) x.EsVenta) - d.EsVenta = False - Next - gcEsVenta.ReadOnly = True - ra.idAlmacenOrigen = Nothing - EstableceSoloLectura(cbAlmacenOrigen, True) - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.CAMBIO_ALMACEN - EstableceSoloLectura(cbAlmacenOrigen, False) - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.SUBALQUILER - ra.idAlmacenOrigen = Nothing - EstableceSoloLectura(cbAlmacenOrigen, True) - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER - EstableceSoloLectura(cbAlmacenOrigen, False) - ra.idAlmacenDestino = Nothing - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.ENTREGA - EstableceSoloLectura(cbAlmacenOrigen, False) - ra.idAlmacenDestino = Nothing - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.RECOGIDA - ra.idAlmacenOrigen = Nothing - EstableceSoloLectura(cbAlmacenOrigen, True) - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.REGULARIZACION_STOCK - ra.idAlmacenOrigen = Nothing - EstableceSoloLectura(cbAlmacenOrigen, True) - End Select - End Select - End If - End Sub + ' Select Case pts.NombreCampo.ToLower + ' Case "tipo" + ' gcEsVenta.ReadOnly = False + ' Select Case DirectCast(ra.Tipo, bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.COMPRA + ' For Each d In ra.detallesalbaranesidAlbaranNavigation.Where(Function(x) x.EsVenta) + ' d.EsVenta = False + ' Next + ' gcEsVenta.ReadOnly = True + ' ra.idAlmacenOrigen = Nothing + ' EstableceSoloLectura(cbAlmacenOrigen, True) + ' EstableceSoloLectura(cbAlmacenDestino, False) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.CAMBIO_ALMACEN + ' EstableceSoloLectura(cbAlmacenOrigen, False) + ' EstableceSoloLectura(cbAlmacenDestino, False) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.SUBALQUILER + ' ra.idAlmacenOrigen = Nothing + ' EstableceSoloLectura(cbAlmacenOrigen, True) + ' EstableceSoloLectura(cbAlmacenDestino, False) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER + ' EstableceSoloLectura(cbAlmacenOrigen, False) + ' ra.idAlmacenDestino = Nothing + ' EstableceSoloLectura(cbAlmacenDestino, True) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.ENTREGA + ' EstableceSoloLectura(cbAlmacenOrigen, False) + ' ra.idAlmacenDestino = Nothing + ' EstableceSoloLectura(cbAlmacenDestino, True) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.RECOGIDA + ' ra.idAlmacenOrigen = Nothing + ' EstableceSoloLectura(cbAlmacenOrigen, True) + ' EstableceSoloLectura(cbAlmacenDestino, False) + ' Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.REGULARIZACION_STOCK + ' ra.idAlmacenOrigen = Nothing + ' EstableceSoloLectura(cbAlmacenOrigen, True) + ' EstableceSoloLectura(cbAlmacenDestino, False) + ' End Select + ' End Select + ' End If + 'End Sub Private Sub hlVale_Click(sender As Object, e As RoutedEventArgs) @@ -699,20 +704,6 @@ Public Class ucAlbaranE Private Sub ucAlbaran_AntesGuardar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, EliminacionManual As Integer) Handles Me.AntesGuardar Dim hte As New Hashtable Select Case DirectCast(ra.Tipo, bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum) - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.COMPRA - For Each d In ra.detallesalbaranesidAlbaranNavigation.Where(Function(x) x.EsVenta) - d.EsVenta = False - Next - If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.CAMBIO_ALMACEN - If ra.idAlmacenOrigen.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_ORIGEN_OBLIGATORIO", "El almacén origen es obligatorio") - If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.SUBALQUILER - If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER - If ra.idAlmacenOrigen.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_ORIGEN_OBLIGATORIO", "El almacén origen es obligatorio") - Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.ENTREGA - If ra.idAlmacenOrigen.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_ORIGEN_OBLIGATORIO", "El almacén origen es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.RECOGIDA If ra.idAlmacenDestino.HasValue = False Then hte.Add("ALMACENAR-ALMACEN_DESTINO_OBLIGATORIO", "El almacén destino es obligatorio") Case bdGrupoSanchoToro.db.albaranes.TipoAlbaranEnum.REGULARIZACION_STOCK @@ -723,32 +714,52 @@ Public Class ucAlbaranE Cancelar = True Else ra.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario - Dim bdtmp = tscGrupoSanchoToro.NuevoContexto + Dim lds As List(Of detallesalbaranes) = Me.gcProductos.ItemsSource + Dim dad = lds.Where(Function(x) x.UnidadesRecogidasTmp < x.Cantidad).ToList + For Each d In dad + Dim nd As New detallesalbaranes + With nd + .Cantidad = d.Cantidad - d.UnidadesRecogidasTmp + .idAlbaran = d.idAlbaran + .idArticulo = d.idArticulo + .idProducto = d.idProducto + .idUltimaFactura = d.idUltimaFactura + .Observaciones = d.Observaciones + .EsVenta = False + .idAlbaranRecogida = Nothing + End With + bd.detallesalbaranes.Add(nd) + d.Cantidad = d.UnidadesRecogidasTmp + Next + Dim bdtmp = tscGrupoSanchoToro.NuevoContexto Select Case Estado Case tsUtilidades.EstadosAplicacion.Nuevo - For Each d In ra.detallesalbaranesidAlbaranNavigation - d.idAlbaranNavigation = ra - d.ActualizaProducto(bdtmp, 1) + For Each d In ra.detallesalbaranesidAlbaranRecogidaNavigation + d.idAlbaranRecogidaNavigation = ra + d.ActualizaProducto(bdtmp, ra.Tipo, 1, ra.idEmpresa) Next Case tsUtilidades.EstadosAplicacion.ModificandoRegistro - Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaran = ra.idAlbaran).ToList + Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaranRecogida = ra.idAlbaran).ToList For Each d In das - d.ActualizaProducto(bdtmp, -1) + d.ActualizaProducto(bdtmp, d.idAlbaranRecogidaNavigation.Tipo, -1, d.idAlbaranRecogidaNavigation.idEmpresa) Next - For Each d In ra.detallesalbaranesidAlbaranNavigation - d.ActualizaProducto(bdtmp, 1) + For Each d In ra.detallesalbaranesidAlbaranRecogidaNavigation + If d.idAlbaranRecogidaNavigation Is Nothing Then d.idAlbaranRecogidaNavigation = ra + d.ActualizaProducto(bdtmp, d.idAlbaranRecogidaNavigation.Tipo, 1, d.idAlbaranRecogidaNavigation.idEmpresa) Next End Select + bdtmp.GuardarCambios() End If End Sub Private Sub ucAlbaran_AntesEliminar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, ByRef OmitirPreguntaContinuar As Boolean) Handles Me.AntesEliminar Dim bdtmp = tscGrupoSanchoToro.NuevoContexto - Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaran = ra.idAlbaran).ToList + Dim das = bdtmp.detallesalbaranes.Where(Function(x) x.idAlbaranRecogida = ra.idAlbaran).ToList For Each d In das - d.ActualizaProducto(bdtmp, -1) + d.ActualizaProducto(bdtmp, d.idAlbaranRecogidaNavigation.Tipo, -1, d.idAlbaranRecogidaNavigation.idEmpresa) Next + bdtmp.SaveChanges() End Sub Private Sub btIrAContrato_Click(sender As Object, e As RoutedEventArgs) @@ -763,46 +774,32 @@ Public Class ucAlbaranE ra.idPresupuestoNavigation = Nothing End Sub - Private Sub tvProductos_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles tvProductos.PreviewKeyDown - If e.Key = Key.F6 Then + 'Private Sub BiBuscarArticulo_Click(sender As Object, e As RoutedEventArgs) - If Not ra.detallesalbaranesidAlbaranNavigation.ToList.Any(Function(x) x.idAlbaranRecogida.HasValue OrElse (x.idUltimaFactura.HasValue AndAlso (x.idUltimaFacturaNavigation.FechaFactura > ra.Fecha))) Then - Select Case gcProductos.CurrentColumn.FieldName.ToLower - Case "idproducto" - BiBuscarProducto_Click(Nothing, Nothing) - Case "idarticulo" - BiBuscarArticulo_Click(Nothing, Nothing) - End Select - - End If - End If - End Sub - Private Sub BiBuscarArticulo_Click(sender As Object, e As RoutedEventArgs) - - Try - If gcProductos.CurrentItem IsNot Nothing Then - Dim dea As detallesalbaranes = gcProductos.CurrentItem - If dea.idProducto > 0 Then - If tvProductos.ActiveEditor Is Nothing Then - Dispatcher.BeginInvoke(New Action(Sub() tvProductos.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render) - End If - Dim dxw As New dxwArticulos(lArticulos, dea.idProducto) - If dxw.ShowDialog Then - Dim art = lArticulos.First(Function(x) x.idArticulo = dxw.idArticulo) - dea.idArticulo = art.idArticulo - dea.Cantidad = 1 - If tvProductos.ActiveEditor IsNot Nothing Then tvProductos.ActiveEditor.EditValue = art.idArticulo - tvProductos.PostEditor() - tvProductos.CloseEditor() - gcProductos.RefreshRow(tvProductos.FocusedRowHandle) - End If - End If - End If - Catch ex As Exception - FuncionesDinamicas.ErrorNoControladoAp(Me, ex) - DXMessageBox.Show(ex.Message, "Error") - End Try - End Sub + ' Try + ' If gcProductos.CurrentItem IsNot Nothing Then + ' Dim dea As detallesalbaranes = gcProductos.CurrentItem + ' If dea.idProducto > 0 Then + ' If tvProductos.ActiveEditor Is Nothing Then + ' Dispatcher.BeginInvoke(New Action(Sub() tvProductos.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render) + ' End If + ' Dim dxw As New dxwArticulos(lArticulos, dea.idProducto) + ' If dxw.ShowDialog Then + ' Dim art = lArticulos.First(Function(x) x.idArticulo = dxw.idArticulo) + ' dea.idArticulo = art.idArticulo + ' dea.Cantidad = 1 + ' If tvProductos.ActiveEditor IsNot Nothing Then tvProductos.ActiveEditor.EditValue = art.idArticulo + ' tvProductos.PostEditor() + ' tvProductos.CloseEditor() + ' gcProductos.RefreshRow(tvProductos.FocusedRowHandle) + ' End If + ' End If + ' End If + ' Catch ex As Exception + ' FuncionesDinamicas.ErrorNoControladoAp(Me, ex) + ' DXMessageBox.Show(ex.Message, "Error") + ' End Try + 'End Sub End Class diff --git a/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml b/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml index bf8c20e..19b53ca 100644 --- a/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml +++ b/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml @@ -67,20 +67,20 @@ - + - + - + - + diff --git a/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml.vb b/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml.vb index d0df516..c444b4f 100644 --- a/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml.vb +++ b/GestionGrupoSanchoToro/Almacen/ucAlbaranes.xaml.vb @@ -92,7 +92,15 @@ Public Class ucAlbaranes End Function Private Sub Nuevo() Handles Me.BotonNuevoPulsado - FuncionesDinamicas.AbrirAP(New ucAlbaran, OtrosParametros) + Dim dxwta As New dxwTipoAlbaran + If dxwta.ShowDialog Then + If dxwta.Tipo = db.albaranes.TipoAlbaranEnum.RECOGIDA Or dxwta.Tipo = db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER Then + FuncionesDinamicas.AbrirAP(New ucAlbaranR(dxwta.Tipo), OtrosParametros) + Else + FuncionesDinamicas.AbrirAP(New ucAlbaran(dxwta.Tipo), OtrosParametros) + End If + End If + End Sub Private Sub ap_Enlazar(Celda As DevExpress.Xpf.Grid.EditGridCellData, Defecto As Boolean) Handles Me.Enlazar @@ -104,7 +112,13 @@ Public Class ucAlbaranes Select Case Celda.Column.FieldName.ToLower Case "numeroalbaran" Dim id As Integer = ra.idAlbaran - FuncionesDinamicas.AbrirAP(New ucAlbaran(id), OtrosParametros) + Select Case DirectCast(ra.Tipo, albaranes.TipoAlbaranEnum) + Case db.albaranes.TipoAlbaranEnum.RECOGIDA, db.albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER + FuncionesDinamicas.AbrirAP(New ucAlbaranR(ra.Tipo, id), OtrosParametros) + Case Else + FuncionesDinamicas.AbrirAP(New ucAlbaran(ra.Tipo, id), OtrosParametros) + End Select + Case "razonsocial" Dim id As Integer = ra.idEntidad FuncionesDinamicas.AbrirAP(New ucEntidad(id), OtrosParametros) @@ -114,7 +128,7 @@ Public Class ucAlbaranes End Sub Public Function ObtieneAlbaranes(TextoBusqueda As String, FechaInicio As DateOnly?, FechaFin As DateOnly?, Tipos As List(Of Integer)) As List(Of v_albaranesextendidos) - Dim rs As IQueryable(Of v_albaranesextendidos) + Dim rs As IQueryable(Of v_albaranesextendidos) = bd.v_albaranesextendidos.Where(Function(x) x.idEmpresa = EmpresaActual.idEmpresa) Dim la As New List(Of v_albaranesextendidos) Dim iNumExc As Integer = 0 Do @@ -122,9 +136,9 @@ Public Class ucAlbaranes If TextoBusqueda <> "" Then Dim parametros(0) As Object Dim ExpresionBusqueda = tsWPFCore.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Me._CamposBusquedaNumericos, Me._CamposBusquedaAlfabeticos, Nothing) - rs = bd.v_albaranesextendidos.Where(ExpresionBusqueda) + rs = rs.Where(ExpresionBusqueda) Else - rs = bd.v_albaranesextendidos.AsQueryable + rs = rs.AsQueryable End If If FechaInicio.HasValue Then diff --git a/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml b/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml index 4ccfa1f..ba109af 100644 --- a/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml +++ b/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml @@ -1,4 +1,4 @@ - - + @@ -25,53 +25,77 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - + + + - - + + + + + - + @@ -82,39 +106,285 @@ - - - - - - - - - + + + + + + + + + - - - + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + diff --git a/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml.vb b/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml.vb index 33b83d8..f6d7375 100644 --- a/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml.vb +++ b/GestionGrupoSanchoToro/FicherosMaestros/ucProducto.xaml.vb @@ -1,14 +1,13 @@ -Imports bdGrupoSanchoToro.db -Imports DevExpress.Xpf.Bars -Imports bdGrupoSanchoToro.db.tscGrupoSanchoToro -Imports bdGrupoSanchoToro.db.Utilidades -Imports DevExpress.Xpf.Grid -Imports System.Collections -Imports tsWPFCore -Imports DevExpress.Xpf.Core -Imports DevExpress.XtraSplashScreen +Imports System.Collections +Imports bdGrupoSanchoToro.db Imports bdGrupoSanchoToro.db.productos +Imports bdGrupoSanchoToro.db.Utilidades +Imports DevExpress.Xpf.Bars +Imports DevExpress.Xpf.Core +Imports DevExpress.Xpf.Grid +Imports DevExpress.XtraSplashScreen Imports Microsoft.EntityFrameworkCore +Imports tsWPFCore Public Class ucProducto @@ -20,31 +19,31 @@ Public Class ucProducto Public Overrides Function EstablecedcPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As tsUtilidades.EstadosAplicacion Dim NuevoEstado As tsUtilidades.EstadosAplicacion If idLog.HasValue Then - Try - Dim log = bd.logs.First(Function(x) x.idLog = idLog) - ra = tsUtilidades.Utilidades.DeserializarSinErrores(log.Log, GetType(productos)) - If ra.idUsuarioCreador.HasValue Then ra.idUsuarioCreadorNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuarioCreador.Value) - If ra.idUsuarioModificador.HasValue Then ra.idUsuarioModificadorNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuarioModificador.Value) - If bd.logs.Any(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "ARTICULOS") Then - Dim entspol = bd.logs.First(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "ARTICULOS") - Dim ld = tsUtilidades.Utilidades.DeserializarSinErrores(entspol.Log, GetType(List(Of articulos))) - For Each d In ld - ra.articulos.Add(d) - Next - End If - NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro - Catch EX As Exception - Throw New Exception("No ha sido posible mostrar el registro del cambio (id " & idLog.Value.ToString & ").", EX) - End Try + 'Try + ' Dim log = bd.logs.First(Function(x) x.idLog = idLog) + ' ra = tsUtilidades.Utilidades.DeserializarSinErrores(log.LogXML, GetType(productos)) + ' If ra.idUsuarioCreador.HasValue Then ra.idUsuarioCreadorNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuarioCreador.Value) + ' If ra.idUsuarioModificador.HasValue Then ra.idUsuarioModificadorNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuarioModificador.Value) + ' If bd.logs.Any(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "ARTICULOS") Then + ' Dim entspol = bd.logs.First(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "ARTICULOS") + ' Dim ld = tsUtilidades.Utilidades.DeserializarSinErrores(entspol.LogXML, GetType(List(Of articulos))) + ' For Each d In ld + ' ra.articulos.Add(d) + ' Next + ' End If + ' NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro + 'Catch EX As Exception + ' Throw New Exception("No ha sido posible mostrar el registro del cambio (id " & idLog.Value.ToString & ").", EX) + 'End Try Else If Estado = tsUtilidades.EstadosAplicacion.Nuevo OrElse _idproducto Is Nothing OrElse FuerzaNuevo Then ra = New productos - 'ra.TotalUnidades = 0 - 'ra.UnidadesVendidas = 0 - 'ra.UnidadesAlquiladas = 0 - 'ra.UnidadesAveriadas = 0 - 'ra.UnidadesDesechadas = 0 - 'ra.FacturarComoVentaPorDefecto = False + ra.TotalUnidades = 0 + ra.UnidadesVendidas = 0 + ra.UnidadesAlquiladas = 0 + ra.UnidadesAveriadas = 0 + ra.UnidadesDesechadas = 0 + ra.FacturarComoVentaPorDefecto = False Me.DataContext = ra _idproducto = Nothing NuevoEstado = tsUtilidades.EstadosAplicacion.Nuevo @@ -53,14 +52,17 @@ Public Class ucProducto NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro End If End If - ' Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idProducto AndAlso x.Aplicacion = "PRODUCTOS").ToList - + ' Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idProducto AndAlso x.Aplicacion = "PRODUCTOS").ToList + Me.gcDesglose.ItemsSource = ra.DesgloseMaterial 'Me.gcServicios.ItemsSource = ra.DesgloseServicios - If ra.Servicio Then + If ra.Tipo <> TipoProductoEnum.SERVICIO Then Me.gcStocksAlmacenes.ItemsSource = ObtieneISAlmacenes() + Me.gcStocksEmpresas.ItemsSource = ra.DesgloseUnidades Else Me.gcStocksAlmacenes.ItemsSource = Nothing + Me.gcStocksEmpresas.ItemsSource = Nothing End If + Me.gcAlbaranes.ItemsSource = bd.detallesalbaranes.Include(Function(x) x.idAlbaranNavigation.idEntidadNavigation).Where(Function(x) x.idProducto = ra.idProducto).OrderByDescending(Function(x) x.idAlbaranNavigation.Fecha).ToList Me.DataContext = ra ' gcArticulos.ItemsSource = ra.articulos @@ -165,7 +167,8 @@ Public Class ucProducto Try Dim idprs = ra.articulos.Where(Function(x) x.idProveedor.HasValue).Select(Function(x) x.idProveedor.Value).ToArray - Me.cbTipo.ItemsSource = tsUtilidades.DescripcionValor.EnumADescripcionValor(GetType(bdGrupoSanchoToro.db.productos.TipoProductoEnum)).ToList + Me.cbTipo.ItemsSource = tsUtilidades.DescripcionValor.EnumADescripcionValor(GetType(bdGrupoSanchoToro.db.productos.TipoProductoEnum)) _ + .OrderBy(Function(x) x.Valor).ToList Catch ex As Exception Throw New Exception(ex.Message, ex) End Try @@ -201,11 +204,34 @@ Public Class ucProducto - + Private Sub ucProducto_DespuesGuardar(sender As Object, e As ItemClickEventArgs, OpcionGuardado As Integer) Handles Me.DespuesGuardar + Try + _idproducto = ra.idProducto + ra.RefrescaCamposTemporales() + If RecalcularStocks Then + RecalcularStocks = False + DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)() + DXSplashScreen.SetState("Recalculando Stocks ...") + Dim lp As New List(Of productos) + lp.Add(ra) + bdGrupoSanchoToro.db.productos.RecalculaStocks(bd, lp) + DXSplashScreen.Close() + End If + RefrescaUC() + Catch ex As Exception + If DXSplashScreen.IsActive Then DXSplashScreen.Close() + Throw New Exception(ex.Message, ex) + End Try + End Sub Private Sub ucProducto_Enlazar(Celda As EditGridCellData, Defecto As Boolean) Handles Me.Enlazar Select Case Celda.Column.FieldName.ToLower + Case "productos1.idproducto" + Dim dp As desgloseproductos = Celda.Row + Dim id As Integer = dp.idProducto + Dim uc As New ucProducto(id) + FuncionesDinamicas.AbrirAP(uc, OtrosParametros) 'Case "idlog" ' Dim log As logs = gcLogs.CurrentItem ' Dim id As Integer = log.idLog @@ -215,9 +241,9 @@ Public Class ucProducto Case "almacen" Dim st As stocks = Celda.Row FuncionesDinamicas.AbrirAP(New ucAlmacen(st.idAlmacen), OtrosParametros) - 'Case "numeroalbaran" - ' Dim al As detallesalbaranes = Celda.Row - ' FuncionesDinamicas.AbrirAP(New ucAlbaran(al.idAlbaran), OtrosParametros) + Case "numeroalbaran" + Dim al As detallesalbaranes = Celda.Row + FuncionesDinamicas.AbrirAP(New ucAlbaran(al.idAlbaran), OtrosParametros) Case "entidad" Dim da As detallesalbaranes = Celda.Row If da.idAlbaranNavigation.idEntidad.HasValue Then FuncionesDinamicas.AbrirAP(New ucEntidad(da.idAlbaranNavigation.idEntidad.Value), OtrosParametros) @@ -237,46 +263,42 @@ Public Class ucProducto Private RecalcularStocks As Boolean - 'Private Sub ucProducto_AntesGuardar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, EliminacionManual As Integer) Handles Me.AntesGuardar - ' ' - ' ' Esto se hace para evitar error duplicate entry en el intercambio de numero de series - ' ' - ' Try - ' Dim bdtmp = tscGrupoSanchoToro.NuevoContexto() - ' Dim arts = bdtmp.articulos.Where(Function(x) x.idProducto = ra.idProducto).ToList - ' For Each art In arts - ' If ra.articulos.Any(Function(x) x.idArticulo <> art.idArticulo AndAlso art.CodigoArticulo = x.CodigoArticulo) Then - ' art.CodigoArticulo = Nothing - ' End If - ' Next - ' 'If Estado = tsUtilidades.EstadosAplicacion.ModificandoRegistro Then - ' ' Dim raant = bdtmp.productos.First(Function(x) x.idProducto = ra.idProducto) - ' ' If (ra.Tipo = TipoProductoEnum.ELEMENTO_FINAL_TRIBUNA OrElse ra.Tipo = TipoProductoEnum.ELEMENTO_FINAL_CARPA OrElse ra.Tipo <= TipoProductoEnum.OTROS) AndAlso - ' ' Not (raant.Tipo = TipoProductoEnum.ELEMENTO_FINAL_TRIBUNA OrElse raant.Tipo = TipoProductoEnum.ELEMENTO_FINAL_CARPA OrElse raant.Tipo <= TipoProductoEnum.OTROS) Then - ' ' RecalcularStocks = True - ' ' Else - ' ' If Not (ra.Tipo = TipoProductoEnum.ELEMENTO_FINAL_TRIBUNA OrElse ra.Tipo = TipoProductoEnum.ELEMENTO_FINAL_CARPA OrElse ra.Tipo <= TipoProductoEnum.OTROS) AndAlso - ' ' (raant.Tipo = TipoProductoEnum.ELEMENTO_FINAL_TRIBUNA OrElse raant.Tipo = TipoProductoEnum.ELEMENTO_FINAL_CARPA OrElse raant.Tipo <= TipoProductoEnum.OTROS) Then - ' ' For i = ra.stocks.Count - 1 To 0 - ' ' bd.stocks.Remove(ra.stocks(i)) - ' ' Next - ' ' ra.TotalUnidades = 0 - ' ' ra.UnidadesInicialesOFabricadas = 0 - ' ' ra.UnidadesCompradas = 0 - ' ' ra.UnidadesVendidas = 0 - ' ' ra.UnidadesAlquiladas = 0 - ' ' ra.UnidadesAveriadas = 0 - ' ' ra.UnidadesDesechadas = 0 - ' ' ra.UnidadesSubAlquiladas = 0 - ' ' End If - ' ' End If - ' 'End If + Private Sub ucProducto_AntesGuardar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, EliminacionManual As Integer) Handles Me.AntesGuardar + ' + ' Esto se hace para evitar error duplicate entry en el intercambio de numero de series + ' + Try + Dim bdtmp = tscGrupoSanchoToro.NuevoContexto() + Dim arts = bdtmp.articulos.Where(Function(x) x.idProducto = ra.idProducto).ToList + For Each art In arts + If ra.articulos.Any(Function(x) x.idArticulo <> art.idArticulo AndAlso art.CodigoArticulo = x.CodigoArticulo) Then + art.CodigoArticulo = Nothing + End If + Next + If Estado = tsUtilidades.EstadosAplicacion.ModificandoRegistro Then + Dim raant = bdtmp.productos.First(Function(x) x.idProducto = ra.idProducto) + If ra.Tipo <> TipoProductoEnum.SERVICIO Then + RecalcularStocks = True + Else + For i = ra.stocks.Count - 1 To 0 + bd.stocks.Remove(ra.stocks(i)) + Next + ra.TotalUnidades = 0 + ra.UnidadesInicialesOFabricadas = 0 + ra.UnidadesCompradas = 0 + ra.UnidadesVendidas = 0 + ra.UnidadesAlquiladas = 0 + ra.UnidadesAveriadas = 0 + ra.UnidadesDesechadas = 0 + ra.UnidadesSubAlquiladas = 0 + End If + End If - ' bdtmp.GuardarCambios() - ' Catch ex As Exception - ' Throw New Exception(ex.Message, ex) - ' End Try - 'End Sub + bdtmp.GuardarCambios() + Catch ex As Exception + Throw New Exception(ex.Message, ex) + End Try + End Sub Private Sub ucProducto_EstadoCambiado(EstadoAnterior As tsUtilidades.EstadosAplicacion, EstadoNuevo As tsUtilidades.EstadosAplicacion) Handles Me.EstadoCambiado If idLog.HasValue Then @@ -288,22 +310,22 @@ Public Class ucProducto Private Sub ucProducto_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion 'Select Case idAccion ' Case 1 ' AÑADIR PRODUCTOS AL DESGLOSE - - + ' Dim prsact = ra.DesgloseMaterial.Select(Function(x) x.idProducto).ToList + ' Dim maxasc = ra.NivelMaximoAscendientes + ' Dim lproductos = bd.productos.ToList.Where(Function(x) (maxasc + x.NivelMaximoDescendientes) < 3 AndAlso ra.ContieneAscendiente(x.idProducto) = False AndAlso prsact.Contains(x.idProducto) = False).ToList + ' Dim dxw As New dxwProductos(lproductos) + ' If dxw.ShowDialog Then + ' Dim prod = lproductos.First(Function(x) x.idProducto = dxw.idProducto) + ' Dim nd As New desgloseproductos + ' With nd + ' .idProductoNavigation = prod + ' .Unidades = 1 + ' .UnidadesMaximas = 1 + ' .UnidadesMinimas = 1 + ' End With + ' ra.desgloseproductosidProductoNavigation.Add(nd) + ' ra.RefrescaCamposTemporales() + ' End If 'End Select End Sub - - Private Sub ucProducto_AntesGuardar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, EliminacionManual As Integer) Handles Me.AntesGuardar - ra.idEmpresa = EmpresaActual.idEmpresa - Dim hte As New Hashtable - ra.idEmpresa = EmpresaActual.idEmpresa - Dim almexi = bd.productos.FirstOrDefault(Function(x) x.idProducto <> ra.idProducto AndAlso x.Descripcion = ra.Descripcion AndAlso x.idEmpresa = EmpresaActual.idEmpresa) - If almexi IsNot Nothing Then - hte.Add("ALMACENAR-PRODUCTO_DUPLIADO", "Producto Duplicado") - End If - If hte.Count > 0 Then - MensajesError = hte - Cancelar = True - End If - End Sub End Class diff --git a/GestionGrupoSanchoToro/FicherosMaestros/ucProductos.xaml.vb b/GestionGrupoSanchoToro/FicherosMaestros/ucProductos.xaml.vb index 13cd973..ecff582 100644 --- a/GestionGrupoSanchoToro/FicherosMaestros/ucProductos.xaml.vb +++ b/GestionGrupoSanchoToro/FicherosMaestros/ucProductos.xaml.vb @@ -60,14 +60,14 @@ Public Class ucProductos Public Overrides Function EstableceDCPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As tsUtilidades.EstadosAplicacion If Refrescar OrElse Background Then ObtieneproductosAsync(bd, Background) - 'If Me.ContenedorAplicacion.cbAcciones.ItemsSource Is Nothing Then - ' Dim Acciones As New List(Of tsWPFCore.Accion) - ' Acciones.Add(New Accion With { - ' .idAccion = 1, - ' .Descripcion = "CORREGIR STOCK"}) - ' Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones - ' Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion - 'End If + If Me.ContenedorAplicacion.cbAcciones.ItemsSource Is Nothing Then + Dim Acciones As New List(Of tsWPFCore.Accion) + Acciones.Add(New Accion With { + .idAccion = 1, + .Descripcion = "CORREGIR STOCK"}) + Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones + Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion + End If Return tsUtilidades.EstadosAplicacion.AplicacionSinIndice @@ -128,7 +128,7 @@ Public Class ucProductos End Sub Public Function Obtieneproductos(TextoBusqueda As String, IncluirBajas As Boolean) As List(Of productos) - Dim iqPr = bd.productos.Where(Function(x) x.idEmpresa = EmpresaActual.idEmpresa) + Dim iqPr = bd.productos.AsQueryable If IncluirBajas Then iqPr = iqPr.Where(Function(x) x.FechaBaja Is Nothing).OrderBy(Function(x) x.Descripcion) Dim rs As List(Of productos) Do @@ -187,6 +187,19 @@ Public Class ucProductos teBusqueda.SelectAll() End Sub - - + Private Sub ucProductos_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion + Try + Select Case idAccion + Case 1 ' RECALCULA STOCKS DE TODOS LOS PRODUCTOS + If DXSplashScreen.IsActive = False Then DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)() + DXSplashScreen.SetState("Recalculando stocks ...") + Dim lp = bd.detallesalbaranes.Where(Function(x) x.idAlbaranRecogida.HasValue = False).Select(Function(x) x.idProductoNavigation).Distinct().ToList() + bdGrupoSanchoToro.db.productos.RecalculaStocks(bd, lp) + DXSplashScreen.Close() + End Select + Catch ex As Exception + If DXSplashScreen.IsActive Then DXSplashScreen.Close() + FuncionesDinamicas.ErrorNoControladoAp(Me, ex) + End Try + End Sub End Class diff --git a/GestionGrupoSanchoToro/Ventas/ucFacturasEmitidas.xaml.vb b/GestionGrupoSanchoToro/Ventas/ucFacturasEmitidas.xaml.vb index 24e9231..77c6e41 100644 --- a/GestionGrupoSanchoToro/Ventas/ucFacturasEmitidas.xaml.vb +++ b/GestionGrupoSanchoToro/Ventas/ucFacturasEmitidas.xaml.vb @@ -124,7 +124,7 @@ Public Class ucFacturasEmitidas Dim iNumExc As Integer = 0 Do Try - rs = bd.facturas.Where(Function(x) x.idClienteNavigation.idEmpresa = EmpresaActual.idEmpresa).Include(Function(x) x.idSerieFacturaNavigation).Include(Function(x) x.movimientoscaja).Include(Function(x) x.idClienteNavigation).Include(Function(x) x.idEventoNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation).Include(Function(x) x.idUsuarioNavigation).AsQueryable + rs = bd.facturas.Where(Function(x) x.idClienteNavigation.idEmpresa = EmpresaActual.idEmpresa).Include(Function(x) x.idSerieFacturaNavigation).Include(Function(x) x.movimientoscaja).Include(Function(x) x.idClienteNavigation).Include(Function(x) x.idObraNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation).Include(Function(x) x.idUsuarioNavigation).AsQueryable If FechaInicio.HasValue Then rs = rs.Where(Function(x) x.FechaFactura >= FechaInicio.Value) diff --git a/GestionGrupoSanchoToro/dxwInicio.xaml.vb b/GestionGrupoSanchoToro/dxwInicio.xaml.vb index 7b7a0ae..6d4ce28 100644 --- a/GestionGrupoSanchoToro/dxwInicio.xaml.vb +++ b/GestionGrupoSanchoToro/dxwInicio.xaml.vb @@ -35,7 +35,7 @@ Public Class dxwInicio Comun.dg = Me.grupodoc tsWPFCore.Configuracion.ModoBusquedaAND = True tsWPFCore.Configuracion.ComportamientoValidacion = DevExpress.Xpf.Editors.Validation.InvalidValueBehavior.AllowLeaveEditor - ' tsWPFCore.Configuracion.ModoEventosContextoSavingChanges = ModoContextoSavingChangesEnum.SoloDespuesGuardar + ' tsWPFCore.Configuracion.ModoObrasContextoSavingChanges = ModoContextoSavingChangesEnum.SoloDespuesGuardar tsWPFCore.Configuracion.MostrarBotonCerrarEnPestaña = True bdGrupoSanchoToro.db.Utilidades.DirectorioLogs = "c:\m3soft\logs\" Catch ex As Exception diff --git a/GestionGrupoSanchoToro/ucEntidad.xaml b/GestionGrupoSanchoToro/ucEntidad.xaml index 2819f71..b238fc1 100644 --- a/GestionGrupoSanchoToro/ucEntidad.xaml +++ b/GestionGrupoSanchoToro/ucEntidad.xaml @@ -205,7 +205,7 @@ - + @@ -213,7 +213,7 @@ - + diff --git a/GestionGrupoSanchoToro/ucEntidad.xaml.bak b/GestionGrupoSanchoToro/ucEntidad.xaml.bak index 6342af4..6c4f474 100644 --- a/GestionGrupoSanchoToro/ucEntidad.xaml.bak +++ b/GestionGrupoSanchoToro/ucEntidad.xaml.bak @@ -174,9 +174,9 @@ - - - + + + @@ -208,7 +208,7 @@ - + @@ -216,7 +216,7 @@ - + @@ -268,7 +268,7 @@ - + diff --git a/GestionGrupoSanchoToro/ucEntidad.xaml.vb b/GestionGrupoSanchoToro/ucEntidad.xaml.vb index 0662898..81d7dbc 100644 --- a/GestionGrupoSanchoToro/ucEntidad.xaml.vb +++ b/GestionGrupoSanchoToro/ucEntidad.xaml.vb @@ -49,9 +49,9 @@ Public Class ucEntidad If ra.idUsuarioModificador.HasValue Then ra.idUsuarioModificadorNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuarioModificador.Value) If bd.logs.Any(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "OBRAS") Then Dim entspol = bd.logs.First(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "OBRAS") - Dim ld = tsUtilidades.Utilidades.deserializarsinerrores(entspol.Log, GetType(List(Of eventos))) + Dim ld = tsUtilidades.Utilidades.deserializarsinerrores(entspol.Log, GetType(List(Of obras))) For Each d In ld - ra.eventos.Add(d) + ra.Obras.Add(d) Next End If NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro @@ -72,7 +72,7 @@ Public Class ucEntidad End If End If - gcFacturasEmitidas.ItemsSource = bd.facturas.Include(Function(x) x.idEventoNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation).Include(Function(x) x.movimientoscaja).Where(Function(x) x.idCliente = ra.idEntidad).OrderByDescending(Function(x) x.FechaFactura).ThenByDescending(Function(x) x.NumeroFactura).ToList + gcFacturasEmitidas.ItemsSource = bd.facturas.Include(Function(x) x.idObraNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation).Include(Function(x) x.movimientoscaja).Where(Function(x) x.idCliente = ra.idEntidad).OrderByDescending(Function(x) x.FechaFactura).ThenByDescending(Function(x) x.NumeroFactura).ToList gcFacturasRecibidas.ItemsSource = bd.facturasrecibidas.Where(Function(x) x.idProveedor = ra.idEntidad).OrderByDescending(Function(x) x.FechaFactura).ToList gcExpediente.ItemsSource = ra.expedientesentidades Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idEntidad AndAlso x.Aplicacion = "ENTIDADES" AndAlso x.idRelacionado Is Nothing).OrderByDescending(Function(x) x.idLog).ToList diff --git a/bdGrupoSanchoToro/Importaciones/ImportaARTICULOS.cs b/bdGrupoSanchoToro/Importaciones/ImportaARTICULOS.cs new file mode 100644 index 0000000..e2b9419 --- /dev/null +++ b/bdGrupoSanchoToro/Importaciones/ImportaARTICULOS.cs @@ -0,0 +1,80 @@ +using Castle.Core.Configuration; +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing.Imaging; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using tsUtilidades.Extensiones; + +namespace bdGrupoSanchoToro.Importaciones +{ + public class ImportaARTICULOS + { + public static void Importar(byte[] Fichero) + { + try + { + var bd = tscGrupoSanchoToro.NuevoContexto(); + var lp = bd.productos.Where(x=> x.Tipo!=(int)db.productos.TipoProductoEnum.GRUA).ToList(); + var la = bd.articulos.ToList(); + + var ds = new XSD.ARTICULOS(); + ds.ReadXml(new System.IO.MemoryStream(Fichero)); + int i = 1; + int Ultimalinea = ds.Tables["Datos"].Rows.Count; + foreach (XSD.ARTICULOS.DatosRow ar in ds.Tables["Datos"].Rows) + { + try + { + + var pr = lp.FirstOrDefault(x => x.Codigo == ar.ARCPR || x.Descripcion == ar.ARDES.Trim()); + if (pr == null) + { + string sDes = ImportaPRODUCTOS.pros.FirstOrDefault(x=>x.PRCOD == ar.ARCPR )?.PRDES; + pr = lp.FirstOrDefault(x => x.Descripcion == sDes); + } + if (pr != null) + { + var art = la.FirstOrDefault(x => x.idProducto == pr.idProducto && x.CodigoArticulo == ar.ARNSE.Trim()) ; + if (art == null) + { + art = new bdGrupoSanchoToro.db.articulos(); + bd.articulos.Add(art); + la.Add(art); + } + art.idProductoNavigation = pr; + art.CodigoArticulo = ar.ARNSE.Trim(); + art.NumeroSerie = ar.ARNSE.Trim(); + art.FechaBaja = ar.ARFEN.FechaStringADateOnly(); + //art.FechaBaja = ar.CPFBA.FechaStringADateOnly(); + // art.Matricula = ar.CPMAT; + i = i + 1; + if (i > 1000) + { + bd.SaveChanges(); + i = 0; + } + } + else + { + Debug.Write("aqui"); + } + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + bd.SaveChanges(); + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + } +} + diff --git a/bdGrupoSanchoToro/Importaciones/ImportaCTESGESL.cs b/bdGrupoSanchoToro/Importaciones/ImportaCTESGESL.cs index a9689d9..f3c0d4b 100644 --- a/bdGrupoSanchoToro/Importaciones/ImportaCTESGESL.cs +++ b/bdGrupoSanchoToro/Importaciones/ImportaCTESGESL.cs @@ -16,12 +16,12 @@ namespace bdGrupoSanchoToro.Importaciones var bd = tscGrupoSanchoToro.NuevoContexto(); var le = bd.enumeraciones.ToList(); var grs = bd.gruposenumeraciones.ToList(); - var dsprueba = new XSD.CTESGESL(); + var ds = new XSD.CTESGESL(); - dsprueba.ReadXml(new System.IO.MemoryStream(Fichero)); + ds.ReadXml(new System.IO.MemoryStream(Fichero)); int i = 1; - int Ultimalinea = dsprueba.Tables["Datos"].Rows.Count; - foreach (XSD.CTESGESL.DatosRow Proant in dsprueba.Tables["Datos"].Rows) + int Ultimalinea = ds.Tables["Datos"].Rows.Count; + foreach (XSD.CTESGESL.DatosRow Proant in ds.Tables["Datos"].Rows) { try { diff --git a/bdGrupoSanchoToro/Importaciones/ImportaGRUASGC.cs b/bdGrupoSanchoToro/Importaciones/ImportaGRUASGC.cs index a1a2511..dff5759 100644 --- a/bdGrupoSanchoToro/Importaciones/ImportaGRUASGC.cs +++ b/bdGrupoSanchoToro/Importaciones/ImportaGRUASGC.cs @@ -1,5 +1,7 @@ using bdGrupoSanchoToro.db; +using System.Diagnostics; using System.Linq.Dynamic.Core; +using tsUtilidades.Extensiones; namespace bdGrupoSanchoToro.Importaciones { public class ImportaGRUASGC @@ -9,34 +11,38 @@ namespace bdGrupoSanchoToro.Importaciones try { var bd = tscGrupoSanchoToro.NuevoContexto(); - var dsprueba = new XSD.GRUASGC(); + var ds = new XSD.GRUASGC(); - dsprueba.ReadXml(new System.IO.MemoryStream(Fichero)); - int Ultimalinea = dsprueba.Tables["Datos"].Rows.Count; + ds.ReadXml(new System.IO.MemoryStream(Fichero)); + int Ultimalinea = ds.Tables["Datos"].Rows.Count; var lp = bd.productos.ToList(); var lm = bd.marcas.ToList(); var lv = bd.versionesgruas.ToList(); - var grs = dsprueba.Tables["Datos"].Rows.Cast().ToList().OrderBy(x=> OrdenGRUASGC(x)).ToList(); + var grs = ds.Tables["Datos"].Rows.Cast().ToList().OrderBy(x=> OrdenGRUASGC(x)).ToList(); foreach (XSD.GRUASGC.DatosRow gr in grs) { try { + if (gr.CGMAR=="SAE") gr.CGMAR = "SAEZ"; + if (gr.CGMAR == "COMANSA LINDE LC8552") gr.CGMAR = "COMANSA"; var mar = lm.First(x => x.Marca == gr.CGMAR); string sDescripcion = "GRÚA " + mar.Marca + " " + gr.CGMDL; bdGrupoSanchoToro.db.productos pr = lp.FirstOrDefault(x => x.Descripcion== sDescripcion); if (pr == null) { pr = new productos() - { - idEmpresa = 1, + { Codigo = "GR-" + gr.CGCOD, Descripcion = sDescripcion, + DescripcionAbreviada = (mar.Marca + " " + gr.CGMDL).Acortar(45), idMarcaNavigation = mar, FechaAlta = DateOnly.FromDateTime(DateTime.Now), Modelo = gr.CGMDL, - Tipo = (int)productos.TipoProductoEnum.GRUA + Tipo = (int)productos.TipoProductoEnum.GRUA, + idFamilia=42 }; + bd.Add(pr); lp.Add(pr); bd.SaveChanges(); diff --git a/bdGrupoSanchoToro/Importaciones/ImportaGRUASPC.cs b/bdGrupoSanchoToro/Importaciones/ImportaGRUASPC.cs new file mode 100644 index 0000000..427f74f --- /dev/null +++ b/bdGrupoSanchoToro/Importaciones/ImportaGRUASPC.cs @@ -0,0 +1,67 @@ +using Castle.Core.Configuration; +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.Drawing.Imaging; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using tsUtilidades.Extensiones; + +namespace bdGrupoSanchoToro.Importaciones +{ + public class ImportaGRUASPC + { + public static void Importar(byte[] Fichero) + { + try + { + var bd = tscGrupoSanchoToro.NuevoContexto(); + var lp = bd.productos.Where(x=> x.Tipo==(int)db.productos.TipoProductoEnum.GRUA).ToList(); + var la = bd.articulos.ToList(); + + var ds = new XSD.GRUASPC(); + ds.ReadXml(new System.IO.MemoryStream(Fichero)); + int i = 1; + int Ultimalinea = ds.Tables["Datos"].Rows.Count; + foreach (XSD.GRUASPC.DatosRow grua in ds.Tables["Datos"].Rows) + { + try + { + string codp = "GR-" + grua.CPCGG; + if (grua.CPMAR == "SAE") grua.CPMAR = "SAEZ"; + if (grua.CPMAR == "COMANSA LINDE LC8552") grua.CPMAR = "COMANSA"; + var gr = lp.First(x => x.Codigo == codp || (x.idMarcaNavigation.Marca == grua.CPMAR && x.Modelo == grua.CPMDL)); + var art = la.FirstOrDefault(x =>x.idProducto==gr.idProducto && x.CodigoArticulo == grua.CPCOD.Trim()); + if (art == null) + { + art = new bdGrupoSanchoToro.db.articulos(); + bd.articulos.Add(art); + la.Add(art); + } + art.idProductoNavigation = gr; + art.CodigoArticulo = grua.CPCOD.Trim(); + art.FechaAlta= grua.CPFAL.FechaStringADateOnly(); + art.FechaBaja = grua.CPFBA.FechaStringADateOnly(); + art.Matricula = grua.CPMAT; + i = i + 1; + if (i > 1000) + { + bd.SaveChanges(); + i = 0; + } + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + bd.SaveChanges(); + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + } +} diff --git a/bdGrupoSanchoToro/Importaciones/ImportaPRODUCTOS.cs b/bdGrupoSanchoToro/Importaciones/ImportaPRODUCTOS.cs index 95e8ec3..35855d5 100644 --- a/bdGrupoSanchoToro/Importaciones/ImportaPRODUCTOS.cs +++ b/bdGrupoSanchoToro/Importaciones/ImportaPRODUCTOS.cs @@ -11,6 +11,7 @@ namespace bdGrupoSanchoToro.Importaciones { public class ImportaPRODUCTOS { + public static List pros; public static void Importar(byte[] Fichero) { try @@ -23,14 +24,14 @@ namespace bdGrupoSanchoToro.Importaciones var lp = bd.productos.ToList(); var lf = bd.familias.ToList(); var lm = bd.marcas.ToList(); - var lfh = bd.enumeraciones.Where(x=> x.idGrupoEnumeracionNavigation.Grupo=="FAMH").ToList(); - var pros = ds.Tables["Datos"].Rows.Cast().ToList(); + var lfh = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == "FAMH").ToList(); + pros = ds.Tables["Datos"].Rows.Cast().ToList(); foreach (XSD.PRODUCTOS.DatosRow pro in pros) { try { - bdGrupoSanchoToro.db.productos p = lp.FirstOrDefault(x => x.Codigo == pro.PRCOD || x.DescripcionAbreviada.RemoveDiacritics() ==pro.PRDES.Trim().RemoveDiacritics().ToUpper() || x.Descripcion.RemoveDiacritics().ToUpper()==pro.PRDESL.Trim().RemoveDiacritics().ToUpper() ); + bdGrupoSanchoToro.db.productos p = lp.FirstOrDefault(x => x.Codigo == pro.PRCOD || x.DescripcionAbreviada.RemoveDiacritics() == pro.PRDES.Trim().RemoveDiacritics().ToUpper() || x.Descripcion.RemoveDiacritics().ToUpper() == pro.PRDESL.Trim().RemoveDiacritics().ToUpper()); if (p == null) { p = new productos() @@ -45,7 +46,7 @@ namespace bdGrupoSanchoToro.Importaciones p.DescripcionAbreviada = pro.PRDES.Trim().RemoveDiacritics().ToUpper(); p.FechaAlta = DateOnly.FromDateTime(DateTime.Now); familias? fam = bd.familias.FirstOrDefault(x => x.Codigo == pro.PRFAM); - p.idFamilia = fam == null ? null : fam.idFamilia; + p.idFamilia = fam == null ? 42 : fam.idFamilia; if (pro.PRMAR.NothingAVacio() != "") { var mar = lm.FirstOrDefault(x => x.Marca == pro.PRMAR); @@ -65,11 +66,11 @@ namespace bdGrupoSanchoToro.Importaciones p.idMarca = null; } p.Modelo = pro.PRMDL; - p.Servicio = (pro.PRCFP=="AL" ? true : false); + // p.Servicio = (pro.PRCFP == "AL" ? true : false); p.idFamiliaHomologacion = null; - if (pro.PRFAMH!="") + if (pro.PRFAMH != "") { - var fh=lfh.FirstOrDefault(x=> x.Codigo==("FAMH." + pro.PRFAMH)); + var fh = lfh.FirstOrDefault(x => x.Codigo == ("FAMH." + pro.PRFAMH)); if (fh != null) { p.idFamiliaHomologacion = fh.idEnumeracion; @@ -85,7 +86,7 @@ namespace bdGrupoSanchoToro.Importaciones p.Tipo = (int)productos.TipoProductoEnum.CONSUMIBLES; break; } - case "CG": + case "CG": { p.Tipo = (int)productos.TipoProductoEnum.ELEMENTO_GRUA; break; @@ -105,12 +106,18 @@ namespace bdGrupoSanchoToro.Importaciones p.Tipo = (int)productos.TipoProductoEnum.REPUESTO; break; } + default: + { + p.Tipo = (int)productos.TipoProductoEnum.ELEMENTO_GRUA; + break; + } + } } } p.PrecioVenta = double.Parse(pro.PRPVP, CultureInfo.InvariantCulture); p.ReferenciaFabrica = pro.PRRFA; - p.PrefijoNumeroSerie = pro.PRPNS; + p.PrefijoNumeroSerie = pro.PRPNS; bd.SaveChanges(); } diff --git a/bdGrupoSanchoToro/Importaciones/ImportarTodo.cs b/bdGrupoSanchoToro/Importaciones/ImportarTodo.cs index d815f68..f1bd564 100644 --- a/bdGrupoSanchoToro/Importaciones/ImportarTodo.cs +++ b/bdGrupoSanchoToro/Importaciones/ImportarTodo.cs @@ -16,11 +16,13 @@ namespace bdGrupoSanchoToro.Importaciones tscGrupoSanchoToro bd = tscGrupoSanchoToro.NuevoContexto(); //00 - //Importa("GRUASGC", bdGrupoSanchoToro.Importaciones.ImportaGRUASGC.Importar, de); //00 + Importa("GRUASGC", bdGrupoSanchoToro.Importaciones.ImportaGRUASGC.Importar, de); //00 //Importa("FAMILIAS", bdGrupoSanchoToro.Importaciones.ImportaFAMILIAS.Importar, de); //00 //Importa("FAMILIAS", bdGrupoSanchoToro.Importaciones.ImportaFAMILIAS.Importar, de); //00 //Importa("CTESGESL", bdGrupoSanchoToro.Importaciones.ImportaCTESGESL.Importar, de); //00 Importa("PRODUCTOS", bdGrupoSanchoToro.Importaciones.ImportaPRODUCTOS.Importar, de); //00 + Importa("GRUASPC", bdGrupoSanchoToro.Importaciones.ImportaGRUASPC.Importar, de); //00 + Importa("ARTICULOS", bdGrupoSanchoToro.Importaciones.ImportaARTICULOS.Importar, de); //00 //Importa("GRUPRO", bdGrupoSanchoToro.Importaciones.ImportaGrupoProductos.Importar, de); //01 //Importa("CAMPAÑAS", bdGrupoSanchoToro.Importaciones.ImportaCampañas.Importar, de); //02 diff --git a/bdGrupoSanchoToro/db/albaranes.cs b/bdGrupoSanchoToro/db/albaranes.cs index 89225b2..8a227d8 100644 --- a/bdGrupoSanchoToro/db/albaranes.cs +++ b/bdGrupoSanchoToro/db/albaranes.cs @@ -71,6 +71,8 @@ public partial class albaranes public DateOnly? FechaPrevistaFinSubalquiler { get; set; } + public int idEmpresa { get; set; } + public virtual municipios? CodigoMunicipioCargaNavigation { get; set; } public virtual municipios? CodigoMunicipioDescargaNavigation { get; set; } @@ -83,6 +85,8 @@ public partial class albaranes public virtual almacenes? idAlmacenOrigenNavigation { get; set; } + public virtual empresas idEmpresaNavigation { get; set; } = null!; + public virtual entidades? idEntidadNavigation { get; set; } public virtual presupuestos? idPresupuestoNavigation { get; set; } diff --git a/bdGrupoSanchoToro/db/desgloseproductos.cs b/bdGrupoSanchoToro/db/desgloseproductos.cs new file mode 100644 index 0000000..155acf8 --- /dev/null +++ b/bdGrupoSanchoToro/db/desgloseproductos.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using PropertyChanged; + +namespace bdGrupoSanchoToro.db; + +[AddINotifyPropertyChangedInterface] +public partial class desgloseproductos +{ + public int idDesglose { get; set; } + + public int idProductoPadre { get; set; } + + public int idProducto { get; set; } + + public int Unidades { get; set; } + + public int UnidadesMinimas { get; set; } + + public int UnidadesMaximas { get; set; } + + public string? DescripcionAdicional { get; set; } + + public int? Version { get; set; } + + public virtual ICollection detallepresupuesto { get; set; } = new List(); + + public virtual productos idProductoNavigation { get; set; } = null!; + + public virtual productos idProductoPadreNavigation { get; set; } = null!; +} diff --git a/bdGrupoSanchoToro/db/detallepresupuesto.cs b/bdGrupoSanchoToro/db/detallepresupuesto.cs index 282fcb6..1e91d0a 100644 --- a/bdGrupoSanchoToro/db/detallepresupuesto.cs +++ b/bdGrupoSanchoToro/db/detallepresupuesto.cs @@ -15,6 +15,8 @@ public partial class detallepresupuesto public double Cantidad { get; set; } + public double GastosPorUnidad { get; set; } + public double Precio { get; set; } public int idPresupuesto { get; set; } @@ -23,10 +25,24 @@ public partial class detallepresupuesto public string? Observaciones { get; set; } + public int? idDetallePresupuestoPadre { get; set; } + + public int? idDesgloseProducto { get; set; } + + public string? Parametros { get; set; } + + public int? NumeroAsientos { get; set; } + + public virtual ICollection InverseidDetallePresupuestoPadreNavigation { get; set; } = new List(); + public virtual ICollection detallesfacturas { get; set; } = new List(); public virtual articulos? idArticuloNavigation { get; set; } + public virtual desgloseproductos? idDesgloseProductoNavigation { get; set; } + + public virtual detallepresupuesto? idDetallePresupuestoPadreNavigation { get; set; } + public virtual presupuestos idPresupuestoNavigation { get; set; } = null!; public virtual productos idProductoNavigation { get; set; } = null!; diff --git a/bdGrupoSanchoToro/db/detallesalbaranes.cs b/bdGrupoSanchoToro/db/detallesalbaranes.cs index 2959f42..722337f 100644 --- a/bdGrupoSanchoToro/db/detallesalbaranes.cs +++ b/bdGrupoSanchoToro/db/detallesalbaranes.cs @@ -17,10 +17,6 @@ public partial class detallesalbaranes public double Cantidad { get; set; } - public double Peso { get; set; } - - public double Volumen { get; set; } - public bool EsVenta { get; set; } public bool IncluidoEnPresupuesto { get; set; } @@ -29,6 +25,14 @@ public partial class detallesalbaranes public int? idUltimaFactura { get; set; } + public DateTime? FechaCancelacion { get; set; } + + public int? idUsuarioQueCancela { get; set; } + + public string? MotivoCancelacion { get; set; } + + public string? Observaciones { get; set; } + public virtual albaranes idAlbaranNavigation { get; set; } = null!; public virtual albaranes? idAlbaranRecogidaNavigation { get; set; } @@ -38,4 +42,6 @@ public partial class detallesalbaranes public virtual productos idProductoNavigation { get; set; } = null!; public virtual facturas? idUltimaFacturaNavigation { get; set; } + + public virtual usuarios? idUsuarioQueCancelaNavigation { get; set; } } diff --git a/bdGrupoSanchoToro/db/empresas.cs b/bdGrupoSanchoToro/db/empresas.cs index 7054bf1..2f31a7e 100644 --- a/bdGrupoSanchoToro/db/empresas.cs +++ b/bdGrupoSanchoToro/db/empresas.cs @@ -27,6 +27,8 @@ public partial class empresas public string Codigo { get; set; } = null!; + public virtual ICollection albaranes { get; set; } = new List(); + public virtual ICollection almacenes { get; set; } = new List(); public virtual ICollection cajas { get; set; } = new List(); @@ -43,7 +45,5 @@ public partial class empresas public virtual ICollection plantillas { get; set; } = new List(); - public virtual ICollection productos { get; set; } = new List(); - public virtual ICollection seriesfacturas { get; set; } = new List(); } diff --git a/bdGrupoSanchoToro/db/entidades.cs b/bdGrupoSanchoToro/db/entidades.cs index 4113c1a..41dee4c 100644 --- a/bdGrupoSanchoToro/db/entidades.cs +++ b/bdGrupoSanchoToro/db/entidades.cs @@ -71,8 +71,6 @@ public partial class entidades public virtual ICollection correos { get; set; } = new List(); - public virtual ICollection eventos { get; set; } = new List(); - public virtual ICollection expedientesentidades { get; set; } = new List(); public virtual ICollection facturas { get; set; } = new List(); @@ -87,5 +85,7 @@ public partial class entidades public virtual usuarios? idUsuarioModificadorNavigation { get; set; } + public virtual ICollection obras { get; set; } = new List(); + public virtual ICollection presupuestos { get; set; } = new List(); } diff --git a/bdGrupoSanchoToro/db/facturas.cs b/bdGrupoSanchoToro/db/facturas.cs index 1a387ec..bbd1d1c 100644 --- a/bdGrupoSanchoToro/db/facturas.cs +++ b/bdGrupoSanchoToro/db/facturas.cs @@ -57,7 +57,7 @@ public partial class facturas public string? ObservacionesAImprimir { get; set; } - public int? idEvento { get; set; } + public int? idObra { get; set; } public double ImportePagado { get; set; } @@ -87,7 +87,7 @@ public partial class facturas public virtual ficheros? idDatosClienteOriginalNavigation { get; set; } - public virtual eventos? idEventoNavigation { get; set; } + public virtual obras? idObraNavigation { get; set; } public virtual seriesfacturas idSerieFacturaNavigation { get; set; } = null!; diff --git a/bdGrupoSanchoToro/db/modelospermitidos.cs b/bdGrupoSanchoToro/db/modelospermitidos.cs new file mode 100644 index 0000000..823fcc7 --- /dev/null +++ b/bdGrupoSanchoToro/db/modelospermitidos.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using PropertyChanged; + +namespace bdGrupoSanchoToro.db; + +[AddINotifyPropertyChangedInterface] +public partial class modelospermitidos +{ + public int idModeloPermitido { get; set; } + + public int idProducto { get; set; } + + public int idModeloGrua { get; set; } + + public bool Version_Apoyada { get; set; } + + public bool Version_Automontante { get; set; } + + public bool Version_Bicolumna { get; set; } + + public bool Version_Empotrada { get; set; } + + public bool Version_ConTraslacion { get; set; } + + public virtual productos idModeloGruaNavigation { get; set; } = null!; + + public virtual productos idProductoNavigation { get; set; } = null!; +} diff --git a/bdGrupoSanchoToro/db/municipios.cs b/bdGrupoSanchoToro/db/municipios.cs index 54302a5..523024f 100644 --- a/bdGrupoSanchoToro/db/municipios.cs +++ b/bdGrupoSanchoToro/db/municipios.cs @@ -27,7 +27,7 @@ public partial class municipios public virtual ICollection entidades { get; set; } = new List(); - public virtual ICollection eventos { get; set; } = new List(); - public virtual ICollection facturas { get; set; } = new List(); + + public virtual ICollection obras { get; set; } = new List(); } diff --git a/bdGrupoSanchoToro/db/eventos.cs b/bdGrupoSanchoToro/db/obras.cs similarity index 94% rename from bdGrupoSanchoToro/db/eventos.cs rename to bdGrupoSanchoToro/db/obras.cs index a2186d7..8380bdc 100644 --- a/bdGrupoSanchoToro/db/eventos.cs +++ b/bdGrupoSanchoToro/db/obras.cs @@ -5,9 +5,9 @@ using PropertyChanged; namespace bdGrupoSanchoToro.db; [AddINotifyPropertyChangedInterface] -public partial class eventos +public partial class obras { - public int idEvento { get; set; } + public int idObra { get; set; } public string Descripcion { get; set; } = null!; diff --git a/bdGrupoSanchoToro/db/presupuestos.cs b/bdGrupoSanchoToro/db/presupuestos.cs index 5913289..d73803b 100644 --- a/bdGrupoSanchoToro/db/presupuestos.cs +++ b/bdGrupoSanchoToro/db/presupuestos.cs @@ -15,7 +15,7 @@ public partial class presupuestos public int idCliente { get; set; } - public int? idEvento { get; set; } + public int? idObra { get; set; } public double ImporteBruto { get; set; } @@ -37,14 +37,6 @@ public partial class presupuestos public double Kilometros { get; set; } - public DateOnly? FechaInicioEvento { get; set; } - - public DateOnly? FechaFinEvento { get; set; } - - public DateOnly? FechaMontaje { get; set; } - - public DateOnly? FechaDesmontaje { get; set; } - public virtual ICollection albaranes { get; set; } = new List(); public virtual ICollection detallepresupuesto { get; set; } = new List(); @@ -55,7 +47,7 @@ public partial class presupuestos public virtual ficheros? idDatosClienteOriginalNavigation { get; set; } - public virtual eventos? idEventoNavigation { get; set; } + public virtual obras? idObraNavigation { get; set; } public virtual usuarios? idUsuarioNavigation { get; set; } } diff --git a/bdGrupoSanchoToro/db/productos.cs b/bdGrupoSanchoToro/db/productos.cs index 4f3c3b3..c238b98 100644 --- a/bdGrupoSanchoToro/db/productos.cs +++ b/bdGrupoSanchoToro/db/productos.cs @@ -15,15 +15,13 @@ public partial class productos public string Descripcion { get; set; } = null!; - public int? idFamilia { get; set; } + public int idFamilia { get; set; } public int? idTipoHomologacion { get; set; } - public bool? Servicio { get; set; } - public string? ReferenciaFabrica { get; set; } - public int? Tipo { get; set; } + public int Tipo { get; set; } public string? CodigoBarras { get; set; } @@ -51,8 +49,6 @@ public partial class productos public string? Observaciones { get; set; } - public int? idEmpresa { get; set; } - public double? UltimoPrecioCoste { get; set; } public double? UltimoPrecioCompra { get; set; } @@ -77,8 +73,16 @@ public partial class productos public double? PrecioVenta { get; set; } + public string? UnidadesPorEmpresa { get; set; } + + public bool? FacturarComoVentaPorDefecto { get; set; } + public virtual ICollection articulos { get; set; } = new List(); + public virtual ICollection desgloseproductosidProductoNavigation { get; set; } = new List(); + + public virtual ICollection desgloseproductosidProductoPadreNavigation { get; set; } = new List(); + public virtual ICollection desglosetiposofertas { get; set; } = new List(); public virtual ICollection detallepresupuesto { get; set; } = new List(); @@ -89,9 +93,7 @@ public partial class productos public virtual ICollection detallesfacturasrecibidas { get; set; } = new List(); - public virtual empresas? idEmpresaNavigation { get; set; } - - public virtual familias? idFamiliaNavigation { get; set; } + public virtual familias idFamiliaNavigation { get; set; } = null!; public virtual marcas? idMarcaNavigation { get; set; } @@ -99,6 +101,10 @@ public partial class productos public virtual usuarios? idUsuarioModificadorNavigation { get; set; } + public virtual ICollection modelospermitidosidModeloGruaNavigation { get; set; } = new List(); + + public virtual ICollection modelospermitidosidProductoNavigation { get; set; } = new List(); + public virtual ICollection stocks { get; set; } = new List(); public virtual ICollection tablaalturas { get; set; } = new List(); diff --git a/bdGrupoSanchoToro/db/usuarios.cs b/bdGrupoSanchoToro/db/usuarios.cs index 00c4601..2b562ed 100644 --- a/bdGrupoSanchoToro/db/usuarios.cs +++ b/bdGrupoSanchoToro/db/usuarios.cs @@ -35,6 +35,8 @@ public partial class usuarios public virtual ICollection correos { get; set; } = new List(); + public virtual ICollection detallesalbaranes { get; set; } = new List(); + public virtual ICollection documentosfacturas { get; set; } = new List(); public virtual ICollection documentosfacturasrecibidas { get; set; } = new List(); @@ -45,8 +47,6 @@ public partial class usuarios public virtual ICollection entidadesidUsuarioModificadorNavigation { get; set; } = new List(); - public virtual ICollection eventos { get; set; } = new List(); - public virtual ICollection expedientesarticulos { get; set; } = new List(); public virtual ICollection expedientesentidades { get; set; } = new List(); @@ -67,6 +67,8 @@ public partial class usuarios public virtual ICollection movimientoscajaidUsuarioSupervisaNavigation { get; set; } = new List(); + public virtual ICollection obras { get; set; } = new List(); + public virtual ICollection presupuestos { get; set; } = new List(); public virtual ICollection productosidUsuarioCreadorNavigation { get; set; } = new List(); diff --git a/bdGrupoSanchoToro/db/v_albaranesextendidos.cs b/bdGrupoSanchoToro/db/v_albaranesextendidos.cs index 92d6d4e..04c0c73 100644 --- a/bdGrupoSanchoToro/db/v_albaranesextendidos.cs +++ b/bdGrupoSanchoToro/db/v_albaranesextendidos.cs @@ -65,23 +65,25 @@ public partial class v_albaranesextendidos public int? idEntidad { get; set; } - public int? idEvento { get; set; } + public int idEmpresa { get; set; } - public string? DescripcionEvento { get; set; } + public int? idObra { get; set; } - public string? Telefono1Evento { get; set; } + public string? DescripcionObra { get; set; } - public string? Telefono2Evento { get; set; } + public string? Telefono1Obra { get; set; } - public string? PersonaContactoEvento { get; set; } + public string? Telefono2Obra { get; set; } - public string? DireccionEvento { get; set; } + public string? PersonaContactoObra { get; set; } - public string? CodigoPostalEvento { get; set; } + public string? DireccionObra { get; set; } - public string? CodigoMunicipioEvento { get; set; } + public string? CodigoPostalObra { get; set; } - public string? ObservacionesEvento { get; set; } + public string? CodigoMunicipioObra { get; set; } + + public string? ObservacionesObra { get; set; } public string? NIF { get; set; } diff --git a/bdGrupoSanchoToro/dbcontext/GrupoSanchoToroContext.cs b/bdGrupoSanchoToro/dbcontext/GrupoSanchoToroContext.cs index f41c979..000b402 100644 --- a/bdGrupoSanchoToro/dbcontext/GrupoSanchoToroContext.cs +++ b/bdGrupoSanchoToro/dbcontext/GrupoSanchoToroContext.cs @@ -52,6 +52,8 @@ public partial class GrupoSanchoToroContext : DbContext public virtual DbSet cuentascorreo { get; set; } + public virtual DbSet desgloseproductos { get; set; } + public virtual DbSet desglosetiposofertas { get; set; } public virtual DbSet detallepresupuesto { get; set; } @@ -76,8 +78,6 @@ public partial class GrupoSanchoToroContext : DbContext public virtual DbSet enumeraciones { get; set; } - public virtual DbSet eventos { get; set; } - public virtual DbSet expedientesarticulos { get; set; } public virtual DbSet expedientesentidades { get; set; } @@ -112,12 +112,16 @@ public partial class GrupoSanchoToroContext : DbContext public virtual DbSet menus { get; set; } + public virtual DbSet modelospermitidos { get; set; } + public virtual DbSet movimientosbancarios { get; set; } public virtual DbSet movimientoscaja { get; set; } public virtual DbSet municipios { get; set; } + public virtual DbSet obras { get; set; } + public virtual DbSet permisos { get; set; } public virtual DbSet plantillas { get; set; } @@ -170,6 +174,8 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idAlmacenDestino, "albaranes_almacenes02_idx"); + entity.HasIndex(e => e.idEmpresa, "albaranes_empresas_idx"); + entity.HasIndex(e => e.idEntidad, "albaranes_entidades_idx"); entity.HasIndex(e => e.CodigoMunicipioCarga, "albaranes_municipios01_idx"); @@ -255,6 +261,10 @@ public partial class GrupoSanchoToroContext : DbContext .HasForeignKey(d => d.idAlmacenOrigen) .HasConstraintName("albaranes_almacenes01"); + entity.HasOne(d => d.idEmpresaNavigation).WithMany(p => p.albaranes) + .HasForeignKey(d => d.idEmpresa) + .HasConstraintName("albaranes_empresas"); + entity.HasOne(d => d.idEntidadNavigation).WithMany(p => p.albaranes) .HasForeignKey(d => d.idEntidad) .HasConstraintName("albaranes_entidades"); @@ -400,10 +410,7 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idProveedor, "articulos_proveedores_idx"); - entity.Property(e => e.CodigoArticulo) - .HasMaxLength(10) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); + entity.Property(e => e.CodigoArticulo).HasMaxLength(20); entity.Property(e => e.Matricula).HasMaxLength(20); entity.Property(e => e.NumeroSerie) .HasMaxLength(40) @@ -809,6 +816,27 @@ public partial class GrupoSanchoToroContext : DbContext .HasConstraintName("cuentascorreos_empresas"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.idDesglose).HasName("PRIMARY"); + + entity.HasIndex(e => e.idProducto, "productos01_hijo_idx"); + + entity.HasIndex(e => e.idProductoPadre, "productosPadre_01_idx"); + + entity.Property(e => e.DescripcionAdicional) + .HasMaxLength(60) + .UseCollation("utf8mb4_0900_as_ci"); + + entity.HasOne(d => d.idProductoNavigation).WithMany(p => p.desgloseproductosidProductoNavigation) + .HasForeignKey(d => d.idProducto) + .HasConstraintName("productos01_hijo"); + + entity.HasOne(d => d.idProductoPadreNavigation).WithMany(p => p.desgloseproductosidProductoPadreNavigation) + .HasForeignKey(d => d.idProductoPadre) + .HasConstraintName("productos00_padre"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.idDesglose).HasName("PRIMARY"); @@ -836,17 +864,33 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idProducto, "detallepresupuesto_productos_idx"); + entity.HasIndex(e => e.idDesgloseProducto, "detallespresupuesto_desgloseproductos_idx"); + + entity.HasIndex(e => e.idDetallePresupuestoPadre, "detallespresupuesto_detallespresupuestos_idx"); + entity.Property(e => e.Cantidad).HasDefaultValueSql("'1'"); entity.Property(e => e.Observaciones) .HasMaxLength(255) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); + .UseCollation("utf8mb4_0900_as_ci"); + entity.Property(e => e.Parametros) + .HasMaxLength(100) + .UseCollation("utf8mb4_0900_as_ci"); entity.HasOne(d => d.idArticuloNavigation).WithMany(p => p.detallepresupuesto) .HasForeignKey(d => d.idArticulo) .OnDelete(DeleteBehavior.SetNull) .HasConstraintName("detallepresupuesto_articulos"); + entity.HasOne(d => d.idDesgloseProductoNavigation).WithMany(p => p.detallepresupuesto) + .HasForeignKey(d => d.idDesgloseProducto) + .OnDelete(DeleteBehavior.SetNull) + .HasConstraintName("detallespresupuesto_desgloseproductos"); + + entity.HasOne(d => d.idDetallePresupuestoPadreNavigation).WithMany(p => p.InverseidDetallePresupuestoPadreNavigation) + .HasForeignKey(d => d.idDetallePresupuestoPadre) + .OnDelete(DeleteBehavior.Cascade) + .HasConstraintName("detallespresupuesto_detallespresupuestos"); + entity.HasOne(d => d.idPresupuestoNavigation).WithMany(p => p.detallepresupuesto) .HasForeignKey(d => d.idPresupuesto) .HasConstraintName("detallespresupuesto_presupuestos"); @@ -871,6 +915,12 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idProducto, "detallesalbaranes_productos_idx"); + entity.HasIndex(e => e.idUsuarioQueCancela, "detallesalbaranes_usuarios_idx"); + + entity.Property(e => e.FechaCancelacion).HasColumnType("datetime"); + entity.Property(e => e.MotivoCancelacion).HasMaxLength(100); + entity.Property(e => e.Observaciones).HasMaxLength(100); + entity.HasOne(d => d.idAlbaranNavigation).WithMany(p => p.detallesalbaranesidAlbaranNavigation) .HasForeignKey(d => d.idAlbaran) .HasConstraintName("detallesalbaranes_albaranes"); @@ -894,13 +944,18 @@ public partial class GrupoSanchoToroContext : DbContext .HasForeignKey(d => d.idUltimaFactura) .OnDelete(DeleteBehavior.SetNull) .HasConstraintName("detallesalbaranes_facturas"); + + entity.HasOne(d => d.idUsuarioQueCancelaNavigation).WithMany(p => p.detallesalbaranes) + .HasForeignKey(d => d.idUsuarioQueCancela) + .OnDelete(DeleteBehavior.Cascade) + .HasConstraintName("detallesalbaranes_usuarios"); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.idDetalle).HasName("PRIMARY"); - entity.HasIndex(e => e.idDetallePresupuesto, "detallesfacturas_detallespresupuestos_idx"); + entity.HasIndex(e => e.idDetallePresupuesto, "detallesfacturas_detallepresupuestos_idx"); entity.HasIndex(e => e.idFactura, "detallesfacturas_facturas_idx"); @@ -918,7 +973,7 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasOne(d => d.idDetallePresupuestoNavigation).WithMany(p => p.detallesfacturas) .HasForeignKey(d => d.idDetallePresupuesto) .OnDelete(DeleteBehavior.SetNull) - .HasConstraintName("detallesfacturas_detallespresupuestos"); + .HasConstraintName("detallesfacturas_detallepresupuestos"); entity.HasOne(d => d.idDetalleRTFNavigation).WithMany(p => p.detallesfacturas) .HasForeignKey(d => d.idDetalleRTF) @@ -1078,14 +1133,14 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.Descripcion, "Descripcion_UNIQUE").IsUnique(); - entity.HasIndex(e => e.idEmpresa, "ejercicioscontables_empresas_idx"); + entity.HasIndex(e => e.idEmpresa, "ejercicioscontables_empresascontables_idx"); entity.Property(e => e.Descripcion).HasMaxLength(40); entity.Property(e => e.NivelesCuentas).HasMaxLength(20); entity.HasOne(d => d.idEmpresaNavigation).WithMany(p => p.ejercicioscontables) .HasForeignKey(d => d.idEmpresa) - .HasConstraintName("ejercicioscontables_empresas"); + .HasConstraintName("ejercicioscontables_empresascontables"); }); modelBuilder.Entity(entity => @@ -1280,70 +1335,6 @@ public partial class GrupoSanchoToroContext : DbContext .HasConstraintName("enumeraciones_gruposenumeraciones"); }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.idEvento).HasName("PRIMARY"); - - entity.HasIndex(e => new { e.idEntidad, e.Descripcion }, "eventos_descripcion_unique").IsUnique(); - - entity.HasIndex(e => e.idEntidad, "obras_entidades_idx"); - - entity.HasIndex(e => e.CodigoMunicipio, "obras_municipios_idx"); - - entity.HasIndex(e => e.idUsuario, "obras_usuarios_idx"); - - entity.Property(e => e.CodigoMunicipio) - .HasMaxLength(10) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); - entity.Property(e => e.CodigoPostal) - .HasMaxLength(10) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); - entity.Property(e => e.Descripcion) - .HasMaxLength(200) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); - entity.Property(e => e.Direccion) - .HasMaxLength(200) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); - entity.Property(e => e.Email) - .HasMaxLength(100) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); - entity.Property(e => e.Observaciones) - .HasMaxLength(200) - .UseCollation("utf8mb3_general_ci") - .HasCharSet("utf8mb3"); - entity.Property(e => e.PersonaContacto) - .HasMaxLength(80) - .UseCollation("latin1_swedish_ci") - .HasCharSet("latin1"); - entity.Property(e => e.Telefono1) - .HasMaxLength(20) - .UseCollation("latin1_swedish_ci") - .HasCharSet("latin1"); - entity.Property(e => e.Telefono2) - .HasMaxLength(20) - .UseCollation("latin1_swedish_ci") - .HasCharSet("latin1"); - - entity.HasOne(d => d.CodigoMunicipioNavigation).WithMany(p => p.eventos) - .HasForeignKey(d => d.CodigoMunicipio) - .OnDelete(DeleteBehavior.SetNull) - .HasConstraintName("destinosmontajes_municipios"); - - entity.HasOne(d => d.idEntidadNavigation).WithMany(p => p.eventos) - .HasForeignKey(d => d.idEntidad) - .OnDelete(DeleteBehavior.Cascade) - .HasConstraintName("destinosmontajes_entidades"); - - entity.HasOne(d => d.idUsuarioNavigation).WithMany(p => p.eventos) - .HasForeignKey(d => d.idUsuario) - .HasConstraintName("destinosmontajes_usuarios"); - }); - modelBuilder.Entity(entity => { entity.HasKey(e => e.idExpediente).HasName("PRIMARY"); @@ -1436,7 +1427,7 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idCliente, "facturas_clientes_idx"); - entity.HasIndex(e => e.idEvento, "facturas_eventos_idx"); + entity.HasIndex(e => e.idObra, "facturas_eventos_idx"); entity.HasIndex(e => e.FechaEnvioAsesoria, "facturas_fechaenvioasesoria"); @@ -1501,10 +1492,10 @@ public partial class GrupoSanchoToroContext : DbContext .OnDelete(DeleteBehavior.SetNull) .HasConstraintName("facturas_DatosOriginales"); - entity.HasOne(d => d.idEventoNavigation).WithMany(p => p.facturas) - .HasForeignKey(d => d.idEvento) + entity.HasOne(d => d.idObraNavigation).WithMany(p => p.facturas) + .HasForeignKey(d => d.idObra) .OnDelete(DeleteBehavior.SetNull) - .HasConstraintName("facturas_eventos"); + .HasConstraintName("facturas_obras"); entity.HasOne(d => d.idSerieFacturaNavigation).WithMany(p => p.facturas) .HasForeignKey(d => d.idSerieFactura) @@ -1827,6 +1818,23 @@ public partial class GrupoSanchoToroContext : DbContext .HasConstraintName("menus_permisos"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.idModeloPermitido).HasName("PRIMARY"); + + entity.HasIndex(e => e.idModeloGrua, "modelospermiticos__idx"); + + entity.HasIndex(e => e.idProducto, "modelospermitidos_productos_idx"); + + entity.HasOne(d => d.idModeloGruaNavigation).WithMany(p => p.modelospermitidosidModeloGruaNavigation) + .HasForeignKey(d => d.idModeloGrua) + .HasConstraintName("modelospermiticos_modelosgruas"); + + entity.HasOne(d => d.idProductoNavigation).WithMany(p => p.modelospermitidosidProductoNavigation) + .HasForeignKey(d => d.idProducto) + .HasConstraintName("modelospermitidos_productos"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.idMovimientoBancario).HasName("PRIMARY"); @@ -1972,6 +1980,70 @@ public partial class GrupoSanchoToroContext : DbContext .HasConstraintName("municipios_provincias"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.idObra).HasName("PRIMARY"); + + entity.HasIndex(e => new { e.idEntidad, e.Descripcion }, "eventos_descripcion_unique").IsUnique(); + + entity.HasIndex(e => e.idEntidad, "obras_entidades_idx"); + + entity.HasIndex(e => e.CodigoMunicipio, "obras_municipios_idx"); + + entity.HasIndex(e => e.idUsuario, "obras_usuarios_idx"); + + entity.Property(e => e.CodigoMunicipio) + .HasMaxLength(10) + .UseCollation("utf8mb3_general_ci") + .HasCharSet("utf8mb3"); + entity.Property(e => e.CodigoPostal) + .HasMaxLength(10) + .UseCollation("utf8mb3_general_ci") + .HasCharSet("utf8mb3"); + entity.Property(e => e.Descripcion) + .HasMaxLength(200) + .UseCollation("utf8mb3_general_ci") + .HasCharSet("utf8mb3"); + entity.Property(e => e.Direccion) + .HasMaxLength(200) + .UseCollation("utf8mb3_general_ci") + .HasCharSet("utf8mb3"); + entity.Property(e => e.Email) + .HasMaxLength(100) + .UseCollation("utf8mb3_general_ci") + .HasCharSet("utf8mb3"); + entity.Property(e => e.Observaciones) + .HasMaxLength(200) + .UseCollation("utf8mb3_general_ci") + .HasCharSet("utf8mb3"); + entity.Property(e => e.PersonaContacto) + .HasMaxLength(80) + .UseCollation("latin1_swedish_ci") + .HasCharSet("latin1"); + entity.Property(e => e.Telefono1) + .HasMaxLength(20) + .UseCollation("latin1_swedish_ci") + .HasCharSet("latin1"); + entity.Property(e => e.Telefono2) + .HasMaxLength(20) + .UseCollation("latin1_swedish_ci") + .HasCharSet("latin1"); + + entity.HasOne(d => d.CodigoMunicipioNavigation).WithMany(p => p.obras) + .HasForeignKey(d => d.CodigoMunicipio) + .HasConstraintName("obra_municipios"); + + entity.HasOne(d => d.idEntidadNavigation).WithMany(p => p.obras) + .HasForeignKey(d => d.idEntidad) + .OnDelete(DeleteBehavior.Cascade) + .HasConstraintName("obras_entidades"); + + entity.HasOne(d => d.idUsuarioNavigation).WithMany(p => p.obras) + .HasForeignKey(d => d.idUsuario) + .OnDelete(DeleteBehavior.SetNull) + .HasConstraintName("obra_usuarios"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.idPermiso).HasName("PRIMARY"); @@ -2047,7 +2119,7 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idCliente, "presupuestos_clientes_idx"); - entity.HasIndex(e => e.idEvento, "presupuestos_obras_idx"); + entity.HasIndex(e => e.idObra, "presupuestos_obras_idx"); entity.HasIndex(e => e.idUsuario, "presupuestos_usuarios_idx"); @@ -2066,10 +2138,10 @@ public partial class GrupoSanchoToroContext : DbContext .OnDelete(DeleteBehavior.SetNull) .HasConstraintName("presupuestos_DatosOriginales"); - entity.HasOne(d => d.idEventoNavigation).WithMany(p => p.presupuestos) - .HasForeignKey(d => d.idEvento) + entity.HasOne(d => d.idObraNavigation).WithMany(p => p.presupuestos) + .HasForeignKey(d => d.idObra) .OnDelete(DeleteBehavior.SetNull) - .HasConstraintName("presupuestos_eventos"); + .HasConstraintName("presupuestos_obras"); entity.HasOne(d => d.idUsuarioNavigation).WithMany(p => p.presupuestos) .HasForeignKey(d => d.idUsuario) @@ -2137,8 +2209,6 @@ public partial class GrupoSanchoToroContext : DbContext entity.HasIndex(e => e.idUsuarioModificador, "productos_02_usuarios_idx"); - entity.HasIndex(e => e.idEmpresa, "productos_empresas_idx"); - entity.HasIndex(e => e.idFamilia, "productos_familias_idx"); entity.HasIndex(e => e.idMarca, "productos_marcas_idx"); @@ -2150,6 +2220,7 @@ public partial class GrupoSanchoToroContext : DbContext .UseCollation("latin1_swedish_ci") .HasCharSet("latin1"); entity.Property(e => e.DescripcionAbreviada).HasMaxLength(45); + entity.Property(e => e.FacturarComoVentaPorDefecto).HasDefaultValueSql("b'0'"); entity.Property(e => e.FechaBaja).HasColumnType("datetime"); entity.Property(e => e.Modelo).HasMaxLength(50); entity.Property(e => e.Observaciones) @@ -2159,14 +2230,11 @@ public partial class GrupoSanchoToroContext : DbContext entity.Property(e => e.PrecioVenta).HasDefaultValueSql("'0'"); entity.Property(e => e.PrefijoNumeroSerie).HasMaxLength(8); entity.Property(e => e.ReferenciaFabrica).HasMaxLength(45); - - entity.HasOne(d => d.idEmpresaNavigation).WithMany(p => p.productos) - .HasForeignKey(d => d.idEmpresa) - .OnDelete(DeleteBehavior.Cascade) - .HasConstraintName("productos_empresas"); + entity.Property(e => e.UnidadesPorEmpresa).HasColumnType("json"); entity.HasOne(d => d.idFamiliaNavigation).WithMany(p => p.productos) .HasForeignKey(d => d.idFamilia) + .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("productos_familias"); entity.HasOne(d => d.idMarcaNavigation).WithMany(p => p.productos) @@ -2398,7 +2466,7 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(10) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.CodigoMunicipioEvento) + entity.Property(e => e.CodigoMunicipioObra) .HasMaxLength(10) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); @@ -2410,7 +2478,7 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(10) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.CodigoPostalEvento) + entity.Property(e => e.CodigoPostalObra) .HasMaxLength(10) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); @@ -2422,11 +2490,11 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(100) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.DescripcionEvento) + entity.Property(e => e.DescripcionObra) .HasMaxLength(200) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.DireccionEvento) + entity.Property(e => e.DireccionObra) .HasMaxLength(200) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); @@ -2456,11 +2524,11 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(20) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.ObservacionesEvento) + entity.Property(e => e.ObservacionesObra) .HasMaxLength(200) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.PersonaContactoEvento) + entity.Property(e => e.PersonaContactoObra) .HasMaxLength(80) .UseCollation("latin1_swedish_ci") .HasCharSet("latin1"); @@ -2480,7 +2548,7 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(30) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.Telefono1Evento) + entity.Property(e => e.Telefono1Obra) .HasMaxLength(20) .UseCollation("latin1_swedish_ci") .HasCharSet("latin1"); @@ -2496,7 +2564,7 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(30) .UseCollation("utf8mb3_general_ci") .HasCharSet("utf8mb3"); - entity.Property(e => e.Telefono2Evento) + entity.Property(e => e.Telefono2Obra) .HasMaxLength(20) .UseCollation("latin1_swedish_ci") .HasCharSet("latin1"); @@ -2504,7 +2572,7 @@ public partial class GrupoSanchoToroContext : DbContext .HasMaxLength(100) .UseCollation("latin1_swedish_ci") .HasCharSet("latin1"); - entity.Property(e => e.idEvento).HasDefaultValueSql("'0'"); + entity.Property(e => e.idObra).HasDefaultValueSql("'0'"); }); modelBuilder.Entity(entity => diff --git a/bdGrupoSanchoToro/dbcontext/conexion.cs b/bdGrupoSanchoToro/dbcontext/conexion.cs index 4b8bc4d..785281c 100644 --- a/bdGrupoSanchoToro/dbcontext/conexion.cs +++ b/bdGrupoSanchoToro/dbcontext/conexion.cs @@ -60,7 +60,7 @@ namespace bdGrupoSanchoToro.dbcontext { try { - // optionsBuilder.UseMySql("server=GrupoSanchoToro;database=GrupoSanchoToro;port=13306;uid=m3soft;pwd=Romian2023--;persistsecurityinfo=True;TreatTinyAsBoolean=True;allowuservariables=True", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.2.0-mysql")); + // optionsBuilder.UseMySql("server=GrupoSanchoToro;database=GrupoSanchoToro;port=13306;uid=m3soft;pwd=SanchoToro2023--;persistsecurityinfo=True;TreatTinyAsBoolean=True;allowuservariables=True", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.2.0-mysql")); string cs = @";persistsecurityinfo=True;TreatTinyAsBoolean=False;allowuservariables=True"; var lc = ListaConexiones(); diff --git a/bdGrupoSanchoToro/dbcontext/tscGrupoSanchoToro.cs b/bdGrupoSanchoToro/dbcontext/tscGrupoSanchoToro.cs index 50942c1..900f2ab 100644 --- a/bdGrupoSanchoToro/dbcontext/tscGrupoSanchoToro.cs +++ b/bdGrupoSanchoToro/dbcontext/tscGrupoSanchoToro.cs @@ -46,7 +46,7 @@ namespace bdGrupoSanchoToro }); private static string? ConexionPorDefecto=null; - public static tscGrupoSanchoToro NuevoContexto(string NombreConexion = "" ,bool Lazy = true, bool SoloLectura = false, bool ConEventoSavingChanges = false, string aplicaciones = "") + public static tscGrupoSanchoToro NuevoContexto(string NombreConexion = "" ,bool Lazy = true, bool SoloLectura = false, bool ConObraSavingChanges = false, string aplicaciones = "") { @@ -71,7 +71,7 @@ namespace bdGrupoSanchoToro var Opciones = ob.Options; tscGrupoSanchoToro bd = new tscGrupoSanchoToro(Opciones); bd.Aplicaciones = aplicaciones; - if (ConEventoSavingChanges) bd.SavingChanges += GuardandoCambios; + if (ConObraSavingChanges) bd.SavingChanges += GuardandoCambios; return bd; } diff --git a/bdGrupoSanchoToro/efpt.config.json b/bdGrupoSanchoToro/efpt.config.json index 59ecfd4..99bb4f3 100644 --- a/bdGrupoSanchoToro/efpt.config.json +++ b/bdGrupoSanchoToro/efpt.config.json @@ -95,6 +95,10 @@ "Name": "cuentascorreo", "ObjectType": 0 }, + { + "Name": "desgloseproductos", + "ObjectType": 0 + }, { "Name": "desglosetiposofertas", "ObjectType": 0 @@ -143,10 +147,6 @@ "Name": "enumeraciones", "ObjectType": 0 }, - { - "Name": "eventos", - "ObjectType": 0 - }, { "Name": "expedientesarticulos", "ObjectType": 0 @@ -215,6 +215,10 @@ "Name": "menus", "ObjectType": 0 }, + { + "Name": "modelospermitidos", + "ObjectType": 0 + }, { "Name": "movimientosbancarios", "ObjectType": 0 @@ -227,6 +231,10 @@ "Name": "municipios", "ObjectType": 0 }, + { + "Name": "obras", + "ObjectType": 0 + }, { "Name": "permisos", "ObjectType": 0 diff --git a/bdGrupoSanchoToro/extensiones/DesglosePorEmpresa.cs b/bdGrupoSanchoToro/extensiones/DesglosePorEmpresa.cs new file mode 100644 index 0000000..9e974c9 --- /dev/null +++ b/bdGrupoSanchoToro/extensiones/DesglosePorEmpresa.cs @@ -0,0 +1,46 @@ +using bdGrupoSanchoToro.db; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace bdGrupoSanchoToro.extensiones +{ + public class DesglosePorEmpresa + { + public int Empresa { get; set; } + + public double TotalUnidades { get; set; } + public double UnidadesInicialesOFabricadas { get; set; } + public double UnidadesCompradas { get; set; } + public double UnidadesAlquiladas { get; set; } + public double UnidadesAveriadas { get; set; } + public double UnidadesVendidas { get; set; } + public double UnidadesSubAlquiladas { get; set; } + public double UnidadesDesechadas { get; set; } + + [NotMapped] + [JsonIgnore] + public double UnidadesDisponibles + { + get + { + return this.TotalUnidades - this.UnidadesAlquiladas - this.UnidadesAveriadas; + } + } + [NotMapped] + [JsonIgnore] + public string NombreEmpresa + { + get + { + var emp = empresas.ListadoEmpresas().FirstOrDefault(x => x.idEmpresa == Empresa); + return emp == null ? "" : emp.RazonSocial; + } + } + + } +} diff --git a/bdGrupoSanchoToro/extensiones/desgloseproductos.cs b/bdGrupoSanchoToro/extensiones/desgloseproductos.cs new file mode 100644 index 0000000..7181335 --- /dev/null +++ b/bdGrupoSanchoToro/extensiones/desgloseproductos.cs @@ -0,0 +1,70 @@ +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; + +namespace bdGrupoSanchoToro.db +{ + + public partial class desgloseproductos + { + [NotMapped] + public bool ContieneHijos + { + get + { + if (this.idProductoNavigation is not null && this.idProductoNavigation.desgloseproductosidProductoPadreNavigation is not null) + { + return this.idProductoNavigation.desgloseproductosidProductoPadreNavigation.Any(); + } + else + { + return false; + } + } + } + [NotMapped] + public ICollection Hijos + { + get + { + return this.idProductoNavigation.desgloseproductosidProductoPadreNavigation; + } + } + + + [NotMapped] + public productos ProductoPadre + { + get + { + return this.idProductoPadreNavigation; + } + set + { + this.idProductoPadreNavigation = value; + } + } + [NotMapped] + public productos Producto + { + get + { + return this.idProductoNavigation; + } + set + { + this.idProductoNavigation = value; + } + } + + [NotMapped] + public bool Descatalogado + { + get + { + return idProductoNavigation.Descatalogado; + } + } + + + } +} \ No newline at end of file diff --git a/bdGrupoSanchoToro/extensiones/detallepresupuesto.cs b/bdGrupoSanchoToro/extensiones/detallepresupuesto.cs new file mode 100644 index 0000000..9db5c2f --- /dev/null +++ b/bdGrupoSanchoToro/extensiones/detallepresupuesto.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using System.Data; +using System.Linq; +using System.Runtime.CompilerServices; + +namespace bdGrupoSanchoToro.db +{ + public partial class detallepresupuesto:INotifyPropertyChanged + { + [NotMapped] + public productos? productos + { + get + { + return this.idProductoNavigation; + } + } + + [NotMapped] + public virtual string DescripcionEspecial + { + get + { + string Des = this.idProductoNavigation.Descripcion ; + if (Des.Contains("(")) + { + Des = Des.Split('(')[0]; + } + return Des; + } + } + + + + [NotMapped] + public virtual ICollection? detallepresupuesto1 + { + get + { + return this.InverseidDetallePresupuestoPadreNavigation; + } + } + + public double Importe + { + get + { + // If EsVenta Then + return Math.Round(this.Cantidad * this.Precio, 2, MidpointRounding.AwayFromZero); + // Else + // Return Math.Round(Cantidad * Precio * presupuestos.DiasAlquiler, 2, MidpointRounding.AwayFromZero) + // End If + } + } + [NotMapped] + public bool ContieneHijos + { + get + { + return this.detallepresupuesto1 is not null && this.detallepresupuesto1.Count > 0; + } + } + [NotMapped] + public virtual List DesgloseServicios + { + get + { + return this.detallepresupuesto1.Where(x => x.productos.Tipo == (int)productos.TipoProductoEnum.SERVICIO).ToList(); + } + } + + [NotMapped] + public virtual List DesgloseMaterial + { + get + { + return this.detallepresupuesto1.Where(x => x.productos.Tipo < (int)productos.TipoProductoEnum.SERVICIO).ToList(); + } + } + + + public event PropertyChangedEventHandler? PropertyChanged; + protected void OnPropertyChanged([CallerMemberName] string name = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + public void RefrescaCamposTemporales() + { + this.OnPropertyChanged("Importe"); + this.OnPropertyChanged("ImporteGastos"); + // OnPropertyChanged("NumeroAsientosTotal") + this.OnPropertyChanged("DesgloseServicios"); + this.OnPropertyChanged("DesgloseMaterial"); + } + } +} \ No newline at end of file diff --git a/bdGrupoSanchoToro/extensiones/detallesalbaranes.cs b/bdGrupoSanchoToro/extensiones/detallesalbaranes.cs index 248e51c..32cfdd5 100644 --- a/bdGrupoSanchoToro/extensiones/detallesalbaranes.cs +++ b/bdGrupoSanchoToro/extensiones/detallesalbaranes.cs @@ -1,4 +1,6 @@ using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using static bdGrupoSanchoToro.db.productos; @@ -7,13 +9,32 @@ namespace bdGrupoSanchoToro.db public partial class detallesalbaranes { - //public albaranes albaranes - //{ - // get - // { - // return this.idAlbaranNavigation; - // } - //} + + private double? _UnidadesRecogidasTmp; + + [NotMapped] + public double? UnidadesRecogidasTmp + { + get + { + if (_UnidadesRecogidasTmp.HasValue == false) + _UnidadesRecogidasTmp = Cantidad; + return _UnidadesRecogidasTmp; + } + set + { + _UnidadesRecogidasTmp = value; + } + } + + [NotMapped] + public string Producto + { + get + { + return this.idProductoNavigation.Descripcion; + } + } public string NumeroAlbaran { get @@ -63,45 +84,68 @@ namespace bdGrupoSanchoToro.db return this.idAlbaranNavigation.Entidad; } } - public void ActualizaProducto(bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext bd, int Factor) + public void ActualizaProducto(bdGrupoSanchoToro.tscGrupoSanchoToro bd, albaranes.TipoAlbaranEnum Tipo, int Factor,int Empresa) { try { var pr = bd.productos.First(x => x.idProducto == this.idProducto); - if (pr.Tipo != (int)TipoProductoEnum.SERVICIO ) + 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) + almacenes almo; + almacenes almd; + if (Tipo==albaranes.TipoAlbaranEnum.RECOGIDA || Tipo==albaranes.TipoAlbaranEnum.DEVOLUCION_SUBALQUILER) + { + almo = this.idAlbaranRecogidaNavigation.idAlmacenOrigen.HasValue ? bd.almacenes.First(x => x.idAlmacen == idAlbaranRecogidaNavigation.idAlmacenOrigen) : (almacenes)null; + almd = this.idAlbaranRecogidaNavigation.idAlmacenDestino.HasValue ? bd.almacenes.First(x => x.idAlmacen == this.idAlbaranRecogidaNavigation.idAlmacenDestino) : (almacenes)null; + // Tipo = (albaranes.TipoAlbaranEnum)this.idAlbaranRecogidaNavigation.Tipo; + } + else + { + almo = this.idAlbaranNavigation.idAlmacenOrigen.HasValue ? bd.almacenes.First(x => x.idAlmacen == idAlbaranNavigation.idAlmacenOrigen) : (almacenes)null; + almd = this.idAlbaranNavigation.idAlmacenDestino.HasValue ? bd.almacenes.First(x => x.idAlmacen == this.idAlbaranNavigation.idAlmacenDestino) : (almacenes)null; + // Tipo = (albaranes.TipoAlbaranEnum)this.idAlbaranNavigation.Tipo; + } + switch (Tipo) { case albaranes.TipoAlbaranEnum.COMPRA: + { + this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto); + pr.UnidadesCompradas += this.Cantidad * (double)Factor; + pr.ActualizaUnidades(TipoUnidadesEnum.COMPRADAS, Empresa, this.Cantidad * (double)Factor); + this.ActStockGlobal(bd, pr, (almacenes.TipoAlmacenEnum)almd.Tipo, true, Factor, Empresa); + break; + } + case albaranes.TipoAlbaranEnum.FABRICACION: case albaranes.TipoAlbaranEnum.REGULARIZACION_STOCK: { this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto); pr.UnidadesInicialesOFabricadas += this.Cantidad * (double)Factor; - this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, true, Factor); + pr.ActualizaUnidades(TipoUnidadesEnum.INICIALES_O_FABRICADAS, Empresa, this.Cantidad * (double)Factor); + this.ActStockGlobal(bd, pr, (almacenes.TipoAlmacenEnum)almd.Tipo, true, Factor, Empresa); 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.ActStockGlobal(bd, pr, (almacenes.TipoAlmacenEnum)almo.Tipo, false, Factor * -1, Empresa); this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto); - this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, false, Factor); + this.ActStockGlobal(bd, pr, (almacenes.TipoAlmacenEnum)almd.Tipo, false, Factor, Empresa); 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); + this.ActStockGlobal(bd,pr, (almacenes.TipoAlmacenEnum)almo.Tipo, this.EsVenta, Factor * -1, Empresa); if (this.EsVenta == false) { pr.UnidadesAlquiladas += this.Cantidad * (double)Factor; + pr.ActualizaUnidades(TipoUnidadesEnum.ALQUILADAS, Empresa, this.Cantidad * (double)Factor); } else { pr.UnidadesVendidas += this.Cantidad * (double)Factor; + pr.ActualizaUnidades(TipoUnidadesEnum.VENDIDAS, Empresa, this.Cantidad * (double)Factor); } break; @@ -109,27 +153,29 @@ namespace bdGrupoSanchoToro.db case albaranes.TipoAlbaranEnum.RECOGIDA: { this.ActStockPorAlmacen(bd, Factor, almd.idAlmacen, pr.idProducto); - this.ActStockGlobal(pr, (almacenes.TipoAlmacenEnum)almd.Tipo, false, Factor); + this.ActStockGlobal(bd,pr, (almacenes.TipoAlmacenEnum)almd.Tipo, false, Factor, Empresa); pr.UnidadesAlquiladas += this.Cantidad * (double)Factor * (double)-1; + pr.ActualizaUnidades(TipoUnidadesEnum.ALQUILADAS, Empresa, 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); + this.ActStockGlobal(bd,pr, (almacenes.TipoAlmacenEnum)almd.Tipo, true, Factor, Empresa); pr.UnidadesSubAlquiladas += this.Cantidad * (double)Factor; + pr.ActualizaUnidades(TipoUnidadesEnum.SUBALQUILADAS, Empresa, 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); + this.ActStockGlobal(bd,pr, (almacenes.TipoAlmacenEnum)almo.Tipo, true, Factor * -1, Empresa); pr.UnidadesSubAlquiladas += this.Cantidad * (double)Factor * (double)-1; + pr.ActualizaUnidades(TipoUnidadesEnum.SUBALQUILADAS, Empresa, this.Cantidad * (double)Factor * (double)-1); break; } } - - // bd.SaveChanges() + bd.GuardarCambios(); } } catch (Exception ex) @@ -137,7 +183,7 @@ namespace bdGrupoSanchoToro.db throw new Exception(ex.Message, ex); } } - private void ActStockPorAlmacen(bdGrupoSanchoToro.dbcontext.GrupoSanchoToroContext bd, int Factor, int idAlmacen, int idProducto) + private void ActStockPorAlmacen(bdGrupoSanchoToro.tscGrupoSanchoToro bd, int Factor, int idAlmacen, int idProducto) { try { @@ -151,13 +197,14 @@ namespace bdGrupoSanchoToro.db bd.stocks.Add(st); } st.Unidades += this.Cantidad * (double)Factor; + bd.GuardarCambios(); } catch (Exception ex) { throw new Exception(ex.Message, ex); } } - private void ActStockGlobal(productos pr, almacenes.TipoAlmacenEnum TipoAlmacen, bool ActTotalUnidades, int Factor) + private void ActStockGlobal(bdGrupoSanchoToro.tscGrupoSanchoToro bd, productos pr, almacenes.TipoAlmacenEnum TipoAlmacen, bool ActTotalUnidades, int Factor,int Empresa) { try { @@ -176,7 +223,11 @@ namespace bdGrupoSanchoToro.db } } if (ActTotalUnidades) + { pr.TotalUnidades += this.Cantidad * (double)Factor; + pr.ActualizaUnidades(TipoUnidadesEnum.TOTAL, Empresa, this.Cantidad * (double)Factor); + } + bd.GuardarCambios(); } catch (Exception ex) { diff --git a/bdGrupoSanchoToro/extensiones/empresas.cs b/bdGrupoSanchoToro/extensiones/empresas.cs new file mode 100644 index 0000000..e5c388d --- /dev/null +++ b/bdGrupoSanchoToro/extensiones/empresas.cs @@ -0,0 +1,23 @@ +using PropertyChanged; +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.CompilerServices; +using tsUtilidades.Extensiones; + +namespace bdGrupoSanchoToro.db +{ + public partial class empresas + { + private static List? _ListadoEmpresas; + public static List ListadoEmpresas() + { + if (_ListadoEmpresas == null) + { + var bd= bdGrupoSanchoToro.tscGrupoSanchoToro.NuevoContexto(); + _ListadoEmpresas = bd.empresas.ToList(); + } + return _ListadoEmpresas; + } + } +} \ No newline at end of file diff --git a/bdGrupoSanchoToro/extensiones/facturas.cs b/bdGrupoSanchoToro/extensiones/facturas.cs index 185e435..ba8fdae 100644 --- a/bdGrupoSanchoToro/extensiones/facturas.cs +++ b/bdGrupoSanchoToro/extensiones/facturas.cs @@ -251,35 +251,35 @@ namespace bdGrupoSanchoToro.db [NotMapped] public virtual string? Email2_TMP { get; set; } [NotMapped] public virtual bool EnviarEmail_TMP { get; set; } - #region Eventos + #region Obras [NotMapped] - public string ProvinciaEvento + public string ProvinciaObra { get { - if (this.idEvento == null || this.idEventoNavigation.CodigoMunicipioNavigation == null) return ""; + if (this.idObra == null || this.idObraNavigation.CodigoMunicipioNavigation == null) return ""; else - return this.idEventoNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation.Nombre; + return this.idObraNavigation.CodigoMunicipioNavigation.CodigoProvinciaNavigation.Nombre; } } [NotMapped] - public string PoblacionEvento + public string PoblacionObra { get { - if (this.idEvento == null || this.idEventoNavigation.CodigoMunicipioNavigation == null) return ""; + if (this.idObra == null || this.idObraNavigation.CodigoMunicipioNavigation == null) return ""; else - return this.idEventoNavigation.CodigoMunicipioNavigation.Nombre; + return this.idObraNavigation.CodigoMunicipioNavigation.Nombre; } } [NotMapped] - public string DireccionEvento + public string DireccionObra { get { - if (this.idEvento == null) return ""; + if (this.idObra == null) return ""; else - return this.idEventoNavigation.DireccionCompleta; + return this.idObraNavigation.DireccionCompleta; } } #endregion diff --git a/bdGrupoSanchoToro/extensiones/eventos.cs b/bdGrupoSanchoToro/extensiones/obras.cs similarity index 96% rename from bdGrupoSanchoToro/extensiones/eventos.cs rename to bdGrupoSanchoToro/extensiones/obras.cs index d187a40..eac3a8a 100644 --- a/bdGrupoSanchoToro/extensiones/eventos.cs +++ b/bdGrupoSanchoToro/extensiones/obras.cs @@ -3,7 +3,7 @@ namespace bdGrupoSanchoToro.db { - public partial class eventos + public partial class obras { public string DireccionCompleta { diff --git a/bdGrupoSanchoToro/extensiones/presupuestos.cs b/bdGrupoSanchoToro/extensiones/presupuestos.cs new file mode 100644 index 0000000..444950c --- /dev/null +++ b/bdGrupoSanchoToro/extensiones/presupuestos.cs @@ -0,0 +1,1070 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using static bdGrupoSanchoToro.tscGrupoSanchoToro; +using static bdGrupoSanchoToro.db.productos; +using Microsoft.VisualBasic.CompilerServices; +using static tsUtilidades.Extensiones.StringExtensions; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace bdGrupoSanchoToro.db +{ + + [NotMapped] + public partial class presupuestos:INotifyPropertyChanged + { + + + + + + [NotMapped] + public virtual List DetalleHijos + { + get + { + return detallepresupuesto.Where(x=> !x.idDetallePresupuestoPadre.HasValue).ToList(); + } + } + + + + public obras? Obras + { + get + { + return this.idObraNavigation; + } + } + + [NotMapped] + public virtual List DetalleProductosFinales + { + get + { + var dpf = this.detallepresupuesto.Where(x => x.productos.Tipo == (int)TipoProductoEnum.ELEMENTO_GRUA || x.productos.Tipo <= (int)TipoProductoEnum.OTROS_PRODUCTOS).ToList(); + var ld = new List(); + foreach (var d in dpf) + this.AñadeProductoFinal(d, ld); + return ld; + } + } + + [NotMapped] + public virtual List DetalleServicios + { + get + { + var dpf = this.detallepresupuesto.Where(x => x.productos.Tipo >= (int)TipoProductoEnum.SERVICIO).ToList(); + + var ld = new List(); + foreach (var d in dpf) + this.AñadeProductoFinal(d, ld); + return ld; + } + } + // Private Sub AñadeProductoFinales(d As detallepresupuesto, ld As List(Of DetalleProductoFinal)) + // Dim dp = ld.FirstOrDefault(Function(x) x.idProducto = d.idProducto) + // If dp Is Nothing Then + // dp = New DetalleProductoFinal + // dp.idProducto = d.idProducto + // dp.Cantidad = d.Cantidad + // dp.Importe = d.Importe + // dp.Descripcion = d.productos.Descripcion + // ld.Add(dp) + // Else + // dp.Cantidad += d.Cantidad + // dp.Importe += d.Importe + // End If + // End Sub + + private void AñadeProductoFinal(detallepresupuesto d, List ld) + { + var dp = ld.FirstOrDefault(x => x.idProducto == d.idProductoNavigation.idProducto); + if (dp is null) + { + dp = new DetalleProductoFinal(); + dp.idProducto = d.idProductoNavigation.idProducto; + dp.Tipo = d.idProductoNavigation.DescripcionTipo; + dp.Cantidad = (int)Math.Round(d.Cantidad); + dp.Descripcion = d.productos.Descripcion; + if (d.productos.Tipo != (int)TipoProductoEnum.HERRAMIENTAS) + { + var padre = d.idDetallePresupuestoPadreNavigation; + while (!(padre is null)) + { + dp.Cantidad = (int)Math.Round((double)dp.Cantidad * padre.Cantidad); + dp.Importe = dp.Importe * padre.Cantidad; + padre = padre.idDetallePresupuestoPadreNavigation; + } + } + ld.Add(dp); + } + else if (d.idProductoNavigation.Tipo != (int)TipoProductoEnum.HERRAMIENTAS) + { + double cant = d.Cantidad; + double imp = 0; // d.ImporteGastos; + var padre = d.idDetallePresupuestoPadreNavigation; + while (!(padre is null)) + { + cant = cant * padre.Cantidad; + imp = imp * padre.Cantidad; + padre = padre.idDetallePresupuestoPadreNavigation; + } + dp.Cantidad = (int)Math.Round(dp.Cantidad + cant); + dp.Importe += imp; + } + else + { + dp.Cantidad = (int)Math.Round(Math.Max((double)dp.Cantidad, d.Cantidad)); + } + } + + + [NotMapped] + public virtual string DescripcionTipo + { + get + { + if (this.idPresupuesto == 0) + { + return ""; + } + else if (this.FechaAceptacion.HasValue) + { + return "CONTRATO"; + } + else + { + return "PRESUPUESTO"; + } + } + } + + + + [NotMapped] + public virtual string NumeroPresupuesto + { + get + { + if (this.idPresupuesto == 0) + { + return ""; + } + else if (this.FechaAceptacion.HasValue) + { + return "CT" + (this.FechaPresupuesto.Year % 100).ToString() + "-" + this.idPresupuesto.ToString().PadLeft(6, '0'); + } + else + { + return "PR" + (this.FechaPresupuesto.Year % 100).ToString() + "-" + this.idPresupuesto.ToString().PadLeft(6, '0'); + } + } + } + + [NotMapped] + public virtual List FacturasEmitidas + { + get + { + var df = this.detallepresupuesto.SelectMany(x => x.detallesfacturas).GroupBy(x => x.idFactura); + return df.Select(x => x.FirstOrDefault().idFacturaNavigation).ToList(); + } + } + + + + + public void RefrescaCamposTemporales() + { + this.OnPropertyChanged("DiasAlquiler"); + this.OnPropertyChanged("BaseImponible"); + this.OnPropertyChanged("NumeroPresupuesto"); + this.OnPropertyChanged("DetalleProductosFinales"); + this.OnPropertyChanged("DetalleServicios"); + } + + + protected void OnPropertyChanged([CallerMemberName] string name = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + + #region Cliente + + private int? _TipoImpresionAlbaranEntregaTmp; + [NotMapped] + public virtual int? TipoImpresionAlbaranEntregaTmp + { + get + { + if (_TipoImpresionAlbaranEntregaTmp.HasValue == false) + { + if (this.idClienteNavigation is not null) + { + int rs; + rs = this.idClienteNavigation.TipoImpresionAlbaranEntrega; + _TipoImpresionAlbaranEntregaTmp = rs; + return rs; + } + else + { + return Conversions.ToInteger(false); + } + } + else + { + return _TipoImpresionAlbaranEntregaTmp; + } + } + set + { + _TipoImpresionAlbaranEntregaTmp = value; + if (this.idClienteNavigation is not null && value.HasValue) + { + this.idClienteNavigation.TipoImpresionAlbaranEntrega = (int)value; + } + this.OnPropertyChanged("TipoImpresionAlbaranEntregaTmp"); + } + } + + + + private bool _NIFClienteTmpEsNulo = true; + private string _NIFClienteTmp; + [NotMapped] + public string NIFClienteTmp + { + get + { + if (_NIFClienteTmpEsNulo) + { + if (this.idClienteNavigation is null) + { + return ""; + } + else + { + _NIFClienteTmp = this.idClienteNavigation.NIF; + _NIFClienteTmpEsNulo = false; + return this.idClienteNavigation.NIF; + } + } + else + { + return _NIFClienteTmp; + } + // If Me.entidades Is Nothing Then + // If _NIFClienteTmpEsNulo Then + // Return "" + // Else + // Return _NIFClienteTmp + // End If + // Else + // Return Me.entidades.NIF + // End If + } + set + { + _NIFClienteTmp = value; + _NIFClienteTmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + if (string.IsNullOrEmpty(value.NothingAVacio())) + { + this.idClienteNavigation.NIF = (string)null; + } + else + { + this.idClienteNavigation.NIF = value; + } + RefrescaCamposSoloLectura(); + } + } + } + public void RefrescaCamposSoloLectura() + { + + this.OnPropertyChanged("NIFClienteTmp"); + this.OnPropertyChanged("RazonSocialClienteTmp"); + this.OnPropertyChanged("CodigoPostalClienteTmp"); + this.OnPropertyChanged("DomicilioClienteTmp"); + this.OnPropertyChanged("CodigoPoblacionClienteTmp"); + this.OnPropertyChanged("PoblacionClienteTmp"); + this.OnPropertyChanged("ProvinciaClienteTmp"); + this.OnPropertyChanged("TelefonoCliente1Tmp"); + this.OnPropertyChanged("TelefonoCliente2Tmp"); + this.OnPropertyChanged("EmailClienteTmp"); + this.OnPropertyChanged("TipoImpresionAlbaranEntregaTmp"); + this.OnPropertyChanged("Advertencias"); + this.OnPropertyChanged("PendientePago"); + this.OnPropertyChanged("NumeroPresupuesto"); + + } + + private bool _RazonSocialClienteTmpEsNulo = true; + private string _RazonSocialClienteTmp; + [NotMapped] + public virtual string RazonSocialClienteTmp + { + get + { + if (_RazonSocialClienteTmpEsNulo) + { + if (this.idClienteNavigation is not null) + { + string rs; + rs = this.idClienteNavigation.RazonSocial; + _RazonSocialClienteTmpEsNulo = false; + _RazonSocialClienteTmp = rs; + return rs; + } + else + { + return ""; + } + } + + else + { + return _RazonSocialClienteTmp; + } + } + set + { + _RazonSocialClienteTmp = value; + _RazonSocialClienteTmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.RazonSocial = value; + } + this.OnPropertyChanged("RazonSocialClienteTmp"); + } + } + private bool _CodigoPostalClienteTmpEsNulo = true; + private string _CodigoPostalClienteTmp; + [NotMapped] + public virtual string CodigoPostalClienteTmp + { + get + { + if (_CodigoPostalClienteTmpEsNulo) + { + if (this.idClienteNavigation is not null) + { + _CodigoPostalClienteTmp = this.idClienteNavigation.CodigoPostal; + _CodigoPostalClienteTmpEsNulo = false; + return this.idClienteNavigation.CodigoPostal; + } + else + { + return ""; + } + } + else + { + return _CodigoPostalClienteTmp; + } + + } + set + { + _CodigoPostalClienteTmp = value; + _CodigoPostalClienteTmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.CodigoPostal = value; + } + this.OnPropertyChanged("CodigoPostalClienteTmp"); + } + } + + private bool _DomicilioClienteTmpEsNulo = true; + private string _DomicilioClienteTmp; + [NotMapped] + public virtual string DomicilioClienteTmp + { + get + { + if (_DomicilioClienteTmpEsNulo) + { + if (this.idClienteNavigation is not null) + { + _DomicilioClienteTmp = this.idClienteNavigation.Direccion.NothingAVacio(); + _DomicilioClienteTmpEsNulo = false; + return this.idClienteNavigation.Direccion; + } + else + { + return ""; + } + } + else + { + return _DomicilioClienteTmp; + } + } + set + { + _DomicilioClienteTmp = value; + _DomicilioClienteTmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.Direccion = value; + } + this.OnPropertyChanged("DomicilioClienteTmp"); + } + } + + + private bool _CodigoPoblacionClienteTmpEsNulo = true; + private string _CodigoPoblacionClienteTmp; + + [NotMapped] + public virtual string CodigoPoblacionClienteTmp + { + get + { + if (_CodigoPoblacionClienteTmpEsNulo) + { + if (this.idClienteNavigation is null) + { + if (this.idClienteNavigation is not null && this.idClienteNavigation.CodigoMunicipioNavigation is null) + { + if (!string.IsNullOrEmpty(this.idClienteNavigation.CodigoPostal.NothingAVacio())) + { + tscGrupoSanchoToro bd = tscGrupoSanchoToro.NuevoContexto(); + var pob = bd.codigospostales.First(x => (x.CodigoPostal ?? "") == (this.idClienteNavigation.CodigoPostal ?? "")); + this.idClienteNavigation.CodigoMunicipio = pob.CodigoMunicipio; + _CodigoPoblacionClienteTmp = pob.CodigoMunicipio; + _CodigoPoblacionClienteTmpEsNulo = false; + return _CodigoPoblacionClienteTmp; + } + else + { + return ""; + } + } + else + { + return ""; + } + } + + else + { + _CodigoPoblacionClienteTmp = this.idClienteNavigation.CodigoMunicipio; + _CodigoPoblacionClienteTmpEsNulo = false; + return this.idClienteNavigation.CodigoMunicipio; + } + } + else + { + return _CodigoPoblacionClienteTmp; + } + + } + set + { + _CodigoPoblacionClienteTmp = value; + _CodigoPoblacionClienteTmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.CodigoMunicipio = value; + } + this.OnPropertyChanged("CodigoPoblacionClienteTmp"); + this.OnPropertyChanged("PoblacionClienteTmp"); + this.OnPropertyChanged("ProvinciaClienteTmp"); + } + } + [NotMapped] + public string Advertencias + { + get + { + string sAdvertencias = ""; + if (this.idClienteNavigation is not null) + { + foreach (var ad in this.idClienteNavigation.expedientesentidades.Where(x => x.EsAdvertencia).ToList()) + sAdvertencias += " -- " + ad.Descripcion; + if (!string.IsNullOrEmpty(sAdvertencias)) + sAdvertencias = sAdvertencias.Substring(4); + } + return sAdvertencias; + } + } + + [NotMapped] + public string PoblacionClienteTmp + { + get + { + return Conversions.ToString(municipios.ObtienePoblacion(CodigoPoblacionClienteTmp)); + } + } + + [NotMapped] + public string ProvinciaClienteTmp + { + get + { + return Conversions.ToString(municipios.ObtieneProvincia(CodigoPoblacionClienteTmp)); + } + } + + private bool _TelefonoCliente1TmpEsNulo = true; + private string _TelefonoCliente1Tmp; + [NotMapped] + public virtual string TelefonoCliente1Tmp + { + get + { + if (_TelefonoCliente1TmpEsNulo) + { + if (this.idClienteNavigation is not null) + { + _TelefonoCliente1Tmp = this.idClienteNavigation.Telefono1; + _TelefonoCliente1TmpEsNulo = false; + return this.idClienteNavigation.Telefono1; + } + else + { + return ""; + } + } + else + { + return _TelefonoCliente1Tmp; + } + } + set + { + _TelefonoCliente1Tmp = value; + _TelefonoCliente1TmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.Telefono1 = value; + } + this.OnPropertyChanged("TelefonoCliente1Tmp"); + } + } + + private bool _TelefonoCliente2TmpEsNulo = true; + private string _TelefonoCliente2Tmp; + [NotMapped] + public virtual string TelefonoCliente2Tmp + { + get + { + if (_TelefonoCliente2TmpEsNulo) + { + if (this.idClienteNavigation is not null) + { + _TelefonoCliente2Tmp = this.idClienteNavigation.Telefono2; + _TelefonoCliente2TmpEsNulo = false; + return this.idClienteNavigation + .Telefono2; + } + else + { + return ""; + } + } + else + { + return _TelefonoCliente2Tmp; + } + } + set + { + _TelefonoCliente2Tmp = value; + _TelefonoCliente2TmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.Telefono2 = value; + } + this.OnPropertyChanged("TelefonoCliente2Tmp"); + } + } + private bool _EmailClienteTmpEsNulo = true; + private string _EmailClienteTmp; + + + [NotMapped] + public virtual string EmailClienteTmp + { + get + { + if (_EmailClienteTmpEsNulo) + { + if (this.idClienteNavigation is null) + { + return ""; + } + else + { + _EmailClienteTmp = this.idClienteNavigation.Email; + _EmailClienteTmpEsNulo = false; + return this.idClienteNavigation.Email; + } + } + else + { + return _EmailClienteTmp; + } + } + set + { + _EmailClienteTmp = value; + _EmailClienteTmpEsNulo = false; + if (this.idClienteNavigation is not null) + { + this.idClienteNavigation.Email = value; + } + this.OnPropertyChanged("EmailClienteTmp"); + } + } + public void ReiniciaValoresTMPCliente() + { + _NIFClienteTmpEsNulo = true; + _RazonSocialClienteTmpEsNulo = true; + _CodigoPoblacionClienteTmpEsNulo = true; + _CodigoPostalClienteTmpEsNulo = true; + _DomicilioClienteTmpEsNulo = true; + _TelefonoCliente1TmpEsNulo = true; + _TelefonoCliente2TmpEsNulo = true; + _EmailClienteTmpEsNulo = true; + _TipoImpresionAlbaranEntregaTmp = default; + } + + #endregion + #region Obras + + private bool _DescripcionObraTmpEsNulo = true; + private string _DescripcionObraTmp; + + [NotMapped] + public virtual string DescripcionObraTmp + { + get + { + if (_DescripcionObraTmpEsNulo) + { + if (this.Obras is not null) + { + _DescripcionObraTmp = this.Obras.Descripcion; + _DescripcionObraTmpEsNulo = false; + return this.Obras.Descripcion; + } + else + { + return ""; + } + } + else + { + return _DescripcionObraTmp; + } + } + set + { + _DescripcionObraTmp = value; + _DescripcionObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.Descripcion = value; + } + this.OnPropertyChanged("DescripcionObraTmp"); + } + } + + private bool _CodigoPostalObraTmpEsNulo = true; + private string _CodigoPostalObraTmp; + [NotMapped] + public virtual string CodigoPostalObraTmp + { + get + { + if (_CodigoPostalObraTmpEsNulo) + { + if (this.Obras is not null) + { + _CodigoPostalObraTmp = this.Obras.CodigoPostal; + _CodigoPostalObraTmpEsNulo = false; + return this.Obras.CodigoPostal; + } + else + { + return ""; + } + } + else + { + return _CodigoPostalObraTmp; + } + + } + set + { + _CodigoPostalObraTmp = value; + _CodigoPostalObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.CodigoPostal = value; + } + this.OnPropertyChanged("CodigoPostalObraTmp"); + } + } + + private bool _DomicilioObraTmpEsNulo = true; + private string _DomicilioObraTmp; + [NotMapped] + public virtual string DomicilioObraTmp + { + get + { + if (_DomicilioObraTmpEsNulo) + { + if (this.Obras is not null) + { + _DomicilioObraTmp = this.Obras.Direccion.NothingAVacio(); + _DomicilioObraTmpEsNulo = false; + return this.Obras.Direccion; + } + else + { + return ""; + } + } + else + { + return _DomicilioObraTmp; + } + } + set + { + _DomicilioObraTmp = value; + _DomicilioObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.Direccion = value; + } + this.OnPropertyChanged("DomicilioObraTmp"); + } + } + + + private bool _CodigoPoblacionObraTmpEsNulo = true; + private string _CodigoPoblacionObraTmp; + [NotMapped] + public virtual string CodigoPoblacionObraTmp + { + get + { + if (_CodigoPoblacionObraTmpEsNulo) + { + if (this.Obras is null) + { + if (this.Obras is not null && this.Obras.CodigoMunicipioNavigation is null) + { + if (!string.IsNullOrEmpty(this.Obras.CodigoPostal.NothingAVacio())) + { + tscGrupoSanchoToro bd = tscGrupoSanchoToro.NuevoContexto(); //tscGrupoSanchoToro.NuevoContexto(); + var pob = bd.codigospostales.First(x => (x.CodigoPostal ?? "") == (this.Obras.CodigoPostal ?? "")); + this.Obras.CodigoMunicipio = pob.CodigoMunicipio; + _CodigoPoblacionObraTmp = pob.CodigoMunicipio; + _CodigoPoblacionObraTmpEsNulo = false; + return _CodigoPoblacionObraTmp; + } + else + { + return ""; + } + } + else + { + return ""; + } + } + + else + { + _CodigoPoblacionObraTmp = this.Obras.CodigoMunicipio; + _CodigoPoblacionObraTmpEsNulo = false; + return this.Obras.CodigoMunicipio; + } + } + else + { + return _CodigoPoblacionObraTmp; + } + + } + set + { + _CodigoPoblacionObraTmp = value; + _CodigoPoblacionObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.CodigoMunicipio = value; + } + this.OnPropertyChanged("CodigoPoblacionObraTmp"); + this.OnPropertyChanged("PoblacionObraTmp"); + this.OnPropertyChanged("ProvinciaObraTmp"); + } + } + + + [NotMapped] + public string PoblacionObraTmp + { + get + { + return Conversions.ToString(municipios.ObtienePoblacion(CodigoPoblacionObraTmp)); + } + } + + [NotMapped] + public string ProvinciaObraTmp + { + get + { + return Conversions.ToString(municipios.ObtieneProvincia(CodigoPoblacionObraTmp)); + } + } + + private bool _TelefonoObra1TmpEsNulo = true; + private string _TelefonoObra1Tmp; + [NotMapped] + public virtual string TelefonoObra1Tmp + { + get + { + if (_TelefonoObra1TmpEsNulo) + { + if (this.Obras is not null) + { + _TelefonoObra1Tmp = this.Obras.Telefono1; + _TelefonoObra1TmpEsNulo = false; + return this.Obras.Telefono1; + } + else + { + return ""; + } + } + else + { + return _TelefonoObra1Tmp; + } + } + set + { + _TelefonoObra1Tmp = value; + _TelefonoObra1TmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.Telefono1 = value; + } + this.OnPropertyChanged("TelefonoObra1Tmp"); + } + } + + private bool _TelefonoObra2TmpEsNulo = true; + private string _TelefonoObra2Tmp; + [NotMapped] + public virtual string TelefonoObra2Tmp + { + get + { + if (_TelefonoObra2TmpEsNulo) + { + if (this.Obras is not null) + { + _TelefonoObra2Tmp = this.Obras.Telefono2; + _TelefonoObra2TmpEsNulo = false; + return this.Obras.Telefono2; + } + else + { + return ""; + } + } + else + { + return _TelefonoObra2Tmp; + } + } + set + { + _TelefonoObra2Tmp = value; + _TelefonoObra2TmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.Telefono2 = value; + } + this.OnPropertyChanged("TelefonoObra2Tmp"); + } + } + private bool _EmailObraTmpEsNulo = true; + private string _EmailObraTmp; + [NotMapped] + public virtual string EmailObraTmp + { + get + { + if (_EmailObraTmpEsNulo) + { + if (this.Obras is not null) + { + _EmailObraTmp = this.Obras.Email; + _EmailObraTmpEsNulo = false; + return this.Obras.Email; + } + else + { + return ""; + } + } + else + { + return _EmailObraTmp; + } + } + set + { + _EmailObraTmp = value; + _EmailObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.Email = value; + } + this.OnPropertyChanged("EmailObraTmp"); + } + } + + + + private bool _ObservacionesObraTmpEsNulo = true; + private string _ObservacionesObraTmp; + + + [NotMapped] + public virtual string ObservacionesObraTmp + { + get + { + if (_ObservacionesObraTmpEsNulo) + { + if (this.Obras is null) + { + return ""; + } + else + { + _ObservacionesObraTmp = this.Obras.Observaciones; + _ObservacionesObraTmpEsNulo = false; + return this.Obras.Observaciones; + } + } + else + { + return _ObservacionesObraTmp; + } + } + set + { + _ObservacionesObraTmp = value; + _ObservacionesObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.Observaciones = value; + } + this.OnPropertyChanged("ObservacionesObraTmp"); + } + } + + private bool _PersonaContactoObraTmpEsNulo = true; + private string _PersonaContactoObraTmp; + + public event PropertyChangedEventHandler? PropertyChanged; + + [NotMapped] + public virtual string PersonaContactoObraTmp + { + get + { + if (_PersonaContactoObraTmpEsNulo) + { + if (this.Obras is null) + { + return ""; + } + else + { + _PersonaContactoObraTmp = this.Obras.PersonaContacto; + _PersonaContactoObraTmpEsNulo = false; + return this.Obras.PersonaContacto; + } + } + else + { + return _PersonaContactoObraTmp; + } + } + set + { + _PersonaContactoObraTmp = value; + _PersonaContactoObraTmpEsNulo = false; + if (this.Obras is not null) + { + this.Obras.PersonaContacto = value; + } + this.OnPropertyChanged("PersonaContactoObraTmp"); + } + } + public void ReiniciaValoresTMPObra() + { + _CodigoPoblacionObraTmpEsNulo = true; + _CodigoPostalObraTmpEsNulo = true; + _DomicilioObraTmpEsNulo = true; + _TelefonoObra1TmpEsNulo = true; + _TelefonoObra2TmpEsNulo = true; + _ObservacionesObraTmpEsNulo = true; + _PersonaContactoObraTmpEsNulo = true; + } + public void ActualizaValoresTMPObra() + { + this.OnPropertyChanged("CodigoPostalObraTmp"); + this.OnPropertyChanged("DomicilioObraTmp"); + this.OnPropertyChanged("CodigoPoblacionObraTmp"); + this.OnPropertyChanged("PoblacionObraTmp"); + this.OnPropertyChanged("ProvinciaObraTmp"); + this.OnPropertyChanged("TelefonoObra1Tmp"); + this.OnPropertyChanged("TelefonoObra2Tmp"); + this.OnPropertyChanged("ObservacionesObraTmp"); + this.OnPropertyChanged("PersonaContactoObraTmp"); + } + #endregion + } + + + + + public class DetalleProductoFinal + { + [Key] + public int idProducto { get; set; } + public string Descripcion { get; set; } + public int Cantidad { get; set; } + public double Importe { get; set; } + public string Tipo { get; set; } + } +} \ No newline at end of file diff --git a/bdGrupoSanchoToro/extensiones/productos.cs b/bdGrupoSanchoToro/extensiones/productos.cs index 0d9d705..feed086 100644 --- a/bdGrupoSanchoToro/extensiones/productos.cs +++ b/bdGrupoSanchoToro/extensiones/productos.cs @@ -1,17 +1,43 @@ -using System; +using bdGrupoSanchoToro.db; +using bdGrupoSanchoToro.extensiones; +using Google.Protobuf.WellKnownTypes; +using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using System.Data; using System.Linq; using System.Runtime.CompilerServices; +using System.Text.Json; namespace bdGrupoSanchoToro.db { - public partial class productos + public partial class productos : INotifyPropertyChanged { + private List? _DesgloseUnidades; + [NotMapped] + public List? DesgloseUnidades + { + get + { + if (_DesgloseUnidades == null) + { + if (string.IsNullOrEmpty(UnidadesPorEmpresa)) + { + _DesgloseUnidades = new List(); + } + else + { + _DesgloseUnidades = JsonSerializer.Deserialize>(UnidadesPorEmpresa); + } + } + return _DesgloseUnidades; + } + set => _DesgloseUnidades=value; + + } [NotMapped] public bool Descatalogado { @@ -32,24 +58,307 @@ namespace bdGrupoSanchoToro.db } } } - // [NotMapped] - //public string DescripcionTipo - //{ - // get - // { - // return ((TipoProductoEnum)this.Tipo).ToString().Replace("_", " "); - // } - //} + + [NotMapped] + public virtual List DesgloseMaterial + { + get + { + try + { + return this.desgloseproductosidProductoPadreNavigation.Where(x => x.Producto.Tipo < (int)TipoProductoEnum.SERVICIO).OrderBy(x => x.idProductoNavigation.Descripcion).ToList(); + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + } + + + + public event PropertyChangedEventHandler? PropertyChanged; + + public void RefrescaCamposTemporales() + { + // this.OnPropertyChanged("DesgloseServicios"); + this.OnPropertyChanged("DesgloseMaterial"); + this.OnPropertyChanged("NumeroProductoTMP"); + } + protected void OnPropertyChanged([CallerMemberName] string name = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + [NotMapped] + public string NumeroProductoTMP + { + get + { + if (this.idProducto == 0) + { + return "« AUTOMÁTICO »"; + } + else + { + return this.idProducto.ToString(); + } + } + } + [NotMapped] + public string DescripcionTipo + { + get + { + return ((TipoProductoEnum)this.Tipo).ToString().Replace("_", " "); + } + } + [NotMapped] + public double UnidadesDisponibles + { + get + { + return this.TotalUnidades - this.UnidadesAlquiladas - this.UnidadesAveriadas; + } + } + [NotMapped] + public int NumeroDescendientes + { + get + { + return this.desgloseproductosidProductoPadreNavigation.Count; + } + } + + + [NotMapped] + public virtual ICollection Padres + { + get + { + return this.desgloseproductosidProductoNavigation; + } + } + [NotMapped] + public int NivelMaximoAscendientes + { + get + { + int NivelMaximo = 0; + int NivelActual = 0; + ObtieneNivelMaximoAscendiente(this, NivelActual, ref NivelMaximo); + return NivelMaximo - 1; + } + } + [NotMapped] + public int NivelMaximoDescendientes + { + get + { + int NivelMaximo = 0; + int NivelActual = 0; + ObtieneNivelMaximoDescendientes(this, NivelActual, ref NivelMaximo); + return NivelMaximo - 1; + } + } + + [NotMapped] + public virtual List ListaAscendientes + { + get + { + var Lista = new List(); + ObtieneListaAscendientes(this, "", ref Lista); + return Lista; + } + } + private void ObtieneListaAscendientes(productos p, string NombrePadre, ref List Lista) + { + string NombreActual = (NombrePadre + "/" + p.Descripcion).TrimStart('/'); + Lista.Add(NombreActual); + foreach (var d in p.Padres) + ObtieneListaAscendientes(d.ProductoPadre, NombreActual, ref Lista); + } + + private void ObtieneNivelMaximoAscendiente(productos p, int NivelActual, ref int NivelMaximo) + { + NivelActual += 1; + NivelMaximo = Math.Max(NivelActual, NivelMaximo); + foreach (var d in p.Padres) + ObtieneNivelMaximoAscendiente(d.ProductoPadre, NivelActual, ref NivelMaximo); + } + public bool ContieneAscendiente(int idProducto) + { + bool bContiene = this.idProducto == idProducto; + if (!bContiene) + { + foreach (var d in Padres) + { + bContiene = d.ProductoPadre.ContieneAscendiente(idProducto); + if (bContiene) + break; + } + } + return bContiene; + } + // Public Function ContieneDescendiente(idProducto As Integer) As Boolean + // Dim bContiene As Boolean = (Me.idProducto = idProducto) + // If Not bContiene Then + // For Each d In Me.desgloseproductos + // bContiene = d.Producto.ContieneDescendiente(idProducto) + // If bContiene Then Exit For + // Next + // End If + // Return bContiene + // End Function + [NotMapped] + public bool ContieneDescendientes + { + get + { + return this.desgloseproductosidProductoPadreNavigation.Any(); + } + } + + private void ObtieneNivelMaximoDescendientes(productos p, int NivelActual, ref int NivelMaximo) + { + NivelActual += 1; + NivelMaximo = Math.Max(NivelActual, NivelMaximo); + foreach (var d in p.desgloseproductosidProductoPadreNavigation) + this.ObtieneNivelMaximoDescendientes(d.Producto, NivelActual, ref NivelMaximo); + } + + [NotMapped] public int CantidadTMP { get; set; } + [NotMapped] public int UnidadesPropiasAIntervaloFechasTMP { get; set; } + [NotMapped] public int UnidadesSubarrendadasAIntervaloFechasTMP { get; set; } + [NotMapped] public int TotalUnidadesAIntervaloFechasTMP { get; set; } + [NotMapped] public int UnidadesPresupuestadasTMP { get; set; } + [NotMapped] public int UnidadesPresupuestadasYAceptadasTMP { get; set; } + [NotMapped] public int UnidadesDisponiblesNoPresupestadasTMP { get; set; } + [NotMapped] public int UnidadesDisponiblesNoContratadasTMP { get; set; } + [NotMapped] public int DisponibilidadTMP { get; set; } + + + + public static void RecalculaStocks(tscGrupoSanchoToro bd, List lp = null) + { + try + { + var prds = lp is null ? bd.productos.Where(x => x.Tipo < (int)TipoProductoEnum.SERVICIO ).ToList() : lp; + foreach (var pr in prds) + { + pr.TotalUnidades = 0d; + pr.UnidadesInicialesOFabricadas = 0d; + pr.UnidadesCompradas = 0d; + pr.UnidadesVendidas = 0d; + pr.UnidadesAlquiladas = 0d; + pr.UnidadesAveriadas = 0d; + pr.UnidadesDesechadas = 0d; + pr.UnidadesSubAlquiladas = 0d; + pr.DesgloseUnidades?.Clear(); + foreach (var st in pr.stocks) + st.Unidades = 0d; + bd.SaveChanges(); + List dets = pr.detallesalbaranes.Where(x=>x.idAlbaranRecogida.HasValue==false).ToList(); + foreach (var d in dets) + { + d.ActualizaProducto(bd, (albaranes.TipoAlbaranEnum)d.idAlbaranNavigation.Tipo, 1,d.idAlbaranNavigation.idEmpresa); + } + } + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + + internal void ActualizaUnidades(TipoUnidadesEnum Tipo, int Empresa, double Cantidad) + { + if (DesgloseUnidades == null) DesgloseUnidades = new List(); + DesglosePorEmpresa du = DesgloseUnidades.FirstOrDefault(x => x.Empresa == Empresa); + if (du == null) + { + du = new DesglosePorEmpresa(); + du.Empresa = Empresa; + du.TotalUnidades = 0d; + du.UnidadesInicialesOFabricadas = 0d; + du.UnidadesCompradas = 0d; + du.UnidadesVendidas = 0d; + du.UnidadesAlquiladas = 0d; + du.UnidadesAveriadas = 0d; + du.UnidadesDesechadas = 0d; + du.UnidadesSubAlquiladas = 0d; + DesgloseUnidades.Add(du); + } + switch (Tipo) + { + case TipoUnidadesEnum.TOTAL: + { + du.TotalUnidades += Cantidad; + break; + } + case TipoUnidadesEnum.INICIALES_O_FABRICADAS: + { + du.UnidadesInicialesOFabricadas += Cantidad; + break; + } + case TipoUnidadesEnum.COMPRADAS: + { + du.UnidadesCompradas += Cantidad; + break; + } + case TipoUnidadesEnum.ALQUILADAS: + { + du.UnidadesAlquiladas += Cantidad; + break; + } + case TipoUnidadesEnum.VENDIDAS: + { + du.UnidadesVendidas += Cantidad; + break; + } + case TipoUnidadesEnum.AVERIADAS: + { + du.UnidadesAveriadas += Cantidad; + break; + } + case TipoUnidadesEnum.DESECHADAS: + { + du.UnidadesDesechadas += Cantidad; + break; + } + case TipoUnidadesEnum.SUBALQUILADAS: + { + du.UnidadesSubAlquiladas += Cantidad; + break; + } + } + UnidadesPorEmpresa = JsonSerializer.Serialize(DesgloseUnidades); + + } + public enum TipoUnidadesEnum + { + TOTAL=0, + INICIALES_O_FABRICADAS=1, + COMPRADAS = 2, + VENDIDAS=3, + ALQUILADAS=4, + AVERIADAS=5, + DESECHADAS=6, + SUBALQUILADAS=7 + } public enum TipoProductoEnum { GRUA = 0, ELEMENTO_GRUA = 1, - REPUESTO =10, + PIES_GRUA = 2, + REPUESTO = 10, OTROS_PRODUCTOS = 11, - CONSUMIBLES =12, + CONSUMIBLES = 12, MATERIAL_OFICINA = 13, - SERVICIO = 99, + HERRAMIENTAS = 99, + SERVICIO = 100, + SOLO_OFERTAS = 200 } } } \ No newline at end of file diff --git a/bdGrupoSanchoToro/extensiones/v_albaranesextendidos.cs b/bdGrupoSanchoToro/extensiones/v_albaranesextendidos.cs new file mode 100644 index 0000000..5e9c1c6 --- /dev/null +++ b/bdGrupoSanchoToro/extensiones/v_albaranesextendidos.cs @@ -0,0 +1,39 @@ +using static bdGrupoSanchoToro.db.albaranes; +using Microsoft.VisualBasic.CompilerServices; + +namespace bdGrupoSanchoToro.db +{ + + public partial class v_albaranesextendidos + { + public string PoblacionCarga + { + get + { + return Conversions.ToString(municipios.ObtienePoblacion(this.CodigoMunicipioCarga)); + } + } + public string PoblacionDescargarga + { + get + { + return Conversions.ToString(municipios.ObtienePoblacion(this.CodigoMunicipioDescarga)); + } + } + public string NumeroAlbaran + { + get + { + return albaranes.ObtieneNumeroAlbaran(this.idAlbaran, (PrefijoAlbaranEnum)this.Tipo); + } + } + public string DescripcionTipoAlbaran + { + get + { + return ((TipoAlbaranEnum)this.Tipo).ToString().Replace("_", " "); + } + } + + } +} \ No newline at end of file