Now you can automatically apply tax to opportunities, quotes, orders and invoices without having to write javascript or custom code, simply create a tax rule record in crm and watch it magically calculate the tax amounts.
You can specify a tax rate per product, per currency or a global tax rate.
We've seen various installations of Dynamics CRM using different techniques to calculate tax or no tax at all so we thought we'd release the plugin we use to manage tax rates.
If you'd like to use this plugin in your organization please contact us.
if (context.Depth == 1 && // avoid infinite loops
EntityIsOK(context.PrimaryEntityName) && // make sure we only hook into what we support
MessageIsOK(context.MessageName)) // make sure the message is either create or update
{
DynamicEntity entity = context.InputParameters.Properties["Target"] as DynamicEntity;
if (entity != null)
{
// linq access to dynamics crm
CrmDataContext xrmDataContext = new CrmDataContext(context.CreateCrmService(true));
xrmDataContext.QueryThrough = QueryThroughType.FetchXml;
// base class + specific classes to handle invoice/opportunity/order/quote tax
TaxLogicBase applier = TaxLogicFactory.CreateInstance(xrmDataContext, entity);
// update the entity with the calculated tax rate based on the rules specified
applier.Apply();
}
}