Imports System Imports System.ComponentModel Imports System.Collections.Generic Imports System.Text Imports System.Data Imports DevExpress.Xpo Imports DevExpress.Xpo.DB Imports DevExpress.Xpo.Helpers Imports DevExpress.Data.Filtering Imports DevExpress.ExpressApp Imports DevExpress.Persistent.Base Imports DevExpress.Persistent.BaseImpl Imports DevExpress.Persistent.Validation Imports System.Drawing Imports DevExpress.Xpo.Metadata Imports DevExpress.ExpressApp.ConditionalAppearance _ _ _ _ Public Class LiquidAssets '-- Pénzeszközök Inherits BaseObject Private _ShortName As String Private _LiquidAssetsType As eLiquidAssetsType = eLiquidAssetsType.NormalCheckout Private _Description As String Private _CustomerFrom As CustomersFrom Private _NumberGeneratorOut As NumberGenerator Private _NumberGeneratorIn As NumberGenerator Private _Active As Boolean = True Private _ImagePicture As Image Private _ChartOfAccounts As ChartOfAccounts Private _CurrencyName As CurrencyName Private _ReportData As ReportData Private _ReportDataV2 As ReportDataV2 'V2 nyopmtatvány Private _ReportData_Return As ReportData Private _IsRounding As Boolean = False Private _ChartOfAccountsPlus As ChartOfAccounts Private _ChartOfAccountsMinus As ChartOfAccounts Private _NoPrint As Boolean 'Nincs bizonylat nyomtatás Private _NoDocumentNumber As Boolean 'Ne legyen sorszám automatikusa Private _NoTimeCheck As Boolean 'Nincs dátum és sorszám ellenőrzés Public Sub New(ByVal session As Session) MyBase.New(session) End Sub Public Overrides Sub AfterConstruction() MyBase.AfterConstruction() NoPrint = False NoDocumentNumber = False NoTimeCheck = False End Sub _ Property ShortName As String Get Return _ShortName End Get Set(ByVal value As String) SetPropertyValue("ShortName", _ShortName, value) End Set End Property _ _ Property LiquidAssetsType As eLiquidAssetsType Get Return _LiquidAssetsType End Get Set(ByVal value As eLiquidAssetsType) SetPropertyValue("LiquidAssetsType", _LiquidAssetsType, value) End Set End Property _ Property Description As String Get Return _Description End Get Set(ByVal value As String) SetPropertyValue("Description", _Description, value) End Set End Property _ Property CustomerFrom As CustomersFrom Get Return _CustomerFrom End Get Set(ByVal value As CustomersFrom) SetPropertyValue("CustomerFrom", _CustomerFrom, value) End Set End Property _ Property NumberGeneratorOut As NumberGenerator Get Return _NumberGeneratorOut End Get Set(ByVal value As NumberGenerator) SetPropertyValue("NumberGeneratorOut", _NumberGeneratorOut, value) End Set End Property _ Property NumberGeneratorIn As NumberGenerator Get Return _NumberGeneratorIn End Get Set(ByVal value As NumberGenerator) SetPropertyValue("NumberGeneratorIn", _NumberGeneratorIn, value) End Set End Property Property Active As Boolean Get Return _Active End Get Set(ByVal value As Boolean) SetPropertyValue("Active", _Active, value) End Set End Property _ _ Property ImagePicture As Image Get Return _ImagePicture End Get Set(ByVal Value As System.Drawing.Image) If Value Is _ImagePicture Then Exit Property _ImagePicture = Value End Set End Property Property ChartOfAccounts() As ChartOfAccounts Get Return _ChartOfAccounts End Get Set(ByVal value As ChartOfAccounts) SetPropertyValue("ChartOfAccounts", _ChartOfAccounts, value) End Set End Property _ Property CurrencyName() As CurrencyName Get Return _CurrencyName End Get Set(ByVal value As CurrencyName) SetPropertyValue("CurrencyName", _CurrencyName, value) End Set End Property Property ReportData As ReportData Get Return _ReportData End Get Set(ByVal value As ReportData) SetPropertyValue("ReportData", _ReportData, value) End Set End Property Property ReportDataV2 As ReportDataV2 Get Return _ReportDataV2 End Get Set(ByVal value As ReportDataV2) SetPropertyValue("ReportDataV2", _ReportDataV2, value) End Set End Property Property ReportData_Return As ReportData Get Return _ReportData_Return End Get Set(ByVal value As ReportData) SetPropertyValue("ReportData_Return", _ReportData_Return, value) End Set End Property _ _ Property IsRounding As Boolean Get Return _IsRounding End Get Set(ByVal value As Boolean) SetPropertyValue("IsRounding", _IsRounding, value) End Set End Property _ Property ChartOfAccountsPlus As ChartOfAccounts Get Return _ChartOfAccountsPlus End Get Set(ByVal value As ChartOfAccounts) SetPropertyValue("ChartOfAccountsPlus", _ChartOfAccountsPlus, value) End Set End Property _ Property ChartOfAccountsMinus As ChartOfAccounts Get Return _ChartOfAccountsMinus End Get Set(ByVal value As ChartOfAccounts) SetPropertyValue("ChartOfAccountsMinus", _ChartOfAccountsMinus, value) End Set End Property Property NoPrint As Boolean Get Return _NoPrint End Get Set(value As Boolean) SetPropertyValue("NoPrint", _NoPrint, value) End Set End Property Property NoDocumentNumber As Boolean Get Return _NoDocumentNumber End Get Set(value As Boolean) SetPropertyValue("NoDocumentNumber", _NoDocumentNumber, value) End Set End Property Property NoTimeCheck As Boolean Get Return _NoTimeCheck End Get Set(value As Boolean) SetPropertyValue("NoTimeCheck", _NoTimeCheck, value) End Set End Property Structure GLRowsToModify_AmountDEVFIFO Dim Oid As Guid Dim AmountDEVFIFO As Double End Structure Function GetCurrencyRateFIFO(_uow As Session, _LiquidAssets As LiquidAssets, _AmountDEV As Double, _DateClose As Date, _GLRows_Out As Guid) As Double '// Adott záródátumra kiszámolja a FIFO árfolyamot Dim _SumAmountDev As Double = 0 Dim _SumAmountHUF As Double = 0 Dim _NewFifo As Double = 0 Dim _GLRowsToModify_ArrayList As ArrayList = New ArrayList Dim _GLRowsToModify As GLRowsToModify_AmountDEVFIFO = New GLRowsToModify_AmountDEVFIFO Dim _GLRows As GLRows Dim _GLRowsFIFO As GLRowsFIFO Dim _AmountDEVTotal As Double = _AmountDEV Dim _GLRowsFIFOOut As GLRows = _uow.GetObjectByKey(Of GLRows)(_GLRows_Out) Dim _GLRows_Collection As New XPCollection(Of GLRows)(PersistentCriteriaEvaluationBehavior.InTransaction, _uow, _ CriteriaOperator.Parse("LiquidAssets.Oid=? And GLHeader.IsEditable=False And InAmountDEV>0 And InAmountDEV>AmountDEVFIFO And GetDate(GLHeader.DateExecution)= _AmountDEV Then '_NewFifo = _GLRows.AmountDEVFIFO + _AmountDEV _NewFifo = _AmountDEV _GLRowsToModify.Oid = _GLRows.Oid _GLRowsToModify.AmountDEVFIFO = _GLRowsToModify.AmountDEVFIFO + _NewFifo _GLRowsToModify_ArrayList.Add(_GLRowsToModify) _SumAmountDev = _SumAmountDev + _AmountDEV _SumAmountHUF = _SumAmountHUF + _AmountDEV * _GLRows.CurrencyRate _AmountDEV = 0 Else _NewFifo = _GLRows.InAmountDEV - _GLRows.AmountDEVFIFO _GLRowsToModify.Oid = _GLRows.Oid _GLRowsToModify.AmountDEVFIFO = _GLRowsToModify.AmountDEVFIFO + _NewFifo _GLRowsToModify_ArrayList.Add(_GLRowsToModify) _SumAmountDev = _SumAmountDev + _NewFifo _SumAmountHUF = _SumAmountHUF + _NewFifo * _GLRows.CurrencyRate _AmountDEV = _AmountDEV - _NewFifo End If _GLRowsFIFO = New GLRowsFIFO(_uow) _GLRowsFIFO.GLRowsIn = _GLRows _GLRowsFIFO.GLRowsOut = _GLRowsFIFOOut _GLRowsFIFO.OutAmountDEV = _AmountDEVTotal _GLRowsFIFO.InAmountDEV = _NewFifo _GLRowsFIFO.Save() If _AmountDEV = 0 Then Exit For End If Next For Each _GLRowsToModify In _GLRowsToModify_ArrayList _GLRows = _uow.GetObjectByKey(Of GLRows)(_GLRowsToModify.Oid) _GLRows.AmountDEVFIFO = _GLRows.AmountDEVFIFO + _GLRowsToModify.AmountDEVFIFO _GLRows.Save() Next If _SumAmountDev = 0 Then Return 0 Else Return _SumAmountHUF / _SumAmountDev End If End Function Function GetCurrencyRateAverage(_uow As Session, _LiquidAssets As LiquidAssets, _DateClose As Date) As Double '// Adott záródátumra kiszámolja a Átlagár árfolyamot Dim _GLRows_Collection As New XPCollection(Of GLRows)(PersistentCriteriaEvaluationBehavior.InTransaction, _uow, _ CriteriaOperator.Parse("LiquidAssets.Oid=? And GLHeader.IsEditable=False And GetDate(GLHeader.DateExecution)<=? and GetDate(GLHeader.DateExecution)>=? and InAmountDEV>0", _ _LiquidAssets.Oid, _DateClose, FirstDayOfYear(_DateClose))) _GLRows_Collection.Sorting.Add(New SortProperty("GLHeader.DateExecution", DB.SortingDirection.Ascending)) Dim _SumAmountDev As Double = 0 Dim _SumAmountHUF As Double = 0 Dim _LiquidAssetsRate As LiquidAssetsRate = _uow.FindObject(Of LiquidAssetsRate)(CriteriaOperator.Parse("LiquidAssets.oid=? and GetYear(DateExecution)=?", _LiquidAssets.Oid, _DateClose.Year)) If _LiquidAssetsRate IsNot Nothing Then _SumAmountDev = _LiquidAssetsRate.AmountDEV _SumAmountHUF = _LiquidAssetsRate.AmountHUF End If For Each _GLRows As GLRows In _GLRows_Collection Dim _GLRowsFIFO_Collection As New XPCollection(Of GLRowsFIFO)(PersistentCriteriaEvaluationBehavior.InTransaction, _uow, CriteriaOperator.Parse("GLRowsOut.Oid=?", _GLRows.Oid)) _uow.Delete(_GLRowsFIFO_Collection) If _GLRows.OutAmountDEV <> 0 Then _SumAmountDev = _SumAmountDev + _GLRows.OutAmountDEV _SumAmountHUF = _SumAmountHUF + _GLRows.OutAmountHUF Else _SumAmountDev = _SumAmountDev + _GLRows.InAmountDEV _SumAmountHUF = _SumAmountHUF + _GLRows.InAmountHUF End If Next If _SumAmountDev = 0 Then Return 0 Else Return _SumAmountHUF / _SumAmountDev End If End Function Function GetCurrencyRateDate(_ocur As Xpo.XPObjectSpace, _TransactionType As eTransactionType, _LiquidAssets As LiquidAssets, _DateExecution As Date) As Double Dim _uow As New UnitOfWork(_ocur.Session.DataLayer) Dim _Rate As Double = 0 Select Case _TransactionType Case eTransactionType.eNormalCredit, eTransactionType.ePartnerCredit '// Árfolyam lekérése először a pénzeszközre Dim _CurrencyRate_Collection As XPCollection(Of CurrencyRate) Dim _CurrencyRate As CurrencyRate _CurrencyRate_Collection = New XPCollection(Of CurrencyRate) _ (_ocur.Session, CriteriaOperator.Parse("CurrencyName=? and LiquidAssets=? and GetDate(DateValid)<=?", _ _LiquidAssets.CurrencyName, _DateExecution.Date)) _CurrencyRate_Collection.Sorting.Add(New SortProperty("DateValid", DB.SortingDirection.Descending)) If _CurrencyRate_Collection.Count > 0 Then For Each _CurrencyRate In _CurrencyRate_Collection If _CurrencyRate.DateValid.Date = _DateExecution.Date Then _Rate = _CurrencyRate.RateAverage Exit For End If Exit For Next Else '// MNB árfolyam lekérése _CurrencyRate_Collection = New XPCollection(Of CurrencyRate) _ (_ocur.Session, CriteriaOperator.Parse("CurrencyName=? and IsMNB=True and GetDate(DateValid)<=?", _ _LiquidAssets.CurrencyName, _DateExecution.Date)) _CurrencyRate_Collection.Sorting.Add(New SortProperty("DateValid", DB.SortingDirection.Descending)) If _CurrencyRate_Collection.Count > 0 Then For Each _CurrencyRate In _CurrencyRate_Collection If _CurrencyRate.DateValid.Date = _DateExecution.Date Then _Rate = _CurrencyRate.RateAverage Exit For End If Exit For Next Else Throw New Exception("*Nincs beállítva sem a pénzeszköz árfolyama sem az MNB árfolyama !") End If End If Case eTransactionType.eNormalDebit, eTransactionType.ePartnerDebit _Rate = _LiquidAssets.GetCurrencyRateAverage(_uow, _LiquidAssets, _DateExecution) End Select Return _Rate End Function '// Readonly propertyk _ ReadOnly Property LiquidAssetsYear As XPCollection(Of LiquidAssetsYear) Get Return GetCollection(Of LiquidAssetsYear)("LiquidAssetsYear") End Get End Property _ ReadOnly Property LiquidAssetsRate As XPCollection(Of LiquidAssetsRate) Get Return GetCollection(Of LiquidAssetsRate)("LiquidAssetsRate") End Get End Property Public Function GetChartOfAccounts(_AccountYear As Long, _Mode As Long) As ChartOfAccounts Dim _ChartOfAccounts As ChartOfAccounts = Nothing Dim _LiquidAssetsYear As LiquidAssetsYear Select Case _Mode Case 0 _ChartOfAccounts = Me.ChartOfAccounts For Each _LiquidAssetsYear In Me.LiquidAssetsYear If _LiquidAssetsYear.AccountYear = _AccountYear Then _ChartOfAccounts = _LiquidAssetsYear.ChartOfAccounts Exit For End If Next Case 1 _ChartOfAccounts = Me.ChartOfAccountsMinus For Each _LiquidAssetsYear In Me.LiquidAssetsYear If _LiquidAssetsYear.AccountYear = _AccountYear Then _ChartOfAccounts = _LiquidAssetsYear.ChartOfAccountsMinus Exit For End If Next Case 2 _ChartOfAccounts = Me.ChartOfAccountsPlus For Each _LiquidAssetsYear In Me.LiquidAssetsYear If _LiquidAssetsYear.AccountYear = _AccountYear Then _ChartOfAccounts = _LiquidAssetsYear.ChartOfAccountsPlus Exit For End If Next End Select Return _ChartOfAccounts End Function End Class