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 eImportMode
    eInternalwithVAT = 0 'Belföldi ÁFÁ-s
    eExternalEUwithVAT = 1 'EU-ból ÁFÁ-s
    eExternalEUNoVAT = 2 'EU-ból nem ÁFÁs
    eExternalOther = 3 ' EU-n kívüli nem ÁFÁS
End Enum
<DefaultClassOptions()> _
<NavigationItem("BusinessStocks")> _
<Appearance("DeliveryNoteInType - Hide RegistryType if  IsPrice=False", AppearanceItemType.ViewItem, "IsPrice=False", TargetItems:="RegistryType", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class DeliveryNoteInType 'Bejövő szállítólevél  tipusok
    Inherits BaseObject
    Private _CustomersFrom As CustomersFrom 'Saját cég
    Private _ImportMode As eImportMode '
    Private _IsPrice As Boolean = True 'Van-e ár
    Private _IsOrderOut As Boolean = False 'Van-e rendeléssel ütköztetés
    Private _ShortName As String 'Megnevezés
    Private _Description As String 'Leírás
    Private _NumberGenerator As NumberGenerator 'Sorszám generátor
    Private _ReportData As ReportData
    Private _RegistryType As RegistryType 'Iktatás tipus kiválasztása számlás bevételezés esetán !!!

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        ImportMode = eImportMode.eInternalwithVAT
        IsPrice = True
        IsOrderOut = True
    End Sub
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    Property ImportMode As eImportMode
        Get
            Return _ImportMode
        End Get
        Set(value As eImportMode)
            SetPropertyValue("ImportMode", _ImportMode, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRequiredField("DeliveryNoteInType.IsPrice", DefaultContexts.Save)> _
    Property IsPrice As Boolean
        Get
            Return _IsPrice
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsPrice", _IsPrice, value)
        End Set
    End Property
    Property IsOrderOut As Boolean
        Get
            Return _IsOrderOut
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsOrderOut", _IsOrderOut, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteInType.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
    <RuleRequiredField("DeliveryNoteInType.NumberGenerator", DefaultContexts.Save)> _
    Property NumberGenerator As NumberGenerator
        Get
            Return _NumberGenerator
        End Get
        Set(value As NumberGenerator)
            SetPropertyValue("NumberGenerator", _NumberGenerator, value)
        End Set
    End Property
    Property ReportData As ReportData
        Get
            Return _ReportData
        End Get
        Set(value As ReportData)
            SetPropertyValue("ReportData", _ReportData, value)
        End Set
    End Property
    <DataSourceProperty("RegistryTypeCollection")> _
    <RuleRequiredField("DeliveryNoteInType-RegistryType", DefaultContexts.Save, targetcriteria:="IsPrice=True")> _
    Property RegistryType As RegistryType
        Get
            Return _RegistryType
        End Get
        Set(value As RegistryType)
            SetPropertyValue("RegistryType", _RegistryType, value)
        End Set
    End Property
    <Browsable(False)> _
    ReadOnly Property RegistryTypeCollection As XPCollection(Of RegistryType)
        Get
            Dim _RegistryTypeReturnCollection As XPCollection(Of RegistryType) = Nothing
            Dim _RegistryType_Collection As New XPCollection(Of RegistryType)(Session, CriteriaOperator.Parse("RegistryMainType=0 and CustomersFrom=?", CustomersFrom))
            Dim Ok As Boolean = False
            If _RegistryType_Collection.Count > 0 Then
                Dim _Filter As String = "Oid in("

                For Each _RegistryType As RegistryType In _RegistryType_Collection
                    For Each _WorkflowSystemSteps As WorkflowSystemSteps In _RegistryType.WorkflowSystem.WorkflowSystemSteps
                        If _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckVATPlusControlling Or _
                            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckVAT Then
                            _Filter += "'" + _RegistryType.Oid.ToString + "',"
                            Ok = True
                            Exit For
                        End If
                    Next

                Next
                _Filter = _Filter.Remove(_Filter.Length - 1, 1)
                _Filter += ")"
                If Ok Then
                    _RegistryTypeReturnCollection = New XPCollection(Of RegistryType)(Session, CriteriaOperator.Parse(_Filter))
                Else

                End If
            End If

                Return _RegistryTypeReturnCollection
        End Get
    End Property
End Class


