@@ -1,4 +1,5 @@
Imports System . Globalization
Imports System . Data . SqlClient
Imports System . Globalization
Imports DAKOSY_Worker
Imports Microsoft . Office . Interop
Imports VERAG_PROG_ALLGEMEIN
@@ -1105,7 +1106,7 @@ Public Class cATLAS_EZA_IMPORT
If header . ContainsKey ( " Invoice Date " ) Then HandelsRgDat = header ( " Invoice Date " )
If header . ContainsKey ( " Currency " ) Then EZA . eza_Rechnungswaehrung = header ( " Currency " )
If header . ContainsKey ( " Delivery Terms (Incoterms) " ) Then EZA . eza_LieferbedingungCode = header ( " Delivery Terms (Incoterms) " )
If header. ContainsKey( " Total Gross Weight (kg)" ) Then EZA . eza_GesamtRohmasse = ToDoubleSafeVERAGTmpl( header( " Total Gross Weight (kg)" ) )
' If header. ContainsKey(" Total Gross Weight (kg)") Then EZA. eza_GesamtRohmasse = ToDoubleSafeVERAGTmpl( header(" Total Gross Weight (kg)")) -> nur in pos!
If header . ContainsKey ( " Truck Plate (Tractor) " ) Then EZA . eza_KennzeichenNameBefoerderungsmittelAnkunft = header ( " Truck Plate (Tractor) " )
' ---------- 2) CONSIGNOR / CONSIGNEE ----------
@@ -1382,7 +1383,7 @@ Public Class cATLAS_EZA_IMPORT
End If
If cPrefCountry <> " " Then
If cPrefCountry . Length >= 2 Then pos . ezaWP_Praeferenzu rsprungsland = origin . Substring ( 0 , 2 )
If cPrefCountry . Length >= 2 Then pos . ezaWP_U rsprungslandCode = origin . Substring ( 0 , 2 )
End If
If cBenefit <> " " Then
@@ -1557,9 +1558,252 @@ Public Class cATLAS_EZA_IMPORT
End Try
End Sub
' In cATLAS_EZA_IMPORT einfügen; bestehenden Button8_Click ersetzen.
' Benötigt: Imports System.Globalization, Imports Microsoft.Office.Interop
' In cATLAS_EZA_IMPORT einfügen; bestehenden Button8_Click ersetzen.
' Benötigt: Imports System.Globalization, Imports Microsoft.Office.Interop
' In cATLAS_EZA_IMPORT einfügen; bestehenden Button8_Click ersetzen.
' Benötigt: Imports System.Globalization, Imports Microsoft.Office.Interop
Private Sub Button8_Click ( sender As Object , e As EventArgs ) Handles Button8 . Click
Try
Me . Cursor = Cursors . WaitCursor
importExcel_TetraPak ( )
Finally
Me . Cursor = Cursors . Default
End Try
End Sub
Private Function importExcel_TetraPak ( ) As Boolean
Dim f As New frmImportFromAVISOAnhaenge ( AVISO , SENDUNG )
f . ShowDialog ( Me )
If f . DialogResult <> DialogResult . OK OrElse f . LIST_FILES Is Nothing OrElse f . LIST_FILES . Count = 0 Then Return False
If f . LIST_FILES . Count <> 1 Then
MsgBox ( " Bitte genau eine Excel-Datei auswählen. " )
Return False
End If
Dim filePath As String = f . LIST_FILES ( 0 )
If Not ( filePath . EndsWith ( " .xlsx " , StringComparison . OrdinalIgnoreCase ) OrElse filePath . EndsWith ( " .xls " , StringComparison . OrdinalIgnoreCase ) ) Then Return False
Dim xlApp As Excel . Application = Nothing
Dim wb As Excel . Workbook = Nothing
Dim ws As Excel . Worksheet = Nothing
Dim imported As New List ( Of DAKOSY_Worker . cDakosy_EZA_Warenposition )
Dim head As New Dictionary ( Of String , Integer ) ( StringComparer . OrdinalIgnoreCase )
Dim kopf As New Dictionary ( Of String , String ) ( StringComparer . OrdinalIgnoreCase )
Try
xlApp = New Excel . Application With { . DisplayAlerts = False , . Visible = False }
wb = xlApp . Workbooks . Open ( filePath , ReadOnly : = True )
ws = CType ( wb . Worksheets ( 1 ) , Excel . Worksheet )
Dim lastCol As Integer = CInt ( ws . Cells ( 1 , ws . Columns . Count ) . End ( Excel . XlDirection . xlToLeft ) . Column )
Dim lastRow As Integer = CInt ( ws . UsedRange . Row + ws . UsedRange . Rows . Count - 1 )
For c As Integer = 1 To lastCol
Dim key As String = TetraCell ( ws . Cells ( 1 , c ) . Value2 )
If key <> " " AndAlso Not head . ContainsKey ( key ) Then head . Add ( key , c )
Next
If lastRow < 2 Then Return False
For r As Integer = 2 To lastRow
Dim line As String = TetraGet ( ws , head , r , " Shipment Line " )
Dim tariff As String = TetraGet ( ws , head , r , " Tariff Number " ) . Replace ( " " , " " )
Dim article As String = TetraGet ( ws , head , r , " Part Number " )
Dim description As String = TetraGet ( ws , head , r , " Part Description " )
If line = " " AndAlso tariff = " " AndAlso article = " " AndAlso description = " " AndAlso
TetraGet ( ws , head , r , " Country of Origin " ) = " " AndAlso
TetraGet ( ws , head , r , " Net Weight (kg) " ) = " " AndAlso
TetraGet ( ws , head , r , " Gross Weight (kg) " ) = " " AndAlso
TetraGet ( ws , head , r , " Line Value " ) = " " AndAlso
TetraGet ( ws , head , r , " Number of Packages " ) = " " AndAlso
TetraGet ( ws , head , r , " Package Type " ) = " " AndAlso
TetraGet ( ws , head , r , " Import Customs Procedure " ) = " " Then Continue For
Dim pos As New DAKOSY_Worker . cDakosy_EZA_Warenposition
If line <> " " Then pos . ezaWP_PositionsNummer = line
If article <> " " Then pos . ezaWP_Artikelnummer = article
If description <> " " Then pos . ezaWP_Warenbezeichnung = description
If tariff <> " " Then pos . ezaWP_WarennummerEZT = tariff
Dim origin As String = TetraGet ( ws , head , r , " Country of Origin " ) . ToUpperInvariant ( )
If origin <> " " Then pos . ezaWP_UrsprungslandCode = origin
Dim currency As String = TetraGet ( ws , head , r , " Currency " ) . ToUpperInvariant ( )
If currency <> " " Then pos . ezaWP_ArtikelpreisWaehrung = currency
Dim number As Decimal
If TetraTryDecimal ( TetraGet ( ws , head , r , " Net Weight (kg) " ) , number ) Then pos . ezaWP_Eigenmasse = number . ToString ( " 0.### " , CultureInfo . CurrentCulture )
If TetraTryDecimal ( TetraGet ( ws , head , r , " Gross Weight (kg) " ) , number ) Then pos . ezaWP_Rohmasse = CDbl ( number )
If TetraTryDecimal ( TetraGet ( ws , head , r , " Line Value " ) , number ) Then pos . ezaWP_Artikelpreis = number . ToString ( " 0.00 " , CultureInfo . CurrentCulture )
If TetraTryDecimal ( TetraGet ( ws , head , r , " Number of Packages " ) , number ) Then pos . ezaWP_PackstueckAnzahl = number . ToString ( " 0.### " , CultureInfo . InvariantCulture )
Dim packageType As String = TetraGet ( ws , head , r , " Package Type " )
If packageType <> " " Then pos . ezaWP_PackstueckArt = packageType
Dim procedure As String = TetraGet ( ws , head , r , " Import Customs Procedure " )
If procedure . Length >= 2 Then pos . ezaWP_AnmeldeVErfahren = procedure . Substring ( 0 , 2 )
If procedure . Length >= 4 Then pos . ezaWP_VerfahrensCodeVorangegangenesVerfahren = procedure . Substring ( 2 , 2 )
Dim preference As String = TetraGet ( ws , head , r , " Preference Code " )
If preference <> " " Then pos . ezaWP_BeguenstigungBenatragtCode = preference
Dim invoice As String = TetraGet ( ws , head , r , " Invoice Number " )
If invoice <> " " Then
pos . ezaWP_UNTERLAGEN . Add ( New DAKOSY_Worker . cDakosy_EZA_WarenpositionVorgelegteUnterlagen With {
. ezaWpUl_Art = " N380 " , . ezaWpUl_Bereich = " 4 " , . ezaWpUl_VorlageKz = " J " , . ezaWpUl_Nummer = invoice , . ezaWpUl_DatumAusstellung = Nothing
} )
End If
Dim ycodes As String = TetraGet ( ws , head , r , " Y-Document Type " )
For Each code As String In ycodes . Split ( New Char ( ) { " , "c , " ; "c } , StringSplitOptions . RemoveEmptyEntries )
Dim docCode As String = code . Trim ( ) . ToUpperInvariant ( )
If docCode <> " " Then
pos . ezaWP_UNTERLAGEN . Add ( New DAKOSY_Worker . cDakosy_EZA_WarenpositionVorgelegteUnterlagen With {
. ezaWpUl_Art = docCode , . ezaWpUl_Bereich = " 5 " , . ezaWpUl_VorlageKz = " J " , . ezaWpUl_Nummer = " " , . ezaWpUl_DatumAusstellung = Nothing
} )
End If
Next
imported . Add ( pos )
For Each key As String In { " Currency " , " Term of Delivery " , " Term of Delivery Place " , " Shipment Gross Weight (kg) " , " Identity of the means of transport at the border " , " Declarant EORI Number " , " Seller Name 1 " , " Seller Name 2 " , " Seller Street " , " Seller City " , " Seller Country " , " Invoice Number " , " Importer EORI Number " , " Country of Dispatch " , " Country of Destination " }
Dim v As String = TetraGet ( ws , head , r , key )
If v <> " " AndAlso ( Not kopf . ContainsKey ( key ) OrElse kopf ( key ) = " " ) Then kopf ( key ) = v
Next
Next
If imported . Count = 0 Then
MsgBox ( " Keine Warenpositionen gefunden. " )
Return False
End If
Dim replace As Boolean = False
If EZA . eza_WARENPOS . Count > 0 Then
Dim answer = MsgBox ( " Vorhandene " & EZA . eza_WARENPOS . Count & " Positionen ersetzen? " & vbCrLf & " Ja = ersetzen, Nein = ergänzen, Abbrechen = Import abbrechen. " , MsgBoxStyle . YesNoCancel Or MsgBoxStyle . Question )
If answer = MsgBoxResult . Cancel Then Return False
replace = ( answer = MsgBoxResult . Yes )
End If
Dim gross As Decimal = 0D
TetraTryDecimal ( TetraKopf ( kopf , " Shipment Gross Weight (kg) " ) , gross )
' Versender (CZ) aus Verkäufer W:AA, sofern noch nicht vorhanden.
Dim sellerName As String = ( TetraKopf ( kopf , " Seller Name 1 " ) & " " & TetraKopf ( kopf , " Seller Name 2 " ) ) . Trim ( )
If sellerName <> " " AndAlso Not EZA . eza_ADRESSEN . Any ( Function ( a ) String . Equals ( a . ezaAd_AdressTyp , " CZ " , StringComparison . OrdinalIgnoreCase ) ) Then
EZA . eza_ADRESSEN . Add ( New DAKOSY_Worker . cDakosy_EZA_Adressen With {
. ezaAd_AdressTyp = " CZ " ,
. ezaAd_NameFirma1 = sellerName ,
. ezaAd_StrasseHausNr1 = TetraKopf ( kopf , " Seller Street " ) ,
. ezaAd_Ort = TetraKopf ( kopf , " Seller City " ) ,
. ezaAd_LandCode = TetraKopf ( kopf , " Seller Country " ) . ToUpperInvariant ( )
} )
End If
' Anmelder = Adresstyp CN, EORI aus Spalte L.
Dim declarantEori As String = TetraKopf ( kopf , " Declarant EORI Number " )
If Not String . IsNullOrWhiteSpace ( declarantEori ) Then
TetraSetBestimmungsbundesland ( declarantEori )
End If
If declarantEori <> " " Then
Dim adrCN = EZA . eza_ADRESSEN . FirstOrDefault ( Function ( a ) String . Equals ( a . ezaAd_AdressTyp , " CN " , StringComparison . OrdinalIgnoreCase ) )
If adrCN Is Nothing Then
adrCN = New DAKOSY_Worker . cDakosy_EZA_Adressen With { . ezaAd_AdressTyp = " CN " }
EZA . eza_ADRESSEN . Add ( adrCN )
End If
adrCN . ezaAd_TeilnehmerEORI = declarantEori
End If
If replace Then EZA . eza_WARENPOS . Clear ( )
For Each pos In imported
EZA . eza_WARENPOS . Add ( pos )
Next
If TetraKopf ( kopf , " Currency " ) <> " " Then EZA . eza_Rechnungswaehrung = TetraKopf ( kopf , " Currency " )
If TetraKopf ( kopf , " Term of Delivery " ) <> " " Then EZA . eza_LieferbedingungCode = TetraKopf ( kopf , " Term of Delivery " )
If TetraKopf ( kopf , " Term of Delivery Place " ) <> " " Then EZA . eza_LieferbedingungOrt = TetraKopf ( kopf , " Term of Delivery Place " )
If gross > 0D Then EZA . eza_GesamtRohmasse = CDbl ( gross )
If TetraKopf ( kopf , " Country of Dispatch " ) <> " " Then EZA . eza_VersendungsLandCode = TetraKopf ( kopf , " Country of Dispatch " )
Dim euEftaCtc As String ( ) = {
" 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 " ,
" IS " , " LI " , " NO " , " CH " ,
" TR " , " MK " , " RS " , " GB " , " UA " , " GE " , " MD " , " ME "
}
If TetraKopf ( kopf , " Country of Dispatch " ) <> " " Then EZA . eza_ZollrechtlicherStatus = If ( euEftaCtc . Contains ( TetraKopf ( kopf , " Country of Dispatch " ) . ToUpperInvariant ( ) ) , " EU " , " IM " )
If TetraKopf ( kopf , " Country of Destination " ) <> " " Then EZA . eza_Bestimmungsland = TetraKopf ( kopf , " Country of Destination " )
If TetraKopf ( kopf , " Identity of the means of transport at the border " ) <> " " Then EZA . eza_KennzeichenNameBefoerderungsmittelAnkunft = TetraKopf ( kopf , " Identity of the means of transport at the border " )
MsgBox ( imported . Count & " Tetra-Pak-Positionen eingelesen. " )
Me . DialogResult = DialogResult . OK
Me . Close ( )
Return True
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( " Tetra Pak Excel-Import: " & ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
Return False
Finally
Try
If wb IsNot Nothing Then wb . Close ( False )
Catch
End Try
Try
If xlApp IsNot Nothing Then xlApp . Quit ( )
Catch
End Try
For Each obj As Object In New Object ( ) { ws , wb , xlApp }
If obj IsNot Nothing Then System . Runtime . InteropServices . Marshal . FinalReleaseComObject ( obj )
Next
End Try
End Function
Private Function TetraCell ( value As Object ) As String
If value Is Nothing Then Return " "
Return Convert . ToString ( value , CultureInfo . InvariantCulture ) . Trim ( )
End Function
Private Function TetraGet ( ws As Excel . Worksheet , header As Dictionary ( Of String , Integer ) , row As Integer , name As String ) As String
If Not header . ContainsKey ( name ) Then Return " "
Return TetraCell ( ws . Cells ( row , header ( name ) ) . Value2 )
End Function
Private Function TetraKopf ( kopf As Dictionary ( Of String , String ) , name As String ) As String
Dim value As String = Nothing
If kopf . TryGetValue ( name , value ) Then Return If ( value , " " )
Return " "
End Function
Private Function TetraTryDecimal ( value As String , ByRef number As Decimal ) As Boolean
number = 0D
If String . IsNullOrWhiteSpace ( value ) Then Return False
If Decimal . TryParse ( value , NumberStyles . Number , CultureInfo . InvariantCulture , number ) Then Return True
Return Decimal . TryParse ( value , NumberStyles . Number , CultureInfo . GetCultureInfo ( " de-DE " ) , number )
End Function
Private Sub TetraSetBestimmungsbundesland ( declarantEORI As String )
If String . IsNullOrWhiteSpace ( declarantEORI ) Then Exit Sub
Dim SQL As New VERAG_PROG_ALLGEMEIN . SQL
Try
Using conn As SqlConnection = SQL . GetNewOpenConnectionFMZOLL ( )
Dim sqlText As String =
" SELECT TOP 1 A.[LandKz], A.[PLZ] " &
" FROM [VERAG].[dbo].[Kunden] K " &
" INNER JOIN [VERAG].[dbo].[Adressen] A ON A.[AdressenNr] = K.[KundenNr] " &
" WHERE LTRIM(RTRIM(K.[EORITIN])) = @EORI "
Using cmd As New SqlCommand ( sqlText , conn )
cmd . Parameters . Add ( " @EORI " , SqlDbType . VarChar , 50 ) . Value = declarantEORI . Trim ( )
Using dr As SqlDataReader = cmd . ExecuteReader ( )
If dr . Read ( ) Then
Dim land As String = If ( dr . IsDBNull ( 0 ) , " " , dr . GetValue ( 0 ) . ToString ( ) . Trim ( ) . ToUpperInvariant ( ) )
Dim plz As String = If ( dr . IsDBNull ( 1 ) , " " , dr . GetValue ( 1 ) . ToString ( ) . Trim ( ) )
If ( land = " DE " Or land = " D " ) AndAlso plz <> " " Then
EZA . eza_Bestimmungsbundesland = VERAG_PROG_ALLGEMEIN . cDEBundeslaenderPLZ . LOADBundeslandCode_ByPLZ ( plz )
ElseIf land <> " " AndAlso land <> " DE " AndAlso land <> " D " Then
EZA . eza_Bestimmungsbundesland = 25
End If
End If
End Using
End Using
End Using
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod ( ) . Name )
End Try
End Sub
'================================================================================================================================