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
Public Enum eFixedAssetsTerminalReason
    eNone = 0
    eSold = 1
    eInventoryShortage = 2
    eDisposal = 3
End Enum
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide info when IsNew=False", AppearanceItemType:="ViewItem", criteria:="IsNew=True", targetitems:="AmountHUFOpen;DateOpen", visibility:=DevExpress.ExpressApp.Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable UniqueObjects if exists", AppearanceItemType:="ViewItem", criteria:="isnull(UniqueObjects)=False", targetitems:="UniqueObjects", enabled:=False)> _
<Appearance("Disable FixedAssetsGroup1 if exists", AppearanceItemType:="ViewItem", criteria:="isnull(FixedAssetsGroup1)=False", targetitems:="FixedAssetsGroup1", enabled:=False)> _
<Appearance("Disable CustomersFrom if exists", AppearanceItemType:="ViewItem", criteria:="isnull(CustomersFrom)=False", targetitems:="CustomersFrom", enabled:=False)> _
Public Class FixedAssetsCard
    Inherits BaseObject

    Private _CustomersFrom As CustomersFrom
    Private _FixedAssetsGroup1 As FixedAssetsGroup1

    Private _ShortName As String
    Private _Description As String
    Private _UniqueObjects As UniqueObjects

    Private _DateFabrication As Date 'Gyártási év
    Private _DateAcquisition As Date 'Beszerzés dátuma
    Private _DateActivation As Date 'Aktiválás dátuma
    Private _DateTerminal As Date 'Kivezetés dátuma
    Private _DateOpen As Date 'ÉCS Nyitó dátuma
    Private _IsActivated As Boolean = False
    Private _AmountHUFBrutto As Double 'Bruttó érték
    Private _AmountHUFOpen As Double 'Nyitó érték
    Private _AmountHUFDevelopmentReserve As Double 'Fejlesztési tartalék
    Private _IsNew As Boolean = True 'Új, vagy másik rendszerből átvett
    Private _IsTerminal As Boolean = False 'Kivezetve ?
    Private _FixedAssetsTerminalReason As eFixedAssetsTerminalReason

    Private _DCPAccounting As FixedAssetsDecrepationParameter 'Számvitel szrinti ÉCS paraméter
    Private _AmountHUFSalvage As Double 'Maradványérték
    Private _DCPTax As FixedAssetsDecrepationParameter 'TA szerinti ÉCS paraméter

    Private _IsEditable As Boolean = True
    Private _ObjectCreated As Date
    Private _UserCreated As User

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
        If UniqueObjects Is Nothing Then
            Dim _UniqueObject_Name As String
            Dim _UniqueObjects As UniqueObjects

            _UniqueObject_Name = Me.FixedAssetsGroup1.NumberGenerator.GetNewNumber(Me.FixedAssetsGroup1.NumberGenerator, Me.DateAcquisition.Year.ToString)
            If _UniqueObject_Name <> "" Then
                _UniqueObjects = New UniqueObjects(Session)
                _UniqueObjects.Name = _UniqueObject_Name
                Me.UniqueObjects = _UniqueObjects
            End If
        End If
    End Sub
    <RuleRequiredField("FixedAssetsCard-CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("FixedAssetsCard-FixedAssetsGroup1", DefaultContexts.Save)> _
    Property FixedAssetsGroup1 As FixedAssetsGroup1
        Get
            Return _FixedAssetsGroup1
        End Get
        Set(value As FixedAssetsGroup1)
            SetPropertyValue("FixedAssetsGroup1", _FixedAssetsGroup1, value)
        End Set
    End Property
    <RuleRequiredField("FixedAssetsCard-ShortName", DefaultContexts.Save)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <Size(-1)> _
    <RuleRequiredField("FixedAssetsCard-Description", DefaultContexts.Save)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    <NonCloneable()> _
    Property UniqueObjects As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
        End Set
    End Property
    Property DateFabrication As Date
        Get
            Return _DateFabrication
        End Get
        Set(value As Date)
            SetPropertyValue("DateFabrication", _DateFabrication, value)
        End Set
    End Property
    Property DateAcquisition As Date
        Get
            Return _DateAcquisition
        End Get
        Set(value As Date)
            SetPropertyValue("DateAcquisition", _DateAcquisition, value)
        End Set
    End Property
    Property DateActivation As Date
        Get
            Return _DateActivation
        End Get
        Set(value As Date)
            SetPropertyValue("DateActivation", _DateActivation, value)
        End Set
    End Property
    Property DateTerminal As Date
        Get
            Return _DateTerminal
        End Get
        Set(value As Date)
            SetPropertyValue("DateTerminal", _DateTerminal, value)
        End Set
    End Property
    Property DateOpen As Date
        Get
            Return _DateOpen
        End Get
        Set(value As Date)
            SetPropertyValue("DateOpen", _DateOpen, value)
        End Set
    End Property
    <NonCloneable()> _
    Property IsActivated As Boolean
        Get
            Return _IsActivated
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsActivated", _IsActivated, value)
        End Set
    End Property
    Property AmountHUFBrutto As Double
        Get
            Return _AmountHUFBrutto
        End Get
        Set(value As Double)
            SetPropertyValue("AmountHUFBrutto", _AmountHUFBrutto, value)
        End Set
    End Property
    Property AmountHUFOpen As Double
        Get
            Return _AmountHUFOpen
        End Get
        Set(value As Double)
            SetPropertyValue("AmountHUFOpen", _AmountHUFOpen, value)
        End Set
    End Property
    Property AmountHUFDevelopmentReserve As Double
        Get
            Return _AmountHUFDevelopmentReserve
        End Get
        Set(value As Double)
            SetPropertyValue("AmountHUFDevelopmentReserve", _AmountHUFDevelopmentReserve, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <NonCloneable()> _
    Property IsNew As Boolean
        Get
            Return _IsNew
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsNew", _IsNew, value)
        End Set
    End Property
    <NonCloneable()> _
    Property IsTerminal As Boolean
        Get
            Return _IsTerminal
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsTerminal", _IsTerminal, value)
        End Set
    End Property
    Property FixedAssetsTerminalReason As eFixedAssetsTerminalReason
        Get
            Return _FixedAssetsTerminalReason
        End Get
        Set(value As eFixedAssetsTerminalReason)
            SetPropertyValue("FixedAssetsTerminalReason", _FixedAssetsTerminalReason, value)
        End Set
    End Property

    <RuleRequiredField("FixedAssetsCard-DCPAccounting", DefaultContexts.Save)> _
    Property DCPAccounting As FixedAssetsDecrepationParameter
        Get
            Return _DCPAccounting
        End Get
        Set(value As FixedAssetsDecrepationParameter)
            SetPropertyValue("DCPAccounting", _DCPAccounting, value)
        End Set
    End Property
    Property AmountHUFSalvage As Double
        Get
            Return _AmountHUFSalvage
        End Get
        Set(value As Double)
            SetPropertyValue("AmountHUFSalvage", _AmountHUFSalvage, value)
        End Set
    End Property
    <RuleRequiredField("FixedAssetsCard-DCPTax", DefaultContexts.Save)> _
    Property DCPTax As FixedAssetsDecrepationParameter
        Get
            Return _DCPTax
        End Get
        Set(value As FixedAssetsDecrepationParameter)
            SetPropertyValue("DCPTax", _DCPTax, value)
        End Set
    End Property
    <NonCloneable()> _
    Property IsEditable As Boolean
        Get
            Return _IsEditable
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property
    <NonCloneable()> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    <NonCloneable()> _
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property

    '//XPCollection
    <Association("FixedAssetsCard-FixedAssetsCardPlanRows", GetType(FixedAssetsCardPlanRows)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property FixedAssetsCardPlanRows As XPCollection(Of FixedAssetsCardPlanRows)
        Get
            Return GetCollection(Of FixedAssetsCardPlanRows)("FixedAssetsCardPlanRows")
        End Get
    End Property
End Class
