Imports System
Imports System.ComponentModel

Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering

Imports DevExpress.ExpressApp
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation

Imports DevExpress.ExpressApp.ConditionalAppearance
Imports DevExpress.ExpressApp.Editors

'<EditorStateRule("Disable all properties", "RegistryHeader;BruttoAmount;Note;VAT", ViewType.DetailView, Criteria:="RegistryHeader.BruttoAmountRemaining = 0", EditorState:=DevExpress.ExpressApp.ConditionalEditorState.EditorState.Disabled)> _

<Appearance("Disable actions if currentstep is not eCheckVAT", AppearanceItemType:="Action", Criteria:="not (RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType in (1,5))", TargetItems:="Save;SaveAndNew;SaveAndClose;Delete", Enabled:=False, Context:="Any")> _
<Appearance("Disable all properties", TargetItems:="RegistryHeader;BruttoAmount;Note;VAT", Criteria:="RegistryHeader.BruttoAmountRemaining = 0", Enabled:=False, Context:="DetailView")> _
<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
Public Class RegistryRowsFinancial '-- Iktatórendszer sorai, ha p.ü. kapcsolat van.
    Inherits BaseObject
    Private _RegistryHeader As RegistryHeader
    Private _BruttoAmount As Double 'Bruttó összeg
    Private _Note As String 'Megjegyzés
    Private _VAT As VAT 'ÁFA kód
    Private _DateVAT As Date
    Private _F_ReadyforBookEntryRows As Boolean
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        If Me.RegistryHeader IsNot Nothing Then

        End If
        F_ReadyforBookEntryRows = False
    End Sub
    <Association("RegistryHeader-RegistryRowsFinancial", GetType(RegistryHeader))> _
    Property RegistryHeader() As RegistryHeader
        Get
            Return _RegistryHeader
            'Me.RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckVAT
        End Get
        Set(ByVal value As RegistryHeader)
            SetPropertyValue("RegistryHeader", _RegistryHeader, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And value IsNot Nothing Then
                If IsDate(Me.RegistryHeader.F_DateVAT) Then
                    DateVAT = Me.RegistryHeader.F_DateExecution
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("RegistryRows-BruttoAmount", DefaultContexts.Save)> _
    Property BruttoAmount As Double
        Get
            Return _BruttoAmount
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("BruttoAmount", _BruttoAmount, value)
        End Set
    End Property
    <Size(-1)> _
    Property Note As String
        Get
            Return _Note
        End Get
        Set(ByVal value As String)

        End Set
    End Property
    <ImmediatePostData(True)> _
    <RuleRequiredField("RegistryRowsFinancial.VAT", DefaultContexts.Save)> _
    Property VAT As VAT
        Get
            Return _VAT
        End Get
        Set(ByVal value As VAT)
            SetPropertyValue("VAT", _VAT, value)
        End Set
    End Property
    ReadOnly Property VATAmount As Double
        Get
            If Me.VAT IsNot Nothing Then
                Dim _VATAmount As Double = Me.BruttoAmount / (100 + Me.VAT.KeyValuePercent) * Me.VAT.KeyValuePercent
                Return Math.Round(_VATAmount, 0, MidpointRounding.AwayFromZero)
            Else
                Return 0
            End If
        End Get
    End Property
    ReadOnly Property NettoAmount As Double
        Get
            If Me.VAT IsNot Nothing Then
                Return Me.BruttoAmount - Me.VATAmount
            End If
        End Get
    End Property
    Property DateVAT As Date
        Get
            Return _DateVAT
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateVAT", _DateVAT, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading And Me.RegistryHeader IsNot Nothing Then
                If Not Me.RegistryHeader.F_DateVAT = value Then
                    Me.RegistryHeader.F_DateVAT = value
                    ' Me.RegistryHeader.Save()
                End If
            End If
        End Set
    End Property
    Property F_ReadyforBookEntryRows As Boolean
        Get
            Return _F_ReadyforBookEntryRows
        End Get
        Set(value As Boolean)
            SetPropertyValue("F_ReadyforBookEntryRows", _F_ReadyforBookEntryRows, value)
        End Set
    End Property

End Class

