ZUGFeRD: Update for new version

This commit is contained in:
Jonathan Jenne 2023-01-12 14:33:54 +01:00
parent 3183b0ed31
commit c1018d176e
5 changed files with 66 additions and 45 deletions

View File

@ -15,7 +15,7 @@ Option Explicit On
Namespace My Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0"), _ Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase Inherits Global.System.Configuration.ApplicationSettingsBase

View File

@ -4,6 +4,7 @@ Imports System.Xml.Serialization
Imports System.Xml.XPath Imports System.Xml.XPath
Imports System.Xml.Xsl Imports System.Xml.Xsl
Imports DigitalData.Modules.Interfaces.Exceptions Imports DigitalData.Modules.Interfaces.Exceptions
Imports DigitalData.Modules.Interfaces.ZUGFeRD
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports GdPicture14 Imports GdPicture14
@ -108,9 +109,9 @@ Public Class ZUGFeRDInterface
Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As ZugferdResult Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As ZugferdResult
Dim oResult = ValidateZUGFeRDFileWithGDPicture(Path) Dim oResult = ValidateZUGFeRDFileWithGDPicture(Path)
If IsNothing(oResult.SchemaObject) Then 'If IsNothing(oResult.SchemaObject) Then
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.") ' Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.")
End If 'End If
Return SerializeZUGFeRDDocument(oResult) Return SerializeZUGFeRDDocument(oResult)
End Function End Function
@ -123,9 +124,9 @@ Public Class ZUGFeRDInterface
Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As ZugferdResult Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As ZugferdResult
Dim oResult = ValidateZUGFeRDFileWithGDPicture(Stream) Dim oResult = ValidateZUGFeRDFileWithGDPicture(Stream)
If IsNothing(oResult.SchemaObject) Then 'If IsNothing(oResult.SchemaObject) Then
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.") ' Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.")
End If 'End If
Return SerializeZUGFeRDDocument(oResult) Return SerializeZUGFeRDDocument(oResult)
End Function End Function
@ -233,6 +234,11 @@ Public Class ZUGFeRDInterface
End Try End Try
End Function End Function
Private Class AllowedType
Public SchemaType As Type
Public Specification As String
End Class
Public Function SerializeZUGFeRDDocument(pResult As ZugferdResult) As ZugferdResult Public Function SerializeZUGFeRDDocument(pResult As ZugferdResult) As ZugferdResult
Try Try
Dim oNavigator As XPathNavigator = pResult.XPathObject.CreateNavigator() Dim oNavigator As XPathNavigator = pResult.XPathObject.CreateNavigator()
@ -241,28 +247,42 @@ Public Class ZUGFeRDInterface
Dim oObject As Object = Nothing Dim oObject As Object = Nothing
Dim oSpecification As String = Nothing Dim oSpecification As String = Nothing
Dim oAllowedTypes As New Dictionary(Of String, Type) Dim oAllowedTypes As New List(Of AllowedType)
If _Options.AllowZugferd_1_0_Schema Then If _Options.AllowZugferd_1_0_Schema Then
oAllowedTypes.Add(ZUGFERD_SPEC_10, GetType(ZUGFeRD.Version1_0.CrossIndustryDocumentType)) oAllowedTypes.Add(New AllowedType With {
.SchemaType = GetType(Version1_0.CrossIndustryDocumentType),
.Specification = ZUGFERD_SPEC_10
})
End If End If
If _Options.AllowZugferd_2_x_Schema Then If _Options.AllowZugferd_2_x_Schema Then
oAllowedTypes.Add(ZUGFERD_SPEC_2x, GetType(ZUGFeRD.Version2_0.CrossIndustryInvoiceType)) oAllowedTypes.AddRange(New List(Of AllowedType) From {
oAllowedTypes.Add(ZUGFERD_SPEC_2x, GetType(ZUGFeRD.Version2_1_1.CrossIndustryInvoiceType)) New AllowedType With {
oAllowedTypes.Add(ZUGFERD_SPEC_2x, GetType(ZUGFeRD.Version2_2_FacturX.CrossIndustryInvoiceType)) .SchemaType = GetType(Version2_0.CrossIndustryInvoiceType),
.Specification = ZUGFERD_SPEC_2x
},
New AllowedType With {
.SchemaType = GetType(Version2_1_1.CrossIndustryInvoiceType),
.Specification = ZUGFERD_SPEC_2x
},
New AllowedType With {
.SchemaType = GetType(Version2_2_FacturX.CrossIndustryInvoiceType),
.Specification = ZUGFERD_SPEC_2x
}
})
End If End If
For Each oType In oAllowedTypes For Each oType In oAllowedTypes
Dim oTypeName As String = oType.Value.FullName Dim oTypeName As String = oType.SchemaType.FullName
Dim oSerializer As New XmlSerializer(oType.Value) Dim oSerializer As New XmlSerializer(oType.SchemaType)
_logger.Debug("Trying Type [{0}]", oTypeName) _logger.Debug("Trying Type [{0}]", oTypeName)
Try Try
oReader = oNavigator.ReadSubtree() oReader = oNavigator.ReadSubtree()
oObject = oSerializer.Deserialize(oReader) oObject = oSerializer.Deserialize(oReader)
oSpecification = oType.Key oSpecification = oType.Specification
_logger.Debug("Serializing with type [{0}] succeeded", oTypeName) _logger.Debug("Serializing with type [{0}] succeeded", oTypeName)
Exit For Exit For

