New Business Logic Entities  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

New Business Logic Entities

Postby SBarnes » Sat Nov 14, 2015 1:58 pm

Hi Guys

Is it possible to add new business logic entities to the system that would then have their own forms and tables so that they can be created by the factory as any normal business entity such as sales or inventory are?

I notice that these and other current system objects inherit from a maintenance object is it as simple as inheriting from this object and implementing the necessary interfaces or what other steps are involved if this is at all possible?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: New Business Logic Entities

Postby Mike.Sheen » Mon Nov 16, 2015 11:48 am

SBarnes wrote:Hi Guys

Is it possible to add new business logic entities to the system that would then have their own forms and tables so that they can be created by the factory as any normal business entity such as sales or inventory are?

I notice that these and other current system objects inherit from a maintenance object is it as simple as inheriting from this object and implementing the necessary interfaces or what other steps are involved if this is at all possible?


This is indeed possible. The Magento integration plugin introduced in 07.00.141.00 has an example of this - it introduces a business logic object and form for maintenance type functions.

Basically, the business logic needs to inherit from JiwaFinancials.JiwaJiwaApplication.BusinessLogic.Maintenance, and then override some properties and methods

Then there are some properties you need to override:
  • DocumentNo
    Eg:
    Code: Select all
    Public Overrides ReadOnly Property DocumentNo As String
       Get
          Return RequestNo
       End Get
    End Property
  • RecIDFieldName
    Eg:
    Code: Select all
    Public Overrides ReadOnly Property RecIDFieldName As String
       Get
          Return "RA_RequestMain.RecID"
       End Get
    End Property
  • SortFieldValue
    Eg:
    Code: Select all
    Public Overrides ReadOnly Property SortFieldValue As String
       Get
          Select Case SortOrder.Description
             Case "Request No."
                Return RequestNo
             Case Else
                Return Nothing
          End Select
       End Get
    End Property
  • TableName
    Eg:
    Code: Select all
    Public Overrides ReadOnly Property TableName As String
       Get
          Return "RA_RequestMain"
       End Get
    End Property

You will also need to do a few things in the constructor for the class:
  • Set the ClientClassName
  • Add to the SortOrders list

Eg:
Code: Select all
Public Sub New()
   MyBase.New()
   MyBase.ClientClassName = "JiwaFinancials.Jiwa.JiwaSupplierReturnsUI.Request.Request"
   ...
   SortOrders.Add(New JiwaApplication.IJiwaNavigable.SortKey With {.Description = "Request No.", .FieldName = "RA_RequestMain.RequestNo"})
End Sub


Methods you should override are:
  • Clear
    This method is called to reset properties back to an empty state (eg: as part of a read)
  • CreateNew
    Invoked when creating a new record
  • Delete
    Deletes the record
  • Read
    Reads a record, given the RecID
  • Save
    Saves a record.

As a guide, below is the code of the Supplier Return Request business logic class - it should be a good reference example to follow for developing business logic :


Code: Select all
' ***********************************************************************
' Assembly         : JiwaSupplierReturns
' Author           : Mike Sheen
' Created          : 10-23-2013
'
' Last Modified By : Mike Sheen
' Last Modified On : 12-20-2013
' ***********************************************************************
' <copyright file="Request.vb" company="Jiwa Financials">
'     Copyright (c) Jiwa Financials. All rights reserved.
' </copyright>
' <summary></summary>
' ***********************************************************************
Option Explicit On
Option Strict Off

Imports System.Data.SqlClient

''' <summary>
''' The Request namespace.
''' </summary>
Namespace Request
    ''' <summary>
    ''' Class Request.
    ''' </summary>
    Public Class Request
        Inherits JiwaApplication.BusinessLogic.Maintenance
        Implements JiwaApplication.IJiwaDocuments
        Implements JiwaApplication.IJiwaNotes
        Implements JiwaApplication.IJiwaCustomFields
        Implements JiwaApplication.IJiwaCustomFieldValues
        Implements JiwaApplication.IJiwaWarehouseFiltering

