' 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 Détails_inventaire
    Public nom_inventaire As String
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Afficher_prod_non_inventoriés()
    End Sub
    Public Sub Afficher_prod_non_inventoriés()
        prod_non_inventoriés_DataGridView1.Rows.Clear()
        Dim produits = BDD.ProduitsTableAdapter.GetData_Non_inventoriés(Stock_Mini_TextBox.Text, Recherche_TextBox_non_inv.Text, nom_inventaire)
        For r = 0 To produits.Rows.Count - 1
            prod_non_inventoriés_DataGridView1.Rows.Add()
        Next
        For r = 0 To produits.Rows.Count - 1
            prod_non_inventoriés_DataGridView1.Item(prod_non_inventoriés_désignation.Index, r).Value = produits(r).Designation
            prod_non_inventoriés_DataGridView1.Item(prod_non_inventoriés_Stock.Index, r).Value = CInt(produits(r).Stock)
        Next
        Recap_non_inventoriés()
    End Sub

    Private Sub Stock_Mini_TextBox_TextChanged(sender As Object, e As EventArgs) Handles Stock_Mini_TextBox.TextChanged
        If Not IsNumeric(Stock_Mini_TextBox.Text) Then
            Stock_Mini_TextBox.Text = "1"
        End If
    End Sub
    Private Sub Recap_non_inventoriés()
        RichTextBox1.Clear()
        Dim nombre_boites As Decimal
        For r = 0 To prod_non_inventoriés_DataGridView1.Rows.Count - 1
            nombre_boites = nombre_boites + CDec(prod_non_inventoriés_DataGridView1.Item(prod_non_inventoriés_Stock.Index, r).Value)
        Next
        RichTextBox1.AppendText("Produits en attente inventaire avec stock >= " & Stock_Mini_TextBox.Text & " :")
        If Recherche_TextBox_non_inv.Text <> "" Then
            RichTextBox1.AppendText("   (filtre:" & Recherche_TextBox_non_inv.Text & ")")
        End If
        RichTextBox1.AppendText(vbCrLf & prod_non_inventoriés_DataGridView1.Rows.Count & " références" & vbCrLf & nombre_boites.ToString & " boites/conditionements")
    End Sub


    Public Sub Afficher_prod_inventoriés()
        prod_inventoriés_DataGridView1.Rows.Clear()
        Dim produits = BDD.InventaireTableAdapter.GetData_affiche_inventaire(nom_inventaire, Recherche_TextBox_inv.Text)
        For r = 0 To produits.Rows.Count - 1
            prod_inventoriés_DataGridView1.Rows.Add()
        Next
        For r = 0 To produits.Rows.Count - 1
            prod_inventoriés_DataGridView1.Item(DataGridViewTextBoxColumn1.Index, r).Value = produits(r).Désignation
            prod_inventoriés_DataGridView1.Item(DataGridViewTextBoxColumn2.Index, r).Value = CInt(produits(r).Stock_avant_inventaire)
            prod_inventoriés_DataGridView1.Item(DataGridViewTextBoxColumn3.Index, r).Value = CInt(produits(r).Quantité_inventaire)
        Next
        Recap_inventoriés()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Afficher_prod_inventoriés()
    End Sub
    Private Sub Recap_inventoriés()
        RichTextBox2.Clear()
        Dim nombre_boites As Decimal
        For r = 0 To prod_inventoriés_DataGridView1.Rows.Count - 1
            nombre_boites = nombre_boites + CDec(prod_inventoriés_DataGridView1.Item(DataGridViewTextBoxColumn3.Index, r).Value)
        Next
        RichTextBox2.AppendText("Produits inventoriés :")
        If Recherche_TextBox_inv.Text <> "" Then
            RichTextBox2.AppendText("   (filtre:" & Recherche_TextBox_non_inv.Text & ")")
        End If
        RichTextBox2.AppendText(vbCrLf & prod_inventoriés_DataGridView1.Rows.Count & " références" & vbCrLf & nombre_boites.ToString & " boites/conditionements")
    End Sub
End Class