Mahnlauf, FaktMail, EORI-Antrag NEU, Offerte, CBAM, MDM-USTVAntrag

This commit is contained in:
2025-05-23 15:15:09 +02:00
parent 44c87e5060
commit 9a1300ba92
19 changed files with 2106 additions and 519 deletions

View File

@@ -24,6 +24,7 @@ Public Class usrCntlFaktAbrechnung
Dim vorherige_RK_ID = 0
Dim nachstehende_RK_ID = 0
Dim veragKunde As Integer = -1
Public isVZ As Boolean = False
' Public VALUE_CHANGED = True ' Eigenschaft, ob das Formular gespeichert ist oder verändert wurde
@@ -1180,6 +1181,14 @@ Public Class usrCntlFaktAbrechnung
Sub initDGVOfferteDetailsUebersicht(kdNr, OffertenNr)
Dim addFieldsBoolean As Boolean = True
Dim addFields As String = ""
If addFieldsBoolean Then
addFields = ", Land, RMC, Fremd, VZ"
End If
With dgvOfferteDetailsUebersicht
If Not IsNumeric(kdNr) OrElse kdNr < 0 Then
.Columns.Clear()
@@ -1210,14 +1219,24 @@ Public Class usrCntlFaktAbrechnung
c = New DataGridViewTextBoxColumn() : c.Name = "BerechnungsartPosInkludiert" : .Columns.Add(c)
c = New DataGridViewTextBoxColumn() : c.Name = "ReverseCharge" : .Columns.Add(c)
If addFieldsBoolean Then
Dim dt As DataTable = SQL.loadDgvBySql(" SELECT [Offertenpositionen].[LeistungsNr],[Offertenpositionen].[LeistungsBez],[Anzahl],[Preis],[Offertenpositionen].[BerechnungsartNr],[BGebLeistungsNr],[BGebProzent],[BGebMinBetrag],Steuerpflichtig, ReverseCharge/*,[Geändert am],[Sachbearbeiter]*/,BerechnungsartPosInkludiert " &
c = New DataGridViewTextBoxColumn() : c.Name = "Land" : .Columns.Add(c)
c = New DataGridViewTextBoxColumn() : c.Name = "RMC" : .Columns.Add(c)
c = New DataGridViewTextBoxColumn() : c.Name = "Fremd" : .Columns.Add(c)
c = New DataGridViewTextBoxColumn() : c.Name = "VZ" : .Columns.Add(c)
End If
Dim dt As DataTable = SQL.loadDgvBySql(" SELECT [Offertenpositionen].[LeistungsNr],[Offertenpositionen].[LeistungsBez],[Anzahl],[Preis],[Offertenpositionen].[BerechnungsartNr],[BGebLeistungsNr],[BGebProzent],[BGebMinBetrag],Steuerpflichtig, ReverseCharge/*,[Geändert am],[Sachbearbeiter]*/,BerechnungsartPosInkludiert " & addFields &
" FROM [Offertenpositionen] INNER JOIN [Leistungen] ON leistungen.LeistungsNr=Offertenpositionen.LeistungsNr " &
" WHERE KundenNr='" & kdNr & "' and OffertenNr='" & OffertenNr & "' ORDER BY LeistungsNr ", "FMZOLL")
'If .ColumnCount = 0 Then Exit Sub
.Columns("LeistungsNr").Width = 30
'If .ColumnCount = 0 Then Exit Sub
.Columns("LeistungsNr").Width = 30
.Columns("LeistungsNr").HeaderText = "Nr"
.Columns("LeistungsBez").MinimumWidth = 180
.Columns("LeistungsBez").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
@@ -1271,6 +1290,12 @@ Public Class usrCntlFaktAbrechnung
' .Columns("Geändert am").Visible = False
'.Columns("Sachbearbeiter").Visible = False
If addFieldsBoolean Then
End If
.Columns("IndexZkteing").Visible = False
@@ -1286,14 +1311,14 @@ Public Class usrCntlFaktAbrechnung
steuerpflichtigTMP = (RECHNUNG.ForceSteuerschlüssel > 0)
End If
If True Then
If addFieldsBoolean Then
dgvOfferteDetailsUebersicht.Rows.Add(r("LeistungsNr"), r("LeistungsBez"), r("Anzahl"), r("Preis"), r("BerechnungsartNr"), r("BGebLeistungsNr"), r("BGebProzent"), r("BGebMinBetrag"), steuerpflichtigTMP,
DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, r("BerechnungsartPosInkludiert"), r("ReverseCharge"))
DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, r("BerechnungsartPosInkludiert"), r("ReverseCharge"), r("Land"), r("RMC"), r("Fremd"), r("VZ"))
Else
dgvOfferteDetailsUebersicht.Rows.Add(r("LeistungsNr"), r("LeistungsBez"), r("Anzahl"), r("Preis"), r("BerechnungsartNr"), DBNull.Value, DBNull.Value, DBNull.Value, steuerpflichtigTMP,
DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, r("BerechnungsartPosInkludiert"))
DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, r("BerechnungsartPosInkludiert"), r("ReverseCharge"))
End If
@@ -1444,9 +1469,9 @@ Public Class usrCntlFaktAbrechnung
POS.Anzahl = If(r.Cells("Anzahl").Value Is DBNull.Value, 0, r.Cells("Anzahl").Value)
'-----------------------MWST-Abrechnung! + Kompat. zu FM-Zoll
If FIRMA IsNot Nothing AndAlso FIRMA.Firma_ID = 19 Then
If FIRMA IsNot Nothing AndAlso FIRMA.Firma_ID = 19 AndAlso RECHNUNG.DruckDatumZeit Is Nothing Then
Dim isRC As Boolean = If(r.Cells("ReverseCharge").Value IsNot DBNull.Value, r.Cells("ReverseCharge").Value, False)
setMWSTABRfromSPEDinPOS(r, POS, landNr, landBez, antrag)
setMWSTABRfromSPEDinPOS(r, POS, landNr, landBez, antrag, isVZ)
End If
'-----------------------MWST-Abrechnung! + Kompat. zu FM-Zoll
@@ -1741,7 +1766,7 @@ Public Class usrCntlFaktAbrechnung
End If
RECHNUNG.LOAD_ANHAENGE()
If RECHNUNG IsNot Nothing AndAlso RECHNUNG.ANHAENGE IsNot Nothing Then
If RECHNUNG IsNot Nothing AndAlso RECHNUNG.ANHAENGE IsNot Nothing And Not VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
'-----------------------------
'ANHÄNGE OHNE AVISO-BEZUG LADEN:
'-----------------------------
@@ -1796,7 +1821,7 @@ Public Class usrCntlFaktAbrechnung
If DAID <> "" AndAlso IsNumeric(DAID) Then
Dim daidno As Integer = CInt(DAID)
Dim ds As New cDATENSERVER(daidno)
.Rows.Add(1, nameLief, ds.da_name, ds.da_id, -1)
.Rows.Add(-1, nameLief, ds.da_name, ds.da_id, -1)
End If
Next
@@ -2570,10 +2595,13 @@ Public Class usrCntlFaktAbrechnung
' POS.BGebLeistungsNr = BGebLeistungsNr
RE.POSITIONEN.Add(POS)
End If
POS.Preis += Betrag
'End If
If POS.Steuerpflichtig Then
POS.SteuerpflichtigerBetrag += Betrag
Else
@@ -4485,22 +4513,49 @@ Nächste_Textzeile_lesen:
Private Sub setMWSTABRfromSPEDinPOS(r As DataGridViewRow, POS As cRechnungsausgangPositionen, LandNr As String, LandBez As String, Optional antrag As cUSTVAntrag = Nothing, Optional isVZ As Boolean = False)
If SPEDBUCH.Abfertigungsart = 114 Or SPEDBUCH.Abfertigungsart = 115 Or SPEDBUCH.Abfertigungsart = 10 Then
If SPEDBUCH IsNot Nothing AndAlso (SPEDBUCH.Abfertigungsart = 114 Or SPEDBUCH.Abfertigungsart = 115 Or SPEDBUCH.Abfertigungsart = 10) Then
Dim LeistungsBez = r.Cells("LeistungsBez").Value
If LeistungsBez <> "" Then
Dim isMWST As Boolean = False
Dim kdNr = IIf(RECHNUNG.RechnungsKundenNr > 0, RECHNUNG.RechnungsKundenNr, kdFirmaRechnungAn.KdNr)
Dim isRMC = IIf(kdNr = 150000 AndAlso antrag.UStVAn_AntragArt = "MWST", True, False)
Dim sumRMC As Double = 0
Dim sumFremdBeleg As Double = 0
If antrag IsNot Nothing AndAlso LandBez <> "" AndAlso antrag.UStVAn_AntragArt <> "" Then
Dim OFFERT_LAND = ""
Dim OFFERT_VZ = False
Dim OFFERT_RMC = False
Dim OFFERT_FREMD = False
Dim OFFERT_LeistungsBez = r.Cells("LeistungsBez").Value
If antrag.UStVAn_AntragArt <> "MWST" Then isRMC = False
If Not IsDBNull(r.Cells("Land").Value) AndAlso r.Cells("Land").Value IsNot Nothing AndAlso r.Cells("Land").Value <> "" Then
OFFERT_LAND = r.Cells("Land").Value
End If
Dim LandISO2 = ""
If Not IsDBNull(r.Cells("VZ").Value) AndAlso r.Cells("VZ").Value IsNot Nothing Then
OFFERT_VZ = r.Cells("VZ").Value
End If
If Not IsDBNull(r.Cells("RMC").Value) AndAlso r.Cells("RMC").Value IsNot Nothing Then
OFFERT_RMC = r.Cells("RMC").Value
End If
If Not IsDBNull(r.Cells("Fremd").Value) AndAlso r.Cells("Fremd").Value IsNot Nothing Then
OFFERT_FREMD = r.Cells("Fremd").Value
End If
If OFFERT_LeistungsBez <> "" AndAlso OFFERT_LAND <> "" Then
If (isVZ = OFFERT_VZ) Then
Dim isMWST As Boolean = False
Dim kdNr = IIf(RECHNUNG.RechnungsKundenNr > 0, RECHNUNG.RechnungsKundenNr, kdFirmaRechnungAn.KdNr)
Dim isRMCKunde = IIf(kdNr = 150000 AndAlso antrag.UStVAn_AntragArt = "MWST", True, False)
Dim sumRMC As Double = 0
Dim sumFremdBeleg As Double = 0
Dim sumBelegVZ As Double = 0
If antrag IsNot Nothing AndAlso LandBez <> "" AndAlso antrag.UStVAn_AntragArt <> "" Then
If antrag.UStVAn_AntragArt <> "MWST" Then isRMCKunde = False
Dim LandISO2 = ""
If LandBez.Length = 2 Then
LandISO2 = LandBez
@@ -4511,115 +4566,138 @@ Nächste_Textzeile_lesen:
End If
If LeistungsBez.ToString.Contains(LandISO2) AndAlso LeistungsBez.ToString.ToLower.StartsWith(antrag.UStVAn_AntragArt.ToString.ToLower) AndAlso IIf(isVZ, LeistungsBez.ToString.Contains("VZ"), Not LeistungsBez.ToString.Contains("VZ")) Then
If OFFERT_LAND = LandISO2 AndAlso OFFERT_LeistungsBez.ToString.ToLower.StartsWith(antrag.UStVAn_AntragArt.ToString.ToLower) Then
'wenn RMC, dann ebenfalls unterscheiden!
If isRMC Then
If isRMCKunde Then
If (OFFERT_FREMD Or OFFERT_RMC) Then
'aus AntragsPOS die
'aus AntragsPOS die
For Each ANTR_POS As cUStVPositionen In antrag.POSITIONEN
For Each ANTR_POS As cUStVPositionen In antrag.POSITIONEN
If ANTR_POS.UStVPo_Leistender.ToString.ToUpper.StartsWith("RMC") Then
sumRMC += ANTR_POS.UStVPo_USteuerbetragEUR
Else
sumFremdBeleg += ANTR_POS.UStVPo_USteuerbetragEUR
If ANTR_POS.UStVPo_Leistender.ToString.ToUpper.StartsWith("RMC") Then
If isVZ Then
If ANTR_POS.UStVPo_VZ AndAlso (IsDBNull(ANTR_POS.UStVPo_VZ_RKID) Or ANTR_POS.UStVPo_VZ_RKID Is Nothing) Then sumRMC += ANTR_POS.UStVPo_USteuerbetragEUR
Else
If ANTR_POS.UStVPo_VZ_RKID Is Nothing AndAlso (IsDBNull(ANTR_POS.UStVPo_VZ) OrElse Not ANTR_POS.UStVPo_VZ) Then sumRMC += ANTR_POS.UStVPo_USteuerbetragEUR
End If
Else
If isVZ Then
If ANTR_POS.UStVPo_VZ AndAlso (IsDBNull(ANTR_POS.UStVPo_VZ_RKID) Or ANTR_POS.UStVPo_VZ_RKID Is Nothing) Then sumFremdBeleg += ANTR_POS.UStVPo_USteuerbetragEUR
Else
If ANTR_POS.UStVPo_VZ_RKID Is Nothing AndAlso (IsDBNull(ANTR_POS.UStVPo_VZ) OrElse Not ANTR_POS.UStVPo_VZ) Then sumFremdBeleg += ANTR_POS.UStVPo_USteuerbetragEUR
End If
End If
Next
'SPEDBUCH.Abfertigungsart = 114 -> EU
'SPEDBUCH.Abfertigungsart = 115 -> DL Drittland
Dim BEZ_LAND_RMC As String = ""
Select Case SPEDBUCH.Abfertigungsart
Case 114 : BEZ_LAND_RMC = IIf(isVZ, "00", "00-00")
Case 115 : BEZ_LAND_RMC = IIf(isVZ, "DL", "DL-00")
End Select
If (OFFERT_RMC Or OFFERT_FREMD) AndAlso OFFERT_VZ = isVZ AndAlso OFFERT_LeistungsBez.ToString.Contains(BEZ_LAND_RMC) Then
isMWST = True
GoTo mwst
End If
Next
End If
Else
'SPEDBUCH.Abfertigungsart = 114 -> EU
'SPEDBUCH.Abfertigungsart = 115 -> DL Drittland
If isVZ AndAlso OFFERT_VZ Then
Dim BEZ_LAND_RMC As String = ""
Select Case SPEDBUCH.Abfertigungsart
Case 114 : BEZ_LAND_RMC = "00-"
Case 115 : BEZ_LAND_RMC = "DL-00"
End Select
For Each ANTR_POS As cUStVPositionen In antrag.POSITIONEN
If ANTR_POS.UStVPo_VZ AndAlso (IsDBNull(ANTR_POS.UStVPo_VZ_RKID) Or ANTR_POS.UStVPo_VZ_RKID Is Nothing) Then sumBelegVZ += ANTR_POS.UStVPo_USteuerbetragEUR
Next
If LeistungsBez.ToString.Contains("RMC-RG") AndAlso LeistungsBez.ToString.Contains(BEZ_LAND_RMC) Then
isMWST = True
GoTo mwst
ElseIf LeistungsBez.ToString.Contains("FREMD-RG") AndAlso LeistungsBez.ToString.Contains(BEZ_LAND_RMC) Then
ElseIf Not isVZ AndAlso Not OFFERT_VZ Then
For Each ANTR_POS As cUStVPositionen In antrag.POSITIONEN
If ANTR_POS.UStVPo_VZ_RKID Is Nothing AndAlso (IsDBNull(ANTR_POS.UStVPo_VZ) OrElse Not ANTR_POS.UStVPo_VZ) Then sumFremdBeleg += ANTR_POS.UStVPo_USteuerbetragEUR
Next
isMWST = True
GoTo mwst
End If
Else
isMWST = True
GoTo mwst
End If
End If
End If
If LandBez <> "" AndAlso LandNr <> "" Then
If SPEDBUCH.Packstücke.ToString.Replace("Mehrwertsteuerrückerstattung " & LandNr, "MWSt-Rückerstattung " & LandBez).StartsWith(LeistungsBez.ToString) AndAlso LeistungsBez.ToString.StartsWith("MWSt-Rückerstattung") Then
isMWST = True
GoTo mwst
End If
Else
If SPEDBUCH.Packstücke.ToString().Replace("Mehrwertsteuerrückerstattung ", "MWSt-Rückerstattung ").StartsWith(LeistungsBez.ToString) AndAlso LeistungsBez.ToString.StartsWith("MWSt-Rückerstattung") Then
isMWST = True
GoTo mwst
End If
End If
mwst:
If isMWST Then
POS.Anzahl = 1
If isMWST Then
POS.Anzahl = 1
If antrag IsNot Nothing AndAlso antrag.UStVAn_ID > 0 Then
If antrag IsNot Nothing AndAlso antrag.UStVAn_ID > 0 Then
If POS.Preis = 0 Then
If POS.Preis = 0 Then
Dim GesamtUSteuerEUR As Double = SQL.DLookup("isnull(sum(UStVPo_USteuerbetragEUR),0)", "tblUStVPositionen", "UStVAn_ID='" & antrag.UStVAn_ID & "'", "FMZOLL", "0")
Dim GesamtErstattungEUR As Double = SQL.DLookup("isnull(sum(UStVEr_USteuerbetragEUR),0)", "tblUStVErstattung", "UStVAn_ID='" & antrag.UStVAn_ID & "'", "FMZOLL", "0")
If isRMCKunde Then
If OFFERT_RMC AndAlso sumRMC <> 0 Then
POS.Preis = sumRMC * -1
ElseIf OFFERT_FREMD AndAlso sumFremdBeleg <> 0 Then
POS.Preis = sumFremdBeleg * -1
End If
Else
If sumBelegVZ <> 0 Then
POS.Preis = sumBelegVZ * -1
Else
Dim GesamtUSteuerEUR As Double = SQL.DLookup("isnull(sum(UStVPo_USteuerbetragEUR),0)", "tblUStVPositionen", "UStVAn_ID='" & antrag.UStVAn_ID & "'", "FMZOLL", "0")
Dim GesamtErstattungEUR As Double = SQL.DLookup("isnull(sum(UStVEr_USteuerbetragEUR),0)", "tblUStVErstattung", "UStVAn_ID='" & antrag.UStVAn_ID & "'", "FMZOLL", "0")
Dim DiffernezbetragEUR As Double = GesamtUSteuerEUR - GesamtErstattungEUR
If DiffernezbetragEUR <> 0 Then
POS.Preis = DiffernezbetragEUR * -1
End If
End If
If isRMC Then
If LeistungsBez.ToString.Contains("RMC-RG") AndAlso sumRMC <> 0 Then
POS.Preis = sumRMC * -1
ElseIf LeistungsBez.ToString.Contains("FREMD-RG") AndAlso sumFremdBeleg <> 0 Then
POS.Preis = sumFremdBeleg * -1
End If
Else
Dim DiffernezbetragEUR As Double = GesamtUSteuerEUR - GesamtErstattungEUR
If DiffernezbetragEUR <> 0 Then
POS.Preis = DiffernezbetragEUR * -1
End If
End If
End If
End If
If r.Cells("BGebLeistungsNr").Value IsNot Nothing AndAlso Not IsDBNull(r.Cells("BGebLeistungsNr").Value) AndAlso r.Cells("BGebProzent").Value IsNot Nothing AndAlso Not IsDBNull(r.Cells("BGebProzent").Value) Then
If r.Cells("BGebLeistungsNr").Value IsNot Nothing AndAlso Not IsDBNull(r.Cells("BGebLeistungsNr").Value) AndAlso r.Cells("BGebProzent").Value IsNot Nothing AndAlso Not IsDBNull(r.Cells("BGebProzent").Value) Then
Dim OffertNr As Integer = IIf(IsNumeric(RECHNUNG.OffertenNr), RECHNUNG.OffertenNr, (SPEDBUCH.Abfertigungsart - 100))
If OffertNr < 0 Then OffertNr = 15
Dim OffertNr As Integer = IIf(IsNumeric(RECHNUNG.OffertenNr), RECHNUNG.OffertenNr, (SPEDBUCH.Abfertigungsart - 100))
If OffertNr < 0 Then OffertNr = 15
Dim OFFERTE As New VERAG_PROG_ALLGEMEIN.cOfferte(IIf(RECHNUNG.RechnungsKundenNr > 0, RECHNUNG.RechnungsKundenNr, kdFirmaRechnungAn.KdNr), OffertNr, True)
Call prBearbGeb(POS, OFFERTE, RECHNUNG, r.Cells("BGebLeistungsNr").Value, r.Cells("BGebProzent").Value, POS.Preis * If(RECHNUNG.Vorzeichen = "-", -1, 1))
Dim OFFERTE As New VERAG_PROG_ALLGEMEIN.cOfferte(IIf(RECHNUNG.RechnungsKundenNr > 0, RECHNUNG.RechnungsKundenNr, kdFirmaRechnungAn.KdNr), OffertNr, True)
Call prBearbGeb(POS, OFFERTE, RECHNUNG, r.Cells("BGebLeistungsNr").Value, r.Cells("BGebProzent").Value, POS.Preis * If(RECHNUNG.Vorzeichen = "-", -1, 1))
End If
End If
End If
End If
End If
End Sub
End Class