Files
AVISO/Aviso/usrcntlFrachtkostenberechnung.vb

459 lines
19 KiB
VB.net

Imports DocumentFormat.OpenXml.Drawing.Charts
Imports DocumentFormat.OpenXml.Drawing.Diagrams
Imports Microsoft.Office.Interop.Excel
Imports SDL
Public Class usrcntlFrachtkostenberechnung
Dim absenderID As Integer = -1
Dim empfaengerID As Integer = -1
Dim origin As String
Dim destination As String
Dim ware As String
Public EUAnteil As Double
Public nichtEUAnteil As Double
Dim gewicht As Double
Dim gesamtFrachtkosten As Double
Dim sql As New VERAG_PROG_ALLGEMEIN.SQL
Dim warenbez As String
Dim avisoid As Integer = -1
Sub New()
InitializeComponent()
End Sub
Public Sub init(avisoid As Integer, absID As String, empfID As String, gewichtInput As String, gesamtfrachtkostenInput As String, ware As String, warenwert As String)
Me.avisoid = avisoid
If gesamtfrachtkostenInput IsNot Nothing AndAlso gesamtfrachtkostenInput.ToString <> "" AndAlso IsNumeric(gesamtfrachtkostenInput) Then
gesamtFrachtkosten = CDbl(gesamtfrachtkostenInput)
tbxGesamtfrachtkosten._value = gesamtFrachtkosten
Else
gesamtFrachtkosten = 0
End If
If gewichtInput IsNot Nothing AndAlso gewichtInput.ToString <> "" AndAlso IsNumeric(gewichtInput) Then
gewicht = CDbl(gewichtInput)
Else
gewicht = 0
End If
If absID IsNot Nothing AndAlso absID.ToString <> "" AndAlso IsNumeric(absID) Then
absenderID = CInt(absID)
Else
absenderID = -1
End If
If empfID IsNot Nothing AndAlso empfID.ToString <> "" AndAlso IsNumeric(empfID) Then
empfaengerID = Int(empfID)
Else
empfaengerID = -1
End If
'cbxLandVon.fillWithSQL("SELECT Distinct(ISNULL([LandKz],'')) as LandKZ FROM [Adressen] order by LandKz asc", False, "FMZOLL", True, True)
cbxLandVon.fillWithSQL(" select distinct landkz, Währungstabelle.Land from Währungstabelle where landkz is not null order by LandKz", True, "FMZOLL", True)
cbxLandVon.changeItem(sql.DLookup("[LandKz]", "[Adressen]", "[AdressenNr]='" & absenderID & "'", "FMZOLL", ""))
txbVonPLZ.fillWithSQL("SELECT ISNULL([PLZ],'') FROM [Adressen] where AdressenNr = '" & absenderID & "'", "FMZOLL")
txbVonOrt.fillWithSQL("SELECT ISNULL([Ort],'') FROM [Adressen] where AdressenNr = '" & absenderID & "'", "FMZOLL")
cbxLandNach.Items.AddRange(cbxLandVon.Items.Cast(Of VERAG_PROG_ALLGEMEIN.MyListItem).ToArray())
cbxLandNach.changeItem(sql.DLookup("[LandKz]", "[Adressen]", "[AdressenNr]='" & empfaengerID & "'", "FMZOLL", ""))
txbNachPLZ.fillWithSQL("SELECT ISNULL([PLZ],'-') FROM [Adressen] where AdressenNr = '" & empfaengerID & "'", "FMZOLL")
txbNachOrt.fillWithSQL("SELECT ISNULL([Ort],'') FROM [Adressen] where AdressenNr = '" & empfaengerID & "'", "FMZOLL")
ckbManAnteilsermittlung.Checked = True
tbEUAnteil._value = 0
tbNichtEUAnteil._value = 0
txbGewicht._value = gewicht.ToString
txbFactor._value = 0.3
txtWare._value = ware
txtGesamtgewicht._value = gewichtInput
checkInputFields()
End Sub
Sub calculateFreight()
'resetInputFields()
setControlEUAnteile()
origin = IIf(cbxLandVon._value <> "", cbxLandVon.Text.Replace(cbxLandVon._value & " -", "").Trim(), "") & " " & IIf(txbVonPLZ._value <> "", txbVonPLZ._value, "") & " " & IIf(txbVonOrt._value <> "", txbVonOrt._value, "")
destination = IIf(cbxLandNach._value <> "", cbxLandNach.Text.Replace(cbxLandNach._value & " -", "").Trim(), "") & " " & IIf(txbNachPLZ._value <> "", txbNachPLZ._value, "") & " " & IIf(txbNachOrt._value <> "", txbNachOrt._value, "")
Dim getValues = True
Dim twoRouteRequest As Boolean = False
Dim duration = ""
Dim distance = ""
Dim durationEU = ""
Dim distanceEU = ""
If cbxLandVon._value = "TR" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Kapitan Andreevo ist EU Grenze für Lieferungen aus der Türkei
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Kapitan Andreevo", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Kapitan Andreevo", destination, durationEU, distanceEU,, getValues)
ElseIf cbxLandVon._value = "SRB" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Horgoš ist EU Grenze für Lieferungen von Serbien
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Horgoš", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Horgoš", destination, durationEU, distanceEU,, getValues)
ElseIf cbxLandNach._value = "SRB" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Horgoš ist EU Grenze für Lieferungen aus Serbien
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Horgoš", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Horgoš", destination, durationEU, distanceEU,, getValues)
ElseIf cbxLandNach._value = "GB" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Dover ist EU Grenze für Lieferungen nach England
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Dover", durationEU, distanceEU,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Dover", destination, duration, distance,, getValues)
ElseIf cbxLandVon._value = "GB" AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Dover ist EU Grenze für Lieferungen aus England
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Dover", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Dover", destination, durationEU, distanceEU,, getValues)
ElseIf cbxLandVon._value = "SRB" AndAlso cbxLandNach._value = "D" AndAlso (absenderID = "551038" Or absenderID = "722998") AndAlso ckbManAnteilsermittlung.Checked Then
twoRouteRequest = True
'Sonderfall für Lukowa-Berechnung
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, "Bajakovo", duration, distance,, getValues)
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance("Bajakovo", destination, durationEU, distanceEU,, getValues)
End If
If twoRouteRequest = True AndAlso ckbManAnteilsermittlung.Checked Then
lblDistanzEU.Text = "EU-Distanz"
lblDistanzNichtEU.Visible = True
txbCalcDistanceNichtEU.Visible = True
Try
If (IsNumeric(distanceEU)) Then
IIf(distanceEU > 1000, Math.Round(distanceEU / 1000, 0), distanceEU)
txbCalcDistanceEU._value = IIf(distanceEU > 1000, Math.Round(distanceEU / 1000, 0), distanceEU)
Else
distanceEU = "0"
MsgBox("Standort vom Bestimmungsort kann nicht ermittelt werden!" & vbCr & "Bitte Eingabe " & txbNachPLZ._value & " " & txbNachOrt._value & " prüfen")
Exit Sub
End If
If (IsNumeric(distance)) Then
txbCalcDistanceNichtEU._value = IIf(CInt(distance) > 1000, Math.Round(CInt(distance) / 1000, 0), CInt(distance))
Else
distance = "0"
MsgBox("Standort vom Abgangsort kann nicht ermittelt werden!" & vbCr & "Bitte Eingabe " & txbVonPLZ._value & " " & txbVonOrt._value & " prüfen")
Exit Sub
End If
Dim totalDistance = CDbl(distance) + CDbl(distanceEU)
Dim distanceNotEUpercent = CDbl(distance) * 100 / totalDistance
Dim distanceEUpercent = CDbl(distanceEU) * 100 / totalDistance
Math.Round(distanceNotEUpercent, 2)
Math.Round(distanceEUpercent, 2)
tbEUAnteil._value = CDbl(distanceEUpercent) / 100
tbNichtEUAnteil._value = CDbl(distanceNotEUpercent) / 100
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
ElseIf ckbManAnteilsermittlung.Checked Then
VERAG_PROG_ALLGEMEIN.cGoogleAPI.GoogleDistance(origin, destination, duration, distance)
tbEUAnteil._value = 0.6
tbNichtEUAnteil._value = 0.4
If distance = "0" Or distance = "" Then
MsgBox("Standort vom Abgangsort/Bestimmungsort kann nicht ermittelt werden!" & vbCr & "Bitte Eingabe prüfen")
End If
lblDistanzEU.Text = "Distanz"
txbCalcDistanceEU._value = distance
lblDistanzNichtEU.Visible = False
txbCalcDistanceNichtEU.Visible = False
Else
lblDistanzEU.Text = "Distanz"
txbCalcDistanceEU._value = distance
lblDistanzNichtEU.Visible = False
txbCalcDistanceNichtEU.Visible = False
End If
End Sub
Sub calculateFreightCosts()
Try
If gesamtFrachtkosten = 0 Then
gesamtFrachtkosten = gewicht * CDbl(txbFactor._value)
tbxGesamtfrachtkosten._value = gesamtFrachtkosten
End If
tbxGesamtfrachtkosten._value = gesamtFrachtkosten
EUAnteil = gesamtFrachtkosten * tbEUAnteil._value
nichtEUAnteil = gesamtFrachtkosten * CDbl(tbNichtEUAnteil._value)
tbEUAnteilberechnet._value = CStr(EUAnteil)
tbNichtEUAnteilberechnet._value = CStr(nichtEUAnteil)
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Function checkInputFields() As Boolean
Dim isFilled As Boolean = True
lblWarningAbgangort.Visible = False
lblWarningBestimmungsort.Visible = False
lblWarningEUAnteil.Visible = False
lblWarningNichtEUAnteil.Visible = False
btnOK.DialogResult = DialogResult.OK
If (tbEUAnteil._value = "" Or Not IsNumeric(tbEUAnteil._value)) Then
lblWarningEUAnteil.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
If (tbNichtEUAnteil._value = "" Or Not IsNumeric(tbNichtEUAnteil._value)) Then
lblWarningNichtEUAnteil.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
If (txbFactor._value = "" Or Not IsNumeric(txbFactor._value)) Then
'Hinweis INPUT false
End If
If (txbVonOrt._value = "" And txbVonPLZ._value = "") Then
lblWarningAbgangort.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
If (txbNachOrt._value = "" And txbNachPLZ._value = "") Then
lblWarningBestimmungsort.Visible = True
btnOK.DialogResult = DialogResult.OK
isFilled = False
End If
Return isFilled
End Function
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
If (checkInputFields() = False) Then Exit Sub
calculateFreight()
If (checkInputFields() = False) Then Exit Sub
calculateFreightCosts()
End Sub
Private Sub resetInputFields()
txbCalcDistanceEU.Clear()
txbCalcDistanceNichtEU.Clear()
tbEUAnteilberechnet.Clear()
tbNichtEUAnteilberechnet.Clear()
If tbEUAnteil._value = "" Then tbEUAnteil._value = 0
If tbNichtEUAnteil._value = "" Then tbNichtEUAnteil._value = 0
End Sub
Private Sub setControlEUAnteile()
If ckbManAnteilsermittlung.Checked Then
tbEUAnteil.Enabled = False
tbNichtEUAnteil.Enabled = False
Else
tbEUAnteil.Enabled = True
tbNichtEUAnteil.Enabled = True
resetInputFields()
End If
End Sub
Private Sub txbCalcDistanceEU_TextChanged(sender As Object, e As EventArgs) Handles txbCalcDistanceEU.TextChanged, txbCalcDistanceNichtEU.TextChanged, txbCalcDistanceNichtEU.TextChanged, tbNichtEUAnteilberechnet.TextChanged, tbEUAnteil.TextChanged, tbNichtEUAnteil.TextChanged
txtDistanzEU.Text = txbCalcDistanceEU.Text
txtDistanzNichtEU.Text = txbCalcDistanceNichtEU.Text
'tbEUAnteilberechnet2.Text = txbCalcDistanceNichtEU.Text
'tbNichtEUAnteilberechnet22.Text = tbNichtEUAnteilberechnet.Text
'tbEUAnteil2.Text = tbEUAnteil.Text
'tbNichtEUAnteil2.Text = tbNichtEUAnteil.Text
End Sub
Private Sub MyTextBox1_ValueChanged() Handles txtAnteilZollInProzent.ValueChanged
If IsNumeric(txtAnteilZollInProzent._value) AndAlso IsNumeric(txtVerzollungskosten._value) Then
If CDbl(txtAnteilZollInProzent._value) < 100 And CDbl(txtAnteilZollInProzent._value) > 0 And CDbl(txtVerzollungskosten._value) > 0 Then
txtAnteilZoll._value = CDbl((txtAnteilZollInProzent._value * 100) * txtVerzollungskosten._value / (100 + CDbl(txtAnteilZollInProzent._value * 100)))
End If
End If
End Sub
Private Sub MyTextBox2_ValueChanged() Handles txtPreis.ValueChanged, txtWarengewichtNetto.ValueChanged
If IsNumeric(txtPreis._value) And IsNumeric(txtWarengewichtNetto._value) Then
txtGesamtpreis._value = txtPreis._value * txtWarengewichtNetto._value
End If
End Sub
Private Sub txtFrachtanteil_ValueChanged() Handles txtFrachtkostenanteil.ValueChanged, txtGesamtpreis.ValueChanged
If IsNumeric(txtFrachtkostenanteil._value) And IsNumeric(txtGesamtpreis._value) Then
txtVerzollungskosten._value = CDbl(txtGesamtpreis._value - txtFrachtkostenanteil._value)
End If
End Sub
Private Sub txtWarengewicht_ValueChanged() Handles txtWarengewichtBrutto.ValueChanged, txtGesamtfracht.ValueChanged
If IsNumeric(txtWarengewichtBrutto._value) And IsNumeric(txtGesamtgewicht._value) Then
Dim anteil As Double = Math.Round(CDbl(txtWarengewichtBrutto._value / txtGesamtgewicht._value * 100), 2)
lblAnteil.Text = anteil & " %"
If IsNumeric(txtGesamtfracht._value) Then
txtWarenanteilsumme._value = CDbl(txtGesamtfracht._value * anteil / 100)
End If
Else
lblAnteil.Text = ""
End If
End Sub
Private Sub txbCalcDistanceNichtEU2_TextChanged(sender As Object, e As EventArgs) Handles txtDistanzNichtEU.TextChanged, txtDistanzEU.TextAlignChanged
If IsNumeric(txtDistanzNichtEU._value) AndAlso IsNumeric(txtDistanzEU._value) Then
txtGesamtdistanz._value = CDbl(txtDistanzNichtEU._value) + CDbl(txtDistanzEU._value)
End If
End Sub
Private Sub txtDistanzGes_ValueChanged() Handles txtGesamtdistanz.ValueChanged, txtWarenanteilsumme.ValueChanged
If IsNumeric(txtGesamtdistanz._value) And IsNumeric(txtWarenanteilsumme._value) And IsNumeric(txtDistanzEU._value) Then
txtGesamtfrachtAnteil._value = CDbl(txtWarenanteilsumme._value / txtGesamtdistanz._value * txtDistanzEU._value)
txtFrachtkostenanteil._value = txtGesamtfrachtAnteil._value
End If
End Sub
Private Sub txtVerzollungskosten_ValueChanged() Handles txtVerzollungskosten.ValueChanged, txtAnteilZoll.ValueChanged
If IsNumeric(txtVerzollungskosten._value) AndAlso IsNumeric(txtAnteilZoll._value) Then
txtBGLZoll._value = CDbl(txtVerzollungskosten._value) + CDbl(txtAnteilZoll._value)
End If
End Sub
Private Sub txtPreis_ValueChanged() Handles txtGesamtpreis.ValueChanged
If IsNumeric(txtGesamtpreis._value) Then
txtBGLEUST._value = txtGesamtpreis._value
End If
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
If Not ContextMenuStrip1.Items.ContainsKey("open") Then
Dim uploadPictures = New ToolStripMenuItem() With {.Text = "öffnen", .Name = "open"}
ContextMenuStrip1.Items.Add(uploadPictures)
AddHandler uploadPictures.Click, AddressOf mnuItem_Clicked
End If
If Not ContextMenuStrip1.Items.ContainsKey("createAttachment") Then
Dim copyToClipboard = New ToolStripMenuItem() With {.Text = "als Anhang anfügen", .Name = "createAttachment"}
AddHandler copyToClipboard.Click, AddressOf mnuItem_Clicked
ContextMenuStrip1.Items.Add(copyToClipboard)
End If
ContextMenuStrip1.Show(Cursor.Position)
End Sub
Private Sub mnuItem_Clicked(sender As Object, e As EventArgs)
ContextMenuStrip1.Hide()
Dim item As ToolStripMenuItem = TryCast(sender, ToolStripMenuItem)
If item IsNot Nothing Then
Dim tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("Frachtkostenberechnung", ".pdf", , False)
If item.Name = "open" Then
createFrachtkostenberechnung(tmpPath)
Process.Start(tmpPath)
ElseIf item.Name = "createAttachment" Then
createFrachtkostenberechnung(tmpPath)
If avisoid < 0 Then
MsgBox("AvisoId wurde nicht korrekt ermittelt!")
Exit Sub
End If
Dim f As New frmSendungAnhangImport(avisoid)
If f.addData_SendungAnhang(tmpPath) > 0 Then
MsgBox("Formular wurde in der Sendung angefügt")
Else
MsgBox("Fehler beim Einfügen")
End If
Else
MsgBox("Funktion nicht implementiert!")
End If
End If
End Sub
Private Sub createFrachtkostenberechnung(tmpPath As String)
Try
Me.Cursor = Cursors.WaitCursor
Dim rptFrachtkosten As New SDL.rptFrachtkostenberechnung(txtWare.Text, txtPreis.Text, txtWarengewichtNetto.Text, txtGesamtpreis.Text, txtFrachtkostenanteil.Text, txtVerzollungskosten.Text, txtAnteilZoll.Text, txtAnteilZollInProzent._value, txtBGLZoll.Text, txtBGLEUST.Text, txtDistanzEU.Text, txtDistanzNichtEU.Text, txtGesamtdistanz.Text, txtGesamtgewicht.Text, txtWarengewichtBrutto.Text, lblAnteil.Text, txtWarenanteilsumme.Text, txtGesamtfracht.Text, txtGesamtfrachtAnteil.Text)
Dim p As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
rptFrachtkosten.Run(False)
p.NeverEmbedFonts = ""
p.Export(rptFrachtkosten.Document, tmpPath)
Me.Cursor = Cursors.Default
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
Me.Cursor = Cursors.Default
End Try
End Sub
End Class