2026-01-30-v2
This commit is contained in:
@@ -0,0 +1,613 @@
|
||||
Option Strict Off
|
||||
Imports DevExpress.Xpf.Editors
|
||||
Imports DevExpress.Xpf.LayoutControl
|
||||
Imports tsWPF
|
||||
Imports System.ComponentModel
|
||||
Imports System.Data
|
||||
Imports DevExpress.Xpf.Editors.Validation
|
||||
Imports DevExpress.Xpf.Editors.Helpers
|
||||
Imports DevExpress.Xpf.Core
|
||||
Imports tsWPF.modExtensiones
|
||||
Imports System.Data.Common
|
||||
Imports System.Data.Entity
|
||||
Imports bdGrupoSanchoToro
|
||||
Imports DevExpress.Xpf.Grid
|
||||
Imports tsl5.Extensiones
|
||||
Imports bdGrupoSanchoToro.apuntes
|
||||
Imports DevExpress.Xpf.Bars
|
||||
Imports tsl5.Datos
|
||||
Imports System.Windows.Media.Animation
|
||||
Imports tsWPF.Comun
|
||||
Imports tsWPFCore.Comun
|
||||
Imports tsWPFCore
|
||||
Imports tsUtilidades
|
||||
|
||||
Imports bdGrupoSanchoToro.db
|
||||
Imports bdGrupoSanchoToro.db.Utilidades
|
||||
|
||||
Public Class ucDiario
|
||||
Private bd As tscGrupoSanchoToro
|
||||
Private _idAsiento? As Integer
|
||||
Private tbAlerta As TextBlock
|
||||
Private ra As asientos
|
||||
Public Sub New(Optional idAsiento As Integer? = Nothing)
|
||||
|
||||
' Esta llamada es exigida por el diseñador.
|
||||
InitializeComponent()
|
||||
_idAsiento = idAsiento
|
||||
' Agregue cualquier inicialización después de la llamada a InitializeComponent().
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides ReadOnly Property idRegistroAplicacionActual As String
|
||||
Get
|
||||
If Estado = EstadosAplicacion.Nuevo Then
|
||||
Return "Asiento.Nuevo"
|
||||
Else
|
||||
Return "Asiento." & DirectCast(Me.DataContext, asientos).idAsiento.ToString
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Overrides ReadOnly Property DescripcionRegistro As String
|
||||
Get
|
||||
Return "Asientos"
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Overrides ReadOnly Property NombreTablaBase As String
|
||||
Get
|
||||
Return "asientos"
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False)
|
||||
cbTipoDocumento.ItemsSource = bdGrupoSanchoToro.db.apuntes.ListaTiposDocumentos
|
||||
|
||||
If Me.ContenedorAplicacion.cbAcciones.ItemsSource Is Nothing Then
|
||||
Dim Acciones As New List(Of tsWPFCore.Accion)
|
||||
Acciones.Add(New Accion With {
|
||||
.idAccion = 1,
|
||||
.Descripcion = "LEE ASIENTO MODELO"})
|
||||
Acciones.Add(New Accion With {
|
||||
.idAccion = 2,
|
||||
.Descripcion = "COPIA ASIENTO ACTUAL COMO ASIENTO MODELO"})
|
||||
Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones
|
||||
Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub EstableceTitulo()
|
||||
If Me.docpanel Is Nothing Then
|
||||
Dim w As dxwGenerica = Window.GetWindow(Me)
|
||||
w.Title = "Agregar nuevo asiento"
|
||||
Else
|
||||
If Me.Estado = EstadosAplicacion.ModificandoRegistro Then
|
||||
Dim asiento As asientos = Me.DataContext
|
||||
Me.docpanel.Caption = "Asiento " & asiento.idAsiento.ToString
|
||||
Me.docpanel.Tag = "Asiento." & asiento.idAsiento.ToString
|
||||
Else
|
||||
Me.docpanel.Caption = "Asiento Nuevo"
|
||||
Me.docpanel.Tag = "Asiento.Nuevo"
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub Cargado()
|
||||
Me.Tipo_ucControlBusqueda = GetType(ucDiarios)
|
||||
' Me.GridBusqueda = GetType(ucDiarios)
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function EstableceDCPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As EstadosAplicacion
|
||||
Dim NuevoEstado As EstadosAplicacion
|
||||
If FuerzaNuevo OrElse _idAsiento Is Nothing Then
|
||||
|
||||
ra = New asientos
|
||||
ra.Fecha = Today ' If(uEc.FechaFin > Now.Date, Now.Date, uEc.FechaFin)
|
||||
ra.FechaIntroduccion = Now
|
||||
Dim uEc = bd.ejercicioscontables.FirstOrDefault(Function(x) x.FechaInicio <= ra.Fecha And x.FechaFin >= ra.Fecha And x.FechaCierre Is Nothing)
|
||||
If uEc Is Nothing Then
|
||||
uEc = bd.ejercicioscontables.Where(Function(x) x.FechaCierre Is Nothing).OrderByDescending(Function(x) x.FechaInicio).First
|
||||
ra.Fecha = uEc.FechaInicio
|
||||
End If
|
||||
ra.idEjercicioNavigation = uEc
|
||||
ra.idEjercicio = uEc.idEjercicio
|
||||
ra.Tipo = bdGrupoSanchoToro.db.asientos.TipoAsiento.NORMAL
|
||||
ra.Punteado = False
|
||||
NuevoEstado = EstadosAplicacion.Nuevo
|
||||
ra.usuarios = bd.usuarios.First(Function(x) x.idUsuario = bdGrupoSanchoToro.Utilidades.dsc.idUsuario)
|
||||
Else
|
||||
ra = bd.asientos.First(Function(x) x.idAsiento = _idAsiento)
|
||||
NuevoEstado = EstadosAplicacion.ModificandoRegistro
|
||||
End If
|
||||
Me.DataContext = ra
|
||||
ra.RellenaCuentaTmp()
|
||||
gcApuntes.ItemsSource = ra.apuntes
|
||||
Return NuevoEstado
|
||||
|
||||
End Function
|
||||
|
||||
Public Overrides Function ObtieneBD() As tsUtilidades.ItsContexto
|
||||
bd = tscGrupoSanchoToro.NuevoContexto()
|
||||
Return bd
|
||||
End Function
|
||||
|
||||
'Public Overrides Function ObtieneConexionBD() As BBDD
|
||||
' Return bdGrupoSanchoToro.gestionasegasaEntities.bdga
|
||||
'End Function
|
||||
|
||||
Public Overrides Function ObtienePermisos() As tsUtilidades.Permisos
|
||||
Return Comun.ObtienePermisos(Me.bd, "AP.CONTABILIDAD", idUsuario)
|
||||
End Function
|
||||
|
||||
Private Sub ucDiario_AntesGuardar(sender As Object, e As DevExpress.Xpf.Bars.ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, OpcionGuardado As Integer) Handles Me.AntesGuardar
|
||||
Dim hte As New Hashtable
|
||||
Dim sd = Math.Round(ra.apuntes.Sum(Function(x) x.Debe), 2, MidpointRounding.AwayFromZero)
|
||||
Dim sh = Math.Round(ra.apuntes.Sum(Function(x) x.Haber), 2, MidpointRounding.AwayFromZero)
|
||||
If sd <> sh Then
|
||||
hte.Add("Almacenar-SUMA", "La suma del Debe no coincide con la suma del Haber")
|
||||
Else
|
||||
If ra.apuntes.Count < 2 Then
|
||||
hte.Add("Almacenar-Apuntes", "Es obligatorio meter al menos 2 apuntes")
|
||||
End If
|
||||
End If
|
||||
If ra.apuntes.Any(Function(x) x.TipoDocumento.HasValue AndAlso (x.TipoDocumento = TiposDocumentos.FACTURA And x.NumeroDocumento.NothingAVacio = "")) Then
|
||||
hte.Add("Almacenar-FaltaNumeroDocumento", "Es obligatorio meter el nº de documento en los apuntes de tipo factura")
|
||||
End If
|
||||
ra.Fecha = ra.Fecha.Date
|
||||
Dim ej = bd.ejercicioscontables.FirstOrDefault(Function(x) x.FechaInicio <= ra.Fecha And x.FechaFin >= ra.Fecha And x.FechaCierre.HasValue = False)
|
||||
If ej Is Nothing Then
|
||||
hte.Add("Almacenar-EjercicioNoAbiertooCerrado", "El ejercicio según la fecha del asiento no se ha abierto o ya se cerró")
|
||||
End If
|
||||
If Estado = EstadosAplicacion.Nuevo Then
|
||||
ra.FechaIntroduccion = tsl5.bbdd.AhoraSqlServer(bd)
|
||||
ra.idUsuario = idUsuario
|
||||
End If
|
||||
If hte.Count > 0 Then
|
||||
MensajesError = hte
|
||||
Cancelar = True
|
||||
Else
|
||||
ra.idEjercicioNavigation = ej
|
||||
ra.idEjercicio = ej.idEjercicio
|
||||
ra.EjercicioTmp = ej.Descripcion
|
||||
For Each ap In ra.apuntes
|
||||
ap.idCuenta = bd.cuentas.First(Function(x) x.idEjercicio = ra.idEjercicio And x.NumeroCuenta = ap.NumeroCuentaTmp).idCuenta
|
||||
If ap.idAsientoNavigation Is Nothing Then ap.idAsientoNavigation = ra
|
||||
Next
|
||||
ra.Importe = sd
|
||||
' If ra.NumeroAsiento.HasValue = False Then ra.EstableceNumeroAsiento(bd)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub ucpersona_ValidarControl(sender As Object, e As DevExpress.Xpf.Editors.ValidationEventArgs, ByRef ev As ErrorValidacion, ByRef ValorOriginalCambiado As Object) Handles Me.ValidarControl
|
||||
Try
|
||||
Dim pts As PropiedadesTS = sender.parent.propiedadests
|
||||
|
||||
If Not pts Is Nothing Then
|
||||
Select Case pts.NombreCampo.ToLower
|
||||
Case "fecha"
|
||||
|
||||
Dim NuevaFecha As DateOnly = e.Value
|
||||
NuevaFecha = NuevaFecha.Date
|
||||
If NuevaFecha <> ra.Fecha Then
|
||||
Dim Ejercicios = bd.ejercicioscontables.ToList
|
||||
Dim EjercicioNuevo = Ejercicios.FirstOrDefault(Function(x) x.FechaInicio <= NuevaFecha And x.FechaFin >= NuevaFecha And x.FechaCierre Is Nothing)
|
||||
If EjercicioNuevo Is Nothing Then
|
||||
ev = New ErrorValidacion(DirectCast(sender.parent.propiedadests, PropiedadesTS).NumeroObjeto, sender, "No existe ningún ejercicio abierto con la fecha indicada", Nothing, DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical)
|
||||
Else
|
||||
Dim EjercicioAnterior = Ejercicios.FirstOrDefault(Function(x) x.FechaInicio <= ra.Fecha And x.FechaFin >= ra.Fecha)
|
||||
If EjercicioAnterior IsNot Nothing AndAlso ra.apuntes.Count > 1 Then
|
||||
Dim sCuentasFaltantes As String = ""
|
||||
If EjercicioAnterior.idEjercicio <> EjercicioNuevo.idEjercicio Then
|
||||
For Each ap In ra.apuntes
|
||||
Dim cta = ap.idCuentaNavigation.NumeroCuenta
|
||||
If Not bd.cuentas.Any(Function(x) x.NumeroCuenta = cta And x.idEjercicio = EjercicioNuevo.idEjercicio) Then
|
||||
sCuentasFaltantes &= cta & ","
|
||||
End If
|
||||
Next
|
||||
If sCuentasFaltantes <> "" Then
|
||||
ev = New ErrorValidacion(DirectCast(sender.parent.propiedadests, PropiedadesTS).NumeroObjeto, sender, "En el ejercicio de la fecha indicada, no existen las cuentas " & sCuentasFaltantes, Nothing, DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical)
|
||||
Else
|
||||
ra.idEjercicioNavigation = EjercicioNuevo
|
||||
ra.idEjercicio = EjercicioNuevo.idEjercicio
|
||||
ra.NumeroAsiento = Nothing
|
||||
ra.RellenaCuentaTmp()
|
||||
teEjercicio.EditValue = EjercicioNuevo.Descripcion
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Select
|
||||
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub BtCuenta_DefaultButtonClick(sender As Object, e As RoutedEventArgs)
|
||||
Try
|
||||
|
||||
Dim dxw As New dxwCuentas(bd, ra.idEjercicio)
|
||||
If dxw.ShowDialog Then
|
||||
|
||||
' If tvApuntes.HasValidationError Then tvApuntes.CancelRowEdit()
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
If tvApuntes.ActiveEditor Is Nothing Then
|
||||
Dispatcher.BeginInvoke(New Action(Sub() tvApuntes.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render)
|
||||
End If
|
||||
|
||||
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
Dim cta = bd.cuentas.First(Function(x) x.idCuenta = dxw.idCuenta)
|
||||
ap.NumeroCuentaTmp = cta.NumeroCuenta
|
||||
ap.DescripcionCuentaTmp = cta.Denominacion
|
||||
If tvApuntes.ActiveEditor IsNot Nothing Then tvApuntes.ActiveEditor.EditValue = cta.NumeroCuenta
|
||||
tvApuntes.PostEditor()
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
tvApuntes.MoveNextCell()
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub tvApuntes_CellValueChanged(sender As Object, e As CellValueChangedEventArgs) Handles tvApuntes.CellValueChanged
|
||||
Try
|
||||
|
||||
Dim ap As apuntes = e.Row
|
||||
If ap IsNot Nothing Then
|
||||
Select Case e.Column.FieldName.ToLower
|
||||
Case "numerocuentatmp"
|
||||
Dim NumeroCuenta As String = ap.NumeroCuentaTmp.NothingAVacio
|
||||
If NumeroCuenta.Contains(".") Then
|
||||
NumeroCuenta = NumeroCuenta.Replace(".", "0".PadRight(9 - NumeroCuenta.Length, "0")).Acortar(8)
|
||||
ap.NumeroCuentaTmp = NumeroCuenta
|
||||
End If
|
||||
Dim cta = bd.cuentas.FirstOrDefault(Function(x) x.NumeroCuenta = NumeroCuenta And x.idEjercicio = ra.idEjercicio)
|
||||
If cta IsNot Nothing Then
|
||||
ap.DescripcionCuentaTmp = cta.Denominacion
|
||||
ap.idCuentaNavigation = cta
|
||||
End If
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
End Select
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub BtConcepto_DefaultButtonClick(sender As Object, e As RoutedEventArgs)
|
||||
Try
|
||||
Dim dxw As New dxwConceptosPredefinidos(bd)
|
||||
If dxw.ShowDialog Then
|
||||
|
||||
' If tvApuntes.HasValidationError Then tvApuntes.CancelRowEdit()
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
If tvApuntes.ActiveEditor Is Nothing Then
|
||||
Dispatcher.BeginInvoke(New Action(Sub() tvApuntes.ShowEditor()), System.Windows.Threading.DispatcherPriority.Render)
|
||||
End If
|
||||
|
||||
Dim con = bd.conceptosapuntes.First(Function(x) x.idConcepto = dxw.idConcepto)
|
||||
ap.Concepto = con.Concepto
|
||||
If tvApuntes.ActiveEditor IsNot Nothing Then tvApuntes.ActiveEditor.EditValue = con.Concepto
|
||||
tvApuntes.PostEditor()
|
||||
tvApuntes.CloseEditor()
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
tvApuntes.MoveNextCell()
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub tvApuntes_ValidateRow(sender As Object, e As GridRowValidationEventArgs) Handles tvApuntes.ValidateRow
|
||||
|
||||
Try
|
||||
Dim htErrores = New Hashtable
|
||||
ErroresValidacion.LimpiarErrores("TSGC-" & gcApuntes.PropiedadesTS.NumeroObjeto.ToString & ":" & e.RowHandle.ToString & ":")
|
||||
Dim ap As apuntes = e.Row
|
||||
|
||||
If ap.Debe <> 0 And ap.Haber <> 0 Then
|
||||
htErrores.Add("ValoresEnDebeYHaber", "Los asientos no pueden tener valor en el debe y el haber al mismo tiempo")
|
||||
End If
|
||||
If ap.Debe = 0 And ap.Haber = 0 Then
|
||||
htErrores.Add("Valor0EnDebeYHaber", "Los asientos deben tener algún valor en el debe y el haber")
|
||||
End If
|
||||
If htErrores.Count > 0 Then
|
||||
Me.AgregaErroresTSGC(gcApuntes, htErrores, e)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub apCL_EstadoCambiado(EstadoAnterior As EstadosAplicacion, EstadoNuevo As EstadosAplicacion) Handles Me.EstadoCambiado
|
||||
Try
|
||||
Select Case EstadoNuevo
|
||||
Case EstadosAplicacion.ModificandoRegistro
|
||||
Dim ra As asientos = DataContext
|
||||
If ra.idEjercicioNavigation.FechaCierre.HasValue Then
|
||||
EstableceSoloLectura()
|
||||
End If
|
||||
End Select
|
||||
EstableceAlerta()
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub TbAlerta_Loaded(sender As Object, e As RoutedEventArgs)
|
||||
Try
|
||||
If tbAlerta Is Nothing Then
|
||||
tbAlerta = sender
|
||||
EstableceAlerta()
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
Private Sub EstableceAlerta()
|
||||
Try
|
||||
If tbAlerta IsNot Nothing Then
|
||||
Dim ra As asientos = Me.DataContext
|
||||
If ra.idEjercicioNavigation IsNot Nothing AndAlso ra.idEjercicioNavigation.FechaInicio.Year <> Now.Year Then
|
||||
tbAlerta.Visibility = Visibility.Visible
|
||||
Dim Emp = ra.idEjercicioNavigation.Descripcion
|
||||
tbAlerta.Text = "Atención: Ejercicio " & Emp
|
||||
Dim sb As Storyboard = Me.FindResource("sbBlink")
|
||||
Storyboard.SetTarget(sb, tbAlerta)
|
||||
BeginStoryboard(sb)
|
||||
Else
|
||||
tbAlerta.Visibility = Visibility.Hidden
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Private Sub GcNumeroCuenta_Validate(sender As Object, e As GridCellValidationEventArgs)
|
||||
Try
|
||||
If e IsNot Nothing AndAlso e.Value IsNot Nothing Then
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
Dim NumeroCuenta As String = e.Value.ToString
|
||||
If Not bd.cuentas.Any(Function(x) x.NumeroCuenta = NumeroCuenta And x.EsCuentaFinal And x.idEjercicio = ra.idEjercicio) Then
|
||||
If NumeroCuenta.Contains(".") Then
|
||||
NumeroCuenta = NumeroCuenta.Replace(".", "0".PadRight(9 - NumeroCuenta.Length, "0")).Acortar(8)
|
||||
End If
|
||||
If Not bd.cuentas.Any(Function(x) x.NumeroCuenta = NumeroCuenta And x.EsCuentaFinal And x.idEjercicio = ra.idEjercicio) Then
|
||||
e.SetError("Nº de cuenta incorrecto")
|
||||
Else
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
ap.NumeroCuentaTmp = NumeroCuenta
|
||||
End If
|
||||
Else
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
ap.NumeroCuentaTmp = NumeroCuenta
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
||||
DXMessageBox.Show(ex.Message, "Error")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub VerDocumento_Click(sender As Object, e As RoutedEventArgs)
|
||||
If gcApuntes.CurrentItem IsNot Nothing Then
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
VerDocumentoApunte(bd, ap)
|
||||
End If
|
||||
End Sub
|
||||
Friend Shared Sub VerDocumentoApunte(bd As tscGrupoSanchoToro, ap As apuntes)
|
||||
If ap.NumeroDocumento.NothingAVacio <> "" AndAlso ap.TipoDocumento.HasValue Then
|
||||
Select Case ap.TipoDocumento
|
||||
Case TiposDocumentos.RECIBO
|
||||
Dim rec = bd.movimientoscaja.FirstOrDefault(Function(x) x.idMovimiento = ap.idAplicacion)
|
||||
If rec IsNot Nothing Then
|
||||
Dim uc As New ucMovimientoCaja(rec.idRecibo)
|
||||
FuncionesDinamicas.AbrirAP(uc)
|
||||
Else
|
||||
DXMessageBox.Show("El recibo no se encuentra", "Atención")
|
||||
End If
|
||||
Case Else
|
||||
DXMessageBox.Show("Tipo de documento no disponible", "Atención")
|
||||
End Select
|
||||
End If
|
||||
End Sub
|
||||
|
||||
' Private Sub apCL_AntesEliminar(sender As Object, e As ItemClickEventArgs, ByRef Cancelar As Boolean, ByRef MensajesError As Hashtable, ByRef EliminacionManual As Boolean) Handles Me.AntesEliminar
|
||||
'bd.asientos.DeleteObject(ra)
|
||||
'bd.GuardarCambios()
|
||||
'Cancelar = True
|
||||
' End Sub
|
||||
|
||||
Private Sub ucDiario_DespuesGuardar(sender As Object, e As ItemClickEventArgs, OpcionGuardado As Integer) Handles Me.DespuesGuardar
|
||||
_idAsiento = ra.idAsiento
|
||||
ra.RefrescaExtensiones
|
||||
End Sub
|
||||
|
||||
Private Sub ucDiario_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion
|
||||
Select Case idAccion
|
||||
Case 1 ' lee asiento modelo
|
||||
If Me.Estado = EstadosAplicacion.Nuevo AndAlso ra.apuntes.Count = 0 AndAlso ra.idEjercicio > 0 Then
|
||||
Dim dxwam As New dxwAsientosModelo(bd)
|
||||
If dxwam.ShowDialog Then
|
||||
Dim am = bd.asientosmodelos.First(Function(x) x.idAsientoModelo = dxwam.idAsientoModelo)
|
||||
ra.idAsientoModelo = am.idAsientoModelo
|
||||
For Each ap In am.apuntesmodelo.OrderBy(Function(x) x.Orden)
|
||||
Dim na As New apuntes
|
||||
With na
|
||||
Dim CTA = bd.cuentas.FirstOrDefault(Function(x) x.idEjercicio = ra.idEjercicio And x.NumeroCuenta = ap.NumeroCuenta)
|
||||
If CTA IsNot Nothing Then
|
||||
na.DescripcionCuentaTmp = CTA.Denominacion
|
||||
na.NumeroCuentaTmp = CTA.NumeroCuenta
|
||||
na.idCuentaNavigation = CTA
|
||||
na.Concepto = ap.Concepto
|
||||
na.Debe = ap.Debe
|
||||
na.Haber = ap.Haber
|
||||
na.idConcepto = ap.idConcepto
|
||||
na.NumeroDocumento = ap.NumeroDocumento
|
||||
na.TipoDocumento = ap.TipoDocumento
|
||||
Else
|
||||
DXMessageBox.Show("Cuenta " & ap.NumeroCuenta & " no existente.", "Atención")
|
||||
End If
|
||||
End With
|
||||
ra.apuntes.Add(na)
|
||||
Next
|
||||
Me.gcApuntes.RefreshData()
|
||||
End If
|
||||
Else
|
||||
DXMessageBox.Show("Solo se pueden leer apuntes si aún está sin apuntes y tiene fecha", "Atención")
|
||||
End If
|
||||
Case 2
|
||||
Dim SoloLectura = Not Me.ContenedorAplicacion.btGuardar.IsEnabled
|
||||
Dim Continuar = SoloLectura
|
||||
If Not SoloLectura Then
|
||||
Continuar = Me.Guardar(Nothing, Nothing, True) = False
|
||||
End If
|
||||
If Continuar Then
|
||||
Dim uc As New ucAsientoModelo(Nothing, ra.idAsiento)
|
||||
FuncionesDinamicas.AbrirAP(uc, OtrosParametros)
|
||||
End If
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub tvApuntes_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles tvApuntes.PreviewKeyDown
|
||||
If e.Key = Key.F6 Then
|
||||
Select Case gcApuntes.CurrentColumn.FieldName.ToLower
|
||||
Case "numerocuentatmp"
|
||||
tvApuntes.ShowEditor()
|
||||
BtCuenta_DefaultButtonClick(Nothing, Nothing)
|
||||
Case "concepto"
|
||||
tvApuntes.ShowEditor()
|
||||
BtConcepto_DefaultButtonClick(Nothing, Nothing)
|
||||
End Select
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub gcApuntes_EnterPulsado() Handles gcApuntes.EnterPulsado
|
||||
Select Case gcApuntes.CurrentColumn.FieldName.ToLower
|
||||
Case "concepto"
|
||||
If tvApuntes.FocusedRowHandle = DataControlBase.NewItemRowHandle Then
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
Dim apant = ra.apuntes.LastOrDefault(Function(x) x.Concepto <> "")
|
||||
If apant IsNot Nothing Then
|
||||
ap.idConcepto = apant.idConcepto
|
||||
ap.Concepto = apant.Concepto
|
||||
End If
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
End If
|
||||
Case "tipodocumento"
|
||||
If tvApuntes.FocusedRowHandle = DataControlBase.NewItemRowHandle Then
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
Dim apant = ra.apuntes.LastOrDefault(Function(x) x.TipoDocumento.HasValue)
|
||||
If apant IsNot Nothing Then
|
||||
ap.TipoDocumento = apant.TipoDocumento
|
||||
End If
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
End If
|
||||
Case "numerodocumento"
|
||||
If tvApuntes.FocusedRowHandle = DataControlBase.NewItemRowHandle Then
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
Dim apant = ra.apuntes.LastOrDefault(Function(x) x.NumeroDocumento.NothingAVacio <> "")
|
||||
If apant IsNot Nothing Then
|
||||
ap.NumeroDocumento = apant.NumeroDocumento
|
||||
End If
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
End If
|
||||
Case "numerocuentatmp"
|
||||
If tvApuntes.FocusedRowHandle = DataControlBase.NewItemRowHandle Then
|
||||
If gcApuntes.CurrentItem Is Nothing Then tvApuntes.AddNewRow()
|
||||
Dim ap As apuntes = gcApuntes.CurrentItem
|
||||
Dim apant = ra.apuntes.LastOrDefault
|
||||
If apant IsNot Nothing Then
|
||||
ap.NumeroCuentaTmp = apant.NumeroCuentaTmp
|
||||
Dim cta = bd.cuentas.FirstOrDefault(Function(x) x.NumeroCuenta = ap.NumeroCuentaTmp And x.idEjercicio = ra.idEjercicio)
|
||||
If cta IsNot Nothing Then
|
||||
ap.DescripcionCuentaTmp = cta.Denominacion
|
||||
ap.idCuentaNavigation = cta
|
||||
End If
|
||||
gcApuntes.RefreshRow(tvApuntes.FocusedRowHandle)
|
||||
End If
|
||||
End If
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub ucDiario_ErrorGuardando(sender As Object, ex As Exception, OpcionGuardado As Integer) Handles Me.ErrorGuardando
|
||||
Try
|
||||
Dim ea = bd.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added)
|
||||
Dim ee = bd.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Deleted)
|
||||
Dim em = bd.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Modified)
|
||||
Dim sMensaje As String = "Entidades Añadidas: " & ea.Count.ToString
|
||||
For Each ent In ea
|
||||
Select Case ent.Entity.GetType
|
||||
Case GetType(apuntes)
|
||||
Dim ap As apuntes = ent.Entity
|
||||
sMensaje &= vbCrLf & " Nº Asiento " & ap.idAsiento.ToString & " Concepto " & ap.Concepto & " Debe " & ap.Debe.ToString("c2") & " Haber " & ap.Haber.ToString("c2")
|
||||
End Select
|
||||
Next
|
||||
sMensaje &= vbCrLf & "Entidades Eliminadas: " & ee.Count.ToString
|
||||
For Each ent In ee
|
||||
Select Case ent.Entity.GetType
|
||||
Case GetType(apuntes)
|
||||
Dim ap As apuntes = ent.Entity
|
||||
sMensaje &= vbCrLf & " Nº Asiento " & ap.idAsiento.ToString & " Concepto " & ap.Concepto & " Debe " & ap.Debe.ToString("c2") & " Haber " & ap.Haber.ToString("c2") & " idApunte " & ap.idApunte.ToString
|
||||
End Select
|
||||
Next
|
||||
|
||||
sMensaje &= vbCrLf & "Entidades Modificadas: " & ee.Count.ToString
|
||||
For Each ent In ee
|
||||
Select Case ent.Entity.GetType
|
||||
Case GetType(apuntes)
|
||||
Dim ap As apuntes = ent.Entity
|
||||
sMensaje &= vbCrLf & " Nº Asiento " & ap.idAsiento.ToString & " Concepto " & ap.Concepto & " Debe " & ap.Debe.ToString("c2") & " Haber " & ap.Haber.ToString("c2") & " idApunte " & ap.idApunte.ToString
|
||||
End Select
|
||||
Next
|
||||
Dim ex2 As New Exception(sMensaje, ex)
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, ex2)
|
||||
Catch exc As Exception
|
||||
FuncionesDinamicas.ErrorNoControladoAp(Me, exc)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub ucDiario_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 "fecha"
|
||||
Dim uEc = bd.ejercicioscontables.FirstOrDefault(Function(x) x.FechaInicio <= ra.Fecha And x.FechaFin >= ra.Fecha And x.FechaCierre Is Nothing)
|
||||
If uEc Is Nothing Then
|
||||
uEc = bd.ejercicioscontables.Where(Function(x) x.FechaCierre Is Nothing).OrderByDescending(Function(x) x.FechaInicio).First
|
||||
ra.Fecha = uEc.FechaInicio
|
||||
End If
|
||||
ra.idEjercicioNavigation = uEc
|
||||
ra.EjercicioTmp = uEc.Descripcion
|
||||
End Select
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user