#Region "Enumerations"
        ''' <summary>
        ''' Enum BatchTypes
        ''' </summary>
        Public Enum BatchTypes
            ''' <summary>
            ''' The request
            ''' </summary>
            Request = 0
            ''' <summary>
            ''' The shipping
            ''' </summary>
            Shipping = 1
        End Enum

        ''' <summary>
        ''' Enum Statuses
        ''' </summary>
        Public Enum Statuses
            ''' <summary>
            ''' The open
            ''' </summary>
            Open = 0
            ''' <summary>
            ''' The activated
            ''' </summary>
            Activated = 1
            ''' <summary>
            ''' The closed
            ''' </summary>
            Closed = 2
        End Enum
#End Region

#Region "Fields"
        Private _RequestNo As String
        Private _Reference As String
        Private _OriginalStatus As Statuses
        Private _Status As Statuses
        Private _LastSavedDateTime As Date
        Private WithEvents _CreatedBy As JiwaApplication.Entities.Staff.Staff
        Private WithEvents _ReturnCode As Entities.ReturnCode
        Private WithEvents _DeliveryAddress As JiwaApplication.Entities.Address
        Private _ContactName As String
        Private _RequestDate As Date
        Private WithEvents _Creditor As JiwaApplication.Entities.Creditor.Creditor
        Private WithEvents _ReturnsWarehouse As JiwaApplication.Inventory.Warehouse.LogicalWarehouse
        Private _TaxRates As JiwaApplication.JiwaTaxSystemRates.TaxRateCollection
        Private _DefaultTaxRate As JiwaApplication.JiwaTaxSystemRates.TaxRate
        Private _DefaultFXTaxRate As JiwaApplication.JiwaTaxSystemRates.TaxRate

        Private _RowHash As Byte()
        Private _OldRowHash As Byte()

        Private WithEvents _Documents As JiwaApplication.Documents.DocumentCollection
        Private WithEvents _Notes As JiwaApplication.Notes.NoteCollection
        Private _SystemSettings As SystemSettings
        Private WithEvents _JournalSet As JiwaJournalSets.JournalSet

        Private WithEvents _Lines As LineCollection
        Private _PurchaseOrders As List(Of JiwaPurchaseOrders.PurchaseOrder)
        Private _ShippingCollection As ShippingCollection
        Private WithEvents _Credits As CreditCollection

        Private WithEvents _CustomFields As JiwaApplication.CustomFields.CustomFieldCollection
        Private WithEvents _CustomFieldValues As JiwaApplication.CustomFields.CustomFieldValueCollection

        Private WithEvents _LineCustomFields As JiwaApplication.CustomFields.CustomFieldCollection
#End Region

#Region "Properties"
        Public Overrides ReadOnly Property DocumentNo As String
            Get
                Return RequestNo
            End Get
        End Property

        ''' <summary>
        ''' Gets the name of the record identifier field.
        ''' </summary>
        ''' <value>The name of the record identifier field.</value>
        Public Overrides ReadOnly Property RecIDFieldName As String
            Get
                Return "RA_RequestMain.RecID"
            End Get
        End Property

        ''' <summary>
        ''' Gets the sort field value.
        ''' </summary>
        ''' <value>The sort field value.</value>
        Public Overrides ReadOnly Property SortFieldValue As String
            Get
                Select Case SortOrder.Description
                    Case "Request No."
                        Return RequestNo
                    Case Else
                        Return Nothing
                End Select
            End Get
        End Property

        ''' <summary>
        ''' Gets the name of the table.
        ''' </summary>
        ''' <value>The name of the table.</value>
        Public Overrides ReadOnly Property TableName As String
            Get
                Return "RA_RequestMain"
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets the request no.
        ''' </summary>
        ''' <value>The request no.</value>
        Public Property RequestNo As String
            Get
                Return _RequestNo
            End Get
            Set(value As String)
                _RequestNo = value
                NotifyPropertyChanged("RequestNo")
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the reference.
        ''' </summary>
        ''' <value>The reference.</value>
        Public Property Reference As String
            Get
                Return _Reference
            End Get
            Set(value As String)
                _Reference = value
                NotifyPropertyChanged("Reference")
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the status.
        ''' </summary>
        ''' <value>The status.</value>
        Public Property Status As Statuses
            Get
                Return _Status
            End Get
            Set(value As Statuses)
                _Status = value
                NotifyPropertyChanged("Status")
            End Set
        End Property

        ''' <summary>
        ''' Gets the original status.
        ''' </summary>
        ''' <value>The original status.</value>
        Public ReadOnly Property OriginalStatus As Statuses
            Get
                Return _OriginalStatus
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets the last saved date time.
        ''' </summary>
        ''' <value>The last saved date time.</value>
        Public Property LastSavedDateTime As Date
            Get
                Return _LastSavedDateTime
            End Get
            Set(value As Date)
                _LastSavedDateTime = value
                NotifyPropertyChanged("LastSavedDateTime")
            End Set
        End Property

        ''' <summary>
        ''' Gets the created by.
        ''' </summary>
        ''' <value>The created by.</value>
        Public ReadOnly Property CreatedBy As JiwaApplication.Entities.Staff.Staff
            Get
                Return _CreatedBy
            End Get
        End Property

        ''' <summary>
        ''' Gets the return code.
        ''' </summary>
        ''' <value>The return code.</value>
        Public ReadOnly Property ReturnCode As Entities.ReturnCode
            Get
                Return _ReturnCode
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets the delivery address.
        ''' </summary>
        ''' <value>The delivery address.</value>
        Public Property DeliveryAddress As JiwaApplication.Entities.Address
            Get
                Return _DeliveryAddress
            End Get
            Set(value As JiwaApplication.Entities.Address)
                _DeliveryAddress = value
                NotifyPropertyChanged("DeliveryAddress")
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the name of the contact.
        ''' </summary>
        ''' <value>The name of the contact.</value>
        Public Property ContactName As String
            Get
                Return _ContactName
            End Get
            Set(value As String)
                _ContactName = value
                NotifyPropertyChanged("ContactName")
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the request date.
        ''' </summary>
        ''' <value>The request date.</value>
        Public Property RequestDate As Date
            Get
                Return _RequestDate
            End Get
            Set(value As Date)
                _RequestDate = value
                NotifyPropertyChanged("RequestDate")
            End Set
        End Property

        ''' <summary>
        ''' Gets the creditor.
        ''' </summary>
        ''' <value>The creditor.</value>
        Public ReadOnly Property Creditor As JiwaApplication.Entities.Creditor.Creditor
            Get
                Return _Creditor
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets the returns warehouse.
        ''' </summary>
        ''' <value>The returns warehouse.</value>
        Public Property ReturnsWarehouse As JiwaApplication.Inventory.Warehouse.LogicalWarehouse
            Get
                Return _ReturnsWarehouse
            End Get
            Set(ByVal Value As JiwaApplication.Inventory.Warehouse.LogicalWarehouse)
                _ReturnsWarehouse = Value
                NotifyPropertyChanged("ReturnsWarehouse")
            End Set
        End Property

        ''' <summary>
        ''' Gets the tax rates.
        ''' </summary>
        ''' <value>The tax rates.</value>
        Public ReadOnly Property TaxRates As JiwaApplication.JiwaTaxSystemRates.TaxRateCollection
            Get
                Return _TaxRates
            End Get

        End Property

        ''' <summary>
        ''' Gets the default tax rate.
        ''' </summary>
        ''' <value>The default tax rate.</value>
        Public ReadOnly Property DefaultTaxRate As JiwaApplication.JiwaTaxSystemRates.TaxRate
            Get
                Return _DefaultTaxRate
            End Get
        End Property

        ''' <summary>
        ''' Gets the default tax rate for FX.
        ''' </summary>
        ''' <value>The default tax rate.</value>
        Public ReadOnly Property DefaultFXTaxRate As JiwaApplication.JiwaTaxSystemRates.TaxRate
            Get
                Return _DefaultFXTaxRate
            End Get
        End Property

        ''' <summary>
        ''' Gets the row hash.
        ''' </summary>
        ''' <value>The row hash.</value>
        Public Property RowHash As Byte()
            Get
                Return _RowHash
            End Get
            Friend Set(value As Byte())
                _RowHash = value
                NotifyPropertyChanged("RowHash")
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the old row hash.
        ''' </summary>
        ''' <value>The old row hash.</value>
        Public Property OldRowHash As Byte()
            Get
                Return _OldRowHash
            End Get
            Set(value As Byte())
                _OldRowHash = value
                NotifyPropertyChanged("OldRowHash")
            End Set
        End Property

        ''' <summary>
        ''' Gets the lines.
        ''' </summary>
        ''' <value>The lines.</value>
        Public ReadOnly Property Lines As LineCollection
            Get
                Return _Lines
            End Get
        End Property

        ''' <summary>
        ''' Gets the system settings.
        ''' </summary>
        ''' <value>The system settings.</value>
        Public ReadOnly Property SystemSettings As SystemSettings
            Get
                Return _SystemSettings
            End Get
        End Property

        ''' <summary>
        ''' Gets the documents.
        ''' </summary>
        ''' <value>The documents.</value>
        Public ReadOnly Property Documents() As JiwaApplication.Documents.DocumentCollection Implements JiwaApplication.IJiwaDocuments.Documents
            Get
                Return _Documents
            End Get
        End Property

        ''' <summary>
        ''' Gets the notes.
        ''' </summary>
        ''' <value>The notes.</value>
        Public Property Notes() As JiwaApplication.Notes.NoteCollection Implements JiwaApplication.IJiwaNotes.Notes
            Get
                Return _Notes
            End Get
            Friend Set(value As JiwaApplication.Notes.NoteCollection)
                _Notes = value
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the journal set.
        ''' </summary>
        ''' <value>The journal set.</value>
        Public Property JournalSet As JiwaJournalSets.JournalSet
            Get
                Return _JournalSet
            End Get
            Set(value As JiwaJournalSets.JournalSet)
                _JournalSet = value
            End Set
        End Property

        ''' <summary>
        ''' Gets the purchase orders.
        ''' </summary>
        ''' <value>The purchase orders.</value>
        Public ReadOnly Property PurchaseOrders As List(Of JiwaPurchaseOrders.PurchaseOrder)
            Get
                Return _PurchaseOrders
            End Get
        End Property

        ''' <summary>
        ''' Gets the shipping collection.
        ''' </summary>
        ''' <value>The shipping collection.</value>
        Public ReadOnly Property ShippingCollection As ShippingCollection
            Get
                Return _ShippingCollection
            End Get
        End Property

        ''' <summary>
        ''' Gets the credits.
        ''' </summary>
        ''' <value>The credits.</value>
        Public ReadOnly Property Credits As CreditCollection
            Get
                Return _Credits
            End Get
        End Property

        Public ReadOnly Property CustomFields() As JiwaApplication.CustomFields.CustomFieldCollection Implements JiwaApplication.IJiwaCustomFields.CustomFields
            Get
                Return _CustomFields
            End Get
        End Property

        Public Property CustomFieldValues As JiwaApplication.CustomFields.CustomFieldValueCollection Implements JiwaApplication.IJiwaCustomFieldValues.CustomFieldValues
            Get
                Return _CustomFieldValues
            End Get
            Set(value As JiwaApplication.CustomFields.CustomFieldValueCollection)
                _CustomFieldValues = value
            End Set
        End Property

        Public ReadOnly Property LineCustomFields() As JiwaApplication.CustomFields.CustomFieldCollection
            Get
                Return _LineCustomFields
            End Get
        End Property
#End Region

#Region "Methods"
        ''' <summary>
        ''' Initializes a new instance of the <see cref="Request"/> class.
        ''' </summary>
        Public Sub New()
            MyBase.New()
            MyBase.ClientClassName = "JiwaFinancials.Jiwa.JiwaSupplierReturnsUI.Request.Request"

            LogicalWarehouseResidingIn = New JiwaApplication.Entities.LogicalWarehouse
            LogicalWarehouseResidingIn.ReadRecord(JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.IN_LogicalID)
            WarehouseColumnName = "WarehouseID"

            _ReturnsWarehouse = JiwaApplication.Manager.Instance.CurrentLogicalWarehouse
            _TaxRates = JiwaApplication.Manager.Instance.TaxRates.GSTRatesAdjIN

            For Each taxRate As JiwaApplication.JiwaTaxSystemRates.TaxRate In TaxRates
                If taxRate.IsDefaultRateInGroup Then
                    _DefaultTaxRate = taxRate
                    Exit For
                End If
            Next

            For Each taxRate As JiwaApplication.JiwaTaxSystemRates.TaxRate In TaxRates
                If taxRate.BASCode = 0 Then
                    _DefaultFXTaxRate = taxRate
                    Exit For
                End If
            Next

            _ReturnCode = New Entities.ReturnCode
            _CreatedBy = New JiwaApplication.Entities.Staff.Staff
            _DeliveryAddress = New JiwaApplication.Entities.Address

            SortOrders.Add(New JiwaApplication.IJiwaNavigable.SortKey With {.Description = "Request No.", .FieldName = "RA_RequestMain.RequestNo"})

            _Documents = New JiwaApplication.Documents.DocumentCollection("RA_RequestDocuments", "RA_RequestMain_RecID", "JiwaFinancials.Jiwa.JiwaSupplierReturns")
            _Notes = New JiwaApplication.Notes.NoteCollection("RA_RequestNotes", "RA_RequestMain_RecID", "JiwaFinancials.Jiwa.JiwaSupplierReturns")

            _CustomFields = New JiwaApplication.CustomFields.CustomFieldCollection(JiwaApplication.Manager.Instance.PluginCollection.CustomFieldModuleCollection.GetItem("ModuleName", "Supplier Return Request"), Me)
            _CustomFieldValues = New JiwaApplication.CustomFields.CustomFieldValueCollection(_CustomFields)
            _LineCustomFields = New JiwaApplication.CustomFields.CustomFieldCollection(JiwaApplication.Manager.Instance.PluginCollection.CustomFieldModuleCollection.GetItem("ModuleName", "Supplier Return Request Line"), Me)

            _SystemSettings = New SystemSettings
            _SystemSettings.Read()

            _JournalSet = JiwaApplication.BusinessLogicFactory.Instance.CreateBusinessLogic(Of JiwaJournalSets.JournalSet)(Nothing)
            _Creditor = New JiwaApplication.Entities.Creditor.Creditor
            _Lines = New LineCollection(Me)
            _PurchaseOrders = New List(Of JiwaPurchaseOrders.PurchaseOrder)
            _ShippingCollection = New ShippingCollection(Me)
            _Credits = New CreditCollection(Me)
        End Sub

        ''' <summary>
        ''' Setups this instance.
        ''' </summary>
        Public Overrides Sub Setup()

        End Sub

        ''' <summary>
        ''' Clears this instance.
        ''' </summary>
        Public Overrides Sub Clear()
            OnClearStart()

            RequestNo = ""
            Reference = ""
            ContactName = ""

            _CreatedBy.ReadRecord(JiwaApplication.Manager.Instance.Staff.RecID)
            _ReturnsWarehouse = JiwaApplication.Manager.Instance.CurrentLogicalWarehouse

            Status = Statuses.Open
            _OriginalStatus = Status
            ReturnCode.ReadDefault()
            DeliveryAddress.Clear()
            RequestDate = JiwaApplication.Manager.Instance.SysDateTime
            Creditor.Clear()

            LastSavedDateTime = Now

            RowHash = Nothing
            OldRowHash = Nothing

            Lines.Clear()
            _Documents.Clear()
            _Notes.Clear()
            _PurchaseOrders.Clear()
            _ShippingCollection.Clear()
            _Credits.Clear()
            _CustomFieldValues.Clear()

            OnClearEnd()
        End Sub

        ''' <summary>
        ''' Copies this instance.
        ''' </summary>
        ''' <exception cref="System.NotImplementedException"></exception>
        Public Overrides Sub Copy()
            Throw New NotImplementedException
        End Sub

        ''' <summary>
        ''' Creates the new.
        ''' </summary>
        Public Overrides Sub CreateNew()
            Clear()
            OnCreateStart()
            RecID = JiwaApplication.Manager.Instance.Database.NewGUID

            InsertFlag = True
            ChangeFlag = True

            _CustomFieldValues.SetupForNewRecord()

            OnCreateEnd()
        End Sub

        ''' <summary>
        ''' Deletes this instance.
        ''' </summary>
        Public Overrides Sub Delete()
            Me.DeleteFlag = True
            Lines.RemoveAll()
            Documents.RemoveAll()
            Notes.RemoveAll()
            Save()
        End Sub

        ''' <summary>
        ''' Reads the specified record identifier.
        ''' </summary>
        ''' <param name="RecID">The record identifier.</param>
        ''' <exception cref="JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException">Supplier Return Request Not Found</exception>
        Public Overrides Sub Read(RecID As String)
            Dim SQL As String = ""
            Dim SQLReader As SqlDataReader = Nothing
            Dim SQLParam As SqlParameter = Nothing
            Dim oldReading As Boolean = IsReading

            Try
                IsReading = True

                With JiwaApplication.Manager.Instance.Database

                    OnReadStart()

                    Clear()

                    SQL = "SELECT TOP 1 RecID, RequestNo, Reference, WarehouseID, Status, LastSavedDateTime, CreatedBy, ReturnCode, DeliveryAddressee, DeliveryStreetAddress1, DeliveryStreetAddress2, DeliveryLocality, DeliveryRegion, DeliveryPostCode, DeliveryCountry, DeliveryTelephone, DeliveryFacsimile, ContactName, Note, CourierDetails, RequestDate, CreditorID, ReturnsWarehouseID, RowHash " &
                            " FROM RA_RequestMain " &
                            " WHERE RecID = @RecID "

                    Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
                        SQLCmd.CommandTimeout = JiwaApplication.Manager.Instance.Database.DefaultCommandTimeout

                        SQLParam = New SqlParameter("@RecID", System.Data.SqlDbType.Char)
                        SQLParam.Value = RecID
                        SQLCmd.Parameters.Add(SQLParam)

                        SQLReader = SQLCmd.ExecuteReader()

                        If SQLReader.Read = True Then
                            LogicalWarehouseResidingIn.ReadRecord(.Sanitise(SQLReader, "WarehouseID"))
                            Me.RecID = .Sanitise(SQLReader, "RecID")
                            RequestNo = .Sanitise(SQLReader, "RequestNo")
                            Reference = .Sanitise(SQLReader, "Reference")
                            Status = .Sanitise(SQLReader, "Status")
                            _OriginalStatus = Status
                            LastSavedDateTime = .Sanitise(SQLReader, "LastSavedDateTime")
                            CreatedBy.ReadRecord(.Sanitise(SQLReader, "CreatedBy"))
                            ReturnCode.ReadRecord(.Sanitise(SQLReader, "ReturnCode"))

                            Creditor.ReadRecord(.Sanitise(SQLReader, "CreditorID")) ' Need to read creditor before the delivery address info as it will set the delivery address to be the creditor default.

                            DeliveryAddress.Addressee = .Sanitise(SQLReader, "DeliveryAddressee")
                            DeliveryAddress.StreetAddress1 = .Sanitise(SQLReader, "DeliveryStreetAddress1")
                            DeliveryAddress.StreetAddress2 = .Sanitise(SQLReader, "DeliveryStreetAddress2")
                            DeliveryAddress.Locality = .Sanitise(SQLReader, "DeliveryLocality")
                            DeliveryAddress.Region = .Sanitise(SQLReader, "DeliveryRegion")
                            DeliveryAddress.Postcode = .Sanitise(SQLReader, "DeliveryPostCode")
                            DeliveryAddress.Country = .Sanitise(SQLReader, "DeliveryCountry")
                            DeliveryAddress.Telephone = .Sanitise(SQLReader, "DeliveryTelephone")
                            DeliveryAddress.Facsimile = .Sanitise(SQLReader, "DeliveryFacsimile")

                            ContactName = .Sanitise(SQLReader, "ContactName")
                            DeliveryAddress.Notes = .Sanitise(SQLReader, "Note")
                            DeliveryAddress.CourierDetails = .Sanitise(SQLReader, "CourierDetails")
                            RequestDate = .Sanitise(SQLReader, "RequestDate")

                            ReturnsWarehouse = JiwaApplication.Manager.Instance.PhysicalWarehouseCollection.FindLogicalWarehouse(.Sanitise(SQLReader, "ReturnsWarehouseID"))
                            RowHash = .Sanitise(SQLReader, "RowHash")

                            OldRowHash = RowHash

                        Else
                            Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException("Supplier Return Request Not Found")
                        End If
                        SQLReader.Close()
                    End Using

                End With

                If Not SQLReader Is Nothing Then
                    SQLReader.Close()
                End If

                Lines.Read()
                ShippingCollection.Read()
                Credits.Read()
                _Documents.Read(MyBase.RecID)
                _Notes.Read(MyBase.RecID)
                _CustomFieldValues.Read(MyBase.RecID)

                OnReadEnd()

            Finally
                If Not SQLReader Is Nothing Then
                    SQLReader.Close()
                End If
                IsReading = oldReading
            End Try
        End Sub

        ''' <summary>
        ''' Deserialises the specified XML string.
        ''' </summary>
        ''' <param name="XMLString">The XML string.</param>
        Public Overrides Sub Deserialise(XMLString As String)

        End Sub

        ''' <summary>
        ''' Serialises the specified XML.
        ''' </summary>
        ''' <param name="XML">The XML.</param>
        Public Overrides Sub Serialise(ByRef XML As String)

        End Sub

        ''' <summary>
        ''' Saves this instance.
        ''' </summary>
        ''' <exception cref="System.Exception">Request Number already exists. Use another number, or leave the field blank for the system to provide one for you.</exception>
        ''' <exception cref="JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ConcurrencyConflictException">
        ''' Unable to  delete from, update table RA_RequestMain
        ''' or
        ''' Unable to delete from table RA_RequestMain
        ''' </exception>
        Public Overrides Sub Save()
            Dim SQL As String = ""
            Dim SQLParam As SqlParameter = Nothing
            Dim SQLReader As SqlDataReader = Nothing
            Dim weStartedTransaction As Boolean

            With JiwaApplication.Manager.Instance.Database
                Try
                    If .SQLTransaction Is Nothing Then
                        ' flag that we created the transaction, so we know if we should be the ones to .commit or .rollback later.
                        .BeginNewTransaction()
                        weStartedTransaction = True
                    End If

                    OnSaveStart()

                    If Not DeleteFlag Then

                        If InsertFlag Then

                            If RequestNo Is Nothing OrElse RequestNo.Trim.Length = 0 Then
                                ' System to generate Bill No.
                                RequestNo = JiwaApplication.Manager.GetSystemNumber("RARequestNo")
                            Else
                                ' User supplied invoice number
                                ' Check if doesn't exist
                                Try
                                    SQL = "SELECT TOP 1 RequestNo FROM RA_RequestMain WHERE RequestNo = @RequestNo"

                                    Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
                                        SQLCmd.CommandTimeout = JiwaApplication.Manager.Instance.Database.DefaultCommandTimeout

                                        SQLParam = New SqlParameter("@RequestNo", System.Data.SqlDbType.VarChar)
                                        SQLParam.Value = RequestNo
                                        SQLCmd.Parameters.Add(SQLParam)

                                        SQLReader = SQLCmd.ExecuteReader()

                                        If SQLReader.Read = True Then
                                            Throw New Exception("Request Number already exists. Use another number, or leave the field blank for the system to provide one for you.")
                                        End If

                                        SQLReader.Close()
                                    End Using

                                Finally
                                    If Not SQLReader Is Nothing Then
                                        SQLReader.Close()
                                    End If
                                End Try
                            End If

                            SQL = "DECLARE @Output TABLE (RowHash varbinary(8) NOT NULL) INSERT INTO RA_RequestMain (RecID, RequestNo, Reference, WarehouseID, Status, LastSavedDateTime, CreatedBy, ReturnCode, DeliveryAddressee, DeliveryStreetAddress1, DeliveryStreetAddress2, DeliveryLocality, DeliveryRegion, DeliveryPostCode, DeliveryCountry, DeliveryTelephone, DeliveryFacsimile, ContactName, Note, CourierDetails, RequestDate, CreditorID, ReturnsWarehouseID) " &
                                "OUTPUT Inserted.RowHash INTO @Output VALUES (" &
                                "@RecID " &
                                ", @RequestNo" &
                                ", @Reference" &
                                ", @WarehouseID" &
                                ", @Status" &
                                ", @LastSavedDateTime" &
                                ", @CreatedBy" &
                                ", @ReturnCode" &
                                ", @DeliveryAddressee" &
                                ", @DeliveryStreetAddress1" &
                                ", @DeliveryStreetAddress2" &
                                ", @DeliveryLocality" &
                                ", @DeliveryRegion" &
                                ", @DeliveryPostCode" &
                                ", @DeliveryCountry" &
                                ", @DeliveryTelephone" &
                                ", @DeliveryFacsimile" &
                                ", @ContactName" &
                                ", @Note" &
                                ", @CourierDetails" &
                                ", @RequestDate" &
                                ", @CreditorID" &
                                ", @ReturnsWarehouseID" &
                                ") SELECT TOP 1 RowHash FROM @Output"
                        Else
                            ' Update sales order
                            SQL = "DECLARE @Output TABLE (RowHash varbinary(8) NOT NULL) UPDATE RA_RequestMain SET " &
                                "RequestNo = @RequestNo" &
                                ", Reference = @Reference" &
                                ", WarehouseID = @WarehouseID" &
                                ", Status = @Status" &
                                ", LastSavedDateTime = @LastSavedDateTime" &
                                ", ReturnCode = @ReturnCode" &
                                ", DeliveryAddressee = @DeliveryAddressee" &
                                ", DeliveryStreetAddress1 = @DeliveryStreetAddress1" &
                                ", DeliveryStreetAddress2 = @DeliveryStreetAddress2" &
                                ", DeliveryLocality = @DeliveryLocality" &
                                ", DeliveryRegion = @DeliveryRegion" &
                                ", DeliveryPostCode = @DeliveryPostCode" &
                                ", DeliveryCountry = @DeliveryCountry" &
                                ", DeliveryTelephone = @DeliveryTelephone" &
                                ", DeliveryFacsimile = @DeliveryFacsimile" &
                                ", ContactName = @ContactName" &
                                ", Note = @Note" &
                                ", CourierDetails = @CourierDetails" &
                                ", RequestDate = @RequestDate" &
                                ", CreditorID = @CreditorID" &
                                ", ReturnsWarehouseID = @ReturnsWarehouseID"

                            SQL = SQL & " OUTPUT Inserted.RowHash INTO @Output WHERE RecID = @RecID" &
                                        " AND RowHash = @RowHash SELECT TOP 1 RowHash FROM @Output"
                        End If

                        Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
                            SQLCmd.CommandTimeout = JiwaApplication.Manager.Instance.Database.DefaultCommandTimeout

                            SQLParam = New SqlParameter("@RecID", System.Data.SqlDbType.Char)
                            SQLParam.Value = RecID
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@RequestNo", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = RequestNo
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@Reference", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = Reference
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@WarehouseID", System.Data.SqlDbType.Char)
                            SQLParam.Value = LogicalWarehouseResidingIn.IN_LogicalID
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@Status", System.Data.SqlDbType.TinyInt)
                            SQLParam.Value = Status
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@LastSavedDateTime", System.Data.SqlDbType.DateTime)
                            SQLParam.Value = JiwaApplication.Manager.Instance.Database.ServerDateTime
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@CreatedBy", System.Data.SqlDbType.Char)
                            SQLParam.Value = CreatedBy.StaffID
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@ReturnCode", System.Data.SqlDbType.Char)
                            SQLParam.Value = ReturnCode.RecID
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryAddressee", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Addressee
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryStreetAddress1", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.StreetAddress1
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryStreetAddress2", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.StreetAddress2
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryLocality", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Locality
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryRegion", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Region
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryPostCode", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Postcode
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryCountry", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Country
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryTelephone", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Telephone
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@DeliveryFacsimile", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Facsimile
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@ContactName", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = ContactName
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@Note", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.Notes
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@CourierDetails", System.Data.SqlDbType.VarChar)
                            SQLParam.Value = DeliveryAddress.CourierDetails
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@RequestDate", System.Data.SqlDbType.DateTime)
                            SQLParam.Value = RequestDate
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@CreditorID", System.Data.SqlDbType.Char)
                            SQLParam.Value = Creditor.CreditorID
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@ReturnsWarehouseID", System.Data.SqlDbType.Char)
                            SQLParam.Value = ReturnsWarehouse.IN_LogicalID
                            SQLCmd.Parameters.Add(SQLParam)

                            If InsertFlag = False Then
                                SQLParam = New SqlParameter("@RowHash", System.Data.SqlDbType.Timestamp)
                                SQLParam.Value = RowHash
                                SQLCmd.Parameters.Add(SQLParam)
                            End If

                            Try
                                SQLReader = SQLCmd.ExecuteReader(CommandBehavior.SingleRow)

                                If SQLReader.Read = True Then
                                    RowHash = .Sanitise(SQLReader, "RowHash")
                                Else
                                    Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ConcurrencyConflictException("Unable to " & IIf(InsertFlag, "insert into", IIf(DeleteFlag, "delete from", "update")) & " table RA_RequestMain with Request No. [" & RequestNo & "], RecID [" & RecID & "]")
                                End If
                            Finally
                                If Not SQLReader Is Nothing Then
                                    SQLReader.Close()
                                End If
                            End Try

                        End Using

                        If Status = Statuses.Activated AndAlso _OriginalStatus = Statuses.Open AndAlso Not ReturnsWarehouse.Equals(JiwaApplication.Manager.Instance.PhysicalWarehouseCollection.FindLogicalWarehouse(LogicalWarehouseResidingIn.IN_LogicalID)) Then
                            ' Move the stock to the returns warehouse.
                            Dim items As New List(Of Line)

                            For Each Line As Line In Lines
                                If Line.ReturnCode.ValueInStock AndAlso Line.QuantityTaken > 0 Then
                                    items.Add(Line)
                                End If
                            Next

                            If items.Count > 0 Then
                                Dim warehouseTransfer As JiwaWhouseTransfer.clsWarehouseTransfer = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaWhouseTransfer.clsWarehouseTransfer)(Nothing)
                                warehouseTransfer.TransferMode = JiwaWhouseTransfer.clsWarehouseTransfer.WarehouseTransferMode.e_WarehouseTransferModeTransferOut
                                warehouseTransfer.CreateNew()
                                warehouseTransfer.InTransit = False
                                warehouseTransfer.SourceWarehouseID = LogicalWarehouseResidingIn.IN_LogicalID
                                warehouseTransfer.DestinationWarehouseID = ReturnsWarehouse.IN_LogicalID
                                warehouseTransfer.Notes = String.Format("Transfer to returns warehouse for supplier return request {0}", RequestNo)
                                warehouseTransfer.SourceID = Me.RecID
                                warehouseTransfer.TransferDate = Me.RequestDate
                                warehouseTransfer.SourceType = JiwaWhouseTransfer.clsWarehouseTransfer.WarehouseTransferSourceTypes.e_WarehouseTransferSourceSupplierReturnRequest
                                warehouseTransfer.Reference = RequestNo

                                For Each item As Line In items
                                    If warehouseTransfer.AddTransferLine(item.Inventory.InventoryID, item.QuantityTaken, warehouseTransfer.TransferLines.Count + 1) = JiwaWhouseTransfer.clsWarehouseTransfer.WarehouseTransferReturnCodes.e_WarehouseTransferReturnCodeSuccess Then
                                        For Each lineDetail As JiwaApplication.Inventory.SOH.LineDetail(Of Line) In item.LineDetails
                                            warehouseTransfer.TransferLines(warehouseTransfer.TransferLines.Count).LineDetails.Add("", lineDetail.Quantity, 0, lineDetail.Cost, lineDetail.SerialNo, "", lineDetail.IN_SOH_LinkID, lineDetail.BinLocation.Description, lineDetail.DateIn, lineDetail.ExpiryDate, lineDetail.SpecialPrice, "", lineDetail.Cost, lineDetail.Quantity, lineDetail.SerialNo, lineDetail.BinLocation.Description, lineDetail.ExpiryDate, 0)
                                        Next
                                    End If
                                Next

                                warehouseTransfer.ActivateRecord(, True)
                            End If
                        End If
                    End If

                    Lines.Save()
                    Documents.Save(MyBase.RecID)
                    Notes.Save(MyBase.RecID)
                    _CustomFieldValues.Save(MyBase.RecID)

                    If DeleteFlag Then
                        SQL = "DELETE FROM RA_RequestMain "
                        SQL = SQL & " WHERE RecID = @RecID" &
                                    " AND RowHash = @RowHash"

                        Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
                            SQLCmd.CommandTimeout = JiwaApplication.Manager.Instance.Database.DefaultCommandTimeout
                            SQLParam = New SqlParameter("@RecID", System.Data.SqlDbType.Char)
                            SQLParam.Value = RecID
                            SQLCmd.Parameters.Add(SQLParam)

                            SQLParam = New SqlParameter("@RowHash", System.Data.SqlDbType.Timestamp)
                            SQLParam.Value = RowHash
                            SQLCmd.Parameters.Add(SQLParam)

                            If SQLCmd.ExecuteNonQuery() = 0 Then
                                Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ConcurrencyConflictException("Unable to delete from table RA_RequestMain with Request No. [" & RequestNo & "], RecID [" & RecID & "]")
                            End If
                        End Using

                    End If

                    OnSaveEnding()

                    If weStartedTransaction Then
                        .Commit()
                    End If

                    OnSaveEnd()

                Catch ex As Exception
                    If weStartedTransaction AndAlso Not JiwaApplication.Manager.Instance.Database.SQLTransaction Is Nothing AndAlso Not JiwaApplication.Manager.Instance.Database.SQLTransaction.Connection Is Nothing Then
                        JiwaApplication.Manager.Instance.Database.SQLTransaction.Rollback()
                        JiwaApplication.Manager.Instance.Database.SQLTransaction.Dispose()
                        JiwaApplication.Manager.Instance.Database.SQLTransaction = Nothing
                    End If

                    RowHash = OldRowHash
                    Lines.RollBack()

                    Throw
                End Try
            End With

        End Sub

        Public Sub Search(OwnerForm As System.Windows.Forms.Form, Optional FilterSQL As String = "")
            With JiwaApplication.Manager.Instance.Search
                .Clear()
                FilterSQL += If(FilterSQL.Trim.Length > 0, " AND ", "") + TableName + "." + WarehouseColumnName + " = '" + LogicalWarehouseResidingIn.RecID + "' "
                .SQLWhereCondition = " WHERE " + FilterSQL
                .SetDefaultSearch(JiwaApplication.JiwaSearch.clsSearch.SearchModes.jswSupplierReturnRequest)
                If .Show(OwnerForm) = System.Windows.Forms.DialogResult.OK Then
                    If .Results.Count > 0 Then
                        Read(.Fields(1).FieldValue)
                    End If
                Else
                    Throw New JiwaApplication.Exceptions.ClientCancelledException
                End If
            End With
        End Sub
