Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.Xpo
Imports DevExpress.ExpressApp.Filtering
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Data.Filtering
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.ExpressApp.CloneObject
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.Persistent.Base.Security

Imports DevExpress.XtraEditors
Imports DevExpress.ExpressApp.Model
Imports DevExpress.Persistent.Validation
Imports DevExpress.ExpressApp.Validation
Imports DevExpress.ExpressApp.Utils



Public Class RegistryVC
    Inherits DevExpress.ExpressApp.ViewController
    Protected selection_RegistryVC As ArrayList
    Protected noselect_RegistryVC As Boolean = False
    Public Event InitWork(ByVal _Minimum As Long, ByVal _Step As Long, ByVal _Maximum As Long)
    Public Event DoWork()
    Public Event FinalWork
    Public Sub New()
        MyBase.New()
        If noselect_RegistryVC = False Then
            selection_RegistryVC = New ArrayList()
        End If
        InitializeComponent()
        RegisterActions(components)
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()

        If selection_RegistryVC.Count = 0 Then
            'Beep()

        End If

        If View.Id = "RegistryTaskGoToNewtStepWithGLAccount_DetailView" Then
            AddHandler Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DialogController)().AcceptAction.Executing, AddressOf RegistryTaskGoToNewtStepWithGLAccount_PopUp_AcceptAction_Executing
        End If

        Frame.GetController(Of RegistryVC).aRegistryTaskGroupGotoNextStep.Active.SetItemValue("", False)
        On Error Resume Next
        If View.Id <> "CRM_Opportunities_RegistryTask_ListView_Set" And
            View.Id <> "RegistryTask_DetailView" Then
            'Frame.GetController(Of RegistryVC)().aRegistryTaskGotoNextStep.Active.SetItemValue("", False)
        End If

        Frame.GetController(Of RegistryVC)().aDocumentSentBack.Active.SetItemValue("", False)
        Frame.GetController(Of RegistryVC).aBankDivideRegistry.Active.SetItemValue("", False)
        Frame.GetController(Of RegistryVC).aBankMergeRegistry.Active.SetItemValue("", False)
        Frame.GetController(Of RegistryVC).aRegistrySetVATandNextStep.Active.SetItemValue("", False)

        '------------------------ LISTVIEW -------------------------------------------------------------------------------------------------------------------------------------
        If View.Id = "RegistryHeader_RegistryBankTransfer_ListView" Then
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aBankDivideRegistry.Active.SetItemValue("", True)
            Frame.GetController(Of RegistryVC).aBankMergeRegistry.Active.SetItemValue("", True)
            AddHandler Frame.GetController(Of DeleteObjectsViewController).DeleteAction.Executing, AddressOf RegistryBankTransfer_DeleteAction_Executing
        End If
      
        If View.Id = "RegistryRowsFinancialControlling_RegistryBankTransfer_ListView" Then
            Frame.GetController(Of RegistryVC).aBankDivideRegistry.Active.SetItemValue("", True)
            Frame.GetController(Of RegistryVC).aBankMergeRegistry.Active.SetItemValue("", True)
            Frame.GetController(Of DeleteObjectsViewController).DeleteAction.Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController).NewObjectAction.Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryHeader_ListView" Then
            If SecuritySystemHelper.IsUserInRole(TryCast(SecuritySystem.CurrentUser, IUserWithRoles), "Administrators") = False Then
                Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            End If
        End If
        If View.Id = "RegistryHeader_WorkFlowCollection_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryHeader_RegistryRowsFinancial_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryTasks_RegistryRowsFinancial_ListView" Then

            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
            Dim _ListView As ListView = TryCast(View, ListView)
            Dim _PropertyCollectionSource As PropertyCollectionSource = TryCast(_ListView.CollectionSource, PropertyCollectionSource)
            Dim _RegistryTasks As RegistryTasks = TryCast(_PropertyCollectionSource.MasterObject, RegistryTasks)

            GLOBAL_RegistryTask_Current_Oid = _RegistryTasks.Oid

            If _RegistryTasks.CurrentWorkflowSystemSteps.StepFinancialType <> eStepFinancialType.eCheckVAT Or _RegistryTasks.RegistryHeader.BruttoAmountRemaining = 0 Then
                Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
                Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Else
                Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
                Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", True)
            End If

        End If

        If View.Id = "RegistryTasks_RegistryRowsFinancialControlling_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)

            Dim _ListView As ListView = TryCast(View, ListView)
            Dim _PropertyCollectionSource As PropertyCollectionSource = TryCast(_ListView.CollectionSource, PropertyCollectionSource)
            Dim _RegistryTasks As RegistryTasks = TryCast(_PropertyCollectionSource.MasterObject, RegistryTasks)

            GLOBAL_RegistryTask_Current_Oid = _RegistryTasks.Oid

        End If
        If View.Id = "RegistryHeader_RegistryTasks_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryHeader_RegistryRowsFinancialControlling_ListView" Then ' Iktatási rendszerben a teljesítésre bontás fül
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryHeader_RegistryFileData_ListView" Then ' Iktatási rendszerben a FileData fül
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryRowsFinancialControlling_RegistryBankTransfer_ListView" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
            Dim nv As ListView = View
            Dim cs As PropertyCollectionSource = TryCast(nv.CollectionSource, PropertyCollectionSource)
            AddHandler cs.MasterObjectChanged, AddressOf MasterObject2_Changed
        End If
        If View.Id = "RegistryTasks_ListView_Completed_Full" Or _
            View.Id = "RegistryTasks_ListView_Completed" Or _
            View.Id = "RegistryTasks_ListView_Not_Completed_Full" Or _
            View.Id = "RegistryTasks_ListView_Not_Completed" Then

            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)

        End If
        If View.Id = "RegistryTasks_ListView_Not_Completed" Or View.Id = "RegistryTasks_ListView_Not_Completed_Full" Then
            Frame.GetController(Of RegistryVC).aRegistryTaskGroupGotoNextStep.Active.SetItemValue("", True)
        End If
        If View.Id = "RegistryHeader_ListView_Subcontractor" Then
            Frame.GetController(Of RegistryVC).aPCICheck_RegistryHeader.Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aRegistrySetTemplate.Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryRowsFinancialControllingTemplatePopup_RegistryHeader_ListView" Then
            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)

            Frame.GetController(Of RegistryRowsFinancialControllingVC).aViewRegistryNoTask.Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aPCICheck_RegistryHeader.Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aRegistrySetTemplate.Active.SetItemValue("", False)
            Frame.GetController(Of RecordsNavigationController).Active.SetItemValue("", False)
        End If
        '------------------------ DETAILVIEW ----------------------------------------------------------------------------------------------------------------------------------
        If View.Id = "RegistryRowsFinancialControlling_ReInvoicePopupWindow_DetailView" Then
            AddHandler Frame.GetController(Of DialogController)().AcceptAction.Executing, AddressOf AcceptAction_Executing
        End If

        If View.Id = "RegistryHeader_DetailView" Then

            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aRegistryStorno.Active.SetItemValue("", True)
            Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)

            If _RegistryHeader.IsEditable = False Then
                Frame.GetController(Of RegistryVC)().aRegistryGotoNextStep.Active.SetItemValue("", False)
                Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
                Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", False)
                Frame.GetController(Of ModificationsController).SaveAction.Active.SetItemValue("", False)
                Frame.GetController(Of ModificationsController).SaveAndCloseAction.Active.SetItemValue("", False)
                Frame.GetController(Of ModificationsController).SaveAndNewAction.Active.SetItemValue("", False)
            Else
                Frame.GetController(Of RegistryVC)().aRegistryGotoNextStep.Active.SetItemValue("", True)
            End If
            If _ocur.IsNewObject(_RegistryHeader) = False Then
                If _RegistryHeader.CurrentWorkflowSystemSteps.StepIndex = 1 Then
                    Frame.GetController(Of RegistryVC)().aDocumentSentBack.Active.SetItemValue("", True)
                End If
            End If
        End If
        If View.Id = "RegistryTasks_DetailView" Then
            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC)().aRegistryTaskGotoNextStep.Active.SetItemValue("", True)
            Dim _RegistryTasks As RegistryTasks = TryCast(View.SelectedObjects(0), RegistryTasks)
            If _RegistryTasks.Status = General.TaskStatus.Completed Then
                Frame.GetController(Of RegistryVC)().aRegistryTaskGotoNextStep.Active.SetItemValue("", False)
            End If
        Else
            ' Frame.GetController(Of RegistryVC)().aRegistryTaskGotoNextStep.Active.SetItemValue("", False)
        End If
        If View.Id = "RegistryRows_Financial_RegistryRows_FinancialControlling" Then
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", False)
        End If
        If View.Id Like "*RegistryTask*" Then
            Frame.GetController(Of ObjectMethodActionsViewController).Actions("Task.MarkCompleted").Active.SetItemValue("", False)
            If View.Id = "RegistryTasks_ListView_Not_Completed" Then
                CType(View, ListView).CollectionSource.Criteria("ByUser") = _
                    CriteriaOperator.Parse("Status<>4 and HRPerson.User.UserName=?", SecuritySystem.CurrentUserName)
            End If
            If View.Id = "RegistryTasks_ListView_Completed" Then
                CType(View, ListView).CollectionSource.Criteria("ByUser") = _
                    CriteriaOperator.Parse("Status=4 and HRPerson.User.UserName=?", SecuritySystem.CurrentUserName)
            End If
        End If
        If View.Id = "RegistryRowsFinancialControlling_DetailView" Then
            Frame.GetController(Of RegistryVC)().aGenerateCOC.Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.Validation.AllContextsView.ShowAllContextsController)().Action.Active.SetItemValue("", True)
            If Not GLOBAL_RegistryTask_Current_Oid = Nothing Then 'Ha nem RegistryTask -ból nyitott�k meg akkor ne sz�lljon el null exception -el
                Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
                Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling = TryCast(View.SelectedObjects(0), RegistryRowsFinancialControlling)
                Dim _RegistryTasks As RegistryTasks = _ocur.FindObject(Of RegistryTasks)(CriteriaOperator.Parse("Oid=?", GLOBAL_RegistryTask_Current_Oid.ToString))
                Dim _RegistryHeader As RegistryHeader = TryCast(_RegistryTasks.RegistryHeader, RegistryHeader)

                If _RegistryHeader IsNot Nothing And _ocur.Session.IsNewObject(_RegistryRowsFinancialControlling) Then
                    _RegistryRowsFinancialControlling.RegistryHeader = _RegistryHeader
                    _RegistryRowsFinancialControlling.Amount = _RegistryHeader.NettoAmountRemaining
                    If _RegistryHeader.UniqueObjects IsNot Nothing Then
                        _RegistryRowsFinancialControlling.UniqueObjects = _RegistryHeader.UniqueObjects
                    End If
                End If
                If _RegistryRowsFinancialControlling.ChoiceRowMode = eChoiceRowMode.eFromCertificate Then
                    Frame.GetController(Of RegistryVC)().aGenerateCOC.Active.SetItemValue("", False)
                Else
                    Frame.GetController(Of RegistryVC)().aGenerateCOC.Active.SetItemValue("", True)
                End If

                Dim _DetailView As DetailView = CType(View, DetailView)
                Dim _ChoiceRowMode As DevExpress.ExpressApp.Editors.ViewItem

                _ChoiceRowMode = _DetailView.FindItem("ChoiceRowMode")
            End If
        End If
        If View.Id = "RegistryBankTransfer_DetailView" Then
            If Not GLOBAL_RegistryTask_Current_Oid = Nothing And View.ObjectSpace.IsNewObject(View.SelectedObjects(0)) Then 'Ha nem RegistryTask -b�l nyitott�k meg akkor ne sz�lljon el null exception -el
                Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
                Dim _RegistryBankTransfer As RegistryBankTransfer = TryCast(View.SelectedObjects(0), RegistryBankTransfer)
                Dim _CurrentRegistryTask As RegistryTasks = _ocur.FindObject(Of RegistryTasks)(CriteriaOperator.Parse("Oid=?", GLOBAL_RegistryTask_Current_Oid))
                _RegistryBankTransfer.RegistryHeader = _CurrentRegistryTask.RegistryHeader
            End If
        End If
        If View.Id = "RegistryRowsFinancial_DetailView" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
            Dim _RegistryRowsFinancial As RegistryRowsFinancial = TryCast(View.SelectedObjects(0), RegistryRowsFinancial)
            Dim _RegistryTasks As RegistryTasks = _ocur.FindObject(Of RegistryTasks)(CriteriaOperator.Parse("Oid=?", GLOBAL_RegistryTask_Current_Oid.ToString))
            Dim _RegistryHeader As RegistryHeader = TryCast(_RegistryTasks.RegistryHeader, RegistryHeader)

            If _RegistryHeader IsNot Nothing And _ocur.Session.IsNewObject(_RegistryRowsFinancial) Then
                _RegistryRowsFinancial.RegistryHeader = _RegistryHeader
                _RegistryRowsFinancial.BruttoAmount = _RegistryHeader.BruttoAmountRemaining
                _RegistryRowsFinancial.DateVAT = _RegistryHeader.F_DateVAT
            End If
        End If
        If View.Id = "DocumentSentBackView_DetailView" Then
            AddHandler Frame.GetController(Of DialogController)().AcceptAction.Executing, AddressOf AcceptAction_Executing
        End If

        If View.Id = "RegistryRowsFinancialPopup_DetailView" Then
            AddHandler Frame.GetController(Of DialogController)().AcceptAction.Executing, AddressOf RegistryRowsFinancialPopup_DetailView_AcceptAction_Executing
        End If

        AddHandler View.SelectionChanged, AddressOf view_SelectionChanged
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
        Frame.GetController(Of ModificationsController).SaveAction.Active.SetItemValue("", True)
        If View.Id = "RegistryHeader_DetailView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of RegistryVC).aRegistryStorno.Active.SetItemValue("", False)
        End If

        If View.Id = "RegistryHeader_ListView" Or View.Id = "RegistryTasks_ListView_Completed" Or View.Id = "RegistryTasks_ListView_Not_Completed_Full" Or View.Id = "RegistryTasks_ListView_Not_Completed" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
        End If
        If View.Id = "RegistryTasks_DetailView" Or View.Id = "RegistryTasks_RegistryRowsFinancialControlling_ListView" Then
            GLOBAL_RegistryTask_Current_Oid = Nothing
        End If
        If View.Id = "RegistryTasks_DetailView" Then
            GLOBAL_RegistryTask_Current_Oid = Nothing
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
        End If

        RemoveHandler View.SelectionChanged, AddressOf view_SelectionChanged

        If View.Id = "RegistryRowsFinancialControlling_RegistryBankTransfer_ListView" Then
            Frame.GetController(Of RegistryVC).aBankDivideRegistry.Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aBankMergeRegistry.Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController).DeleteAction.Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController).NewObjectAction.Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController).Active.SetItemValue("", True)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", True)

        End If

        If View.Id = "RegistryTasks_RegistryRowsFinancial_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
        End If
        If View.Id = "RegistryHeader_RegistryRowsFinancialControlling_ListView" Then ' Iktatási rendszerben a teljesítésre bontás fül
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
        End If
        If View.Id = "RegistryHeader_RegistryRowsFinancial_ListView" Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.LinkUnlinkController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of DevExpress.ExpressApp.CloneObject.CloneObjectViewController)().Active.SetItemValue("", True)
        End If
        If View.Id = "RegistryHeader_ListView_Subcontractor" Then
            Frame.GetController(Of RegistryVC).aPCICheck_RegistryHeader.Active.SetItemValue("", True)
            Frame.GetController(Of RegistryVC).aRegistrySetTemplate.Active.SetItemValue("", True)
        End If
        If View.Id = "RegistryRowsFinancialControllingTemplatePopup_RegistryHeader_ListView" Then
            Frame.GetController(Of DeleteObjectsViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of CloneObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of NewObjectViewController)().Active.SetItemValue("", True)
            Frame.GetController(Of LinkUnlinkController)().Active.SetItemValue("", True)

            Frame.GetController(Of RegistryRowsFinancialControllingVC).aViewRegistryNoTask.Active.SetItemValue("", False)
            Frame.GetController(Of RegistryVC).aPCICheck_RegistryHeader.Active.SetItemValue("", True)
            Frame.GetController(Of RegistryVC).aRegistrySetTemplate.Active.SetItemValue("", True)
            Frame.GetController(Of RecordsNavigationController).Active.SetItemValue("", True)
        End If
        'If View.Id = "RegistryTasks_ListView_Not_Completed_Full" Or _
        '   View.Id = "RegistryTasks_ListView_Not_Completed" Then
        '    RemoveHandler View.SelectionChanged, AddressOf RegistryTasks_ListView_Not_Completed_Full_SelectionChanged

        'End If
    End Sub
    Private Sub AcceptAction_Executing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
        Validator.RuleSet.ValidateAll(View.ObjectSpace, View.SelectedObjects, "DocumentSendBack_Context")

    End Sub
    Private Sub RegistryBankTransfer_DeleteAction_Executing(sender As Object, e As System.ComponentModel.CancelEventArgs)
        Dim _RegistryBankTransfer As RegistryBankTransfer

        For Each _RegistryBankTransfer In View.SelectedObjects
            If _RegistryBankTransfer.BankSavedFileName = "" Then
            Else
                e.Cancel = True
            End If
        Next

    End Sub
    Sub AcceptAction_Executing()
        Validator.RuleSet.ValidateAll(View.ObjectSpace, View.SelectedObjects, "Reinvoice_ok")
    End Sub
    Sub RegistryRowsFinancialPopup_DetailView_AcceptAction_Executing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
        Validator.RuleSet.ValidateAll(View.ObjectSpace, View.SelectedObjects, "DialogOk_Contexts")
    End Sub
    Private Sub view_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim _RegistryTask As RegistryTasks
        If View Is Nothing Then Exit Sub
        If View.Id = "RegistryTasks_ListView_Not_Completed" And noselect_RegistryVC = False Then
            selection_RegistryVC.Clear()
            For Each _RegistryTask In View.SelectedObjects
                selection_RegistryVC.Add(_RegistryTask)
            Next
        End If
        If View.Id = "RegistryTasks_ListView_Not_Completed_Full" And noselect_RegistryVC = False Then
            selection_RegistryVC.Clear()
            For Each _RegistryTask In View.SelectedObjects
                selection_RegistryVC.Add(_RegistryTask)
            Next
        End If
        '--------------------------------------------------------------------
        Dim _RegistryHeader As RegistryHeader
        If View.Id = "RegistryHeader_ListView" And noselect_RegistryVC = False Then
            selection_RegistryVC.Clear()
            For Each _RegistryHeader In View.SelectedObjects
                selection_RegistryVC.Add(_RegistryHeader)
            Next
        End If
        '-----------------------------------------------------------------------
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        If (View.Id = "RegistryRowsFinancialControlling_ListView_Reinvoice_InGeneral" Or View.Id = "RegistryRowsFinancialControlling_ListView_Reinvoice_InDetail") And noselect_RegistryVC = False Then
            selection_RegistryVC.Clear()
            For Each _RegistryRowsFinancialControlling In View.SelectedObjects
                selection_RegistryVC.Add(_RegistryRowsFinancialControlling)
            Next
        End If
        '-----------------------------------------------------------------------
        Dim _RegistryBankTransfer As RegistryBankTransfer
        If View.Id = "RegistryRowsFinancialControlling_RegistryBankTransfer_ListView" And noselect_RegistryVC = False Then
            selection_RegistryVC.Clear()
            For Each _RegistryBankTransfer In View.SelectedObjects
                selection_RegistryVC.Add(_RegistryBankTransfer)
            Next
        End If
    End Sub
    Protected Overrides Sub OnFrameAssigned()
        MyBase.OnFrameAssigned()
        Dim standardController As NewObjectViewController = Frame.GetController(Of NewObjectViewController)()
        AddHandler standardController.ObjectCreated, AddressOf standardController_ObjectCreated
    End Sub
    Private Sub standardController_ObjectCreated(ByVal sender As Object, ByVal e As ObjectCreatedEventArgs)
        If View.Id = "RegistryHeader_RegistryRowsFinancial_ListView" Then
            CType(e.CreatedObject, RegistryRowsFinancial).BruttoAmount = CType(e.CreatedObject, RegistryRowsFinancial).RegistryHeader.BruttoAmountRemaining
        End If
        If View.Id = "RegistryRowsFinancial_RegistryRowsFinancialControlling_ListView" Then
            CType(e.CreatedObject, RegistryRowsFinancialControlling).Amount = CType(e.CreatedObject, RegistryRowsFinancialControlling).RegistryHeader.NettoAmountRemaining
        End If
    End Sub
    Private Sub MasterObject2_Changed(ByVal sender As Object, ByVal e As EventArgs)
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling = TryCast((CType(sender, PropertyCollectionSource)).MasterObject, RegistryRowsFinancialControlling)
        If _RegistryRowsFinancialControlling.RegistryHeader.BruttoAmountRemainingBank = 0 Then
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", False)
        Else
            Frame.GetController(Of DevExpress.ExpressApp.SystemModule.NewObjectViewController)().Active.SetItemValue("", True)
        End If
    End Sub
    Private Sub aRegistryGotoNextStep_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aRegistryGotoNextStep.Execute
        'Véglegesít egy iktatást és tovább lépteti az első lépés utánira
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = _ocur.Session
        Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)


        Dim _RegistryTask As RegistryTasks

        Dim _RegistryChoiceNextStep As RegistryChoiceNextStep = TryCast(e.PopupWindow.View.SelectedObjects(0), RegistryChoiceNextStep)

        Dim _OK_NewRegistryTask As Boolean = False
        Dim _ExistingRegistryHeader As RegistryHeader = _ocur.FindObject(Of RegistryHeader)(CriteriaOperator.Parse("CustomersFrom=? AND Customers=? AND DocumentNumber=? AND RegistryAcceptState=0", _RegistryHeader.CustomersFrom, _
                                           _RegistryHeader.Customers, _RegistryHeader.DocumentNumber), True)

        If _RegistryHeader IsNot Nothing Then

            'Duplikált számlaiktatás elkerülése miatt megkeressük van e már adott cégek között ilyen bizonylatszámú számla
            'Exception TESZT miatt!!!!
            If _ExistingRegistryHeader IsNot Nothing Then
                If _ExistingRegistryHeader.Oid <> _RegistryHeader.Oid Then
                    Throw New Exception("*Létezik már a rendszerben számla a megadott azonosítóval!")
                End If
            End If

            '-- ha van létező aktív feladat hozzá akkor lezárja
            If _RegistryHeader.CurrentWorkflowSystemSteps.StepIndex = 1 Then
                CloseRegistryTask(_uow, _RegistryHeader)
            End If
            If CheckNextStep(_uow, _RegistryHeader, _RegistryChoiceNextStep.WorkflowSystemSteps) Then
                _OK_NewRegistryTask = True
            End If
            If _RegistryHeader.IsEditable And _OK_NewRegistryTask = True Then
                _RegistryHeader.IsEditable = False
                _RegistryHeader.CurrentWorkflowSystemSteps = _uow.GetObjectByKey(Of WorkflowSystemSteps)(_RegistryChoiceNextStep.WorkflowSystemSteps.Oid)
                If _RegistryHeader.CurrentWorkflowSystemSteps.StepIndex = 1 Then '--- Ha az első lépésre állítja vissza újra legyen szerkeszthető az iktatás
                    _RegistryHeader.IsEditable = True
                End If

                ' -- Banki csomag létrehozása
                If (_RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount _
                    Or _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eInvoiceAdvanceAsk _
                    Or _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eInvoiceFinal) And _RegistryHeader.RegistryBankTransfer.Count = 0 Then
                    If _RegistryHeader.F_PayMode = ePayMode.InTransfer Then
                        If Not (_RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eInvoiceFinal And Not _RegistryHeader.F_AmountBruttoHUF > 0) Then
                            Dim _RegistryBankTransfer As RegistryBankTransfer = New RegistryBankTransfer(_uow)
                            _RegistryBankTransfer.RegistryHeader = _RegistryHeader
                            _RegistryBankTransfer.DatePayment = _RegistryHeader.F_DatePayment
                            _RegistryBankTransfer.AmountDEV = _RegistryHeader.F_AmountBruttoDEV
                            _RegistryBankTransfer.AmountHUF = _RegistryHeader.F_AmountBruttoHUF
                        End If
                    End If
                End If

                '-- Pontozás létrehozása '
                ' -- Banki csomag és számla végösszeg egyezésének ellenőrzése
                If _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                    If _RegistryHeader.F_PayMode = ePayMode.InTransfer Then
                        If Not _RegistryHeader.RegistryBankTransfer.Count = 0 Then
                            Dim _BankTransferSumAmount As Double = 0
                            For Each _RegistryBankTransfer As RegistryBankTransfer In _RegistryHeader.RegistryBankTransfer
                                _BankTransferSumAmount += _RegistryBankTransfer.AmountHUF
                            Next
                            If Math.Abs(_BankTransferSumAmount - _RegistryHeader.F_AmountBruttoHUF) > 5 Then
                                Throw New Exception("*A banki csomagok összege nem egyezik meg a számla végösszegével!")
                            End If
                        End If
                    Else
                        '// Le kell venni a banki pontozást, ha van !

                    End If
                End If

                '-- Az új feladat létrehozása -----------------------------------
                _RegistryTask = New RegistryTasks(_uow)
                _RegistryTask.RegistryHeader = _RegistryHeader
                _RegistryTask.CurrentWorkflowSystemSteps = _RegistryHeader.CurrentWorkflowSystemSteps
                _RegistryTask.StartDate = GetSQLTime(_ocur.Session)
                _RegistryTask.Status = General.TaskStatus.NotStarted
                _RegistryTask.HRPerson = _uow.GetObjectByKey(Of HRPerson)(_RegistryChoiceNextStep.HRPerson.Oid)
                _RegistryTask.Description = _RegistryChoiceNextStep.Description
                _RegistryTask.Subject = _RegistryHeader.ShortName
                _RegistryTask.DueDate = DateAdd(DateInterval.Day, _RegistryChoiceNextStep.WorkflowSystemSteps.ExpirationDayofFailure, Now)


                _RegistryChoiceNextStep.Delete()

                _uow.CommitChanges()
                _ocur.CommitChanges()

                If _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                    Dim _pci_uow As New UnitOfWork(_ocur.Session.DataLayer)
                    GLFunctions.ReconfigurePCI(_pci_uow, _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, 1, _RegistryHeader.F_ConnectInfo)
                End If
                View.Close(False)

            End If
        End If
    End Sub
    Private Sub aRegistryGotoNextStep_Cancel(sender As Object, e As System.EventArgs) Handles aRegistryGotoNextStep.Cancel
        noselect_RegistryVC = False
    End Sub
    Private Sub aRegistryTaskGotoNextStep_Cancel(ByVal sender As Object, ByVal e As System.EventArgs) Handles aRegistryTaskGotoNextStep.Cancel
        noselect_RegistryVC = False
    End Sub
    Private Sub aRegistryTaskGotoNextStep_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aRegistryTaskGotoNextStep.Execute
        '---Egy véglegesített iktatásból generált feladatot hoz létre, és azon keresztül lépteti az iktatást-------
        Dim _ocur_original As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur_original.Session.DataLayer)

        Dim _RegistryTask As RegistryTasks = _uow.GetObjectByKey(Of RegistryTasks)(TryCast(View.SelectedObjects(0), RegistryTasks).Oid)
        Dim _RegistryTask_New As RegistryTasks
        Dim _RegistryHeader As RegistryHeader = _RegistryTask.RegistryHeader

        Dim _RegistryChoiceNextStep As RegistryChoiceNextStep = TryCast(e.PopupWindow.View.SelectedObjects(0), RegistryChoiceNextStep)

        Dim _OK_NewRegistryTask As Boolean = False
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Dim _Controlling_File As FileData

        If _RegistryHeader IsNot Nothing Then
            'View.Refresh()
            If CheckNextStep(_uow, _RegistryHeader, _RegistryChoiceNextStep.WorkflowSystemSteps) Then
                _OK_NewRegistryTask = True
            End If

            '----- Megkeressük a telj sorokban a csatolt file-t ------------------------------------------------------
            If _RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckCOCScanned Then
                For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                    If _RegistryRowsFinancialControlling.File IsNot Nothing Then
                        _Controlling_File = _RegistryRowsFinancialControlling.File
                        Exit For
                    End If
                Next
                '------------- Azokhoz a sorokhoz ahova nincs becsatolva a file, csatoljuk. ----------------------------
                If _Controlling_File IsNot Nothing Then
                    For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                        If _RegistryRowsFinancialControlling.File Is Nothing Then
                            _RegistryRowsFinancialControlling.File = _Controlling_File
                        End If
                    Next
                End If
            End If

            _RegistryHeader.CurrentWorkflowSystemSteps = _uow.GetObjectByKey(Of WorkflowSystemSteps)(_RegistryChoiceNextStep.WorkflowSystemSteps.Oid) '-- Az iktatás aktuális lépésének beállítása
            If _RegistryHeader.CurrentWorkflowSystemSteps.StepIndex = 1 Then '--- Ha az első lépésre állítja vissza újra legyen szerkeszthető az iktatás
                _RegistryHeader.IsEditable = True
            Else
                _RegistryHeader.IsEditable = False
            End If


            If _RegistryHeader.CurrentWorkflowSystemSteps.IsLastStep = False Then '--- Ha az aktuális lépés az utolsó, akkor ne hozzon létre új Task-ot
                If _OK_NewRegistryTask = True Then

                    _RegistryTask.Status = General.TaskStatus.Completed '---A megnyitott feladat státuszának készre állítása

                    _RegistryTask_New = New RegistryTasks(_uow) '--- Egy új feladat példányosítása
                    _RegistryTask_New.RegistryHeader = _RegistryHeader '--- Az új feladatnak az iktatás fejlécét átadjuk
                    _RegistryTask_New.CurrentWorkflowSystemSteps = _RegistryHeader.CurrentWorkflowSystemSteps
                    _RegistryTask_New.StartDate = GetSQLTime(_ocur_original.Session)
                    _RegistryTask_New.Status = General.TaskStatus.NotStarted
                    _RegistryTask_New.HRPerson = _uow.GetObjectByKey(Of HRPerson)(_RegistryChoiceNextStep.HRPerson.Oid)
                    _RegistryTask_New.Description = _RegistryChoiceNextStep.Description
                    _RegistryTask_New.Subject = _RegistryHeader.ShortName
                    _RegistryTask_New.DueDate = DateAdd(DateInterval.Day, _RegistryChoiceNextStep.WorkflowSystemSteps.ExpirationDayofFailure, Now)

                    _RegistryChoiceNextStep.Delete()

                Else
                    _RegistryTask.Status = General.TaskStatus.Completed '---A megnyitott feladat státuszának készre állítása
                    _RegistryChoiceNextStep.Delete()
                End If
            Else

                _RegistryTask.Status = General.TaskStatus.Completed '---A megnyitott feladat státuszának készre állítása
                _RegistryChoiceNextStep.Delete()

                'Utolsó lépésnél az üzenet menjen be a WorkflowMessage változóba !
                For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                    _RegistryRowsFinancialControlling.WorkflowMessage = _RegistryChoiceNextStep.Description
                Next
            End If
            _uow.CommitChanges()
            If TryCast(View, DetailView) IsNot Nothing Then
                View.Close(False)
            End If
        End If
    End Sub
    Private Sub CloseRegistryTask(ByVal _uow As UnitOfWork, ByVal _RegistryHeader As RegistryHeader)
        Dim _RegistryTask_Collection As New XPCollection(Of RegistryTasks)(PersistentCriteriaEvaluationBehavior.InTransaction, _uow, CriteriaOperator.Parse("CurrentWorkflowSystemSteps=? AND RegistryHeader=?", _
                                                                                                        _RegistryHeader.CurrentWorkflowSystemSteps, _RegistryHeader))
        Dim _RegistryTask As RegistryTasks

        For Each _RegistryTask In _RegistryTask_Collection
            _RegistryTask.Status = 4
        Next

    End Sub
    Private Sub aRegistryGotoNextStep_CustomizePopupWindowParams(ByVal sender As Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aRegistryGotoNextStep.CustomizePopupWindowParams, aRegistryTaskGotoNextStep.CustomizePopupWindowParams, aRegistryTaskGroupGotoNextStep.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _RegistryChoiceNextStep As RegistryChoiceNextStep = _onew.CreateObject(Of RegistryChoiceNextStep)()
        Dim _WorkflowSystemSteps As WorkflowSystemSteps
        Dim _WorkflowSystem As WorkflowSystem
        Dim _Step As Long
        Dim _IsGroup As Boolean = False
        Dim _RegistryHeader As RegistryHeader = Nothing

        If View.SelectedObjects.Count = 0 Then Exit Sub

        If View.Id = "RegistryHeader_DetailView" Then
            _RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
        End If

        If View.Id = "RegistryTasks_DetailView" Or View.Id = "RegistryTasks_ListView_Not_Completed" Or _
            View.Id = "CRM_Opportunities_RegistryTask_ListView_Set" Or View.Id = "RegistryTasks_ListView_Not_Completed_Full" Then
            _RegistryHeader = TryCast(View.SelectedObjects(0), RegistryTasks).RegistryHeader

        End If

        If _RegistryHeader Is Nothing Then Exit Sub

        _RegistryChoiceNextStep.RegistryHeader = _onew.GetObject(_RegistryHeader)
        _WorkflowSystem = _RegistryChoiceNextStep.RegistryHeader.CurrentWorkflowSystemSteps.WorkflowSystem
        _Step = _RegistryChoiceNextStep.RegistryHeader.CurrentWorkflowSystemSteps.StepIndex + 1
        _WorkflowSystemSteps = _onew.FindObject(Of WorkflowSystemSteps)(CriteriaOperator.Parse("WorkflowSystem=? and StepIndex=?", _WorkflowSystem, _Step), True)

        _RegistryChoiceNextStep.HRPerson = _RegistryChoiceNextStep.RegistryHeader.HRResponsible
        _RegistryChoiceNextStep.WorkflowSystemSteps = _WorkflowSystemSteps

        noselect_RegistryVC = True

        e.View = Application.CreateDetailView(_onew, "RegistryChoiceNextStep_DetailView", False, _RegistryChoiceNextStep)

    End Sub
    Private Sub aRegistryTaskGroupGotoNextStep_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aRegistryTaskGroupGotoNextStep.Execute
        '---Egy v?gleges?tett iktat?sb?l gener?lt feladatot hoz l?tre, ?s azon kereszt?l l?pteti az iktat?st-------
        Dim _ocur_original As Xpo.XPObjectSpace = View.ObjectSpace
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur_original.Session.DataLayer)

        Dim _RegistryTaskFirst As RegistryTasks = _uow.GetObjectByKey(Of RegistryTasks)(TryCast(selection_RegistryVC(0), RegistryTasks).Oid)
        Dim _CurrentWorkflowSystemStepsFirst As WorkflowSystemSteps = _uow.GetObjectByKey(Of WorkflowSystemSteps)(TryCast(_RegistryTaskFirst.RegistryHeader.CurrentWorkflowSystemSteps, WorkflowSystemSteps).Oid)
        Dim _RegistryHeader As RegistryHeader = _RegistryTaskFirst.RegistryHeader
        Dim _RegistryTask_New As RegistryTasks

        Dim _RegistryChoiceNextStep As RegistryChoiceNextStep = TryCast(e.PopupWindow.View.SelectedObjects(0), RegistryChoiceNextStep)

        Dim _RegistryTasks As RegistryTasks
        Dim _Faild As Boolean = False
        Dim _OK_NewRegistryTask As Boolean = False
        Dim _RegistryTasks_Selection As RegistryTasks
        If selection_RegistryVC IsNot Nothing Then
            For Each _RegistryTasks_Selection In selection_RegistryVC
                _RegistryTasks = _uow.GetObjectByKey(Of RegistryTasks)(_RegistryTasks_Selection.Oid)

                If CheckNextStep(_uow, _RegistryTasks.RegistryHeader, _RegistryChoiceNextStep.WorkflowSystemSteps) Then
                    _OK_NewRegistryTask = True
                End If
                If _RegistryTasks.RegistryHeader.CurrentWorkflowSystemSteps.ShortName = _CurrentWorkflowSystemStepsFirst.ShortName Then
                    _RegistryTasks.RegistryHeader.CurrentWorkflowSystemSteps = _uow.GetObjectByKey(Of WorkflowSystemSteps)(_RegistryChoiceNextStep.WorkflowSystemSteps.Oid)
                    If _RegistryTasks.RegistryHeader.CurrentWorkflowSystemSteps.StepIndex = 1 Then
                        _RegistryTasks.RegistryHeader.IsEditable = True
                    End If
                    _RegistryTasks.Status = General.TaskStatus.Completed

                    If _RegistryChoiceNextStep.WorkflowSystemSteps.IsLastStep = False Then
                        If _OK_NewRegistryTask = True Then
                            _RegistryTask_New = New RegistryTasks(_uow) '--- Egy új feladat példányosítása
                            _RegistryTask_New.RegistryHeader = _RegistryTasks.RegistryHeader '--- Az új feladatnak az iktatás fejlécét átadjuk
                            _RegistryTask_New.CurrentWorkflowSystemSteps = _RegistryTasks.RegistryHeader.CurrentWorkflowSystemSteps
                            _RegistryTask_New.StartDate = GetSQLTime(_ocur_original.Session)
                            _RegistryTask_New.Status = General.TaskStatus.NotStarted
                            _RegistryTask_New.HRPerson = _uow.GetObjectByKey(Of HRPerson)(_RegistryChoiceNextStep.HRPerson.Oid)
                            _RegistryTask_New.Description = _RegistryChoiceNextStep.Description
                            _RegistryTask_New.Subject = _RegistryTasks.RegistryHeader.ShortName
                            _RegistryTask_New.DueDate = DateAdd(DateInterval.Day, _RegistryChoiceNextStep.WorkflowSystemSteps.ExpirationDayofFailure, Now)


                        End If
                    Else
                        For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                            _RegistryRowsFinancialControlling.WorkflowMessage = _RegistryChoiceNextStep.Description
                        Next
                    End If
                Else
                    _Faild = True
                End If
            Next
        End If
        noselect_RegistryVC = False
        _uow.CommitChanges()

        If _Faild = True Then
            '---- Teszt Miatt-------------------
            e.PopupWindow.Close()
            noselect_RegistryVC = False
            Throw New Exception("*A kijelölt elemek között volt nem megfelelő lépésen álló feladat, ami nem került léptetésre!")

            _OK_NewRegistryTask = False
        End If

        If Frame.GetController(Of RefreshController).RefreshAction.Enabled Then
            Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
        End If
    End Sub
    Public Function CheckNextStep(ByVal p_uow As UnitOfWork, ByVal p_RegistryHeader As RegistryHeader, ByVal p_StepToJump As WorkflowSystemSteps)
        'Ha ezt módosítod akkor a bookentryVC-ben is módosíts!
        Dim _WorkflowSystem As WorkflowSystem = p_uow.FindObject(Of WorkflowSystem)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("ShortName=?", p_RegistryHeader.RegistryType.WorkflowSystem.ShortName))
        Dim _CurrentStepIndex As Long = p_RegistryHeader.CurrentWorkflowSystemSteps.StepIndex - 1
        Dim _StepToJumpIndex As Long = p_StepToJump.StepIndex - 2

        Dim _sortCollection As SortingCollection = New SortingCollection()
        _sortCollection.Add(New SortProperty("StepIndex", DB.SortingDirection.Ascending))
        _WorkflowSystem.WorkflowSystemSteps.Sorting = _sortCollection

        For i = _CurrentStepIndex To _StepToJumpIndex
            If TryCast(_WorkflowSystem.WorkflowSystemSteps(i), WorkflowSystemSteps).StepFinancialType = eStepFinancialType.eCheckVAT Or _
               TryCast(_WorkflowSystem.WorkflowSystemSteps(i), WorkflowSystemSteps).StepFinancialType = eStepFinancialType.eCheckVATPlusControlling Then
                If p_RegistryHeader.BruttoAmountRemaining <> 0 Then
                    '---- TESZT MIATT-----------------------------
                    Throw New Exception("*Nincs Áfára teljesen lebontva, nem lehet tovább léptetni")
                End If
            End If
            If TryCast(_WorkflowSystem.WorkflowSystemSteps(i), WorkflowSystemSteps).StepFinancialType = eStepFinancialType.eCheckControlling Or _
               TryCast(_WorkflowSystem.WorkflowSystemSteps(i), WorkflowSystemSteps).StepFinancialType = eStepFinancialType.eCheckVATPlusControlling Then
                Dim _ParentControllings As String = "" 'Azon kontrollszámok nevét tartalmazó string amelyek focsoportok
                If p_RegistryHeader.NettoAmountRemaining <> 0 Then
                    '--- TESZT MIATT---------------------
                    Throw New Exception("*Nincs a számla teljesen leigazolva, nem lehet tovább léptetni")
                End If

                If p_RegistryHeader.BruttoAmountRemainingBank <> 0 And (p_RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount Or _
                                                                        p_RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eInvoiceAdvanceAsk) Then
                    Throw New Exception("*Nincs a teljes összeg lebontva a banki csomagokra")
                End If
                'Az iktatás összes számlaigazolási sorának vizsgálata, hogy van e bennük hivatkozás focsoport cm-re
                For Each _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling In p_RegistryHeader.RegistryRowsFinancialControlling
                    If _RegistryRowsFinancialControlling.Controlling.IsParent = True Then
                        _ParentControllings += _RegistryRowsFinancialControlling.Controlling.Name & ", "
                    End If
                Next
                If Not _ParentControllings = "" Then

                    Throw New Exception("*Figyelem a felhasznált CM számok focsoportok: " & _ParentControllings & "! Kérem válasszon egy nem főcsoport CM számot")
                End If
            End If
            If TryCast(_WorkflowSystem.WorkflowSystemSteps(i), WorkflowSystemSteps).StepFinancialType = eStepFinancialType.eCheckCOCScanned Then
                'Aktuális iktatáshoz rendelt teljesítésre bontás sorokat ellenoriz. A teljes leigazolandó nettó összegre vonatkozóan a CM számoknak beállított határértéket vizsgál
                'miszerint köteles visszacsatolt aláírt telesítési igazolás nyomtatványt visszacsatolni

                'Összegyujti az iktatáshoz tartozó teljesítésre bontás sorokat
                Dim _RegistryRowsFinancialControllingCollection As XPCollection(Of RegistryRowsFinancialControlling) = New XPCollection(Of RegistryRowsFinancialControlling)(PersistentCriteriaEvaluationBehavior.InTransaction, p_uow, CriteriaOperator.Parse("RegistryHeader=?", p_RegistryHeader))
                Dim sortCollection As SortingCollection = New SortingCollection()
                Dim j As Long = 0
                Dim _WhileNextStep As Boolean = True
                Dim _AmountonCM As Double

                'Sorba rendezi a kollekciót cm szám alapján
                sortCollection.Add(New SortProperty("Controlling.Name", DB.SortingDirection.Ascending))
                _RegistryRowsFinancialControllingCollection.Sorting = sortCollection

                Do While _WhileNextStep
                    ' Az aktu�lis CM sz�m egyenlege null�r�l indul
                    _AmountonCM = 0
                    Do
                        'A CM egyenleg�t n�velj�k addig am�g az aktu�lis soron r� hivatkoznak
                        _AmountonCM += _RegistryRowsFinancialControllingCollection(j).Amount

                        'Ha a CM -nek be van �ll�tva, hogy k�telesek vagyunk elv�gezni a vizsg�latot
                        '�s a CM aktu�lis egyenlege meghaladja a megengedett �sszeget �s nincs f�jl visszacsatolva
                        'akkor nem lehet tov�bbengedni a folyamatot.
                        If _RegistryRowsFinancialControllingCollection(j).Controlling.IsCOCRequired And _
                            _AmountonCM > _RegistryRowsFinancialControllingCollection(j).Controlling.COCAboveAmount And _
                            _RegistryRowsFinancialControllingCollection(j).File Is Nothing Then
                            '--- TESZT MIATT---------------------
                            Throw New Exception("*Nincs feltöltve a beszkennelt aláírt teljesítési igazolás!")
                        End If

                        If j = _RegistryRowsFinancialControllingCollection.Count - 1 Then
                            _WhileNextStep = False
                            Exit Do
                        End If

                        j += 1

                    Loop While _RegistryRowsFinancialControllingCollection(j - 1).Controlling.Name = _RegistryRowsFinancialControllingCollection(j).Controlling.Name
                Loop
            End If
        Next
        Return True
    End Function
    Private Sub aOpenRegistryFromTask_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aOpenRegistryFromTask.Execute
        Try
            Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
            Dim _RegistryHeader As RegistryHeader = TryCast(e.SelectedObjects(0), RegistryTasks).RegistryHeader
            e.ShowViewParameters.CreatedView = Application.CreateDetailView(_onew, "RegistryHeader_DetailView", True, _onew.GetObject(_RegistryHeader))
        Catch
        End Try
    End Sub
    Private Sub aPrintCOC_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aPrintCOC.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling = TryCast(View.SelectedObjects(0), RegistryRowsFinancialControlling)
        Dim _CertificateofContractHeader As CertificateofContractHeader
        Dim _CertificateofContractRows As CertificateofContractRows
        Dim _ReportData As ReportData

        If _RegistryRowsFinancialControlling IsNot Nothing Then
            If _RegistryRowsFinancialControlling.ContractRows IsNot Nothing Then
                _CertificateofContractRows = _ocur.FindObject(Of CertificateofContractRows)(CriteriaOperator.Parse("ContractRows.Oid=?", _RegistryRowsFinancialControlling.ContractRows.Oid), True)
                If _CertificateofContractRows IsNot Nothing Then
                    _CertificateofContractHeader = _CertificateofContractRows.CertificateofContractHeader
                    _ReportData = _ocur.FindObject(Of ReportData)(CriteriaOperator.Parse("Oid=?", _CertificateofContractHeader.Contracts.ContractTemplate.COC_ReportData.Oid), True)
                    If _ReportData Is Nothing Or _CertificateofContractHeader Is Nothing Then
                    Else
                        Frame.GetController(Of Reports.ReportServiceController).ShowPreview(_ReportData, CriteriaOperator.Parse("CertificateofContractHeader.DocumentNumber =?", _CertificateofContractHeader.DocumentNumber), True)
                    End If
                End If
            End If
        End If

    End Sub
    Private Sub aGenerateCOC_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aGenerateCOC.Execute
        Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling = TryCast(e.SelectedObjects(0), RegistryRowsFinancialControlling)
        Dim _CertificateofContractHeader As CertificateofContractHeader
        Dim _CertificateofContractRows As CertificateofContractRows

        Dim _CertificateofContractRows_Exists As CertificateofContractRows
        If _RegistryRowsFinancialControlling.ContractRows IsNot Nothing Then
            If _RegistryRowsFinancialControlling.ContractRows.CertificateofContractRows Is Nothing Then
                If _RegistryRowsFinancialControlling.ContractRows.Contracts.ContractTemplate.IsTechnical = True Then
                    _ocur.Rollback()
                    Throw New Exception("*Technikai szerződéshez nem lehet teljesítési igazolást készíteni !")
                Else
                    _CertificateofContractRows_Exists = _ocur.FindObject(Of CertificateofContractRows)(CriteriaOperator.Parse("ContractRows.Oid=?", _RegistryRowsFinancialControlling.ContractRows.Oid))
                    If _CertificateofContractRows_Exists IsNot Nothing Then
                        _ocur.Rollback()
                        Throw New Exception("*Ehhez a szerződési sorhoz már készült teljesítési igazolás !")
                    Else
                        _CertificateofContractHeader = _ocur.CreateObject(Of CertificateofContractHeader)()
                        _CertificateofContractHeader.DateExecution = _RegistryRowsFinancialControlling.ContractRows.DateExecution
                        _CertificateofContractHeader.Contracts = _RegistryRowsFinancialControlling.ContractRows.Contracts
                        _CertificateofContractHeader.ReportHeader = _RegistryRowsFinancialControlling.ContractRows.Contracts.ContractTemplate.COC_ReportHeader
                        _CertificateofContractHeader.ReportFooter = _RegistryRowsFinancialControlling.ContractRows.Contracts.ContractTemplate.COC_ReportFooter
                        _CertificateofContractHeader.IsEditable = False
                        _CertificateofContractHeader.IsStorno = False

                        '-- Sor létrehozása --------------------
                        _CertificateofContractRows = _ocur.CreateObject(Of CertificateofContractRows)()
                        _CertificateofContractRows.CertificateofContractHeader = _CertificateofContractHeader
                        _CertificateofContractRows.ContractRows = _RegistryRowsFinancialControlling.ContractRows
                        _CertificateofContractRows.ContractRows.CertificateofContractRows = _CertificateofContractRows

                        _ocur.CommitChanges()

                        Frame.GetController(Of RegistryVC).aPrintCOC.DoExecute()
                    End If
                End If
            End If
        End If
    End Sub
    Private Sub aRegistryStorno_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aRegistryStorno.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)

        Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
        Dim _RegistryBankTransfer_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryBankTransfer), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
        Dim _RegistryRowsFinancialControlling_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryRowsFinancialControlling), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
        Dim _RegistryRowsFinancial_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryRowsFinancial), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
        Dim _RegistryTasks_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryTasks), CriteriaOperator.Parse("RegistryHeader = ? AND Status='0'", _RegistryHeader))
        Dim _IsTransfered As Boolean = False
        Dim _IsControlled As Boolean = False
        Dim _IsReInvoiced As Boolean = False
        Dim _IsVATControlled As Boolean = False

        For Each _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling In _RegistryRowsFinancialControlling_Collection
            If _RegistryRowsFinancialControlling.ContractRows IsNot Nothing Then
                _IsControlled = True
            End If
            If _RegistryRowsFinancialControlling.ReInvoice_ContractRows IsNot Nothing Then
                _IsReInvoiced = True
            End If
        Next

        For Each _RegistryBankTransfer As RegistryBankTransfer In _RegistryBankTransfer_Collection
            If Not _RegistryBankTransfer.BankSavedFileName = "" Then
                _IsTransfered = True
            End If
        Next

        For Each _RegistryRowsFinancial As RegistryRowsFinancial In _RegistryRowsFinancial_Collection
            _IsVATControlled = True
        Next
        For Each _RegistryTasks As RegistryTasks In _RegistryTasks_Collection
            _RegistryTasks.Status = General.TaskStatus.Completed
        Next

        If _IsControlled = False And _IsReInvoiced = False And _IsTransfered = False Then
            _RegistryHeader.IsStorno = True
            _RegistryHeader.IsEditable = False
            _ocur.Delete(_RegistryTasks_Collection)
            _ocur.Delete(_RegistryBankTransfer_Collection)
            _ocur.Delete(_RegistryRowsFinancial_Collection)
            _ocur.Delete(_RegistryRowsFinancialControlling_Collection)
            _ocur.CommitChanges()

            If _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)
                GLFunctions.ReconfigurePCI(_uow, _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, ePartnerType.ePayabels, _RegistryHeader.F_ConnectInfo)
                GLFunctions.ReconfigurePCI(_uow, _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, ePartnerType.ePayabels, _RegistryHeader.F_ConnectInfo)
            End If
        Else
            ''!!!!! - Teszt miatti exception!
            _ocur.Rollback()
            If _IsControlled Then Throw New Exception("*Nem lehet stornozni, mert van számla igazolási sor ! Előbb törölje számla igazolást.")
            If _IsReInvoiced Then Throw New Exception("*Nem lehet stornózni, tovább lett számlázva a tétel !")
            If _IsTransfered Then Throw New Exception("*Nem lehet stornózni, történt pénzügyi kiegyenlítés ! Előbb vegye le a pénzügyi kiegyenlítés pontozását.")
            If _IsVATControlled Then Throw New Exception("*Nem lehet stornózni, áfa sor van rögzítve a számlához ! Előbb törölje az áfa sort. Felhívjuk a figyelmet, hogy az áfa sor az áfa analitikából is törlődik. Amennyiben bevallással lezárt időszakról van szó, revízió beadására lehet szükség!")
        End If

    End Sub
    Private Sub aCreateTechnicalContractFromRegistry_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aCreateTechnicalContractFromRegistry.Execute
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False) ' A valid�ci� ideiglenes letilt�sa az akci� v�grehajt�s�nak idej�re.
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling = TryCast(View.SelectedObjects(0), RegistryRowsFinancialControlling)
        Dim _RegistryHeader As RegistryHeader = _RegistryRowsFinancialControlling.RegistryHeader
        Dim _TechnicalContractTemplate As ContractTemplate = _ocur.FindObject(Of ContractTemplate)(CriteriaOperator.Parse("CustomersFrom=? And IsTechnical=True", _RegistryHeader.CustomersFrom))
        Dim _ExistingTechnicalContract As Contracts = _ocur.FindObject(Of Contracts)(CriteriaOperator.Parse("CustomersFrom=? AND Customers=? AND ContractTemplate=?", _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, _TechnicalContractTemplate))
        Dim _RegistryRowsFinancial As RegistryRowsFinancial
        Dim _TechnicalLimitAmount As Double = _RegistryRowsFinancialControlling.Controlling.TechnicalContractLimit
        If _TechnicalLimitAmount = 0 Then _TechnicalLimitAmount = 200000
        'If SecuritySystemHelper.IsUserInRole(TryCast(SecuritySystem.CurrentUser, IUserWithRoles), "GV") Then _TechnicalLimitAmount = 999999999

        If _RegistryRowsFinancialControlling.Amount <= _TechnicalLimitAmount Then
            If _ExistingTechnicalContract Is Nothing Then
                Dim _Contracts As Contracts = _ocur.CreateObject(Of Contracts)()
                Dim _ContractRows As ContractRows = _ocur.CreateObject(Of ContractRows)()

                _Contracts.CustomersFrom = _RegistryHeader.CustomersFrom
                _Contracts.Customers = _RegistryHeader.Customers
                _Contracts.ContractTemplate = _TechnicalContractTemplate
                _Contracts.DateCreated = _RegistryHeader.F_DateCreated
                _Contracts.DateExecution = _RegistryHeader.F_DateExecution
                _Contracts.DocumentNumber = _Contracts.ContractTemplate.NumberGenerator.GetNewNumber(_Contracts.ContractTemplate.NumberGenerator)
                _Contracts.State = State.Signed

                If _Contracts IsNot Nothing Then
                    _ContractRows.Contracts = _Contracts
                    _ContractRows.CurrencyName = _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyName
                    _ContractRows.ContractRowsType = eContractRowsType.eFix
                    _ContractRows.DateExecution = _RegistryRowsFinancialControlling.RegistryHeader.F_DateExecution
                    _ContractRows.Controlling = _RegistryRowsFinancialControlling.Controlling
                    If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyName.ShortName = "HUF" Then
                        _ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
                    Else
                        If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate <> 0 Then
                            _ContractRows.NettoPriceDEV = _RegistryRowsFinancialControlling.Amount / _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate
                        Else
                            _ContractRows.NettoPriceDEV = 0
                        End If
                        _ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
                    End If
                    _ContractRows.ShortName = _RegistryRowsFinancialControlling.Note
                    _ContractRows.PaymentOption = _RegistryRowsFinancialControlling.PaymentOption
                    _ContractRows.UniqueObjects = _RegistryRowsFinancialControlling.UniqueObjects

                    'IDE KELL VALAMI ÁFA !

                    For Each _RegistryRowsFinancial In _RegistryRowsFinancialControlling.RegistryHeader.RegistryRowsFinancial
                        _ContractRows.VAT = _RegistryRowsFinancial.VAT
                        Exit For
                    Next

                    _ContractRows.CostHolder = _RegistryRowsFinancialControlling.CostHolder
                    _ContractRows.CostPlace = _RegistryRowsFinancialControlling.CostPlace
                    _ContractRows.Controlling = _RegistryRowsFinancialControlling.Controlling
                    _ContractRows.JobNumberObjects = _RegistryRowsFinancialControlling.JobNumberObjects

                    _RegistryRowsFinancialControlling.ContractRows = _ContractRows
                End If
                _ocur.CommitChanges()
                Frame.GetController(Of RegistryVC).aCreateTechnicalContractFromRegistry.Active.SetItemValue("", False)
                Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)

                If TryCast(View, DetailView) IsNot Nothing Then
                    View.Close()
                End If
            Else
                Dim _ContractRows As ContractRows = _ocur.CreateObject(Of ContractRows)()

                _ContractRows.Contracts = _ExistingTechnicalContract
                _ContractRows.CurrencyName = _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyName
                _ContractRows.ContractRowsType = eContractRowsType.eFix
                _ContractRows.DateExecution = _RegistryRowsFinancialControlling.RegistryHeader.F_DateExecution
                _ContractRows.Controlling = _RegistryRowsFinancialControlling.Controlling
                If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyName.ShortName = "HUF" Then
                    _ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
                Else
                    If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate <> 0 Then
                        _ContractRows.NettoPriceDEV = _RegistryRowsFinancialControlling.Amount / _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate
                    Else
                        _ContractRows.NettoPriceDEV = 0
                    End If
                    _ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
                End If
                _ContractRows.ShortName = _RegistryRowsFinancialControlling.Note
                _ContractRows.PaymentOption = _RegistryRowsFinancialControlling.PaymentOption
                _ContractRows.UniqueObjects = _RegistryRowsFinancialControlling.UniqueObjects

                For Each _RegistryRowsFinancial In _RegistryRowsFinancialControlling.RegistryHeader.RegistryRowsFinancial
                    _ContractRows.VAT = _RegistryRowsFinancial.VAT
                    Exit For
                Next

                _ContractRows.CostHolder = _RegistryRowsFinancialControlling.CostHolder
                _ContractRows.CostPlace = _RegistryRowsFinancialControlling.CostPlace
                _ContractRows.Controlling = _RegistryRowsFinancialControlling.Controlling
                _ContractRows.JobNumberObjects = _RegistryRowsFinancialControlling.JobNumberObjects
                _ContractRows.Description = _RegistryRowsFinancialControlling.Note

                _RegistryRowsFinancialControlling.ContractRows = _ContractRows

                _ocur.CommitChanges()
                Frame.GetController(Of RegistryVC).aCreateTechnicalContractFromRegistry.Active.SetItemValue("", False)
                Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
                Frame.GetController(Of RegistryVC).aCreateTechnicalContractFromRegistry.Active.SetItemValue("", False)
                Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
                If TryCast(View, DetailView) IsNot Nothing Then
                    View.Close()
                    Exit Sub
                End If
            End If
            Frame.GetController(Of RegistryVC).aCreateTechnicalContractFromRegistry.Active.SetItemValue("", False)
            Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
        Else
            '-------!!!!!!!TESZT MIATT!!!!!------------------------------------------
            Dim _Message As String = String.Format("Technikai limit van beállítva ! {0}", _TechnicalLimitAmount)
            Throw New Exception(_Message)
        End If

    End Sub
    Private Sub aCreateContractsRowsfromControllingRows_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aCreateContractsRowsfromControllingRows.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling = TryCast(View.SelectedObjects(0), RegistryRowsFinancialControlling)
        Dim _Contracts As Contracts = TryCast(_RegistryRowsFinancialControlling.Contracts, Contracts)
        Dim _ContractRows As ContractRows
        If _Contracts Is Nothing Then Exit Sub

        If _RegistryRowsFinancialControlling IsNot Nothing And _Contracts IsNot Nothing Then

            _ContractRows = _ocur.CreateObject(Of ContractRows)()
            _ContractRows.Contracts = _Contracts
            _ContractRows.ContractRowsType = eContractRowsType.eFix
            _ContractRows.DateExecution = _RegistryRowsFinancialControlling.RegistryHeader.F_DateExecution
            _ContractRows.Controlling = _RegistryRowsFinancialControlling.Controlling
            _ContractRows.CurrencyName = _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyName
            _ContractRows.NettoPriceHUF = _RegistryRowsFinancialControlling.Amount
            If Not _ContractRows.CurrencyName.ShortName = "HUF" Then
                If _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate <> 0 Then
                    _ContractRows.NettoPriceDEV = Math.Round(_RegistryRowsFinancialControlling.Amount / _RegistryRowsFinancialControlling.RegistryHeader.F_CurrencyRate, 2, MidpointRounding.AwayFromZero)
                End If
            End If
            _ContractRows.ShortName = _RegistryRowsFinancialControlling.Note
            _ContractRows.Description = _RegistryRowsFinancialControlling.Note
            _ContractRows.PaymentOption = _RegistryRowsFinancialControlling.PaymentOption
            _ContractRows.UniqueObjects = _RegistryRowsFinancialControlling.UniqueObjects
            If _RegistryRowsFinancialControlling.RegistryHeader.RegistryRowsFinancial.Count > 0 Then
                _ContractRows.VAT = TryCast(_RegistryRowsFinancialControlling.RegistryHeader.RegistryRowsFinancial(0), RegistryRowsFinancial).VAT
            End If
            _ContractRows.CostHolder = _RegistryRowsFinancialControlling.CostHolder
            _ContractRows.CostPlace = _RegistryRowsFinancialControlling.CostPlace
            _ContractRows.Controlling = _RegistryRowsFinancialControlling.Controlling
            _ContractRows.JobNumberObjects = _RegistryRowsFinancialControlling.JobNumberObjects
            _ContractRows.QTT = 1
            _ContractRows.Units = _ocur.FindObject(Of Units)(CriteriaOperator.Parse("DefaultForBusinnes=True"))
            _RegistryRowsFinancialControlling.ContractRows = _ContractRows

            _ocur.CommitChanges()

            If TryCast(View, DetailView) IsNot Nothing Then
                View.Close()
                Exit Sub
            End If
        End If
        If Frame.GetController(Of RefreshController).RefreshAction.Enabled Then
            Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
        End If
    End Sub
    Private Sub aReInvoice_InvoiceHeaderConnection_CustomizePopupWindowParams(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _InvoiceHeaderListView As ListView = Application.CreateListView(_onew, GetType(InvoiceHeader), False)
        _InvoiceHeaderListView.CollectionSource.Criteria.Add("Criteria1", CriteriaOperator.Parse("IsEditable=False AND IsProforma=False AND IsStorno=False AND IsImported=False"))
        e.View = _InvoiceHeaderListView
    End Sub
    Private Sub aRegistryTaskGroupGotoNextStep_Cancel(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aRegistryTaskGroupGotoNextStep.Cancel
        noselect_RegistryVC = False
    End Sub
    Private Sub aDocumentSentBack_CustomizePopupWindowParams(ByVal sender As Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aDocumentSentBack.CustomizePopupWindowParams
        Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _DocumentSentBackView As DocumentSentBackView = _ocur.CreateObject(Of DocumentSentBackView)()
        Dim _DocumentSentBackView_New As DocumentSentBackView

        _DocumentSentBackView.CauseOfRefuse = ""
        _DocumentSentBackView.ReturnType = eDeliveryType.eLetter
        _DocumentSentBackView.Save()
        _ocur.CommitChanges()
        _DocumentSentBackView_New = _onew.GetObject(_DocumentSentBackView)

        e.View = Application.CreateDetailView(_onew, "DocumentSentBackView_DetailView", False, _DocumentSentBackView_New)
    End Sub
    Private Sub aDocumentSentBack_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aDocumentSentBack.Execute
        Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
        Dim _DocumentSentBackView As DocumentSentBackView = TryCast(e.PopupWindow.View.SelectedObjects(0), DocumentSentBackView)
        Dim _RegistryBankTransfer_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryBankTransfer), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
        Dim _RegistryRowsFinancial_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryRowsFinancial), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
        Dim _RegistryRowsFinancialControlling_Collection As XPCollection = _ocur.CreateCollection(GetType(RegistryRowsFinancialControlling), CriteriaOperator.Parse("RegistryHeader=?", _RegistryHeader))
        Dim _RegistryTasks_Collection As XPCollection = View.ObjectSpace.CreateCollection(GetType(RegistryTasks), CriteriaOperator.Parse("RegistryHeader = ? AND Status='0'", _RegistryHeader))
        Dim _IsTransfered As Boolean = False
        Dim _IsControlled As Boolean = False
        Dim _IsReInvoiced As Boolean = False

        For Each _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling In _RegistryRowsFinancialControlling_Collection
            If _RegistryRowsFinancialControlling.ContractRows IsNot Nothing Then
                _IsControlled = True
            End If
            If _RegistryRowsFinancialControlling.ReInvoice_ContractRows IsNot Nothing Then
                _IsReInvoiced = True
            End If
        Next

        For Each _RegistryBankTransfer As RegistryBankTransfer In _RegistryBankTransfer_Collection
            If Not _RegistryBankTransfer.BankSavedFileName = "" Then
                _IsTransfered = True
            End If
        Next

        If _IsControlled = False And _IsReInvoiced = False And _IsTransfered = False Then
            _RegistryHeader.CauseOfRefuse = _ocur.GetObject(_DocumentSentBackView.CauseOfRefuse)
            _RegistryHeader.ReturnType = _ocur.GetObject(_DocumentSentBackView.ReturnType)
            _RegistryHeader.RegistryAcceptState = eRegistryAcceptState.eDecline
            _RegistryHeader.DateReturn = GetSQLTime(_ocur.Session)
            _RegistryHeader.IsEditable = False
            _RegistryHeader.IsStorno = True

            _ocur.Delete(_RegistryBankTransfer_Collection)
            _ocur.Delete(_RegistryRowsFinancialControlling_Collection)
            _ocur.Delete(_RegistryRowsFinancial_Collection)

            For Each _RegistryTasks As RegistryTasks In _RegistryTasks_Collection
                _RegistryTasks.Status = General.TaskStatus.Completed
                _RegistryTasks.Save()
            Next

            _RegistryHeader.Save()
            _ocur.CommitChanges()

            If _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then
                Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)
                GLFunctions.ReconfigurePCI(_uow, _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, ePartnerType.ePayabels, _RegistryHeader.F_ConnectInfo)
                GLFunctions.ReconfigurePCI(_uow, _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, ePartnerType.ePayabels, _RegistryHeader.DocumentNumber)
            End If

            View.Close(False)
        Else
            '!!!!! - Teszt miatti exception!
            If _IsControlled Then Throw New UserFriendlyException("Nem lehet visszaküldeni, mert történt számla igazolás! Előbb ezt vissza kell vonni!")
            If _IsTransfered Then Throw New UserFriendlyException("Nem lehet visszaküldeni, mert történt banki utalás!")
            If _IsReInvoiced Then Throw New UserFriendlyException("Nem lehet visszaküldeni, mert történt továbbszámlázás erről a számláról!")
        End If
    End Sub
    Private Sub aCreateReInvoiceContractRow_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aCreateReInvoiceContractRow.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Dim _ContractRows As ContractRows
        Dim _RegistryRowsFinancialControlling_ReInvoicePopupWindow As RegistryRowsFinancialControlling_ReInvoicePopupWindow = TryCast(e.PopupWindow.View.SelectedObjects(0), RegistryRowsFinancialControlling_ReInvoicePopupWindow)

        '// A kiválasztott tételek továbbszámlázási jogcímeinek ellenőrzése, hogy mind ugyanarra szól-e

        For i = 1 To selection_RegistryVC.Count - 1
            If TryCast(selection_RegistryVC(i), RegistryRowsFinancialControlling).ReInvoiceReason IsNot TryCast(selection_RegistryVC(0), RegistryRowsFinancialControlling).ReInvoiceReason Then
                _ocur.Rollback()
                Throw New Exception("*A kijelölt továbbszámlázandó tételek jogcímei nem egyeznek meg!")
            End If
        Next

        '// A számlák teljesítési dátumának ellenőrzése

        For Each _RegistryRowsFinancialControlling In selection_RegistryVC
            If _RegistryRowsFinancialControlling.RegistryHeader.F_DateExecution > _RegistryRowsFinancialControlling_ReInvoicePopupWindow.DateExecution Then
                _ocur.Rollback()
                Throw New Exception("*A továbbszámlázandó tétel (" & _RegistryRowsFinancialControlling.RegistryHeader.ShortName & ") teljesítési dátuma későbbi mint a most készülő számla teljesítési dátuma!")
            End If
        Next

        '// A szerződési sor létrehozása
        _ContractRows = _ocur.CreateObject(Of ContractRows)()
        _ContractRows.ContractRowsType = eContractRowsType.eFix
        _ContractRows.Contracts = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.Contracts)
        _ContractRows.DateExecution = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.DateExecution)

        _ContractRows.NettoPriceHUF = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.FinalAmount)
        _ContractRows.Description = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.Description)
        _ContractRows.VAT = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.VAT)
        _ContractRows.UniqueObjects = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.UniqueObjects)
        _ContractRows.PaymentOption = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.PaymentOption)
        _ContractRows.ShortName = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.ReInvoiceReason.ReInvoiceDescription)

        '// Jelölő adatok beállítása
        _ContractRows.Controlling = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.ReInvoiceReason)
        _ContractRows.CostHolder = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.CostHolder)
        _ContractRows.CostPlace = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.CostPlace)
        _ContractRows.JobNumberObjects = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.JobNumberObjects)
        _ContractRows.UniqueObjects = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.UniqueObjects)

        If Not _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.ShortName) = "" Then
            _ContractRows.ShortName = _ocur.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow.ShortName)
        End If

        _ContractRows.QTT = 1
        ' Erre ki kell találni valami paramétert, hogy ne így kelljen keresni!!!
        _ContractRows.Units = _ocur.FindObject(Of Units)(CriteriaOperator.Parse("ShortName LIKE '%DB%'"))

        For Each _RegistryRowsFinancialControlling In selection_RegistryVC
            _RegistryRowsFinancialControlling.ReInvoice_ContractRows = _ContractRows
        Next
        _ocur.CommitChanges()
        noselect_RegistryVC = False
    End Sub
    Private Sub aCreateReInvoiceContractRow_CustomizePopupWindowParams(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aCreateReInvoiceContractRow.CustomizePopupWindowParams
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _SumAmountOfSelectedItems As Double = 0
        Dim _RegistryRowsFinancialControlling_ReInvoicePopupWindow As RegistryRowsFinancialControlling_ReInvoicePopupWindow = _onew.CreateObject(Of RegistryRowsFinancialControlling_ReInvoicePopupWindow)()
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling

        noselect_RegistryVC = True

        For Each _RegistryRowsFinancialControlling In selection_RegistryVC
            _SumAmountOfSelectedItems += _RegistryRowsFinancialControlling.Amount
        Next
        _RegistryRowsFinancialControlling = TryCast(View.SelectedObjects(0), RegistryRowsFinancialControlling)

        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.SumAmountOfSelectedItems = _SumAmountOfSelectedItems
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.RegistryRowsFinancialControlling = _onew.GetObject(_RegistryRowsFinancialControlling)
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.ShortName = _RegistryRowsFinancialControlling.ReInvoiceReason.ReInvoiceDescription
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.FinalAmount = _SumAmountOfSelectedItems
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.Description = "A számla közvetített szolgáltatást tartalmaz."
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.CostHolder = _onew.GetObject(TryCast(selection_RegistryVC(0), RegistryRowsFinancialControlling).CostHolder)
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.CostPlace = _onew.GetObject(TryCast(selection_RegistryVC(0), RegistryRowsFinancialControlling).CostPlace)
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.JobNumberObjects = _onew.GetObject(TryCast(selection_RegistryVC(0), RegistryRowsFinancialControlling).JobNumberObjects)
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.UniqueObjects = _onew.GetObject(TryCast(selection_RegistryVC(0), RegistryRowsFinancialControlling).UniqueObjects)
        _RegistryRowsFinancialControlling_ReInvoicePopupWindow.VAT = _onew.FindObject(Of VAT)(_onew.ParseCriteria("DefaultForBusinnes=True"))


        e.View = Application.CreateDetailView(_onew, "RegistryRowsFinancialControlling_ReInvoicePopupWindow_DetailView", False, _onew.GetObject(_RegistryRowsFinancialControlling_ReInvoicePopupWindow))

    End Sub
    Private Sub aCreateReInvoiceContractRow_Cancel(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aCreateReInvoiceContractRow.Cancel
        noselect_RegistryVC = False
    End Sub
    Private Sub aGoToNextStepGroup_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)

    End Sub
    Private Sub aBankDivide_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aBankDivideRegistry.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _GLBankDivide As GLBankDivide = TryCast(e.PopupWindow.View.SelectedObjects(0), GLBankDivide)
        Dim _RegistryBankTransfer As RegistryBankTransfer = View.SelectedObjects(0)

        If Not _RegistryBankTransfer.BankSavedFileName = "" Then
            Throw New Exception("*A tétel már csomaghoz van rendelve, nem lehet szétbontani!")
        End If

        If _GLBankDivide.AmountHUF = 0 And _GLBankDivide.AmountDEV = 0 And _GLBankDivide.AmountPercent = 0 Then
            Throw New Exception("*Kérem adjon meg legalább egy a bontáshoz szükséges paramétert!")
        End If
        If Not _RegistryBankTransfer.RegistryHeader.BruttoAmountRemainingBank = 0 Then
            Throw New Exception("*A számla banki csomagjai nem fedik a számla teljes összegét, kérem ellenőrizze!")
        End If

        If _GLBankDivide.AmountDEV > _RegistryBankTransfer.AmountDEV Or _GLBankDivide.AmountHUF > _RegistryBankTransfer.AmountHUF Then
            Throw New Exception("*A megadott adatok meghaladják a csomag értékét!")
        End If

        If _GLBankDivide.AmountPercent > 0 Then
            Dim _RegistryBankTransfer_New As RegistryBankTransfer = _ocur.CreateObject(Of RegistryBankTransfer)()
            _RegistryBankTransfer_New.RegistryHeader = _ocur.GetObject(_RegistryBankTransfer.RegistryHeader)
            _RegistryBankTransfer_New.AmountHUF = Math.Round((_RegistryBankTransfer.AmountHUF * (_GLBankDivide.AmountPercent / 100)), 2, MidpointRounding.AwayFromZero)
            If Not _RegistryBankTransfer.RegistryHeader.F_CurrencyName.ShortName = "HUF" Then
                _RegistryBankTransfer_New.AmountDEV = Math.Round(_RegistryBankTransfer.AmountDEV * (_GLBankDivide.AmountPercent / 100), 2, MidpointRounding.AwayFromZero)
                _RegistryBankTransfer_New.AmountHUF = Math.Round((_RegistryBankTransfer_New.AmountDEV * _RegistryBankTransfer.RegistryHeader.F_CurrencyRate), 2, MidpointRounding.AwayFromZero)
            End If
            _RegistryBankTransfer_New.DatePayment = _GLBankDivide.DatePayment
            _RegistryBankTransfer_New.Note = _GLBankDivide.Note


            _RegistryBankTransfer.AmountHUF -= _RegistryBankTransfer_New.AmountHUF
            If Not _RegistryBankTransfer.RegistryHeader.F_CurrencyName.ShortName = "HUF" Then
                _RegistryBankTransfer.AmountDEV -= _RegistryBankTransfer_New.AmountDEV
            End If


        ElseIf _RegistryBankTransfer.RegistryHeader.F_CurrencyName.ShortName = "HUF" And _GLBankDivide.AmountHUF > 0 Then

            Dim _RegistryBankTransfer_New As RegistryBankTransfer = _ocur.CreateObject(Of RegistryBankTransfer)()
            _RegistryBankTransfer_New.RegistryHeader = _ocur.GetObject(_RegistryBankTransfer.RegistryHeader)
            _RegistryBankTransfer_New.AmountHUF = _GLBankDivide.AmountHUF

            _RegistryBankTransfer_New.DatePayment = _GLBankDivide.DatePayment
            _RegistryBankTransfer_New.Note = _GLBankDivide.Note

            _RegistryBankTransfer.AmountHUF -= _RegistryBankTransfer_New.AmountHUF

        Else

            Dim _RegistryBankTransfer_New As RegistryBankTransfer = _ocur.CreateObject(Of RegistryBankTransfer)()
            _RegistryBankTransfer_New.RegistryHeader = _ocur.GetObject(_RegistryBankTransfer.RegistryHeader)
            _RegistryBankTransfer_New.AmountDEV = _GLBankDivide.AmountDEV
            _RegistryBankTransfer_New.AmountHUF = _RegistryBankTransfer_New.AmountDEV * _RegistryBankTransfer.RegistryHeader.F_CurrencyRate

            _RegistryBankTransfer_New.DatePayment = _GLBankDivide.DatePayment
            _RegistryBankTransfer_New.Note = _GLBankDivide.Note

            _RegistryBankTransfer.AmountHUF -= _RegistryBankTransfer_New.AmountHUF
            _RegistryBankTransfer.AmountDEV -= _RegistryBankTransfer_New.AmountDEV

        End If

        _ocur.CommitChanges()
        If View.IsRoot Then
            Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
        Else
            Dim nestedFrame As NestedFrame = TryCast(Frame, NestedFrame)
            If nestedFrame IsNot Nothing Then
                Dim parentView As View = nestedFrame.ViewItem.View
                parentView.Refresh()
            End If
        End If
    End Sub
    Private Sub aBankDivide_CustomizePopupWindowParams(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aBankDivideRegistry.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _GLBankDivide As GLBankDivide = _onew.CreateObject(Of GLBankDivide)()
        Dim _RegistryBankTransfer As RegistryBankTransfer

        If View.Id = "RegistryRowsFinancialControlling_RegistryBankTransfer_ListView" Then
            _RegistryBankTransfer = View.SelectedObjects(0)
        End If
        If View.Id = "RegistryHeader_RegistryBankTransfer_ListView" Then
            _RegistryBankTransfer = View.SelectedObjects(0)
        End If
        _GLBankDivide.RegistryBankTransfer_AmountDEV = _RegistryBankTransfer.AmountDEV
        _GLBankDivide.RegistryBankTransfer_AmountHUF = _RegistryBankTransfer.AmountHUF
        _GLBankDivide.RegistryBankTransfer_RegistryHeader_CurrencyName = _RegistryBankTransfer.RegistryHeader.F_CurrencyName.ShortName
        _GLBankDivide.Note = _RegistryBankTransfer.Note
        e.View = Application.CreateDetailView(_onew, "GLBankDivide_DetailView", False, _GLBankDivide)
    End Sub
    Private Sub aBankMergeRegistry_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aBankMergeRegistry.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryBankTransfer As RegistryBankTransfer
        Dim _RegistryBankTransfer_Base As RegistryBankTransfer

        Dim _DelArray As New ArrayList
        Dim _AmountHUF As Double = 0
        Dim _AmountDEV As Double = 0



        _DelArray.Clear()
        If selection_RegistryVC Is Nothing Or selection_RegistryVC.Count <= 0 Then Exit Sub
        For I = 0 To selection_RegistryVC.Count - 1
            If Not TryCast(selection_RegistryVC(I), RegistryBankTransfer).BankSavedFileName = "" Then
                Throw New Exception("*A tétel már csomaghoz van rendelve, nem lehet összevonni!")
            End If
            If I = 0 Then
                _RegistryBankTransfer_Base = TryCast(selection_RegistryVC(I), RegistryBankTransfer)
            Else
                _RegistryBankTransfer = TryCast(selection_RegistryVC(I), RegistryBankTransfer)
                If _RegistryBankTransfer.RegistryHeader.Oid = _RegistryBankTransfer_Base.RegistryHeader.Oid Then
                    _AmountDEV += _RegistryBankTransfer.AmountDEV
                    _AmountHUF += _RegistryBankTransfer.AmountHUF
                    _DelArray.Add(_RegistryBankTransfer)
                End If
            End If

        Next
        _RegistryBankTransfer_Base.AmountHUF += _AmountHUF
        _RegistryBankTransfer_Base.AmountDEV += _AmountDEV
        _RegistryBankTransfer_Base.Save()

        For i = 0 To _DelArray.Count - 1
            _ocur.Delete(_DelArray(i))
        Next

        _ocur.CommitChanges()
        If Frame.GetController(Of RefreshController).RefreshAction.Enabled Then
            Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
        End If
    End Sub
    Private Sub aImportInvoiceAdvances_CustomizePopupWindowParams(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aImportInvoiceAdvances.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        e.View = Application.CreateListView(_onew, GetType(RegistryHeader), False)
        TryCast(e.View, ListView).CollectionSource.Criteria("Filter1") = New BinaryOperator("RegistryType.RegistryMainType", "2", BinaryOperatorType.Equal)
        TryCast(e.View, ListView).CollectionSource.Criteria("Filter2") = New BinaryOperator("CustomersFrom", TryCast(_onew.GetObject(View.SelectedObjects(0)), RegistryHeader).CustomersFrom, BinaryOperatorType.Equal)
        TryCast(e.View, ListView).CollectionSource.Criteria("Filter3") = New BinaryOperator("Customers", TryCast(_onew.GetObject(View.SelectedObjects(0)), RegistryHeader).Customers, BinaryOperatorType.Equal)
    End Sub
    'Private Sub aImportInvoiceAdvances_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aImportInvoiceAdvances.Execute
    '    Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
    '    Dim _RegistryHeader As RegistryHeader = View.SelectedObjects(0)

    '    For Each _InvoiceAdvance As RegistryHeader In e.PopupWindow.View.SelectedObjects

    '        'Áfa sorok átvétele
    '        For Each _RegistryRowsFinancial As RegistryRowsFinancial In _InvoiceAdvance.RegistryRowsFinancial

    '            'Minden előlegszámláról átvesszük az ÁFA sorokat
    '            Dim _RegistryRowsFinancial_New As RegistryRowsFinancial = _ocur.CreateObject(Of RegistryRowsFinancial)()
    '            _RegistryRowsFinancial_New.RegistryHeader = _RegistryHeader
    '            _RegistryRowsFinancial_New.VAT = _ocur.GetObject(_RegistryRowsFinancial.VAT)
    '            _RegistryRowsFinancial_New.BruttoAmount = _RegistryRowsFinancial.BruttoAmount
    '            _RegistryRowsFinancial_New.Save()

    '            'Létrehozzuk az ellentétes előjelű áfa sorokat is
    '            Dim _RegistryRowsFinancial_New_Negative As RegistryRowsFinancial = _ocur.CreateObject(Of RegistryRowsFinancial)()
    '            _RegistryRowsFinancial_New_Negative.RegistryHeader = _RegistryHeader
    '            _RegistryRowsFinancial_New_Negative.VAT = _ocur.GetObject(_RegistryRowsFinancial.VAT)
    '            _RegistryRowsFinancial_New_Negative.BruttoAmount = _RegistryRowsFinancial.BruttoAmount * -1
    '            _RegistryRowsFinancial_New_Negative.Save()
    '        Next

    '        'Az előleg számlához tartozó bekérő teljesítési igazolását is átvesszük
    '        For Each _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling In _InvoiceAdvance.F_AdvanceAsk.RegistryRowsFinancialControlling
    '            Dim _RegistryRowsFinancialControlling_New As RegistryRowsFinancialControlling = _ocur.CreateObject(Of RegistryRowsFinancialControlling)()
    '            _RegistryRowsFinancialControlling_New.RegistryHeader = _RegistryHeader
    '            _RegistryRowsFinancialControlling_New.ContractRows = _ocur.GetObject(_RegistryRowsFinancialControlling.ContractRows)
    '            _RegistryRowsFinancialControlling_New.Amount = _RegistryRowsFinancialControlling.Amount
    '            _RegistryRowsFinancialControlling_New.CertificateofContractRows = _ocur.GetObject(_RegistryRowsFinancialControlling.CertificateofContractRows)
    '            _RegistryRowsFinancialControlling_New.Controlling = _ocur.GetObject(_RegistryRowsFinancialControlling.Controlling)
    '            _RegistryRowsFinancialControlling_New.CostHolder = _ocur.GetObject(_RegistryRowsFinancialControlling.CostHolder)
    '            _RegistryRowsFinancialControlling_New.CostPlace = _ocur.GetObject(_RegistryRowsFinancialControlling.CostPlace)
    '            _RegistryRowsFinancialControlling_New.File = _ocur.GetObject(_RegistryRowsFinancialControlling.File)
    '            _RegistryRowsFinancialControlling_New.IsReInvoice = _RegistryRowsFinancialControlling.IsReInvoice
    '            _RegistryRowsFinancialControlling_New.JobNumberObjects = _ocur.GetObject(_RegistryRowsFinancialControlling.JobNumberObjects)
    '            _RegistryRowsFinancialControlling_New.Note = _RegistryRowsFinancialControlling.Note
    '            _RegistryRowsFinancialControlling_New.ReInvoice_ContractRows = _ocur.GetObject(_RegistryRowsFinancialControlling.ReInvoice_ContractRows)
    '            _RegistryRowsFinancialControlling_New.ReInvoice_Customers = _ocur.GetObject(_RegistryRowsFinancialControlling.ReInvoice_Customers)
    '            _RegistryRowsFinancialControlling_New.ReInvoiceMode = _RegistryRowsFinancialControlling.ReInvoiceMode
    '            _RegistryRowsFinancialControlling_New.UniqueObjects = _ocur.GetObject(_RegistryRowsFinancialControlling.UniqueObjects)
    '            _RegistryRowsFinancialControlling_New.Save()
    '        Next
    '        Dim _localInvoiceAdvance As RegistryHeader = _ocur.GetObjectByKey(Of RegistryHeader)(_InvoiceAdvance.Oid)
    '        _localInvoiceAdvance.F_FinalInvoice = _RegistryHeader
    '        _localInvoiceAdvance.Save()
    '    Next
    '    _ocur.CommitChanges()
    'End Sub
    Private Sub aImportICInvoice_CustomizePopupWindowParams(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aImportICInvoice.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
        Dim _RegistryHeader_Collection As XPCollection = _onew.CreateCollection(GetType(RegistryHeader), _
             CriteriaOperator.Parse("CustomersFrom=? AND NOT RegistryType.RegistryMainType=1", _onew.GetObject(_RegistryHeader.CustomersFrom)))
        Dim _InvoiceHeader_Collection As XPCollection = _onew.CreateCollection(GetType(InvoiceHeader), _
             CriteriaOperator.Parse("Customers=? AND IsEditable=False AND IsProforma=False", _onew.GetObject(_RegistryHeader.CustomersFrom)))
        Dim _CS As CollectionSource = New CollectionSource(_onew, GetType(InvoiceHeader))
        Dim _AddToList As Boolean

        _CS.BeginUpdateCriteria()
        _CS.Criteria.Add("Filter1", CriteriaOperator.Parse("1=2"))
        _CS.EndUpdateCriteria()

        For Each _Invoice As InvoiceHeader In _InvoiceHeader_Collection
            _AddToList = True
            For Each _RegistryHeader0 As RegistryHeader In _RegistryHeader_Collection
                If _Invoice.DocumentNumber = _RegistryHeader0.DocumentNumber Then
                    _AddToList = False
                End If
            Next
            If _AddToList Then
                _CS.Add(_Invoice)
            End If
        Next

        e.View = Application.CreateListView("InvoiceHeader_ListView_PopUp", _CS, False)
    End Sub
    Private Sub aImportICInvoice_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aImportICInvoice.Execute
        Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
        Dim _InvoiceHeader As InvoiceHeader = TryCast(e.PopupWindow.View.SelectedObjects(0), InvoiceHeader)
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _CustomerBankAccount As CustomerBankAccounts
        If _InvoiceHeader IsNot Nothing Then
            _RegistryHeader.Customers = _ocur.GetObject(_InvoiceHeader.CustomersFrom)
            _RegistryHeader.DocumentNumber = _ocur.GetObject(_InvoiceHeader.DocumentNumber)
            _RegistryHeader.F_CurrencyRate = _ocur.GetObject(_InvoiceHeader.CurrencyRate)
            _RegistryHeader.F_AmountBruttoDEV = _ocur.GetObject(_InvoiceHeader.TotalBruttoDEV)
            _RegistryHeader.F_AmountBruttoHUF = _ocur.GetObject(_InvoiceHeader.TotalBruttoHUF)
            _RegistryHeader.F_CurrencyName = _ocur.GetObject(_InvoiceHeader.CurrencyName)
            _RegistryHeader.F_DateCreated = _ocur.GetObject(_InvoiceHeader.DateCreated)
            _RegistryHeader.F_DateExecution = _ocur.GetObject(_InvoiceHeader.DateExecution)
            _RegistryHeader.F_DatePayment = _ocur.GetObject(_InvoiceHeader.DatePayment)
            _CustomerBankAccount = _ocur.FindObject(Of CustomerBankAccounts)(CriteriaOperator.Parse("AccountNumber=? AND Customers=?", _ocur.GetObject(_InvoiceHeader.BankInformation.AccountNumber), _RegistryHeader.Customers))
            If _CustomerBankAccount IsNot Nothing Then
                _RegistryHeader.F_CustomerBankAccounts = _CustomerBankAccount
            End If
            _RegistryHeader.Save()
        End If
    End Sub
    Private Sub aRegistrySetVATandNextStep_CustomizePopupWindowParams(ByVal sender As Object, ByVal e As DevExpress.ExpressApp.Actions.CustomizePopupWindowParamsEventArgs) Handles aRegistrySetVATandNextStep.CustomizePopupWindowParams
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryRowsFinancialPopup As RegistryRowsFinancialPopup = _onew.CreateObject(Of RegistryRowsFinancialPopup)()
        Dim _RegistryTask As RegistryTasks = TryCast(View.SelectedObjects(0), RegistryTasks)
        Dim _WorkflowSystemSteps As WorkflowSystemSteps
        Dim _WorkflowSystem As WorkflowSystem
        Dim _StepIndex As Long
        If _RegistryTask.RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckVAT Then
            _RegistryRowsFinancialPopup.RegistryHeader = _onew.GetObject(_RegistryTask.RegistryHeader)
            _WorkflowSystem = _RegistryTask.RegistryHeader.CurrentWorkflowSystemSteps.WorkflowSystem
            _StepIndex = _RegistryTask.RegistryHeader.CurrentWorkflowSystemSteps.StepIndex
            _WorkflowSystemSteps = _ocur.FindObject(Of WorkflowSystemSteps)(CriteriaOperator.Parse("StepIndex=? and WorkflowSystem.Oid=?", _StepIndex + 1, _WorkflowSystem.Oid))

            _RegistryRowsFinancialPopup.VAT = _onew.FindObject(Of VAT)(CriteriaOperator.Parse("DefaultForBusinnes=True"))
            _RegistryRowsFinancialPopup.WorkflowSystemSteps = _onew.FindObject(Of WorkflowSystemSteps)(CriteriaOperator.Parse("Oid=?", _WorkflowSystemSteps.Oid))
            If _WorkflowSystemSteps.HRResponsible IsNot Nothing Then
                _RegistryRowsFinancialPopup.HRPerson = _onew.FindObject(Of HRPerson)(CriteriaOperator.Parse("Oid=?", _WorkflowSystemSteps.HRResponsible.Oid))
            End If
            noselect_RegistryVC = True
            e.View = Application.CreateDetailView(_onew, "RegistryRowsFinancialPopup_DetailView", False, _RegistryRowsFinancialPopup)
        End If
    End Sub
    Private Sub aRegistrySetVATandNextStep_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.PopupWindowShowActionExecuteEventArgs) Handles aRegistrySetVATandNextStep.Execute
        Dim _ocur_original As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As New UnitOfWork(_ocur_original.Session.DataLayer)

        Dim _RegistryTasks As RegistryTasks
        Dim _RegistryTasks_New As RegistryTasks
        Dim _RegistryHeader As RegistryHeader
        Dim _RegistryRowsFinancial As RegistryRowsFinancial
        Dim _IsRegistryRowsFinancial As Boolean = False
        Dim _RegistryRowsFinancialPopup As RegistryRowsFinancialPopup = _uow.GetObjectByKey(Of RegistryRowsFinancialPopup)(TryCast(e.PopupWindow.View.SelectedObjects(0), RegistryRowsFinancialPopup).Oid)

        Dim _HRPerson As HRPerson = _uow.FindObject(Of HRPerson)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("Oid=?", _RegistryRowsFinancialPopup.HRPerson.Oid))
        Dim _VAT As VAT = _uow.FindObject(Of VAT)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("Oid=?", _RegistryRowsFinancialPopup.VAT.Oid))
        Dim _WorkflowSystemSteps As WorkflowSystemSteps = _uow.FindObject(Of WorkflowSystemSteps)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("Oid=?", _RegistryRowsFinancialPopup.WorkflowSystemSteps.Oid))

        If selection_RegistryVC IsNot Nothing Then
            RaiseEvent InitWork(1, 1, selection_RegistryVC.Count)
            For Each _RegistryTasks In selection_RegistryVC
                RaiseEvent DoWork()
                If _RegistryTasks.Status <> General.TaskStatus.Completed Then
                    _RegistryHeader = _RegistryTasks.RegistryHeader
                    _IsRegistryRowsFinancial = False
                    If _RegistryHeader.CurrentWorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckVAT Then
                        If _RegistryHeader.RegistryType.RegistryMainType = eRegistryMainType.eAccount Then 'Ez hogy lehet más mint pénzügyi iktatás ha a folyamata számla iktatás?
                            For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
                                _IsRegistryRowsFinancial = True
                            Next
                            If _IsRegistryRowsFinancial = False Then
                                _RegistryRowsFinancial = New RegistryRowsFinancial(_uow)
                                _RegistryRowsFinancial.RegistryHeader = _RegistryHeader
                                _RegistryRowsFinancial.VAT = _VAT
                                _RegistryRowsFinancial.BruttoAmount = _RegistryHeader.F_AmountBruttoHUF
                                _RegistryRowsFinancial.DateVAT = _RegistryHeader.F_DateVAT

                                If CheckNextStep(_uow, _RegistryHeader, _WorkflowSystemSteps) Then 'Léptetés engedélyének vizsgálata
                                    '-- Régi feladat lezárása
                                    _RegistryTasks.Status = General.TaskStatus.Completed

                                    '-- Új feladat létrehozása
                                    _RegistryTasks_New = New RegistryTasks(_uow)
                                    _RegistryTasks_New.Status = General.TaskStatus.NotStarted
                                    _RegistryTasks_New.Subject = _RegistryHeader.ShortName
                                    _RegistryTasks_New.RegistryHeader = _RegistryHeader
                                    _RegistryTasks_New.CurrentWorkflowSystemSteps = _WorkflowSystemSteps
                                    _RegistryTasks_New.HRPerson = _HRPerson

                                    _RegistryHeader.CurrentWorkflowSystemSteps = _WorkflowSystemSteps 'Header aktuális lépését is állítani kell

                                End If
                            End If
                        End If
                    End If
                End If
            Next
            _uow.CommitChanges()
            noselect_RegistryVC = False
            RaiseEvent FinalWork
            View.Refresh()
        End If
    End Sub
    Private Sub aCreateContractsRowsfromControllingRows_ExecuteCanceled(ByVal sender As Object, ByVal e As DevExpress.ExpressApp.Actions.ActionBaseEventArgs) Handles aCreateContractsRowsfromControllingRows.ExecuteCanceled

    End Sub

    Private Sub aPCICheck_RegistryHeader_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aPCICheck_RegistryHeader.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)

        Dim _RegistryHeader As RegistryHeader

        RaiseEvent InitWork(1, 1, View.SelectedObjects.Count)
        For Each _RegistryHeader In View.SelectedObjects
            RaiseEvent DoWork()
            If _RegistryHeader IsNot Nothing Then
                GLFunctions.ReconfigurePCI(_uow, _RegistryHeader.CustomersFrom, _RegistryHeader.Customers, 1, _RegistryHeader.F_ConnectInfo)
            End If
        Next
        _ocur.CommitChanges()
        RaiseEvent FinalWork
    End Sub

    Private Sub aRegistrySetTemplate_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aRegistrySetTemplate.Execute
        Try
            Dim _ocur As Xpo.XPObjectSpace = View.ObjectSpace
            Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)
            If _RegistryHeader Is Nothing Then Throw New Exception("*Nincs kiválasztva egyetlen sor sem!")

            If _RegistryHeader.RegistryType.RegistryMainType <> eRegistryMainType.eAccount Then Throw New Exception("*A kiválasztott iktatás nem számla típus!")
            If _RegistryHeader.RegistryRowsFinancialControlling.Count = 0 Then Throw New Exception("*Nem lehet sablonként használni olyan iktatást, melyenek számaligazolás része üres!")
            _RegistryHeader.IsTemplate = Not (_RegistryHeader.IsTemplate)

            _ocur.CommitChanges()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub aDocumentReturnfromSendBack_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aDocumentReturnfromSendBack.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryHeader As RegistryHeader

        RaiseEvent InitWork(1, 1, View.SelectedObjects.Count)
        For Each _RegistryHeader In View.SelectedObjects
            RaiseEvent DoWork()
            _RegistryHeader.CauseOfRefuse = Nothing
            _RegistryHeader.ReturnType = eDeliveryType.eNotSet
            _RegistryHeader.RegistryAcceptState = eRegistryAcceptState.eAccept
            _RegistryHeader.DateReturn = Nothing
            _RegistryHeader.IsEditable = True
            _RegistryHeader.IsStorno = False
        Next
        _ocur.CommitChanges()
        RaiseEvent FinalWork

    End Sub

    Private Sub aRegistryTaskGroupGotoNextStepWithGLAccount_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles aRegistryTaskGroupGotoNextStepWithGLAccount.CustomizePopupWindowParams
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _RegistryTaskGoToNewtStepWithGLAccount As RegistryTaskGoToNewtStepWithGLAccount = _onew.CreateObject(Of RegistryTaskGoToNewtStepWithGLAccount)()     

        _RegistryTaskGoToNewtStepWithGLAccount.SelectedTasks = New ArrayList()
        _RegistryTaskGoToNewtStepWithGLAccount.SelectedTasks.AddRange(selection_RegistryVC)


        Dim _RegistryTasks As RegistryTasks
        _RegistryTasks = TryCast(View.SelectedObjects(0), RegistryTasks)
        _RegistryTaskGoToNewtStepWithGLAccount.CustomersFrom = _ocur.GetObject(_RegistryTasks.RegistryHeader.CustomersFrom)
      
        noselect_RegistryVC = True

        e.View = Application.CreateDetailView(_onew, "RegistryTaskGoToNewtStepWithGLAccount_DetailView", True, _RegistryTaskGoToNewtStepWithGLAccount)
    End Sub

    Private Sub aRegistryTaskGroupGotoNextStepWithGLAccount_Execute(sender As Object, e As PopupWindowShowActionExecuteEventArgs) Handles aRegistryTaskGroupGotoNextStepWithGLAccount.Execute
        '// Az action leigazol egy számlát technikai szerződéssel egy soron , majd fel is adja a könyvelésbe
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)

        Dim _RegistryTasks As RegistryTasks
        Dim _RegistryTaskGoToNewtStepWithGLAccount As RegistryTaskGoToNewtStepWithGLAccount = TryCast(e.PopupWindow.View.SelectedObjects(0), RegistryTaskGoToNewtStepWithGLAccount)

        Dim pController As PersistenceValidationController = Frame.GetController(Of PersistenceValidationController)()

        If pController IsNot Nothing Then
            AddHandler pController.NeedToValidateObject, AddressOf NeedToValidateObject
        End If
        RaiseEvent InitWork(1, 1, View.SelectedObjects.Count)
        For Each _RegistryTasks In View.SelectedObjects

            RaiseEvent DoWork()
            '// Technikai szerződés készítése
            Dim _TechnicalContractTemplate As ContractTemplate = _ocur.FindObject(Of ContractTemplate)(CriteriaOperator.Parse("CustomersFrom=? And IsTechnical=True", _RegistryTasks.RegistryHeader.CustomersFrom))
            Dim _Contracts As Contracts = _ocur.FindObject(Of Contracts)(CriteriaOperator.Parse("CustomersFrom=? AND Customers=? AND ContractTemplate=?",
                                                                                                _RegistryTasks.RegistryHeader.CustomersFrom, _RegistryTasks.RegistryHeader.Customers,
                                                                                                _TechnicalContractTemplate))
            Dim _ContractRows As ContractRows
            Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
            If _Contracts Is Nothing Then
                _Contracts = _ocur.CreateObject(Of Contracts)()
                _Contracts.CustomersFrom = _RegistryTasks.RegistryHeader.CustomersFrom
                _Contracts.Customers = _RegistryTasks.RegistryHeader.Customers
                _Contracts.ContractTemplate = _TechnicalContractTemplate
                _Contracts.DateCreated = _RegistryTasks.RegistryHeader.F_DateCreated
                _Contracts.DateExecution = _RegistryTasks.RegistryHeader.F_DateExecution
                _Contracts.DocumentNumber = _Contracts.ContractTemplate.NumberGenerator.GetNewNumber(_Contracts.ContractTemplate.NumberGenerator)
                _Contracts.State = State.Signed
                _Contracts.ShortName = "TECHNIKAI SZRERZŐDÉS"
            End If

            _ContractRows = _ocur.CreateObject(Of ContractRows)()
            _ContractRows.Contracts = _Contracts
            _ContractRows.CurrencyName = _RegistryTasks.RegistryHeader.F_CurrencyName
            _ContractRows.ContractRowsType = eContractRowsType.eFix
            _ContractRows.DateExecution = _RegistryTasks.RegistryHeader.F_DateExecution
            _ContractRows.Controlling = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.Controlling)
            If _RegistryTasks.RegistryHeader.F_CurrencyName.ShortName = "HUF" Then
                _ContractRows.NettoPriceHUF = _RegistryTasks.RegistryHeader.NettoAmountRemaining
            Else
                If _RegistryTasks.RegistryHeader.F_CurrencyRate <> 0 Then
                    _ContractRows.NettoPriceDEV = _RegistryTasks.RegistryHeader.NettoAmountRemaining / _RegistryTasks.RegistryHeader.F_CurrencyRate
                Else
                    _ContractRows.NettoPriceDEV = 0
                End If
                _ContractRows.NettoPriceHUF = _RegistryTasks.RegistryHeader.NettoAmountRemaining
            End If
            _ContractRows.ShortName = _RegistryTasks.RegistryHeader.ShortName


            'IDE KELL VALAMI ÁFA !
            Dim _RegistryRowsFinancial As RegistryRowsFinancial
            For Each _RegistryRowsFinancial In _RegistryTasks.RegistryHeader.RegistryRowsFinancial
                _RegistryRowsFinancial.F_ReadyforBookEntryRows = True
            Next

            For Each _RegistryRowsFinancial In _RegistryTasks.RegistryHeader.RegistryRowsFinancial
                _ContractRows.VAT = _RegistryRowsFinancial.VAT
                Exit For
            Next


            'If _TechnicalContractTemplate.Rule5DMatrix.RequireUniqueObjects = True Then
            '    If _RegistryTaskGoToNewtStepWithGLAccount.UniqueObjects IsNot Nothing Then
            '        _ContractRows.UniqueObjects = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.UniqueObjects)
            '    Else
            '        MsgBox("Az Egyedi azonosító paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
            '    End If
            'Else
            '    _ContractRows.UniqueObjects = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.UniqueObjects)
            'End If
            If _RegistryTasks.RegistryHeader.UniqueObjects IsNot Nothing Then
                _ContractRows.UniqueObjects = _ocur.GetObject(_RegistryTasks.RegistryHeader.UniqueObjects)
            Else
                _ContractRows.UniqueObjects = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.UniqueObjects)
            End If

            _ContractRows.CostHolder = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.CostHolder)
            _ContractRows.CostPlace = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.CostPlace)
            _ContractRows.Controlling = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.Controlling)
            _ContractRows.JobNumberObjects = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.JobNumberObjects)

            _RegistryRowsFinancialControlling = _ocur.CreateObject(Of RegistryRowsFinancialControlling)()
            _RegistryRowsFinancialControlling.RegistryHeader = _RegistryTasks.RegistryHeader
            _RegistryRowsFinancialControlling.ContractRows = _ContractRows
            _RegistryRowsFinancialControlling.Amount = _RegistryTasks.RegistryHeader.NettoAmountRemaining
            _RegistryRowsFinancialControlling.Controlling = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.Controlling)
            _RegistryRowsFinancialControlling.CostHolder = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.CostHolder)
            _RegistryRowsFinancialControlling.CostPlace = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.CostPlace)
            _RegistryRowsFinancialControlling.Note = _RegistryTasks.RegistryHeader.ShortName
            _RegistryRowsFinancialControlling.JobNumberObjects = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.JobNumberObjects)
            _RegistryRowsFinancialControlling.UniqueObjects = _ocur.GetObject(_RegistryTaskGoToNewtStepWithGLAccount.UniqueObjects)


            If _RegistryTaskGoToNewtStepWithGLAccount.IsReinvoice = True Then
                _RegistryRowsFinancialControlling.IsReInvoice = _RegistryTaskGoToNewtStepWithGLAccount.IsReinvoice
                _RegistryRowsFinancialControlling.ReInvoiceMode = eReinvoiceMode.eGeneral
            End If

            _RegistryRowsFinancialControlling.F_ReadyforBookEntryRows = True
            _ContractRows.RegistryRowsFinancialControlling = _RegistryRowsFinancialControlling
            _RegistryTasks.RegistryHeader.F_ReadyforBookEntry = True

            '// El is kell léptetni az utolsó lépésre ! (itt már nem generálódik feladat !!!)
            Dim _WorkflowSystemSteps As WorkflowSystemSteps
            For Each _WorkflowSystemSteps In _RegistryTasks.RegistryHeader.RegistryType.WorkflowSystem.WorkflowSystemSteps
                If _WorkflowSystemSteps.IsLastStep Then
                    _RegistryTasks.RegistryHeader.CurrentWorkflowSystemSteps = _WorkflowSystemSteps
                    _RegistryTasks.CurrentWorkflowSystemSteps = _WorkflowSystemSteps
                    Exit For
                End If
            Next
            _RegistryTasks.Status = General.TaskStatus.Completed


            _ocur.CommitChanges()

            If _RegistryTasks.RegistryHeader.BookEntryCheck(0, _RegistryTasks.RegistryHeader, _ocur.Session) = True Then
                _RegistryTasks.RegistryHeader.BookEntry(0, _RegistryTasks.RegistryHeader, _ocur.Session, True)
            Else

            End If
        Next
        RaiseEvent FinalWork
        noselect_RegistryVC = False
    End Sub

    Private Sub NeedToValidateObject(sender As Object, e As NeedToValidateObjectEventArgs)

    End Sub

    Private Sub RegistryTaskGoToNewtStepWithGLAccount_PopUp_AcceptAction_Executing(sender As Object, e As CancelEventArgs)
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _RegistryTaskGoToNewtStepWithGLAccount As RegistryTaskGoToNewtStepWithGLAccount = TryCast(View.SelectedObjects(0), RegistryTaskGoToNewtStepWithGLAccount)


        For Each _RegistryTasks As RegistryTasks In _RegistryTaskGoToNewtStepWithGLAccount.SelectedTasks
            Dim _TechnicalContractTemplate As ContractTemplate = _onew.FindObject(Of ContractTemplate)(CriteriaOperator.Parse("CustomersFrom=? And IsTechnical=True", _onew.GetObject(_RegistryTasks.RegistryHeader.CustomersFrom)))

            If _TechnicalContractTemplate IsNot Nothing And _TechnicalContractTemplate.Rule5DMatrix IsNot Nothing Then
              
                If _TechnicalContractTemplate.Rule5DMatrix.RequireUniqueObjects = True Then
                    If _RegistryTaskGoToNewtStepWithGLAccount.UniqueObjects Is Nothing Then
                        MsgBox("Az Egyedi azonosító paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
                        e.Cancel = True
                        noselect_RegistryVC = False
                        Exit For
                    End If
                End If
                If _TechnicalContractTemplate.Rule5DMatrix.RequireControlling = True Then
                    If _RegistryTaskGoToNewtStepWithGLAccount.Controlling Is Nothing Then
                        MsgBox("A controllszám paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
                        e.Cancel = True
                        noselect_RegistryVC = False
                        Exit For
                    End If
                End If
                If _TechnicalContractTemplate.Rule5DMatrix.RequireCostHolder = True Then
                    If _RegistryTaskGoToNewtStepWithGLAccount.CostHolder Is Nothing Then
                        MsgBox("A költségviselő paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
                        e.Cancel = True
                        noselect_RegistryVC = False
                        Exit For
                    End If
                End If
                If _TechnicalContractTemplate.Rule5DMatrix.RequireCostPlace = True Then
                    If _RegistryTaskGoToNewtStepWithGLAccount.CostPlace Is Nothing Then
                        MsgBox("A költséghely paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
                        e.Cancel = True
                        noselect_RegistryVC = False
                        Exit For
                    End If
                End If
                If _TechnicalContractTemplate.Rule5DMatrix.RequireJobNumberObjects = True Then
                    If _RegistryTaskGoToNewtStepWithGLAccount.JobNumberObjects Is Nothing Then
                        MsgBox("A projekt paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
                        e.Cancel = True
                        noselect_RegistryVC = False
                        Exit For
                    End If
                End If              
            End If
            
            If _RegistryTaskGoToNewtStepWithGLAccount.IsReinvoice = True And _RegistryTaskGoToNewtStepWithGLAccount.Controlling Is Nothing Then
                MsgBox("A t.sz.-hoz a controllszám paramétert kötelező megadni!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, String.Format(CaptionHelper.GetLocalizedText("Exceptions\SISBusinessExceptions", "MsgBoxCheckItAgain")))
                e.Cancel = True
                noselect_RegistryVC = False
                Exit For
            End If
        Next
    End Sub

    Private Sub aRegistryTaskGroupGotoNextStepWithGLAccount_Cancel(sender As Object, e As EventArgs) Handles aRegistryTaskGroupGotoNextStepWithGLAccount.Cancel
        noselect_RegistryVC = False
    End Sub

    Private Sub aViewPCIDW_RegistryHeader_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles aViewPCIDW_RegistryHeader.Execute
        Dim _onew As Xpo.XPObjectSpace = Application.CreateObjectSpace
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryHeader As RegistryHeader = TryCast(View.SelectedObjects(0), RegistryHeader)

        If _RegistryHeader IsNot Nothing Then
            ViewPDCI.ViewPDCIDetail(_onew, Application, e, _RegistryHeader.CustomersFrom, _
                              _RegistryHeader.Customers, 1, _
                              _RegistryHeader.DocumentNumber)
        End If
    End Sub
End Class
