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

Public Enum eWeightMode
    eTotalWeightperQuantity = 0 'Össz súly
    eUnitWeightperQuantity = 1 'Egység súly
End Enum
<DefaultClassOptions()>
<NavigationItem("BusinessTransactions")>
<DefaultProperty("DisplayName")>
<Appearance("DeliveryNoteInHeader - Disable IsStorno and IsEditable_DeliveryNoteIn", AppearanceItemType.ViewItem, "1=1", TargetItems:="IsStorno;IsEditable", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable all properties on DetailNoteInHeader when IsEditable = False",
    AppearanceItemType.ViewItem,
    "IsEditable = False",
    TargetItems:="DeliveryNoteInType;DocumentNumber;CustomersFrom;DateCreated;" +
                 "CurrencyRate;IsEditable;IsStorno;ObjectCreated;UserCreated;IsControlled;IsStoraged", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Hide payment properties if DeliveryNoteInType.IsPrice = False", AppearanceItemType.ViewItem, "DeliveryNoteInType.IsPrice=False", TargetItems:="PaymentOption;DatePayment;row_ListPriceDEV;row_ListPriceHUF;CurrencyName;CurrencyRate;row_DiscountPercent", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Hide DeliveryNoteInHeader-CurrencyRate", AppearanceItemType.ViewItem, "CurrencyName.ShortName='HUF'", TargetItems:="CurrencyRate", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Hide _row_ListPriceDEV if CurrencyName is HUF", AppearanceItemType.ViewItem, "CurrencyName.ShortName='HUF' Or IsNull(DeliveryNoteInType)=True", TargetItems:="row_ListPriceDEV", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Hide _row_ListPriceHUF if CurrencyName is not HUF", AppearanceItemType.ViewItem, "(CurrencyName.ShortName<>'HUF' And IsNull(CurrencyName)=False) Or IsNull(DeliveryNoteInType)=True", TargetItems:="row_ListPriceHUF", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Disable aToTable_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aTotable_DeliveryNoteIn", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Disable aToTableD_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aTotableD_DeliveryNoteIn", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Disable aFinalize_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="aFinalize_DeliveryNoteIn;aFinalize_And_Storage_DeliveryNoteIn", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Enable aFinalize_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = True", TargetItems:="aFinalize_DeliveryNoteIn", Enabled:=True)>
<Appearance("DeliveryNoteInHeader - Disable aGenerateStorageIn_From_DeliveryNoteInRows", AppearanceItemType.Action, "IsStorno = True", TargetItems:="aGenerateStorageIn_From_DeliveryNoteInRows", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable aStorno_DeliveryNoteIn", AppearanceItemType.Action, "IsStorno = True Or IsEditable = True", TargetItems:="aStorno_DeliveryNoteIn", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Enable aStorno_DeliveryNoteIn", AppearanceItemType.Action, "IsStorno = False And IsEditable = False", TargetItems:="aStorno_DeliveryNoteIn", Enabled:=True)>
<Appearance("DeliveryNoteInHeader - Disable OpeneObject_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="OpenObject", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable Delete_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="Delete", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable Save_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="Save", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable SaveAndNew_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="SaveAndNew", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable SaveAndClose_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="SaveAndClose", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable ShowAllContexts_DeliveryNoteIn", AppearanceItemType.Action, "IsEditable = False", TargetItems:="ShowAllContexts", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable DeliveryNoteInHeader-CustomersFrom", AppearanceItemType.ViewItem, "IsNull(CustomersFrom)=False", TargetItems:="CustomersFrom", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable DeliveryNoteInHeader-DeliveryNoteInType", AppearanceItemType.ViewItem, "IsNull(DeliveryNoteInType)=False", TargetItems:="DeliveryNoteInType", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable DeliveryNoteInHeader-Customers", AppearanceItemType.ViewItem, "IsNull(Customers)=False", TargetItems:="Customers", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable DocumentNumber", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Set line to red if IsStorno=True", AppearanceItemType:="ViewItem", TargetItems:="*", FontColor:="Red", Criteria:="IsStorno=True", Context:="ListView")>
<Appearance("DeliveryNoteInHeader - Disable ObjectCreated DeliveryNoteInHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Disable UserCreated DeliveryNoteInHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)>
<Appearance("DeliveryNoteInHeader - Hide Tab_DeliveryNoteInRows", AppearanceItemType.LayoutItem, "IsNull(DeliveryNoteInType) Or IsNull(DocumentNumber) Or IsNull(Customers) Or IsNull(CustomersFrom)", TargetItems:="Tab_DeliveryNoteInRows", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Hide Tab_StorageInRows", AppearanceItemType.LayoutItem, "IsNull(DeliveryNoteInType) Or IsNull(DocumentNumber) Or IsNull(Customers) Or IsNull(CustomersFrom)", TargetItems:="Tab_StorageInRows", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Hide Tab_StorageOutRowsInRows", AppearanceItemType.LayoutItem, "IsNull(DeliveryNoteInType) Or IsNull(DocumentNumber) Or IsNull(Customers) Or IsNull(CustomersFrom)", TargetItems:="Tab_StorageOutRowsInRows", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Hide all row_ properties, when IsEditable = False",
             AppearanceItemType.ViewItem,
             "IsEditable = False",
             TargetItems:="row_PacketNumber;row_CountryFrom;row_Weight;row_OrderOutRows;row_Products;row_QTT;" +
                          "row_ListPriceHUF;row_ListPriceDEV;row_DiscountPercent;row_NoteRows;row_WeightMode;", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("DeliveryNoteInHeader - Disable DatePayment", AppearanceItemType.ViewItem, "1=1", TargetItems:="DatePayment", Enabled:=False)>
Public Class DeliveryNoteInHeader 'Bejövő szállítólevél fejléc
    Inherits BaseObject
    Private _DeliveryNoteInType As DeliveryNoteInType 'Bejövő szállítólevél tipusa
    Private _DocumentNumber As String 'Bizonylat száma
    Private _DocumentNumberIn As String 'Belső sorszám (véglegesítéskor kapja)
    Private _CustomersFrom As CustomersFrom 'Saját cég
    Private _Customers As Customers 'Beszállító
    Private _DateCreated As Date 'Kiáll. dátuma
    Private _DateExecution As Date 'Teljesítés dátuma
    Private _DatePayment As Date 'Fizetési határidő
    Private _PaymentOption As PaymentOption 'Fizetési opció
    Private _ShipmentOption As ShipmentOption 'Szállítási opció
    Private _QualityOption As QualityOption 'Minőségi opció
    Private _CurrencyName As CurrencyName 'Deviza
    Private _CurrencyRate As Double 'Deviza árfolyam
    Private _Note As String 'Fejléc megjegyzés
    Private _IsEditable As Boolean = True 'Szerkeszthető
    Private _IsStorno As Boolean = False 'Végleges
    Private _ObjectCreated As Date 'Objektum keletkezésének dátuma
    Private _UserCreated As User
    Private _IsControlled As Boolean 'Akkor lesz True, ha a szállítólevélen lévő összes sor össze van pontozva számlával
    Private _IsStoraged As Boolean 'Akkor lesz True, ha minden tétele be lett vételezve
    Private _DocumentFile As FileData 'A beszkennelt szállítólevél
    '-- Non persistent
    Private _row_OrderOutRows As OrderOutRows 'Kimenő megrendelési sorok
    Private _row_Products As Products 'Termék, ami a szállítólevelen van
    Private _row_QTT As Double 'Termék szállított mennyisége
    Private _row_ListPriceHUF As Double 'Termék listaára HUF
    Private _row_ListPriceDEV As Double 'Termék listaára DEV
    Private _row_DiscountPercent As Double 'Termék ár kedvezmény %-ban
    Private _row_NoteRows As String 'Sor megjegyzés
    Private _row_PacketNumber As String 'Kötegszám, Fémzárszám
    Private _row_Weight As Double
    Private _row_WeightMode As eWeightMode
    Private _row_CountryFrom As Country 'Származási ország !

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

        IsEditable = True
        IsStorno = False
        IsControlled = False
        IsStoraged = False
        CurrencyName = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName='HUF'"))
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If _DocumentNumber = "" Then
            _DocumentNumber = DeliveryNoteInType.NumberGenerator.GetNewNumber(DeliveryNoteInType.NumberGenerator)
        End If
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub

    <ImmediatePostData()>
    <RuleRequiredField("DeliveryNoteInHeader.DeliveryNoteInType", DefaultContexts.Save)>
    Property DeliveryNoteInType As DeliveryNoteInType
        Get
            Return _DeliveryNoteInType
        End Get
        Set(value As DeliveryNoteInType)
            SetPropertyValue("DeliveryNoteInType", _DeliveryNoteInType, value)
        End Set
    End Property
    <NonCloneable()>
    Property DocumentNumber() As String
        Get
            Return _DocumentNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    <NonCloneable()>
    <RuleRequiredField("DeliveryNoteInHeaderDocumentNumberIn-1", "aFinalize_DeliveryNoteIn_Contexts")>
    <RuleRequiredField("DeliveryNoteInHeaderDocumentNumberIn-2", "aFinalize_And_Storage_DeliveryNoteIn_Contexts")>
    Property DocumentNumberIn() As String
        Get
            Return _DocumentNumberIn
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumberIn", _DocumentNumberIn, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteInHeader.Customers", DefaultContexts.Save)>
    <ImmediatePostData(True)>
    Property Customers() As Customers
        Get
            Return _Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    <RuleRequiredField("DeliveryNoteInHeader.CustomersFrom", DefaultContexts.Save)>
    <ImmediatePostData(True)>
    Property CustomersFrom() As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(ByVal value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    Property DateCreated() As Date
        Get
            Return _DateCreated
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateCreated", _DateCreated, value)
        End Set
    End Property
    <ImmediatePostData()>
    Property DateExecution() As Date
        Get
            Return _DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                If Me.PaymentOption IsNot Nothing Then
                    Me.DatePayment = Nothing
                    If PaymentOption.DatePaymentMode = eDatePaymentMode.eDateCreated Then
                    Else
                        Me.DatePayment = value.AddDays(PaymentOption.PayDay)
                    End If
                End If
            End If
        End Set
    End Property
    <ImmediatePostData()>
    Property DatePayment() As Date
        Get
            Return _DatePayment
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DatePayment", _DatePayment, value)
        End Set
    End Property
    <ImmediatePostData()>
    Property PaymentOption As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                If Me.DateExecution <> Nothing And value IsNot Nothing Then
                    Me.DatePayment = Nothing
                    Me.DatePayment = DateExecution.AddDays(value.PayDay)
                End If
            End If
        End Set
    End Property
    Property ShipmentOption() As ShipmentOption
        Get
            Return _ShipmentOption
        End Get
        Set(ByVal value As ShipmentOption)
            SetPropertyValue("ShipmentOption", _ShipmentOption, 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
    <ImmediatePostData()>
    <RuleRequiredField("DeliveryNoteInHeader.CurrencyName", DefaultContexts.Save, TargetCriteria:="DeliveryNoteInType.IsPrice=True")>
    Property CurrencyName() As CurrencyName
        Get
            Return _CurrencyName
        End Get
        Set(ByVal value As CurrencyName)
            SetPropertyValue("CurrencyName", _CurrencyName, value)
        End Set
    End Property
    <RuleRange("DeliveryNoteInHeader.CurrencyRate", DefaultContexts.Save, 0.001, 999999999, TargetCriteria:="CurrencyName.ShortName<>'HUF' And IsNull(CurrencyName)=False And DeliveryNoteInType.IsPrice=True")>
    Property CurrencyRate As Double
        Get
            Return _CurrencyRate
        End Get
        Set(value As Double)
            SetPropertyValue("CurrencyRate", _CurrencyRate, value)
        End Set
    End Property
    <Size(-1)>
    Property Note() As String
        Get
            Return _Note
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Note", _Note, value)
        End Set
    End Property
    <NonCloneable()>
    Property IsEditable() As Boolean
        Get
            Return _IsEditable
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsEditable", _IsEditable, value)
        End Set
    End Property
    <NonCloneable()>
    Property IsStorno() As Boolean
        Get
            Return _IsStorno
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsStorno", _IsStorno, value)
        End Set
    End Property
    <NonCloneable()>
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    <NonCloneable()>
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    Property IsControlled As Boolean
        Get
            Return _IsControlled
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsControlled", _IsControlled, value)
        End Set
    End Property
    Property IsStoraged As Boolean
        Get
            Return _IsStoraged
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsStoraged", _IsStoraged, value)
        End Set
    End Property
    <Aggregated(), ExpandObjectMembers(ExpandObjectMembers.Never)>
    Property DocumentFile() As FileData
        Get
            Return _DocumentFile
        End Get
        Set(ByVal value As FileData)
            SetPropertyValue("DocumentFile", _DocumentFile, value)
        End Set
    End Property

    '-- NON persistent propertyk-------------------------------
    <VisibleInListView(False)>
    <ImmediatePostData(True), DataSourceProperty("OrderOutRows")>
    <NonPersistent>
    Property row_OrderOutRows As OrderOutRows
        Get
            Return _row_OrderOutRows
        End Get
        Set(value As OrderOutRows)
            SetPropertyValue("row_OrderOutRows", _row_OrderOutRows, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If value IsNot Nothing Then
                    Me.row_Products = value.Products
                    Me.row_QTT = value.QTT - value.QTT_DeliveryNoteIn
                    Me.row_ListPriceHUF = value.ListPriceHUF
                    Me.row_ListPriceDEV = value.ListPriceDEV
                    Me.row_DiscountPercent = value.DiscountPercent
                End If
            End If
        End Set
    End Property
    <NonPersistent()>
    <RuleRequiredField("DeliveryNoteInHeader.row_Products", "aToTableDeliveryNoteIn_Context")>
    <VisibleInListView(False)>
    <ImmediatePostData()>
    Property row_Products As Products
        Get
            Return _row_Products
        End Get
        Set(ByVal value As Products)
            SetPropertyValue("row_Products", _row_Products, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If row_Products IsNot Nothing Then
                    Me.row_ListPriceHUF = Me.row_Products.ListPriceInHUF
                    Me.row_ListPriceDEV = Me.row_Products.ListPriceInDEV
                End If
            End If
        End Set
    End Property
    <NonPersistent()>
    <RuleRange("DeliveryNoteInHeader.row_QTT", "aToTableDeliveryNoteIn_Context", 0.001, 999999999)>
    <VisibleInListView(False)>
    Property row_QTT As Double
        Get
            Return _row_QTT
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_QTT", _row_QTT, value)
        End Set
    End Property
    <NonPersistent()>
    <RuleRange("DeliveryNoteInHeader.row_ListPriceHUF", "aToTableDeliveryNoteIn_Context", 0.001, 999999999, TargetCriteria:="CurrencyName.ShortName='HUF' And DeliveryNoteInType.IsPrice=True")>
    <VisibleInListView(False)>
    Property row_ListPriceHUF As Double
        Get
            Return _row_ListPriceHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_ListPriceHUF", _row_ListPriceHUF, value)
        End Set
    End Property
    <NonPersistent()>
    <RuleRange("DeliveryNoteInHeader.row_ListPriceDEV", "aToTableDeliveryNoteIn_Context", 0.001, 999999999, TargetCriteria:="CurrencyName.ShortName<>'HUF' And IsNull(CurrencyName)=False And DeliveryNoteInType.IsPrice=True")>
    <VisibleInListView(False)>
    Property row_ListPriceDEV As Double
        Get
            Return _row_ListPriceDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_ListPriceDEV", _row_ListPriceDEV, value)
        End Set
    End Property
    <RuleRange("DeliveryNoteInHeader.row_DiscountPercent", "aToTableDeliveryNoteIn_Context", 0, 99)>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_DiscountPercent As Double
        Get
            Return _row_DiscountPercent
        End Get
        Set(ByVal value As Double)
            'If value < 0 Or value > 99 Then
            '    Throw New Exception("*A kedvemény mértékének 1 és 99 között kell lennie.")
            'End If
            SetPropertyValue("row_DiscountPercent", _row_DiscountPercent, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_NoteRows As String
        Get
            Return _row_NoteRows
        End Get
        Set(value As String)
            SetPropertyValue("row_NoteRows", _row_NoteRows, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_PacketNumber As String
        Get
            Return _row_PacketNumber
        End Get
        Set(value As String)
            SetPropertyValue("row_PacketNumber", _row_PacketNumber, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_Weight As Double
        Get
            Return _row_Weight
        End Get
        Set(value As Double)
            SetPropertyValue("row_Weight", _row_Weight, value)
        End Set
    End Property
    <NonPersistent>
    Property row_WeightMode As eWeightMode
        Get
            Return _row_WeightMode
        End Get
        Set(value As eWeightMode)
            SetPropertyValue("row_WeightMode", _row_WeightMode, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_CountryFrom As Country
        Get
            Return _row_CountryFrom
        End Get
        Set(value As Country)
            SetPropertyValue("row_CountryFrom", _row_CountryFrom, value)
        End Set
    End Property


    <VisibleInListView(False)>
    <Browsable(False)>
    Private ReadOnly Property OrderOutRows As XPCollection(Of OrderOutRows)
        Get
            'Dim _OrderOutRows As OrderOutRows
            Dim _OrderOutRows_Collection As XPCollection(Of OrderOutRows)
            Dim _Criteria As String


            _Criteria = "OrderOutHeader.IsEditable = False and OrderOutHeader.IsStorno = False and OrderOutHeader.CustomersFrom.Oid=? "
            _Criteria += " and OrderOutHeader.CustomersOrder.Oid=? and QTT_DeliveryNoteIn<QTT"

            _OrderOutRows_Collection = New XPCollection(Of OrderOutRows)(Session, CriteriaOperator.Parse(_Criteria, Me.CustomersFrom.Oid, Me.Customers.Oid))
            Return _OrderOutRows_Collection
        End Get
    End Property
    <Association("DeliveryNoteInHeader-DeliveryNoteInRows", GetType(DeliveryNoteInRows)), VisibleInListView(False)>
    ReadOnly Property DeliveryNoteInrows As XPCollection(Of DeliveryNoteInRows)
        Get
            Return GetCollection(Of DeliveryNoteInRows)("DeliveryNoteInrows")
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)>
    ReadOnly Property StorageOutRowsInRows As XPCollection(Of StorageOutRowsInRows)
        Get
            Return New XPCollection(Of StorageOutRowsInRows)(Session, CriteriaOperator.Parse("StorageInRows.DeliveryNoteInRows.DeliveryNoteInHeader=?", Me))
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)>
    ReadOnly Property StorageInRows As XPCollection(Of StorageInRows)
        Get
            Return New XPCollection(Of StorageInRows)(Session, CriteriaOperator.Parse("DeliveryNoteInRows.DeliveryNoteInHeader=?", Me))
        End Get
    End Property

    <VisibleInListView(False), VisibleInLookupListView(False)>
    ReadOnly Property DeliveryNoteInRRFC As XPCollection(Of DeliveryNoteInRRFC)
        Get
            Return New XPCollection(Of DeliveryNoteInRRFC)(Session, CriteriaOperator.Parse("DeliveryNoteInRows.DeliveryNoteInHeader=?", Me))
        End Get
    End Property

    <VisibleInDetailView(False)>
    <VisibleInListView(False)>
    <VisibleInLookupListView(False)>
    ReadOnly Property DisplayName As String
        Get
            Return Me.DocumentNumber & ", " & Me.DocumentNumberIn & ", " & Me.DateExecution
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)>
    ReadOnly Property OrderInTo As XPCollection(Of OrderInTo)
        Get
            Dim _OrderInTo_Collection As New XPCollection(Of OrderInTo)(Session, CriteriaOperator.Parse("1=2"))
            Dim _OrderInTo As OrderInTo
            Dim _DeliveryNoteInRows As DeliveryNoteInRows

            For Each _DeliveryNoteInRows In Me.DeliveryNoteInrows
                If _DeliveryNoteInRows.OrderOutRows IsNot Nothing Then
                    Dim _OrderInTo_Collection_1 As New XPCollection(Of OrderInTo)(Session, CriteriaOperator.Parse("OrderOutRows=?", _DeliveryNoteInRows.OrderOutRows))
                    For Each _OrderInTo In _OrderInTo_Collection_1
                        _OrderInTo_Collection.Add(_OrderInTo)
                    Next
                End If
            Next
            Return _OrderInTo_Collection
        End Get
    End Property
End Class


