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