#End Region

#Region "Event Handlers"

        Private Sub _Creditor_Cleared() Handles _Creditor.Cleared

        End Sub

        Private Sub _Creditor_Read() Handles _Creditor.Read
            Dim address As JiwaApplication.Entities.Address = Creditor.ReadDefaultWarehouseAddress()

            DeliveryAddress.StreetAddress1 = address.StreetAddress1
            DeliveryAddress.StreetAddress2 = address.StreetAddress2
            DeliveryAddress.Locality = address.Locality
            DeliveryAddress.Region = address.Region
            DeliveryAddress.Postcode = address.Postcode
            DeliveryAddress.Country = address.Country
            DeliveryAddress.Notes = address.Notes
            DeliveryAddress.CourierDetails = address.CourierDetails
        End Sub

        Private Sub _Lines_Added(item As Line) Handles _Lines.Added
            NotifyPropertyChanged("Lines")
        End Sub

        Private Sub _Lines_Changed(item As Line, e As ComponentModel.PropertyChangedEventArgs) Handles _Lines.Changed
            NotifyPropertyChanged("Lines")
        End Sub

        Private Sub _Lines_Removed(item As Line) Handles _Lines.Removed
            NotifyPropertyChanged("Lines")
        End Sub

        Private Sub _DeliveryAddress_PropertyChanged(sender As Object, e As ComponentModel.PropertyChangedEventArgs) Handles _DeliveryAddress.PropertyChanged
            NotifyPropertyChanged(e.PropertyName)
        End Sub

        Private Sub _ReturnCode_Read() Handles _ReturnCode.Read
            NotifyPropertyChanged("ReturnCode")
        End Sub

        Private Sub _Documents_Added(item As JiwaApplication.Documents.Document) Handles _Documents.Added
            NotifyPropertyChanged("Documents")
        End Sub

        Private Sub _Documents_Changed(item As JiwaApplication.Documents.Document, e As System.ComponentModel.PropertyChangedEventArgs) Handles _Documents.Changed
            NotifyPropertyChanged("Documents")
        End Sub

        Private Sub _Documents_Removed(item As JiwaApplication.Documents.Document) Handles _Documents.Removed
            NotifyPropertyChanged("Documents")
        End Sub

        Private Sub _Notes_Added(item As JiwaApplication.Notes.Note) Handles _Notes.Added
            NotifyPropertyChanged("Notes")
        End Sub

        Private Sub _Notes_Changed(item As JiwaApplication.Notes.Note, e As System.ComponentModel.PropertyChangedEventArgs) Handles _Notes.Changed
            NotifyPropertyChanged("Notes")
        End Sub

        Private Sub _Notes_Removed(item As JiwaApplication.Notes.Note) Handles _Notes.Removed
            NotifyPropertyChanged("Notes")
        End Sub

        Private Sub _CustomFieldValues_Added(item As JiwaApplication.CustomFields.CustomFieldValue) Handles _CustomFieldValues.Added
            NotifyPropertyChanged("CustomFieldValues")
        End Sub

        Private Sub _CustomFieldValues_Changed(item As JiwaApplication.CustomFields.CustomFieldValue, e As ComponentModel.PropertyChangedEventArgs) Handles _CustomFieldValues.Changed
            NotifyPropertyChanged("CustomFieldValues")
        End Sub

        Private Sub _CustomFieldValues_Removed(item As JiwaApplication.CustomFields.CustomFieldValue) Handles _CustomFieldValues.Removed
            NotifyPropertyChanged("CustomFieldValues")
        End Sub

        Private Sub _Lines_CustomFieldValueChanged(Item As JiwaApplication.IJiwaLineCustomFieldValues, CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Handles _Lines.CustomFieldValueChanged
            NotifyPropertyChanged("Lines")
        End Sub
#End Region

        Public Property LogicalWarehouseResidingIn As JiwaApplication.Entities.LogicalWarehouse Implements JiwaApplication.IJiwaWarehouseFiltering.LogicalWarehouseResidingIn

        Public Property WarehouseColumnName As String Implements JiwaApplication.IJiwaWarehouseFiltering.WarehouseColumnName
    End Class
End Namespace


One final thing you would need to do to enable the Business Logic factory to create your object using the class name (rather than the type), is to add an entry to the SY_BusinessLogic table.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: New Business Logic Entities

Postby SBarnes » Sat Dec 19, 2015 8:03 am

Hi Mike,

Thanks for the reply sorry for the delay in coming back to this, this explains exactly what I needed, but one other questions I have is there a way to the plug the new business object into Jiwa's security?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: New Business Logic Entities

Postby Mike.Sheen » Sat Dec 19, 2015 10:55 am

SBarnes wrote:is there a way to the plug the new business object into Jiwa's security?


Currently security is managed by default at the UI level. If you have a form using your business logic, then the security/permissions system in Jiwa can control who is allowed to load that form automatically. If a user uses an application which uses the Jiwa business logic (eg: 3rd party developed application) then there is no automatic permission controls.

You can, however create an abstract permission and have your business logic check the current user has that permission on instantiation or setup of the business logic - or any other method when invoked. That way you can enforce permissions purely on the business logic level.

An example is the abstract permission in the sales order business logic to control who can process a sales order:

Code: Select all
Dim processPermission As JiwaApplication.Security.UserGroup.AccessLevels = JiwaApplication.Manager.Instance.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "Process")

