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

<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide HUF If currencyname != HUF", AppearanceItemType:="LayoutItem", Criteria:="CurrencyName.ShortName != 'HUF'", Context:="Any", TargetItems:="AmountHUF", Visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide DEV If currencyname = HUF", AppearanceItemType:="LayoutItem", Criteria:="CurrencyName.ShortName = 'HUF'", Context:="Any", TargetItems:="AmountDEV", Visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class CRMEstate_Opportunity_AdvanceMoney
    Inherits BaseObject
    Private _CRMEstate_Opportunity_Immovables As CRMEstate_Opportunity_Immovables
    Private _CustomersFrom As CustomersFrom
    Private _Customers As Customers
    Private _DocumentNumber As String 'Dokumentum sorszáma (nyomtatáshoz kell)
    Private _DateCreated As Date 'Káll. dátuma
    Private _DateExpiration As Date 'Lejárat dátuma
    Private _AmountHUF As Double 'Összeg (HUF)
    Private _AmountDEV As Double 'Összeg (DEV)
    Private _CurrencyName As CurrencyName 'Deviza
    Private _Active As Boolean = False
    Private _ContractRows As ContractRows 'Számla fejléc (ha készült róla)
    Private _PaymentOption As PaymentOption 'A kiállítandó számla fizetési opciója
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.CurrencyName = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'"))
        Me.PaymentOption = Session.FindObject(Of PaymentOption)(CriteriaOperator.Parse("PayMode=0"))
    End Sub
    <Association("CRMEstate_Opportunity_Immovables-CRMEstate_Opportunity_AdvanceMoney", GetType(CRMEstate_Opportunity_Immovables))> _
    Property CRMEstate_Opportunity_Immovables As CRMEstate_Opportunity_Immovables
        Get
            Return _CRMEstate_Opportunity_Immovables
        End Get
        Set(value As CRMEstate_Opportunity_Immovables)
            SetPropertyValue("CRMEstate_Opportunity_Immovables", _CRMEstate_Opportunity_Immovables, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving And value IsNot Nothing Then
                Me.CustomersFrom = TryCast(value.CRMEstate_Leads_Immovables.Immovables.CustomersOwner, CustomersFrom)
            End If
        End Set
    End Property
    <RuleRequiredField("CRMEstate_Opportunity_AdvanceMoney.Customers", DefaultContexts.Save)> _
    Property Customers As Customers
        Get
            Return _Customers
        End Get
        Set(value As Customers)
            SetPropertyValue("CustomersFrom", _Customers, value)
        End Set
    End Property
    <RuleRequiredField("CRMEstate_Opportunity_AdvanceMoney.CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <NonCloneable()> _
    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRequiredField("CRMEstate_Opportunity_AdvanceMoney.DateCreated", DefaultContexts.Save)> _
    Property DateCreated As Date
        Get
            Return _DateCreated
        End Get
        Set(value As Date)
            SetPropertyValue("DateCreated", _DateCreated, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.DateExpiration = value.AddDays(14)
            End If
        End Set
    End Property
    <RuleRequiredField("CRMEstate_Opportunity_AdvanceMoney.DateExpiration", DefaultContexts.Save)> _
    Property DateExpiration As Date
        Get
            Return _DateExpiration
        End Get
        Set(value As Date)
            SetPropertyValue("DateExpiration", _DateExpiration, value)
        End Set
    End Property
    <RuleRange("CRMEstate_Opportunity_AdvanceMoney.AmountHUF", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName = 'HUF'")> _
    Property AmountHUF As Double
        Get
            Return _AmountHUF
        End Get
        Set(value As Double)
            SetPropertyValue("AmountHUF", _AmountHUF, value)
        End Set
    End Property
    <RuleRange("CRMEstate_Opportunity_AdvanceMoney.AmountDEV", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName != 'HUF'")> _
    Property AmountDEV As Double
        Get
            Return _AmountDEV
        End Get
        Set(value As Double)
            SetPropertyValue("AmountDEV", _AmountDEV, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRequiredField("CRMEstate_Opportunity_AdvanceMoney.CurrencyName", DefaultContexts.Save)> _
    Property CurrencyName As CurrencyName
        Get
            Return _CurrencyName
        End Get
        Set(value As CurrencyName)
            SetPropertyValue("CurrencyName", _CurrencyName, value)
        End Set
    End Property
    Property Active As Boolean
        Get
            Return _Active
        End Get
        Set(value As Boolean)
            SetPropertyValue("Active", _Active, value)
        End Set
    End Property
    Property ContractRows As ContractRows
        Get
            Return _ContractRows
        End Get
        Set(ByVal value As ContractRows)
            SetPropertyValue("InvoiceHeader", _ContractRows, value)
        End Set
    End Property
    <RuleRequiredField("CRMEstate_Opportunity_AdvanceMoney.PaymentOption", DefaultContexts.Save)> _
    Property PaymentOption As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(ByVal value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
        End Set
    End Property
End Class
