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.SystemModule
Imports DevExpress.Persistent.Base.Security

Imports DevExpress.ExpressApp.ConditionalAppearance
Imports DevExpress.ExpressApp.Filtering

'<EditorStateRule("Hide COC when PartnerType=0", "COC_ReportHeader;COC_ReportFooter;COC_ReportData;COC_NumberGenerator", EditorState.Hidden, "PartnerType=0", ViewType.DetailView)> _
'<EditorStateRule("Hide InvoiceType when PartnerType=1", "InvoiceType;InvoiceTypeAdvanced;InvoiceTypeCustomRate", EditorState.Hidden, "PartnerType=1", ViewType.DetailView)> _
'<Appearance("Hide ContractTemplate-IsCRM;IsProducts;IsImmovables when PartnerType=1", AppearanceItemType.ViewItem, "PartnerType=1", TargetItems:="IsCRM;IsProducts;IsImmovables", visibility:=Editors.ViewItemVisibility.Hide)> _

<DefaultClassOptions()> _
<NavigationItem("Contracts")> _
<Appearance("Hide COC when PartnerType=0", TargetItems:="COC_ReportHeader;COC_ReportFooter;COC_ReportData;COC_NumberGenerator", Criteria:="PartnerType=0", Visibility:=Editors.ViewItemVisibility.Hide, Context:="DetailView")> _
<Appearance("Hide InvoiceType when PartnerType=1", TargetItems:="InvoiceType;InvoiceTypeAdvanced;InvoiceTypeCustomRate", Criteria:="PartnerType=1", Visibility:=Editors.ViewItemVisibility.Hide, Context:="DetailView")> _
<Appearance("Disable ContractTemplate-PartnerType when PartnerType<>-1", AppearanceItemType.ViewItem, "PartnerType<>-1", TargetItems:="PartnerType", Enabled:=False)> _
<Appearance("Disable ContractTemplate-CustomersFrom when IsNull(CustomersFrom)=False", AppearanceItemType.ViewItem, "IsNull(CustomersFrom)=False", TargetItems:="CustomersFrom", Enabled:=False)> _
<Appearance("Hide ContractTemplate-IsTechnical when PartnerType=0", AppearanceItemType.ViewItem, "PartnerType=0", TargetItems:="IsTechnical", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide ContractTemplate-Controlling when IsProducts=False", AppearanceItemType.ViewItem, "IsProducts=False", TargetItems:="Controlling", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class ContractTemplate 'Szerzõdési sablonok
    Inherits BaseObject
    Private _CustomersFrom As CustomersFrom
    Private _ShortName As String 'Megnevezés
    Private _CreatedBy As User ' Ki csinálta a szerzõdési sablont
    Private _PartnerType As ePartnerType = -1 'Szállítói vagy vevõi a szerzõdés
    Private _DocumentBody As String 'Dokumentum törzs
    Private _NumberGenerator As NumberGenerator 'Sorszám generálása
    Private _COC_ReportHeader As String 'Teljesítési igazolás fejléc sablon
    Private _COC_ReportFooter As String 'Teljesítési igazolás lábléc sablon
    Private _COC_ReportData As ReportData 'Teljesítési igazolás nyomtatvány
    Private _COC_NumberGenerator As NumberGenerator 'Teljesítési igazolás szigorú sorszáma
    Private _InvoiceType As InvoiceType 'Ha vevõi a szerzõdés akkor milyen a kimenõ számla tipusa
    Private _InvoiceTypeAdvanced As InvoiceType 'Ha vevõi a szerzõdés akkor milyen az elõleg vagy foglaló számla tipusa
    Private _InvoiceTypeCustomRate As InvoiceType 'Egyéb bekérõ dijakhoz számla szerû dolgok
    Private _IsTechnical As Boolean = False 'Technikai szerződés
    Private _IsCRM As Boolean = False 'CRM tipusú szerződés
    Private _IsProducts As Boolean = False 'Termékes FIFO szerződési sor
    Private _IsImmovables As Boolean = False 'Ingatlanos szerződési tipus
    Private _IsAPCSheet As Boolean 'Mezőgazdasági termeltéshez kapcsolódó sablon
    Private _Rule5DMatrix As Rule5DMatrix
    Private _Controlling As Controlling
    Private _ContractsProperties As String
    Private _APCSheetByProductsProperties As String
    Private _ReportData As ReportData 'Szerződés nyomtatvány, amit ki lehet nyomtatni.

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        If Not SecuritySystem.CurrentUser Is Nothing Then
            Dim currentUser As User = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
            _CreatedBy = currentUser
        End If
        IsCRM = False
        IsProducts = False
        IsTechnical = False
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Not IsDeleted Then
            If Me.IsTechnical = True Then
                Dim _ContractTemplate As ContractTemplate = Session.FindObject(Of ContractTemplate)(CriteriaOperator.Parse("IsTechnical=? AND CustomersFrom=?", True, Me.CustomersFrom))
                If _ContractTemplate IsNot Nothing Then
                    If _ContractTemplate.Oid.ToString() <> Me.Oid.ToString() Then
                        '---------------------------TESZT MIATT---------------------------------------->>>
                        Throw New Exception("*Adott saját céghez csak egy technikai szerzõdés sablon tartozhat!")
                        '---------------------------TESZT MIATT----------------------------------------<<<
                    End If
                End If
            End If
        End If
    End Sub
    <RuleRequiredField("RuleRequiredField for CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(ByVal value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("RuleRequiredField for ContratctTemplate.ShortName", DefaultContexts.Save)> _
    Public Property ShortName() As String
        Get
            Return _ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property

    Public Property CreatedBy() As User
        Get
            Return _CreatedBy
        End Get
        Set(ByVal value As User)
            SetPropertyValue("CreatedBy", _CreatedBy, value)
        End Set
    End Property
    <ImmediatePostData(True)> _
    <RuleValueComparison("ContractTemplate-ePartnerType <>-1", DefaultContexts.Save, ValueComparisonType.NotEquals, ePartnerType.eNotSet)> _
    Property PartnerType() As ePartnerType
        Get
            Return _PartnerType
        End Get
        Set(ByVal value As ePartnerType)
            SetPropertyValue("PartnerType", _PartnerType, value)
        End Set
    End Property
    <Size(-1)> _
    Property DocumentBody() As String
        Get
            Return _DocumentBody
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentBody", _DocumentBody, value)
        End Set
    End Property
    <RuleRequiredField("ContractTemplate-NumberGenerator", DefaultContexts.Save)> _
    Property NumberGenerator As NumberGenerator
        Get
            Return _NumberGenerator
        End Get
        Set(ByVal value As NumberGenerator)
            SetPropertyValue("NumberGenerator", _NumberGenerator, value)
        End Set
    End Property
    <Size(-1)> _
    Property COC_ReportHeader As String
        Get
            Return _COC_ReportHeader
        End Get
        Set(ByVal value As String)
            SetPropertyValue("COC_ReportHeader", _COC_ReportHeader, value)
        End Set
    End Property
    <Size(-1)> _
    Property COC_ReportFooter As String
        Get
            Return _COC_ReportFooter
        End Get
        Set(ByVal value As String)
            SetPropertyValue("COC_ReportFooter", _COC_ReportFooter, value)
        End Set
    End Property
    Property COC_ReportData As ReportData
        Get
            Return _COC_ReportData
        End Get
        Set(ByVal value As ReportData)
            SetPropertyValue("COC_ReportData", _COC_ReportData, value)
        End Set
    End Property
    Property COC_NumberGenerator As NumberGenerator
        Get
            Return _COC_NumberGenerator
        End Get
        Set(ByVal value As NumberGenerator)
            SetPropertyValue("COC_NumberGenerator", _COC_NumberGenerator, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceType", DefaultContexts.Save, targetcriteria:="PartnerType=0")> _
    Property InvoiceType As InvoiceType
        Get
            Return _InvoiceType
        End Get
        Set(ByVal value As InvoiceType)
            SetPropertyValue("InvoiceType", _InvoiceType, value)
        End Set
    End Property
    Property InvoiceTypeAdvanced As InvoiceType
        Get
            Return _InvoiceTypeAdvanced
        End Get
        Set(ByVal value As InvoiceType)
            SetPropertyValue("InvoiceTypeAdvanced", _InvoiceTypeAdvanced, value)
        End Set
    End Property
    Property InvoiceTypeCustomRate As InvoiceType
        Get
            Return _InvoiceTypeCustomRate
        End Get
        Set(ByVal value As InvoiceType)
            SetPropertyValue("InvoiceTypeCustomRate", _InvoiceTypeCustomRate, value)
        End Set
    End Property
    Property IsTechnical As Boolean
        Get
            Return _IsTechnical
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsTechnical", _IsTechnical, value)
        End Set
    End Property
    Property IsCRM As Boolean
        Get
            Return _IsCRM
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsCRM", _IsCRM, value)
        End Set
    End Property
    Property IsImmovables As Boolean
        Get
            Return _IsImmovables
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsImmovables", _IsImmovables, value)
        End Set
    End Property
    Property IsAPCSheet As Boolean
        Get
            Return _IsAPCSheet
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsAPCSheet", _IsAPCSheet, value)
        End Set
    End Property
    Property Rule5DMatrix As Rule5DMatrix
        Get
            Return _Rule5DMatrix
        End Get
        Set(value As Rule5DMatrix)
            SetPropertyValue("Rule5DMatrix", _Rule5DMatrix, value)
        End Set
    End Property
    Property IsProducts As Boolean
        Get
            Return _IsProducts
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsProducts", _IsProducts, value)
        End Set
    End Property
    Property Controlling As Controlling
        Get
            Return _Controlling
        End Get
        Set(value As Controlling)
            SetPropertyValue("Controlling", _Controlling, value)
        End Set
    End Property
    <NonPersistent()> _
    <VisibleInLookupListView(False)> _
    <VisibleInListView(False)> _
    Property ContractsProperties As String
        Get
            Return _ContractsProperties
        End Get
        Set(value As String)
            SetPropertyValue("ContractsProperties", _ContractsProperties, value)
        End Set
    End Property
    <NonPersistent()> _
    <VisibleInLookupListView(False)> _
    <VisibleInListView(False)> _
    Property APCSheetByProductsProperties As String
        Get
            Return _APCSheetByProductsProperties
        End Get
        Set(value As String)
            SetPropertyValue("APCSheetByProductsProperties", _APCSheetByProductsProperties, 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
End Class