If processPermission <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
    Throw New JiwaApplication.Exceptions.PermissionDeniedException("You do not have the required permission to process a sales order")
End If


The above code is in the Process method of the sales order business logic class. It is looking at an abstract permission for the form which has a class name of "JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", and the permission name is "Process".

To set the permission you need to edit the permissions for the sales order form - open the sales order form, on the utilities tab choose set permissions and then on the permission dialog on the abstract permissions tab you will see those permissions.

So, you could use the above to have your own business logic permissions for your own object - if you have a form for your business logic, then you obviously should put it there. If you don't have a form, then it really doesn't matter where you place the abstract permission - you can add it to any existing form - you just need a form which has an entry in the table SY_Forms so you have a way in the user interface to set the permissions.

To add your own abstract permission you need to perform a SQL insert into the SY_FormsAbstractPermissions table. For example - if you wanted to add one to sales orders - then you would do this:

Code: Select all
INSERT INTO SY_FormsAbstractPermissions(RecID, SY_Forms_ClassName, Name, Description, ItemNo)
SELECT NewID(), 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm', 'My Permission', 'My test permission',
(SELECT COALESCE(MAX(ItemNo), 0) + 1 FROM SY_FormsAbstractPermissions WHERE SY_Forms_ClassName = 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm')


Now if you load the permissions dialog you will see that permission in the abstract permissions list (you will need to logout and log back into Jiwa after running the above query) and you can set the permission each user group has for that.

Then in your business logic, you can do a check like the following to control what methods the user can invoke:
Code: Select all
Dim myPermission As JiwaApplication.Security.UserGroup.AccessLevels = JiwaApplication.Manager.Instance.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "My Permission")

