Creating Sales Order  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Creating Sales Order

Postby perry » Fri Feb 09, 2018 3:50 pm

Hi,

Finally have chance to use API interface, love it. Thanks for the hard work.

v7.1.0
I have 2 problems with below order

{"InvoiceID":null,"InvoiceNo":null,"DebtorAccountNo":"005","BillType":"0","OrderNo":"FRBill","Reference":"FRBill","OrderType":"1","InitiatedDate":"08/01/2018 11:34:49 AM","Lines":[{"PartNo":"01140008","QuantityOrdered":1.0,"DiscountedPrice":39.92, FixPrice:1, FixSellPrice:1, SellPrice:39.92},
{"PartNo":"test123","QuantityOrdered":1.0,"DiscountedPrice":39.92, FixPrice:1, FixSellPrice:1, SellPrice:39.92}]}"


1. FixPrice property is not set on sales order line,
2. initiated Date is set to 1st of August (thanks to American). Current setup is self hosted and running with Local System account.

Thanks in advance
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: Creating Sales Order  Topic is solved

Postby Mike.Sheen » Fri Feb 09, 2018 4:53 pm

Hi Perry,

Thanks for the feedback - the FixPrice being ignored is now logged as DEV-6465. However, you'll only see any use for that if you're sending a jiwa-stateful request header with your POST or PATCH, and then performing subsequent PATCH operations also with a jiwa-stateful request header - the FixPrice property of the sales order line is not persisted to the database. If your intent is to ensure the price supplied in the operation is the one that is used, then that is already the case - unless I'm missing something?

As for the date, you have a few options. If you provide it in an unambiguous format eg: "2018-01-08 11:34:49 AM", then it'll certainly work as expected.

ServiceStack defaults to the .NET DataContractSerializer way of serialising / deserialising datetimes - it looks like this:

{"InitiatedDate":"\/Date(1515371689000-0000)\/","DebtorAccountNo":"1001"}

The above was the result of this C#:
Code: Select all
var so = new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder { DebtorAccountNo = "1001", InitiatedDate = new DateTime(2018, 01, 08, 11, 34, 49) };
string body = so.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder>();


And when the above is POSTed to the SalesOrders route, the date is correct.

I'd suggest using a serialisation framework to generate the JSON - the above is using ServiceStack.Text (it provides extension methods like .ToJson() above), but you can use others like Json.NET, Microsoft's DataContractJsonSerializer.

You can also control the DateHandler the REST API Service uses to format dates which are serialised - you can override this in your own plugin which implements IJiwaRESTAPIPlugin:
Code: Select all
namespace JiwaFinancials.Jiwa.JiwaServiceModel
{   
   public class RESTAPIPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
   {      
      public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost  AppHost, Funq.Container Container, JiwaApplication.Manager JiwaApplicationManager)
      {
         ServiceStack.Text.JsConfig.DateHandler = DateHandler.ISO8601;
      }
   }
}


This above will cause the ISO8601 format to be used - which probably would suit you if you're trying to keep human readable values in the JSON - but if you're generating that JSON manually you'll have to format the datetime correctly to ISO8601 format. You just need to create a new plugin with the above and enable it and it will cause our REST API plugin to use that DateHandler - no need to edit the standard REST API plugin.

The valid values for the DateHandler property can be seen in the sourcecode of JSConfig.cs.

EDIT: I should mention that it appears as though you're manually constructing the JSON being sent - I wouldn't recommend that - instead create an object and serialise that to JSON... how was that JSON you provided generated?

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

Re: Creating Sales Order

Postby perry » Thu Mar 15, 2018 4:55 pm

Hi Mike,

Sorry, I totally forgot about this post. I normally only check the parent forum...

I'm coding a SSIS package and we dont want to install too many things on that server so I only have Newtonsoft.Json DLL available to me.

I define a class with properties I needed (and I only realize today that the date field is defined as String, probably thats why...) for de/serialisation
Code: Select all
Private Class SalesOrder
        Public Property InvoiceID As String
        Public Property InvoiceNo As String
        Public Property DebtorAccountNo As String
        Public Property BillType As String
        Public Property OrderNo As String
        Public Property Reference As String
        Public Property OrderType As String
        Public Property InitiatedDate As String
        Public Property BranchID As String
        Public Property Lines As List(Of SalesOrderLine)

        Public Class SalesOrderLine
            Public Property PartNo As String
            Public Property QuantityOrdered As Decimal
            Public Property DiscountedPrice As Decimal
        End Class
    End Class


Then everybody calls this for posting but I dont specific whether it is jiwa-stateful
Code: Select all
Private Function APIPOST(arg As String, obj As Object) As Newtonsoft.Json.Linq.JObject

        If String.IsNullOrEmpty(SessionID) Then
            Throw New Exception("login first.")
        End If


        Using WebClient As New WebClient
            WebClient.Headers.Add(System.Net.HttpRequestHeader.Cookie, String.Format("ss-id={0}", SessionID))
            WebClient.Headers(System.Net.HttpRequestHeader.ContentType) = "application/json"

            Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(obj)

            Dim responseBody As String = WebClient.UploadString(String.Concat(JiwaAPIURL, arg), "POST", json)

            Return Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody)
        End Using

    End Function
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: Creating Sales Order

Postby Mike.Sheen » Thu Mar 15, 2018 10:22 pm

perry wrote:we dont want to install too many things on that server so I only have Newtonsoft.Json DLL available to me.


That's fine - any popular or reputable framework for serialisation would be acceptable - we don't require any specific serialisation framework.

perry wrote:I define a class with properties I needed (and I only realize today that the date field is defined as String, probably thats why...) for de/serialisation


Yes - don't make your POCO/DTO use string for date fields or what will happen is the culture of the local machine will be used for formatting dates. Either declare it as date/datetime or format your setting of the string to use an unambiguous format like ISO8601. We do our best to interpret date/datetimes, but if you do give us a string for a date/datetime field it's open to interpretation unless you use ISO8601 format (eg: x.ToString("yyyy-MM-dd HH:mm:ss")).

We do provide XSD's and even VB.NET classes you can use instead of constructing your own POCO/DTO, which should eliminate such issues. You can build classes for a bunch of popular languages (including VB.NET) from the XSD using such tools as xsd.exe - but why bother when we generate that for you! You can copy/paste only the classes you need in your client and discard the parts you don't use to keep the size of your client down.

If you use other languages, our metdata page has links to the classes for those - just scroll down to the bottom of api.jiwa.com.au until you see the Plugin Links.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Creating Sales Order

Postby Mike.Sheen » Sun Mar 25, 2018 2:34 pm

FYI - I've added improvement DEV-6544 to change the date serialisation to use ISO8601 format by default.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to REST API

Who is online

Users browsing this forum: No registered users and 0 guests

cron