This commit is contained in:
Jonathan Jenne
2021-10-18 14:25:51 +02:00
parent b7602d896a
commit 5c58e05204
20 changed files with 638 additions and 132 deletions

View File

@@ -7,11 +7,22 @@ Namespace Documents
Public Type As DocumentType
Public Selected As Boolean = False
''' <summary>
''' TODO: Set before submitting to web services
''' </summary>
Public CreatedAt As Date
Public TemplateName As String
Public TemplateType As Integer
Public [Option] As Integer
Public PrintVoucher As Integer
''' <summary>
''' Original Values, read-only
''' </summary>
Public Property Rows As New List(Of DocumentRow)
Public ReadOnly Property FullName As String
Get
Return File?.FullName
@@ -24,7 +35,6 @@ Namespace Documents
End Get
End Property
Public Rows As New List(Of DocumentRow)
' Public Type As DocumentType
' Public Data As Object

View File

@@ -18,6 +18,7 @@ Namespace Documents
Public Files As New List(Of Document)
Public Sub New(pLogConfig As LogConfig, pWinline As Winline.Data)
MyBase.New(pLogConfig, pLogConfig.GetLogger())
Winline = pWinline
@@ -40,6 +41,7 @@ Namespace Documents
Files = oFiles.
Select(AddressOf WrapFileInfo).
Select(AddressOf LoadDocumentData2).
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators)).
ToList()
Return True
@@ -67,12 +69,15 @@ Namespace Documents
Dim oRows As New List(Of DocumentRow)
For Each oElement As XElement In oRowElements
Dim oFields As New Dictionary(Of String, String)
Dim oFields As New Dictionary(Of String, DocumentRow.FieldValue)
Dim oSubElements = oElement.Descendants().ToList()
For Each oSubElement As XElement In oSubElements
oFields.Add(oSubElement.Name.ToString, oSubElement.Value)
oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With {
.Original = oSubElement.Value,
.Final = oSubElement.Value
})
Next
Dim oRow = New DocumentRow With {
@@ -91,68 +96,104 @@ Namespace Documents
Return pDocument
End Function
'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()
' If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
' Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument.Data)
' Dim oData As Schemas.Orders.Input.MESOWebService = MatchOrderData(pDocument.Data, oMandator)
' If oMandator Is Nothing Then
' Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
' End If
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()
' pDocument.Mandator = oMandator.Id
' pDocument.Data = oData
' End If
Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument)
' Return pDocument
'End Function
If oMandator Is Nothing Then
Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
End If
Private Function MatchOrderData(pData As Input.MESOWebService, pMandator As Winline.Mandator) As Input.MESOWebService
pDocument = MatchOrderData(pDocument, oMandator)
pDocument.Mandator = oMandator.Id
'If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
' Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument.Data)
' Dim oData As Schemas.Orders.Input.MESOWebService = MatchOrderData(pDocument.Data, oMandator)
' If oMandator Is Nothing Then
' Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
' End If
' pDocument.Mandator = oMandator.Id
' pDocument.Data = oData
'End If
Return pDocument
End Function
Private Function MatchOrderData(pDocument As Document, pMandator As Winline.Mandator) As Document
Dim oYear = Winline.GetWinLineYear()
If pMandator Is Nothing Then
Return pData
Return pDocument
End If
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)
Dim oHead As DocumentRow = pDocument.Rows.
Where(Function(r) r.Name.ToUpper.EndsWith("T025")).
SetValue(Sub(r As DocumentRow)
Dim oAccountNumberItem = IIf(r.Fields.ContainsKey("Fakt_Kontonummer"), r.Fields.Item("Fakt_Kontonummer"), Nothing)
Dim oAccountNameItem = Nothing
If r.Fields.ContainsKey("Fakt_Name") Then
oAccountNameItem = r.Fields.Item("Fakt_Name")
End If
Dim oAccount = Winline.TryGetAccount(oAccountNumberItem.Original, pMandator)
If oAccount IsNot Nothing Then
h.Fakt_Kontonummer = oAccount.Id
h.Fakt_Name = oAccount.Name
oAccountNumberItem.External = oAccount.Id
If r.Fields.ContainsKey("Fakt_Name") Then
oAccountNameItem.External = oAccount.Name
End If
End If
End Sub).
SetValue(Sub(h As Input.MESOWebServiceEXIMVRG_ordersT025)
Dim oAccount = Winline.TryGetAccount(h.Lief_Kontonummer, pMandator)
SetValue(Sub(r As DocumentRow)
Dim oAccountNumberItem = Nothing
If r.Fields.ContainsKey("Lief_Kontonummer") Then
oAccountNumberItem = r.Fields.Item("Lief_Kontonummer")
Else
Exit Sub
End If
Dim oAccountNameItem = Nothing
If r.Fields.ContainsKey("Lief_Name") Then
oAccountNameItem = r.Fields.Item("Lief_Name")
End If
Dim oAccount = Winline.TryGetAccount(oAccountNumberItem.Original, pMandator)
If oAccount IsNot Nothing Then
h.Lief_Kontonummer = oAccount.Id
h.Lief_Name = oAccount.Name
oAccountNumberItem.External = oAccount.Id
If r.Fields.ContainsKey("Lief_Name") Then
oAccountNameItem.External = oAccount.Name
End If
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)
Dim oPositions As List(Of DocumentRow) = pDocument.Rows.
Where(Function(r) r.Name.ToUpper.EndsWith("T026")).
SetValue(Sub(p As DocumentRow)
Dim oArticleNumberItem = p.Fields.Item("Artikelnummer")
Dim oArticleNumber = Winline.TryGetArticleNumber(oArticleNumberItem.Original, pMandator)
If oArticleNumber IsNot Nothing Then
p.Artikelnummer = oArticleNumber
oArticleNumberItem.External = 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()
Dim oList As New List(Of DocumentRow) From {oHead}
pDocument.Rows = oList.Concat(oPositions).ToList()
Return pData
Return pDocument
End Function
Private Function WrapFileInfo(pFileInfo As FileInfo) As Document

View File

@@ -1,4 +1,23 @@
Public Class DocumentRow
''' <summary>
''' Tabellen/Elementname aus XML
''' </summary>
Public Name As String
Public Fields As Dictionary(Of String, String)
Public Id As New Guid
Public Fields As Dictionary(Of String, FieldValue)
Public Sub New()
Id = Guid.NewGuid()
End Sub
Public Class FieldValue
Public Original As String = ""
Public External As String = ""
Public Final As String = ""
Public Overrides Function ToString() As String
Return Final
End Function
End Class
End Class