Zugferd, etc.

This commit is contained in:
2026-04-28 17:11:48 +02:00
parent 77370be55d
commit 674532460a
5 changed files with 709 additions and 321 deletions

View File

@@ -5,11 +5,13 @@ Imports VERAG_PROG_ALLGEMEIN
Public Class frmKundenUebersichtZollRgDetails
Dim RK_ID As Integer = -1
Dim Sammelrechnung As Integer = -1
Dim SQL As New SQL
Dim sammelrechnungskopie As Boolean
Dim filialeTmp As String
Dim abfertigungsNrTmp As String
Dim ZugferdDaId As Integer = -1
Sub New(RK_ID)
' Dieser Aufruf ist für den Designer erforderlich.
@@ -28,7 +30,9 @@ Public Class frmKundenUebersichtZollRgDetails
End Sub
Private Sub frmKundenUebersichtZollRg_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dt As DataRow = SQL.loadDgvBySql("SELECT *, /*[SteuerpflichtigerGesamtbetrag]*[Steuersatz %]*/ SteuerpflichtigerGesamtbetrag/(1+[Steuersatz %])*[Steuersatz %] as ErgSteuerbetrag , [SteuerpflichtigerGesamtbetrag]+[SteuerfreierGesamtbetrag] as RgBetrag FROM Rechnungsausgang WHERE RK_ID = " & RK_ID & "", "FMZOLL").Rows(0)
Dim dt As DataRow = SQL.loadDgvBySql("SELECT *, /*[SteuerpflichtigerGesamtbetrag]*[Steuersatz %]*/ SteuerpflichtigerGesamtbetrag/(1+[Steuersatz %])*[Steuersatz %] as ErgSteuerbetrag , [SteuerpflichtigerGesamtbetrag]+[SteuerfreierGesamtbetrag] as RgBetrag,cast(isnull(zugferdcheck,0) as Bit) as zugferdcheck, isnull(zugferdcheck_daid, -1) as zugferdcheck_daid FROM Rechnungsausgang WHERE RK_ID = " & RK_ID & "", "FMZOLL").Rows(0)
lblRgNr.Text = dt("RechnungsNr").ToString
lblRgBetrag.Text = CDbl(dt("RgBetrag")).ToString("N2", CultureInfo.CurrentCulture)
@@ -49,7 +53,31 @@ Public Class frmKundenUebersichtZollRgDetails
lblBelegartNr.Text = dt("BelegartenNr").ToString
lblWaerung.Text = dt("Währungscode").ToString
If Not IsDBNull(dt("zugferdcheck")) Then
If dt("zugferdcheck") Then
btnZugferd.BackColor = Color.LightGreen
If IsNumeric(dt("zugferdcheck_daid")) Then ZugferdDaId = dt("zugferdcheck_daid")
Else
If IsNumeric(dt("zugferdcheck_daid")) Then ZugferdDaId = dt("zugferdcheck_daid")
btnZugferd.BackColor = Color.IndianRed
End If
Else
btnZugferd.BackColor = Color.White
End If
Sammelrechnung = CInt(dt("Sammelrechnung").ToString)
If RK_ID > 0 Then initDGV()
If Environment.MachineName = "H6CCWP3" Then
Button2.Visible = True
Else
Button2.Visible = False
End If
End Sub
Sub initDGV()
@@ -109,7 +137,34 @@ Public Class frmKundenUebersichtZollRgDetails
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cFakturierung.doRechnungsDruck_SRorER(RK_ID,, False, 3,,,,, sammelrechnungskopie)
If RK_ID > 0 Then
Dim RE As New cRechnungsausgang(RK_ID)
If RE.dsId > 0 Then
Dim RE_PDF As New cDATENSERVER(RE.dsId)
Dim tmpPath = RE_PDF.GET_TOP1_PATH
If tmpPath <> "" Then
Process.Start(tmpPath)
End If
Else
Dim SRAnhangen As Boolean = False
If Sammelrechnung <> 0 Then
If vbYes = MsgBox("Soll die Sammelrechnung mit Anlagen angezeigt werden?", vbYesNoCancel) Then SRAnhangen = True
End If
cFakturierung.doRechnungsDruck_SRorER(RK_ID,, False, 3,,,,, sammelrechnungskopie,, SRAnhangen)
End If
End If
End Sub
Public Shared Function ConvertToPdfA3_WithMustang(inputPdf As String) As String
@@ -141,168 +196,73 @@ Public Class frmKundenUebersichtZollRgDetails
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnZugferd.Click
If ZugferdDaId > 0 Then
Dim ZUG As New cDATENSERVER(ZugferdDaId)
Dim tmpPath_Report = ZUG.GET_TOP1_PATH
If tmpPath_Report <> "" Then
Process.Start(tmpPath_Report)
End If
Else
End If
End Sub
Private Sub PictureBox5_Click(sender As Object, e As EventArgs) Handles PictureBox5.Click
Dim webAddress As String = "https://wiki.verag.ag/de/software/aviso/howtos/E-Rechnung"
Process.Start(webAddress)
End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
Dim Path_temp As String = ""
cFakturierung.doRechnungsDruck_SRorER(RK_ID,, False, 3, Path_temp,,,, sammelrechnungskopie)
If Sammelrechnung = 0 Then
cFakturierung.doRechnungsDruck_SRorER(RK_ID,, False, 3, Path_temp,,,, sammelrechnungskopie,, False)
Else
cFakturierung.doRechnungsDruck_SRorER(RK_ID,, False, 3, Path_temp,,,, sammelrechnungskopie,, False)
End If
If Path_temp <> "" Then
Try
'ConvertToPdfA3_WithMustang(Path_temp)
Dim psi As New ProcessStartInfo()
Dim psi As New ProcessStartInfo()
psi.FileName = "C:\Program Files\Eclipse Adoptium\jre-11.0.28.6-hotspot\bin\java.exe"
psi.Arguments = "-jar ""C:\Users\d.breimaier\Downloads\Mustang-CLI-2.21.0.jar"" --no-notices --action validate --source " & Path_temp & ""
psi.FileName = "C:\Program Files\Eclipse Adoptium\jre-11.0.28.6-hotspot\bin\java.exe"
psi.Arguments = "-jar ""C:\Users\d.breimaier\Downloads\Mustang-CLI-2.21.0.jar"" --no-notices --action validate --source " & Path_temp & ""
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.UseShellExecute = False
psi.CreateNoWindow = True
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.UseShellExecute = False
psi.CreateNoWindow = True
Using p As Process = Process.Start(psi)
Dim output = p.StandardOutput.ReadToEnd()
Dim err = p.StandardError.ReadToEnd()
p.WaitForExit()
Using p As Process = Process.Start(psi)
Dim output = p.StandardOutput.ReadToEnd()
Dim err = p.StandardError.ReadToEnd()
p.WaitForExit()
Console.WriteLine("ExitCode: " & p.ExitCode)
Console.WriteLine(output)
Console.WriteLine(err)
Console.WriteLine("ExitCode: " & p.ExitCode)
Console.WriteLine(output)
Console.WriteLine(err)
If output <> "" Then
Dim tmpPath_Report = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("MUSTANG-REPORT", ".pdf", , False)
CreateValidationPdf(output, Path_temp, RK_ID, tmpPath_Report)
If tmpPath_Report <> "" Then Process.Start(tmpPath_Report)
End If
If output <> "" Then
Dim tmpPath_Report = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("MUSTANG-REPORT", ".pdf", , False)
VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.CreateValidationPdf(output, Path_temp, RK_ID, tmpPath_Report)
If tmpPath_Report <> "" Then Process.Start(tmpPath_Report)
End If
End Using
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End If
End Sub
Private Function ExtractMustangResult(xmlLog As String, invoiceFile As String, RK_ID As Integer) As String
Dim doc As New Xml.XmlDocument()
doc.LoadXml(xmlLog)
Dim fileInfo As New FileInfo(invoiceFile)
Dim invoice As New cRechnungsausgang(RK_ID)
' --- PDF Status ---
Dim pdfNode = doc.SelectSingleNode("//pdf/summary")
Dim pdfStatus As String = If(pdfNode?.Attributes("status")?.Value = "valid", "VALID", "INVALID")
' --- XML Status ---
Dim xmlNode = doc.SelectSingleNode("//xml/summary")
Dim xmlStatus As String = If(xmlNode?.Attributes("status")?.Value = "valid", "VALID", "INVALID")
' --- Profile ---
Dim profileNode = doc.SelectSingleNode("//xml/info/profile")
Dim profile As String = If(profileNode IsNot Nothing, profileNode.InnerText, "UNKNOWN")
' --- XML Version ---
Dim xmlVersionNode = doc.SelectSingleNode("//xml/info/version")
Dim xmlVersion As String = If(xmlVersionNode IsNot Nothing, xmlVersionNode.InnerText, "-")
' --- Validator Version ---
Dim validatorNode = doc.SelectSingleNode("//xml/info/validator")
Dim validatorVersion As String = validatorNode?.Attributes("version")?.Value
' --- Duration ---
Dim pdfDuration = doc.SelectSingleNode("//pdf/info/duration")?.InnerText
Dim xmlDuration = doc.SelectSingleNode("//xml/info/duration")?.InnerText
Dim duration As String = ""
If pdfDuration IsNot Nothing AndAlso xmlDuration IsNot Nothing Then
duration = $"{pdfDuration} ms (PDF) / {xmlDuration} ms (XML)"
End If
' --- Tests ---
Dim firedNode = doc.SelectSingleNode("//xml/info/rules/fired")
Dim failedNode = doc.SelectSingleNode("//xml/info/rules/failed")
Dim fired As Integer = If(firedNode IsNot Nothing, Integer.Parse(firedNode.InnerText), 0)
Dim failed As Integer = If(failedNode IsNot Nothing, Integer.Parse(failedNode.InnerText), 0)
Dim passed As Integer = fired - failed
' --- PDF Errors ---
Dim failedAssertions = doc.SelectNodes("//pdf//TestAssertion[@status='failed']")
Dim errorCount As Integer = If(failedAssertions IsNot Nothing, failedAssertions.Count, 0)
' --- Top Errors ---
Dim errorDetails As New List(Of String)
If failedAssertions IsNot Nothing Then
For i = 0 To Math.Min(2, failedAssertions.Count - 1)
Dim msg = failedAssertions(i).Attributes("message")?.Value
If msg IsNot Nothing Then errorDetails.Add("- " & msg)
Next
End If
' --- Output ---
Dim result As New Text.StringBuilder()
result.AppendLine("ZUGFeRD VALIDATION RESULT")
result.AppendLine("================================")
result.AppendLine($"PDF File : {fileInfo.Name}")
result.AppendLine($"Invoice No : {invoice.RechnungsNr}")
result.AppendLine("--------------------------------")
result.AppendLine($"PDF Status : {pdfStatus}")
result.AppendLine($"XML Status : {xmlStatus}")
result.AppendLine($"Profile : {profile}")
result.AppendLine($"XML Version : {xmlVersion}")
result.AppendLine($"Validator : {validatorVersion}")
result.AppendLine("--------------------------------")
result.AppendLine($"Tests Passed : {passed} / {fired}")
result.AppendLine($"XML Failed : {failed}")
result.AppendLine($"PDF Errors : {errorCount}")
result.AppendLine($"Duration : {duration}")
If errorDetails.Count > 0 Then
result.AppendLine("--------------------------------")
result.AppendLine("Top Errors:")
For Each err_ In errorDetails
result.AppendLine(err_)
Next
End If
result.AppendLine("================================")
Return result.ToString()
End Function
Public Sub CreateValidationPdf(log As String, Invoice_file As String, RK_ID As Integer, outputPath As String)
Dim resultText = ExtractMustangResult(log, Invoice_file, RK_ID)
Using fs As New FileStream(outputPath, FileMode.Create)
Using doc As New itextsharp.text.Document()
Dim writer = itextsharp.text.pdf.PdfWriter.GetInstance(doc, fs)
doc.Open()
Dim titleFont = itextsharp.text.FontFactory.GetFont("Arial", 14, itextsharp.text.Font.BOLD)
Dim bodyFont = itextsharp.text.FontFactory.GetFont("Arial", 10)
doc.Add(New itextsharp.text.Paragraph("ZUGFeRD VALIDATION REPORT", titleFont))
doc.Add(New itextsharp.text.Paragraph(" "))
Dim lines = resultText.Split(vbCrLf)
For Each line In lines
doc.Add(New itextsharp.text.Paragraph(line, bodyFont))
Next
doc.Close()
End Using
End Using
End If
End Sub
End Class