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

<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
Public Class GLOpenCloseHeader
    Inherits BaseObject
    Private _ShortName As String
    Private _CustomersFrom As CustomersFrom
    Private _AccountYearClose As Long
    Private _AccountYearOpen As Long
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _IsEditable As Boolean = True
    Private _IsClosedBallance As Boolean = False 'Mérlegszámlák lezárva ?
    Private _IsClosedSheetProfit As Boolean = False 'Eredményszámlák lezárva ?
    Private _IsDividend As Boolean = False 'Osztalék elszámolva
    Private _IsOpenNew As Boolean = False 'Új év megnyitva

    Private _TrialBalanceHeaderBeforeClose As TrialBalanceHeader 'Zárás alapjául szolgáló főkönyvi kivonat
    Private _TrialBalanceHeaderAfterClose_Ballance As TrialBalanceHeader 'Zárás utáni főkönyvi kivonat (mérlegszámlák után)
    Private _TrialBalanceHeaderAfterClose_SheetProfit As TrialBalanceHeader 'Zárás utáni főkönyvi kivonat (eredményszámlák után)
    Private _TrialBalanceHeaderAfterDividend As TrialBalanceHeader 'Osztalék elszámolás utáni fk. kivonat
    Private _TrialBalanceHeaderAfterOpen As TrialBalanceHeader 'Új év megnyitása utáni főkönyvi kivonat

    Private _GLMixed_AfterClose_SheetProfit As GLMixed 'Eredményszámlák zárása fk. vegyes bizonylat
    Private _GLMixed_AfterClose_Ballance As GLMixed 'Mérlegszámlák zárása vegyes bizonylat
    Private _GLMixed_AfterDividend As GLMixed 'Osztalék elszámolási fk vegyes bizonylat
    Private _GLMixed_AfterOpen 'Nyitási fk. vegyes bizonylat

    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()
        ' Place here your initialization code.
        AccountYearClose = GetSQLTime(Session).Year - 1
        AccountYearOpen = GetSQLTime(Session).Year
        IsClosedBallance = False
        IsClosedSheetProfit = False
        IsDividend = False
        IsOpenNew = False
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
            If TrialBalanceHeaderBeforeClose Is Nothing Then
                TrialBalanceHeaderBeforeClose = New TrialBalanceHeader(Session)
                TrialBalanceHeaderBeforeClose.CustomersFrom = Me.CustomersFrom
                TrialBalanceHeaderBeforeClose.DateFrom = New Date(Me.AccountYearClose, 1, 1)
                TrialBalanceHeaderBeforeClose.DateTo = New Date(Me.AccountYearClose, 12, 31)
                TrialBalanceHeaderBeforeClose.GLReportDateExecutionMode = eDateExecutionMode.eHeader
                TrialBalanceHeaderBeforeClose.QueryLevel = 10
                TrialBalanceHeaderBeforeClose.ShortName = Me.ShortName & " - zárás előtti főkönyvi kivonat"
                TrialBalanceHeaderBeforeClose.IsGLOpenClose = True
                TrialBalanceHeaderBeforeClose.Save()

                TrialBalanceHeaderAfterClose_SheetProfit = New TrialBalanceHeader(Session)
                TrialBalanceHeaderAfterClose_SheetProfit.CustomersFrom = Me.CustomersFrom
                TrialBalanceHeaderAfterClose_SheetProfit.DateFrom = New Date(Me.AccountYearClose, 1, 1)
                TrialBalanceHeaderAfterClose_SheetProfit.DateTo = New Date(Me.AccountYearClose, 12, 31)
                TrialBalanceHeaderAfterClose_SheetProfit.GLReportDateExecutionMode = eDateExecutionMode.eHeader
                TrialBalanceHeaderAfterClose_SheetProfit.QueryLevel = 10
                TrialBalanceHeaderAfterClose_SheetProfit.ShortName = Me.ShortName & " - eredményszámlák zárása utáni főkönyvi kivonat"
                TrialBalanceHeaderAfterClose_SheetProfit.IsGLOpenClose = True
                TrialBalanceHeaderAfterClose_SheetProfit.Save()

                TrialBalanceHeaderAfterClose_Ballance = New TrialBalanceHeader(Session)
                TrialBalanceHeaderAfterClose_Ballance.CustomersFrom = Me.CustomersFrom
                TrialBalanceHeaderAfterClose_Ballance.DateFrom = New Date(Me.AccountYearClose, 1, 1)
                TrialBalanceHeaderAfterClose_Ballance.DateTo = New Date(Me.AccountYearClose, 12, 31)
                TrialBalanceHeaderAfterClose_Ballance.GLReportDateExecutionMode = eDateExecutionMode.eHeader
                TrialBalanceHeaderAfterClose_Ballance.QueryLevel = 10
                TrialBalanceHeaderAfterClose_Ballance.ShortName = Me.ShortName & " - mérlegszámlák zárása utáni főkönyvi kivonat"
                TrialBalanceHeaderAfterClose_Ballance.IsGLOpenClose = True
                TrialBalanceHeaderAfterClose_Ballance.Save()

                TrialBalanceHeaderAfterDividend = New TrialBalanceHeader(Session)
                TrialBalanceHeaderAfterDividend.CustomersFrom = Me.CustomersFrom
                TrialBalanceHeaderAfterDividend.DateFrom = New Date(Me.AccountYearClose, 1, 1)
                TrialBalanceHeaderAfterDividend.DateTo = New Date(Me.AccountYearClose, 12, 31)
                TrialBalanceHeaderAfterDividend.GLReportDateExecutionMode = eDateExecutionMode.eHeader
                TrialBalanceHeaderAfterDividend.QueryLevel = 10
                TrialBalanceHeaderAfterDividend.ShortName = Me.ShortName & " - osztalék elszámolás utáni főkönyvi kivonat"
                TrialBalanceHeaderAfterDividend.IsGLOpenClose = True
                TrialBalanceHeaderAfterDividend.Save()

                TrialBalanceHeaderAfterOpen = New TrialBalanceHeader(Session)
                TrialBalanceHeaderAfterOpen.CustomersFrom = Me.CustomersFrom
                TrialBalanceHeaderAfterOpen.DateFrom = New Date(Me.AccountYearClose, 1, 1)
                TrialBalanceHeaderAfterOpen.DateTo = New Date(Me.AccountYearClose, 12, 31)
                TrialBalanceHeaderAfterOpen.GLReportDateExecutionMode = eDateExecutionMode.eHeader
                TrialBalanceHeaderAfterOpen.QueryLevel = 10
                TrialBalanceHeaderAfterOpen.ShortName = Me.ShortName & " - nyitás utáni főkönyvi kivonat"
                TrialBalanceHeaderAfterOpen.IsGLOpenClose = True
                TrialBalanceHeaderAfterOpen.Save()

                
            End If

        End If
        If Me.GLMixed_AfterDividend Is Nothing Then
            GLMixed_AfterDividend = New GLMixed(Session)
            GLMixed_AfterDividend.CustomersFrom = Me.CustomersFrom
            GLMixed_AfterDividend.DateExecution = New Date(Me.AccountYearClose, 12, 31)
            GLMixed_AfterDividend.DateCreated = GLMixed_AfterDividend.DateExecution
            GLMixed_AfterDividend.DatePayment = GLMixed_AfterDividend.DateExecution
            GLMixed_AfterDividend.CurrencyName = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'"))
            GLMixed_AfterDividend.Save()
        End If
    End Sub

    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    Property AccountYearClose As Long
        Get
            Return _AccountYearClose
        End Get
        Set(value As Long)
            SetPropertyValue("AccountYearClose", _AccountYearClose, value)
        End Set
    End Property
    Property AccountYearOpen As Long
        Get
            Return _AccountYearOpen
        End Get
        Set(value As Long)
            SetPropertyValue("AccountYearOpen", _AccountYearOpen, value)
        End Set
    End Property
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    <NonCloneable> _
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    Property IsEditable As Boolean
        Get
            Return _IsEditable
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property
    Property IsClosedBallance As Boolean
        Get
            Return _IsClosedBallance
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsClosedBallance", _IsClosedBallance, value)
        End Set
    End Property
    Property IsClosedSheetProfit As Boolean
        Get
            Return _IsClosedSheetProfit
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsClosedSheetProfit", _IsClosedSheetProfit, value)
        End Set
    End Property
    Property IsDividend As Boolean
        Get
            Return _IsDividend
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsDividend", _IsDividend, value)
        End Set
    End Property
    Property IsOpenNew As Boolean
        Get
            Return _IsOpenNew
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsOpenNew", _IsOpenNew, value)
        End Set
    End Property

    <Browsable(False)> _
    Property TrialBalanceHeaderBeforeClose As TrialBalanceHeader
        Get
            Return _TrialBalanceHeaderBeforeClose
        End Get
        Set(value As TrialBalanceHeader)
            SetPropertyValue("TrialBalanceHeaderBeforeClose", _TrialBalanceHeaderBeforeClose, value)
        End Set
    End Property
    <Browsable(False)> _
    Property TrialBalanceHeaderAfterClose_Ballance As TrialBalanceHeader
        Get
            Return _TrialBalanceHeaderAfterClose_Ballance
        End Get
        Set(value As TrialBalanceHeader)
            SetPropertyValue("TrialBalanceHeaderAfterClose_Ballance", _TrialBalanceHeaderAfterClose_Ballance, value)
        End Set
    End Property
    <Browsable(False)> _
    Property TrialBalanceHeaderAfterClose_SheetProfit As TrialBalanceHeader
        Get
            Return _TrialBalanceHeaderAfterClose_SheetProfit
        End Get
        Set(value As TrialBalanceHeader)
            SetPropertyValue("TrialBalanceHeaderAfterClose_SheetProfit", _TrialBalanceHeaderAfterClose_SheetProfit, value)
        End Set
    End Property
    <Browsable(False)> _
    Property TrialBalanceHeaderAfterDividend As TrialBalanceHeader
        Get
            Return _TrialBalanceHeaderAfterDividend
        End Get
        Set(value As TrialBalanceHeader)
            SetPropertyValue("TrialBalanceHeaderAfterDividend", _TrialBalanceHeaderAfterDividend, value)
        End Set
    End Property
    <Browsable(False)> _
    Property TrialBalanceHeaderAfterOpen As TrialBalanceHeader
        Get
            Return _TrialBalanceHeaderAfterOpen
        End Get
        Set(value As TrialBalanceHeader)
            SetPropertyValue("TrialBalanceHeaderAfterOpen", _TrialBalanceHeaderAfterOpen, value)
        End Set
    End Property

    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property GLMixed_AfterClose_SheetProfit As GLMixed
        Get
            Return _GLMixed_AfterClose_SheetProfit
        End Get
        Set(value As GLMixed)
            SetPropertyValue("GLMixed_AfterClose_SheetProfit", _GLMixed_AfterClose_SheetProfit, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property GLMixed_AfterClose_Ballance As GLMixed
        Get
            Return _GLMixed_AfterClose_Ballance
        End Get
        Set(value As GLMixed)
            SetPropertyValue("GLMixed_AfterClose_Ballance", _GLMixed_AfterClose_Ballance, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property GLMixed_AfterDividend As GLMixed
        Get
            Return _GLMixed_AfterDividend
        End Get
        Set(value As GLMixed)
            SetPropertyValue("GLMixed_AfterDividend", _GLMixed_AfterDividend, value)
        End Set
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    Property GLMixed_AfterOpen As GLMixed
        Get
            Return _GLMixed_AfterOpen
        End Get
        Set(value As GLMixed)
            SetPropertyValue("GLMixed_AfterOpen", _GLMixed_AfterOpen, value)
        End Set
    End Property

    '//XPCollections
    '<Association("GLOpenCloseHeader-GLOpenCloseRows", GetType(GLOpenCloseRows)), VisibleInListView(False), VisibleInLookupListView(False)> _
    'ReadOnly Property GLOpenCloseRows As XPCollection(Of GLOpenCloseRows)
    '    Get
    '        Return GetCollection(Of GLOpenCloseRows)("GLOpenCloseRows")
    '    End Get
    'End Property
End Class
