First bug fixes

This commit is contained in:
Jonathan Jenne
2021-10-29 16:12:10 +02:00
parent 880a345e06
commit 61286f16ef
28 changed files with 2329 additions and 2345 deletions

View File

@@ -12,9 +12,11 @@ Namespace Winline
Private ReadOnly Database As MSSQLServer
Private ReadOnly Config As Config
Public Articles As New List(Of Article)
Public Accounts As New List(Of Account)
Public Mandators As New List(Of Mandator)
Public DocumentKinds As New List(Of DocumentKind)
Public Years As List(Of Integer)
Public TemplateConfiguration As New List(Of TemplateColumn)
@@ -23,14 +25,18 @@ Namespace Winline
Public Const ALL_MESOCOMP = "mesocomp"
Public Const V21_ARTICLENUMBER = "c011"
Public Const V21_ARTICLENUMBER = "c002"
Public Const V21_ARTICLEDESCRIPTION = "c003"
Public Const V21_MAINARTICLENUMBER = "c011"
Public Const V21_REPLACEMENTARTICLENUMBER = "c123"
Public Const V21_EAN = "c075"
Public Const V50_ACCOUNTNUMBER = "c002"
Public Const V50_ACCOUNTNAME = "c003"
Public Const V50_STREETNAME = "c050"
Public Const V50_ZIPCODE = "c051"
Public Const V50_CITYNAME = "c052"
Public Const V50_GLN = "c260"
Public Const T45_KEY = "c000"
Public Const T45_NAME = "c001"
@@ -62,7 +68,46 @@ Namespace Winline
Return GetWinLineYear(Config.GetYear)
End Function
Public Sub LoadAccounts(pMandator As Mandator)
Public Async Function LoadArticles(pMandator As Mandator) As Task
Logger.Info("Loading Articles for Mandator [{0}]", pMandator)
Dim oYear = GetWinLineYear()
Try
Dim oSQL = $"
SELECT DISTINCT
[c002], -- Artikelnummer
[c003], -- Bezeichnung
[c075] -- EAN
FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v021]
WHERE
mesocomp = '{pMandator.Id}'
AND mesoyear = {oYear}"
Dim oTable = Await Database.GetDatatableAsync(oSQL)
Dim oArticles As New List(Of Article)
For Each oRow As DataRow In oTable.Rows
Dim oArticleId As String = Utils.NotNull(oRow.Item(V21_ARTICLENUMBER), String.Empty)
Dim oArticleDescription As String = Utils.NotNull(oRow.Item(V21_ARTICLEDESCRIPTION), String.Empty)
Dim oEAN As String = Utils.NotNull(oRow.Item(V21_EAN), String.Empty)
oArticles.Add(New Article With {
.Id = oArticleId,
.Name = oArticleDescription,
.EAN = oEAN,
.Mandator = pMandator
})
Next
Articles.AddRange(oArticles)
Logger.Info("[{0}] Articles loaded for Mandator [{1}]", oArticles.Count, pMandator)
Catch ex As Exception
Logger.Warn("Could not load Articles for Mandator [{0}]", pMandator)
Logger.Error(ex)
End Try
End Function
Public Async Function LoadAccounts(pMandator As Mandator) As Task
Logger.Info("Loading Accounts for Mandator [{0}]", pMandator)
Dim oYear = GetWinLineYear()
@@ -73,13 +118,14 @@ Namespace Winline
[c003], -- Kundenname
[c050], -- Straße
[c052], -- Ort
[c051] -- PLZ
[c051], -- PLZ
[c260] -- GLN
FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v050]
WHERE
c139 IS NULL
AND mesocomp = '{pMandator.Id}'
AND mesoyear = {oYear}"
Dim oTable = Database.GetDatatable(oSQL)
Dim oTable = Await Database.GetDatatableAsync(oSQL)
Dim oAccounts As New List(Of Account)
For Each oRow As DataRow In oTable.Rows
@@ -88,6 +134,7 @@ Namespace Winline
Dim oStreetName As String = Utils.NotNull(oRow.Item(V50_STREETNAME), String.Empty)
Dim oZipCode As String = Utils.NotNull(oRow.Item(V50_ZIPCODE), String.Empty)
Dim oCityName As String = Utils.NotNull(oRow.Item(V50_CITYNAME), String.Empty)
Dim oGLN As String = Utils.NotNull(oRow.Item(V50_GLN), String.Empty)
oAccounts.Add(New Account With {
.Id = oAccountNumber,
@@ -95,7 +142,8 @@ Namespace Winline
.StreetName = oStreetName,
.ZipCode = oZipCode,
.CityName = oCityName,
.Mandator = pMandator.Id
.GLN = oGLN,
.Mandator = pMandator
})
Next
Accounts.AddRange(oAccounts)
@@ -105,12 +153,12 @@ Namespace Winline
Logger.Warn("Could not load Accounts for Mandator [{0}]", pMandator)
Logger.Error(ex)
End Try
End Sub
End Function
Public Sub LoadMandators()
Public Async Function LoadMandators() As Task
Try
Dim oSQL = "SELECT [c000], [c003], [c004] FROM [cwlsystem].[dbo].[T001SRV] (NOLOCK)"
Dim oTable = Database.GetDatatable(oSQL)
Dim oTable = Await Database.GetDatatableAsync(oSQL)
Mandators.Clear()
For Each oRow As DataRow In oTable.Rows
@@ -123,8 +171,8 @@ Namespace Winline
}
Dim oMandatorConfig As Config.MandatorConfig = Config.Mandators.
Where(Function(m) oMandator.Id = m.Name).
SingleOrDefault()
Where(Function(m) oMandator.Id = m.Name).
SingleOrDefault()
If oMandatorConfig IsNot Nothing Then
oMandator.IsWhitelisted = True
@@ -141,7 +189,7 @@ Namespace Winline
Logger.Warn("Could not load Mandators")
Logger.Error(ex)
End Try
End Sub
End Function
Public Sub LoadEconomicYears()
Dim oCurrentYear = Now.Year
@@ -149,50 +197,41 @@ Namespace Winline
Years = oRange
End Sub
Public Sub LoadDocumentKinds(pMandators As List(Of Mandator))
Dim oDocumentKinds As New List(Of DocumentKind)
Dim oMandatorString = String.Join(",", pMandators.Select(Function(m) $"'{m.Id}'").ToArray)
Public Async Function LoadDocumentKinds(pMandator As Mandator) As Task
Dim oYear As Integer = GetWinLineYear()
DocumentKinds.Clear()
For Each oMandator As Mandator In pMandators
Try
' TODO: This is Schaum specific, maybe move to config later
Dim oSQL = $"
Try
' TODO: This is Schaum specific, maybe move to config later
Dim oSQL = $"
SELECT
[c030],
[c001],
[mesocomp]
FROM [{oMandator.Database}].[dbo].[t357] (NOLOCK)
FROM [{pMandator.Database}].[dbo].[t357] (NOLOCK)
WHERE (
[c001] LIKE 'Werk%(VK)' OR
[c001] LIKE 'Werk%(WK)'
)
AND [mesocomp] = '{oMandator.Id}' AND [mesoyear] = {oYear}"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSQL)
Dim oKinds As New List(Of DocumentKind)
If oTable.Rows.Count = 0 Then
Logger.Debug("No DocumentKinds found for Mandator [{0}]", oMandator.Id)
Continue For
End If
For Each oRow As DataRow In oTable.Rows
oKinds.Add(New DocumentKind With {
.Id = oRow.Item(T357_KINDID),
.Name = oRow.Item(T357_KINDNAME),
.Mandator = pMandator
})
Next
For Each oRow As DataRow In oTable.Rows
oDocumentKinds.Add(New DocumentKind With {
.Id = oRow.Item(T357_KINDID),
.Name = oRow.Item(T357_KINDNAME),
.Mandator = oRow.Item(ALL_MESOCOMP)
})
Next
DocumentKinds.AddRange(oKinds)
Catch ex As Exception
Logger.Warn("Could not load DocumentKinds")
Logger.Error(ex)
End Try
Next
DocumentKinds = oDocumentKinds.ToList()
End Sub
Logger.Info("[{0}] DocumentKinds loaded for [{1}]", Mandators.Count, pMandator)
Catch ex As Exception
Logger.Warn("Could not load DocumentKinds")
Logger.Error(ex)
End Try
End Function
Public Function TryGetAccount(pGLN As String, pMandator As Mandator) As Account
Try
@@ -241,7 +280,7 @@ Namespace Winline
.StreetName = oStreetName,
.CityName = oCityName,
.ZipCode = oZipCode,
.Mandator = pMandator.Id
.Mandator = pMandator
}
Catch ex As Exception
Logger.Warn("Error while trying to get account for GLN [{0}]", pGLN)
@@ -279,7 +318,7 @@ Namespace Winline
End If
Dim oRow As DataRow = oTable.Rows.Item(0)
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_ARTICLENUMBER), String.Empty)
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_MAINARTICLENUMBER), String.Empty)
Return oArticleNumber
Catch ex As Exception
@@ -412,7 +451,7 @@ Namespace Winline
End If
Dim oRow As DataRow = oTable.Rows.Item(0)
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_ARTICLENUMBER), String.Empty)
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V21_MAINARTICLENUMBER), String.Empty)
' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
If oMandator.Regex <> String.Empty Then