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

'<Appearance("Disable ContractRows-CurrencyName when IsNull(CurrencyName)=False", AppearanceItemType.ViewItem, "IsNull(CurrencyName)=False", TargetItems:="CurrencyName", Enabled:=False)> _
'<EditorStateRule("Hide DEV when DEV is HUF", "NettoPriceDEV;CurrencyRate", EditorState.Hidden, "CurrencyName.ShortName='HUF'", ViewType.DetailView)> _
'<EditorStateRule("Hide MileStone when DEV ContractRowsType<>1", "MileStone", EditorState.Hidden, "ContractRowsType<>1", ViewType.DetailView)> _
'<EditorStateRule("Disable edit when invoicerow not nothing", _
'    "MileStone;DateExecution;Controlling;UniqueObjects;ShortName;Description;QTT;Units;NettoPriceHUF;NettoPriceDEV;CurrencyName;CurrencyRate;PaymentOption;ShipmentOption;QualityOption;VAT;ContractRowsType;CostHolder;CostPlace;InvoicePeriod", _
'    EditorState.Disabled, "IsNull(InvoiceRows)=False", DevExpress.ExpressApp.ViewType.Any)> _

<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide DEV when DEV is HUF", TargetItems:="NettoPriceDEV;CurrencyRate", Criteria:="CurrencyName.ShortName='HUF'", Visibility:=Editors.ViewItemVisibility.Hide, Context:="DetailView")> _
<Appearance("Hide MileStone when DEV ContractRowsType<>1", TargetItems:="MileStone", Criteria:="ContractRowsType<>1", Visibility:=Editors.ViewItemVisibility.Hide, Context:="DetailView")> _
<Appearance("Disable edit when invoicerow not nothing", _
    TargetItems:="MileStone;DateExecution;Controlling;UniqueObjects;ShortName;Description;QTT;Units;NettoPriceHUF;NettoPriceDEV;CurrencyName;CurrencyRate;PaymentOption;ShipmentOption;QualityOption;VAT;ContractRowsType;CostHolder;CostPlace;InvoicePeriod", _
    Criteria:="IsNull(InvoiceRows)=False", Enabled:=False, Context:="Any")>
