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

<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
Public Class InventorySC
    Inherits BaseObject
    Private _InventoryHeader As InventoryHeader
    Private _Products As Products
    Private _QTT As Double 'Raktáron lévő mennyiség GÉPI készlet
    Private _QTT_Found As Double 'Raktáron lévő TALÁLT mennyiség
    Private _QTT_Different As Double 'Különbség GÉPI-TALÁLT
    Private _AveragePriceHUF As Double 'Mérlegelt átlagár adott záró dátumra vonatkozólag
    Private _SumAveragePriceHUF_Found As Double 'Talált átlagár
    Private _SumAveragePriceHUF As Double 'Gépi érték
    Private _SumAveragePriceHUF_Different As Double 'különbség érték
    Private _SumAveragePriceHUF_Surplus As Double 'Összes Többlet
    Private _SumAveragePriceHUF_Want As Double 'Összes Hiány

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub

    <Association("InventoryHeader-InventorySC", GetType(InventoryHeader))> _
    Property InventoryHeader As InventoryHeader
        Get
            Return _InventoryHeader
        End Get
        Set(value As InventoryHeader)
            SetPropertyValue("InventoryHeader", _InventoryHeader, value)
        End Set
    End Property
    Property Products As Products
        Get
            Return _Products
        End Get
        Set(value As Products)
            SetPropertyValue("Products", _Products, value)
        End Set
    End Property
    Property QTT As Double
        Get
            Return Math.Round(_QTT, 4, MidpointRounding.AwayFromZero)
        End Get
        Set(value As Double)
            SetPropertyValue("QTT", _QTT, Math.Round(value, 4, MidpointRounding.AwayFromZero))
        End Set
    End Property
    Property QTT_Found As Double
        Get
            Return Math.Round(_QTT_Found, 4, MidpointRounding.AwayFromZero)
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Found", _QTT_Found, Math.Round(value, 4, MidpointRounding.AwayFromZero))
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                QTT_Different = Math.Round(value - QTT, 4, MidpointRounding.AwayFromZero)

                SumAveragePriceHUF_Found = AveragePriceHUF * value
                SumAveragePriceHUF_Different = SumAveragePriceHUF_Found - SumAveragePriceHUF

                If SumAveragePriceHUF_Different > 0 Then
                    SumAveragePriceHUF_Surplus = SumAveragePriceHUF_Different
                Else
                    SumAveragePriceHUF_Want = Math.Abs(SumAveragePriceHUF_Different)
                End If
            End If
        End Set
    End Property
    Property QTT_Different As Double
        Get
            Return Math.Round(_QTT_Different, 4, MidpointRounding.AwayFromZero)
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Different", _QTT_Different, Math.Round(value, 4, MidpointRounding.AwayFromZero))
        End Set
    End Property
    Property AveragePriceHUF As Double
        Get
            Return _AveragePriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("AveragePriceHUF", _AveragePriceHUF, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                SumAveragePriceHUF_Found = Math.Round(AveragePriceHUF * QTT_Found, 0, MidpointRounding.AwayFromZero)
                SumAveragePriceHUF = Math.Round(AveragePriceHUF * QTT, 0, MidpointRounding.AwayFromZero)
                SumAveragePriceHUF_Different = Math.Round(AveragePriceHUF * QTT_Different, 0, MidpointRounding.AwayFromZero)
            End If
        End Set
    End Property
    Property SumAveragePriceHUF_Found As Double
        Get
            Return _SumAveragePriceHUF_Found
        End Get
        Set(value As Double)
            SetPropertyValue("SumAveragePriceHUF_Found", _SumAveragePriceHUF_Found, value)
        End Set
    End Property
    Property SumAveragePriceHUF As Double
        Get
            Return Math.Round(_SumAveragePriceHUF, 4, MidpointRounding.AwayFromZero)
        End Get
        Set(value As Double)
            SetPropertyValue("SumAveragePriceHUF", _SumAveragePriceHUF, Math.Round(value, 4, MidpointRounding.AwayFromZero))
        End Set
    End Property
    Property SumAveragePriceHUF_Different As Double
        Get
            Return Math.Round(_SumAveragePriceHUF_Different, 4, MidpointRounding.AwayFromZero)
        End Get
        Set(value As Double)
            SetPropertyValue("SumAveragePriceHUF_Different", _SumAveragePriceHUF_Different, Math.Round(value, 4, MidpointRounding.AwayFromZero))
        End Set
    End Property
    Property SumAveragePriceHUF_Surplus As Double
        Get
            Return _SumAveragePriceHUF_Surplus
        End Get
        Set(value As Double)
            SetPropertyValue("SumAveragePriceHUF_Surplus", _SumAveragePriceHUF_Surplus, value)
        End Set
    End Property
    Property SumAveragePriceHUF_Want As Double
        Get
            Return _SumAveragePriceHUF_Want
        End Get
        Set(value As Double)
            SetPropertyValue("SumAveragePriceHUF_Want", _SumAveragePriceHUF_Want, value)
        End Set
    End Property
End Class
