diff --git a/Interfaces/My Project/AssemblyInfo.vb b/Interfaces/My Project/AssemblyInfo.vb index 2900e333..b9c75128 100644 --- a/Interfaces/My Project/AssemblyInfo.vb +++ b/Interfaces/My Project/AssemblyInfo.vb @@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices - + @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - - + + diff --git a/Interfaces/ZUGFeRDInterface.vb b/Interfaces/ZUGFeRDInterface.vb index 9af7367f..4bea907a 100644 --- a/Interfaces/ZUGFeRDInterface.vb +++ b/Interfaces/ZUGFeRDInterface.vb @@ -209,10 +209,9 @@ Public Class ZUGFeRDInterface Catch ex As Exception _logger.Error(ex) End Try - Else - Return Nothing End If + Return Nothing End Function Public Function GetSerializedXMLContentFromFile(oFileInfo As FileInfo) As ZugferdResult diff --git a/Interfaces/ZUGFeRDInterface/PropertyValues.vb b/Interfaces/ZUGFeRDInterface/PropertyValues.vb index 7b2426c9..a7a11d4e 100644 --- a/Interfaces/ZUGFeRDInterface/PropertyValues.vb +++ b/Interfaces/ZUGFeRDInterface/PropertyValues.vb @@ -3,6 +3,7 @@ Imports System.Reflection Imports System.Text.RegularExpressions Imports System.Xml Imports DigitalData.Modules.Logging +Imports GdPicture.Internal.MSOfficeBinary.translator.Spreadsheet.XlsFileFormat.Records Imports GdPicture.Internal.MSOfficeBinary.translator.Tools Public Class PropertyValues @@ -225,9 +226,15 @@ 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", oTableColumn) + _logger.Warn("Item [{0}] may be configured incorrectly", oTableColumn) oPropertyValue = Nothing End If + + If IsComplexeObject(oPropertyValue) = True Then + _logger.Debug("Item Value [{0}] is complexe. cant be used.", oTableColumn) + oPropertyValue = Nothing + End If + End Select End If Catch ex As Exception @@ -593,8 +600,21 @@ Public Class PropertyValues firstElement = oList.FirstOrDefault() If firstElement IsNot Nothing AndAlso IsArray(firstElement) Then - ' Attachments sind Byte-Arrays und müssen umgewandelt werden - Return Convert.ToBase64String(firstElement) + Dim oStr As String + ' Array behandeln -> erstes Element nehmen + If TypeOf firstElement Is String() Then + Dim arr As String() = CType(firstElement, String()) + oStr = If(arr.Length > 0, arr(0), String.Empty) + Else + oStr = firstElement.ToString() + End If + + If IsBase64String(oStr) Then + ' Attachments sind Byte-Arrays und müssen umgewandelt werden + Return Convert.ToBase64String(firstElement) + Else + Return oStr + End If Else Return DoGetFinalPropValue(oList.First()) @@ -636,4 +656,40 @@ Public Class PropertyValues Return Regex.IsMatch(Prop, _indexPattern) End Function + Private Function IsComplexeObject(obj As Object) As Boolean + If obj Is Nothing Then Return False + + Dim t As Type = obj.GetType() + + ' Einfache Typen ausschließen + If t.IsPrimitive OrElse + t.IsEnum OrElse + t Is GetType(String) OrElse + t Is GetType(Decimal) OrElse + t Is GetType(DateTime) Then + Return False + End If + + ' Wenn es öffentliche Properties hat, ist es "komplex" + Return t.GetProperties().Length > 0 OrElse t.IsClass + End Function + + Function IsBase64String(str As String) As Boolean + If String.IsNullOrEmpty(str) Then Return False + + ' Base64 hat bestimmte Zeichen und meist Länge Vielfaches von 4 + If str.Length Mod 4 <> 0 Then Return False + + ' Regex-Check für gültige Base64-Zeichen + If Not System.Text.RegularExpressions.Regex.IsMatch(str, "^[A-Za-z0-9+/]*={0,2}$") Then + Return False + End If + + Try + Dim bytes As Byte() = Convert.FromBase64String(str) + Return True + Catch ex As FormatException + Return False + End Try + End Function End Class diff --git a/Jobs/My Project/AssemblyInfo.vb b/Jobs/My Project/AssemblyInfo.vb index 7053521d..2572b52b 100644 --- a/Jobs/My Project/AssemblyInfo.vb +++ b/Jobs/My Project/AssemblyInfo.vb @@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices - + @@ -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: - - + + diff --git a/Jobs/ZUGFeRD/EmailFunctions.vb b/Jobs/ZUGFeRD/EmailFunctions.vb index 20c6a24d..f3166e99 100644 --- a/Jobs/ZUGFeRD/EmailFunctions.vb +++ b/Jobs/ZUGFeRD/EmailFunctions.vb @@ -137,7 +137,11 @@ Namespace ZUGFeRD , '{pParameter2}' , 77" - _mssql.ExecuteNonQuery(oExecute, pTransaction) + If pTransaction IsNot Nothing Then + _mssql.ExecuteNonQuery(oExecute, pTransaction) + Else + _mssql.ExecuteNonQuery(oExecute) + End If Catch ex As Exception _logger.Error(ex) diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index d70831d7..60303973 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -68,6 +68,7 @@ Public Class ImportZUGFeRDFiles Private ReadOnly _embeds As PDFEmbeds Private SQL_xRechnung_ItemTemplate As String = "" + Private SQL_ebInterface_CompleteXMLItems As String = "" Private ReadOnly _gdpictureLicenseKey As String Private ReadOnly _xRechnungCreator As XRechnungViewDocument @@ -81,6 +82,8 @@ Public Class ImportZUGFeRDFiles Public ZugferdFileCount As Integer = 0 Public MD5Checksum As String = Nothing + Public XMLSpecification As String = Nothing + Public XMLSchema As String = Nothing Public EmailAttachmentFiles As New List(Of FileInfo) Public EmbeddedAttachmentFiles As New List(Of PDFEmbeds.EmbeddedFile) @@ -114,6 +117,7 @@ Public Class ImportZUGFeRDFiles Public Sub Start(Arguments As Object) Implements IJob.Start Dim oArgs As WorkerArgs = Arguments Dim oAttachmentExtractor = New PDFEmbeds(_logConfig) + Dim oSpecification As String = String.Empty _EmailOutAccountId = oArgs.EmailOutProfileId @@ -125,12 +129,16 @@ Public Class ImportZUGFeRDFiles }) _logger.Debug("Starting Job {0}", [GetType].Name) - If oArgs.AllowXRechnung Then - ' TODO - Config-Schalter hat NIX mit XRechnung-Dateien u. Sichtbelegen zu tun, sondern nur mit Dateinamen zu tun. + If oArgs.AllowXRechnung Or oArgs.AllowPeppolBISBill3x Or oArgs.AllowEBInterface Then Dim oSQL = "SELECT SQL_COMMAND FROM TBDD_SQL_COMMANDS WITH (NOLOCK) WHERE TITLE = 'VWDD_ZUGFERD_VIEW_RECEIPT_TEMPLATE_ITEMS'" SQL_xRechnung_ItemTemplate = _mssql.GetScalarValue(oSQL) End If + If oArgs.AllowEBInterface Then + Dim oSQL = "SELECT SQL_COMMAND FROM TBDD_SQL_COMMANDS WITH (NOLOCK) WHERE TITLE = 'EBINTERFACE_COMPLETE_MISSING_XML_ITEMS'" + SQL_ebInterface_CompleteXMLItems = _mssql.GetScalarValue(oSQL) + End If + Try 'For Each oPath As String In oArgs.WatchDirectory Dim oPath As String = oArgs.WatchDirectory @@ -209,6 +217,7 @@ Public Class ImportZUGFeRDFiles Try For Each oFile In oEInvoiceFileGroup + oSpecification = String.Empty oFileCounter += 1 Dim oResult As ProcessFileResult @@ -222,6 +231,7 @@ Public Class ImportZUGFeRDFiles _logger.Debug("eInvoice File found") oMD5CheckSum = oResult.MD5Checksum oZUGFeRDCount = oResult.ZugferdFileCount + oSpecification = oResult.XMLSpecification oEmailAttachmentFiles.AddRange(oResult.EmailAttachmentFiles) oEmbeddedAttachmentFiles.AddRange(oResult.EmbeddedAttachmentFiles) Else ' No zugferd found! @@ -440,21 +450,34 @@ Public Class ImportZUGFeRDFiles If oMoveDirectory = DIRECTORY_DONT_MOVE Then _logger.Info("Application Error occurred. Files for message Id {0} will not be moved.", oMessageId) - ElseIf oArgs.AllowXRechnung And oIsSuccess And + ElseIf (oArgs.AllowXRechnung Or oArgs.AllowPeppolBISBill3x Or oArgs.AllowEBInterface) And oIsSuccess And oEInvoiceFileGroup.Item(0).Extension.Equals(".xml", StringComparison.OrdinalIgnoreCase) = True Then _logger.Debug("Before Creating the PDF-File from XML data / Before Commit") oxRechnungHandle = True + + If oSQLTransaction IsNot Nothing Then + ' Commit Transaction - muss ausgeführt werden, sonst sind keine Daten in der DB vorhanden + oSQLTransaction.Commit() + _logger.Debug("XML commit triggered") + End If + + ' Vor der Sichtbeleg-Erzeugung, müssen ggf Daten nachberechnet werden. + ' Hier wird die Prozedur für EBINTERFACE_61 aufgerufen, falls der Beleg dieses Schema verwendet + If oArgs.AllowEBInterface AndAlso + String.Equals(oSpecification, "EBINTERFACE_61", StringComparison.InvariantCultureIgnoreCase) AndAlso + Not String.IsNullOrEmpty(SQL_ebInterface_CompleteXMLItems) Then + _logger.Debug("Before Calling ebInterface Procedure") + Dim oSQL_MsgIDReplace_1 As String = SQL_ebInterface_CompleteXMLItems.Replace("@MSG_ID", oFileGroup.Key) + Dim oSqlResult = _mssql.ExecuteNonQuery(oSQL_MsgIDReplace_1) + _logger.Debug("Result of ebInterface Procedure: [{0}]", oSqlResult) + End If + ' Hier das neue PDF erzeugen 'but before we need to get all Data we need MyTemplateValues_xInvDT = Nothing Dim oSQL_MsgIDReplace = SQL_xRechnung_ItemTemplate oSQL_MsgIDReplace = oSQL_MsgIDReplace.Replace("@MSG_ID", oFileGroup.Key) - If oSQLTransaction IsNot Nothing Then - ' Commit Transaction - oSQLTransaction.Commit() - _logger.Debug("XML commit triggered") - End If MyTemplateValues_xInvDT = _mssql.GetDatatable(oSQL_MsgIDReplace) If Not IsNothing(MyTemplateValues_xInvDT) Then @@ -598,6 +621,8 @@ Public Class ImportZUGFeRDFiles If oDocument IsNot Nothing Then sqlResult = StoreXMLItemsInDatabase(pMessageId, oDocument, pFile, pConnections, pArgs, oResult) + oResult.XMLSpecification = oDocument.Specification + oResult.XMLSchema = oDocument.UsedXMLSchema End If Catch ex As Exception