Compare commits
26 Commits
Update-Net
...
a5226a8101
| Author | SHA1 | Date | |
|---|---|---|---|
| a5226a8101 | |||
| b534c4c799 | |||
| dc80138311 | |||
| 477bb511c4 | |||
| 0b66b80591 | |||
| 5fd924d413 | |||
| e8ebc30225 | |||
| 262805d112 | |||
| 623807c55d | |||
| aee7997cb3 | |||
| 82a95faaaf | |||
| af7534df48 | |||
| fa2c2a6417 | |||
| 390a524736 | |||
| 0ed996100d | |||
| 2e0ae13a77 | |||
| 267e038725 | |||
| 2673755b14 | |||
| 5052ce4f14 | |||
| 717909d7e8 | |||
| 04a408ab97 | |||
| face3c76fb | |||
| 2d3a1cd25c | |||
| 43e95a20b9 | |||
| 05d0bd60ab | |||
| 7e70c059b6 |
@@ -652,6 +652,11 @@ Public Class MSSQLServer
|
||||
Select(Function(p) $"({p.ParameterName}={p.Value})").
|
||||
ToList()
|
||||
|
||||
Return String.Join(",", oList)
|
||||
Dim oParamString = String.Join(",", oList)
|
||||
If oParamString.Length > 1000 Then
|
||||
oParamString = oParamString.Substring(1, 1000)
|
||||
End If
|
||||
Return oParamString
|
||||
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Database")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2025")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
<Assembly: AssemblyTrademark("2.3.6.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.3.5.4")>
|
||||
<Assembly: AssemblyFileVersion("2.3.5.4")>
|
||||
<Assembly: AssemblyVersion("2.3.6.0")>
|
||||
<Assembly: AssemblyFileVersion("2.3.6.0")>
|
||||
|
||||
@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Interfaces")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2025")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
<Assembly: AssemblyTrademark("2.3.5.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.3.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.3.0.0")>
|
||||
<Assembly: AssemblyVersion("2.3.5.0")>
|
||||
<Assembly: AssemblyFileVersion("2.3.5.0")>
|
||||
|
||||
@@ -19,6 +19,7 @@ Public Class ZUGFeRDInterface
|
||||
Public Const ZUGFERD_SPEC_DEFAULT = "DEFAULT"
|
||||
Public Const ZUGFERD_SPEC_10 = "ZUGFERD_10"
|
||||
Public Const ZUGFERD_SPEC_2x = "ZUGFERD_2x"
|
||||
Public Const ZUGFERD_SPEC_2_3x = "ZUGFERD_2_3x"
|
||||
|
||||
Public Const UBL_SPEC_21 = "UBL_21"
|
||||
|
||||
@@ -60,6 +61,7 @@ Public Class ZUGFeRDInterface
|
||||
Public Property AllowXRechnung_Filename As Boolean = True
|
||||
Public Property AllowZugferd_1_0_Schema As Boolean = True
|
||||
Public Property AllowZugferd_2_x_Schema As Boolean = True
|
||||
Public Property AllowZugferd_2_3_x_Schema As Boolean = True
|
||||
Public Property AllowPeppol_3_x_Schema As Boolean = False
|
||||
End Class
|
||||
|
||||
@@ -130,20 +132,41 @@ Public Class ZUGFeRDInterface
|
||||
AllowedFilenames = oAllowedFilenames
|
||||
End Sub
|
||||
|
||||
Public Function FilterPropertyMap(pPropertyMap As Dictionary(Of String, XmlItemProperty), pSpecification As String) As Dictionary(Of String, XmlItemProperty)
|
||||
_logger.Debug("Filtering Property map for Specification [{0}]", pSpecification)
|
||||
Public Function FilterPropertyMap(pPropertyMapList As List(Of XmlItemProperty), pSpecification As String) As Dictionary(Of String, XmlItemProperty)
|
||||
_logger.Debug("Filtering Property map list for Specification [{0}]", pSpecification)
|
||||
|
||||
If pSpecification = ZUGFERD_SPEC_10 Then
|
||||
_logger.Debug("Special Case [{0}], including [{1}]", ZUGFERD_SPEC_10, ZUGFERD_SPEC_DEFAULT)
|
||||
Return pPropertyMap.
|
||||
Where(Function(kv) kv.Value.Specification = pSpecification Or kv.Value.Specification = ZUGFERD_SPEC_DEFAULT).
|
||||
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
|
||||
Try
|
||||
|
||||
_logger.Debug("Special Case [{0}], including [{1}]", ZUGFERD_SPEC_10, ZUGFERD_SPEC_DEFAULT)
|
||||
|
||||
Dim countElements As Integer = pPropertyMapList.Where(Function(x) x.Specification = pSpecification Or x.Specification = ZUGFERD_SPEC_DEFAULT).Count
|
||||
_logger.Debug("Property map list contains [{0}] elements for specification [{1}]", countElements, pSpecification)
|
||||
|
||||
Return pPropertyMapList.
|
||||
Where(Function(kv) kv.Specification = pSpecification Or kv.Specification = ZUGFERD_SPEC_DEFAULT).
|
||||
ToDictionary(Function(kv) kv.XMLPath, Function(kv) kv)
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
Else
|
||||
_logger.Debug("Using Specification [{0}]", pSpecification)
|
||||
Return pPropertyMap.
|
||||
Where(Function(kv) kv.Value.Specification = pSpecification).
|
||||
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
|
||||
|
||||
Try
|
||||
|
||||
Dim countElements As Integer = pPropertyMapList.Where(Function(x) x.Specification = pSpecification).Count
|
||||
_logger.Debug("Property map list contains [{0}] elements for specification [{1}]", countElements, pSpecification)
|
||||
|
||||
Return pPropertyMapList.
|
||||
Where(Function(kv) kv.Specification = pSpecification).
|
||||
ToDictionary(Function(kv) kv.XMLPath, Function(kv) kv)
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Function GetSerializedXMLContentFromFile(oFileInfo As FileInfo) As ZugferdResult
|
||||
@@ -248,7 +271,7 @@ Public Class ZUGFeRDInterface
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Error while validating ZUGFeRD file with GDPicture")
|
||||
_logger.Warn("Error while validating eInvoice file with GDPicture")
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
@@ -277,7 +300,7 @@ Public Class ZUGFeRDInterface
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Error while validating ZUGFeRD file with GDPicture")
|
||||
_logger.Warn("Error while validating eInvoice file with GDPicture")
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
@@ -358,6 +381,7 @@ Public Class ZUGFeRDInterface
|
||||
})
|
||||
End If
|
||||
|
||||
'' Reihenfolge 2.0 muss unverändert bleiben. Älteste Version immer zuerst!
|
||||
If _Options.AllowZugferd_2_x_Schema Then
|
||||
oAllowedTypes.AddRange(New List(Of AllowedType) From {
|
||||
New AllowedType With {
|
||||
@@ -374,16 +398,22 @@ Public Class ZUGFeRDInterface
|
||||
.SchemaType = GetType(Version2_2_FacturX.CrossIndustryInvoiceType),
|
||||
.Specification = ZUGFERD_SPEC_2x,
|
||||
.XMLSchema = XMLSCHEMA_ZUGFERD_22
|
||||
}
|
||||
})
|
||||
End If
|
||||
|
||||
'' Reihenfolge ab 2.3 geändert. Neuste Version immer zuerst
|
||||
If _Options.AllowZugferd_2_3_x_Schema Then
|
||||
oAllowedTypes.AddRange(New List(Of AllowedType) From {
|
||||
New AllowedType With {
|
||||
.SchemaType = GetType(Version2_3_3_FacturX.CrossIndustryInvoiceType),
|
||||
.Specification = ZUGFERD_SPEC_2_3x,
|
||||
.XMLSchema = XMLSCHEMA_ZUGFERD_233
|
||||
},
|
||||
New AllowedType With {
|
||||
.SchemaType = GetType(Version2_3_FacturX.CrossIndustryInvoiceType),
|
||||
.Specification = ZUGFERD_SPEC_2x,
|
||||
.Specification = ZUGFERD_SPEC_2_3x,
|
||||
.XMLSchema = XMLSCHEMA_ZUGFERD_23
|
||||
},
|
||||
New AllowedType With {
|
||||
.SchemaType = GetType(Version2_3_3_FacturX.CrossIndustryInvoiceType),
|
||||
.Specification = ZUGFERD_SPEC_2x,
|
||||
.XMLSchema = XMLSCHEMA_ZUGFERD_233
|
||||
}
|
||||
})
|
||||
End If
|
||||
@@ -442,7 +472,7 @@ Public Class ZUGFeRDInterface
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Dim oMessage = "Datei ist eine ungültige ZUGFeRD Datei oder das Format wird nicht unterstüzt, oder das Format ist deaktiviert."
|
||||
Dim oMessage = "Datei ist eine ungültige eInvoice Datei oder das Format wird nicht unterstüzt, oder das Format ist deaktiviert."
|
||||
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, oMessage)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
DateType '1
|
||||
MoneyType '2
|
||||
FileType '3
|
||||
ListType '4 - vgl. Währung
|
||||
|
||||
End Enum
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Imports System.Reflection
|
||||
Imports System.Globalization
|
||||
Imports System.Reflection
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
@@ -27,6 +28,7 @@ Public Class PropertyValues
|
||||
Public IsRequired As Boolean
|
||||
Public GroupCounter As Integer = -1
|
||||
|
||||
Public EN16931_ID As String
|
||||
Public Description As String
|
||||
Public Value As String
|
||||
Public XMLPath As String
|
||||
@@ -35,6 +37,7 @@ Public Class PropertyValues
|
||||
End Class
|
||||
|
||||
Public Class MissingProperty
|
||||
Public EN16931_ID As String
|
||||
Public Description As String
|
||||
Public XMLPath As String
|
||||
|
||||
@@ -54,7 +57,7 @@ Public Class PropertyValues
|
||||
ToDictionary(Function(Item) Item.Key,
|
||||
Function(Item) Item.Value)
|
||||
|
||||
_logger.Debug("Found {0} default properties.", oDefaultProperties.Count)
|
||||
_logger.Debug("Found {0} ungrouped properties.", oDefaultProperties.Count)
|
||||
|
||||
' PropertyMap items with `IsGrouped = True` are grouped by group scope
|
||||
Dim oGroupedProperties = PropertyMap.
|
||||
@@ -112,13 +115,14 @@ Public Class PropertyValues
|
||||
Dim oPropertyDescription As String = oColumn.Key.Description
|
||||
Dim oPropertyPath As String = oColumn.Key.XMLPath
|
||||
Dim oItemType As Integer = oColumn.Key.ItemType
|
||||
Dim oEN16931Value As String = oColumn.Key.EN16931_ID
|
||||
|
||||
Dim oRowCounter = oRowIndex + oGlobalGroupCounter + 1
|
||||
|
||||
' Returns nothing if oColumn.Value contains an empty list
|
||||
Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex)
|
||||
|
||||
_logger.Debug("Processing itemSpecification *TableColumn* [{0}].", oTableColumn)
|
||||
_logger.Debug("Processing itemColumn *TableColumn* [{0}].", oTableColumn)
|
||||
If oTableColumn = "INVOICE_SELLER_EMAIL" Then
|
||||
Console.WriteLine("INVOICE_SELLER_EMAIL")
|
||||
ElseIf oTableColumn = "INVOICE_POSITION_ARTICLE" Then
|
||||
@@ -126,20 +130,29 @@ Public Class PropertyValues
|
||||
End If
|
||||
If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then
|
||||
If oColumn.Key.IsRequired Then
|
||||
_logger.Warn($"{MessageId} # oPropertyValue for specification [{oTableColumn}] is empty or not found but is required. Continuing with Empty String.")
|
||||
_logger.Warn($"{MessageId} - oPropertyValue for column [{oTableColumn}] is empty or not found but is required. Continuing with Empty String.")
|
||||
Dim oMissingProperty = New MissingProperty() With {
|
||||
.EN16931_ID = oEN16931Value,
|
||||
.Description = oPropertyDescription,
|
||||
.XMLPath = oPropertyPath
|
||||
}
|
||||
oResult.MissingProperties.Add(oMissingProperty)
|
||||
Else
|
||||
_logger.Debug($"{MessageId} # oPropertyValue for specification [{oTableColumn}] is empty or not found. Continuing with Empty String.")
|
||||
_logger.Debug($"{MessageId} - oPropertyValue for column [{oTableColumn}] is empty or not found. Continuing with Empty String.")
|
||||
End If
|
||||
|
||||
oPropertyValue = String.Empty
|
||||
End If
|
||||
|
||||
_logger.Debug("ItemSpecification [{0}] has value '{1}'", oTableColumn, oPropertyValue)
|
||||
If (oPropertyValue IsNot Nothing) Then
|
||||
Dim logValue As String = oPropertyValue.ToString()
|
||||
If logValue.Length > 50 Then
|
||||
_logger.Debug("Item [{0}] has value '{1}...'", oTableColumn, logValue.Substring(1, 50))
|
||||
Else
|
||||
_logger.Debug("Item [{0}] has value '{1}'", oTableColumn, oPropertyValue)
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
oResult.ValidProperties.Add(New ValidProperty() With {
|
||||
.MessageId = MessageId,
|
||||
@@ -150,7 +163,8 @@ Public Class PropertyValues
|
||||
.TableColumn = oTableColumn,
|
||||
.IsRequired = oIsRequired,
|
||||
.XMLPath = oPropertyPath,
|
||||
.ItemType = oItemType
|
||||
.ItemType = oItemType,
|
||||
.EN16931_ID = oEN16931Value
|
||||
})
|
||||
Next
|
||||
Next
|
||||
@@ -169,11 +183,12 @@ Public Class PropertyValues
|
||||
Dim oIsRequired = oItem.Value.IsRequired
|
||||
Dim oDescription = oItem.Value.Description
|
||||
Dim oItemType = oItem.Value.ItemType
|
||||
Dim oEN16931_ID = oItem.Value.EN16931_ID
|
||||
|
||||
Try
|
||||
oPropertyValueList = GetPropValue(pDocument, oItem.Key)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("{2} # Unknown error occurred while fetching specification [{0}] in group [{1}]:", oPropertyDescription, oItem.Value.GroupScope, MessageId)
|
||||
_logger.Warn("{2} - Unknown error occurred while fetching specification [{0}] in group [{1}]:", oTableColumn, oItem.Value.GroupScope, MessageId)
|
||||
_logger.Warn("ERROR-MESSAGE [{0}]", ex.Message)
|
||||
_logger.Error(ex)
|
||||
oPropertyValueList = New List(Of Object)
|
||||
@@ -192,20 +207,20 @@ Public Class PropertyValues
|
||||
|
||||
' This should hopefully show config errors
|
||||
If TypeOf oPropertyValue Is List(Of Object) Then
|
||||
_logger.Warn("Item with specification [{0}] may be configured incorrectly", oPropertyDescription)
|
||||
_logger.Warn("Item with specification [{0}] may be configured incorrectly", oTableColumn)
|
||||
oPropertyValue = Nothing
|
||||
End If
|
||||
End Select
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Unknown error occurred while processing specification [{0}]:", oPropertyDescription)
|
||||
_logger.Warn("Unknown error occurred while processing specification [{0}]:", oTableColumn)
|
||||
_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, oPropertyDescription)
|
||||
_logger.Warn("Specification [{0}] is empty, but marked as required! Skipping.", oTableColumn)
|
||||
Dim oMissingProperty = New MissingProperty With
|
||||
{
|
||||
.Description = oPropertyDescription,
|
||||
@@ -214,14 +229,14 @@ Public Class PropertyValues
|
||||
oResult.MissingProperties.Add(oMissingProperty)
|
||||
Continue For
|
||||
Else
|
||||
_logger.Debug("{0} # oPropertyValue for specification [{1}] is empty or not found. Skipping.", MessageId, oPropertyDescription)
|
||||
_logger.Debug("oPropertyValue for specification [{0}] is empty or not found. Skipping.", oTableColumn)
|
||||
|
||||
Continue For
|
||||
End If
|
||||
End If
|
||||
|
||||
' Statt dem Zahlenwert des Enums, wollen wir die Währunsgbezeichnung
|
||||
If oTableColumn = "INVOICE_CURRENCY" Then
|
||||
' Statt dem Zahlenwert des Enums, wollen wir die Währungsbezeichnung
|
||||
If oTableColumn = "INVOICE_CURRENCY" Or oItemType = 4 Then
|
||||
oPropertyValue = oPropertyValue.ToString()
|
||||
End If
|
||||
|
||||
@@ -233,7 +248,8 @@ Public Class PropertyValues
|
||||
.TableColumn = oTableColumn,
|
||||
.IsRequired = oIsRequired,
|
||||
.XMLPath = oPropertyPath,
|
||||
.ItemType = oItemType
|
||||
.ItemType = oItemType,
|
||||
.EN16931_ID = oEN16931_ID
|
||||
})
|
||||
Next
|
||||
|
||||
@@ -280,17 +296,11 @@ Public Class PropertyValues
|
||||
|
||||
Obj = oInfo.GetValue(Obj, Nothing)
|
||||
|
||||
' TODO: This code should check for array properties by itself
|
||||
' and should not rely on the user to
|
||||
'If oInfo.PropertyType.IsArray Then
|
||||
' Obj = Obj(0)
|
||||
'End If
|
||||
|
||||
If oHasIndex Then
|
||||
Obj = Obj(0)
|
||||
End If
|
||||
|
||||
If IsArray(Obj) And Not oHasIndex Then
|
||||
If IsArray(Obj) And Not oHasIndex And oPart <> "Value" Then
|
||||
Dim oCurrentPart As String = oPart
|
||||
Dim oSplitString As String() = New String() {oCurrentPart & "."}
|
||||
Dim oPathFragments = PropertyName.Split(oSplitString, StringSplitOptions.None)
|
||||
@@ -310,8 +320,56 @@ Public Class PropertyValues
|
||||
Next
|
||||
|
||||
Return oResults
|
||||
End If
|
||||
Else
|
||||
If oPart = "Value" AndAlso Obj IsNot Nothing Then
|
||||
' Der Name des gefundenen Datentyps
|
||||
Dim oObjType = oInfo.PropertyType.FullName
|
||||
|
||||
If oObjType.Equals("System.DateTime", StringComparison.OrdinalIgnoreCase) Then
|
||||
|
||||
Dim d As Date
|
||||
Dim s As String
|
||||
Dim oResult As String
|
||||
|
||||
s = Convert.ToString(Obj)
|
||||
|
||||
If IsDate(s) = True Then
|
||||
' Hier wird das DEFAULT-Format auf yyyyMMdd gesetzt
|
||||
Dim dtfi As DateTimeFormatInfo = CultureInfo.CreateSpecificCulture(CultureInfo.InvariantCulture.Name).DateTimeFormat
|
||||
dtfi.DateSeparator = ""
|
||||
dtfi.ShortDatePattern = "yyyyMMdd"
|
||||
|
||||
d = CDate(s)
|
||||
oResult = d.ToString("d", dtfi)
|
||||
|
||||
'Return New List(Of Object) From {oResult}
|
||||
Dim oRetValue As List(Of Object) = New List(Of Object) From {
|
||||
oResult
|
||||
}
|
||||
|
||||
Return oRetValue
|
||||
|
||||
End If
|
||||
ElseIf oObjType.Equals("System.Decimal", StringComparison.OrdinalIgnoreCase) Then
|
||||
|
||||
Dim oResult As String
|
||||
|
||||
If IsNumeric(Obj) = True Then
|
||||
Dim decValue As Decimal = CDec(Obj)
|
||||
' Es wird immer ein . als Dezimaltrenner verwendet, falls nötig
|
||||
oResult = decValue.ToString(CultureInfo.InvariantCulture)
|
||||
|
||||
'Return New List(Of Object) From {oResult}
|
||||
Dim oRetValue As List(Of Object) = New List(Of Object) From {
|
||||
oResult
|
||||
}
|
||||
|
||||
Return oRetValue
|
||||
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
Return New List(Of Object) From {Obj}
|
||||
@@ -339,8 +397,20 @@ Public Class PropertyValues
|
||||
Select Case oCount
|
||||
Case 0
|
||||
Return Nothing
|
||||
Case 1
|
||||
Dim firstElement As Object
|
||||
firstElement = oList.FirstOrDefault()
|
||||
If firstElement IsNot Nothing AndAlso IsArray(firstElement) Then
|
||||
|
||||
' Attachments sind Byte-Arrays und müssen umgewandelt werden
|
||||
Return Convert.ToBase64String(firstElement)
|
||||
|
||||
Else
|
||||
Return DoGetFinalPropValue(oList.First())
|
||||
End If
|
||||
Case Else
|
||||
Return DoGetFinalPropValue(oList.First())
|
||||
|
||||
End Select
|
||||
|
||||
Return DoGetFinalPropValue(Value)
|
||||
|
||||
@@ -14,6 +14,7 @@ Public Class Validator
|
||||
ValidateDecimalNodes(pResult)
|
||||
ValidateCurrencyNodes(pResult)
|
||||
|
||||
'TODO Validate Datumsfelder
|
||||
Return pResult
|
||||
End Function
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -558,7 +558,7 @@ Namespace ZUGFeRD.Version2_3_FacturX
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
|
||||
'''<remarks/>
|
||||
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0"), _
|
||||
System.SerializableAttribute(), _
|
||||
@@ -566,18 +566,31 @@ Namespace ZUGFeRD.Version2_3_FacturX
|
||||
System.ComponentModel.DesignerCategoryAttribute("code"), _
|
||||
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100")> _
|
||||
Partial Public Class DateTimeType
|
||||
|
||||
Private itemField As Object
|
||||
|
||||
|
||||
'Private itemField As Object
|
||||
|
||||
''''<remarks/>
|
||||
'<System.Xml.Serialization.XmlElementAttribute("DateTime", GetType(Date)), _
|
||||
' System.Xml.Serialization.XmlElementAttribute("DateTimeString", GetType(DateTimeTypeDateTimeString))> _
|
||||
'Public Property Item() As Object
|
||||
' Get
|
||||
' Return Me.itemField
|
||||
' End Get
|
||||
' Set
|
||||
' Me.itemField = value
|
||||
' End Set
|
||||
'End Property
|
||||
|
||||
Private itemField As DateTimeTypeDateTimeString
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlElementAttribute("DateTime", GetType(Date)), _
|
||||
System.Xml.Serialization.XmlElementAttribute("DateTimeString", GetType(DateTimeTypeDateTimeString))> _
|
||||
Public Property Item() As Object
|
||||
<System.Xml.Serialization.XmlElementAttribute("DateTimeString")>
|
||||
Public Property DateTimeString() As DateTimeTypeDateTimeString
|
||||
Get
|
||||
Return Me.itemField
|
||||
End Get
|
||||
Set
|
||||
Me.itemField = value
|
||||
Me.itemField = Value
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
@@ -9418,6 +9431,18 @@ Namespace ZUGFeRD.Version2_3_FacturX
|
||||
<System.Xml.Serialization.XmlEnumAttribute("870")>
|
||||
Item870 = 870
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlEnumAttribute("875")>
|
||||
Item875 = 875
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlEnumAttribute("876")>
|
||||
Item876 = 876
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlEnumAttribute("877")>
|
||||
Item877 = 877
|
||||
|
||||
'''<remarks/>
|
||||
<System.Xml.Serialization.XmlEnumAttribute("890")>
|
||||
Item890 = 890
|
||||
|
||||
@@ -22,7 +22,14 @@
|
||||
''' 0 = Default / Text
|
||||
''' 1 = Datum
|
||||
''' 2 = Gleitkomma
|
||||
''' 3 = Memo-Feld
|
||||
''' 3 = Attachment-Felder
|
||||
''' 4 = Elemente einer Liste, vgl Currency
|
||||
''' </summary>
|
||||
Public ItemType As Integer
|
||||
|
||||
''' <summary>
|
||||
''' BT-Feld-Bezeichnung
|
||||
''' </summary>
|
||||
Public EN16931_ID As String
|
||||
|
||||
End Class
|
||||
@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Jobs")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2025")>
|
||||
<Assembly: AssemblyTrademark("2.9.3.0")>
|
||||
<Assembly: AssemblyTrademark("2.9.9.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices
|
||||
' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
|
||||
<Assembly: AssemblyVersion("2.9.3.0")>
|
||||
<Assembly: AssemblyFileVersion("2.9.3.0")>
|
||||
<Assembly: AssemblyVersion("2.9.9.0")>
|
||||
<Assembly: AssemblyFileVersion("2.9.9.0")>
|
||||
|
||||
@@ -33,11 +33,6 @@ Public Class HashFunctions
|
||||
End If
|
||||
|
||||
' Check if Checksum exists in History Table
|
||||
'Dim oCheckCommand = $"SELECT * FROM TBEDM_ZUGFERD_HISTORY_IN WHERE GUID = (SELECT MAX(GUID) FROM TBEDM_ZUGFERD_HISTORY_IN WHERE UPPER(MD5HASH) = UPPER('{oMD5CheckSum}'))"
|
||||
'Dim oTable As DataTable = _firebird.GetDatatable(oCheckCommand, Firebird.TransactionMode.NoTransaction)
|
||||
|
||||
' Check if Checksum exists in History Table
|
||||
' TODO: WHAT THE FUCK IS THIS
|
||||
Dim oCheckCommand = $"SELECT * FROM TBEMLP_HISTORY WHERE GUID = (SELECT MAX(GUID) FROM TBEMLP_HISTORY WHERE UPPER(MD5HASH) = UPPER('{oMD5CheckSum}'))"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oCheckCommand, MSSQLServer.TransactionMode.NoTransaction)
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ Imports DigitalData.Modules.Interfaces.Exceptions
|
||||
Imports DigitalData.Modules.Interfaces.PropertyValues
|
||||
Imports DigitalData.Modules.Jobs.Exceptions
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports GdPicture14
|
||||
|
||||
Public Class ImportZUGFeRDFiles
|
||||
Implements IJob
|
||||
@@ -27,10 +28,35 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Private Const DIRECTORY_DONT_MOVE = "DIRECTORY_DONT_MOVE"
|
||||
|
||||
Private Const MIME_TYPE_PDF = "application/pdf"
|
||||
Private Const MIME_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
Private Const MIME_TYPE_ODT = "application/vnd.oasis.opendocument.spreadsheet"
|
||||
|
||||
' List of allowed extensions for PDF/A Attachments
|
||||
' This list should not contain xml so the zugferd xml file will be filtered out
|
||||
Private ReadOnly AllowedExtensions As New List(Of String) From {"docx", "doc", "pdf", "xls", "xlsx", "ppt", "pptx", "txt"}
|
||||
|
||||
' List of the Columns we need to store embedded files on disk and database
|
||||
Private ReadOnly EmbeddedFilesColumnNames As List(Of String) = New List(Of String) From {
|
||||
"ATTACHMENT_FILE_FILENAME", "ATTACHMENT_FILE_VALUE", "ATTACHMENT_FILE_MIMECODE"
|
||||
}
|
||||
|
||||
' List of the allowed MIME-Codes
|
||||
' Allowed Values are:
|
||||
'- application/pdf
|
||||
'- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx)
|
||||
'- application/vnd.oasis.opendocument.spreadsheet (odt)
|
||||
'- image/jpeg
|
||||
'- image/png
|
||||
'- image/tiff (UBL)
|
||||
'- text/csv
|
||||
'- text/xml (UBL)
|
||||
Private ReadOnly AllowedMimeTypesInEmbeddedFiles As List(Of String) = New List(Of String) From {
|
||||
MIME_TYPE_PDF,
|
||||
MIME_TYPE_XLSX,
|
||||
MIME_TYPE_ODT
|
||||
}
|
||||
|
||||
Private ReadOnly _logger As Logger
|
||||
Private ReadOnly _logConfig As LogConfig
|
||||
Private ReadOnly _filesystem As FilesystemEx
|
||||
@@ -140,8 +166,6 @@ Public Class ImportZUGFeRDFiles
|
||||
' Start a new transaction for each file group.
|
||||
' This way we can rollback database changes for the whole filegroup in case something goes wrong.
|
||||
Dim oSQLConnection As SqlConnection = _mssql.GetConnection()
|
||||
|
||||
|
||||
Dim oSQLTransaction As SqlTransaction = oSQLConnection?.BeginTransaction()
|
||||
|
||||
Dim oConnections As New DatabaseConnections() With {
|
||||
@@ -194,7 +218,7 @@ Public Class ImportZUGFeRDFiles
|
||||
End If
|
||||
|
||||
If oResult.ZugferdFileFound = True Then
|
||||
_logger.Debug("Zugferd File found")
|
||||
_logger.Debug("eInvoice File found")
|
||||
oMD5CheckSum = oResult.MD5Checksum
|
||||
oZUGFeRDCount = oResult.ZugferdFileCount
|
||||
oEmailAttachmentFiles.AddRange(oResult.EmailAttachmentFiles)
|
||||
@@ -311,7 +335,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = String.Format(EmailStrings.EMAIL_TOO_MUCH_FERDS, oEmailData.Subject)
|
||||
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "TooMuchFerdsException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.TooMuchFerdsException, "", "")
|
||||
AddRejectedState(oMessageId, oRejectionCodeString, "Email enthielt mehr als ein ZUGFeRD-Dokument", "", oSQLTransaction)
|
||||
AddRejectedState(oMessageId, oRejectionCodeString, "Email enthielt mehr als ein eInvoice-Dokument", "", oSQLTransaction)
|
||||
|
||||
Catch ex As NoFerdsException
|
||||
_logger.Error(ex)
|
||||
@@ -324,7 +348,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = String.Format(EmailStrings.EMAIL_NO_FERDS, oEmailData.Subject)
|
||||
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "NoFerdsException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.NoFerdsException, "", "")
|
||||
AddRejectedState(oMessageId, oRejectionCodeString, "Email enthielt keine ZUGFeRD-Dokumente", "", oSQLTransaction)
|
||||
AddRejectedState(oMessageId, oRejectionCodeString, "Email enthielt keine eInvoice-Dokumente", "", oSQLTransaction)
|
||||
|
||||
Catch ex As MissingValueException
|
||||
_logger.Error(ex)
|
||||
@@ -343,7 +367,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oEmailData = _file.MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "MissingValueException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.MissingValueException, oOrgFilename, oMissingFieldList)
|
||||
AddRejectedState(oMessageId, oRejectionCodeString, "Es fehlten ZugferdSpezifikationen", "", oSQLTransaction)
|
||||
AddRejectedState(oMessageId, oRejectionCodeString, "Es fehlten eInvoice-Spezifikationen", "", oSQLTransaction)
|
||||
|
||||
Catch ex As FileSizeLimitReachedException
|
||||
_logger.Error(ex)
|
||||
@@ -376,7 +400,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = _email.CreateBodyForUnhandledException(oMessageId, ex)
|
||||
Dim oEmailData As New EmailData With {
|
||||
.From = oArgs.ExceptionEmailAddress,
|
||||
.Subject = $"OutOfMemoryException im ZUGFeRD-Parser @ {oMessageId}"
|
||||
.Subject = $"OutOfMemoryException im eInvoice-Parser @ {oMessageId}"
|
||||
}
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "OutOfMemoryException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.UnhandledException, ex.Message, ex.StackTrace)
|
||||
|
||||
@@ -399,7 +423,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = _email.CreateBodyForUnhandledException(oMessageId, ex)
|
||||
Dim oEmailData As New EmailData With {
|
||||
.From = oArgs.ExceptionEmailAddress,
|
||||
.Subject = $"UnhandledException im ZUGFeRD-Parser @ {oMessageId}"
|
||||
.Subject = $"UnhandledException im eInvoice-Parser @ {oMessageId}"
|
||||
}
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "UnhandledException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.UnhandledException, ex.Message, ex.StackTrace)
|
||||
|
||||
@@ -455,7 +479,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = _email.CreateBodyForUnhandledException(oMessageId, ex)
|
||||
Dim oEmailData As New EmailData With {
|
||||
.From = oArgs.ExceptionEmailAddress,
|
||||
.Subject = $"FileMoveException im ZUGFeRD-Parser @ {oMessageId}"
|
||||
.Subject = $"FileMoveException im eInvoice-Parser @ {oMessageId}"
|
||||
}
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "FileMoveException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.UnhandledException, ex.Message, ex.StackTrace)
|
||||
|
||||
@@ -541,21 +565,21 @@ Public Class ImportZUGFeRDFiles
|
||||
Catch ex As ZUGFeRDExecption
|
||||
Select Case ex.ErrorType
|
||||
Case ZUGFeRDInterface.ErrorType.NoZugferd
|
||||
_logger.Info("File [{0}] is not a valid ZUGFeRD document. Skipping.", pFile.Name)
|
||||
_logger.Info("File [{0}] is not a valid eInvoice document. Skipping.", pFile.Name)
|
||||
|
||||
oResult.EmailAttachmentFiles.Add(pFile)
|
||||
Return oResult
|
||||
|
||||
Case ZUGFeRDInterface.ErrorType.UnsupportedFormat
|
||||
_logger.Info("File [{0}/{1}] is an unsupported ZUFeRD document format!", pFile.Name, ex.XmlFile)
|
||||
_logger.Info("File [{0}/{1}] is an unsupported eInvoice document format!", pFile.Name, ex.XmlFile)
|
||||
Throw New UnsupportedFerdException(ex.XmlFile)
|
||||
|
||||
Case ZUGFeRDInterface.ErrorType.NoValidZugferd
|
||||
_logger.Info("File [{0}] is an Incorrectly formatted ZUGFeRD document!", pFile.Name)
|
||||
_logger.Info("File [{0}] is an Incorrectly formatted eInvoice document!", pFile.Name)
|
||||
Throw New InvalidFerdException()
|
||||
|
||||
Case Else
|
||||
_logger.Warn("Unexpected Error occurred while extracting ZUGFeRD Information from file {0}", pFile.Name)
|
||||
_logger.Warn("Unexpected Error occurred while extracting eInvoice Information from file {0}", pFile.Name)
|
||||
Throw ex
|
||||
End Select
|
||||
|
||||
@@ -563,7 +587,7 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Try
|
||||
oDocument.ReceiptFileType = ZUGFeRDInterface.RECEIPT_TYPE_XML
|
||||
Dim sqlResult As Boolean = StoreXMLItemsInDatabase(pMessageId, oDocument, pFile, pConnections, pArgs)
|
||||
Dim sqlResult As Boolean = StoreXMLItemsInDatabase(pMessageId, oDocument, pFile, pConnections, pArgs, oResult)
|
||||
Catch ex As Exception
|
||||
Throw ex
|
||||
End Try
|
||||
@@ -613,21 +637,21 @@ Public Class ImportZUGFeRDFiles
|
||||
Catch ex As ZUGFeRDExecption
|
||||
Select Case ex.ErrorType
|
||||
Case ZUGFeRDInterface.ErrorType.NoZugferd
|
||||
_logger.Info("File [{0}] is not a valid ZUGFeRD document. Skipping.", pFile.Name)
|
||||
_logger.Info("File [{0}] is not a valid eInvoice document. Skipping.", pFile.Name)
|
||||
|
||||
oResult.EmailAttachmentFiles.Add(pFile)
|
||||
Return oResult
|
||||
|
||||
Case ZUGFeRDInterface.ErrorType.UnsupportedFormat
|
||||
_logger.Info("File [{0}/{1}] is an unsupported ZUFeRD document format!", pFile.Name, ex.XmlFile)
|
||||
_logger.Info("File [{0}/{1}] is an unsupported eInvoice document format!", pFile.Name, ex.XmlFile)
|
||||
Throw New UnsupportedFerdException(ex.XmlFile)
|
||||
|
||||
Case ZUGFeRDInterface.ErrorType.NoValidZugferd
|
||||
_logger.Info("File [{0}] is an Incorrectly formatted ZUGFeRD document!", pFile.Name)
|
||||
_logger.Info("File [{0}] is an incorrectly formatted eInvoice document!", pFile.Name)
|
||||
Throw New InvalidFerdException()
|
||||
|
||||
Case Else
|
||||
_logger.Warn("Unexpected Error occurred while extracting ZUGFeRD Information from file {0}", pFile.Name)
|
||||
_logger.Warn("Unexpected Error occurred while extracting eInvoice Information from file {0}", pFile.Name)
|
||||
Throw ex
|
||||
End Select
|
||||
End Try
|
||||
@@ -653,7 +677,7 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Try
|
||||
oDocument.ReceiptFileType = ZUGFeRDInterface.RECEIPT_TYPE_PDF
|
||||
Dim sqlResult As Boolean = StoreXMLItemsInDatabase(pMessageId, oDocument, pFile, pConnections, pArgs)
|
||||
Dim sqlResult As Boolean = StoreXMLItemsInDatabase(pMessageId, oDocument, pFile, pConnections, pArgs, oResult)
|
||||
Catch ex As Exception
|
||||
Throw ex
|
||||
End Try
|
||||
@@ -670,12 +694,12 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
End Function
|
||||
|
||||
Private Function StoreXMLItemsInDatabase(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pFile As FileInfo, pConnections As DatabaseConnections, pArgs As WorkerArgs) As Boolean
|
||||
Private Function StoreXMLItemsInDatabase(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pFile As FileInfo, pConnections As DatabaseConnections, pArgs As WorkerArgs, pProcessFileResult As ProcessFileResult) As Boolean
|
||||
' Check the document against the configured property map and return:
|
||||
' - a List of valid properties
|
||||
' - a List of missing properties
|
||||
|
||||
Dim oPropertyMap = _zugferd.FilterPropertyMap(pArgs.PropertyMap, pDocument.Specification)
|
||||
Dim oPropertyMap As Dictionary(Of String, XmlItemProperty) = _zugferd.FilterPropertyMap(pArgs.PropertyMapList, pDocument.Specification)
|
||||
Dim oCheckResult = _zugferd.PropertyValues.CheckPropertyValues(pDocument.SchemaObject, oPropertyMap, pMessageId)
|
||||
|
||||
_logger.Info("Properties checked: [{0}] missing properties / [{1}] valid properties found.", oCheckResult.MissingProperties.Count, oCheckResult.ValidProperties.Count)
|
||||
@@ -693,39 +717,359 @@ Public Class ImportZUGFeRDFiles
|
||||
Throw New Exception("Bulk Insert failed! Exiting.")
|
||||
End If
|
||||
|
||||
' TODO hier BAUSTELLE
|
||||
' Eingebettete Dateien speichern
|
||||
'If CreateEmbeddedFilesOnDisk(pMessageId, pDocument, pConnections, oCheckResult) = False Then
|
||||
' _logger.Debug("Files saving for MessageId [{0}] failed!", pMessageId)
|
||||
'End If
|
||||
If HandleEmbeddedAttachments(pMessageId, pDocument, pConnections, oCheckResult, pArgs, pProcessFileResult) = False Then
|
||||
_logger.Debug("Files saving for MessageId [{0}] failed!", pMessageId)
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Function CreateEmbeddedFilesOnDisk(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pConnections As DatabaseConnections, pCheckResult As CheckPropertyValuesResult) As Boolean
|
||||
''' <summary>
|
||||
''' Hier werden die Dateianhänge behandelt, die im XML als base64 eingetragen wurden.
|
||||
''' Die zusammengehörigen Knoten müssen über "FILES" gruppiert werden!
|
||||
'''
|
||||
''' Die erwarteten Knoten-Namen sind in der List EmbeddedFilesColumnNames enthalten!
|
||||
''' </summary>
|
||||
Private Function HandleEmbeddedAttachments(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pConnections As DatabaseConnections,
|
||||
pCheckResult As CheckPropertyValuesResult, pArgs As WorkerArgs, pProcessFileResult As ProcessFileResult) As Boolean
|
||||
|
||||
' Finde alle Eintraege in pCheckResult mit Item_Type=3
|
||||
' Finde Dateinamen (Index nach ~attm) und Dateityp. Wir speichern nur PDF.
|
||||
' TODO Funktion aufrufen
|
||||
'SaveBase64ToDisk("", "") = False Then
|
||||
If (pCheckResult Is Nothing) Then
|
||||
_logger.Debug("pCheckResult is empty!")
|
||||
Return True
|
||||
End If
|
||||
|
||||
If (CheckEmbeddedAttachmentEntries(pCheckResult) = False) Then
|
||||
_logger.Debug("No embedded Files in XML found!")
|
||||
Return True
|
||||
End If
|
||||
|
||||
Dim embAttachmentList As List(Of ValidProperty) = pCheckResult.ValidProperties.Where(
|
||||
Function(z)
|
||||
Return EmbeddedFilesColumnNames.Contains(z.TableColumn)
|
||||
End Function
|
||||
).ToList()
|
||||
|
||||
If embAttachmentList Is Nothing OrElse embAttachmentList.Count <= 0 Then
|
||||
_logger.Debug("No Fields for Embedded Files configured!")
|
||||
Return True
|
||||
End If
|
||||
|
||||
' GroupCounter Werte in Hashset eintragen, um distinct Werte zu erhalten
|
||||
Dim oIndexList As HashSet(Of Integer) = New HashSet(Of Integer)
|
||||
For Each resultItem In embAttachmentList
|
||||
oIndexList.Add(resultItem.GroupCounter)
|
||||
Next
|
||||
|
||||
Dim oOutputPath As String = GetOutputPathForEmbeddedAttachments(pArgs)
|
||||
Dim nextAttachmentIndex As Integer = 0
|
||||
nextAttachmentIndex = GetNextAttachmentIndex(pMessageId)
|
||||
If nextAttachmentIndex <= 0 Then
|
||||
nextAttachmentIndex = 1
|
||||
End If
|
||||
|
||||
For Each groupIndex In oIndexList
|
||||
|
||||
Dim oMimeCodeString As String = String.Empty
|
||||
Dim oOrgFilename As String = String.Empty
|
||||
Dim oBase64String As String = String.Empty
|
||||
|
||||
Dim oMimeTypeProperty As ValidProperty = GetIndexProperty(embAttachmentList, groupIndex, "ATTACHMENT_FILE_MIMECODE")
|
||||
|
||||
If oMimeTypeProperty IsNot Nothing AndAlso oMimeTypeProperty.Value.IsNotNullOrEmpty() Then
|
||||
oMimeCodeString = oMimeTypeProperty.Value.ToLower()
|
||||
Else
|
||||
_logger.Debug("Empty MIME-Code! File can not be stored!")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oFilenameProperty As ValidProperty = GetIndexProperty(embAttachmentList, groupIndex, "ATTACHMENT_FILE_FILENAME")
|
||||
If oFilenameProperty IsNot Nothing AndAlso oFilenameProperty.Value.IsNotNullOrEmpty() Then
|
||||
oOrgFilename = oFilenameProperty.Value
|
||||
Else
|
||||
_logger.Debug("Empty Filename! File can not be stored!")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oBase64ValueProperty As ValidProperty = GetIndexProperty(embAttachmentList, groupIndex, "ATTACHMENT_FILE_VALUE")
|
||||
If oBase64ValueProperty IsNot Nothing AndAlso oBase64ValueProperty.Value.IsNotNullOrEmpty() Then
|
||||
oBase64String = oBase64ValueProperty.Value
|
||||
Else
|
||||
_logger.Error("Empty base64 String! File can not be stored!")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim newAttachmentFilename = pMessageId + "~attm" + nextAttachmentIndex.ToString
|
||||
|
||||
Dim oFileExtension = GetEmbeddedFileExtension(oMimeTypeProperty.Value)
|
||||
If oFileExtension.IsNotNullOrEmpty() Then
|
||||
newAttachmentFilename += "." + oFileExtension
|
||||
Else
|
||||
_logger.Warn("No extension found! File can not be stored!")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim embeddedFilePath = Path.Combine(oOutputPath, newAttachmentFilename)
|
||||
_logger.Debug("Next Attachment File is [{0}]", embeddedFilePath)
|
||||
If SaveBase64ToDisk(embeddedFilePath, oBase64String) = True Then
|
||||
_logger.Debug("Saved file [{0}] to disk", embeddedFilePath)
|
||||
pProcessFileResult.EmailAttachmentFiles.Add(New FileInfo(embeddedFilePath))
|
||||
Else
|
||||
_logger.Error("Could not save File to Disk!")
|
||||
Dim oReasonString = "Could not save file " + newAttachmentFilename + " to disk."
|
||||
AddRejectedState(pMessageId, oReasonString, "EMBEDDED FILE CONSISTENCY NOT OK", "Info GUI", pConnections.SQLServerTransaction)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If TestFileOnDisk(embeddedFilePath, oMimeCodeString) = False Then
|
||||
_logger.Error("Could not save File to Disk!")
|
||||
Dim oReasonString = "Validation of file " + newAttachmentFilename + " on disk was NOT succesfully."
|
||||
AddRejectedState(pMessageId, oReasonString, "EMBEDDED FILE CONSISTENCY NOT OK", "Info GUI", pConnections.SQLServerTransaction)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If InsertAttachmentHistoryEntry(pMessageId, oOrgFilename, embeddedFilePath) = False Then
|
||||
_logger.Error("Could not save attachment Data to DB!")
|
||||
Return False
|
||||
End If
|
||||
|
||||
If InsertEmbeddedFileDataToDB(pMessageId, oBase64String, oOrgFilename, oMimeCodeString, groupIndex) = False Then
|
||||
_logger.Error("Could not save attachment Data to DB!")
|
||||
Return False
|
||||
End If
|
||||
|
||||
nextAttachmentIndex += 1
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Function SaveBase64ToDisk(pExportFilePath As String, pBase64String As String) As Boolean
|
||||
Private Function TestFileOnDisk(pEmbeddedFilePath As String, pMimeCodeString As String) As Boolean
|
||||
Try
|
||||
Dim base64BinaryDataString As String = pBase64String ' Hier Base64-String einfügen
|
||||
Dim binaryDataString As Byte() = System.Convert.FromBase64String(base64BinaryDataString)
|
||||
Dim oFilename As String = pExportFilePath
|
||||
Dim Stream As System.IO.FileStream = New System.IO.FileStream(oFilename, System.IO.FileMode.Create)
|
||||
Stream.Write(binaryDataString, 0, binaryDataString.Length)
|
||||
Stream.Close()
|
||||
Catch ex As Exception
|
||||
_logger.Error("Could NOT save File to Disk for MessageId [{0}] !", pExportFilePath)
|
||||
If pMimeCodeString = MIME_TYPE_PDF Then
|
||||
Dim oGdPicturePDF As New GdPicturePDF
|
||||
Dim oStatus As GdPictureStatus = oGdPicturePDF.LoadFromFile(pEmbeddedFilePath, True)
|
||||
If oStatus <> GdPictureStatus.OK Then
|
||||
_logger.Error("File [{0}] has no proper state!", pEmbeddedFilePath)
|
||||
Return False
|
||||
End If
|
||||
|
||||
Else
|
||||
' Test other files
|
||||
Dim fileInfo As FileInfo = New FileInfo(pEmbeddedFilePath)
|
||||
If fileInfo.Exists = False Then
|
||||
_logger.Error("Could not find File [{0}] on Disk!", pEmbeddedFilePath)
|
||||
Return False
|
||||
End If
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetEmbeddedFileExtension(pMimeTypeValue As String) As String
|
||||
|
||||
If pMimeTypeValue.IsNullOrEmpty() Then
|
||||
_logger.Warn("Empty MimeCode is not allowed!")
|
||||
Return String.Empty
|
||||
End If
|
||||
|
||||
Select Case pMimeTypeValue.ToLower()
|
||||
Case MIME_TYPE_PDF
|
||||
Return "pdf"
|
||||
Case MIME_TYPE_XLSX
|
||||
Return "xlsx"
|
||||
Case MIME_TYPE_ODT
|
||||
Return "odt"
|
||||
Case "image/jpeg"
|
||||
Return "jpg"
|
||||
Case "image/png"
|
||||
Return "png"
|
||||
Case "image/tiff"
|
||||
Return "tif"
|
||||
Case "text/csv"
|
||||
Return "csv"
|
||||
Case "text/xml"
|
||||
Return "xml"
|
||||
Case Else
|
||||
Return String.Empty
|
||||
End Select
|
||||
|
||||
End Function
|
||||
|
||||
Private Shared Function GetIndexProperty(pListResult As List(Of ValidProperty), pGroupIndex As Integer, pTableColumn As String) As ValidProperty
|
||||
Return pListResult.Where(
|
||||
Function(z)
|
||||
Return z.GroupCounter = pGroupIndex AndAlso z.TableColumn = pTableColumn
|
||||
End Function
|
||||
).FirstOrDefault
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Speichert die Daten inkl. base64-String in die Datenbank
|
||||
''' </summary>
|
||||
Private Function InsertEmbeddedFileDataToDB(pMessageId As String, pItemValue As String, pOrgFilename As String, pMimeType As String, pGroupIndex As Integer) As Boolean
|
||||
Try
|
||||
Dim oCommand = New SqlCommand(
|
||||
"INSERT INTO TBEDMI_ITEM_FILES (
|
||||
REFERENCE_GUID,
|
||||
ITEM_VALUE,
|
||||
ORG_FILENAME,
|
||||
MIME_TYPE,
|
||||
GROUP_INDEX,
|
||||
CREATED_WHO
|
||||
) VALUES (
|
||||
@MESSAGE_ID,
|
||||
@ITEM_VALUE,
|
||||
@ORG_FILENAME,
|
||||
@MIME_TYPE,
|
||||
@GROUP_INDEX,
|
||||
@CREATED_WHO
|
||||
)")
|
||||
|
||||
Dim fileBytes As Byte() = Convert.FromBase64String(pItemValue)
|
||||
|
||||
oCommand.Parameters.Add("MESSAGE_ID", SqlDbType.VarChar, 250).Value = pMessageId
|
||||
oCommand.Parameters.Add("ITEM_VALUE", SqlDbType.VarBinary).Value = fileBytes
|
||||
oCommand.Parameters.Add("ORG_FILENAME", SqlDbType.VarChar, 256).Value = pOrgFilename
|
||||
oCommand.Parameters.Add("MIME_TYPE", SqlDbType.VarChar, 256).Value = pMimeType
|
||||
oCommand.Parameters.Add("GROUP_INDEX", SqlDbType.Int).Value = pGroupIndex
|
||||
oCommand.Parameters.Add("CREATED_WHO", SqlDbType.VarChar, 100).Value = "eInvoice Parser"
|
||||
|
||||
_mssql.ExecuteNonQuery(oCommand)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Ermittelt den Ausgabepfad für die eingebetteten Anhänge
|
||||
''' </summary>
|
||||
Private Function GetOutputPathForEmbeddedAttachments(pArgs As WorkerArgs) As String
|
||||
Return pArgs.WatchDirectory
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Prüft, ob Embedded Attachments in den XML-Ergebnissen enthalten sind,
|
||||
''' in dem geprüft wird, ob bestimmte MIME-Codes vorhanden sind.
|
||||
''' </summary>
|
||||
''' <param name="pCheckResult"></param>
|
||||
''' <returns></returns>
|
||||
Private Function CheckEmbeddedAttachmentEntries(pCheckResult As CheckPropertyValuesResult) As Boolean
|
||||
|
||||
Try
|
||||
Dim resultList = pCheckResult.ValidProperties.Where(
|
||||
Function(z)
|
||||
Return (z.TableColumn = "ATTACHMENT_FILE_MIMECODE" AndAlso AllowedMimeTypesInEmbeddedFiles.Contains(z.Value.ToLower()))
|
||||
End Function
|
||||
).ToList()
|
||||
|
||||
If resultList.Count > 0 Then
|
||||
_logger.Info("Found [{0}] embedded XML-Attachments.", resultList.Count)
|
||||
Return True
|
||||
Else
|
||||
_logger.Info("No embedded XML-Attachments found.")
|
||||
Return False
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_logger.Error("Error searching pCheckResult! {0}", ex.Message)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Speichere base64 als Datei auf der Platte ab.
|
||||
''' </summary>
|
||||
Private Function SaveBase64ToDisk(pExportFilePath As String, pBase64String As String) As Boolean
|
||||
|
||||
Try
|
||||
Dim oFilename As String = pExportFilePath
|
||||
Dim base64BinaryDataString As String = pBase64String
|
||||
Dim binaryDataString As Byte() = Convert.FromBase64String(base64BinaryDataString)
|
||||
|
||||
' Using verwenden, um blockieren der Datei zu verhindern
|
||||
Using fs = New FileStream(oFilename, FileMode.Create, FileAccess.ReadWrite)
|
||||
fs.Write(binaryDataString, 0, binaryDataString.Length)
|
||||
fs.Flush()
|
||||
fs.Close()
|
||||
End Using
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error("Could NOT save File [{0}] to Disk! Exception: [{1}]", pExportFilePath, ex.Message)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Die Methode lädt die bisherigen Dateinamen zu einer MessageID
|
||||
''' Die Datei mit dem höchsten Index gibt den folgenden Index vor.
|
||||
''' </summary>
|
||||
''' <returns>Nächster Attachment Index</returns>
|
||||
Private Function GetNextAttachmentIndex(pMessageId As String) As Integer
|
||||
Try
|
||||
Dim oSQL = $"SELECT count(*) FROM TBEMLP_HISTORY_ATTACHMENT WHERE EMAIL_MSGID = '{pMessageId}'"
|
||||
|
||||
Dim sqlResult = _mssql.GetScalarValue(oSQL)
|
||||
If sqlResult = 0 Then
|
||||
sqlResult = 1 ' Kleinster Index = 1
|
||||
End If
|
||||
|
||||
Return sqlResult
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Speichert die Infos zu einem embedded Dateianhang in die DB.
|
||||
''' Mangels EMail-Daten werden die EMail-Felder (FROM, BODY, usw.) nicht gefüllt
|
||||
''' </summary>
|
||||
''' <returns>true, wenn erfolgreich</returns>
|
||||
Private Function InsertAttachmentHistoryEntry(pMessageId As String, pFileName As String, pNewFileName As String) As Boolean
|
||||
|
||||
Try
|
||||
Dim oCommand = New SqlCommand(
|
||||
"INSERT INTO TBEMLP_HISTORY_ATTACHMENT (
|
||||
WORK_PROCESS,
|
||||
EMAIL_MSGID,
|
||||
EMAIL_ATTMT,
|
||||
EMAIL_ATTMT_INDEX,
|
||||
EMAIL_FROM,
|
||||
EMAIL_BODY
|
||||
) VALUES (
|
||||
@WORK_PROCESS,
|
||||
@MESSAGE_ID,
|
||||
@ATTACHMENT,
|
||||
@ATTACHMENT_INDEX,
|
||||
'-',
|
||||
'-'
|
||||
)")
|
||||
|
||||
oCommand.Parameters.Add("WORK_PROCESS", SqlDbType.VarChar, 100).Value = "Attachment Sniffer (Embedded Files)"
|
||||
oCommand.Parameters.Add("MESSAGE_ID", SqlDbType.VarChar, 500).Value = pMessageId
|
||||
oCommand.Parameters.Add("ATTACHMENT", SqlDbType.VarChar, 500).Value = pFileName
|
||||
oCommand.Parameters.Add("ATTACHMENT_INDEX", SqlDbType.VarChar, 500).Value = pNewFileName
|
||||
|
||||
_mssql.ExecuteNonQuery(oCommand)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function BulkInsertDataToDatabase(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pConnections As DatabaseConnections, pCheckResults As CheckPropertyValuesResult) As Boolean
|
||||
@@ -771,7 +1115,7 @@ Public Class ImportZUGFeRDFiles
|
||||
' Erste Zeile enthält die Spezifikation
|
||||
Dim oFirstRow As DataRow = oDataTable.NewRow()
|
||||
oFirstRow("REFERENCE_GUID") = pMessageId
|
||||
oFirstRow("ITEM_DESCRIPTION") = "ZUGFeRDSpezifikation"
|
||||
oFirstRow("ITEM_DESCRIPTION") = "Verwendete Spezifikation der E-Rechnung"
|
||||
oFirstRow("ITEM_VALUE") = pDocument.Specification
|
||||
oFirstRow("GROUP_COUNTER") = 0
|
||||
oFirstRow("SPEC_NAME") = "ZUGFERD_SPECIFICATION"
|
||||
@@ -783,7 +1127,7 @@ Public Class ImportZUGFeRDFiles
|
||||
' Zweite Zeile enthält das verwendete XML Schema
|
||||
Dim oSecondRow As DataRow = oDataTable.NewRow()
|
||||
oSecondRow("REFERENCE_GUID") = pMessageId
|
||||
oSecondRow("ITEM_DESCRIPTION") = "ZUGFeRDXMLSchema"
|
||||
oSecondRow("ITEM_DESCRIPTION") = "Verwendetes XML-Schema (XSD) der E-Rechnung"
|
||||
oSecondRow("ITEM_VALUE") = pDocument.UsedXMLSchema
|
||||
oSecondRow("GROUP_COUNTER") = 0
|
||||
oSecondRow("SPEC_NAME") = "ZUGFERD_XML_SCHEMA"
|
||||
@@ -795,7 +1139,7 @@ Public Class ImportZUGFeRDFiles
|
||||
' Dritte Zeile enthält das verwendete Datei-Format des Belegs (PDF/XML)
|
||||
Dim oThirdRow As DataRow = oDataTable.NewRow()
|
||||
oThirdRow("REFERENCE_GUID") = pMessageId
|
||||
oThirdRow("ITEM_DESCRIPTION") = "ReceiptFileType"
|
||||
oThirdRow("ITEM_DESCRIPTION") = "Dateityp der E-Rechnung"
|
||||
oThirdRow("ITEM_VALUE") = pDocument.ReceiptFileType
|
||||
oThirdRow("GROUP_COUNTER") = 0
|
||||
oThirdRow("SPEC_NAME") = "RECEIPT_FILE_TYPE"
|
||||
@@ -811,6 +1155,12 @@ Public Class ImportZUGFeRDFiles
|
||||
Continue For
|
||||
End If
|
||||
|
||||
' ItemType = 0 (normale texte) dürfen nicht leer sein
|
||||
If oProperty.ItemType = 0 And oProperty.Value.IsNullOrEmpty Then
|
||||
_logger.Debug("No Mapping for Property [{0}] with empty value, because of ItemType = 0.", oProperty.TableColumn)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
' If GroupCounter is -1, it means this is a default property that can only occur once.
|
||||
' Set the actual inserted value to 0
|
||||
Dim oGroupCounterValue As Integer = oProperty.GroupCounter
|
||||
@@ -822,15 +1172,22 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Warn("Value for field [{0}] is longer than 900 characters, will be truncated!", oProperty.TableColumn)
|
||||
End If
|
||||
|
||||
Dim oDescription As String
|
||||
If oProperty.EN16931_ID IsNot Nothing AndAlso oProperty.EN16931_ID.Length > 1 Then
|
||||
oDescription = oProperty.EN16931_ID + " (" + oProperty.Description + ")"
|
||||
Else
|
||||
oDescription = oProperty.Description
|
||||
End If
|
||||
|
||||
Dim oNewRow As DataRow = oDataTable.NewRow()
|
||||
oNewRow("REFERENCE_GUID") = pMessageId
|
||||
oNewRow("ITEM_DESCRIPTION") = oProperty.Description
|
||||
oNewRow("ITEM_VALUE") = oProperty.Value.Truncate(900).Replace("'", "''")
|
||||
oNewRow("ITEM_DESCRIPTION") = oDescription
|
||||
oNewRow("ITEM_VALUE") = oProperty.Value.Truncate(900)
|
||||
oNewRow("GROUP_COUNTER") = oGroupCounterValue
|
||||
oNewRow("SPEC_NAME") = oProperty.TableColumn
|
||||
oNewRow("IS_REQUIRED") = oProperty.IsRequired
|
||||
|
||||
_logger.Debug("Mapping Property [{0}] with value [{1}]", oProperty.TableColumn, oProperty.Value.Replace("'", "''"))
|
||||
_logger.Debug("Mapping Property [{0}] with value [{1}]", oProperty.TableColumn, oProperty.Value)
|
||||
oDataTable.Rows.Add(oNewRow)
|
||||
Next
|
||||
|
||||
@@ -848,6 +1205,15 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
|
||||
Try
|
||||
oDelSQL = $"DELETE FROM TBEDMI_ITEM_FILES where REFERENCE_GUID = '{pMessageId}'"
|
||||
oStep = "TBEDMI_ITEM_FILES Delete MessageID Items"
|
||||
Dim retValue As Boolean = _mssql.ExecuteNonQueryWithConnectionObject(oDelSQL, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction)
|
||||
Return retValue
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
|
||||
Return False
|
||||
End Function
|
||||
|
||||
@@ -871,6 +1237,10 @@ Public Class ImportZUGFeRDFiles
|
||||
Return True
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Fügt neue Datensätze in Tabelle TBEMLP_HISTORY_STATE ein,
|
||||
''' per Prozedur DD_ECM.[dbo].[PRCUST_ADD_HISTORY_STATE]
|
||||
''' </summary>
|
||||
Private Sub AddRejectedState(pMessageID As String, pTitle As String, pTitle1 As String, pComment As String, pTransaction As SqlTransaction)
|
||||
Try
|
||||
'PRCUST_ADD_HISTORY_STATE: @MessageID VARCHAR(250), @TITLE1 VARCHAR(250), @TITLE2 VARCHAR(250)
|
||||
@@ -880,4 +1250,5 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
@@ -12,7 +12,7 @@ Public Class WorkerArgs
|
||||
Public NonZugferdDirectory As String = Nothing
|
||||
|
||||
' Property Parameter
|
||||
Public PropertyMap As New Dictionary(Of String, XmlItemProperty)
|
||||
Public PropertyMapList As New List(Of XmlItemProperty)
|
||||
|
||||
' Email Parameter
|
||||
Public EmailOutProfileId As Integer = 0
|
||||
@@ -31,6 +31,7 @@ Public Class WorkerArgs
|
||||
Public AllowXRechnung As Boolean = True
|
||||
Public AllowZugferd10 As Boolean = True
|
||||
Public AllowZugferd2x As Boolean = True
|
||||
Public AllowZugferd23x As Boolean = True
|
||||
Public AllowPeppolBISBill3x As Boolean = False
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user