Page 1 of 2

washington state sales tax integration

Posted: Tue Jul 01, 2008 11:05 pm
by compunerdy
http://dor.wa.gov/Content/FindTaxesAndR ... rface.aspx

Anyone want to tackle making that work?
I know there are a few people on these boards willing to pay for integration for this along with me.

Re: washington state sales tax integration

Posted: Wed Jul 02, 2008 10:11 am
by nickc
Hmm. I may wind up doing this. How many is "a few"?

Re: Washington state sales tax integration

Posted: Wed Jul 02, 2008 11:31 am
by calvis
Put me on the list as a potential contributor.

Re: washington state sales tax integration

Posted: Wed Jul 02, 2008 5:16 pm
by WylieE
We're working on it. Not sure when it will be ready for prime time though.

Re: washington state sales tax integration

Posted: Wed Jul 02, 2008 5:51 pm
by nickc
Are you implementing using ITaxProvider?

Re: washington state sales tax integration

Posted: Wed Jul 02, 2008 5:56 pm
by WylieE
No. Homegrown. It's just one of many things we're working on with our new website though. It may not see the light of day for a bit.

Be sure to check out: http://dor.wa.gov/Content/FindTaxesAndR ... brary.aspx

There's quite a bit of information between the two pages listed in this thread.

Re: washington state sales tax integration

Posted: Tue Sep 30, 2008 11:39 am
by compunerdy
Anybody get this working or a similar solution?

Re: washington state sales tax integration

Posted: Tue Sep 30, 2008 12:06 pm
by BryanWarmoth
I created a TaxLookup Class that has methods the use the web services provided by the Department of Revenue of Washington State.
http://dor.wa.gov/Content/FindTaxesAndR ... rface.aspx

They include a c# example that I followed to create the class. The main method of the class takes a basket as a parameter and then grabs the shipping address and applies the correct tax to the order if the customer lives in Washington. It also saves the location code in the shipping fax number field because we don't use if for anything else but I'm sure you could add an extra field if you needed to. The method then returns the basket object back.

NOTE: You have to create a tax code and a tax rule for each of the percentages in washington state. They range from .075 - .090. You then have to set each rule to its corresponding code. Once you get the correct tax rate from WA DOR then find the right tax code and apply it to every item in the basket.

I then added code to the OnePageCheckout ConLib in the RecalculateBasket method to call my tax lookup method. IMPORTANT: Make sure you call basket.Recalculate() after the first big if statement and then add your tax lookup code and then recalculate the basket again so that tax will be applied to the shipping amount as well. You have to repeat this process for the Admin area if you use it to place orders. I put the code inside the UpdateShipMethod() method in PlaceOrder2.aspx.

Hope this helps. Let me know if you need any more help.

Re: washington state sales tax integration

Posted: Tue Sep 30, 2008 12:11 pm
by compunerdy
Are you willing to share the code or sell it?

Re: washington state sales tax integration

Posted: Tue Sep 30, 2008 1:50 pm
by WylieE
compunerdy wrote:Are you willing to share the code or sell it?
Since most of the code came from WA state, I don't think it would be proper to sell.

Seriously, check out the work the DoR has done. It is fairly complete. If it doesn't make sense, let us know where you need help.

Re: washington state sales tax integration

Posted: Wed Oct 01, 2008 10:35 am
by compunerdy
I am not much of a programmer so if you can share the modified files that would be great. If not then I am still looking for someone willing to turn this into a for sale module or share the files to make it work.

Re: washington state sales tax integration

Posted: Wed Oct 01, 2008 3:52 pm
by BryanWarmoth
Sorry for the wait. Hopefully this will help you out. The code hasn't been tested in a production environment yet but it has been working while we have been testing.

First you need to create a tax code and a corresponding tax rule for every tax rate in washington (0.075-0.090).

Create a new c# class file called TaxLookUp.cs in your App_Code folder and paste this code into it:

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Orders;
using CommerceBuilder.Taxes;
using System.Net;
using System.IO;
using System.Xml;

/// <summary>
/// Summary description for TaxLookUp
/// </summary>
public class TaxLookUp
{
    public TaxLookUp()
    {

    }

