Developer forum

Forum » Integration » Taxes and Live Integration

Taxes and Live Integration

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

With the live integration we get back tax information from the ERP. Initially I created a new order line of type Tax inside ProcessResponse to set the tax. However, that line doesn't seem to stick. I then followed the same approach as with the LiveDiscountProvider and implemented and registered a custom LiveTaxProvider as follows:

using System;
using System.Web;
using Dynamicweb.eCommerce.Orders;
using Dynamicweb.eCommerce.Prices;
using Dynamicweb.eCommerce.Products.Taxes;
using Dynamicweb.Extensibility;

namespace Dynamicweb.eCommerce.LiveIntegration
{
  [AddInName("Live integration sales tax"),
  AddInDescription("Apply sales tax retrieved via live integration.")]
  public class LiveTaxProvider : TaxProvider
  {
    public override void AddTaxOrderLinesToOrder(Order order)
    {
      var o = HttpContext.Current.Session["LiveIntegrationTax" + order.ID];
      if (o != null)
      {
        var totalTax = (double)o;
        var tax = new Tax
        {
          Name = Name,
          Amount = new PriceRaw(totalTax, order.Currency),
          CalculateVat = true
        };

        var taxLine = new OrderLine
        {
          Date = DateTime.Now,
          Modified = DateTime.Now,
          ProductName = tax.Name,
          ProductVariantText = this.Name,
          Order = order,
          OrderID = order.ID,
          Quantity = 1.0,
          Type = Base.ChkString((int)Base.ChkInteger(OrderLine.OrderLineType.Tax)),
        };
        taxLine.SetUnitPrice(tax.Price);
        order.OrderLines.Add(taxLine);
      }
    }
  }
}


which does seem to do the trick. Is this required indeed? And if so, should we have something similar in the standard code? Note, in my case I am storing just the tax value in session state, but I could follow the same pattern as with discounts and store the actual lines.

Thoughts?

Imar


Replies

 
Jonas Krarup Dam
Reply

Hi Imar,

This seems like a fine solution to the problem.

It might make sense to add it to the standard code. My main thought is that we have always tried to limit the standard implementation to functionality that is supported out of the box in the systems that we integrate to (NAV and AX). I'm not sure to what extent seperate tax calculation is standard functionality in those systems, but if it is, we could definitely consider including it in the live integration (and the code units) as well.

Regards, Jonas

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I'd say it makes sense as the ERPs handle tax calculation.

I think the problem is that it's often all or nothing. When you let the ERP calculate prices, you want it to do everything: prices, discounts, taxes. If you let Dynamicweb to half and the ERP the other half, you're going to get problems. In this case, since we let the ERP deal with prices, discounts and tax, the integration framework also needs to support the tax handling. Right now I fiddled with it for hours until I realized I needed to have my own TaxProvider.

The sample code (which is what it is, right?) could have a full LiveTaxProvider line mine and then some sample code / comments in the OrderHandler describing how to handle tax in case the ERP returns it. Would that make sense?

Imar

 
Jonas Krarup Dam
Reply

Definitely - I always strongly advise against splitting up the business logic :-)

Sounds like a good idea, and the more I think about it (and read your post), the more it makes sense to handle taxes as well, for completenes.

I'll add it to the backlog, for when we've finished DW9 - if you have any code you'd like to share for this, I would appreciate an email ;-)

/Jonas

 

You must be logged in to post in the forum