Greenpulse, VERA_Customseclarations

This commit is contained in:
2026-01-05 15:27:35 +01:00
parent 1976d4f509
commit 6b44360ed4
7 changed files with 269 additions and 46 deletions

View File

@@ -12,8 +12,8 @@ Public Class cDakosyEZA_Greenpulse
If eza Is Nothing Then Throw New ArgumentNullException(NameOf(eza))
' --- Adressen (Heuristik: CN=Importer, CZ=Exporter, DT=Declarant) ---
Dim importer = GuessAddressByType(eza.eza_ADRESSEN, {"CN", "IM", "IMP"})
Dim exporter = GuessAddressByType(eza.eza_ADRESSEN, {"CZ", "EX", "EXP"})
Dim importer = GuessAddressByType(eza.eza_ADRESSEN, {"CN", "IM", "IMP", "IMPORTER"})
Dim exporter = GuessAddressByType(eza.eza_ADRESSEN, {"CZ", "EX", "EXP", "EXPORTER"})
Dim declarant = GuessAddressByType(eza.eza_ADRESSEN, {"DT", "DEC", "ANM", "DECLARANT"})
' --- Rechnungsdaten (Unterlagen N380) ---
@@ -164,33 +164,196 @@ Public Class cDakosyEZA_Greenpulse
If DY IsNot Nothing AndAlso DY.dy_SendungsId IsNot Nothing Then
Dim sendungsId As Integer
If Integer.TryParse(DY.dy_SendungsId.ToString(), sendungsId) AndAlso sendungsId > 0 Then
Dim ANH_LIST As New List(Of cAvisoAnhaenge)
cAvisoAnhaenge.LOAD_LIST_BySendung(ANH_LIST, sendungsId)
For Each doc In ANH_LIST
Select Case doc.anh_Art
Case "Rechnung", "eFatura"
Dim pfad As String = VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(doc.anh_docId)
Dim dateiBytes As Byte() = System.IO.File.ReadAllBytes(pfad)
Dim d As New cATEZ_Greenpulse_KafkaInvoices.DocumentNode With {
.Reference = doc.anh_Name,
.DocType = "invoice",
.MimeType = cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY.GuessMimeTypeFromNumber(doc.anh_Typ),
.Blob = Convert.ToBase64String(dateiBytes)
}
dest.Documents.Add(d)
End Select
Next
dest = BuildInvoices(sendungsId)
End If
End If
Return dest
End Function
Public Shared Function BuildInvoices(sendungsId As Integer) As cATEZ_Greenpulse_KafkaInvoices
' Zielobjekt NUR für Dokumente
Dim dest As New cATEZ_Greenpulse_KafkaInvoices() With {
.Documents = New List(Of cATEZ_Greenpulse_KafkaInvoices.DocumentNode)()
}
If sendungsId > 0 Then
Dim ANH_LIST As New List(Of cAvisoAnhaenge)
cAvisoAnhaenge.LOAD_LIST_BySendung(ANH_LIST, sendungsId)
For Each doc In ANH_LIST
Select Case doc.anh_Art
Case "Rechnung", "eFatura"
Dim pfad As String = VERAG_PROG_ALLGEMEIN.cDATENSERVER.GET_PDFPath_BY_DocID(doc.anh_docId)
Dim dateiBytes As Byte() = System.IO.File.ReadAllBytes(pfad)
Dim d As New cATEZ_Greenpulse_KafkaInvoices.DocumentNode With {
.Reference = doc.anh_Name,
.DocType = "invoice",
.MimeType = cATEZ_Greenpulse_KafkaDecsBuilder_DAKOSY.GuessMimeTypeFromNumber(doc.anh_Typ),
.Blob = Convert.ToBase64String(dateiBytes)
}
dest.Documents.Add(d)
End Select
Next
End If
Return dest
End Function
Public Shared Function BuildByMrn(za As cVERAG_CustomsDeclarations) As cATEZ_Greenpulse_KafkaDecs
If za Is Nothing Then Throw New ArgumentNullException(NameOf(za))
' --- Parties (Heuristik über zaParty_Role) ---
Dim importer = GuessPartyByRole(za.Parties, {"CN", "IMPORTER", "IM"})
Dim exporter = GuessPartyByRole(za.Parties, {"CZ", "EXPORTER", "EX"})
Dim declarant = GuessPartyByRole(za.Parties, {"CB", "DECLARANT", "DEC"})
' --- Rechnungsdaten (Header-Dokument N380) ---
Dim inv = If(za.Documents IsNot Nothing,
za.Documents.FirstOrDefault(Function(d) _
SafeStr(d.zaDoc_Code).Equals("N380", StringComparison.OrdinalIgnoreCase) _
AndAlso Not String.IsNullOrWhiteSpace(SafeStr(d.zaDoc_Reference))),
Nothing)
' --- Zielobjekt ---
Dim dest As New cATEZ_Greenpulse_KafkaDecs With {
.Declaration = New cATEZ_Greenpulse_KafkaDecs.DeclarationNode With {
.DeclarationSourceId = SafeStr(za.za_Id),
.DeclarationNo = FirstNonEmptyStr(za.za_MRN, za.za_DeclarationNo),
.DeclarationDate = ToDateYMD(FirstNonEmpty(za.za_DeclarationDate, za.za_ReleaseDate, za.za_AcceptanceDate)),
.RequestedProcedure = SafeStr(za.za_MainProcedure),
.PreviousProcedure = "",
.Goods = New List(Of cATEZ_Greenpulse_KafkaDecs.GoodItem)()
},
.Parties = New cATEZ_Greenpulse_KafkaDecs.PartiesNode With {
.ImporterIdentificationNumber = FirstNonEmptyStr(
If(importer IsNot Nothing, importer.zaParty_EORI, Nothing),
If(importer IsNot Nothing, importer.zaParty_TIN, Nothing)
),
.ExporterIdentificationNumber = FirstNonEmptyStr(
If(exporter IsNot Nothing, exporter.zaParty_EORI, Nothing),
If(exporter IsNot Nothing, exporter.zaParty_TIN, Nothing)
),
.TypeOfRepresentation = SafeStr(za.za_RepresentationCode)
},
.Commercial = New cATEZ_Greenpulse_KafkaDecs.CommercialNode With {
.InvoiceNumbers = If(inv IsNot Nothing, SafeStr(inv.zaDoc_Reference), ""),
.InvoiceDate = If(inv IsNot Nothing, ToDateYMD(inv.zaDoc_Date), "")
},
.ExporterDetails = New cATEZ_Greenpulse_KafkaDecs.ExporterDetailsNode With {
.ExporterTitle = If(exporter IsNot Nothing, SafeStr(exporter.zaParty_Name), ""),
.ExporterEmail = If(exporter IsNot Nothing, SafeStr(exporter.zaParty_Email), ""),
.ExporterPhone = If(exporter IsNot Nothing, SafeStr(exporter.zaParty_Phone), "")
},
.ImporterDetails = New cATEZ_Greenpulse_KafkaDecs.ImporterDetailsNode With {
.ImporterTitle = If(importer IsNot Nothing, SafeStr(importer.zaParty_Name), ""),
.ImporterEmail = If(importer IsNot Nothing, SafeStr(importer.zaParty_Email), ""),
.ImporterPhone = If(importer IsNot Nothing, SafeStr(importer.zaParty_Phone), ""),
.ImporterCountryCodeOrMemberState = If(importer IsNot Nothing, SafeStr(importer.zaParty_Country), ""),
.ImporterSubdivision = "",
.ImporterCity = If(importer IsNot Nothing, SafeStr(importer.zaParty_City), ""),
.ImporterStreet = If(importer IsNot Nothing, SafeStr(importer.zaParty_Street), ""),
.ImporterStreetAdditional = "",
.ImporterAddressNumber = "",
.ImporterPostCode = If(importer IsNot Nothing, SafeStr(importer.zaParty_PostalCode), ""),
.ImporterPoBox = "",
.ImporterCoordinateLongitudeX = "",
.ImporterCoordinateLatitudeY = ""
},
.Documents = New List(Of cATEZ_Greenpulse_KafkaDecs.DocumentNode)()
}
Select Case za.za_System
Case "DAKOSY"
Select Case If(za.za_RepresentationCode, "")
Case "2" : dest.Parties.ReportingDeclarantEORINumber = If(declarant IsNot Nothing, declarant.zaParty_EORI, Nothing) ' '2=indirekt
Case Else : dest.Parties.ReportingDeclarantEORINumber = If(importer IsNot Nothing, importer.zaParty_EORI, Nothing) ' direkt
End Select
Case "DHF", "DHF_UNISPED"
Select Case If(za.za_RepresentationCode, "")
Case "3" : dest.Parties.ReportingDeclarantEORINumber = If(declarant IsNot Nothing, declarant.zaParty_EORI, Nothing) ' 'indirekt
Case "5"
If If(za.za_ApplicantTaxOffice, "") = "73001" Then : dest.Parties.ReportingDeclarantEORINumber = If(declarant IsNot Nothing, declarant.zaParty_EORI, Nothing) ' 'indirekt '!!!!!!!!!!!!!!!!!!!!!! za_ApplicantTaxOffice stimmt nciht!!!!!
Else : dest.Parties.ReportingDeclarantEORINumber = If(importer IsNot Nothing, importer.zaParty_EORI, Nothing) : End If ' direkt
Case Else : dest.Parties.ReportingDeclarantEORINumber = If(importer IsNot Nothing, importer.zaParty_EORI, Nothing) ' direkt
End Select
Case "TELOTEC"
Select Case If(za.za_RepresentationCode, "")
Case "3" : dest.Parties.ReportingDeclarantEORINumber = If(declarant IsNot Nothing, declarant.zaParty_EORI, Nothing) ' '3=indirekt
Case "5"
If If(za.za_ApplicantTaxOffice, "") = "73001" Then : dest.Parties.ReportingDeclarantEORINumber = If(declarant IsNot Nothing, declarant.zaParty_EORI, Nothing) ' 'indirekt '!!!!!!!!!!!!!!!!!!!!!! za_ApplicantTaxOffice stimmt nciht!!!!!
Else : dest.Parties.ReportingDeclarantEORINumber = If(importer IsNot Nothing, importer.zaParty_EORI, Nothing) : End If ' direkt
Case Else : dest.Parties.ReportingDeclarantEORINumber = If(importer IsNot Nothing, importer.zaParty_EORI, Nothing) ' direkt
End Select
End Select
' --- EORI-Lookups (optional, wie bisher) ---
Dim impEori As String = SafeStr(If(importer IsNot Nothing, importer.zaParty_EORI, Nothing))
If Not String.IsNullOrWhiteSpace(impEori) Then
PopulateImporterByEori(impEori, dest.Parties, dest.ImporterDetails)
End If
Dim expEori As String = SafeStr(If(exporter IsNot Nothing, exporter.zaParty_EORI, Nothing))
If Not String.IsNullOrWhiteSpace(expEori) Then
PopulateExporterByEori(expEori, dest.Parties, dest.ExporterDetails)
End If
Dim decEori As String = SafeStr(If(declarant IsNot Nothing, declarant.zaParty_EORI, Nothing))
If Not String.IsNullOrWhiteSpace(decEori) Then
PopulateDeclarantByEori(decEori, dest.Parties)
End If
' --- Warenpositionen -> Goods ---
If za.Items IsNot Nothing Then
For Each it In za.Items
Dim gi As New cATEZ_Greenpulse_KafkaDecs.GoodItem With {
.CommodityCode = SafeStr(it.zaItem_HSCode),
.OriginCountryCode = SafeStr(it.zaItem_OriginCountry),
.NetMass = ToInvariantStr(it.zaItem_NetMass),
.TypeOfMeasurementUnit = UnitCodeToKafkaName("KGM"),
.SpecialProcedures = New cATEZ_Greenpulse_KafkaDecs.SpecialProceduresNode With {
.MemberStateAutharization = SafeStr(If(importer IsNot Nothing, importer.zaParty_Country, Nothing)),
.DischargeBillWaiver = "",
.Authorisation = "",
.StartTime = "",
.EndTime = "",
.Deadline = ""
}
}
dest.Declaration.Goods.Add(gi)
Next
End If
' --- Requested/Previous Procedure Fallback aus erster Position ---
Dim it0 = If(za.Items IsNot Nothing, za.Items.FirstOrDefault(), Nothing)
If it0 IsNot Nothing Then
If String.IsNullOrWhiteSpace(dest.Declaration.RequestedProcedure) Then
dest.Declaration.RequestedProcedure = SafeStr(it0.zaItem_MainProcedure)
End If
dest.Declaration.PreviousProcedure = SafeStr(it0.zaItem_PrevProcedure)
End If
Return dest
End Function
Private Shared Function GuessPartyByRole(parties As List(Of cVERAG_CustomsDeclarations_Parties),
roles As IEnumerable(Of String)) _
As cVERAG_CustomsDeclarations_Parties
If parties Is Nothing Then Return Nothing
Return parties.FirstOrDefault(Function(p) roles.Any(
Function(r) SafeStr(p.zaParty_Role).Equals(r, StringComparison.OrdinalIgnoreCase)))
End Function