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
Public Enum eVATMode
    eIn = 1
    eOut = 0
End Enum
<DefaultClassOptions()> _
<NavigationItem("FinancialStock")> _
<Appearance("Hide KeyValue if InverState=True", AppearanceItemType:="ViewItem", criteria:="InversState=True", targetitems:="KeyValue", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide InversKeyValue if InverState=False", AppearanceItemType:="ViewItem", criteria:="InversState=False", targetitems:="InversKeyValue", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class VAT
    Inherits BaseObject
    Private _ShortName As String
    Private _Description As String
    Private _KeyValue As Double
    Private _ChartOfAccountsOut As ChartOfAccounts
    Private _ChartOfAccountsIn As ChartOfAccounts
    Private _ClaimState As Boolean 'Levonható ?
    Private _Active As Boolean 'Aktív ?
    Private _InversState As Boolean = False 'Fordított ÁFA ?
    Private _InverskeyValue As Double 'Fordított kulcs
    Private _DefaultForBusinnes As Boolean = False 'Alapértelmezett az üzleti tranzakciók miatt
    Private _DefaultForExternalEUNoVAT As Boolean = False 'EU-n belüli ÁFA kód (erre gyűjt majd !)
    Private _DefaultForExternalOther As Boolean = False 'EU-n kívüli ÁFA kód ? (erre gyűjt majd !)
    Private _DefaultForInversVAT As Boolean = False 'Fordított adózás alapértelmezett kódja

    '65A bevalláshoz mező azonosítás
    Private _XML65AFieldIDBaseValueIn As String '65A bevallás melyik mezőkódjára tegye az ÁFA alapjának értékét levonható! 
    Private _XML65AFieldIDValueIn As String '65A bevallás melyik mezőkódjára tegye az ÁFA értékét levonható!
    Private _XML65AFieldIDBaseValueOut As String '65A bevallás melyik mezőkódjára tegye az ÁFA alapjának értékét fizetendő!
    Private _XML65AFieldIDValueOut As String '65A bevallás melyik mezőkódjára tegye az ÁFA értékét fizetendő!

    Private _XML65AFieldIDBaseValueInSum As String '65A bevallás melyik mezőkódjára tegye az ÁFA alapjának értékét levonható! 
    Private _XML65AFieldIDValueInSum As String '65A bevallás melyik mezőkódjára tegye az ÁFA értékét levonható!
    Private _XML65AFieldIDBaseValueOutSum As String '65A bevallás melyik mezőkódjára tegye az ÁFA alapjának értékét fizetendő!
    Private _XML65AFieldIDValueOutSum As String '65A bevallás melyik mezőkódjára tegye az ÁFA értékét fizetendő!

    Private _VATBag As String 'Áfa csomag, például pénztárgéphez

    Public Sub New(ByVal session As Session)
        MyBase.New(session)

    End Sub
    ReadOnly Property KeyValuePercent() As Double
        Get
            Return _KeyValue * 100
        End Get
    End Property
    Property ShortName() As String
        Get
            Return _ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    Property KeyValue() As Double
        Get
            Return _KeyValue
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("KeyValue", _KeyValue, value)
        End Set
    End Property
    <Browsable(False)>
    Property ChartOfAccountsOut() As ChartOfAccounts
        Get
            Return _ChartOfAccountsOut
        End Get
        Set(ByVal value As ChartOfAccounts)
            SetPropertyValue("ChartOfAccountsOut", _ChartOfAccountsOut, value)
        End Set
    End Property
    <Browsable(False)>
    Property ChartOfAccountsIn() As ChartOfAccounts
        Get
            Return _ChartOfAccountsIn
        End Get
        Set(ByVal value As ChartOfAccounts)
            SetPropertyValue("ChartOfAccountsIn", _ChartOfAccountsIn, value)
        End Set
    End Property
    Property ClaimState() As Boolean
        Get
            Return _ClaimState
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("ClaimState", _ClaimState, value)
        End Set
    End Property
    Property Active() As Boolean
        Get
            Return _Active
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("Active", _Active, value)
        End Set
    End Property
    <ImmediatePostData()> _
    Property InversState() As Boolean
        Get
            Return _InversState
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("InversState", _InversState, value)
            If Session.IsObjectsLoading = False AndAlso Session.IsObjectsSaving = False Then
                If value = True Then
                    KeyValue = 0
                Else
                    InversKeyValue = 0
                End If
            End If
        End Set
    End Property
    Property InversKeyValue() As Double
        Get
            Return _InverskeyValue
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("InversKeyValue", _InverskeyValue, value)
        End Set
    End Property
    Property DefaultForBusinnes As Boolean
        Get
            Return _DefaultForBusinnes
        End Get
        Set(value As Boolean)
            SetPropertyValue("DefaultForBusinnes", _DefaultForBusinnes, value)
        End Set
    End Property
    Property DefaultForExternalEUNoVAT As Boolean
        Get
            Return _DefaultForExternalEUNoVAT
        End Get
        Set(value As Boolean)
            SetPropertyValue("DefaultForExternalEUNoVAT", _DefaultForExternalEUNoVAT, value)
        End Set
    End Property
    Property DefaultForExternalOther As Boolean
        Get
            Return _DefaultForExternalOther
        End Get
        Set(value As Boolean)
            SetPropertyValue("DefaultForExternalOther", _DefaultForExternalOther, value)
        End Set
    End Property
    Property DefaultForInversVAT As Boolean
        Get
            Return _DefaultForInversVAT
        End Get
        Set(value As Boolean)
            SetPropertyValue("DefaultForInversVAT", _DefaultForInversVAT, value)
        End Set
    End Property
    Property XML65AFieldIDBaseValueIn As String
        Get
            Return _XML65AFieldIDBaseValueIn
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDBaseValueIn", _XML65AFieldIDBaseValueIn, value)
        End Set
    End Property
    Property XML65AFieldIDValueIn As String
        Get
            Return _XML65AFieldIDValueIn
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDValueIn", _XML65AFieldIDValueIn, value)
        End Set
    End Property
    Property XML65AFieldIDBaseValueOut As String
        Get
            Return _XML65AFieldIDBaseValueOut
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDBaseValueOut", _XML65AFieldIDBaseValueOut, value)
        End Set
    End Property
    Property XML65AFieldIDValueOut As String
        Get
            Return _XML65AFieldIDValueOut
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDValueOut", _XML65AFieldIDValueOut, value)
        End Set
    End Property
    Property XML65AFieldIDBaseValueInSum As String
        Get
            Return _XML65AFieldIDBaseValueInSum
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDBaseValueInSum", _XML65AFieldIDBaseValueInSum, value)
        End Set
    End Property
    Property XML65AFieldIDValueInSum As String
        Get
            Return _XML65AFieldIDValueInSum
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDValueInSum", _XML65AFieldIDValueInSum, value)
        End Set
    End Property
    Property XML65AFieldIDBaseValueOutSum As String
        Get
            Return _XML65AFieldIDBaseValueOutSum
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDBaseValueOutSum", _XML65AFieldIDBaseValueOutSum, value)
        End Set
    End Property
    Property XML65AFieldIDValueOutSum As String
        Get
            Return _XML65AFieldIDValueOutSum
        End Get
        Set(value As String)
            SetPropertyValue("XML65AFieldIDValueOutSum", _XML65AFieldIDValueOutSum, value)
        End Set
    End Property
    Property VATBag As String
        Get
            Return _VATBag
        End Get
        Set(value As String)
            SetPropertyValue("VATBag", _VATBag, value)
        End Set
    End Property


    <Association("VAT-VATYear", GetType(VATYear)), VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property VATYear As XPCollection(Of VATYear)
        Get
            Return GetCollection(Of VATYear)("VATYear")
        End Get
    End Property
    Public Function GetChartOfAccounts(_AccountYear As Long, _VATMode As eVATMode) As ChartOfAccounts
        Dim _ChartOfAccounts As ChartOfAccounts = Nothing
        Dim _VATYear As VATYear
        Select Case _VATMode
            Case eVATMode.eIn
                _ChartOfAccounts = Me.ChartOfAccountsIn
                For Each _VATYear In Me.VATYear
                    If _VATYear.AccountYear = _AccountYear Then
                        _ChartOfAccounts = _VATYear.ChartOfAccountsIn
                        Exit For
                    End If
                Next
            Case eVATMode.eOut
                _ChartOfAccounts = Me.ChartOfAccountsOut
                For Each _VATYear In Me.VATYear
                    If _VATYear.AccountYear = _AccountYear Then
                        _ChartOfAccounts = _VATYear.ChartOfAccountsOut
                        Exit For
                    End If
                Next
        End Select
        Return _ChartOfAccounts
    End Function
End Class 'ÁFA kódok
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
<RuleCriteria("RuleCriteria VATYear-ChartOfAccountsOut", DefaultContexts.Save, "ChartOfAccountsOut.Children.Count=0", "Csak gyermek objektum választható ki!", SkipNullOrEmptyValues:=False)> _
<RuleCriteria("RuleCriteria VATYear-ChartOfAccountsIn", DefaultContexts.Save, "ChartOfAccountsIn.Children.Count=0", "Csak gyermek objektum választható ki!", SkipNullOrEmptyValues:=False)> _
Public Class VATYear
    Inherits BaseObject

    Private _VAT As VAT
    Private _AccountYear As Long
    Private _ChartOfAccountsOut As ChartOfAccounts
    Private _ChartOfAccountsIn As ChartOfAccounts
    Public Sub New(ByVal session As Session)
        MyBase.New(session)

    End Sub

    <Association("VAT-VATYear", GetType(VAT))> _
    Property VAT As VAT
        Get
            Return _VAT
        End Get
        Set(value As VAT)
            SetPropertyValue("VAT", _VAT, value)
        End Set
    End Property
    Property AccountYear As Long
        Get
            Return _AccountYear
        End Get
        Set(value As Long)
            SetPropertyValue("AccountYear", _AccountYear, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("AccountYear='@This.AccountYear'")>
    Property ChartOfAccountsOut As ChartOfAccounts
        Get
            Return _ChartOfAccountsOut
        End Get
        Set(value As ChartOfAccounts)
            SetPropertyValue("ChartOfAccountsOut", _ChartOfAccountsOut, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("AccountYear='@This.AccountYear'")>
    Property ChartOfAccountsIn As ChartOfAccounts
        Get
            Return _ChartOfAccountsIn
        End Get
        Set(value As ChartOfAccounts)
            SetPropertyValue("ChartOfAccountsIn", _ChartOfAccountsIn, value)
        End Set
    End Property
End Class