TetraPak
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.IO
|
||||
Imports ClosedXML.Excel
|
||||
Imports VERAG_PROG_ALLGEMEIN
|
||||
Public Class cImporter_DakosyToVERAG
|
||||
|
||||
@@ -340,6 +342,16 @@ Public Class cImporter_DakosyToVERAG
|
||||
' ======KAFKA==========================================================
|
||||
If saved AndAlso freshInsert Then cDakosyEZA_Greenpulse.INSERT_KAFKA(ZA)
|
||||
' ================================================================
|
||||
|
||||
|
||||
If saved Then
|
||||
Try
|
||||
UpdateBrokerManagementFileTETRAPAK(ZA)
|
||||
Catch ex As Exception
|
||||
cErrorHandler.ERR(ex.Message, ex.StackTrace, "UpdateBrokerManagementFile")
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return saved
|
||||
|
||||
|
||||
@@ -349,6 +361,323 @@ Public Class cImporter_DakosyToVERAG
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Sub UpdateBrokerManagementFileTETRAPAK(ZA As cVERAG_CustomsDeclarations)
|
||||
Const kundenNrTETRAPAK As Integer = 719649
|
||||
Const prefix As String = "[TETRAPAK] "
|
||||
|
||||
Debug.WriteLine(prefix & "========== START BrokerManagementFile ==========")
|
||||
|
||||
Try
|
||||
If ZA Is Nothing OrElse ZA.za_Id <= 0 Then
|
||||
Debug.WriteLine(prefix & "ABBRUCH: Keine gültige Zollanmeldung")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
'Zollanmeldung vollständig aus VERAG-Datenbank laden
|
||||
Dim ZOLL As New cVERAG_CustomsDeclarations
|
||||
ZOLL.za_Id = ZA.za_Id
|
||||
ZOLL.LOAD()
|
||||
|
||||
If Not ZOLL.hasEntry Then
|
||||
Throw New Exception("Zollanmeldung nicht gefunden. za_Id=" & ZA.za_Id)
|
||||
End If
|
||||
|
||||
Debug.WriteLine(prefix & "ZA-ID: " & ZOLL.za_Id)
|
||||
Debug.WriteLine(prefix & "MRN: " & Convert.ToString(ZOLL.za_MRN))
|
||||
Debug.WriteLine(prefix & "LRN: " & Convert.ToString(ZOLL.za_LRN))
|
||||
Debug.WriteLine(prefix & "AvisoId: " & Convert.ToString(ZOLL.za_AvisoId))
|
||||
Debug.WriteLine(prefix & "SendungsId: " & Convert.ToString(ZOLL.za_SendungsId))
|
||||
|
||||
If Not ZOLL.za_SendungsId.HasValue OrElse ZOLL.za_SendungsId.Value <= 0 Then
|
||||
Debug.WriteLine(prefix & "ABBRUCH: Keine SendungsId")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
'Auftraggeber prüfen
|
||||
Dim SND As New VERAG_PROG_ALLGEMEIN.cSendungen(ZOLL.za_SendungsId.Value)
|
||||
|
||||
Debug.WriteLine(prefix & "Auftraggeber: " & Convert.ToString(SND.tblSnd_Auftraggeber))
|
||||
Debug.WriteLine(prefix & "Kundennummer: " & Convert.ToString(SND.tblSnd_AuftraggeberKdNr))
|
||||
|
||||
Dim kundenNr As Integer
|
||||
If Not Integer.TryParse(Convert.ToString(SND.tblSnd_AuftraggeberKdNr), kundenNr) Then
|
||||
Debug.WriteLine(prefix & "ABBRUCH: Ungültige Kundennummer")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If kundenNr <> kundenNrTETRAPAK Then
|
||||
Debug.WriteLine(prefix & "ABBRUCH: Kein TETRAPAK-Auftraggeber")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
'Warenpositionen aus tblVERAG_CustomsDeclarations_Items
|
||||
Dim positionen = ZOLL.Items.OrderBy(Function(p) p.zaItem_PosNo).ToList()
|
||||
|
||||
If positionen.Count = 0 Then
|
||||
Debug.WriteLine(prefix & "ABBRUCH: Keine Warenpositionen vorhanden")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Debug.WriteLine(prefix & "Warenpositionen: " & positionen.Count)
|
||||
Debug.WriteLine(prefix & "Kopfabgaben: " & ZOLL.Duties.Count)
|
||||
|
||||
'Abgaben aus tblVERAG_CustomsDeclarations_Duties
|
||||
'Positionen und Kopf getrennt behandeln
|
||||
Dim gesamtZollPositionen As Decimal = 0D
|
||||
Dim gesamtEustPositionen As Decimal = 0D
|
||||
Dim gesamtZollKopf As Decimal = 0D
|
||||
Dim gesamtEustKopf As Decimal = 0D
|
||||
Dim anzahlPositionsabgaben As Integer = 0
|
||||
|
||||
For Each wp In positionen
|
||||
Debug.WriteLine(prefix & "Position " & wp.zaItem_PosNo & " | ItemId=" & wp.zaItem_Id & " | Abgaben=" & wp.Duties.Count)
|
||||
|
||||
For Each duty In wp.Duties
|
||||
Dim betrag As Decimal = If(duty.zaDuty_AmountEUR, 0D)
|
||||
Dim art As String = If(duty.zaDuty_DutyType, "").Trim().ToUpperInvariant()
|
||||
|
||||
Select Case art
|
||||
Case "A0000", "A00"
|
||||
gesamtZollPositionen += betrag
|
||||
Case "B0000", "B00"
|
||||
gesamtEustPositionen += betrag
|
||||
End Select
|
||||
|
||||
anzahlPositionsabgaben += 1
|
||||
|
||||
Debug.WriteLine(prefix & " Duty: " & art &
|
||||
" | Betrag=" & betrag.ToString("0.00") &
|
||||
" | ItemId=" & Convert.ToString(duty.zaDuty_zaItemId))
|
||||
Next
|
||||
Next
|
||||
|
||||
For Each duty In ZOLL.Duties
|
||||
Dim betrag As Decimal = If(duty.zaDuty_AmountEUR, 0D)
|
||||
Dim art As String = If(duty.zaDuty_DutyType, "").Trim().ToUpperInvariant()
|
||||
|
||||
Select Case art
|
||||
Case "A0000", "A00"
|
||||
gesamtZollKopf += betrag
|
||||
Case "B0000", "B00"
|
||||
gesamtEustKopf += betrag
|
||||
End Select
|
||||
|
||||
Debug.WriteLine(prefix & "Kopfabgabe: " & art & " | Betrag=" & betrag.ToString("0.00"))
|
||||
Next
|
||||
|
||||
Debug.WriteLine(prefix & "Positions-Zoll gesamt: " & gesamtZollPositionen.ToString("0.00"))
|
||||
Debug.WriteLine(prefix & "Positions-EUSt gesamt: " & gesamtEustPositionen.ToString("0.00"))
|
||||
Debug.WriteLine(prefix & "Kopf-Zoll gesamt: " & gesamtZollKopf.ToString("0.00"))
|
||||
Debug.WriteLine(prefix & "Kopf-EUSt gesamt: " & gesamtEustKopf.ToString("0.00"))
|
||||
|
||||
'Bei fehlenden Positionsabgaben keine künstliche Verteilung
|
||||
Dim nurKopfabgaben As Boolean = (anzahlPositionsabgaben = 0)
|
||||
|
||||
If nurKopfabgaben AndAlso positionen.Count > 1 AndAlso ZOLL.Duties.Count > 0 Then
|
||||
Throw New Exception("BrokerManagementFile: Es sind " & positionen.Count &
|
||||
" Warenpositionen vorhanden, aber nur Kopfabgaben gespeichert. " &
|
||||
"Eine eindeutige Verteilung von Zoll/EUSt ist nicht möglich. ZA-ID=" & ZOLL.za_Id)
|
||||
End If
|
||||
|
||||
If nurKopfabgaben AndAlso ZOLL.Duties.Count = 0 Then
|
||||
Debug.WriteLine(prefix & "WARNUNG: Keine Abgaben in der Zollanmeldung gespeichert")
|
||||
End If
|
||||
|
||||
If Not nurKopfabgaben Then
|
||||
If ZOLL.Duties.Count > 0 Then
|
||||
If gesamtZollPositionen <> gesamtZollKopf OrElse gesamtEustPositionen <> gesamtEustKopf Then
|
||||
Debug.WriteLine(prefix & "WARNUNG: Positionssummen und Kopfsummen weichen voneinander ab")
|
||||
Else
|
||||
Debug.WriteLine(prefix & "OK: Positionssummen entsprechen den Kopfsummen")
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'Anhänge über AVISO und Sendung laden
|
||||
Dim anhaenge As New List(Of VERAG_PROG_ALLGEMEIN.cAvisoAnhaenge)
|
||||
|
||||
If ZOLL.za_AvisoId.HasValue AndAlso ZOLL.za_AvisoId.Value > 0 Then
|
||||
VERAG_PROG_ALLGEMEIN.cAvisoAnhaenge.LOAD_LIST_ByAviso(anhaenge, ZOLL.za_AvisoId.Value)
|
||||
End If
|
||||
|
||||
Dim sendungsAnhaenge As New List(Of VERAG_PROG_ALLGEMEIN.cAvisoAnhaenge)
|
||||
VERAG_PROG_ALLGEMEIN.cAvisoAnhaenge.LOAD_LIST_BySendung(sendungsAnhaenge, ZOLL.za_SendungsId.Value)
|
||||
|
||||
For Each anh In sendungsAnhaenge
|
||||
If Not anhaenge.Any(Function(a) a.anh_docId = anh.anh_docId) Then anhaenge.Add(anh)
|
||||
Next
|
||||
|
||||
Debug.WriteLine(prefix & "Anhänge gefunden: " & anhaenge.Count)
|
||||
|
||||
Dim dateienGefunden As Integer = 0
|
||||
Dim dateienGespeichert As Integer = 0
|
||||
|
||||
For Each anh In anhaenge
|
||||
Debug.WriteLine(prefix & "Prüfe Anhang: " & Convert.ToString(anh.anh_Art) & " | docId=" & anh.anh_docId)
|
||||
|
||||
If Not String.Equals(Convert.ToString(anh.anh_Art).Trim(), "BrokerManagementFile", StringComparison.OrdinalIgnoreCase) Then Continue For
|
||||
If anh.anh_docId <= 0 Then Continue For
|
||||
|
||||
Dim pfad As String = (New VERAG_PROG_ALLGEMEIN.cDATENSERVER(anh.anh_docId)).GET_TOP1_PATH(False)
|
||||
|
||||
Debug.WriteLine(prefix & "Archivpfad: " & Convert.ToString(pfad))
|
||||
|
||||
If String.IsNullOrWhiteSpace(pfad) OrElse Not File.Exists(pfad) Then
|
||||
Debug.WriteLine(prefix & "Übersprungen: Archivdatei nicht gefunden")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If Not String.Equals(Path.GetExtension(pfad), ".xlsx", StringComparison.OrdinalIgnoreCase) Then
|
||||
Debug.WriteLine(prefix & "Übersprungen: Keine XLSX-Datei")
|
||||
Continue For
|
||||
End If
|
||||
|
||||
dateienGefunden += 1
|
||||
|
||||
Using wb As New XLWorkbook(pfad)
|
||||
Dim ws = wb.Worksheet(1)
|
||||
Dim letzteVerwendeteZeile = ws.LastRowUsed()
|
||||
|
||||
If letzteVerwendeteZeile Is Nothing Then
|
||||
Debug.WriteLine("BrokerManagementFile ist leer: " & pfad)
|
||||
End If
|
||||
|
||||
'Datenzeilen anhand Spalte A
|
||||
Dim datenZeilen As New List(Of Integer)
|
||||
Dim letzteZeile As Integer = letzteVerwendeteZeile.RowNumber()
|
||||
|
||||
For zeile As Integer = 2 To letzteZeile
|
||||
If Not String.IsNullOrWhiteSpace(ws.Cell(zeile, "A").GetString()) Then datenZeilen.Add(zeile)
|
||||
Next
|
||||
|
||||
Debug.WriteLine(prefix & "Excel-Zeilen: " & datenZeilen.Count)
|
||||
Debug.WriteLine(prefix & "Zollpositionen: " & positionen.Count)
|
||||
|
||||
If datenZeilen.Count <> positionen.Count Then
|
||||
Debug.WriteLine("BrokerManagementFile: Positionsanzahl stimmt nicht überein. Excel=" &
|
||||
datenZeilen.Count & ", Zollanmeldung=" & positionen.Count & ", Datei=" & pfad)
|
||||
End If
|
||||
|
||||
For i As Integer = 0 To positionen.Count - 1
|
||||
Dim wp = positionen(i)
|
||||
Dim zeile As Integer = datenZeilen(i)
|
||||
Dim posNr As Integer = wp.zaItem_PosNo
|
||||
|
||||
Dim zollbetr As Decimal = 0D
|
||||
Dim eust As Decimal = 0D
|
||||
|
||||
'Positionsabgaben aus Datenbank
|
||||
If Not nurKopfabgaben Then
|
||||
For Each duty In wp.Duties
|
||||
Dim betrag As Decimal = If(duty.zaDuty_AmountEUR, 0D)
|
||||
Dim art As String = If(duty.zaDuty_DutyType, "").Trim().ToUpperInvariant()
|
||||
Select Case art.Trim.ToUpperInvariant()
|
||||
'Zoll inkl. Zusatz-, Antidumping- und Ausgleichszoll
|
||||
Case "A0000", "A00", "A2000", "A20", "A3000", "A30", "A35", "A4000", "A40"
|
||||
zollbetr += betrag
|
||||
|
||||
'Einfuhrumsatzsteuer
|
||||
Case "B0000", "B00", "5EV"
|
||||
eust += betrag
|
||||
|
||||
'Sicherheiten, Summen und sonstige Abgaben nicht berücksichtigen
|
||||
Case "2EU", "2IG", "2KO", "2PE", "2VF", "2VS", "5EU", "5ZO", "9EA", "6BE"
|
||||
'Keine Addition
|
||||
|
||||
Case Else
|
||||
'Debug.WriteLine("Unbekannte Abgabenart: " & art & " / Betrag: " & betrag.ToString())
|
||||
zollbetr += betrag 'Default: Alle unbekannten Abgabenarten werden als Zoll behandelt
|
||||
End Select
|
||||
Next
|
||||
ElseIf positionen.Count = 1 Then
|
||||
'Nur bei einer Position sind Kopfabgaben eindeutig zuordenbar
|
||||
zollbetr = gesamtZollKopf
|
||||
eust = gesamtEustKopf
|
||||
End If
|
||||
|
||||
Debug.WriteLine(prefix & "----------------------------------------")
|
||||
Debug.WriteLine(prefix & "Position: " & posNr)
|
||||
Debug.WriteLine(prefix & "Excel-Zeile: " & zeile)
|
||||
Debug.WriteLine(prefix & "Zoll: " & zollbetr.ToString("0.00"))
|
||||
Debug.WriteLine(prefix & "EUSt: " & eust.ToString("0.00"))
|
||||
|
||||
'AZ - Registration Number ATC/ATD
|
||||
ws.Cell(zeile, "AZ").Value = If(zoll.za_DeclarationNo, "")
|
||||
|
||||
'BA - Date of Acceptance
|
||||
If zoll.za_AcceptanceDate.HasValue Then
|
||||
ws.Cell(zeile, "BA").Value = zoll.za_AcceptanceDate.Value.ToString("dd.MM.yyyy")
|
||||
Else
|
||||
ws.Cell(zeile, "BA").Value = ""
|
||||
End If
|
||||
|
||||
'BB - Registration Number MRN
|
||||
ws.Cell(zeile, "BB").Value = If(zoll.za_MRN, "")
|
||||
|
||||
'BC - Office of Entry
|
||||
ws.Cell(zeile, "BC").Value = If(zoll.za_EntryCustomsOffice, "")
|
||||
|
||||
'BD - Mode of Transport at the Border
|
||||
ws.Cell(zeile, "BD").Value = If(ZOLL.za_TransportModeBorder, If(ZOLL.za_TransportModeInland, ""))
|
||||
|
||||
'BE - Identity of means of transport at the border
|
||||
ws.Cell(zeile, "BE").Value = If(zoll.za_MeansOfTransport_Vehicle, "")
|
||||
|
||||
'BF - Nationality of means of transport at the border
|
||||
ws.Cell(zeile, "BF").Value = If(zoll.za_MeansOfTransport_Nationality, "")
|
||||
|
||||
'BG - Inland Mode of Transport
|
||||
ws.Cell(zeile, "BG").Value = If(ZOLL.za_TransportModeInland, If(ZOLL.za_TransportModeBorder, ""))
|
||||
|
||||
'BH - Identity of inland means of transport
|
||||
ws.Cell(zeile, "BH").Value = If(zoll.za_MeansOfTransport_Vehicle, "")
|
||||
|
||||
'BI - Nationality of inland means of transport
|
||||
ws.Cell(zeile, "BI").Value = If(zoll.za_MeansOfTransport_Nationality, "")
|
||||
|
||||
'BJ - Assessment of payable duty
|
||||
ws.Cell(zeile, "BJ").Value = zollbetr
|
||||
ws.Cell(zeile, "BJ").Style.NumberFormat.Format = "0.00"
|
||||
|
||||
'BK - Assessment of payable Import VAT
|
||||
ws.Cell(zeile, "BK").Value = eust
|
||||
ws.Cell(zeile, "BK").Style.NumberFormat.Format = "0.00"
|
||||
|
||||
Debug.WriteLine(prefix & "AZ=" & ws.Cell(zeile, "AZ").GetString())
|
||||
Debug.WriteLine(prefix & "BA=" & ws.Cell(zeile, "BA").GetString())
|
||||
Debug.WriteLine(prefix & "BB=" & ws.Cell(zeile, "BB").GetString())
|
||||
Debug.WriteLine(prefix & "BC=" & ws.Cell(zeile, "BC").GetString())
|
||||
Debug.WriteLine(prefix & "BD=" & ws.Cell(zeile, "BD").GetString())
|
||||
Debug.WriteLine(prefix & "BE=" & ws.Cell(zeile, "BE").GetString())
|
||||
Debug.WriteLine(prefix & "BF=" & ws.Cell(zeile, "BF").GetString())
|
||||
Debug.WriteLine(prefix & "BG=" & ws.Cell(zeile, "BG").GetString())
|
||||
Debug.WriteLine(prefix & "BH=" & ws.Cell(zeile, "BH").GetString())
|
||||
Debug.WriteLine(prefix & "BI=" & ws.Cell(zeile, "BI").GetString())
|
||||
Debug.WriteLine(prefix & "BJ=" & zollbetr.ToString("0.00"))
|
||||
Debug.WriteLine(prefix & "BK=" & eust.ToString("0.00"))
|
||||
Next
|
||||
|
||||
|
||||
wb.Save()
|
||||
Debug.WriteLine(prefix & "Original gespeichert: " & pfad)
|
||||
|
||||
|
||||
dateienGespeichert += 1
|
||||
End Using
|
||||
Next
|
||||
|
||||
Debug.WriteLine(prefix & "BrokerManagementFiles gefunden: " & dateienGefunden)
|
||||
Debug.WriteLine(prefix & "BrokerManagementFiles gespeichert: " & dateienGespeichert)
|
||||
|
||||
If dateienGefunden = 0 Then Debug.WriteLine(prefix & "WARNUNG: Kein BrokerManagementFile gefunden")
|
||||
|
||||
Catch ex As Exception
|
||||
Debug.WriteLine(prefix & "FEHLER: " & ex.ToString())
|
||||
Throw
|
||||
Finally
|
||||
Debug.WriteLine(prefix & "========== ENDE BrokerManagementFile ==========")
|
||||
End Try
|
||||
End Sub
|
||||
' =====================================================================
|
||||
' NCTS 004 -> VERAG TRANSIT
|
||||
' =====================================================================
|
||||
|
||||
Reference in New Issue
Block a user