ViewDocument xrechnung

This commit is contained in:
Developer01 2025-09-17 10:38:54 +02:00
parent 48406884ca
commit 51798a28f5

View File

@ -19,6 +19,7 @@ Public Class XRechnungViewDocument
Private fontResNameItalic As String Private fontResNameItalic As String
Private MyGDPicturePDF As GdPicturePDF 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,27 +46,31 @@ 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)
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)
If File.Exists(oOutputPath) Then If File.Exists(oOutputPath) Then
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
_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)
@ -79,6 +84,7 @@ Public Class XRechnungViewDocument
' Dim oCurrent As Integer = MyGDPicturePDF.GetCurrentPage() ' Dim oCurrent As Integer = MyGDPicturePDF.GetCurrentPage()
Dim yPosition As Single = Create_PageHeader(False) Dim yPosition As Single = Create_PageHeader(False)
Create_PageFooter() Create_PageFooter()
Dim oArea As String = "" Dim oArea As String = ""
@ -145,6 +151,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 +180,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 +207,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 +219,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 +248,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 +293,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 +332,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 +437,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 +446,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 +459,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}"