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 System.Linq

<DefaultClassOptions(), CreatableItem(False), NavigationItem(False)> _
Public Class DeliveryNoteInFromOffersInRowsRows
    Inherits BaseObject

    Private _DeliveryNoteInFromOffersInRowsHeader As DeliveryNoteInFromOffersInRowsHeader
    Private _OfferInRows As OfferInRows
    Private _QTT_Process As Double
    Public Sub New(ByVal session As Session)
        MyBase.New(session)

    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()

    End Sub
    <Association("DeliveryNoteInFromOffersInRowsHeader-DeliveryNoteInFromOffersInRowsRows", GetType(DeliveryNoteInFromOffersInRowsHeader))> _
    Property DeliveryNoteInFromOrderOutRowsHeader As DeliveryNoteInFromOffersInRowsHeader
        Get
            Return _DeliveryNoteInFromOffersInRowsHeader
        End Get
        Set(value As DeliveryNoteInFromOffersInRowsHeader)
            SetPropertyValue("DeliveryNoteInFromOffersInRowsHeader", _DeliveryNoteInFromOffersInRowsHeader, value)
        End Set
    End Property
    Property OfferInRows As OfferInRows
        Get
            Return _OfferInRows
        End Get
        Set(value As OfferInRows)
            SetPropertyValue("OfferInRows", _OfferInRows, value)
        End Set
    End Property
    Property QTT_Process As Double
        Get
            Return _QTT_Process
        End Get
        Set(value As Double)
            SetPropertyValue("QTT_Process", _QTT_Process, value)
        End Set
    End Property
    ReadOnly Property QTT_DeliveryNoteIn As Double
        Get
            Dim _DeliveryNoteInRows As New XPQuery(Of DeliveryNoteInRows)(Session)
            Dim _QTT_Sum As Double = 0
            Dim query = From _DNIR In _DeliveryNoteInRows
                    Where _DNIR.OfferInRows Is OfferInRows
            Group _DNIR By _DNIR.OfferInRows Into g = Group _
            Select New With {Key .QTT_Sum = g.Sum(Function(inv) inv.QTT)}

            For Each item In query
                _QTT_Sum = item.QTT_Sum
            Next

            Return _QTT_Sum
        End Get
    End Property
End Class
