Imports System
Imports System.Security.Principal
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Base.Security
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Security
Imports DevExpress.ExpressApp.Updating
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
Imports System.Data.SqlClient
Imports System.IO
Public Class Updater
    Inherits DevExpress.ExpressApp.Updating.ModuleUpdater

    Public Sub New(ByVal ObjectSpace As IObjectSpace, ByVal currentDBVersion As Version)
        MyBase.New(ObjectSpace, currentDBVersion)
    End Sub
    Public Overrides Sub UpdateDatabaseAfterUpdateSchema()
        MyBase.UpdateDatabaseAfterUpdateSchema()

        'Dim anonymousUser As SecurityUser = ObjectSpace.FindObject(Of SecurityUser)(New BinaryOperator("UserName", SecurityStrategy.AnonymousUserName))
        'If anonymousUser Is Nothing Then
        '    anonymousUser = ObjectSpace.CreateObject(Of SecurityUser)()
        '    anonymousUser.UserName = SecurityStrategy.AnonymousUserName
        '    anonymousUser.IsActive = True
        '    anonymousUser.SetPassword("")
        '    anonymousUser.Save()
        'End If


        ' If a user named 'Sam' doesn't exist in the database, create this user 
        Dim _SysAdmin As User = ObjectSpace.FindObject(Of User)(New BinaryOperator("UserName", "SysAdmin"))
        If _SysAdmin Is Nothing Then
            _SysAdmin = ObjectSpace.CreateObject(Of User)()
            _SysAdmin.UserName = "SysAdmin"
            _SysAdmin.FirstName = "SysAdmin"
            ' Set a password if the standard authentication type is used 
            _SysAdmin.SetPassword("SysAdmin")
        End If
        ' If a role with the Administrators name doesn't exist in the database, create this role 
        Dim adminRole As Role = ObjectSpace.FindObject(Of Role)(New BinaryOperator("Name", "Administrators"))
        If adminRole Is Nothing Then
            adminRole = ObjectSpace.CreateObject(Of Role)()
            adminRole.Name = "Administrators"
        End If

        Dim ListViewModelManagerRole As Role = ObjectSpace.FindObject(Of Role)(New BinaryOperator("Name", "ListViewModelManager"))
        If ListViewModelManagerRole Is Nothing Then
            ListViewModelManagerRole = ObjectSpace.CreateObject(Of Role)()
            ListViewModelManagerRole.Name = "ListViewModelManager"
        End If

        ' Delete all permissions assigned to the Administrators and Users roles 
        Do While adminRole.PersistentPermissions.Count > 0
            ObjectSpace.Delete(adminRole.PersistentPermissions(0))
        Loop
        ' Allow full access to all objects to the Administrators role 
        adminRole.AddPermission(New ObjectAccessPermission(GetType(Object), ObjectAccess.AllAccess))
        ' Allow editing the Application Model to the Administrators role 
        adminRole.AddPermission(New EditModelPermission(ModelAccessModifier.Allow))
        ' Save the Administrators role to the database 
        adminRole.Save()
        ' Allow full access to all objects to the Users role 
        ' Add the Administrators role to the _SysAdmin 
        _SysAdmin.Roles.Add(adminRole)
        ' Save the users to the database 
        _SysAdmin.Save()

        'Dim administratorRole As SecurityRole = ObjectSpace.FindObject(Of SecurityRole)(New BinaryOperator("Name", SecurityStrategy.AdministratorRoleName))
        'If administratorRole Is Nothing Then
        '    administratorRole = ObjectSpace.CreateObject(Of SecurityRole)()
        '    administratorRole.Name = SecurityStrategy.AdministratorRoleName
        '    administratorRole.CanEditModel = True
        'End If

        'administratorRole.BeginUpdate()
        'administratorRole.Permissions.GrantRecursive(GetType(Object), SecurityOperations.FullAccess)
        'administratorRole.EndUpdate()
        'administratorRole.Save()
        'Dim adminName As String = "Administrator"
        'Dim administratorUser As SecurityUser = ObjectSpace.FindObject(Of SecurityUser)(New BinaryOperator("UserName", adminName))
        'If administratorUser Is Nothing Then
        '    administratorUser = ObjectSpace.CreateObject(Of SecurityUser)()
        '    administratorUser.UserName = adminName
        '    administratorUser.IsActive = True
        '    administratorUser.SetPassword("")
        '    administratorUser.Roles.Add(administratorRole)
        '    administratorUser.Save()
        'End If


        '-- Devizák hozzáadása
        Dim _CurrencyName As CurrencyName = ObjectSpace.FindObject(Of CurrencyName)(New BinaryOperator("ShortName", "HUF"))
        If _CurrencyName Is Nothing Then
            _CurrencyName = ObjectSpace.CreateObject(Of CurrencyName)()
            _CurrencyName.ShortName = "HUF"
        End If
        _CurrencyName.Save()
        _CurrencyName = ObjectSpace.FindObject(Of CurrencyName)(New BinaryOperator("ShortName", "EUR"))
        If _CurrencyName Is Nothing Then
            _CurrencyName = ObjectSpace.CreateObject(Of CurrencyName)()
            _CurrencyName.ShortName = "EUR"
        End If
        _CurrencyName.Save()
        _CurrencyName = ObjectSpace.FindObject(Of CurrencyName)(New BinaryOperator("ShortName", "USD"))
        If _CurrencyName Is Nothing Then
            _CurrencyName = ObjectSpace.CreateObject(Of CurrencyName)()
            _CurrencyName.ShortName = "USD"
        End If
        _CurrencyName.Save()

        Dim _NumberGeneratorGroups As NumberGeneratorGroups = ObjectSpace.FindObject(Of NumberGeneratorGroups)(New BinaryOperator("ShortName", "Support"))
        If _NumberGeneratorGroups Is Nothing Then
            _NumberGeneratorGroups = ObjectSpace.CreateObject(Of NumberGeneratorGroups)()
            _NumberGeneratorGroups.ShortName = "Support"
            _NumberGeneratorGroups.Description = "Support"
            _NumberGeneratorGroups.Save()
        End If
        Dim _SupportNG As SupportNG = ObjectSpace.FindObject(Of SupportNG)(New BinaryOperator("SupportType", 0))
        If _SupportNG Is Nothing Then
            Dim _NG As NumberGenerator
            _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
            _NG.NumberGeneratorGroups = _NumberGeneratorGroups
            _NG.PrefixString = "Q"
            _NG.NewNumberPerYear = False
            _NG.YearFormat = eYearFormat.YearNoDigit
            _NG.SerialNumberDigit = 5
            _NG.SerialNumberPlace = ePlace.Right
            _NG.Save()

            _SupportNG = ObjectSpace.CreateObject(Of SupportNG)()
            _SupportNG.SupportType = 0
            _SupportNG.NumberGenerator = _NG
            _SupportNG.Save()
        End If
        _SupportNG = ObjectSpace.FindObject(Of SupportNG)(New BinaryOperator("SupportType", 1))
        If _SupportNG Is Nothing Then
            Dim _NG As NumberGenerator
            _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
            _NG.NumberGeneratorGroups = _NumberGeneratorGroups
            _NG.PrefixString = "A"
            _NG.NewNumberPerYear = False
            _NG.YearFormat = eYearFormat.YearNoDigit
            _NG.SerialNumberDigit = 5
            _NG.SerialNumberPlace = ePlace.Right
            _NG.Save()

            _SupportNG = ObjectSpace.CreateObject(Of SupportNG)()
            _SupportNG.SupportType = 1
            _SupportNG.NumberGenerator = _NG
            _SupportNG.Save()
        End If
        _SupportNG = ObjectSpace.FindObject(Of SupportNG)(New BinaryOperator("SupportType", 2))
        If _SupportNG Is Nothing Then
            Dim _NG As NumberGenerator
            _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
            _NG.NumberGeneratorGroups = _NumberGeneratorGroups
            _NG.PrefixString = "PE"
            _NG.NewNumberPerYear = False
            _NG.YearFormat = eYearFormat.YearNoDigit
            _NG.SerialNumberDigit = 5
            _NG.SerialNumberPlace = ePlace.Right
            _NG.Save()

            _SupportNG = ObjectSpace.CreateObject(Of SupportNG)()
            _SupportNG.SupportType = 2
            _SupportNG.NumberGenerator = _NG
            _SupportNG.Save()
        End If

        Dim _LiquidAssetsBallanceHeader As LiquidAssetsBallanceHeader

        Dim _LiquidAssetsBallanceRows_Collection As New XPCollection(Of LiquidAssetsBallanceRows)(TryCast(ObjectSpace, Xpo.XPObjectSpace).Session)
        ObjectSpace.Delete(_LiquidAssetsBallanceRows_Collection)

        Dim _LiquidAssetsBallanceHeader_Collection As New XPCollection(Of LiquidAssetsBallanceHeader)(TryCast(ObjectSpace, Xpo.XPObjectSpace).Session)
        ObjectSpace.Delete(_LiquidAssetsBallanceHeader_Collection)

        _LiquidAssetsBallanceHeader = ObjectSpace.CreateObject(Of LiquidAssetsBallanceHeader)()
        _LiquidAssetsBallanceHeader.DateExecution = Now
        _LiquidAssetsBallanceHeader.Save()
        '----------------------------SQL command ------------------------------------------------------------
        'ExecuteSQLCommands("App_Data\SQLScripts.sql")
        '----------------------------------------------------------------------------------------------------
        '_2011_01_07(ObjectSpace)
        '_2011_03_08(ObjectSpace)
        '_2011_04_20(ObjectSpace)
        '_2011_05_10(ObjectSpace)
        '_2011_06_01(ObjectSpace)
        '_2011_06_28(ObjectSpace)
        'DropTable("PartnerConnectionInfo", True)
        'DeleteObjectType("Nuvolar.Module.PartnerConnectionInfo")
        '_2011_09_09(ObjectSpace)
        '_2011_09_25(ObjectSpace)
        '_2011_09_30(ObjectSpace)




        Dim _CustomersNG As CustomersNG = ObjectSpace.FindObject(Of CustomersNG)(CriteriaOperator.Parse("Oid=Oid"))
        If _CustomersNG Is Nothing Then
            Dim _NG As NumberGenerator
            _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
            _NG.NumberGeneratorGroups = _NumberGeneratorGroups
            _NG.PrefixString = "S"
            _NG.NewNumberPerYear = False
            _NG.YearFormat = eYearFormat.YearNoDigit
            _NG.SerialNumberDigit = 5
            _NG.SerialNumberPlace = ePlace.Right
            _NG.Save()

            _CustomersNG = ObjectSpace.CreateObject(Of CustomersNG)()
            _CustomersNG.NumberGenerator = _NG
            _CustomersNG.ShortName = "Ügyfelek sorszámai"

        End If

        Dim _ContactsNG As ContactsNG = ObjectSpace.FindObject(Of ContactsNG)(CriteriaOperator.Parse("Oid=Oid"))
        If _ContactsNG Is Nothing Then
            Dim _NG As NumberGenerator
            _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
            _NG.NumberGeneratorGroups = _NumberGeneratorGroups
            _NG.PrefixString = "K"
            _NG.NewNumberPerYear = False
            _NG.YearFormat = eYearFormat.YearNoDigit
            _NG.SerialNumberDigit = 5
            _NG.SerialNumberPlace = ePlace.Right
            _NG.Save()

            _ContactsNG = ObjectSpace.CreateObject(Of ContactsNG)()
            _ContactsNG.NumberGenerator = _NG
            _ContactsNG.ShortName = "Kapcsolatok sorszámai"

        End If

        SetDefaultStorage(ObjectSpace)
        SetWorkflow(ObjectSpace)
        SetCRM(ObjectSpace)
        SetDefaultfixedAssets(ObjectSpace)

        '_2011_11_22(ObjectSpace, CurrentDBVersion)
        _2012_03_01(ObjectSpace, CurrentDBVersion)
        _2012_03_10(ObjectSpace, CurrentDBVersion)
        _2012_04_13(ObjectSpace, CurrentDBVersion)
        _2012_05_02(ObjectSpace, CurrentDBVersion)
        _2012_05_08(ObjectSpace, CurrentDBVersion)
        _2012_08_31(ObjectSpace, CurrentDBVersion)
        _2012_10_29(ObjectSpace, CurrentDBVersion)
        _2012_11_08(ObjectSpace, CurrentDBVersion)
        _2013_04_17(ObjectSpace, CurrentDBVersion)
        _2013_04_25(ObjectSpace, CurrentDBVersion)
        _2013_07_23(ObjectSpace, CurrentDBVersion)
        _2013_07_23_1(ObjectSpace, CurrentDBVersion)
        _2014_02_14(ObjectSpace, CurrentDBVersion)
        _2014_03_07(ObjectSpace, CurrentDBVersion)
        _2016_01_28(ObjectSpace, CurrentDBVersion)
        ProductsGant(ObjectSpace)
        ' ZIPHUUpdate(ObjectSpace)
        StorageOut_Storno_Regenerate(ObjectSpace)
        'RegistryHeader_UserCreated(ObjectSpace)


    End Sub
    Private Sub _2011_01_07(ByVal ObjectSpace As Xpo.XPObjectSpace)
        'RegistryBankTransfer javítása
        Dim _RegistryHeader_Collection As XPCollection(Of RegistryHeader) = _
            New XPCollection(Of RegistryHeader)(ObjectSpace.Session, CriteriaOperator.Parse("RegistryType.RegistryMainType=0 and (F_AmountBruttoHUF>0 or F_AmountBruttoDEV > 0)"))
        Dim _RegistryHeader As RegistryHeader

        For Each _RegistryHeader In _RegistryHeader_Collection
            If _RegistryHeader.RegistryBankTransfer.Count = 0 Then
                If _RegistryHeader.F_PayMode = ePayMode.InTransfer Or _RegistryHeader.F_PayMode = ePayMode.InContinuous Then
                    Dim _RegistryBankTransfer As RegistryBankTransfer = ObjectSpace.CreateObject(Of RegistryBankTransfer)()
                    _RegistryBankTransfer.RegistryHeader = _RegistryHeader
                    _RegistryBankTransfer.DatePayment = _RegistryHeader.F_DatePayment
                    _RegistryBankTransfer.AmountDEV = _RegistryHeader.F_AmountBruttoDEV
                    _RegistryBankTransfer.AmountHUF = _RegistryHeader.F_AmountBruttoHUF
                    _RegistryBankTransfer.Save()
                End If
            End If
        Next
    End Sub
    Private Sub _2011_03_08(ByVal ObjectSpace As Xpo.XPObjectSpace)
        'ExecuteNonQueryCommand(

    End Sub
    Private Sub _2011_04_20(ByVal ObjectSpace As Xpo.XPObjectSpace)
        Dim _COA As ChartOfAccounts
        _COA = ObjectSpace.FindObject(Of ChartOfAccounts)(CriteriaOperator.Parse("isnull(ChartOfAccounts1)=True"))
        If _COA IsNot Nothing Then
            _COA.Reconfigure_ChartOfAccounts(ObjectSpace)
        End If
    End Sub
    Private Sub _2011_05_10(ByVal ObjectSpace As Xpo.XPObjectSpace)
        Dim _GLRows As GLRows
        Dim _InvoiceRows As InvoiceRows
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling

        Dim I As Long = 0
        Dim _GLRows_Collection As New XPCollection(Of GLRows) _
            (ObjectSpace.Session, CriteriaOperator.Parse("GLHeader.CurrencyName.ShortName='HUF' and AmountDEV<>0"))

        For Each _GLRows In _GLRows_Collection
            _GLRows.AmountDEV = 0
            _GLRows.Save()
        Next

        Dim _InvoiceRows_Collection As New XPCollection(Of InvoiceRows) _
          (ObjectSpace.Session, CriteriaOperator.Parse("isnull(ReadyforBookEntryRows)=True"))
        For Each _InvoiceRows In _InvoiceRows_Collection
            _InvoiceRows.ReadyforBookEntryRows = False
            _InvoiceRows.Save()
        Next

        Dim _RegistryRowsFinancialControlling_Collection As New XPCollection(Of RegistryRowsFinancialControlling) _
          (ObjectSpace.Session, CriteriaOperator.Parse("isnull(F_ReadyforBookEntryRows)=True"))
        For Each _RegistryRowsFinancialControlling In _RegistryRowsFinancialControlling_Collection
            _RegistryRowsFinancialControlling.F_ReadyforBookEntryRows = False
            _RegistryRowsFinancialControlling.Save()
        Next

    End Sub
    Private Sub _2011_06_01(ByVal ObjectSpace As Xpo.XPObjectSpace)
        Dim _Controlling_Collection As New XPCollection(Of Controlling)(ObjectSpace.Session)
        Dim _Controlling As Controlling

        For Each _Controlling In _Controlling_Collection
            _Controlling.ReconfigureGroup(ObjectSpace, _Controlling, False)
        Next
    End Sub
    Private Sub _2011_06_28(ByVal ObjectSpace As Xpo.XPObjectSpace)

        Dim _uow As New UnitOfWork(ObjectSpace.Session.DataLayer)
        Dim _uow2 As New UnitOfWork(ObjectSpace.Session.DataLayer)


        '// Stornó számlák javítása
        Dim _InvoiceHeader_Collection As New XPCollection(_uow, GetType(InvoiceHeader), CriteriaOperator.Parse("IsStorno=True"))
        Dim _OriginalInvoice As InvoiceHeader
        Dim _OriginalInvoiceRows As InvoiceRows
        Dim _RowsUpdateSucceded As Boolean
        Dim _HasError As Boolean = False

        For Each _InvoiceHeader As InvoiceHeader In _InvoiceHeader_Collection

            'Feltételezzük, hogy nincs benne hiba
            _HasError = False

            For Each _InvoiceRows As InvoiceRows In _InvoiceHeader.InvoiceRows

                ' Ha a sorokban hiány lép fel akkor szinkronizáljuk az eredeti számlasorral a jelölő adatokat

                If _InvoiceRows.InvoiceRows Is Nothing Then
                    _OriginalInvoice = _uow.FindObject(Of InvoiceHeader)(CriteriaOperator.Parse("DocumentNumber=?", _InvoiceHeader.ConnectInfo))
                    _OriginalInvoiceRows = _uow.FindObject(Of InvoiceRows)(CriteriaOperator.Parse("InvoiceHeader=? AND ShortName=?", _OriginalInvoice, _InvoiceRows.ShortName))
                    'Jelezzük, hogy újra kell könyvelni a sorhoz tartozó fejlécet
                    _HasError = True
                    _RowsUpdateSucceded = False
                    'Jelölő adatok átadása
                    If _OriginalInvoiceRows IsNot Nothing Then
                        _InvoiceRows.JobNumberObjects = _OriginalInvoiceRows.JobNumberObjects
                        _InvoiceRows.UniqueObjects = _OriginalInvoiceRows.UniqueObjects
                        _InvoiceRows.Controlling = _OriginalInvoiceRows.Controlling
                        _InvoiceRows.CostHolder = _OriginalInvoiceRows.CostHolder
                        _InvoiceRows.CostPlace = _OriginalInvoiceRows.CostPlace
                        _InvoiceRows.InvoiceRows = _OriginalInvoiceRows
                        _RowsUpdateSucceded = True
                    End If
                    'Könyvelhetőség visszaállítása

                    _InvoiceRows.ReadyforBookEntryRows = False

                End If
            Next
            If _HasError And _InvoiceHeader.GLAccounts IsNot Nothing Then
                'Könyvelési tételek visszavonása
                _InvoiceHeader.BookEntryRemove(_InvoiceHeader, _uow, True)
                If _RowsUpdateSucceded Then
                    'Újra könyvelés
                    _InvoiceHeader.ReadyforBookEntry = False
                    _InvoiceHeader.BookEntry(0, _InvoiceHeader, _uow, True)
                End If
            End If
        Next
        _uow.CommitChanges()

        '// Hibás könyvelt ÁFA sorok visszavonása

        Dim _GLRows_Collection As New XPCollection(_uow2, GetType(GLRows), (CriteriaOperator.Parse("GLHeader.GLRows.Count=1 AND GLHeader.GLDocumentType=1")))
        Dim _RegistryHeader_Collection As New XPCollection(_uow2, GetType(RegistryHeader), CriteriaOperator.Parse("1=2"))
        For i As Integer = 0 To _GLRows_Collection.Count - 1 Step 1
            If _GLRows_Collection(i).GLRowsTypeVAT = eGLRowsTypeVAT.eVATRow Then
                Dim _RegistryHeader As RegistryHeader = _uow2.FindObject(Of RegistryHeader)(CriteriaOperator.Parse("F_GLAccounts.Oid=?", _GLRows_Collection(i).GLHeader.Oid))
                _RegistryHeader_Collection.Add(_RegistryHeader)
            End If
        Next
        For Each _RegistryHeader As RegistryHeader In _RegistryHeader_Collection
            _RegistryHeader.BookEntryRemove(_RegistryHeader, _uow2, True)
        Next

        _uow2.CommitChanges()

    End Sub
    Private Sub _2011_09_09(ByVal ObjectSpace As Xpo.XPObjectSpace)
        'ExecuteNonQueryCommand("update GLBank set LiquidAssets_Main=row_LiquidAssets_Main", False)
        'ExecuteNonQueryCommand("update GLCassa set LiquidAssets_Cassa=row_LiquidAssets_Cassa", False)
        'ExecuteNonQueryCommand("update GLCompensation set LiquidAssets_Main=row_LiquidAssets_Main", False)
    End Sub
    Private Sub _2011_09_25(ByVal ObjectSpace As Xpo.XPObjectSpace)
        Dim _GLCassa As GLCassa
        Dim _InvoiceRows As InvoiceRows
        Dim _InvoiceVATRows As InvoiceVATRows
        Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
        Dim _RegistryRowsFinancial As RegistryRowsFinancial

        Dim _GLCassa_Collection As New XPCollection(Of GLCassa)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(IsStorno)=True"))
        For Each _GLCassa In _GLCassa_Collection
            _GLCassa.IsStorno = False
            _GLCassa.Save()
        Next
        Dim _GLCassa_Collection1 As New XPCollection(Of GLCassa)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(DocumentNumber)=True"))
        For Each _GLCassa In _GLCassa_Collection1
            _GLCassa.DocumentNumber = ""
            _GLCassa.Save()
        Next


        Dim _InvoiceRows_Collection As New XPCollection(Of InvoiceRows)(ObjectSpace.Session, CriteriaOperator.Parse("ReadyforBookEntryRows = True and InvoiceHeader.ReadyforBookEntry = False"))
        For Each _InvoiceRows In _InvoiceRows_Collection
            _InvoiceRows.InvoiceHeader.ReadyforBookEntry = True
            _InvoiceRows.InvoiceHeader.Save()
        Next

        Dim _InvoiceVATRows_Collection As New XPCollection(Of InvoiceVATRows)(ObjectSpace.Session, CriteriaOperator.Parse("ReadyforBookEntryRows = True and InvoiceHeader.ReadyforBookEntry = False"))
        For Each _InvoiceVATRows In _InvoiceVATRows_Collection
            _InvoiceVATRows.InvoiceHeader.ReadyforBookEntry = True
            _InvoiceVATRows.InvoiceHeader.Save()
        Next

        Dim _RegistryRowsFinancial_Collection As New XPCollection(Of RegistryRowsFinancial)(ObjectSpace.Session, CriteriaOperator.Parse("F_ReadyforBookEntryRows = True and RegistryHeader.F_ReadyforBookEntry = False"))
        For Each _RegistryRowsFinancial In _RegistryRowsFinancial_Collection
            _RegistryRowsFinancial.RegistryHeader.F_ReadyforBookEntry = True
            _RegistryRowsFinancial.RegistryHeader.Save()
        Next

        Dim _RegistryRowsFinancialControlling_Collection As New XPCollection(Of RegistryRowsFinancialControlling)(ObjectSpace.Session, CriteriaOperator.Parse("F_ReadyforBookEntryRows = True and RegistryHeader.F_ReadyforBookEntry = False"))
        For Each _RegistryRowsFinancialControlling In _RegistryRowsFinancialControlling_Collection
            _RegistryRowsFinancialControlling.RegistryHeader.F_ReadyforBookEntry = True
            _RegistryRowsFinancialControlling.RegistryHeader.Save()
        Next

        '-- GLAccounts javítása
        Dim _GLRows_Collection As New XPCollection(Of GLRows)(ObjectSpace.Session, CriteriaOperator.Parse("VAT.InversState=True"))
        Dim _GLRows As GLRows
        Dim _GLAccounts As GLAccounts
        For Each _GLRows In _GLRows_Collection
            _GLAccounts = ObjectSpace.GetObjectByKey(Of GLAccounts)(_GLRows.GLHeader.Oid)
            If _GLAccounts IsNot Nothing Then
                _GLAccounts.RecalculateTotal()
                _GLAccounts.Save()
            End If
        Next

        '-- Pénztári bizonylatok javítása
        _GLRows_Collection = New XPCollection(Of GLRows)(ObjectSpace.Session, CriteriaOperator.Parse("GLHeader.GLDocumentType=3 and isnull(VAT)=False"))
        For Each _GLRows In _GLRows_Collection
            _GLRows.DateVAT = _GLRows.GLHeader.DateExecution
            _GLRows.Save()
        Next

        Dim _GLAccounts_Collection As New XPCollection(Of GLAccounts)(ObjectSpace.Session)
        For Each _GLAccounts In _GLAccounts_Collection
            _GLAccounts.IsRegistryGLAccounts = _GLAccounts.IsRegistry
            _GLAccounts.Save()
        Next

    End Sub
    Private Sub _2011_09_30(ByVal ObjectSpace As Xpo.XPObjectSpace)
        Dim _VATReport As VATReport
        Dim _VATReport_Collection As New XPCollection(Of VATReport)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(ObjectCreated)=True Or isnull(UserCreated)=True"))

        Dim _Contracts As Contracts
        Dim _Contracts_Collection As New XPCollection(Of Contracts)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(ObjectCreated)=True Or isnull(UserCreated)=True"))

        Dim _TrialBalanceHeader As TrialBalanceHeader
        Dim _TrialBalanceHeader_Collection As New XPCollection(Of TrialBalanceHeader)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(ObjectCreated)=True Or isnull(UserCreated)=True"))

        Dim _SpecTranRevaluation As SpecTranRevaluation
        Dim _SpecTranRevaluation_Collection As New XPCollection(Of SpecTranRevaluation)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(ObjectCreated)=True Or isnull(UserCreated)=True"))

        Dim _GLReport As GLReport
        Dim _GLReport_Collection As New XPCollection(Of GLReport)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(ObjectCreated)=True Or isnull(UserCreated)=True"))

        Dim _GLCardsHeader As GLCardsHeader
        Dim _GLCardsHeader_Collection As New XPCollection(Of GLCardsHeader)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(ObjectCreated)=True Or isnull(UserCreated)=True"))

        Dim _User_Collection As New XPCollection(Of User)(ObjectSpace.Session, CriteriaOperator.Parse("1=1"))
        Dim _User As User = Nothing
        Dim _Audit_Collection As XPCollection(Of AuditDataItemPersistent)
        Dim _Audit As AuditDataItemPersistent

        For Each _VATReport In _VATReport_Collection
            _Audit_Collection = AuditedObjectWeakReference.GetAuditTrail(ObjectSpace.Session, _VATReport)

            For Each _Audit In _Audit_Collection
                If _Audit.OperationType = "ObjectCreated" Then

                    For Each _User In _User_Collection
                        If _User.UserName = _Audit.UserName Then
                            Exit For
                        End If
                    Next

                    _VATReport.ObjectCreated = _Audit.ModifiedOn
                    _VATReport.UserCreated = _User
                    _VATReport.Save()
                End If

            Next
        Next

        For Each _Contracts In _Contracts_Collection
            _Audit_Collection = AuditedObjectWeakReference.GetAuditTrail(ObjectSpace.Session, _Contracts)
            If _Audit_Collection IsNot Nothing Then
                For Each _Audit In _Audit_Collection
                    If _Audit.OperationType = "ObjectCreated" Then

                        For Each _User In _User_Collection
                            If _User.UserName = _Audit.UserName Then
                                Exit For
                            End If
                        Next

                        _Contracts.ObjectCreated = _Audit.ModifiedOn
                        _Contracts.UserCreated = _User
                        _Contracts.Save()
                    End If

                Next
            End If
        Next

        For Each _TrialBalanceHeader In _TrialBalanceHeader_Collection
            _Audit_Collection = AuditedObjectWeakReference.GetAuditTrail(ObjectSpace.Session, _TrialBalanceHeader)

            For Each _Audit In _Audit_Collection
                If _Audit.OperationType = "ObjectCreated" Then

                    For Each _User In _User_Collection
                        If _User.UserName = _Audit.UserName Then
                            Exit For
                        End If
                    Next

                    _TrialBalanceHeader.ObjectCreated = _Audit.ModifiedOn
                    _TrialBalanceHeader.UserCreated = _User
                    _TrialBalanceHeader.Save()
                End If

            Next
        Next

        For Each _SpecTranRevaluation In _SpecTranRevaluation_Collection
            _Audit_Collection = AuditedObjectWeakReference.GetAuditTrail(ObjectSpace.Session, _SpecTranRevaluation)

            For Each _Audit In _Audit_Collection
                If _Audit.OperationType = "ObjectCreated" Then

                    For Each _User In _User_Collection
                        If _User.UserName = _Audit.UserName Then
                            Exit For
                        End If
                    Next

                    _SpecTranRevaluation.ObjectCreated = _Audit.ModifiedOn
                    _SpecTranRevaluation.UserCreated = _User
                    _SpecTranRevaluation.Save()
                End If

            Next
        Next

        For Each _GLReport In _GLReport_Collection
            _Audit_Collection = AuditedObjectWeakReference.GetAuditTrail(ObjectSpace.Session, _GLReport)

            For Each _Audit In _Audit_Collection
                If _Audit.OperationType = "ObjectCreated" Then

                    For Each _User In _User_Collection
                        If _User.UserName = _Audit.UserName Then
                            Exit For
                        End If
                    Next

                    _GLReport.ObjectCreated = _Audit.ModifiedOn
                    _GLReport.UserCreated = _User
                    _GLReport.Save()
                End If

            Next
        Next

        For Each _GLCardsHeader In _GLCardsHeader_Collection
            _Audit_Collection = AuditedObjectWeakReference.GetAuditTrail(ObjectSpace.Session, _GLCardsHeader)

            For Each _Audit In _Audit_Collection
                If _Audit.OperationType = "ObjectCreated" Then

                    For Each _User In _User_Collection
                        If _User.UserName = _Audit.UserName Then
                            Exit For
                        End If
                    Next

                    _GLCardsHeader.ObjectCreated = _Audit.ModifiedOn
                    _GLCardsHeader.UserCreated = _User
                    _GLCardsHeader.Save()
                End If

            Next
        Next
    End Sub
    Private Sub _2011_11_22(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)

        If currentDBVersion.ToString <= "11.1.8.1083" Then
            Dim _RegistryHeader_Collection As New XPCollection(Of RegistryHeader)(ObjectSpace.Session, CriteriaOperator.Parse("RegistryType.RegistryMainType='eAccount'"))
            Dim _RegistryHeader As RegistryHeader

            For Each _RegistryHeader In _RegistryHeader_Collection
                _RegistryHeader.F_ConnectInfo = _RegistryHeader.DocumentNumber
                _RegistryHeader.Save()
            Next
        End If
    End Sub
    Private Sub _2012_03_01(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        Dim _ChartOfAccountsYear As ChartOfAccountsYear = ObjectSpace.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("1=1"))
        If _ChartOfAccountsYear Is Nothing Then
            _ChartOfAccountsYear = ObjectSpace.CreateObject(Of ChartOfAccountsYear)()
            _ChartOfAccountsYear.AccountYear = 2011
            _ChartOfAccountsYear.Save()
        End If

        If currentDBVersion.ToString <= "11.2.8.1018" Then
            Dim _ChartOfAccounts_Collection As New XPCollection(Of ChartOfAccounts)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(AccountYear)=True or AccountYear<=0"))
            Dim _ChartOfAccounts As ChartOfAccounts

            For Each _ChartOfAccounts In _ChartOfAccounts_Collection
                _ChartOfAccounts.AccountYear = 2011
                _ChartOfAccounts.Save()
            Next

            Dim _LiquidAssets_Collection As New XPCollection(Of LiquidAssets)(ObjectSpace.Session)
            Dim _LiquidAssets As LiquidAssets
            Dim _LiquidAssetsYear As LiquidAssetsYear
            For Each _LiquidAssets In _LiquidAssets_Collection
                If _LiquidAssets.LiquidAssetsYear.Count <= 0 Then
                    _LiquidAssetsYear = ObjectSpace.CreateObject(Of LiquidAssetsYear)()
                    _LiquidAssetsYear.AccountYear = 2011
                    _LiquidAssetsYear.LiquidAssets = _LiquidAssets
                    _LiquidAssetsYear.ChartOfAccounts = _LiquidAssets.ChartOfAccounts
                    _LiquidAssetsYear.ChartOfAccountsMinus = _LiquidAssets.ChartOfAccountsMinus
                    _LiquidAssetsYear.ChartOfAccountsPlus = _LiquidAssetsYear.ChartOfAccountsPlus
                End If
            Next

            Dim _VAT_Collection As New XPCollection(Of VAT)(ObjectSpace.Session)
            Dim _VAT As VAT
            Dim _VATYear As VATYear
            For Each _VAT In _VAT_Collection
                If _VAT.VATYear.Count <= 0 Then
                    _VATYear = ObjectSpace.CreateObject(Of VATYear)()
                    _VATYear.AccountYear = 2011
                    _VATYear.VAT = _VAT
                    _VATYear.ChartOfAccountsIn = _VAT.ChartOfAccountsIn
                    _VATYear.ChartOfAccountsOut = _VAT.ChartOfAccountsOut
                End If
            Next

            Dim _CustomersGLParameters_Collection As New XPCollection(Of CustomersGLParameters)(ObjectSpace.Session)
            Dim _CustomersGLParameters As CustomersGLParameters
            Dim _CustomersGLParametersYear As CustomersGLParametersYear
            For Each _CustomersGLParameters In _CustomersGLParameters_Collection
                If _CustomersGLParameters.CustomersGLParametersYear.Count <= 0 Then
                    _CustomersGLParametersYear = ObjectSpace.CreateObject(Of CustomersGLParametersYear)()
                    _CustomersGLParametersYear.AccountYear = 2011
                    _CustomersGLParametersYear.CustomersGLParameters = _CustomersGLParameters
                End If
            Next

            Dim _Controlling_Collection As New XPCollection(Of Controlling)(ObjectSpace.Session)
            Dim _Controlling As Controlling
            Dim _ControllingYear As ControllingYear
            For Each _Controlling In _Controlling_Collection
                If _Controlling.ControllingYear.Count <= 0 Then
                    _ControllingYear = ObjectSpace.CreateObject(Of ControllingYear)()
                    _ControllingYear.AccountYear = 2011
                    _ControllingYear.Controlling = _Controlling
                    _ControllingYear.ChartOfAccounts = _Controlling.ChartOfAccounts
                    _ControllingYear.ChartOfAccounts2 = _Controlling.ChartOfAccounts2
                End If
            Next

            Dim _GLHeader_RateDiffParameter_Collection As New XPCollection(Of GLHeader_RateDiffParameter)(ObjectSpace.Session)
            Dim _GLHeader_RateDiffParameter As GLHeader_RateDiffParameter
            Dim _GLHeader_RateDiffParameterYear As GLHeader_RateDiffParameterYear
            For Each _GLHeader_RateDiffParameter In _GLHeader_RateDiffParameter_Collection
                If _GLHeader_RateDiffParameter.GLHeader_RateDiffParameterYear.Count <= 0 Then
                    _GLHeader_RateDiffParameterYear = ObjectSpace.CreateObject(Of GLHeader_RateDiffParameterYear)()
                    _GLHeader_RateDiffParameterYear.AccountYear = 2011
                    _GLHeader_RateDiffParameterYear.GLHeader_RateDiffParameter = _GLHeader_RateDiffParameter
                    _GLHeader_RateDiffParameterYear.ChartOfAccounts_RateDiff_Loss = _GLHeader_RateDiffParameter.ChartOfAccounts_RateDiff_Loss
                    _GLHeader_RateDiffParameterYear.ChartOfAccounts_RateDiff_Win = _GLHeader_RateDiffParameter.ChartOfAccounts_RateDiff_Win
                    _GLHeader_RateDiffParameterYear.ChartOfAccounts_Rounding_Loss = _GLHeader_RateDiffParameter.ChartOfAccounts_Rounding_Loss
                    _GLHeader_RateDiffParameterYear.ChartOfAccounts_Rounding_Win = _GLHeader_RateDiffParameter.ChartOfAccounts_Rounding_Win
                End If
            Next
        End If
    End Sub
    Private Sub _2012_04_13(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString <= "11.2.8.1020" Then
            Dim _Apartments_Collection As New XPCollection(Of Apartments)(ObjectSpace.Session)
            Dim _Apartments As Apartments
            For Each _Apartments In _Apartments_Collection
                If _Apartments.AreaNettoForCostRecord = 0 Then
                    _Apartments.AreaNettoForCostRecord = _Apartments.AreaNettoForSale
                    _Apartments.Save()
                End If

                Dim _Garages_Collection As New XPCollection(Of Garages)(ObjectSpace.Session)
                Dim _Garages As Garages
                For Each _Garages In _Garages_Collection
                    If _Garages.AreaNettoForCostRecord = 0 Then
                        _Garages.AreaNettoForCostRecord = _Garages.AreaNetto
                        _Garages.Save()
                    End If
                Next

                Dim _Offices_Collection As New XPCollection(Of Offices)(ObjectSpace.Session)
                Dim _Offices As Offices
                For Each _Offices In _Offices_Collection
                    If _Offices.AreaNettoForCostRecord = 0 Then
                        _Offices.AreaNettoForCostRecord = _Offices.AreaNetto
                        _Offices.Save()
                    End If
                Next

                Dim _Container_Collection As New XPCollection(Of Container)(ObjectSpace.Session)
                Dim _Container As Container
                For Each _Container In _Container_Collection
                    If _Container.AreaNettoForCostRecord = 0 Then
                        _Container.AreaNettoForCostRecord = _Container.AreaNetto
                        _Container.Save()
                    End If
                Next
            Next
        End If
    End Sub
    Private Sub _2012_03_10(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "11.2.8.1026" Then


            'Dim _GLRows_Collection As New XPCollection(Of GLRows)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(GLHeader)=False and GLHeader.IsEditable=False"))
            'Dim _GLRows As GLRows

            'For Each _GLRows In _GLRows_Collection
            '    If _GLRows.DateExecution = Nothing Then
            '        _GLRows.DateExecution = _GLRows.GLHeader.DateExecution.Date
            '    End If
            'Next

            'Dim _RegistryRowsFinancialControlling_Collection As New XPCollection(Of RegistryRowsFinancialControlling)(ObjectSpace.Session, CriteriaOperator.Parse("isnull(RegistryHeader)=False and RegistryHeader.IsEditable=False and RegistryHeader.RegistryType.RegistryMainType in ('eAccount')"))
            'Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling

            'For Each _RegistryRowsFinancialControlling In _RegistryRowsFinancialControlling_Collection
            '    If _RegistryRowsFinancialControlling.DateExecution = Nothing Then
            '        _RegistryRowsFinancialControlling.DateExecution = _RegistryRowsFinancialControlling.RegistryHeader.F_DateExecution.Date
            '    End If
            'Next

        End If
    End Sub
    Private Sub _2012_05_02(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString <= "11.2.8.1027" Then
            Dim _CustomersFrom_Collection As New XPCollection(Of CustomersFrom)(ObjectSpace.Session)
            Dim _CustomersFrom As CustomersFrom
            Dim _GLMixedNG As GLMixedNG
            Dim _NumberGeneratorGroups As NumberGeneratorGroups = ObjectSpace.FindObject(Of NumberGeneratorGroups)(New BinaryOperator("ShortName", "Vegyes könyvelési tranzakciók"))
            Dim _NG As NumberGenerator

            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = ObjectSpace.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.ShortName = "Vegyes könyvelési tranzakciók"
                _NumberGeneratorGroups.Description = "Vegyes könyvelési tranzakciók"
                _NumberGeneratorGroups.Save()
            End If

            For Each _CustomersFrom In _CustomersFrom_Collection

                _GLMixedNG = ObjectSpace.FindObject(Of GLMixedNG)(CriteriaOperator.Parse("CustomersFrom=?", _CustomersFrom))

                If _GLMixedNG Is Nothing Then
                    _GLMixedNG = ObjectSpace.CreateObject(Of GLMixedNG)()
                    _GLMixedNG.CustomersFrom = _CustomersFrom
                End If

                If _GLMixedNG.NumberGenerator Is Nothing Then
                    _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                    _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                    _NG.PrefixString = "VN-"
                    _NG.SuffixString = "-"
                    _NG.NewNumberPerYear = True
                    _NG.YearFormat = eYearFormat.YearTwoDigit
                    _NG.SerialNumberDigit = 3
                    _NG.SerialNumberPlace = ePlace.Right
                    _NG.Save()

                    _GLMixedNG.NumberGenerator = _NG

                End If
                If _GLMixedNG.NumberGenerator_RateDiff Is Nothing Then
                    _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                    _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                    _NG.PrefixString = "V-ÁRFOLY-"
                    _NG.SuffixString = "-"
                    _NG.NewNumberPerYear = True
                    _NG.YearFormat = eYearFormat.YearTwoDigit
                    _NG.SerialNumberDigit = 3
                    _NG.SerialNumberPlace = ePlace.Right
                    _NG.Save()

                    _GLMixedNG.NumberGenerator_RateDiff = _NG

                End If
                If _GLMixedNG.NumberGenerator_Revaluation Is Nothing Then
                    _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                    _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                    _NG.PrefixString = "V-ÁTÉRT-"
                    _NG.SuffixString = "-"
                    _NG.NewNumberPerYear = True
                    _NG.YearFormat = eYearFormat.YearTwoDigit
                    _NG.SerialNumberDigit = 3
                    _NG.SerialNumberPlace = ePlace.Right
                    _NG.Save()

                    _GLMixedNG.NumberGenerator_Revaluation = _NG

                End If
                If _GLMixedNG.NumberGenerator_Rounding Is Nothing Then
                    _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                    _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                    _NG.PrefixString = "V-ELENG-"
                    _NG.SuffixString = "-"
                    _NG.NewNumberPerYear = True
                    _NG.YearFormat = eYearFormat.YearTwoDigit
                    _NG.SerialNumberDigit = 3
                    _NG.SerialNumberPlace = ePlace.Right
                    _NG.Save()

                    _GLMixedNG.NumberGenerator_Rounding = _NG
                End If

                _GLMixedNG.Save()
            Next


        End If
    End Sub
    Private Sub _2012_05_08(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
        Dim _WebParameters As WebParameters = _ocur.FindObject(Of WebParameters)(CriteriaOperator.Parse("1=1"))

        If _WebParameters Is Nothing Then
            _WebParameters = _ocur.CreateObject(Of WebParameters)()
            _WebParameters.Save()
        End If


    End Sub
    Private Sub _2012_08_31(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
        Dim _TrialBalanceHeader_Collection As New XPCollection(Of TrialBalanceHeader)(_ocur.Session, CriteriaOperator.Parse("isnull(IsGLOpenClose)=True"))
        Dim _TrialBalanceHeader As TrialBalanceHeader

        For Each _TrialBalanceHeader In _TrialBalanceHeader_Collection
            _TrialBalanceHeader.IsGLOpenClose = False
            _TrialBalanceHeader.Save()
        Next

    End Sub
    Private Sub _2012_10_29(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "12.1.7.1002" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _InvoiceRows_Collection As New XPCollection(Of InvoiceRows)(_ocur.Session, CriteriaOperator.Parse("InvoiceHeader.IsEditable=False"))
            Dim _InvoiceRows As InvoiceRows
            For Each _InvoiceRows In _InvoiceRows_Collection
                _InvoiceRows.CalculateSum()
                _ocur.CommitChanges()
            Next
        End If
    End Sub
    Private Sub _2012_11_08(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "12.1.7.1002" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _APCSheetByProducts_Collection As New XPCollection(Of APCSheetByProducts)(_ocur.Session, CriteriaOperator.Parse("FundingAmountHUF-FundingAmountUsedHUF<>FundingAmountAvailableHUF"))
            Dim _APCSheetByProducts As APCSheetByProducts
            For Each _APCSheetByProducts In _APCSheetByProducts_Collection
                _APCSheetByProducts.FundingAmountAvailableHUF = _APCSheetByProducts.FundingAmountHUF - _APCSheetByProducts.FundingAmountUsedHUF
                _ocur.CommitChanges()
            Next
        End If
    End Sub
    Private Sub _2013_04_17(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "12.1.8.1036" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)
            Dim _GLAccounts As GLAccounts
            Dim _GLAccounts_Collection As New XPCollection(Of GLAccounts)(_ocur.Session,
                                CriteriaOperator.Parse("IsNull(ConnectInfo)=True or ConnectInfo=''"))
            For Each _GLAccounts In _GLAccounts_Collection
                _GLAccounts.ConnectInfo = _GLAccounts.DocumentNumber
                _GLAccounts.Save()
                '_ocur.CommitChanges()
                GLFunctions.ReconfigurePCI(_uow, _GLAccounts.CustomersFrom, _GLAccounts.Customers, _GLAccounts.PartnerType, _GLAccounts.ConnectInfo)
                '_uow.CommitChanges()
            Next
        End If
    End Sub
    Private Sub _2013_04_25(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "12.1.8.1036" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _GLAccounts_Collection As New XPCollection(Of GLAccounts)(_ocur.Session, CriteriaOperator.Parse("IsNull(ImportedRegistryHeader)=False and GetDate(DatePayment)<>GetDate(ImportedRegistryHeader.F_DatePayment)"))
            Dim _GLAccounts As GLAccounts
            Dim _PCIGroup As PCIGroup
            Dim _PCIDetail As PCIDetail

            For Each _GLAccounts In _GLAccounts_Collection
                _GLAccounts.DatePayment = _GLAccounts.ImportedRegistryHeader.F_DatePayment
                _PCIGroup = _ocur.FindObject(Of PCIGroup)(CriteriaOperator.Parse("CustomersFrom=? and PartnerType=1 and Customers=? and ConnectInfo=?",
                                                                                 _GLAccounts.CustomersFrom, _GLAccounts.Customers, _GLAccounts.ConnectInfo))
                If _PCIGroup IsNot Nothing Then
                    _PCIGroup.DatePayment_Account = _GLAccounts.DatePayment
                    Dim _PCIDetail_Collection As New XPCollection(Of PCIDetail)(_ocur.Session, CriteriaOperator.Parse("PCIGroup=?", _PCIGroup))
                    For Each _PCIDetail In _PCIDetail_Collection
                        _PCIDetail.DatePayment_Account = _PCIGroup.DatePayment_Account
                    Next
                End If

                _ocur.CommitChanges()
            Next
        End If
    End Sub
    Private Sub _2013_07_23(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "12.2.11.1001" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _InvoiceHeader As InvoiceHeader
            Dim _InvoiceHeader_Collection As New XPCollection(Of InvoiceHeader)(_ocur.Session,
                        CriteriaOperator.Parse("IsFactoring=True and IsNull(InvoiceFactoringBank)=True and Factoring_Send_Number<>'' and Factoring_Send=True"))
            Dim _InvoiceFactoringBank As InvoiceFactoringBank

            For Each _InvoiceHeader In _InvoiceHeader_Collection
                _InvoiceFactoringBank = _ocur.FindObject(Of InvoiceFactoringBank)(CriteriaOperator.Parse("Factoring_Send_Number=?", _InvoiceHeader.Factoring_Send_Number))
                If _InvoiceFactoringBank Is Nothing Then
                    _InvoiceFactoringBank = _ocur.CreateObject(Of InvoiceFactoringBank)()
                    _InvoiceFactoringBank.Factoring_Send_Number = _InvoiceHeader.Factoring_Send_Number
                    _InvoiceFactoringBank.Factoring_Send_Date = _InvoiceHeader.Factoring_Send_Date
                    _InvoiceFactoringBank.Customers = _InvoiceHeader.Customers
                    _InvoiceFactoringBank.CustomersFrom = _InvoiceHeader.CustomersFrom
                End If
                _InvoiceHeader.InvoiceFactoringBank = _InvoiceFactoringBank
                _ocur.CommitChanges()
            Next


        End If
    End Sub
    Private Sub _2013_07_23_1(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "12.2.11.1001" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _InvoiceFactoringBank As InvoiceFactoringBank
            Dim _InvoiceHeader As InvoiceHeader
            Dim _InvoiceFactoringBank_Collection As New XPCollection(Of InvoiceFactoringBank)(_ocur.Session, CriteriaOperator.Parse(" IsNull(FileData)=True"))
            For Each _InvoiceFactoringBank In _InvoiceFactoringBank_Collection
                For Each _InvoiceHeader In _InvoiceFactoringBank.InvoiceHeader
                    If _InvoiceHeader.Factoring_PDF_Signed IsNot Nothing Then
                        _InvoiceFactoringBank.FileData = _InvoiceHeader.Factoring_PDF_Signed
                        Exit For
                    End If
                Next
            Next
            _ocur.CommitChanges()

            'Dim _InvoiceHeader_Collection As New XPCollection(Of InvoiceHeader)(_ocur.Session, CriteriaOperator.Parse("IsNull(IsAssetsHandling)=True"))
            'For Each _InvoiceHeader In _InvoiceHeader_Collection
            '    _InvoiceHeader.IsAssetsHandling = True
            '    _ocur.CommitChanges()
            'Next


        End If
    End Sub
    Private Sub _2014_02_14(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "13.2.6.1001" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _GLRows As GLRows = Nothing
            Dim _GLAccounts As GLAccounts = Nothing
            Dim _GLRows_Collection As New XPCollection(Of GLRows)(_ocur.Session, CriteriaOperator.Parse("PartnerType<>-1 and (ConnectInfo='' or IsNull(ConnectInfo)=True)"))
            For Each _GLRows In _GLRows_Collection
                If TryCast(_GLRows.GLHeader, GLAccounts) IsNot Nothing Then
                    _GLAccounts = TryCast(_GLRows.GLHeader, GLAccounts)
                    If String.IsNullOrEmpty(_GLAccounts.ConnectInfo) = False Then
                        _GLRows.ConnectInfo = _GLAccounts.ConnectInfo
                    End If
                End If
            Next
            _ocur.CommitChanges()
        End If
    End Sub
    Private Sub _2014_03_07(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "13.2.6.1004" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _NumberGeneratorSemafor_Collection As New XPCollection(Of NumberGeneratorSemafor)(_ocur.Session)
            Dim _NumberGeneratorSemafor As NumberGeneratorSemafor

            For Each _NumberGeneratorSemafor In _NumberGeneratorSemafor_Collection
                If _NumberGeneratorSemafor.NewNumberPerMonth = True Then
                Else
                    _NumberGeneratorSemafor.NewNumberPerMonth = False

                End If
            Next
            _ocur.CommitChanges()
        End If
    End Sub
    Private Sub _2016_01_28(ByVal ObjectSpace As Xpo.XPObjectSpace, ByVal currentDBVersion As Version)
        If currentDBVersion.ToString < "15.1.8.1002" Then
            Dim _ocur As Xpo.XPObjectSpace = TryCast(ObjectSpace, Xpo.XPObjectSpace)
            Dim _CustomersOrderPriority_Collection As New XPCollection(Of CustomersOrderPriority)(_ocur.Session, CriteriaOperator.Parse("IsNull(Products.CustomersOrder01)=True or IsNull(Products.CustomersOrder02)=True"))

            For Each _CustomersOrderPriority As CustomersOrderPriority In _CustomersOrderPriority_Collection
                If _CustomersOrderPriority.Products IsNot Nothing Then
                    _CustomersOrderPriority.Products.Parameter_10 = "-"
                End If

            Next
            _ocur.CommitChanges()
        End If
    End Sub
    Private Sub ExecuteSQLCommands(ByVal _FileName As String)
        'Dim sArray() As String
        'Dim con As New SqlConnection(GLOBAL_ConnectionString)
        'Dim cmd As New SqlCommand
        'Dim i As Long
        'Dim s As String
        's = File.OpenText(_FileName).ReadToEnd
        'sArray = Split(s, "go")
        'Try
        '    con.Open()
        '    If con.State = System.Data.ConnectionState.Open Then
        '        For i = LBound(sArray) To UBound(sArray)
        '            cmd.Connection = con
        '            cmd.CommandType = System.Data.CommandType.Text
        '            If LTrim(RTrim(sArray(i))) <> "" Then
        '                cmd.CommandText = sArray(i)
        '                cmd.ExecuteNonQuery()
        '            End If
        '        Next i
        '    End If
        'Catch e As Exception
        '    MsgBox(e)
        'End Try
    End Sub
    Private Sub SetDefaultStorage(ByVal _ocur As Xpo.XPObjectSpace)
        Dim _Storage As Storage
        Dim _CustomersFrom As CustomersFrom = _ocur.FindObject(Of CustomersFrom)(CriteriaOperator.Parse("Oid=Oid"))
        Dim _NumberGenerator
        Dim _NumberGeneratorGroups As NumberGeneratorGroups
        Dim _StorageMoveType As StorageMoveType

        If _CustomersFrom Is Nothing Then Exit Sub

        _Storage = _ocur.FindObject(Of Storage)(CriteriaOperator.Parse("Oid=Oid"))

        If _Storage Is Nothing Then
            '-- 1. Raktár felvitele
            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Raktári sorszámok'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Raktári sorszámok"
                _NumberGeneratorGroups.ShortName = "Raktári sorszámok"
            End If
            _Storage = _ocur.CreateObject(Of Storage)()
            _Storage.Address = _CustomersFrom.Address1
            _Storage.CustomersFrom = _CustomersFrom
            _Storage.Description = "1. Raktár"

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "BETÁR-1"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Betárolás 1. raktár"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _Storage.NumberGeneratorIn = _NumberGenerator

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "BETÁR-1-S"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Betárolás 1. raktár stornó"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _Storage.NumberGeneratorInS = _NumberGenerator

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "KITÁR-1"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Kitárolás 1. raktár"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _Storage.NumberGeneratorOut = _NumberGenerator

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "KITÁR-1-S"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Kitárolás 1. raktár stornó"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _Storage.NumberGeneratorOutS = _NumberGenerator
            _Storage.ShortName = "1. Raktár"

            _Storage.Save()
            '-- 2. Raktár felvitele

            '-- 3. Bizományos raktár felvitele

            '-- 4. Eszköz raktár felvitele

            '-- 5. Fogyóeszköz raktár felvitele

            '-- 6. 
        End If

        Dim _OrderInParameters As OrderInParameters = _ocur.FindObject(Of OrderInParameters)(CriteriaOperator.Parse("Oid=Oid"))

        If _OrderInParameters Is Nothing Then
            _StorageMoveType = _ocur.CreateObject(Of StorageMoveType)()
            _StorageMoveType.MoveType = eMoveType.Sales


            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Rendelési sorszámok'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Rendelési sorszámok"
                _NumberGeneratorGroups.ShortName = "Rendelési sorszámok"
            End If
            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "V-REND"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Vevői rendelés"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _OrderInParameters = _ocur.CreateObject(Of OrderInParameters)()

            _OrderInParameters.CustomersFrom = _CustomersFrom
            _OrderInParameters.CurrencyName = _ocur.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'"))
            _OrderInParameters.Description = "Bejövő megrendelés HUF paraméter"
            _OrderInParameters.ShortName = "Bejövő megrendelés HUF paraméter"

            _OrderInParameters.NumberGenerator = _NumberGenerator

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "V-REND-IG"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Vevői rendelés visszaigazolása"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _OrderInParameters.NumberGeneratorAcknowledgement = _NumberGenerator
            _OrderInParameters.StorageMoveType = _StorageMoveType

            _OrderInParameters.Save()
        End If

        Dim _OfferInParameters As OfferInParameters = _ocur.FindObject(Of OfferInParameters)(CriteriaOperator.Parse("Oid=Oid"))

        If _OfferInParameters Is Nothing Then
            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Ajánlati sorszámok'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Ajánlati sorszámok"
                _NumberGeneratorGroups.ShortName = "Ajánlati sorszámok"
            End If
            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "AJ-BE"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő ajánlat"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _OfferInParameters = _ocur.CreateObject(Of OfferInParameters)()

            _OfferInParameters.CustomersFrom = _CustomersFrom
            _OfferInParameters.Description = "Bejövő ajánlat paraméter"
            _OfferInParameters.ShortName = "Bejövő ajánlat paraméter"
            _OfferInParameters.NumberGenerator = _NumberGenerator

            _OfferInParameters.Save()
        End If

        Dim _OfferOutParameters As OfferOutParameters = _ocur.FindObject(Of OfferOutParameters)(CriteriaOperator.Parse("Oid=Oid"))

        If _OfferOutParameters Is Nothing Then
            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Ajánlati sorszámok'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Ajánlati sorszámok"
                _NumberGeneratorGroups.ShortName = "Ajánlati sorszámok"
            End If
            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "AJ-KI"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Kimenő ajánlat"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _OfferOutParameters = _ocur.CreateObject(Of OfferOutParameters)()

            _OfferOutParameters.CustomersFrom = _CustomersFrom
            _OfferOutParameters.Description = "Kimenő ajánlat paraméter"
            _OfferOutParameters.ShortName = "Bejövő ajánlat paraméter"
            _OfferOutParameters.NumberGenerator = _NumberGenerator

            _OfferOutParameters.Save()
        End If

        Dim _DeliveryNoteOutType As DeliveryNoteOutType = _ocur.FindObject(Of DeliveryNoteOutType)(CriteriaOperator.Parse("Oid=Oid"))
        If _DeliveryNoteOutType Is Nothing Then

            _DeliveryNoteOutType = _ocur.CreateObject(Of DeliveryNoteOutType)()

            _DeliveryNoteOutType.Description = "Vevői szállítólevél"
            _DeliveryNoteOutType.ExportMode = eExportMode.eInternalwithVAT
            _DeliveryNoteOutType.IsPrice = True

            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Szállítólevél sorszámok'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Szállítólevél sorszámok"
                _NumberGeneratorGroups.ShortName = "Szállítólevél sorszámok"
            End If

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "V-SZÁLL"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Vevői szállítólevél"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _DeliveryNoteOutType.NumberGenerator = _NumberGenerator
            _DeliveryNoteOutType.ShortName = "Vevői szállítólevél"

            _DeliveryNoteOutType.Save()

        End If
        Dim _DeliveryNoteInType As DeliveryNoteInType = _ocur.FindObject(Of DeliveryNoteInType)(CriteriaOperator.Parse("Oid=Oid"))
        If _DeliveryNoteInType Is Nothing Then

            _DeliveryNoteInType = _ocur.CreateObject(Of DeliveryNoteInType)()

            _DeliveryNoteInType.Description = "Szállítói szállítólevél"
            _DeliveryNoteInType.ImportMode = eImportMode.eInternalwithVAT
            _DeliveryNoteInType.IsPrice = False

            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Szállítólevél sorszámok'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Szállítólevél sorszámok"
                _NumberGeneratorGroups.ShortName = "Szállítólevél sorszámok"
            End If

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "S-SZÁLL"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Szállítói szállítólevél"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _DeliveryNoteInType.NumberGenerator = _NumberGenerator
            _DeliveryNoteInType.ShortName = "Szállítói szállítólevél"

            _DeliveryNoteInType.Save()

        End If
    End Sub
    Private Sub SetWorkflow(ByVal _ocur As Xpo.XPObjectSpace)
        Dim _CustomersFrom As CustomersFrom = _ocur.FindObject(Of CustomersFrom)(CriteriaOperator.Parse("Oid=Oid"))
        If _CustomersFrom Is Nothing Then Exit Sub

        Dim _WorkflowSystemSteps As WorkflowSystemSteps
        Dim _NumberGeneratorGroups As NumberGeneratorGroups
        Dim _NumberGenerator As NumberGenerator
        Dim _RegistryType As RegistryType = _ocur.FindObject(Of RegistryType) _
                                              (CriteriaOperator.Parse("Oid=Oid"))

        Dim _WorkflowSystem As WorkflowSystem = _ocur.FindObject(Of WorkflowSystem) _
                                              (CriteriaOperator.Parse("Oid=Oid"))
        If _WorkflowSystem Is Nothing Then
            _WorkflowSystem = _ocur.CreateObject(Of WorkflowSystem)()
            _WorkflowSystem.CustomersFrom = _CustomersFrom
            _WorkflowSystem.Description = "Szállítói számla iktatása"
            _WorkflowSystem.PartnerType = ePartnerType.ePayabels
            _WorkflowSystem.ShortName = "Szállítói számla iktatása"
            _WorkflowSystem.Save()

            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Iktatórendszer'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Iktatórendszer"
                _NumberGeneratorGroups.ShortName = "Iktatórendszer"
            End If

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "BSZ"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő számla iktatási sorszáma"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit


            _RegistryType = _ocur.CreateObject(Of RegistryType)()
            _RegistryType.CustomersFrom = _CustomersFrom
            _RegistryType.NumberGenerator = _NumberGenerator
            _RegistryType.RegistryCRMType = eRegistryCRMType.eNotSet
            _RegistryType.RegistryDirection = eRegistryDirection.eInput
            _RegistryType.RegistryMainType = eRegistryMainType.eAccount
            _RegistryType.WorkflowSystem = _WorkflowSystem
            _RegistryType.ShortName = "Bejövő számla iktatása"



            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "1. Számla iktatása + ÁFA"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckVAT
            _WorkflowSystemSteps.StepIndex = 1
            _WorkflowSystemSteps.TaskDescription = "Szállítói számla iktatása + ÁFA bontása"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "2. Számla igazolása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eCheckControlling
            _WorkflowSystemSteps.StepIndex = 2
            _WorkflowSystemSteps.TaskDescription = "Szállítói számla igazolása"
            _WorkflowSystemSteps.Save()


            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "3. Számla könyvelése"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 3
            _WorkflowSystemSteps.TaskDescription = "Szállítói számla könyvelése"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.IsReadyForImport = True
            _WorkflowSystemSteps.Save()

            _WorkflowSystem = _ocur.CreateObject(Of WorkflowSystem)()
            _WorkflowSystem.CustomersFrom = _CustomersFrom
            _WorkflowSystem.Description = "Bejövő posta iktatása"
            _WorkflowSystem.PartnerType = ePartnerType.ePayabels
            _WorkflowSystem.ShortName = "Bejövő posta iktatása"
            _WorkflowSystem.Save()

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "BL"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő posta iktatása"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit


            _RegistryType = _ocur.CreateObject(Of RegistryType)()
            _RegistryType.CustomersFrom = _CustomersFrom
            _RegistryType.NumberGenerator = _NumberGenerator
            _RegistryType.RegistryCRMType = eRegistryCRMType.eNotSet
            _RegistryType.RegistryDirection = eRegistryDirection.eInput
            _RegistryType.RegistryMainType = eRegistryMainType.eOther
            _RegistryType.WorkflowSystem = _WorkflowSystem
            _RegistryType.ShortName = "Bejövő posta iktatása"

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "1. Postabontás + iktatás"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 1
            _WorkflowSystemSteps.TaskDescription = "Postabontás + iktatás"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "2. Felelős áttekintése"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 2
            _WorkflowSystemSteps.TaskDescription = "Felelős áttekintése"
            _WorkflowSystemSteps.Save()


            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "3. Irattározva"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 3
            _WorkflowSystemSteps.TaskDescription = "Irattározva"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.IsReadyForImport = True
            _WorkflowSystemSteps.Save()

        End If
    End Sub
    Private Sub SetDefaultfixedAssets(ByVal ObjectSpace As Xpo.XPObjectSpace)
        Dim _CustomersFrom_Collection As New XPCollection(Of CustomersFrom)(TryCast(ObjectSpace, Xpo.XPObjectSpace).Session)
        Dim _CustomersFrom As CustomersFrom
        Dim _NG As NumberGenerator
        Dim _NumberGeneratorGroups As NumberGeneratorGroups
        Dim _FixedAssetsNGParameters As FixedAssetsNGParameters


        _NumberGeneratorGroups = ObjectSpace.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Tárgyieszköz sorszámok'"))
        If _NumberGeneratorGroups Is Nothing Then
            _NumberGeneratorGroups = ObjectSpace.CreateObject(Of NumberGeneratorGroups)()
            _NumberGeneratorGroups.ShortName = "Tárgyieszköz sorszámok"
            _NumberGeneratorGroups.Description = "Tárgyieszköz sorszámok"
            _NumberGeneratorGroups.Save()
        End If

        For Each _CustomersFrom In _CustomersFrom_Collection
            _FixedAssetsNGParameters = ObjectSpace.FindObject(Of FixedAssetsNGParameters)(CriteriaOperator.Parse("CustomersFrom=?", _CustomersFrom))
            If _FixedAssetsNGParameters Is Nothing Then
                _FixedAssetsNGParameters = ObjectSpace.CreateObject(Of FixedAssetsNGParameters)()
                _FixedAssetsNGParameters.CustomersFrom = _CustomersFrom

                _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                _NG.ShortName = "Aktiválás"
                _NG.PrefixString = "TE-AKT"
                _NG.PrefixTag = "-"
                _NG.SuffixString = "-"
                _NG.NewNumberPerYear = True
                _NG.YearFormat = eYearFormat.YearTwoDigit
                _NG.SerialNumberDigit = 4
                _NG.SerialNumberPlace = ePlace.Right
                _NG.Save()
                _FixedAssetsNGParameters.NumberGenerator_Activation = _NG

                _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                _NG.ShortName = "Értékcsökkenés"
                _NG.PrefixString = "TE-ÉCS"
                _NG.PrefixTag = "-"
                _NG.SuffixString = "-"
                _NG.NewNumberPerYear = True
                _NG.YearFormat = eYearFormat.YearTwoDigit
                _NG.SerialNumberDigit = 4
                _NG.SerialNumberPlace = ePlace.Right
                _NG.Save()
                _FixedAssetsNGParameters.NumberGenerator_Decrepation = _NG

                _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                _NG.ShortName = "Kivezetés selejtezés"
                _NG.PrefixString = "TE-SEL"
                _NG.PrefixTag = "-"
                _NG.SuffixString = "-"
                _NG.NewNumberPerYear = True
                _NG.YearFormat = eYearFormat.YearTwoDigit
                _NG.SerialNumberDigit = 4
                _NG.SerialNumberPlace = ePlace.Right
                _NG.Save()
                _FixedAssetsNGParameters.NumberGenerator_Disposal = _NG

                _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                _NG.ShortName = "Kivezetés értékesítés"
                _NG.PrefixString = "TE-ÉRT"
                _NG.PrefixTag = "-"
                _NG.SuffixString = "-"
                _NG.NewNumberPerYear = True
                _NG.YearFormat = eYearFormat.YearTwoDigit
                _NG.SerialNumberDigit = 4
                _NG.SerialNumberPlace = ePlace.Right
                _NG.Save()
                _FixedAssetsNGParameters.NumberGenerator_Sold = _NG

                _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                _NG.ShortName = "Kivezetés leltárhiány"
                _NG.PrefixString = "TE-LEH"
                _NG.PrefixTag = "-"
                _NG.SuffixString = "-"
                _NG.NewNumberPerYear = True
                _NG.YearFormat = eYearFormat.YearTwoDigit
                _NG.SerialNumberDigit = 4
                _NG.SerialNumberPlace = ePlace.Right
                _NG.Save()
                _FixedAssetsNGParameters.NumberGenerator_InventoryShortage = _NG

                _NG = ObjectSpace.CreateObject(Of NumberGenerator)()
                _NG.NumberGeneratorGroups = _NumberGeneratorGroups
                _NG.ShortName = "Tárgyieszközök"
                _NG.PrefixString = "TE"
                _NG.PrefixTag = "-"
                _NG.SuffixString = "-"
                _NG.NewNumberPerYear = True
                _NG.YearFormat = eYearFormat.YearTwoDigit
                _NG.SerialNumberDigit = 4
                _NG.SerialNumberPlace = ePlace.Right
                _NG.Save()
                _FixedAssetsNGParameters.NumberGenerator_UniqueObjects = _NG

                _FixedAssetsNGParameters.Save()

            End If
        Next



    End Sub
    Private Sub SetCRM(ByVal _ocur As Xpo.XPObjectSpace)
        Dim _CustomersFrom As CustomersFrom = _ocur.FindObject(Of CustomersFrom)(CriteriaOperator.Parse("Oid=Oid"))
        If _CustomersFrom Is Nothing Then Exit Sub

        Dim _CRM_Opportunities_Probability As CRM_Opportunities_Probability = _ocur.FindObject(Of CRM_Opportunities_Probability)(CriteriaOperator.Parse("Oid=Oid"))

        If _CRM_Opportunities_Probability Is Nothing Then
            _CRM_Opportunities_Probability = _ocur.CreateObject(Of CRM_Opportunities_Probability)()
            _CRM_Opportunities_Probability.Probability = 0
            _CRM_Opportunities_Probability.ShortName = "Elvesztett"

            _CRM_Opportunities_Probability = _ocur.CreateObject(Of CRM_Opportunities_Probability)()
            _CRM_Opportunities_Probability.Probability = 30
            _CRM_Opportunities_Probability.ShortName = "Árajánlatot kér"

            _CRM_Opportunities_Probability = _ocur.CreateObject(Of CRM_Opportunities_Probability)()
            _CRM_Opportunities_Probability.Probability = 50
            _CRM_Opportunities_Probability.ShortName = "Árajánlat kiadva"

            _CRM_Opportunities_Probability = _ocur.CreateObject(Of CRM_Opportunities_Probability)()
            _CRM_Opportunities_Probability.Probability = 80
            _CRM_Opportunities_Probability.ShortName = "Áralku"

            _CRM_Opportunities_Probability = _ocur.CreateObject(Of CRM_Opportunities_Probability)()
            _CRM_Opportunities_Probability.Probability = 100
            _CRM_Opportunities_Probability.ShortName = "Megnyert"


        End If
        Dim _CRM_FirstMeet As CRM_FirstMeet = _ocur.FindObject(Of CRM_FirstMeet)(CriteriaOperator.Parse("Oid=Oid"))
        If _CRM_FirstMeet Is Nothing Then
            _CRM_FirstMeet = _ocur.CreateObject(Of CRM_FirstMeet)()
            _CRM_FirstMeet.DefaultforBusiness = True
            _CRM_FirstMeet.ShortName = "Meglévő ügyfelünk"

            _CRM_FirstMeet = _ocur.CreateObject(Of CRM_FirstMeet)()
            _CRM_FirstMeet.DefaultforBusiness = False
            _CRM_FirstMeet.ShortName = "Direkt marketing"

            _CRM_FirstMeet = _ocur.CreateObject(Of CRM_FirstMeet)()
            _CRM_FirstMeet.DefaultforBusiness = False
            _CRM_FirstMeet.ShortName = "Ügyfél ajánlás"

            _CRM_FirstMeet = _ocur.CreateObject(Of CRM_FirstMeet)()
            _CRM_FirstMeet.DefaultforBusiness = False
            _CRM_FirstMeet.ShortName = "Kiállítás alatti ismerkedés"

            _CRM_FirstMeet = _ocur.CreateObject(Of CRM_FirstMeet)()
            _CRM_FirstMeet.DefaultforBusiness = False
            _CRM_FirstMeet.ShortName = "Hirdetés, reklám, kampány"
        End If

        Dim _WorkflowSystem As WorkflowSystem = _ocur.FindObject(Of WorkflowSystem)(CriteriaOperator.Parse("PartnerType=0"))
        If _WorkflowSystem Is Nothing Then
            Dim _NumberGeneratorGroups As NumberGeneratorGroups
            Dim _NumberGenerator As NumberGenerator
            Dim _RegistryType As RegistryType
            Dim _WorkflowSystemSteps As WorkflowSystemSteps

            _NumberGeneratorGroups = _ocur.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Iktatórendszer'"))
            If _NumberGeneratorGroups Is Nothing Then
                _NumberGeneratorGroups = _ocur.CreateObject(Of NumberGeneratorGroups)()
                _NumberGeneratorGroups.Description = "Iktatórendszer"
                _NumberGeneratorGroups.ShortName = "Iktatórendszer"
            End If

            '-- Bejövő árajánlat kérés CRM folyamata -------------------------------------------------------------------------------
            _WorkflowSystem = _ocur.CreateObject(Of WorkflowSystem)()
            _WorkflowSystem.CustomersFrom = _CustomersFrom
            _WorkflowSystem.Description = "Bejövő árajánlat kérés"
            _WorkflowSystem.PartnerType = ePartnerType.eReceivables
            _WorkflowSystem.ShortName = "Bejövő árajánlat kérés"
            _WorkflowSystem.Save()

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "B-AJK"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő ajánlat kérés iktatási sorszáma"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _RegistryType = _ocur.CreateObject(Of RegistryType)()
            _RegistryType.CustomersFrom = _CustomersFrom
            _RegistryType.NumberGenerator = _NumberGenerator
            _RegistryType.RegistryCRMType = eRegistryCRMType.eOfferInAsk
            _RegistryType.RegistryDirection = eRegistryDirection.eInput
            _RegistryType.RegistryMainType = eRegistryMainType.eCRM
            _RegistryType.WorkflowSystem = _WorkflowSystem
            _RegistryType.ShortName = "Bejövő ajánlat kérés"

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "1. Ajánlatkérés iktatása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 1
            _WorkflowSystemSteps.TaskDescription = "Ajánlatkérés iktatása"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "2. Ajánlatkérés feldolgozása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 2
            _WorkflowSystemSteps.TaskDescription = "Ajánlatkérés feldolgozása"
            _WorkflowSystemSteps.Save()


            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "4. Ajánlat vezetői ellenőrzése"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 4
            _WorkflowSystemSteps.TaskDescription = "Ajánlat vezetői ellenőrzése"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "5. Ajánlat kiadva"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 5
            _WorkflowSystemSteps.TaskDescription = "Ajánlat kiadva"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "6. Ajánlatkérés elvetése"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 6
            _WorkflowSystemSteps.TaskDescription = "Ajánlatkérés elvetése"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.Save()
            '----------------------------------------------------------------------------------------------------------------------------
            '-- Bejövő árajánlat CRM folyamata
            _WorkflowSystem = _ocur.CreateObject(Of WorkflowSystem)()
            _WorkflowSystem.CustomersFrom = _CustomersFrom
            _WorkflowSystem.Description = "Bejövő árajánlat"
            _WorkflowSystem.PartnerType = ePartnerType.ePayabels
            _WorkflowSystem.ShortName = "Bejövő árajánlat"
            _WorkflowSystem.Save()

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "B-AJ"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő ajánlat iktatási sorszáma"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _RegistryType = _ocur.CreateObject(Of RegistryType)()
            _RegistryType.CustomersFrom = _CustomersFrom
            _RegistryType.NumberGenerator = _NumberGenerator
            _RegistryType.RegistryCRMType = eRegistryCRMType.eOfferIn
            _RegistryType.RegistryDirection = eRegistryDirection.eInput
            _RegistryType.RegistryMainType = eRegistryMainType.eCRM
            _RegistryType.WorkflowSystem = _WorkflowSystem
            _RegistryType.ShortName = "Bejövő ajánlat"

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "1. Ajánlat iktatása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 1
            _WorkflowSystemSteps.TaskDescription = "Ajánlat iktatása"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "2. Ajánlat feldolgozása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 2
            _WorkflowSystemSteps.TaskDescription = "Ajánlatkérés feldolgozása"
            _WorkflowSystemSteps.Save()


            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "3. Ajánlat elfogadása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 3
            _WorkflowSystemSteps.TaskDescription = "Ajánlat elfogadása"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "4. Ajánlat elutasítása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 4
            _WorkflowSystemSteps.TaskDescription = "Ajánlat elutasítása"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.Save()

            '-- Bejövő megrendelés CRM folyamata
            _WorkflowSystem = _ocur.CreateObject(Of WorkflowSystem)()
            _WorkflowSystem.CustomersFrom = _CustomersFrom
            _WorkflowSystem.Description = "Bejövő megrendelés"
            _WorkflowSystem.PartnerType = ePartnerType.eReceivables
            _WorkflowSystem.ShortName = "Bejövő megrendelés"
            _WorkflowSystem.Save()

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "B-MR"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő megrendelés iktatási sorszáma"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _RegistryType = _ocur.CreateObject(Of RegistryType)()
            _RegistryType.CustomersFrom = _CustomersFrom
            _RegistryType.NumberGenerator = _NumberGenerator
            _RegistryType.RegistryCRMType = eRegistryCRMType.eOrderIn
            _RegistryType.RegistryDirection = eRegistryDirection.eInput
            _RegistryType.RegistryMainType = eRegistryMainType.eCRM
            _RegistryType.WorkflowSystem = _WorkflowSystem
            _RegistryType.ShortName = "Bejövő megrendelés"

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "1. Megrendelés iktatása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 1
            _WorkflowSystemSteps.TaskDescription = "Megrendelés iktatása"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "2. Megrendelés feldolgozása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 2
            _WorkflowSystemSteps.TaskDescription = "Megrendelés feldolgozása"
            _WorkflowSystemSteps.Save()


            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "3. Vezetői ellenőrzés"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 3
            _WorkflowSystemSteps.TaskDescription = "Vezetői ellenőrzés"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.Save()

            '-- Bejövő reklamáció folyamata
            _WorkflowSystem = _ocur.CreateObject(Of WorkflowSystem)()
            _WorkflowSystem.CustomersFrom = _CustomersFrom
            _WorkflowSystem.Description = "Bejövő reklamáció"
            _WorkflowSystem.PartnerType = ePartnerType.eNotSet
            _WorkflowSystem.ShortName = "Bejövő reklamáció"
            _WorkflowSystem.Save()

            _NumberGenerator = _ocur.CreateObject(Of NumberGenerator)()
            _NumberGenerator.MonthAfterYear = False
            _NumberGenerator.NewNumberPerYear = True
            _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
            _NumberGenerator.PrefixString = "B-RK"
            _NumberGenerator.PrefixTag = "-"
            _NumberGenerator.SerialNumber = 1
            _NumberGenerator.SerialNumberDigit = 4
            _NumberGenerator.SerialNumberPlace = ePlace.Right
            _NumberGenerator.ShortName = "Bejövő reklamáció iktatási sorszáma"
            _NumberGenerator.SuffixString = "-"
            _NumberGenerator.SuffixTag = ""
            _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

            _RegistryType = _ocur.CreateObject(Of RegistryType)()
            _RegistryType.CustomersFrom = _CustomersFrom
            _RegistryType.NumberGenerator = _NumberGenerator
            _RegistryType.RegistryCRMType = eRegistryCRMType.eComplaintIn
            _RegistryType.RegistryDirection = eRegistryDirection.eInput
            _RegistryType.RegistryMainType = eRegistryMainType.eCRM
            _RegistryType.WorkflowSystem = _WorkflowSystem
            _RegistryType.ShortName = "Bejövő reklamáció"

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "1. Reklamáció iktatása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 1
            _WorkflowSystemSteps.TaskDescription = "Reklamáció iktatása"
            _WorkflowSystemSteps.Save()

            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "2. Ügyintézés folyamatban"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 2
            _WorkflowSystemSteps.TaskDescription = "Ügyintézés folyamatban"
            _WorkflowSystemSteps.Save()


            _WorkflowSystemSteps = _ocur.CreateObject(Of WorkflowSystemSteps)()
            _WorkflowSystemSteps.WorkflowSystem = _WorkflowSystem
            _WorkflowSystemSteps.ShortName = "3. Reklamáció lezárása"
            _WorkflowSystemSteps.StepFinancialType = eStepFinancialType.eNoCheck
            _WorkflowSystemSteps.StepIndex = 3
            _WorkflowSystemSteps.TaskDescription = " Reklamáció lezárása"
            _WorkflowSystemSteps.IsLastStep = True
            _WorkflowSystemSteps.Save()

        End If
    End Sub
    Private Sub ProductsGant(ByVal _ocur As Xpo.XPObjectSpace)
        Dim _CustomersFrom_Collection As New XPCollection(Of CustomersFrom)(_ocur.Session)

        For Each _CustomersFrom As CustomersFrom In _CustomersFrom_Collection
            Dim _ProductsGant As ProductsGant = _ocur.FindObject(Of ProductsGant)(CriteriaOperator.Parse("CustomersFrom=?", _CustomersFrom))
            If _ProductsGant Is Nothing Then
                _ProductsGant = New ProductsGant(_ocur.Session)
                _ProductsGant.CustomersFrom = _CustomersFrom
                _ProductsGant.Save()
            End If
        Next
    End Sub
    Private Sub ZIPHUUpdate(ByVal _ocur As Xpo.XPObjectSpace)
        Dim _Address_Collection As New XPCollection(Of Address)(_ocur.Session)

        For Each _Address As Address In _Address_Collection
            Dim _ZIPHU As ZIPHU = _ocur.FindObject(Of ZIPHU)(CriteriaOperator.Parse("Zip=?", _Address.ZipPostal))
            If _ZIPHU IsNot Nothing Then
                _Address.City = _ZIPHU.City
                _Address.StateProvince = _ZIPHU.County
                _Address.Save()
            End If
        Next
    End Sub
    Private Sub StorageOut_Storno_Regenerate(ByVal _ocur As Xpo.XPObjectSpace)
        Dim _StoregeOutHeder_Storno_Collection As New XPCollection(Of StorageOutHeader)(_ocur.Session, CriteriaOperator.Parse("IsStorno=True AND Active=False"))

        If _StoregeOutHeder_Storno_Collection.Count > 0 Then
            For Each _StorageOutHeader_Storno As StorageOutHeader In _StoregeOutHeder_Storno_Collection
                If Not String.IsNullOrEmpty(_StorageOutHeader_Storno.ConnectInfo) Then

                    Dim _StorageOutHeader_Original As StorageOutHeader = _ocur.FindObject(Of StorageOutHeader)(CriteriaOperator.Parse("DocumentNumber=?", _StorageOutHeader_Storno.ConnectInfo))
                    If _StorageOutHeader_Original IsNot Nothing Then
                        With _StorageOutHeader_Original
                            .IsStorno = True
                            .Active = False
                            .IsEditable = False
                        End With

                        _StorageOutHeader_Original.Save()

                        For Each _StorageOutRows_Original As StorageOutRows In _StorageOutHeader_Original.StorageOutRows
                            Dim _StorageOutRowsInRows_Storno_Collection As New XPCollection(Of StorageOutRowsInRows)(_ocur.Session, CriteriaOperator.Parse("StorageOutRows=? AND QTT<0", _StorageOutRows_Original))

                            If _StorageOutRowsInRows_Storno_Collection.Count > 0 Then
                                For Each _StorageOutRowsInRows_Storno As StorageOutRowsInRows In _StorageOutRowsInRows_Storno_Collection
                                    Dim _StorageOutRows_Storno As StorageOutRows = _ocur.FindObject(Of StorageOutRows)(CriteriaOperator.Parse("StorageOutHeader=? AND QTT=?", _StorageOutHeader_Storno, _StorageOutRowsInRows_Storno.QTT))
                                    If _StorageOutRows_Storno IsNot Nothing Then
                                        _StorageOutRowsInRows_Storno.StorageOutRows = _StorageOutRows_Storno
                                    End If

                                    _StorageOutRowsInRows_Storno.Save()

                                Next
                            End If
                        Next
                    End If
                End If
            Next
        End If
    End Sub
    Private Sub RegistryHeader_UserCreated(ByVal _ocur As Xpo.XPObjectSpace)
        Try
            Dim _RegistryHeader_Collection As New XPCollection(Of RegistryHeader)(_ocur.Session, CriteriaOperator.Parse("IsNull(UserCreated)=True "))
            If _RegistryHeader_Collection.Count > 0 Then
                For Each _RegistryHeader As RegistryHeader In _RegistryHeader_Collection
                    Dim _AuditDataItemPersistent_Collection As XPCollection(Of AuditDataItemPersistent)
                    _AuditDataItemPersistent_Collection = AuditedObjectWeakReference.GetAuditTrail(_ocur.Session, _RegistryHeader)
                    If _AuditDataItemPersistent_Collection IsNot Nothing Then
                        If _AuditDataItemPersistent_Collection.Count > 0 Then
                            For Each _AuditDataItemPersistent In _AuditDataItemPersistent_Collection
                                If _AuditDataItemPersistent.OperationType = "ObjectCreated" Then
                                    Dim _User As User = _ocur.FindObject(Of User)(CriteriaOperator.Parse("UserName=?", _AuditDataItemPersistent_Collection(0).UserName))
                                    If _User IsNot Nothing Then
                                        _RegistryHeader.UserCreated = _User
                                    End If

                                    _RegistryHeader.Save()

                                    Exit For
                                End If
                            Next
                        End If
                    End If
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class