View File

@ -24,7 +24,7 @@ Public Class PropertyValues
Public TableName As String Public TableName As String
Public TableColumn As String Public TableColumn As String
Public ISRequired As Boolean Public IsRequired As Boolean
Public GroupCounter As Integer = -1 Public GroupCounter As Integer = -1
Public Description As String Public Description As String
@ -99,9 +99,7 @@ Public Class PropertyValues
Dim oIsRequired As Boolean = oColumn.Key.IsRequired Dim oIsRequired As Boolean = oColumn.Key.IsRequired
Dim oPropertyDescription As String = oColumn.Key.Description Dim oPropertyDescription As String = oColumn.Key.Description
Dim oRowCounter = oRowIndex + oGlobalGroupCounter + 1 Dim oRowCounter = oRowIndex + oGlobalGroupCounter + 1
If IsNothing(oRowCounter) Then
End If
' Returns nothing if oColumn.Value contains an empty list ' Returns nothing if oColumn.Value contains an empty list
Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex) Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex)
@ -127,7 +125,7 @@ Public Class PropertyValues
.GroupCounter = oRowCounter, .GroupCounter = oRowCounter,
.TableName = oTableName, .TableName = oTableName,
.TableColumn = oTableColumn, .TableColumn = oTableColumn,
.ISRequired = oIsRequired .IsRequired = oIsRequired
}) })
Next Next
Next Next
@ -139,6 +137,7 @@ Public Class PropertyValues
For Each oItem As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties For Each oItem As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
Dim oPropertyValueList As List(Of Object) Dim oPropertyValueList As List(Of Object)
Dim oTableColumn As String = oItem.Value.TableColumn Dim oTableColumn As String = oItem.Value.TableColumn
Dim oPropertyDescription As String = oItem.Value.Description
Dim oPropertyValue As Object = Nothing Dim oPropertyValue As Object = Nothing
Dim oTableName = oItem.Value.TableName Dim oTableName = oItem.Value.TableName
Dim oIsRequired = oItem.Value.IsRequired Dim oIsRequired = oItem.Value.IsRequired
@ -146,7 +145,7 @@ Public Class PropertyValues
Try Try
oPropertyValueList = GetPropValue(Document, oItem.Key) oPropertyValueList = GetPropValue(Document, oItem.Key)
Catch ex As Exception Catch ex As Exception
_logger.Warn("{2} # Unknown error occurred while fetching specification [{0}] in group [{1}]:", oTableColumn, oItem.Value.GroupScope, MessageId) _logger.Warn("{2} # Unknown error occurred while fetching specification [{0}] in group [{1}]:", oPropertyDescription, oItem.Value.GroupScope, MessageId)
_logger.Error(ex) _logger.Error(ex)
oPropertyValueList = New List(Of Object) oPropertyValueList = New List(Of Object)
End Try End Try
@ -164,24 +163,24 @@ Public Class PropertyValues
' This should hopefully show config errors ' This should hopefully show config errors
If TypeOf oPropertyValue Is List(Of Object) Then If TypeOf oPropertyValue Is List(Of Object) Then
_logger.Warn("Item with TableColumn [{0}] may be configured incorrectly", oTableColumn) _logger.Warn("Item with specification [{0}] may be configured incorrectly", oPropertyDescription)
oPropertyValue = Nothing oPropertyValue = Nothing
End If End If
End Select End Select
End If End If
Catch ex As Exception Catch ex As Exception
_logger.Warn("Unknown error occurred while processing specification [{0}]:", oTableColumn) _logger.Warn("Unknown error occurred while processing specification [{0}]:", oPropertyDescription)
_logger.Error(ex) _logger.Error(ex)
oPropertyValue = Nothing oPropertyValue = Nothing
End Try End Try
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
If oItem.Value.IsRequired Then If oItem.Value.IsRequired Then
_logger.Warn("{0} # Specification [{1}] is empty, but marked as required! Skipping.", MessageId, oTableColumn) _logger.Warn("{0} # Specification [{1}] is empty, but marked as required! Skipping.", MessageId, oPropertyDescription)
oResult.MissingProperties.Add(oTableColumn) oResult.MissingProperties.Add(oPropertyDescription)
Continue For Continue For
Else Else
_logger.Debug("{0} # oPropertyValue for specification [{1}] is empty or not found. Skipping.", MessageId, oTableColumn) _logger.Debug("{0} # oPropertyValue for specification [{1}] is empty or not found. Skipping.", MessageId, oPropertyDescription)
Continue For Continue For
End If End If
@ -193,7 +192,7 @@ Public Class PropertyValues
.Value = oPropertyValue, .Value = oPropertyValue,
.TableName = oTableName, .TableName = oTableName,
.TableColumn = oTableColumn, .TableColumn = oTableColumn,
.ISRequired = oIsRequired .IsRequired = oIsRequired
}) })
Next Next

