Creating a Credit Note based on an existing Order  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Creating a Credit Note based on an existing Order

Postby indikad » Wed Nov 28, 2018 2:47 pm

Trying to replicate a legacy code into a plugin : Jiwa 7.2

Have 2 questions both related to the same job
1 - I have managed to create a Credit note with the following line however it has failed to pickup the base order lines -
Code: Select all
salesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCreditNote,sDebtorId,True,sOrderInvHistoryID)
salesOrder.Warehouse.IN_LogicalID = sLogicalWarehouseID

2 - The following code is from the legacy ( V6)
what does this do ? I could not find a mapping for the InvoiceLineDetail though ... is this required in V7.2 ?
Code: Select all
                            For Each InvoiceLine In MyJiwaSalesOrder.SalesOrderLines
                                    For Each InvoiceLineDetail In InvoiceLine.LineDetails
                                        InvoiceLineDetail.IN_LogicalID = CreditWarehouseID
                                    Next
                                Next
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Creating a Credit Note based on an existing Order

Postby Mike.Sheen » Wed Nov 28, 2018 3:01 pm

The signature of CreateNew for sales orders / credit notes changed a bit in V7 - we added a new parameter for providing the source quote history id - you're setting the InvoiceHistoryID parameter but you need to set the QuoteHistoryID parameter.

Code: Select all
Public Overloads Sub CreateNew(ByVal NewSalesOrderType As NewSalesOrderTypes, ByVal DebtorSeed As String, Optional ByVal DebtorSeedIsID As Boolean = True, Optional ByVal InvoiceHistoryID As String = "", Optional ByVal JobID As String = "", Optional ByVal QuoteHistoryID As String = "", Optional ByVal LogicalWarehouseID As String = "")


indikad wrote:what does this do ? I could not find a mapping for the InvoiceLineDetail though ... is this required in V7.2 ?
Code: Select all
                            For Each InvoiceLine In MyJiwaSalesOrder.SalesOrderLines
                                    For Each InvoiceLineDetail In InvoiceLine.LineDetails
                                        InvoiceLineDetail.IN_LogicalID = CreditWarehouseID
                                    Next
                                Next


It looks like it was overriding the warehouse the stock was being credited into. So, if the sales order was in warehouse X, that code would have allowed you to be in warehouse X, create a credit note and the stock would be put into warehouse Y - even though the sales order credit note is in Warehouse X.

This would typically be done when people want to accept credit returns but have them go into a quarantine warehouse so they wouldn't appear as free stock and couldn't be sold - some sort of process would then be performed to inspect the goods and those of resale quality transferred back to the main warehouse at some point.

You probably want to keep that functionality.
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Creating a Credit Note based on an existing Order

Postby indikad » Wed Nov 28, 2018 5:09 pm

Hi Mike,

Thanks for the reply. I have further information on the question and a further question on it.
The credit note I am creating is not based on a sale quotation - its rather based on a sale order. Therefore I do not have a QuoteHistoryID to supply to the
QuoteHistoryID parameter.
However my code line worked ( as far as bringing the order lines to the credit note) when I tested on V7.0.175
BUT- does not work on 7.2 ( it only creates the header ) Is this a bug in 7.2 ?

one side question : what does the last parameter do in this case ( the LogicalWarehouseID ). Could I potentially use this to create the credit and all its lines on a different warehouse to the base order ? Therefore not having to use the lagacy way of specifying the Logical ID in linedetail ?
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Creating a Credit Note based on an existing Order

Postby Mike.Sheen » Thu Nov 29, 2018 9:13 am

indikad wrote:The credit note I am creating is not based on a sale quotation - its rather based on a sale order. Therefore I do not have a QuoteHistoryID to supply to the
QuoteHistoryID parameter.


Indeed. I don't know why I assumed it was coming from a quote!

indikad wrote:However my code line worked ( as far as bringing the order lines to the credit note) when I tested on V7.0.175
BUT- does not work on 7.2 ( it only creates the header ) Is this a bug in 7.2 ?

