343 lines
18 KiB
VB.net
343 lines
18 KiB
VB.net
Imports System.Data.Entity
|
|
Imports DevExpress.Xpf.Core.ServerMode
|
|
Imports bdGrupoSanchoToro.db
|
|
Imports bdGrupoSanchoToro.db.Utilidades
|
|
Imports DevExpress.Xpf.Grid
|
|
Imports DevExpress.Xpf.Core
|
|
Imports System.Linq.Dynamic
|
|
Imports tsUtilidades.Datos
|
|
Imports tsWPFCore
|
|
Imports DevExpress.Xpf.Bars
|
|
Imports System.IO
|
|
Imports Microsoft.Win32
|
|
Imports System.Threading.Tasks
|
|
Imports System.Linq.Dynamic.Core
|
|
Imports tsUtilidades.Enumeraciones
|
|
|
|
Public Class ucExtractosBancarios
|
|
|
|
Dim bd As tscGrupoSanchoToro
|
|
|
|
Public Overrides Sub EstableceTitulo()
|
|
Me.docpanel.Caption = "Extractos Bancarios"
|
|
End Sub
|
|
|
|
|
|
|
|
Public Overrides ReadOnly Property idRegistroAplicacionActual As String
|
|
Get
|
|
Return "ExtractosBancarios"
|
|
End Get
|
|
End Property
|
|
|
|
Public Overrides ReadOnly Property DescripcionRegistro As String
|
|
Get
|
|
Return "Extracto Bancario"
|
|
End Get
|
|
End Property
|
|
|
|
Public Overrides ReadOnly Property NombreTablaBase As String
|
|
Get
|
|
Return "extractosbancarios"
|
|
End Get
|
|
End Property
|
|
|
|
Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False)
|
|
Dim Acciones As New List(Of tsWPFCore.Accion)
|
|
Acciones.Add(New Accion With {
|
|
.idAccion = 1,
|
|
.Descripcion = "LEE FICHERO DE EXTRACTO"})
|
|
Me.ContenedorAplicacion.cbAcciones.ItemsSource = Acciones
|
|
If Acciones.Count > 0 Then Me.ContenedorAplicacion.beAcciones.EditValue = Acciones.First.idAccion
|
|
End Sub
|
|
|
|
|
|
|
|
Public Overrides Sub Cargado()
|
|
Me.HabilitarRefresco = True
|
|
deFechaInicio.EditValue = New Date(Now.AddMonths(-6).Year, Now.AddMonths(-6).Month, 1)
|
|
deFechaFin.EditValue = Now
|
|
GridBusqueda = Me.gc
|
|
End Sub
|
|
|
|
|
|
|
|
Public Overrides Function EstableceDCPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As tsUtilidades.EstadosAplicacion
|
|
' ObtieneAsientosAsync(bd, Background)
|
|
If Refrescar OrElse Background Then ObtieneExtractosAsync(bd, Background)
|
|
Return tsUtilidades.EstadosAplicacion.AplicacionSinIndice
|
|
End Function
|
|
|
|
Public Overrides Function ObtieneBD() As tsUtilidades.ItsContexto
|
|
bd = tscGrupoSanchoToro.NuevoContexto()
|
|
Return bd
|
|
End Function
|
|
|
|
'Public Overrides Function ObtieneConexionBD() As BBDD
|
|
' Return bdGrupoSanchoToro.db.tscGrupoSanchoToro.bdga
|
|
'End Function
|
|
|
|
Public Overrides Function ObtienePermisos() As tsUtilidades.Permisos
|
|
Dim per = Comun.ObtienePermisos(Me.bd, "AP.ADMINISTRATIVOS", idUsuario)
|
|
per.Nuevos = False
|
|
Return per
|
|
End Function
|
|
|
|
|
|
|
|
Public Sub New()
|
|
|
|
' Esta llamada es exigida por el diseñador.
|
|
InitializeComponent()
|
|
|
|
|
|
|
|
' Agregue cualquier inicialización después de la llamada a InitializeComponent().
|
|
|
|
End Sub
|
|
Public Function ObtieneExtractos(ByRef DataContext As Object, BackGround As Boolean, TextoBusqueda As String, FechaInicio As DateOnly?, FechaFin As DateOnly?) As List(Of extractosbancarios)
|
|
Dim rs As IQueryable(Of extractosbancarios)
|
|
Dim iNumExc As Integer = 0
|
|
|
|
Do
|
|
Try
|
|
rs = bd.extractosbancarios.Include(Function(x) x.idCajaNavigation).AsQueryable
|
|
If TextoBusqueda <> "" Then
|
|
|
|
Dim ExpresionBusqueda = tsWPFCore.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, {"idExtracto"}, {"idCajaNavigation.Descripcion", "idCajaNavigation.IBAN"}, Nothing)
|
|
rs = rs.Where(ExpresionBusqueda)
|
|
End If
|
|
If FechaInicio.HasValue Then
|
|
Dim fi As DateOnly = FechaInicio.Value
|
|
rs = rs.Where(Function(x) x.FechaInicial >= fi)
|
|
End If
|
|
If FechaFin.HasValue Then
|
|
Dim ff As DateOnly = FechaFin.Value
|
|
rs = rs.Where(Function(x) x.FechaInicial < ff)
|
|
End If
|
|
Exit Do
|
|
Catch ex As Exception
|
|
iNumExc += 1
|
|
If iNumExc > 3 Then
|
|
rs = Nothing
|
|
Exit Do
|
|
End If
|
|
End Try
|
|
Loop
|
|
If rs IsNot Nothing Then
|
|
Return rs.ToList
|
|
Else
|
|
Return Nothing
|
|
End If
|
|
End Function
|
|
|
|
Public Async Sub ObtieneExtractosAsync(bd As tscGrupoSanchoToro, Background As Boolean)
|
|
Try
|
|
|
|
|
|
Dim rs As New List(Of extractosbancarios)
|
|
Dim fi = If(deFechaInicio.EditValue Is Nothing, Nothing, DateOnly.FromDateTime(deFechaInicio.EditValue))
|
|
Dim ff = If(deFechaFin.EditValue Is Nothing, Nothing, DateOnly.FromDateTime(deFechaFin.EditValue))
|
|
|
|
Dim Busqueda As String
|
|
|
|
Busqueda = Me.teBusqueda.Text.Trim
|
|
If Background Then
|
|
Me.ContenedorAplicacion.IsEnabled = False
|
|
Await Task.Run(Sub()
|
|
rs = ObtieneExtractos(bd, Background, Busqueda, fi, ff)
|
|
End Sub)
|
|
Else
|
|
If DXSplashScreen.IsActive = False Then DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)()
|
|
DXSplashScreen.SetState("Buscando Extractos ...")
|
|
rs = ObtieneExtractos(bd, Background, Busqueda, fi, ff)
|
|
End If
|
|
|
|
gc.ItemsSource = rs
|
|
DataContext = rs
|
|
|
|
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, extractosbancarios).idExtracto
|
|
FuncionesDinamicas.AbrirAP(New ucExtractoBancario(id), OtrosParametros)
|
|
End Sub
|
|
|
|
Private Sub BtBuscar_Click(sender As Object, e As RoutedEventArgs)
|
|
ObtieneExtractosAsync(bd, False)
|
|
End Sub
|
|
|
|
Private Sub ucExtractosBancarios_EjecutarAccion(sender As Object, e As ItemClickEventArgs, idAccion As Integer) Handles Me.EjecutarAccion
|
|
Try
|
|
Select Case idAccion
|
|
Case 1 ' LECTURA DE FICHEROS
|
|
Dim bdtmp = tscGrupoSanchoToro.NuevoContexto()
|
|
Dim NumLinea As Integer
|
|
Dim reader As TextReader = Nothing
|
|
Try
|
|
Dim ofd As New OpenFileDialog
|
|
ofd.CheckPathExists = True
|
|
ofd.Filter = "Archivos|*.*"
|
|
If ofd.ShowDialog Then
|
|
DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)()
|
|
DXSplashScreen.SetState("Leyendo Extractos ...")
|
|
Dim ne As extractosbancarios = Nothing
|
|
Dim nm As movimientosbancarios = Nothing
|
|
reader = New StreamReader(ofd.FileName)
|
|
Dim linea As String = reader.ReadLine
|
|
NumLinea = 1
|
|
Dim SaldoSumado As Double = 0
|
|
Dim sBanco As String = ""
|
|
Do Until linea Is Nothing
|
|
If linea.Trim <> "" Then
|
|
Dim Tipo As String = linea.Substring(0, 2)
|
|
Select Case Tipo
|
|
Case "11" 'REGISTRO DE CABECERA DE CUENTA
|
|
linea = linea.PadRight(80, " ")
|
|
sBanco = linea.Substring(2, 4).Trim.PadLeft(4, "0")
|
|
Dim sOficina = linea.Substring(6, 4).Trim.PadLeft(4, "0")
|
|
Dim sCta = linea.Substring(10, 10).Trim.PadLeft(10, "0")
|
|
Dim sFechaInicial = linea.Substring(20, 6)
|
|
Dim sFechaFinal = linea.Substring(26, 6)
|
|
Dim fi As DateOnly = DateOnly.FromDateTime(tsUtilidades.Extensiones.FechaStringADate("20" & sFechaInicial))
|
|
Dim ff As DateOnly = DateOnly.FromDateTime(tsUtilidades.Extensiones.FechaStringADate("20" & sFechaFinal))
|
|
Dim sDoH = linea.Substring(32, 1)
|
|
Dim sSaldoAnterior = linea.Substring(33, 14)
|
|
Dim sDivisa = linea.Substring(47, 3)
|
|
Dim sModalidad = linea.Substring(50, 1)
|
|
Dim sNombreAbreviado = linea.Substring(51, 26)
|
|
Dim sLibre = linea.Substring(77, 3)
|
|
Dim sDC = tsUtilidades.Bancos.Genericas.CalcularDigitoControlBancario(sBanco, sOficina, sCta)
|
|
Dim sIBAN = tsUtilidades.Bancos.Genericas.CalcularIBAN("ES", sBanco, sOficina, sDC, sCta)
|
|
Dim cj = bd.cajas.FirstOrDefault(Function(x) x.IBAN = sIBAN)
|
|
If cj Is Nothing Then Throw New Exception("La caja con el IBAN " & sIBAN & " no está dada de alta.")
|
|
If bd.movimientosbancarios.Any(Function(x) x.FechaOperacion >= fi AndAlso x.FechaOperacion <= ff AndAlso x.idExtractoBancarioNavigation.idCajaNavigation.IBAN = sIBAN) Then Throw New Exception("Ya existen extractos bancarios entre las fechas de inicio y fin del fichero seleccionado")
|
|
Dim idcaja = cj.idCaja
|
|
|
|
ne = New extractosbancarios
|
|
bdtmp.extractosbancarios.Add(ne)
|
|
With ne
|
|
ne.idCaja = idcaja
|
|
ne.FechaInicial = fi
|
|
ne.FechaFinal = ff
|
|
ne.FechaLectura = Now
|
|
ne.SaldoAnterior = Math.Round(Double.Parse(sSaldoAnterior) / 100, 2)
|
|
ne.idUsuario = idUsuario
|
|
End With
|
|
Case "22"
|
|
linea = linea.PadRight(80, " ")
|
|
Select Case sBanco
|
|
Case "0182"
|
|
Dim sLibre = linea.Substring(2, 4)
|
|
Dim sOficina = linea.Substring(6, 4)
|
|
Dim sFechaOperacion = linea.Substring(10, 6)
|
|
Dim sFechaValor = linea.Substring(16, 6)
|
|
Dim sConceptoComun = linea.Substring(22, 2)
|
|
Dim sConceptoPropio = linea.Substring(24, 3)
|
|
Dim sDoH = linea.Substring(27, 1)
|
|
Dim sImporte = linea.Substring(28, 14)
|
|
Dim sNumeroDocumento = linea.Substring(42, 10)
|
|
Dim sReferencia1 = linea.Substring(52).Trim
|
|
nm = New movimientosbancarios
|
|
ne.movimientosbancarios.Add(nm)
|
|
With nm
|
|
.FechaOperacion = DateOnly.FromDateTime(tsUtilidades.Extensiones.FechaStringADate("20" & sFechaOperacion))
|
|
.FechaValor = DateOnly.FromDateTime(tsUtilidades.Extensiones.FechaStringADate("20" & sFechaValor))
|
|
.CodigoConcepto = sConceptoComun
|
|
.ConceptoPropio = sConceptoPropio
|
|
.Importe = Math.Round(Double.Parse(sImporte) / 100, 2) * If(sDoH = "1", -1, 1)
|
|
SaldoSumado += .Importe
|
|
.NumeroDocumento = sNumeroDocumento
|
|
.Detalle = ""
|
|
.ReferenciaBanco = sReferencia1
|
|
End With
|
|
|
|
Case Else
|
|
Dim sLibre = linea.Substring(2, 4)
|
|
Dim sOficina = linea.Substring(6, 4)
|
|
Dim sFechaOperacion = linea.Substring(10, 6)
|
|
Dim sFechaValor = linea.Substring(16, 6)
|
|
Dim sConceptoComun = linea.Substring(22, 2)
|
|
Dim sConceptoPropio = linea.Substring(24, 3)
|
|
Dim sDoH = linea.Substring(27, 1)
|
|
Dim sImporte = linea.Substring(28, 14)
|
|
Dim sNumeroDocumento = linea.Substring(42, 10)
|
|
Dim sReferencia1 = linea.Substring(52, 12)
|
|
Dim sReferencia2 = linea.Substring(64, 16)
|
|
nm = New movimientosbancarios
|
|
ne.movimientosbancarios.Add(nm)
|
|
With nm
|
|
.FechaOperacion = DateOnly.FromDateTime(tsUtilidades.Extensiones.FechaStringADate("20" & sFechaOperacion))
|
|
.FechaValor = DateOnly.FromDateTime(tsUtilidades.Extensiones.FechaStringADate("20" & sFechaValor))
|
|
.CodigoConcepto = sConceptoComun
|
|
.ConceptoPropio = sConceptoPropio
|
|
.Importe = Math.Round(Double.Parse(sImporte) / 100, 2) * If(sDoH = "1", -1, 1)
|
|
SaldoSumado += .Importe
|
|
.NumeroDocumento = sNumeroDocumento
|
|
.Detalle = sReferencia2.Trim
|
|
.ReferenciaBanco = sReferencia1
|
|
End With
|
|
End Select
|
|
Case "23"
|
|
Select Case sBanco
|
|
Case "0182"
|
|
Dim sCodigoDato = linea.Substring(2, 2)
|
|
Dim sConcepto1 = linea.Substring(4, 38).Trim
|
|
Dim sConcepto2 = linea.Substring(42, 38).Trim
|
|
With nm
|
|
.Detalle &= (" " & sConcepto1 & " " & sConcepto2).Trim
|
|
If .Detalle = "" Then .Detalle = .ReferenciaBanco
|
|
End With
|
|
Case Else
|
|
Dim sCodigoDato = linea.Substring(2, 2)
|
|
Dim sConcepto1 = linea.Substring(4, 38).Trim
|
|
Dim sConcepto2 = linea.Substring(42, 38).Trim
|
|
With nm
|
|
.Detalle &= (" " & sConcepto1 & " " & sConcepto2).Trim
|
|
|
|
End With
|
|
End Select
|
|
|
|
Case "33"
|
|
Dim sDoH = linea.Substring(58, 1)
|
|
Dim sSaldoFinal = linea.Substring(59, 14)
|
|
Dim dSaldo = Math.Round(Double.Parse(sSaldoFinal) / 100, 2) * If(sDoH = "1", -1, 1)
|
|
ne.SaldoFinal = dSaldo
|
|
End Select
|
|
End If
|
|
linea = reader.ReadLine
|
|
NumLinea += 1
|
|
Loop
|
|
If Math.Round(ne.SaldoFinal, 2) <> Math.Round(ne.SaldoAnterior + SaldoSumado, 2) Then Throw New Exception("El saldo final no corresponde con las suma de los apuntes en el fichero y el saldo anterior")
|
|
bdtmp.GuardarCambios()
|
|
reader.Close()
|
|
ObtieneExtractosAsync(bd, False)
|
|
If DXSplashScreen.IsActive Then DXSplashScreen.Close()
|
|
End If
|
|
Catch ex As Exception
|
|
If DXSplashScreen.IsActive Then DXSplashScreen.Close()
|
|
Try
|
|
reader.Close()
|
|
Catch
|
|
End Try
|
|
DXMessageBox.Show(ex.Message, "Error")
|
|
Catch ex As Exception
|
|
If DXSplashScreen.IsActive Then DXSplashScreen.Close()
|
|
Throw New Exception("Error en la Línea " & NumLinea.ToString & " " & ex.Message, ex)
|
|
End Try
|
|
End Select
|
|
Catch ex As Exception
|
|
FuncionesDinamicas.ErrorNoControladoAp(Me, ex)
|
|
DXMessageBox.Show(ex.Message, "Error")
|
|
End Try
|
|
End Sub
|
|
End Class
|
|
|