    public Basket getTaxCodes(Basket basket)
    {
        BasketShipment shipment = basket.Shipments[0];
        XmlDocument doc = new XmlDocument();
        string xml = "";
        if (shipment.Address.ProvinceId == 93)
        {

            WebClient wc = new WebClient();
            string protocol = "http";
            string server = "dor.wa.gov";
            string port = "";
            string street = shipment.Address.Address1;
            string city = shipment.Address.City;
            string zip = shipment.Address.PostalCode;
            

            string urlPrefix = protocol +
                        "://" + server +
                        "/AddressRates.aspx?output=xml";

            string uri = urlPrefix +
                        "&addr=" +
                        street +
                        "&city=" +
                        city +
                        "&zip=" +
                        zip;
        
            
            StreamReader reader = new StreamReader(wc.OpenRead(uri));
            xml = reader.ReadToEnd();
            reader.Close();
        
        

            // Now parse the XML
            // ...
            //doc = new XmlDocument();
            doc.LoadXml(xml);
            //doc.Save(Server);

            XmlNode node = doc.SelectSingleNode("response");
            XmlNode addressNode = doc.SelectSingleNode("addressline");
            string locCode = node.Attributes["loccode"].Value;
            string rate = node.Attributes["rate"].Value;
            shipment.Address.Fax = locCode;
            shipment.Address.Save();

            //Get the right tax code
            //Set the tax code variable equally to the id of the tax code in your database
            int taxCode = 0;

            switch (rate)
            {
                case "0.075":
                    taxCode = 5;
                    break;
                case "0.076":
                    taxCode = 6;
                    break;
                case "0.077":
                    taxCode = 7;
                    break;
                case "0.078":
                    taxCode = 8;
                    break;
                case "0.079":
                    taxCode = 9;
                    break;
                case "0.080":
                    taxCode = 10;
                    break;
                case "0.081":
                    taxCode = 11;
                    break;
                case "0.082":
                    taxCode = 12;
                    break;
                case "0.083":
                    taxCode = 13;
                    break;
                case "0.084":
                    taxCode = 14;
                    break;
                case "0.085":
                    taxCode = 15;
                    break;
                case "0.086":
                    taxCode = 16;
                    break;
                case "0.087":
                    taxCode = 17;
                    break;
                case "0.088":
                    taxCode = 18;
                    break;
                case "0.089":
                    taxCode = 19;
                    break;
                case "0.090":
                    taxCode = 20;
                    break;
                default:
                    break;
            }


            foreach (BasketItem item in basket.Items)
            {
                item.TaxCodeId = taxCode;
            }
            basket.Shipments[0].ShipMethod.TaxCodeId = taxCode;
            basket.Save();
        }
        
    //return basket;
        return basket;
    }
}
Take a close look at the switch statment. I am setting the tax codes based on the rate that WA DOR returns. The numbers I am using are the ids of the tax codes in my database so most likely you will need to change them.

You will then need to call the function to add the correct tax to a customers basket.
Go to ConLib/OnePageCheckout.ascx.cs and replace the recalculateBasket() function with this:

Code: Select all

private void RecalculateBasket(bool rebindPaymentForms)
    {
        Basket basket = Token.Instance.User.Basket;
        if (trShowRates.Visible)
        {
            int shipmentIndex = 0;
            foreach (RepeaterItem item in ShipmentList.Items)
            {
                BasketShipment shipment = basket.Shipments[shipmentIndex];
                DropDownList ShipMethodList = (DropDownList)item.FindControl("ShipMethodList");
                if (ShipMethodList != null)
                {
                    shipment.ShipMethodId = AlwaysConvert.ToInt(ShipMethodList.SelectedValue);
                }
                else
                {
                    shipment.ShipMethodId = 0;
                }
                shipment.Save();
                shipmentIndex++;
            }
        }

        basket.Recalculate();
        if (rebindPaymentForms) BindPaymentMethodForms();
        //Adding washington state taxes to each item in the basket
        TaxLookUp taxes = new TaxLookUp();
        basket = taxes.getTaxCodes(basket);

        //RECALCULATE SHIPPING, TAXES, DISCOUNTS, ETC.
        basket.Recalculate();
        _CurrentBasketHash = basket.GetContentHash(OrderItemType.Product);
        if (rebindPaymentForms) BindPaymentMethodForms();
    }
The correct tax should be applied. Let me know if you have any questions.

Re: washington state sales tax integration

Posted: Wed Oct 01, 2008 8:09 pm
by Shopping Cart Admin
Hello Bryan,

Looks like this might end up being a good reference post and wiki doc! Thank you for your contribution.

Re: washington state sales tax integration

Posted: Wed Oct 01, 2008 9:09 pm
by compunerdy
Ok..

So I create a tax code for 7.5%, 7.6%, etc..