If myPermission <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
    Throw New JiwaApplication.Exceptions.PermissionDeniedException("You do not have permission")
End If


You can also do this in the constructor (New sub in VB.Net) to cause an exception on instantiation to completely prevent use of the object. Then, when you attempt to create your object using the business logic factory (or when they invoke a method in which you throw a PermissionDeniedException), you can selectively deal with insufficient permissions by catching the PermissionDeniedException.

Code: Select all
Try
    myBL = JiwaApplication.BusinessLogicFactory.Instance.CreateBusinessLogic(Of MyNS.MyClass)(Nothing)
Catch permissionDenied As JiwaApplication.Exceptions.PermissionDeniedException
   ' gracefully handle a no-permission exception
End Try


I hope that all makes sense!

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: New Business Logic Entities

Postby SBarnes » Sat Dec 19, 2015 11:46 am

Hi Mike,

Thanks for the reply I am assuming you sql to max + 1 to set the item number is what should also be done in SY_BusinessLogic as I was unsure on the field there?

One other question in this area is it possible to use one of the current built in business objects and extend or override some of its behavour or are the objects "sealed" ?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: New Business Logic Entities

Postby Mike.Sheen » Sat Dec 19, 2015 11:56 am

SBarnes wrote:Thanks for the reply I am assuming you sql to max + 1 to set the item number is what should also be done in SY_BusinessLogic as I was unsure on the field there?


