Purchase Order - extra field  Topic is solved

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

Purchase Order - extra field

Postby neil.interactit » Thu Sep 03, 2015 11:44 am

Hi guys,

I have a requirement to add a new field to the "main" section of a purchase order and to save the value with the purchase order ...

poextrafield.png


I suspect this has already been explained elsewhere, but I have not been able to solve this trawling through existing posts.

Thanks in advance,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Purchase Order - extra field

Postby Scott.Pearce » Thu Sep 03, 2015 2:16 pm

This should get you on your way. Create a new plugin, enabled it, and add class JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders to the "Forms" tab (this tells the plugin to load when we use the purchase order form and also adds the references we need to talk to the purchase order form).

Also add a Custom field called "CreditorInvoiceNumber" to the "Purchase Order" module on the "Custom Fields" tab. Our control will sync with this field, so that we don't have to worry about the reading and saving of the value. I'm lazy.

Please excuse my use of VB, I tend to revert to my native tongue when in a hurry :-)

On the "Code" tab, FormPlugin class, Setup:

Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      If TypeOf(JiwaForm) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
         Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(JiwaForm, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)
         purchaseOrderForm_Load(purchaseOrderForm, New System.EventArgs)
      End If      
    End Sub


The purchaseOrderForm_Load function creates the new controls and adds some handlers:

Code: Select all
   Public Sub purchaseOrderForm_Load(sender As Object, e As System.EventArgs)
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
         Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(sender, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)
         
         'Create a lable control and set it up
         Dim CreditorInvoiceNumberUltraLabel As New Infragistics.Win.Misc.UltraLabel
         CreditorInvoiceNumberUltraLabel.Text = "Creditor invoice number"
         CreditorInvoiceNumberUltraLabel.Width = 130
         CreditorInvoiceNumberUltraLabel.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle
         
         Dim CreditorInvoiceNumberUltraTextBox As New Infragistics.Win.UltraWinEditors.UltraTextEditor
         CreditorInvoiceNumberUltraTextBox.Width = 130
         CreditorInvoiceNumberUltraTextBox.Name = "CreditorInvoiceNumberUltraTextBox"
         
         'Add it to the form
         purchaseOrderForm.HeaderUltraExpandableGroupBoxPanel.Controls.Add(CreditorInvoiceNumberUltraLabel) 'A neat way to figure out the parent control (HeaderUltraExpandableGroupBoxPanel) is to open the purhcase order form, then go into permission mode.  Clicking on the form then reveals the underlying control names on the Set Permissions dialog.
         CreditorInvoiceNumberUltraLabel.Location = New System.Drawing.Point (600, PurchaseOrderForm.ReceivedGRNsJiwaGrid.Location.Y)
         purchaseOrderForm.HeaderUltraExpandableGroupBoxPanel.Controls.Add(CreditorInvoiceNumberUltraTextBox)
         CreditorInvoiceNumberUltraTextBox.Location = New System.Drawing.Point (CreditorInvoiceNumberUltraLabel.Location.X + CreditorInvoiceNumberUltraLabel.Width, CreditorInvoiceNumberUltraLabel.Location.Y)
         
         'Add some handlers
         AddHandler CreditorInvoiceNumberUltraTextBox.Validated, AddressOf CreditorInvoiceNumberUltraTextBox_Validated
         AddHandler purchaseOrderForm.PurchaseOrder.PropertyChanged, AddressOf PurchaseOrder_PropertyChanged
         AddHandler purchaseOrderForm.PurchaseOrder.CreateEnd, AddressOf PurchaseOrder_CreateEnd
         AddHandler purchaseOrderForm.PurchaseOrder.ReadEnd, AddressOf PurchaseOrder_ReadEnd
         AddHandler purchaseOrderForm.PurchaseOrder.CopyEnd, AddressOf PurchaseOrder_CopyEnd
         AddHandler purchaseOrderForm.PurchaseOrder.DeserialiseEnd, AddressOf PurchaseOrder_DeserialiseEnd
      End If
   End Sub


Here are the handlers. These essentially push and pull the value between the control and the custom field we created earlier.

