' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Public Class Pauses

    Private Sub imprimer_Button_Click(sender As Object, e As EventArgs) Handles imprimer_Button.Click
        PrintDialog1.Document = PrintDocument1
        If Config.Ticket_pause_default_printer <> "" Then
            PrintDocument1.PrinterSettings.PrinterName = Config.Ticket_pause_default_printer
            PrintDocument1.Print()
        ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PrintDocument1.Print()
        End If
        Me.Close()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim drawFont As New Font("Courier", 10)
        Dim drawBrush As New SolidBrush(Color.Black)
        If Config.Ticket_pause_lignes_blanches > 0 Then
            For i = 1 To Config.Ticket_pause_lignes_blanches
                RichTextBox1.Text = Chr(10) & RichTextBox1.Text
            Next
        End If
        e.Graphics.DrawString(RichTextBox1.Text, drawFont, drawBrush, 10, 10)
    End Sub

    Private Sub Pauses_Load(sender As Object, e As EventArgs) Handles Me.Load
        RichTextBox1.Clear()
        RichTextBox1.AppendText(Now.ToShortDateString & " " & Now.ToShortTimeString & Chr(10) & Chr(10))
        RichTextBox1.AppendText("benef: " & COMPTOIR_MAIN.ComboBoxLECTURE_VITALE.Text & "  " & COMPTOIR_MAIN.NirTextBox.Text & Chr(10) & Chr(10))
        RichTextBox1.AppendText("prescr: " & COMPTOIR_MAIN.PrescripteurMyCombobox.Text & Chr(10) & Chr(10) & Chr(10))
        For i = 0 To COMPTOIR_MAIN.Vente.RowCount - 1
            If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value <> "" Or COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value <> "" Or _
                (COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, i).Value <> "" And COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCodeActe.Index, i).Value = "") Then
                RichTextBox1.AppendText(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value & " " & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, i).Value)
                If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value <> "" Then
                    RichTextBox1.AppendText(" " & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value & " ")
                ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value <> "" Then
                    RichTextBox1.AppendText(" " & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value & " ")
                End If
                If Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value) > Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteStock.Index, i).Value) Then
                    If Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteStock.Index, i).Value) >= 0 Then
                        RichTextBox1.AppendText(Chr(10) & "   MANQUE " & (Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value) - Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteStock.Index, i).Value)).ToString & Chr(10) & Chr(10))
                    Else
                        RichTextBox1.AppendText(Chr(10) & "   MANQUANT" & Chr(10) & Chr(10))
                    End If
                Else
                    RichTextBox1.AppendText(Chr(10) & Chr(10))
                End If

            End If
        Next
    End Sub
End Class