From 7c473b9a277e05bbf33c2c80d2a51949a550281a Mon Sep 17 00:00:00 2001 From: Developer01 Date: Fri, 14 Mar 2025 14:43:11 +0100 Subject: [PATCH] MS Module Base StringFunctions Modules.Jibs Sichtbeleg Anpassung --- Base/Base.vbproj | 1 + Base/My Project/AssemblyInfo.vb | 4 +- Base/StringFunctions.vb | 22 ++++ Jobs/Jobs.vbproj | 1 + Jobs/My Project/AssemblyInfo.vb | 4 +- Jobs/ZUGFeRD/XRechnungViewDocument.vb | 155 +++++++++++++++++++++++--- 6 files changed, 166 insertions(+), 21 deletions(-) create mode 100644 Base/StringFunctions.vb diff --git a/Base/Base.vbproj b/Base/Base.vbproj index bb03a7e8..a6b1e6c8 100644 --- a/Base/Base.vbproj +++ b/Base/Base.vbproj @@ -89,6 +89,7 @@ + diff --git a/Base/My Project/AssemblyInfo.vb b/Base/My Project/AssemblyInfo.vb index 7e120f51..deab368b 100644 --- a/Base/My Project/AssemblyInfo.vb +++ b/Base/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' indem Sie "*" wie unten gezeigt eingeben: ' - - + + diff --git a/Base/StringFunctions.vb b/Base/StringFunctions.vb new file mode 100644 index 00000000..1eb4b131 --- /dev/null +++ b/Base/StringFunctions.vb @@ -0,0 +1,22 @@ +Public Class StringFunctions + Public Shared Function SplitText_Length(ByVal input As String, ByVal maxLength As Integer) As List(Of String) + Dim result As New List(Of String) + + For i As Integer = 0 To input.Length - 1 Step maxLength + ' Textabschnitt extrahieren + Dim chunk As String = input.Substring(i, Math.Min(maxLength, input.Length - i)) + result.Add(chunk) + Next + + Return result + End Function + Public Shared Function SplitTextByNewLine(text As String) As List(Of String) + If String.IsNullOrEmpty(text) Then + Return New List(Of String)() + End If + + ' Zerlege den Text anhand von Zeilenumbrüchen + Dim lines As List(Of String) = text.Split({vbCrLf, vbLf, vbCr}, StringSplitOptions.None).ToList() + Return lines + End Function +End Class diff --git a/Jobs/Jobs.vbproj b/Jobs/Jobs.vbproj index a9c4900e..03e72587 100644 --- a/Jobs/Jobs.vbproj +++ b/Jobs/Jobs.vbproj @@ -138,6 +138,7 @@ + diff --git a/Jobs/My Project/AssemblyInfo.vb b/Jobs/My Project/AssemblyInfo.vb index 50024539..cb7c26f3 100644 --- a/Jobs/My Project/AssemblyInfo.vb +++ b/Jobs/My Project/AssemblyInfo.vb @@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' übernehmen, indem Sie "*" eingeben: - - + + diff --git a/Jobs/ZUGFeRD/XRechnungViewDocument.vb b/Jobs/ZUGFeRD/XRechnungViewDocument.vb index da06bb87..b11e9f29 100644 --- a/Jobs/ZUGFeRD/XRechnungViewDocument.vb +++ b/Jobs/ZUGFeRD/XRechnungViewDocument.vb @@ -5,7 +5,8 @@ Imports DigitalData.Modules.Base Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging Imports GdPicture14 - +Imports System.Drawing +Imports System.Linq Public Class XRechnungViewDocument Private ReadOnly _logger As Logger Private ReadOnly _logConfig As LogConfig @@ -69,16 +70,23 @@ Public Class XRechnungViewDocument MyGDPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) ' Dim oCurrent As Integer = MyGDPicturePDF.GetCurrentPage() - Dim yPosition As Integer = Create_PageHeader(False) + Dim yPosition As Single = Create_PageHeader(False) Create_PageFooter() Dim oArea As String = "" Dim oIsPosition As Boolean = False Dim oPosCount = 0 Dim oPosTerm As String = "" + Dim oPosDesc As String = "" Dim oCurrencySymbol = "€" + Dim oWidthLine = 200 yPosition += 5 + + Dim font As New Font("Helvetica", 10) + Dim xRight As Integer = 100 Dim oIndex As Integer = 0 + Dim oYPlus As Integer = 0 + Dim oCreateTextBox As Boolean = False For Each oRow As DataRow In pDTItemValues.Rows Dim Y_eq_lastrow As Boolean = CBool(oRow.Item("Y_eq_lastrow")) Dim oRowCaption As String = oRow.Item("Row_Caption") @@ -86,6 +94,7 @@ Public Class XRechnungViewDocument Dim oItemValue As String = oRow.Item("ITEM_VALUE") Dim oDisplay As Boolean = oRow.Item("Display") Dim oAreaSwitch As Boolean = False + If oRow.Item("Area") = "INTERNAL" Then If oItemSPECNAME = "STATIC_Y_SWITCH" Then yPosition = oItemValue @@ -113,6 +122,7 @@ Public Class XRechnungViewDocument If oArea <> oRow.Item("Area") Then '########## AREA WECHSEL ########### oAreaSwitch = True + oCreateTextBox = False oArea = oRow.Item("Area") _logger.Debug($"Area-Switch to: {oArea}") Dim oAREACaption As String @@ -127,6 +137,7 @@ Public Class XRechnungViewDocument oIsPosition = True ElseIf oArea = "AMOUNT" Then oAREACaption = "Beträge / Amounts:" + oCreateTextBox = True ElseIf oArea = "TAXPOS" Then oAREACaption = "Steuerbeträge / Tax amounts:" oIsPosition = True @@ -139,17 +150,25 @@ Public Class XRechnungViewDocument If Not oAREACaption = String.Empty Then 'erste Area-Linie yPosition += 5 - MyGDPicturePDF.DrawLine(10, yPosition, 125, yPosition) + MyGDPicturePDF.DrawLine(10, yPosition, oWidthLine, yPosition) 'gdpicturePDF.DrawText(fontResName, 10, yPosition, XRechnungStrings.Seperator_Line) yPosition += 5 'Area caption MyGDPicturePDF.DrawText(fontResNameBold, 10, yPosition, oAREACaption) - yPosition += 5 If oArea = "TYPE" Then - MyGDPicturePDF.DrawLine(10, yPosition, 125, yPosition) + MyGDPicturePDF.DrawLine(10, yPosition, oWidthLine, yPosition) ' gdpicturePDF.DrawText(fontResName, 10, yPosition, XRechnungStrings.Seperator_Line) yPosition += 5 + ElseIf oArea = "POSITION" Then + 'Tabellendarstellung + MyGDPicturePDF.DrawText(fontResName, 10, yPosition, "Pos#") + MyGDPicturePDF.DrawText(fontResName, 20, yPosition, "Anz./Am.") + MyGDPicturePDF.DrawText(fontResName, 38, yPosition, "Pos.-Text") + MyGDPicturePDF.DrawText(fontResName, 155, yPosition, "Steuer/Tax") + MyGDPicturePDF.DrawText(fontResName, 175, yPosition, "Betrag/Sum") + yPosition += 5 + 'Tabellendarstellung Ende End If End If If oArea = "TYPE" Then @@ -162,10 +181,20 @@ Public Class XRechnungViewDocument oIsPosition = True If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then oPosCount += 1 - oPosTerm = $"{oPosCount}. {oItemValue} * " - oItemValue = oPosTerm + 'oPosTerm = $"{oPosCount}. {oItemValue} * " + 'oItemValue = oPosTerm + 'Tabellendarstellung + 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, 20, yPosition, oItemValue) + 'Tabellendarstellung Ende oDisplay = False - yPosition -= 5 + ' yPosition -= 5 End If ElseIf oArea = "TAXPOS" Then oIsPosition = True @@ -179,20 +208,77 @@ Public Class XRechnungViewDocument End If Else 'INDIVIDUELLES VERHALTEN BEI Folge-ITEMS - _logger.Debug($"FollowItem: {oItemSPECNAME} - ItemValue: {oItemValue}") + _logger.Debug($"FollowItem - Area: [{oArea}] - ItemSpecname: [{oItemSPECNAME}] - ItemValue: [{oItemValue}]") + Dim otextBoxYPos As Integer If oArea = "POSITION" Then If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then oPosCount += 1 - oPosTerm = $"{oPosCount}. {oItemValue} * " + oYPlus = 0 + 'oPosTerm = $"{oPosCount}. {oItemValue} * " + '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, 20, yPosition, oItemValue) + 'Tabellendarstellung Ende oDisplay = False ElseIf oItemSPECNAME = "INVOICE_POSITION_ARTICLE" Then - oPosTerm += $" {oItemValue}" + 'Tabellendarstellung + oYPlus = 0 + oPosDesc = "" + oPosDesc = oItemValue + 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, 38, oYDyn, part) + Next + Next + 'Tabellendarstellung Ende + ' oPosTerm += $" {oItemValue}" + oDisplay = False + ElseIf oItemSPECNAME = "INVOICE_POSITION_NOTE" Then + 'Tabellendarstellung + Dim cleanedText As String = RemoveNewlinesAndTabs(oItemValue) + Dim oParts As List(Of String) = StringFunctions.SplitText_Length(cleanedText, 68) + ' Durchlaufen der einzelnen Teile in einer Schleife + Dim oYDyn As Integer = yPosition + Dim oPartsNL As List(Of String) = StringFunctions.SplitTextByNewLine(oItemValue) + For Each olinepart As String In oPartsNL + Dim oPartsPN As List(Of String) = StringFunctions.SplitText_Length(olinepart, 67) + ' Durchlaufen der einzelnen Teile in einer Schleife + For Each part As String In oPartsPN + oYDyn += 5 + oYPlus += 5 + MyGDPicturePDF.DrawText(fontResName, 38, oYDyn, part) + Next + Next + 'Tabellendarstellung Ende + 'oPosTerm += $" {oItemValue}" oDisplay = False ElseIf oItemSPECNAME = "INVOICE_TAXPOS_TAX_RATE" Or oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then - oPosTerm += $" - {oItemValue} %" + 'Tabellendarstellung + MyGDPicturePDF.DrawText(fontResName, 155, yPosition, $"{oItemValue} %") + 'Tabellendarstellung ENDE + ' oPosTerm += $" - {oItemValue} %" oDisplay = False ElseIf oItemSPECNAME = "INVOICE_POSITION_TAX_AMOUNT" Then - oPosTerm += $" - {oItemValue} {oCurrencySymbol}" + ' oPosTerm += $" - {oItemValue} {oCurrencySymbol}" + 'Tabellendarstellung + Dim oYPos = yPosition - 3.5 + MyGDPicturePDF.DrawTextBox(fontResName, 175, oYPos, 193, YCoo_TextBoxPlus5(oYPos), + TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentNear, + $"{oItemValue} {oCurrencySymbol}") + ' MyGDPicturePDF.DrawText(fontResName, 175, yPosition, $"{oItemValue} {oCurrencySymbol}") + 'Tabellendarstellung Ende End If oItemValue = oPosTerm ElseIf oArea = "HEAD" Then @@ -210,26 +296,36 @@ Public Class XRechnungViewDocument oPosTerm += $" {oItemValue} {oCurrencySymbol}" oDisplay = False ElseIf oItemSPECNAME = "INVOICE_TAXPOS_TYPE" Then - oPosTerm += $" - {oItemValue}" + oPosTerm += $" {oItemValue}" End If oItemValue = oPosTerm End If End If - If oDisplay = True Then + If oDisplay = True And Len(oItemValue) > 0 Then If Y_eq_lastrow = False And oAreaSwitch = False Then yPosition += 5 End If If oArea = "AMOUNT" Then - If oItemSPECNAME = "INVOICE_TOTAL_NET" Or oItemSPECNAME = "INVOICE_TOTAL_GROSS" Then + If oItemSPECNAME = "INVOICE_TOTAL_TAX" Or oItemSPECNAME = "INVOICE_TOTAL_NET" Or oItemSPECNAME = "INVOICE_TOTAL_GROSS" Then oItemValue += $" {oCurrencySymbol}" End If End If If oRowCaption <> String.Empty Then + 'Zuerst die RowCaption MyGDPicturePDF.DrawText(fontResName, 10, yPosition, oRowCaption) - MyGDPicturePDF.DrawText(fontResName, 70, yPosition, oItemValue) + 'Dann den Wert + If oCreateTextBox Then + Dim otextBoxYPos = yPosition - 3 + MyGDPicturePDF.DrawTextBox(fontResName, 70, otextBoxYPos, 90, YCoo_TextBoxPlus5(otextBoxYPos), + TextAlignment.TextAlignmentFar, TextAlignment.TextAlignmentCenter, + oItemValue) + Else + MyGDPicturePDF.DrawText(fontResName, 70, yPosition, oItemValue) + End If + Else If Y_eq_lastrow = True Then MyGDPicturePDF.DrawText(fontResName, oRow.Item("xPosition"), yPosition, oItemValue) @@ -256,6 +352,12 @@ Public Class XRechnungViewDocument End If End If + Else + 'Tabellendarstellung + If oItemSPECNAME = "INVOICE_POSITION_TAX_AMOUNT" And oYPlus > 0 Then + yPosition += oYPlus - 5 + End If + 'Tabellendarstellung Ende End If oIndex += 1 Next @@ -288,7 +390,26 @@ Public Class XRechnungViewDocument Return Nothing End Try End Function + Private Function RemoveNewlinesAndTabs(ByVal text As String) As String + Return text.Replace(vbCr, " - ").Replace(vbLf, "").Replace(vbTab, " ") + End Function + Private Function YCoo_TextBoxMinus5(yPosition As Integer) + Return yPosition - 5 + End Function + Private Function YCoo_TextBoxPlus5(yPosition As Integer) + Return yPosition + 5 + End Function + + Function SplitTextByNewLine(text As String) As List(Of String) + If String.IsNullOrEmpty(text) Then + Return New List(Of String)() + End If + + ' Zerlege den Text anhand von Zeilenumbrüchen + 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