Imports DevExpress.Xpf.Editors Imports DevExpress.Xpf.LayoutControl Imports tsWPFCore Imports System.ComponentModel Imports System.Data Imports DevExpress.Xpf.Editors.Validation Imports DevExpress.Xpf.Editors.Helpers Imports DevExpress.Xpf.Core Imports tsWPFCore.modExtensiones Imports System.Data.Common Imports bdGrupoSanchoToro.db Imports tsUtilidades.Datos Imports DevExpress.Xpf.Bars Imports DevExpress.Xpf.Grid Imports System.Collections Imports tsEFCore8.Extensiones Imports bdGrupoSanchoToro.db.Utilidades Imports tsUtilidades.Enumeraciones Imports tsUtilidades Imports bdGrupoSanchoToro.db.productos Imports System.IO Imports Microsoft.Win32 Imports tsUtilidades.Extensiones 'TODO: Comprobar cuando se puede modificar una factura (o eliminar) Public Class ucFacturaRecibida Private bd As tscGrupoSanchoToro Friend _idFactura As Nullable(Of Integer) Private lProductos As List(Of productos) Private ivas As List(Of enumeraciones) Friend idLog As Integer? Dim ra As facturasrecibidas Public Overrides Sub Cargado() Me.Tipo_ucControlBusqueda = GetType(ucFacturasRecibidas) End Sub Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False) Try lProductos = bd.productos.OrderBy(Function(x) x.Descripcion).ToList Dim lProductosFra = ra.detallesfacturasrecibidas.Select(Function(x) x.idProducto).ToArray lProductos = lProductos.Where(Function(x) x.FechaBaja Is Nothing OrElse lProductosFra.Contains(x.idProducto)).ToList cbProducto.ItemsSource = lProductos 'For Each d In ra.detallesfacturasrecibidas ' If Not ivas.Contains(d.PorcentajeIVA) Then ivas.Add(d.PorcentajeIVA) 'Next cbIva.ItemsSource = ivas cbTipoDocumento.ItemsSource = tsUtilidades.DescripcionValor.EnumADescripcionValor(GetType(bdGrupoSanchoToro.db.documentosfacturasrecibidas.TipoDocumentoFacturaEnum)).OrderBy(Function(x) x.Descripcion) cbCategoria.ItemsSource = bd.enumeraciones.Where(Function(x) x.idGrupoEnumeracionNavigation.Grupo = "CATFR").OrderBy(Function(x) x.Descripcion).ToList Dim plantillas As List(Of tsWPFCore.Plantilla) = Comun.ObtienePlantillas(bd, {"GRUPLA.FACREC"}, False) Me.ContenedorAplicacion.cbPlantillaAImprimir.ItemsSource = plantillas If plantillas.Count > 0 Then Me.ContenedorAplicacion.bePlantilla.EditValue = plantillas.First.idPlantilla End If Catch ex As Exception Throw New Exception(ex.Message, ex) End Try End Sub 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 ivas = bd.enumeraciones.Where(Function(x) x.idGrupoEnumeracionNavigation.Grupo = "PIVA").OrderBy(Function(x) x.ValorNumerico2).ToList If idLog.HasValue Then Try Dim log = bd.logs.First(Function(x) x.idLog = idLog) ra = tsUtilidades.Utilidades.DeserializarSinErrores(log.Log, GetType(facturasrecibidas)) If ra.idUsuario.HasValue Then ra.idUsuarioNavigation = bd.usuarios.FirstOrDefault(Function(x) x.idUsuario = ra.idUsuario.Value) Dim df = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "DETALLESFACTURASRECIBIDAS") If df IsNot Nothing Then Dim ld = tsUtilidades.Utilidades.DeserializarSinErrores(df.Log, GetType(List(Of detallesfacturasrecibidas))) For Each d In ld ra.detallesfacturasrecibidas.Add(d) Next End If Dim mv = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "MOVIMIENTOSCAJA_FR") If mv IsNot Nothing Then Dim ld = tsUtilidades.Utilidades.DeserializarSinErrores(mv.Log, GetType(List(Of movimientoscaja))) For Each d In ld ra.movimientoscaja.Add(d) Next End If Dim lent = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "ENTIDADES") If lent IsNot Nothing Then Dim ent = tsUtilidades.Utilidades.DeserializarSinErrores(lent.Log, GetType(entidades)) ra.idProveedorNavigation = ent lgDatosProveedor.DataContext = ra.idProveedorNavigation End If Dim lfic = bd.logs.FirstOrDefault(Function(x) x.idRelacionado = log.idLog AndAlso x.Aplicacion = "FICHEROS") If lfic IsNot Nothing Then Dim fic = tsUtilidades.Utilidades.DeserializarSinErrores(lfic.Log, GetType(db.ficheros)) ra.idFicheroNavigation = fic 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 FuerzaNuevo OrElse _idFactura Is Nothing Then ra = New facturasrecibidas ra.FechaFactura = DateOnly.FromDateTime(Today) _idFactura = Nothing ra.FechaRegistro = DateOnly.FromDateTime(Today) NuevoEstado = tsUtilidades.EstadosAplicacion.Nuevo lgDatosProveedor.DataContext = ra.idProveedorNavigation Else ra = bd.facturasrecibidas.First(Function(x) x.idFactura = _idFactura) NuevoEstado = tsUtilidades.EstadosAplicacion.ModificandoRegistro lgDatosProveedor.DataContext = ra.idProveedorNavigation End If End If cbIVA.ItemsSource = ivas Dim lCajas = bd.cajas.Where(Function(x) x.idEmpresa = EmpresaActual.idEmpresa).ToList.Where(Function(x) (x.FechaBaja.HasValue = False OrElse ra.movimientoscaja.Any(Function(y) y.idCaja = x.idCaja))).OrderBy(Function(x) x.Descripcion).ToList Me.cbCaja.ItemsSource = lCajas cbRazonSocial.ItemsSource = bd.entidades.Where(Function(x) x.idEmpresa = EmpresaActual.idEmpresa AndAlso ((x.EsProveedor AndAlso x.FechaBaja.HasValue = False) OrElse x.idEntidad = ra.idProveedor)).ToList gcDetalle.ItemsSource = ra.detallesfacturasrecibidas gcRecibos.ItemsSource = ra.movimientoscaja gcDocumentos.ItemsSource = ra.documentosfacturasrecibidas Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idFactura AndAlso x.Aplicacion = "FACTURASRECIBIDAS").ToList 'Dim Acciones As New List(Of tsWPFCore.Accion) 'Acciones.Add(New Accion With { ' .idAccion = 1, ' .Descripcion = "AGREGAR PRODUCTOS PENDIENTES DE FACTURAR"}) 'Acciones.Add(New Accion With { ' .idAccion = 2, ' .Descripcion = "SALDAR FACTURA POR CAJA CONTADO"}) 'Acciones.Add(New Accion With { ' .idAccion = 3, ' .Descripcion = "SALDAR FACTURA POR TPV"}) 'Acciones.Add(New Accion With { ' .idAccion = 4, ' .Descripcion = "SALDAR FACTURA POR BANCO"}) 'Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones 'Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion Me.DataContext = ra Return NuevoEstado End Function Public Overrides Function ObtieneBD() As tsUtilidades.ItsContexto bd = tscGrupoSanchoToro.NuevoContexto Return bd End Function Public Overrides ReadOnly Property NombreTablaBase As String Get Return "facturasrecibidas" End Get End Property 'Public Overrides ReadOnly Property CampoIndice As String ' Get ' Return "idFactura" ' End Get 'End Property Public Overrides ReadOnly Property idRegistroAplicacionActual As String Get If idLog.HasValue Then Return "Gastos / Factura Proveedor R.C.:" & idLog.ToString Else If Me.Estado = tsUtilidades.EstadosAplicacion.Nuevo Then Return "Gastos / Factura Proveedor.Nuevo" Else Return "Gastos / Factura Proveedor." & DirectCast(Me.DataContext, facturasrecibidas).idFactura.ToString End If End If End Get End Property Public Overrides ReadOnly Property DescripcionRegistro As String Get Return "Gastos / Factura Proveedor" End Get End Property Public Sub New(Optional idFactura As Integer? = Nothing) ' Llamada necesaria para el diseñador. InitializeComponent() _idFactura = idFactura ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Public Overrides Sub EstableceTitulo() If idLog.HasValue Then Dim fr As facturasrecibidas = Me.DataContext Me.docpanel.Caption = "R.C. Gastos / Factura de Proveedor " & fr.NumeroFactura Me.docpanel.Tag = "R.C. Gastos / Factura Recibida." & fr.NumeroFactura Else If Me.Estado = tsUtilidades.EstadosAplicacion.ModificandoRegistro Then Dim fr As facturasrecibidas = Me.DataContext Me.docpanel.Caption = " Gastos / Factura de Proveedor " & fr.NumeroFactura Me.docpanel.Tag = " Gastos / Factura Recibida." & fr.NumeroFactura Else Me.docpanel.Caption = " Gastos / Factura de Proveedor Nueva" Me.docpanel.Tag = " Gastos / FacturaRecibida.Nuevo" End If End If ' End If 'End If End Sub Public Overrides Function ObtienePermisos() As tsUtilidades.Permisos Dim pers = Comun.ObtienePermisos(Me.bd, "AP.ADMINISTRATIVOS", idUsuario) ' pers.Eliminar = False Return pers End Function Private Sub ap_ValidarControl(sender As Object, e As ValidationEventArgs, ByRef ev As ErrorValidacion, ByRef ValorOriginalCambiado As Object) Handles Me.ValidarControl Dim pts As PropiedadesTS = sender.parent.propiedadests Try If Not pts Is Nothing Then Me.ErroresValidacion.EliminaError("validando-" & pts.NombreCampo) Dim ra As facturasrecibidas = Me.DataContext Select Case pts.NombreCampo.ToLower Case "idproveedor_nulable" Dim id As Integer = e.Value Dim ent = bd.entidades.First(Function(x) x.idEntidad = id) lgDatosProveedor.DataContext = ent End Select End If Catch ex As Exception Dim sCodigoError As String = "validando-" If pts IsNot Nothing Then sCodigoError &= pts.NombreCampo End If ev = New ErrorValidacion(sCodigoError, sender, ex.Message, ex, DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical) e.IsValid = False End Try End Sub Private Sub ap_DespuesGuardar(sender As Object, e As ItemClickEventArgs, OpcionGuardado As Integer) Handles Me.DespuesGuardar _idFactura = ra.idFactura RefrescaUC() ' Me.gcRecibos.ItemsSource = ra.movimientoscaja ' Me.gcLogs.ItemsSource = bd.logs.Where(Function(x) x.id = ra.idFactura AndAlso x.Aplicacion = "FACTURASRECIBIDAS").ToList End Sub Private Sub ap_Enlazar(Celda As EditGridCellData, Defecto As Boolean) Handles Me.Enlazar Dim ra As facturasrecibidas = Me.DataContext Select Case Celda.Column.FieldName.ToLower Case "idlog" Dim log As logs = gcLogs.CurrentItem Dim id As Integer = log.idLog Dim uc As New ucFacturaRecibida uc.idLog = log.idLog FuncionesDinamicas.AbrirAP(uc, OtrosParametros) End Select 'Select Case Celda.Column.FieldName.ToLower ' Case "numeroalbaranentrega" ' Dim ra = DirectCast(Me.gcDetalle.CurrentItem, detallesfacturasrecibidas) ' Dim id As Integer = ra.detallesalbaranes.idAlbaranEntrega ' FuncionesDinamicas.AbrirAP(New ucAlbaranEntrega(id), OtrosParametros) ' Case "numeroalbaranrecogida" ' Dim ra = DirectCast(Me.gcDetalle.CurrentItem, detallesfacturasrecibidas) ' Dim id As Integer = ra.detallesalbaranes.idAlbaranRecogida ' FuncionesDinamicas.AbrirAP(New ucAlbaranRecogida(id), OtrosParametros) 'End Select End Sub Private Sub ap_EstadoCambiado(EstadoAnterior As tsUtilidades.EstadosAplicacion, EstadoNuevo As tsUtilidades.EstadosAplicacion) Handles Me.EstadoCambiado Select Case EstadoNuevo Case EstadosAplicacion.ModificandoRegistro Dim ra As facturasrecibidas = Me.DataContext ' Dim ra As albaranesrecogida = Me.DataContext ' If ra.detallesfacturasrecibidas.ToList.Any(Function(x) x.idAlbaranRecogida.HasValue OrElse (x.idUltimaFactura.HasValue AndAlso (x.facturasrecibidas.Fecha > ra.Fecha.Date))) Then me.EstableceSoloLectura() End Select If idLog.HasValue Then EstableceSoloLectura() EstableceSoloLecturaCI() End Sub Private Sub BiBuscarProducto_Click(sender As Object, e As RoutedEventArgs) 'Dim dxw As New dxwProductos(lProductos) 'If dxw.ShowDialog Then ' If gcDetalle.CurrentItem Is Nothing Then tvDetalle.AddNewRow() ' Dim def As detallesfacturasrecibidas = gcDetalle.CurrentItem ' Dim prod = lProductos.First(Function(x) x.idProducto = dxw.idProducto) ' def.idProducto = prod.idProducto ' RellenaDatosProducto(def) ' tvDetalle.MoveNextCell() ' gcDetalle.RefreshRow(tvDetalle.FocusedRowHandle) 'End If If tvDetalle.ActiveEditor Is Nothing Then Dispatcher.BeginInvoke(New Action(Sub() tvDetalle.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render) End If Dim dxw As New dxwProductos(lProductos) If dxw.ShowDialog Then If gcDetalle.CurrentItem Is Nothing Then tvDetalle.AddNewRow() Dim def As detallesfacturasrecibidas = gcDetalle.CurrentItem Dim prod = lProductos.First(Function(x) x.idProducto = dxw.idProducto) def.idProducto = prod.idProducto If tvDetalle.ActiveEditor IsNot Nothing Then tvDetalle.ActiveEditor.EditValue = prod.idProducto tvDetalle.PostEditor() tvDetalle.CloseEditor() gcDetalle.RefreshRow(tvDetalle.FocusedRowHandle) End If End Sub Private Sub ap_AntesGuardar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, OpcionGuardado As Integer) Handles Me.AntesGuardar ra.idUsuario = idUsuario Dim hte As New Hashtable If ra.detallesfacturasrecibidas.Count = 0 Then hte.Add("ALMACENAR-DETALLE_OBLIGATORIO", "Es obligatorio introducir al menos un artículo") End If If bd.facturasrecibidas.Any(Function(x) x.NumeroFactura = ra.NumeroFactura AndAlso x.idProveedor = ra.idProveedor AndAlso x.idFactura <> ra.idFactura) Then hte.Add("ALMACENAR-YA-EXISTE-OTRA-FACTURA", "Ya existe esta factura del mismo cliente registrada") End If If ra.TotalFactura = 0 Then hte.Add("ALMACENAR-IMPORTE_0", "El total de la factura no puede ser 0") End If If Math.Abs(ra.ImportePagado) > Math.Abs(ra.TotalFactura) Then hte.Add("ALMACENAR-IMPORTE_PAGADO_SUPERIOR", "El importe pagado de los recibos no puede superar al total de la factura") End If If hte.Count > 0 Then MensajesError = hte Cancelar = True Else For Each mv In ra.movimientoscaja mv.Tipo = TipoMovimientoEnum.RECIBO_PROVEEDOR If mv.idUsuario.HasValue = False Then mv.idUsuario = idUsuario Next For Each d In ra.documentosfacturasrecibidas If d.idUsuario.HasValue = False Then d.idUsuario = idUsuario Next If ra.ImportePendiente = 0 Then ra.FechaPago = DateOnly.FromDateTime(ra.movimientoscaja.OrderByDescending(Function(x) x.Fecha).First.Fecha) Else ra.FechaPago = Nothing End If If ra.PorcentajeIVA2.HasValue = False Then ra.BaseImponible2 = Nothing ra.CuotaIVA2 = Nothing End If If ra.PorcentajeIVA3.HasValue = False Then ra.BaseImponible3 = Nothing ra.CuotaIVA3 = Nothing End If End If End Sub Private Sub tvDetalle_CellValueChanged(sender As Object, e As CellValueChangedEventArgs) Handles tvDetalle.CellValueChanged Try Dim def As detallesfacturasrecibidas = e.Row Select Case e.Column.FieldName.ToLower Case "idproducto" RellenaDatosProducto(def) 'Case "cantidad", "precio" ' def.RefrescaImporte() Case "idtipoiva" Dim idTIVA = CInt(e.Value) def.PorcentajeIVA = ivas.First(Function(x) x.idEnumeracion = idTIVA).ValorNumerico1 End Select Catch ex As Exception End Try End Sub Private Sub RellenaDatosProducto(dea As detallesfacturasrecibidas) Dim ae As facturasrecibidas = Me.DataContext Dim pr = lProductos.First(Function(x) x.idProducto = dea.idProducto) dea.Precio = pr.UltimoPrecioCompra If dea.Cantidad = 0 Then dea.Cantidad = 1 'dea.RefrescaImporte() End Sub Private Sub BiBuscarProveedor_Click(sender As Object, e As RoutedEventArgs) If Me.ContenedorAplicacion.btGuardar.IsEnabled Then Dim dxw As New dxwEntidades(bd, False, True) If dxw.ShowDialog Then Dim ra As facturasrecibidas = Me.DataContext Dim ent = bd.entidades.First(Function(x) x.idEntidad = dxw.Entidad.idEntidad) ra.idProveedorNavigation = ent ra.idProveedor_Nulable = ent.idEntidad lgDatosProveedor.DataContext = ent End If End If End Sub Private Sub ap_ImprimirPlantilla(sender As Object, e As ItemClickEventArgs, idPlantilla As Integer, Previsualizar As Boolean) Handles Me.ImprimirPlantilla Imprimir(idPlantilla, False, 1) End Sub Private Sub Imprimir(idPlantilla As Integer, ImpresoraDefecto As Boolean, Copias As Integer) Dim ds As List(Of facturasrecibidas) Dim pl = bd.plantillas.AsNoTracking.Where(Function(x) x.idPlantilla = idPlantilla).Select(Function(x) New With {.Fichero = x.idFicheroNavigation.Fichero, .Tipo = x.idGrupoNavigation.Codigo}).FirstOrDefault ds = New List(Of facturasrecibidas) ds.Add(ra) Informes.ImprimirPlantilla(bd, pl.Fichero, ds, ImpresoraDefecto, Copias) End Sub 'Private Sub ap_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion 'End Sub Private Sub tvDetalle_RowUpdated(sender As Object, e As DevExpress.Xpf.Grid.RowEventArgs) Handles tvDetalle.RowUpdated Call CalculaTotales() End Sub Sub CalculaTotales() Dim ra As facturasrecibidas = Me.DataContext Dim ivas(2) As Double? For Each df In ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA.HasValue).ToList For i = 0 To 3 If i = 3 Then Throw New Exception("Demasiados tipos de iva en la misma factura.") If ivas(i).HasValue = False OrElse ivas(i).Value = df.PorcentajeIVA Then ivas(i) = df.PorcentajeIVA Exit For End If Next Next ra.PorcentajeIVA1 = ivas(0) ra.PorcentajeIVA2 = ivas(1) ra.PorcentajeIVA3 = ivas(2) ra.BaseImponibleExenta = ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA.HasValue = False).Sum(Function(x) x.Importe) ra.BaseImponible1 = Nothing ra.BaseImponible2 = Nothing ra.BaseImponible3 = Nothing If ivas(0).HasValue Then ra.BaseImponible1 = ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA.HasValue AndAlso x.PorcentajeIVA = ivas(0)).Sum(Function(x) x.Importe) If ivas(1).HasValue Then ra.BaseImponible2 = ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA.HasValue AndAlso x.PorcentajeIVA = ivas(1)).Sum(Function(x) x.Importe) If ivas(2).HasValue Then ra.BaseImponible3 = ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA.HasValue AndAlso x.PorcentajeIVA = ivas(2)).Sum(Function(x) x.Importe) 'ra.BaseImponible2 = If(ivas(2).HasValue, ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA = ivas(1)).Sum(Function(x) x.Importe), 0) 'ra.BaseImponible3 = If(ivas(2).HasValue, ra.detallesfacturasrecibidas.Where(Function(x) x.PorcentajeIVA = ivas(2)).Sum(Function(x) x.Importe), 0) ra.TotalBaseImponible = Math.Round(ra.detallesfacturasrecibidas.Sum(Function(x) x.Importe), 2) CalculaIRPF(ra) CalculaCuotasIVA(ra) CalculaTotalesFinales(ra) End Sub Public Sub CalculaIRPF(F As facturasrecibidas) F.IRPF = Math.Round(F.TotalBaseImponible * F.PorcentajeIRPF / 100, 2, MidpointRounding.AwayFromZero) End Sub Public Sub CalculaCuotasIVA(F As facturasrecibidas) F.CuotaIVA1 = Nothing F.CuotaIVA2 = Nothing F.CuotaIVA3 = Nothing If F.PorcentajeIVA1.HasValue Then F.CuotaIVA1 = Math.Round(F.BaseImponible1.Value * F.PorcentajeIVA1.Value / 100, 2, MidpointRounding.AwayFromZero) End If If F.PorcentajeIVA2.HasValue Then F.CuotaIVA2 = Math.Round(F.BaseImponible2.Value * F.PorcentajeIVA2.Value / 100, 2, MidpointRounding.AwayFromZero) End If If F.PorcentajeIVA3.HasValue Then F.CuotaIVA3 = Math.Round(F.BaseImponible3.Value * F.PorcentajeIVA3.Value / 100, 2, MidpointRounding.AwayFromZero) End If End Sub Public Sub CalculaTotalesFinales(ra As facturasrecibidas) ra.TotalIVA = If(ra.CuotaIVA1.HasValue, ra.CuotaIVA1.Value, 0) + If(ra.CuotaIVA2.HasValue, ra.CuotaIVA2.Value, 0) + If(ra.CuotaIVA3.HasValue, ra.CuotaIVA3.Value, 0) ra.TotalFactura = Math.Round(ra.TotalBaseImponible + ra.TotalIVA - ra.IRPF, 2, MidpointRounding.AwayFromZero) ra.ImportePagado = Math.Round(ra.movimientoscaja.Sum(Function(x) x.ImporteNegativo), 2, MidpointRounding.AwayFromZero) End Sub Private Sub tvDetalle_ValidaFila(sender As Object, e As DevExpress.Xpf.Grid.GridRowValidationEventArgs) Handles tvDetalle.ValidateRow 'Dim df As detallesfacturasrecibidas = e.Row 'Dim htErrores = New Hashtable 'If df.Cantidad = 0 Then ' DXMessageBox.Show("La Cantidad no puede ser 0", "Error") ' e.SetError("La Cantidad no puede ser 0") ' e.IsValid = False 'End If Try Dim htErrores = New Hashtable ErroresValidacion.LimpiarErrores("TSGC-" & gcDetalle.PropiedadesTS.NumeroObjeto.ToString & ":" & e.RowHandle.ToString & ":") Dim df As detallesfacturasrecibidas = e.Row If df.Cantidad = 0 Then htErrores.Add("Cantidad0", "La Cantidad no puede ser 0") End If If htErrores.Count > 0 Then Me.AgregaErroresTSGC(gcDetalle, htErrores, e) End If Catch ex As Exception FuncionesDinamicas.ErrorNoControladoAp(Me, ex) DXMessageBox.Show(ex.Message, "Error") End Try End Sub Private Sub gcDetalle_DespuesEliminar(gc As tsGridControl) Handles gcDetalle.DespuesEliminar CalculaTotales() End Sub Private Sub tvRecibos_ValidaFila(sender As Object, e As GridRowValidationEventArgs) Handles tvRecibos.ValidateRow 'Dim mv As movimientoscaja = e.Row 'If mv.Importe = 0 Then ' DXMessageBox.Show("El Importe no puede ser 0", "Error") ' e.SetError("El Importe no puede ser 0") ' e.IsValid = False 'End If Try Dim htErrores = New Hashtable ErroresValidacion.LimpiarErrores("TSGC-" & gcRecibos.PropiedadesTS.NumeroObjeto.ToString & ":" & e.RowHandle.ToString & ":") Dim mv As movimientoscaja = e.Row If mv.Importe = 0 Then htErrores.Add("Importe0", "El Importe no puede ser 0") End If If htErrores.Count > 0 Then Me.AgregaErroresTSGC(gcRecibos, htErrores, e) End If Catch ex As Exception FuncionesDinamicas.ErrorNoControladoAp(Me, ex) DXMessageBox.Show(ex.Message, "Error") End Try End Sub Private Sub gcRecibos_DespuesEliminar(gc As tsGridControl) Handles gcRecibos.DespuesEliminar CalculaTotales() End Sub Private Sub tvRecibos_RowUpdated(sender As Object, e As RowEventArgs) Handles tvRecibos.RowUpdated Dim ra As facturasrecibidas = Me.DataContext CalculaTotalesFinales(ra) End Sub Private Sub tvRecibos_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles tvRecibos.InitNewRow gcRecibos.SetCellValue(e.RowHandle, "Fecha", Now) gcRecibos.SetCellValue(e.RowHandle, "FechaCreacion", Now) End Sub Private Sub ucFacturaRecibida_CampoActualizado(sender As Object, e As DataTransferEventArgs) Handles Me.CampoActualizado Dim pts As PropiedadesTS = sender.parent.propiedadests If Not pts Is Nothing Then Dim ra As facturasrecibidas = Me.DataContext Select Case pts.NombreCampo.ToLower Case "porcentajeirpf" CalculaIRPF(ra) CalculaTotalesFinales(ra) Case "cuotaiva1", "cuotaiva2", "cuotaiva3", "irpf" CalculaTotalesFinales(ra) Case "idproveedor_nulable" ra.idProveedorNavigation = bd.entidades.First(Function(x) x.idEntidad = ra.idProveedor) End Select End If End Sub Private Sub tvDetalle_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles tvDetalle.InitNewRow gcDetalle.SetCellValue(e.RowHandle, "idTipoIVA", ivas.OrderByDescending(Function(x) x.ValorNumerico1).First.idEnumeracion) End Sub Private Sub tvDetalle_PreviewKeyDown(sender As Object, e As Input.KeyEventArgs) Handles tvDetalle.PreviewKeyDown If e.Key = Key.F6 Then Select Case gcDetalle.CurrentColumn.FieldName.ToLower Case "idproducto" tvDetalle.ShowEditor() BiBuscarProducto_Click(Nothing, Nothing) End Select End If End Sub Private Sub cbRazonSocial_PreviewKeyDown(sender As Object, e As Input.KeyEventArgs) Handles cbRazonSocial.PreviewKeyDown If e.Key = Key.F6 Then BiBuscarProveedor_Click(Nothing, Nothing) End If End Sub Private Sub gcRecibos_AntesEliminar(gc As tsGridControl, ByRef Cancelar As Boolean) Handles gcRecibos.AntesEliminar Dim da As movimientoscaja = gc.CurrentItem If da.idMovimientoCierre.HasValue Then DXMessageBox.Show("No se puede eliminar un pago ya que está cerrado") Cancelar = True End If End Sub Private Sub tvDocumentos_ValidateRow(sender As Object, e As GridRowValidationEventArgs) Handles tvDocumentos.ValidateRow Dim ges As documentosfacturasrecibidas = gcDocumentos.CurrentItem If ges.idUsuario.HasValue = False Then ges.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario End If End Sub Private Sub VerDocumento(sender As System.Object, e As System.Windows.RoutedEventArgs) Try Dim exp As documentosfacturasrecibidas = gcDocumentos.CurrentItem If exp IsNot Nothing AndAlso exp.idFicheroNavigation IsNot Nothing AndAlso exp.idFicheroNavigation.NombreFichero IsNot Nothing AndAlso exp.idFicheroNavigation.Fichero IsNot Nothing Then Dim sftmp As String = tsUtilidades.Utilidades.ObtieneDirectorioAleatorio("GrupoSanchoToro") & "\" & exp.idFicheroNavigation.NombreFichero tsUtilidades.Utilidades.ByteArrayAFichero(exp.idFicheroNavigation.Fichero, sftmp, True) tsUtilidades.Sistema.EjecutaFichero(sftmp) End If Catch ex As Exception End Try End Sub Private Sub Examinar(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btFichero.DefaultButtonClick Try If gcDocumentos.CurrentItem Is Nothing Then tvDocumentos.AddNewRow() Dim exp As documentosfacturasrecibidas = gcDocumentos.CurrentItem Dim ofd As New OpenFileDialog If ofd.ShowDialog() Then Dim fin As New FileInfo(ofd.FileName) If fin.Length > 1024 * 1024 * 50 Then DXMessageBox.Show("El fichero no puede ser mayor de 50 Mb", "Atención") Else Dim f() As Byte = IO.File.ReadAllBytes(ofd.FileName) Dim idTipoDocumentoExp = bd.enumeraciones.First(Function(x) x.Codigo = "TIPFIC.EXPENT").idEnumeracion If exp.idFicheroNavigation Is Nothing Then Dim fi As New db.ficheros exp.idFicheroNavigation = fi End If exp.idFicheroNavigation.NombreFichero = IO.Path.GetFileName(ofd.FileName) exp.idFicheroNavigation.Fichero = f exp.idFicheroNavigation.Fecha = Now exp.idFicheroNavigation.Descripcion = exp.Descripcion.Acortar(80) exp.idFicheroNavigation.idTipo = idTipoDocumentoExp exp.Fecha = Now Dim usu = bd.usuarios.First(Function(x) x.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario) exp.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario exp.idUsuarioNavigation = usu tvDocumentos.MoveNextCell() gcDocumentos.RefreshRow(tvDocumentos.FocusedRowHandle) End If End If Catch ex As Exception DXMessageBox.Show(ex.Message, "Error") End Try End Sub Private Sub tvDocumentos_PreviewKeyDown(sender As Object, e As KeyEventArgs) If e.Key = Key.F6 AndAlso gcDocumentos.CurrentColumn.FieldName.ToLower = "ficheros.nombrefichero" Then Examinar(Nothing, Nothing) End If End Sub Private Sub tvDocumentos_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles tvDocumentos.InitNewRow gcDocumentos.SetCellValue(e.RowHandle, "Fecha", Now) End Sub Private Sub teBI1_EditValueChanged(sender As Object, e As EditValueChangedEventArgs) Handles teBI1.EditValueChanged EstableceSoloLectura(teCuotaIVA1, ra IsNot Nothing AndAlso ra.BaseImponible1.HasValue AndAlso ra.BaseImponible1.Value <> 0) End Sub Private Sub teBI2_EditValueChanged(sender As Object, e As EditValueChangedEventArgs) Handles teBI1.EditValueChanged EstableceSoloLectura(teCuotaIVA2, ra IsNot Nothing AndAlso ra.BaseImponible2.HasValue AndAlso ra.BaseImponible2.Value <> 0) End Sub Private Sub teBI3_EditValueChanged(sender As Object, e As EditValueChangedEventArgs) Handles teBI1.EditValueChanged EstableceSoloLectura(teCuotaIVA3, ra IsNot Nothing AndAlso ra.BaseImponible3.HasValue AndAlso ra.BaseImponible3.Value <> 0) End Sub Private Sub EstableceSoloLecturaCI() EstableceSoloLectura(teCuotaIVA1, ra IsNot Nothing AndAlso ra.BaseImponible1.HasValue AndAlso ra.BaseImponible1.Value <> 0) EstableceSoloLectura(teCuotaIVA2, ra IsNot Nothing AndAlso ra.BaseImponible2.HasValue AndAlso ra.BaseImponible2.Value <> 0) EstableceSoloLectura(teCuotaIVA3, ra IsNot Nothing AndAlso ra.BaseImponible3.HasValue AndAlso ra.BaseImponible3.Value <> 0) End Sub End Class