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.Data.SqlClient
Imports DevExpress.ExpressApp.ConditionalAppearance
Imports System.Linq
Imports System.Linq.Expressions
Imports DevExpress.ExpressApp.Reports
Imports System.IO
Imports DevExpress.ExpressApp.ReportsV2
Imports DevExpress.XtraReports.UI
Imports DevExpress.Persistent.Base.ReportsV2

Public Enum eDatePaymentMode
    eDateCreated = 0
    eDateExecution = 1
End Enum
'<EditorStateRuleAttribute("Disable, all properties when IsEditable = False", "*", EditorState.Disabled, "IsEditable=False", ViewType.DetailView)> _
'<EditorStateRuleAttribute("Disable InvoiceType when is not empty", "InvoiceType", ViewType.DetailView, "IsNull(InvoiceType) = False", EditorState.Disabled)> _
'<EditorStateRuleAttribute("Disable Customers when is not empty in invoice", "Customers", ViewType.DetailView, "IsNull(Customers) = False", EditorState.Disabled)> _
'<Appearance("Hide tab page Item2 if header is incomplete-InvoiceHeader", AppearanceItemType.LayoutItem, "IsNull(InvoiceType)=True", TargetItems:="Item2", visibility:=Editors.ViewItemVisibility.Hide)> _
'<EditorStateRuleAttribute("Disable, som properties when is corrigendum", "CustomersFrom; InvoiceType; Customers; BankInformation; DateCreated; " _
'    & "PaymentOption; CurrencyName", EditorState.Disabled, "IsNull(InvoiceHeader)=False", ViewType.DetailView)> _
<NavigationItem("BusinessTransactions")>
<Appearance("Disable UserCreated InvoiceHeader", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)>
<Appearance("Disable, all properties when IsEditable = False", TargetItems:="*", Criteria:="IsEditable=False", Enabled:=False, Context:="DetailView")>
<Appearance("Hide BankInfo when PaymentOption.PayMode = 0", AppearanceItemType.ViewItem, "PaymentOption.PayMode = 0", TargetItems:="BankInformation", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("Disable InvoiceType when is not empty", TargetItems:="InvoiceType", Criteria:="IsNull(InvoiceType) = False", Enabled:=False, Context:="DetailView")>
<Appearance("Disable Customers when is not empty in invoice", TargetItems:="Customers", Criteria:="IsNull(Customers) = False", Enabled:=False, Context:="DetailView")>
<Appearance("InvoiceHeader.TotalNettoDEV Hide", AppearanceItemType.ViewItem, "CurrencyName.ShortName = 'HUF'", TargetItems:="row_ListPriceDEV", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("InvoiceHeader.TotalNettoHUF Hide", AppearanceItemType.ViewItem, "CurrencyName.ShortName != 'HUF'", TargetItems:="row_ListPriceHUF", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("Hide row_ info when IsEditable=False", AppearanceItemType.ViewItem, "IsEditable=False", TargetItems:="row_ShortName; row_Description; row_ListPriceHUF; row_ListPriceDEV; row_DiscountPercent;" _
    & "row_QTT; row_Units; row_VAT; row_QualityOption; row_Controlling; row_UniqueObjects; row_CostHolder; row_CostPlace; row_JobNumberObjects; row_CustomsTariffs; row_InvoicePeriod", Visibility:=Editors.ViewItemVisibility.Hide)>
<Appearance("Hide CurrencyRate", AppearanceItemType.ViewItem, "CurrencyName.ShortName = 'HUF'", TargetItems:="CurrencyRate", Visibility:=Editors.ViewItemVisibility.Hide)>
<DefaultProperty("DisplayName")>
<RuleCriteria("RuleCriteria InvoiceHeader-Controlling", "aToTable_Invoice_Contexts",
    "((row_Controlling.IsParent=False) or (InvoiceType.Rule5DMatrix.RequireControlling=False and isnull(row_Controlling)=True)) or IsCorrigendum=True",
    "Gyüjtő kontrollszám nem választható ki!", SkipNullOrEmptyValues:=False)>
<RuleCriteria("RuleCriteria InvoiceHeader-DateExecution", "Save",
    "IsVATClosed=False",
    "ÁFA időszak zárva, nem lehet rögzíteni !", SkipNullOrEmptyValues:=False)>
<Appearance("InvoiceHeader - Hide aCreateInvoiceCreditNote", AppearanceItemType.Action, "IsEditable=True OR IsStorno=True OR DocumentNumber=''", TargetItems:="aCreateInvoiceCreditNote", Visibility:=Editors.ViewItemVisibility.Hide)>
Public Class InvoiceHeader
    Inherits BaseObject
    Private _InvoiceType As InvoiceType
    Private _DocumentNumber As String 'Számla száma
    Private _DocumentNumberProforma As String 'Számla száma proforma !
    Private _ConnectInfo As String 'A kapcsolt számla száma (stornó esetén a stornózott számla száma)
    Private _CustomersFrom As CustomersFrom 'Saját cég
    Private _Customers As Customers 'Ügyfél
    Private _DateCreated As Date 'Kiállítás dátuma
    Private _DateExecution As Date 'Teljesítés dátuma
    Private _VATAvowalType As eVATAvowalType 'ÁFA bevallás módja
    '// PIVOT miatt --------------------------------------------------------------
    Private _DateExecutionYear As String
    Private _DateExecutionMonth As String
    Private _DateExecutionQuarter As String
    Private _DateExecutionWeek As String
    '----------------------------------------------------------------------------
    Private _DatePayment As Date 'Fizetési határidő
    Private _DatePaymentMode As eDatePaymentMode
    Private _InvoicePeriod As String 'Számlázási időszak string
    Private _Description As String 'Számlán szereplő megjegyzés
    Private _DescriptionHeader As String 'Számlán szereplő  fejléc megjegyzés
    Private _PaymentOption As PaymentOption 'Fizetési opció (ebből automatikusan DatePayment és Date Execution)
    Private _ShipmentOption As ShipmentOption 'Szállítási kondíció
    Private _QualityOption As QualityOption ' Minőségbiztosítási kondíció
    Private _CurrencyName As CurrencyName 'Deviza
    Private _CurrencyRate As Double = 0 'Árfolyam, ha a deviza nem HUF egyébként 1
    Private _IsEditable As Boolean = True 'Szerkeszthető, végleges
    Private _IsStorno As Boolean = False 'Stornó
    Private _IsProforma As Boolean = False 'Próbaszámla állapot
    Private _IsCorrigendum As Boolean = False 'Helyesbítő számla
    Private _IsCreditNote As Boolean = False 'Jóváíró számla
    Private _HUNumberToText As String = "" 'Ez tárolja az azaz kettőezer-kettőszáthuszonkilenc szöveget
    Private _TotalNettoHUF As Double = 0
    Private _TotalVATHUF As Double = 0
    Private _TotalBruttoHUF As Double = 0
    Private _BankInformation As BankInformation ' A fejlécben megjelenő számlaszám
    Private _TotalNettoDEV As Double = 0
    Private _TotalVATDEV As Double = 0
    Private _TotalBruttoDEV As Double = 0

    Private _TotalAdvancedBruttoHUF As Double = 0 'Ha előlegszámla, akkor eddig mennyi előleg lett visszaadva. (HUF)
    Private _TotalAdvancedBruttoDEV As Double = 0 'Ha előlegszámla, akkor eddig mennyi előleg lett visszaadva. (DEV)
    Private _TotalAdvancedWill As Double = 0 'Mennyit akar betudni a fennáló be nem tudott előlegekből ?

    Private _PCIGroup As PCIGroup
    Private _IsImported As Boolean = False 'Főkönyvbe be lett e már rögzítve
    Private _GLAccounts As GLAccounts 'Főkönyvbe rögzített feladott számla
    Private _BookEntryErrorString As String = "" 'Főkönyvi feladás során hiba
    Private _ReadyforBookEntry As Boolean = False
    Private _InvoiceHeader As InvoiceHeader 'Helyesbített számla esetén az eredeti számla, amit helyesbít
    Private _LateChargesCountMode As LateChargesCountMode 'A késedelmi kamat számításának módszere

    Private _IsAssetsHandling As Boolean = True 'Lesz e kinnlévőség kezelése
    Private _AssetsHandling_Note As String 'Kinnlévőség megjegyzés
    Private _AssetsHandlingStatus As AssetsHandlingStatus
    Private _AssetsHandling_GLMixed As GLMixed 'Ha van késedelmi kamatértesítő, akkor ebbe kerül be
    Private _IsLateCharge As Boolean = True 'Kell-e erre a számlára vonatkozólag késedelmi kamat ?

    Private _UserCreated As User
    Private _NotNeedFinancial As Boolean = False 'Pénzügyi rendezést nem igényel
    Private _LateChargesBalanceHUF As Double 'Késedelmi kamat összege forintban

    '-- a számla kiállításakor el kell menteni bizonyos adatokat

    Private _Saved_Customers_Name As String
    Private _Saved_Customers_Address_Country As String
    Private _Saved_Customers_Address_ZipPostal As String
    Private _Saved_Customers_Address_Street As String
    Private _Saved_Customers_Address_City As String
    Private _Saved_Customers_Address_StateProvince As String
    Private _Saved_Customers_VATNumber As String
    Private _Saved_Customers_VATNumberEU As String

    Private _Saved_CustomersFrom_Name As String
    Private _Saved_CustomersFrom_Address_Country As String
    Private _Saved_CustomersFrom_Address_ZipPostal As String
    Private _Saved_CustomersFrom_Address_Street As String
    Private _Saved_CustomersFrom_Address_City As String
    Private _Saved_CustomersFrom_Address_StateProvince As String
    Private _Saved_CustomersFrom_VATNumber As String
    Private _Saved_CustomersFrom_VATNumberEU As String

    Private _Saved_CustomersFrom_Bank_ShortName As String
    Private _Saved_CustomersFrom_Bank_IBAN As String
    Private _Saved_CustomersFrom_Bank_SWIFT As String
    Private _Saved_CustomersFrom_Bank_AccountNumber As String



    '-- PDF !!!
    Private _PDF_Original As FileData '
    Private _PDF_Copy As FileData
    Private _PrintCopy As Long = 0


    '-- Faktor információk !!!
    Private _IsFactoring As Boolean = False 'Faktorálás van-e ?
    Private _Factoring_PDF_Signed As FileData 'Az ügyfél által aláírt szkennelt számla !
    Private _Factoring_Send As Boolean = False 'El lett-e küldve a bank felé
    Private _Factoring_Send_Date As Date 'Mikor lett elküldve
    Private _Factoring_Send_Number As String 'Milyen sorszámon, ez a beküldési reporthoz kell.
    Private _InvoiceFactoringRows As InvoiceFactoringRows 'Milyen engedményezési szerződésen igazolták vissza
    Private _InvoiceFactoringParameter As InvoiceFactoringParameter ' Faktorálási paraméter !!!
    Private _InvoiceFactoringBank As InvoiceFactoringBank 'Bankba küldési csomag !

    '-- Nonpersistent objektumok a számla sor rögzítéséhez
    Private _row_CustomsTariffs As CustomsTariffs 'ITJ, SZJ, Vámtarifaszám stb.
    Private _row_ShortName As String 'Megnevezés
    Private _row_Description As String 'Leírás
    Private _row_ListPriceHUF As Double = 0 ' Egységár HUF (nettó !)
    Private _row_ListPriceDEV As Double = 0 ' Egységár DEV (Nettó !)
    Private _row_DiscountPercent As Double 'Kedvezmény mértéke %-ban
    Private _row_QTT As Double = 0 'Mennyiség
    Private _row_Units As Units ' Mennyiségi egység
    Private _row_VAT As VAT 'ÁFA
    Private _row_QualityOption As QualityOption 'Minőségi kondíció
    Private _row_Controlling As Controlling '-- Controlling szám
    Private _row_UniqueObjects As UniqueObjects ' -- Egyedi azonosító
    Private _row_CostHolder As CostHolder ' -- Költség viselő
    Private _row_CostPlace As CostPlace ' -- Költség viselő
    Private _row_JobNumberObjects As JobNumberObjects ' -- Project
    Private _row_InvoicePeriod As String 'Számlázási időszak 
    Private _row_Products As Products 'Termék a terméktörzsből
    Private _row_Services As Services 'Szolgáltatás a szolgáltatástörzsből

    '-- Előleg lekezelése miatt

    Structure sVAT
        Dim VAT As VAT
        Dim AmountNettoHUF As Double
        Dim AmountVATHUF As Double
        Dim AmountBruttoHUF As Double
        Dim AmountNettoDEV As Double
        Dim AmountVATDEV As Double
        Dim AmountBruttoDEV As Double
    End Structure
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.DateCreated = GetSQLTime(Session)
        Me.DateExecution = GetSQLTime(Session)
        Me.CurrencyName = Session.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName = 'HUF'"))
        Me.row_VAT = Session.FindObject(Of VAT)(CriteriaOperator.Parse("DefaultForBusinnes='True'"))
        Me.row_Units = Session.FindObject(Of Units)(CriteriaOperator.Parse("DefaultForBusinnes='True'"))
        Me.row_QTT = 1
        Me.IsAssetsHandling = True
        Me.VATAvowalType = eVATAvowalType.eGeneral
        Me.TotalAdvancedWill = Me.TotalBruttoHUF - Me.TotalAdvancedBruttoHUF
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()

        '// Az árfolyammal újra kell számolni a sorokat ! (DEV -> HUF !!)
        If Me.CurrencyName.ShortName <> "HUF" Then

        End If
        If UserCreated Is Nothing Then
            Me.UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If

        If String.IsNullOrEmpty(DateExecutionYear) Then DateExecutionYear = DateExecution.Year.ToString
        If String.IsNullOrEmpty(DateExecutionMonth) Then DateExecutionMonth = DateExecution.Month.ToString
        If String.IsNullOrEmpty(DateExecutionQuarter) Then DateExecutionQuarter = DatePart(DateInterval.Quarter, DateExecution).ToString
        If String.IsNullOrEmpty(DateExecutionWeek) Then DateExecutionWeek = DatePart(DateInterval.WeekOfYear, DateExecution).ToString

    End Sub

    ' --- XPCollections
    <VisibleInListView(False)>
    <Association("InvoiceHeader", GetType(InvoiceRows))>
    Public ReadOnly Property InvoiceRows() As XPCollection(Of InvoiceRows)
        Get
            Return GetCollection(Of InvoiceRows)("InvoiceRows")
        End Get
    End Property
    <VisibleInListView(False)>
    <Association("InvoiceHeader-InvoiceVATRows", GetType(InvoiceVATRows))>
    Public ReadOnly Property InvoiceVATRows() As XPCollection(Of InvoiceVATRows)
        Get
            Return GetCollection(Of InvoiceVATRows)("InvoiceVATRows")
        End Get
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)>
    ReadOnly Property InvoiceHold As XPCollection(Of InvoiceHold)
        Get
            Return New XPCollection(Of InvoiceHold)(Session, CriteriaOperator.Parse("InvoiceHeader=?", Me))
        End Get
    End Property

    <ImmediatePostData(True), DataSourceCriteria("CustomersFrom='@This.CustomersFrom' and InvoiceTypeBase in (2,3)")>
    <RuleRequiredField("InvoiceHeader-InvoiceType", DefaultContexts.Save)>
    Property InvoiceType() As InvoiceType
        Get
            Return _InvoiceType
        End Get
        Set(ByVal value As InvoiceType)
            SetPropertyValue("InvoiceType", _InvoiceType, value)
            If Session.IsObjectsSaving = False And Session.IsObjectsLoading = False Then
                If row_Controlling Is Nothing Then
                    row_Controlling = value.ControllingDefault
                End If
            End If
        End Set
    End Property
    Property InvoicePeriod As String
        Get
            Return _InvoicePeriod
        End Get
        Set(value As String)
            SetPropertyValue("InvoicePeriod", _InvoicePeriod, 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()>
    Property DocumentNumberProforma As String
        Get
            Return _DocumentNumberProforma
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DocumentNumberProforma", _DocumentNumberProforma, value)
        End Set
    End Property
    <NonCloneable()>
    Property ConnectInfo() As String
        Get
            Return _ConnectInfo
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ConnectInfo", _ConnectInfo, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceHeader.CustomersFrom", "aInvoiceFromContractsRows_Context")>
    Property CustomersFrom() As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(ByVal value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceHeader.Customers", "aInvoiceFromContractsRows_Context")>
    Property Customers() As Customers
        Get
            Return _Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("Customers", _Customers, value)
            If Not Session.IsObjectsSaving And Not Session.IsObjectsLoading Then
                If value IsNot Nothing Then
                    If value.PaymentOption IsNot Nothing And Me.PaymentOption Is Nothing Then
                        Me.PaymentOption = value.PaymentOption
                    End If
                    If value.ShipmentOption IsNot Nothing And Me.ShipmentOption Is Nothing Then
                        Me.ShipmentOption = value.ShipmentOption
                    End If
                    If value.QualityOption IsNot Nothing And Me.QualityOption Is Nothing Then
                        Me.QualityOption = value.QualityOption
                    End If
                End If
            End If
        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()>
    <RuleRequiredField("InvoiceHeader.DateExecution", "aInvoiceFromContractsRows_Context")>
    Property DateExecution() As Date
        Get
            Return _DateExecution
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateExecution", _DateExecution, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False And Me.PaymentOption IsNot Nothing Then
                Select Case Me.DatePaymentMode
                    Case eDatePaymentMode.eDateCreated
                    Case eDatePaymentMode.eDateExecution
                        Me.DatePayment = Me.DateExecution.AddDays(Me.PaymentOption.PayDay)
                End Select

            End If
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False And Me.DateExecution = Nothing Then
                Me.DatePayment = Nothing
            End If
        End Set
    End Property
    Property VATAvowalType As eVATAvowalType
        Get
            Return _VATAvowalType
        End Get
        Set(value As eVATAvowalType)
            SetPropertyValue("VATAvowalType", _VATAvowalType, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)>
    Property DateExecutionYear As String
        Get
            Return _DateExecutionYear
        End Get
        Set(value As String)
            SetPropertyValue("DateExecutionYear", _DateExecutionYear, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)>
    Property DateExecutionMonth As String
        Get
            Return _DateExecutionMonth
        End Get
        Set(value As String)
            SetPropertyValue("DateExecutionMonth", _DateExecutionMonth, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)>
    Property DateExecutionQuarter As String
        Get
            Return _DateExecutionQuarter
        End Get
        Set(value As String)
            SetPropertyValue("DateExecutionQuarter", _DateExecutionQuarter, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)>
    Property DateExecutionWeek As String
        Get
            Return _DateExecutionWeek
        End Get
        Set(value As String)
            SetPropertyValue("DateExecutionWeek", _DateExecutionWeek, value)
        End Set
    End Property
    Property DatePayment() As Date
        Get
            Return _DatePayment
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DatePayment", _DatePayment, value)
        End Set
    End Property
    Property DatePaymentMode As eDatePaymentMode
        Get
            Return _DatePaymentMode
        End Get
        Set(value As eDatePaymentMode)
            SetPropertyValue("DatePaymentMode", _DatePaymentMode, 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 DescriptionHeader As String
        Get
            Return _DescriptionHeader
        End Get
        Set(ByVal value As String)
            SetPropertyValue("DescriptionHeader", _DescriptionHeader, value)
        End Set
    End Property
    <ImmediatePostData()>
    <RuleRequiredField("InvoiceHeader-PaymentOption", "aGenerateInvoicefromContractsRows_Context")>
    <RuleRequiredField("InvoiceHeader-PaymentOption2", DefaultContexts.Save)>
    Property PaymentOption() As PaymentOption
        Get
            Return _PaymentOption
        End Get
        Set(ByVal value As PaymentOption)
            SetPropertyValue("PaymentOption", _PaymentOption, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False And IsStorno = False Then
                If Me.DateExecution > #1/1/1900# And Me.PaymentOption IsNot Nothing Then
                    Select Case Me.DatePaymentMode
                        Case eDatePaymentMode.eDateExecution
                            Me.DatePayment = Me.DateExecution.AddDays(Me.PaymentOption.PayDay)
                        Case eDatePaymentMode.eDateCreated
                            Me.DatePayment = Me.DateCreated.AddDays(Me.PaymentOption.PayDay)
                    End Select

                End If
                If value.PayMode = ePayMode.InCash Then
                    Me.DateExecution = GetSQLTime(Session)
                    Me.DatePayment = GetSQLTime(Session)
                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
    <RuleRequiredField("InvoiceHeader.CurrencyName required", DefaultContexts.Save)>
    <ImmediatePostData(True)>
    Property CurrencyName() As CurrencyName
        Get
            Return _CurrencyName
        End Get
        Set(ByVal value As CurrencyName)
            SetPropertyValue("CurrencyName", _CurrencyName, value)
        End Set
    End Property
    <RuleRange("InvoiceHeader-CurrencyRate-aToTable", "aToTable_Invoice_Contexts", 1, Double.MaxValue, TargetCriteria:="CurrencyName.ShortName<>'HUF'")>
    <RuleRange("InvoiceHeader-CurrencyRate", DefaultContexts.Save, 1, Double.MaxValue, TargetCriteria:="CurrencyName.ShortName <> 'HUF'")>
    Property CurrencyRate() As Double
        Get
            Return _CurrencyRate
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("CurrencyRate", _CurrencyRate, 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 IsProforma As Boolean
        Get
            Return _IsProforma
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsProforma", _IsProforma, value)
        End Set
    End Property
    <VisibleInDetailView(False)>
    Property IsCorrigendum As Boolean
        Get
            Return _IsCorrigendum
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsCorrigendum", _IsCorrigendum, value)
        End Set
    End Property
    <VisibleInDetailView(False)>
    Property IsCreditNote As Boolean
        Get
            Return _IsCreditNote
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsCreditNote", _IsCreditNote, value)
        End Set
    End Property
    <ImmediatePostData(True), DataSourceCriteria("LiquidAssests.CustomerFrom = '@This.CustomersFrom'")>
    <RuleRequiredField("InvoiceHeader-BankInformation", DefaultContexts.Save, TargetCriteria:="PaymentOption.PayMode = 1 and not (InvoiceType.InvoiceTypeBase in ('eEarnestofTender','eAdvancePayment'))")>
    Property BankInformation As BankInformation
        Get
            Return _BankInformation
        End Get
        Set(ByVal value As BankInformation)
            SetPropertyValue("CustomerBankAccounts", _BankInformation, value)
        End Set
    End Property
    <NonCloneable()>
    Property InvoiceHeader As InvoiceHeader
        Get
            Return _InvoiceHeader
        End Get
        Set(ByVal value As InvoiceHeader)
            SetPropertyValue("InvoiceHeader", _InvoiceHeader, value)
        End Set
    End Property
    Property LateChargesCountMode As LateChargesCountMode
        Get
            Return _LateChargesCountMode
        End Get
        Set(value As LateChargesCountMode)
            SetPropertyValue("LateChargesCountMode", _LateChargesCountMode, value)
        End Set
    End Property
    <VisibleInDetailView(False), VisibleInLookupListView(False)>
    Property IsAssetsHandling As Boolean
        Get
            Return _IsAssetsHandling
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsAssetsHandling", _IsAssetsHandling, value)
        End Set
    End Property
    <Size(-1), VisibleInDetailView(False), VisibleInListView(False), VisibleInLookupListView(False)>
    Property AssetsHandling_Note As String
        Get
            Return _AssetsHandling_Note
        End Get
        Set(value As String)
            SetPropertyValue("AssetsHandling_Note", _AssetsHandling_Note, value)
        End Set
    End Property
    Property AssetsHandlingStatus As AssetsHandlingStatus
        Get
            Return _AssetsHandlingStatus
        End Get
        Set(value As AssetsHandlingStatus)
            SetPropertyValue("AssetsHandlingStatus", _AssetsHandlingStatus, value)
        End Set
    End Property
    <VisibleInDetailView(False)>
    Property AssetsHandling_GLMixed As GLMixed
        Get
            Return _AssetsHandling_GLMixed
        End Get
        Set(value As GLMixed)
            SetPropertyValue("AssetsHandling_GLMixed", _AssetsHandling_GLMixed, value)
        End Set
    End Property
    <VisibleInDetailView(False)>
    Property IsLateCharge As Boolean
        Get
            Return _IsLateCharge
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsLateCharge", _IsLateCharge, 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 NotNeedFinancial As Boolean
        Get
            Return _NotNeedFinancial
        End Get
        Set(value As Boolean)
            SetPropertyValue("NotNeedFinancial", _NotNeedFinancial, value)
        End Set
    End Property

    Property LateChargesBalanceHUF As Double
        Get
            Return _LateChargesBalanceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("LateChargesBalanceHUF", _LateChargesBalanceHUF, value)
        End Set
    End Property

    '-- a számla kiállításakor el kell menteni bizonyos adatokat
    <NonCloneable()>
    Property Saved_Customers_Name As String
        Get
            Return _Saved_Customers_Name
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_Name", _Saved_Customers_Name, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_Address_Country As String
        Get
            Return _Saved_Customers_Address_Country
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_Address_Country", _Saved_Customers_Address_Country, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_Address_ZipPostal As String
        Get
            Return _Saved_Customers_Address_ZipPostal
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_Address_ZipPostal", _Saved_Customers_Address_ZipPostal, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_Address_Street As String
        Get
            Return _Saved_Customers_Address_Street
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_Address_Street", _Saved_Customers_Address_Street, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_Address_City As String
        Get
            Return _Saved_Customers_Address_City
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_Address_City", _Saved_Customers_Address_City, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_Address_StateProvince As String
        Get
            Return _Saved_Customers_Address_StateProvince
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_Address_StateProvince", _Saved_Customers_Address_StateProvince, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_VATNumber As String
        Get
            Return _Saved_Customers_VATNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_VATNumber", _Saved_Customers_VATNumber, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_Customers_VATNumberEU As String
        Get
            Return _Saved_Customers_VATNumberEU
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_Customers_VATNumberEU ", _Saved_Customers_VATNumberEU, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Name As String
        Get
            Return _Saved_CustomersFrom_Name
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Name", _Saved_CustomersFrom_Name, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Address_Country As String
        Get
            Return _Saved_CustomersFrom_Address_Country
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Address_Country", _Saved_CustomersFrom_Address_Country, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Address_ZipPostal As String
        Get
            Return _Saved_CustomersFrom_Address_ZipPostal
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Address_ZipPostal", _Saved_CustomersFrom_Address_ZipPostal, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Address_Street As String
        Get
            Return _Saved_CustomersFrom_Address_Street
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Address_Street", _Saved_CustomersFrom_Address_Street, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Address_City As String
        Get
            Return _Saved_CustomersFrom_Address_City
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Address_City", _Saved_CustomersFrom_Address_City, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Address_StateProvince As String
        Get
            Return _Saved_CustomersFrom_Address_StateProvince
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Address_StateProvince", _Saved_CustomersFrom_Address_StateProvince, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_VATNumber As String
        Get
            Return _Saved_CustomersFrom_VATNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_VATNumber", _Saved_CustomersFrom_VATNumber, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_VATNumberEU As String
        Get
            Return _Saved_CustomersFrom_VATNumberEU
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_VATNumberEU", _Saved_CustomersFrom_VATNumberEU, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Bank_ShortName As String
        Get
            Return _Saved_CustomersFrom_Bank_ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Bank_ShortName", _Saved_CustomersFrom_Bank_ShortName, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Bank_IBAN As String
        Get
            Return _Saved_CustomersFrom_Bank_IBAN
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Bank_IBAN", _Saved_CustomersFrom_Bank_IBAN, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Bank_SWIFT As String
        Get
            Return _Saved_CustomersFrom_Bank_SWIFT
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Bank_SWIFT", _Saved_CustomersFrom_Bank_SWIFT, value)
        End Set
    End Property
    <NonCloneable()>
    Property Saved_CustomersFrom_Bank_AccountNumber As String
        Get
            Return _Saved_CustomersFrom_Bank_AccountNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("Saved_CustomersFrom_Bank_AccountNumber", _Saved_CustomersFrom_Bank_AccountNumber, value)
        End Set
    End Property

    ReadOnly Property Saved_Customers_FullAddress As String
        Get
            Return Saved_Customers_Address_ZipPostal & " " & Saved_Customers_Address_City & " " & vbCrLf &
            Saved_Customers_Address_Street & vbCrLf & Saved_Customers_Address_Country
        End Get
    End Property
    ReadOnly Property Saved_CustomersFrom_FullAddress As String
        Get
            Return Saved_CustomersFrom_Address_ZipPostal & " " & Saved_CustomersFrom_Address_City & " " & vbCrLf &
            Saved_CustomersFrom_Address_Street & vbCrLf & Saved_CustomersFrom_Address_Country
        End Get
    End Property

    <NonCloneable()>
    Property TotalBruttoHUF As Double
        Get
            Return _TotalBruttoHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("TotalBruttoHUF", _TotalBruttoHUF, value)
        End Set
    End Property
    Property TotalNettoHUF As Double
        Get
            Return _TotalNettoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("TotalNettoHUF", _TotalNettoHUF, value)
        End Set
    End Property
    Property TotalVATHUF As Double
        Get
            Return _TotalVATHUF
        End Get
        Set(value As Double)
            SetPropertyValue("TotalVATHUF", _TotalVATHUF, value)
        End Set
    End Property

    <NonCloneable()>
    Property TotalBruttoDEV As Double
        Get
            Return _TotalBruttoDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("TotalBruttoDEV", _TotalBruttoDEV, value)
        End Set
    End Property
    Property TotalNettoDEV As Double
        Get
            Return _TotalNettoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("TotalNettoDEV", _TotalNettoDEV, value)
        End Set
    End Property
    Property TotalVATDEV As Double
        Get
            Return _TotalVATDEV
        End Get
        Set(value As Double)
            SetPropertyValue("TotalVATDEV", _TotalVATDEV, value)
        End Set
    End Property

    Property PCIGroup As PCIGroup
        Get
            Return _PCIGroup
        End Get
        Set(value As PCIGroup)
            SetPropertyValue("PCIGroup", _PCIGroup, value)
        End Set
    End Property


    Property TotalAdvancedBruttoHUF As Double
        Get
            Return _TotalAdvancedBruttoHUF
        End Get
        Set(value As Double)
            SetPropertyValue("TotalAdvancedBruttoHUF", _TotalAdvancedBruttoHUF, value)
        End Set
    End Property

    Property TotalAdvancedBruttoDEV As Double
        Get
            Return _TotalAdvancedBruttoDEV
        End Get
        Set(value As Double)
            SetPropertyValue("TotalAdvancedBruttoDEV", _TotalAdvancedBruttoDEV, value)
        End Set
    End Property
    <NonPersistent>
    Property TotalAdvancedWill As Double
        Get
            Return _TotalAdvancedWill
        End Get
        Set(value As Double)
            SetPropertyValue("TotalAdvancedWill", _TotalAdvancedWill, value)
        End Set
    End Property

    <Size(255)>
    <NonCloneable()>
    Property HUNumberToText As String
        Get
            Return _HUNumberToText
        End Get
        Set(ByVal value As String)
            SetPropertyValue("HUNumberToText", _HUNumberToText, value)
        End Set
    End Property
    <NonCloneable()>
    Property IsImported As Boolean
        Get
            Return _IsImported
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsImported", _IsImported, value)
        End Set
    End Property
    <NonCloneable()>
    Property GLAccounts As GLAccounts
        Get
            Return _GLAccounts
        End Get
        Set(ByVal value As GLAccounts)
            SetPropertyValue("GLAccounts", _GLAccounts, value)
        End Set
    End Property
    <Size(255)>
    <NonCloneable()>
    Property BookEntryErrorString As String
        Get
            Return _BookEntryErrorString
        End Get
        Set(ByVal value As String)
            SetPropertyValue("BookEntryErrorString", _BookEntryErrorString, value)
        End Set
    End Property
    <NonCloneable()>
    Property ReadyforBookEntry As Boolean
        Get
            Return _ReadyforBookEntry
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("ReadyforBookEntry", _ReadyforBookEntry, value)
        End Set
    End Property

    Property PDF_Original As FileData
        Get
            Return _PDF_Original
        End Get
        Set(value As FileData)
            SetPropertyValue("PDF_Original", _PDF_Original, value)
        End Set
    End Property
    Property PDF_Copy As FileData
        Get
            Return _PDF_Copy
        End Get
        Set(value As FileData)
            SetPropertyValue("PDF_Copy", _PDF_Copy, value)
        End Set
    End Property
    Property PrintCopy As Long
        Get
            Return _PrintCopy
        End Get
        Set(value As Long)
            SetPropertyValue("PrintCopy", _PrintCopy, value)
        End Set
    End Property

    ReadOnly Property IsBookEntry As Boolean
        Get
            If _GLAccounts IsNot Nothing Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property
    <VisibleInDetailView(False)>
    ReadOnly Property DisplayName() As String
        Get
            If Me.CurrencyName IsNot Nothing Then
                Return Me.DocumentNumber & "," & Me.CurrencyName.ShortName
            Else
                Return Me.DocumentNumber
            End If
        End Get
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)>
    ReadOnly Property Contact_string() As String
        Get
            Dim _Contact As String = ""
            If OrderInHeader_Collection.Count > 0 Then
                _Contact = OrderInHeader_Collection(0).Contacts.DisplayNamePostal.ToString
            End If
            Return _Contact
        End Get
    End Property
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)>
    ReadOnly Property CustomersRefNumber_string() As String
        Get
            Dim _CustomersRefNumber As String = ""
            If OrderInHeader_Collection.Count > 0 Then
                If OrderInHeader_Collection(0).CustomersRefNumber <> Nothing Then
                    _CustomersRefNumber = OrderInHeader_Collection(0).CustomersRefNumber.ToString
                End If
            End If
            Return _CustomersRefNumber
        End Get
    End Property

    'Faktorálás miatt
    Property IsFactoring As Boolean
        Get
            Return _IsFactoring
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsFactoring", _IsFactoring, value)
        End Set
    End Property
    Property Factoring_PDF_Signed As FileData
        Get
            Return _Factoring_PDF_Signed
        End Get
        Set(value As FileData)
            SetPropertyValue("Factoring_PDF_Signed", _Factoring_PDF_Signed, value)
        End Set
    End Property
    Property Factoring_Send As Boolean
        Get
            Return _Factoring_Send
        End Get
        Set(value As Boolean)
            SetPropertyValue("Factoring_Send", _Factoring_Send, value)
        End Set
    End Property
    Property Factoring_Send_Date As Date
        Get
            Return _Factoring_Send_Date
        End Get
        Set(value As Date)
            SetPropertyValue("Factoring_Send_Date", _Factoring_Send_Date, value)
        End Set
    End Property
    Property Factoring_Send_Number As String
        Get
            Return _Factoring_Send_Number
        End Get
        Set(value As String)
            SetPropertyValue("Factoring_Send_Number", _Factoring_Send_Number, value)
        End Set
    End Property
    Property InvoiceFactoringRows As InvoiceFactoringRows
        Get
            Return _InvoiceFactoringRows
        End Get
        Set(value As InvoiceFactoringRows)
            SetPropertyValue("InvoiceFactoringRows", _InvoiceFactoringRows, value)
        End Set
    End Property
    Property InvoiceFactoringParameter As InvoiceFactoringParameter
        Get
            Return _InvoiceFactoringParameter
        End Get
        Set(value As InvoiceFactoringParameter)
            SetPropertyValue("InvoiceFactoringParameter", _InvoiceFactoringParameter, value)
        End Set
    End Property
    Property InvoiceFactoringBank As InvoiceFactoringBank
        Get
            Return _InvoiceFactoringBank
        End Get
        Set(value As InvoiceFactoringBank)
            SetPropertyValue("InvoiceFactoringBank", _InvoiceFactoringBank, value)
        End Set
    End Property
    '-- Nonpersistent property-k a számla sor rögzítéséhez
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_CustomsTariffs As CustomsTariffs
        Get
            Return _row_CustomsTariffs
        End Get
        Set(value As CustomsTariffs)
            SetPropertyValue("row_CustomsTariffs", _row_CustomsTariffs, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceHeader-row_ShortName", "aToTable_Invoice_Contexts", TargetCriteria:="IsCorrigendum=False")>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_ShortName() As String 'Megnevezés
        Get
            Return _row_ShortName
        End Get
        Set(ByVal value As String)
            SetPropertyValue("row_ShortName", _row_ShortName, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    <Size(4000)>
    Property row_Description() As String 'Leírás
        Get
            Return _row_Description
        End Get
        Set(ByVal value As String)
            SetPropertyValue("row_Description", _row_Description, value)
        End Set
    End Property
    <RuleRange("InvoiceHeader-row_ListPriceHUF", "aToTable_Invoice_Contexts", 0.00001, Double.MaxValue, TargetCriteria:="CurrencyName.ShortName='HUF'")>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_ListPriceHUF() As Double ' Egységár HUF (nettó !)
        Get
            Return _row_ListPriceHUF
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_ListPriceHUF", _row_ListPriceHUF, value)
        End Set
    End Property
    <RuleRange("InvoiceHeader-row_ListPriceDEV", "aToTable_Invoice_Contexts", 0.00001, Double.MaxValue, TargetCriteria:="CurrencyName.ShortName!='HUF' and IsCorrigendum=False")>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_ListPriceDEV() As Double ' Egységár DEV (Nettó !)
        Get
            Return _row_ListPriceDEV
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_ListPriceDEV", _row_ListPriceDEV, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                row_ListPriceHUF = Math.Round(Me.CurrencyRate, 2, MidpointRounding.AwayFromZero) * value
            End If
        End Set
    End Property
    <RuleRange("InvoiceHeader-row_DiscountPercent", "aToTable_Invoice_Contexts", 0, 99, TargetCriteria:="IsCorrigendum=False")>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_DiscountPercent() As Double 'Kedvezmény mértéke %-ban
        Get
            Return _row_DiscountPercent
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_DiscountPercent", _row_DiscountPercent, value)
        End Set
    End Property
    '<RuleValueComparison("RuleValue-PayMode-RegistryHeader", "RegistryNextStep_Context", ValueComparisonType.NotEquals, ePayMode.NotSet, TargetCriteria:="RegistryType.RegistryMainType=0")> _
    '<RuleRange("InvoiceHeader-row_QTT", "aToTable_Invoice_Contexts", 0.00001, Double.MaxValue)> _
    <RuleValueComparison("InvoiceHeader-row_QTT", "aToTable_Invoice_Contexts", ValueComparisonType.NotEquals, 0)>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_QTT() As Double 'Mennyiség
        Get
            Return _row_QTT
        End Get
        Set(ByVal value As Double)
            SetPropertyValue("row_QTT", _row_QTT, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceHeader-row_Units", "aToTable_Invoice_Contexts", TargetCriteria:="IsCorrigendum=False")>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_Units() As Units ' Mennyiségi egység
        Get
            Return _row_Units
        End Get
        Set(ByVal value As Units)
            SetPropertyValue("row_Units", _row_Units, value)
        End Set
    End Property
    <RuleRequiredField("InvoiceHeader-row_VAT", "aToTable_Invoice_Contexts", TargetCriteria:="IsCorrigendum=False")>
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_VAT() As VAT 'ÁFA
        Get
            Return _row_VAT
        End Get
        Set(ByVal value As VAT)
            SetPropertyValue("row_VAT", _row_VAT, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    Property row_QualityOption() As QualityOption 'Minőségi kondíció
        Get
            Return _row_QualityOption
        End Get
        Set(ByVal value As QualityOption)
            SetPropertyValue("row_QualityOption", _row_QualityOption, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInDetailView(False)>
    <VisibleInLookupListView(False)>
    Property row_InvoicePeriod As String
        Get
            Return _row_InvoicePeriod
        End Get
        Set(value As String)
            SetPropertyValue("row_InvoicePeriod", _row_InvoicePeriod, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInDetailView(False)>
    <VisibleInListView(False)>
    <VisibleInLookupListView(False)>
    Property row_Products As Products
        Get
            Return _row_Products
        End Get
        Set(value As Products)
            SetPropertyValue("row_Products", _row_Products, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInDetailView(False)>
    <VisibleInListView(False)>
    <VisibleInLookupListView(False)>
    Property row_Services As Services
        Get
            Return _row_Services
        End Get
        Set(value As Services)
            SetPropertyValue("row_Services", _row_Services, value)
        End Set
    End Property
    'Rule5DMatrix ...
    <NonPersistent()>
    <VisibleInListView(False)>
    <RuleRequiredField("InvoiceHeader-row_Controlling", "aToTable_Invoice_Contexts", TargetCriteria:="InvoiceType.Rule5DMatrix.RequireControlling=True and IsCorrigendum=False")>
    <ImmediatePostData(True), DataSourceCriteria("IsAdvancePayment=False")>
    Property row_Controlling() As Controlling '-- Controlling szám
        Get
            Return _row_Controlling
        End Get
        Set(ByVal value As Controlling)
            SetPropertyValue("row_Controlling", _row_Controlling, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    <RuleRequiredField("InvoiceHeader-row_UniqueObjects", "aToTable_Invoice_Contexts", TargetCriteria:="InvoiceType.Rule5DMatrix.RequireUniqueObjects=True and IsCorrigendum=False")>
    Property row_UniqueObjects() As UniqueObjects ' -- Egyedi azonosító
        Get
            Return _row_UniqueObjects
        End Get
        Set(ByVal value As UniqueObjects)
            SetPropertyValue("row_UniqueObjects", _row_UniqueObjects, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    <RuleRequiredField("InvoiceHeader-row_CostHolder", "aToTable_Invoice_Contexts", TargetCriteria:="InvoiceType.Rule5DMatrix.RequireCostHolder=True and IsCorrigendum=False")>
    Property row_CostHolder() As CostHolder ' -- Költség viselő
        Get
            Return _row_CostHolder
        End Get
        Set(ByVal value As CostHolder)
            SetPropertyValue("row_CostHolder", _row_CostHolder, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    <RuleRequiredField("InvoiceHeader-row_CostPlace", "aToTable_Invoice_Contexts", TargetCriteria:="InvoiceType.Rule5DMatrix.RequireCostPlace=True and IsCorrigendum=False")>
    Property row_CostPlace() As CostPlace ' -- Költség viselő
        Get
            Return _row_CostPlace
        End Get
        Set(ByVal value As CostPlace)
            SetPropertyValue("row_CostPlace", _row_CostPlace, value)
        End Set
    End Property
    <NonPersistent()>
    <VisibleInListView(False)>
    <RuleRequiredField("InvoiceHeader-row_JobNumberObjects", "aToTable_Invoice_Contexts", TargetCriteria:="InvoiceType.Rule5DMatrix.RequireJobNumberObjects=True and IsCorrigendum=False")>
    Property row_JobNumberObjects() As JobNumberObjects ' -- Project
        Get
            Return _row_JobNumberObjects
        End Get
        Set(ByVal value As JobNumberObjects)
            SetPropertyValue("row_JobNumberObjects", _row_JobNumberObjects, value)
        End Set
    End Property
    '-- Függvények egyéb eljárások
    Sub RecalculateInvoice(ByVal _InvoiceHeader As InvoiceHeader, ByVal _ocur As Xpo.XPObjectSpace)
        '-- A rutin újragenerálja a pénzügyi sorokat
        Dim _InvoiceVATRows As InvoiceVATRows
        Dim i As Long = 1
        Dim j As Long = 1
        Dim _Exists As Boolean = False

        _ocur.Delete(_InvoiceHeader.InvoiceVATRows)
        Dim invoices = New XPQuery(Of InvoiceRows)(_ocur.Session)
        Dim query = From invoice In invoices Where invoice.InvoiceHeader.Oid = _InvoiceHeader.Oid
                    Group invoice By invoice.VAT Into g = Group
                    Select New With {Key .VAT = VAT,
                                     Key .AmountNettoHUF = g.Sum(Function(inv) (inv.ListPriceHUF - inv.DiscountPriceHUF) * inv.QTT),
                                     Key .AmountNettoDEV = g.Sum(Function(inv) (inv.ListPriceDEV - inv.DiscountPriceDEV) * inv.QTT),
                                     Key .S2 = g.Sum(Function(inv) inv.ListPriceDEV),
                                     Key .M1 = g.Max(Function(inv) inv.DiscountPriceHUF * inv.QTT)}
        For Each item In query
            _InvoiceVATRows = _ocur.CreateObject(Of InvoiceVATRows)()
            _InvoiceVATRows.InvoiceHeader = _InvoiceHeader
            _InvoiceVATRows.VAT = item.VAT
            _InvoiceVATRows.AmountNettoHUF = item.AmountNettoHUF
            _InvoiceVATRows.AmountVATHUF = 0
            If item.VAT IsNot Nothing Then
                _InvoiceVATRows.AmountVATHUF = Math.Round(item.VAT.KeyValue * _InvoiceVATRows.AmountNettoHUF, 0, MidpointRounding.AwayFromZero)
            End If
            _InvoiceVATRows.AmountBruttoHUF = Math.Round(_InvoiceVATRows.AmountNettoHUF, 0, MidpointRounding.AwayFromZero) + _InvoiceVATRows.AmountVATHUF
            _InvoiceVATRows.AmountNettoHUF = Math.Round(_InvoiceVATRows.AmountNettoHUF, 0, MidpointRounding.AwayFromZero)
            _InvoiceVATRows.AmountNettoDEV = Math.Round(item.AmountNettoDEV, 2, MidpointRounding.AwayFromZero)
            _InvoiceVATRows.AmountVATDEV = 0
            If item.VAT IsNot Nothing Then
                _InvoiceVATRows.AmountVATDEV = Math.Round(item.VAT.KeyValue * _InvoiceVATRows.AmountNettoDEV, 2, MidpointRounding.AwayFromZero)
            End If
            _InvoiceVATRows.AmountBruttoDEV = _InvoiceVATRows.AmountNettoDEV + _InvoiceVATRows.AmountVATDEV


            _InvoiceHeader.InvoiceVATRows.Add(_InvoiceVATRows)
        Next
        TotalBruttoDEV = 0
        TotalBruttoHUF = 0
        TotalNettoHUF = 0
        TotalVATHUF = 0
        TotalNettoDEV = 0
        TotalVATDEV = 0
        For Each _InvoiceVATRows In _InvoiceHeader.InvoiceVATRows
            TotalBruttoHUF += _InvoiceVATRows.AmountBruttoHUF
            TotalBruttoDEV += _InvoiceVATRows.AmountBruttoDEV

            TotalNettoHUF += _InvoiceVATRows.AmountNettoHUF
            TotalNettoDEV += _InvoiceVATRows.AmountNettoDEV

            TotalVATHUF += _InvoiceVATRows.AmountVATHUF
            TotalVATDEV += _InvoiceVATRows.AmountVATDEV
        Next

        'If CurrencyName.ShortName <> "HUF" Then
        '    If TotalBruttoDEV <> 0 Then
        '        CurrencyRate = Math.Round(TotalBruttoHUF / TotalBruttoDEV, 2, MidpointRounding.AwayFromZero)
        '    Else
        '        CurrencyRate = 1
        '    End If
        'Else
        '    CurrencyRate = 1
        'End If

        If _InvoiceHeader.CurrencyName.ShortName = "HUF" Then
            _InvoiceHeader.HUNumberToText = GetHUNumberToText(TotalBruttoHUF)
        Else
            _InvoiceHeader.HUNumberToText = GetHUNumberToText(TotalBruttoDEV)
        End If
        _ocur.CommitChanges()

        Dim _uow As New UnitOfWork(_ocur.Session.DataLayer)
        GLFunctions.ReconfigurePCI(_uow, _InvoiceHeader.CustomersFrom, _InvoiceHeader.Customers, 0, _InvoiceHeader.ConnectInfo)
    End Sub
    Sub BookEntryRemove(ByVal _p_InvoiceHeader As InvoiceHeader, ByVal _uow As UnitOfWork, Optional ByVal _WithCommit As Boolean = False)
        'Az eljárás visszavon egy feladást a főkönyvből
        Dim _InvoiceRows As InvoiceRows
        Dim _InvoiceVATRows As InvoiceVATRows

        Dim _InvoiceHeader As InvoiceHeader = _uow.GetObjectByKey(Of InvoiceHeader)(_p_InvoiceHeader.Oid)

        Dim _ChartOfAccountsYear As ChartOfAccountsYear = _uow.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", _InvoiceHeader.DateExecution.Year))

        If _ChartOfAccountsYear Is Nothing Then
            _InvoiceHeader.BookEntryErrorString = String.Format("Nincs megnyitva a {0} főkönyvi év !", _InvoiceHeader.DateExecution.Year.ToString)
            _InvoiceHeader.Save()
            If _WithCommit Then _uow.CommitTransaction()
            Exit Sub
        End If

        If _ChartOfAccountsYear.IsClosed Then
            _InvoiceHeader.BookEntryErrorString = String.Format("Zárolt főkönyvi év ! {0}", _InvoiceHeader.DateExecution.Year.ToString)
            _InvoiceHeader.Save()
            If _WithCommit Then _uow.CommitTransaction()
            Exit Sub
        End If

        Dim _GLRows_Collection As New XPCollection(Of GLRows)(_uow, CriteriaOperator.Parse("GLHeader.Oid=?", _InvoiceHeader.GLAccounts.Oid))
        _uow.Delete(_GLRows_Collection)

        Dim _GLAccounts_Collection As New XPCollection(Of GLAccounts)(_uow, CriteriaOperator.Parse("Oid=?", _InvoiceHeader.GLAccounts.Oid))
        _uow.Delete(_GLAccounts_Collection)
        _InvoiceHeader.GLAccounts = Nothing
        _InvoiceHeader.ReadyforBookEntry = False
        For Each _InvoiceRows In _InvoiceHeader.InvoiceRows
            _InvoiceRows.ReadyforBookEntryRows = False
        Next
        For Each _InvoiceVATRows In _InvoiceHeader.InvoiceVATRows
            _InvoiceVATRows.ReadyforBookEntryRows = False
        Next

        If _WithCommit Then _uow.CommitChanges()
    End Sub
    Sub BookEntry(ByVal _p_BookEntryMode As Long, ByVal _p_InvoiceHeader As InvoiceHeader, ByVal _uow As UnitOfWork, Optional ByVal _WithCommit As Boolean = False)

        '//ÁFA miatt !!!
        Dim _SQL As String = ""
        Select Case GLOBAL_SQLType
            Case eSQLType.MySQL
                _SQL = " UPDATE InvoiceVATRows t1 JOIN Invoiceheader t2 ON"
                _SQL += " t1.InvoiceHeader = t2.Oid"
                _SQL += " SET t1.DateVAT = t2.DateExecution"
                _SQL += " WHERE t1.DateVAT IS NULL AND t2.GCRecord IS NULL"
            Case eSQLType.MSSQL
                _SQL = " UPDATE InvoiceVATRows t1 JOIN Invoiceheader t2 ON t1.InvoiceHeader = t2.Oid AND t1.DateVAT IS NULL AND t2.GCRecord IS NULL"
                _SQL += " SET t1.DateVAT=t2.DateExecution"
            Case eSQLType.PostgreSQL
                _SQL = "UPDATE ""InvoiceVATRows"" set ""DateVAT""=t2.""DateExecution"""
                _SQL += " from ""InvoiceVATRows"" t1 JOIN ""InvoiceHeader"" t2 ON"
                _SQL += " t1.""InvoiceHeader""=t2.""Oid"""
                _SQL += " WHERE t1.""DateVAT"" IS NULL AND t2.""GCRecord"" IS NULL"
        End Select

        _uow.ExecuteNonQuery(_SQL)
        _uow.CommitChanges()



        ' Az eljárás feladást készít erről a számláról
        ' BookentryMode=0 akkor tételes fealás
        ' BookentryMode=1 akkor jelölőadatokra csoportosított feladás
        If _p_InvoiceHeader Is Nothing Then Exit Sub
        'If _p_InvoiceHeader.InvoiceType.InvoiceTypeBase = eInvoiceTypeBase.eCustomRate Then Exit Sub 'Az előleg bekérőt nem könyveljük !!!

        Dim _InvoiceHeader As InvoiceHeader = _uow.GetObjectByKey(Of InvoiceHeader)(_p_InvoiceHeader.Oid)
        Dim _InvoiceRows As InvoiceRows
        Dim _InvoiceVATRows As InvoiceVATRows
        Dim _GLAccounts As GLAccounts
        Dim _GLRows As GLRows
        Dim _DebitChartOfAccounts As ChartOfAccounts = _InvoiceHeader.Customers.CustomersGLParameters.GetChartOfAccounts(_InvoiceHeader.DateExecution.Year, eVATMode.eOut)


        Dim _CreditChartOfAccounts As ChartOfAccounts
        Dim _Controlling As Controlling
        Dim _CostHolder As CostHolder
        Dim _CostPlace As CostPlace
        Dim _JobNumberObjects As JobNumberObjects
        Dim _UniqueObjects As UniqueObjects

        Dim _GUID As Guid = Guid.NewGuid
        Dim _NettoNotRounded As Double = 0
        Dim _NettoRounded As Double = 0
        ' Megnézi, hogy történt-e már feladás
        If _InvoiceHeader.GLAccounts IsNot Nothing Then
            BookEntryRemove(_InvoiceHeader, _uow, False)
        End If
        If BookEntryCheck(_p_BookEntryMode, _InvoiceHeader, _uow, _WithCommit) = False Then

            Exit Sub
        End If
        If _p_BookEntryMode = 0 Then 'Tételes feladás a főkönyvbe
            _GLAccounts = New GLAccounts(_uow)
            _GLAccounts.AmountDEVBrutto = _InvoiceHeader.TotalBruttoDEV
            _GLAccounts.AmountHUFBrutto = _InvoiceHeader.TotalBruttoHUF
            _GLAccounts.ImportedInvoice = _InvoiceHeader
            _GLAccounts.Customers = _InvoiceHeader.Customers
            _GLAccounts.PartnerType = ePartnerType.eReceivables
            _GLAccounts.PaymentOption = _InvoiceHeader.PaymentOption
            _GLAccounts.CurrencyName = _InvoiceHeader.CurrencyName
            _GLAccounts.CurrencyRate = _InvoiceHeader.CurrencyRate
            _GLAccounts.CustomersFrom = _InvoiceHeader.CustomersFrom
            _GLAccounts.DateCreated = _InvoiceHeader.DateCreated.Date
            _GLAccounts.DateExecution = _InvoiceHeader.DateExecution.Date
            _GLAccounts.DatePayment = _InvoiceHeader.DatePayment.Date
            _GLAccounts.DocumentNumber = _InvoiceHeader.DocumentNumber
            _GLAccounts.ConnectInfo = _InvoiceHeader.ConnectInfo
            _GLAccounts.IsEditable = False
            _GLAccounts.IsStorno = False
            _GLAccounts.NoteHeader = _InvoiceHeader.Description
            _GLAccounts.RegistryNumber = _InvoiceHeader.DocumentNumber


            _InvoiceHeader.GLAccounts = _GLAccounts

            For Each _InvoiceRows In _InvoiceHeader.InvoiceRows
                '-- Netto sor

                _GLRows = New GLRows(_uow)
                If _InvoiceRows.DateExecution = Nothing Then
                    _GLRows.DateExecution = _InvoiceHeader.DateExecution
                Else
                    _GLRows.DateExecution = _InvoiceRows.DateExecution
                End If

                If _InvoiceRows.ContractRows IsNot Nothing Then
                    If _InvoiceRows.ChartOfAccounts Is Nothing Then
                        _CreditChartOfAccounts = _InvoiceRows.ContractRows.Controlling.GetChartOfAccounts(_InvoiceHeader.DateExecution.Year, False)
                    Else
                        _CreditChartOfAccounts = _InvoiceRows.ChartOfAccounts
                    End If
                    _Controlling = _InvoiceRows.ContractRows.Controlling
                    _CostHolder = _InvoiceRows.ContractRows.CostHolder
                    _CostPlace = _InvoiceRows.ContractRows.CostPlace
                    _JobNumberObjects = _InvoiceRows.ContractRows.JobNumberObjects
                    _UniqueObjects = _InvoiceRows.ContractRows.UniqueObjects
                Else
                    If _InvoiceRows.ChartOfAccounts Is Nothing Then
                        _CreditChartOfAccounts = _InvoiceRows.Controlling.GetChartOfAccounts(_InvoiceHeader.DateExecution.Year, False)
                    Else
                        _CreditChartOfAccounts = _InvoiceRows.ChartOfAccounts
                    End If
                    _Controlling = _InvoiceRows.Controlling
                    _CostHolder = _InvoiceRows.CostHolder
                    _CostPlace = _InvoiceRows.CostPlace
                    _JobNumberObjects = _InvoiceRows.JobNumberObjects
                    _UniqueObjects = _InvoiceRows.UniqueObjects
                End If

                If _InvoiceRows.InvoiceHeader.InvoiceType.InvoiceTypeBase = eInvoiceTypeBase.eAdvancePayment Then
                    _GLRows.ConnectInfoAdvanced = _InvoiceRows.InvoiceHeader.DocumentNumber
                End If
                If _InvoiceRows.InvoiceRowsAdvance IsNot Nothing Then
                    _GLRows.ConnectInfoAdvanced = _InvoiceRows.InvoiceRowsAdvance.InvoiceHeader.DocumentNumber
                End If
                _GLRows.InvoiceRows = _InvoiceRows
                _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _DebitChartOfAccounts, _CreditChartOfAccounts, _InvoiceRows.SumPriceDEV,
                                   _InvoiceRows.SumPriceHUF, Nothing, _InvoiceHeader.Customers, _InvoiceHeader.DateExecution.Date, _InvoiceRows.VAT,
                                   _InvoiceRows.Description, _UniqueObjects, _Controlling, _JobNumberObjects,
                                    _CostPlace, _CostHolder, _InvoiceHeader.ConnectInfo, eGLRowsTypeVAT.eNettoRow,
                                    _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.eReceivables)
                _NettoNotRounded += _InvoiceRows.SumPriceHUF
            Next
            For Each _InvoiceVATRows In _InvoiceHeader.InvoiceVATRows
                _GLRows = New GLRows(_uow)
                _GLRows.AddGLRows(TryCast(_GLAccounts, GLHeader), _DebitChartOfAccounts, _InvoiceVATRows.VAT.GetChartOfAccounts(_InvoiceHeader.DateExecution.Year, eVATMode.eOut), _InvoiceVATRows.AmountVATDEV,
                                   _InvoiceVATRows.AmountVATHUF, Nothing, _InvoiceHeader.Customers, _InvoiceVATRows.DateVAT.Date, _InvoiceVATRows.VAT,
                                   "", Nothing, Nothing, Nothing,
                                    Nothing, Nothing, _InvoiceHeader.ConnectInfo, eGLRowsTypeVAT.eVATRow,
                                    _GUID, eTransactionType.eNotSet, eCashType.ePartner, ePartnerType.eReceivables)

                _NettoRounded += _InvoiceVATRows.AmountBruttoHUF - _InvoiceVATRows.AmountVATHUF
            Next

            '-- Most a kerekítésből adódó sort rátesszük a legnagyobb netto sorra
            If Math.Round(_NettoRounded - _NettoNotRounded, 2, MidpointRounding.AwayFromZero) <> 0 Then
                _GLAccounts.GLRows.Sorting.Add(New SortProperty("AmountHUF", DB.SortingDirection.Descending))
                For Each _GLRows In _GLAccounts.GLRows
                    _GLRows.AmountHUF += Math.Round(_NettoRounded - _NettoNotRounded, 2, MidpointRounding.AwayFromZero)
                    Exit For
                Next
            End If



        ElseIf _p_BookEntryMode = 1 Then '-- Összevont feladás

        End If

        If _WithCommit Then _uow.CommitChanges()
    End Sub
    Function BookEntryCheck(ByVal _BookEntryMode As Long, ByVal _InvoiceHeader As InvoiceHeader, ByVal _uow As UnitOfWork, Optional ByVal WithCommit As Boolean = False)
        'Feladás előtti ellenőrzés
        'Mit kell ellenőrizni ?
        'Főkönyvi számlák, Debit,Credit
        'ÁFA főkönyvi számlája
        Dim _InvoiceRows As InvoiceRows
        'If _InvoiceHeader.InvoiceType.InvoiceTypeBase = eInvoiceTypeBase.eCustomRate Then
        '    Return True
        '    Exit Function
        'End If

        Dim _ChartOfAccountsYear As ChartOfAccountsYear = _uow.FindObject(Of ChartOfAccountsYear)(CriteriaOperator.Parse("AccountYear=?", _InvoiceHeader.DateExecution.Year))

        If _ChartOfAccountsYear Is Nothing Then
            _InvoiceHeader.BookEntryErrorString = String.Format("Nincs megnyitva a {0} főkönyvi év !", _InvoiceHeader.DateExecution.Year.ToString)
            _InvoiceHeader.Save()
            _uow.CommitTransaction()
            Return False
        End If

        If _ChartOfAccountsYear.IsClosed Then
            _InvoiceHeader.BookEntryErrorString = String.Format("Zárolt főkönyvi év ! {0}", _InvoiceHeader.DateExecution.Year.ToString)
            _InvoiceHeader.Save()
            _uow.CommitTransaction()
            Return False
        End If

        If _InvoiceHeader.GLAccounts IsNot Nothing Then
            _InvoiceHeader.BookEntryErrorString = String.Format("Könyvelve {0}")
            _InvoiceHeader.Save()
            _uow.CommitTransaction()
            Return False
        End If
        For Each _InvoiceRows In _InvoiceHeader.InvoiceRows
            If _InvoiceRows.ContractRows IsNot Nothing Then
                If _InvoiceRows.ContractRows.Controlling Is Nothing Then
                    _InvoiceHeader.BookEntryErrorString = String.Format("Nincs kontrollszám: {0}", _InvoiceRows.ShortName)
                    _InvoiceHeader.Save()
                    _uow.CommitTransaction()
                    Return False
                Else
                    If _InvoiceRows.ContractRows.Controlling.GetChartOfAccounts(_InvoiceHeader.DateExecution.Year, False) Is Nothing Then
                        _InvoiceHeader.BookEntryErrorString = String.Format("Nincs FK. szám: {0}", _InvoiceRows.ContractRows.Controlling.Name)
                        _InvoiceHeader.Save()
                        _uow.CommitTransaction()
                        Return False
                    End If
                End If
            Else
                If _InvoiceRows.Controlling Is Nothing Then
                    _InvoiceHeader.BookEntryErrorString = String.Format("Nincs kontrollszám: {0}", _InvoiceRows.ShortName)
                    _InvoiceHeader.Save()
                    _uow.CommitTransaction()
                    Return False
                Else
                    If _InvoiceRows.Controlling.GetChartOfAccounts(_InvoiceHeader.DateExecution.Year, False) Is Nothing Then
                        _InvoiceHeader.BookEntryErrorString = String.Format("Nincs FK. szám: {0}", _InvoiceRows.Controlling.Name)
                        _InvoiceHeader.Save()
                        _uow.CommitTransaction()
                        Return False
                    End If
                End If
            End If
            If _InvoiceRows.ReadyforBookEntryRows = False Then
                _InvoiceHeader.BookEntryErrorString = String.Format("Nem könyvelhető minden nettó sor !")
                _InvoiceHeader.Save()
                _uow.CommitTransaction()
                Return False
            End If
        Next

        Dim _InvoiceVATRows As InvoiceVATRows
        For Each _InvoiceVATRows In _InvoiceHeader.InvoiceVATRows
            If _InvoiceVATRows.ReadyforBookEntryRows = False Then
                _InvoiceHeader.BookEntryErrorString = String.Format("Nem könyvelhető minden ÁFA sor !")
                _InvoiceHeader.Save()
                _uow.CommitTransaction()
                Return False
            End If
        Next
        Return True

    End Function
    Function GeneratePDFs(_ocur As Xpo.XPObjectSpace, Frame As Frame, _InvoiceHeader As InvoiceHeader, Optional _DeletePDF As Boolean = True, Optional _ReportDataV2 As ReportDataV2 = Nothing) As String
        If _ReportDataV2 Is Nothing Then
            _ReportDataV2 = _InvoiceHeader.InvoiceType.ReportDataV2
        End If

        If _ReportDataV2 IsNot Nothing Then
            Dim _XtraReport As XtraReport = ReportDataProvider.ReportsStorage.LoadReport(_ReportDataV2)
            Dim dataSource As Object = TryCast(_XtraReport.DataSource, ISupportCriteria)
            dataSource.Criteria = CriteriaOperator.Parse("InvoiceHeader.Oid=?", _InvoiceHeader.Oid)

            Frame.GetController(Of ReportsV2.ReportServiceController).SetupBeforePrint(_XtraReport, Nothing, Nothing, False, Nothing, False)

            Dim _FileName As String = Path.GetTempPath & CorrectFileName(_InvoiceHeader.DocumentNumber) & ".pdf"
            Dim _StreamFile As New FileStream(_FileName, FileMode.Create)

            _XtraReport.ExportToPdf(_StreamFile)
            _StreamFile.Close()

            _StreamFile = New FileStream(_FileName, FileMode.Open, FileAccess.Read)
            Dim _StreamReader As New StreamReader(_StreamFile)
            _StreamFile.Seek(0, SeekOrigin.Begin)

            If _InvoiceHeader.PrintCopy = 1 Then
                _InvoiceHeader.PDF_Original = New FileData(_ocur.Session)
                _InvoiceHeader.PDF_Original.LoadFromStream(CorrectFileName(_InvoiceHeader.DocumentNumber) & "_ORIGINAL.pdf", _StreamFile)
                _InvoiceHeader.PDF_Original.FileName = CorrectFileName(_InvoiceHeader.DocumentNumber) & "_ORIGINAL.pdf"
            Else
                _InvoiceHeader._PDF_Copy = New FileData(_ocur.Session)
                _InvoiceHeader._PDF_Copy.LoadFromStream(CorrectFileName(_InvoiceHeader.DocumentNumber) & "_COPY.pdf", _StreamFile)
                _InvoiceHeader._PDF_Copy.FileName = CorrectFileName(_InvoiceHeader.DocumentNumber) & "_COPY.pdf"
            End If

            _StreamReader.Close()
            _StreamFile.Close()

            If _DeletePDF Then
                File.Delete(_FileName)
                Return ""
            Else
                Return _FileName
            End If
        Else
            Return ""
        End If
    End Function

    '-- Számla információk (XPCollection)
    '// Kapcsolódó bejövő megrendelések
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    ReadOnly Property OrderInHeader_Collection As XPCollection(Of OrderInHeader)
        Get
            Dim _OrderInHeader_Collection As XPCollection(Of OrderInHeader)
            Dim _InvoiceRows As InvoiceRows
            Dim _CriteriaString As String = ""
            For Each _InvoiceRows In Me.InvoiceRows
                If _InvoiceRows.OrderInRows IsNot Nothing Then
                    If _CriteriaString = "" Then
                        _CriteriaString = " Oid in ('" & _InvoiceRows.OrderInRows.OrderInHeader.Oid.ToString & "'"
                    Else
                        _CriteriaString += ", '" & _InvoiceRows.OrderInRows.OrderInHeader.Oid.ToString & "'"
                    End If
                End If
                If _InvoiceRows.OrderInRowsOther IsNot Nothing Then
                    If _CriteriaString = "" Then
                        _CriteriaString = " Oid in ('" & _InvoiceRows.OrderInRowsOther.OrderInHeader.Oid.ToString & "'"
                    Else
                        _CriteriaString += ", '" & _InvoiceRows.OrderInRowsOther.OrderInHeader.Oid.ToString & "'"
                    End If
                End If
            Next
            If _CriteriaString <> "" Then
                _CriteriaString += ")"
            End If
            If _CriteriaString = "" Then
                _OrderInHeader_Collection = New XPCollection(Of OrderInHeader)(Session, CriteriaOperator.Parse("1=2"))
            Else
                _OrderInHeader_Collection = New XPCollection(Of OrderInHeader)(Session, CriteriaOperator.Parse(_CriteriaString))
            End If

            Return _OrderInHeader_Collection
        End Get
    End Property
    '// Kapcsolódó munkalapok
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)> _
    ReadOnly Property WorkSheet_Header_Collection As XPCollection(Of WorkSheet_Header)
        Get
            Dim _WorkSheet_Header_Collection As XPCollection(Of WorkSheet_Header)
            Dim _InvoiceRows As InvoiceRows
            Dim _CriteriaString As String = ""
            For Each _InvoiceRows In Me.InvoiceRows
                If _InvoiceRows.Worksheet_CostRows IsNot Nothing Then
                    If _CriteriaString = "" Then
                        _CriteriaString = " Oid in ('" & _InvoiceRows.Worksheet_CostRows.WorkSheet_Header.Oid.ToString & "'"
                    Else
                        _CriteriaString += ", '" & _InvoiceRows.Worksheet_CostRows.WorkSheet_Header.Oid.ToString & "'"
                    End If
                End If
            Next
            If _CriteriaString <> "" Then
                _CriteriaString += ")"
            End If
            If _CriteriaString = "" Then
                _WorkSheet_Header_Collection = New XPCollection(Of WorkSheet_Header)(Session, CriteriaOperator.Parse("1=2"))
            Else
                _WorkSheet_Header_Collection = New XPCollection(Of WorkSheet_Header)(Session, CriteriaOperator.Parse(_CriteriaString))
            End If

            Return _WorkSheet_Header_Collection
        End Get
    End Property
    ''' <summary>
    ''' Kapcsolódó szerződések
    ''' </summary>
    ''' <returns></returns>
    <VisibleInListView(False), VisibleInDetailView(False), VisibleInLookupListView(False)>
    ReadOnly Property Contracts_Collection As XPCollection(Of Contracts)
        Get
            Dim _Contracts_Collection As XPCollection(Of Contracts)
            Dim _InvoiceRows As InvoiceRows
            Dim _CriteriaString As String = ""
            For Each _InvoiceRows In Me.InvoiceRows
                If _InvoiceRows.ContractRows IsNot Nothing Then
                    If _CriteriaString = "" Then
                        _CriteriaString = " Oid in ('" & _InvoiceRows.ContractRows.Contracts.Oid.ToString & "'"
                    Else
                        _CriteriaString += ", '" & _InvoiceRows.ContractRows.Contracts.Oid.ToString & "'"
                    End If
                End If
            Next
            If _CriteriaString <> "" Then
                _CriteriaString += ")"
            End If
            If _CriteriaString = "" Then
                _Contracts_Collection = New XPCollection(Of Contracts)(Session, CriteriaOperator.Parse("1=2"))
            Else
                _Contracts_Collection = New XPCollection(Of Contracts)(Session, CriteriaOperator.Parse(_CriteriaString))
            End If

            Return _Contracts_Collection
        End Get
    End Property

    <VisibleInListView(False), VisibleInLookupListView(False), VisibleInDetailView(False)> _
    ReadOnly Property IsVATClosed As Boolean
        Get
            Dim _Closed As Boolean = False
            If Me.CustomersFrom IsNot Nothing Then
                If Me.IsEditable = False Then
                    Dim _VATReport As VATReport = Session.FindObject(Of VATReport) _
                            (CriteriaOperator.Parse("GetDate(DateFrom)<=? and GetDate(DateTo)>=? and CustomersFrom=? and Closed=True", _
                            Me.DateExecution.Date, Me.DateExecution.Date, Me.CustomersFrom))
                    If _VATReport IsNot Nothing Then
                        _Closed = _VATReport.Closed
                    End If
                End If
            End If
            Return _Closed
        End Get
    End Property
End Class

