2 Commits

Author SHA1 Message Date
Developer01
e9427b35be ViewDocument before GDPicture Update 2025-09-17 14:05:04 +02:00
Developer01
51798a28f5 ViewDocument xrechnung 2025-09-17 10:38:54 +02:00

View File

@@ -17,8 +17,6 @@ Public Class XRechnungViewDocument
Private fontResName As String Private fontResName As String
Private fontResNameBold As String Private fontResNameBold As String
Private fontResNameItalic As String Private fontResNameItalic As String
Private MyGDPicturePDF As GdPicturePDF
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, GDPictureLicenseKey As String) Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, GDPictureLicenseKey As String)
_logConfig = LogConfig _logConfig = LogConfig
_logger = LogConfig.GetLogger() _logger = LogConfig.GetLogger()
@@ -45,13 +43,30 @@ Public Class XRechnungViewDocument
File.Delete(oTempFilePath) File.Delete(oTempFilePath)
End If End If
_logger.Debug("Vor MOVE... oxmlFilePath: [{0}] / oTempFilePath: [{1}]", oXmlFilePath, oTempFilePath)
File.Move(oXmlFilePath, oTempFilePath)
pXmlFile = New FileInfo(oTempFilePath) pXmlFile = New FileInfo(oTempFilePath)
'oViewRecieptFilename = oViewRecieptFilename.Replace(".xml", ".pdf") 'oViewRecieptFilename = oViewRecieptFilename.Replace(".xml", ".pdf")
oViewRecieptFilename = Regex.Replace(oViewRecieptFilename, ".xml", ".pdf", RegexOptions.IgnoreCase) oViewRecieptFilename = Regex.Replace(oViewRecieptFilename, ".xml", ".pdf", RegexOptions.IgnoreCase)
Using gdpicturePDF As New GdPicturePDF()
' Create a new PDF/A-2a compliant document (blank, no pages yet)
Dim status As GdPictureStatus = gdpicturePDF.NewPDF(PdfConformance.PDF_A_2a)
If status = GdPictureStatus.OK Then
Else
MsgBox("The NewPDF(PdfConformance.PDF_A_2a) method has failed with the status: " + status.ToString(), "Example: NewPDF")
End If
End Using
Dim MyGDPicturePDF = New GdPicturePDF()
Dim oPDFStatus As GdPictureStatus = MyGDPicturePDF.NewPDF(PdfConformance.PDF_A_2a)
If oPDFStatus <> GdPictureStatus.OK Then
_logger.Warn($"Error initializing PDF: {oPDFStatus}")
Return Nothing
End If
Dim oOutputPath = Path.Combine(Path.GetDirectoryName(oXmlFilePath), oViewRecieptFilename) Dim oOutputPath = Path.Combine(Path.GetDirectoryName(oXmlFilePath), oViewRecieptFilename)
_logger.Debug("Create_PDFfromXML() Resulting PDF Filepath: [{0}]", oOutputPath) _logger.Debug("Create_PDFfromXML() Resulting PDF Filepath: [{0}]", oOutputPath)
@@ -59,13 +74,10 @@ Public Class XRechnungViewDocument
File.Delete(oOutputPath) File.Delete(oOutputPath)
End If End If
MyGDPicturePDF = New GdPicturePDF() _logger.Debug("Vor MOVE... oxmlFilePath: [{0}] / oTempFilePath: [{1}]", oXmlFilePath, oTempFilePath)
MyGDPicturePDF.NewPDF(PdfConformance.PDF_A_2a)
Dim oPDFStatus As GdPictureStatus = MyGDPicturePDF.NewPDF() File.Move(oXmlFilePath, oTempFilePath)
If oPDFStatus <> GdPictureStatus.OK Then Dim oCreatedString = $"Maschinell erstellt durch / Automatically created by Digital Data E-Rechnung Parser: {Now.ToString}"
_logger.Warn($"Error initializing PDF: {oPDFStatus}")
Return Nothing
End If
MyGDPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft) MyGDPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
MyGDPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter) MyGDPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
MyGDPicturePDF.SetLineWidth(1) MyGDPicturePDF.SetLineWidth(1)
@@ -77,9 +89,23 @@ Public Class XRechnungViewDocument
'Create a New page 'Create a New page
MyGDPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) MyGDPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4)
' Dim oCurrent As Integer = MyGDPicturePDF.GetCurrentPage() ' Dim oCurrent As Integer = MyGDPicturePDF.GetCurrentPage()
'Den HEader erzeugen
Dim yPosition As Integer = 15
MyGDPicturePDF.SetTextSize(18)
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "xRechnung Sichtbeleg - xInvoice Visual Receipt")
yPosition += 10
MyGDPicturePDF.SetTextSize(10)
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_DE_Row1)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_DE_Row2)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_EN_Row1)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_EN_Row2)
'Den Footer erzeugen
MyGDPicturePDF.DrawLine(10, 280, 200, 280)
Dim yPosition As Single = Create_PageHeader(False) MyGDPicturePDF.DrawText(fontResName, 10, 285, oCreatedString)
Create_PageFooter()
Dim oArea As String = "" Dim oArea As String = ""
Dim oIsPosition As Boolean = False Dim oIsPosition As Boolean = False
@@ -114,8 +140,23 @@ Public Class XRechnungViewDocument
_logger.Warn($"Could not create a second page. The error was: {oPDFStatus}") _logger.Warn($"Could not create a second page. The error was: {oPDFStatus}")
Exit For Exit For
Else Else
yPosition = Create_PageHeader(True) 'Wieder einen Header und Footer erzeugen
Create_PageFooter() yPosition = 15
MyGDPicturePDF.SetTextSize(18)
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "xRechnung Sichtbeleg - xInvoice Visual Receipt")
yPosition += 10
MyGDPicturePDF.SetTextSize(10)
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_DE_Row1)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_DE_Row2)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_EN_Row1)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_EN_Row2)
MyGDPicturePDF.DrawLine(10, 280, 200, 280)
'Footer erzeugen
MyGDPicturePDF.DrawText(fontResName, 10, 285, oCreatedString)
End If End If
'oCurrent = MyGDPicturePDF.GetCurrentPage() 'oCurrent = MyGDPicturePDF.GetCurrentPage()
End If End If
@@ -145,6 +186,7 @@ Public Class XRechnungViewDocument
oIsPosition = True oIsPosition = True
ElseIf oArea = "ALLOWANCE" Then ElseIf oArea = "ALLOWANCE" Then
oAREACaption = "Zu- oder Abschlag/Surcharge or Discount:" oAREACaption = "Zu- oder Abschlag/Surcharge or Discount:"
oIsPosition = True
ElseIf oArea = "AMOUNT" Then ElseIf oArea = "AMOUNT" Then
oAREACaption = "Beträge / Amounts:" oAREACaption = "Beträge / Amounts:"
oCreateTextBox = True oCreateTextBox = True
@@ -173,15 +215,19 @@ Public Class XRechnungViewDocument
' gdpicturePDF.DrawText(fontResName, 10, yPosition, XRechnungStrings.Seperator_Line) ' gdpicturePDF.DrawText(fontResName, 10, yPosition, XRechnungStrings.Seperator_Line)
yPosition += 5 yPosition += 5
ElseIf oArea = "POSITION" Then ElseIf oArea = "POSITION" Then
'Tabellendarstellung
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "Pos#") MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "Pos#")
MyGDPicturePDF.DrawText(fontResName, 19, yPosition, "Anz./am.") MyGDPicturePDF.DrawText(fontResName, 19, yPosition, "Anz./am.")
MyGDPicturePDF.DrawText(fontResName, 35, yPosition, "Einh/unt") MyGDPicturePDF.DrawText(fontResName, 35, yPosition, "Einh/Unit")
MyGDPicturePDF.DrawText(fontResName, 50, yPosition, "Pos.Text") MyGDPicturePDF.DrawText(fontResName, 50, yPosition, "Pos.Text")
MyGDPicturePDF.DrawText(fontResName, 164, yPosition, "Steuer/tax") MyGDPicturePDF.DrawText(fontResName, 164, yPosition, "Steuer/Tax")
MyGDPicturePDF.DrawText(fontResName, 181, yPosition, "Betrag/sum") MyGDPicturePDF.DrawText(fontResName, 181, yPosition, "Betrag/Sum")
yPosition += 5 yPosition += 5
'Tabellendarstellung Ende ElseIf oArea = "ALLOWANCE" Then
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "Pos#")
MyGDPicturePDF.DrawText(fontResName, 19, yPosition, "Grund/Reason")
MyGDPicturePDF.DrawText(fontResName, 164, yPosition, "Steuer/Tax")
MyGDPicturePDF.DrawText(fontResName, 181, yPosition, "Betrag/Sum")
oPosCount = 0
ElseIf oArea = "EXEMPTION" Then ElseIf oArea = "EXEMPTION" Then
End If End If
@@ -196,9 +242,6 @@ Public Class XRechnungViewDocument
oIsPosition = True oIsPosition = True
If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then
oPosCount += 1 oPosCount += 1
'oPosTerm = $"{oPosCount}. {oItemValue} * "
'oItemValue = oPosTerm
'Tabellendarstellung
oPosTerm = "" oPosTerm = ""
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount) MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount)
' '
@@ -211,6 +254,20 @@ Public Class XRechnungViewDocument
oDisplay = False oDisplay = False
' yPosition -= 5 ' yPosition -= 5
End If End If
ElseIf oArea = "ALLOWANCE" Then
oIsPosition = True
If oItemSPECNAME = "RECEIPT_ALLOWANCE_REASON" Then
oPosCount += 1
oPosTerm = ""
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount)
'
'Dim otextBoxYPos As Integer = yPosition - 3.5
'MyGDPicturePDF.DrawTextBox(fontResName, 10, otextBoxYPos, 16, YCoo_TextBoxPlus5(otextBoxYPos),
' TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear,
' oPosCount)
MyGDPicturePDF.DrawText(fontResName, 19, yPosition, oItemValue)
oDisplay = False
End If
ElseIf oArea = "TAXPOS" Then ElseIf oArea = "TAXPOS" Then
oIsPosition = True oIsPosition = True
If oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then If oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then
@@ -226,20 +283,29 @@ Public Class XRechnungViewDocument
'INDIVIDUELLES VERHALTEN BEI Folge-ITEMS 'INDIVIDUELLES VERHALTEN BEI Folge-ITEMS
_logger.Debug($"FollowItem - Area: [{oArea}] - ItemSpecname: [{oItemSPECNAME}] - ItemValue: [{oItemValue}]") _logger.Debug($"FollowItem - Area: [{oArea}] - ItemSpecname: [{oItemSPECNAME}] - ItemValue: [{oItemValue}]")
'Dim otextBoxYPos As Integer 'Dim otextBoxYPos As Integer
If oArea = "POSITION" Then If oArea = "POSITION" Or oArea = "ALLOWANCE" Then
If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Or oItemSPECNAME = "RECEIPT_ALLOWANCE_REASON" Then
oPosCount += 1 oPosCount += 1
oYPlus = 0 oYPlus = 0
'Tabellendarstellung
yPosition += 5 yPosition += 5
oPosTerm = "" oPosTerm = ""
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount) MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount)
'otextBoxYPos = yPosition - 3.5 If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then
'MyGDPicturePDF.DrawTextBox(fontResName, 10, otextBoxYPos, 16, YCoo_TextBoxPlus5(otextBoxYPos), MyGDPicturePDF.DrawText(fontResName, 19, yPosition, oItemValue)
' TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear, Else
' oPosCount) Dim oYDyn As Integer = yPosition - 5
MyGDPicturePDF.DrawText(fontResName, 19, yPosition, oItemValue) Dim oPartsNL As List(Of String) = StringFunctions.SplitTextByNewLine(oItemValue)
'Tabellendarstellung Ende For Each olinepart As String In oPartsNL
Dim oParts As List(Of String) = StringFunctions.SplitText_Length(olinepart, 67)
' Durchlaufen der einzelnen Teile in einer Schleife
For Each part As String In oParts
oYDyn += 5
oYPlus += 5
MyGDPicturePDF.DrawText(fontResName, 19, oYDyn, part)
Next
Next
End If
oDisplay = False oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_POSITION_UNIT_TYPE" Then ElseIf oItemSPECNAME = "INVOICE_POSITION_UNIT_TYPE" Then
oYPlus = 0 oYPlus = 0
@@ -262,8 +328,6 @@ Public Class XRechnungViewDocument
MyGDPicturePDF.DrawText(fontResName, 50, oYDyn, part) MyGDPicturePDF.DrawText(fontResName, 50, oYDyn, part)
Next Next
Next Next
'Tabellendarstellung Ende
' oPosTerm += $" {oItemValue}"
oDisplay = False oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_POSITION_NOTE" Then ElseIf oItemSPECNAME = "INVOICE_POSITION_NOTE" Then
'Tabellendarstellung 'Tabellendarstellung
@@ -303,24 +367,19 @@ Public Class XRechnungViewDocument
'oPosTerm += $" {oItemValue}" 'oPosTerm += $" {oItemValue}"
oDisplay = False oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_TAXPOS_TAX_RATE" Or oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then ElseIf oItemSPECNAME = "INVOICE_TAXPOS_TAX_RATE" Or oItemSPECNAME = "INVOICE_TAXPOS_RATE" Or oItemSPECNAME = "RECEIPT_ALLOWANCE_VAT_RATE" Then
'Tabellendarstellung
MyGDPicturePDF.DrawText(fontResName, 164, yPosition, $"{oItemValue} %") MyGDPicturePDF.DrawText(fontResName, 164, yPosition, $"{oItemValue} %")
'Tabellendarstellung ENDE
' oPosTerm += $" - {oItemValue} %"
oDisplay = False oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_POSITION_TAX_AMOUNT" Then ElseIf oItemSPECNAME = "INVOICE_POSITION_TAX_AMOUNT" Or oItemSPECNAME = "RECEIPT_ALLOWANCE_ACTUAL_AMOUNT" Then
'Tabellendarstellung
Dim oYPos = yPosition - 3.5 Dim oYPos = yPosition - 3.5
Dim TAXTERM = FormatCurrency(oItemValue, oCurrencySymbol) Dim TAXTERM = FormatCurrency(oItemValue, oCurrencySymbol)
MyGDPicturePDF.DrawTextBox(fontResName, 177, oYPos, 198, YCoo_TextBoxPlus5(oYPos), MyGDPicturePDF.DrawTextBox(fontResName, 177, oYPos, 198, YCoo_TextBoxPlus5(oYPos),
TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear,
TAXTERM) TAXTERM)
' MyGDPicturePDF.DrawText(fontResName, 180, yPosition, $"{oItemValue} {oCurrencySymbol}")
'Tabellendarstellung Ende
End If End If
oItemValue = oPosTerm oItemValue = oPosTerm
ElseIf oArea = "HEAD" Then ElseIf oArea = "HEAD" Then
If oItemSPECNAME = "INVOICE_DATE" Or oItemSPECNAME = "INVOICE_SERVICE_DATE" Then If oItemSPECNAME = "INVOICE_DATE" Or oItemSPECNAME = "INVOICE_SERVICE_DATE" Then
oItemValue = StringFunctions.DatetimeStringToGermanStringConverter(oItemValue, _logger) oItemValue = StringFunctions.DatetimeStringToGermanStringConverter(oItemValue, _logger)
@@ -413,6 +472,7 @@ Public Class XRechnungViewDocument
_logger.Info("PDF VisualReceipt generated successfully!") _logger.Info("PDF VisualReceipt generated successfully!")
Else Else
_logger.Warn($"Error generating PDF VisualReceipt: {oPDFStatus}") _logger.Warn($"Error generating PDF VisualReceipt: {oPDFStatus}")
File.Move(oTempFilePath, oXmlFilePath)
End If End If
'Release resources 'Release resources
@@ -421,10 +481,10 @@ Public Class XRechnungViewDocument
File.Delete(oXRechnungFile) File.Delete(oXRechnungFile)
oNewFileinfo = New FileInfo(oOutputPath) oNewFileinfo = New FileInfo(oOutputPath)
_logger.Debug("Create_PDFfromXML() End successfully. File [{0}] written.", oNewFileinfo.FullName) _logger.Info("Create_PDFfromXML() End successfully. File [{0}] written.", oNewFileinfo.FullName)
Return oNewFileinfo Return oNewFileinfo
Else Else
_logger.Debug("Create_PDFfromXML() Ends with nothing") _logger.Warn("Create_PDFfromXML() Ends with nothing")
Return Nothing Return Nothing
End If End If
@@ -434,7 +494,7 @@ Public Class XRechnungViewDocument
End Try End Try
End Function End Function
Private Function FormatCurrency(ByVal pValue As String, pCurrencySymbol As String) As String Private Function FormatCurrency(ByVal pValue As String, pCurrencySymbol As String) As String
pValue = pValue.replace(".", ",") pValue = pValue.Replace(".", ",")
Dim oBetrag As Decimal = pValue Dim oBetrag As Decimal = pValue
Dim oFormatiert As String = oBetrag.ToString("N2", New Globalization.CultureInfo("de-DE")) Dim oFormatiert As String = oBetrag.ToString("N2", New Globalization.CultureInfo("de-DE"))
oFormatiert = $"{oFormatiert} {pCurrencySymbol}" oFormatiert = $"{oFormatiert} {pCurrencySymbol}"
@@ -463,29 +523,6 @@ Public Class XRechnungViewDocument
Dim lines As List(Of String) = text.Split({vbCrLf, vbLf, vbCr}, StringSplitOptions.None).ToList() Dim lines As List(Of String) = text.Split({vbCrLf, vbLf, vbCr}, StringSplitOptions.None).ToList()
Return lines Return lines
End Function End Function
Public Function Create_PageHeader(pFollowPage As Boolean) As Integer
'Draw content on the PDF
Dim yPosition As Integer = 15
MyGDPicturePDF.SetTextSize(18)
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "xRechnung Sichtbeleg - xInvoice Visual Receipt")
yPosition += 10
MyGDPicturePDF.SetTextSize(10)
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_DE_Row1)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_DE_Row2)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_EN_Row1)
yPosition += 5
MyGDPicturePDF.DrawText(fontResNameItalic, 10, yPosition, XRechnungStrings.CommentSichtbeleg_EN_Row2)
Return yPosition
End Function
Public Sub Create_PageFooter()
MyGDPicturePDF.DrawLine(10, 280, 200, 280)
Dim oCreatedString = $"Maschinell erstellt durch / Automatically created by Digital Data E-Rechnung Parser: {Now.ToString}"
MyGDPicturePDF.DrawText(fontResName, 10, 285, oCreatedString)
End Sub
Private Function Return_InvType(pType As String) As String Private Function Return_InvType(pType As String) As String
Dim oReturn As String = "Rechnung/invoice" Dim oReturn As String = "Rechnung/invoice"
If pType = "380" Then If pType = "380" Then