
Imports System.Data.SqlClient
Imports System.Reflection
Public Class cPLOSE

    Property plose_Id As Integer

    Property plose_RechnungsDatum As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_RechnungsNr As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_SupplierRechnungsDatum As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_SupplierRechnungsNr As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_RechnungsJahr As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_Lieferant As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_LieferantCode As Object = Nothing '                  VARCHAR(3)     NULL, 
    Property plose_Dateiname As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_Einlesedatum As Date = Now '                  VARCHAR(3)     NULL,
    Property plose_Datensatztyp As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_KodexMautTankstelle As Object = Nothing '           VARCHAR(7)     NULL,
    Property plose_BeschreibungMautTankstelle As Object = Nothing '    VARCHAR(12)    NULL,
    Property plose_KodexEinfahrt As Object = Nothing '                 VARCHAR(7)     NULL,
    Property plose_BeschreibungEinfahrt As Object = Nothing '          VARCHAR(12)    NULL,
    Property plose_KodexAusfahrt As Object = Nothing '                 VARCHAR(7)     NULL,
    Property plose_BeschreibungAusfahrt As Object = Nothing '          VARCHAR(12)    NULL,
    Property plose_Kartenkodex As Object = Nothing '                   VARCHAR(7)     NULL,
    Property plose_Kontonummer As Object = Nothing '                   VARCHAR(13)    NULL,
    Property plose_NummerKarteGeraet As Object = Nothing '             VARCHAR(20)    NULL,
    Property plose_Kennzeichen As Object = Nothing '                   VARCHAR(10)    NULL,
    Property plose_InterneNrFahrzeug As Object = Nothing '             VARCHAR(6)     NULL,
    Property plose_POLSEKundennummer As Object = Nothing '             VARCHAR(6)     NULL,
    Property plose_Firmenname As Object = Nothing '                    VARCHAR(35)    NULL,
    Property plose_DatumTransaktion As Object = Nothing '              VARCHAR(8)     NULL,
    Property plose_Produktbeschreibung As Object = Nothing '           VARCHAR(15)    NULL,
    Property plose_Menge As Object = Nothing '                         Decimal (9, 2)  NULL,
    Property plose_Preis As Object = Nothing '                         Decimal (9, 3)  NULL,
    Property Einheitsrabatt As Object = Nothing '                      VARCHAR(8)     NULL,
    Property plose_NettobetragTransaktion As Object = Nothing '        Decimal (12, 2) NULL,
    Property plose_MWSTBetrag As Object = Nothing '                    Decimal (12, 2) NULL,
    Property plose_BruttobetragTransaktion As Object = Nothing '       Decimal (12, 2) NULL,
    Property plose_NettobetragWaehrungAbbuchung As Object = Nothing '  Decimal (12, 2) NULL,
    Property plose_MWSTBetragWaehrungAbbuchung As Object = Nothing '   Decimal (12, 2) NULL,
    Property plose_BruttobetragWaehrungAbbuchung As Object = Nothing ' Decimal (12, 2) NULL,
    Property plose_WaehrungLandDiesntleistung As Object = Nothing '    VARCHAR(3)     NULL,
    Property plose_WaehrungAbbuchung As Object = Nothing '             VARCHAR(3)     NULL,
    Property plose_DokumentNrQuittungUhrzeit As Object = Nothing '     VARCHAR(7)     NULL,
    Property plose_ArtTransaktion As Object = Nothing '                VARCHAR(1)     NULL,
    Property plose_Fahrzeugklasse As Object = Nothing '                VARCHAR(2)     NULL,
    Property plose_KlassenidentifikationEURO As Object = Nothing
    Property plose_ProduktbeschreibungShort As Object = Nothing
    Property plose_TransaktionUhrzeit As Object = Nothing
    Property plose_Geraetetyp As Object = Nothing
    Property plose_ProduktCode As Object = Nothing
    Property plose_ReferenzenBuchungMaut As Object = Nothing
    Property plose_Fakturiert As Boolean = False
    Property plose_FakturiertDatum As Object = Nothing


    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Sub New()

    End Sub

    Sub New(plose_id)
        Me.plose_Id = plose_id
        LOAD()
    End Sub


    Public Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_id", plose_Id, , True, True))

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_RechnungsDatum", plose_RechnungsDatum)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_RechnungsJahr", plose_RechnungsJahr)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_SupplierRechnungsDatum", plose_SupplierRechnungsDatum)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_SupplierRechnungsNr", plose_SupplierRechnungsNr)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_RechnungsNr", plose_RechnungsNr)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Lieferant", plose_Lieferant)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_LieferantCode", plose_LieferantCode)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Dateiname", plose_Dateiname)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Einlesedatum", plose_Einlesedatum)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Datensatztyp", plose_Datensatztyp)) '                  VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_KodexMautTankstelle", plose_KodexMautTankstelle)) '           VARCHAR(7)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_BeschreibungMautTankstelle", plose_BeschreibungMautTankstelle)) '    VARCHAR(12)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_KodexEinfahrt", plose_KodexEinfahrt)) '                 VARCHAR(7)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_BeschreibungEinfahrt", plose_BeschreibungEinfahrt)) '          VARCHAR(12)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_KodexAusfahrt", plose_KodexAusfahrt)) '                 VARCHAR(7)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_BeschreibungAusfahrt", plose_BeschreibungAusfahrt)) '          VARCHAR(12)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Kartenkodex", plose_Kartenkodex)) '                   VARCHAR(7)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Kontonummer", plose_Kontonummer)) '                   VARCHAR(13)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_NummerKarteGeraet", plose_NummerKarteGeraet)) '             VARCHAR(20)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Kennzeichen", plose_Kennzeichen)) '                   VARCHAR(10)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_InterneNrFahrzeug", plose_InterneNrFahrzeug)) '             VARCHAR(6)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_POLSEKundennummer", plose_POLSEKundennummer)) '             VARCHAR(6)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Firmenname", plose_Firmenname)) '                    VARCHAR(35)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_DatumTransaktion", plose_DatumTransaktion)) '              VARCHAR(8)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Produktbeschreibung", plose_Produktbeschreibung)) '           VARCHAR(15)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Menge", plose_Menge)) '                         Decimal (9, 2)  NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Preis", plose_Preis)) '                         Decimal (9, 3)  NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("Einheitsrabatt", Einheitsrabatt)) '                      VARCHAR(8)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_NettobetragTransaktion", plose_NettobetragTransaktion)) '        Decimal (12, 2) NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_MWSTBetrag", plose_MWSTBetrag)) '                    Decimal (12, 2) NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_BruttobetragTransaktion", plose_BruttobetragTransaktion)) '       Decimal (12, 2) NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_NettobetragWaehrungAbbuchung", plose_NettobetragWaehrungAbbuchung)) '  Decimal (12, 2) NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_MWSTBetragWaehrungAbbuchung", plose_MWSTBetragWaehrungAbbuchung)) '   Decimal (12, 2) NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_BruttobetragWaehrungAbbuchung", plose_BruttobetragWaehrungAbbuchung)) ' Decimal (12, 2) NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_WaehrungLandDiesntleistung", plose_WaehrungLandDiesntleistung)) '    VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_WaehrungAbbuchung", plose_WaehrungAbbuchung)) '             VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_DokumentNrQuittungUhrzeit", plose_DokumentNrQuittungUhrzeit)) '     VARCHAR(7)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_ArtTransaktion", plose_ArtTransaktion)) '                VARCHAR(1)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Fahrzeugklasse", plose_Fahrzeugklasse)) '                VARCHAR(2)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_KlassenidentifikationEURO", plose_KlassenidentifikationEURO)) '     VARCHAR(2)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_ProduktbeschreibungShort", plose_ProduktbeschreibungShort)) '      VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_TransaktionUhrzeit", plose_TransaktionUhrzeit)) '            VARCHAR(4)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Geraetetyp", plose_Geraetetyp)) '                    VARCHAR(3)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_ProduktCode", plose_ProduktCode)) '                   VARCHAR(6)     NULL,

        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_ReferenzenBuchungMaut", plose_ReferenzenBuchungMaut)) '         VARCHAR(33)    NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_Fakturiert", plose_Fakturiert)) '                   VARCHAR(6)     NULL,
        list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_FakturiertDatum", plose_FakturiertDatum)) '                   VARCHAR(6)     NULL,

        Return list
    End Function




    Public Function SAVE() As Boolean
        Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

        If Not VERAG_PROG_ALLGEMEIN.cProgramFunctions.ValidateSQLFieldLengths(list, "tblPLOSE_Details", "", "FMZOLL") Then
            Return False
        End If

        Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblPLOSE_Details WITH(updlock,serializable) WHERE plose_id=@plose_id) " &
                       " BEGIN " & getUpdateCmd() & " End " &
                       " Else " &
                       " BEGIN " & getInsertCmd() & " End " &
                       " commit tran "

        plose_Id = SQL.doSQLVarListID(plose_Id, sqlstr, "FMZOLL", , list)
        Return plose_Id > 0
    End Function


    Public Sub LOAD()
        Try
            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("Select * FROM tblPLOSE_Details WHERE plose_id=@plose_id  ", conn)
                    cmd.Parameters.AddWithValue("@plose_id", plose_Id)
                    Dim dr = cmd.ExecuteReader()
                    If dr.Read Then
                        For Each l In getParameterList()
                            Dim propInfo As PropertyInfo = Me.GetType.GetProperty(l.Scalarvariable)

                            If dr.Item(l.Text) Is DBNull.Value Then
                                propInfo.SetValue(Me, Nothing)
                            Else
                                propInfo.SetValue(Me, dr.Item(l.Text))
                            End If

                        Next

                    End If
                    dr.Close()
                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

    Shared Sub UPDATE_RGDatum(plose_RechnungsDatum As Date, plose_RechnungsNr As Integer, plose_POLSEKundennummer As Integer)
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
            SQL.doSQL("UPDATE tblPLOSE_Details SET plose_RechnungsDatum='" & plose_RechnungsDatum.ToShortDateString & "'  WHERE plose_RechnungsNr='" & plose_RechnungsNr & "'   AND plose_POLSEKundennummer='" & plose_POLSEKundennummer & "'   ", "FMZOLL")

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
    End Sub

    Shared Sub UPDATE_Lieferant(plose_Lieferant As Date, plose_RechnungsNr As Integer, plose_POLSEKundennummer As Integer)
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
            SQL.doSQL("UPDATE tblPLOSE_Details SET plose_Lieferant='" & plose_Lieferant & "'  WHERE plose_RechnungsNr='" & plose_RechnungsNr & "'   AND plose_POLSEKundennummer='" & plose_POLSEKundennummer & "'   ", "FMZOLL")

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
    End Sub


    Public Function getUpdateCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()

            Dim str As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            Return (" UPDATE [tblPLOSE_Details] SET " & str & " WHERE plose_id=@plose_id ")

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function


    Public Function getInsertCmd() As String
        Try
            Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
            Dim str As String = ""
            Dim values As String = ""
            For Each i In list
                If Not i.isPrimaryParam Then
                    str &= "[" & i.Text & "],"
                    values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
                End If
            Next
            str = str.Substring(0, str.Length - 1) 'wg. ','
            values = values.Substring(0, values.Length - 1) 'wg. ','
            Return (" INSERT INTO tblPLOSE_Details  (" & str & ") VALUES(" & values & ")  ")
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function


    Public Function DELETE() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
        Dim sqlstr = " DELETE FROM [tblPLOSE_Details] WITH(updlock,serializable) WHERE plose_id=" & Me.plose_Id
        Return SQL.doSQL(sqlstr, "FMZOLL")
    End Function

    Public Shared Function GET_Antraege(von As Date, bis As Date, KundenNr As Integer, Land As String, Optional Archiv As Object = Nothing, Optional MWSTSummenAusBeleg As Boolean = False) As List(Of cPLOSE_USTV_ANTR)
        Dim LIST As New List(Of cPLOSE_USTV_ANTR)

        If Not MWSTSummenAusBeleg Then
            GET_Antraege_PLOSE(LIST, von, bis, KundenNr, Land, Archiv)
            GET_Antraege_ByLieferantCode(LIST, "'90'", von, bis, KundenNr, Land, Archiv) 'SOFICO
            GET_Antraege_ByLieferantCodeNULL(LIST, von, bis, KundenNr, Land, Archiv) 'SOFICO
        Else
            GET_Antraege_PLOSE_NEU(LIST, von, bis, KundenNr, Land, Archiv)
        End If



        cPLOSE_USTV_ANTR.reOrderList(LIST)
        Return LIST
    End Function


    Public Shared Function GET_Antraege_ByLieferantCode(ByRef LIST As List(Of cPLOSE_USTV_ANTR), LieferantCode As String, von As Date, bis As Date, KundenNr As Integer, Land As String, Optional Archiv As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT  [plose_SupplierRechnungsDatum],[plose_SupplierRechnungsNr],[plose_Lieferant],[plose_LieferantCode],sum([plose_NettobetragWaehrungAbbuchung])[plose_NettobetragWaehrungAbbuchung],sum([plose_MWSTBetragWaehrungAbbuchung])[plose_MWSTBetragWaehrungAbbuchung] ,sum([plose_BruttobetragWaehrungAbbuchung] )[plose_BruttobetragWaehrungAbbuchung], [plose_WaehrungAbbuchung]
                                                    ,sum([plose_NettobetragTransaktion])[plose_NettobetragTransaktion],sum([plose_MWSTBetrag])[plose_MWSTBetrag] ,sum([plose_BruttobetragTransaktion] )[plose_BruttobetragTransaktion]
                                              FROM [tblPLOSE_Details] 
                                                    INNER JOIN Adressen on PLOSEKundenNr=plose_POLSEKundennummer 
                                                    INNER JOIN [tblPLOSE_Produktbeschreibung] ON [plp_ProductCode]=[plose_ProduktCode]
                                              where cast(plose_SupplierRechnungsDatum as date) between @von and @bis and AdressenNr=@AdressenNr 
                                                   AND plose_LieferantCode IN (" & LieferantCode & ")
                                                   AND plp_Land ='" & Land & "'
                                              " & IIf(Archiv, "", " AND plose_Archiv = 0") & "
                                                group by  [plose_SupplierRechnungsDatum],[plose_SupplierRechnungsNr],[plose_LieferantCode],[plose_Lieferant],[plose_WaehrungAbbuchung]
                                                 having sum(plose_MWSTBetrag)>0
                                              	order by plose_SupplierRechnungsDatum
                                              ", conn)

                    cmd.Parameters.AddWithValue("@von", von)
                    cmd.Parameters.AddWithValue("@bis", bis)
                    cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)


                    Dim dr = cmd.ExecuteReader()
                    While dr.Read

                        Dim cPLOSE_USTV_ANT As New cPLOSE_USTV_ANTR
                        cPLOSE_USTV_ANT.plose_RechnungsDatum = dr.Item("plose_SupplierRechnungsDatum")
                        cPLOSE_USTV_ANT.plose_RechnungsNr = dr.Item("plose_SupplierRechnungsNr")
                        cPLOSE_USTV_ANT.plose_Lieferant = dr.Item("plose_Lieferant")
                        cPLOSE_USTV_ANT.plose_LieferantCode = dr.Item("plose_LieferantCode")
                        cPLOSE_USTV_ANT.plose_NettobetragTransaktion = dr.Item("plose_NettobetragTransaktion")
                        cPLOSE_USTV_ANT.plose_MWSTBetrag = dr.Item("plose_MWSTBetrag")
                        cPLOSE_USTV_ANT.plose_BruttobetragTransaktion = dr.Item("plose_BruttobetragTransaktion")
                        cPLOSE_USTV_ANT.plose_NettobetragWaehrungAbbuchung = dr.Item("plose_NettobetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_MWSTBetragWaehrungAbbuchung = dr.Item("plose_MWSTBetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_BruttobetragWaehrungAbbuchung = dr.Item("plose_BruttobetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_WaehrungAbbuchung = dr.Item("plose_WaehrungAbbuchung")

                        LIST.Add(cPLOSE_USTV_ANT)

                    End While
                    dr.Close()

                End Using
            End Using
            Return True
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return False

    End Function

    Public Shared Function GET_Antraege_ByLieferantCodeNULL(ByRef LIST As List(Of cPLOSE_USTV_ANTR), von As Date, bis As Date, KundenNr As Integer, Land As String, Optional Archiv As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT  [plose_SupplierRechnungsDatum],[plose_SupplierRechnungsNr],[plose_Lieferant],[plose_LieferantCode],sum([plose_NettobetragWaehrungAbbuchung])[plose_NettobetragWaehrungAbbuchung],sum([plose_MWSTBetragWaehrungAbbuchung])[plose_MWSTBetragWaehrungAbbuchung] ,sum([plose_BruttobetragWaehrungAbbuchung] )[plose_BruttobetragWaehrungAbbuchung], [plose_WaehrungAbbuchung]
                                                    ,sum([plose_NettobetragTransaktion])[plose_NettobetragTransaktion],sum([plose_MWSTBetrag])[plose_MWSTBetrag] ,sum([plose_BruttobetragTransaktion] )[plose_BruttobetragTransaktion]
                                              FROM [tblPLOSE_Details] 
                                                    INNER JOIN Adressen on PLOSEKundenNr=plose_POLSEKundennummer 
                                                    INNER JOIN [tblPLOSE_Produktbeschreibung] ON [plp_ProductCode]=[plose_ProduktCode]
                                              where cast(plose_SupplierRechnungsDatum as date) between @von and @bis and AdressenNr=@AdressenNr 
                                                   AND plose_LieferantCode is null
                                                   AND plp_Land ='" & Land & "'
                                                   " & IIf(Archiv, "", " AND plose_Archiv = 0") & "
                                                group by  [plose_SupplierRechnungsDatum],[plose_SupplierRechnungsNr],[plose_LieferantCode],[plose_Lieferant],[plose_WaehrungAbbuchung]
                                                 having sum(plose_MWSTBetrag)>0
                                              	order by plose_SupplierRechnungsDatum
                                              ", conn)

                    cmd.Parameters.AddWithValue("@von", von)
                    cmd.Parameters.AddWithValue("@bis", bis)
                    cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)


                    Dim dr = cmd.ExecuteReader()
                    While dr.Read

                        Dim cPLOSE_USTV_ANT As New cPLOSE_USTV_ANTR
                        cPLOSE_USTV_ANT.plose_RechnungsDatum = dr.Item("plose_SupplierRechnungsDatum")
                        cPLOSE_USTV_ANT.plose_RechnungsNr = dr.Item("plose_SupplierRechnungsNr")
                        cPLOSE_USTV_ANT.plose_Lieferant = dr.Item("plose_Lieferant")
                        cPLOSE_USTV_ANT.plose_LieferantCode = dr.Item("plose_LieferantCode")
                        cPLOSE_USTV_ANT.plose_NettobetragTransaktion = dr.Item("plose_NettobetragTransaktion")
                        cPLOSE_USTV_ANT.plose_MWSTBetrag = dr.Item("plose_MWSTBetrag")
                        cPLOSE_USTV_ANT.plose_BruttobetragTransaktion = dr.Item("plose_BruttobetragTransaktion")
                        cPLOSE_USTV_ANT.plose_NettobetragWaehrungAbbuchung = dr.Item("plose_NettobetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_MWSTBetragWaehrungAbbuchung = dr.Item("plose_MWSTBetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_BruttobetragWaehrungAbbuchung = dr.Item("plose_BruttobetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_WaehrungAbbuchung = dr.Item("plose_WaehrungAbbuchung")

                        LIST.Add(cPLOSE_USTV_ANT)

                    End While
                    dr.Close()

                End Using
            End Using
            Return True
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return False

    End Function


    Public Shared Function getWhereDblEntry() As String
        Return " AND   (SELECT count(*)  FROM [tblUStVAntrag]  as ANTRAG2  inner join [tblUStVPositionen] as POS2 on ANTRAG2.UStVAn_ID= POS2.UStVAn_ID
                                WHERE   POS2.UStVPo_SchnittstellenNr=6 AND [plose_RechnungsNr] = POS2.UStVPo_ReNr AND [plose_RechnungsDatum]=POS2.UStVPo_ReDat  )   = 0 "
    End Function

    Public Shared Function GET_Antraege_PLOSE(ByRef LIST As List(Of cPLOSE_USTV_ANTR), von As Date, bis As Date, KundenNr As Integer, Land As String, Optional Archiv As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT  [plose_RechnungsDatum],[plose_RechnungsNr],[plose_Lieferant],[plose_LieferantCode],sum([plose_NettobetragWaehrungAbbuchung])[plose_NettobetragWaehrungAbbuchung],sum([plose_MWSTBetragWaehrungAbbuchung])[plose_MWSTBetragWaehrungAbbuchung] ,sum([plose_BruttobetragWaehrungAbbuchung] )[plose_BruttobetragWaehrungAbbuchung], [plose_WaehrungAbbuchung]
                                                    ,sum([plose_NettobetragTransaktion])[plose_NettobetragTransaktion],sum([plose_MWSTBetrag])[plose_MWSTBetrag] ,sum([plose_BruttobetragTransaktion] )[plose_BruttobetragTransaktion]
                                              FROM [tblPLOSE_Details]
                                                    INNER JOIN Adressen on PLOSEKundenNr=plose_POLSEKundennummer 
                                                    INNER JOIN [tblPLOSE_Produktbeschreibung] ON [plp_ProductCode]=[plose_ProduktCode]
                                           where cast(plose_RechnungsDatum as date) between @von and @bis and AdressenNr=@AdressenNr
                                                    AND plose_LieferantCode IN (0,1,7,9)
                                                    AND plp_Land ='" & Land & "'
                                                   " & IIf(Archiv, "", " AND plose_Archiv = 0") & "
                                                group by  [plose_RechnungsDatum],[plose_RechnungsNr],[plose_LieferantCode],[plose_Lieferant],[plose_WaehrungAbbuchung]
                                                 having sum(plose_MWSTBetrag)>0
                                                order by plose_RechnungsDatum
                                                ", conn)

                    cmd.Parameters.AddWithValue("@von", von)
                    cmd.Parameters.AddWithValue("@bis", bis)
                    cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)


                    Dim dr = cmd.ExecuteReader()
                    While dr.Read

                        Dim cPLOSE_USTV_ANT As New cPLOSE_USTV_ANTR
                        cPLOSE_USTV_ANT.plose_RechnungsDatum = dr.Item("plose_RechnungsDatum")
                        cPLOSE_USTV_ANT.plose_RechnungsNr = dr.Item("plose_RechnungsNr")
                        cPLOSE_USTV_ANT.plose_Lieferant = dr.Item("plose_Lieferant")
                        cPLOSE_USTV_ANT.plose_LieferantCode = dr.Item("plose_LieferantCode")
                        cPLOSE_USTV_ANT.plose_NettobetragTransaktion = dr.Item("plose_NettobetragTransaktion")
                        cPLOSE_USTV_ANT.plose_MWSTBetrag = dr.Item("plose_MWSTBetrag")
                        cPLOSE_USTV_ANT.plose_BruttobetragTransaktion = dr.Item("plose_BruttobetragTransaktion")
                        cPLOSE_USTV_ANT.plose_NettobetragWaehrungAbbuchung = dr.Item("plose_NettobetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_MWSTBetragWaehrungAbbuchung = dr.Item("plose_MWSTBetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_BruttobetragWaehrungAbbuchung = dr.Item("plose_BruttobetragWaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_WaehrungAbbuchung = dr.Item("plose_WaehrungAbbuchung")

                        LIST.Add(cPLOSE_USTV_ANT)

                    End While
                    dr.Close()

                End Using
            End Using
            Return True
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return False

    End Function


    Public Shared Function GET_Antraege_PLOSE_NEU(ByRef LIST As List(Of cPLOSE_USTV_ANTR), von As Date, bis As Date, KundenNr As Integer, Land As String, Optional Archiv As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
                Using cmd As New SqlCommand("SELECT plInv_SupplierRechnungsDatum,plInv_SupplierRechnungsNr, plInv_Lieferant,plInv_Nettobetrag,plInv_MWSTBetrag, plInv_Bruttobetrag, isnull(plInv_Currency,'EUR') as plInv_WaehrungAbbuchung , case when plInv_LieferantCode = 'PSS' then 0 else 9 end as plInv_LieferantCode, plInv_daId from tblPLOSE_Inv_Data
													INNER JOIN Adressen on PLOSEKundenNr=plInv_PLOSEKundennummer 
													 where  cast(plInv_SupplierRechnungsDatum as date) between @von and @bis and AdressenNr=@AdressenNr " & IIf(Archiv, "", " AND plInv_Archiv = 0") & " AND
                                                        plInv_SupplierCountry ='" & Land & "'and plInv_MWSTBetrag <> 0 /* AND (plInv_LieferantCode = 'PSS' OR plInv_LieferantCode = 'UNI') AND plInv_SupplierRechnungsNr not like '%-SFC-%'*/" &  'wie Lieferantencode = 90
                                                 "order by plInv_SupplierRechnungsDatum", conn)

                    cmd.Parameters.AddWithValue("@von", von)
                    cmd.Parameters.AddWithValue("@bis", bis)
                    cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)


                    Dim dr = cmd.ExecuteReader()
                    While dr.Read

                        Dim cPLOSE_USTV_ANT As New cPLOSE_USTV_ANTR
                        cPLOSE_USTV_ANT.plose_RechnungsDatum = dr.Item("plInv_SupplierRechnungsDatum")
                        cPLOSE_USTV_ANT.plose_RechnungsNr = dr.Item("plInv_SupplierRechnungsNr")
                        cPLOSE_USTV_ANT.plose_Lieferant = dr.Item("plInv_Lieferant")
                        cPLOSE_USTV_ANT.plose_LieferantCode = dr.Item("plInv_LieferantCode")
                        cPLOSE_USTV_ANT.plose_NettobetragTransaktion = dr.Item("plInv_Nettobetrag")
                        cPLOSE_USTV_ANT.plose_MWSTBetrag = dr.Item("plInv_MWSTBetrag")
                        cPLOSE_USTV_ANT.plose_BruttobetragTransaktion = dr.Item("plInv_Bruttobetrag")
                        cPLOSE_USTV_ANT.plose_NettobetragWaehrungAbbuchung = dr.Item("plInv_Nettobetrag")
                        cPLOSE_USTV_ANT.plose_MWSTBetragWaehrungAbbuchung = dr.Item("plInv_MWSTBetrag")
                        cPLOSE_USTV_ANT.plose_BruttobetragWaehrungAbbuchung = dr.Item("plInv_Bruttobetrag")
                        cPLOSE_USTV_ANT.plose_WaehrungAbbuchung = dr.Item("plInv_WaehrungAbbuchung")
                        cPLOSE_USTV_ANT.plose_daId = dr.Item("plInv_daId")

                        LIST.Add(cPLOSE_USTV_ANT)

                    End While
                    dr.Close()

                End Using
            End Using
            Return True
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return False

    End Function


    'Public Shared Function GET_Antraege_PLOSE(ByRef LIST As List(Of cPLOSE_USTV_ANTR), von As Date, bis As Date, KundenNr As Integer, Land As String, Optional Archiv As Object = Nothing) As Boolean
    '    Try
    '        Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    '        Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
    '            Using cmd As New SqlCommand("SELECT  [plose_RechnungsDatum],[plose_RechnungsNr],[plose_Lieferant],[plose_LieferantCode],sum([plose_NettobetragWaehrungAbbuchung])[plose_NettobetragWaehrungAbbuchung],sum([plose_MWSTBetragWaehrungAbbuchung])[plose_MWSTBetragWaehrungAbbuchung] ,sum([plose_BruttobetragWaehrungAbbuchung] )[plose_BruttobetragWaehrungAbbuchung], [plose_WaehrungAbbuchung]
    '                                                ,sum([plose_NettobetragTransaktion])[plose_NettobetragTransaktion],sum([plose_MWSTBetrag])[plose_MWSTBetrag] ,sum([plose_BruttobetragTransaktion] )[plose_BruttobetragTransaktion]
    '                                          FROM [tblPLOSE_Details]
    '                                                INNER JOIN Adressen on PLOSEKundenNr=plose_POLSEKundennummer 
    '                                                INNER JOIN [tblPLOSE_Produktbeschreibung] ON [plp_ProductCode]=[plose_ProduktCode]
    '                                       where cast(plose_RechnungsDatum as date) between @von and @bis and AdressenNr=@AdressenNr
    '                                                AND plose_LieferantCode IN (0,1,7)
    '                                                AND plp_Land ='" & Land & "'
    '                                               /* " & If(Archiv IsNot Nothing, " AND plose_Archiv=@Archiv ", "") & "*/
    '                                            group by  [plose_RechnungsDatum],[plose_RechnungsNr],[plose_LieferantCode],[plose_Lieferant],[plose_WaehrungAbbuchung]
    '                                             having sum(plose_MWSTBetrag)>0
    '                                            order by plose_RechnungsDatum
    '                                            ", conn)

    '                cmd.Parameters.AddWithValue("@von", von)
    '                cmd.Parameters.AddWithValue("@bis", bis)
    '                cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)
    '                If Archiv IsNot Nothing Then cmd.Parameters.AddWithValue("@Archiv", If(Archiv, 1, 0))

    '                Dim dr = cmd.ExecuteReader()
    '                While dr.Read

    '                    Dim cPLOSE_USTV_ANT As New cPLOSE_USTV_ANTR
    '                    cPLOSE_USTV_ANT.plose_RechnungsDatum = dr.Item("plose_RechnungsDatum")
    '                    cPLOSE_USTV_ANT.plose_RechnungsNr = dr.Item("plose_RechnungsNr")
    '                    cPLOSE_USTV_ANT.plose_Lieferant = dr.Item("plose_Lieferant")
    '                    cPLOSE_USTV_ANT.plose_LieferantCode = dr.Item("plose_LieferantCode")
    '                    cPLOSE_USTV_ANT.plose_NettobetragTransaktion = dr.Item("plose_NettobetragTransaktion")
    '                    cPLOSE_USTV_ANT.plose_MWSTBetrag = dr.Item("plose_MWSTBetrag")
    '                    cPLOSE_USTV_ANT.plose_BruttobetragTransaktion = dr.Item("plose_BruttobetragTransaktion")
    '                    cPLOSE_USTV_ANT.plose_NettobetragWaehrungAbbuchung = dr.Item("plose_NettobetragWaehrungAbbuchung")
    '                    cPLOSE_USTV_ANT.plose_MWSTBetragWaehrungAbbuchung = dr.Item("plose_MWSTBetragWaehrungAbbuchung")
    '                    cPLOSE_USTV_ANT.plose_BruttobetragWaehrungAbbuchung = dr.Item("plose_BruttobetragWaehrungAbbuchung")
    '                    cPLOSE_USTV_ANT.plose_WaehrungAbbuchung = dr.Item("plose_WaehrungAbbuchung")

    '                    LIST.Add(cPLOSE_USTV_ANT)

    '                End While
    '                dr.Close()

    '            End Using
    '        End Using
    '        Return True
    '    Catch ex As Exception
    '        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
    '    End Try
    '    Return False

    'End Function



    'Public Shared Function GET_Antraege(von As Date, bis As Date, KundenNr As Integer, Optional Archiv As Object = Nothing) As List(Of cPLOSE_USTV_ANTR)
    '    Try
    '        Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    '        Dim LIST As New List(Of cPLOSE_USTV_ANTR)
    '        Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
    '            Using cmd As New SqlCommand("SELECT  [plose_RechnungsDatum],[plose_RechnungsNr],[plose_Lieferant],[plose_LieferantCode],sum([plose_NettobetragWaehrungAbbuchung])[plose_NettobetragWaehrungAbbuchung],sum([plose_MWSTBetragWaehrungAbbuchung])[plose_MWSTBetragWaehrungAbbuchung] ,sum([plose_BruttobetragWaehrungAbbuchung] )[plose_BruttobetragWaehrungAbbuchung], [plose_WaehrungAbbuchung]
    '                                                ,sum([plose_NettobetragTransaktion])[plose_NettobetragTransaktion],sum([plose_MWSTBetrag])[plose_MWSTBetrag] ,sum([plose_BruttobetragTransaktion] )[plose_BruttobetragTransaktion]
    '                                          FROM [tblPLOSE_Details] INNER JOIN Adressen on PLOSEKundenNr=plose_POLSEKundennummer
    '                                          where cast(plose_RechnungsDatum as date) between @von and @bis and AdressenNr=@AdressenNr
    '                                            " & If(Archiv IsNot Nothing, " AND plose_Archiv=@Archiv ", "") & "
    '                                            group by  [plose_RechnungsDatum],[plose_RechnungsNr],[plose_LieferantCode],[plose_Lieferant],[plose_WaehrungAbbuchung]
    '                                             having sum(plose_MWSTBetrag)>0
    '                                            ", conn)

    '                cmd.Parameters.AddWithValue("@von", von)
    '                cmd.Parameters.AddWithValue("@bis", bis)
    '                cmd.Parameters.AddWithValue("@AdressenNr", KundenNr)
    '                If Archiv IsNot Nothing Then cmd.Parameters.AddWithValue("@Archiv", If(Archiv, 1, 0))

    '                Dim dr = cmd.ExecuteReader()
    '                While dr.Read

    '                    Dim cPLOSE_USTV_ANT As New cPLOSE_USTV_ANTR
    '                    cPLOSE_USTV_ANT.plose_RechnungsDatum = dr.Item("plose_RechnungsDatum")
    '                    cPLOSE_USTV_ANT.plose_RechnungsNr = dr.Item("plose_RechnungsNr")
    '                    cPLOSE_USTV_ANT.plose_Lieferant = dr.Item("plose_Lieferant")
    '                    cPLOSE_USTV_ANT.plose_LieferantCode = dr.Item("plose_LieferantCode")
    '                    cPLOSE_USTV_ANT.plose_NettobetragTransaktion = dr.Item("plose_NettobetragTransaktion")
    '                    cPLOSE_USTV_ANT.plose_MWSTBetrag = dr.Item("plose_MWSTBetrag")
    '                    cPLOSE_USTV_ANT.plose_BruttobetragTransaktion = dr.Item("plose_BruttobetragTransaktion")
    '                    cPLOSE_USTV_ANT.plose_NettobetragWaehrungAbbuchung = dr.Item("plose_NettobetragWaehrungAbbuchung")
    '                    cPLOSE_USTV_ANT.plose_MWSTBetragWaehrungAbbuchung = dr.Item("plose_MWSTBetragWaehrungAbbuchung")
    '                    cPLOSE_USTV_ANT.plose_BruttobetragWaehrungAbbuchung = dr.Item("plose_BruttobetragWaehrungAbbuchung")
    '                    cPLOSE_USTV_ANT.plose_WaehrungAbbuchung = dr.Item("plose_WaehrungAbbuchung")

    '                    LIST.Add(cPLOSE_USTV_ANT)

    '                End While
    '                dr.Close()

    '            End Using
    '        End Using
    '        Return LIST
    '    Catch ex As Exception
    '        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
    '    End Try
    '    Return Nothing

    'End Function



    Public Shared Function UPDATE_ARCHIV(von As Date, bis As Date, KundenNr As Integer, UStVAn_ID As Integer, Optional plose_RechnungsNr As String = "", Optional proRechnung As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("von", von))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("bis", bis))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("KundenNr", KundenNr))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("UStVAn_ID", UStVAn_ID))
            If plose_RechnungsNr <> "" Then list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_RechnungsNr", plose_RechnungsNr))

            Dim sqlUpdate = "UPDATE [tblPLOSE_Details] 
                        set plose_Archiv=1, [plose_ArchiviertDatum]=GETDATE(), UStVAn_ID = @UStVAn_ID
                    FROM [tblPLOSE_Details]  INNER JOIN Adressen on PLOSEKundenNr=plose_POLSEKundennummer
                        INNER JOIN [tblPLOSE_Produktbeschreibung] ON [plp_ProductCode]=[plose_ProduktCode]
                    WHERE cast(plose_RechnungsDatum as date) between @von and @bis and AdressenNr=@KundenNr AND plose_LieferantCode IN (0,1,7,9) " & IIf(proRechnung AndAlso plose_RechnungsNr <> "", "AND plose_RechnungsNr=@plose_RechnungsNr", "")

            Return SQL.doSQLVarList(sqlUpdate, "FMZOLL",, list)



        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function



    Public Shared Function UPDATE_ARCHIV_NEULOGIK(von As Date, bis As Date, KundenNr As Integer, UStVAn_ID As Integer, Optional plose_RechnungsNr As String = "", Optional proRechnung As Boolean = False) As Boolean
        Try
            Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

            Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("von", von))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("bis", bis))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("KundenNr", KundenNr))
            list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("UStVAn_ID", UStVAn_ID))
            If plose_RechnungsNr <> "" Then list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("plose_RechnungsNr", plose_RechnungsNr))

            Dim sqlUpdate = "UPDATE [tblPLOSE_Inv_Data] 
                        set plInv_Archiv=1, [plInv_ArchiviertDatum]=GETDATE(), plInv_UStVAn_ID = @UStVAn_ID
                    FROM [tblPLOSE_Inv_Data]  INNER JOIN Adressen on PLOSEKundenNr=[plInv_PLOSEKundennummer]
                    WHERE cast([plInv_SupplierRechnungsDatum] as date) between @von and @bis and AdressenNr=@KundenNr " & IIf(proRechnung AndAlso plose_RechnungsNr <> "", "AND [plInv_SupplierRechnungsNr]=@plose_RechnungsNr", "")

            Return SQL.doSQLVarList(sqlUpdate, "FMZOLL", True, list)



        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function





    Public ANLAGEN

    Dim Dateiname = ""

    Public Function initImportPfade() As Boolean

        ANLAGEN = cPLOSE.Paramter.GET_PARAM_ByName("ANLAGEN", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)

        Return True

    End Function


    Public Class Paramter

        Shared apiSettingsloaded As Boolean = False
        Shared SQL As New VERAG_PROG_ALLGEMEIN.SQL

        Shared Function GET_PARAM_ByName(tcParam_name, TESTSYSTEM) As String
            Return SQL.getValueTxtBySql("SELECT TOP 1 [Param_value]  FROM [tblPartnersystem_Paramter] WHERE  Param_system='PLOSE' AND [Param_name]='" & tcParam_name & "' AND Param_testsystem = " & IIf(TESTSYSTEM, 1, 0), , , SQL.GetNewOpenConnectionFMZOLL_SYSTEM(TESTSYSTEM))
        End Function
    End Class


