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()> _
<NavigationItem(False), CreatableItem(False)> _
Public Class DeliveryNoteInFromOrderOutRowsRows
    Inherits BaseObject
    Private _DeliveryNoteInFromOrderOutRowsHeader As DeliveryNoteInFromOrderOutRowsHeader
    Private _OrderOutRows As OrderOutRows
    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("DeliveryNoteInFromOrderOutRowsHeader-DeliveryNoteInFromOrderOutRowsRows", GetType(DeliveryNoteInFromOrderOutRowsHeader))> _
    Property DeliveryNoteInFromOrderOutRowsHeader As DeliveryNoteInFromOrderOutRowsHeader
        Get
            Return _DeliveryNoteInFromOrderOutRowsHeader
        End Get
        Set(value As DeliveryNoteInFromOrderOutRowsHeader)
            SetPropertyValue("DeliveryNoteInFromOrderOutRowsHeader", _DeliveryNoteInFromOrderOutRowsHeader, value)
        End Set
    End Property
    Property OrderOutRows As OrderOutRows
        Get
            Return _OrderOutRows
        End Get
        Set(value As OrderOutRows)
            SetPropertyValue("OrderOutRows", _OrderOutRows, 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.OrderOutRows Is OrderOutRows
            Group _DNIR By _DNIR.OrderOutRows 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
