Exemplo n.º 1
0
        /// <summary>
        /// Calculate tax according the region in the deliveryAddress argument.
        /// </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="deliveryAddress">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 deliveryAddress) where T : ICartItemInfo
        {
            TaxInfo taxInfo = GetTaxRates(portalID);

            if (taxInfo != null && taxInfo.ShowTax)
            {
                decimal taxRate = (taxInfo.DefaultTaxRate / 100);
                // 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);
        }
Exemplo n.º 2
0
        private void LoadTaxRates()
        {
            TaxController controller = new TaxController();
            TaxInfo       taxInfo    = controller.GetTaxRates(PortalId);

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

            IsReady = true;
        }
Exemplo n.º 3
0
        public TaxInfo GetTaxRates(int portalID)
        {
            TaxInfo taxInfo = (TaxInfo)DataCache.GetCache("StoreTaxRates" + portalID);

            if (taxInfo == null)
            {
                taxInfo = CBO.FillObject <TaxInfo>(DataProvider.Instance().ExecuteReader("Store_Administration_GetTaxRates", portalID));
                if (taxInfo != null)
                {
                    DataCache.SetCache("StoreTaxRates" + portalID, taxInfo);
                }
            }
            return(taxInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate tax according the region in the deliveryAddress argument.
        /// </summary>
        /// <param name="portalID">ID of the portal</param>
        /// <param name="cartItems">ArrayList of ItemInfo 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="deliveryAddress">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(int portalID, ArrayList cartItems, Shipping.IShippingInfo shippingInfo, Address.IAddressInfo deliveryAddress)
        {
            TaxInfo taxInfo = new TaxInfo();

            taxInfo = GetTaxRates(portalID);
            //decimal regionTaxRate = 0M;
            //if (deliveryAddress.RegionCode != null && deliveryAddress.RegionCode.Length > 0)
            //{
                //NOTE: The registration address uses country and region text(ex. Idaho) rather than code(ex. ID).
                //      As a result all address are stored using the coutnry and region text rather then code.
                //      We have to lookup the region code here, because taxes are associated with region codes.
                //      This is only done for the United States since the DefaultTaxProvider only recognizes the United States.
            //	if ( "united states".Equals(deliveryAddress.CountryCode.ToLower()) || "us".Equals(deliveryAddress.CountryCode.ToLower() ) )
            //	{
            //		ListController ctlEntry = new ListController();
            //		ListEntryInfoCollection regionCollection = ctlEntry.GetListEntryInfoCollection("Region", "", "Country.US");

            //		foreach(DotNetNuke.Common.Lists.ListEntryInfo entry in regionCollection)
            //		{
            //			if (entry.Text.Equals(deliveryAddress.RegionCode))
            //			{
            //				if (taxRates.Contains(entry.Value))
            //				{
            //					regionTaxRate = decimal.Parse((string)taxRates[entry.Value]);
            //				}
            //				break;
            //			}
            //		}
            //	}
            //}

            decimal cartTotal = shippingInfo.Cost;
            foreach (DotNetNuke.Modules.Store.Cart.ItemInfo itemInfo in cartItems)
            {
                cartTotal += itemInfo.Quantity * itemInfo.UnitCost;
            }

            taxInfo.SalesTax = cartTotal * (taxInfo.DefaultTaxRate/100);

            return taxInfo;
        }
Exemplo n.º 5
0
        public TaxInfo GetTaxRates(int portalID)
        {
            IDataReader reader = DataProvider.Instance().GetTaxRates(portalID);
            TaxInfo taxInfo = new TaxInfo();

            if (reader.Read())
            {
                taxInfo.DefaultTaxRate = (reader["DefaultTaxRate"] == System.DBNull.Value) ? -1 : (decimal)reader["DefaultTaxRate"];
                taxInfo.ShowTax = (bool)reader["ShowTax"];
            }

            return taxInfo;
        }
Exemplo n.º 6
0
        public ITaxInfo GetDefautTaxRates(int portalID)
        {
            TaxInfo taxInfo = new TaxInfo();

            taxInfo = GetTaxRates(portalID);
            return taxInfo;
        }