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("CRMEstate_Opportunity_Payment_Forecast Hide HUF If currencyname != HUF", AppearanceItemType:="LayoutItem", Criteria:="CurrencyName.ShortName != 'HUF'", Context:="Any", TargetItems:="SumPriceNettoHUF;SumPriceVATHUF;SumPriceBruttoHUF", Visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("CRMEstate_Opportunity_Payment_Forecast Hide DEV If currencyname = HUF", AppearanceItemType:="LayoutItem", Criteria:="CurrencyName.ShortName = 'HUF'", Context:="Any", TargetItems:="SumPriceNettoDEV;SumPriceVATDEV;SumPriceBruttoDEV", Visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("CRMEstate_Opportunity_Payment_Forecast disable some porperties", AppearanceItemType.ViewItem, "1=1", TargetItems:="SumPriceVATHUF;SumPriceVATDEV;SumPriceBruttoHUF;SumPriceBruttoDEV", Enabled:=False)> _
Public Class CRMEstate_Opportunity_Payment_Forecast
    Inherits BaseObject
    Private _CRMEstate_Opportunity_Immovables As CRMEstate_Opportunity_Immovables
    Private _CustomersFrom As CustomersFrom 'Saját cég
    Private _RowIndex As Long 'Sor index
    Private _MileStonePayment As eMileStonePayment 'Mérföldkő
    Private _InvoiceTypeBase As eInvoiceTypeBase 'Számla bázis tipusa
    Private _CurrencyName As CurrencyName 'Deviza
    Private _DateExecution As Date 'A pénzügyi teljesülés dátuma
    Private _Description As String
    Private _SumPriceNettoHUF As Double 'Netto HUF
    Private _SumPriceVATHUF As Double 'ÁFA HUF
    Private _SumPriceBruttoHUF As Double 'Bruttó HUF
    Private _SumPriceNettoDEV As Double 'Netto DEV
    Private _SumPriceVATDEV As Double 'ÁFA DEV
    Private _SumPriceBruttoDEV As Double 'Brutto DEV
    Private _SumPricePercent As Double 'Vételár %-os
    Private _ContractRows As ContractRows

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.SumPricePercent = 100
    End Sub
    <Association("CRMEstate_Opportunity_Immovables-CRMEstate_Opportunity_Payment_Forecast", _
    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)
        End Set
    End Property
    <RuleRequiredField("CRMEstate_Opportunity_Payment_Forecast.CustomersFrom", DefaultContexts.Save)> _
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("CRMEstate_Opportunity_Payment_Forecast.RowIndex", DefaultContexts.Save)> _
    Property RowIndex As Long
        Get
            Return _RowIndex
        End Get
        Set(value As Long)
            SetPropertyValue("RowIndex", _RowIndex, value)
        End Set
    End Property
    Property MileStonePayment As eMileStonePayment
        Get
            Return _MileStonePayment
        End Get
        Set(value As eMileStonePayment)
            SetPropertyValue("MileStonePayment", _MileStonePayment, value)
        End Set
    End Property

    Property InvoiceTypeBase As eInvoiceTypeBase
        Get
            Return _InvoiceTypeBase
        End Get
        Set(value As eInvoiceTypeBase)
            SetPropertyValue("InvoiceTypeBase", _InvoiceTypeBase, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRequiredField("CRMEstate_Opportunity_Payment_Forecast.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 DateExecution As Date
        Get
            Return _DateExecution
        End Get
        Set(value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRange("CRMEstate_Opportunity_Payment_Forecast.SumPriceNettoHUF", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName = 'HUF'")> _
    Property SumPriceNettoHUF As Double
        Get
            Return _SumPriceNettoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceNettoHUF", _SumPriceNettoHUF, value)

            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                If Not Me.SumPriceBruttoHUF = value + Me.SumPriceVATHUF Then
                    Me.SumPriceVATHUF = Math.Round((value * (Me.ImmovablesGroupsParameters.VAT.KeyValuePercent / 100)), 0, MidpointRounding.AwayFromZero)
                    Me.SumPriceBruttoHUF = value + Me.SumPriceVATHUF

                End If
            End If
        End Set
    End Property
    <RuleRange("CRMEstate_Opportunity_Payment_Forecast.SumPriceVATHUF", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName = 'HUF'")> _
    Property SumPriceVATHUF As Double
        Get
            Return _SumPriceVATHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceVATHUF", _SumPriceVATHUF, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRange("CRMEstate_Opportunity_Payment_Forecast.SumPriceBruttoHUF", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName = 'HUF'")> _
    Property SumPriceBruttoHUF As Double
        Get
            Return _SumPriceBruttoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceBruttoHUF", _SumPriceBruttoHUF, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                If Not Me.SumPriceNettoHUF = value - Me.SumPriceVATHUF Then
                    Me.SumPriceVATHUF = Math.Round((value / (100 + Me.ImmovablesGroupsParameters.VAT.KeyValuePercent) * Me.ImmovablesGroupsParameters.VAT.KeyValuePercent), 0, MidpointRounding.AwayFromZero)
                    Me.SumPriceNettoHUF = value - Me.SumPriceVATHUF
                End If
            End If
        End Set
    End Property
    <RuleRange("CRMEstate_Opportunity_Payment_Forecast.SumPriceNettoDEV", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName != 'HUF'")> _
    Property SumPriceNettoDEV As Double
        Get
            Return _SumPriceNettoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceNettoDEV", _SumPriceNettoDEV, value)
        End Set
    End Property
    <RuleRange("CRMEstate_Opportunity_Payment_Forecast.SumPriceVATDEV", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName != 'HUF'")> _
    Property SumPriceVATDEV As Double
        Get
            Return _SumPriceVATDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceVATDEV", _SumPriceVATDEV, value)
        End Set
    End Property
    <RuleRange("CRMEstate_Opportunity_Payment_Forecast.SumPriceBruttoDEV", DefaultContexts.Save, 0.1, Int64.MaxValue, TargetCriteria:="CurrencyName.ShortName != 'HUF'")> _
    Property SumPriceBruttoDEV As Double
        Get
            Return _SumPriceBruttoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceBruttoDEV", _SumPriceBruttoDEV, value)
        End Set
    End Property
    Property SumPricePercent As Double
        Get
            Return _SumPricePercent
        End Get
        Set(value As Double)
            SetPropertyValue("SumPricePercent", _SumPricePercent, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.SumPriceBruttoHUF = Me.SumPriceBruttoHUF * (value / 100)
            End If
        End Set
    End Property
    Property ContractRows As ContractRows
        Get
            Return _ContractRows
        End Get
        Set(value As ContractRows)
            SetPropertyValue("ContractRows", _ContractRows, value)
        End Set
    End Property

    '----------ReadOnly--------------------
    <Browsable(False)> _
    ReadOnly Property ImmovablesGroupsParameters As ImmovablesGroupsParameters
        Get
            If Me.CRMEstate_Opportunity_Immovables IsNot Nothing Then
                Dim _ImmovablesGroupsParameters As ImmovablesGroupsParameters = Session.FindObject(Of ImmovablesGroupsParameters)(CriteriaOperator.Parse("ImmovablesGroups=?", _CRMEstate_Opportunity_Immovables.CRMEstate_Leads_Immovables.Immovables.ImmovableGroups))
                Return _ImmovablesGroupsParameters
            Else
                Return Nothing
            End If
        End Get
    End Property

End Class



