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
<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)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase

View File

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

View File

@ -24,7 +24,7 @@ Public Class PropertyValues
Public TableName As String
Public TableColumn As String
Public ISRequired As Boolean
Public IsRequired As Boolean
Public GroupCounter As Integer = -1
Public Description As String
@ -99,9 +99,7 @@ Public Class PropertyValues
Dim oIsRequired As Boolean = oColumn.Key.IsRequired
Dim oPropertyDescription As String = oColumn.Key.Description
Dim oRowCounter = oRowIndex + oGlobalGroupCounter + 1
If IsNothing(oRowCounter) Then
End If
' Returns nothing if oColumn.Value contains an empty list
Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex)
@ -127,7 +125,7 @@ Public Class PropertyValues
.GroupCounter = oRowCounter,
.TableName = oTableName,
.TableColumn = oTableColumn,
.ISRequired = oIsRequired
.IsRequired = oIsRequired
})
Next
Next
@ -139,6 +137,7 @@ Public Class PropertyValues
For Each oItem As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
Dim oPropertyValueList As List(Of Object)
Dim oTableColumn As String = oItem.Value.TableColumn
Dim oPropertyDescription As String = oItem.Value.Description
Dim oPropertyValue As Object = Nothing
Dim oTableName = oItem.Value.TableName
Dim oIsRequired = oItem.Value.IsRequired
@ -146,7 +145,7 @@ Public Class PropertyValues
Try
oPropertyValueList = GetPropValue(Document, oItem.Key)
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)
oPropertyValueList = New List(Of Object)
End Try
@ -164,24 +163,24 @@ Public Class PropertyValues
' This should hopefully show config errors
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
End If
End Select
End If
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)
oPropertyValue = Nothing
End Try
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
If oItem.Value.IsRequired Then
_logger.Warn("{0} # Specification [{1}] is empty, but marked as required! Skipping.", MessageId, oTableColumn)
oResult.MissingProperties.Add(oTableColumn)
_logger.Warn("{0} # Specification [{1}] is empty, but marked as required! Skipping.", MessageId, oPropertyDescription)
oResult.MissingProperties.Add(oPropertyDescription)
Continue For
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
End If
@ -193,7 +192,7 @@ Public Class PropertyValues
.Value = oPropertyValue,
.TableName = oTableName,
.TableColumn = oTableColumn,
.ISRequired = oIsRequired
.IsRequired = oIsRequired
})
Next

View File

@ -12,11 +12,12 @@ Option Strict 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.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
Partial Friend NotInheritable Class Settings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As Settings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()),Settings)
@ -52,7 +53,8 @@ Partial Friend NotInheritable Class Settings
Return defaultInstance
End Get
End Property
End Class
End Class
End Namespace
Namespace My
@ -62,9 +64,9 @@ Namespace My
Friend Module MySettingsProperty
<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
Return Global.DigitalData.Modules.Jobs.Settings.Default
Return Global.DigitalData.Modules.Jobs.My.Settings.Default
End Get
End Property
End Module

View File

@ -328,7 +328,7 @@ Public Class ImportZUGFeRDFiles
End If
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)
' Insert into SQL Server
If oArgs.InsertIntoSQLServer = True Then