This commit is contained in:
2026-01-05 15:19:26 +01:00
parent 2187035214
commit 3a30253c2d
14 changed files with 3160 additions and 225 deletions

View File

@@ -146,14 +146,7 @@ Public Class cATEZ_Greenpulse_CBAM_CostCalculation
' ------------------------------------------------------------------------
' calcCBAM mit automatischem Fallback auf CN-Code Defaults
' ------------------------------------------------------------------------
Public Shared Function calcCBAM(
cn_code As String,
weight As Object,
country_code As String,
Optional see_total As Object = Nothing,
Optional year As Object = Nothing,
Optional benchmark_value As Object = Nothing
) As String
Public Shared Function calcCBAM(cn_code As String, weight As Object, country_code As String, Optional ByRef see_total As Object = Nothing, Optional year As Object = Nothing, Optional ByRef benchmark_value As Object = Nothing, Optional ByRef CBAM_COST As Decimal = -1, Optional ByRef CBAM_EMISSION As Decimal = -1) As String
' ------------------------------------------------------------
' Basis-Validierung
@@ -207,6 +200,9 @@ Public Class cATEZ_Greenpulse_CBAM_CostCalculation
If defResp.success Then
defaultEmission = defResp.data.default_emission
defaultBenchmark = defResp.data.benchmark
benchmark_value = defaultBenchmark
see_total = defaultEmission
Else
Return $"FEHLER DEFAULTS {defResp.error.code}: {defResp.error.message}"
End If
@@ -272,7 +268,7 @@ Public Class cATEZ_Greenpulse_CBAM_CostCalculation
s &= $"Gewicht: {req.weight:N2} t" & vbCrLf
s &= vbCrLf
s &= $"Kosten: {d.cost:N2} {d.currency}" & vbCrLf
's &= $"Kosten: {d.cost:N2} {d.currency}" & vbCrLf
s &= $"CBAM Emission: {d.cbam_emission:N5}" & vbCrLf
s &= $"Benchmark: {d.benchmark:N5}" & vbCrLf
s &= $"Phase-Faktor: {d.phase_factor:P2}" & vbCrLf
@@ -281,12 +277,96 @@ Public Class cATEZ_Greenpulse_CBAM_CostCalculation
If Not String.IsNullOrWhiteSpace(d.info_message) Then
s &= vbCrLf & "Info: " & d.info_message & vbCrLf
End If
s &= vbCrLf
s &= $"CBAM Kosten: {d.cost:N2} {d.currency}" & vbCrLf
CBAM_COST = d.cost
CBAM_EMISSION = see_total
Return s
End Function
Public Shared Function calcCBAM_ByCertificatePrice(cn_code As String, weight As Object, country_code As String, certificate_price As Object, year As Object, Optional ByRef CBAM_COST As Decimal = -1, Optional ByRef CBAM_EMISSION As Decimal = -1) As String
' ------------------------------------------------------------
' Validierung
' ------------------------------------------------------------
If cn_code Is Nothing OrElse Not IsNumeric(cn_code) _
OrElse Not {4, 6, 8}.Contains(cn_code.Length) Then
Return "Fehler: CN-Code muss 4-, 6- oder 8-stellig numerisch sein"
End If
If weight Is Nothing OrElse Not IsNumeric(weight) OrElse CDbl(weight) <= 0 Then
Return "Fehler: Gewicht muss > 0 sein"
End If
If country_code Is Nothing OrElse country_code.Length <> 2 Then
Return "Fehler: country_code muss ISO-2 sein"
End If
If certificate_price Is Nothing OrElse Not IsNumeric(certificate_price) OrElse CDbl(certificate_price) <= 0 Then
Return "Fehler: Zertifikatspreis muss > 0 sein"
End If
If year Is Nothing Or Not IsNumeric(year) Then
Return "Fehler: ungültiges Jahr"
End If
' ------------------------------------------------------------
' SEE total (Default-Emission) laden
' ------------------------------------------------------------
Dim api As New cATEZ_Greenpulse_CBAM_CostCalculation()
Dim see_total As Decimal
Try
Dim defResp = api.GetCnCodeDefaults(
cn_code,
country_code.ToUpperInvariant(),
CInt(year)
)
If Not defResp.success Then
Return $"FEHLER DEFAULTS {defResp.error.code}: {defResp.error.message}"
End If
If defResp.data.default_emission < 0 Then
Return "Fehler: Keine Default-Emission (see_total) verfügbar"
End If
see_total = defResp.data.default_emission
Catch ex As Exception
Return "Technischer Fehler beim Laden der CN-Code Defaults: " & ex.Message
End Try
' ------------------------------------------------------------
' Berechnung (ohne Phase-Faktor!)
' ------------------------------------------------------------
Dim w As Decimal = CDec(weight)
Dim price As Decimal = CDec(certificate_price)
Dim cbamEmission As Decimal = w * see_total
Dim cbamCost As Decimal = cbamEmission * price
' ------------------------------------------------------------
' Ausgabe
' ------------------------------------------------------------
Dim s As String = ""
s &= "CBAM Kostenberechnung (ohne Benchmark)" & vbCrLf
s &= "-----------------------------------------------------------" & vbCrLf
s &= $"CN-Code: {cn_code}" & vbCrLf
s &= $"Ursprungsland: {country_code.ToUpperInvariant()}" & vbCrLf
s &= $"Gewicht: {w:N2} t" & vbCrLf
s &= $"SEE total (Default): {see_total:N5}" & vbCrLf
s &= $"CBAM Emission: {cbamEmission:N5} t CO₂" & vbCrLf
s &= $"Zertifikatspreis: {price:N2} EUR/t" & vbCrLf
s &= vbCrLf
s &= $"CBAM Kosten: {cbamCost:N2} EUR" & vbCrLf
CBAM_COST = cbamCost
CBAM_EMISSION = see_total
Return s
End Function
' ------------------------------------------------------------------------
' Helpers
' ------------------------------------------------------------------------

View File

@@ -46,6 +46,13 @@ Public Class cATEZ_Greenpulse_KafkaDecs
Dim m = (mrn).ToUpperInvariant()
Return String.Join(SEP_PIPE, New String() {KEY_VERSION, c, s, m})
End Function
Public Shared Function GetUniqueKey_Pipe_FromVERAG_CustomsDec(CD As VERAG_PROG_ALLGEMEIN.cVERAG_CustomsDeclarations, Optional mrn As String = "") As String
Dim c = (If(CD.za_CountryImport, CD.za_CustomsSystemCountry)).ToUpperInvariant()
Dim s = (If(CD.za_System, CD.za_CustomsSystem)).ToUpperInvariant()
Dim m = (If(mrn = "", CD.za_MRN, mrn)).ToUpperInvariant()
Return String.Join(SEP_PIPE, New String() {KEY_VERSION, c, s, m})
End Function
'========================
'== Datenobjekte lt. UDM-Schema