Imports GrapeCity.ActiveReports
Imports GrapeCity.ActiveReports.Document
Imports System.Globalization


Public Class rptAuswertungMWSTOffeneAntraegeMitVorauszahlung
    Public datVon As Date
    Public erstelltVon As String = ""
    Private Sub PageFooter1_Format(sender As System.Object, e As System.EventArgs) Handles PageFooter.Format
        lblDetails.Text = String.Format("erstellt am {0} um {1} von {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), erstelltVon)

    End Sub

    Private Sub rptAuswertung_NoData(sender As Object, e As System.EventArgs) Handles Me.NoData
        MsgBox("Es wurden keine Daten zum Drucken gefunden.", vbInformation, "Druck Aviso-Auswertung")
        Me.Cancel()  'ev. abbrechen, falls noch aufgebaut wird
    End Sub

    '''''''' ADD AT RUNTIME:
    'Dim d As New GrapeCity.ActiveReports.SectionReportModel.TextBox
    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart

        '''''''' ADD AT RUNTIME:
        'd.Location = New Point(2, 0)
        'd.Text = "asd"
        'Me.Detail.Controls.Add(d)


        Me.Name = "Auswertung offene Anträge mit Vorauszahlung"

        'lblHeader.Text = Me.Name

        'Format + Ränder setzen
        Me.PageSettings.Orientation = Section.PageOrientation.Portrait
        Me.PageSettings.Margins.Left = 0.3
        Me.PageSettings.Margins.Right = 0.3
        Me.PageSettings.Margins.Top = 0.5
        Me.PageSettings.Margins.Bottom = 0.4

        Dim sqlStr As String = " SELECT  tblUStVAntrag.UStVAn_KuNr as kdNr, (SELECT Ordnungsbegriff from Adressen WHERE Adressen.AdressenNr=tblUStVAntrag.UStVAn_KuNr ) as Firma, SUM(([UStVAn_USteuerbetragEUR]-[UStVAn_ErstattungsbetragEUR])) as [Summe Differnezbetrag],count(*) as [Anzahl Anträge] " &
                                    " FROM tblUStVAntrag INNER JOIN Adressen on Adressen.AdressenNr=tblUStVAntrag.UStVAn_KuNr " &
                                " WHERE  UStVAn_ReDatVon >='" & datVon.ToShortDateString & "' " &
                                    " and UStVAn_ReDatBis <=GETDATE() " &
                                    " and ([UStVAn_USteuerbetrag]-[UStVAn_Erstattungsbetrag])>0 " &
                                    " and UStVAn_VZBetrag is null " &
                                    " and Adressen.MWSTVorauszahlung is not null " &
                                    " and Adressen.MWSTVorauszahlung = 1 " &
                                " group by UStVAn_KuNr " &
                                " order by Firma "



        Dim kundenSQL As New kundenSQL
        Me.DataSource = kundenSQL.loadDgvBySql(sqlStr, "FMZOLL")

    End Sub

    Dim dummycount As Integer = 0
    Private Sub Detail1_Format(sender As System.Object, e As System.EventArgs) Handles Detail.Format
        dummycount = dummycount + 1
        TextBoxKdnr.Text = CStr(Fields.Item("kdNr").Value)
        txtFirma.Text = CStr(Fields.Item("Firma").Value)
        txtBetraege.Text = "€ " & CDbl(Fields.Item("Summe Differnezbetrag").Value).ToString("N2", CultureInfo.InvariantCulture)
        txtAnzahl.Text = CStr(Fields.Item("Anzahl Anträge").Value)


        'Abwechselnd grauen und weißen Hintergrund
        If (dummycount Mod 2) = 0 Then
            Detail.BackColor = Color.White
        Else
            Detail.BackColor = Color.WhiteSmoke
        End If
    End Sub
End Class
