From cf9650be50105519e13817ae8a38964dae4d90ee Mon Sep 17 00:00:00 2001 From: pitzm Date: Tue, 13 May 2025 14:48:09 +0200 Subject: [PATCH] Peppol 3017 / UBL Logik --- Interfaces/Interfaces.vbproj | 1 + Interfaces/ZUGFeRDInterface.vb | 4 +- .../ZUGFeRDInterface/Enums/Item_Types.vb | 7 +++ Interfaces/ZUGFeRDInterface/PropertyValues.vb | 6 +-- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 51 ++++++++++++++++++- 5 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 Interfaces/ZUGFeRDInterface/Enums/Item_Types.vb diff --git a/Interfaces/Interfaces.vbproj b/Interfaces/Interfaces.vbproj index 48e821e5..dc4375f8 100644 --- a/Interfaces/Interfaces.vbproj +++ b/Interfaces/Interfaces.vbproj @@ -226,6 +226,7 @@ + diff --git a/Interfaces/ZUGFeRDInterface.vb b/Interfaces/ZUGFeRDInterface.vb index 43fae6c0..4cca2f1f 100644 --- a/Interfaces/ZUGFeRDInterface.vb +++ b/Interfaces/ZUGFeRDInterface.vb @@ -21,8 +21,8 @@ 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 PEPPOL_SPEC_3x_INVOICE = "PEPPOL_BISBILL_3x_INVOICE" - Public Const PEPPOL_SPEC_3x_CREDITNOTE = "PEPPOL_BISBILL_3x_CREDITNOTE" + Public Const PEPPOL_SPEC_3x_INVOICE = "PEPPOL_BISBILL_3x" + Public Const PEPPOL_SPEC_3x_CREDITNOTE = "PEPPOL_BISBILL_3x" Public Const XMLSCHEMA_ZUGFERD_10 = "Version1_0" Public Const XMLSCHEMA_ZUGFERD_20 = "Version2_0" diff --git a/Interfaces/ZUGFeRDInterface/Enums/Item_Types.vb b/Interfaces/ZUGFeRDInterface/Enums/Item_Types.vb new file mode 100644 index 00000000..f1e51814 --- /dev/null +++ b/Interfaces/ZUGFeRDInterface/Enums/Item_Types.vb @@ -0,0 +1,7 @@ +Public Enum Item_Types + StringType '0 + DateType '1 + MoneyType '2 + FileType '3 + +End Enum diff --git a/Interfaces/ZUGFeRDInterface/PropertyValues.vb b/Interfaces/ZUGFeRDInterface/PropertyValues.vb index c9a9c29b..e59d8c66 100644 --- a/Interfaces/ZUGFeRDInterface/PropertyValues.vb +++ b/Interfaces/ZUGFeRDInterface/PropertyValues.vb @@ -83,17 +83,17 @@ Public Class PropertyValues _logger.Error(ex) oPropertyValues = New List(Of Object) End Try + + ' check the first batch of values to determine the row count If oRowCount = 0 Then '08.04.2025 MS Added as Workaround for Positions Or oGroupScope = "POSITIONS" ! oRowCount = oPropertyValues.Count End If + ' Flatten result value oPropertyValues = GetFinalPropValue(oPropertyValues) ' Add to list oPropertyList.Add(oProperty.Value, oPropertyValues) - - ' check the first batch of values to determine the row count - Next ' Structure of oPropertyList diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index 7539c8b2..c44e4be6 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -8,6 +8,7 @@ Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Interfaces.Exceptions +Imports DigitalData.Modules.Interfaces.PropertyValues Imports DigitalData.Modules.Jobs.Exceptions Imports DigitalData.Modules.Logging @@ -686,12 +687,54 @@ Public Class ImportZUGFeRDFiles _logger.Debug("No missing properties found. Continuing.") End If + ' Daten in die Datenbank speichern + If BulkInsertDataToDatabase(pMessageId, pDocument, pConnections, oCheckResult) = False Then + _logger.Error("Bulk Insert for MessageId [{0}] failed!", pMessageId) + 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 + + Return True + End Function + + Private Function CreateEmbeddedFilesOnDisk(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pConnections As DatabaseConnections, pCheckResult As CheckPropertyValuesResult) 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 + + Return True + End Function + + Private Function SaveBase64ToDisk(pExportFilePath As String, pBase64String 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) + + End Try + + Return True + End Function + + Private Function BulkInsertDataToDatabase(pMessageId As String, pDocument As ZUGFeRDInterface.ZugferdResult, pConnections As DatabaseConnections, pCheckResults As CheckPropertyValuesResult) As Boolean If DeleteExistingPropertyValues(pMessageId, pConnections) = False Then Throw New Exception("Could not cleanup data. Exiting.") End If ' DataTable vorbereiten - Dim oDataTable As DataTable = FillDataTable(pMessageId, oCheckResult, pDocument) + Dim oDataTable As DataTable = FillDataTable(pMessageId, pCheckResults, pDocument) ' ColumnList initialisieren Dim oColumnNames As List(Of String) = New List(Of String) From { @@ -714,6 +757,7 @@ Public Class ImportZUGFeRDFiles Return True End Function + Private Function FillDataTable(pMessageId As String, pCheckResult As PropertyValues.CheckPropertyValuesResult, pDocument As ZUGFeRDInterface.ZugferdResult) As DataTable Dim oDataTable As DataTable = New DataTable() @@ -762,6 +806,11 @@ Public Class ImportZUGFeRDFiles For Each oProperty In pCheckResult.ValidProperties + ' ItemType = 3 => eingebettete Datei, nicht den base64 speichern + If oProperty.ItemType = 3 Then + 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