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.ExpressApp.ConditionalAppearance



<DefaultClassOptions()> _
<NavigationItem(False), CreatableItem(False)> _
<Appearance("Disable InsertServicesToOfferOut", AppearanceItemType.Action, "OfferInHeader.IsEditable = False", TargetItems:="InsertServicesToOfferIN", Enabled:=False)> _
Public Class OfferInRows
    Inherits BaseObject
    Private _OfferInHeader As OfferInHeader 'Árajánlat fejléce
    Private _RowType As eRowType 'Sor miről szól ?
    Private _RowGroup1 As String 'Szöveges csoportosítás (nem kötelező)
    Private _RowGroup2 As String 'Szöveges másodlagos csoportosítás (nem kötelező)
    Private _Product As Products 'Termék
    Private _Installation As Installation 'Gyártmány
    Private _RowIndex As Long 'Sor index (mozgathatónak kell lennie !)
    Private _ShortName As String 'Megnevezés -> Ez megy majd rá később a számlára is !
    Private _Description As String 'Leírás -> ez is rá fog menni a számlára !
    Private _DescriptionPrivate As String 'Na ez csak látszódjon, de nem menjen föl semmilyen doksira !!!
    Private _QTT As Double = 0 'Mennyiség. A Mennyiségi egység vagy a Products-ból, vag Installationnál DB
    Private _QualityOption As QualityOption 'Minőségi opció
    Private _Units As Units
    Private _VAT As VAT
    Private _DateAcknowledgement As Date 'Visszaigazolás dátuma
    'Árak !!!!
    Private _SumPriceHUF As Double
    Private _SumPriceDEV As Double
    Private _FinalPriceDEV As Double
    Private _FinalPriceHUF As Double

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

    <Association("OfferInHeader", GetType(OfferInHeader))> _
    Property OfferInHeader() As OfferInHeader
        Get
            Return _OfferInHeader
        End Get
        Set(ByVal value As OfferInHeader)
            SetPropertyValue("OfferInHeader", _OfferInHeader, value)
        End Set
    End Property
    Property RowType() As eRowType
        Get
            Return _RowType
        End Get
        Set(ByVal value As eRowType)
            SetPropertyValue("RowType", _RowType, value)
        End Set
    End Property
    Property RowGroup1 As String
        Get
            Return _RowGroup1
        End Get
        Set(value As String)
            SetPropertyValue("RowGroup1", _RowGroup1, value)
        End Set
    End Property
    Property RowGroup2 As String
        Get
            Return _RowGroup2
        End Get
        Set(value As String)
            SetPropertyValue("RowGroup2", _RowGroup2, value)
        End Set
    End Property
    <RuleRequiredField("", "aToTable_OfferIn_Contexts", TargetCriteria:="RowType=0")> _
    Property Product() As Products
        Get
            Return _Product
        End Get
        Set(ByVal value As Products)
            SetPropertyValue("Product", _Product, value)
        End Set
    End Property
    Property Installation As Installation
        Get
            Return _Installation
        End Get
        Set(ByVal value As Installation)
            SetPropertyValue("Installation", _Installation, value)
        End Set
    End Property
    Property RowIndex() As Long
        Get
            Return _RowIndex
        End Get
        Set(ByVal value As Long)
            SetPropertyValue("RowIndex", _RowIndex, value)
        End Set
    End Property
    <Size(255)> _
    Property ShortName() As String
        Get
            Return _ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    <Size(-1)> _
    Property DescriptionPrivate As String
        Get
            Return _DescriptionPrivate
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DescriptionPrivate", _DescriptionPrivate, value)
        End Set
    End Property
    <RuleRequiredField("", DefaultContexts.Save)> _
    <RuleRange("", DefaultContexts.Save, 0.001, 999999999)> _
    Property QTT() As Double
        Get
            Return _QTT
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("QTT", _QTT, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                SumPriceDEV = QTT * FinalPriceDEV
                SumPriceHUF = QTT * FinalPriceHUF
            End If
        End Set
    End Property
    Property Units As Units
        Get
            Return _Units
        End Get
        Set(value As Units)
            SetPropertyValue("Units", _Units, value)
        End Set
    End Property
    Property VAT As VAT
        Get
            Return _VAT
        End Get
        Set(value As VAT)
            SetPropertyValue("VAT", _VAT, value)
        End Set
    End Property
    Property QualityOption() As QualityOption
        Get
            Return _QualityOption
        End Get
        Set(ByVal value As QualityOption)
            SetPropertyValue("QualityOption", _QualityOption, value)
        End Set
    End Property
    Property DateAcknowledgement As Date
        Get
            Return _DateAcknowledgement
        End Get
        Set(value As Date)
            SetPropertyValue("DateAcknowledgement", _DateAcknowledgement, value)
        End Set
    End Property

    Property SumPriceHUF As Double
        Get
            Return _SumPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceHUF", _SumPriceHUF, value)
        End Set
    End Property
    Property SumPriceDEV As Double
        Get
            Return _SumPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("SumPriceDEV", _SumPriceDEV, value)
        End Set
    End Property
    Property FinalPriceDEV As Double
        Get
            Return _FinalPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("FinalPriceDEV", _FinalPriceDEV, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                SumPriceDEV = QTT * FinalPriceDEV
            End If
        End Set
    End Property
    Property FinalPriceHUF As Double
        Get
            Return _FinalPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("FinalPriceHUF", _FinalPriceHUF, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                SumPriceHUF = QTT * FinalPriceHUF
            End If
        End Set
    End Property

    Public Sub AddRows(ByVal _p_OfferInHeader As OfferInHeader)
        ' Sor hozzáadása
        Me.OfferInHeader = _p_OfferInHeader

        If _p_OfferInHeader.row_RowType = eRowType.IsInstallation Then ' Sor hozzáadása ha gyártmány típusú a sor
            Me.Installation = _p_OfferInHeader.row_Installation
            Me.RowType = _p_OfferInHeader.row_RowType
            Me.QTT = _p_OfferInHeader.row_QTT
            Me.Units = Session.FindObject(Of Units)(CriteriaOperator.Parse("ShortName='DB'"))
            Me.RowGroup1 = _p_OfferInHeader.row_RowGroup1
            Me.RowGroup2 = _p_OfferInHeader.row_RowGroup2
            Me.VAT = _p_OfferInHeader.row_VAT


            FinalPriceDEV = _p_OfferInHeader.row_FinalPriceDEV
            FinalPriceHUF = _p_OfferInHeader.row_FinalPriceHUF
            SumPriceDEV = FinalPriceDEV * QTT
            SumPriceHUF = FinalPriceHUF * QTT
        End If

        If _p_OfferInHeader.row_RowType = eRowType.IsOther Then ' Sor hozzáadása ha egyéb típusú a sor
            Me.ShortName = _p_OfferInHeader.row_ShortName
            Me.RowType = _p_OfferInHeader.row_RowType
            Me.QTT = _p_OfferInHeader.row_QTT
            Me.Units = _p_OfferInHeader.row_Units
            Me.Description = _p_OfferInHeader.row_Description
            Me.VAT = _p_OfferInHeader.row_VAT
            Me.RowGroup1 = _p_OfferInHeader.row_RowGroup1
            Me.RowGroup2 = _p_OfferInHeader.row_RowGroup2


            FinalPriceDEV = _p_OfferInHeader.row_FinalPriceDEV
            FinalPriceHUF = _p_OfferInHeader.row_FinalPriceHUF
            SumPriceDEV = FinalPriceDEV * QTT
            SumPriceHUF = FinalPriceHUF * QTT
        End If

        If _p_OfferInHeader.row_RowType = eRowType.IsProduct Then ' Sor hozzáadása ha termék típusú a sor
            Me.Product = _p_OfferInHeader.row_Products
            Me.RowType = _p_OfferInHeader.row_RowType
            Me.QTT = _p_OfferInHeader.row_QTT
            Me.Units = _p_OfferInHeader.row_Units
            Me.VAT = _p_OfferInHeader.row_Products.VAT
            Me.RowGroup1 = _p_OfferInHeader.row_RowGroup1
            Me.RowGroup2 = _p_OfferInHeader.row_RowGroup2

            FinalPriceDEV = _p_OfferInHeader.row_FinalPriceDEV
            FinalPriceHUF = _p_OfferInHeader.row_FinalPriceHUF
            SumPriceDEV = FinalPriceDEV * QTT
            SumPriceHUF = FinalPriceHUF * QTT
        End If

        ' Indexelés
        If _p_OfferInHeader.OfferInRows.Count = 0 Then
            Me.RowIndex = 0
        Else
            Me.RowIndex = _p_OfferInHeader.OfferInRows.Count - 1
        End If
    End Sub
    Public Sub RemoveRows()
        Me.Delete()
    End Sub
End Class