Yes - we have a unique index on ItemNo, so the only way to guarantee your insert into SY_BusinessLogic succeeds would be to use MAX(ItemNo) + 1

SBarnes wrote:One other question in this area is it possible to use one of the current built in business objects and extend or override some of its behavour or are the objects "sealed" ?


You can inherit from our business logic and extend it. However, our forms will use our implementation - we don't have a dependency injection framework yet - so if you inherit from say our sales order object, our sales order form will only know about our implementation and yours will be ignored.

What is it you are trying to achieve? Most behaviours can be extended or overridden by using a plugin to hook into events - that would be the recommended way to go until we work out dependency injection in the Jiwa framework.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: New Business Logic Entities

Postby SBarnes » Sat Dec 19, 2015 12:14 pm

Hi Mike,

The behaviour I was looking at overwriting was the process on an order in certain instances but at other times to follow the normal behaviour.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: New Business Logic Entities

Postby Mike.Sheen » Sat Dec 19, 2015 1:17 pm

SBarnes wrote:Hi Mike,

The behaviour I was looking at overwriting was the process on an order in certain instances but at other times to follow the normal behaviour.


The ProcessingStart event is fired at the start of processing - you could add a handler for that, and then under your desired conditions do your own actions and then throw a JiwaApplication.Exceptions.ClientCancelledException - this will cause the normal processing to abort and no error will be reported to the user.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: New Business Logic Entities

