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
' A bekérõ, elõleg és végszámla iktatáshoz tartozó szabályok
'<EditorStateRuleAttribute("Disable registry type when CustromersFrom is nothing", "RegistryType", ViewType.DetailView, "isnull(CustomersFrom)", EditorState.Disabled)> _
'<EditorStateRuleAttribute("Hide when Currency is HUF", "F_AmountBruttoDEV", EditorState.Hidden, "F_CurrencyName.ShortName='HUF'", ViewType.DetailView)> _
'<EditorStateRuleAttribute("Hide return state", "ReturnType;DateReturn", EditorState.Hidden, "RegistryAcceptState=0", ViewType.DetailView)> _
'<EditorStateRuleAttribute("Hide financial info", "PCIDetail;DocumentNumber;F_DateCreated;F_DateExecution;F_DatePayment;F_AmountBruttoHUF;F_AmountBruttoDEV;F_CurrencyName;F_CustomerBankAccounts;F_PayMode;F_DateVAT", ' EditorState.Hidden, "isnull(RegistryType) or (RegistryType.RegistryMainType <> 0)", ViewType.DetailView)> 
'<EditorStateRuleAttribute("Disabled all properties if IsEditable=False", "CustomersFrom;Customers;Contacts;RegistryType;RegistryAcceptState;ShortName;DocumentNumber;RegistryNumber;JobNumberObjects;UniqueObjects;DateCreated;DeliveryType;ReturnType;DateReturn;RegistryRows;DocumentFile;IsEditable;IsStorno;CurrentWorkflowSystemSteps;HRResponsible;F_DateCreated;F_DateExecution;F_DatePayment;F_AmountBruttoHUF;F_AmountBruttoDEV;F_CurrencyName;F_CustomerBankAccounts;F_IsImported;F_CurrencyRate;F_PayMode;F_DateVAT", EditorState.Disabled, "IsEditable=False", ViewType.DetailView)> _
'<EditorStateRuleAttribute("Hide F_CustomerBankAccounts", "F_CustomerBankAccounts", EditorState.Hidden, "F_PayMode = 0", ViewType.DetailView)> _
'<EditorStateRuleAttribute("Disable CustomresFrom when is not empty", "CustomersFrom", ViewType.DetailView, "IsNull(CustomersFrom) = False", EditorState.Disabled)> _
'<EditorStateRuleAttribute("Disable RegistryType when it is not empty", "RegistryType", ViewType.DetailView, "IsNull(RegistryType) = False", EditorState.Disabled)> _
'<EditorStateRuleAttribute("Disable RegistryHeader.F_BruttoAmountHUF and DEV if registry has a transfered bank!", "Customers;F_DatePayment;F_AmountBruttoHUF;F_AmountBruttoDEV;F_CurrencyName;F_CustomerBankAccounts;F_PayMode", EditorState.Disabled, "HasTransferedBank = True", ViewType.DetailView)> _

'<Appearance("Hide InvoiceAdvance collection if it is not FinalInvoice", AppearanceItemType.ViewItem, "RegistryType.RegistryMainType!=4", TargetItems:="InvoiceAdvance", Visibility:=Editors.ViewItemVisibility.Hide)> _
'<Appearance("Hide AdvanceAsk if it is not InvoiceAdvance", AppearanceItemType.ViewItem, "RegistryType.RegistryMainType!=2", TargetItems:="F_AdvanceAsk", Visibility:=Editors.ViewItemVisibility.Hide)> _
'<Appearance("Hide Finalinvoice if it is not InvoiceAdvance", AppearanceItemType.ViewItem, "RegistryType.RegistryMainType!=2 OR IsNull(F_FinalInvoice)", TargetItems:="F_FinalInvoice", Visibility:=Editors.ViewItemVisibility.Hide)> _
'<EditorStateRuleAttribute("Hide VAT and Controlling when type not financial 2", AppearanceItemType.ViewItem, TargetItems:="RegistryRowsFinancial;RegistryRowsFinancialControlling", EditorState.Hidden, "RegistryType.RegistryMainType <> 0", ViewType.DetailView)> _
<DefaultClassOptions()> _
<NavigationItem("FinancialTransactions")> _
<Appearance("Disable registry type when CustromersFrom is nothing", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="RegistryType", _
                          Criteria:="isnull(CustomersFrom)", _
                          Enabled:=False, _
                          Context:="DetailView")> _
<Appearance("Hide when Currency is HUF", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="F_AmountBruttoDEV", _
                          Criteria:="F_CurrencyName.ShortName='HUF'", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide return state if RegistryAcceptState=0", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="ReturnType;DateReturn", _
                          Criteria:="RegistryAcceptState=0", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide Financial infos ViewItem", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="PCIDetail;DocumentNumber;F_DateCreated;F_DateExecution;F_DatePayment;F_AmountBruttoHUF;F_AmountBruttoDEV;" + _
                                       "F_CurrencyName;F_CustomerBankAccounts;F_PayMode;F_DateVAT;F_VATAvowalType;RegistryRowsFinancial;RegistryRowsFinancialControlling;" + _
                                       "BruttoAmountRemaining;NettoAmountRemaining;BruttoAmountRemainingBank", _
                          Criteria:="isnull(RegistryType) or (RegistryType.RegistryMainType in (1,5))", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide Financial infos LayoutItem", _
                          AppearanceItemType:="LayoutItem", _
                          TargetItems:="TabRegistryRowsFinancial;RegistryRowsFinancialControlling;PCIDetail", _
                          Criteria:="isnull(RegistryType) or (RegistryType.RegistryMainType in (1,5))", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide Financial infos when RegistryType.RegistryMainType=3 LayoutItem", _
                          AppearanceItemType:="LayoutItem", _
                          TargetItems:="TabRegistryRowsFinancial;RegistryRowsFinancialControlling;PCIDetail", _
                          Criteria:="RegistryType.RegistryMainType=3", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide Financial infos Action", _
                          AppearanceItemType:="Action", _
                          criteria:="(IsEditable=False) or (RegistryType.RegistryMainType in (1,3,5)) or (CurrentWorkflowSystemSteps.StepFinancialType in (0,2,3,4))", _
                          TargetItems:="aToTable_RRF;aToTableD_RRF;aControllRegistryTelephone", _
                          visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Disabled all properties if IsEditable=False", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="CustomersFrom;Customers;Contacts;RegistryType;RegistryAcceptState;ShortName;DocumentNumber;RegistryNumber;" + _
                                       "JobNumberObjects;UniqueObjects;DateCreated;DeliveryType;ReturnType;DateReturn;RegistryRows;DocumentFile;IsEditable;" + _
                                       "IsStorno;CurrentWorkflowSystemSteps;HRResponsible;F_DateCreated;F_DateExecution;F_DatePayment;F_AmountBruttoHUF;" + _
                                       "F_AmountBruttoDEV;F_CurrencyName;F_CustomerBankAccounts;F_IsImported;F_CurrencyRate;F_PayMode;F_DateVAT;F_VATAvowalType", _
                          Criteria:="IsEditable=False", _
                          Enabled:=False, _
                          Context:="DetailView")> _
<Appearance("Hide F_CustomerBankAccounts", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="F_CustomerBankAccounts", _
                          Criteria:="F_PayMode = 0", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Disable CustomresFrom when is not empty", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="CustomersFrom", _
                          Criteria:="IsNull(CustomersFrom) = False", _
                          Enabled:=False, _
                          Context:="DetailView")> _
<Appearance("Disable RegistryType when it is not empty", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="RegistryType", _
                          Criteria:="IsNull(RegistryType) = False", _
                          Enabled:=False, _
                          Context:="DetailView")> _
<Appearance("Hide CauseOfRefuse when RegistryAcceptState = 0", _
                          AppearanceItemType:="ViewItem", _
                          criteria:="RegistryAcceptState = 0", _
                          TargetItems:="CauseOfRefuse", _
                          visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Disable RegistryHeader.F_BruttoAmountHUF and DEV if registry has a transfered bank!", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="Customers;F_DatePayment;F_AmountBruttoHUF;F_AmountBruttoDEV;F_CurrencyName;F_CustomerBankAccounts;F_PayMode", _
                          Criteria:="HasTransferedBank = True", _
                          Enabled:=False, _
                          Context:="DetailView")> _
