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

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
Imports DevExpress.ExpressApp.SystemModule

Public Class GLReportCashflowVC
    Inherits DevExpress.ExpressApp.ViewController

    Public Event InitWork(ByVal _Minimum As Long, ByVal _Step As Long, ByVal _Maximum As Long)
    Public Event DoWork()
    Public Event FinalWork

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        Frame.GetController(Of GLReportCashflowVC).aGenerateGLReportCashflow.Active.SetItemValue("", False)
        If View.Id = "GLReportCashflowHeader_DetailView" Then
            Frame.GetController(Of GLReportCashflowVC).aGenerateGLReportCashflow.Active.SetItemValue("", True)

        End If
        If View.Id = "GLReportCashflowHeader_GLReportCashflowRows_ListView_Table" Or _
            View.Id = "GLReportCashflowHeader_GLReportCashflowRows_ListView_Pivot" Then
            Frame.GetController(Of GLReportCashflowVC).aGenerateGLReportCashflow.Active.SetItemValue("", True)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "GLReportCashflowHeader_DetailView" Then
            Frame.GetController(Of GLReportCashflowVC).aGenerateGLReportCashflow.Active.SetItemValue("", False)

        End If
        If View.Id = "GLReportCashflowHeader_GLReportCashflowRows_ListView_Table" Or _
            View.Id = "GLReportCashflowHeader_GLReportCashflowRows_ListView_Pivot" Then
            Frame.GetController(Of GLReportCashflowVC).aGenerateGLReportCashflow.Active.SetItemValue("", False)
        End If
    End Sub

    Private Sub aGenerateGLReportCashflow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aGenerateGLReportCashflow.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _uow_stat As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _GLReportCashflowHeader As GLReportCashflowHeader = Nothing
        Dim _GLReportCashflowRows As GLReportCashflowRows = Nothing
        Dim _PCIDetailCollection As XPCollection(Of PCIDetail)


        If TryCast(View, ListView) IsNot Nothing Then
            Dim _ListView As ListView = TryCast(View, ListView)
            Dim _PropertyCollectionSource As PropertyCollectionSource = TryCast(_ListView.CollectionSource, PropertyCollectionSource)

            If _PropertyCollectionSource IsNot Nothing Then
                _GLReportCashflowHeader = _uow.GetObjectByKey(Of GLReportCashflowHeader)(TryCast(_PropertyCollectionSource.MasterObject, GLReportCashflowHeader).Oid)
            Else
                _GLReportCashflowRows = TryCast(_ListView.CollectionSource.List(0), GLReportCashflowRows)
                If _GLReportCashflowRows IsNot Nothing Then
                    _GLReportCashflowHeader = _uow.GetObjectByKey(Of GLReportCashflowHeader)(_GLReportCashflowRows.GLReportCashflowHeader.Oid)
                End If
            End If
        ElseIf TryCast(View, DetailView) IsNot Nothing Then
            _GLReportCashflowHeader = _uow.GetObjectByKey(Of GLReportCashflowHeader)(TryCast(View.SelectedObjects(0), GLReportCashflowHeader).Oid)
        End If

        If _GLReportCashflowHeader Is Nothing Then Exit Sub

        Dim _QueryStatistics As QueryStatistics = New QueryStatistics(_uow_stat)
        _QueryStatistics.TimeStart = GetSQLTime(_uow_stat)
        _QueryStatistics.ObjectKey = _GLReportCashflowHeader.Oid
        _QueryStatistics.ObjectName = "GLReportCashflowHeader"

        Dim _GLReportCashflowRows_Collection As New XPCollection(Of GLReportCashflowRows)(_uow, CriteriaOperator.Parse("GLReportCashflowHeader.Oid=?", _GLReportCashflowHeader))
        _uow.Delete(_GLReportCashflowRows_Collection)

        '//Pénzeszközönként fel kell vinni a nyitót ami a FromDate-t megelőző időszak


        '// --------------------------------- Most a beérkezett p.ü. teljesítések --------------------------------------------------
        If _GLReportCashflowHeader.IsCustomersFrom Then
            _PCIDetailCollection = New XPCollection(Of PCIDetail)(_uow, CriteriaOperator.Parse("GetDate(DateExecution) between (?,?) and GLRows.GLHeader.GLDocumentType in ('eGLBank','eGLCassa','eGLCompensation')", _
                                    _GLReportCashflowHeader.FromDate.Date, _GLReportCashflowHeader.ToDate.Date))
        Else
            _PCIDetailCollection = New XPCollection(Of PCIDetail)(_uow, CriteriaOperator.Parse("CustomersFrom.Oid=? and GetDate(DateExecution) between (?,?) and GLRows.GLHeader.GLDocumentType in ('eGLBank','eGLCassa','eGLCompensation')", _
                                    _GLReportCashflowHeader.CustomersFrom.Oid, _GLReportCashflowHeader.FromDate.Date, _GLReportCashflowHeader.ToDate.Date))
        End If
        Dim _PCIDetail As PCIDetail
        RaiseEvent InitWork(1, 1, _PCIDetailCollection.Count)
        _QueryStatistics.RecordNumber = _PCIDetailCollection.Count
        For Each _PCIDetail In _PCIDetailCollection
            RaiseEvent DoWork()
            If _PCIDetail.GLRows.PartnerType = ePartnerType.eNotSet Then
                '// Normál tétel
                _GLReportCashflowRows = New GLReportCashflowRows(_uow)
                _GLReportCashflowRows.GLReportRowsState = eGLReportRowsState.eGLFinal
                _GLReportCashflowRows.GLReportCashflowHeader = _GLReportCashflowHeader

                _GLReportCashflowRows.CustomersFrom = _PCIDetail.CustomersFrom
                _GLReportCashflowRows.Customers = _PCIDetail.Customers
                _GLReportCashflowRows.ConnectInfo = _PCIDetail.ConnectInfo

                _GLReportCashflowRows.LiquidAssets = _PCIDetail.GLRows.LiquidAssets
                _GLReportCashflowRows.DateExecution = _PCIDetail.GLRows.GLHeader.DateExecution

                _GLReportCashflowRows.DateExecution_Y = AlignStr(DatePart(DateInterval.Year, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 4)
                _GLReportCashflowRows.DateExecution_Q = AlignStr(DatePart(DateInterval.Quarter, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                _GLReportCashflowRows.DateExecution_M = AlignStr(DatePart(DateInterval.Month, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                _GLReportCashflowRows.DateExecution_W = AlignStr(DatePart(DateInterval.WeekOfYear, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)

                _GLReportCashflowRows.InAmountHUF = _PCIDetail.GLRows.InAmountHUF
                _GLReportCashflowRows.InAmountDEV = _PCIDetail.GLRows.InAmountDEV
                _GLReportCashflowRows.OutAmountHUF = _PCIDetail.GLRows.OutAmountHUF
                _GLReportCashflowRows.OutAmountDEV = _PCIDetail.GLRows.OutAmountDEV

                If _PCIDetail.GLRows.DebitChartOfAccounts Is _PCIDetail.GLRows.LiquidAssets.GetChartOfAccounts(_PCIDetail.DateExecution.Year, 0) Then
                    _GLReportCashflowRows.ChartOfAccounts = _PCIDetail.GLRows.CreditChartOfAccounts
                Else
                    _GLReportCashflowRows.ChartOfAccounts = _PCIDetail.GLRows.DebitChartOfAccounts
                End If
                _GLReportCashflowRows.Controlling = _PCIDetail.GLRows.Controlling
                _GLReportCashflowRows.CostHolder = _PCIDetail.GLRows.CostHolder
                _GLReportCashflowRows.CostPlace = _PCIDetail.GLRows.CostPlace
                _GLReportCashflowRows.UniqueObjects = _PCIDetail.GLRows.UniqueObjects
                _GLReportCashflowRows.JobNumberObjects = _PCIDetail.GLRows.JobNumberObjects
            Else
                '//GLAccountban keresés
                Dim _GLAccounts As GLAccounts = _uow.FindObject(Of GLAccounts)(CriteriaOperator.Parse("CustomersFrom=? and Customers=? and PartnerType=? and ConnectInfo=?", _PCIDetail.CustomersFrom, _PCIDetail.Customers, _PCIDetail.PartnerType, _PCIDetail.ConnectInfo))

                If _GLAccounts IsNot Nothing Then
                    Dim _GLRows As GLRows
                    Dim _AmountHUFVAT As Double = 0
                    Dim _AmountDEVVAT As Double = 0


                    For Each _GLRows In _GLAccounts.GLRows
                        If _GLRows.GLRowsTypeVAT = eGLRowsTypeVAT.eVATRow Then
                            _AmountHUFVAT += _GLRows.AmountHUF
                            _AmountDEVVAT += _GLRows.AmountDEV
                        End If
                    Next

                    Dim _AmountHUFNetto As Double = _GLAccounts.AmountHUFBrutto - _AmountHUFVAT
                    Dim _AmountDEVNetto As Double = _GLAccounts.AmountDEVBrutto - _AmountDEVVAT

                    For Each _GLRows In _GLAccounts.GLRows
                        If _GLRows.GLRowsTypeVAT = eGLRowsTypeVAT.eNettoRow Then
                            _GLReportCashflowRows = New GLReportCashflowRows(_uow)
                            _GLReportCashflowRows.GLReportRowsState = eGLReportRowsState.eGLFinal
                            _GLReportCashflowRows.GLReportCashflowHeader = _GLReportCashflowHeader

                            _GLReportCashflowRows.CustomersFrom = _PCIDetail.CustomersFrom
                            _GLReportCashflowRows.Customers = _PCIDetail.Customers
                            _GLReportCashflowRows.ConnectInfo = _PCIDetail.ConnectInfo

                            _GLReportCashflowRows.LiquidAssets = _PCIDetail.GLRows.LiquidAssets
                            _GLReportCashflowRows.DateExecution = _PCIDetail.GLRows.GLHeader.DateExecution

                            _GLReportCashflowRows.DateExecution_Y = AlignStr(DatePart(DateInterval.Year, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 4)
                            _GLReportCashflowRows.DateExecution_Q = AlignStr(DatePart(DateInterval.Quarter, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                            _GLReportCashflowRows.DateExecution_M = AlignStr(DatePart(DateInterval.Month, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                            _GLReportCashflowRows.DateExecution_W = AlignStr(DatePart(DateInterval.WeekOfYear, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)


                            If _AmountHUFNetto <> 0 Then
                                If (_GLRows.AmountHUF / _AmountHUFNetto) <> 0 Then _GLReportCashflowRows.InAmountHUF = Math.Round(_PCIDetail.GLRows.InAmountHUF * (_GLRows.AmountHUF / _AmountHUFNetto), 4, MidpointRounding.AwayFromZero)
                                If (_GLRows.AmountHUF / _AmountHUFNetto) <> 0 Then _GLReportCashflowRows.OutAmountHUF = Math.Round(_PCIDetail.GLRows.OutAmountHUF * (_GLRows.AmountHUF / _AmountHUFNetto), 4, MidpointRounding.AwayFromZero)
                            End If
                            If _AmountDEVNetto <> 0 Then
                                If (_GLRows.AmountDEV / _AmountDEVNetto) <> 0 Then _GLReportCashflowRows.InAmountDEV = Math.Round(_PCIDetail.GLRows.InAmountDEV * (_GLRows.AmountDEV / _AmountDEVNetto), 4, MidpointRounding.AwayFromZero)
                                If (_GLRows.AmountDEV / _AmountDEVNetto) <> 0 Then _GLReportCashflowRows.OutAmountDEV = Math.Round(_PCIDetail.GLRows.OutAmountDEV * (_GLRows.AmountDEV / _AmountDEVNetto), 4, MidpointRounding.AwayFromZero)
                            End If

                            _GLReportCashflowRows.Controlling = _GLRows.Controlling
                            _GLReportCashflowRows.CostHolder = _GLRows.CostHolder
                            _GLReportCashflowRows.CostPlace = _GLRows.CostPlace
                            _GLReportCashflowRows.UniqueObjects = _GLRows.UniqueObjects
                            _GLReportCashflowRows.JobNumberObjects = _GLRows.JobNumberObjects
                        End If
                    Next
                Else
                    '//InvoiceHeaderben kersesés
                    Dim _InvoiceHeader As InvoiceHeader = _uow.FindObject(Of InvoiceHeader)(CriteriaOperator.Parse("CustomersFrom=? and Customers=? and ConnectInfo=? and isnull(GLAccounts)=True", _PCIDetail.CustomersFrom, _PCIDetail.Customers, _PCIDetail.ConnectInfo))
                    If _InvoiceHeader IsNot Nothing AndAlso _PCIDetail.PartnerType = ePartnerType.eReceivables Then
                        Dim _InvoiceRows As InvoiceRows
                        Dim _AmountHUFNetto As Double = 0
                        Dim _AmountDEVNetto As Double = 0
                        Dim _InvoiceVATRows As InvoiceVATRows

                        For Each _InvoiceVATRows In _InvoiceHeader.InvoiceVATRows
                            _AmountDEVNetto += _InvoiceVATRows.AmountNettoDEV
                            _AmountHUFNetto += _InvoiceVATRows.AmountNettoHUF
                        Next

                        For Each _InvoiceRows In _InvoiceHeader.InvoiceRows
                            Dim _FinalPriceHUF As Double = Math.Round((_InvoiceRows.ListPriceHUF - _InvoiceRows.DiscountPriceHUF) * _InvoiceRows.QTT, 0, MidpointRounding.AwayFromZero)
                            Dim _FinalPriceDEV As Double = Math.Round((_InvoiceRows.ListPriceHUF - _InvoiceRows.DiscountPriceHUF) * _InvoiceRows.QTT, 2, MidpointRounding.AwayFromZero)
                            _GLReportCashflowRows = New GLReportCashflowRows(_uow)
                            _GLReportCashflowRows.GLReportRowsState = eGLReportRowsState.eInvoice
                            _GLReportCashflowRows.GLReportCashflowHeader = _GLReportCashflowHeader

                            _GLReportCashflowRows.CustomersFrom = _PCIDetail.CustomersFrom
                            _GLReportCashflowRows.Customers = _PCIDetail.Customers
                            _GLReportCashflowRows.ConnectInfo = _PCIDetail.ConnectInfo

                            _GLReportCashflowRows.LiquidAssets = _PCIDetail.GLRows.LiquidAssets
                            _GLReportCashflowRows.DateExecution = _PCIDetail.GLRows.GLHeader.DateExecution

                            _GLReportCashflowRows.DateExecution_Y = AlignStr(DatePart(DateInterval.Year, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 4)
                            _GLReportCashflowRows.DateExecution_Q = AlignStr(DatePart(DateInterval.Quarter, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                            _GLReportCashflowRows.DateExecution_M = AlignStr(DatePart(DateInterval.Month, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                            _GLReportCashflowRows.DateExecution_W = AlignStr(DatePart(DateInterval.WeekOfYear, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)


                            If _AmountHUFNetto <> 0 Then
                                If (_FinalPriceHUF / _AmountHUFNetto) <> 0 Then _GLReportCashflowRows.InAmountHUF = Math.Round(_PCIDetail.GLRows.InAmountHUF * (_FinalPriceHUF / _AmountHUFNetto), 4, MidpointRounding.AwayFromZero)
                                If (_FinalPriceHUF / _AmountHUFNetto) <> 0 Then _GLReportCashflowRows.OutAmountHUF = Math.Round(_PCIDetail.GLRows.OutAmountHUF * (_FinalPriceHUF / _AmountHUFNetto), 4, MidpointRounding.AwayFromZero)
                            End If
                            If _AmountDEVNetto <> 0 Then
                                If (_FinalPriceDEV / _AmountDEVNetto) <> 0 Then _GLReportCashflowRows.InAmountDEV = Math.Round(_PCIDetail.GLRows.InAmountDEV * (_FinalPriceDEV / _AmountDEVNetto), 4, MidpointRounding.AwayFromZero)
                                If (_FinalPriceDEV / _AmountDEVNetto) <> 0 Then _GLReportCashflowRows.OutAmountDEV = Math.Round(_PCIDetail.GLRows.OutAmountDEV * (_FinalPriceDEV / _AmountDEVNetto), 4, MidpointRounding.AwayFromZero)
                            End If

                            _GLReportCashflowRows.Controlling = _InvoiceRows.Controlling
                            _GLReportCashflowRows.CostHolder = _InvoiceRows.CostHolder
                            _GLReportCashflowRows.CostPlace = _InvoiceRows.CostPlace
                            _GLReportCashflowRows.UniqueObjects = _InvoiceRows.UniqueObjects
                            _GLReportCashflowRows.JobNumberObjects = _InvoiceRows.JobNumberObjects
                        Next
                    Else
                        '//RegistryHeaderben keresés
                        Dim _RegistryHeader As RegistryHeader = _uow.FindObject(Of RegistryHeader)(CriteriaOperator.Parse("CustomersFrom=? and Customers=? and ConnectInfo=? and isnull(F_GLAccounts)=True and RegistryType.RegistryMainType in (0,2,3,4)"))
                        If _RegistryHeader IsNot Nothing AndAlso _PCIDetail.PartnerType = ePartnerType.ePayabels Then
                            Dim _RegistryRowsFinancialControlling As RegistryRowsFinancialControlling
                            Dim _RegistryRowsFinancial As RegistryRowsFinancial
                            Dim _AmountHUFNetto As Double = 0
                            Dim _AmountDEVNetto As Double = 0
                            Dim _AmountHUFVAT As Double = 0
                            Dim _AmountDEVVAT As Double = 0
                            For Each _RegistryRowsFinancial In _RegistryHeader.RegistryRowsFinancial
                                _AmountHUFVAT += _RegistryRowsFinancial.NettoAmount
                                If _RegistryHeader.F_CurrencyRate <> 0 Then
                                    _AmountDEVVAT += Math.Round(_RegistryRowsFinancial.NettoAmount / _RegistryHeader.F_CurrencyRate, 2, MidpointRounding.AwayFromZero)
                                End If
                            Next

                            _AmountHUFNetto = _RegistryHeader.F_AmountBruttoHUF - _AmountHUFVAT
                            If _RegistryHeader.F_CurrencyRate <> 0 Then
                                _AmountDEVNetto = _AmountHUFNetto / _RegistryHeader.F_CurrencyRate
                            End If

                            For Each _RegistryRowsFinancialControlling In _RegistryHeader.RegistryRowsFinancialControlling
                                Dim _FinalPriceHUF As Double = _RegistryRowsFinancialControlling.Amount
                                Dim _FinalPriceDEV As Double = 0
                                If _RegistryHeader.F_CurrencyRate <> 0 Then
                                    _FinalPriceDEV = _FinalPriceHUF / _RegistryHeader.F_CurrencyRate
                                End If

                                _GLReportCashflowRows = New GLReportCashflowRows(_uow)
                                _GLReportCashflowRows.GLReportRowsState = eGLReportRowsState.eRegistry
                                _GLReportCashflowRows.GLReportCashflowHeader = _GLReportCashflowHeader

                                _GLReportCashflowRows.CustomersFrom = _PCIDetail.CustomersFrom
                                _GLReportCashflowRows.Customers = _PCIDetail.Customers
                                _GLReportCashflowRows.ConnectInfo = _PCIDetail.ConnectInfo

                                _GLReportCashflowRows.LiquidAssets = _PCIDetail.GLRows.LiquidAssets
                                _GLReportCashflowRows.DateExecution = _PCIDetail.GLRows.GLHeader.DateExecution

                                _GLReportCashflowRows.DateExecution_Y = AlignStr(DatePart(DateInterval.Year, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 4)
                                _GLReportCashflowRows.DateExecution_Q = AlignStr(DatePart(DateInterval.Quarter, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                                _GLReportCashflowRows.DateExecution_M = AlignStr(DatePart(DateInterval.Month, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                                _GLReportCashflowRows.DateExecution_W = AlignStr(DatePart(DateInterval.WeekOfYear, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)

                                If _AmountHUFNetto <> 0 Then
                                    If (_FinalPriceHUF / _AmountHUFNetto) <> 0 Then _GLReportCashflowRows.InAmountHUF = Math.Round(_PCIDetail.GLRows.InAmountHUF * (_FinalPriceHUF / _AmountHUFNetto), 4, MidpointRounding.AwayFromZero)
                                    If (_FinalPriceHUF / _AmountHUFNetto) <> 0 Then _GLReportCashflowRows.OutAmountHUF = Math.Round(_PCIDetail.GLRows.OutAmountHUF * (_FinalPriceHUF / _AmountHUFNetto), 4, MidpointRounding.AwayFromZero)
                                End If
                                If _AmountDEVNetto <> 0 Then
                                    If (_FinalPriceDEV / _AmountDEVNetto) <> 0 Then _GLReportCashflowRows.InAmountDEV = Math.Round(_PCIDetail.GLRows.InAmountDEV * (_FinalPriceDEV / _AmountDEVNetto), 4, MidpointRounding.AwayFromZero)
                                    If (_FinalPriceDEV / _AmountDEVNetto) <> 0 Then _GLReportCashflowRows.OutAmountDEV = Math.Round(_PCIDetail.GLRows.OutAmountDEV * (_FinalPriceDEV / _AmountDEVNetto), 4, MidpointRounding.AwayFromZero)
                                End If

                                _GLReportCashflowRows.Controlling = _RegistryRowsFinancialControlling.Controlling
                                _GLReportCashflowRows.CostHolder = _RegistryRowsFinancialControlling.CostHolder
                                _GLReportCashflowRows.CostPlace = _RegistryRowsFinancialControlling.CostPlace
                                _GLReportCashflowRows.UniqueObjects = _RegistryRowsFinancialControlling.UniqueObjects
                                _GLReportCashflowRows.JobNumberObjects = _RegistryRowsFinancialControlling.JobNumberObjects
                            Next
                        Else
                            _GLReportCashflowRows = New GLReportCashflowRows(_uow)

                            _GLReportCashflowRows.GLReportRowsState = eGLReportRowsState.eGLFinal
                            _GLReportCashflowRows.GLReportCashflowHeader = _GLReportCashflowHeader

                            _GLReportCashflowRows.CustomersFrom = _PCIDetail.CustomersFrom
                            _GLReportCashflowRows.Customers = _PCIDetail.Customers
                            _GLReportCashflowRows.ConnectInfo = _PCIDetail.ConnectInfo

                            _GLReportCashflowRows.LiquidAssets = _PCIDetail.GLRows.LiquidAssets
                            _GLReportCashflowRows.DateExecution = _PCIDetail.GLRows.GLHeader.DateExecution

                            _GLReportCashflowRows.DateExecution_Y = AlignStr(DatePart(DateInterval.Year, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 4)
                            _GLReportCashflowRows.DateExecution_Q = AlignStr(DatePart(DateInterval.Quarter, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                            _GLReportCashflowRows.DateExecution_M = AlignStr(DatePart(DateInterval.Month, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)
                            _GLReportCashflowRows.DateExecution_W = AlignStr(DatePart(DateInterval.WeekOfYear, _GLReportCashflowRows.DateExecution).ToString, eDirection.Left, "0", 2)

                            _GLReportCashflowRows.InAmountHUF = _PCIDetail.GLRows.InAmountHUF
                            _GLReportCashflowRows.InAmountDEV = _PCIDetail.GLRows.InAmountDEV
                            _GLReportCashflowRows.OutAmountHUF = _PCIDetail.GLRows.OutAmountHUF
                            _GLReportCashflowRows.OutAmountDEV = _PCIDetail.GLRows.OutAmountDEV
                        End If
                    End If
                End If

            End If
            _uow.CommitChanges()
        Next
        _uow.CommitChanges()
        _QueryStatistics.TimeStop = GetSQLTime(_uow_stat)
        _QueryStatistics.TimeEllapsed = _QueryStatistics.TimeStop - _QueryStatistics.TimeStart
        _uow_stat.CommitChanges()
        RaiseEvent FinalWork

        If TryCast(View, DetailView) IsNot Nothing Then
            If Frame.GetController(Of RefreshController).RefreshAction.Enabled Then
                Frame.GetController(Of RefreshController).RefreshAction.DoExecute()
            End If
        ElseIf TryCast(View, ListView) IsNot Nothing Then
            TryCast(View, ListView).CollectionSource.Reload()
        End If

    End Sub

    Private Sub aViewAttachments_Cashflow_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aViewAttachments_Cashflow.Execute
        Dim _GLReportCashflowRows As GLReportCashflowRows = TryCast(View.SelectedObjects(0), GLReportCashflowRows)
        Dim _CustomersFrom As CustomersFrom = _GLReportCashflowRows.CustomersFrom
        Dim _Customers As Customers = _GLReportCashflowRows.Customers
        Dim _DocumentNumber As String = _GLReportCashflowRows.ConnectInfo

        ViewAttachments.ViewAttachments(View.ObjectSpace, Frame, _CustomersFrom, _Customers, _DocumentNumber, "")
    End Sub

End Class
