Revert sales order line changed to original value  Topic is solved

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

Revert sales order line changed to original value

Postby DannyC » Thu Jul 30, 2015 11:15 am

Hi,

I have a custom field on Staff Maintenance which says what the allowable discount is when entering/editing sales order lines.
The plugin works well...almost.

If the allowable discount has been exceeded, I just need the price to revert back to what it was prior to the edit.

This is my code so far
Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim SalesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)      
      AddHandler salesOrderForm.SalesOrder.SalesOrderLines.Changed, AddressOf SOLineDiscount_Changed
   End Sub
   
   Private Sub   SOLineDiscount_Changed(item As JiwaSales.SalesOrder.SalesOrderLine, e As System.ComponentModel.PropertyChangedEventArgs)
      Dim MyStaff As JiwaApplication.JiwaStaff.clsStaff =JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaApplication.JiwaStaff.clsStaff)(Nothing)
      MyStaff.Read(JiwaApplication.Manager.Instance.Staff.RecID)
      Dim DiscPcnt As Integer
       For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In JiwaApplication.Manager.Instance.Staff.CustomFieldValues
        If customFieldValue.CustomField.PluginCustomField.Name = "DISC" Then
         Integer.TryParse(customFieldValue.Contents, DiscPcnt)
           Exit For
        End If
       Next
      msgbox(DiscPcnt)
      If item.DiscountPercentage > DiscPcnt Then
         MessageBox.Show("You don't have authority for this discount.", "Verify allowed discount")
         Throw New JiwaApplication.Exceptions.ClientCancelledException
      End If
   End Sub


Can you advise how I can put the line values back to what they were prior to the price change?

Cheers
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Revert sales order line changed to original value  Topic is solved

Postby Scott.Pearce » Tue Aug 18, 2015 4:12 pm

Declare a variable to hold the original values. It's scope should be global to the class. The variable would have to be something like a list, so you can store the RecID of the line along with it's price. The RecID is what you would use to index into the list.

Every time a sales order is read, the list of original variables is cleared and re-populated with the current sales order's line RecIDs and prices.

Also, every time a line change occurs, and the e.PropertyName is "Price" (or whatever the exact text is), you index into the list using the lines' RecID and update the price with the new value.

Now, when you do the discount check, if it fails you will always have access to the original value for the lines' price via your list. You may have to fiddle around to get the handlers in the correct order though, I guess.
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


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest