|
|
|
|
@@ -3974,7 +3974,8 @@ Class cSpeditionsbuchReport
|
|
|
|
|
AbfVon As Date,
|
|
|
|
|
AbfBis As Date,
|
|
|
|
|
Optional whereStr As String = "",
|
|
|
|
|
Optional Open As Boolean = True) As String
|
|
|
|
|
Optional Open As Boolean = True,
|
|
|
|
|
Optional DL_Kosten As Boolean = False) As String
|
|
|
|
|
Try
|
|
|
|
|
Dim dt As DataTable = LoadSpeditionsbuchData(KDNR, AbfVon, AbfBis, whereStr)
|
|
|
|
|
If dt Is Nothing OrElse dt.Rows.Count = 0 Then
|
|
|
|
|
@@ -3997,7 +3998,7 @@ Class cSpeditionsbuchReport
|
|
|
|
|
blatt = datei.Worksheets(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CreateDetailReport(blatt, dt, KDNR)
|
|
|
|
|
CreateDetailReport(blatt, dt, KDNR, DL_Kosten)
|
|
|
|
|
' CreateGeneralReport(blatt, dt, KDNR, AbfVon, AbfBis)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4160,7 +4161,7 @@ Class cSpeditionsbuchReport
|
|
|
|
|
Return cd
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Sub CreateDetailReport(blatt As Object, dt As DataTable, kdnr As Integer)
|
|
|
|
|
Private Sub CreateDetailReport(blatt As Object, dt As DataTable, kdnr As Integer, Optional DL_Kosten As Boolean = False)
|
|
|
|
|
Dim cnt As Integer = 2
|
|
|
|
|
|
|
|
|
|
For Each r As DataRow In dt.Rows
|
|
|
|
|
@@ -4174,7 +4175,7 @@ Class cSpeditionsbuchReport
|
|
|
|
|
If(r("AbfertigungsNr"), "").ToString())
|
|
|
|
|
End If
|
|
|
|
|
's
|
|
|
|
|
WriteDetailReportRow(blatt, r, cd, cnt, kdnr)
|
|
|
|
|
WriteDetailReportRow(blatt, r, cd, cnt, kdnr, DL_Kosten)
|
|
|
|
|
|
|
|
|
|
Catch ex As Exception
|
|
|
|
|
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
|
|
|
|
|
@@ -4211,6 +4212,203 @@ Class cSpeditionsbuchReport
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
Private Sub WriteDetailReportRow(blatt As Object,
|
|
|
|
|
r As DataRow,
|
|
|
|
|
cd As cVERAG_CustomsDeclarations,
|
|
|
|
|
ByRef cnt As Integer,
|
|
|
|
|
kdnrsrch As Integer,
|
|
|
|
|
Optional DL_Kosten As Boolean = False)
|
|
|
|
|
|
|
|
|
|
Dim kdAtrNr As String = NormalizeKdAuftragsNr(r("KdAuftragsNr"), kdnrsrch)
|
|
|
|
|
|
|
|
|
|
Dim dienstleistungsKosten As Decimal = 0D
|
|
|
|
|
|
|
|
|
|
If DL_Kosten Then
|
|
|
|
|
blatt.Range("AF1").Value = "Service Costs"
|
|
|
|
|
dienstleistungsKosten = GetDienstleistungskosten(r, kdnrsrch)
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
If cd IsNot Nothing AndAlso cd.hasEntry Then
|
|
|
|
|
|
|
|
|
|
Dim empfaenger As String = GetPartyName(cd, cVERAG_CustomsDeclarations.IMPORTER_ROLES, "")
|
|
|
|
|
Dim absender As String = GetPartyName(cd, cVERAG_CustomsDeclarations.EXPORTER_ROLES, "")
|
|
|
|
|
|
|
|
|
|
If cd.Items IsNot Nothing AndAlso cd.Items.Count > 0 Then
|
|
|
|
|
|
|
|
|
|
For Each item As cVERAG_CustomsDeclarations_Item In cd.Items
|
|
|
|
|
|
|
|
|
|
' Abgaben kommen jetzt von der Position
|
|
|
|
|
Dim eustBetrag As Decimal = GetDutyAmount(item, {"B%", "B00", "EUST", "VAT"})
|
|
|
|
|
Dim zollBetrag As Decimal = GetDutyAmountExcluding(item, {"B%", "B00", "EUST", "VAT"})
|
|
|
|
|
|
|
|
|
|
Dim itemInvoiceAmount As Decimal =
|
|
|
|
|
If(item.zaItem_InvoiceValueForeign, item.zaItem_InvoiceValueEUR)
|
|
|
|
|
|
|
|
|
|
Dim zollInProzent As Double = 0
|
|
|
|
|
|
|
|
|
|
If itemInvoiceAmount <> 0 Then
|
|
|
|
|
zollInProzent = CDbl(zollBetrag / itemInvoiceAmount * 100D)
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
blatt.Range("A" & cnt).Value = cnt - 1
|
|
|
|
|
blatt.Range("B" & cnt).Value = r("Abfertigungsdatum")
|
|
|
|
|
blatt.Range("C" & cnt).Value = VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(r("FilialenNr"))
|
|
|
|
|
blatt.Range("D" & cnt).Value = empfaenger
|
|
|
|
|
blatt.Range("E" & cnt).Value = r("FilialenNr") & "/" & r("AbfertigungsNr")
|
|
|
|
|
blatt.Range("F" & cnt).Value = kdAtrNr
|
|
|
|
|
blatt.Range("G" & cnt).Value =
|
|
|
|
|
If(Not String.IsNullOrWhiteSpace(If(r("BelegNr"), "").ToString()),
|
|
|
|
|
r("BelegNr"),
|
|
|
|
|
cd.za_MRN)
|
|
|
|
|
|
|
|
|
|
blatt.Range("H" & cnt).Value = item.zaItem_PosNo
|
|
|
|
|
blatt.Range("I" & cnt).Value = item.zaItem_HSCode
|
|
|
|
|
blatt.Range("J" & cnt).Value = "-"
|
|
|
|
|
blatt.Range("K" & cnt).Value = item.zaItem_Description
|
|
|
|
|
blatt.Range("L" & cnt).Value = ""
|
|
|
|
|
|
|
|
|
|
blatt.Range("M" & cnt).Value =
|
|
|
|
|
If(Not String.IsNullOrWhiteSpace(If(item.zaItem_InvoiceCurrency, "")),
|
|
|
|
|
item.zaItem_InvoiceCurrency,
|
|
|
|
|
cd.za_InvoiceCurrency)
|
|
|
|
|
|
|
|
|
|
blatt.Range("N" & cnt).Value = item.zaItem_MainProcedure
|
|
|
|
|
blatt.Range("O" & cnt).Value = cd.za_EntryCustomsOffice
|
|
|
|
|
blatt.Range("P" & cnt).Value = If(item.zaItem_PosNo = 1, cd.za_TotGrossMass, "")
|
|
|
|
|
blatt.Range("Q" & cnt).Value = item.zaItem_NetMass
|
|
|
|
|
blatt.Range("R" & cnt).Value = itemInvoiceAmount
|
|
|
|
|
blatt.Range("S" & cnt).Value = eustBetrag
|
|
|
|
|
blatt.Range("T" & cnt).Value = zollBetrag
|
|
|
|
|
blatt.Range("U" & cnt).Value = zollInProzent.ToString("N2") & " %"
|
|
|
|
|
blatt.Range("V" & cnt).Value = cd.za_CountryDispatch
|
|
|
|
|
blatt.Range("W" & cnt).Value = absender
|
|
|
|
|
blatt.Range("X" & cnt).Value = item.zaItem_OriginCountry
|
|
|
|
|
blatt.Range("Y" & cnt).Value = cd.za_CountryDestination
|
|
|
|
|
blatt.Range("Z" & cnt).Value = cd.za_Incoterms
|
|
|
|
|
blatt.Range("AA" & cnt).Value = cd.za_IncotermsPlace
|
|
|
|
|
|
|
|
|
|
blatt.Range("AB" & cnt).Value =
|
|
|
|
|
item.zaItem_MainProcedure &
|
|
|
|
|
If(Not String.IsNullOrWhiteSpace(item.zaItem_AdditionalProc),
|
|
|
|
|
"/" & item.zaItem_AdditionalProc,
|
|
|
|
|
"")
|
|
|
|
|
|
|
|
|
|
blatt.Range("AC" & cnt).Value = item.zaItem_PreferenceCode
|
|
|
|
|
blatt.Range("AD" & cnt).Value = If(IsItemCBAM(item), "Y", "N")
|
|
|
|
|
blatt.Range("AE" & cnt).Value = item.GetInvoiceListString()
|
|
|
|
|
|
|
|
|
|
If DL_Kosten Then
|
|
|
|
|
blatt.Range("AF" & cnt).Value = dienstleistungsKosten
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
|
|
Next
|
|
|
|
|
|
|
|
|
|
Else
|
|
|
|
|
|
|
|
|
|
'Fallback: wenn keine Positionen vorhanden sind,
|
|
|
|
|
'weiterhin Header-Duties verwenden
|
|
|
|
|
|
|
|
|
|
Dim eustBetrag As Decimal =
|
|
|
|
|
GetDutyAmount(cd, {"B%", "B00", "EUST", "VAT"})
|
|
|
|
|
|
|
|
|
|
Dim zollBetrag As Decimal =
|
|
|
|
|
GetDutyAmountExcluding(cd, {"B%", "B00", "EUST", "VAT"})
|
|
|
|
|
|
|
|
|
|
Dim invoiceAmount As Decimal = If(cd.za_InvoiceAmount, 0D)
|
|
|
|
|
|
|
|
|
|
Dim zollInProzent As Double = 0
|
|
|
|
|
|
|
|
|
|
If invoiceAmount <> 0 Then
|
|
|
|
|
zollInProzent = CDbl(zollBetrag / invoiceAmount * 100D)
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
blatt.Range("A" & cnt).Value = cnt - 1
|
|
|
|
|
blatt.Range("B" & cnt).Value = r("Abfertigungsdatum")
|
|
|
|
|
blatt.Range("C" & cnt).Value = VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(r("FilialenNr"))
|
|
|
|
|
blatt.Range("D" & cnt).Value = empfaenger
|
|
|
|
|
blatt.Range("E" & cnt).Value = r("FilialenNr") & "/" & r("AbfertigungsNr")
|
|
|
|
|
blatt.Range("F" & cnt).Value = kdAtrNr
|
|
|
|
|
|
|
|
|
|
blatt.Range("G" & cnt).Value =
|
|
|
|
|
If(Not String.IsNullOrWhiteSpace(If(r("BelegNr"), "").ToString()),
|
|
|
|
|
r("BelegNr"),
|
|
|
|
|
cd.za_MRN)
|
|
|
|
|
|
|
|
|
|
blatt.Range("H" & cnt).Value = ""
|
|
|
|
|
blatt.Range("I" & cnt).Value = ""
|
|
|
|
|
blatt.Range("J" & cnt).Value = "-"
|
|
|
|
|
blatt.Range("K" & cnt).Value = ""
|
|
|
|
|
blatt.Range("L" & cnt).Value = ""
|
|
|
|
|
blatt.Range("M" & cnt).Value = cd.za_InvoiceCurrency
|
|
|
|
|
blatt.Range("N" & cnt).Value = cd.za_MainProcedure
|
|
|
|
|
blatt.Range("O" & cnt).Value = cd.za_EntryCustomsOffice
|
|
|
|
|
blatt.Range("P" & cnt).Value = cd.za_TotGrossMass
|
|
|
|
|
blatt.Range("Q" & cnt).Value = ""
|
|
|
|
|
blatt.Range("R" & cnt).Value = cd.za_InvoiceAmount
|
|
|
|
|
blatt.Range("S" & cnt).Value = eustBetrag
|
|
|
|
|
blatt.Range("T" & cnt).Value = zollBetrag
|
|
|
|
|
blatt.Range("U" & cnt).Value = zollInProzent.ToString("N2") & " %"
|
|
|
|
|
blatt.Range("V" & cnt).Value = cd.za_CountryDispatch
|
|
|
|
|
blatt.Range("W" & cnt).Value = absender
|
|
|
|
|
blatt.Range("X" & cnt).Value = ""
|
|
|
|
|
blatt.Range("Y" & cnt).Value = cd.za_CountryDestination
|
|
|
|
|
blatt.Range("Z" & cnt).Value = cd.za_Incoterms
|
|
|
|
|
blatt.Range("AA" & cnt).Value = cd.za_IncotermsPlace
|
|
|
|
|
blatt.Range("AB" & cnt).Value = ""
|
|
|
|
|
blatt.Range("AC" & cnt).Value = ""
|
|
|
|
|
blatt.Range("AD" & cnt).Value = ""
|
|
|
|
|
blatt.Range("AE" & cnt).Value = ""
|
|
|
|
|
|
|
|
|
|
If DL_Kosten Then
|
|
|
|
|
blatt.Range("AF" & cnt).Value = dienstleistungsKosten
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
Else
|
|
|
|
|
|
|
|
|
|
blatt.Range("A" & cnt).Value = cnt - 1
|
|
|
|
|
blatt.Range("B" & cnt).Value = r("Abfertigungsdatum")
|
|
|
|
|
blatt.Range("C" & cnt).Value = VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(r("FilialenNr"))
|
|
|
|
|
blatt.Range("D" & cnt).Value = r("Empfänger")
|
|
|
|
|
blatt.Range("E" & cnt).Value = r("FilialenNr") & "/" & r("AbfertigungsNr")
|
|
|
|
|
blatt.Range("F" & cnt).Value = kdAtrNr
|
|
|
|
|
blatt.Range("G" & cnt).Value = r("BelegNr")
|
|
|
|
|
|
|
|
|
|
If DL_Kosten Then
|
|
|
|
|
blatt.Range("AF" & cnt).Value = dienstleistungsKosten
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
Private Function GetDienstleistungskosten(r As DataRow, kdnrsrch As Integer) As Decimal
|
|
|
|
|
Try
|
|
|
|
|
Dim sqlstr As String =
|
|
|
|
|
"SELECT ISNULL(SUM(pos.SteuerfreierBetrag + pos.SteuerpflichtigerBetrag), 0) " &
|
|
|
|
|
"FROM Rechnungsausgang RK " &
|
|
|
|
|
"INNER JOIN RechnungsausgangPositionen POS ON RK.RK_ID = POS.RK_ID " &
|
|
|
|
|
"INNER JOIN Leistungen ON POS.LeistungsNr = Leistungen.LeistungsNr " &
|
|
|
|
|
"WHERE RK.FilialenNr = " & CInt(r("FilialenNr")) & " " &
|
|
|
|
|
"AND RK.AbfertigungsNr = " & CInt(r("AbfertigungsNr")) & " " &
|
|
|
|
|
"AND Leistungen.Abfertigungskosten = 1 " &
|
|
|
|
|
"AND Leistungen.abzugsfaehigInZZ = 0 " &
|
|
|
|
|
"AND RK.RechnungsKundenNr = " & kdnrsrch
|
|
|
|
|
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
|
|
|
|
|
|
|
|
|
|
Return SQL.getValueTxtBySql(sqlstr, "FMZOLL",,, 0)
|
|
|
|
|
|
|
|
|
|
Catch
|
|
|
|
|
Return 0D
|
|
|
|
|
End Try
|
|
|
|
|
End Function
|
|
|
|
|
Private Sub WriteDetailReportRow_OLD(blatt As Object,
|
|
|
|
|
r As DataRow,
|
|
|
|
|
cd As cVERAG_CustomsDeclarations,
|
|
|
|
|
ByRef cnt As Integer,
|
|
|
|
|
@@ -4379,6 +4577,22 @@ Class cSpeditionsbuchReport
|
|
|
|
|
Sum(Function(d) If(d.zaDuty_AmountEUR, 0D))
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Function GetDutyAmount(cd As cVERAG_CustomsDeclarations_Item, dutyTypes As String()) As Decimal
|
|
|
|
|
If cd Is Nothing OrElse cd.Duties Is Nothing Then Return 0D
|
|
|
|
|
|
|
|
|
|
Return cd.Duties.
|
|
|
|
|
Where(Function(d) DutyTypeMatches(If(d.zaDuty_DutyType, ""), dutyTypes)).
|
|
|
|
|
Sum(Function(d) If(d.zaDuty_AmountEUR, 0D))
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Function GetDutyAmountExcluding(cd As cVERAG_CustomsDeclarations_Item, excludedDutyTypes As String()) As Decimal
|
|
|
|
|
If cd Is Nothing OrElse cd.Duties Is Nothing Then Return 0D
|
|
|
|
|
|
|
|
|
|
Return cd.Duties.
|
|
|
|
|
Where(Function(d) Not DutyTypeMatches(If(d.zaDuty_DutyType, ""), excludedDutyTypes)).
|
|
|
|
|
Sum(Function(d) If(d.zaDuty_AmountEUR, 0D))
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Function DutyTypeMatches(dutyType As String, patterns As String()) As Boolean
|
|
|
|
|
Dim value As String = If(dutyType, "").Trim().ToUpper()
|
|
|
|
|
If value = "" OrElse patterns Is Nothing Then Return False
|
|
|
|
|
@@ -4424,11 +4638,13 @@ Class cSpeditionsbuchReport
|
|
|
|
|
Distinct())
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Function IsItemCBAM(item As cVERAG_CustomsDeclarations_Item) As Boolean
|
|
|
|
|
Private Function IsItemCBAM_TNR(item As cVERAG_CustomsDeclarations_Item) As Boolean
|
|
|
|
|
Try
|
|
|
|
|
If item Is Nothing Then Return False
|
|
|
|
|
|
|
|
|
|
Dim cbamList = VERAG_PROG_ALLGEMEIN.cGreendeal_CBAM_Trn.LoadCBAMTariffNumbers()
|
|
|
|
|
If VERAG_PROG_ALLGEMEIN.cAllgemein.CBAM_LIST Is Nothing Then VERAG_PROG_ALLGEMEIN.cAllgemein.CBAM_LIST = cGreendeal_CBAM_Trn.LoadCBAMTariffNumbers
|
|
|
|
|
|
|
|
|
|
Dim cbamList = VERAG_PROG_ALLGEMEIN.cAllgemein.CBAM_LIST ' VERAG_PROG_ALLGEMEIN.cGreendeal_CBAM_Trn.LoadCBAMTariffNumbers()
|
|
|
|
|
Dim hs = If(item.zaItem_HSCode, "").Trim()
|
|
|
|
|
|
|
|
|
|
If hs = "" OrElse cbamList Is Nothing Then Return False
|
|
|
|
|
@@ -4441,6 +4657,50 @@ Class cSpeditionsbuchReport
|
|
|
|
|
|
|
|
|
|
Return False
|
|
|
|
|
End Function
|
|
|
|
|
Private Function IsItemCBAM(item As cVERAG_CustomsDeclarations_Item) As Boolean
|
|
|
|
|
|
|
|
|
|
Try
|
|
|
|
|
|
|
|
|
|
If item Is Nothing Then Return False
|
|
|
|
|
|
|
|
|
|
' Ursprungsland prüfen (nicht CBAM-pflichtige Länder ausschließen)
|
|
|
|
|
Dim originCountry = If(item.zaItem_OriginCountry, "").Trim().ToUpper()
|
|
|
|
|
|
|
|
|
|
Select Case originCountry
|
|
|
|
|
' EU-27
|
|
|
|
|
Case "AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR",
|
|
|
|
|
"DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL",
|
|
|
|
|
"PL", "PT", "RO", "SK", "SI", "ES", "SE", ' Ausnahmen
|
|
|
|
|
"CH", ' Schweiz
|
|
|
|
|
"NO", ' Norwegen
|
|
|
|
|
"IS", ' Island
|
|
|
|
|
"LI", ' Liechtenstein
|
|
|
|
|
"XI" ' Nordirland
|
|
|
|
|
|
|
|
|
|
Return False
|
|
|
|
|
End Select
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If VERAG_PROG_ALLGEMEIN.cAllgemein.CBAM_LIST Is Nothing Then VERAG_PROG_ALLGEMEIN.cAllgemein.CBAM_LIST = cGreendeal_CBAM_Trn.LoadCBAMTariffNumbers
|
|
|
|
|
|
|
|
|
|
Dim cbamList = VERAG_PROG_ALLGEMEIN.cAllgemein.CBAM_LIST ' VERAG_PROG_ALLGEMEIN.cGreendeal_CBAM_Trn.LoadCBAMTariffNumbers()
|
|
|
|
|
|
|
|
|
|
Dim hs = If(item.zaItem_HSCode, "").Trim()
|
|
|
|
|
|
|
|
|
|
If hs = "" OrElse cbamList Is Nothing Then Return False
|
|
|
|
|
|
|
|
|
|
For Each p In cbamList
|
|
|
|
|
|
|
|
|
|
If hs.StartsWith(If(p, "").Trim()) Then Return True
|
|
|
|
|
|
|
|
|
|
Next
|
|
|
|
|
|
|
|
|
|
Catch
|
|
|
|
|
End Try
|
|
|
|
|
|
|
|
|
|
Return False
|
|
|
|
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Private Function NormalizeKdAuftragsNr(value As Object, kdnrsrch As Integer) As String
|
|
|
|
|
Dim kdAtrNr As String = If(value, "").ToString()
|
|
|
|
|
|