<Appearance("Disable IC Invoice Import if not editable and CustomersFrom Is not null and RegistryMainType.RegistryType is not 1", _
                          AppearanceItemType:="Action", _
                          Criteria:="IsEditable=False OR RegistryType.RegistryMainType=1 Or IsNull(CustomersFrom)", _
                          TargetItems:="aImportICInvoice", _
                          Enabled:=False, _
                          Context:="Any")> _
<Appearance("Hide RRFC infos Action", _
                          AppearanceItemType:="Action", _
                          criteria:="(IsEditable=False) or (RegistryType.RegistryMainType != 0) or (CurrentWorkflowSystemSteps.StepFinancialType in (0,1,2,3,4))", _
                          TargetItems:="aToTable_RRFC;aToTableD_RRFC;aToTable_RRFC_With_TContract;aToTable_RRFC_With_RContract", _
                          visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide Financial infos row_*", _
                          AppearanceItemType:="ViewItem", _
                          criteria:="(IsEditable=False) or (RegistryType.RegistryMainType in (1,5)) or (CurrentWorkflowSystemSteps.StepFinancialType in (0,2,3,4))", _
                          TargetItems:="row_VAT;row_VAT_BruttoAmount", _
                          visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RRFC infos row_*", _
                          AppearanceItemType:="ViewItem", _
                          criteria:="(IsEditable=False) or (RegistryType.RegistryMainType in (1,5)) or (CurrentWorkflowSystemSteps.StepFinancialType in (0,1,2,3,4))", _
                          TargetItems:="row_RRFC_JobNumberObjects;row_RRFC_UniqueObjects;row_RRFC_Controlling;row_RRFC_CostPlace;row_RRFC_CostHolder;" + _
                                       "row_RRFC_Note;row_RRFC_Amount As Double;row_RRFC_ContractRows", _
                          visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide RegistryBankTransfer when not BANK LayoutItem", _
                          AppearanceItemType:="LayoutItem", _
                          criteria:="F_PayMode != 1", _
                          targetitems:="RegistryBankTransfer", _
                          visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide RegistryBankTransfer when not BANK ViewItem", _
                          AppearanceItemType:="ViewItem", _
                          criteria:="F_PayMode != 1", _
                          targetitems:="RegistryBankTransfer", _
                          visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide CurrencyRate if CurrencyName is HUF", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="F_CurrencyRate", _
                          Criteria:="F_CurrencyName.ShortName = 'HUF'", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("EFR_RegistryBankTransfer",
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="RegistryBankTransfer;BruttoAmountRemainingBank", _
                          Criteria:="Not ((F_PayMode = 'InTransfer' Or F_PayMode = 'InContinuous') And RegistryType.RegistryMainType = 'eAccount')", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide Bank information when InvoiceAdvance ViewItem", _
                          AppearanceItemType:="ViewItem", _
                          TargetItems:="F_CustomerBankAccounts;RegistryBankTransfer;BruttoAmountRemainingBank", _
                          Criteria:="RegistryType.RegistryMainType=2", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Hide Bank information when InvoiceAdvance LayoutItem", _
                          AppearanceItemType:="LayoutItem", _
                          TargetItems:="RegistryBankTransfer", _
                          Criteria:="RegistryType.RegistryMainType=2", _
                          Visibility:=Editors.ViewItemVisibility.Hide, _
                          Context:="DetailView")> _
<Appearance("Disable UserCreated all",
                AppearanceItemType:="ViewItem",
                   TargetItems:="UserCreated",
                   Criteria:="1=1",
                   Enabled:=False)> _
<RuleCriteria("RuleCriteria RegistryHeader-ChartOfAccountsYearIsClosed-RegistryNextStep_Context", "RegistryNextStep_Context", "ChartOfAccountsYearIsClosed=False", "Zárolt főkönyvi évre nem lehet rögzíteni!",
                         SkipNullOrEmptyValues:=False)> _
<RuleCriteria("RuleCriteria RegistryHeader-DateExecution", "Save", _
    "IsVATClosed=False", _
    "ÁFA időszak zárva, nem lehet rögzíteni !", SkipNullOrEmptyValues:=False)> _
<DefaultProperty("DisplayName")> _
Public Class RegistryHeader '-- iktatórendszer
    Inherits BaseObject
    Private _CustomersFrom As CustomersFrom 'Saját cég
    Private _Customers As Customers 'Partner
    Private _Contacts As Contacts 'Partner kapcsolat, ha van kiválasztás akkor aut. partner
    Private _RegistryType As RegistryType 'Iktatás típusa
    Private _RegistryAcceptState As eRegistryAcceptState 'Elfogadva, vagy elutasítva
    Private _ShortName As String 'Megnevezés
    Private _DocumentNumber As String 'Bizonylatszám
    Private _RegistryNumber As String 'Iktatószám (a gép adja)
    Private _JobNumberObjects As JobNumberObjects 'Munkaszám
    Private _UniqueObjects As UniqueObjects 'Egyedi
    Private _DateCreated As Date = Now ' Dátum
    Private _DeliveryType As eDeliveryType 'Érkezés küldés módja
    Private _ReturnType As eDeliveryType ' Visszaküldés módja
    Private _DateReturn As Date 'Visszaküldés dátuma
    Private _RegistryRows As XPCollection(Of RegistryRows) 'Iktató sorok
    Private _DocumentFile As FileData
    Private _IsEditable As Boolean = True 'Szerkeszthetõ vagy végleges
    Private _IsStorno As Boolean = False
    Private _IsTemplate As Boolean = False
    Private _CurrentWorkflowSystemSteps As WorkflowSystemSteps 'Hanyadik lépésnél tart a dolog
    Private _HRResponsible As HRPerson 'Fõfelelõs
    Private _F_ConnectInfo As String 'Pontozási azonosító (mínuszos számlák miatt)
    Private _F_AdvanceAsk As RegistryHeader 'Ha elõlegszámla akkor a hozzá tartozó elõleg bekérõ megadása kötelezõ
    Private _F_FinalInvoice As RegistryHeader ' Ha elõlegszámla akkor melyik végszámlához tartozik
    Private _F_DateCreated As Date 'Számla kiállítási dátuma
    Private _F_DateExecution As Date 'Számla teljesítési dátuma
    Private _F_DateVAT As Date ' -- ÁFA dátuma
    Private _F_VATAvowalType As eVATAvowalType 'ÁFA bevallás módja
    Private _F_DatePayment As Date ' Számla fizetési határideje
    Private _F_AmountBruttoHUF As Double 'A számla végösszege bruttó HUF
    Private _F_AmountBruttoDEV As Double 'A számla végösszege bruttó DEV
    Private _F_CurrencyRate As Double = 1 'Árfolyam, ha nem HUF
    Private _F_CurrencyName As CurrencyName ' A számla devizaneme
    Private _F_CustomerBankAccounts As CustomerBankAccounts 'Partner bankszámlaszáma
    Private _F_IsImported As Boolean = False 'Fõkönyvbe be lett e már rögzítve
    Private _F_GLAccounts As GLAccounts 'A fõkönyvbe feladott szla
    Private _F_Paymode As ePayMode = ePayMode.NotSet
    Private _F_BookEntryErrorString As String = "" 'A szállítói számla, akkor a szállítói számla feladásakor feladási hibaüzenet.
    Private _F_ReadyforBookEntry As Boolean = False
    Private _BruttoAmountRemaining As Double 'ÁFÁ-ra bontás mennyi van még
    Private _BruttoAmountRemainingBank As Double = 0 'Utalásra bontásból mennyi van még
    Private _NettoAmountRemaining As Double 'Nettóra bontás mennyi van még
    Private _CauseOfRefuse As String ' -- Visszaküldés oka 
    Private _CRM_Opportunities As CRM_Opportunities
    Private _UserCreated As User 'Létrehozta

    '// Nonpersistent propertyk annak érdekében, hogy ÁFA + Számlaigazolás gyorsabb legyen

    Private _row_VAT As VAT
    Private _row_VAT_BruttoAmount As Double

    '// Nonpersistent propertyk a gyors számlaigazolás elkészítéséhez

    Private _row_RRFC_Controlling As Controlling
    Private _row_RRFC_CostPlace As CostPlace
    Private _row_RRFC_CostHolder As CostHolder
    Private _row_RRFC_UniqueObjects As UniqueObjects
    Private _row_RRFC_JobNumberObjects As JobNumberObjects
    Private _row_RRFC_Note As String
    Private _row_RRFC_Amount As Double
    Private _row_RRFC_ContractRows As ContractRows

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
        RegistryAcceptState = 0
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.DeliveryType = eDeliveryType.ePostal
        Me.F_CurrencyName = Session.FindObject(Of CurrencyName)(1, CriteriaOperator.Parse("ShortName='HUF'"))
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) = True Then
            If RegistryNumber = "" And IsEditable = False Then
                DateCreated = GetSQLTime(Session)
            End If
        End If
        If Me.RegistryNumber = "" Then
            If Me.RegistryType IsNot Nothing Then
                Me.RegistryNumber = Me.RegistryType.NumberGenerator.GetNewNumber(Me.RegistryType.NumberGenerator, Year(Me.DateCreated).ToString, Month(Me.DateCreated).ToString)
            End If
        End If
        If Session.IsNewObject(Me) Then
            Dim _UserCreated As User = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))

            If _RegistryType IsNot Nothing Then
                If _RegistryType.AutomaticSetResponsible = True Then
                    Dim _HRPerson As HRPerson = Session.FindObject(Of HRPerson)(CriteriaOperator.Parse("User=?", _UserCreated))
                    If _HRPerson IsNot Nothing Then
                        Me.HRResponsible = _HRPerson
                    End If
                End If
            End If
            Me.UserCreated = _UserCreated
        End If
    End Sub

    <RuleRequiredField("Registry-CustomersFrom", "RegistryNextStep_Context")> _
    <ImmediatePostData(True)> _
    Property CustomersFrom() As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(ByVal value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("Registry-Customers", "RegistryNextStep_Context")> _
    <ImmediatePostData()> _
    Property Customers As Customers
        Get
            Return _Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("Customers", _Customers, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.F_CustomerBankAccounts = Nothing
            End If
        End Set
    End Property
    Property Contacts As Contacts
        Get
            Return _Contacts
        End Get
        Set(ByVal value As Contacts)
            SetPropertyValue("Contacts", _Contacts, value)
            'If value Is Nothing Then
            'Else
            '    Customers = value.Customers
            'End If
        End Set
    End Property
    <RuleRequiredField("Registry-ShortName", "RegistryNextStep_Context")> _
    <Size(100)> _
    Property ShortName() As String
        Get
            Return _ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <RuleRequiredField("Registry-RegistryType Save", DefaultContexts.Save)>
    <RuleRequiredField("Registry-RegistryType", "RegistryNextStep_Context")>
    <ImmediatePostData(True), DataSourceCriteria("CustomersFrom = '@This.CustomersFrom' and RegistryMainType<>4 and RegistryGLAccount=False")>
    Property RegistryType() As RegistryType
        Get
            Return _RegistryType
        End Get
        Set(ByVal value As RegistryType)
            SetPropertyValue("RegistryType", _RegistryType, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If Me.CurrentWorkflowSystemSteps Is Nothing Then
                    If Me.RegistryType.WorkflowSystem Is Nothing Then
                    Else
                        CurrentWorkflowSystemSteps = Session.FindObject(Of WorkflowSystemSteps)(1, CriteriaOperator.Parse("StepIndex=1 and WorkflowSystem=?", Me.RegistryType.WorkflowSystem))
                    End If
                End If
                If Me.CustomersFrom IsNot Nothing And value IsNot Nothing Then
                    If Me.IsEditable = True Then
                        If Me.RegistryNumber = "" Or Me.RegistryNumber Is Nothing Then
                            RegistryNumber = Me.RegistryType.NumberGenerator.GetNewNumber(Me.RegistryType.NumberGenerator, DateCreated.Date.Year.ToString, DateCreated.Date.Month.ToString)
                            Me.Save()
                            Session.CommitTransaction()
                        End If
                    End If
                End If
            End If
        End Set
    End Property
    <ImmediatePostData(True)>
    Property RegistryAcceptState As eRegistryAcceptState
        Get
            Return _RegistryAcceptState
        End Get
        Set(ByVal value As eRegistryAcceptState)
            SetPropertyValue("RegistryAcceptState", _RegistryAcceptState, value)
        End Set
    End Property
    <RuleRequiredField("Registry-DocumentNumber", "RegistryNextStep_Context", TargetCriteria:="RegistryAcceptState=0 AND RegistryType.RegistryMainType = 0")>
    Property DocumentNumber() As String
        Get
            Return _DocumentNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If F_ConnectInfo <> value Then
                    F_ConnectInfo = value
                End If
            End If
        End Set
    End Property
    Property RegistryNumber() As String
        Get
            Return _RegistryNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("RegistryNumber", _RegistryNumber, value)
        End Set
    End Property
    Property JobNumberObjects() As JobNumberObjects
        Get
            Return _JobNumberObjects
        End Get
        Set(ByVal value As JobNumberObjects)
            SetPropertyValue("JobNumberObjects", _JobNumberObjects, value)
        End Set
    End Property
    Property UniqueObjects() As UniqueObjects
        Get
            Return _UniqueObjects
        End Get
        Set(ByVal value As UniqueObjects)
            SetPropertyValue("UniqueObjects", _UniqueObjects, value)
        End Set
    End Property
    Property DateCreated() As Date
        Get
            Return _DateCreated
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateCreated", _DateCreated, value)
        End Set
    End Property
    <RuleRequiredField("RegistryHeader-DeliveryType", "RegistryNextStep_Context")>
    Property DeliveryType() As eDeliveryType
        Get
            Return _DeliveryType
        End Get
        Set(ByVal value As eDeliveryType)
            SetPropertyValue("DeliveryType", _DeliveryType, value)
        End Set
    End Property
    Property ReturnType As eDeliveryType
        Get
            Return _ReturnType
        End Get
        Set(ByVal value As eDeliveryType)
            SetPropertyValue("ReturnType", _ReturnType, value)
        End Set
    End Property
    Property DateReturn As Date
        Get
            Return _DateReturn
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateReturn", _DateReturn, value)
        End Set
    End Property


    <RuleRequiredField("RegistryHeader.DocumentFile_If_Financial_Registry", "RegistryNextStep_Context", TargetCriteria:="DeliveryType<>'ePhone'")>
    <Aggregated(), ExpandObjectMembers(ExpandObjectMembers.Never)>
    Property DocumentFile() As FileData
        Get
            Return _DocumentFile
        End Get
        Set(ByVal value As FileData)
            SetPropertyValue("DocumentFile", _DocumentFile, value)
        End Set
    End Property
    Property IsEditable As Boolean
        Get
            Return _IsEditable
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property
    Property IsStorno As Boolean
        Get
            Return _IsStorno
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsStorno", _IsStorno, value)
        End Set
    End Property
    Property IsTemplate As Boolean
        Get
            Return _IsTemplate
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsTemplate", _IsTemplate, value)
        End Set
    End Property
    <RuleRequiredField("RegistryHeader.HRResponsible_If_Financial_Registry", "RegistryNextStep_Context", "RegistryType.RegistryMainType = 0")>
    Property HRResponsible As HRPerson
        Get
            Return _HRResponsible
        End Get
        Set(ByVal value As HRPerson)
            SetPropertyValue("HRResponsible", _HRResponsible, value)
        End Set
    End Property
    <VisibleInDetailView(False)>
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(ByVal value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    '<RuleRequiredField("AdvanceAsk required if main type is InvoiceAdvance", DefaultContexts.Save, TargetCriteria:="RegistryType.RegistryMainType = 2")> _
    '<ImmediatePostData(True), DataSourceCriteria("RegistryType.RegistryMainType = 3 AND CustomersFrom = '@This.CustomersFrom' AND Customers='@This.Customers'")> _
    'Property F_AdvanceAsk As RegistryHeader
    '    Get
    '        Return _F_AdvanceAsk
    '    End Get
    '    Set(ByVal value As RegistryHeader)
    '        SetPropertyValue("F_AdvanceAsk", _F_AdvanceAsk, value)
    '    End Set
    'End Property
    'Property F_FinalInvoice As RegistryHeader
    '    Get
    '        Return _F_FinalInvoice
    '    End Get
    '    Set(ByVal value As RegistryHeader)
    '        SetPropertyValue("F_FinalInvoice", _F_FinalInvoice, value)
    '    End Set
    'End Property
    <RuleRequiredField("RegistryHeader.F_DateCreated_If_Financial_Registry", "RegistryNextStep_Context", TargetCriteria:="RegistryType.RegistryMainType = 0")>
    Property F_DateCreated As Date
        Get
            Return _F_DateCreated
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("F_DateCreated", _F_DateCreated, value)
        End Set
    End Property
    <RuleRequiredField("RegistryHeader.F_DateExecution_If_Financial_Registry", "RegistryNextStep_Context", TargetCriteria:="RegistryType.RegistryMainType = 0")>
    Property F_DateExecution As Date
        Get
            Return _F_DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("F_DateExecution", _F_DateExecution, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                Me.F_DateVAT = value
                If F_PayMode = ePayMode.InContinuous Then
                    F_DatePayment = value
                End If
                If F_CurrencyName IsNot Nothing Then
                    If F_CurrencyName.ShortName <> "HUF" Then
                        Dim _CurrencyRate_MNB_Collection = New XPCollection(Of CurrencyRate)(Session,
                            CriteriaOperator.Parse("CurrencyName=? and IsMNB=True and GetDate(DateValid)<=?",
                             F_CurrencyName, value.Date))
                        _CurrencyRate_MNB_Collection.Sorting.Add(New SortProperty("DateValid", DB.SortingDirection.Descending))
                        If _CurrencyRate_MNB_Collection.Count > 0 Then
                            For Each _CurrencyRate_MNB In _CurrencyRate_MNB_Collection
                                If _CurrencyRate_MNB.DateValid.Date = F_DateExecution.Date Then
                                    F_CurrencyRate = _CurrencyRate_MNB.RateAverage
                                    Exit For
                                End If
                                Exit For
                            Next
                        End If
                    End If
                End If
            End If
        End Set
    End Property
    <ImmediatePostData(True)>
    Property F_DateVAT As Date
        Get
            Return _F_DateVAT
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("F_DateVAT", _F_DateVAT, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                If Me.RegistryRowsFinancial.Count > 0 Then
                    For Each _RegistryRowsFinancial As RegistryRowsFinancial In Me.RegistryRowsFinancial
                        If Not _RegistryRowsFinancial.DateVAT = value Then
                            _RegistryRowsFinancial.DateVAT = value
                        End If
                    Next
                End If
            End If
        End Set
    End Property
    Property F_VATAvowalType As eVATAvowalType
        Get
            Return _F_VATAvowalType
        End Get
        Set(value As eVATAvowalType)
            SetPropertyValue("F_VATAvowalType", _F_VATAvowalType, value)
        End Set
    End Property
    <RuleRequiredField("RegistryHeader.F_DatePayment_If_Financial_Registry", "RegistryNextStep_Context", TargetCriteria:="RegistryType.RegistryMainType = 0")>
    Property F_DatePayment As Date
        Get
            Return _F_DatePayment
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("F_DatePayment", _F_DatePayment, value)
        End Set
    End Property
    <ImmediatePostData()>
    Property F_AmountBruttoHUF As Double
        Get
            Return _F_AmountBruttoHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("F_AmountBruttoHUF", _F_AmountBruttoHUF, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If Me.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                    row_VAT = Session.FindObject(Of VAT)(CriteriaOperator.Parse("DefaultForBusinnes=True"))
                    row_VAT_BruttoAmount = value
                End If
            End If
        End Set
    End Property
    Property F_AmountBruttoDEV As Double
        Get
            Return _F_AmountBruttoDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("F_AmountBruttoDEV", _F_AmountBruttoDEV, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                Me.F_AmountBruttoHUF = Math.Round((Me.F_AmountBruttoDEV * F_CurrencyRate), 0, MidpointRounding.AwayFromZero)
            End If
        End Set
    End Property

    <ImmediatePostData(True)>
    Property F_CurrencyRate As Double
        Get
            Return _F_CurrencyRate
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("F_CurrencyRate", _F_CurrencyRate, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                Me.F_AmountBruttoHUF = Math.Round((Me.F_AmountBruttoDEV * F_CurrencyRate), 0, MidpointRounding.AwayFromZero)
            End If
        End Set
    End Property
    <ImmediatePostData(True)>
    <RuleRequiredField("RegistryHeader.F_CurrencyName_If_Financial_Registry", "RegistryNextStep_Context", TargetCriteria:="RegistryType.RegistryMainType = 0")>
    Property F_CurrencyName As CurrencyName
        Get
            Return _F_CurrencyName
        End Get
        Set(ByVal value As CurrencyName)
            SetPropertyValue("F_CurrencyName", _F_CurrencyName, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                If F_CurrencyName IsNot Nothing Then
                    If F_CurrencyName.ShortName <> "HUF" Then
                        Dim _CurrencyRate_MNB_Collection = New XPCollection(Of CurrencyRate)(Session,
                            CriteriaOperator.Parse("CurrencyName=? and IsMNB=True and GetDate(DateValid)<=?",
                             F_CurrencyName, F_DateExecution.Date))
                        _CurrencyRate_MNB_Collection.Sorting.Add(New SortProperty("DateValid", DB.SortingDirection.Descending))
                        If _CurrencyRate_MNB_Collection.Count > 0 Then
                            For Each _CurrencyRate_MNB In _CurrencyRate_MNB_Collection
                                If _CurrencyRate_MNB.DateValid.Date = F_DateExecution.Date Then
                                    F_CurrencyRate = _CurrencyRate_MNB.RateAverage
                                    Exit For
                                End If
                                Exit For
                            Next
                        End If
                    End If
                End If
            End If
        End Set
    End Property
    <RuleRequiredField("RegistryHeader.F_CustomerBankAccount_If_Financial_Registry", "RegistryNextStep_Context", TargetCriteria:="RegistryType.RegistryMainType in (0,3) AND F_PayMode = 1")>
    <ImmediatePostData(True), DataSourceCriteria("Customers='@This.Customers'")>
    Property F_CustomerBankAccounts As CustomerBankAccounts
        Get
            Return _F_CustomerBankAccounts
        End Get
        Set(ByVal value As CustomerBankAccounts)
            SetPropertyValue("F_CustomerBankAccounts", _F_CustomerBankAccounts, value)
        End Set
    End Property
    <RuleValueComparison("RuleValue-PayMode-RegistryHeader", "RegistryNextStep_Context", ValueComparisonType.NotEquals, ePayMode.NotSet, TargetCriteria:="RegistryType.RegistryMainType=0")>
    <ImmediatePostData()>
    Property F_PayMode As ePayMode
        Get
            Return _F_Paymode
        End Get
        Set(ByVal value As ePayMode)
            SetPropertyValue("F_PayMode", _F_Paymode, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                If value = ePayMode.InContinuous Then
                    F_DatePayment = _F_DateExecution
                End If
                If value = ePayMode.InCash Then
                    F_DateExecution = F_DateCreated
                    F_DatePayment = F_DateCreated
                End If
            End If
        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

    Property F_IsImported As Boolean
        Get
            Return _F_IsImported
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("F_IsImported", _F_IsImported, value)
        End Set
    End Property
    Property F_GLAccounts As GLAccounts
        Get
            Return _F_GLAccounts
        End Get
        Set(ByVal value As GLAccounts)
            SetPropertyValue("F_GLAccounts", _F_GLAccounts, value)
        End Set
    End Property
    <Size(255)>
    Property F_BookEntryErrorString As String
        Get
            Return _F_BookEntryErrorString
        End Get
        Set(ByVal value As String)
            SetPropertyValue("F_BookEntryErrorString", _F_BookEntryErrorString, value)
        End Set
    End Property
    Property F_ReadyforBookEntry As Boolean
        Get
            Return _F_ReadyforBookEntry
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("F_ReadyforBookEntry", _F_ReadyforBookEntry, value)
        End Set
    End Property
    <VisibleInDetailView(False)>
    Property F_ConnectInfo As String
        Get
            Return _F_ConnectInfo
        End Get
        Set(value As String)
            SetPropertyValue("F_ConnectInfo", _F_ConnectInfo, value)
        End Set
    End Property

    ReadOnly Property F_IsBookEntry As Boolean
        Get
            If _F_GLAccounts IsNot Nothing Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property
    <NonPersistent()>
    <ImmediatePostData()>
    Property BruttoAmountRemaining As Double
        Get
            Dim _RowsAmount As Double = 0
            Dim _RegistryRowsFinancial As RegistryRowsFinancial
            For Each _RegistryRowsFinancial In Me.RegistryRowsFinancial
                If Session.IsNewObject(_RegistryRowsFinancial) = False Then
                    _RowsAmount += _RegistryRowsFinancial.BruttoAmount
                End If
            Next
            _BruttoAmountRemaining = F_AmountBruttoHUF - _RowsAmount
            Return Math.Round(_BruttoAmountRemaining, 2, MidpointRounding.AwayFromZero)
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("BruttoAmountRemainig", _BruttoAmountRemaining, value)
        End Set
    End Property
    <NonPersistent()>
    <ImmediatePostData()>
    Property NettoAmountRemaining As Double
        Get
            Dim _RowsAmount As Double = 0
            Dim _VATAmount As Double = 0
            Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
            Dim _RegistryRowsFinancial As RegistryRowsFinancial
            For Each _RegistryRowsFinancial In Me.RegistryRowsFinancial
                If _RegistryRowsFinancial.VAT IsNot Nothing Then
                    _VATAmount += _RegistryRowsFinancial.BruttoAmount / (100 + _RegistryRowsFinancial.VAT.KeyValuePercent) * _RegistryRowsFinancial.VAT.KeyValuePercent
                Else

                End If
            Next
            _VATAmount = Math.Round(_VATAmount, 0, MidpointRounding.AwayFromZero)
            For Each _RegistryRowsFinancialControlling In Me.RegistryRowsFinancialControlling
                If Session.IsNewObject(_RegistryRowsFinancialControlling) = False Then
                    _RowsAmount += _RegistryRowsFinancialControlling.Amount
                End If
            Next
            _NettoAmountRemaining = F_AmountBruttoHUF - _VATAmount - _RowsAmount
            'Me.row_RRFC_Amount = _NettoAmountRemaining
            Return Math.Round(_NettoAmountRemaining, 2, MidpointRounding.AwayFromZero)
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("NettoAmountRemainig", _NettoAmountRemaining, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                If RegistryType IsNot Nothing Then
                    If RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                        If Me.row_RRFC_ContractRows Is Nothing Then
                            'Me.row_RRFC_Amount = value
                        End If
                    End If
                End If
                value = Math.Round(value, 2, MidpointRounding.AwayFromZero)
            End If

        End Set
    End Property
    <NonPersistent()>
    Property BruttoAmountRemainingBank As Double
        Get
            If Me._F_Paymode = ePayMode.InTransfer Then
                Dim _RowsAmountHUF As Double = 0
                Dim _RegistryBankTransfer As RegistryBankTransfer
                For Each _RegistryBankTransfer In Me.RegistryBankTransfer
                    _RowsAmountHUF += _RegistryBankTransfer.AmountHUF
                Next
                _BruttoAmountRemainingBank = F_AmountBruttoHUF - _RowsAmountHUF
                Return _BruttoAmountRemainingBank
            Else
                Return 0
            End If
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("BruttoAmountRemainigBank", _BruttoAmountRemainingBank, value)
        End Set
    End Property
    Property CauseOfRefuse As String
        Get
            Return _CauseOfRefuse
        End Get
        Set(ByVal value As String)
            SetPropertyValue("CauseOfRefuse", _CauseOfRefuse, value)
        End Set
    End Property
    ' <Browsable(False)> _ 
    <ImmediatePostData(True), DataSourceCriteria("CustomersFrom='@This.CustomersFrom' and Customers='@This.Customers'")>
    Property CRM_Opportunities As CRM_Opportunities
        Get
            Return _CRM_Opportunities
        End Get
        Set(ByVal value As CRM_Opportunities)
            SetPropertyValue("CRM_Opportunities", _CRM_Opportunities, value)
        End Set
    End Property
    ReadOnly Property HasTransferedBank As Boolean ' -- van e a számlának utalási csomagba tett tétele? mert akkor nem szabad módosítani a számla összegét!
        Get
            Dim _HasTransferedBank As Boolean = False
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                If Me.RegistryBankTransfer.Count > 0 Then
                    For Each _RegistryBankTransfer As RegistryBankTransfer In Me.RegistryBankTransfer
                        If Not _RegistryBankTransfer.BankSavedFileName = "" Then
                            _HasTransferedBank = True
                        End If
                    Next
                End If
            End If
            Return _HasTransferedBank
        End Get
    End Property
    <VisibleInDetailView(False)>
    ReadOnly Property DisplayName As String
        Get
            If RegistryType IsNot Nothing And RegistryNumber IsNot Nothing And Customers IsNot Nothing Then
                Return RegistryType.ShortName & ", " & RegistryNumber & ", " & Customers.FullName
            Else
                Return ""
            End If
        End Get
    End Property


    '// Nonpersistent propertyk VAT igazoláshoz
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)>
    Property row_VAT As VAT
        Get
            Return _row_VAT
        End Get
        Set(value As VAT)
            SetPropertyValue("row_VAT", _row_VAT, value)
        End Set
    End Property
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)>
    Property row_VAT_BruttoAmount As Double
        Get
            Return _row_VAT_BruttoAmount
        End Get
        Set(value As Double)
            SetPropertyValue("row_VAT_BruttoAmount", _row_VAT_BruttoAmount, value)
        End Set
    End Property

    '// Nonpersistent propertyk RRFC igazoláshoz 
    <NonPersistent(), VisibleInListView(False), VisibleInLookupListView(False)>
    <RuleRequiredField("RegistryHeader-row_RRFC_Controlling", "aToTable_RRFC_Contexts", TargetCriteria:="RegistryType.Rule5DMatrix.RequireControlling")>
    <RuleRequiredField("RegistryHeader-row_RRFC_Controlling_T", "aToTable_RRFC_With_TContract_Contexts", TargetCriteria:="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("RegistryHeader-row_RRFC_CostPlace", "aToTable_RRFC_Contexts", TargetCriteria:="RegistryType.Rule5DMatrix.RequireCostPlace")>
    <RuleRequiredField("RegistryHeader-row_RRFC_CostPlace_T", "aToTable_RRFC_With_TContract_Contexts", TargetCriteria:="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("RegistryHeader-row_RRFC_CostHolder", "aToTable_RRFC_Contexts", TargetCriteria:="RegistryType.Rule5DMatrix.RequireCostHolder")>
    <RuleRequiredField("RegistryHeader-row_RRFC_CostHolder_T", "aToTable_RRFC_With_TContract_Contexts", TargetCriteria:="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)>
    <RuleRequiredField("RegistryHeader-row_RRFC_JobNumberObjects", "aToTable_RRFC_RegistryTask_Contexts", TargetCriteria:="RegistryType.Rule5DMatrix.RequireJobNumberObjects")>
    <RuleRequiredField("RegistryHeader-row_RRFC_JobNumberObjects_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", TargetCriteria:="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("RegistryHeader-row_RRFC_UniqueObjects", "aToTable_RRFC_RegistryTask_Contexts", TargetCriteria:="RegistryType.Rule5DMatrix.RequireUniqueObjects")>
    <RuleRequiredField("RegistryHeader-row_RRFC_UniqueObjects_T", "aToTable_RRFC_With_TContract_RegistryTask_Contexts", TargetCriteria:="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_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)>
    <RuleRequiredField("RegistryHeader-row_RRFC_ContractRows", "aToTable_RRFC_Contexts")>
    <ImmediatePostData(True), DataSourceCriteria("Contracts.ContractTemplate.PartnerType=1 and Contracts.Customers='@This.Customers' and Contracts.CustomersFrom ='@This.CustomersFrom' AND Contracts.ContractTemplate.IsTechnical=False AND (Contracts.State = 1 OR Contracts.State = 2) and IsNull(RegistryRowsFinancialControlling)=True and Contracts.CurrencyName.ShortName='@This.F_CurrencyName.ShortName'")>
    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_UniqueObjects = value.UniqueObjects
                    row_RRFC_Note = value.Description
                    row_RRFC_CostHolder = value.CostHolder
                    row_RRFC_CostPlace = value.CostPlace
                    row_RRFC_JobNumberObjects = value.JobNumberObjects

                    If Me.F_CurrencyName.ShortName <> "HUF" Then
                        row_RRFC_Amount = Math.Round(value.NettoPriceDEV * Me.F_CurrencyRate, 0, MidpointRounding.AwayFromZero)
                    Else
                        Me.row_RRFC_Amount = value.NettoPriceHUF
                    End If
                End If
            End If
        End Set
    End Property


    <VisibleInListView(False), VisibleInLookupListView(False), VisibleInDetailView(False)> _
    ReadOnly Property IsVATClosed As Boolean
        Get
            Dim _Closed As Boolean = False
            If Me.CustomersFrom IsNot Nothing Then
                If Me.RegistryType IsNot Nothing Then
                    Select Case Me.RegistryType.RegistryMainType
                        Case eRegistryMainType.eAccount, eRegistryMainType.eInvoiceAdvance, eRegistryMainType.eInvoiceFinal
                            Dim _VATReport As VATReport = Session.FindObject(Of VATReport) _
                            (CriteriaOperator.Parse("GetDate(DateFrom)<=? and GetDate(DateTo)>=? and CustomersFrom=? and Closed=True", _
                            Me.F_DateVAT.Date, Me.F_DateVAT.Date, Me.CustomersFrom))
                            If _VATReport IsNot Nothing Then
                                _Closed = _VATReport.Closed
                            End If
                    End Select
                End If
            End If
            Return _Closed
        End Get
    End Property

    '-- XPCollections -------------------
    <Association("RegistryHeader-RegistryRows", GetType(RegistryRows)), VisibleInListView(False)> _
    ReadOnly Property RegistryRows() As XPCollection(Of RegistryRows)
        Get
            Return GetCollection(Of RegistryRows)("RegistryRows")
        End Get
    End Property
    <Association("RegistryHeader-RegistryRowsFinancial", GetType(RegistryRowsFinancial)), VisibleInListView(False)> _
    ReadOnly Property RegistryRowsFinancial() As XPCollection(Of RegistryRowsFinancial)
        Get
            Return GetCollection(Of RegistryRowsFinancial)("RegistryRowsFinancial")
        End Get
    End Property
    <Association("RegistryHeader-RegistryRowsFinancialControlling", GetType(RegistryRowsFinancialControlling)), VisibleInListView(False)> _
    ReadOnly Property RegistryRowsFinancialControlling() As XPCollection(Of RegistryRowsFinancialControlling)
        Get
            Return GetCollection(Of RegistryRowsFinancialControlling)("RegistryRowsFinancialControlling")
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property RegistryTasks As XPCollection(Of RegistryTasks)
        Get
            Return New XPCollection(Of RegistryTasks)(Session, CriteriaOperator.Parse("RegistryHeader=?", Me))
        End Get
    End Property
    <Association("RegistryHeader-RegistryFileData", GetType(RegistryFileData)), VisibleInListView(False)> _
    ReadOnly Property RegistryFileData As XPCollection(Of RegistryFileData)
        Get
            Return GetCollection(Of RegistryFileData)("RegistryFileData")
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property PCIDetail As XPCollection(Of PCIDetail)
        Get
            If Session.IsNewObject(Me) = False Then
                If Me.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                    Return New XPCollection(Of PCIDetail)(Session, _
                               CriteriaOperator.Parse("CustomersFrom=? and Customers=? and PartnerType=1 and ConnectInfo=?", _
                                                      Me.CustomersFrom, Me.Customers, Me.DocumentNumber))
                Else
                    Return Nothing
                End If
            Else
                Return Nothing
            End If
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property WorkFlowCollection As XPCollection(Of WorkflowSystemSteps)
        Get
            If Me.RegistryType Is Nothing Then
                Return Nothing
            End If
            If Me.RegistryType.WorkflowSystem Is Nothing Then
                Return Nothing
            End If
            Dim _WorkFlowSystemSteps_Collection As New XPCollection(Of WorkflowSystemSteps)(Session, CriteriaOperator.Parse("WorkflowSystem=?", Me.RegistryType.WorkflowSystem))
            Return _WorkFlowSystemSteps_Collection
        End Get
    End Property
    <Association("RegistryHeader-RegistryBankTransfer", GetType(RegistryBankTransfer)), VisibleInListView(False)> _
    ReadOnly Property RegistryBankTransfer As XPCollection(Of RegistryBankTransfer)
        Get
            Return GetCollection(Of RegistryBankTransfer)("RegistryBankTransfer")
        End Get
    End Property
    <Browsable(False)> _
    ReadOnly Property ChartOfAccountsYearIsClosed As Boolean
        Get
            If Me.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                Dim _ChartOfAccountsYear As ChartOfAccountsYear = Session.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", Me.F_DateExecution.Year))
                If _ChartOfAccountsYear Is Nothing Then
                    Return True
                Else
                    Return _ChartOfAccountsYear.IsClosed
                End If
            Else
                Return False
            End If
        End Get
    End Property
    '--Metódusok -----------------------------------
    '<EditorStateRule("ESR_F_CurrencyRate", "F_CurrencyRate", ViewType.DetailView)> _
    '<Appearance("ESR_F_CurrencyRate", TargetItems:="F_CurrencyRate", Criteria:="F_CurrencyName.ShortName = 'HUF'", Visibility:=Editors.ViewItemVisibility.Hide, Context:="DetailView")> _
    'Public Function ESR_F_CurrencyRate(<System.Runtime.InteropServices.Out()> ByRef active As Boolean) As EditorState
    '    active = _F_CurrencyName.ShortName = "HUF"
    '    Return EditorState.Hidden
    'End Function
    ' <EditorStateRule("EFR_RegistryBankTransfer", "RegistryBankTransfer;BruttoAmountRemainingBank", ViewType.DetailView)> _
    '<Appearance("EFR_RegistryBankTransfer", TargetItems:="RegistryBankTransfer;BruttoAmountRemainingBank", Criteria:="Not ((F_PayMode = ePayMode.InTransfer Or F_PayMode = ePayMode.InContinuous) And Me.RegistryType.RegistryMainType = eRegistryMainType.eAccount)", Visibility:=Editors.ViewItemVisibility.Hide, Context:="DetailView")> _
    'Public Function ESR_F_RegistryBankTransfer(<System.Runtime.InteropServices.Out()> ByRef active As Boolean) As EditorState
    '    If Me.RegistryType IsNot Nothing Then
    '        active = Not ((F_PayMode = ePayMode.InTransfer Or F_PayMode = ePayMode.InContinuous) And Me.RegistryType.RegistryMainType = eRegistryMainType.eAccount)
    '        Return EditorState.Hidden
    '    End If
    'End Function
    Sub BookEntryRemove(ByVal _p_RegistryHeader As RegistryHeader, ByVal _uow As UnitOfWork, Optional ByVal _WithCommit As Boolean = False, Optional _KeepReady As Boolean = False)
        'Az eljárás visszavon egy feladást a fõkönyvbõl
        Dim _RegistryRowsFinancial As RegistryRowsFinancial
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling

        Dim _RegistryHeader As RegistryHeader = _uow.GetObjectByKey(Of RegistryHeader)(_p_RegistryHeader.Oid)

        Dim _ChartOfAccountsYear As ChartOfAccountsYear = _uow.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", _RegistryHeader.F_DateExecution.Year))
        If _ChartOfAccountsYear.IsClosed Then
            _RegistryHeader.F_BookEntryErrorString = String.Format("Zárolt főkönyvi év ! {0}", _RegistryHeader.F_DateExecution.Year.ToString)
            _RegistryHeader.Save()
            If _WithCommit Then _uow.CommitTransaction()
            Exit Sub
        End If

        Dim _GLRows_Collection As New XPCollection(Of GLRows)(_uow, CriteriaOperator.Parse("GLHeader.Oid=?", _RegistryHeader.F_GLAccounts.Oid))
        _uow.Delete(_GLRows_Collection)
        Dim _GLAccounts_Collection As New XPCollection(Of GLAccounts)(_uow, CriteriaOperator.Parse("Oid=?", _RegistryHeader.F_GLAccounts.Oid))
        _uow.Delete(_GLAccounts_Collection)

        _RegistryHeader.F_GLAccounts = Nothing
        _RegistryHeader.F_ReadyforBookEntry = False

        For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
            If _KeepReady = False Then _RegistryRowsFinancial.F_ReadyforBookEntryRows = False
        Next

        For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
            If _KeepReady = False Then _RegistryRowsFinancialControlling.F_ReadyforBookEntryRows = False
        Next

        If _WithCommit Then _uow.CommitChanges()
    End Sub
    Sub BookEntry(ByVal _p_BookEntryMode As Long, ByVal _p_RegistryHeader As RegistryHeader, ByVal _uow As UnitOfWork, Optional ByVal _WithCommit As Boolean = False)
        ' Az eljárás feladást készít errõl a számláról
        ' BookentryMode=0 akkor tételes fealás
        ' BookentryMode=1 akkor jelölõadatokra csoportosított feladás
        If _p_RegistryHeader Is Nothing Then Exit Sub

        Dim _RegistryHeader As RegistryHeader = _uow.GetObjectByKey(Of RegistryHeader)(_p_RegistryHeader.Oid)
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Dim _RegistryRowsFinancial As RegistryRowsFinancial
        Dim _GLAccounts As GLAccounts
        Dim _GLRows As GLRows
        Dim _CreditChartOfAccounts As ChartOfAccounts
        Dim _GUID As Guid = Guid.NewGuid
        Dim _DebitChartOfAccounts As ChartOfAccounts
        Dim _AmountDEV As Double = 0
        ' Megnézi, hogy történt-e már feladás
        If _RegistryHeader.F_GLAccounts IsNot Nothing Then
            BookEntryRemove(_RegistryHeader, _uow, False)
        End If
        If BookEntryCheck(_p_BookEntryMode, _RegistryHeader, _uow, _WithCommit) = False Then

            Exit Sub
        End If
        If _p_BookEntryMode = 0 Then 'Tételes feladás a fõkönyvbe
            _GLAccounts = New GLAccounts(_uow)
            _GLAccounts.AmountDEVBrutto = _RegistryHeader.F_AmountBruttoDEV
            _GLAccounts.AmountHUFBrutto = _RegistryHeader.F_AmountBruttoHUF
            _GLAccounts.ImportedRegistryHeader = _RegistryHeader
            _GLAccounts.Customers = _RegistryHeader.Customers

            If _RegistryHeader.RegistryType.RegistryDirection = eRegistryDirection.eOutput Then
                _GLAccounts.PartnerType = ePartnerType.eReceivables
                _DebitChartOfAccounts = _RegistryHeader.Customers.CustomersGLParameters.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eOut)
            Else
                _GLAccounts.PartnerType = ePartnerType.ePayabels
                _CreditChartOfAccounts = _RegistryHeader.Customers.CustomersGLParameters.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eIn)
            End If

            _GLAccounts.CurrencyName = _RegistryHeader.F_CurrencyName
            _GLAccounts.CurrencyRate = _RegistryHeader.F_CurrencyRate
            _GLAccounts.CustomersFrom = _RegistryHeader.CustomersFrom
            _GLAccounts.DateCreated = _RegistryHeader.F_DateCreated.Date
            _GLAccounts.DateExecution = _RegistryHeader.F_DateExecution.Date
            _GLAccounts.PaymentOption = _uow.FindObject(Of PaymentOption)(CriteriaOperator.Parse("PayMode=?", _RegistryHeader.F_PayMode), True)
            _GLAccounts.DatePayment = _RegistryHeader.F_DatePayment.Date
            _GLAccounts.DocumentFile = _RegistryHeader.DocumentFile
            _GLAccounts.DocumentNumber = _RegistryHeader.DocumentNumber
            _GLAccounts.ConnectInfo = _RegistryHeader.F_ConnectInfo
            _GLAccounts.IsEditable = False
            _GLAccounts.IsStorno = False
            _GLAccounts.NoteHeader = _RegistryHeader.ShortName
            _GLAccounts.RegistryNumber = _RegistryHeader.RegistryNumber


            _GLAccounts.Save()

            _RegistryHeader.F_GLAccounts = _GLAccounts
            _RegistryHeader.Save()
            '--- Nettó sorok
            For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                '-- Netto sor
                _GLRows = New GLRows(_uow)
                _GLRows.ConnectInfoAdvanced = _RegistryRowsFinancialControlling.ConnectInfoAdvanced
                If _RegistryRowsFinancialControlling.DateExecution = Nothing Then
                    _GLRows.DateExecution = _RegistryRowsFinancialControlling.RegistryHeader.F_DateExecution
                Else
                    _GLRows.DateExecution = _RegistryRowsFinancialControlling.DateExecution
                End If

                _GLRows.RegistryRowsFinancialControlling = _RegistryRowsFinancialControlling
                If _RegistryRowsFinancialControlling.ChartOfAccounts Is Nothing Then

                    '// Ha szállítói számláról van szó
                    If _RegistryHeader.RegistryType.RegistryDirection = eRegistryDirection.eOutput Then
                        _CreditChartOfAccounts = _RegistryRowsFinancialControlling.Controlling.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, False)
                    Else
                        If _RegistryRowsFinancialControlling.IsReInvoice = True Then
                            _DebitChartOfAccounts = _RegistryRowsFinancialControlling.Controlling.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, True)
                        Else
                            _DebitChartOfAccounts = _RegistryRowsFinancialControlling.Controlling.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, False)
                        End If
                    End If

                Else
                    _DebitChartOfAccounts = _RegistryRowsFinancialControlling.ChartOfAccounts
                End If
                If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyName.ShortName = "HUF" Then

                    _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _DebitChartOfAccounts, _CreditChartOfAccounts, 0, _
                                       _RegistryRowsFinancialControlling.Amount, Nothing, _RegistryHeader.Customers, _RegistryHeader.F_DateVAT, Nothing, _
                                       _RegistryRowsFinancialControlling.Note, _RegistryRowsFinancialControlling.UniqueObjects, _RegistryRowsFinancialControlling.Controlling, _RegistryRowsFinancialControlling.JobNumberObjects, _
                                       _RegistryRowsFinancialControlling.CostPlace, _RegistryRowsFinancialControlling.CostHolder, _RegistryHeader.F_ConnectInfo, eGLRowsTypeVAT.eNettoRow, _
                                       _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.ePayabels)
                Else
                    If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate <> 0 Then
                        _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _DebitChartOfAccounts, _CreditChartOfAccounts, _RegistryRowsFinancialControlling.Amount / _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate, _
                                           _RegistryRowsFinancialControlling.Amount, Nothing, _RegistryHeader.Customers, _RegistryHeader.F_DateVAT, Nothing, _
                                           _RegistryRowsFinancialControlling.Note, _RegistryRowsFinancialControlling.UniqueObjects, _RegistryRowsFinancialControlling.Controlling, _RegistryRowsFinancialControlling.JobNumberObjects, _
                                           _RegistryRowsFinancialControlling.CostPlace, _RegistryRowsFinancialControlling.CostHolder, _RegistryHeader.F_ConnectInfo, eGLRowsTypeVAT.eNettoRow, _
                                          _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.ePayabels)
                    Else
                        _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _DebitChartOfAccounts, _CreditChartOfAccounts, 0, _
                                           _RegistryRowsFinancialControlling.Amount, Nothing, _RegistryHeader.Customers, _RegistryHeader.F_DateVAT, Nothing, _
                                           _RegistryRowsFinancialControlling.Note, _RegistryRowsFinancialControlling.UniqueObjects, _RegistryRowsFinancialControlling.Controlling, _RegistryRowsFinancialControlling.JobNumberObjects, _
                                           _RegistryRowsFinancialControlling.CostPlace, _RegistryRowsFinancialControlling.CostHolder, _RegistryHeader.F_ConnectInfo, eGLRowsTypeVAT.eNettoRow, _
                                          _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.ePayabels)
                    End If

                End If

            Next
            '-- ÁFA sorok -------------------------------------
            For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
                '-- ÁFA sor
                Dim _VATAmountDEV As Double = 0

                If _RegistryRowsFinancial.RegistryHeader.F_CurrencyRate <> 0 Then
                    If _RegistryRowsFinancial.RegistryHeader.F_CurrencyName.ShortName <> "HUF" Then
                        _VATAmountDEV = Math.Round(_RegistryRowsFinancial.VATAmount / _RegistryRowsFinancial.RegistryHeader.F_CurrencyRate, 2, MidpointRounding.AwayFromZero)
                    End If
                End If
                If _RegistryRowsFinancial.VAT.InversState = True Then
                    _GLRows = New GLRows(_uow)
                    _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _RegistryRowsFinancial.VAT.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eIn), _
                                      _RegistryRowsFinancial.VAT.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eOut), 0, _
                                      Math.Round(_RegistryRowsFinancial.NettoAmount * _RegistryRowsFinancial.VAT.InversKeyValue, 0, MidpointRounding.AwayFromZero), _
                                      Nothing, _RegistryHeader.Customers, _RegistryRowsFinancial.DateVAT, _RegistryRowsFinancial.VAT, _
                                      _RegistryRowsFinancial.Note, Nothing, Nothing, Nothing, _
                                      Nothing, Nothing, _RegistryHeader.F_ConnectInfo, eGLRowsTypeVAT.eVATRow, _
                                      _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.ePayabels)
                    _GLRows = New GLRows(_uow)
                Else
                    _GLRows = New GLRows(_uow)

                    If _RegistryHeader.RegistryType.RegistryDirection = eRegistryDirection.eOutput Then
                        _DebitChartOfAccounts = _RegistryHeader.Customers.CustomersGLParameters.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eOut)
                        _CreditChartOfAccounts = _RegistryRowsFinancial.VAT.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eOut)
                    Else
                        _DebitChartOfAccounts = _RegistryRowsFinancial.VAT.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eIn)
                        _CreditChartOfAccounts = _RegistryHeader.Customers.CustomersGLParameters.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, eVATMode.eIn)
                    End If

                    _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _DebitChartOfAccounts, _CreditChartOfAccounts, _VATAmountDEV, _
                                   _RegistryRowsFinancial.VATAmount, Nothing, _RegistryHeader.Customers, _RegistryRowsFinancial.DateVAT, _RegistryRowsFinancial.VAT, _
                                   _RegistryRowsFinancial.Note, Nothing, Nothing, Nothing, _
                                   Nothing, Nothing, _RegistryHeader.F_ConnectInfo, eGLRowsTypeVAT.eVATRow, _
                                   _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.ePayabels)

                End If

            Next
        ElseIf _p_BookEntryMode = 1 Then '-- Összevont feladás

        End If


        If _WithCommit Then _uow.CommitChanges()
    End Sub
    Function BookEntryCheck(ByVal _BookEntryMode As Long, ByVal _RegistryHeader As RegistryHeader, ByVal _uow As UnitOfWork, Optional ByVal WithCommit As Boolean = False)
        'Feladás elõtti ellenõrzés
        'Mit kell ellenõrizni ?

        'Fõkönyvi számlák, Debit,Credit
        'ÁFA fõkönyvi számlája
        'CM számok
        Dim _ChartOfAccountsYear As ChartOfAccountsYear = _uow.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", _RegistryHeader.F_DateExecution.Year))
        If _ChartOfAccountsYear.IsClosed Then
            _RegistryHeader.F_BookEntryErrorString = String.Format("Zárolt főkönyvi év ! {0}", _RegistryHeader.F_DateExecution.Year.ToString)
            _RegistryHeader.Save()
            _uow.CommitTransaction()
            Return False
        End If

        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Dim _Exists As Boolean = False
        Dim _RegistryTask As RegistryTasks
        Dim _RegistryTask_Collection As New XPCollection(Of RegistryTasks)(_uow, CriteriaOperator.Parse("RegistryHeader=? and Status<>4", _RegistryHeader))
        If _RegistryHeader.F_GLAccounts IsNot Nothing Then
            _RegistryHeader._F_BookEntryErrorString = String.Format("Könyvelve")
            _RegistryHeader.Save()
            _uow.CommitTransaction()
            Return False
        End If

        For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
            _Exists = True
            If _RegistryRowsFinancialControlling.Controlling Is Nothing Then
                'Nincs meadva a kontrollszám
                _RegistryHeader._F_BookEntryErrorString = String.Format("Nincs kontrollszám {0}", _RegistryRowsFinancialControlling.Note)
                _RegistryHeader.Save()
                _uow.CommitTransaction()
                Return False
            Else
                If _RegistryRowsFinancialControlling.Controlling.GetChartOfAccounts(_RegistryHeader.F_DateExecution.Year, _RegistryRowsFinancialControlling.IsReInvoice) Is Nothing Then
                    'Nincs megadva a kontrollszámhoz tartozó FK számla száma
                    _RegistryHeader._F_BookEntryErrorString = String.Format("Nincs fk. számla száma {0}", _RegistryRowsFinancialControlling.Controlling.Name)
                    _RegistryHeader.Save()
                    _uow.CommitTransaction()
                    Return False
                End If
                If _RegistryRowsFinancialControlling.F_ReadyforBookEntryRows = False Then
                    _RegistryHeader._F_BookEntryErrorString = String.Format("Nem könyvelhetõ minden nettó sora !")
                    _RegistryHeader.Save()
                    _uow.CommitTransaction()
                    Return False
                End If
            End If
        Next
        If _Exists = False Then
            _RegistryHeader._F_BookEntryErrorString = String.Format("Nincs teljesítési igazolási sor !")
            _RegistryHeader.Save()
            _uow.CommitTransaction()
            Return False
        End If

        Dim _RegistryRowsFinancial As RegistryRowsFinancial
        For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
            If _RegistryRowsFinancial.F_ReadyforBookEntryRows = False Then
                _RegistryHeader._F_BookEntryErrorString = String.Format("Nem könyvelhető minden ÁFA sora !")
                _RegistryHeader.Save()
                _uow.CommitTransaction()
                Return False
            End If
        Next

        '-- Meg kell nézni, hogy ez az iktatás olyan Task-hoz tartozik e, amely workflowsystemstep IsReadyForImport = True

        For Each _RegistryTask In _RegistryTask_Collection
            If _RegistryTask.CurrentWorkflowSystemSteps.IsReadyForImport = False Then
                _RegistryHeader._F_BookEntryErrorString = String.Format("Nem a lekönyvelhető lépésen van a feladat !")
                _RegistryHeader.Save()
                _uow.CommitTransaction()
                Return False
            End If
        Next
        Return True

    End Function
    Sub RecalculateVAT(_ocur As Xpo.XPObjectSpace, _RegistryHeader As RegistryHeader)

        Dim _NettoAmount_RRF As Double = 0
        Dim _NettoAmount_RRFC As Double = 0
        Dim _NettoDiff As Double = 0

        Dim _RegistryRowsFinancial As RegistryRowsFinancial
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling

        For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
            _NettoAmount_RRF += _RegistryRowsFinancial.NettoAmount
        Next
        For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
            _NettoAmount_RRFC += _RegistryRowsFinancialControlling.Amount
        Next

        _NettoDiff = _NettoAmount_RRF - _NettoAmount_RRFC

        If _NettoDiff <> 0 Then
            For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                _RegistryRowsFinancialControlling.Amount = Math.Round(_RegistryRowsFinancialControlling.Amount * (_NettoAmount_RRF / _NettoAmount_RRFC), 0, MidpointRounding.AwayFromZero)
                If _RegistryRowsFinancialControlling.ContractRows IsNot Nothing Then
                    If _RegistryRowsFinancialControlling.ContractRows.CurrencyName.ShortName = "HUF" Then
                        _RegistryRowsFinancialControlling.ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
                    Else
                        _RegistryRowsFinancialControlling.ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
                        _RegistryRowsFinancialControlling.ContractRows.NettoPriceDEV = _RegistryRowsFinancialControlling.ContractRows.NettoPriceHUF * _RegistryHeader.F_CurrencyRate
                    End If
                End If
            Next
            _NettoAmount_RRF = 0
            _NettoAmount_RRFC = 0
            For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
                _NettoAmount_RRF += _RegistryRowsFinancial.NettoAmount
            Next
            For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                _NettoAmount_RRFC += _RegistryRowsFinancialControlling.Amount
            Next

            _NettoDiff = _NettoAmount_RRF - _NettoAmount_RRFC
            If _NettoDiff <> 0 Then
                Dim _RegistryRowsFinancialControlling_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryRowsFinancialControlling), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
                _RegistryRowsFinancialControlling_Collection.Sorting.Add(New SortProperty("Amount", DB.SortingDirection.Descending))
                TryCast(_RegistryRowsFinancialControlling_Collection(0), RegistryRowsFinancialControlling).Amount += _NettoDiff
                If _RegistryRowsFinancialControlling_Collection(0).ContractRows IsNot Nothing Then
                    If _RegistryRowsFinancialControlling_Collection(0).ContractRows.CurrencyName.ShortName = "HUF" Then
                        _RegistryRowsFinancialControlling_Collection(0).ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling_Collection(0).Amount
                    Else
                        _RegistryRowsFinancialControlling_Collection(0).ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling_Collection(0).Amount
                        _RegistryRowsFinancialControlling_Collection(0).ContractRows.NettoPriceDEV = _RegistryRowsFinancialControlling_Collection(0).ContractRows.NettoPriceHUF * _RegistryHeader.F_CurrencyRate
                    End If
                End If
            End If
        End If
    End Sub
End Class

