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 eAPCStatus
    eRegistered = 0
    eSigned = 1
    eSendToBank = 2
    eSendToInsurrance = 3
    eAccepted = 4
    eReject = 5
End Enum
Public Enum ePaymentDiscipline
    eNotSet = 0
    eGood = 1
    eDay0_15 = 2
    eDay30_60 = 3
    eDay60to = 4
End Enum
Public Enum eIsNewContactNoWhy
    eNotSet = 0
    eDidNotKnow = 1 'Nem ismert minket
    eDidNotFund = 2 'Nem finanszírozott
    eOther = 3 'Egyéb
End Enum
Public Enum eBankPreQualificationState
    eNotSet = 0
    eAccept = 1
    aReject = 2
End Enum
Public Enum eSalespersonsProposal
    eSuggest = 0    'Javaslom
    eNotRecommended = 1 'Nem javaslom
End Enum
Public Enum eManagementAcceptType
    eNotSet = 0 'Nincs beállítva    
    eHRPerson = 1 'Saját cég
    eManagement = 2 'Banki engedély
End Enum
Public Enum eManagementQualificationState
    eNotSet = 0 'Nincs beállítva
    eCreditental = 1 'Hitelezhető
    eNotCreditental = 2 'Nem hitelezhető
End Enum

<DefaultClassOptions()> _
<NavigationItem(False)> _
<CreatableItem(False)> _
<Appearance("APCSheetHeader - Disable DocumentNumber all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="DocumentNumber", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable TerritorialArea all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="TerritorialArea", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable ManagementDeferredPaymentDay all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="ManagementDeferredPaymentDay", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable ManagementTerritorialArea all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="ManagementTerritorialArea", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable SalesDeferredPaymentHUF all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="SalesDeferredPaymentHUF", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable APCStatus all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="APCStatus", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable ObjectCreated all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable UserCreated all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable EconomyArea all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="EconomyArea", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable DeferredPaymentHUF all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="DeferredPaymentHUF", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable DeferredPaymentDay all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="DeferredPaymentDay", Enabled:=False)> _
<Appearance("APCSheetHeader - Disable DateSigned if APCStatus in (2,3,4)", AppearanceItemType.ViewItem, "APCStatus in (2,3,4)", TargetItems:="DateSigned", Enabled:=False)> _
<Appearance("APCSheetHeader - Hide Description_Reject if  APCStatus <> 5", AppearanceItemType.ViewItem, "APCStatus <> 5", TargetItems:="Description_Reject", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("APCSheetHeader - Hide ManagementAcceptPerson if  ManagementAcceptType <> 1", AppearanceItemType.ViewItem, "ManagementAcceptType <> 1", TargetItems:="ManagementAcceptPerson", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("APCSheetHeader - Disable all properties, when APCStatus=4", AppearanceItemType.ViewItem, "APCStatus=4", TargetItems:="*", Enabled:=False)> _
Public Class APCSheetHeader
    Inherits BaseObject
    Private _DocumentNumber As String
    Private _APCParameters As APCParameters
    Private _HRPerson As HRPerson
    Private _Customers As Customers
    Private _Contacts As Contacts 'Kapcsolat
    Private _ContactsWithFullRight As Contacts 'Tulajdonos / cégjegyzésre jogosult személy
    Private _CustomersFrom As CustomersFrom
    Private _CropProtectionSpecialist As Contacts 'Növényvédelmi szakember
    Private _ShortName As String
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _APCStatus As eAPCStatus
    Private _PDFOriginal As FileData
    Private _PDFSigned As FileData

    Private _IsNewContact As Boolean = True
    Private _IsNewContactNoWhy As eIsNewContactNoWhy 'Új kontakt miért
    Private _IsNewContactNoReason As String 'Új kontakt miért egyéb ok
    Private _PaymentDiscipline As ePaymentDiscipline 'Fizetési fegyelem
    Private _CleanerDryerMachinetype As String 'Tisztító szárító gép tipusa
    Private _CleanerDryerMachineCapacity As Double 'Kapacitása tonna / nap
    Private _ShipmentCapacityMachine As Long 'Szállítási kapacitás gép száma
    Private _ShipmentCapacityAmount As Double 'Szállítási kapacitás /tonna
    Private _StorageCapacitybyFlat As Double 'Sík tárolás /tonna
    Private _StorageCapacitybySilo As Double 'Siló tárolás /tonna

    '------------------------------------------------
    Private _MachineryTractors As Long 'Traktorok szám
    Private _MachineryTillage As Long 'Talajművelő gépek száma
    Private _MachineryHarvesting As Long 'Betakarító gép
    Private _MachineryFighting As Long 'Nővényvédelmi gép
    Private _MachinerySeedDrill As Long 'Vetőgép 
    Private _MachinerySpecial As Long ' Egyéb speciális gép

    '------------------------------------------------
    Private _EconomyArea As Double 'Gazdaság nagysága
    Private _EconomyMajorCropsGrown As String 'Termesztett főbb növények
    Private _EconomyAreaOwner As Double 'Saját tulajdon ebből
    Private _EconomyAreaRent As Double 'Bérelt ebből
    Private _EconomyActualYear As Long 'Gazdaság bemutatásához akutási év
    Private _EconomyPreviousYear As Long 'Gazdaság bemutatásához előző év

    '------------------------------------------------
    Private _MainCustomers As String 'Főbb beszállítók
    Private _Description As String 'Egyéb megjegyzések

    '------------------------------------------------
    Private _TerritorialArea As Double 'Üzletkötő által javasolt terület
    Private _DeferredPaymentDay As Long 'Halasztott fizetés napra
    Private _DeferredPaymentHUF As Double 'Halasztott fizetés HUF ig
    Private _SalespersonsProposal As eSalespersonsProposal 'Üzletkötő javaslata
    Private _SalesDeferredPaymentHUF As Double 'Creditmanager által engedélyezett fizetés HUF

    '------------------------------------------------
    Private _BankPreQualificationState As eBankPreQualificationState 'Előminősítés
    Private _ManagementQualificationState As eManagementQualificationState 'Bank általi jóváhagyás
    Private _ManagementDeferredPaymentDay As Long 'Bank által engedélyezett halasztott fizetés napra
    Private _ManagementDeferredPaymentHUF As Double 'Bank által engedélyezett Halasztott fizetés HUF ig
    Private _ManagementTerritorialArea As Double 'Bank által engedélyezett Üzletkötő által javasolt terület
    Private _ManagementAcceptDocument As FileData 'Engedélyezési okirat
    Private _SendToBankDate As Date 'Bankba küldés dátuma
    Private _ManagementAcceptType As eManagementAcceptType 'Ki engedélyezte Cofas vagy HRPerson
    Private _ManagementAcceptPerson As HRPerson 'Ha HRPerson engedélyezte, akkor kötelező beállítani és csak akkor látszik

    Private _Activity As String 'Partner tevékenysége
    Private _ActivityStartDate As Date 'Tevékenység kezdete
    Private _IsPrivateCredit As Boolean 'Van-e magánszemélyként hiteltartozása
    Private _IsPrivateCreditAmountHUF As Double 'Hiteltartozás összege
    Private _OtherCompanyInfo As String 'Egyéb vállalkozásnak tagja-e és hol ?

    Private _DateSigned As Date 'Aláírás Dátuma
    Private _Description_Reject As String ' Miért lett elutasítva?
    Private _APCSheetAdministrator As HRPerson 'Termeltetési szerződés ügyintézője
    Private _APCSheetContractHandlingPlace As APCSheetContractHandlingPlace
    '-------------------------------------------
    'Reporthoz
    Private _MaxExpirationDate As Date
    Private _IsActive As Boolean

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

        APCStatus = eAPCStatus.eRegistered
        IsActive = True

        If Session.IsNewObject(Me) Then
            Dim _APCSheetCreditClassificationFinancialRows As APCSheetCreditClassificationFinancialRows

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 1
            _APCSheetCreditClassificationFinancialRows.ShortName = "Pénzeszközök (összes bevétel-összes kiadás)"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 2
            _APCSheetCreditClassificationFinancialRows.ShortName = "Tárgyi eszközök nettó értéke"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 3
            _APCSheetCreditClassificationFinancialRows.ShortName = "Folyamatban lévő beruházások értéke"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 4
            _APCSheetCreditClassificationFinancialRows.ShortName = "Forgóeszközök"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 5
            _APCSheetCreditClassificationFinancialRows.ShortName = "Készletek leltár szerinti értéke"
            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)

            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 6
            _APCSheetCreditClassificationFinancialRows.ShortName = "Vevőkkel szembeni követelések"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 7
            _APCSheetCreditClassificationFinancialRows.ShortName = "Egyéb követelések"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 8
            _APCSheetCreditClassificationFinancialRows.ShortName = "Határidőn túli követelések"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 9
            _APCSheetCreditClassificationFinancialRows.ShortName = "Hosszú lejáratú kötelezettségek"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 10
            _APCSheetCreditClassificationFinancialRows.ShortName = "Szállítókkal szembeni kötelezettségek"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 11
            _APCSheetCreditClassificationFinancialRows.ShortName = "Adó és TB tartozás"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 12
            _APCSheetCreditClassificationFinancialRows.ShortName = "Egyéb rövid lejáratú kötelezettségek"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 13
            _APCSheetCreditClassificationFinancialRows.ShortName = "Hosszúlejáratú hitelek tárgyidőszaki törlesztése"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 14
            _APCSheetCreditClassificationFinancialRows.ShortName = "Nettó árbevétel"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 15
            _APCSheetCreditClassificationFinancialRows.ShortName = "Egyéb bevétel"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 16
            _APCSheetCreditClassificationFinancialRows.ShortName = "Adózás előtti eredmény"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 17
            _APCSheetCreditClassificationFinancialRows.ShortName = "Adózott eredmény"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 18
            _APCSheetCreditClassificationFinancialRows.ShortName = "Fennálló összes hitel tipusú tartozás éves törlesztő részlete"

            _APCSheetCreditClassificationFinancialRows = New APCSheetCreditClassificationFinancialRows(Session)
            _APCSheetCreditClassificationFinancialRows.APCSheetHeader = Me
            _APCSheetCreditClassificationFinancialRows.RowIndex = 19
            _APCSheetCreditClassificationFinancialRows.ShortName = "Terv szerinti ÉCS leírás"
        End If
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If String.IsNullOrEmpty(DocumentNumber) Then DocumentNumber = APCParameters.NumberGenerator.GetNewNumber(APCParameters.NumberGenerator)
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
        'DeferredPaymentHUF = 0

        'For Each _APCSheetByProducts As APCSheetByProducts In APCSheetByProducts
        '    DeferredPaymentHUF += _APCSheetByProducts.FundingAmountHUF
        'Next

        'SalesDeferredPaymentHUF = DeferredPaymentHUF

        'EconomyArea = 0
        'TerritorialArea = 0
        'For Each _APCSheetPresentation As APCSheetPresentation In APCSheetPresentation
        '    EconomyArea += _APCSheetPresentation.Area
        '    TerritorialArea += _APCSheetPresentation.Area
        'Next
        'EconomyAreaOwner = 0
        'Dim _APCSheetByTerritorialOwner_Collection As New XPCollection(Of APCSheetByTerritorial)(Session, CriteriaOperator.Parse("APCSheetHeader=? AND OwnerState=0", Me))
        'If _APCSheetByTerritorialOwner_Collection.Count > 0 Then
        '    For Each _APCSheetByTerritorial As APCSheetByTerritorial In _APCSheetByTerritorialOwner_Collection
        '        EconomyAreaOwner += _APCSheetByTerritorial.Area
        '    Next
        'End If
        'EconomyAreaRent = 0
        'Dim _APCSheetByTerritorialRent_Collection As New XPCollection(Of APCSheetByTerritorial)(Session, CriteriaOperator.Parse("APCSheetHeader=? AND (OwnerState=1 OR OwnerState=2)", Me))
        'If _APCSheetByTerritorialRent_Collection.Count > 0 Then
        '    For Each _APCSheetByTerritorial As APCSheetByTerritorial In _APCSheetByTerritorialRent_Collection
        '        EconomyAreaRent += _APCSheetByTerritorial.Area
        '    Next
        'End If

        'If DateSigned.Year = GetSQLTime(Session).Year Then
        '    APCSheetByProducts.Sorting.Add(New SortProperty("ProductExpirationDate", DB.SortingDirection.Descending))
        '    If Me.APCSheetByProducts.Count > 0 Then
        '        Dim _MaxDate As Date = Me.APCSheetByProducts(0).ProductExpirationDate
        '        Me.DeferredPaymentDay = CType((_MaxDate - DateSigned).Days, Long)
        '    Else
        '        Me.DeferredPaymentDay = 0
        '    End If
        'End If
        'ManagementDeferredPaymentDay = DeferredPaymentDay
    End Sub

    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    <RuleRequiredField("APCSheetHeader - APCParameters", DefaultContexts.Save)> _
    Property APCParameters As APCParameters
        Get
            Return _APCParameters
        End Get
        Set(value As APCParameters)
            SetPropertyValue("APCParameters", _APCParameters, value)
        End Set
    End Property
    <RuleRequiredField("APCSheetHeader - HRPerson", DefaultContexts.Save)> _
    Property HRPerson As HRPerson
        Get
            Return _HRPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("HRPerson", _HRPerson, value)
        End Set
    End Property
    <RuleRequiredField("APCSheetHeader - Customers", DefaultContexts.Save)> _
    Property Customers As Customers
        Get
            Return _Customers
        End Get
        Set(value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    <DataSourceCriteria("Customers='@This.Customers'")> _
    Property Contacts As Contacts
        Get
            Return _Contacts
        End Get
        Set(value As Contacts)
            SetPropertyValue("Contacts", _Contacts, value)
        End Set
    End Property
    <RuleRequiredField("APCSheetHeader - ContactsWithFullRight", DefaultContexts.Save)> _
    <DataSourceCriteria("Customers='@This.Customers'")> _
    Property ContactsWithFullRight As Contacts
        Get
            Return _ContactsWithFullRight
        End Get
        Set(value As Contacts)
            SetPropertyValue("ContactsWithFullRight", _ContactsWithFullRight, value)
        End Set
    End Property
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <RuleRequiredField("APCSheetHeader - CropProtectionSpecialist", DefaultContexts.Save)> _
    <DataSourceProperty("CropProtectionSpecialistList")> _
    Property CropProtectionSpecialist As Contacts
        Get
            Return _CropProtectionSpecialist
        End Get
        Set(value As Contacts)
            SetPropertyValue("CropProtectionSpecialist", _CropProtectionSpecialist, value)
        End Set
    End Property
    <Size(255)> _
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, 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
    <ImmediatePostData(True)> _
    Property APCStatus As eAPCStatus
        Get
            Return _APCStatus
        End Get
        Set(value As eAPCStatus)
            SetPropertyValue("APCStatus", _APCStatus, value)
        End Set
    End Property
    Property PDFOriginal As FileData
        Get
            Return _PDFOriginal
        End Get
        Set(value As FileData)
            SetPropertyValue("PDFOriginal", _PDFOriginal, value)
        End Set
    End Property
    Property PDFSigned As FileData
        Get
            Return _PDFSigned
        End Get
        Set(value As FileData)
            SetPropertyValue("PDFSigned", _PDFSigned, value)
        End Set
    End Property

    Property IsNewContact As Boolean
        Get
            Return _IsNewContact
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsNewContact", _IsNewContact, value)
        End Set
    End Property
    Property IsNewContactNoWhy As eIsNewContactNoWhy
        Get
            Return _IsNewContactNoWhy
        End Get
        Set(value As eIsNewContactNoWhy)
            SetPropertyValue("IsNewContactNoWhy", _IsNewContactNoWhy, value)
        End Set
    End Property
    <Size(255)> _
    Property IsNewContactNoReason As String
        Get
            Return _IsNewContactNoReason
        End Get
        Set(value As String)
            SetPropertyValue("IsNewContactNoReason", _IsNewContactNoReason, value)
        End Set
    End Property
    Property PaymentDiscipline As ePaymentDiscipline
        Get
            Return _PaymentDiscipline
        End Get
        Set(value As ePaymentDiscipline)
            SetPropertyValue("PaymentDiscipline", _PaymentDiscipline, value)
        End Set
    End Property
    <Size(255)> _
    Property CleanerDryerMachinetype As String
        Get
            Return _CleanerDryerMachinetype
        End Get
        Set(value As String)
            SetPropertyValue("CleanerDryerMachinetype", _CleanerDryerMachinetype, value)
        End Set
    End Property
    Property CleanerDryerMachineCapacity As Double
        Get
            Return _CleanerDryerMachineCapacity
        End Get
        Set(value As Double)
            SetPropertyValue("CleanerDryerMachineCapacity", _CleanerDryerMachineCapacity, value)
        End Set
    End Property
    Property ShipmentCapacityMachine As Long
        Get
            Return _ShipmentCapacityMachine
        End Get
        Set(value As Long)
            SetPropertyValue("ShipmentCapacityMachine", _ShipmentCapacityMachine, value)
        End Set
    End Property
    Property ShipmentCapacityAmount As Double
        Get
            Return _ShipmentCapacityAmount
        End Get
        Set(value As Double)
            SetPropertyValue("ShipmentCapacityAmount", _ShipmentCapacityAmount, value)
        End Set
    End Property
    Property StorageCapacitybyFlat As Double
        Get
            Return _StorageCapacitybyFlat
        End Get
        Set(value As Double)
            SetPropertyValue("StorageCapacitybyFlat", _StorageCapacitybyFlat, value)
        End Set
    End Property
    Property StorageCapacitybySilo As Double
        Get
            Return _StorageCapacitybySilo
        End Get
        Set(value As Double)
            SetPropertyValue("StorageCapacitybySilo", _StorageCapacitybySilo, value)
        End Set
    End Property

    '------------------------------------------------
    Property MachineryTractors As Long
        Get
            Return _MachineryTractors
        End Get
        Set(value As Long)
            SetPropertyValue("MachineryTractors", _MachineryTractors, value)
        End Set
    End Property
    Property MachineryTillage As Long
        Get
            Return _MachineryTillage
        End Get
        Set(value As Long)
            SetPropertyValue("MachineryTillage", _MachineryTillage, value)
        End Set
    End Property
    Property MachineryHarvesting As Long
        Get
            Return _MachineryHarvesting
        End Get
        Set(value As Long)
            SetPropertyValue("MachineryHarvesting", _MachineryHarvesting, value)
        End Set
    End Property
    Property MachineryFighting As Long
        Get
            Return _MachineryFighting
        End Get
        Set(value As Long)
            SetPropertyValue("MachineryFighting", _MachineryFighting, value)
        End Set
    End Property
    Property MachinerySeedDrill As Long
        Get
            Return _MachinerySeedDrill
        End Get
        Set(value As Long)
            SetPropertyValue("MachinerySeedDrill", _MachinerySeedDrill, value)
        End Set
    End Property
    Property MachinerySpecial As Long
        Get
            Return _MachinerySpecial
        End Get
        Set(value As Long)
            SetPropertyValue("MachinerySpecial", _MachinerySpecial, value)
        End Set
    End Property

    '------------------------------------------------
    <RuleRequiredField("APCSheetHeader - EconomyArea", DefaultContexts.Save)> _
    Property EconomyArea As Double
        Get
            Return _EconomyArea
        End Get
        Set(value As Double)
            SetPropertyValue("EconomyArea", _EconomyArea, value)
        End Set
    End Property
    <Size(800)> _
    Property EconomyMajorCropsGrown As String
        Get
            Return _EconomyMajorCropsGrown
        End Get
        Set(value As String)
            SetPropertyValue("EconomyMajorCropsGrown", _EconomyMajorCropsGrown, value)
        End Set
    End Property
    Property EconomyAreaOwner As Double
        Get
            Return _EconomyAreaOwner
        End Get
        Set(value As Double)
            SetPropertyValue("EconomyAreaOwner", _EconomyAreaOwner, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.EconomyArea = Me.EconomyAreaRent + value
            End If
        End Set
    End Property
    Property EconomyAreaRent As Double
        Get
            Return _EconomyAreaRent
        End Get
        Set(value As Double)
            SetPropertyValue("EconomyAreaRent", _EconomyAreaRent, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Me.EconomyArea = Me.EconomyAreaOwner + value
            End If
        End Set
    End Property
    Property EconomyActualYear As Long
        Get
            Return _EconomyActualYear
        End Get
        Set(value As Long)
            SetPropertyValue("EconomyActualYear", _EconomyActualYear, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                EconomyPreviousYear = value - 1
            End If
        End Set
    End Property
    Property EconomyPreviousYear As Long
        Get
            Return _EconomyPreviousYear
        End Get
        Set(value As Long)
            SetPropertyValue("EconomyPreviousYear", _EconomyPreviousYear, value)
        End Set
    End Property
    '------------------------------------------------
    <Size(255)> _
    Property MainCustomers As String
        Get
            Return _MainCustomers
        End Get
        Set(value As String)
            SetPropertyValue("MainCustomers", _MainCustomers, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property

    '------------------------------------------------
    Property TerritorialArea As Double
        Get
            Return _TerritorialArea
        End Get
        Set(value As Double)
            SetPropertyValue("TerritorialArea", _TerritorialArea, value)
        End Set
    End Property
    Property DeferredPaymentDay As Long
        Get
            Return _DeferredPaymentDay
        End Get
        Set(value As Long)
            SetPropertyValue("DeferredPaymentDay", _DeferredPaymentDay, value)
        End Set
    End Property
    Property DeferredPaymentHUF As Double
        Get
            Return _DeferredPaymentHUF
        End Get
        Set(value As Double)
            SetPropertyValue("DeferredPaymentHUF", _DeferredPaymentHUF, value)
        End Set
    End Property
    Public Property SalespersonsProposal() As eSalespersonsProposal
        Get
            Return _SalespersonsProposal
        End Get
        Set(ByVal value As eSalespersonsProposal)
            SetPropertyValue("SalespersonsProposal", _SalespersonsProposal, value)
        End Set
    End Property
    Property SalesDeferredPaymentHUF As Double
        Get
            Return _SalesDeferredPaymentHUF
        End Get
        Set(value As Double)
            SetPropertyValue("SalesDeferredPaymentHUF", _SalesDeferredPaymentHUF, value)
        End Set
    End Property

    '------------------------------------------------
    Property BankPreQualificationState As eBankPreQualificationState
        Get
            Return _BankPreQualificationState
        End Get
        Set(value As eBankPreQualificationState)
            SetPropertyValue("BankPreQualificationState", _BankPreQualificationState, value)
        End Set
    End Property
    Property ManagementQualificationState As eManagementQualificationState
        Get
            Return _ManagementQualificationState
        End Get
        Set(value As eManagementQualificationState)
            SetPropertyValue("ManagementQualificationState", _ManagementQualificationState, value)
        End Set
    End Property
    Property ManagementDeferredPaymentDay As Long
        Get
            Return _ManagementDeferredPaymentDay
        End Get
        Set(value As Long)
            SetPropertyValue("ManagementDeferredPaymentDay", _ManagementDeferredPaymentDay, value)
        End Set
    End Property
    Property ManagementDeferredPaymentHUF As Double
        Get
            Return _ManagementDeferredPaymentHUF
        End Get
        Set(value As Double)
            SetPropertyValue("ManagementDeferredPaymentHUF", _ManagementDeferredPaymentHUF, value)
        End Set
    End Property
    Property ManagementTerritorialArea As Double
        Get
            Return _ManagementTerritorialArea
        End Get
        Set(value As Double)
            SetPropertyValue("ManagementTerritorialArea", _ManagementTerritorialArea, value)
        End Set
    End Property
    Property ManagementAcceptDocument As FileData
        Get
            Return _ManagementAcceptDocument
        End Get
        Set(value As FileData)
            SetPropertyValue("ManagementAcceptDocument", _ManagementAcceptDocument, value)
        End Set
    End Property
    Property SendToBankDate As Date
        Get
            Return _SendToBankDate
        End Get
        Set(value As Date)
            SetPropertyValue("SendToBankDate", _SendToBankDate, value)
        End Set
    End Property
    <ImmediatePostData()> _
    Property ManagementAcceptType As eManagementAcceptType
        Get
            Return _ManagementAcceptType
        End Get
        Set(value As eManagementAcceptType)
            SetPropertyValue("ManagementAcceptType", _ManagementAcceptType, value)
        End Set
    End Property
    <RuleRequiredField("APCSheetHeader - ManagementAcceptPerson", DefaultContexts.Save, TargetCriteria:="ManagementAcceptType = 1")> _
    Property ManagementAcceptPerson As HRPerson
        Get
            Return _ManagementAcceptPerson
        End Get
        Set(value As HRPerson)
            SetPropertyValue("ManagementAcceptPerson", _ManagementAcceptPerson, value)
        End Set
    End Property

    Property Activity As String
        Get
            Return _Activity
        End Get
        Set(value As String)
            SetPropertyValue("Activity", _Activity, value)
        End Set
    End Property
    Property ActivityStartDate As Date
        Get
            Return _ActivityStartDate
        End Get
        Set(value As Date)
            SetPropertyValue("ActivityStartDate", _ActivityStartDate, value)
        End Set
    End Property
    Property IsPrivateCredit As Boolean
        Get
            Return _IsPrivateCredit
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsPrivateCredit", _IsPrivateCredit, value)
        End Set
    End Property
    Property IsPrivateCreditAmountHUF As Double
        Get
            Return _IsPrivateCreditAmountHUF
        End Get
        Set(value As Double)
            SetPropertyValue("IsPrivateCreditAmountHUF", _IsPrivateCreditAmountHUF, value)
        End Set
    End Property
    Property OtherCompanyInfo As String
        Get
            Return _OtherCompanyInfo
        End Get
        Set(value As String)
            SetPropertyValue("OtherCompanyInfo", _OtherCompanyInfo, value)
        End Set
    End Property
    <ImmediatePostData()> _
    <RuleRequiredField("APCSheetHeader - DateSigned", DefaultContexts.Save, TargetCriteria:="APCStatus <> 0")> _
    Property DateSigned() As Date
        Get
            Return _DateSigned
        End Get
        Set(ByVal value As Date)
            SetPropertyValue("DateSigned", _DateSigned, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description_Reject As String
        Get
            Return _Description_Reject
        End Get
        Set(value As String)
            SetPropertyValue("Description_Reject", _Description_Reject, value)
        End Set
    End Property
    Property APCSheetAdministrator As HRPerson
        Get
            Return _APCSheetAdministrator
        End Get
        Set(value As HRPerson)
            SetPropertyValue("APCSheetAdministrator", _APCSheetAdministrator, value)
        End Set
    End Property
    Property APCSheetContractHandlingPlace As APCSheetContractHandlingPlace
        Get
            Return _APCSheetContractHandlingPlace
        End Get
        Set(value As APCSheetContractHandlingPlace)
            SetPropertyValue("APCSheetContractHandlingPlace", _APCSheetContractHandlingPlace, value)
        End Set
    End Property
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property MaxExpirationDate As Date
        Get
            Return _MaxExpirationDate
        End Get
        Set(value As Date)
            SetPropertyValue("MaxExpirationDate", _MaxExpirationDate, value)
        End Set
    End Property
    Property IsActive As Boolean
        Get
            Return _IsActive
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsActive", _IsActive, value)
        End Set
    End Property

    '-- Nonpersistent propertyk


    '--------------ReadOnly---------------
    <Association("APCSheetHeader-APCSheetByProducts", GetType(APCSheetByProducts)), VisibleInListView(False)> _
    <ImmediatePostData()> _
    ReadOnly Property APCSheetByProducts As XPCollection(Of APCSheetByProducts)
        Get
            Return GetCollection(Of APCSheetByProducts)("APCSheetByProducts")
        End Get
    End Property
    <Association("APCSheetHeader-APCSheetPresentation", GetType(APCSheetPresentation)), VisibleInListView(False)> _
    ReadOnly Property APCSheetPresentation As XPCollection(Of APCSheetPresentation)
        Get
            Return GetCollection(Of APCSheetPresentation)("APCSheetPresentation")
        End Get
    End Property
    <Association("APCSheetHeader-APCSheetByTerritorial", GetType(APCSheetByTerritorial)), VisibleInListView(False)> _
    ReadOnly Property APCSheetByTerritorial As XPCollection(Of APCSheetByTerritorial)
        Get
            Return GetCollection(Of APCSheetByTerritorial)("APCSheetByTerritorial")
        End Get
    End Property
    <Association("APCSheetHeader-APCSheetCreditClassificationAnimalRows", GetType(APCSheetCreditClassificationAnimalRows)), VisibleInListView(False)> _
    ReadOnly Property APCSheetCreditClassificationAnimalRows As XPCollection(Of APCSheetCreditClassificationAnimalRows)
        Get
            Return GetCollection(Of APCSheetCreditClassificationAnimalRows)("APCSheetCreditClassificationAnimalRows")
        End Get
    End Property
    <Association("APCSheetHeader-APCSheetCreditClassificationFinancialRows", GetType(APCSheetCreditClassificationFinancialRows)), VisibleInListView(False)> _
    ReadOnly Property APCSheetCreditClassificationFinancialRows As XPCollection(Of APCSheetCreditClassificationFinancialRows)
        Get
            Return GetCollection(Of APCSheetCreditClassificationFinancialRows)("APCSheetCreditClassificationFinancialRows")
        End Get
    End Property
    <Browsable(False)> _
    Private ReadOnly Property CropProtectionSpecialistList As XPCollection(Of Contacts)
        Get
            Dim _CropProtectionSpecialistList_Collection As New XPCollection(Of Contacts)(Session, CriteriaOperator.Parse("IsNull(CropProtectionRegistrationNumber)=False"))

            Return _CropProtectionSpecialistList_Collection
        End Get
    End Property
    ReadOnly Property APCSheetReviewHeader As XPCollection(Of APCSheetReviewHeader)
        Get
            Return New XPCollection(Of APCSheetReviewHeader)(Session, CriteriaOperator.Parse("APCSheetByProducts.APCSheetHeader=?", Me))
        End Get
    End Property
End Class
