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

'-- Szolgáltatások
<DefaultClassOptions()> _
<NavigationItem("BusinessStocks")> _
<Appearance("Disable ObjectCreated and UserCreated", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated;UserCreated", Enabled:=False)> _
Public Class Services 'Szolgáltatások törzse
    Inherits BaseObject
    Private _RowGroup1 As String 'Szöveges csoportosítás (nem kötelező)
    Private _RowGroup2 As String 'Szöveges másodlagos csoportosítás (nem kötelező)
    Private _ShortName As String 'Megnevezés
    Private _Description As String 'Leírás
    Private _CustomsTariffs As CustomsTariffs 'Vámtarifaszám, vagy szj szám vagy még ami lesz
    Private _ListPriceHUF As Double = 0 'Listaár HUF
    Private _ListPriceDEV As Double = 0 ' Listaár DEV
    Private _CostPriceHUF As Double = 0 'Költségár HUF
    Private _CostPriceDEV As Double = 0 ' Költségár DEV
    Private _Units As Units 'Mennyiségi egység
    Private _VAT As VAT 'ÁFA kód
    Private _Recipe As Recipe 'A szolgáltatáshoz milyen recept tartozik
    Private _ObjectCreated As Date 'Létrehozás dátuma
    Private _UserCreated As User 'Létrehozó
    Private _MasterBusinessDirectory As BusinessDirectory
    Private _QTT_Will As Double

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.ObjectCreated = GetSQLTime(Session)
        Me.UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        Me.VAT = Session.FindObject(Of VAT)(CriteriaOperator.Parse("DefaultForBusinnes='True'"))
    End Sub
    Property RowGroup1 As String
        Get
            Return _RowGroup1
        End Get
        Set(value As String)
            SetPropertyValue("RowGroup1", _RowGroup1, value)
        End Set
    End Property
    Property RowGroup2 As String
        Get
            Return _RowGroup2
        End Get
        Set(value As String)
            SetPropertyValue("RowGroup2", _RowGroup2, value)
        End Set
    End Property
    <RuleRequiredField("Services-ShortName", DefaultContexts.Save)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    Property CustomsTariffs As CustomsTariffs
        Get
            Return _CustomsTariffs
        End Get
        Set(value As CustomsTariffs)
            SetPropertyValue("CustomsTariffs", _CustomsTariffs, value)
        End Set
    End Property
    <RuleRequiredField("", DefaultContexts.Save)> _
   <RuleValueComparison("Services-ListPriceHUF 0<", DefaultContexts.Save, ValueComparisonType.GreaterThan, 0)> _
    Property ListPriceHUF As Double
        Get
            Return _ListPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceHUF", _ListPriceHUF, value)
        End Set
    End Property
    Property ListPriceDEV As Double
        Get
            Return _ListPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceDEV", _ListPriceDEV, value)
        End Set
    End Property
    Property CostPriceHUF As Double
        Get
            Return _CostPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("CostPriceHUF", _CostPriceHUF, value)
        End Set
    End Property
    Property CostPriceDEV As Double
        Get
            Return _CostPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("CostPriceDEV", _CostPriceDEV, value)
        End Set
    End Property
    <RuleRequiredField("Services-Units", DefaultContexts.Save)> _
    Property Units As Units
        Get
            Return _Units
        End Get
        Set(value As Units)
            SetPropertyValue("Units", _Units, value)
        End Set
    End Property
    <RuleRequiredField("Services-VAT", DefaultContexts.Save)> _
    Property VAT As VAT
        Get
            Return _VAT
        End Get
        Set(value As VAT)
            SetPropertyValue("VAT", _VAT, value)
        End Set
    End Property
    Property Recipe As Recipe
        Get
            Return _Recipe
        End Get
        Set(value As Recipe)
            SetPropertyValue("Recipe", _Recipe, 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
    Property MasterBusinessDirectory As BusinessDirectory
        Get
            Return _MasterBusinessDirectory
        End Get
        Set(value As BusinessDirectory)
            SetPropertyValue("MasterBusinessDirectory", _MasterBusinessDirectory, value)
        End Set
    End Property
    <NonPersistent()> _
    Property QTT_Will As Double
        Get
            Return _QTT_Will
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Will", _QTT_Will, value)
        End Set
    End Property

    ReadOnly Property Services_BusinessDirectory As XPCollection(Of BusinessDirectory)
        Get
            Dim _BusinessDirectory_Collection As New XPCollection(Of BusinessDirectory)(Session, CriteriaOperator.Parse("1=2"))

            If MasterBusinessDirectory IsNot Nothing Then
                If MasterBusinessDirectory.Children.Count > 0 Then
                    _BusinessDirectory_Collection.Add(MasterBusinessDirectory)
                    RecursiveBusinessDirectory(_BusinessDirectory_Collection, MasterBusinessDirectory.NestedBusinessDirectory)
                Else
                    _BusinessDirectory_Collection.Add(MasterBusinessDirectory)
                End If
            End If


            Return _BusinessDirectory_Collection
        End Get
    End Property

#Region "Other subs"
    Private Sub RecursiveBusinessDirectory(_BusinessDirectoryList As XPCollection(Of BusinessDirectory), _NestedBusinessDirectory As XPCollection(Of BusinessDirectory))
        For Each _BusinessDirectory As BusinessDirectory In _NestedBusinessDirectory
            If _BusinessDirectory.Children.Count > 0 Then
                _BusinessDirectoryList.Add(_BusinessDirectory)
                RecursiveBusinessDirectory(_BusinessDirectoryList, _BusinessDirectory.NestedBusinessDirectory)
            Else
                _BusinessDirectoryList.Add(_BusinessDirectory)
            End If
        Next
    End Sub
#End Region
End Class







