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("GLRowsDivideH-row_AmountDEV disable", targetitems:="row_AmountDEV;AmountDiffDEV", criteria:="GLRowsBase.GLHeader.CurrencyName.ShortName='HUF'", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("GLRowsDivideH-row_CashType disable", targetitems:="row_ChartOfAccounts", criteria:="row_CashType=0", visibility:=Editors.ViewItemVisibility.Hide)> _
<RuleCriteria("RuleCriteria GLRowsDivideH-row_Controlling.IsParent=False", "aToTable_GLRowsDivide", "row_Controlling.IsParent=False", _
              "Csak gyermek objektum választható ki!", SkipNullOrEmptyValues:=False, targetcriteria:="row_PartnerType=-1")> _
<Appearance("GLRowsDivideH-hide if not GLMixed", "ViewItem", targetitems:="row_DebitChartOfAccounts;row_CreditChartOfAccounts", _
            criteria:="GLRowsBase.GLHeader.GLDocumentType != 0", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("GLRowsDivideH-hide if GLMixed", "ViewItem", targetitems:="row_ChartOfAccounts", criteria:="GLRowsBase.GLHeader.GLDocumentType = 0", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("GLRowsDivideH-hide if not Partner ViewItem", "ViewItem", targetitems:="row_Customers;row_ConnectInfo", criteria:="row_PartnerType=-1", visibility:=DevExpress.ExpressApp.Editors.ViewItemVisibility.Hide)> _
<Appearance("GLRowsDivideH-hide if not Partner Action", AppearanceItemType:="Action", targetitems:="aFindPCI", criteria:="row_PartnerType=-1", visibility:=DevExpress.ExpressApp.Editors.ViewItemVisibility.Hide)> _
<RuleCriteria("RuleCriteria GLRowsDivideH-row_ChartOfAccounts", "aToTable_GLRowsDivide", "row_ChartOfAccounts.Children.Count=0", "Csak gyermek objektum választható ki!", SkipNullOrEmptyValues:=False)> _
<RuleCriteria("RuleCriteria GLRowsDivideH-row_DebitChartOfAccounts", "aToTable_GLRowsDivide", "row_DebitChartOfAccounts.Children.Count=0", "Csak gyermek objektum választható ki!", SkipNullOrEmptyValues:=False)> _
<RuleCriteria("RuleCriteria GLRowsDivideH-row_CreditChartOfAccounts", "aToTable_GLRowsDivide", "row_CreditChartOfAccounts.Children.Count=0", "Csak gyermek objektum választható ki!", SkipNullOrEmptyValues:=False)> _
Public Class GLRowsDivideH
    Inherits BaseObject
    Private _GLRows_Oid As Guid
    Private _row_CashType As eCashType
    Private _row_PartnerType As ePartnerType
    Private _row_Customers As Customers
    Private _row_ConnectInfo As String
    Private _row_ChartOfAccounts As ChartOfAccounts
    Private _row_DebitChartOfAccounts As ChartOfAccounts
    Private _row_CreditChartOfAccounts As ChartOfAccounts

    Private _row_Controlling As Controlling
    Private _row_CostHolder As CostHolder
    Private _row_CostPlace As CostPlace
    Private _row_JobNumberObjects As JobNumberObjects
    Private _row_UniqueObjects As UniqueObjects
    Private _row_Cars As Cars 'Jármű
    Private _row_HRPerson As HRPerson 'Ember
    Private _row_Phones As Phones 'Telefon

    Private _row_AmountHUF As Double
    Private _row_AmountDEV As Double
    Private _row_NoteRow As String


    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()

    End Sub

    ReadOnly Property GLRowsBase As GLRows
        Get
            Dim _GLRows As GLRows
            _GLRows = Session.FindObject(Of GLRows)(CriteriaOperator.Parse("Oid=?", Me.GLRows_Oid))
            Return _GLRows
        End Get
    End Property
    <RuleRange("GLRowsDivideH-AmountDiffHUF", "DialogOk_Contexts", 0, 0)> _
    ReadOnly Property AmountDiffHUF As Double
        Get
            Dim _AmountHUF As Double = 0
            Dim _GLRows As GLRows = Session.FindObject(Of GLRows)(CriteriaOperator.Parse("Oid=?", GLRows_Oid))
            Dim _GLRowsDivideR As GLRowsDivideR
            For Each _GLRowsDivideR In Me.GLRowsDivideR
                _AmountHUF += _GLRowsDivideR.AmountHUF
            Next
            If _GLRows IsNot Nothing Then
                Return _GLRows.AmountHUF - _AmountHUF
            Else
                Return -_AmountHUF
            End If
        End Get
    End Property
    <RuleRange("GLRowsDivideH-AmountDiffDEV", "DialogOk_Contexts", 0, 0)> _
    ReadOnly Property AmountDiffDEV As Double
        Get
            Dim _AmountDEV As Double = 0
            Dim _GLRows As GLRows = Session.FindObject(Of GLRows)(CriteriaOperator.Parse("Oid=?", GLRows_Oid))
            Dim _GLRowsDivideR As GLRowsDivideR
            For Each _GLRowsDivideR In Me.GLRowsDivideR
                _AmountDEV += _GLRowsDivideR.AmountDEV
            Next
            If _GLRows IsNot Nothing Then
                Return _GLRows.AmountDEV - _AmountDEV
            Else
                Return -_AmountDEV
            End If
            GLRowsBase.GLHeader.CurrencyName.ShortName = "HUF"
        End Get
    End Property
    Property GLRows_Oid As Guid
        Get
            Return _GLRows_Oid
        End Get
        Set(ByVal value As Guid)
            SetPropertyValue("GLRows_Oid", _GLRows_Oid, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If GLRowsBase IsNot Nothing Then
                    row_Controlling = GLRowsBase.Controlling
                    row_CostHolder = GLRowsBase.CostHolder
                    row_CostPlace = GLRowsBase.CostPlace
                    row_UniqueObjects = GLRowsBase.UniqueObjects
                    row_JobNumberObjects = GLRowsBase.JobNumberObjects
                    row_NoteRow = GLRowsBase.NoteRows
                    row_AmountDEV = GLRowsBase.AmountDEV
                    row_AmountHUF = GLRowsBase.AmountHUF

                    If GLRowsBase.GLHeader.GLDocumentType = eGLDocumentType.eGLMixed Then
                        row_DebitChartOfAccounts = GLRowsBase.DebitChartOfAccounts
                        row_CreditChartOfAccounts = GLRowsBase.CreditChartOfAccounts
                        If GLRowsBase.PartnerType = ePartnerType.eNotSet Then
                            row_CashType = eCashType.eNormal
                            row_PartnerType = ePartnerType.eNotSet
                        Else
                            row_CashType = eCashType.ePartner
                            row_PartnerType = GLRowsBase.PartnerType
                        End If
                    End If
                End If
            End If
        End Set
    End Property
    '--Nonpersistent propertyk
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_CashType As eCashType
        Get
            Return _row_CashType
        End Get
        Set(ByVal value As eCashType)
            SetPropertyValue("row_CashType", _row_CashType, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_PartnerType As ePartnerType
        Get
            Return _row_PartnerType
        End Get
        Set(ByVal value As ePartnerType)
            SetPropertyValue("row_PartnerType", _row_PartnerType, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <RuleRequiredField("GLRowsDivideH-row_Customers", "aToTable_GLRowsDivide", targetcriteria:="row_CashType=0")> _
    <VisibleInListView(False)> _
    Property row_Customers As Customers
        Get
            Return _row_Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("row_Customers", _row_Customers, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <RuleRequiredField("GLRowsDivideH-row_ConnectInfo", "aToTable_GLRowsDivide", targetcriteria:="row_CashType=0 and GLRowsBase.GLHeader.GLDocumentType != 0")> _
    <VisibleInListView(False)> _
    Property row_ConnectInfo As String
        Get
            Return _row_ConnectInfo
        End Get
        Set(ByVal value As String)
            SetPropertyValue("row_ConnectInfo", _row_ConnectInfo, value)
        End Set
    End Property
    <NonPersistent()>
    <RuleRequiredField("GLRowsDivideH-row_CashType", "aToTable_GLRowsDivide", TargetCriteria:="row_CashType=1 and GLRowsBase.GLHeader.GLDocumentType != 0")>
    <ImmediatePostData(True), DataSourceCriteria("AccountYear=GetYear('@This.GLRowsBase.GLHeader.DateExecution')")>
    Property row_ChartOfAccounts As ChartOfAccounts
        Get
            Return _row_ChartOfAccounts
        End Get
        Set(ByVal value As ChartOfAccounts)
            SetPropertyValue("row_ChartOfAccounts", _row_ChartOfAccounts, value)
        End Set
    End Property
    <NonPersistent()>
    <RuleRequiredField("GLRowsDivideH-row_DebitChartOfAccounts", "aToTable_GLRowsDivide", TargetCriteria:="GLRowsBase.GLHeader.GLDocumentType = 0")>
    <ImmediatePostData(True), DataSourceCriteria("AccountYear=GetYear('@This.GLRowsBase.GLHeader.DateExecution')")>
    Property row_DebitChartOfAccounts As ChartOfAccounts
        Get
            Return _row_DebitChartOfAccounts
        End Get
        Set(value As ChartOfAccounts)
            SetPropertyValue("row_DebitChartOfAccounts", _row_DebitChartOfAccounts, value)
        End Set
    End Property
    <NonPersistent()>
    <RuleRequiredField("GLRowsDivideH-row_CreditChartOfAccounts", "aToTable_GLRowsDivide", TargetCriteria:="GLRowsBase.GLHeader.GLDocumentType = 0")>
    <ImmediatePostData(True), DataSourceCriteria("AccountYear=GetYear('@This.GLRowsBase.GLHeader.DateExecution')")>
    Property row_CreditChartOfAccounts As ChartOfAccounts
        Get
            Return _row_CreditChartOfAccounts
        End Get
        Set(value As ChartOfAccounts)
            SetPropertyValue("row_CreditChartOfAccounts", _row_CreditChartOfAccounts, value)
        End Set
    End Property

    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_Controlling As Controlling
        Get
            Return _row_Controlling
        End Get
        Set(ByVal value As Controlling)
            SetPropertyValue("row_Controlling", _row_Controlling, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_CostHolder As CostHolder
        Get
            Return _row_CostHolder
        End Get
        Set(ByVal value As CostHolder)
            SetPropertyValue("row_CostHolder", _row_CostHolder, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_CostPlace As CostPlace
        Get
            Return _row_CostPlace
        End Get
        Set(ByVal value As CostPlace)
            SetPropertyValue("row_CostPlace", _row_CostPlace, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_JobNumberObjects As JobNumberObjects
        Get
            Return _row_JobNumberObjects
        End Get
        Set(ByVal value As JobNumberObjects)
            SetPropertyValue("row_JobNumberObjects", _row_JobNumberObjects, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_UniqueObjects As UniqueObjects
        Get
            Return _row_UniqueObjects
        End Get
        Set(ByVal value As UniqueObjects)
            SetPropertyValue("row_UniqueObjects", _row_UniqueObjects, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_Cars As Cars
        Get
            Return _row_Cars
        End Get
        Set(value As Cars)
            SetPropertyValue("row_Cars", _row_Cars, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_HRPerson As HRPerson
        Get
            Return _row_HRPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("row_HRPerson", _row_HRPerson, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <VisibleInListView(False)> _
    Property row_Phones As Phones
        Get
            Return _row_Phones
        End Get
        Set(value As Phones)
            SetPropertyValue("row_Phones", _row_Phones, value)
        End Set
    End Property


    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <RuleRange("GLRowsDivideH-row_AmountHUF", "aToTable_GLRowsDivide", 0, 999999999)> _
    <VisibleInListView(False)> _
    Property row_AmountHUF As Double
        Get
            Return _row_AmountHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_AmountHUF", _row_AmountHUF, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData(True)> _
    <RuleRange("GLRowsDivideH-row_AmountDEV", "aToTable_GLRowsDivide", 0, 999999999, targetcriteria:="GLRowsBase.GLHeader.CurrencyName.ShortName<>'HUF'")> _
    <VisibleInListView(False)> _
    Property row_AmountDEV As Double
        Get
            Return _row_AmountDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_AmountDEV", _row_AmountDEV, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                If Me.GLRowsBase.CurrencyRate <> 0 And GLRowsBase.GLHeader.CurrencyName.ShortName <> "HUF" Then
                    row_AmountHUF = value * Me.GLRowsBase.CurrencyRate
                End If
            End If
        End Set
    End Property
    <Size(255)> _
    <NonPersistent()> _
    <VisibleInListView(False)> _
    Property row_NoteRow As String
        Get
            Return _row_NoteRow
        End Get
        Set(ByVal value As String)
            SetPropertyValue("row_NoteRow", _row_NoteRow, value)
        End Set
    End Property

    <VisibleInListView(False)> _
  <Association("GLRowsDivideH-GLRowsDivideR", GetType(GLRowsDivideR))> _
    ReadOnly Property GLRowsDivideR As XPCollection(Of GLRowsDivideR)
        Get
            Return GetCollection(Of GLRowsDivideR)("GLRowsDivideR")
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property GLRows As XPCollection(Of GLRows)
        Get
            Return New XPCollection(Of GLRows)(Session, CriteriaOperator.Parse("Oid=?", Me.GLRows_Oid))
        End Get
    End Property
End Class
