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

'<EditorStateRuleAttribute("Disable all properties whenStatus=Completed", "RegistryHeader;HRPerson;CurrentWorkflowSystemSteps", EditorState.Disabled, "Status=4", ViewType.DetailView)> _

<DefaultClassOptions()> _
<NavigationItem("FinancialTransactions")> _
<Appearance("Disable all properties whenStatus=Completed",
                   TargetItems:="RegistryHeader;HRPerson;CurrentWorkflowSystemSteps",
                   Criteria:="Status=4",
                   Enabled:=False,
                   Context:="DetailView")> _
<Appearance("Hide financial infos2 when RegistryHeader.RegistryType.RegistryMainType in (1,3,4,5)",
                  AppearanceItemType:="LayoutItem", _
                  criteria:="RegistryHeader.RegistryType.RegistryMainType in (1,3,4,5)",
                  TargetItems:="RegistryRowsFinancial;RegistryRowsFinancialControlling",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RRFC infos row_* RegistryTask",
                  AppearanceItemType:="ViewItem",
                  criteria:="(RegistryHeader.IsEditable=True) or (RegistryHeader.RegistryType.RegistryMainType in (1,3,4,5)) or " + _
                            "(RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType in (0,1,3,4,5))", _
                  TargetItems:="row_RRFC_ReInvoiceMode;row_RRFC_ReInvoice_Customers;row_RRFC_ReInvoiceReason;row_RRFC_IsReInvoice;row_RRFC_File;" + _
                               "row_RRFC_JobNumberObjects;row_RRFC_UniqueObjects;row_RRFC_Controlling;row_RRFC_CostPlace;row_RRFC_CostHolder;" + _
                               "row_RRFC_Note;row_RRFC_Amount;row_RRFC_ContractRows;row_RRFC_Contracts",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RRFC infos Action RegistryTask",
                  AppearanceItemType:="Action",
                  criteria:="(RegistryHeader.IsEditable=True) or (RegistryHeader.RegistryType.RegistryMainType in (1,3,4,5)) or " +
                            "(RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType in (0,1,3,4,5))", _
                  TargetItems:="aToTable_RRFC_RegistryTask;aToTableD_RRFC_RegistryTask;aToTable_RRFC_With_TContract_RegistryTask;" +
                               "aToTable_RRFC_With_RContract_RegistryTask;aPaymentCertificates;aImport_RRFC",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide ReInvoice info",
                  AppearanceItemType:="ViewItem",
                  targetitems:="row_RRFC_ReInvoiceReason;row_RRFC_ReInvoice_Customers;row_RRFC_ReInvoiceMode",
                  criteria:="row_RRFC_IsReInvoice=False",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RRF and RRFC when Invoice Advance Ask LayoutItem",
                  AppearanceItemType:="LayoutItem",
                  targetitems:="RegistryRowsFinancial;RegistryRowsFinancialControlling",
                  criteria:="RegistryHeader.RegistryType.RegistryMainType=3",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RRF and RRFC when Invoice Advance Ask Actions",
                  AppearanceItemType:="Action",
                  targetitems:="aToTable_RRFC_RegistryTask;aToTableD_RRFC_RegistryTask;aToTable_RRFC_With_TContract_RegistryTask;" + _
                               "aToTable_RRFC_With_RContract_RegistryTask;aPaymentCertificates;aImport_RRFC",
                  criteria:="RegistryHeader.RegistryType.RegistryMainType=3",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RRFC aPaymentCertificates Action",
                  AppearanceItemType:="Action",
                  criteria:="isnull(row_RRFC_Controlling)=True",
                  TargetItems:="aPaymentCertificates",
                  visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Disable ObjectCreatedRegistry all",
                AppearanceItemType:="ViewItem",
                   TargetItems:="ObjectCreatedRegistry",
                   Criteria:="1=1",
                   Enabled:=False)> _
Public Class RegistryTasks '-- Registryhez task a feladatokhoz
    Inherits Task
    Private _RegistryHeader As RegistryHeader 'Iktatás fejléce
    Private _HRPerson As HRPerson 'Felelős
    Private _CurrentWorkflowSystemSteps As WorkflowSystemSteps 'A feladat kiadásakor hol állt a rendszer


    '// Nonpersistent propertyk a számlaigazoláshoz

    Private _row_RRFC_Controlling As Controlling
    Private _row_RRFC_CostPlace As CostPlace
    Private _row_RRFC_CostHolder As CostHolder
    Private _row_RRFC_Note As String
    Private _row_RRFC_Amount As Double
    Private _row_RRFC_Contracts As Contracts
    Private _row_RRFC_ContractRows As ContractRows
    Private _row_RRFC_UniqueObjects As UniqueObjects
    Private _row_RRFC_JobNumberObjects As JobNumberObjects
    Private _row_RRFC_File As FileData
    Private _row_RRFC_IsReInvoice As Boolean = False
    Private _row_RRFC_ReInvoiceReason As Controlling
    Private _row_RRFC_ReInvoice_Customers As Customers
    Private _row_RRFC_ReInvoiceMode As eReinvoiceMode
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Property RegistryHeader As RegistryHeader
        Get
            Return _RegistryHeader
        End Get
        Set(ByVal value As RegistryHeader)
            SetPropertyValue("RegistryHeader", _RegistryHeader, value)

        End Set
    End Property
    Property HRPerson As HRPerson
        Get
            Return _HRPerson
        End Get
        Set(ByVal value As HRPerson)
            SetPropertyValue("HRPerson", _HRPerson, value)
        End Set
    End Property
    Property CurrentWorkflowSystemSteps As WorkflowSystemSteps
        Get
            Return _CurrentWorkflowSystemSteps
        End Get
        Set(ByVal value As WorkflowSystemSteps)
            SetPropertyValue("CurrentWorkflowSystemSteps", _CurrentWorkflowSystemSteps, value)
        End Set
    End Property
    ReadOnly Property CustomersFrom As CustomersFrom
        Get
            If Me.RegistryHeader IsNot Nothing Then
                Return Me.RegistryHeader.CustomersFrom
            Else
                Return Nothing
            End If
        End Get
    End Property
    ReadOnly Property Customers As Customers
        Get
            If Me.RegistryHeader IsNot Nothing Then
                Return Me.RegistryHeader.Customers
            Else
                Return Nothing
            End If
        End Get
    End Property

    '// Nonpersistent propertyk RRFC igazoláshoz 
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False), ImmediatePostData(True)> _
    <RuleRequiredField("RegistryTask-row_RRFC_Controlling", "aToTable_RRFC_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireControlling")> _
    <RuleRequiredField("RegistryTask-row_RRFC_Controlling_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireControlling")> _
    Property row_RRFC_Controlling As Controlling
        Get
            Return _row_RRFC_Controlling
        End Get
        Set(value As Controlling)
            SetPropertyValue("row_RRFC_Controlling", _row_RRFC_Controlling, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_CostPlace", "aToTable_RRFC_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireCostPlace")> _
    <RuleRequiredField("RegistryTask-row_RRFC_CostPlace_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireCostPlace")> _
    Property row_RRFC_CostPlace As CostPlace
        Get
            Return _row_RRFC_CostPlace
        End Get
        Set(value As CostPlace)
            SetPropertyValue("row_RRFC_CostPlace", _row_RRFC_CostPlace, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_CostHolder", "aToTable_RRFC_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireCostHolder")> _
    <RuleRequiredField("RegistryTask-row_RRFC_CostHolder_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireCostHolder")> _
    Property row_RRFC_CostHolder As CostHolder
        Get
            Return _row_RRFC_CostHolder
        End Get
        Set(value As CostHolder)
            SetPropertyValue("row_RRFC_CostHolder", _row_RRFC_CostHolder, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property row_RRFC_Note As String
        Get
            Return _row_RRFC_Note
        End Get
        Set(value As String)
            SetPropertyValue("row_RRFC_Note", _row_RRFC_Note, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property row_RRFC_Amount As Double
        Get
            Return _row_RRFC_Amount
        End Get
        Set(value As Double)
            SetPropertyValue("row_RRFC_Amount", _row_RRFC_Amount, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <DataSourceCriteria("(State = 1 OR State = 2) and ContractTemplate.PartnerType=1 and ContractTemplate.IsTechnical=False and CurrencyName.ShortName='@This.RegistryHeader.F_CurrencyName.ShortName' and CustomersFrom='@This.RegistryHeader.CustomersFrom' and Customers='@This.RegistryHeader.Customers'")> _
    Property row_RRFC_Contracts As Contracts
        Get
            Return _row_RRFC_Contracts
        End Get
        Set(value As Contracts)
            SetPropertyValue("row_RRFC_Contracts", _row_RRFC_Contracts, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_RegistryTask_ContractRows", "aToTable_RRFC_RegistryTask_Contexts")> _
    <DataSourceCriteria("(Contracts.State = 1 OR Contracts.State = 2) and Contracts.ContractTemplate.PartnerType=1 and Contracts.ContractTemplate.IsTechnical=False and IsNull(RegistryRowsFinancialControlling)=True and CurrencyName.ShortName='@This.RegistryHeader.F_CurrencyName.ShortName' and Contracts.CustomersFrom='@This.RegistryHeader.CustomersFrom' and Contracts.Customers='@This.RegistryHeader.Customers'")> _
    <ImmediatePostData()> _
    Property row_RRFC_ContractRows As ContractRows
        Get
            Return _row_RRFC_ContractRows
        End Get
        Set(value As ContractRows)
            SetPropertyValue("row_RRFC_ContractRows", _row_RRFC_ContractRows, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If value IsNot Nothing Then

                    row_RRFC_Controlling = value.Controlling
                    row_RRFC_Note = value.Description
                    row_RRFC_CostHolder = value.CostHolder
                    row_RRFC_CostPlace = value.CostPlace
                    row_RRFC_JobNumberObjects = value.JobNumberObjects
                    row_RRFC_UniqueObjects = value.UniqueObjects

                    If Me.RegistryHeader.F_CurrencyName.ShortName <> "HUF" Then
                        row_RRFC_Amount = Math.Round(value.NettoPriceDEV * Me.RegistryHeader.F_CurrencyRate, 0, MidpointRounding.AwayFromZero)
                    Else
                        Me.row_RRFC_Amount = value.NettoPriceHUF
                    End If
                End If
            End If
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_JobNumberObjects", "aToTable_RRFC_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireJobNumberObjects")> _
    <RuleRequiredField("RegistryTask-row_RRFC_JobNumberObjects_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireJobNumberObjects")> _
    Property row_RRFC_JobNumberObjects As JobNumberObjects
        Get
            Return _row_RRFC_JobNumberObjects
        End Get
        Set(value As JobNumberObjects)
            SetPropertyValue("row_RRFC_JobNumberObjects", _row_RRFC_JobNumberObjects, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_UniqueObjects", "aToTable_RRFC_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireUniqueObjects")> _
    <RuleRequiredField("RegistryTask-row_RRFC_UniqueObjects_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", targetcriteria:="RegistryHeader.RegistryType.Rule5DMatrix.RequireUniqueObjects")> _
    Property row_RRFC_UniqueObjects As UniqueObjects
        Get
            Return _row_RRFC_UniqueObjects
        End Get
        Set(value As UniqueObjects)
            SetPropertyValue("row_RRFC_UniqueObjects", _row_RRFC_UniqueObjects, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    Property row_RRFC_File As FileData
        Get
            Return _row_RRFC_File
        End Get
        Set(value As FileData)
            SetPropertyValue("row_RRFC_File", _row_RRFC_File, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <ImmediatePostData()> _
    Property row_RRFC_IsReInvoice As Boolean
        Get
            Return _row_RRFC_IsReInvoice
        End Get
        Set(value As Boolean)
            SetPropertyValue("row_RRFC_IsReInvoice", _row_RRFC_IsReInvoice, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_ReInvoiceReason", "aToTable_RRFC_RegistryTask_Contexts", TargetCriteria:="row_RRFC_IsReInvoice=True AND row_RRFC_ReInvoiceMode=1")> _
    <RuleRequiredField("RegistryTask-row_RRFC_ReInvoiceReason_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", TargetCriteria:="row_RRFC_IsReInvoice=True AND row_RRFC_ReInvoiceMode=1")> _
    <RuleRequiredField("RegistryTask-row_RRFC_ReInvoiceReason_R", "aToTable_RRFC_With_RContract_RegistryTask_Contexts", TargetCriteria:="row_RRFC_IsReInvoice=True AND row_RRFC_ReInvoiceMode=1")> _
    <DataSourceCriteria("Controllingdirection = 0 And IsReInvoiceReason = True")> _
    Property row_RRFC_ReInvoiceReason As Controlling
        Get
            Return _row_RRFC_ReInvoiceReason
        End Get
        Set(value As Controlling)
            SetPropertyValue("row_RRFC_ReInvoiceReason", _row_RRFC_ReInvoiceReason, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <RuleRequiredField("RegistryTask-row_RRFC_ReInvoice_Customers", "aToTable_RRFC_RegistryTask_Contexts", TargetCriteria:="row_RRFC_IsReInvoice=True AND row_RRFC_ReInvoiceMode=1")> _
    <RuleRequiredField("RegistryTask-row_RRFC_ReInvoice_Customers_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", TargetCriteria:="row_RRFC_IsReInvoice=True AND row_RRFC_ReInvoiceMode=1")> _
    <RuleRequiredField("RegistryTask-row_RRFC_ReInvoice_Customers_R", "aToTable_RRFC_With_RContract_RegistryTask_Contexts", TargetCriteria:="row_RRFC_IsReInvoice=True AND row_RRFC_ReInvoiceMode=1")> _
    Property row_RRFC_ReInvoice_Customers As Customers
        Get
            Return _row_RRFC_ReInvoice_Customers
        End Get
        Set(value As Customers)
            SetPropertyValue("row_RRFC_ReInvoice_Customers", _row_RRFC_ReInvoice_Customers, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)> _
    <ImmediatePostData(True)> _
    <RuleValueComparison("RegistryTask-row_RRFC_ReInvoiceMode", "aToTable_RRFC_RegistryTask_Contexts", ValueComparisonType.NotEquals, eReinvoiceMode.eNotSet, TargetCriteria:="row_RRFC_IsReInvoice = True")> _
    <RuleValueComparison("RegistryTask-row_RRFC_ReInvoiceMode_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", ValueComparisonType.NotEquals, eReinvoiceMode.eNotSet, TargetCriteria:="row_RRFC_IsReInvoice = True")> _
    <RuleValueComparison("RegistryTask-row_RRFC_ReInvoiceMode_R", "aToTable_RRFC_With_RContract_RegistryTask_Contexts", ValueComparisonType.NotEquals, eReinvoiceMode.eNotSet, TargetCriteria:="row_RRFC_IsReInvoice = True")> _
    Property row_RRFC_ReInvoiceMode As eReinvoiceMode
        Get
            Return _row_RRFC_ReInvoiceMode
        End Get
        Set(value As eReinvoiceMode)
            SetPropertyValue("row_RRFC_ReInvoiceMode", _row_RRFC_ReInvoiceMode, value)
        End Set
    End Property

    '---------------- Readonly property -------------------------------------------------
    <VisibleInListView(False)> _
    ReadOnly Property FileData_Collection As XPCollection(Of RegistryFileData)
        Get
            If Me.RegistryHeader Is Nothing Then
                Return Nothing
            Else
                Return Me.RegistryHeader.RegistryFileData
            End If

        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property RegistryRowsFinancial As XPCollection(Of RegistryRowsFinancial)
        Get
            Return New XPCollection(Of RegistryRowsFinancial)(Session, CriteriaOperator.Parse("RegistryHeader=?", RegistryHeader))
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property RegistryRowsFinancialControlling As XPCollection(Of RegistryRowsFinancialControlling)
        Get
            Return New XPCollection(Of RegistryRowsFinancialControlling)(Session, CriteriaOperator.Parse("RegistryHeader=?", RegistryHeader))
        End Get
    End Property

End Class

