ImportZUGFeRD: fix shti
This commit is contained in:
parent
2e19d878e0
commit
cc9ab1b0b0
@ -163,11 +163,15 @@ Public Class ThreadRunner
|
||||
Dim tableName = row.Item("TABLE_NAME")
|
||||
Dim description = row.Item("DESCRIPTION")
|
||||
Dim isRequired = row.Item("IS_REQUIRED")
|
||||
Dim isGrouped = row.Item("IS_GROUPED")
|
||||
Dim groupScope = row.Item("GROUP_SCOPE")
|
||||
|
||||
args.PropertyMap.Add(xmlPath, New XmlItemProperty() With {
|
||||
.Description = description,
|
||||
.TableName = tableName,
|
||||
.IsRequired = isRequired
|
||||
.IsRequired = isRequired,
|
||||
.IsGrouped = isGrouped,
|
||||
.GroupScope = groupScope
|
||||
})
|
||||
Next
|
||||
|
||||
|
||||
@ -300,13 +300,15 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
' Iterate through groups to get group scope and group items
|
||||
For Each oGroup In oGroupedProperties
|
||||
Dim oGroupScope = oGroup.Key
|
||||
Dim oGroupScope As String = oGroup.Key
|
||||
Dim oPropertyList As New Dictionary(Of XmlItemProperty, List(Of Object))
|
||||
Dim oRowCount = 0
|
||||
|
||||
_logger.Debug("Fetching Property values for group {0}.", oGroupScope)
|
||||
|
||||
' get properties as a nested object, see `oPropertyList`
|
||||
For Each oProperty As KeyValuePair(Of String, XmlItemProperty) In oGroup
|
||||
Dim oPropertyValues As List(Of Object) = PropertyValues.GetPropValues(oDocument, oProperty.Key)
|
||||
Dim oPropertyValues As List(Of Object) = PropertyValues.GetPropValue(oDocument, oProperty.Key)
|
||||
|
||||
oPropertyList.Add(oProperty.Value, oPropertyValues)
|
||||
|
||||
@ -316,6 +318,8 @@ Public Class ImportZUGFeRDFiles
|
||||
End If
|
||||
Next
|
||||
|
||||
_logger.Debug("Done Fetching Property values.")
|
||||
|
||||
' Structure of oPropertyList
|
||||
' [ # Propertyname # Row 1 # Row 2
|
||||
' PositionsMenge: [BilledQuantity1, BilledQuantity2, ...],
|
||||
@ -323,23 +327,39 @@ Public Class ImportZUGFeRDFiles
|
||||
' ...
|
||||
' ]
|
||||
For oRowIndex = 0 To oRowCount - 1
|
||||
_logger.Debug("Processing row {0}", oRowIndex)
|
||||
|
||||
For Each oColumn As KeyValuePair(Of XmlItemProperty, List(Of Object)) In oPropertyList
|
||||
Dim oTableName As String = oColumn.Key.TableName
|
||||
Dim oPropertyDescription As String = oColumn.Key.Description
|
||||
Dim oPropertyValue = oColumn.Value.Item(oRowIndex)
|
||||
Dim oRowCounter = oRowIndex + 1
|
||||
|
||||
If String.IsNullOrEmpty(oPropertyValue) Then
|
||||
_logger.Debug("Processing property {0}.", oPropertyDescription)
|
||||
|
||||
If TypeOf oPropertyValue Is List(Of Object) Then
|
||||
Select Case oPropertyValue.Count
|
||||
Case 0
|
||||
oPropertyValue = String.Empty
|
||||
Case Else
|
||||
Dim oList As List(Of Object) = DirectCast(oPropertyValue, List(Of Object))
|
||||
oPropertyValue = oList.Item(0)
|
||||
End Select
|
||||
End If
|
||||
|
||||
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
|
||||
If oColumn.Key.IsRequired Then
|
||||
_logger.Warn("Property {0} is empty or not found. Continuing with Empty String.", oPropertyDescription)
|
||||
_logger.Warn("Property {0} is empty or not found but was required. Continuing with Empty String.", oPropertyDescription)
|
||||
oMissingProperties.Add(oPropertyDescription)
|
||||
Else
|
||||
_logger.Warn("Property {0} is empty or not found. Continuing with Empty String.", oPropertyDescription)
|
||||
End If
|
||||
|
||||
oPropertyDescription = String.Empty
|
||||
oPropertyValue = String.Empty
|
||||
End If
|
||||
|
||||
_logger.Debug("Property {0} has value {1}", oPropertyDescription, oPropertyValue)
|
||||
|
||||
Dim oCommand = $"INSERT INTO {oTableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER) VALUES ('{oFileGroupId}', '{oPropertyDescription}', '{oPropertyValue}', {oRowCounter})"
|
||||
_logger.Debug("Mapping Property {0} to value {1}. Will be inserted into table {2} with RowCounter {3}", oPropertyDescription, oPropertyValue, oTableName, oRowCounter)
|
||||
|
||||
@ -360,12 +380,21 @@ Public Class ImportZUGFeRDFiles
|
||||
' Iterate through default properties
|
||||
For Each Item As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
|
||||
Dim oPropertyValueList As List(Of Object) = PropertyValues.GetPropValue(oDocument, Item.Key)
|
||||
Dim oPropertyValue = oPropertyValueList.
|
||||
DefaultIfEmpty(New List(Of Object) From {Nothing}).
|
||||
First()
|
||||
Dim oPropertyDescription As String = Item.Value.Description
|
||||
Dim oPropertyValue As Object = Nothing
|
||||
|
||||
If String.IsNullOrEmpty(oPropertyValue) Then
|
||||
If IsNothing(oPropertyValueList) Then
|
||||
oPropertyValue = Nothing
|
||||
ElseIf TypeOf oPropertyValueList Is List(Of Object) Then
|
||||
Select Case oPropertyValueList.Count
|
||||
Case 0
|
||||
oPropertyValue = Nothing
|
||||
Case Else
|
||||
oPropertyValue = oPropertyValueList.First()
|
||||
End Select
|
||||
End If
|
||||
|
||||
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
|
||||
If Item.Value.IsRequired Then
|
||||
_logger.Warn("Property {0} is empty but marked as required! Skipping.", oPropertyDescription)
|
||||
oMissingProperties.Add(oPropertyDescription)
|
||||
|
||||
@ -10,7 +10,7 @@ Public Class PropertyValues
|
||||
Dim oNameParts As String() = PropertyName.Split("."c)
|
||||
|
||||
If IsNothing(Obj) Then
|
||||
Return Nothing
|
||||
Return New List(Of Object)
|
||||
End If
|
||||
|
||||
If oNameParts.Length = 1 Then
|
||||
@ -31,11 +31,11 @@ Public Class PropertyValues
|
||||
Dim oInfo As PropertyInfo = oType.GetProperty(oPartName)
|
||||
|
||||
If IsNothing(oInfo) Then
|
||||
Return Nothing
|
||||
Return New List(Of Object)
|
||||
End If
|
||||
|
||||
If IsNothing(oInfo.GetValue(Obj, Nothing)) Then
|
||||
Return Nothing
|
||||
Return New List(Of Object)
|
||||
End If
|
||||
|
||||
Obj = oInfo.GetValue(Obj, Nothing)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user