Postby SBarnes » Sun Dec 20, 2015 7:09 am

Thanks Mike for the help.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: New Business Logic Entities

Postby SBarnes » Thu May 19, 2016 6:32 pm

Hi Mike,

Revisiting the topic of creating business entities and help you provided before for a different project and I have two questions:

1. In creating a business entity I noticed that all properties implement Notify Property changed, I would assume this is so that the entity can be bound to the the Infragistics controls but is this mandatory on all properties i.e. if something is not going to be bound to a control does it need to do so?

2. In creating a form that would inherit from JiwaFinancials.Jiwa.JiwaApplication.Forms.Maintenance, can you review the steps I have identified to hook it up to the Jiwa framework, these steps I already have worked out from looking at the Magento Plug in as you suggested previously are:

A. Add the code created by the designer to the bottom on the plugin
B. Make sure the class for the form has a constructor that calls Initializecomponent
C. Override Setup making sure to call base.setup and setupwindow
D. Override SetupBeforeHandlers and set the MDIParent and set the forms BusinessLogic property to an instance of of the new entity
E. Add the plugin under forms maintenance and add a menu item to the form /plugin

Is there anything I've missed?

3. Could you also provide an example or insight into implementing IJiwaCollectionItem as the entity I am creating will have lines as well and for consistency I would like to try and use the Jiwa Collection properly. The related collection code would also help.

Thanks.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests