Compare commits
2 Commits
upgrade-to
...
e9427b35be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9427b35be | ||
|
|
51798a28f5 |
@@ -17,8 +17,6 @@ Public Class XRechnungViewDocument
|
||||
Private fontResName As String
|
||||
Private fontResNameBold As String
|
||||
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,13 +43,30 @@ 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)
|
||||
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)
|
||||
_logger.Debug("Create_PDFfromXML() Resulting PDF Filepath: [{0}]", oOutputPath)
|
||||
@@ -59,13 +74,10 @@ Public Class XRechnungViewDocument
|
||||
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)
|
||||
Dim oCreatedString = $"Maschinell erstellt durch / Automatically created by Digital Data E-Rechnung Parser: {Now.ToString}"
|
||||
MyGDPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
|
||||
MyGDPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
|
||||
MyGDPicturePDF.SetLineWidth(1)
|
||||
@@ -77,9 +89,23 @@ Public Class XRechnungViewDocument
|
||||
'Create a New page
|
||||
MyGDPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4)
|
||||
' 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)
|
||||
Create_PageFooter()
|
||||
MyGDPicturePDF.DrawText(fontResName, 10, 285, oCreatedString)
|
||||
|
||||
Dim oArea As String = ""
|
||||
Dim oIsPosition As Boolean = False
|
||||
@@ -114,8 +140,23 @@ Public Class XRechnungViewDocument
|
||||
_logger.Warn($"Could not create a second page. The error was: {oPDFStatus}")
|
||||
Exit For
|
||||
Else
|
||||
yPosition = Create_PageHeader(True)
|
||||
Create_PageFooter()
|
||||
'Wieder einen Header und Footer erzeugen
|
||||
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
|
||||
'oCurrent = MyGDPicturePDF.GetCurrentPage()
|
||||
End If
|
||||
@@ -145,6 +186,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 +215,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 +242,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 +254,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 +283,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 +328,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 +367,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 +472,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 +481,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 +494,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}"
|
||||
@@ -463,29 +523,6 @@ Public Class XRechnungViewDocument
|
||||
Dim lines As List(Of String) = text.Split({vbCrLf, vbLf, vbCr}, StringSplitOptions.None).ToList()
|
||||
Return lines
|
||||
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
|
||||
Dim oReturn As String = "Rechnung/invoice"
|
||||
If pType = "380" Then
|
||||
|
||||
Reference in New Issue
Block a user