Exemple #1
0
        public TaxInfo GetTaxRates(int portalID)
        {
            TaxInfo taxInfo = (TaxInfo)DataCache.GetCache("StoreCountryTaxRates" + portalID);

            if (taxInfo == null)
            {
                taxInfo = CBO.FillObject <TaxInfo>(DataProvider.Instance().ExecuteReader("Store_Administration_GetCountryTaxRates", portalID));
                if (taxInfo != null)
                {
                    DataCache.SetCache("StoreCountryTaxRates" + portalID, taxInfo);
                }
            }
            return(taxInfo);
        }
Exemple #2
0
        private void LoadTaxRates()
        {
            TaxController controller = new TaxController();
            TaxInfo       taxInfo    = controller.GetTaxRates(PortalId);

            if (taxInfo != null)
            {
                cbEnableTax.Checked    = taxInfo.ShowTax;
                txtDefaultTaxRate.Text = taxInfo.DefaultTaxRate < 0 ? "" : taxInfo.DefaultTaxRate.ToString("0.00");
                BindTaxRates(taxInfo.CountryTaxes);
            }

            IsReady = true;
        }
Exemple #3
0
        /// <summary>
        /// Calculate tax according the country/region of the deliveryAddress.
        /// </summary>
        /// <param name="portalID">ID of the portal</param>
        /// <param name="cartItems">List of ICartItemInfo that need to have taxes calculated on.</param>
        /// <param name="shippingInfo">ShippingInfo in the case that taxes need to be applied to shipping</param>
        /// <param name="billingAddress">The address that the taxes should be applied for.</param>
        /// <returns>ITaxInfo with the total amount of tax due for the cart items shipping cost.</returns>
        public ITaxInfo CalculateSalesTax <T>(int portalID, IEnumerable <T> cartItems, IShippingInfo shippingInfo, IAddressInfo billingAddress) where T : ICartItemInfo
        {
            TaxInfo taxInfo = GetTaxRates(portalID);

            if (taxInfo != null && taxInfo.ShowTax)
            {
                decimal taxRate = taxInfo.DefaultTaxRate / 100;

                if (billingAddress != null && taxInfo.CountryTaxes != null)
                {
                    ListController       listController = new ListController();
                    List <ListEntryInfo> countries      = new List <ListEntryInfo>(listController.GetListEntryInfoItems("Country"));
                    string countryCode = GetEntryValue(billingAddress.CountryCode, countries);
                    string regionCode  = billingAddress.RegionCode;

                    if (!string.IsNullOrEmpty(regionCode))
                    {
                        List <ListEntryInfo> regions = new List <ListEntryInfo>(listController.GetListEntryInfoItems("Region", "Country." + countryCode));
                        regionCode = GetEntryValue(regionCode, regions);
                    }

                    taxRate = GetCountryRegionTaxRate(countryCode, regionCode, billingAddress.PostalCode, taxInfo.CountryTaxes, taxInfo.DefaultTaxRate);
                }

                // Compute Shipping Tax if needed
                taxInfo.ShippingTax = shippingInfo.ApplyTaxRate ? shippingInfo.Cost * taxRate : 0M;
                // Compute Sales Tax
                decimal cartTotal = 0M;
                foreach (T itemInfo in cartItems)
                {
                    cartTotal += (itemInfo.SubTotal - itemInfo.Discount) * taxRate;
                }
                taxInfo.SalesTax = cartTotal + taxInfo.ShippingTax;
            }
            else
            {
                if (taxInfo == null)
                {
                    taxInfo = new TaxInfo();
                }
                taxInfo.ShowTax        = false;
                taxInfo.DefaultTaxRate = 0M;
                taxInfo.SalesTax       = 0M;
                taxInfo.ShippingTax    = 0M;
            }

            return(taxInfo);
        }