Sales Order XML  Topic is solved

Discussions relating to breakout scripting, .NET and COM programming with Jiwa objects.

Sales Order XML  Topic is solved

Postby SBarnes » Fri Nov 07, 2014 3:50 pm

Hi All

What is necessary in vb.net code for both Jiwa version 6 and Jiwa version 7 to be able to serialize a sales order object to XML and deserialize a sales order object from XML?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Sales Order XML

Postby Mike.Sheen » Fri Nov 07, 2014 4:26 pm

SBarnes wrote:Hi All

What is necessary in vb.net code for both Jiwa version 6 and Jiwa version 7 to be able to serialize a sales order object to XML and deserialize a sales order object from XML?


Hi Stuart,

In both version 6 and 7 our sales order business logic has serialisation and deserialisation capabilities.

With version 6 there are the methods "GenerateXML" and "ConsumeXML", in version 7 all our business logic have a Serialise and Deserialise method, but in version 7 we overloaded those methods so it can accept or return either an XML document, or a representation of the POCO objects we use for serialisation/deserialisation.

In version 7 the code to read and serialise a sales order to an XML file from a stand-alone VB.NET application is as simple this:

Code: Select all
Imports JiwaFinancials.Jiwa
  Public Class TestClass

     Private Sub SerialiseSalesOrder(ByVal InvoiceID As String)
         JiwaApplication.Manager.Instance.Logon("JiwaMike", "JiwaDemo", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password")

         Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaSales.SalesOrder.SalesOrder)()
         salesOrder.Read(InvoiceID) ' If you don't know the invoice ID, we have a Find method to obtain it from the Invoice No. instead.

         Dim xmlString as String
         Dim fileName as String = "C:\test.xml"
         salesOrder.Serialise(xmlString)
         My.Computer.FileSystem.WriteAllText(fileName , xmlString, True)

         Console.WriteLine(String.Format("Invoice No. {0} is has been saved as {1}.", salesOrder.InvoiceNo, fileName))

         JiwaApplication.Manager.Instance.LogOff()
     End Sub
  End Class


You don't need to save it to file - my example above was just illustrating serialisation to a file. The above code is very similar to what happens when you click on the "Export to XML" button on the sales order ribbon in version 7. If you're interested, I adapted code from the on-line reference to construct the above sample.

Deserialising in version 7 is much the same, but just reading the file and calling the Deserialise method instead, and passing the XML or POCO object in as an argument (there is an import from XML ribbon button also on sales order in version 7).

Version 6 is similar in concept, but requires some more overhead in the connection to Jiwa and instantiating the sales order business logic - that would be a fair chunk of code to post, so I'm not going to post it here unless you have a specific requirement for it.

Note also in Version 7 that whilst it is easy and supported to write your own applications using our API, it might be a neater solution to use our plugin framework. You can write your own .NET code in our plugin and each Jiwa client will read that from the database, compile it and execute it when desired (a button click, an action such as printing, or even on a scheduled basis using the plugin scheduler service). That way you don't need to deploy your application to all the clients that need it, it's already done for you!

If you have a specific problem you're trying to solve and need some more guidance just post back here with more detail.

I hope this was of use,

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: Sales Order XML

Postby SBarnes » Sun Nov 09, 2014 8:32 am

Hi Mike,

Firstly thanks for the as always for the quick reply, the reason for my question is that currently our sales force use an in house application that runs a number of PowerPoint presentations of our products and then lets the sales rep key in their orders which produces an excel file of the order for human readability and an xml file which is currently imported into 6.5.13 through the orders screen when it reaches head office by our customer service.

Currently the two files are sent to head office simply as email attachments through outlook, I am looking to change the system of transport to use a self hosted web service (probably in web api as wcf would over complicate things) that would take the XML logon to Jiwa and use the xml serialise/deserialise interface to put the order into the system and then send the invoice back to client as XML and hence remove the manual step from customer service and be able to record the invoice number on the client side.

I could write the data directly into the database tables but breaking the business logic and reinventing the wheel would not be a smart thing to do, hence the reason for my question, but given we are still currently running 6.5.13 due to other systems Jiwa interacts with I still have to code this under version 6 but will need to move it to version 7 eventually, any help on the version 6 code would be appreciated.

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

Re: Sales Order XML

Postby Mike.Sheen » Sun Nov 09, 2014 4:30 pm

SBarnes wrote:Hi Mike,

Firstly thanks for the as always for the quick reply, the reason for my question is that currently our sales force use an in house application that runs a number of PowerPoint presentations of our products and then lets the sales rep key in their orders which produces an excel file of the order for human readability and an xml file which is currently imported into 6.5.13 through the orders screen when it reaches head office by our customer service.

