Page 1 of 1

Webhooks Tax

PostPosted: Sat Apr 28, 2018 3:30 pm
by minhhieu106
Hi Mike,

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

Please advise how to get it?

Thanks,
Hieu

Re: Webhooks Tax

PostPosted: Sat Apr 28, 2018 4:56 pm
by Mike.Sheen
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

Re: Webhooks Tax

PostPosted: Sun Apr 29, 2018 10:38 am
by minhhieu106
Thank you Mike!

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

Thanks,
Hieu

Re: Webhooks Tax  Topic is solved

PostPosted: Sun Apr 29, 2018 2:10 pm
by Mike.Sheen
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.

Re: Webhooks Tax

PostPosted: Tue May 01, 2018 3:16 pm
by minhhieu106
Hi Mike,

It work fine now.

Thank you so much!