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 MyGDPicturePDF As GdPicturePDF
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, GDPictureLicenseKey As String)
_logConfig = LogConfig
_logger = LogConfig.GetLogger()
@ -45,27 +46,31 @@ Public Class XRechnungViewDocument
File.Delete(oTempFilePath)
End If
_logger.Debug("Vor MOVE... oxmlFilePath: [{0}] / oTempFilePath: [{1}]", oXmlFilePath, oTempFilePath)
File.Move(oXmlFilePath, oTempFilePath)
pXmlFile = New FileInfo(oTempFilePath)
'oViewRecieptFilename = oViewRecieptFilename.Replace(".xml", ".pdf")
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)
_logger.Debug("Create_PDFfromXML() Resulting PDF Filepath: [{0}]", oOutputPath)
If File.Exists(oOutputPath) Then
File.Delete(oOutputPath)
End If
MyGDPicturePDF = New GdPicturePDF()
MyGDPicturePDF.NewPDF(PdfConformance.PDF_A_2a)
Dim oPDFStatus As GdPictureStatus = MyGDPicturePDF.NewPDF()
If oPDFStatus <> GdPictureStatus.OK Then
_logger.Warn($"Error initializing PDF: {oPDFStatus}")
Return Nothing
End If
_logger.Debug("Vor MOVE... oxmlFilePath: [{0}] / oTempFilePath: [{1}]", oXmlFilePath, oTempFilePath)
File.Move(oXmlFilePath, oTempFilePath)
MyGDPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
MyGDPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
MyGDPicturePDF.SetLineWidth(1)
@ -79,6 +84,7 @@ Public Class XRechnungViewDocument
' Dim oCurrent As Integer = MyGDPicturePDF.GetCurrentPage()
Dim yPosition As Single = Create_PageHeader(False)
Create_PageFooter()
Dim oArea As String = ""
@ -145,6 +151,7 @@ Public Class XRechnungViewDocument
oIsPosition = True
ElseIf oArea = "ALLOWANCE" Then
oAREACaption = "Zu- oder Abschlag/Surcharge or Discount:"
oIsPosition = True
ElseIf oArea = "AMOUNT" Then
oAREACaption = "Beträge / Amounts:"
oCreateTextBox = True
@ -173,15 +180,19 @@ Public Class XRechnungViewDocument
' gdpicturePDF.DrawText(fontResName, 10, yPosition, XRechnungStrings.Seperator_Line)
yPosition += 5
ElseIf oArea = "POSITION" Then
'Tabellendarstellung
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "Pos#")
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, 164, yPosition, "Steuer/tax")
MyGDPicturePDF.DrawText(fontResName, 181, yPosition, "Betrag/sum")
MyGDPicturePDF.DrawText(fontResName, 164, yPosition, "Steuer/Tax")
MyGDPicturePDF.DrawText(fontResName, 181, yPosition, "Betrag/Sum")
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
End If
@ -196,9 +207,6 @@ Public Class XRechnungViewDocument
oIsPosition = True
If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then
oPosCount += 1
'oPosTerm = $"{oPosCount}. {oItemValue} * "
'oItemValue = oPosTerm
'Tabellendarstellung
oPosTerm = ""
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount)
'
@ -211,6 +219,20 @@ Public Class XRechnungViewDocument
oDisplay = False
' yPosition -= 5
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
oIsPosition = True
If oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then
@ -226,20 +248,29 @@ Public Class XRechnungViewDocument
'INDIVIDUELLES VERHALTEN BEI Folge-ITEMS
_logger.Debug($"FollowItem - Area: [{oArea}] - ItemSpecname: [{oItemSPECNAME}] - ItemValue: [{oItemValue}]")
'Dim otextBoxYPos As Integer
If oArea = "POSITION" Then
If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then
If oArea = "POSITION" Or oArea = "ALLOWANCE" Then
If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Or oItemSPECNAME = "RECEIPT_ALLOWANCE_REASON" Then
oPosCount += 1
oYPlus = 0
'Tabellendarstellung
yPosition += 5
oPosTerm = ""
MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oPosCount)
'otextBoxYPos = yPosition - 3.5
'MyGDPicturePDF.DrawTextBox(fontResName, 10, otextBoxYPos, 16, YCoo_TextBoxPlus5(otextBoxYPos),
' TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear,
' oPosCount)
MyGDPicturePDF.DrawText(fontResName, 19, yPosition, oItemValue)
'Tabellendarstellung Ende
If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then
MyGDPicturePDF.DrawText(fontResName, 19, yPosition, oItemValue)
Else
Dim oYDyn As Integer = yPosition - 5
Dim oPartsNL As List(Of String) = StringFunctions.SplitTextByNewLine(oItemValue)
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
ElseIf oItemSPECNAME = "INVOICE_POSITION_UNIT_TYPE" Then
oYPlus = 0
@ -262,8 +293,6 @@ Public Class XRechnungViewDocument
MyGDPicturePDF.DrawText(fontResName, 50, oYDyn, part)
Next
Next
'Tabellendarstellung Ende
' oPosTerm += $" {oItemValue}"
oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_POSITION_NOTE" Then
'Tabellendarstellung
@ -303,24 +332,19 @@ Public Class XRechnungViewDocument
'oPosTerm += $" {oItemValue}"
oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_TAXPOS_TAX_RATE" Or oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then
'Tabellendarstellung
ElseIf oItemSPECNAME = "INVOICE_TAXPOS_TAX_RATE" Or oItemSPECNAME = "INVOICE_TAXPOS_RATE" Or oItemSPECNAME = "RECEIPT_ALLOWANCE_VAT_RATE" Then
MyGDPicturePDF.DrawText(fontResName, 164, yPosition, $"{oItemValue} %")
'Tabellendarstellung ENDE
' oPosTerm += $" - {oItemValue} %"
oDisplay = False
ElseIf oItemSPECNAME = "INVOICE_POSITION_TAX_AMOUNT" Then
'Tabellendarstellung
ElseIf oItemSPECNAME = "INVOICE_POSITION_TAX_AMOUNT" Or oItemSPECNAME = "RECEIPT_ALLOWANCE_ACTUAL_AMOUNT" Then
Dim oYPos = yPosition - 3.5
Dim TAXTERM = FormatCurrency(oItemValue, oCurrencySymbol)
MyGDPicturePDF.DrawTextBox(fontResName, 177, oYPos, 198, YCoo_TextBoxPlus5(oYPos),
TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear,
TAXTERM)
' MyGDPicturePDF.DrawText(fontResName, 180, yPosition, $"{oItemValue} {oCurrencySymbol}")
'Tabellendarstellung Ende
End If
oItemValue = oPosTerm
ElseIf oArea = "HEAD" Then
If oItemSPECNAME = "INVOICE_DATE" Or oItemSPECNAME = "INVOICE_SERVICE_DATE" Then
oItemValue = StringFunctions.DatetimeStringToGermanStringConverter(oItemValue, _logger)
@ -413,6 +437,7 @@ Public Class XRechnungViewDocument
_logger.Info("PDF VisualReceipt generated successfully!")
Else
_logger.Warn($"Error generating PDF VisualReceipt: {oPDFStatus}")
File.Move(oTempFilePath, oXmlFilePath)
End If
'Release resources
@ -421,10 +446,10 @@ Public Class XRechnungViewDocument
File.Delete(oXRechnungFile)
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
Else
_logger.Debug("Create_PDFfromXML() Ends with nothing")
_logger.Warn("Create_PDFfromXML() Ends with nothing")
Return Nothing
End If
@ -434,7 +459,7 @@ Public Class XRechnungViewDocument
End Try
End Function
Private Function FormatCurrency(ByVal pValue As String, pCurrencySymbol As String) As String
pValue = pValue.replace(".", ",")
pValue = pValue.Replace(".", ",")
Dim oBetrag As Decimal = pValue
Dim oFormatiert As String = oBetrag.ToString("N2", New Globalization.CultureInfo("de-DE"))
oFormatiert = $"{oFormatiert} {pCurrencySymbol}"