Currently the two files are sent to head office simply as email attachments through outlook, I am looking to change the system of transport to use a self hosted web service (probably in web api as wcf would over complicate things) that would take the XML logon to Jiwa and use the xml serialise/deserialise interface to put the order into the system and then send the invoice back to client as XML and hence remove the manual step from customer service and be able to record the invoice number on the client side.

I could write the data directly into the database tables but breaking the business logic and reinventing the wheel would not be a smart thing to do, hence the reason for my question, but given we are still currently running 6.5.13 due to other systems Jiwa interacts with I still have to code this under version 6 but will need to move it to version 7 eventually, any help on the version 6 code would be appreciated.

Thanks.

Hi Stuart,

Working on a Sunday? shame on you! :P

(probably in web api as wcf would over complicate things) that would take the XML logon to Jiwa and use the xml serialise/deserialise interface to put the order into the system and then send the invoice back to client as XML and hence remove the manual step from customer service and be able to record the invoice number on the client side


That's certainly do-able without too much work. Your web service would need to logon to Jiwa (version 6) and create a sales order business logic object, then pass the XML to the Consume XML function - and then call the Save method - at that point if the save was successful, then a ReadRecord and then Generate XML could be called to provide the sales order XML back. There are some niggling details to get right to do this in version 6 - I'd much rather you do this with version 7 (did I mention we have in beta a RESTful webservice endpoint using your choice of json or XML in version 7?) as it's a lot easier - but if it must be version 6 then so be it.

You're right with the strategy not to write directly to the tables - I've been on that ride with integrations and it's never worked out very well.

With what you've explained so far, It seems like you need only one webservice method - this would accept a login and password (or an API Key), and a sales order XML document - it would then login to Jiwa and import the order from the XML provided, save it, and return the resultant XML document which would include the Invoice No. of the new order. You could always make your webservice establish the connection to Jiwa at the time the service starts - but In my experience with version 6's ADO and ODBC connections it doesn't tolerate long-running connections that well - I think it best the service connect for each sales order, then disconnect when done.

An example of how to login with version 6 using code can be seen here. Once you have that working from your webservice it should be a simple matter to create the sales order from XML - but let's reach that first milestone of successfully connecting to Jiwa first, and then tackle the order creation.

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: Sales Order XML

Postby SBarnes » Sat Nov 15, 2014 3:09 pm

Hi Mike,

May I point out that you were also working on a Sunday :P and let's not get into the irony that it's the weekend again.

I now have a Web API project working that will take the XML orders as a parameter to a post action and will logon to Jiwa, the only difficulty I had to overcome was getting the web api to pass through the XML correctly in its raw format as I had to create a custom MediaTypeFormatter to get it treated as text see http://myadventuresincoding.wordpress.com/2012/06/19/c-supporting-textplain-in-an-mvc-4-rc-web-api-application/ if you are interested.

Now I just need some help putting, the code together to save the order, one other question I had also thought of is what does Jiwa do at the object level when an order is imported and the debtor account is on hold as I know the UI won't let you save the order?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Sales Order XML

Postby Mike.Sheen » Mon Nov 17, 2014 10:04 am

SBarnes wrote:Now I just need some help putting, the code together to save the order


Is this for version 6 or 7? From what you've posted previously I believe you are working with version 6 - if it is V6, let me know and I'll also move this thread as I think it would be more appropriate in the Version 6 forum.

SBarnes wrote:Now I just need some help putting, the code together to save the order, one other question I had also thought of is what does Jiwa do at the object level when an order is imported and the debtor account is on hold as I know the UI won't let you save the order?


In both version 6 and 7 this business rule is applied in the business logic level, but there is a system setting "IgnoreDebtorOnHold" which you can set within the sales order's system setting cache to override that behavior for just the instance of the sales order object you're working with (without having to actually have the setting impact anyone or anything else).

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: Sales Order XML

Postby SBarnes » Mon Nov 17, 2014 10:09 am

Hi Mike,

This is for version 6.5.13.
Thanks
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Sales Order XML

Postby Mike.Sheen » Mon Nov 17, 2014 1:50 pm

Hi Stuart,

I've tested this Vb6 Code against 06.05.13 for importing a sales order using XML - it's working for me. I had to add references to the JiwaODBC, JiwaSysProfile, JiwaLib, JiwaCommonLib and JiwaSalesOrder dll's.
The code is below:

Code: Select all
Dim XMLDocument As String
    Dim FileName As String
    FileName = "C:\test.xml"
   
    Dim handle As Integer
    handle = FreeFile
    Open FileName For Input As handle
    XMLDocument = Input(LOF(handle), handle)
    Close handle

    Dim logicalWarehouseID As String
    logicalWarehouseID = "ZZZZZZZZZZ0000000000"
   
    Dim serverName As String
    serverName = "JiwaMike"
   
    Dim databaseName As String
    databaseName = "JiwaDemo_060513"
   
    Dim userName As String
    userName = "JiwaLogin"
   
    Dim password As String
    password = "JiwaApplicationLogin123"
   
    Dim connectionString As String
    connectionString = "Provider=SQLOLEDB;" & _
                        "Data Source=" & serverName & ";" & _
                        "Initial Catalog=" & databaseName & ";" & _
                        "User ID=" & userName & ";" & _
                        "Password=" & password & ";"
                                   
    Dim database As JiwaODBC.database
    Set database = New JiwaODBC.database
    database.ConnectionDetails = connectionString
   
    Dim SystemProfile As JiwaSysProfile.clsSysProfile
    Set SystemProfile = New JiwaSysProfile.clsSysProfile
    SystemProfile.Load ("C:\Program Files\Jiwa Financials\Jiwa\Jiwa.xml")
   
    Dim JLib As JiwaLib.StdFunctions
    Set JLib = New JiwaLib.StdFunctions
    Set JLib.database = database
   
    Dim CommonLib As JiwaCommonLib.StdFunctions
    Set CommonLib = New JiwaCommonLib.StdFunctions
    Set CommonLib.database = database
   
    If database.MakeConnections(Me.hWnd) = True Then
        Dim userMustChangePassword As Boolean
        Dim passwordLastChangedDateTime As Date
       
        If database.DoLogOn("Admin", "password", userMustChangePassword, passwordLastChangedDateTime) = True Then
            Dim salesOrder As JiwaSalesOrder.clsSalesOrder
            Set salesOrder = New JiwaSalesOrder.clsSalesOrder
            Set salesOrder.database = database
            Set salesOrder.JiwaCommLib = CommonLib
            Set salesOrder.JLib = JLib
            Set salesOrder.SystemProfile = SystemProfile
            salesOrder.Setup e_SalesOrderNormalSalesOrder, logicalWarehouseID
           
            Dim NewSalesOrderID As String
            If salesOrder.ConsumeXML(XMLDocument, NewSalesOrderID) = e_SalesOrderReturnCodeSuccess Then
                If salesOrder.SaveOrder(-1, False, False) = e_SalesOrderReturnCodeSuccess Then
                    MsgBox "Saved Order " & salesOrder.InvoiceNo & "."
                Else
                    MsgBox salesOrder.ErrorString
                End If
            Else
                MsgBox salesOrder.ErrorString
            End If
        Else
            MsgBox database.ErrorMessage
        End If
       
        Set JLib = Nothing
        Set CommonLib = Nothing
        Set SystemProfile = Nothing
       
        database.BreakConnections
        Set database = Nothing
    Else
        MsgBox database.ErrorMessage
    End If


The sample XML document I used (working with known parts and debtors in demo data) is also attached.

test.xml
test sales order xml for version 6.5.13
(1.61 KiB) Downloaded 310 times


Hopefully this will be enough to get you to incorporate importing sales orders with your web service. If not, report back any issues and we deal with those as they arise.

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: Sales Order XML

Postby SBarnes » Tue Nov 18, 2014 3:46 pm

Hi Mike

Great news I was able to get the code running and post the order, as always thanks for all your help.

I just have one last question is there a way to get the warehouseID without hard coding the value to ZZZZZZZZZZ0000000000 I tried WarehouseID = Database.CurrentLogicalWarehouseID; but got a null value which of course meant consuming the XML failed?

Thanks
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Sales Order XML

Postby Mike.Sheen » Tue Nov 18, 2014 4:55 pm

SBarnes wrote:Hi Mike

Great news I was able to get the code running and post the order, as always thanks for all your help.

I just have one last question is there a way to get the warehouseID without hard coding the value to ZZZZZZZZZZ0000000000 I tried WarehouseID = Database.CurrentLogicalWarehouseID; but got a null value which of course meant consuming the XML failed?

Thanks


Hi Stuart,

The Database.CurrentLogicalWarehouseID needs to be set by your code. Typically this is the Last Logical Warehouse which is stored in the XML file - so something like this is all that is needed:
Code: Select all
Database.CurrentLogicalWarehouseID = SystemProfile.GetValue("JiwaDocument/Parameters/InventoryParams/LastLogicalWarehouseID")

Put the above code in your code after you've logged on, and then your database will use the last used warehouse.

If that's not desired, you can just query the IN_Logical table directly and set the Database.CurrentLogicalWarehouseID to be the desired ID.

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

Next

Return to Technical / Programming

Who is online

Users browsing this forum: No registered users and 2 guests