Hard to say but there must be a way to work around it if it is a bug, as the sales order form in Jiwa is able to create credit notes based on a sales order and it simply uses the business logic as you are. This is the exact line of code used by the sales order form to create a credit note from a known sales order history ID:
Code: Select all
_SalesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCreditNote, "", True, SourceHistoryID)


I've had a look at the code inside CreateNew and the only thing I can see which would cause the behaviour you are seeing is if the SourceHistoryID was blank or invalid. Check for leading or trailing spaces as well.

indikad wrote:one side question : what does the last parameter do in this case ( the LogicalWarehouseID ). Could I potentially use this to create the credit and all its lines on a different warehouse to the base order ? Therefore not having to use the lagacy way of specifying the Logical ID in linedetail ?


Yes, that would work also if each line is going into the same warehouse. That parameter was originally used by the Service Manager module to override the warehouse used for invoices or credits created from service jobs.
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Creating a Credit Note based on an existing Order

Postby indikad » Mon Dec 03, 2018 12:05 pm

Thanks Mile. I discovered that the reason it did not work on 7..2 was because the "This Del" column did not have a value in the base order . once that fixed it worked with the following bit of code
see below:
Code: Select all
Private Sub createCreditNoteTester(salesOrder As JiwaSales.SalesOrder.SalesOrder, ByRef salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
   'salesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCreditNote,sDebtorActNo, sDebtorId ,sOrderInvHistoryID)
   ' so inv no = 0001217414
   Dim sDebtorActNo As String   = "xhhh"
   Dim sDebtorId As String  = "xxxxx" '--unused
   Dim sOrderInvHistoryID As String  = "HistID1234"
   Dim sLogicalWarehouseID As String  = "whsID1234"
   ''' code below works on v7.0 but not on 72
   'salesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCreditNote,sDebtorId,True,sOrderInvHistoryID)
   'salesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCr1editNote,sDebtorId,True,sOrderInvHistoryID,vbNull,sOrderInvHistoryID,vbNull)

   Dim logicalWarehouse As JiwaApplication.Inventory.Warehouse.LogicalWarehouse = salesOrder.Manager.PhysicalWarehouseCollection.FindLogicalWarehouse(sLogicalWarehouseID)   '   .BusinessLogicFactory.CreateBusinessLogic (Of JiwaFinancials.Jiwa.JiwaWarehouses.LogicalWarehouse)(Nothing)
   
   salesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCreditNote,"",True,sOrderInvHistoryID,vbNull,vbnull,sLogicalWarehouseID)
   salesOrder.Warehouse = logicalWarehouse
   
   salesOrder.Reference = "testCredit1"
   If salesOrder.SalesOrderLines.Count > 0 Then
      For Each oLine As JiwaSales.SalesOrder.SalesOrderLine  In salesOrder.SalesOrderLines
         For Each InvoiceLineDetail As JiwaSales.SalesOrder.LineDetail  In oLine.LineDetails
            InvoiceLineDetail.IN_LogicalID = sLogicalWarehouseID
         Next            
      Next
   End If
   salesOrder.Save()
End Sub




However my ultimate objective is for this to work on file watcher/csv import BUT a similar code did not work on CSV import.
that bit of code is given below. it failed after the salesOrder.Save() with a strange error
"
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SO_Main_IN_PriceSchemes". The conflict occurred in database "dbname", table "dbo.IN_PriceSchemes", column 'PriceSchemeID'. "

I am passing in the same parameters that worked with the code that worked with my earlier test plugin. ( which was a button click off the sales order ). BTW: the same error happens on a fresh JiwaDemo database on a different machine on V7.2
CSV import code below
Code: Select all
Try   
            debug_LogToTextFile("after Try")
            Using csvParser As New FileIO.TextFieldParser(FileName)   
               csvParser.TextFieldType = FileIO.FieldType.Delimited               
               csvParser.Delimiters = New String() {","}
               csvParser.HasFieldsEnclosedInQuotes = False                  

               Do While Not csvParser.EndOfData
                  debug_LogToTextFile("insde start of do loop")
                  iReadrows  =  iReadrows + 1
                  csvFields = csvParser.ReadFields
                  If ( iReadrows > 0  ) Then '--- use the first row for header infor
                     If Not bHeaderRead Then
                        debug_LogToTextFile("inside if not header read")
' Create a new credit note
                        sOrderInvHistoryID = csvFields(13).ToString().Trim()
                        sDebtorId = csvFields(1).ToString().Trim()
                        bWholeSalesInvoice = IIf(csvFields(10).ToString().Trim() = "Y" , True,False)
                        sJiwaOrderType = csvFields(9).ToString().Trim()
                        sOrderOrCredit = csvFields(8).ToString().Trim()
                        sPOSourceCosntant = csvFields(12)
                        sDebtorActNo = csvFields(0)
                        sLogicalWarehouseID = csvFields(2)
                        debug_LogToTextFile("logical whs id  = " + sLogicalWarehouseID)
                        sOrderGUIId = csvFields(11)  '--- order ref generated by the macro goes to custom field and log table
                        sDocTypeStringforLog = "CR"
                        ologicalWarehouse =_plugin.Manager.PhysicalWarehouseCollection.FindLogicalWarehouse(sLogicalWarehouseID)
                        debug_LogToTextFile("logical whs id from object is  = " + ologicalWarehouse.IN_LogicalID.ToString() )

                        salesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrderCreditNote,"",True,sOrderInvHistoryID,vbNull,vbnull,sLogicalWarehouseID)
                        salesOrder.Warehouse = ologicalWarehouse
                        shSelectedHistoryNo = salesOrder.CurrentHistoryNo
                        Dim slsHist As JiwaSales.SalesOrder.SalesOrderHistory = salesOrder.SalesOrderHistorys(shSelectedHistoryNo)

                        salesOrder.Reference  =  "Upload"
                        salesOrder.CustomFieldValues.ItemFromSettingName("ediOrderRef").Contents  = sOrderGUIId

                        bHeaderRead = True             
                     End If      
                  End If
               Loop      
               debug_LogToTextFile("out of loop")
               If salesOrder.SalesOrderLines.Count > 0 Then
                  debug_LogToTextFile("sales order line count > 0")
                  For Each oLine As JiwaSales.SalesOrder.SalesOrderLine  In salesOrder.SalesOrderLines
                     For Each InvoiceLineDetail As JiwaSales.SalesOrder.LineDetail  In oLine.LineDetails
                        InvoiceLineDetail.IN_LogicalID = sLogicalWarehouseID
                     Next
                  Next
                  debug_LogToTextFile("befoe save ")
                  salesOrder.Save() '-- fails here
                  debug_LogToTextFile("after save ")
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Creating a Credit Note based on an existing Order

Postby Scott.Pearce » Tue Dec 11, 2018 9:40 am

Something is wrong with the value being saved to SO_Main.PriceSchemeID, hence the foreign key error.

1. What is the value of sOrderInvHistoryID?
2. What is the value of salesOrder.PriceSchemeID right before the call to salesOrder.Save?
3. Does the sales order that the credit note is being created from have a *valid* value in SO_Main.PriceSchemeID?
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 743
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Creating a Credit Note based on an existing Order

Postby Mike.Sheen » Tue Dec 11, 2018 9:49 am

indikad wrote:BTW: the same error happens on a fresh JiwaDemo database on a different machine on V7.2


If that's the case, you should be able to provide us a sample CSV file and plugin and if that reproduces the problem then we'll be able to identify the problem really quickly.

If you want a quick response, you should always make it as easy as possible for us to reproduce the issue ourselves.

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

Re: Creating a Credit Note based on an existing Order

Postby indikad » Wed Dec 12, 2018 10:02 am

Sent the sample code through the support case.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Creating a Credit Note based on an existing Order  Topic is solved

Postby Mike.Sheen » Wed Dec 12, 2018 2:45 pm

DEV-6996 details the cause and a work-around for this.
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 9 guests