Files
ADMIN/DAKOSY_Worker/cImporter_MICToVERAG.vb
2026-09-28 08:56:33 +02:00

728 lines
32 KiB
VB.net

Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Imports VERAG_PROG_ALLGEMEIN
Imports VERAG_PROG_ALLGEMEIN.MicCustImportMessage
Public Class cImporter_MICToVERAG
Private SQL As New VERAG_PROG_ALLGEMEIN.SQL
' ========================================================================
' MAIN ENTRY
' ========================================================================
Public Function ImporMICCustoms(doc As String, xmldoc As XmlDocument, type As String, Optional overwrite As Boolean = True, Optional freshInsert As Boolean = False) As Boolean
If doc Is Nothing Then Return False
Return ImportMIcCustom(doc, xmldoc, type, overwrite, freshInsert)
Return False
End Function
Public Function ImportMIcCustom(doc As String, xmldoc As XmlDocument, type As String, Optional overwrite As Boolean = True, Optional freshInsert As Boolean = False) As Boolean
Try
If doc Is Nothing Then Return False
Select Case type
Case "IMPORT"
Dim IMP_Message_new As MicCustImportMessage = LoadMicImport(xmldoc)
Dim IMP_Message As MicCustImportMessage = MicCustImportMessage.LoadFromFile(doc)
setData_Import(IMP_Message_new, type)
Case "EXPORT"
Dim EXP_Shipment As MicCustExportShipment.ExportShipment = MicCustExportShipment.ExportShipment.LoadFromFile(doc)
setData_Import(EXP_Shipment, type)
Case "NCTS"
Dim NCTS_TransitDeclaration As MicNctsTransitDeclarationP5.TransitDeclaration = MicNctsTransitDeclarationP5.TransitDeclaration.LoadFromFile(doc)
setData_Import(NCTS_TransitDeclaration, type)
End Select
Catch ex As Exception
cErrorHandler.ERR(ex.Message, ex.StackTrace, Reflection.MethodInfo.GetCurrentMethod.Name)
Return False
End Try
End Function
Shared Function LoadMicImport(doc As XmlDocument) As MicCustImportMessage
Dim body As XmlElement = Nothing
For Each el As XmlElement In doc.SelectNodes("//*[local-name()='Body' and @messageType]")
If UCase(el.GetAttribute("messageType")) = "CUSTIMPORT" Then
body = el : Exit For
End If
Next
If body Is Nothing Then Throw New InvalidOperationException("Kein CUSTIMPORT-Body gefunden.")
Dim inner As String = body.InnerText.Trim()
Dim innerDoc As New XmlDocument()
innerDoc.LoadXml(inner)
' Alle Blattelemente (ohne Kindelemente) mit exaktem Inhalt "Y"/"N" patchen
For Each el As XmlElement In innerDoc.SelectNodes("//*[not(*)]")
Dim txt As String = el.InnerText.Trim()
If txt = "Y" Then
el.InnerText = "true"
ElseIf txt = "N" Then
el.InnerText = "false"
ElseIf txt = "" Then
' leeres optionales Element entfernen -> Serializer nutzt Default statt Formatfehler
el.ParentNode.RemoveChild(el)
ElseIf System.Text.RegularExpressions.Regex.IsMatch(txt, "^-?\d{1,3}(\.\d{3})*,\d+$") Then
el.InnerText = txt.Replace(".", "").Replace(",", ".")
ElseIf System.Text.RegularExpressions.Regex.IsMatch(txt, "^-?\d+,\d+$") Then
el.InnerText = txt.Replace(",", ".")
End If
Next
Try
Using sr As New StringReader(innerDoc.OuterXml)
Dim ser As New XmlSerializer(GetType(MicCustImportMessage))
Return CType(ser.Deserialize(sr), MicCustImportMessage)
End Using
Catch ex As InvalidOperationException
Throw New Exception(ex.Message & vbCrLf & If(ex.InnerException?.Message, "keine InnerException"), ex)
End Try
End Function
Private Function setData_Import(IMP_Message As Object, type As String)
If type = "IMPORT" Then
IMP_Message = TryCast(IMP_Message, MicCustImportMessage)
ElseIf type = "EXPORT" Then
IMP_Message = TryCast(IMP_Message, MicCustExportShipment.ExportShipment)
End If
' ================================================================
' HEADER
' ================================================================
Dim ZA As cVERAG_CustomsDeclarations
If IMP_Message IsNot Nothing AndAlso IMP_Message.Shipment IsNot Nothing Then
If IMP_Message.Shipment.ShipmentHead IsNot Nothing Then
Dim SH = IMP_Message.Shipment.ShipmentHead
If SH.mrn <> "" Then
ZA = cVERAG_CustomsDeclarations.loadByMRN(SH.mrn, True)
Else
ZA = New cVERAG_CustomsDeclarations
End If
ZA.za_System = "MIC"
ZA.za_CustomsSystem = "ATLAS"
ZA.za_REGIME = "IMPORT"
ZA.za_CustomsSystemCountry = "AT" ' Import -> AT (siehe importState/officeEntry)
ZA.za_IsExternalSystem = False
ZA.za_IsFinalDeclaration = True
ZA.za_Firma = IMP_Message.Shipment.company
ZA.za_Niederlassung = IMP_Message.Shipment.plant ' oder mic_ci.eza_niederlassung
ZA.za_MRN = SH.mrn
ZA.za_LRN = IMP_Message.Shipment.shipmentId ' shipmentId als LRN-Referenz
' declType: type1 = Verfahren (IM), type2 = Zusatz (A)
If SH.declType IsNot Nothing Then
ZA.za_MainProcedure = SH.declType.type1 ' z.B. "IM"
'ZA.za_MainProcedureAddCode = SH.declType.type2 ' z.B. "A"
End If
ZA.za_DeclarationDate = ToNullableDate(SH.customsDate)
ZA.za_ReleaseDate = ToNullableDate(SH.importDate)
ZA.za_TotGrossMass = ToNullableDecimal(SH.grossWeight)
ZA.za_CountryDispatch = SH.dispatchCountry
ZA.za_CountryDestination = SH.importState ' AT
ZA.za_CountryDestinationState = SH.destinationRegion ' OOE
'ZA.za_PlaceOfLoading = SH.departurePlace ' LINZ VOEST RAMP 12
'ZA.za_PlaceOfUnloading = SH.destinationPlace ' LINZ WAREHOUSE A12
ZA.za_CustomsOffice = SH.officeEntry ' AT600000
'ZA.za_Incoterms = SH.carriageCosts ' falls vorhanden
'ZA.za_IncotermsPlace = SH.placeDest
'If SH.CustomerFields IsNot Nothing Then
' ZA.za_Text1 = SH.CustomerFields.text1
' ZA.za_Text2 = SH.CustomerFields.text2
'End If
VERAG_PROG_ALLGEMEIN.cProgramFunctions.tryGetFirmaNiederlassung(ZA.za_Firma, ZA.za_Niederlassung, "", ZA.za_LRN)
VERAG_PROG_ALLGEMEIN.cProgramFunctions.tryGetAvisoId_SndId_ByLRN(ZA.za_LRN, ZA.za_AvisoId, ZA.za_SendungsId)
End If
End If
' ================================================================
' ADRESSEN / PARTNERS
' ================================================================
If IMP_Message.Shipment.Partners IsNot Nothing Then
For Each pt In IMP_Message.Shipment.Partners.Partner
Dim party As New cVERAG_CustomsDeclarations_Parties
party.zaParty_Role = pt.partnerRole
party.zaParty_EORI = pt.PartnerAddress.addrEori
'party.zaParty_Name = pt.PartnerAddress.addrName
party.zaParty_Street = pt.PartnerAddress.addrStreet
party.zaParty_PostalCode = pt.PartnerAddress.addrZip
party.zaParty_City = pt.PartnerAddress.addrLoc
party.zaParty_Country = pt.PartnerAddress.addrCtry
party.zaParty_TIN = pt.PartnerAddress.addrTin
party.zaParty_VATNumber = pt.PartnerAddress.addrVatNumber
party.zaParty_Email = pt.PartnerAddress.email
If If(party.zaParty_EORI, "") <> "" Then
Dim AD As VERAG_PROG_ALLGEMEIN.cAdressen = cZOLL_IMPORT.getAdresseFromEORI(party.zaParty_EORI, "", "", True)
If AD IsNot Nothing Then
party.zaParty_Name = (If(AD.Name_1, "") & " " & If(AD.Name_2, "")).Trim
party.zaParty_Country = VERAG_PROG_ALLGEMEIN.cProgramFunctions.getISO2Land(AD.LandKz)
party.zaParty_City = AD.Ort
party.zaParty_Street = AD.Straße
party.zaParty_PostalCode = AD.PLZ
End If
End If
ZA.Parties.Add(party)
Next
End If
' ================================================================
' ZUSATZKOSTEN (AdditionalCosts) -> ABGABEN/KOSTEN
' ================================================================
'If IMP_Message.Shipment.ad IsNot Nothing Then
' For Each ac In IMP_Message.Shipment.AdditionalCosts
' Dim cost As New cVERAG_CustomsDeclarations_Duty
' cost.zaDuty_DutyType = ac.addType ' z.B. "HD"
' cost.zaDuty_AmountForeign = ToNullableDecimal(ac.addAmount)
' cost.zaDuty_Currency = ac.addCurrency ' EUR
' 'cost.zaDuty_ProRating = ToNullableBool(ac.addProRating) ' Y/N
' ZA.Duties.Add(cost)
' Next
'End If
' ================================================================
' ZUSATZINFORMATIONEN (AdditionalInformation)
' ================================================================
If IMP_Message.Shipment.AdditionalInformation IsNot Nothing Then
For Each ai As TMicAttribute In IMP_Message.Shipment.AdditionalInformation.Attribute
Dim doc As New cVERAG_CustomsDeclarations_Document
doc.zaDoc_Code = ai.attrType
doc.zaDoc_Reference = ai.attrText
doc.zaDoc_Section = "ADDINFO"
ZA.Documents.Add(doc)
Next
End If
' ================================================================
' RECHNUNGEN + POSITIONEN
' ================================================================
If IMP_Message.Invoice IsNot Nothing Then
For Each inv As TMicInvoice In IMP_Message.Invoice
' ---- Rechnungskopf ----
' ZA-Rechnungsdaten am Kopf setzen (letzte/erste Rechnung):
If inv.InvoiceHead IsNot Nothing Then
ZA.za_InvoiceAmount = ToNullableDecimal(inv.InvoiceHead.invoiceValue)
ZA.za_InvoiceCurrency = inv.InvoiceHead.invoiceCurrency
'ZA.za_invoice = inv.InvoiceHead.invoiceNo
'ZA.za_InvoiceDate = ToNullableDate(inv.InvoiceHead.invoiceDate)
' shipTo als Empfänger-Party ergänzen (optional):
If inv.InvoiceHead.consignee IsNot Nothing Then
Dim party As New cVERAG_CustomsDeclarations_Parties
party.zaParty_Role = "CN" ' Consignee
party.zaParty_Name = inv.InvoiceHead.consignee
'party.zaParty_Street = inv.InvoiceHead.shipTo.addrStreet
'party.zaParty_PostalCode = inv.InvoiceHead.shipTo.addrZip
'party.zaParty_City = inv.InvoiceHead.shipTo.addrLoc
'party.zaParty_Country = inv.InvoiceHead.shipTo.addrCtry
ZA.Parties.Add(party)
End If
End If
' ---- Positionen ----
If inv.InvoiceLines IsNot Nothing Then
For Each ln As TMicInvoiceLine In inv.InvoiceLines.Line
Dim item As New cVERAG_CustomsDeclarations_Item
item.zaItem_PosNo = ToInt(ln.lineNumber)
item.zaItem_ArticleCode = ln.Item.partNumber
item.zaItem_Description = ln.Item.partDescription
' HS-Code aus TariffCode
If ln.Item.TariffCode IsNot Nothing Then
item.zaItem_HSCode = ln.Item.TariffCode.hsCode ' z.B. 8471
'item.zaItem_HSCodeType = ln.Item.TariffCode.type ' "HS"
End If
'item.zaItem_Quantity = ToNullableDecimal(ln.quantity)
'item.zaItem_QuantityUom = ln.quantityUom ' NAR
item.zaItem_NetMass = ToNullableDecimal(ln.netWeight)
item.zaItem_GrossMass = ToNullableDecimal(ln.grossWeight)
item.zaItem_InvoiceValueForeign = ToNullableDecimal(ln.price) ' Einzelpreis
'item.zaItem_LineValueForeign = ToNullableDecimal(ln.lineValue) ' Positionspreis
item.zaItem_OriginCountry = ln.countryOfOrigin
item.zaItem_MainProcedure = ln.customsProcedure ' 4000
' UCR / CUS-Code falls am Item vorhanden
' item.zaItem_UCR = ln.ucr
' item.zaItem_CusCode = ln.cusCode
' ---- Positions-UNTERLAGEN aus AtlasCompletionSumD / Documents ----
If ln.Documents IsNot Nothing Then
For Each ul As TMicDocument In ln.Documents.Document
Dim doc As New cVERAG_CustomsDeclarations_Document
doc.zaDoc_Code = ul.docType
doc.zaDoc_Reference = ul.docNo
doc.zaDoc_Date = ToNullableDate(ul.docDate)
item.Documents.Add(doc)
Next
End If
' ---- CustomerFields der Position ----
'If ln.CustomerFields IsNot Nothing Then
' item.zaItem_Text1 = ln.CustomerFields.text1
' item.zaItem_Text2 = ln.CustomerFields.text2
'End If
ZA.Items.Add(item)
Next
End If
Next
End If
End Function
'Private Function setData_Import(IMP_Message As MicCustImportMessage, IMP_Invoice As MicCustImportInvoiceComponent)
' Dim ZA As cVERAG_CustomsDeclarations
' If IMP_Message IsNot Nothing Then
' If IMP_Message.Shipment IsNot Nothing Then
' If IMP_Message.Shipment.ShipmentHead IsNot Nothing Then
' If IMP_Message.Shipment.ShipmentHead.mrn <> "" Then
' ZA = cVERAG_CustomsDeclarations.loadByMRN(IMP_Message.Shipment.ShipmentHead.mrn, True)
' Else
' ZA = New cVERAG_CustomsDeclarations
' End If
' ' ================================================================
' ' HEADER
' ' ================================================================
' ZA.za_System = "MIC"
' ZA.za_CustomsSystem = "ATLAS"
' ZA.za_REGIME = "IMPORT"
' ZA.za_CustomsSystemCountry = "NL"
' ZA.za_IsExternalSystem = False
' ZA.za_IsFinalDeclaration = True
' ZA.za_Firma = IMP_Message.Shipment.company
' ZA.za_Niederlassung = mic_ci.eza_niederlassung
' ZA.za_MRN = If(mic_ci.eza_MRN, mic_ci.eza_ANR)
' ZA.za_LRN = mic_ci.eza_ObjectName
' VERAG_PROG_ALLGEMEIN.cProgramFunctions.tryGetFirmaNiederlassung(ZA.za_Firma, ZA.za_Niederlassung, "", ZA.za_LRN)
' VERAG_PROG_ALLGEMEIN.cProgramFunctions.tryGetAvisoId_SndId_ByLRN(ZA.za_LRN, ZA.za_AvisoId, ZA.za_SendungsId)
' End If
' End If
' End If
' '' AB HIER
' Dim DY = cDakosy_Zollanmeldungen.LOADById(mic_ci.eza_dyaAnmID)
' If DY IsNot Nothing Then
' If ZA.za_AvisoId Is Nothing AndAlso DY.dy_AvisoId IsNot Nothing Then ZA.za_AvisoId = DY.dy_AvisoId
' If ZA.za_SendungsId Is Nothing AndAlso DY.dy_SendungsId IsNot Nothing Then ZA.za_SendungsId = DY.dy_SendungsId
' End If
' If mic_ci.eza_Anmeldedatum IsNot Nothing AndAlso mic_ci.eza_Anmeldedatum.ToString <> "" Then
' ZA.za_DeclarationDate = CDate(mic_ci.eza_Anmeldedatum)
' ZA.za_ReleaseDate = CDate(mic_ci.eza_Anmeldedatum)
' Else
' Dim dateumRelease As String = (New VERAG_PROG_ALLGEMEIN.SQL).DLookup("isnull(dySt_DakosyTransaktionsDatum,'')", "[tblDakosy_Statusmeldungen]", " dySt_status = 60 And dySt_dyId = '" & mic_ci.eza_dyaAnmID & "' Order By [dySt_DakosyTransaktionsDatum] desc", "FMZOLL",)
' If dateumRelease <> "" AndAlso IsDate(dateumRelease) Then
' ZA.za_DeclarationDate = CDate(dateumRelease)
' ZA.za_ReleaseDate = CDate(dateumRelease)
' Else
' ZA.za_DeclarationDate = ToNullableDate(If(mic_ci.eza_Anmeldedatum, mic_ci.eza_LetzteBearbeitung))
' ZA.za_ReleaseDate = ToNullableDate(If(mic_ci.eza_Anmeldedatum, mic_ci.eza_LetzteBearbeitung))
' End If
' End If
' ZA.za_MainProcedure = mic_ci.eza_VerfahrenBeantragtCode
' ZA.za_RepresentationCode = mic_ci.eza_VertretungsVerhaeltnisCode
' ZA.za_FiscalRepFlag = ToNullableBool(mic_ci.eza_FiskalvertretungKz)
' ZA.za_ApplicantVATNo = ToStringSafe(mic_ci.eza_UstIdAnmelder)
' ZA.za_ApplicantTaxOffice = ToStringSafe(mic_ci.eza_FinanzamtAnmelder)
' ZA.za_TaxDeduction = ToNullableBool(mic_ci.eza_Vorsteuerabzug)
' ZA.za_CountryDispatch = mic_ci.eza_VersendungsLandCode
' ZA.za_CountryDestination = mic_ci.eza_Bestimmungsland
' ZA.za_CountryDestinationState = mic_ci.eza_Bestimmungsbundesland
' ZA.za_ContainerNr1 = mic_ci.eza_ContainerNr1
' ZA.za_ContainerNr2 = mic_ci.eza_ContainerNr2
' ZA.za_ContainerNr3 = mic_ci.eza_ContainerNr3
' ZA.za_ContainerNr4 = mic_ci.eza_ContainerNr4
' ZA.za_ContainerNr5 = mic_ci.eza_ContainerNr5
' ZA.za_ContainerNr6 = mic_ci.eza_ContainerNr6
' ZA.za_ContainerNr7 = mic_ci.eza_ContainerNr7
' ZA.za_ContainerNr8 = mic_ci.eza_ContainerNr8
' ZA.za_ContainerNr9 = mic_ci.eza_ContainerNr9
' ZA.za_MeansOfTransport_Vehicle = mic_ci.eza_KennzeichenNameBefoerderungsmittelAnkunft
' ZA.za_MeansOfTransport_Nationality = mic_ci.eza_BeförderungsmittelGrenzeStaatszugehörigkeitCode
' ZA.za_MeansOfTransport_Type = mic_ci.eza_BeförderungsmittelGrenzeArt
' ZA.za_CountryImport = "NL"
' ZA.za_WarehouseCode = mic_ci.eza_Warenort
' ZA.za_InvoiceAmount = mic_ci.eza_Rechnungspreis
' ZA.za_InvoiceCurrency = mic_ci.eza_Rechnungswaehrung
' ZA.za_DV1Flag = ToNullableBool(mic_ci.eza_DV1Kz)
' ZA.za_PrevDocument_No = mic_ci.eza_VorpapierNr
' ZA.za_PrevDocument_Type = mic_ci.eza_VorpapierArtCode
' ZA.za_Incoterms = mic_ci.eza_LieferbedingungCode
' ZA.za_IncotermsPlace = mic_ci.eza_LieferbedingungOrt
' ZA.za_Sachbearbeiter = mic_ci.eza_AnmeldenderBearbeiterName
' ZA.za_TotGrossMass = ToNullableDecimal(mic_ci.eza_GesamtRohmasse)
' ZA.za_TransportModeBorder = ToStringSafe(mic_ci.eza_VerkehrszweigGrenze)
' ' ================================================================
' ' ADRESSEN
' ' ================================================================
' If mic_ci.eza_ADRESSEN IsNot Nothing Then
' For Each p In mic_ci.eza_ADRESSEN
' Dim party As New cVERAG_CustomsDeclarations_Parties
' party.zaParty_Role = p.ezaAd_AdressTyp
' party.zaParty_EORI = p.ezaAd_TeilnehmerEORI
' party.zaParty_EORI_NL = p.ezaAd_TeilnehmerNLNR
' party.zaParty_Name = p.ezaAd_NameFirma1
' party.zaParty_Street = p.ezaAd_StrasseHausNr1
' party.zaParty_PostalCode = p.ezaAd_PLZ
' party.zaParty_City = p.ezaAd_Ort
' party.zaParty_Country = p.ezaAd_LandCode
' 'party.zaParty_TIN = p.
' party.zaParty_VATNumber = p.ezaAd_UStIDAnmelder
' party.zaParty_TaxOffice = p.ezaAd_FinanzamtIDAnmelder
' If If(party.zaParty_EORI, "") <> "" Then
' Dim AD As VERAG_PROG_ALLGEMEIN.cAdressen = cZOLL_IMPORT.getAdresseFromEORI(party.zaParty_EORI, "", "", True)
' If AD IsNot Nothing Then
' party.zaParty_Name = (If(AD.Name_1, "") & " " & If(AD.Name_2, "")).trim
' party.zaParty_Country = VERAG_PROG_ALLGEMEIN.cProgramFunctions.getISO2Land(AD.LandKz)
' party.zaParty_City = AD.Ort
' party.zaParty_Street = AD.Straße
' 'party.ImporterAddressNumber = ""
' party.zaParty_PostalCode = AD.PLZ
' 'party.ImporterEmail = AD.E_Mail
' 'party.ImporterPhone = AD.Telefon
' End If
' End If
' ZA.Parties.Add(party)
' Next
' End If
' ' ================================================================
' ' ABGABEN
' ' ================================================================
' If mic_ci.eza_AUFSCHUB IsNot Nothing Then
' For Each d In mic_ci.eza_AUFSCHUB
' If d.ezaAfb_PositionsNummer Is Nothing Then
' Dim duty As New cVERAG_CustomsDeclarations_Duty
' duty.zaDuty_ApplicationType = d.ezaAfb_ArtAufschubantrag
' duty.zaDuty_AccountType = d.ezaAfb_Aufschubart
' duty.zaDuty_AccountHeadCustoms = d.ezaAfb_HZA
' duty.zaDuty_AccountNo = d.ezaAfb_KontoNr
' duty.zaDuty_AccountEORI = d.ezaAfb_AufschubnehmerEORI
' duty.zaDuty_AccountHolderName = d.AufschubnehmerName
' duty.zaDuty_DutyType = d.ezaAfb_AbgabeArt
' duty.zaDuty_BIN = d.ezaAfb_AufschuBIN
' duty.zaDuty_AmountEUR = ToNullableDecimal(d.ezaAfb_Abgabenbetrag)
' duty.zaDuty_AmountForeign = ToNullableDecimal(d.ezaAfb_Abgabenbetrag)
' duty.zaDuty_Currency = "EUR"
' duty.zaDuty_LimitDate = ToNullableDate(d.ezaAfb_Faelligkeit)
' ZA.Duties.Add(duty)
' End If
' Next
' End If
' ' ================================================================
' ' HEADER-UNTERLAGEN (ItemId = NULL)
' ' ================================================================
' If mic_ci.eza_UNTERLAGEN IsNot Nothing Then
' For Each ul In mic_ci.eza_UNTERLAGEN
' Dim doc As New cVERAG_CustomsDeclarations_Document
' doc.zaDoc_Section = ul.ezaUl_Bereich
' doc.zaDoc_ItemId = Nothing
' doc.zaDoc_Code = ul.ezaUl_Art
' doc.zaDoc_Reference = ul.ezaUl_Nummer
' doc.zaDoc_Date = ul.ezaUl_DatumAusstellung
' ZA.Documents.Add(doc)
' Next
' End If
' ' ================================================================
' ' POSITIONEN + POSITIONS-UNTERLAGEN
' ' ================================================================
' If mic_ci.eza_WARENPOS IsNot Nothing Then
' For Each wp In mic_ci.eza_WARENPOS
' Dim item As New cVERAG_CustomsDeclarations_Item
' item.zaItem_PosNo = ToInt(wp.ezaWP_PositionsNummer)
' item.zaItem_ArticleCode = wp.ezaWP_Artikelnummer
' item.zaItem_HSCode = wp.ezaWP_WarennummerEZT
' item.zaItem_HSAddition1 = wp.ezaWP_Warennummerzusatz1
' item.zaItem_HSAddition2 = wp.ezaWP_Warennummerzusatz2
' item.zaItem_HSAddCodes1 = wp.ezaWP_WarennummerZusatzCode1
' item.zaItem_HSAddCodes2 = wp.ezaWP_WarennummerZusatzCode2
' item.zaItem_HSAddCodes3 = wp.ezaWP_WarennummerZusatzCode3
' item.zaItem_HSAddCodes4 = wp.ezaWP_WarennummerZusatzCode4
' item.zaItem_HSAddCodes5 = wp.ezaWP_WarennummerZusatzCode5
' item.zaItem_HSAddCodes6 = wp.ezaWP_WarennummerZusatzCode6
' item.zaItem_HSAddCodes7 = wp.ezaWP_WarennummerZusatzCode7
' item.zaItem_HSAddCodes8 = wp.ezaWP_WarennummerZusatzCode8
' item.zaItem_HSAddCodes9 = wp.ezaWP_WarennummerZusatzCode9
' item.zaItem_HSAddCodes10 = wp.ezaWP_WarennummerZusatzCode10
' item.zaItem_Description = wp.ezaWP_Warenbezeichnung
' item.zaItem_PrevProcedure = wp.ezaWP_VerfahrensCodeVorangegangenesVerfahren
' item.zaItem_PreferentialCountry = wp.ezaWP_Praeferenzursprungsland
' item.zaItem_MainProcedure = wp.ezaWP_AnmeldeVErfahren
' item.zaItem_PackageColli = (wp.ezaWP_PackstueckAnzahl)
' item.zaItem_PackageType = wp.ezaWP_PackstueckArt
' item.zaItem_GrossMass = ToNullableDecimal(wp.ezaWP_Rohmasse)
' item.zaItem_NetMass = ToNullableDecimal(wp.ezaWP_Eigenmasse)
' item.zaItem_InvoiceValueForeign = ToNullableDecimal(wp.ezaWP_Artikelpreis)
' item.zaItem_InvoiceCurrency = wp.ezaWP_ArtikelpreisWaehrung
' If If(wp.ezaWP_ArtikelpreisWaehrung, "") = "EUR" Then
' item.zaItem_InvoiceValueEUR = ToNullableDecimal(wp.ezaWP_Artikelpreis)
' End If
' item.zaItem_CustomsValueEUR = ToNullableDecimal(wp.ezaWP_Zollwert)
' item.zaItem_StatisticalValueEUR = ToNullableDecimal(wp.ezaWP_AHStatWert)
' item.zaItem_OriginCountry = wp.ezaWP_UrsprungslandCode
' item.zaItem_PreferenceCode = wp.ezaWP_BeguenstigungBenatragtCode
' item.zaItem_PosAddition = If(wp.ezaWP_PositionsZusatz, "")
' ' -------------------------------
' ' POSITIONS-UNTERLAGEN
' ' -------------------------------
' If wp.ezaWP_UNTERLAGEN IsNot Nothing Then
' For Each ul In wp.ezaWP_UNTERLAGEN
' Dim doc As New cVERAG_CustomsDeclarations_Document
' doc.zaDoc_Section = ul.ezaWpUl_Bereich
' doc.zaDoc_Code = ul.ezaWpUl_Art
' doc.zaDoc_Reference = ul.ezaWpUl_Nummer
' doc.zaDoc_Date = ToNullableDate(ul.ezaWpUl_DatumAusstellung)
' doc.zaDoc_Presentation = ul.ezaWpUl_VorlageKz
' doc.zaDoc_DepreciationAmount = (ul.ezaWpUl_AbschreibungsMenge)
' doc.zaDoc_DepreciationUnitmeasurement = ul.ezaWpUl_AbschreibungsMengeMasseinheit
' doc.zaDoc_DepreciationUnitmeasurementQualifier = ul.ezaWpUl_AbschreibungsMengeMasseinheitQualifier
' item.Documents.Add(doc)
' Next
' End If
' ' ================================================================
' ' ABGABEN POS
' ' ================================================================
' If mic_ci.eza_AUFSCHUB IsNot Nothing Then
' For Each d In mic_ci.eza_AUFSCHUB
' If d.ezaAfb_PositionsNummer IsNot Nothing AndAlso CInt(d.ezaAfb_PositionsNummer) = item.zaItem_PosNo Then
' Dim duty As New cVERAG_CustomsDeclarations_Duty
' duty.zaDuty_ApplicationType = d.ezaAfb_ArtAufschubantrag
' duty.zaDuty_AccountType = d.ezaAfb_Aufschubart
' duty.zaDuty_AccountHeadCustoms = d.ezaAfb_HZA
' duty.zaDuty_AccountNo = d.ezaAfb_KontoNr
' duty.zaDuty_AccountEORI = d.ezaAfb_AufschubnehmerEORI
' duty.zaDuty_AccountHolderName = d.AufschubnehmerName
' duty.zaDuty_DutyType = d.ezaAfb_AbgabeArt
' duty.zaDuty_BIN = d.ezaAfb_AufschuBIN
' duty.zaDuty_AmountEUR = ToNullableDecimal(d.ezaAfb_Abgabenbetrag)
' duty.zaDuty_AmountForeign = ToNullableDecimal(d.ezaAfb_Abgabenbetrag)
' duty.zaDuty_Currency = "EUR"
' duty.zaDuty_LimitDate = ToNullableDate(d.ezaAfb_Faelligkeit)
' duty.zaDuty_Prozentsatz = ToNullableDecimal(d.ezaAfb_Prozentsatz)
' item.Duties.Add(duty)
' End If
' Next
' End If
' ZA.Items.Add(item)
' Next
' End If
' ' ================================================================
' 'CBAM WARNING
' ' ================================================================
' If freshInsert Then
' ZA.checkfreshCBAMWarning()
' End If
' ' ================================================================
' ' SAVE
' Dim saved = ZA.SAVE()
' ' ======KAFKA==========================================================
' 'If freshInsert Then cDakosyEZA_Greenpulse.INSERT_KAFKA(ZA)
' ' ================================================================
' Return saved
'End Function
' =====================================================================
' DUPLIKATSPRÜFUNG
' =====================================================================
Private Function ExistsInVERAG(eza As cDakosyEZA) As Boolean
Dim sql As String =
"SELECT TOP 1 1 FROM tblVERAG_CustomsDeclarations " &
"WHERE za_System='DAKOSY' " &
"AND (za_MRN=@mrn OR za_MRN=@anr)"
Dim p As New List(Of SQLVariable) From {
New SQLVariable("mrn", eza.eza_MRN),
New SQLVariable("anr", eza.eza_ANR)
}
Dim dt = New SQL().loadDgvBySql_Param(sql, "VERAG", , p)
Return dt IsNot Nothing AndAlso dt.Rows.Count > 0
End Function
' =========================================================================
' Small helpers (falls du sie schon hast, kannst du diese entfernen)
' =========================================================================
Private Function ToStringSafe(v As Object) As String
If v Is Nothing Then Return Nothing
Dim s As String = TryCast(v, String)
If s IsNot Nothing Then Return s
Return Convert.ToString(v, Globalization.CultureInfo.InvariantCulture)
End Function
Private Function ToInt(v As Object) As Integer
If v Is Nothing Then Return 0
Dim s = Convert.ToString(v, Globalization.CultureInfo.InvariantCulture)
Dim i As Integer
If Integer.TryParse(s, Globalization.NumberStyles.Any, Globalization.CultureInfo.InvariantCulture, i) Then Return i
Return 0
End Function
Private Function ToNullableDecimal(v As Object) As Decimal?
If v Is Nothing Then Return Nothing
Dim s = Convert.ToString(v, Globalization.CultureInfo.InvariantCulture)
Dim d As Decimal
If Decimal.TryParse(s, Globalization.NumberStyles.Any, Globalization.CultureInfo.InvariantCulture, d) Then Return d
Return Nothing
End Function
Private Function ToNullableDate(v As Object) As Date?
If v Is Nothing Then Return Nothing
If TypeOf v Is Date Then Return CType(v, Date)
Dim s = Convert.ToString(v, Globalization.CultureInfo.InvariantCulture)
Dim dt As Date
If Date.TryParse(s, Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, dt) Then Return dt
Return Nothing
End Function
Private Function ToNullableBool(v As Object) As Boolean?
If v Is Nothing Then Return Nothing
If TypeOf v Is Boolean Then Return CType(v, Boolean)
Dim s = Convert.ToString(v, Globalization.CultureInfo.InvariantCulture).Trim().ToLowerInvariant()
If s = "J" OrElse s = "1" OrElse s = "true" OrElse s = "y" OrElse s = "yes" Then Return True
If s = "N" OrElse s = "0" OrElse s = "false" OrElse s = "n" OrElse s = "no" Then Return False
Return Nothing
End Function
End Class