View File

@ -12,15 +12,16 @@ Option Strict On
Option Explicit On Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class Settings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As Settings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()),Settings)
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class Settings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As Settings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()),Settings)
#Region "Automatische My.Settings-Speicherfunktion" #Region "Automatische My.Settings-Speicherfunktion"
#If _MyType = "WindowsForms" Then #If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean Private Shared addedHandler As Boolean
@ -35,10 +36,10 @@ Partial Friend NotInheritable Class Settings
End Sub End Sub
#End If #End If
#End Region #End Region
Public Shared ReadOnly Property [Default]() As Settings Public Shared ReadOnly Property [Default]() As Settings
Get Get
#If _MyType = "WindowsForms" Then #If _MyType = "WindowsForms" Then
If Not addedHandler Then If Not addedHandler Then
SyncLock addedHandlerLockObject SyncLock addedHandlerLockObject
@ -49,10 +50,11 @@ Partial Friend NotInheritable Class Settings
End SyncLock End SyncLock
End If End If
#End If #End If
Return defaultInstance Return defaultInstance
End Get End Get
End Property End Property
End Class End Class
End Namespace
Namespace My Namespace My
@ -62,9 +64,9 @@ Namespace My
Friend Module MySettingsProperty Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _ <Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Jobs.Settings Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Jobs.My.Settings
Get Get
Return Global.DigitalData.Modules.Jobs.Settings.Default Return Global.DigitalData.Modules.Jobs.My.Settings.Default
End Get End Get
End Property End Property
End Module End Module

View File

@ -328,7 +328,7 @@ Public Class ImportZUGFeRDFiles
End If End If
Dim oCommand = $"INSERT INTO {oProperty.TableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER,SPEC_NAME,IS_REQUIRED) VALUES Dim oCommand = $"INSERT INTO {oProperty.TableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER,SPEC_NAME,IS_REQUIRED) VALUES
('{oMessageId}', '{oProperty.Description}', '{oProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{oProperty.TableColumn}','{oProperty.ISRequired}')" ('{oMessageId}', '{oProperty.Description}', '{oProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{oProperty.TableColumn}','{oProperty.IsRequired}')"
_logger.Debug("Mapping Property [{0}] with value [{1}], Will be inserted into table [{2}]", oProperty.TableColumn, oProperty.Value.Replace("'", "''"), oProperty.TableName) _logger.Debug("Mapping Property [{0}] with value [{1}], Will be inserted into table [{2}]", oProperty.TableColumn, oProperty.Value.Replace("'", "''"), oProperty.TableName)
' Insert into SQL Server ' Insert into SQL Server
If oArgs.InsertIntoSQLServer = True Then If oArgs.InsertIntoSQLServer = True Then