Then I create a tax rule for each as well? What do I do for the postal code fields?

Re: washington state sales tax integration

Posted: Thu Oct 02, 2008 9:59 am
by BryanWarmoth
Yep, you will have to create a tax rule for each of the tax codes. They should have a 1 to 1 relationship so each tax code should have only one tax rule. You do not need to put anything into the postal code field since we do not want able commerce to apply the tax code based on the postal code.

Re: washington state sales tax integration

Posted: Thu Oct 02, 2008 10:34 am
by compunerdy
Ok..still a tad confused :oops:

1. Do I need to worry about assigning items to the tax codes?

2. Does it matter that all the items are already assigned to a different tax code?

Or does the code ignore all of this anyways so just do what you said to do and quit thinking so hard? :idea:

Re: washington state sales tax integration

Posted: Thu Oct 02, 2008 4:04 pm
by WylieE
compunerdy wrote:Ok..still a tad confused :oops:

1. Do I need to worry about assigning items to the tax codes?

2. Does it matter that all the items are already assigned to a different tax code?

Or does the code ignore all of this anyways so just do what you said to do and quit thinking so hard? :idea:
No tax codes are assigned to individual items. I believe you'll need to remove taxation from the items, otherwise you may end up with duplicate taxes against the order.

Re: washington state sales tax integration

Posted: Thu Oct 02, 2008 5:51 pm
by BryanWarmoth
You don't need to worry about adding tax codes to items. I'm not sure if it matter if they already have tax codes applied to them. None of our items have a tax code associated with them. The code replaces the taxcodeid of each item in the basket but I don't know if Able Commerce replaces them later at checkout or not. Let me know if it works with the tax codes already set or not.

Re: washington state sales tax integration

Posted: Thu Oct 02, 2008 11:50 pm
by compunerdy
I did just what you said to do and I did not change any of my previous setup and it looks to be working fine.

THANKS!!!

Re: washington state sales tax integration

Posted: Fri Oct 03, 2008 12:49 am
by calvis
Hey Tim,

This is great news that you got the code working!!!

It's great that we have so many Washingtonians willing to share code on here. Especially code that deals with the DOR. I went though one audit with those guys and don't wish to do it again.

Re: washington state sales tax integration

Posted: Fri Oct 03, 2008 12:58 am
by Shopping Cart Admin
Hello,

Mirrored and moved to good reference posts and this should be a good wiki as well. Thanks again for sharing, we really do have a great community!

Re: washington state sales tax integration

Posted: Sat Jan 31, 2009 2:42 pm
by compunerdy
This did collect the correct sales tax amount as far as I can tell. My system was screwed up a bit because of my initial setup. I think I have it setup correctly now though.

When you go to file the state tax's how are you figuring out which countys you sold to? I know how much of each percentage rate I collected but no clue what amount to which county like the tax setup is asking for.

Re: washington state sales tax integration

Posted: Mon Feb 02, 2009 10:06 am
by WylieE
compunerdy wrote:This did collect the correct sales tax amount as far as I can tell. My system was screwed up a bit because of my initial setup. I think I have it setup correctly now though.

When you go to file the state tax's how are you figuring out which countys you sold to? I know how much of each percentage rate I collected but no clue what amount to which county like the tax setup is asking for.
There is a form to fill out on the DOR website. (I cannot find it right now) The form has you list the location code along with the total sales and sales tax collected. My understanding is you use the location code for filing and not the county since sales tax can change within the county due to various taxing districts.

Re: washington state sales tax integration

Posted: Mon Feb 02, 2009 11:44 am
by compunerdy
Ok..yes when I went to fill out the form online it asks for the name or location code.. The problem is how do I know which location codes we sold to? As far as I know all I can easily see is what percentage rate we charged yet there will be like 10 location codes with the same percentage rate.

Re: washington state sales tax integration

Posted: Mon Feb 02, 2009 11:56 am
by WylieE
compunerdy wrote:Ok..yes when I went to fill out the form online it asks for the name or location code.. The problem is how do I know which location codes we sold to? As far as I know all I can easily see is what percentage rate we charged yet there will be like 10 location codes with the same percentage rate.
Uh... you didn't capture that information when you looked up the tax rates ??? :shock: We use the sales tax integration routine to capture the location code (we stuff it in the fax number since we do not track shipping fax numbers)

Hmmm... If you have a limited number of WA customers, it may not be too painful to manually look up the info this time. Otherwise, yuck and double yuck!