Example #1
0
        protected virtual ZoneRecord AppendZone(string zoneID, string description)
        {
            ZoneRecord zr = new ZoneRecord();

            zr.ZoneID      = zoneID;
            zr.Description = description;

            zones.Add(zr);

            return(zr);
        }
Example #2
0
        protected virtual ZoneDetailRecord AppendZoneDetail(ZoneRecord zone, TaxRecord tax)
        {
            ZoneDetailRecord zd = new ZoneDetailRecord();

            zd.ZoneID = zone.ZoneID;
            zd.TaxID  = tax.TaxID;

            zoneDetails.Add(zd);

            return(zd);
        }
Example #3
0
        protected virtual void AppendZip(ZoneRecord zone, TXImportFileData t)
        {
            var zips = from z in zipData
                       where z.ZipCode == t.ZipCode && z.CountyName == t.CountyName
                       select z;

            bool added = false;

            foreach (TXImportZipFileData zz in zips)
            {
                ZoneZipPlusRecord pr = new ZoneZipPlusRecord();
                pr.ZoneID  = zone.ZoneID;
                pr.ZipCode = t.ZipCode;
                pr.ZipMin  = zz.Plus4PortionOfZipCode;
                pr.ZipMax  = zz.Plus4PortionOfZipCode2;

                if (zoneZipPlus.ContainsKey(zone))
                {
                    zoneZipPlus[zone].Add(pr);
                }
                else
                {
                    List <ZoneZipPlusRecord> list = new List <ZoneZipPlusRecord>();
                    list.Add(pr);
                    zoneZipPlus.Add(zone, list);
                }

                added = true;
            }

            if (!added)
            {
                ZoneZipPlusRecord pr = new ZoneZipPlusRecord();
                pr.ZoneID  = zone.ZoneID;
                pr.ZipCode = t.ZipCode;
                pr.ZipMin  = 1;
                pr.ZipMax  = 9999;

                if (zoneZipPlus.ContainsKey(zone))
                {
                    zoneZipPlus[zone].Add(pr);
                }
                else
                {
                    List <ZoneZipPlusRecord> list = new List <ZoneZipPlusRecord>();
                    list.Add(pr);
                    zoneZipPlus.Add(zone, list);
                }
            }
        }
