Imports System.Data.Entity Imports DevExpress.Xpf.Core.ServerMode Imports bdGrupoSanchoToro Imports DevExpress.Xpf.Grid Imports DevExpress.Xpf.Core Imports System.Linq.Dynamic Imports DevExpress.Xpf.Bars Imports tsUtilidades.Datos Imports tsWPF Imports tsWPF.Comun Imports tsWPFCore.Comun Imports tsWPFCore Imports tsUtilidades Imports bdGrupoSanchoToro.db Imports bdGrupoSanchoToro.db.Utilidades Public Class ucApuntes Dim bd As tscGrupoSanchoToro Dim EjerContables As List(Of ejercicioscontables) ' Private _Ejercicios As List(Of Integer) ' Private _NivelCuentas As Integer Public Overrides ReadOnly Property idRegistroAplicacionActual As String Get Return "Apuntes" End Get End Property Public Overrides ReadOnly Property DescripcionRegistro As String Get Return "Apuntes" End Get End Property Public Overrides ReadOnly Property NombreTablaBase As String Get Return "apuntes" End Get End Property Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False) End Sub Public Overrides Sub EstableceTitulo() Me.docpanel.Caption = "Extractos Cuentas" End Sub Public Overrides Sub Cargado() Dim Ejercicios = bd.ejercicioscontables.OrderByDescending(Function(x) x.FechaInicio).ToList Dim ejab = Ejercicios.Where(Function(x) x.FechaCierre Is Nothing) deFechaInicio.EditValue = ejab.OrderBy(Function(x) x.FechaInicio).First.FechaInicio deFechaFin.EditValue = ejab.OrderByDescending(Function(x) x.FechaFin).First.FechaFin End Sub Public Overrides Function EstableceDCPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As EstadosAplicacion Dim Ejercicios = bd.ejercicioscontables.OrderByDescending(Function(x) x.FechaInicio).ToList Return EstadosAplicacion.AplicacionSinIndice End Function Public Overrides Function ObtieneBD() As tsUtilidades.ItsContexto bd = tscGrupoSanchoToro.NuevoContexto() Return bd End Function Public Overrides Function ObtienePermisos() As tsUtilidades.Permisos Return Comun.ObtienePermisos(Me.bd, "AP.CONTABILIDAD", idUsuario) End Function Public Sub New() ' Esta llamada es exigida por el diseñador. InitializeComponent() 'Me.lgFiltrosBusquedaRapida.Visibility = Visibility.Collapsed 'Me.lgFiltrosBusquedaAvanzada.Visibility = Visibility.Visible ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Public Function ObtieneApuntes(ByRef DataContext As Object, BackGround As Boolean, TextoBusqueda As String, FechaInicio As DateOnly, FechaFin As DateOnly) As List(Of ApunteExtracto) Dim rs As List(Of apuntes) Dim parametros(0) As Object Dim iNumExc As Integer = 0 Dim lae As New List(Of ApunteExtracto) Do Try If TextoBusqueda <> "" Then Dim Calf() As String = {"cuentas.Denominacion"} Dim Calfc() As String = {"cuentas.NumeroCuenta"} Dim ExpBus As String = tsWPFCore.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Nothing, Calf, Nothing, Calfc) If ExpBus = "" Then rs = bd.apuntes.Include(Function(x) x.idAsientoNavigation).Include(Function(x) x.idCuentaNavigation).Where(Function(x) x.idAsientoNavigation.Fecha >= FechaInicio And x.idAsientoNavigation.Fecha <= FechaFin).OrderBy(Function(x) x.idCuentaNavigation.NumeroCuenta).ThenBy(Function(x) x.idAsientoNavigation.Fecha).ThenBy(Function(x) x.idAsientoNavigation.NumeroAsiento).ToList() Else rs = bd.apuntes.Include(Function(x) x.idAsientoNavigation).Include(Function(x) x.idCuentaNavigation).Where(ExpBus, parametros).Where(Function(x) x.idAsientoNavigation.Fecha >= FechaInicio And x.idAsientoNavigation.Fecha <= FechaFin).OrderBy(Function(x) x.idCuentaNavigation.NumeroCuenta).ThenBy(Function(x) x.idAsientoNavigation.Fecha).ThenBy(Function(x) x.idAsientoNavigation.NumeroAsiento).ToList End If Else rs = bd.apuntes.Include(Function(x) x.idAsientoNavigation.idAsiento).Include(Function(x) x.idCuentaNavigation.idCuenta).Where(Function(x) x.idAsientoNavigation.Fecha >= FechaInicio And x.idAsientoNavigation.Fecha <= FechaFin).OrderBy(Function(x) x.idCuentaNavigation.NumeroCuenta).ThenBy(Function(x) x.idAsientoNavigation.Fecha).ThenBy(Function(x) x.idAsientoNavigation.NumeroAsiento).ToList() End If Dim rsa = rs.GroupBy(Function(x) x.idCuentaNavigation.NumeroCuenta).ToList Dim orden As Integer Dim SaldoAcumulado As Double = 0 For Each g In rsa Dim ea As New ApunteExtracto orden += 1 With ea .Orden = orden .Concepto = "Saldo Anterior" .Cuenta = g.First().idCuentaNavigation.Denominacion .Debe = g.First.DebeAnterior(bd, FechaInicio) .Haber = g.First.HaberAnterior(bd, FechaInicio) .Saldo = .Debe - .Haber .Tipo = ApunteExtracto.ApunteExtractoTipoEnum.SALDO_ANTERIOR SaldoAcumulado = .Saldo End With lae.Add(ea) For Each apu In g Dim apue As New ApunteExtracto orden += 1 With apue .Orden = orden .Concepto = apu.Concepto .Fecha = apu.idAsientoNavigation.Fecha .Cuenta = apu.idCuentaNavigation.Denominacion .NumeroAsiento = If(apu.idAsiento = 0, "", apu.idAsiento.ToString) .idAsiento = apu.idAsiento .Debe = apu.Debe .Haber = apu.Haber SaldoAcumulado += (apu.Debe - apu.Haber) .Saldo = SaldoAcumulado .Tipo = ApunteExtracto.ApunteExtractoTipoEnum.APUNTE End With lae.Add(apue) Next Next ' rs = bd.asientos.Where(Function(x) x.Fecha >= FechaInicio And x.Fecha <= FechaFin).ToList Exit Do Catch ex As Exception iNumExc += 1 If iNumExc > 3 Then Throw New Exception(ex.Message, ex) End If End Try Loop Return lae End Function Public Async Sub ObtieneApuntesAsync(bd As tscGrupoSanchoToro, Background As Boolean) Try Dim rs As New List(Of ApunteExtracto) Dim fi, ff As DateOnly? Dim Busqueda As String Busqueda = Me.teBusqueda.Text.Trim fi = deFechaInicio.EditValue ff = deFechaFin.EditValue If Background Then Me.ContenedorAplicacion.IsEnabled = False Await Task.Run(Sub() rs = ObtieneApuntes(bd, Background, Busqueda, fi, ff) End Sub) Else If DXSplashScreen.IsActive = False Then DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)() DXSplashScreen.SetState("Buscando Apuntes ...") rs = ObtieneApuntes(bd, Background, Busqueda, fi, ff) End If gc.ItemsSource = rs DataContext = rs gc.ExpandAllGroups() Catch ex As Exception If DXSplashScreen.IsActive Then DXSplashScreen.Close() DXMessageBox.Show(ex.Message, "Error") Finally Me.ContenedorAplicacion.IsEnabled = True If DXSplashScreen.IsActive Then DXSplashScreen.Close() End Try End Sub Private Sub ApLineas_Enlazar(Celda As EditGridCellData, Defecto As Boolean) Handles Me.Enlazar Dim id As Integer = DirectCast(Me.gc.CurrentItem, ApunteExtracto).idAsiento If id > 0 Then Dim uc As New ucDiario(id) FuncionesDinamicas.AbrirAP(uc, OtrosParametros) End If End Sub Private Sub BtBuscar_Click(sender As Object, e As RoutedEventArgs) ObtieneApuntesAsync(bd, False) End Sub 'Private Sub CbEjerciciosBA_EditValueChanged(sender As Object, e As DevExpress.Xpf.Editors.EditValueChangedEventArgs) ' ObtienecuentasAsync(bd, False, True) 'End Sub 'Private Sub ApLineas_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion ' Select Case idAccion ' Case 1 ' balance de situacion ' End Select 'End Sub End Class Public Class ApunteExtracto Property Orden As Integer Property Tipo As ApunteExtractoTipoEnum Property Cuenta As String Property idAsiento As Integer Property NumeroAsiento As String Property Concepto As String Property Fecha As DateOnly? Property Debe As Double Property Haber As Double Property Saldo As Double Public Enum ApunteExtractoTipoEnum SALDO_ANTERIOR = 0 APUNTE = 1 End Enum End Class