Diverses Zugferd
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
Imports System.Data
|
||||
Imports System.IO
|
||||
Imports System.Linq
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
@@ -225,6 +226,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
|
||||
Dim oFileGroupId As String = oFileGroup.Key
|
||||
Dim oMissingProperties As New List(Of String)
|
||||
Dim oMD5CheckSum As String
|
||||
|
||||
_logger.NewBlock($"Message Id {oFileGroupId}")
|
||||
_logger.Info("Start processing file group {0}", oFileGroupId)
|
||||
@@ -251,6 +253,23 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
||||
Continue For
|
||||
End Try
|
||||
oMD5CheckSum = checkMD5(oFile.FullName)
|
||||
If oMD5CheckSum <> "" Then
|
||||
Dim oCheckCommand = $"SELECT * FROM TBEDM_ZUGFERD_HISTORY_IN WHERE UPPER(MD5HASH) = UPPER('{oMD5CheckSum}')"
|
||||
Dim oMD5DT As DataTable = _firebird.GetDatatable(oCheckCommand, Firebird.TransactionMode.ExternalTransaction)
|
||||
If Not IsNothing(oMD5DT) Then
|
||||
If oMD5DT.Rows.Count = 1 Then
|
||||
'Hier muss noch gepüft werden ob die Rechnung schon mal abgelehnt wurde?!
|
||||
Throw New MD5HashException()
|
||||
End If
|
||||
Else
|
||||
_logger.Info("Be careful: oExistsDT is nothing!")
|
||||
End If
|
||||
Else
|
||||
_logger.Info("Be careful: oMD5CheckSum is nothing!")
|
||||
End If
|
||||
|
||||
|
||||
|
||||
' Check if there are more than one ZUGFeRD files
|
||||
If oZUGFeRDCount = 1 Then
|
||||
@@ -296,13 +315,27 @@ Public Class ImportZUGFeRDFiles
|
||||
End If
|
||||
Next
|
||||
|
||||
' Check if there are no ZUGFeRD files
|
||||
'Check if there are no ZUGFeRD files
|
||||
If oZUGFeRDCount = 0 Then
|
||||
Throw New NoFerdsException()
|
||||
End If
|
||||
|
||||
' If no errors occurred, commit the transaction
|
||||
'If no errors occurred...
|
||||
'Log the History
|
||||
If oMD5CheckSum <> "" Then
|
||||
Dim oInsertCommand = $"INSERT INTO TBEDM_ZUGFERD_HISTORY_IN (MESSAGE_ID, MD5HASH) VALUES ('{oFileGroupId}', '{oMD5CheckSum}')"
|
||||
_firebird.ExecuteNonQueryWithConnection(oInsertCommand, oConnection, Firebird.TransactionMode.ExternalTransaction, oTransaction)
|
||||
End If
|
||||
'commit the transaction
|
||||
oTransaction.Commit()
|
||||
Catch ex As MD5HashException
|
||||
_logger.Error(ex)
|
||||
|
||||
oMoveDirectory = args.ErrorDirectory
|
||||
|
||||
Dim oBody = "<p>The invoice attached to Your email has already been worked in our system.</p>"
|
||||
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||
Catch ex As TooMuchFerdsException
|
||||
_logger.Error(ex)
|
||||
|
||||
@@ -367,4 +400,24 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Return oBody
|
||||
End Function
|
||||
Private Function checkMD5(ByVal filename As String) As String
|
||||
Try
|
||||
Dim MD5 As New MD5CryptoServiceProvider
|
||||
Dim Hash As Byte()
|
||||
Dim Result As String = ""
|
||||
Dim Tmp As String = ""
|
||||
|
||||
Dim FN As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
|
||||
MD5.ComputeHash(FN)
|
||||
FN.Close()
|
||||
|
||||
Hash = MD5.Hash
|
||||
Result = Strings.Replace(BitConverter.ToString(Hash), "-", "")
|
||||
Return Result
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return ""
|
||||
End Try
|
||||
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@@ -28,4 +28,11 @@ Public Class Exceptions
|
||||
MyBase.New("No ZUGFeRD documents found")
|
||||
End Sub
|
||||
End Class
|
||||
Public Class MD5HashException
|
||||
Inherits ApplicationException
|
||||
|
||||
Public Sub New()
|
||||
MyBase.New("There is already an identical invoice")
|
||||
End Sub
|
||||
End Class
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user