End Class
Public Class cPLOSE_USTV_ANTR
    Property plose_RechnungsDatum As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_RechnungsNr As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_Lieferant As Object = Nothing '                  VARCHAR(3)     NULL,
    Property plose_LieferantCode As Object = Nothing '                  VARCHAR(3)     NULL, 
    Property plose_NettobetragWaehrungAbbuchung As Object = Nothing '  Decimal (12, 2) NULL,
    Property plose_MWSTBetragWaehrungAbbuchung As Object = Nothing '   Decimal (12, 2) NULL,
    Property plose_BruttobetragWaehrungAbbuchung As Object = Nothing ' Decimal (12, 2) NULL, 
    Property plose_WaehrungAbbuchung As Object = Nothing '             VARCHAR(3)     NULL, 
    Property plose_NettobetragTransaktion As Object = Nothing '        Decimal (12, 2) NULL,
    Property plose_MWSTBetrag As Object = Nothing '                    Decimal (12, 2) NULL,
    Property plose_BruttobetragTransaktion As Object = Nothing '       Decimal (12, 2) NULL,
    Property plose_daId As Object = Nothing


    Public Shared Sub reOrderList(ByRef LIST As List(Of cPLOSE_USTV_ANTR))
        LIST.Sort(Function(x, y) x.plose_RechnungsDatum.CompareTo(y.plose_RechnungsDatum))
    End Sub

End Class

