Credit note events  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Credit note events

Postby perry » Thu Aug 14, 2014 5:05 pm

Hi,

JIWA 7.0.78

I want to be able to handle sales order line added event when credit note is created from an existing SO.
I also want to know the source sales order line ID of the existing CN line.

For example, New Credit Note -> based on existing sales order -> select history no
SalesOrder.SalesOrderLineAdded event is not triggered in above case.

Thanks,
Perry
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Credit note events  Topic is solved

Postby Mike.Sheen » Thu Aug 14, 2014 6:40 pm

Hi Perry,

You can do what you want after the credit note is created - you just need to read the original sales order and match the itemno property of each line.

Create Credit Note Sample.rar
Sample plugin
(4.95 KiB) Downloaded 145 times

I have attached a plugin demonstrating this - the bulk of the work can be seen in my handler of the Created event of the sales order:

Code: Select all
Public Sub SalesOrder_Created(sender As Object, e As System.EventArgs, ByVal NewSalesOrderType As JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes, ByRef SourceQuoteObject As JiwaSales.SalesQuote.SalesQuote)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)      
      If salesOrder.CreditNote Then
         If salesOrder.CreditNoteInvoiceHistoryID.Trim.Length > 0 Then
            ' Read the InvoiceID
            Dim InvoiceID As String
            Dim HistoryNo As Integer
               
            With JiwaApplication.Manager.Instance.Database
               Dim Sql As String
               Dim SQLReader As SqlDataReader = Nothing
               Dim SQLParam As SqlParameter = Nothing
            
                    Try
                        Sql = "SELECT TOP 1 InvoiceID, HistoryNo FROM SO_History WHERE InvoiceHistoryID = @InvoiceHistoryID"

                        Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)

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

                            SQLReader = SQLCmd.ExecuteReader()

                            If SQLReader.Read = True Then
                                InvoiceID = .Sanitise(SQLReader, "InvoiceID")
                        HistoryNo = .Sanitise(SQLReader, "HistoryNo")
                            Else
                                Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException(String.Format("Sales History with ID of '{0}' was not found.", salesOrder.CreditNoteInvoiceHistoryID))
                            End If

                            SQLReader.Close()
                        End Using
                    Finally
                        If Not SQLReader Is Nothing Then
                            SQLReader.Close()
                        End If
                    End Try
                End With
               
            Dim sourceSalesOrder As JiwaSales.SalesOrder.SalesOrder = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaSales.SalesOrder.SalesOrder)
            sourceSalesOrder.Read(InvoiceID)
            sourceSalesOrder.SelectedHistoryNo = HistoryNo
               
            For Each sourceSalesOrderLine As JiwaSales.SalesOrder.SalesOrderLine In sourceSalesOrder.SalesOrderLines   
               For Each salesOrderLine As JiwaSales.SalesOrder.SalesOrderLine In salesOrder.SalesOrderLines   
                  If sourceSalesOrderLine.ItemNo = salesOrderLine.ItemNo Then
                     JiwaApplication.Manager.DisplayMessage(Nothing, String.Format("Credit note line {0} was created from source sales order line with InvoiceLineID of {1}", salesOrderLine.ItemNo, sourceSalesOrderLine.RecID), vbOKOnly, vbInformation, vbOKOnly)
                     Exit For
                  End If
               Next
            Next
         End If
      End If
   End Sub


The trick is knowing that the CreditNoteInvoiceHistoryID property contains the SO_History.InvoiceHistoryID of the sales order the credit note was created from.
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Credit note events

Postby perry » Fri Aug 15, 2014 4:17 pm

Thanks Mike,

Though, ItemNo can be duplicated, can we use line no?
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Credit note events

Postby Mike.Sheen » Fri Aug 15, 2014 4:22 pm

perry wrote:Thanks Mike,

Though, ItemNo can be duplicated, can we use line no?


Where did you get that idea from?

The property ItemNo of the SalesOrderLine class maps to the LineNum column of the SO_Lines table. SO_Lines has a unique composite index on InvoiceHistoryID and LineNum, so there cannot be duplicates in the table, and when interacting with the ItemNo property of the SalesOrderLine class, or adding and removing from the collection, it will renumber other items automatically to avoid duplicates and make the ItemNo sequential.

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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Credit note events

Postby perry » Mon Aug 18, 2014 5:04 pm

Thanks Mike, I got confused between ItemNo and PartNo...
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Credit note events

Postby Mike.Sheen » Mon Aug 18, 2014 9:16 pm

perry wrote:Thanks Mike, I got confused between ItemNo and PartNo...


Ahh - lol - ok... I'm going to mark this as solved then.

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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron