Creditor Classification webhooks event.  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Creditor Classification webhooks event.

Postby minhhieu106 » Sat Apr 21, 2018 10:19 pm

Hi Mike,

I try to add new event (Created, Updated, Deleted) for Creditor Classification on Webhooks.

Here is sample code for Debtor Classification. It work fine.

Code: Select all
async public void debtorClassification_SaveEnd(object sender, System.EventArgs e)
   {
      JiwaFinancials.Jiwa.JiwaDebtors.Configuration.Classification.Classification classification = (JiwaFinancials.Jiwa.JiwaDebtors.Configuration.Classification.Classification)sender;
      string body = classification.DTO_Serialise().ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Classification.DebtorClassification>();         
      
      Webhook(classification.Manager, body, (classification.InsertFlag) ? "debtorclassification.created" : (classification.DeleteFlag) ? "debtorclassification.deleted" : "debtorclassification.updated");
   }


But for Creditor Classification it does not work.

Image

It seems JiwaServiceModel do not have Classification class for Creditor and also does not have DTO_Serialise() method.

Pleaes advise which classes use for Creditor classification.

Thanks,
Attachments
WebHooks Error.PNG
minhhieu106
Occasional Contributor
Occasional Contributor
 
Posts: 49
Joined: Thu Mar 29, 2018 3:29 pm
Topics Solved: 0

Re: Creditor Classification webhooks event.  Topic is solved

Postby Mike.Sheen » Tue Apr 24, 2018 5:18 pm

Hi minhhieu106,

Firstly well done on working out how to extend the Webhooks to add hooks for the debtor classifications.

We don't have the DTO for serialising or deserialising the creditor classifications (yet) - because nobody has ever needed it (until now).

If you must have webhooks for Creditor Classifications (are you sure you need creditor classification webhooks in the iVend POS Integration?), then all that needs to be done is to write your own DTO_Serialise method for the creditor classification, and your own DTO for the creditor classification.

Or you can even cheat a little just to do it quickly and use OrmLite to generate the Json string from a simple OrmLite query on the SQL table backing a Creditor Classification:

Code: Select all
async public void creditorClassification_SaveEnd(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaCreditors.Configuration.Classification.Classification classification = (JiwaFinancials.Jiwa.JiwaCreditors.Configuration.Classification.Classification)sender;
   
   var dbFactory = new OrmLiteConnectionFactory(classification.Manager.Database.ConnectionString, ServiceStack.OrmLite.SqlServer2012Dialect.Provider);
   using (var db = dbFactory.Open())
   {   
      JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Classification CR_ClassificationTable  = db.SingleById<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Classification>(classification.RecID);         
      string body = CR_ClassificationTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Classification>();
      Webhook(classification.Manager, body, (classification.InsertFlag) ? "classification.created" : (classification.DeleteFlag) ? "classification.deleted" : "classification.updated");
   }            
}


So instead of using the business logic to serialise the a DTO defined in JiwaFinancials.Jiwa.JiwaServiceModel - because we have a DTO for every SQL table and view Jiwa uses in JiwaFinancials.Jiwa.JiwaServiceModel.Tables - we just read the CR_Classification record and serialise that instead.

That should be good enough for your purposes.

Don't forget to add to the Business Logic tab of your plugin the Creditor Classifications business logic, and in the Setup method of the BusinessLogicPlugin class the code to add the handler for the creditor classification save event:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if (JiwaBusinessLogic is JiwaFinancials.Jiwa.JiwaCreditors.Configuration.Classification.Classification)
   {                  
      JiwaFinancials.Jiwa.JiwaCreditors.Configuration.Classification.Classification classification = (JiwaFinancials.Jiwa.JiwaCreditors.Configuration.Classification.Classification)JiwaBusinessLogic;
      classification.SaveEnd += creditorClassification_SaveEnd;
   }
}


And also you'll need to add the webhooks to the WebHookEvents property of the WebHooksRESTAPIPlugin class:

Code: Select all
WebHookEvents.Add(new WebHookEvent { Name = "creditorclassification.created", Description = "Occurs when a creditor classification is created" });
WebHookEvents.Add(new WebHookEvent { Name = "creditorclassification.updated", Description = "Occurs when a creditor classification is modified" });
WebHookEvents.Add(new WebHookEvent { Name = "creditorclassification.deleted", Description = "Occurs when a creditor classification is deleted" });


But you will have added to your plugin a Plugin Reference (via the Plugin References Tab) to the REST API Webhooks plugin first!

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: Creditor Classification webhooks event.

Postby minhhieu106 » Wed Apr 25, 2018 1:22 am

Hi Mike,

Great! It work fine with your solutions.

Thank you for your support

Hieu
minhhieu106
Occasional Contributor
Occasional Contributor
 
Posts: 49
Joined: Thu Mar 29, 2018 3:29 pm
Topics Solved: 0


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 17 guests