Webhooks Tax  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Webhooks Tax

Postby minhhieu106 » Sat Apr 28, 2018 3:30 pm

Hi Mike,

I try to create new webhooks event for tax. But get this error.
Image

Please advise how to get it?

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

Re: Webhooks Tax

Postby Mike.Sheen » Sat Apr 28, 2018 4:56 pm

Hi Hieu,

The Jiwa Tax object obviously doesn't like to be serialised! we've logged this improvement as DEV-6594.

In the meantime, you can use the same technique as I demonstrated in my post in how to get the Creditor Classification - this time you're interested in the JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main class.

I hope that's enough for you to go on - if not, post back here and I shall assist you further!

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: Webhooks Tax

Postby minhhieu106 » Sun Apr 29, 2018 10:38 am

Thank you Mike!

Please help to how to get all the changes and convert json in this case

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

Re: Webhooks Tax  Topic is solved

Postby Mike.Sheen » Sun Apr 29, 2018 2:10 pm

Hi Hieu,

Here's what I came up with - you'll note there are 4 collections in the TaxRates object - GSTRatesOUT, GSTRatesIN, GSTRatesAdjOUT and GSTRatesAdjIN - so I just iterate through each.

Then I need to handle the deleted ones separately - as they get moved to the deleted collection of each rate collection.

So we end up potentially sending multiple webhook notifications (depending how many the user added/changed.deleted in the one edit)- one webhook notification for each tax rate added or changed or deleted.

Hope this makes sense!

Mike

EDIT: Oh, and BTW we have already added DTO serialisation for Tax Rates to the REST API in 07.01.01.00 - when that's released this gets much easier and neater to do - but this method shown here will continue to work.

Code: Select all
async public void taxRates_SaveEnd(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRates taxRates = (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRates)sender;
   
   var dbFactory = new OrmLiteConnectionFactory(taxRates.Manager.Database.ConnectionString, ServiceStack.OrmLite.SqlServer2012Dialect.Provider);
   using (var db = dbFactory.Open())
   {   
      foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesOUT)
      {                     
         JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable  = db.SingleById<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>(taxRate.RecID);         
         string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
         Webhook(taxRates.Manager, body, (taxRate.InsertFlag) ? "taxrate.created" : "taxrate.updated");
      }
      
      foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesIN)
      {                     
         JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable  = db.SingleById<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>(taxRate.RecID);         
         string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
         Webhook(taxRates.Manager, body, (taxRate.InsertFlag) ? "taxrate.created" : "taxrate.updated");
      }
      
      foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesAdjOUT)
      {                     
         JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable  = db.SingleById<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>(taxRate.RecID);         
         string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
         Webhook(taxRates.Manager, body, (taxRate.InsertFlag) ? "taxrate.created" : "taxrate.updated");
      }
      
      foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesAdjIN)
      {                     
         JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable  = db.SingleById<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>(taxRate.RecID);         
         string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
         Webhook(taxRates.Manager, body, (taxRate.InsertFlag) ? "taxrate.created" : "taxrate.updated");
      }
   }                    
   
   // Handle deletes - these will still be in the deleted collection at SaveEnd
   foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesOUT.DeletedCollection)
   {         
      JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main() { TaxID = taxRate.RecID, Description = taxRate.Description, TaxRate = taxRate.TaxRate, DefaultRate = taxRate.IsDefault ? 1 : 0, BASCode = taxRate.BASCode, Disabled = ! taxRate.IsEnabled };
      string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
      Webhook(taxRates.Manager, body, "taxrate.deleted");         
   }
   
   foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesIN.DeletedCollection)
   {         
      JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main() { TaxID = taxRate.RecID, Description = taxRate.Description, TaxRate = taxRate.TaxRate, DefaultRate = taxRate.IsDefault ? 1 : 0, BASCode = taxRate.BASCode, Disabled = ! taxRate.IsEnabled };
      string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
      Webhook(taxRates.Manager, body, "taxrate.deleted");         
   }
   
   foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesAdjOUT.DeletedCollection)
   {         
      JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main() { TaxID = taxRate.RecID, Description = taxRate.Description, TaxRate = taxRate.TaxRate, DefaultRate = taxRate.IsDefault ? 1 : 0, BASCode = taxRate.BASCode, Disabled = ! taxRate.IsEnabled };
      string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
      Webhook(taxRates.Manager, body, "taxrate.deleted");         
   }
   
   foreach (JiwaFinancials.Jiwa.JiwaApplication.JiwaTaxSystemRates.TaxRate taxRate in taxRates.GSTRatesAdjIN.DeletedCollection)
   {         
      JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main TX_MainTable = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main() { TaxID = taxRate.RecID, Description = taxRate.Description, TaxRate = taxRate.TaxRate, DefaultRate = taxRate.IsDefault ? 1 : 0, BASCode = taxRate.BASCode, Disabled = ! taxRate.IsEnabled };
      string body = TX_MainTable.ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.TX_Main>();
      Webhook(taxRates.Manager, body, "taxrate.deleted");         
   }
}


EDIT: Updated code - I realised I was handling deletes wrong.
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: Webhooks Tax

Postby minhhieu106 » Tue May 01, 2018 3:16 pm

Hi Mike,

It work fine now.

Thank you so much!
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 24 guests