Example #4
0
        protected override void ExecuteBuilder()
        {
            TaxRecord  stateTax = null;
            TaxRecord  zeroTax  = null;
            ZoneRecord zeroZone = null;
            Dictionary <string, ZoneRecord> zoneDict = new Dictionary <string, ZoneRecord>();

            Dictionary <string, TaxRecord> districtTax        = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> districtTransitTax = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> districtOther1Tax  = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> districtOther2Tax  = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> districtOther3Tax  = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> districtOther4Tax  = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> cityTax            = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> cityTransitTax     = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> cityOther1Tax      = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> cityOther2Tax      = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> cityOther3Tax      = new Dictionary <string, TaxRecord>();
            Dictionary <string, TaxRecord> cityOther4Tax      = new Dictionary <string, TaxRecord>();


            foreach (TXImportFileData t in data)
            {
                string           zoneKey = State;
                List <TaxRecord> list    = new List <TaxRecord>();

                if (!HasTax(t))
                {
                    if (zeroTax == null)
                    {
                        zeroTax = AppendTax(State + "ZERO", "NO Tax", t.CombinedSalesTaxRate, t.CombinedSalesTaxRateEffectiveDate, t.CombinedSalesTaxPreviousRate);
                        SetFlags(zeroTax, t);

                        zeroZone              = new ZoneRecord();
                        zeroZone.ZoneID       = "NO Tax";
                        zeroZone.Description  = "No Tax";
                        zeroZone.CombinedRate = t.CombinedSalesTaxRate;
                        zones.Add(zeroZone);

                        AppendZoneDetail(zeroZone, zeroTax);
                    }

                    AppendZip(zeroZone, t);
                }
                else
                {
                    if (stateTax == null)
                    {
                        stateTax               = AppendTax(State + "STATE", State + " State Tax");
                        stateTax.Rate          = t.StateSalesTaxRate;
                        stateTax.PreviousRate  = t.StateSalesTaxPreviousRate;
                        stateTax.EffectiveDate = t.StateSalesTaxRateEffectiveDate;
                        SetFlags(stateTax, t);
                    }

                    if (t.StateSalesTaxRate > 0)
                    {
                        list.Add(stateTax);
                    }

                    #region County
                    if (t.CountySalesTaxRate > 0 || t.CountySalesTaxPreviousRate > 0)
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeCounty))
                        {
                            zoneKey = t.SignatureCodeCounty;
                        }

                        if (!districtTax.ContainsKey(t.SignatureCodeCounty))
                        {
                            string    taxID = t.StateCode + t.SignatureCodeCounty;
                            TaxRecord info  = AppendTax(taxID, "County Tax " + t.CountyName);
                            info.Rate          = t.CountySalesTaxRate;
                            info.PreviousRate  = t.CountySalesTaxPreviousRate;
                            info.EffectiveDate = t.CountySalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            districtTax.Add(t.SignatureCodeCounty, info);
                            list.Add(info);

                            info.CountyCode = t.SignatureCodeCounty;
                            info.CountyName = t.CountyName;
                        }
                        else
                        {
                            list.Add(districtTax[t.SignatureCodeCounty]);
                        }
                    }

                    if (t.TransitTaxIsCity == "C" && (t.TransitSalesTaxRate > 0 || t.TransitSalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeTransit))
                        {
                            zoneKey = t.SignatureCodeTransit;
                        }

                        if (!districtTransitTax.ContainsKey(t.SignatureCodeTransit))
                        {
                            string    taxID = t.StateCode + "CT" + t.SignatureCodeTransit;
                            TaxRecord info  = AppendTax(taxID, "Transit Tax " + t.CityName);
                            info.Rate          = t.TransitSalesTaxRate;
                            info.PreviousRate  = t.TransitSalesTaxPreviousRate;
                            info.EffectiveDate = t.TransitSalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            districtTransitTax.Add(t.SignatureCodeTransit, info);
                            list.Add(info);

                            info.CountyCode = t.SignatureCodeTransit;
                            info.CountyName = t.CountyName;
                        }
                        else
                        {
                            list.Add(districtTransitTax[t.SignatureCodeTransit]);
                        }
                    }
                    if (t.Other1TaxIsCity == "C" && (t.Other1SalesTaxRate > 0 || t.Other1SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther1))
                        {
                            zoneKey = t.SignatureCodeOther1;
                        }

                        if (!districtOther1Tax.ContainsKey(t.SignatureCodeOther1))
                        {
                            string    taxID = t.StateCode + "CO1" + t.SignatureCodeOther1;
                            TaxRecord info  = AppendTax(taxID, "County Other 1 Tax " + t.CountyName);
                            info.Rate          = t.Other1SalesTaxRate;
                            info.PreviousRate  = t.Other1SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other1SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            districtOther1Tax.Add(t.SignatureCodeOther1, info);
                            list.Add(info);

                            info.CountyCode = t.SignatureCodeOther1;
                            info.CountyName = t.CountyName;
                        }
                        else
                        {
                            list.Add(districtOther1Tax[t.SignatureCodeOther1]);
                        }
                    }
                    if (t.Other2TaxIsCity == "C" && (t.Other2SalesTaxRate > 0 || t.Other2SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther2))
                        {
                            zoneKey = t.SignatureCodeOther2;
                        }

                        if (!districtOther2Tax.ContainsKey(t.SignatureCodeOther2))
                        {
                            string    taxID = t.StateCode + "CO2" + t.SignatureCodeOther2;
                            TaxRecord info  = AppendTax(taxID, "County Other 2 Tax " + t.CountyName);
                            info.Rate          = t.Other2SalesTaxRate;
                            info.PreviousRate  = t.Other2SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other2SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            districtOther2Tax.Add(t.SignatureCodeOther2, info);
                            list.Add(info);

                            info.CountyCode = t.SignatureCodeOther2;
                            info.CountyName = t.CountyName;
                        }
                        else
                        {
                            list.Add(districtOther2Tax[t.SignatureCodeOther2]);
                        }
                    }
                    if (t.Other3TaxIsCity == "C" && (t.Other3SalesTaxRate > 0 || t.Other3SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther3))
                        {
                            zoneKey = t.SignatureCodeOther3;
                        }

                        if (!districtOther3Tax.ContainsKey(t.SignatureCodeOther3))
                        {
                            string    taxID = t.StateCode + "CO3" + t.SignatureCodeOther3;
                            TaxRecord info  = AppendTax(taxID, "County Other 3 Tax " + t.CountyName);
                            info.Rate          = t.Other3SalesTaxRate;
                            info.PreviousRate  = t.Other3SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other3SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            districtOther3Tax.Add(t.SignatureCodeOther3, info);
                            list.Add(info);

                            info.CountyCode = t.SignatureCodeOther3;
                            info.CountyName = t.CountyName;
                        }
                        else
                        {
                            list.Add(districtOther3Tax[t.SignatureCodeOther3]);
                        }
                    }

                    if (t.Other4TaxIsCity == "C" && (t.Other4SalesTaxRate > 0 || t.Other4SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther4))
                        {
                            zoneKey = t.SignatureCodeOther4;
                        }

                        if (!districtOther4Tax.ContainsKey(t.SignatureCodeOther4))
                        {
                            string    taxID = t.StateCode + "CO4" + t.SignatureCodeOther4;
                            TaxRecord info  = AppendTax(taxID, "County Other 4 Tax " + t.CountyName);
                            info.Rate          = t.Other4SalesTaxRate;
                            info.PreviousRate  = t.Other4SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other4SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            districtOther4Tax.Add(t.SignatureCodeOther4, info);
                            list.Add(info);

                            info.CountyCode = t.SignatureCodeOther4;
                            info.CountyName = t.CountyName;
                        }
                        else
                        {
                            list.Add(districtOther4Tax[t.SignatureCodeOther4]);
                        }
                    }
                    #endregion

                    #region City
                    if (t.CitySalesTaxRate > 0 || t.CitySalesTaxPreviousRate > 0)
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeCity))
                        {
                            zoneKey = t.SignatureCodeCity;
                        }

                        if (!cityTax.ContainsKey(t.SignatureCodeCity))
                        {
                            string    taxID = t.StateCode + (t.SignatureCodeCity);
                            TaxRecord info  = AppendTax(taxID, "City Tax " + t.CityName);
                            info.Rate          = t.CitySalesTaxRate;
                            info.PreviousRate  = t.CitySalesTaxPreviousRate;
                            info.EffectiveDate = t.CitySalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            cityTax.Add(t.SignatureCodeCity, info);
                            list.Add(info);

                            info.CityCode = t.SignatureCodeCity;
                            info.CityName = t.CityName;
                        }
                        else
                        {
                            list.Add(cityTax[t.SignatureCodeCity]);
                        }
                    }

                    if (t.TransitTaxIsCity == "T" && (t.TransitSalesTaxRate > 0 || t.TransitSalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeTransit))
                        {
                            zoneKey = t.SignatureCodeTransit;
                        }

                        if (!cityTransitTax.ContainsKey(t.SignatureCodeTransit))
                        {
                            string    taxID = t.StateCode + "TT" + (t.SignatureCodeCounty);
                            TaxRecord info  = AppendTax(taxID, "City Transit Tax " + t.CityName);
                            info.Rate          = t.TransitSalesTaxRate;
                            info.PreviousRate  = t.TransitSalesTaxPreviousRate;
                            info.EffectiveDate = t.TransitSalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            cityTransitTax.Add(t.SignatureCodeTransit, info);
                            list.Add(info);

                            info.CityCode = t.SignatureCodeTransit;
                            info.CityName = t.CityName;
                        }
                        else
                        {
                            list.Add(cityTransitTax[t.SignatureCodeTransit]);
                        }
                    }
                    if (t.Other1TaxIsCity == "T" && (t.Other1SalesTaxRate > 0 || t.Other1SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther1))
                        {
                            zoneKey = t.SignatureCodeOther1;
                        }

                        if (!cityOther1Tax.ContainsKey(t.SignatureCodeOther1))
                        {
                            string    taxID = t.StateCode + "TO1" + (t.SignatureCodeOther1);
                            TaxRecord info  = AppendTax(taxID, "City Other 1 Tax " + t.CityName);
                            info.Rate          = t.Other1SalesTaxRate;
                            info.PreviousRate  = t.Other1SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other1SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            cityOther1Tax.Add(t.SignatureCodeOther1, info);
                            list.Add(info);

                            info.CityCode = t.SignatureCodeOther1;
                            info.CityName = t.CityName;
                        }
                        else
                        {
                            list.Add(cityOther1Tax[t.SignatureCodeOther1]);
                        }
                    }
                    if (t.Other2TaxIsCity == "T" && (t.Other2SalesTaxRate > 0 || t.Other2SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther2))
                        {
                            zoneKey = t.SignatureCodeOther2;
                        }

                        if (!cityOther2Tax.ContainsKey(t.SignatureCodeOther2))
                        {
                            string    taxID = t.StateCode + "TO2" + (t.SignatureCodeOther2);
                            TaxRecord info  = AppendTax(taxID, "City Other 2 Tax " + t.CityName);
                            info.Rate          = t.Other2SalesTaxRate;
                            info.PreviousRate  = t.Other2SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other2SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            cityOther2Tax.Add(t.SignatureCodeOther2, info);
                            list.Add(info);

                            info.CityCode = t.SignatureCodeOther2;
                            info.CityName = t.CityName;
                        }
                        else
                        {
                            list.Add(cityOther2Tax[t.SignatureCodeOther2]);
                        }
                    }
                    if (t.Other3TaxIsCity == "T" && (t.Other3SalesTaxRate > 0 || t.Other3SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther3))
                        {
                            zoneKey = t.SignatureCodeOther3;
                        }

                        if (!cityOther3Tax.ContainsKey(t.SignatureCodeOther3))
                        {
                            string    taxID = t.StateCode + "TO3" + t.SignatureCodeOther3;
                            TaxRecord info  = AppendTax(taxID, "City Other 3 Tax " + t.CityName);
                            info.Rate          = t.Other3SalesTaxRate;
                            info.PreviousRate  = t.Other3SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other3SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            cityOther3Tax.Add(t.SignatureCodeOther3, info);
                            list.Add(info);

                            info.CityCode = t.CityTaxCodeAssignedByState ?? t.OtherTaxCode1AssignedByState;
                            info.CityName = t.CityName;
                        }
                        else
                        {
                            list.Add(cityOther3Tax[t.SignatureCodeOther3]);
                        }
                    }

                    if (t.Other4TaxIsCity == "T" && (t.Other4SalesTaxRate > 0 || t.Other4SalesTaxPreviousRate > 0))
                    {
                        if (!string.IsNullOrEmpty(t.SignatureCodeOther4))
                        {
                            zoneKey = t.SignatureCodeOther4;
                        }

                        if (!cityOther4Tax.ContainsKey(t.SignatureCodeOther4))
                        {
                            string    taxID = t.StateCode + "TO4" + t.SignatureCodeOther4;
                            TaxRecord info  = AppendTax(taxID, "City Other 4 Tax " + t.CityName);
                            info.Rate          = t.Other4SalesTaxRate;
                            info.PreviousRate  = t.Other4SalesTaxPreviousRate;
                            info.EffectiveDate = t.Other4SalesTaxRateEffectiveDate;
                            SetFlags(info, t);
                            cityOther4Tax.Add(t.SignatureCodeOther4, info);
                            list.Add(info);

                            info.CityCode = t.SignatureCodeOther4;
                            info.CityName = t.CityName;
                        }
                        else
                        {
                            list.Add(cityOther4Tax[t.SignatureCodeOther4]);
                        }
                    }
                    #endregion


                    ZoneRecord zr = null;
                    if (!zoneDict.ContainsKey(zoneKey))
                    {
                        string countyZoneID = null;
                        string cityZoneID   = null;
                        string cityName     = null;
                        string countyName   = null;

                        foreach (TaxRecord tr in list)
                        {
                            if (countyZoneID == null && !string.IsNullOrEmpty(tr.CountyCode))
                            {
                                countyZoneID = State + tr.CountyCode;
                                countyName   = tr.CountyName;
                            }
                            else if (countyZoneID != null && !string.IsNullOrEmpty(tr.CountyCode))
                            {
                                if (countyZoneID != (State + tr.CountyCode))
                                {
                                    Debug.Print(string.Format("CountyZoneID mismatch {0} <> {1}", countyZoneID, (State + tr.CountyCode)));
                                }
                            }

                            if (cityZoneID == null && !string.IsNullOrEmpty(tr.CityCode))
                            {
                                cityZoneID = State + tr.CityCode;
                                cityName   = tr.CityName;
                            }
                            else if (cityZoneID != null && !string.IsNullOrEmpty(tr.CityCode))
                            {
                                if (cityZoneID != (State + tr.CityCode))
                                {
                                    Debug.Print(string.Format("CityZoneID mismatch {0} <> {1}", cityZoneID, (State + tr.CityCode)));
                                }
                            }
                        }

                        string zoneID   = cityZoneID;
                        string zoneDesc = countyName;

                        if (zoneID == null)
                        {
                            zoneID = countyZoneID;
                        }

                        if (!string.IsNullOrEmpty(cityName))
                        {
                            zoneDesc = cityName + " - " + countyName;
                        }


                        if (zoneID == null)
                        {
                            zoneID = zoneKey;
                        }

                        if (zoneDesc == null)
                        {
                            zoneDesc = State;
                        }

                        zr              = new ZoneRecord();
                        zr.ZoneID       = zoneID;
                        zr.Description  = zoneDesc;
                        zr.CombinedRate = t.CombinedSalesTaxRate;
                        zones.Add(zr);
                        zoneDict.Add(zoneKey, zr);

                        foreach (TaxRecord tr in list)
                        {
                            AppendZoneDetail(zr, tr);
                        }
                    }
                    else
                    {
                        zr = zoneDict[zoneKey];
                    }


                    AppendZip(zr, t);
                }
            }
        }