Public Class rptRechnungMDM_AnlagenDruck_Zinsennachberechnung
    Dim _LAN = ""
    Dim RECHNUNG As VERAG_PROG_ALLGEMEIN.cRechnungsausgang = Nothing
    Dim LeistungsText As String
    Dim Anzahl As Integer
    Dim Betrag As Double
    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
    Sub New(_LAN As String, RECHNUNG As VERAG_PROG_ALLGEMEIN.cRechnungsausgang, LeistungsText As String, Anzahl As Integer, Betrag As Double)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me._LAN = _LAN
        Me.RECHNUNG = RECHNUNG
        Me.LeistungsText = LeistungsText
        Me.Anzahl = Anzahl
        Me.Betrag = Betrag
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
    End Sub
    Private Sub rptRechnungDruck_ReportStart(sender As Object, e As EventArgs) Handles MyBase.ReportStart
        If _LAN.replace("DE", "") <> "" Then
            SDL.cProgramFunctions._TRANSLATE_RPT(Me, Me.GroupHeader4.Controls, _LAN, "rptRechnungDruck_MDM")
            SDL.cProgramFunctions._TRANSLATE_RPT(Me, Me.PageFooter.Controls, _LAN, "rptRechnungDruck_MDM")
        End If
    End Sub


    Private Sub Detail_Format(sender As Object, e As EventArgs) Handles Detail.Format
        If Me.DataSource IsNot Nothing AndAlso Me.Fields IsNot Nothing Then
            txtREnr.Text = ""
            txtReDat.Text = ""
            txtReBetrag.Text = ""

            txtZE.Text = ""
            txtTage.Text = ""
            txtZinsen.Text = ""
            txtVZ.Text = ""
            txtFaellig.Text = ""
            txt_Anmerkung.Text = ""

            If Me.Fields.Item("clmnReNr") IsNot Nothing AndAlso Me.Fields.Item("clmnReNr").Value IsNot Nothing Then txtREnr.Text &= Me.Fields.Item("clmnReNr").Value.ToString
            If Me.Fields.Item("clmnReDatum") IsNot Nothing AndAlso Me.Fields.Item("clmnReDatum").Value IsNot Nothing AndAlso IsDate(Me.Fields.Item("clmnReDatum").Value) Then txtReDat.Text &= CDate(Me.Fields.Item("clmnReDatum").Value).ToShortDateString
            If Me.Fields.Item("clmnReBetrag") IsNot Nothing AndAlso Me.Fields.Item("clmnReBetrag").Value IsNot Nothing AndAlso IsNumeric(Me.Fields.Item("clmnReBetrag").Value) AndAlso CDbl(Me.Fields.Item("clmnReBetrag").Value) <> 0 Then txtReBetrag.Text &= Math.Abs(CDbl(Me.Fields.Item("clmnReBetrag").Value)).ToString("N2")
            If Me.Fields.Item("clmnFaellig") IsNot Nothing AndAlso Me.Fields.Item("clmnFaellig").Value IsNot Nothing AndAlso IsDate(Me.Fields.Item("clmnFaellig").Value) Then txtFaellig.Text &= CDate(Me.Fields.Item("clmnFaellig").Value).ToShortDateString
            If Me.Fields.Item("clmnZE") IsNot Nothing AndAlso Me.Fields.Item("clmnZE").Value IsNot Nothing Then
                If IsDate(Me.Fields.Item("clmnZE").Value) Then
                    txtZE.Text &= CDate(Me.Fields.Item("clmnZE").Value).ToShortDateString
                    txt_Anmerkung.Visible = False
                    txtZE.Visible = True
                    txtFaellig.Visible = True
                    txtTage.Visible = True
                    txtReBetrag.Visible = True
                Else
                    txt_Anmerkung.Text &= Me.Fields.Item("clmnZE").Value
                    txt_Anmerkung.Visible = True
                    txtZE.Visible = False
                    txtFaellig.Visible = False
                    txtTage.Visible = False
                    txtReBetrag.Visible = False
                End If
            End If
            If Me.Fields.Item("clmnTage") IsNot Nothing AndAlso Me.Fields.Item("clmnTage").Value IsNot Nothing Then txtTage.Text &= Me.Fields.Item("clmnTage").Value.ToString
            If Me.Fields.Item("clmnZinsen") IsNot Nothing AndAlso Me.Fields.Item("clmnZinsen").Value IsNot Nothing AndAlso IsNumeric(Me.Fields.Item("clmnZinsen").Value) AndAlso CDbl(Me.Fields.Item("clmnZinsen").Value) <> 0 Then txtZinsen.Text &= CDbl(Me.Fields.Item("clmnZinsen").Value).ToString("N2")
            If Me.Fields.Item("clmnVZ") IsNot Nothing AndAlso Me.Fields.Item("clmnVZ").Value IsNot Nothing AndAlso IsNumeric(Me.Fields.Item("clmnVZ").Value) Then txtVZ.Text &= Me.Fields.Item("clmnVZ").Value.ToString() & "%"

        End If
    End Sub

    Private Sub rptAuswertung_ReportStart(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportStart
        If RECHNUNG Is Nothing Then Exit Sub

        Dim dt As New DataTable
        dt.Columns.Add("clmnID")
        dt.Columns.Add("clmnReNr")
        dt.Columns.Add("clmnReDatum")
        dt.Columns.Add("clmnAbfNr")
        dt.Columns.Add("clmnReBetrag")
        dt.Columns.Add("clmnZE")
        dt.Columns.Add("clmnTage")
        dt.Columns.Add("clmnZinsen")
        dt.Columns.Add("clmnVZ")
        dt.Columns.Add("clmnFaellig")

        RECHNUNG.ORDER_POSITIONEN()

        If RECHNUNG.POSITIONEN.Any() Then

            If Anzahl > 0 AndAlso Betrag < 0 Then

                Dim Rabatt As String = "Rabatt"

                Select Case RECHNUNG.RechnungSprache
                    Case "EN" : Rabatt = "Discount"
                    Case "RO" : Rabatt = "Reducere"
                    Case "TR" : Rabatt = "İndirim"
                    Case Else
                        Rabatt = "Rabatt"

                End Select


                dt.Rows.Add("0", Rabatt, RECHNUNG.Abfertigungsdatum.ToShortDateString, "", "", LeistungsText.ToString, "", Betrag.ToString, "", "")
                'dt.Rows.Add(rg.Item("clmnID"), rg.Item("clmnReNr"), rg.Item("clmnReDatum"), rg.Item("clmnAbfNr"), rg.Item("clmnReBetrag"), rg.Item("clmnZE"), rg.Item("clmnTage"), rg.Item("clmnZinsen"), rg.Item("clmnVZ"), rg.Item("clmnFaellig"))

            Else


                If RECHNUNG.BelegartenKz <> "AG" Then

                    Dim dtTemp As DataTable
                    dtTemp = SQL.loadDgvBySql_Param("select [id] as clmnID,[belegNr] as clmnReNr,[buchungstext] as clmnAbfNr,[zinssatz] clmnVZ,[belegZahlungsziel],[ueberschreitungInTagen] clmnTage,[zinsbetrag] clmnZinsen,[belegDatum] as clmnReDatum,[zahlungsBetrag] as clmnReBetrag,[zahlungDatum] as clmnZE, [faelligkeitsDatum] as clmnFaellig from tblMDM_Zinsberechnung where RK_ID =" & RECHNUNG.RK_ID & " and RIGHT('00000' + CAST(id AS VARCHAR(5)), 5) +'-'+ buchungstext like '" & LeistungsText.Trim() & "%'", "FMZOLL")

                    For Each rg As DataRow In dtTemp.Rows
                        dt.Rows.Add(rg.Item("clmnID"), rg.Item("clmnReNr"), rg.Item("clmnReDatum"), rg.Item("clmnAbfNr"), rg.Item("clmnReBetrag"), rg.Item("clmnZE"), rg.Item("clmnTage"), rg.Item("clmnZinsen"), rg.Item("clmnVZ"), rg.Item("clmnFaellig"))
                    Next
                Else
                    dt.Rows.Add("0", "", RECHNUNG.Abfertigungsdatum.ToShortDateString, "", "", LeistungsText.ToString, "", Betrag.ToString, "", "")

                End If

            End If
        End If


        Me.DataSource = dt

    End Sub
End Class
