1198 lines
56 KiB
VB.net
1198 lines
56 KiB
VB.net
Imports com.sun.tools.javac.code.Symbol
|
||
Imports Newtonsoft.Json
|
||
Imports Newtonsoft.Json.Linq
|
||
|
||
Public Class cModalTransNCTS
|
||
' Haupt-Requestklasse für NCTS-Versandverfahren
|
||
Public Class cMT_NCTS_DeclarationRequest
|
||
' Nachricht
|
||
Public Property message_sender As String = "AVISO.APP"
|
||
Public Property message_sender_code As String = "" '"ITTR0000000000153"
|
||
Public Property message_recipient As String = "" '"NTA.BG"
|
||
Public Property message_recipient_code As String '= "BG005804"
|
||
Public Property message_identification As String = "BG015C"
|
||
Public Property message_type As String = "BG015C"
|
||
|
||
' Zusätzliche Pflichtfelder lt. Fehlermeldung
|
||
Public Property destination_country_id As String
|
||
Public Property trans_method As String
|
||
Public Property vehicle_id As String
|
||
Public Property trailer_id As String
|
||
|
||
' TransitOperation
|
||
Public Property lrn As String = "LRN-DEMO-12345"
|
||
Public Property declaration_type As String = "T1"
|
||
Public Property additional_declaration_type As String = "A"
|
||
Public Property security_level As String = "3"
|
||
Public Property reduced_dataset_indicator As String = "0"
|
||
Public Property binding_itinerary As String = "0"
|
||
|
||
' Zollstellen
|
||
Public Property departure_office As String
|
||
Public Property destination_office As String
|
||
Public Property transit_office_ref As String
|
||
Public Property transit_arrival_est As String
|
||
|
||
' Inhaber des Verfahrens
|
||
Public Property holder_eori As String
|
||
Public Property holder_name As String
|
||
Public Property holder_address As String
|
||
Public Property holder_postcode As String
|
||
Public Property holder_city As String
|
||
Public Property holder_country As String
|
||
Public Property holder_contact_name As String
|
||
Public Property holder_contact_phone As String
|
||
Public Property holder_contact_email As String
|
||
|
||
' Guarantee
|
||
Public Property guarantee_type As String
|
||
Public Property guarantee_sequence As String
|
||
Public Property guarantee_reference_sequence As String
|
||
Public Property guarantee_grn As String
|
||
Public Property guarantee_access_code As String
|
||
Public Property guarantee_amount As String
|
||
Public Property guarantee_currency As String
|
||
|
||
' Consignment
|
||
Public Property consignment_country_of_destination As String
|
||
Public Property consignment_container_indicator As String
|
||
Public Property consignment_inland_mode As String
|
||
Public Property consignment_border_mode As String
|
||
Public Property consignment_gross_mass As String
|
||
|
||
' Carrier
|
||
Public Property carrier_identification_number As String
|
||
|
||
' Consignor
|
||
Public Property consignor_name As String
|
||
Public Property consignor_street As String
|
||
Public Property consignor_postcode As String
|
||
Public Property consignor_city As String
|
||
Public Property consignor_country As String
|
||
|
||
' Consignee
|
||
Public Property consignee_name As String
|
||
Public Property consignee_street As String
|
||
Public Property consignee_postcode As String
|
||
Public Property consignee_city As String
|
||
Public Property consignee_country As String
|
||
|
||
' Transportmittel Abgangsort
|
||
Public Property departure_transport_sequence As String
|
||
Public Property departure_transport_type_id As String
|
||
Public Property departure_transport_number As String
|
||
Public Property departure_transport_nationality As String
|
||
|
||
' Routenländer
|
||
Public Property routing_countries As List(Of String)
|
||
|
||
' Grenzüberschreitendes Transportmittel
|
||
Public Property border_transport_customs_office As String
|
||
Public Property border_transport_type_id As String
|
||
Public Property border_transport_number As String
|
||
Public Property border_transport_nationality As String
|
||
|
||
' Beladungs- / Entladeort
|
||
Public Property loading_country As String
|
||
Public Property loading_location As String
|
||
Public Property unloading_country As String
|
||
Public Property unloading_location As String
|
||
|
||
' Steuer
|
||
Public Property tax_total_sum As String
|
||
Public Property tax_entries As List(Of cMT_NCTS_Tax)
|
||
|
||
' Hausversand / Warenpositionen
|
||
Public Property house_consignments As List(Of cMT_NCTS_HouseConsignment)
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_Tax
|
||
Public Property sequence_number As String
|
||
Public Property tax_type As String
|
||
Public Property tax_sum As String
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_HouseConsignment
|
||
Public Property sequence_number As String
|
||
Public Property gross_mass As String
|
||
Public Property items As List(Of cMT_NCTS_Item)
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_Item
|
||
Public Property goods_item_number As String
|
||
Public Property declaration_goods_item_number As String
|
||
Public Property description As String
|
||
Public Property hs_code As String
|
||
Public Property gross_mass As String
|
||
Public Property net_mass As String
|
||
Public Property packages As List(Of cMT_NCTS_Package)
|
||
Public Property supporting_documents As List(Of cMT_NCTS_Document)
|
||
Public Property transport_documents As List(Of cMT_NCTS_Document)
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_Package
|
||
Public Property sequence_number As String
|
||
Public Property package_type As String
|
||
Public Property number_of_packages As String
|
||
Public Property marks As String
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_Document
|
||
Public Property sequence_number As String
|
||
Public Property doc_type As String
|
||
Public Property reference As String
|
||
End Class
|
||
|
||
|
||
' Response-Klasse für NCTS-Antworten
|
||
Public Class cMT_NCTS_DeclarationResponse
|
||
Public Property status As String
|
||
Public Property message As String
|
||
Public Property declaration_id As String
|
||
Public Property mrn As String
|
||
Public Property lrn As String
|
||
Public Property created_at As String
|
||
End Class
|
||
|
||
|
||
|
||
|
||
Public Class cMT_NCTS_GET_DeclarationResponse
|
||
Public Property transaction_id As Integer?
|
||
Public Property reference As String
|
||
Public Property doc_type As String
|
||
Public Property doc_date As String
|
||
Public Property vehicle_code As String
|
||
Public Property vehicle_coun As String
|
||
Public Property trailer_code As String
|
||
Public Property trailer_coun As String
|
||
Public Property border_cross_vehicle As String
|
||
Public Property container As String
|
||
Public Property seal_info As String
|
||
Public Property security As Boolean?
|
||
Public Property tanker As Boolean?
|
||
Public Property is_aeo As Boolean?
|
||
Public Property aeo_location As String
|
||
Public Property transit_date As String
|
||
Public Property departure_custom_code As String
|
||
Public Property dispatch_country_id As String
|
||
Public Property load_place As String
|
||
Public Property goods_location As String
|
||
Public Property arrival_custom_code As String
|
||
Public Property destination_country_id As String
|
||
Public Property unload_place As String
|
||
Public Property border_custom_code As String
|
||
Public Property transit_customs_codes As String
|
||
Public Property transit_countries_codes As String
|
||
Public Property carrier_name As String
|
||
Public Property carrier_address As String
|
||
Public Property carrier_postcode As String
|
||
Public Property carrier_city As String
|
||
Public Property carrier_country_id As String
|
||
Public Property carrier_taxno As String
|
||
Public Property carrier_eori_code As String
|
||
Public Property custom_line As String
|
||
Public Property custom_staff_name As String
|
||
Public Property trans_method As String
|
||
Public Property roro_operator_code As String
|
||
Public Property guarantee_price As Decimal?
|
||
Public Property guarantee_curr As String
|
||
Public Property status As String
|
||
Public Property lrn_no As String
|
||
Public Property lrn As String
|
||
Public Property mrn As String
|
||
Public Property mrn_no As String
|
||
Public Property lrn_url As String
|
||
Public Property manifesto_price As Decimal?
|
||
Public Property manifesto_curr As String
|
||
Public Property position_no As String
|
||
Public Property remote_ref As String
|
||
Public Property notes As String
|
||
Public Property letter_grn As String
|
||
Public Property guarantor_name As String
|
||
Public Property guarantor_city As String
|
||
Public Property guarantor_taxno As String
|
||
Public Property guarantor_address As String
|
||
Public Property guarantor_postcode As String
|
||
Public Property guarantor_eori_code As String
|
||
Public Property guarantor_country_id As String
|
||
Public Property mrn_date As String
|
||
Public Property stamp_duty As String
|
||
Public Property ncts5_checker As Boolean?
|
||
Public Property released_at As String
|
||
Public Property goods_attributes As List(Of cMT_NCTS_GoodsAttribute)
|
||
|
||
Public Class cMT_NCTS_GoodsAttribute
|
||
Public Property line_no As Integer?
|
||
Public Property gtip_code As String
|
||
Public Property commodity As String
|
||
Public Property brut_wg As Decimal?
|
||
Public Property net_wg As Decimal?
|
||
Public Property invoice_amount As Decimal?
|
||
Public Property invoice_curr As String
|
||
Public Property exp_customs_type As String
|
||
Public Property exp_customs_partial As Boolean?
|
||
Public Property exp_customs_no As String
|
||
Public Property manifesto_type As String
|
||
Public Property dep_country_id As String
|
||
Public Property arv_country_id As String
|
||
Public Property sender_taxno As String
|
||
Public Property sender_name As String
|
||
Public Property sender_address As String
|
||
Public Property sender_postcode As String
|
||
Public Property sender_city As String
|
||
Public Property sender_country_id As String
|
||
Public Property sender_eori_code As String
|
||
Public Property consignee_taxno As String
|
||
Public Property consignee_name As String
|
||
Public Property consignee_address As String
|
||
Public Property consignee_postcode As String
|
||
Public Property consignee_city As String
|
||
Public Property consignee_country_id As String
|
||
Public Property consignee_eori_code As String
|
||
Public Property packs_attributes As List(Of cMT_NCTS_PackAttribute)
|
||
Public Property documents_attributes As List(Of cMT_NCTS_DocumentAttribute)
|
||
Public Property produced_documents_attributes As List(Of cMT_NCTS_ProducedDocumentAttribute)
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_PackAttribute
|
||
Public Property pack_type As String
|
||
Public Property pack_count As Integer?
|
||
Public Property notes As String
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_DocumentAttribute
|
||
Public Property doc_type As String
|
||
Public Property doc_no As String
|
||
Public Property pre_post As String
|
||
End Class
|
||
|
||
Public Class cMT_NCTS_ProducedDocumentAttribute
|
||
Public Property code As String
|
||
Public Property reference As String
|
||
Public Property status As String
|
||
Public Property reason As String
|
||
Public Property quantity As Decimal?
|
||
End Class
|
||
|
||
End Class
|
||
|
||
|
||
|
||
Public Class cMT_NCTS_GET_TimelineResponse
|
||
Public Property transaction_id As Integer?
|
||
Public Property reference As String
|
||
Public Property doc_type As String
|
||
Public Property doc_date As String
|
||
Public Property transit_date As String
|
||
Public Property status As String
|
||
Public Property lrn As String
|
||
Public Property mrn As String
|
||
Public Property manifesto_price As Decimal?
|
||
Public Property manifesto_curr As String
|
||
Public Property guarantee_price As Decimal?
|
||
Public Property guarantee_diff As Decimal?
|
||
Public Property guarantee_curr As String
|
||
Public Property seal_no As String
|
||
Public Property lrn_date As String
|
||
Public Property mrn_date As String
|
||
Public Property manifesto_closed_date As String
|
||
Public Property vahicle_arrived_date As String
|
||
Public Property custom_staff_name As String
|
||
Public Property custom_line As String
|
||
Public Property timelines As List(Of cMT_NCTS_GET_TimelineItem)
|
||
Public Class cMT_NCTS_GET_TimelineItem
|
||
Public Property timeline_id As String
|
||
Public Property status_date As String
|
||
Public Property status_code As String
|
||
Public Property notes As String
|
||
Public Property source As String
|
||
Public Property country_id As String
|
||
End Class
|
||
End Class
|
||
|
||
|
||
|
||
|
||
|
||
Public Class cMT_NCTS_ApiClient
|
||
Private http As New Chilkat.Http()
|
||
Private authToken As String
|
||
|
||
Public Sub New()
|
||
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
|
||
|
||
http.SetRequestHeader("Content-Type", "application/json")
|
||
End Sub
|
||
|
||
|
||
|
||
' SEND NCTS Declaration using object and convert to wrapped XML JSON
|
||
Public Function SendNCTSDeclaration(declaration As cMT_NCTS_DeclarationRequest) As cMT_NCTS_DeclarationResponse
|
||
Dim result As New cMT_NCTS_DeclarationResponse()
|
||
|
||
If Not cModalTransBase.Authenticate(authToken) Then
|
||
result.status = "Error"
|
||
result.message = "❌ Authentifizierung fehlgeschlagen."
|
||
Return result
|
||
End If
|
||
|
||
' XML manuell generieren aus dem Objekt
|
||
|
||
Dim xml As New Chilkat.Xml()
|
||
xml.Tag = "ie:BG015C"
|
||
xml.AddAttribute("xmlns:ie", "http://ncts.dgtaxud.ec")
|
||
|
||
xml.UpdateChildContent("messageSender", declaration.message_sender)
|
||
xml.UpdateChildContent("messageSenderCode", declaration.message_sender_code)
|
||
xml.UpdateChildContent("messageRecipient", declaration.message_recipient)
|
||
xml.UpdateChildContent("messageRecipientCode", declaration.message_recipient_code)
|
||
xml.UpdateChildContent("preparationDateAndTime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"))
|
||
xml.UpdateChildContent("messageIdentification", declaration.message_identification)
|
||
xml.UpdateChildContent("messageType", declaration.message_type)
|
||
|
||
Dim transitOp = xml.NewChild("TransitOperation", "")
|
||
transitOp.UpdateChildContent("LRN", declaration.lrn)
|
||
transitOp.UpdateChildContent("declarationType", declaration.declaration_type)
|
||
transitOp.UpdateChildContent("additionalDeclarationType", declaration.additional_declaration_type)
|
||
transitOp.UpdateChildContent("security", declaration.security_level)
|
||
transitOp.UpdateChildContent("reducedDatasetIndicator", declaration.reduced_dataset_indicator)
|
||
transitOp.UpdateChildContent("bindingItinerary", declaration.binding_itinerary)
|
||
MsgBox(declaration.vehicle_id)
|
||
xml.UpdateChildContent("vehicleId", declaration.vehicle_id)
|
||
xml.UpdateChildContent("trailerId", declaration.trailer_id)
|
||
xml.UpdateChildContent("CustomsOfficeOfDeparture/referenceNumber", declaration.departure_office)
|
||
xml.UpdateChildContent("CustomsOfficeOfDestinationDeclared/referenceNumber", declaration.destination_office)
|
||
|
||
If Not String.IsNullOrWhiteSpace(declaration.transit_office_ref) Then
|
||
Dim transitOffice = xml.NewChild("CustomsOfficeOfTransitDeclared", "")
|
||
transitOffice.UpdateChildContent("sequenceNumber", "1")
|
||
transitOffice.UpdateChildContent("referenceNumber", declaration.transit_office_ref)
|
||
transitOffice.UpdateChildContent("arrivalDateAndTimeEstimated", declaration.transit_arrival_est)
|
||
End If
|
||
|
||
Dim holder = xml.NewChild("HolderOfTheTransitProcedure", "")
|
||
holder.UpdateChildContent("identificationNumber", declaration.holder_eori)
|
||
holder.UpdateChildContent("name", declaration.holder_name)
|
||
Dim holderAddr = holder.NewChild("Address", "")
|
||
holderAddr.UpdateChildContent("streetAndNumber", declaration.holder_address)
|
||
holderAddr.UpdateChildContent("postcode", declaration.holder_postcode)
|
||
holderAddr.UpdateChildContent("city", declaration.holder_city)
|
||
holderAddr.UpdateChildContent("country", declaration.holder_country)
|
||
|
||
If Not String.IsNullOrWhiteSpace(declaration.holder_contact_name) Then
|
||
Dim contact = holder.NewChild("ContactPerson", "")
|
||
contact.UpdateChildContent("name", declaration.holder_contact_name)
|
||
contact.UpdateChildContent("phoneNumber", declaration.holder_contact_phone)
|
||
contact.UpdateChildContent("eMailAddress", declaration.holder_contact_email)
|
||
End If
|
||
|
||
Dim guarantee = xml.NewChild("Guarantee", "")
|
||
guarantee.UpdateChildContent("sequenceNumber", declaration.guarantee_sequence)
|
||
guarantee.UpdateChildContent("guaranteeType", declaration.guarantee_type)
|
||
Dim gr = guarantee.NewChild("GuaranteeReference", "")
|
||
gr.UpdateChildContent("sequenceNumber", declaration.guarantee_reference_sequence)
|
||
gr.UpdateChildContent("GRN", declaration.guarantee_grn)
|
||
gr.UpdateChildContent("accessCode", declaration.guarantee_access_code)
|
||
gr.UpdateChildContent("amountToBeCovered", declaration.guarantee_amount)
|
||
gr.UpdateChildContent("currency", declaration.guarantee_currency)
|
||
|
||
Dim cons = xml.NewChild("Consignment", "")
|
||
cons.UpdateChildContent("countryOfDestination", declaration.consignment_country_of_destination)
|
||
cons.UpdateChildContent("containerIndicator", declaration.consignment_container_indicator)
|
||
cons.UpdateChildContent("inlandModeOfTransport", declaration.consignment_inland_mode)
|
||
cons.UpdateChildContent("modeOfTransportAtTheBorder", declaration.consignment_border_mode)
|
||
cons.UpdateChildContent("grossMass", declaration.consignment_gross_mass)
|
||
|
||
Dim carrier = cons.NewChild("Carrier", "")
|
||
carrier.UpdateChildContent("identificationNumber", declaration.carrier_identification_number)
|
||
|
||
Dim consignor = cons.NewChild("Consignor", "")
|
||
consignor.UpdateChildContent("name", declaration.consignor_name)
|
||
Dim consignorAddr = consignor.NewChild("Address", "")
|
||
consignorAddr.UpdateChildContent("streetAndNumber", declaration.consignor_street)
|
||
consignorAddr.UpdateChildContent("postcode", declaration.consignor_postcode)
|
||
consignorAddr.UpdateChildContent("city", declaration.consignor_city)
|
||
consignorAddr.UpdateChildContent("country", declaration.consignor_country)
|
||
|
||
Dim consignee = cons.NewChild("Consignee", "")
|
||
consignee.UpdateChildContent("name", declaration.consignee_name)
|
||
Dim consigneeAddr = consignee.NewChild("Address", "")
|
||
consigneeAddr.UpdateChildContent("streetAndNumber", declaration.consignee_street)
|
||
consigneeAddr.UpdateChildContent("postcode", declaration.consignee_postcode)
|
||
consigneeAddr.UpdateChildContent("city", declaration.consignee_city)
|
||
consigneeAddr.UpdateChildContent("country", declaration.consignee_country)
|
||
|
||
Dim dtm = cons.NewChild("DepartureTransportMeans", "")
|
||
dtm.UpdateChildContent("sequenceNumber", declaration.departure_transport_sequence)
|
||
dtm.UpdateChildContent("typeOfIdentification", declaration.departure_transport_type_id)
|
||
dtm.UpdateChildContent("identificationNumber", declaration.departure_transport_number)
|
||
dtm.UpdateChildContent("nationality", declaration.departure_transport_nationality)
|
||
|
||
If declaration.routing_countries IsNot Nothing Then
|
||
For i = 0 To declaration.routing_countries.Count - 1
|
||
Dim rc = cons.NewChild("CountryOfRoutingOfConsignment", "")
|
||
rc.UpdateChildContent("sequenceNumber", (i + 1).ToString())
|
||
rc.UpdateChildContent("country", declaration.routing_countries(i))
|
||
Next
|
||
End If
|
||
|
||
Dim activeBorder = cons.NewChild("ActiveBorderTransportMeans", "")
|
||
activeBorder.UpdateChildContent("sequenceNumber", "1")
|
||
activeBorder.UpdateChildContent("customsOfficeAtBorderReferenceNumber", declaration.border_transport_customs_office)
|
||
activeBorder.UpdateChildContent("typeOfIdentification", declaration.border_transport_type_id)
|
||
activeBorder.UpdateChildContent("identificationNumber", declaration.border_transport_number)
|
||
activeBorder.UpdateChildContent("nationality", declaration.border_transport_nationality)
|
||
|
||
Dim placeLoading = cons.NewChild("PlaceOfLoading", "")
|
||
placeLoading.UpdateChildContent("country", declaration.loading_country)
|
||
placeLoading.UpdateChildContent("location", declaration.loading_location)
|
||
|
||
Dim placeUnloading = cons.NewChild("PlaceOfUnloading", "")
|
||
placeUnloading.UpdateChildContent("country", declaration.unloading_country)
|
||
placeUnloading.UpdateChildContent("location", declaration.unloading_location)
|
||
|
||
Dim taxCalc = cons.NewChild("TaxCalculation", "")
|
||
taxCalc.UpdateChildContent("totalSum", declaration.tax_total_sum)
|
||
If declaration.tax_entries IsNot Nothing Then
|
||
For Each tax In declaration.tax_entries
|
||
Dim taxNode = taxCalc.NewChild("Tax", "")
|
||
taxNode.UpdateChildContent("sequenceNumber", tax.sequence_number)
|
||
taxNode.UpdateChildContent("taxType", tax.tax_type)
|
||
taxNode.UpdateChildContent("taxSum", tax.tax_sum)
|
||
Next
|
||
End If
|
||
|
||
If declaration.house_consignments IsNot Nothing Then
|
||
For Each house In declaration.house_consignments
|
||
Dim hc = cons.NewChild("HouseConsignment", "")
|
||
hc.UpdateChildContent("sequenceNumber", house.sequence_number)
|
||
hc.UpdateChildContent("grossMass", house.gross_mass)
|
||
For Each item In house.items
|
||
Dim ci = hc.NewChild("ConsignmentItem", "")
|
||
ci.UpdateChildContent("goodsItemNumber", item.goods_item_number)
|
||
ci.UpdateChildContent("declarationGoodsItemNumber", item.declaration_goods_item_number)
|
||
Dim com = ci.NewChild("Commodity", "")
|
||
com.UpdateChildContent("descriptionOfGoods", item.description)
|
||
Dim cc = com.NewChild("CommodityCode", "")
|
||
cc.UpdateChildContent("harmonizedSystemSubHeadingCode", item.hs_code)
|
||
Dim gm = com.NewChild("GoodsMeasure", "")
|
||
gm.UpdateChildContent("grossMass", item.gross_mass)
|
||
gm.UpdateChildContent("netMass", item.net_mass)
|
||
For Each pkg In item.packages
|
||
Dim pk = ci.NewChild("Packaging", "")
|
||
pk.UpdateChildContent("sequenceNumber", pkg.sequence_number)
|
||
pk.UpdateChildContent("typeOfPackages", pkg.package_type)
|
||
pk.UpdateChildContent("numberOfPackages", pkg.number_of_packages)
|
||
pk.UpdateChildContent("shippingMarks", pkg.marks)
|
||
Next
|
||
For Each doc In item.supporting_documents
|
||
Dim d = ci.NewChild("SupportingDocument", "")
|
||
d.UpdateChildContent("sequenceNumber", doc.sequence_number)
|
||
d.UpdateChildContent("type", doc.doc_type)
|
||
d.UpdateChildContent("referenceNumber", doc.reference)
|
||
Next
|
||
For Each doc In item.transport_documents
|
||
Dim d = ci.NewChild("TransportDocument", "")
|
||
d.UpdateChildContent("sequenceNumber", doc.sequence_number)
|
||
d.UpdateChildContent("type", doc.doc_type)
|
||
d.UpdateChildContent("referenceNumber", doc.reference)
|
||
Next
|
||
Next
|
||
Next
|
||
End If
|
||
|
||
Dim xmlContent As String = xml.GetXml()
|
||
Dim jsonPayload As String = JsonConvert.SerializeObject(New With {
|
||
.manifesto = New With {
|
||
.ncts_data = xmlContent
|
||
}
|
||
})
|
||
|
||
|
||
|
||
Dim url As String = cModalTransBase.baseUrl & "/api/v1/ncts_declarations"
|
||
http.SetRequestHeader("Authorization", "Bearer " & authToken)
|
||
http.SetRequestHeader("Content-Type", "application/json")
|
||
|
||
Dim resp As Chilkat.HttpResponse = http.PostJson(url, jsonPayload)
|
||
|
||
If resp Is Nothing Then
|
||
result.status = "Error"
|
||
result.message = "❌ Keine Verbindung: " & http.LastErrorText
|
||
Return result
|
||
End If
|
||
|
||
Select Case resp.StatusCode
|
||
Case 201, 200
|
||
result.status = "Success"
|
||
result.message = "✅ NCTS-Anmeldung erfolgreich übermittelt."
|
||
Dim json = JsonConvert.DeserializeObject(Of JObject)(resp.BodyStr)
|
||
result.lrn = json.SelectToken("lrn")?.ToString()
|
||
result.mrn = json.SelectToken("mrn")?.ToString()
|
||
result.declaration_id = json.SelectToken("declaration_id")?.ToString()
|
||
|
||
Case 400, 422
|
||
result.status = "Validation Error"
|
||
result.message = $"⚠️ Fehlerhafte Eingabe ({resp.StatusCode}): {resp.BodyStr}"
|
||
|
||
Case 401
|
||
result.status = "Unauthorized"
|
||
result.message = "❌ Zugriff verweigert – bitte Authentifizierung prüfen."
|
||
|
||
Case Else
|
||
result.status = "Error"
|
||
result.message = $"❌ Unerwarteter Fehler ({resp.StatusCode}): {resp.BodyStr}"
|
||
End Select
|
||
|
||
Console.WriteLine("Status: " & result.status)
|
||
Console.WriteLine("Nachricht: " & result.message)
|
||
Return result
|
||
End Function
|
||
|
||
|
||
Public Function GetNCTSDeclarationByMRN(mrn As String) As cMT_NCTS_GET_DeclarationResponse
|
||
If Not cModalTransBase.Authenticate(authToken) Then
|
||
Console.WriteLine("❌ Authentifizierung fehlgeschlagen.")
|
||
Return Nothing
|
||
End If
|
||
http.SetRequestHeader("Authorization", "Bearer " & authToken)
|
||
Dim url = $"{cModalTransBase.baseUrl}/api/v1/ncts_declarations/{mrn}"
|
||
Dim resp = http.QuickGetObj(url)
|
||
If resp Is Nothing Then
|
||
Console.WriteLine("❌ Keine Verbindung: " & http.LastErrorText)
|
||
Return Nothing
|
||
End If
|
||
Select Case resp.StatusCode
|
||
Case 200
|
||
Try
|
||
Dim result = JsonConvert.DeserializeObject(Of cMT_NCTS_GET_DeclarationResponse)(resp.BodyStr)
|
||
Console.WriteLine("✅ NCTS-Anmeldung erfolgreich abgerufen (MRN).")
|
||
Return result
|
||
Catch ex As Exception
|
||
Console.WriteLine("❌ Fehler beim Parsen: " & ex.Message)
|
||
Console.WriteLine(resp.BodyStr)
|
||
End Try
|
||
Case 401
|
||
Console.WriteLine("❌ Zugriff verweigert (401)")
|
||
Case 404
|
||
Console.WriteLine("⚠️ Anmeldung nicht gefunden (404)")
|
||
Case Else
|
||
Console.WriteLine($"❌ Fehler ({resp.StatusCode}): {resp.BodyStr}")
|
||
End Select
|
||
Return Nothing
|
||
End Function
|
||
|
||
Public Function ConvertModaltransToNCTSFremd(nctsTmp As cMT_NCTS_GET_DeclarationResponse,
|
||
Optional OverrideNCTSFin As Boolean = False,
|
||
Optional PartnerSystem As String = "MODALTRANS") As VERAG_PROG_ALLGEMEIN.cNCTS_FREMD
|
||
If nctsTmp Is Nothing Then Return Nothing
|
||
If String.IsNullOrWhiteSpace(If(nctsTmp.mrn, "")) Then Return Nothing
|
||
|
||
Dim nctsFremd As VERAG_PROG_ALLGEMEIN.cNCTS_FREMD = VERAG_PROG_ALLGEMEIN.cNCTS_FREMD.LOADByMRN(nctsTmp.mrn, True)
|
||
If nctsFremd Is Nothing Then nctsFremd = New VERAG_PROG_ALLGEMEIN.cNCTS_FREMD
|
||
|
||
If Not OverrideNCTSFin Then
|
||
If If(nctsFremd.ncts_Status, 0) = 60 Then
|
||
Return nctsFremd
|
||
End If
|
||
End If
|
||
|
||
nctsFremd.ncts_Partnersystem = PartnerSystem
|
||
nctsFremd.ncts_MRN = nctsTmp.mrn
|
||
nctsFremd.ncts_ObjectName = If(If(nctsTmp.lrn, "") <> "", nctsTmp.lrn, nctsTmp.reference)
|
||
nctsFremd.ncts_Trans_Referenz = nctsTmp.reference
|
||
nctsFremd.ncts_Declarationtype = nctsTmp.doc_type
|
||
nctsFremd.ncts_TransitDeclarationType = nctsTmp.doc_type
|
||
nctsFremd.ncts_statusFremd = nctsTmp.status
|
||
|
||
|
||
nctsFremd.ncts_CustomsOfficeOfDeparture = nctsTmp.departure_custom_code
|
||
nctsFremd.ncts_CustomsOfficeOfDestinationDeclared = nctsTmp.arrival_custom_code
|
||
nctsFremd.ncts_CustomsOfficeOfExitForTransitDeclared = nctsTmp.border_custom_code
|
||
nctsFremd.ncts_CountryOfDispatch = nctsTmp.dispatch_country_id
|
||
|
||
nctsFremd.ncts_CountryOfDestination = nctsTmp.destination_country_id
|
||
|
||
nctsFremd.ncts_PlaceOfLoading_Location = nctsTmp.load_place
|
||
nctsFremd.ncts_PlaceOfUnLoading_Location = nctsTmp.unload_place
|
||
nctsFremd.ncts_LocationOfGoods_AdditionalIdentifier = nctsTmp.goods_location
|
||
' nctsFremd.ncts_ModeOfTransportAtTheBorder = nctsTmp.trans_method
|
||
' nctsFremd.ncts_InlandModeOfTransport = nctsTmp.trans_method
|
||
'nctsFremd.ncts_GrossMass = nctsTmp.
|
||
|
||
'''
|
||
nctsFremd.ncts_Consignor_Name = nctsTmp.carrier_name
|
||
nctsFremd.ncts_Carrier_AdressCode = Nothing
|
||
nctsFremd.ncts_Carrier_IdentificationNumber = nctsTmp.carrier_eori_code
|
||
nctsFremd.ncts_Carrier_ContactPerson_Name = nctsTmp.custom_staff_name
|
||
nctsFremd.ncts_Carrier_ContactPerson_EMailAddress = Nothing
|
||
nctsFremd.ncts_Carrier_ContactPerson_PhoneNumber = Nothing
|
||
nctsFremd.ncts_Consignee_Name = Nothing
|
||
|
||
nctsFremd.ncts_ActiveBorderTransportMeans_1_IdentificationNumber = nctsTmp.trailer_code
|
||
nctsFremd.ncts_ActiveBorderTransportMeans_1_Nationality = nctsTmp.trailer_coun
|
||
nctsFremd.ncts_DepartureTransportMeans_1_IdentificationNumber = nctsTmp.vehicle_code
|
||
nctsFremd.ncts_DepartureTransportMeans_1_Nationality = nctsTmp.vehicle_coun
|
||
nctsFremd.ncts_ContainerIndicator = nctsTmp.container
|
||
nctsFremd.ncts_Security = nctsTmp.security
|
||
nctsFremd.ncts_NachrichtenSenderTIN = Nothing
|
||
nctsFremd.ncts_NachrichtenSenderNLNR = Nothing
|
||
nctsFremd.ncts_NachrichtenempfaengerDST = Nothing
|
||
nctsFremd.ncts_Trans_DatumZeit = If(IsDate(nctsTmp.doc_date), CDate(nctsTmp.doc_date), Now)
|
||
|
||
If IsDate(nctsTmp.transit_date) Then
|
||
nctsFremd.ncts_Eroeffnung = CDate(nctsTmp.transit_date)
|
||
'If If(nctsFremd.ncts_LimitDate, "").ToString = "" Then
|
||
' nctsFremd.ncts_LimitDate = CDate(nctsTmp.limi).AddDays(10)
|
||
'End If
|
||
ElseIf IsDate(nctsTmp.doc_date) Then
|
||
nctsFremd.ncts_Eroeffnung = CDate(nctsTmp.doc_date)
|
||
If If(nctsFremd.ncts_LimitDate, "").ToString = "" Then
|
||
nctsFremd.ncts_LimitDate = CDate(nctsTmp.doc_date).AddDays(10)
|
||
End If
|
||
End If
|
||
|
||
|
||
Dim statusNeu As Integer = 0
|
||
|
||
Select Case UCase(If(nctsTmp.status, ""))
|
||
Case "DRAFT", "SENT"
|
||
statusNeu = 10
|
||
Case "IN_USE", "MRN", "REL_TRA", "MRN_ALL", "MRN_NOTIFIED", "GUAINF", "CTR_DEC", "CTRINFDEP", "WRT_NOT", "MRN_OK", "TRUCK_RELEASED", "TRUCK_IS_READY"
|
||
statusNeu = 50
|
||
Case "ARR_ADV", "AT_ARRIVAL_POINT"
|
||
statusNeu = 53
|
||
If If(nctsFremd.ncts_Ankunft, "").ToString = "" Then
|
||
|
||
End If
|
||
Case "TRANSIT_CLOSE", "RELEASED", "COMPLETED"
|
||
statusNeu = 60
|
||
If If(nctsFremd.ncts_Ankunft, "").ToString = "" Then
|
||
|
||
End If
|
||
If If(nctsFremd.ncts_Erledigung, "").ToString = "" Then
|
||
|
||
End If
|
||
Case "CANCELLED"
|
||
statusNeu = 90
|
||
|
||
Case Else
|
||
statusNeu = If(IsNumeric(nctsFremd.ncts_Status), CInt(nctsFremd.ncts_Status), 0)
|
||
If statusNeu = 0 Then statusNeu = 50
|
||
End Select
|
||
|
||
|
||
|
||
nctsFremd.ncts_Status = statusNeu
|
||
nctsFremd.ncts_Status_KEWILL_Equivalent = statusNeu
|
||
|
||
nctsFremd.LOAD_Guarantee()
|
||
nctsFremd.ncts_GUARANTEE.Clear()
|
||
|
||
If nctsTmp.guarantee_price.HasValue AndAlso nctsTmp.guarantee_price.Value > 0 AndAlso If(nctsTmp.letter_grn, "") <> "" Then
|
||
Dim grt As New VERAG_PROG_ALLGEMEIN.cNCTS_FREMD_Guarantee
|
||
grt.nctsGRT_Type = Nothing
|
||
grt.nctsGRT_AccessCode = Nothing
|
||
grt.nctsGRT_GRN = nctsTmp.letter_grn
|
||
grt.nctsGRT_AmountToBeCoveredFremdWaehrung = nctsTmp.guarantee_price.Value
|
||
grt.nctsGRT_Currency = nctsTmp.guarantee_curr
|
||
|
||
Console.WriteLine("guarantee_curr:" & nctsTmp.guarantee_curr)
|
||
|
||
|
||
|
||
If grt.nctsGRT_AmountToBeCoveredFremdWaehrung IsNot Nothing Then
|
||
If If(grt.nctsGRT_Currency, "") <> "" AndAlso If(grt.nctsGRT_Currency, "") <> "EUR" Then
|
||
Dim betragEUR = VERAG_PROG_ALLGEMEIN.cEZB_Waehrungskurse.EXCHANGE_CURTOEUR(
|
||
grt.nctsGRT_AmountToBeCoveredFremdWaehrung,
|
||
grt.nctsGRT_Currency,
|
||
nctsFremd.ncts_Trans_DatumZeit.ToShortDateString
|
||
)
|
||
grt.nctsGRT_AmountToBeCovered = If(betragEUR > 0, betragEUR, grt.nctsGRT_AmountToBeCoveredFremdWaehrung)
|
||
Else
|
||
grt.nctsGRT_AmountToBeCovered = grt.nctsGRT_AmountToBeCoveredFremdWaehrung
|
||
End If
|
||
End If
|
||
|
||
nctsFremd.ncts_GUARANTEE.Add(grt)
|
||
End If
|
||
|
||
|
||
'Status updaten:
|
||
If UpdateNCTSFremdStatusFromTimelines(nctsFremd.ncts_MRN, nctsFremd, False) Then
|
||
nctsFremd.SAVE_ALL()
|
||
End If
|
||
|
||
|
||
|
||
|
||
|
||
Return nctsFremd
|
||
End Function
|
||
|
||
|
||
' LIST all declarations
|
||
Public Function GetNCTSDeclarations(fromDate As DateTime, Optional page As Integer = 1) As List(Of cMT_NCTS_DeclarationResponse)
|
||
Dim list As New List(Of cMT_NCTS_DeclarationResponse)()
|
||
|
||
If Not cModalTransBase.Authenticate(authToken) Then
|
||
Console.WriteLine("❌ Authentifizierung fehlgeschlagen.")
|
||
Return list
|
||
End If
|
||
http.SetRequestHeader("Authorization", "Bearer " & authToken)
|
||
|
||
Dim fromDateStr As String = fromDate.ToString("yyyy-MM-dd")
|
||
|
||
Dim url As String = cModalTransBase.baseUrl & "/api/v1/ncts_declarations?from_date=" & fromDateStr & "&page=" & page.ToString()
|
||
|
||
http.SetRequestHeader("Authorization", "Bearer " & authToken)
|
||
Dim resp As Chilkat.HttpResponse = http.QuickGetObj(url)
|
||
If resp Is Nothing Then
|
||
Console.WriteLine("❌ Keine Verbindung: " & http.LastErrorText)
|
||
Return list
|
||
End If
|
||
|
||
|
||
If resp Is Nothing Then
|
||
Console.WriteLine("❌ Keine Verbindung: " & http.LastErrorText)
|
||
Return list
|
||
End If
|
||
Select Case resp.StatusCode
|
||
Case 200
|
||
Try
|
||
Dim token As JToken = JToken.Parse(resp.BodyStr)
|
||
If TypeOf token Is JArray Then
|
||
list = token.ToObject(Of List(Of cMT_NCTS_DeclarationResponse))()
|
||
ElseIf TypeOf token Is JObject Then
|
||
Dim obj As JObject = CType(token, JObject)
|
||
Dim dataToken As JToken = obj.SelectToken("data")
|
||
If dataToken IsNot Nothing AndAlso TypeOf dataToken Is JArray Then
|
||
list = dataToken.ToObject(Of List(Of cMT_NCTS_DeclarationResponse))()
|
||
Else
|
||
Console.WriteLine("⚠️ Antwort ist ein Objekt, aber kein Array unter 'data' gefunden.")
|
||
End If
|
||
Else
|
||
Console.WriteLine("⚠️ Unbekanntes JSON-Format in der Listenantwort.")
|
||
End If
|
||
Catch ex As Exception
|
||
Console.WriteLine("❌ Fehler beim Parsen der Liste: " & ex.Message)
|
||
Console.WriteLine(resp.BodyStr)
|
||
End Try
|
||
Case 401
|
||
Console.WriteLine("❌ Zugriff verweigert – bitte Authentifizierung prüfen.")
|
||
Case Else
|
||
Console.WriteLine("❌ Fehler (" & resp.StatusCode.ToString() & "): " & resp.BodyStr)
|
||
End Select
|
||
Return list
|
||
End Function
|
||
|
||
Public Function GetAllNCTSDeclarations(fromDate As DateTime) As List(Of cMT_NCTS_DeclarationResponse)
|
||
Dim allItems As New List(Of cMT_NCTS_DeclarationResponse)()
|
||
Dim currentPage As Integer = 1
|
||
Do
|
||
Dim pageItems As List(Of cMT_NCTS_DeclarationResponse) = GetNCTSDeclarations(fromDate, currentPage)
|
||
If pageItems Is Nothing OrElse pageItems.Count = 0 Then
|
||
Exit Do
|
||
End If
|
||
allItems.AddRange(pageItems)
|
||
Console.WriteLine("Seite " & currentPage.ToString() & ": " & pageItems.Count.ToString() & " Einträge geladen.")
|
||
currentPage += 1
|
||
Loop
|
||
Console.WriteLine("Gesamt geladen: " & allItems.Count.ToString() & " Einträge.")
|
||
Return allItems
|
||
End Function
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Public Function GetNCTSDeclarationTimelinesByMRN(mrn As String) As cMT_NCTS_GET_TimelineResponse
|
||
If Not cModalTransBase.Authenticate(authToken) Then
|
||
Console.WriteLine("❌ Authentifizierung fehlgeschlagen.")
|
||
Return Nothing
|
||
End If
|
||
http.SetRequestHeader("Authorization", "Bearer " & authToken)
|
||
Dim url = $"{cModalTransBase.baseUrl}/api/v1/ncts_declarations/{mrn}/timelines"
|
||
Dim resp = http.QuickGetObj(url)
|
||
If resp Is Nothing Then
|
||
Console.WriteLine("❌ Keine Verbindung: " & http.LastErrorText)
|
||
Return Nothing
|
||
End If
|
||
Select Case resp.StatusCode
|
||
Case 200
|
||
Try
|
||
Dim result = JsonConvert.DeserializeObject(Of cMT_NCTS_GET_TimelineResponse)(resp.BodyStr)
|
||
Console.WriteLine("✅ NCTS-Timelines erfolgreich abgerufen.")
|
||
Return result
|
||
Catch ex As Exception
|
||
Console.WriteLine("❌ Fehler beim Parsen der Timeline-Antwort: " & ex.Message)
|
||
Console.WriteLine(resp.BodyStr)
|
||
End Try
|
||
Case 400
|
||
Console.WriteLine("⚠️ Ungültige Anfrage (400): " & resp.BodyStr)
|
||
Case 403
|
||
Console.WriteLine("❌ Zugriff verweigert (403): " & resp.BodyStr)
|
||
Case 404
|
||
Console.WriteLine("⚠️ Anmeldung nicht gefunden (404): " & resp.BodyStr)
|
||
Case Else
|
||
Console.WriteLine("❌ Fehler (" & resp.StatusCode.ToString() & "): " & resp.BodyStr)
|
||
End Select
|
||
Return Nothing
|
||
End Function
|
||
|
||
|
||
Public Function UpdateNCTSFremdStatusFromTimelines(mrn As String,
|
||
ByRef nctsFremd As VERAG_PROG_ALLGEMEIN.cNCTS_FREMD,
|
||
Optional OverrideNCTSFin As Boolean = False) As Boolean
|
||
|
||
Try
|
||
|
||
If String.IsNullOrWhiteSpace(mrn) Then Return False
|
||
If nctsFremd Is Nothing Then Return False
|
||
Console.WriteLine("Status Update before:" & If(nctsFremd.ncts_Status, ""))
|
||
|
||
If Not OverrideNCTSFin Then
|
||
If IsNumeric(nctsFremd.ncts_Status) AndAlso (CInt(nctsFremd.ncts_Status) = 60 Or CInt(nctsFremd.ncts_Status) = 90) Then
|
||
Return True
|
||
End If
|
||
End If
|
||
|
||
Dim tl = GetNCTSDeclarationTimelinesByMRN(mrn)
|
||
If tl Is Nothing Then Return False
|
||
|
||
nctsFremd.ncts_MRN = mrn
|
||
|
||
Dim dtMrn As DateTime?
|
||
Dim dtLrn As DateTime?
|
||
Dim dtArrived As DateTime?
|
||
Dim dtClosed As DateTime?
|
||
|
||
If IsDate(tl.mrn_date) Then dtMrn = CDate(tl.mrn_date)
|
||
If IsDate(tl.lrn_date) Then dtLrn = CDate(tl.lrn_date)
|
||
If IsDate(tl.vahicle_arrived_date) Then dtArrived = CDate(tl.vahicle_arrived_date)
|
||
If IsDate(tl.manifesto_closed_date) Then dtClosed = CDate(tl.manifesto_closed_date)
|
||
|
||
If dtMrn.HasValue Then
|
||
nctsFremd.ncts_Eroeffnung = dtMrn.Value
|
||
If If(nctsFremd.ncts_LimitDate, "").ToString() = "" Then
|
||
nctsFremd.ncts_LimitDate = dtMrn.Value.AddDays(10)
|
||
End If
|
||
ElseIf dtLrn.HasValue Then
|
||
If If(nctsFremd.ncts_Eroeffnung, "").ToString() = "" Then nctsFremd.ncts_Eroeffnung = dtLrn.Value
|
||
If If(nctsFremd.ncts_LimitDate, "").ToString() = "" Then
|
||
nctsFremd.ncts_LimitDate = dtLrn.Value.AddDays(10)
|
||
End If
|
||
End If
|
||
|
||
Dim statusNeu As Integer = If(IsNumeric(nctsFremd.ncts_Status), CInt(nctsFremd.ncts_Status), 0)
|
||
|
||
Select Case UCase(If(tl.status, ""))
|
||
Case "IN_USE", "MRN_NOTIFIED", "WRT_NOT", "GUAINF", "CTR_DEC", "CTRINFDEP", "MRN_ALL", "REL_TRA"
|
||
statusNeu = 50
|
||
If dtMrn.HasValue Then nctsFremd.ncts_Eroeffnung = dtMrn.Value
|
||
|
||
Case "ARR_ADV", "ARRIVED"
|
||
statusNeu = 53
|
||
If If(nctsFremd.ncts_Ankunft, "").ToString() = "" Then
|
||
If dtArrived.HasValue Then
|
||
nctsFremd.ncts_Ankunft = dtArrived.Value
|
||
ElseIf dtMrn.HasValue Then
|
||
nctsFremd.ncts_Ankunft = dtMrn.Value
|
||
End If
|
||
End If
|
||
|
||
Case "TRANSIT_CLOSE", "RELEASED"
|
||
statusNeu = 60
|
||
If If(nctsFremd.ncts_Ankunft, "").ToString() = "" Then
|
||
If dtArrived.HasValue Then
|
||
nctsFremd.ncts_Ankunft = dtArrived.Value
|
||
ElseIf dtMrn.HasValue Then
|
||
nctsFremd.ncts_Ankunft = dtMrn.Value
|
||
End If
|
||
End If
|
||
If If(nctsFremd.ncts_Erledigung, "").ToString() = "" Then
|
||
If dtClosed.HasValue Then
|
||
nctsFremd.ncts_Erledigung = dtClosed.Value
|
||
ElseIf dtArrived.HasValue Then
|
||
nctsFremd.ncts_Erledigung = dtArrived.Value
|
||
ElseIf dtMrn.HasValue Then
|
||
nctsFremd.ncts_Erledigung = dtMrn.Value
|
||
End If
|
||
End If
|
||
|
||
Case "CANCELLED"
|
||
statusNeu = 90
|
||
End Select
|
||
|
||
If tl.timelines IsNot Nothing Then
|
||
For Each t In tl.timelines.OrderBy(Function(x) If(IsDate(x.status_date), CDate(x.status_date), Date.MinValue))
|
||
Select Case UCase(If(t.status_code, ""))
|
||
|
||
Case "TRUCK_IS_READY", "MRN"
|
||
If If(nctsFremd.ncts_Eroeffnung, "").ToString() = "" AndAlso IsDate(t.status_date) Then
|
||
nctsFremd.ncts_Eroeffnung = CDate(t.status_date)
|
||
End If
|
||
If statusNeu < 50 Then statusNeu = 50
|
||
Case "ARR_ADV", "AT_ARRIVAL_POINT", "ARRIVED"
|
||
If If(nctsFremd.ncts_Ankunft, "").ToString() = "" AndAlso IsDate(t.status_date) Then
|
||
nctsFremd.ncts_Ankunft = CDate(t.status_date)
|
||
End If
|
||
If statusNeu < 53 Then statusNeu = 53
|
||
|
||
Case "TRANSIT_CLOSE", "RELEASED", "COMPLETED"
|
||
If If(nctsFremd.ncts_Ankunft, "").ToString() = "" AndAlso IsDate(t.status_date) Then
|
||
nctsFremd.ncts_Ankunft = CDate(t.status_date)
|
||
End If
|
||
If If(nctsFremd.ncts_Erledigung, "").ToString() = "" AndAlso IsDate(t.status_date) Then
|
||
nctsFremd.ncts_Erledigung = CDate(t.status_date)
|
||
End If
|
||
statusNeu = 60
|
||
|
||
Case "CANCELLED"
|
||
statusNeu = 90
|
||
End Select
|
||
Next
|
||
End If
|
||
|
||
If statusNeu > 0 Then
|
||
nctsFremd.ncts_Status = statusNeu
|
||
nctsFremd.ncts_Status_KEWILL_Equivalent = statusNeu
|
||
End If
|
||
|
||
Console.WriteLine("Status Update after:" & If(nctsFremd.ncts_Status, ""))
|
||
Return True
|
||
|
||
|
||
Catch ex As Exception
|
||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodBase.GetCurrentMethod.Name, VERAG_PROG_ALLGEMEIN.ERROR_OP.MAIL)
|
||
|
||
End Try
|
||
Return False
|
||
End Function
|
||
|
||
|
||
|
||
End Class
|
||
Public Shared Function ceateAndSend_NCTS_FromSENDUNG(LRN As String, SND As cSendungen) As Boolean
|
||
If SND.tblSnd_AvisoID <= 0 Then Return False
|
||
Dim AVISO As cAviso = (New cAvisoDAL).LesenAviso(SND.tblSnd_AvisoID, "")
|
||
Return ceateAndSend_NCTS_FromSENDUNG(LRN, SND, AVISO)
|
||
End Function
|
||
|
||
|
||
Public Shared Function ceateAndSend_NCTS_FromSENDUNG(LRN As String, SND As cSendungen, AVISO As cAviso) As Boolean
|
||
' Objekt mit allen notwendigen Pflichtfeldern befüllen
|
||
Dim MT_NCTS As New cMT_NCTS_DeclarationRequest With {
|
||
.lrn = LRN,
|
||
.departure_office = "GB000060",
|
||
.destination_office = "",
|
||
.transit_office_ref = "",
|
||
.trans_method = "3",
|
||
.transit_arrival_est = "2024-06-14T00:00:00",
|
||
.holder_eori = "DE828088257899835",
|
||
.holder_name = "VERAG SPEDITION GMBH",
|
||
.holder_address = "Hartham 6",
|
||
.holder_postcode = "94152",
|
||
.holder_city = "NEUHAUS AM INN",
|
||
.holder_country = "DE",
|
||
.holder_contact_name = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME,
|
||
.holder_contact_phone = "0043771127770",
|
||
.holder_contact_email = "customs@verag-unisped.uk",
|
||
.departure_transport_sequence = "1",
|
||
.departure_transport_nationality = AVISO.LKW_Nationalitaet,
|
||
.border_transport_number = AVISO.LKW_Nr,
|
||
.border_transport_nationality = AVISO.LKW_Nationalitaet
|
||
}
|
||
|
||
|
||
|
||
Select Case If(AVISO.Transportmittelart, "")
|
||
Case "CONTAINER"
|
||
' MT_NCTS.border_transport_type = "1" ' z. B. Ocean
|
||
' MT_NCTS.arrival_transport_type = "10"
|
||
' MT_NCTS.border_transport_type_id = "1" ' z. B. Straße '?6 RORO??
|
||
' MT_NCTS.departure_transport_type_id = "3" ' z. B. Straße '?6 RORO??
|
||
MT_NCTS.consignment_inland_mode = "3"
|
||
MT_NCTS.consignment_border_mode = "3"
|
||
MT_NCTS.consignment_container_indicator = "1"
|
||
|
||
Case Else
|
||
MT_NCTS.consignment_container_indicator = "0"
|
||
MT_NCTS.border_transport_type_id = "30"
|
||
MT_NCTS.departure_transport_type_id = "30"
|
||
MT_NCTS.consignment_inland_mode = "3"
|
||
MT_NCTS.consignment_border_mode = "3"
|
||
' MT_NCTS.border_transport_type = "6" ' z. B. 3 Straße '?6 RORO??
|
||
' MT_NCTS.arrival_transport_type = "30"
|
||
|
||
End Select
|
||
|
||
MT_NCTS.departure_transport_number = AVISO.LKW_Nr
|
||
MT_NCTS.vehicle_id = AVISO.LKW_Nr
|
||
MT_NCTS.trailer_id = AVISO.LKW_Nr ' AVISO.LKW_Nationalitaet
|
||
|
||
|
||
|
||
If SND.tblSnd_EmpfaengerKdNr > 0 Then
|
||
Dim AD As New cAdressen(SND.tblSnd_EmpfaengerKdNr)
|
||
Dim KD As New cKunde(SND.tblSnd_EmpfaengerKdNr)
|
||
Dim CN As New VERAG_PROG_ALLGEMEIN.cRelayHub.cRelayHubAddress
|
||
' MT_NCTS.consignee_eori = If(KD.EORITIN, "")
|
||
MT_NCTS.consignee_name = AD.Name_1
|
||
MT_NCTS.consignee_street = AD.Straße
|
||
MT_NCTS.consignee_postcode = AD.PLZ
|
||
MT_NCTS.consignee_city = AD.Ort
|
||
MT_NCTS.consignee_country = cProgramFunctions.getISO2Land(AD.LandKz)
|
||
MT_NCTS.destination_country_id = MT_NCTS.consignee_country
|
||
MT_NCTS.consignment_country_of_destination = MT_NCTS.consignee_country
|
||
MT_NCTS.unloading_country = MT_NCTS.consignee_country
|
||
MT_NCTS.unloading_location = MT_NCTS.consignee_country
|
||
End If
|
||
|
||
If SND.tblSnd_AbsenderKdNr > 0 Then
|
||
Dim AD As New cAdressen(SND.tblSnd_AbsenderKdNr)
|
||
Dim KD As New cKunde(SND.tblSnd_AbsenderKdNr)
|
||
Dim CZ As New VERAG_PROG_ALLGEMEIN.cRelayHub.cRelayHubAddress
|
||
|
||
' MT_NCTS.consignor_city= If(KD.EORITIN, "")
|
||
MT_NCTS.consignor_name = AD.Name_1
|
||
MT_NCTS.consignor_street = AD.Straße
|
||
MT_NCTS.consignor_postcode = AD.PLZ
|
||
MT_NCTS.consignor_city = AD.Ort
|
||
MT_NCTS.consignor_country = cProgramFunctions.getISO2Land(AD.LandKz)
|
||
' MT_NCTS.export_country = MT_NCTS.consignor_country_id
|
||
MT_NCTS.loading_country = MT_NCTS.consignor_country
|
||
MT_NCTS.loading_location = MT_NCTS.consignor_country
|
||
End If
|
||
|
||
|
||
|
||
' API-Client erstellen (mit Benutzer & Passwort in der Klasse eingebaut)
|
||
Dim client As New cMT_NCTS_ApiClient()
|
||
|
||
' Senden und Ergebnis anzeigen
|
||
Dim response As cMT_NCTS_DeclarationResponse = client.SendNCTSDeclaration(MT_NCTS)
|
||
|
||
If response IsNot Nothing Then
|
||
Console.WriteLine("Status: " & response.status)
|
||
Console.WriteLine("Message: " & response.message)
|
||
Console.WriteLine("Declaration ID: " & response.declaration_id)
|
||
Console.WriteLine("LRN: " & response.lrn)
|
||
Console.WriteLine("MRN: " & response.mrn)
|
||
Else
|
||
Console.WriteLine("❌ Keine Antwort erhalten.")
|
||
End If
|
||
|
||
Return False
|
||
End Function
|
||
|
||
|
||
Public Shared Sub TestNCTSSend()
|
||
Dim client As New cMT_NCTS_ApiClient()
|
||
Dim declaration As New cMT_NCTS_DeclarationRequest With {
|
||
.lrn = "LRN-DEMO-" & DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||
.departure_office = "BG005804",
|
||
.destination_office = "TR343100",
|
||
.transit_office_ref = "TR220200",
|
||
.destination_country_id = "GB",
|
||
.trans_method = "3",
|
||
.transit_arrival_est = "2024-06-14T00:00:00",
|
||
.holder_eori = "DE828088257899835",
|
||
.holder_name = "VERAG SPEDITION AGMBH",
|
||
.holder_address = "Hartham 6",
|
||
.holder_postcode = "94152",
|
||
.holder_city = "NEUHAUS AM INN",
|
||
.holder_country = "DE",
|
||
.holder_contact_name = "Luxbauer",
|
||
.holder_contact_phone = "0771127770",
|
||
.holder_contact_email = "customs@verag-unisped.uk",
|
||
.guarantee_type = "0",
|
||
.guarantee_sequence = "1",
|
||
.guarantee_reference_sequence = "1",
|
||
.guarantee_grn = "DE123456789",
|
||
.guarantee_access_code = "XXXX",
|
||
.guarantee_amount = "1",
|
||
.guarantee_currency = "EUR",
|
||
.consignment_country_of_destination = "TR",
|
||
.consignment_container_indicator = "0",
|
||
.consignment_inland_mode = "3",
|
||
.consignment_border_mode = "3",
|
||
.consignment_gross_mass = "10.000",
|
||
.carrier_identification_number = "ateos13456",
|
||
.consignor_name = "test",
|
||
.consignor_street = "test",
|
||
.consignor_postcode = "01111",
|
||
.consignor_city = "test",
|
||
.consignor_country = "at",
|
||
.consignee_name = "test",
|
||
.consignee_street = "test",
|
||
.consignee_postcode = "34850",
|
||
.consignee_city = "ISTANBUL",
|
||
.consignee_country = "TR",
|
||
.departure_transport_sequence = "1",
|
||
.departure_transport_type_id = "30",
|
||
.departure_transport_number = "123456789",
|
||
.departure_transport_nationality = "TR",
|
||
.routing_countries = New List(Of String) From {"RS", "BG", "TR"},
|
||
.border_transport_customs_office = "tr132456",
|
||
.border_transport_type_id = "30",
|
||
.border_transport_number = "139786546",
|
||
.border_transport_nationality = "TR",
|
||
.loading_country = "BG",
|
||
.loading_location = "BG",
|
||
.unloading_country = "TR",
|
||
.unloading_location = "TR",
|
||
.vehicle_id = "16BCB723",
|
||
.trailer_id = "16APM317",
|
||
.tax_total_sum = "3",
|
||
.tax_entries = New List(Of cMT_NCTS_Tax) From {
|
||
New cMT_NCTS_Tax With {.sequence_number = "1", .tax_type = "A00", .tax_sum = "1"},
|
||
New cMT_NCTS_Tax With {.sequence_number = "2", .tax_type = "B00", .tax_sum = "2"}
|
||
},
|
||
.house_consignments = New List(Of cMT_NCTS_HouseConsignment) From {
|
||
New cMT_NCTS_HouseConsignment With {
|
||
.sequence_number = "1",
|
||
.gross_mass = "11777.000",
|
||
.items = New List(Of cMT_NCTS_Item) From {
|
||
New cMT_NCTS_Item With {
|
||
.goods_item_number = "1",
|
||
.declaration_goods_item_number = "1",
|
||
.description = "Textilprodukte",
|
||
.hs_code = "380991",
|
||
.gross_mass = "1.000",
|
||
.net_mass = "1.000",
|
||
.packages = New List(Of cMT_NCTS_Package) From {
|
||
New cMT_NCTS_Package With {
|
||
.sequence_number = "1",
|
||
.package_type = "PK",
|
||
.number_of_packages = "1",
|
||
.marks = "NO MARKS"
|
||
}
|
||
},
|
||
.supporting_documents = New List(Of cMT_NCTS_Document) From {
|
||
New cMT_NCTS_Document With {.sequence_number = "1", .doc_type = "N380", .reference = "A1111"}
|
||
},
|
||
.transport_documents = New List(Of cMT_NCTS_Document) From {
|
||
New cMT_NCTS_Document With {.sequence_number = "1", .doc_type = "N730", .reference = "CMR"}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
Dim response = client.SendNCTSDeclaration(declaration)
|
||
If response IsNot Nothing Then
|
||
Console.WriteLine("Status: " & response.status)
|
||
Console.WriteLine("Message: " & response.message)
|
||
Console.WriteLine("Declaration ID: " & response.declaration_id)
|
||
Console.WriteLine("LRN: " & response.lrn)
|
||
Console.WriteLine("MRN: " & response.mrn)
|
||
Else
|
||
Console.WriteLine("❌ Keine Antwort erhalten.")
|
||
End If
|
||
End Sub
|
||
|
||
|
||
End Class |