Imports Microsoft.VisualBasic

<Serializable>
Public Class CalculettePaiementNOSP2
    Public Property IsGestionCumul As Boolean
    Private _isCumulSituationEditable As Boolean = True

    Private _cumulAnterieur As Decimal
    Public Property CumulAnterieur As Decimal
        Get
            Return _cumulAnterieur
        End Get
        Set(value As Decimal)
            _cumulAnterieur = value
        End Set
    End Property

    Private _cumulEnCours As Decimal
    Public Property CumulEnCours As Decimal
        Get
            Return _cumulEnCours
        End Get
        Set(value As Decimal)
            _cumulEnCours = value
        End Set
    End Property

    Public Property IsCumulSituationEditable As Boolean
        Get
            Return _isCumulSituationEditable
        End Get
        Private Set(value As Boolean)
            _isCumulSituationEditable = value
        End Set
    End Property

    Private _montantDemande As Decimal
    Public Property MontantDemande As Decimal
        Get
            Return _montantDemande
        End Get
        Set(value As Decimal)
            _montantDemande = value
        End Set
    End Property

    Private _deductions As CalculetteDeductionNOSP2
    Public Property Deductions As CalculetteDeductionNOSP2
        Get
            Return _deductions
        End Get
        Set(value As CalculetteDeductionNOSP2)
            _deductions = value
        End Set
    End Property

    Private _montantHTVA As Decimal
    Public Property MontantHTVA As Decimal
        Get
            Return _montantHTVA
        End Get
        Set(value As Decimal)
            _montantHTVA = value
        End Set
    End Property

    Private _montantTVA As Decimal
    Public Property MontantTVA As Decimal
        Get
            Return _montantTVA
        End Get
        Set(value As Decimal)
            _montantTVA = value
        End Set
    End Property

    Private _TauxTVA As Decimal
    Public Property TauxTVA As Decimal
        Get
            Return _TauxTVA
        End Get
        Set(value As Decimal)
            _TauxTVA = value
        End Set
    End Property

    Private _montantTTC As Decimal
    Public Property MontantTTC As Decimal
        Get
            Return _montantTTC
        End Get
        Set(value As Decimal)
            _montantTTC = value
        End Set
    End Property

#Region "EditionPossible"

    Public ReadOnly Property MontantDemandeEditable As Boolean
        Get
            Return Not IsGestionCumul
        End Get
    End Property

#End Region

    Private Sub CalculTVA()
        MontantTVA = MontantTTC - MontantHTVA
        CalculTauxTVA()
    End Sub

    Public Sub CalculTauxTVA()
        If MontantHTVA = 0 Then
            TauxTVA = 0
        Else
            TauxTVA = ((MontantTTC / MontantHTVA) - 1) * 100
        End If
    End Sub

    Public Sub Calcul()
        If IsGestionCumul Then
            MontantDemande = CumulEnCours - CumulAnterieur
        End If

        If Deductions IsNot Nothing Then
            Deductions.AutoCalcul(MontantDemande)
            MontantHTVA = MontantDemande - Deductions.Total
        Else
            MontantHTVA = MontantDemande
        End If

        CalculTVA()
    End Sub

    Public Sub DesactivationDeductionRG()
        If Deductions IsNot Nothing Then
            Deductions.DesactivationEditionRG()
        End If
    End Sub

    Public Sub DesactivationDeductionProrata()
        If Deductions IsNot Nothing Then
            Deductions.DesactivationEditionProrata()
        End If
    End Sub

    Public Sub DesactivationDeductionPenalite()
        If Deductions IsNot Nothing Then
            Deductions.DesactivationEditionPenalite()
        End If
    End Sub

    Public Sub DesactivationDeductionAutre()
        If Deductions IsNot Nothing Then
            Deductions.DesactivationEditionAutre()
        End If
    End Sub

#Region "Constructors"

    Public Sub New(isGestionCumul As Boolean, isCumulSituationEditable As Boolean)
        Deductions = New CalculetteDeductionNOSP2()

        Me.IsGestionCumul = isGestionCumul
        Me.IsCumulSituationEditable = isCumulSituationEditable
    End Sub

#End Region

End Class
