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

'-- Paraméterek, enumok
<DefaultClassOptions()>
<NavigationItem("RealEstateTransactions")> _
<CreatableItem(False)> _
<DefaultProperty("CRMEstate_Leads")> _
Public Class CRMEstate_Leads_Immovables
    Inherits BaseObject
    Private _CRMEstate_Leads As CRMEstate_Leads
    Private _Immovables As Immovables

    Private _VAT As VAT
    Private _AreaPriceDivide As Double '%-ban a telek és felépítmény ár
    Private _ParcelPriceNettoHUF As Double 'Telek netto ár
    Private _SuperstructurePriceNettoHUF As Double 'Felépítmény ár
    Private _ParcelPriceNettoDEV As Double 'Telek netto ár
    Private _SuperstructurePriceNettoDEV As Double 'Felépítmény ár

    'Értékesítési árak
    Private _ListPriceBruttoDEV As Double
    Private _ListPriceBruttoHUF As Double
    Private _ListPriceNettoDEV As Double
    Private _ListPriceNettoHUF As Double
    '--

    'Bérlési árak
    Private _ListPriceBruttoDEVRent As Double
    Private _ListPriceBruttoHUFRent As Double
    Private _ListPriceNettoDEVRent As Double
    Private _ListPriceNettoHUFRent As Double
    '--

    ' Értékesítési nm árak
    Private _AreaListPriceBruttoDEV As Double
    Private _AreaListPriceBruttoHUF As Double
    Private _AreaListPriceNettoDEV As Double
    Private _AreaListPriceNettoHUF As Double
    '--

    'Bérleti nm árak
    Private _AreaListPriceBruttoDEVRent As Double
    Private _AreaListPriceBruttoHUFRent As Double
    Private _AreaListPriceNettoDEVRent As Double
    Private _AreaListPriceNettoHUFRent As Double

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
        ' This constructor is used when an object is loaded from a persistent storage.
        ' Do not place any code here or place it only when the IsLoading property is false:
        ' if (!IsLoading){
        '   It is now OK to place your initialization code here.
        ' }
        ' or as an alternative, move your initialization code into the AfterConstruction method.
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.AreaPriceDivide = 30

    End Sub
    <Association("CRMEstate_Leads-CRMEstate_Leads_Immovables", GetType(CRMEstate_Leads))> _
    Property CRMEstate_Leads As CRMEstate_Leads
        Get
            Return _CRMEstate_Leads
        End Get
        Set(value As CRMEstate_Leads)
            SetPropertyValue("CRMEstate_Leads", _CRMEstate_Leads, value)
        End Set
    End Property
    Property Immovables As Immovables
        Get
            Return _Immovables
        End Get
        Set(value As Immovables)
            SetPropertyValue("Immovables", _Immovables, value)
        End Set
    End Property
    <ImmediatePostData()> _
    Property VAT As VAT
        Get
            Return _VAT
        End Get
        Set(value As VAT)
            SetPropertyValue("VAT", _VAT, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.ListPriceBruttoHUF = Math.Round((1 + value.KeyValue) * ListPriceNettoHUF, 0, MidpointRounding.AwayFromZero)
                Me.ListPriceBruttoHUFRent = Math.Round((1 + value.KeyValue) * ListPriceNettoHUFRent, 0, MidpointRounding.AwayFromZero)
            End If
        End Set
    End Property
    <ImmediatePostData()> _
    Property AreaPriceDivide As Double
        Get
            Return _AreaPriceDivide
        End Get
        Set(value As Double)
            SetPropertyValue("AreaPriceDivide", _AreaPriceDivide, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.ParcelPriceNettoHUF = Math.Round((Me.ListPriceNettoHUF * (value / 100)), 0, MidpointRounding.AwayFromZero)
                Me.SuperstructurePriceNettoHUF = Me.ListPriceNettoHUF - Me.ParcelPriceNettoHUF
            End If
        End Set
    End Property
    Property ParcelPriceNettoHUF As Double
        Get
            Return _ParcelPriceNettoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("ParcelPriceNettoHUF", _ParcelPriceNettoHUF, value)
        End Set
    End Property
    Property SuperstructurePriceNettoHUF As Double
        Get
            Return _SuperstructurePriceNettoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SuperstructurePriceNettoHUF", _SuperstructurePriceNettoHUF, value)
        End Set
    End Property
    Property ParcelPriceNettoDEV As Double
        Get
            Return _ParcelPriceNettoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("ParcelPriceNettoDEV", _ParcelPriceNettoDEV, value)
        End Set
    End Property
    Property SuperstructurePriceNettoDEV As Double
        Get
            Return _SuperstructurePriceNettoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SuperstructurePriceNettoDEV", _SuperstructurePriceNettoDEV, value)
        End Set
    End Property


    'Értékesítési árak
    Property ListPriceBruttoDEV As Double
        Get
            Return _ListPriceBruttoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceBruttoDEV", _ListPriceBruttoDEV, value)
        End Set
    End Property
    Property ListPriceBruttoHUF As Double
        Get
            Return _ListPriceBruttoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceBruttoHUF", _ListPriceBruttoHUF, value)
        End Set
    End Property
    Property ListPriceNettoDEV As Double
        Get
            Return _ListPriceNettoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceNettoDEV", _ListPriceNettoDEV, value)
        End Set
    End Property
    Property ListPriceNettoHUF As Double
        Get
            Return _ListPriceNettoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceNettoHUF", _ListPriceNettoHUF, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                Me.ListPriceBruttoHUF = Math.Round(value * (1 + Me.VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
                Me.ParcelPriceNettoHUF = Math.Round(value * (AreaPriceDivide / 100), 0, MidpointRounding.AwayFromZero)
                Me.SuperstructurePriceNettoHUF = Math.Round(value - Me.ParcelPriceNettoHUF, 0, MidpointRounding.AwayFromZero)
                If TryCast(Me.Immovables, Apartments) IsNot Nothing Then
                    Me.AreaListPriceNettoHUF = Math.Round(value / TryCast(Me.Immovables, Apartments).AreaNettoForSale, 0, MidpointRounding.AwayFromZero)
                    Me.AreaListPriceBruttoHUF = Math.Round(Me.AreaListPriceNettoHUF * (1 + Me.VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
                End If
                If TryCast(Me.Immovables, Offices) IsNot Nothing Then
                    Me.AreaListPriceNettoHUF = Math.Round(value / TryCast(Me.Immovables, Offices).AreaNettoForSale, 0, MidpointRounding.AwayFromZero)
                    Me.AreaListPriceBruttoHUF = Math.Round(Me.AreaListPriceNettoHUF * (1 + Me.VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
                End If
                If TryCast(Me.Immovables, Container) IsNot Nothing Then
                    Me.AreaListPriceNettoHUF = Math.Round(value / TryCast(Me.Immovables, Container).AreaNetto, 0, MidpointRounding.AwayFromZero)
                    Me.AreaListPriceBruttoHUF = Math.Round(Me.AreaListPriceNettoHUF * (1 + Me.VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
                End If
                If TryCast(Me.Immovables, Garages) IsNot Nothing Then
                    Me.AreaListPriceNettoHUF = Math.Round(value / TryCast(Me.Immovables, Garages).AreaNetto, 0, MidpointRounding.AwayFromZero)
                    Me.AreaListPriceBruttoHUF = Math.Round(Me.AreaListPriceNettoHUF * (1 + Me.VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
                End If
            End If
        End Set
    End Property
    '--

    'Bérlési árak
    Property ListPriceBruttoDEVRent As Double
        Get
            Return _ListPriceBruttoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceBruttoDEVRent", _ListPriceBruttoDEVRent, value)
        End Set
    End Property
    Property ListPriceBruttoHUFRent As Double
        Get
            Return _ListPriceBruttoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceBruttoHUFRent", _ListPriceBruttoHUFRent, value)
        End Set
    End Property
    Property ListPriceNettoDEVRent As Double
        Get
            Return _ListPriceNettoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceNettoDEVRent", _ListPriceNettoDEVRent, value)
        End Set
    End Property
    Property ListPriceNettoHUFRent As Double
        Get
            Return _ListPriceNettoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("ListPriceNettoHUFRent", _ListPriceNettoHUFRent, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                ListPriceBruttoHUFRent = Math.Round(value * (1 + Me.VAT.KeyValue), 0, MidpointRounding.AwayFromZero)
            End If
        End Set
    End Property
    '--

    ' Értékesítési nm árak
    Property AreaListPriceBruttoDEV As Double
        Get
            Return _AreaListPriceBruttoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceBruttoDEV", _AreaListPriceBruttoDEV, value)
        End Set
    End Property
    Property AreaListPriceBruttoHUF As Double
        Get
            Return _AreaListPriceBruttoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceBruttoHUF", _AreaListPriceBruttoHUF, value)
        End Set
    End Property
    Property AreaListPriceNettoDEV As Double
        Get
            Return _AreaListPriceNettoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceNettoDEV", _AreaListPriceNettoDEV, value)
        End Set
    End Property
    Property AreaListPriceNettoHUF As Double
        Get
            Return _AreaListPriceNettoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceNettoHUF", _AreaListPriceNettoHUF, value)
        End Set
    End Property
    '--

    'Bérleti nm árak
    Property AreaListPriceBruttoDEVRent As Double
        Get
            Return _AreaListPriceBruttoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceBruttoDEVRent", _AreaListPriceBruttoDEVRent, value)
        End Set
    End Property
    Property AreaListPriceBruttoHUFRent As Double
        Get
            Return _AreaListPriceBruttoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceBruttoHUFRent", _AreaListPriceBruttoHUFRent, value)
        End Set
    End Property
    Property AreaListPriceNettoDEVRent As Double
        Get
            Return _AreaListPriceNettoDEVRent
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceNettoDEVRent", _AreaListPriceNettoDEVRent, value)
        End Set
    End Property
    Property AreaListPriceNettoHUFRent As Double
        Get
            Return _AreaListPriceNettoHUFRent
        End Get
        Set(value As Double)
            SetPropertyValue("AreaListPriceNettoHUFRent", _AreaListPriceNettoHUFRent, value)
        End Set
    End Property

    '---------ReadOnly properties--------------------
    <VisibleInListView(False)> _
    <Association("CRMEstate_Leads_Immovables-CRMEstate_Leads_Immovables_Reservation", GetType(CRMEstate_Leads_Immovables_Reservation))> _
    ReadOnly Property CRMEstate_Leads_Immovables_Reservation As XPCollection(Of CRMEstate_Leads_Immovables_Reservation)
        Get
            Return GetCollection(Of CRMEstate_Leads_Immovables_Reservation)("CRMEstate_Leads_Immovables_Reservation")
        End Get
    End Property
End Class