Code: Select all

   Private Sub CreditorInvoiceNumberUltraTextBox_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs)
      If TypeOf(sender) Is Infragistics.Win.UltraWinEditors.UltraTextEditor Then
         Dim CreditorInvoiceNumberUltraTextBox As Infragistics.Win.UltraWinEditors.UltraTextEditor = DirectCast(sender, Infragistics.Win.UltraWinEditors.UltraTextEditor)
         Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(JiwaApplication.Manager.GetOwnerForm(CreditorInvoiceNumberUltraTextBox), JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)
         If purchaseOrderForm.PurchaseOrder.IsReading = False Then
            Dim customFieldValue As JiwaApplication.CustomFields.CustomFieldValue = Nothing
            customFieldValue = purchaseOrderForm.PurchaseOrder.CustomFieldValues.ItemFromSettingName("CreditorInvoiceNumber", "Add field to Purchase Order Screen")
            If Not customFieldValue Is Nothing Then
               customFieldValue.Contents = CreditorInvoiceNumberUltraTextBox.Text
            Else
               customFieldValue = New JiwaApplication.CustomFields.CustomFieldValue
               customFieldValue.Contents = CreditorInvoiceNumberUltraTextBox.Text
               purchaseOrderForm.PurchaseOrder.CustomFieldValues.Add(customFieldValue)
              End If               
         End If
      End If
    End Sub   
   
   Public Sub PurchaseOrder_PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder Then
         Dim purchaseOrderObject As JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)
         If Not purchaseOrderObject.Client Is Nothing AndAlso TypeOf(purchaseOrderObject.Client) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
            Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(purchaseOrderObject.Client, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)         
            DisplayCreditorInvoiceNumber(purchaseOrderForm)
         End If
      End If
   End Sub
   
   Public Sub PurchaseOrder_CreateEnd(sender As Object, e As System.EventArgs)
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder Then
         Dim purchaseOrderObject As JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)
         If Not purchaseOrderObject.Client Is Nothing AndAlso TypeOf(purchaseOrderObject.Client) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
            Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(purchaseOrderObject.Client, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)         
            DisplayCreditorInvoiceNumber(purchaseOrderForm)
         End If
      End If      
   End Sub
   
   Public Sub PurchaseOrder_ReadEnd(sender As Object, e As System.EventArgs)
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder Then
         Dim purchaseOrderObject As JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)
         If Not purchaseOrderObject.Client Is Nothing AndAlso TypeOf(purchaseOrderObject.Client) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
            Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(purchaseOrderObject.Client, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)         
            DisplayCreditorInvoiceNumber(purchaseOrderForm)
         End If
      End If      
   End Sub
   
   Public Sub PurchaseOrder_CopyEnd(sender As Object, e As System.EventArgs)
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder Then
         Dim purchaseOrderObject As JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)
         If Not purchaseOrderObject.Client Is Nothing AndAlso TypeOf(purchaseOrderObject.Client) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
            Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(purchaseOrderObject.Client, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)         
            DisplayCreditorInvoiceNumber(purchaseOrderForm)
         End If
      End If      
   End Sub
   
   Public Sub PurchaseOrder_DeserialiseEnd(sender As Object, e As System.EventArgs, poco As Object)
      If TypeOf(sender) Is JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder Then
         Dim purchaseOrderObject As JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)
         If Not purchaseOrderObject.Client Is Nothing AndAlso TypeOf(purchaseOrderObject.Client) Is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders Then
            Dim purchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders = DirectCast(purchaseOrderObject.Client, JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)         
            DisplayCreditorInvoiceNumber(purchaseOrderForm)
         End If
      End If      
   End Sub


Finally, the display routine that is used by the handlers to display the value in the control:

Code: Select all
   Public Sub DisplayCreditorInvoiceNumber(ByRef PurchaseOrderForm As JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.PurchaseOrders)      
      Dim oldReading As Boolean = PurchaseOrderForm.PurchaseOrder.IsReading
      Try
         PurchaseOrderForm.PurchaseOrder.IsReading = True   
         
         PurchaseOrderForm.HeaderUltraExpandableGroupBoxPanel.Controls("CreditorInvoiceNumberUltraTextBox").Text = ""
         Dim customFieldValue As JiwaApplication.CustomFields.CustomFieldValue = Nothing
         customFieldValue = PurchaseOrderForm.PurchaseOrder.CustomFieldValues.ItemFromSettingName("CreditorInvoiceNumber", "Add field to Purchase Order Screen")
         If Not customFieldValue Is Nothing Then
            PurchaseOrderForm.HeaderUltraExpandableGroupBoxPanel.Controls("CreditorInvoiceNumberUltraTextBox").Text = customFieldValue.Contents
           End If         
        Finally
            PurchaseOrderForm.PurchaseOrder.IsReading = oldReading
        End Try            
   End Sub
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Purchase Order - extra field  Topic is solved

Postby Scott.Pearce » Thu Sep 03, 2015 2:19 pm

Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Purchase Order - extra field

Postby neil.interactit » Tue Sep 08, 2015 5:11 pm

Very sweet. Thanks.

Cheers,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests