Imports System Imports System.ComponentModel Imports DevExpress.Xpo Imports DevExpress.Data.Filtering Imports DevExpress.ExpressApp Imports DevExpress.Persistent.Base Imports DevExpress.Persistent.BaseImpl Imports DevExpress.Persistent.Validation Imports DevExpress.Persistent.Base.General Imports System.Data.SqlClient Imports System.Configuration Imports System.Linq Imports System.Linq.Expressions Imports DevExpress.ExpressApp.ConditionalAppearance Imports DevExpress.Xpo.DB ' _ _ Public Class GLBank Inherits GLHeader Private _PartnerType As ePartnerType Private _TransactionType As eTransactionType Private _ChartOfAccounts As ChartOfAccounts Private _TotalInAmountHUF As Double = 0 Private _TotalOutAmountHUF As Double = 0 Private _TotalInAmountDEV As Double = 0 Private _TotalOutAmountDEV As Double = 0 Private _LiquidAssets As LiquidAssets Private _BallanceHUF As Double Private _BallanceDEV As Double Private _PCIGroup As PCIGroup Private _GLHeader_RateDiff As GLHeader 'Kapcsolódó árf. kül. elszámolási vegyes bizonylat '-- A másodlagos Private _row_CurrencyRate As Double Private _row_AmountDEV2 As Double = 0 Private _row_CurrencyRate2 As Double = 0 Private _row_CurrencyName2 As CurrencyName Private _BankImportHeaderSum As BankImportHeaderSum Public Sub New(ByVal session As Session) MyBase.New(session) End Sub Public Overrides Sub AfterConstruction() MyBase.AfterConstruction() If Session.IsNewObject(Me) Then Me.GLDocumentType = eGLDocumentType.eGLBank Me.DateExecution = Now Me.row_PartnerType = ePartnerType.eNotSet Me.row_TransactionType = eTransactionType.eNotSet End If End Sub _ _ _ Property row_PartnerType() As ePartnerType Get Return _PartnerType End Get Set(ByVal value As ePartnerType) SetPropertyValue("row_PartnerType", _PartnerType, value) End Set End Property _ _ _ _ Property row_TransactionType() As eTransactionType Get Return _TransactionType End Get Set(ByVal value As eTransactionType) SetPropertyValue("row_TransactionType", _TransactionType, value) If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then If LiquidAssets_Main IsNot Nothing Then Select Case row_TransactionType Case eTransactionType.eNormalCredit, eTransactionType.eNormalDebit, eTransactionType.eNotSet, eTransactionType.eCorrectionCreditHUF, eTransactionType.eCorrectionDebitHUF row_PartnerType = ePartnerType.eNotSet row_CurrencyName2 = LiquidAssets_Main.CurrencyName Case eTransactionType.ePartnerCredit row_PartnerType = ePartnerType.eReceivables Case eTransactionType.ePartnerDebit row_PartnerType = ePartnerType.ePayabels End Select End If End If End Set End Property Property row_ChartOfAccounts() As ChartOfAccounts Get Return _ChartOfAccounts End Get Set(ByVal value As ChartOfAccounts) SetPropertyValue("row_ChartOfAccounts", _ChartOfAccounts, value) End Set End Property Property row_PCIGroup() As PCIGroup Get Return _PCIGroup End Get Set(ByVal value As PCIGroup) SetPropertyValue("row_PCIGroup", _PCIGroup, value) If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then If value IsNot Nothing Then row_ConnectInfo = value.ConnectInfo row_Customer = value.Customers row_PartnerType = value.PartnerType If value.CurrencyName_Account Is Nothing Then If Me.CurrencyName.ShortName = "HUF" Then Me.row_AmountHUF = Math.Abs(value.BallanceHUF) row_CurrencyName2 = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'")) Else row_CurrencyName2 = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'")) End If Else If value.CurrencyName_Account.ShortName = "HUF" Then If Me.CurrencyName.ShortName = "HUF" Then Me.row_AmountHUF = Math.Abs(value.BallanceHUF) row_CurrencyName2 = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'")) Else row_CurrencyName2 = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'")) End If Else If Me.CurrencyName.ShortName = value.CurrencyName_Account.ShortName Then Me.row_AmountDEV = Math.Abs(value.BallanceDEV) row_CurrencyName2 = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", value.CurrencyName_Account.ShortName)) Else row_CurrencyName2 = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", value.CurrencyName_Account.ShortName)) End If End If End If End If End If End Set End Property _ _ _ Property LiquidAssets_Main() As LiquidAssets Get Return _LiquidAssets End Get Set(ByVal value As LiquidAssets) SetPropertyValue("LiquidAssets_Main", _LiquidAssets, value) If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then row_LiquidAssets = value row_CurrencyName2 = value.CurrencyName If value IsNot Nothing Then Me.CurrencyName = value.CurrencyName Me.row_CurrencyName2 = CurrencyName If Me.DateExecution > Now.AddYears(-1) Then BallanceHUF = GetBallanceHUF(value, Me.DateExecution) BallanceDEV = GetBallanceDEV(value, Me.DateExecution) End If End If End If End Set End Property _ _ _ _ Property row_CurrencyRate As Double Get Return _row_CurrencyRate End Get Set(value As Double) SetPropertyValue("row_CurrencyRate", _row_CurrencyRate, value) If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then If row_CurrencyName2 Is Nothing Then row_CurrencyName2 = LiquidAssets_Main.CurrencyName If LiquidAssets_Main.CurrencyName.ShortName = "HUF" And row_CurrencyName2.ShortName <> "HUF" Then If row_CurrencyRate <> 0 Then row_AmountDEV2 = Math.Round(row_AmountHUF / row_CurrencyRate, 2, MidpointRounding.AwayFromZero) End If If LiquidAssets_Main.CurrencyName.ShortName <> "HUF" And row_CurrencyName2.ShortName = "HUF" Then row_AmountHUF = row_AmountDEV * Math.Round(row_CurrencyRate, 4, MidpointRounding.AwayFromZero) row_AmountDEV2 = row_AmountHUF End If If LiquidAssets_Main.CurrencyName.ShortName <> "HUF" And row_CurrencyName2.ShortName <> "HUF" Then row_AmountHUF = row_AmountDEV * Math.Round(row_CurrencyRate, 4, MidpointRounding.AwayFromZero) End If End If End Set End Property _ _ _ Property row_AmountDEV2 As Double Get Return _row_AmountDEV2 End Get Set(value As Double) SetPropertyValue("row_AmountDEV2", _row_AmountDEV2, value) If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then If row_CurrencyName2 Is Nothing Then row_CurrencyName2 = LiquidAssets_Main.CurrencyName If LiquidAssets_Main.CurrencyName.ShortName <> "HUF" And _ row_CurrencyName2.ShortName <> "HUF" And _ LiquidAssets_Main.CurrencyName.ShortName <> row_CurrencyName2.ShortName Then If row_AmountDEV <> 0 Then row_CurrencyRate2 = Math.Round(row_AmountDEV2 / row_AmountDEV, 4, MidpointRounding.AwayFromZero) End If End If End If End Set End Property _ _ _ _ Property row_CurrencyRate2 As Double Get Return _row_CurrencyRate2 End Get Set(ByVal value As Double) SetPropertyValue("row_CurrencyRate2", _row_CurrencyRate2, value) End Set End Property _ _ _ Property row_CurrencyName2 As CurrencyName Get Return _row_CurrencyName2 End Get Set(value As CurrencyName) SetPropertyValue("row_CurrencyName2", _row_CurrencyName2, value) If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then row_AmountDEV2 = 0 row_CurrencyRate2 = 0 End If End Set End Property Property TotalInAmountHUF As Double Get Return _TotalInAmountHUF End Get Set(ByVal value As Double) SetPropertyValue("TotalInAmountHUF", _TotalInAmountHUF, value) End Set End Property Property TotalOutAmountHUF As Double Get Return _TotalOutAmountHUF End Get Set(ByVal value As Double) SetPropertyValue("TotalOutAmountHUF", _TotalOutAmountHUF, value) End Set End Property Property TotalInAmountDEV As Double Get Return _TotalInAmountDEV End Get Set(ByVal value As Double) SetPropertyValue("TotalInAmountDEV", _TotalInAmountDEV, value) End Set End Property Property TotalOutAmountDEV As Double Get Return _TotalOutAmountDEV End Get Set(ByVal value As Double) SetPropertyValue("TotalOutAmountDEV", _TotalOutAmountDEV, value) End Set End Property Property BallanceHUF As Double Get Return _BallanceHUF End Get Set(ByVal value As Double) SetPropertyValue("BallanceHUF", _BallanceHUF, value) End Set End Property Property BallanceDEV As Double Get Return _BallanceDEV End Get Set(ByVal value As Double) SetPropertyValue("BallanceDEV", _BallanceDEV, value) End Set End Property Property BankImportHeaderSum As BankImportHeaderSum Get Return _BankImportHeaderSum End Get Set(value As BankImportHeaderSum) SetPropertyValue("BankImportHeaderSum", _BankImportHeaderSum, value) End Set End Property Property GLHeader_RateDiff As GLHeader Get Return _GLHeader_RateDiff End Get Set(value As GLHeader) SetPropertyValue("GLHeader_RateDiff", _GLHeader_RateDiff, value) End Set End Property Sub RecalculateTotal() Dim _GLRows As GLRows TotalInAmountHUF = 0 TotalOutAmountHUF = 0 TotalInAmountDEV = 0 TotalOutAmountDEV = 0 For Each _GLRows In Me.GLRows Me.TotalInAmountHUF += _GLRows.InAmountHUF Me.TotalOutAmountHUF += _GLRows.OutAmountHUF Me.TotalInAmountDEV += _GLRows.InAmountDEV Me.TotalOutAmountDEV += _GLRows.OutAmountDEV Next Me.Save() End Sub ReadOnly Property CloseHUF As Double Get Return BallanceHUF + TotalInAmountHUF - TotalOutAmountHUF End Get End Property ReadOnly Property CloseDEV As Double Get Return BallanceDEV + TotalInAmountDEV - TotalOutAmountDEV End Get End Property ReadOnly Property DisplayName As String Get If Me.LiquidAssets_Main IsNot Nothing Then Return Me.LiquidAssets_Main.ShortName Else Return Nothing End If End Get End Property _ Overrides Property row_AmountDEV As Double Get Return MyBase.row_AmountDEV End Get Set(value As Double) MyBase.row_AmountDEV = value If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then If row_CurrencyName2 Is Nothing Then row_CurrencyName2 = LiquidAssets_Main.CurrencyName If Me.row_CurrencyRate > 0 Then Me.row_AmountHUF = value * Me.row_CurrencyRate End If If LiquidAssets_Main.CurrencyName.ShortName <> "HUF" Then If LiquidAssets_Main.CurrencyName.ShortName = row_CurrencyName2.ShortName Then Else row_AmountDEV2 = row_AmountDEV * Math.Round(row_CurrencyRate2, 2, MidpointRounding.AwayFromZero) End If End If End If End Set End Property _ _ Overrides Property row_Customer As Customers Get Return MyBase.row_Customer End Get Set(value As Customers) MyBase.row_Customer = value End Set End Property Overrides Property row_Controlling As Controlling Get Return MyBase.row_Controlling End Get Set(value As Controlling) MyBase.row_Controlling = value If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then If value.ChartOfAccounts IsNot Nothing Then row_ChartOfAccounts = value.GetChartOfAccounts(Me.DateExecution.Year, False) End If End If End Set End Property Function GetBallanceHUF(ByVal _LiquidAssets As LiquidAssets, ByVal _ToDate As Date) As Double Dim _SQL As String Dim _SelectedData As SelectedData = Nothing Dim _BallanceHUF As Double = 0 _SQL = " SELECT t1.LiquidAssets_Main AS LiquidAssets," _SQL += " SUM(t3.InAmountHUF)-SUM(t3.OutAmountHUF) As BallanceHUF," _SQL += " SUM(t3.InAmountDEV)-SUM(t3.OutAmountDEV) As BallanceDEV" _SQL += " FROM GLBank t1 JOIN GLHeader t2 ON" _SQL += " t1.Oid=t2.Oid JOIN GLRows t3 On" _SQL += " t2.Oid=t3.GLHeader" _SQL += " WHERE t2.GCRecord IS NULL AND t3.GCRecord IS NULL AND t1.LiquidAssets_Main=@Bank AND " _SQL += " DATE(t2.DateExecution)<=@Date" Dim _stringparam() As String = New String() {"@Bank", "@Date"} Dim _objectparam() As Object = New Object() {_LiquidAssets.Oid, _ToDate.Date} _SelectedData = Session.ExecuteQuery(_SQL, _stringparam, _objectparam) For Each row As SelectStatementResultRow In _SelectedData.ResultSet(0).Rows _BallanceHUF = row.Values(1) Next row Return _BallanceHUF End Function Function GetBallanceOpenHUF(ByVal _LiquidAssets As LiquidAssets, ByVal _ToDate As Date) As Double Dim _SQL As String Dim _SelectedData As SelectedData = Nothing Dim _BallanceHUF As Double = 0 _SQL = " SELECT t1.LiquidAssets_Main AS LiquidAssets," _SQL += " SUM(t3.InAmountHUF)-SUM(t3.OutAmountHUF) As BallanceHUF," _SQL += " SUM(t3.InAmountDEV)-SUM(t3.OutAmountDEV) As BallanceDEV" _SQL += " FROM GLBank t1 JOIN GLHeader t2 ON" _SQL += " t1.Oid=t2.Oid JOIN GLRows t3 On" _SQL += " t2.Oid=t3.GLHeader" _SQL += " WHERE t2.GCRecord IS NULL AND t3.GCRecord IS NULL AND t1.LiquidAssets_Main=@Bank AND " _SQL += " DATE(t2.DateExecution)<@Date" Dim _stringparam() As String = New String() {"@Bank", "@Date"} Dim _objectparam() As Object = New Object() {_LiquidAssets.Oid, _ToDate.Date} _SelectedData = Session.ExecuteQuery(_SQL, _stringparam, _objectparam) For Each row As SelectStatementResultRow In _SelectedData.ResultSet(0).Rows _BallanceHUF = row.Values(1) Next row Return _BallanceHUF End Function Function GetBallanceDEV(ByVal _LiquidAssets As LiquidAssets, ByVal _ToDate As Date) As Double Dim _SQL As String Dim _SelectedData As SelectedData = Nothing Dim _BallanceDEV As Double = 0 _SQL = " SELECT t1.LiquidAssets_Main AS LiquidAssets," _SQL += " SUM(t3.InAmountHUF)-SUM(t3.OutAmountHUF) As BallanceHUF," _SQL += " SUM(t3.InAmountDEV)-SUM(t3.OutAmountDEV) As BallanceDEV" _SQL += " FROM GLBank t1 JOIN GLHeader t2 ON" _SQL += " t1.Oid=t2.Oid JOIN GLRows t3 On" _SQL += " t2.Oid=t3.GLHeader" _SQL += " WHERE t2.GCRecord IS NULL AND t3.GCRecord IS NULL AND t1.LiquidAssets_Main=@Bank AND " _SQL += " DATE(t2.DateExecution)<=@Date" Dim _stringparam() As String = New String() {"@Bank", "@Date"} Dim _objectparam() As Object = New Object() {_LiquidAssets.Oid, _ToDate.Date} _SelectedData = Session.ExecuteQuery(_SQL, _stringparam, _objectparam) For Each row As SelectStatementResultRow In _SelectedData.ResultSet(0).Rows _BallanceDEV = row.Values(2) Next row Return _BallanceDEV End Function Function GetBallanceOpenDEV(ByVal _LiquidAssets As LiquidAssets, ByVal _ToDate As Date) As Double Dim _SQL As String Dim _SelectedData As SelectedData = Nothing Dim _BallanceDEV As Double = 0 _SQL = " SELECT t1.LiquidAssets_Main AS LiquidAssets," _SQL += " SUM(t3.InAmountHUF)-SUM(t3.OutAmountHUF) As BallanceHUF," _SQL += " SUM(t3.InAmountDEV)-SUM(t3.OutAmountDEV) As BallanceDEV" _SQL += " FROM GLBank t1 JOIN GLHeader t2 ON" _SQL += " t1.Oid=t2.Oid JOIN GLRows t3 On" _SQL += " t2.Oid=t3.GLHeader" _SQL += " WHERE t2.GCRecord IS NULL AND t3.GCRecord IS NULL AND t1.LiquidAssets_Main=@Bank AND " _SQL += " DATE(t2.DateExecution)<@Date" Dim _stringparam() As String = New String() {"@Bank", "@Date"} Dim _objectparam() As Object = New Object() {_LiquidAssets.Oid, _ToDate.Date} _SelectedData = Session.ExecuteQuery(_SQL, _stringparam, _objectparam) For Each row As SelectStatementResultRow In _SelectedData.ResultSet(0).Rows _BallanceDEV = row.Values(2) Next row Return _BallanceDEV End Function End Class