wip
This commit is contained in:
@@ -5,6 +5,7 @@ Imports System.Xml.XPath
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports ImporterShared.Documents
|
||||
Imports ImporterShared.Schemas.Orders
|
||||
|
||||
Namespace Documents
|
||||
Public Class DocumentLoader
|
||||
@@ -54,9 +55,9 @@ Namespace Documents
|
||||
|
||||
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Winline.Mandator)) As Document
|
||||
Dim oMandators As List(Of Winline.Mandator) = pMandators.
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
|
||||
Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument.Data)
|
||||
@@ -73,43 +74,45 @@ Namespace Documents
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Function MatchOrderData(pData As Schemas.Orders.Input.MESOWebService, pMandator As Winline.Mandator) As Schemas.Orders.Input.MESOWebService
|
||||
Private Function MatchOrderData(pData As Input.MESOWebService, pMandator As Winline.Mandator) As Input.MESOWebService
|
||||
Dim oYear = Winline.GetWinLineYear()
|
||||
|
||||
If pMandator Is Nothing Then
|
||||
Return pData
|
||||
End If
|
||||
|
||||
Dim oHead As Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT025 = pData.Items.
|
||||
Where(Function(h) TypeOf h Is Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT025).
|
||||
SetValue(Sub(h)
|
||||
Dim oAccountNumber = Winline.TryGetAccountNumber(h.Fakt_Kontonummer, pMandator)
|
||||
If oAccountNumber IsNot Nothing Then
|
||||
h.Fakt_Kontonummer = oAccountNumber
|
||||
End If
|
||||
|
||||
Dim oAccountNumber2 = Winline.TryGetAccountNumber(h.Lief_Kontonummer, pMandator)
|
||||
If oAccountNumber2 IsNot Nothing Then
|
||||
h.Lief_Kontonummer = oAccountNumber2
|
||||
End If
|
||||
End Sub).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oPositions As List(Of Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
|
||||
Where(Function(p) TypeOf p Is Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026).
|
||||
SetValue(Sub(p)
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(p.Artikelnummer, pMandator)
|
||||
If oArticleNumber IsNot Nothing Then
|
||||
p.Artikelnummer = oArticleNumber
|
||||
End If
|
||||
End Sub).
|
||||
Select(Of Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
|
||||
ToList()
|
||||
Dim oHead As Input.MESOWebServiceEXIMVRG_ordersT025 = pData.Items.
|
||||
Where(Function(h) TypeOf h Is Input.MESOWebServiceEXIMVRG_ordersT025).
|
||||
SetValue(Sub(h As Input.MESOWebServiceEXIMVRG_ordersT025)
|
||||
Dim oAccount = Winline.TryGetAccount(h.Fakt_Kontonummer, pMandator)
|
||||
If oAccount IsNot Nothing Then
|
||||
h.Fakt_Kontonummer = oAccount.Id
|
||||
h.Fakt_Name = oAccount.Name
|
||||
End If
|
||||
End Sub).
|
||||
SetValue(Sub(h As Input.MESOWebServiceEXIMVRG_ordersT025)
|
||||
Dim oAccount = Winline.TryGetAccount(h.Lief_Kontonummer, pMandator)
|
||||
If oAccount IsNot Nothing Then
|
||||
h.Lief_Kontonummer = oAccount.Id
|
||||
h.Lief_Name = oAccount.Name
|
||||
End If
|
||||
End Sub).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oPositions As List(Of Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
|
||||
Where(Function(p) TypeOf p Is Input.MESOWebServiceEXIMVRG_ordersT026).
|
||||
SetValue(Sub(p)
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(p.Artikelnummer, pMandator)
|
||||
If oArticleNumber IsNot Nothing Then
|
||||
p.Artikelnummer = oArticleNumber
|
||||
End If
|
||||
End Sub).
|
||||
Select(Of Input.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
|
||||
ToList()
|
||||
|
||||
pData.Items = New List(Of Object) From {oHead}.
|
||||
Concat(oPositions).
|
||||
ToArray()
|
||||
Concat(oPositions).
|
||||
ToArray()
|
||||
|
||||
Return pData
|
||||
End Function
|
||||
|
||||
@@ -117,9 +117,10 @@
|
||||
<Compile Include="Schemas\Orders\Output.vb" />
|
||||
<Compile Include="Schemas\Orders\ReportSource.vb" />
|
||||
<Compile Include="Serializer.vb" />
|
||||
<Compile Include="Winline\Account.vb" />
|
||||
<Compile Include="Winline\Entities\Account.vb" />
|
||||
<Compile Include="Winline\Data.vb" />
|
||||
<Compile Include="Winline\Mandator.vb" />
|
||||
<Compile Include="Winline\Entities\DocumentKind.vb" />
|
||||
<Compile Include="Winline\Entities\Mandator.vb" />
|
||||
<Compile Include="Winline\WebService.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -17,9 +17,16 @@ Namespace Winline
|
||||
Public Years As List(Of Integer)
|
||||
|
||||
Public Const V21_ARTICLENUMBER = "c011"
|
||||
|
||||
Public Const V50_ACCOUNTNUMBER = "c002"
|
||||
Public Const V50_ACCOUNTNAME = "c003"
|
||||
|
||||
Public Const V05_ACCOUNTID = "c002"
|
||||
Public Const V05_ACCOUNTNAME = "c003"
|
||||
|
||||
Public Const T357_KINDID = "c030"
|
||||
Public Const T357_KINDNAME = "c001"
|
||||
|
||||
Public Const T01_DATABASEINFO = "c004"
|
||||
Public Const T01_MANDATORID = "c000"
|
||||
Public Const T01_MANDATORNAME = "c003"
|
||||
@@ -39,44 +46,63 @@ Namespace Winline
|
||||
End Function
|
||||
|
||||
Public Sub LoadAccounts(pMandator As Mandator)
|
||||
Dim oSQL = $"SELECT [c002], [c003] FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v005] WHERE c139 IS NULL"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
Logger.Info("Loading Accounts for Mandator [{0}]", pMandator)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Accounts.Add(New Account With {
|
||||
.Id = oRow.Item(V05_ACCOUNTID),
|
||||
.Name = oRow.Item(V05_ACCOUNTNAME),
|
||||
.Mandator = pMandator.Id
|
||||
})
|
||||
Next
|
||||
Try
|
||||
Dim oSQL = $"SELECT DISTINCT [c002], [c003] FROM [{pMandator.Server}].[{pMandator.Database}].[dbo].[v005] WHERE c139 IS NULL"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
Dim oAccounts As New List(Of Account)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oAccounts.Add(New Account With {
|
||||
.Id = oRow.Item(V05_ACCOUNTID),
|
||||
.Name = oRow.Item(V05_ACCOUNTNAME),
|
||||
.Mandator = pMandator.Id
|
||||
})
|
||||
Next
|
||||
Accounts.AddRange(oAccounts)
|
||||
|
||||
Logger.Info("[{0}] Accounts loaded for Mandator [{1}]", oAccounts.Count, pMandator)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load Accounts for Mandator [{0}]", pMandator)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub LoadMandators()
|
||||
Dim oSQL = "SELECT [c000], [c003], [c004] FROM [cwlsystem].[dbo].[T001SRV] (NOLOCK)"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
Try
|
||||
Dim oSQL = "SELECT [c000], [c003], [c004] FROM [cwlsystem].[dbo].[T001SRV] (NOLOCK)"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
|
||||
Mandators.Clear()
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oDbInfo = SplitConnectionInfo(oRow)
|
||||
Dim oMandator = New Mandator With {
|
||||
.Id = oRow.Item(T01_MANDATORID),
|
||||
.Name = oRow.Item(T01_MANDATORNAME),
|
||||
.Database = oDbInfo.Item1,
|
||||
.Server = oDbInfo.Item2
|
||||
}
|
||||
Mandators.Clear()
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oDbInfo = SplitConnectionInfo(oRow)
|
||||
Dim oMandator = New Mandator With {
|
||||
.Id = oRow.Item(T01_MANDATORID),
|
||||
.Name = oRow.Item(T01_MANDATORNAME),
|
||||
.Database = oDbInfo.Item1,
|
||||
.Server = oDbInfo.Item2
|
||||
}
|
||||
|
||||
Dim oMandatorConfig As Config.MandatorConfig = Config.Mandators.
|
||||
Where(Function(m) oMandator.Id = m.Name).
|
||||
SingleOrDefault()
|
||||
Dim oMandatorConfig As Config.MandatorConfig = Config.Mandators.
|
||||
Where(Function(m) oMandator.Id = m.Name).
|
||||
SingleOrDefault()
|
||||
|
||||
If oMandatorConfig IsNot Nothing Then
|
||||
oMandator.IsWhitelisted = True
|
||||
oMandator.Regex = oMandatorConfig.ArticleRegex
|
||||
oMandator.Order = oMandatorConfig.Order
|
||||
End If
|
||||
If oMandatorConfig IsNot Nothing Then
|
||||
oMandator.IsWhitelisted = True
|
||||
oMandator.Regex = oMandatorConfig.ArticleRegex
|
||||
oMandator.Order = oMandatorConfig.Order
|
||||
End If
|
||||
|
||||
Mandators.Add(oMandator)
|
||||
Next
|
||||
|
||||
Mandators.Add(oMandator)
|
||||
Next
|
||||
|
||||
Logger.Info("[{0}] Mandators loaded", Mandators.Count)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load Mandators")
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub LoadEconomicYears()
|
||||
@@ -85,17 +111,58 @@ Namespace Winline
|
||||
Years = oRange
|
||||
End Sub
|
||||
|
||||
Public Function TryGetAccountNumber(pGLN As String, pMandator As Mandator) As String
|
||||
Public Function GetDocumentKinds(pMandator As Mandator, pYear As Integer) As List(Of DocumentKind)
|
||||
Dim oDocumentKinds As New List(Of DocumentKind)
|
||||
|
||||
Try
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c030],
|
||||
[c001]
|
||||
FROM [t357] (NOLOCK)
|
||||
WHERE (
|
||||
[c001] LIKE 'Werk%(VK)' OR
|
||||
[c001] LIKE 'Werk%(WK)'
|
||||
)
|
||||
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {pYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Logger.Warn("No DocumentKinds found")
|
||||
Return oDocumentKinds
|
||||
|
||||
End If
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
oDocumentKinds.Add(New DocumentKind With {
|
||||
.Id = oRow.Item(T357_KINDID),
|
||||
.Name = oRow.Item(T357_KINDNAME)
|
||||
})
|
||||
Next
|
||||
|
||||
Return oDocumentKinds
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not load DocumentKinds")
|
||||
Logger.Error(ex)
|
||||
Return oDocumentKinds
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TryGetAccount(pGLN As String, pMandator As Mandator) As Account
|
||||
Try
|
||||
If pGLN Is Nothing OrElse pGLN = String.Empty Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oYear As Integer = GetWinLineYear()
|
||||
Dim oSQL = $"
|
||||
SELECT
|
||||
[c002], -- Kundennummer
|
||||
[c003] -- Kundenname
|
||||
FROM [{pMandator.Database}].[dbo].[v050]
|
||||
WHERE [c004] = 2 -- Was für ein Konto??
|
||||
AND [c260] = {pGLN}
|
||||
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
|
||||
SELECT
|
||||
[c002], -- Kundennummer
|
||||
[c003] -- Kundenname
|
||||
FROM [{pMandator.Database}].[dbo].[v050]
|
||||
WHERE [c004] = 2 -- KontoTyp
|
||||
AND [c260] = '{pGLN}'
|
||||
AND [mesocomp] = '{pMandator.Id}' and [mesoyear] = {oYear}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' GLN not found in this Mandator, continue to next one
|
||||
@@ -113,9 +180,16 @@ Namespace Winline
|
||||
End If
|
||||
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oArticleNumber As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNUMBER), String.Empty)
|
||||
Return oArticleNumber
|
||||
Dim oAccountNumber As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNUMBER), String.Empty)
|
||||
Dim oAccountName As String = Utils.NotNull(oRow.Item(V50_ACCOUNTNAME), String.Empty)
|
||||
|
||||
Return New Account With {
|
||||
.Id = oAccountNumber,
|
||||
.Name = oAccountName,
|
||||
.Mandator = pMandator.Id
|
||||
}
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while trying to get account for GLN [{0}]", pGLN)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
|
||||
7
ImporterShared/Winline/Entities/DocumentKind.vb
Normal file
7
ImporterShared/Winline/Entities/DocumentKind.vb
Normal file
@@ -0,0 +1,7 @@
|
||||
Namespace Winline
|
||||
Public Class DocumentKind
|
||||
Public Id As Integer
|
||||
Public Name As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user