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()> _
<NonPersistent()> _
<NavigationItem(False), CreatableItem(False)> _
<Appearance("Disable CreateInvoiceFromWorksheetCost_PopUp-CurrencyRate, when WorkSheet_Header.CurrencyName.ShortName=HUF ", AppearanceItemType.ViewItem, " WorkSheet_Header.CurrencyName.ShortName='HUF'", TargetItems:="CurrencyRate", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable CreateInvoiceFromWorksheetCost_PopUp-BankInformation, when PaymentOption.PayMode=0 ", AppearanceItemType.ViewItem, "PaymentOption.PayMode=0", TargetItems:="BankInformation", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class CreateInvoiceFromWorksheetCost_PopUp
    Inherits BaseObject

    Private _Customers As Customers
    Private _InvoiceType As InvoiceType
    Private _InvoicePeriod As String 'Számlázási időszak string
    Private _Description As String
    Private _DescriptionHeader As String 'Számlán szereplő  fejléc megjegyzés
    Private _DateExecution As Date 'Teljesítés dátuma
    Private _DatePayment As Date 'Fizetési határidő
    Private _PaymentOption As PaymentOption
    Private _CurrencyRate As Double
    Private _BankInformation As BankInformation
    Private _WorkSheet_Header As WorkSheet_Header

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        DatePayment = GetSQLTime(Session)
    End Sub

    Property Customers() As Customers
        Get
            Return _Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("CustomersFrom='@This.WorkSheet_Header.CustomersFrom' and InvoiceTypeBase in (2,3)")>
    Property InvoiceType() As InvoiceType
        Get
            Return _InvoiceType
        End Get
        Set(ByVal value As InvoiceType)
            SetPropertyValue("InvoiceType", _InvoiceType, 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
    <Size(-1)>
    Property Description As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    <Size(-1)>
    Property DescriptionHeader As String
        Get
            Return _DescriptionHeader
        End Get
        Set(value As String)
            SetPropertyValue("DescriptionHeader", _DescriptionHeader, value)
        End Set
    End Property
    Property DateExecution() As Date
        Get
            Return _DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
        End Set
    End Property
    Property DatePayment() As Date
        Get
            Return _DatePayment
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DatePayment", _DatePayment, value)
        End Set
    End Property
    <ImmediatePostData()>
    Property PaymentOption As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If value.PayMode = ePayMode.InCash Then
                    Me.DateExecution = GetSQLTime(Session)
                    Me.DatePayment = GetSQLTime(Session)
                ElseIf value.PayMode = ePayMode.InContinuous Then
                    Me.DateExecution = Me.DatePayment
                ElseIf value.PayMode = ePayMode.InTransfer Then
                    Me.DatePayment = DateAdd(DateInterval.Day, value.PayDay, GetSQLTime(Session))
                End If
            End If
        End Set
    End Property
    '<RuleRange("InvoiceHeader-CurrencyRate-aToTable", "aToTable_Invoice_Contexts", 1, Double.MaxValue, TargetCriteria:="CurrencyName.ShortName<>'HUF'")> _
    '<RuleRange("CreateInvoiceFromWorksheetCost_PopUp-CurrencyRate", DefaultContexts.Save, 1, Double.MaxValue, TargetCriteria:="WorkSheet_Header.CurrencyName.ShortName <> 'HUF'")> _
    Property CurrencyRate() As Double
        Get
            Return _CurrencyRate
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("CurrencyRate", _CurrencyRate, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("LiquidAssests.CustomerFrom = '@This.WorkSheet_Header.CustomersFrom'")>
    Property BankInformation As BankInformation
        Get
            Return _BankInformation
        End Get
        Set(ByVal value As BankInformation)
            SetPropertyValue("CustomerBankAccounts", _BankInformation, value)
        End Set
    End Property
    <VisibleInListView(False)> _
    <VisibleInDetailView(False)> _
    Property WorkSheet_Header As WorkSheet_Header
        Get
            Return _WorkSheet_Header
        End Get
        Set(value As WorkSheet_Header)
            SetPropertyValue("WorkSheet_Header", _WorkSheet_Header, value)
        End Set
    End Property

    '--------------ReadOnly-------------
    'ReadOnly Property Worksheet_CostRows As XPCollection(Of Worksheet_CostRows)
    '    Get  'Dim _OrderOutRows As OrderOutRows
    '        Dim _Worksheet_CostRows_Collection As XPCollection(Of Worksheet_CostRows)

    '        _Worksheet_CostRows_Collection = New XPCollection(Of Worksheet_CostRows)(Session, CriteriaOperator.Parse("WorkSheet_Header.Oid=? AND IsNull(InvoiceRows)=True", Me.WorkSheet_Header.Oid))
    '        Return _Worksheet_CostRows_Collection
    '    End Get
    'End Property
End Class