<Appearance("Disable delete and modifications if Controlled Or Invoiced", AppearanceItemType:="Action", TargetItems:="Delete,aDivideContractRows,aMergeContractRows", Enabled:=False, Criteria:="IsNull(RegistryRowsFinancialControlling)=False OR IsNull(InvoiceRows)=False OR IsNull(InvoiceRowsAdvance)=False", Context:="Any")> _
<Appearance("Disable open coc if not certificated", AppearanceItemType:="Action", TargetItems:="aOpenCOCFromContractRows", Enabled:=False, Criteria:="IsNull(CertificateofContractRows)", Context:="Any")> _
<Appearance("Disable open invoice if not invoiced", AppearanceItemType:="Action", TargetItems:="aOpenInvoiceFromContractRows", Enabled:=False, Criteria:="IsNull(InvoiceRows)", Context:="Any")> _
<Appearance("Disable open registry invoice if not controlled", AppearanceItemType:="Action", TargetItems:="aOpenRegistryInvoiceFromContractRows", Enabled:=False, Criteria:="IsNull(RegistryRowsFinancialControlling)", Context:="Any")> _
<Appearance("Status in rows in PartnerType=0", AppearanceItemType:="ViewItem", TargetItems:="eContractRowsCOCState;eContractRowsRRFCState", Enabled:=False, Criteria:="Contracts.ContractTemplate.PartnerType=0", Context:="Any")> _
<Appearance("Status in rows in PartnerType=1", AppearanceItemType:="ViewItem", TargetItems:="eContractRowsInvoiceState", Enabled:=False, Criteria:="Contracts.ContractTemplate.PartnerType=1", Context:="Any")> _
<Appearance("Disable ContractRows-RowGroup1, RowGroup2 when Contracts.ContractTemplate.IsCRM=False", AppearanceItemType.ViewItem, "Contracts.ContractTemplate.IsCRM=False", TargetItems:="RowGroup1;RowGroup2", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable ContractRows-ShipmentOption, QualityOption when Contracts.ContractTemplate.IsCRM=False", AppearanceItemType.ViewItem, "Contracts.ContractTemplate.IsCRM=False", TargetItems:="ShipmentOption;QualityOption", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable ContractRows-InvoiceRows;eContractRowsInvoiceState;InvoiceRowsAdvance;CustomsTariffs when Contracts.ContractTemplate.PartnerType=1", AppearanceItemType.ViewItem, "Contracts.ContractTemplate.PartnerType=1", TargetItems:="InvoiceRows;eContractRowsInvoiceState;InvoiceRowsAdvance;CustomsTariffs", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable ContractRows-eContractRowsCOCState;eContractRowsRRFCState; when Contracts.ContractTemplate.PartnerType=0", AppearanceItemType.ViewItem, "Contracts.ContractTemplate.PartnerType=0", TargetItems:="eContractRowsCOCState;eContractRowsRRFCState", visibility:=Editors.ViewItemVisibility.Hide)> _
<DefaultProperty("DisplayName")> _
<RuleCriteria("RuleCriteria ContactRows-Controlling", DefaultContexts.Save, _
    "(Controlling.IsParent=False) or (Contracts.ContractTemplate.Rule5DMatrix.RequireControlling=False and isnull(Controlling)=True) or (IsNull(Contracts.ContractTemplate.Rule5DMatrix)=True)", _
    "Gyüjtő kontrollszám nem választható ki!", SkipNullOrEmptyValues:=False)> _
Public Class ContractRows 'Szerződési sorok
    Inherits BaseObject
    Private _Contracts As Contracts '-- Szerződés fejléc
    Private _MileStone As ContractMileStone '-- Mérföldkő
    Private _DateExecution As Date '-- Teljesítési dátum
    Private _ShortName As String '-- Megnevezés
    Private _Description As String '-- Leírás
    Private _QTT As Double '-- Mennyiség
    Private _Units As Units '-- Mennyiségi egység
    Private _NettoPriceHUF As Double '-- Nettó egységár (HUF)
    Private _NettoPriceDEV As Double '-- Nettó egységár (DEV)

    Private _SumNettoPriceHUF As Double '-- Nettó sorérték (HUF)
    Private _SumNettoPriceDEV As Double '-- Nettó sorérték (DEV)
    Private _SumBruttoPriceHUF As Double '-- Nettó sorérték (HUF)
    Private _SumBruttoPriceDEV As Double '-- Nettó sorérték (DEV)

    Private _CurrencyName As CurrencyName '-- Deviza
    Private _CurrencyRate As Double = 1 '-- Árfolyam
    Private _PaymentOption As PaymentOption '--Fizetési opció
    Private _ShipmentOption As ShipmentOption '-- Szállítási opció
    Private _QualityOption As QualityOption '-- Minőségi opció
    Private _VAT As VAT 'ÁFA kód
    Private _InvoiceRows As InvoiceRows '-- Milyen soron lett kiszámlázva<NonCloneable()> _
    Private _InvoiceRowsAdvance As InvoiceRows ' --Ez a szerződés sor, ha ki van állítva számlán akkor milyen számlán lett visszaminuszolva.<NonCloneable()> _
    Private _ContractRowsType As eContractRowsType ' -- A szerződés sorának a típusa
    '-- Jelölő adatok -------------------------------------------------------------------------------
    Private _Controlling As Controlling '-- Controlling szám
    Private _CostHolder As CostHolder ' -- Költségviselő
    Private _CostPlace As CostPlace '-- Költséghely
    Private _JobNumberObjects As JobNumberObjects '-- Projekt amihez a sor tartozik
    Private _UniqueObjects As UniqueObjects ' -- Egyedi azonosító
    '------------------------------------------------------------------------------------------------
    Private _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling ' -- Iktatási teljesítésre bontás sora (le van e teljesítési igazolva a sor)<NonCloneable()> _
    Private _RowGroup1 As String
    Private _RowGroup2 As String
    Private _CustomsTariffs As CustomsTariffs
    Private _InvoicePeriod As String 'Számlázási időszak
    Private _CertificateofContractRows As CertificateofContractRows '<NonCloneable()> _
    Private _eContractRowsInvoiceState As eContractRowsInvoiceState 'Ki van-e számlázva az aktuális sor?<NonCloneable()> _
    Private _eContractRowsCOCState As eContractRowsCOCState 'Le van-e teljesítési igazolva az aktuális sor?<NonCloneable()> _
    Private _eContractRowsRRFCState As eContractRowsRRFCState 'Le van-e számla igazolva az aktuális sor?<NonCloneable()> _
    Private _ImmovablesCostRecordEvents As ImmovablesCostRecordEvents

    Private _Apartments As Apartments '-- Lakás
    Private _Garages As Garages '-- Garázs
    Private _Container As Container '-- Tároló
    Private _Offices As Offices '-- Üzletek
    Private _XLSGuid As String ' XLS sorban lévő saját guid

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Units = Session.FindObject(Of Units)(1, CriteriaOperator.Parse("ShortName='DB'"))
        QTT = 1
        CurrencyName = Session.FindObject(Of CurrencyName)(PersistentCriteriaEvaluationBehavior.InTransaction, Session.ParseCriteria("ShortName='HUF'"))
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If VAT Is Nothing Then
            SumNettoPriceHUF = Math.Round(QTT * NettoPriceHUF, 0, MidpointRounding.AwayFromZero)
            SumBruttoPriceHUF = SumNettoPriceHUF
            SumNettoPriceDEV = Math.Round(QTT * NettoPriceDEV, 2, MidpointRounding.AwayFromZero)
            SumBruttoPriceDEV = SumNettoPriceDEV
        Else
            SumNettoPriceHUF = Math.Round(QTT * NettoPriceHUF, 0, MidpointRounding.AwayFromZero)
            SumBruttoPriceHUF = Math.Round(SumNettoPriceHUF * (1 + VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
            SumNettoPriceDEV = Math.Round(QTT * NettoPriceDEV, 2, MidpointRounding.AwayFromZero)
            SumBruttoPriceDEV = Math.Round(SumNettoPriceDEV * (1 + VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
        End If
    End Sub
    <Association("Contracts-ContractRows", GetType(Contracts))> _
    Property Contracts() As Contracts
        Get
            Return _Contracts
        End Get
        Set(ByVal value As Contracts)
            SetPropertyValue("Contracts", _Contracts, value)
        End Set
    End Property
    <RuleRequiredField("ContractRows-MileStone", DefaultContexts.Save, TargetCriteria:="ContractRowsType=1")> _
    Property MileStone As ContractMileStone
        Get
            Return _MileStone
        End Get
        Set(ByVal value As ContractMileStone)
            SetPropertyValue("MileStone", _MileStone, value)
        End Set
    End Property
    <RuleRequiredField("ContactRows-DateExecution", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.IsProducts=False and ContractRowsType<>1")> _
    Property DateExecution() As Date
        Get
            Return _DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    ' <ImmediatePostData(True), DataSourceCriteria("Controlling.Controllingdirection=-1 AND Contracts.ContractTemplate.PartnerType=0")> _
    <RuleRequiredField("ContactRows-ShortName", DefaultContexts.Save)> _
    Property ShortName() As String
        Get
            Return _ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    Property QTT() As Double
        Get
            Return _QTT
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("QTT", _QTT, value)
        End Set
    End Property
    <RuleRequiredField("ContractRows_Units", DefaultContexts.Save)> _
    Property Units() As Units
        Get
            Return _Units
        End Get
        Set(ByVal value As Units)
            SetPropertyValue("Units", _Units, value)
        End Set
    End Property
    <RuleRequiredField("ContractRows_NettoPriceHUF", DefaultContexts.Save, TargetCriteria:="CurrencyName.ShortName='HUF'")> _
    Property NettoPriceHUF() As Double
        Get
            Return _NettoPriceHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("NettoPriceHUF", _NettoPriceHUF, value)
        End Set
    End Property
    <RuleRequiredField("ContractRows_NettoPriceDEV", DefaultContexts.Save, TargetCriteria:="CurrencyName.ShortName<>'HUF'")> _
    Property NettoPriceDEV() As Double
        Get
            Return _NettoPriceDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("NettoPriceDEV", _NettoPriceDEV, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                If CurrencyName IsNot Nothing Then
                    If CurrencyName.ShortName <> "HUF" Then
                        NettoPriceHUF = Math.Round(CurrencyRate * value, 0, MidpointRounding.AwayFromZero)
                    End If
                End If
            End If
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property SumNettoPriceHUF As Double
        Get
            Return _SumNettoPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SumNettoPriceHUF", _SumNettoPriceHUF, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property SumNettoPriceDEV As Double
        Get
            Return _SumNettoPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SumNettoPriceDEV", _SumNettoPriceDEV, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property SumBruttoPriceHUF As Double
        Get
            Return _SumBruttoPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SumBruttoPriceHUF", _SumBruttoPriceHUF, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property SumBruttoPriceDEV As Double
        Get
            Return _SumBruttoPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SumBruttoPriceDEV", _SumBruttoPriceDEV, value)
        End Set
    End Property
    <ImmediatePostData(True)> _
    Property CurrencyName() As CurrencyName
        Get
            Return _CurrencyName
        End Get
        Set(ByVal value As CurrencyName)
            SetPropertyValue("CurrencyName", _CurrencyName, value)
        End Set
    End Property
    '<RuleValueComparison("ContractRows-CurrencyRate <>1", DefaultContexts.Save, ValueComparisonType.NotEquals, 1, TargetCriteria:="CurrencyName.ShortName<>'HUF'")> _
    <RuleValueComparison("ContractRows-CurrencyRate 0<", DefaultContexts.Save, ValueComparisonType.GreaterThan, 0, TargetCriteria:="CurrencyName.ShortName<>'HUF'")> _
    Property CurrencyRate As Double
        Get
            Return _CurrencyRate
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("CurrencyRate", _CurrencyRate, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                If CurrencyName IsNot Nothing Then
                    If CurrencyName.ShortName <> "HUF" Then
                        NettoPriceHUF = Math.Round(NettoPriceDEV * value, 0, MidpointRounding.AwayFromZero)
                    End If
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("ContractRows.PaymentOptions", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.PartnerType = 0")> _
    Property PaymentOption() As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(ByVal value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
        End Set
    End Property
    Property ShipmentOption() As ShipmentOption
        Get
            Return _ShipmentOption
        End Get
        Set(ByVal value As ShipmentOption)
            SetPropertyValue("ShipmentOption", _ShipmentOption, value)
        End Set
    End Property
    Property QualityOption() As QualityOption
        Get
            Return _QualityOption
        End Get
        Set(ByVal value As QualityOption)
            SetPropertyValue("QualityOption", _QualityOption, value)
        End Set
    End Property
    <RuleRequiredField("VAT is required if ContractsTemplate receiveables", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.PartnerType=0")> _
    Property VAT As VAT
        Get
            Return _VAT
        End Get
        Set(ByVal value As VAT)
            SetPropertyValue("VAT", _VAT, value)
        End Set
    End Property
    <NonCloneable()> _
    Property InvoiceRows As InvoiceRows
        Get
            Return _InvoiceRows
        End Get
        Set(ByVal value As InvoiceRows)
            SetPropertyValue("InvoiceRows", _InvoiceRows, value)
        End Set
    End Property
    <NonCloneable()> _
    Property InvoiceRowsAdvance As InvoiceRows
        Get
            Return _InvoiceRowsAdvance
        End Get
        Set(ByVal value As InvoiceRows)
            SetPropertyValue("InvoiceRowsAdvance", _InvoiceRowsAdvance, value)
        End Set
    End Property
    <ImmediatePostData(True)> _
    Property ContractRowsType As eContractRowsType
        Get
            Return _ContractRowsType
        End Get
        Set(ByVal value As eContractRowsType)
            SetPropertyValue("ContractRowsType", _ContractRowsType, value)
        End Set
    End Property
    Property InvoicePeriod As String
        Get
            Return _InvoicePeriod
        End Get
        Set(value As String)
            SetPropertyValue("InvoicePeriod", _InvoicePeriod, value)
        End Set
    End Property
    <Browsable(False)> _
    Property ImmovablesCostRecordEvents As ImmovablesCostRecordEvents
        Get
            Return _ImmovablesCostRecordEvents
        End Get
        Set(value As ImmovablesCostRecordEvents)
            SetPropertyValue("ImmovablesCostRecordEvents", _ImmovablesCostRecordEvents, value)
        End Set
    End Property

    'Rule5DMatrix ! ---------------------------------
    <RuleRequiredField("ContactRows-Controlling", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.Rule5DMatrix.RequireControlling=True")> _
    Property Controlling() As Controlling
        Get
            Return _Controlling
        End Get
        Set(ByVal value As Controlling)
            SetPropertyValue("Controlling", _Controlling, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And Me.RegistryRowsFinancialControlling IsNot Nothing Then
                If Me.RegistryRowsFinancialControlling.Controlling IsNot value Then
                    _RegistryRowsFinancialControlling.Controlling = value
                    _RegistryRowsFinancialControlling.Save()
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("ContactRows-CostHolder", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.Rule5DMatrix.RequireCostHolder=True")> _
    Property CostHolder As CostHolder
        Get
            Return _CostHolder
        End Get
        Set(ByVal value As CostHolder)
            SetPropertyValue("CostHolder", _CostHolder, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And Me.RegistryRowsFinancialControlling IsNot Nothing Then
                If Me.RegistryRowsFinancialControlling.CostHolder IsNot value Then
                    Me.RegistryRowsFinancialControlling.CostHolder = value
                    Me.RegistryRowsFinancialControlling.Save()
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("ContactRows-CostPlace", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.Rule5DMatrix.RequireCostPlace=True")> _
    Property CostPlace As CostPlace
        Get
            Return _CostPlace
        End Get
        Set(ByVal value As CostPlace)
            SetPropertyValue("CostPlace", _CostPlace, value)
        End Set
    End Property
    <RuleRequiredField("ContactRows-JobNumberObjects", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.Rule5DMatrix.RequireJobNumberObjects=True")> _
    Property JobNumberObjects As JobNumberObjects
        Get
            Return _JobNumberObjects
        End Get
        Set(ByVal value As JobNumberObjects)
            SetPropertyValue("JobNumberObjects", _JobNumberObjects, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And Me.RegistryRowsFinancialControlling IsNot Nothing Then
                If Me.RegistryRowsFinancialControlling.JobNumberObjects IsNot value Then
                    Me.RegistryRowsFinancialControlling.JobNumberObjects = value
                    Me.RegistryRowsFinancialControlling.Save()
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("ContactRows-UniqueObjects", DefaultContexts.Save, TargetCriteria:="Contracts.ContractTemplate.Rule5DMatrix.RequireUniqueObjects=True")> _
    Property UniqueObjects As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(ByVal value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And Me.RegistryRowsFinancialControlling IsNot Nothing Then
                If Me.RegistryRowsFinancialControlling.UniqueObjects IsNot value Then
                    _RegistryRowsFinancialControlling.UniqueObjects = value
                    _RegistryRowsFinancialControlling.Save()
                End If
            End If
        End Set
    End Property

    <NonCloneable()> _
    Property RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Get
            Return _RegistryRowsFinancialControlling
        End Get
        Set(ByVal value As RegistryRowsFinancialControlling)
            SetPropertyValue("RegistryRowsFinancialControlling", _RegistryRowsFinancialControlling, value)
        End Set
    End Property
    Property RowGroup1 As String
        Get
            Return _RowGroup1
        End Get
        Set(ByVal value As String)
            SetPropertyValue("RowGroup1", _RowGroup1, value)
        End Set
    End Property
    Property RowGroup2 As String
        Get
            Return _RowGroup2
        End Get
        Set(ByVal value As String)
            SetPropertyValue("RowGroup2", _RowGroup2, 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
    <NonCloneable()> _
    Property CertificateofContractRows As CertificateofContractRows
        Get
            Return _CertificateofContractRows
        End Get
        Set(value As CertificateofContractRows)
            SetPropertyValue("CertificateofContractRows", _CertificateofContractRows, value)
        End Set
    End Property
    'Readonly
    ReadOnly Property DisplayName() As String
        Get
            If Me.Contracts Is Nothing Then
                Return ShortName & ", " & DateExecution
            ElseIf Me.Contracts.Customers Is Nothing Then
                Return Contracts.DocumentNumber & ", " & ShortName & ", " & DateExecution
            Else
                Return Contracts.DocumentNumber & ", " & ShortName & ", " & DateExecution & ", " & Contracts.Customers.FullName
            End If
        End Get
    End Property
    ReadOnly Property eContractRowsCOCState As eContractRowsCOCState
        Get
            If Me.CertificateofContractRows IsNot Nothing Then
                Return [Module].eContractRowsCOCState.eCertificated
            Else
                Return [Module].eContractRowsCOCState.eNotCertificated
            End If
        End Get
    End Property
    ReadOnly Property eContractRowsInvoiceState As eContractRowsInvoiceState
        Get
            If Me.InvoiceRows IsNot Nothing Or Me.InvoiceRowsAdvance IsNot Nothing Then
                Return [Module].eContractRowsInvoiceState.eInvoiced
            Else
                Return [Module].eContractRowsInvoiceState.eNotInvoiced
            End If
        End Get
    End Property
    ReadOnly Property eContractRowsRRFCState As eContractRowsRRFCState
        Get
            If Me.RegistryRowsFinancialControlling IsNot Nothing Then
                Return [Module].eContractRowsRRFCState.eControlled
            Else
                Return [Module].eContractRowsRRFCState.eNotControlled
            End If
        End Get
    End Property

    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property Apartments As Apartments
        Get
            Return _Apartments
        End Get
        Set(value As Apartments)
            SetPropertyValue("Apartments", _Apartments, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property Garages As Garages
        Get
            Return _Garages
        End Get
        Set(value As Garages)
            SetPropertyValue("Garages", _Garages, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property Container As Container
        Get
            Return _Container
        End Get
        Set(value As Container)
            SetPropertyValue("Container", _Container, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property Offices As Offices
        Get
            Return _Offices
        End Get
        Set(value As Offices)
            SetPropertyValue("Offices", _Offices, value)
        End Set
    End Property
    <Browsable(False)> _
    Property XLSGuid As String
        Get
            Return _XLSGuid
        End Get
        Set(value As String)
            SetPropertyValue("XLSGuid", _XLSGuid, value)
        End Set
    End Property
End Class
