' 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 Choix_Facturation_TP

    Private Sub Choix_Facturation_TP_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        date_accident_droit_commun()
    End Sub

    Private Sub Facturation_Choix_TP_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If MsgBox("LES SOINS DISPENSÉS SONT-ILS LA CONSÉQUENCE D'UN ACCIDENT CAUSÉ PAR UN TIERS?", 36) = MsgBoxResult.Yes Then
            Accident_CheckBox.Checked = True
        Else
            Accident_CheckBox.Checked = False
        End If

        If ((COMPTOIR_MAIN.AMC_NumAMC_TextBox.Text = "" And COMPTOIR_MAIN.MUT_NumMutuelle_TextBox.Text = "") Or COMPTOIR_MAIN.CheckBox_Facturation_AMC.Checked = False) _
        And COMPTOIR_MAIN.AMC_NumAMC_TextBox.Text <> "75500017" And COMPTOIR_MAIN.MUT_NumMutuelle_TextBox.Text <> "75500017" Then
            Button_Facturation_TP.Visible = False
        End If

        If COMPTOIR_MAIN.FS_Papier = True Then
            Button_Facturation_AMO.Visible = False
            Button_Facturation_AMC.Visible = False
            Button_Facturation_HTP.Visible = False
            Button_Facturation_TP.Visible = False
        End If
        If COMPTOIR_MAIN.NatureAssurance_Button.Text = "MALADIE" Then
            Accident_CheckBox.Visible = True
        End If

        If (COMPTOIR_MAIN.CheckBox_Facturation_AMC.Checked = False Or (CurrentConvention.selected = True And CurrentConvention.type_Accord = "H")) _
        And COMPTOIR_MAIN.AMC_NumAMC_TextBox.Text <> "75500017" And COMPTOIR_MAIN.MUT_NumMutuelle_TextBox.Text <> "75500017" Then
            Button_Facturation_TP.Visible = False
            Button_Facturation_AMC.Visible = False
        End If
        If CurrentConvention.selected = True And CurrentConvention.type_Accord = "T" Then
            Button_Facturation_AMO.Visible = False
            Button_Facturation_AMC.Visible = True
            Button_Facturation_HTP.Visible = False
            Button_Facturation_TP.Visible = True
        End If
        If CurrentConvention.selected = True And CurrentConvention.type_Accord = "H" Then
            Button_Facturation_AMO.Visible = True
            Button_Facturation_HTP.Visible = True
            Button_Facturation_TP.Visible = False
            Button_Facturation_AMC.Visible = False
        End If
        If CurrentConvention.selected = True Then
            Convention_Label.Text = "CONVENTION: "
            If CurrentConvention.type_Accord = "T" Then
                Convention_Label.Text = Convention_Label.Text + "Tiers-Payant" + Chr(10)
            ElseIf CurrentConvention.type_Accord = "H" Then
                Convention_Label.Text = Convention_Label.Text + "Hors Tiers-Payant" + Chr(10)
            End If
            Convention_Label.Text = Convention_Label.Text + "org signataire: " + CurrentConvention.Libellé_org_signataire + Chr(10) + "org complémentaire: " + CurrentConvention.libellé_Org_complémentaire
        Else
            Convention_Label.Text = "PAS DE CONVENTION"
        End If
        If tab_current_formule_STS.Length > 1 Then
            Convention_Label.Text = Convention_Label.Text + Chr(10) + Chr(10) + "Formules AMC:"
            For i = 1 To tab_current_formule_STS.Length - 1
                Convention_Label.Text = Convention_Label.Text + Chr(10) + "Prestation n°" + i.ToString + " --> formule " + tab_current_formule_STS(i).Numéro + ", " + tab_current_formule_STS(i).Libellé
            Next
        ElseIf current_formule_STS.selected = True And tab_current_formule_STS.Length = 1 Then
            Convention_Label.Text = Convention_Label.Text + Chr(10) + " Formule AMC appliquée au niveau facture: " + current_formule_STS.Numéro + ", " + current_formule_STS.Libellé
        Else
            Convention_Label.Text = Convention_Label.Text + Chr(10) + "Pas de Formule AMC"
        End If
        If CurrentFactureVitale.TOP_CMU = True Then
            Button_Facturation_TP.Visible = True
        End If
        If COMPTOIR_MAIN.NatureAssurance_Button.Text = "SMG" Then
            Button_Facturation_TP.Visible = False
        End If
    End Sub
    Private Sub Button_Facturation_TP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_TP.Click
        CurrentFactureVitale.TP_AMO = True
        CurrentFactureVitale.TP_AMC = True
        COMPTOIR_MAIN.Choix_Facturation_TP_retour = True
        Me.Dispose()
    End Sub

    Private Sub Button_Facturation_HTP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_HTP.Click
        CurrentFactureVitale.TP_AMO = False
        CurrentFactureVitale.TP_AMC = False
        COMPTOIR_MAIN.Choix_Facturation_TP_retour = True
        Me.Dispose()
    End Sub

    Private Sub Button_Facturation_FSPapier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_FSPapier.Click
        COMPTOIR_MAIN.FS_Papier = True
        COMPTOIR_MAIN.Choix_Facturation_TP_retour = True
        Me.Dispose()
    End Sub

    Private Sub Button_Facturation_AMO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_AMO.Click
        CurrentFactureVitale.TP_AMO = True
        CurrentFactureVitale.TP_AMC = False
        COMPTOIR_MAIN.Choix_Facturation_TP_retour = True
        Me.Dispose()
    End Sub

    Private Sub Button_Facturation_AMC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_AMC.Click
        CurrentFactureVitale.TP_AMO = False
        CurrentFactureVitale.TP_AMC = True
        COMPTOIR_MAIN.Choix_Facturation_TP_retour = True
        Me.Dispose()
    End Sub

    Private Sub Accident_CheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Accident_CheckBox.CheckedChanged
        If Accident_CheckBox.Checked = True Then
            Accident_DateTimePicker.Enabled = True
        Else
            Accident_DateTimePicker.Enabled = False
        End If
    End Sub

    Private Sub date_accident_droit_commun()
        If Accident_CheckBox.Checked = True Then
            CurrentFactureVitale.G1511C1 = Format(Accident_DateTimePicker.Value, "yyyyMMdd") + "0000"
        End If
    End Sub

    Private Sub Button_Annuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Annuler.Click
        COMPTOIR_MAIN.Choix_Facturation_TP_retour = False
        ReDim tab_current_formule_STS(0)
        current_formule_STS.Clear()
        CurrentConvention.clear()
        COMPTOIR_MAIN.PictureBox_Facturation.Visible = True
        Me.Dispose()
    End Sub



    Private Sub Change_Couleur_in(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_TP.Enter, Button_Facturation_AMO.Enter, Button_Facturation_HTP.Enter, Button_Facturation_FSPapier.Enter, Button_Annuler.Enter, Button_Facturation_AMC.Enter
        sender.BackColor = Color.Yellow
    End Sub
    Private Sub Change_Couleur_out(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Facturation_TP.LostFocus, Button_Facturation_AMO.LostFocus, Button_Facturation_HTP.LostFocus, Button_Facturation_FSPapier.LostFocus, Button_Annuler.LostFocus, Button_Facturation_AMC.LostFocus
        sender.BackColor = DefaultBackColor
    End Sub


End Class