public decimal CalculateFullPrice(CSBusiness.ShoppingManagement.Cart cart) { decimal taxToReturn = 0; SitePreference list = CSFactory.GetCartPrefrence(); decimal taxableAmount = cart.SubTotalFullPrice; if (list.IncludeShippingCostInTaxCalculation) { decimal shippingCostDiscount = 0; if (CSWebBase.SiteBasePage.IsFreeShipOrderMainSku(cart)) { shippingCostDiscount = SiteBasePage.GetMainSkuShippingCost(cart); } taxableAmount += cart.ShippingCost; if (cart.ShippingMethod == CSBusiness.Shipping.UserShippingMethodType.Rush) { taxableAmount += cart.RushShippingCost; } taxableAmount -= shippingCostDiscount; // don't count shipping cost amount in tax calcultor } //If this returns a value, it means country has states and we need to //find tax for states if (cart.ShippingAddress.CountryId > 0) { //CodeReview By Sri on 09/15: Need to change TaxRegionCache Object TaxRegion countryRegion = null, stateRegion = null, zipRegion = null; //Comments on 11/2: pulling data from Cache object TaxregionCache cache = new TaxregionCache(HttpContext.Current); List <TaxRegion> taxRegions = (List <TaxRegion>)cache.Value; countryRegion = taxRegions.FirstOrDefault(t => t.CountryId == cart.ShippingAddress.CountryId && t.StateId == 0 && string.IsNullOrEmpty(t.ZipCode)); stateRegion = taxRegions.FirstOrDefault(t => t.CountryId == cart.ShippingAddress.CountryId && t.StateId == cart.ShippingAddress.StateProvinceId && string.IsNullOrEmpty(t.ZipCode)); zipRegion = taxRegions.FirstOrDefault(t => t.CountryId == cart.ShippingAddress.CountryId && t.StateId == cart.ShippingAddress.StateProvinceId && t.ZipCode == cart.ShippingAddress.ZipPostalCode); //Tax regions are always returned by country //taxRegions = CSFactory.GetTaxByCountry(cart.ShippingAddress.CountryId); if (zipRegion != null) { taxToReturn = taxableAmount * zipRegion.Value / 100; } else if (stateRegion != null) { taxToReturn = taxableAmount * stateRegion.Value / 100; } else if (countryRegion != null) { taxToReturn = taxableAmount * countryRegion.Value / 100; } } return(Math.Round(taxToReturn, 2)); }
public static decimal CalculateTaxRate(int orderId, decimal skuPrice) { Order orderItem = new OrderManager().GetBatchProcessOrder(orderId); decimal taxToReturn = 0; SitePreference list = CSFactory.GetCartPrefrence(); decimal taxableAmount = skuPrice; //If this returns a value, it means country has states and we need to //find tax for states if (orderItem.CustomerInfo.ShippingAddress.CountryId > 0) { //CodeReview By Sri on 09/15: Need to change TaxRegionCache Object TaxRegion countryRegion = null, stateRegion = null, zipRegion = null; //Comments on 11/2: pulling data from Cache object TaxregionCache cache = new TaxregionCache(HttpContext.Current); List <TaxRegion> taxRegions = (List <TaxRegion>)cache.Value; countryRegion = taxRegions.FirstOrDefault(t => t.CountryId == orderItem.CustomerInfo.ShippingAddress.CountryId && t.StateId == 0 && string.IsNullOrEmpty(t.ZipCode)); stateRegion = taxRegions.FirstOrDefault(t => t.CountryId == orderItem.CustomerInfo.ShippingAddress.CountryId && t.StateId == orderItem.CustomerInfo.ShippingAddress.StateProvinceId && string.IsNullOrEmpty(t.ZipCode)); zipRegion = taxRegions.FirstOrDefault(t => t.CountryId == orderItem.CustomerInfo.ShippingAddress.CountryId && t.StateId == orderItem.CustomerInfo.ShippingAddress.StateProvinceId && t.ZipCode == orderItem.CustomerInfo.ShippingAddress.ZipPostalCode); //Tax regions are always returned by country //taxRegions = CSFactory.GetTaxByCountry(cart.ShippingAddress.CountryId); if (zipRegion != null) { taxToReturn = zipRegion.Value; } else if (stateRegion != null) { taxToReturn = stateRegion.Value; } else if (countryRegion != null) { taxToReturn = countryRegion.Value; } } return(taxToReturn); }
public decimal CalculateTax(Order order) { decimal taxToReturn = 0; //decimal taxToReturn2 = 0; SitePreference list = CSFactory.GetCartPrefrence(); decimal taxableAmount = 0; if (list.IncludeShippingCostInTaxCalculation) { taxableAmount += order.ShippingCost; } //If this returns a value, it means country has states and we need to //find tax for states //CodeReview By Sri on 09/15: Need to change TaxRegionCache Object TaxRegion countryRegion = null, stateRegion = null, zipRegion = null; //Comments on 11/2: pulling data from Cache object TaxregionCache cache = new TaxregionCache(HttpContext.Current); List <TaxRegion> taxRegions = (List <TaxRegion>)cache.Value; countryRegion = taxRegions.FirstOrDefault(t => t.CountryId == order.CustomerInfo.ShippingAddress.CountryId && t.StateId == 0 && string.IsNullOrEmpty(t.ZipCode)); stateRegion = taxRegions.FirstOrDefault(t => t.CountryId == order.CustomerInfo.ShippingAddress.CountryId && t.StateId == order.CustomerInfo.ShippingAddress.StateProvinceId && string.IsNullOrEmpty(t.ZipCode)); zipRegion = taxRegions.FirstOrDefault(t => t.CountryId == order.CustomerInfo.ShippingAddress.CountryId && t.StateId == order.CustomerInfo.ShippingAddress.StateProvinceId && t.ZipCode == order.CustomerInfo.ShippingAddress.ZipPostalCode); if (zipRegion != null) { taxToReturn = Math.Round(taxableAmount * zipRegion.Value / 100, 2, MidpointRounding.AwayFromZero);; } else if (stateRegion != null) { taxToReturn = Math.Round(taxableAmount * stateRegion.Value / 100, 2, MidpointRounding.AwayFromZero);; } else if (countryRegion != null) { taxToReturn = Math.Round(taxableAmount * countryRegion.Value / 100, MidpointRounding.AwayFromZero);; } taxToReturn = Math.Round(taxToReturn, 2, MidpointRounding.AwayFromZero); int i = 0; foreach (Sku item in order.SkuItems) { i++; decimal itemPrice = item.FullPrice; if (i == 1) { if (order.DiscountAmount > 0) { itemPrice -= order.DiscountAmount; } } if (order.CustomerInfo.ShippingAddress.CountryId > 0) { if (zipRegion != null) { taxToReturn += Math.Round((itemPrice * item.Quantity) * zipRegion.Value / 100, 2, MidpointRounding.AwayFromZero); } else if (stateRegion != null) { taxToReturn += Math.Round((itemPrice * item.Quantity) * stateRegion.Value / 100, 2, MidpointRounding.AwayFromZero); } else if (countryRegion != null) { taxToReturn += Math.Round((itemPrice * item.Quantity) * countryRegion.Value / 100, 2, MidpointRounding.AwayFromZero); } } } //if (order.DiscountAmount > 0) //{ // if (zipRegion != null) // { // taxToReturn += Math.Round(-order.DiscountAmount * zipRegion.Value / 100, 2, MidpointRounding.AwayFromZero); ; // } // else if (stateRegion != null) // { // taxToReturn += Math.Round(-order.DiscountAmount * stateRegion.Value / 100, 2, MidpointRounding.AwayFromZero); ; // } // else if (countryRegion != null) // { // taxToReturn += Math.Round(-order.DiscountAmount * countryRegion.Value / 100, MidpointRounding.AwayFromZero); ; // } //} return(Math.Round(taxToReturn, 2, MidpointRounding.AwayFromZero)); }