Imports VERAG_PROG_ALLGEMEIN

Public Class usrCntlMDMDatenverarbeitungAuswertungen_divers

    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
    Dim MAIN As frmMDMDatenverarbetiung
    Dim Lieferant As String
    Dim abrechnugsdatum As String
    Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub
    Sub New(MAIN As frmMDMDatenverarbetiung, Lieferant As String)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.MAIN = MAIN
        Me.Lieferant = Lieferant
        init()
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub

    Sub init()

        Select Case Lieferant

            Case "PLOSE"
                Button6.Text = "Auswertung IT Maut (Konsortium)"
                Button2.Text = "Auswert. Kunden (Konsortium)"
                Button1.Text = "Auswertung nach Länder EU Kunden"
                Button1.Visible = False
                cbxConsFakt.Visible = True
                cbxNurEULander.Visible = True

            Case "UTA"

                Button6.Text = "fehlende KdNr"
                Button2.Text = "fehlende Fakt.warenart"
                Button1.Text = "fehlende Offertenpos."

            Case "MSE"

                Button6.Text = "Nach Spezifikation"
                Button2.Text = "Leistungsnummern"
                Button1.Text = "Kunden"
                Button3.Text = "fehlende Transakt."
                Button3.Visible = True


            Case Else

        End Select

    End Sub

    Function getSQLPLOSE(plp_ProductCode_IN As String, plp_ProductCode_NOTIN As String, plose_POLSEKundennummer As String, plp_Kategorie_IN As String, onlyEUCountries As Boolean) As String
        Return "   SELECT Adressennr KundenNr, [Name 1] Firma,Adressen.LandKz,plz,Ort,CASE WHEN  MitgliedslandEU =1 THEN 'JA' ELSE 'NEIN' END as EU, plose_POLSEKundennummer PLOSEKundennummer,sum(plose_NettobetragWaehrungAbbuchung) as Netto, sum(plose_MWSTBetragWaehrungAbbuchung) as MWST , sum(plose_BruttobetragWaehrungAbbuchung) as Brutto
              FROM tblPLOSE_Details inner join Adressen on PLOSEKundenNr=plose_POLSEKundennummer
              inner join tblPLOSE_Produktbeschreibung on  plp_ProductCode=plose_ProduktCode
              inner join [Währungstabelle] on [Währungstabelle].LandKz=Adressen.LandKz
              WHERE plose_Fakturiert=1 and CAST(plose_FakturiertDatum AS DATE) between '" & MAIN.dat_Sum_Von.Value & "' and '" & MAIN.dat_Sum_Bis.Value & "'
              and plp_Land='IT' 
             " & If(onlyEUCountries, " and MitgliedslandEU=1 ", "") & " 
              " & If(plp_Kategorie_IN <> "", "   and plp_Kategorie IN (" & plp_Kategorie_IN & ")", "") & "
              " & If(plp_ProductCode_IN <> "", "   and plp_ProductCode IN (" & plp_ProductCode_IN & ")", "") & "
              " & If(plp_ProductCode_NOTIN <> "", "   and plp_ProductCode NOT IN (" & plp_ProductCode_NOTIN & ")", "") & "
              " & If(plose_POLSEKundennummer <> "", "   and plose_POLSEKundennummer IN (" & plose_POLSEKundennummer & ")", "") & "
              group by plose_POLSEKundennummer,Adressennr,[Name 1],Adressen.LandKz,plz,Ort,MitgliedslandEU
              order by MitgliedslandEU desc,[Name 1]"


    End Function
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

        Select Case Lieferant

            Case "PLOSE"

                genKonsortiumPLOSE()

            Case "UTA"
                genUTABericht("KDNR")

            Case "MSE"

                genMSEBericht("SPEZ")

            Case Else

                MsgBox("nicht definiert!")


        End Select

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Select Case Lieferant

            Case "PLOSE"

                genLaendergesamtPLOSE()

            Case "UTA"
                genUTABericht("OP")

            Case "MSE"
                genMSEBericht("KDNR")


        End Select



    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Select Case Lieferant

            Case "PLOSE"

                genKundenbericht_PLOSE()

            Case "UTA"
                genUTABericht("FKWA")

            Case "MSE"
                genMSEBericht("LENR")

        End Select




    End Sub

    Sub genKonsortiumPLOSE()


        Dim sqlstr = getSQLPLOSE("", "", "", "", cbxNurEULander.Checked) ' 262


        Dim dt As DataTable = SQL.loadDgvBySql_Param(sqlstr, "FMZOLL")
        Dim print As New frmPrintLayout
        print.Text = "PLOSE"
        If dt Is Nothing OrElse dt.Rows.Count = 0 Then
            MsgBox("Keine Daten!")
            Exit Sub
        End If


        Dim rpt As New rptPLOSE_Konsortium
        rpt.DataSource = dt

        Dim sum = 0
        '  rpt.lblUeberschrift.Text = "PLOSE Summenbericht " & dat_Sum_Von.Text & " bis " & dat_Sum_Bis.Text
        rpt.lblSachbearbeiter.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
        'rpt.lblMandantNiederlassung.Text = PERSONAL.Mandant & "  /  " & PERSONAL.Niederlassung

        'Dim cnt As Integer = 0
        rpt.lblDat.Text = Now.ToLongDateString


        Dim sumPreis As Double = 0
        Dim sumNetto As Double = 0
        Dim sumMWST As Double = 0
        Dim sumBrutto As Double = 0
        Dim sumBruttoAlleLeistungen As Double = 0
        Dim sumMenge As Double = 0

        AddHandler rpt.Detail.Format, Sub()
                                          rpt.lblFirma.Text = SQL.isDbnullEmpty(rpt.Fields.Item("Firma").Value, "")
                                          rpt.lblOrt.Text = SQL.isDbnullEmpty(rpt.Fields.Item("PLZ").Value, "") & " " & SQL.isDbnullEmpty(rpt.Fields.Item("ORT").Value, "")
                                          rpt.lblLand.Text = SQL.isDbnullEmpty(rpt.Fields.Item("LandKz").Value, "")
                                          rpt.lblEU.Text = SQL.isDbnullEmpty(rpt.Fields.Item("EU").Value, "")
                                          rpt.lblKdNR.Text = SQL.isDbnullEmpty(rpt.Fields.Item("KundenNr").Value, "")


                                          rpt.lblBruttoAlleLeistungen.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Brutto").Value, 2, "")
                                          sumBruttoAlleLeistungen += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Brutto").Value, 4, 0)


                                          Dim dt2 As DataTable = SQL.loadDgvBySql_Param(getSQLPLOSE("", "", rpt.Fields.Item("PLOSEKundennummer").Value, "'MAUT'", cbxNurEULander.Checked), "FMZOLL") ' NUR MAUT je Kunde

                                          If dt2.Rows.Count > 0 Then
                                              rpt.lblNetto.Text = SQL.isDbnullEmptyDbl(dt2(0)("Netto"), 2, "")
                                              rpt.lblMWST.Text = SQL.isDbnullEmptyDbl(dt2(0)("MWST"), 2, "")
                                              rpt.lblBrutto.Text = SQL.isDbnullEmptyDbl(dt2(0)("Brutto"), 2, "")

                                              sumNetto += SQL.isDbnullEmptyDbl(dt2(0)("Netto"), 4, 0)
                                              sumMWST += SQL.isDbnullEmptyDbl(dt2(0)("MWST"), 4, 0)
                                              sumBrutto += SQL.isDbnullEmptyDbl(dt2(0)("Brutto"), 4, 0)
                                          Else
                                              rpt.lblNetto.Text = "-"
                                              rpt.lblMWST.Text = "-"
                                              rpt.lblBrutto.Text = "-"

                                          End If


                                      End Sub


        AddHandler rpt.ReportFooter1.Format, Sub()
                                                 rpt.lblSumNetto.Text = sumNetto.ToString("N2")
                                                 rpt.lblSumMwst.Text = sumMWST.ToString("N2")
                                                 rpt.lblSumBrutto.Text = sumBrutto.ToString("N2")
                                                 rpt.lblSumBruttoAlleLeistungen.Text = "(" & sumBruttoAlleLeistungen.ToString("N2") & ")"

                                             End Sub

        print.Viewer.LoadDocument(rpt)
        print.Viewer.ViewType = GrapeCity.Viewer.Common.Model.ViewType.Continuous
        print.Show()

    End Sub

    Sub genLaendergesamtPLOSE()


        Dim sqlstr = "SELECT plp_Land, CASE WHEN   MitgliedslandEU =1 THEN 'JA' ELSE 'NEIN' END as EU, sum(plose_NettobetragWaehrungAbbuchung) as Netto, sum(plose_MWSTBetragWaehrungAbbuchung) as MWST , sum(plose_BruttobetragWaehrungAbbuchung) as Brutto
              FROM tblPLOSE_Details inner join Adressen on PLOSEKundenNr=plose_POLSEKundennummer
              inner join tblPLOSE_Produktbeschreibung on  plp_ProductCode=plose_ProduktCode
              inner join [Währungstabelle] on [Währungstabelle].LandKz=Adressen.LandKz
              WHERE plose_Fakturiert=1 and CAST(plose_FakturiertDatum AS DATE) between '" & MAIN.dat_Sum_Von.Value & "' and '" & MAIN.dat_Sum_Bis.Value & "'
              group by plp_Land,MitgliedslandEU
			  order by  plp_Land, MitgliedslandEU desc"


        Dim dt As DataTable = SQL.loadDgvBySql_Param(sqlstr, "FMZOLL")
        Dim print As New frmPrintLayout
        print.Text = "PLOSE"
        If dt Is Nothing OrElse dt.Rows.Count = 0 Then
            MsgBox("Keine Daten!")
            Exit Sub
        End If


        Dim rpt As New rptPLOSE_LaenderGesamt
        rpt.DataSource = dt

        Dim sum = 0
        '  rpt.lblUeberschrift.Text = "PLOSE Summenbericht " & dat_Sum_Von.Text & " bis " & dat_Sum_Bis.Text
        rpt.lblSachbearbeiter.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
        'rpt.lblMandantNiederlassung.Text = PERSONAL.Mandant & "  /  " & PERSONAL.Niederlassung

        'Dim cnt As Integer = 0
        rpt.lblDat.Text = Now.ToLongDateString


        Dim sumPreis As Double = 0
        Dim sumNetto As Double = 0
        Dim sumMWST As Double = 0
        Dim sumBrutto As Double = 0
        Dim sumBruttoAlleLeistungen As Double = 0
        Dim sumMenge As Double = 0

        AddHandler rpt.Detail.Format, Sub()
                                          rpt.lblLand.Text = SQL.isDbnullEmpty(rpt.Fields.Item("plp_Land").Value, "")
                                          rpt.lblEU.Text = SQL.isDbnullEmpty(rpt.Fields.Item("EU").Value, "")

                                          rpt.lblNetto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Netto").Value, 2, "")
                                          rpt.lblMWST.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("MWST").Value, 2, "")
                                          rpt.lblBrutto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Brutto").Value, 2, "")

                                          sumNetto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Netto").Value, 4, 0)
                                          sumMWST += SQL.isDbnullEmptyDbl(rpt.Fields.Item("MWST").Value, 4, 0)
                                          sumBrutto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Brutto").Value, 4, 0)



                                      End Sub


        AddHandler rpt.ReportFooter1.Format, Sub()
                                                 rpt.lblSumNetto.Text = sumNetto.ToString("N2")
                                                 rpt.lblSumMwst.Text = sumMWST.ToString("N2")
                                                 rpt.lblSumBrutto.Text = sumBrutto.ToString("N2")

                                             End Sub

        print.Viewer.LoadDocument(rpt)
        print.Viewer.ViewType = GrapeCity.Viewer.Common.Model.ViewType.Continuous
        print.Show()

    End Sub


    Sub genUTABericht(art As String)

        Dim sqlstr = ""

        Select Case art

            Case "KDNR"

                sqlstr = "SELECT tblUTAImportNew.Kundennummer as 'fehlende UTA-Kundennummer'
                FROM tblUTAImportNew LEFT JOIN Adressen ON tblUTAImportNew.Kundennummer = Adressen.UTAKundenNr
                Where UTAKundenNr <> 868070
                GROUP BY tblUTAImportNew.Kundennummer, Adressen.UTAKundenNr
                HAVING (((Adressen.UTAKundenNr) Is Null))"

            Case "FKWA"


                sqlstr = "SELECT tblUTAImportNew.Fakturierwarenart as Fakturierwarenart, tblUTAImportNew.Lieferland as Lieferland
                FROM tblUTAImportNew LEFT JOIN tblUTALeistungen ON (tblUTAImportNew.Fakturierwarenart = tblUTALeistungen.Fakturierwarenart) AND (tblUTAImportNew.Lieferland = tblUTALeistungen.Lieferland)
                GROUP BY tblUTAImportNew.Fakturierwarenart, tblUTAImportNew.Lieferland, tblUTALeistungen.Fakturierwarenart, tblUTALeistungen.Lieferland
                HAVING (((tblUTALeistungen.Fakturierwarenart) Is Null) AND ((tblUTALeistungen.Lieferland) Is Null))"


            Case "OP"

                sqlstr = "SELECT * FROM vwUTA_PrüfungInkonsistenzVERAGOffertenpositionen2_new"

            Case Else
                MsgBox("Auswertungsart nicht definiert!")
                Exit Sub

        End Select

        Dim dt As DataTable = SQL.loadDgvBySql_Param(sqlstr, "FMZOLL")
        Dim print As New frmPrintLayout
        print.Text = "UTA"
        If dt Is Nothing OrElse dt.Rows.Count = 0 Then
            MsgBox("Keine Daten!")
            Exit Sub
        End If


        cProgramFunctions.genExcelCSVFromDT(dt, True)

        'Dim rpt As New rptPLOSE_LaenderGesamt
        'rpt.DataSource = dt

        'Dim sum = 0
        ''  rpt.lblUeberschrift.Text = "PLOSE Summenbericht " & dat_Sum_Von.Text & " bis " & dat_Sum_Bis.Text
        'rpt.lblSachbearbeiter.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
        ''rpt.lblMandantNiederlassung.Text = PERSONAL.Mandant & "  /  " & PERSONAL.Niederlassung

        ''Dim cnt As Integer = 0
        'rpt.lblDat.Text = Now.ToLongDateString


        ''Dim sumPreis As Double = 0
        ''Dim sumNetto As Double = 0
        ''Dim sumMWST As Double = 0
        ''Dim sumBrutto As Double = 0
        ''Dim sumBruttoAlleLeistungen As Double = 0
        ''Dim sumMenge As Double = 0

        ''AddHandler rpt.Detail.Format, Sub()
        ''                                  rpt.lblLand.Text = SQL.isDbnullEmpty(rpt.Fields.Item("plp_Land").Value, "")
        ''                                  rpt.lblEU.Text = SQL.isDbnullEmpty(rpt.Fields.Item("EU").Value, "")

        ''                                  rpt.lblNetto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Netto").Value, 2, "")
        ''                                  rpt.lblMWST.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("MWST").Value, 2, "")
        ''                                  rpt.lblBrutto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Brutto").Value, 2, "")

        ''                                  sumNetto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Netto").Value, 4, 0)
        ''                                  sumMWST += SQL.isDbnullEmptyDbl(rpt.Fields.Item("MWST").Value, 4, 0)
        ''                                  sumBrutto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Brutto").Value, 4, 0)



        ''                              End Sub


        ''AddHandler rpt.ReportFooter1.Format, Sub()
        ''                                         rpt.lblSumNetto.Text = sumNetto.ToString("N2")
        ''                                         rpt.lblSumMwst.Text = sumMWST.ToString("N2")
        ''                                         rpt.lblSumBrutto.Text = sumBrutto.ToString("N2")

        ''                                     End Sub

        'print.Viewer.LoadDocument(rpt)
        'print.Viewer.ViewType = GrapeCity.Viewer.Common.Model.ViewType.Continuous
        'print.Show()

    End Sub

    Sub genMSEBericht(art As String)

        Dim sqlstr = ""

        Select Case art

            Case "SPEZ"

                sqlstr = "    SELECT  inv.invoice_id as Rechnung,bills.specification_page_id AS Spezifikation_Id ,bills.specification_page_name AS Spezifikation,count(*) as AnzahlTransactionen, 
                                Sum(trans.msts_fee_amount) as Gebühren_MSE,	                                
                                Sum(trans.transaction_net_amount) as Transaktionsbetrag_Netto,
	                            Sum(trans.USteuer_EUR) As Steuerbetrag,
	                            Sum(trans.transaction_gross_amount) As Transaktionsbetrag_Brutto
	                                                                    
                                 FROM [VERAG].[dbo].[tblMSESettlements] as bills 
                                 inner join [VERAG].[dbo].[tblMSETransactions] as trans on bills.[transaction_id] = trans.[transaction_id] 
                                 inner join [VERAG].[dbo].[tblMSEInvoices] as inv on inv.[invoice_id] = bills.[invoice_number]  and trans.transaction_country = inv.country
                                 
                                 where bills.invoice_date =  '" & MAIN.DateTimePicker2.Text & "'  --and trans.charged <> 1  
                                 GROUP BY inv.invoice_id,bills.specification_page_id, bills.specification_page_name"

            Case "LENR"

                sqlstr = "Select trans.device_product_type, trans.transaction_country,trans.transaction_product_name, trans.transaction_product_id, cust.[customer_id], trans.partner_haulier_id, cust.customer_name, 
                          sum(trans.transaction_gross_amount) As [Summe Transaction Amount ( EUR )], 
                          sum(trans.msts_fee_amount) As [Summe Admin Fee Amount ( EUR )], 
                          sum(trans.msts_fee_amount) As [Summe Fees And Costs Amount ( EUR )], 
                          sum(trans.msts_vat_amount) As [Summe VAT Amount ( EUR )], 
                          sum(trans.transaction_gross_amount) As [Summe Total Amount ( EUR )]
                          From [VERAG].[dbo].[tblMSESettlements] as bills 
                          Left Join [VERAG].[dbo].[tblMSETransactions] as trans on bills.[transaction_id] = trans.[transaction_id] 
                          Left Join [VERAG].[dbo].[tblMSECustomers] as cust on cust.partner_customer_number = trans.partner_haulier_id
                          Left Join [VERAG].[dbo].[tblMSEInvoices] as inv on inv.[invoice_id] = bills.[invoice_number] And inv.customer_number = cust.[customer_id] And trans.transaction_country = inv.country
                          Left Join tblMSELeistungen ON trans.device_product_type = tblMSELeistungen.[Card Type] And trans.transaction_country = tblMSELeistungen.[Transaction Country]
                          WHERE((trans.transaction_gross_amount <> 0) And tblMSELeistungen.LeistungsNr Is Null) And bills.[invoice_date] = '" & MAIN.DateTimePicker2.Text & "'                        
                          GROUP by trans.device_product_type, trans.transaction_country, trans.transaction_product_name, trans.transaction_product_id, cust.[customer_id], trans.partner_haulier_id, cust.customer_name"

            Case "KDNR"

                sqlstr = "   Select cust.customer_id, cust.customer_name, Adressen.AdressenNr, (SELECT Offerten.OffertenNr FROM Offerten WHERE (((Offerten.KundenNr)=isnull(Adressen.[AdressenNr],0)) AND ((Offerten.OffertenNr)=23))) AS Offerte_23
                             FROM [VERAG].[dbo].[tblMSESettlements] as bills 
                             left join [VERAG].[dbo].[tblMSETransactions] as trans on bills.[transaction_id] = trans.[transaction_id] 
                             left join [VERAG].[dbo].[tblMSECustomers] as cust on cust.partner_customer_number = trans.partner_haulier_id
                             left join [VERAG].[dbo].[tblMSEInvoices] as inv on inv.[invoice_id] = bills.[invoice_number] and inv.customer_number = cust.[customer_id] and trans.transaction_country = inv.country
                             left join adressen ON cust.[customer_id] = Adressen.MSEKundenNr 
                             WHERE bills.[invoice_date] = '" & MAIN.DateTimePicker2.Text & "'                               
                             GROUP BY cust.customer_id, cust.customer_name, Adressen.AdressenNr                                    
                             HAVING (((cust.customer_id) Is Not Null) AND ((Adressen.AdressenNr) Is Null)) OR (((cust.customer_id) Is Not Null) AND ((Adressen.AdressenNr) Is Not Null) AND (((SELECT Offerten.OffertenNr FROM Offerten WHERE (((Offerten.KundenNr)=isnull(Adressen.[AdressenNr],0)) AND ((Offerten.OffertenNr)=23)))) Is Null))"

            Case "TRANS"

                sqlstr = "  select * FROM [VERAG].[dbo].[tblMSESettlements] where [invoice_date] = '" & MAIN.DateTimePicker2.Text & "' AND [transaction_id] not in (select [transaction_id] from [VERAG].[dbo].[tblMSETransactions])"

            Case Else
                MsgBox("Auswertungsart nicht definiert!")
                Exit Sub

        End Select

        Dim dt As DataTable = SQL.loadDgvBySql_Param(sqlstr, "FMZOLL")
        Dim print As New frmPrintLayout
        print.Text = "MSE"
        If dt Is Nothing OrElse dt.Rows.Count = 0 Then
            MsgBox("Keine Daten!")
            Exit Sub
        End If

        cProgramFunctions.genExcelCSVFromDT(dt, True)

        'DEAKVIERT weil zu aufwendig, aktuell per Excel-Export
        'Dim rpt As New rptPLOSE_LaenderGesamt
        'rpt.DataSource = dt

        'Dim sum = 0
        ''  rpt.lblUeberschrift.Text = "PLOSE Summenbericht " & dat_Sum_Von.Text & " bis " & dat_Sum_Bis.Text
        'rpt.lblSachbearbeiter.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
        ''rpt.lblMandantNiederlassung.Text = PERSONAL.Mandant & "  /  " & PERSONAL.Niederlassung

        ''Dim cnt As Integer = 0
        'rpt.lblDat.Text = Now.ToLongDateString


        'Dim sumPreis As Double = 0
        'Dim sumNetto As Double = 0
        'Dim sumMWST As Double = 0
        'Dim sumBrutto As Double = 0
        'Dim sumBruttoAlleLeistungen As Double = 0
        'Dim sumMenge As Double = 0

        'AddHandler rpt.Detail.Format, Sub()
        '                                  rpt.lblLand.Text = SQL.isDbnullEmpty(rpt.Fields.Item("Rechnung").Value, "") & " - " & SQL.isDbnullEmpty(rpt.Fields.Item("Spezifikation_Id").Value, "")
        '                                  rpt.lblEU.Text = SQL.isDbnullEmpty(rpt.Fields.Item("Spezifikation").Value, "")

        '                                  rpt.lblNetto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Transaktionsbetrag_Netto").Value, 2, "")
        '                                  rpt.lblMWST.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Steuerbetrag").Value, 2, "")
        '                                  rpt.lblBrutto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("Transaktionsbetrag_Brutto").Value, 2, "")

        '                                  sumNetto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Transaktionsbetrag_Netto").Value, 4, 0)
        '                                  sumMWST += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Steuerbetrag").Value, 4, 0)
        '                                  sumBrutto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("Transaktionsbetrag_Brutto").Value, 4, 0)



        '                              End Sub

        'AddHandler rpt.ReportFooter1.Format, Sub()
        '                                         rpt.lblSumNetto.Text = sumNetto.ToString("N2")
        '                                         rpt.lblSumMwst.Text = sumMWST.ToString("N2")
        '                                         rpt.lblSumBrutto.Text = sumBrutto.ToString("N2")

        '                                     End Sub

        'print.Viewer.LoadDocument(rpt)
        'print.Viewer.ViewType = GrapeCity.Viewer.Common.Model.ViewType.Continuous
        'print.Show()

    End Sub

    Sub genKundenbericht_PLOSE()
        Dim displayFilter = False
        Dim sqlstr As String = ""
        Dim frmMDM As frmMDMDatenverarbetiung = Me.ParentForm

        sqlstr &= "   Select  count(*) Anzahl,AdressenNr,Ordnungsbegriff "
        sqlstr &= " ,sum(plose_Menge) As plose_Menge "
        sqlstr &= " ,sum(plose_Preis) As plose_Preis "
        sqlstr &= " ,sum(plose_NettobetragWaehrungAbbuchung) As plose_NettobetragWaehrungAbbuchung "
        sqlstr &= " ,sum(plose_MWSTBetragWaehrungAbbuchung) As plose_MWSTBetragWaehrungAbbuchung "
        sqlstr &= " ,sum(plose_BruttobetragWaehrungAbbuchung) As plose_BruttobetragWaehrungAbbuchung  "
        sqlstr &= " FROM tblPLOSE_Details "
        sqlstr &= " INNER JOIN Adressen On PLOSEKundenNr=plose_POLSEKundennummer "
        sqlstr &= " WHERE 1=1  "

        sqlstr &= " And plose_RechnungsDatum between '" & frmMDM.dat_Sum_Von.Value & "' and '" & frmMDM.dat_Sum_Bis.Value & "' "

        If cbxConsFakt.CheckState = CheckState.Checked Then
            sqlstr &= " AND plose_Fakturiert =1  "
        ElseIf cbxConsFakt.CheckState = CheckState.Unchecked Then
            sqlstr &= " AND plose_Fakturiert =0  "
        End If

        sqlstr &= " AND plose_ProduktCode IN (262,267,275,281,282,285,298,300,301,307,308,310) "

        sqlstr &= " group by AdressenNr,Ordnungsbegriff "
        sqlstr &= " order by Ordnungsbegriff "


        Dim dt As DataTable = SQL.loadDgvBySql_Param(sqlstr, "FMZOLL")
        'DataGridView.DataSource = dt


        Dim print As New frmPrintLayout
        print.Text = "PLOSE"

        Dim rpt As New rptPLOSE_CustomerConsortio

        rpt.DataSource = dt


        'If cbxProdukt.Checked Then
        '    rpt.GroupHeader2.DataField = "prod_descr"
        'Else
        '    rpt.GroupHeader2.Visible = False
        '    rpt.GroupFooter2.Visible = False
        'End If


        Dim sum = 0
        rpt.lblUeberschrift.Text = "PLOSE Summenbericht " & frmMDM.dat_Sum_Von.Text & " bis " & frmMDM.dat_Sum_Bis.Text
        rpt.lblSachbearbeiter.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME
        'rpt.lblMandantNiederlassung.Text = PERSONAL.Mandant & "  /  " & PERSONAL.Niederlassung

        'Dim cnt As Integer = 0
        rpt.lblDat.Text = Now.ToLongDateString


        Dim sumPreis As Double = 0
        Dim sumNetto As Double = 0
        Dim sumMWST As Double = 0
        Dim sumBrutto As Double = 0
        Dim sumMenge As Double = 0

        AddHandler rpt.Detail.Format, Sub()
                                          '   rpt.lblProduktBeschreibung.Text = isDbnullEmpty(rpt.Fields.Item("BC_DESCR").Value, "")
                                          rpt.lblAnzahl.Text = SQL.isDbnullEmpty(rpt.Fields.Item("Anzahl").Value, "")
                                          rpt.Label5.Text = SQL.isDbnullEmpty(rpt.Fields.Item("AdressenNr").Value, "")
                                          rpt.lblProdukt.Text = SQL.isDbnullEmpty(rpt.Fields.Item("Ordnungsbegriff").Value, "")

                                          rpt.lblMenge.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_Menge").Value, 0, "")
                                          ' rpt.lblPreis.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_Preis").Value, 2, "")
                                          rpt.lblNetto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_NettobetragWaehrungAbbuchung").Value, 2, "")
                                          rpt.lblMWST.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_MWSTBetragWaehrungAbbuchung").Value, 2, "")
                                          rpt.lblBrutto.Text = SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_BruttobetragWaehrungAbbuchung").Value, 2, "")



                                          sumMenge += SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_Menge").Value, 4, 0)
                                          '  sumPreis += SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_Preis").Value, 4, 0)
                                          sumNetto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_NettobetragWaehrungAbbuchung").Value, 4, 0)
                                          sumMWST += SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_MWSTBetragWaehrungAbbuchung").Value, 4, 0)
                                          sumBrutto += SQL.isDbnullEmptyDbl(rpt.Fields.Item("plose_BruttobetragWaehrungAbbuchung").Value, 4, 0)


                                      End Sub


        AddHandler rpt.ReportFooter1.Format, Sub()
                                                 rpt.lblSumMenge.Text = sumMenge.ToString("N0")
                                                 'rpt.lblSumPreis.Text = sumPreis.ToString("N2")
                                                 rpt.lblSumNetto.Text = sumNetto.ToString("N2")
                                                 rpt.lblSumMwst.Text = sumMWST.ToString("N2")
                                                 rpt.lblSumBrutto.Text = sumBrutto.ToString("N2")

                                             End Sub

        print.Viewer.LoadDocument(rpt)
        print.Viewer.ViewType = GrapeCity.Viewer.Common.Model.ViewType.Continuous
        print.Show()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Select Case Lieferant


            Case "MSE"
                genMSEBericht("TRANS")

        End Select

    End Sub
End Class
