private void UpdateTaxRates(List <TaxRateInfo> taxRateInfos) { using (esTransactionScope transaction = new esTransactionScope()) { int storeId = StoreContext.CurrentStore.Id.Value; //---- delete all tax regions for this store TaxRegionQuery q = new TaxRegionQuery(); q.Where(q.StoreId == storeId); TaxRegionCollection taxRegions = new TaxRegionCollection(); taxRegions.Load(q); taxRegions.MarkAllAsDeleted(); taxRegions.Save(); //---- and re-insert them // remove duplicate entries taxRateInfos.RemoveDuplicates((left, right) => (left.CountryCode == right.CountryCode && left.Region == right.Region) ? 1 : -1); foreach (TaxRateInfo taxRate in taxRateInfos) { TaxRegion newTaxRegion = taxRegions.AddNew(); newTaxRegion.StoreId = storeId; newTaxRegion.CountryCode = taxRate.CountryCode; newTaxRegion.Region = taxRate.Region; newTaxRegion.TaxRate = taxRate.TaxRate; } taxRegions.Save(); transaction.Complete(); } }
public static TaxRegion CreateTaxRegion(string locationId, global::System.DateTimeOffset validFrom, global::System.DateTimeOffset validTo) { TaxRegion taxRegion = new TaxRegion(); taxRegion.LocationId = locationId; taxRegion.ValidFrom = validFrom; taxRegion.ValidTo = validTo; return(taxRegion); }
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)); }
protected void dlStateList_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { TaxRegion taxRegion = e.Item.DataItem as TaxRegion; ITextControl lblTitle = e.Item.FindControl("lblTitle") as ITextControl; TextBox txtpercentage = e.Item.FindControl("txtOrderNo") as TextBox; HyperLink hlLikn = e.Item.FindControl("hlAddState") as HyperLink; lblTitle.Text = StateManager.GetStateName(taxRegion.StateId); txtpercentage.Text = String.Format("{0:0.##}", taxRegion.Value); } }
protected void dlCountryList_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { TaxRegion taxRegion = e.Item.DataItem as TaxRegion; ITextControl lblTitle = e.Item.FindControl("lblTitle") as ITextControl; TextBox txtpercentage = e.Item.FindControl("txtOrderNo") as TextBox; HyperLink hlLikn = e.Item.FindControl("hlAddState") as HyperLink; lblTitle.Text = CountryManager.CountryName(taxRegion.CountryId); txtpercentage.Text = String.Format("{0:0.##}", taxRegion.Value); hlLikn.NavigateUrl = "StateTax.aspx?Id=" + taxRegion.CountryId; } }
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)); }
protected void Page_Load(object sender, EventArgs e) { thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId); var company_id = Convert.ToInt64(Request.QueryString["id"]); if (AuthBLL.GetUserCompanyAuth(LoginUserId, LoginUser.security_Level_id, company_id).CanEdit == false) // 权限验证 { Response.End(); return; } try { company_udfList = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.COMPANY); company_udfValueList = new UserDefinedFieldsBLL().GetUdfValue(DicEnum.UDF_CATE.COMPANY, company_id, company_udfList); site_udfList = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.SITE); site_udfValueList = new UserDefinedFieldsBLL().GetUdfValue(DicEnum.UDF_CATE.SITE, company_id, site_udfList); account = new CompanyBLL().GetCompany(company_id); location_list = new LocationBLL().GetLocationByCompany(company_id); // defaultLocation = new LocationBLL().GetLocationByAccountId(company_id); //if (!IsPostBack) //{ // var company_id = Convert.ToInt64(Request.QueryString["id"]); if (account != null) { subCompanyList = new crm_account_dal().GetMyCompany(account.id); //searchCompany = new crm_account_dal().GetSubCompanys(); #region 为下拉框获取数据源 dic = new CompanyBLL().GetField(); // 分类类别 classification.DataTextField = "show"; classification.DataValueField = "val"; classification.DataSource = dic.FirstOrDefault(_ => _.Key == "classification").Value; classification.DataBind(); classification.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 公司类型 CompanyType.DataTextField = "show"; CompanyType.DataValueField = "val"; CompanyType.DataSource = dic.FirstOrDefault(_ => _.Key == "company_type").Value; CompanyType.DataBind(); CompanyType.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 市场领域 MarketSegment.DataTextField = "show"; MarketSegment.DataValueField = "val"; MarketSegment.DataSource = dic.FirstOrDefault(_ => _.Key == "market_segment").Value; MarketSegment.DataBind(); MarketSegment.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 销售区域 TerritoryName.DataTextField = "show"; TerritoryName.DataValueField = "val"; TerritoryName.DataSource = dic.FirstOrDefault(_ => _.Key == "territory").Value; TerritoryName.DataBind(); TerritoryName.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 客户经理 AccountManger.DataTextField = "show"; AccountManger.DataValueField = "val"; AccountManger.DataSource = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value; AccountManger.DataBind(); AccountManger.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 税区 TaxRegion.DataTextField = "show"; TaxRegion.DataValueField = "val"; TaxRegion.DataSource = dic.FirstOrDefault(_ => _.Key == "taxRegion").Value; TaxRegion.DataBind(); TaxRegion.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 竞争对手 Competitor.DataTextField = "show"; Competitor.DataValueField = "val"; Competitor.DataSource = dic.FirstOrDefault(_ => _.Key == "competition").Value; Competitor.DataBind(); Competitor.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); #endregion company_name.Text = account.name; //isactive.Checked = account.is_active == 1; CompanyNumber.Text = account.no; Phone.Text = account.phone; AlternatePhone1.Text = account.alternate_phone1; AlternatePhone2.Text = account.alternate_phone2; Fax.Text = account.fax; WebSite.Text = account.web_site; is_optoutSurvey.Checked = account.is_optout_survey == 1; mileage.Text = account.mileage == null ? "" : account.mileage.ToString();// todo decmail? 保留两位小数点?? stock_symbol.Text = account.stock_symbol; sic_code.Text = account.sic_code; stock_market.Text = account.stock_market; weibo_url.Text = account.weibo_url; wechat_mp_service.Text = account.wechat_mp_service; wechat_mp_subscription.Text = account.wechat_mp_subscription; CompanyType.SelectedValue = account.type_id == null ? "0" : account.type_id.ToString(); AccountManger.SelectedValue = account.resource_id == null ? "0" : account.resource_id.ToString(); TerritoryName.SelectedValue = account.territory_id == null ? "0" : account.territory_id.ToString(); MarketSegment.SelectedValue = account.market_segment_id == null ? "0" : account.market_segment_id.ToString(); Competitor.SelectedValue = account.competitor_id == null ? "0" : account.competitor_id.ToString(); Tax_Exempt.Checked = account.is_tax_exempt == 1; TaxRegion.SelectedValue = account.tax_region_id == null ? "0" : account.tax_region_id.ToString(); classification.SelectedValue = account.classification_id == null ? "0" : account.classification_id.ToString(); if (Tax_Exempt.Checked) { TaxRegion.Enabled = true; } TaxId.Text = account.tax_identification; if (account.parent_id != null) { var parCompany = new CompanyBLL().GetCompany((long)this.account.parent_id); ParentComoanyName.Text = parCompany == null ? "" : parCompany.name; //父客户 } asset_value.Text = account.asset_value.ToString(); location = new LocationBLL().GetLocationByAccountId(account.id); if (location != null) // 如果该客户的地址是默认地址,不可更改为非默认,只能通过添加别的地址设置为默认这种方式去更改默认地址 { country_idInit.Value = location.country_id.ToString(); province_idInit.Value = location.province_id.ToString(); city_idInit.Value = location.city_id.ToString(); district_idInit.Value = location.district_id.ToString(); address.Text = location.address; AdditionalAddress.Text = location.additional_address; } var company_detail_alert = new EMT.DoneNOW.DAL.crm_account_alert_dal().FindAlert(account.id, EMT.DoneNOW.DTO.DicEnum.ACCOUNT_ALERT_TYPE.COMPANY_DETAIL_ALERT); var new_ticket_alert = new EMT.DoneNOW.DAL.crm_account_alert_dal().FindAlert(account.id, EMT.DoneNOW.DTO.DicEnum.ACCOUNT_ALERT_TYPE.NEW_TICKET_ALERT); var ticket_detail_alert = new EMT.DoneNOW.DAL.crm_account_alert_dal().FindAlert(account.id, EMT.DoneNOW.DTO.DicEnum.ACCOUNT_ALERT_TYPE.TICKET_DETAIL_ALERT); if (company_detail_alert != null) { Company_Detail_Alert.Text = company_detail_alert.alert_text; } if (new_ticket_alert != null) { New_Ticket_Alert.Text = new_ticket_alert.alert_text; } if (ticket_detail_alert != null) { Ticket_Detail_Alert.Text = ticket_detail_alert.alert_text; } } else { Response.End(); } //} } catch (Exception) { Response.End(); } }
public void ReCalculateOrderTotals() { var store = DataModel.Store.GetStore(StoreId); // SubTotal - add up cart items and quantities decimal cartItemSubTotal = 0.0m; decimal taxableSubTotal = 0.0m; List <vCartItemProductInfo> cartItems = cart.GetCartItemsWithProductInfo(); foreach (vCartItemProductInfo item in cartItems) { decimal itemPriceForQuantity = item.GetPriceForQuantity(); cartItemSubTotal += itemPriceForQuantity; if (item.ProductIsTaxable.GetValueOrDefault(true)) { taxableSubTotal += itemPriceForQuantity; } } SubTotal = cartItemSubTotal; // Shipping Cost - Provided by ShippingProvider bool calculateShipping = (ShippingAddress != null) && (!string.IsNullOrEmpty(ShippingAddress.PostalCode)); if (calculateShipping) { var shippingService = ShippingServiceFactory.Get(StoreId, ShippingProvider, null, cart.Id); if (shippingService != null) { ShipmentPackagingStrategy shipmentPackagingStrategy = WA.Enum <ShipmentPackagingStrategy> .TryParseOrDefault(store.GetSetting(StoreSettingNames.ShipmentPackagingStrategy), ShipmentPackagingStrategy.SingleBox); var rate = shippingService.GetRate(store.Address.ToPostalAddress(), ShippingAddress.ToPostalAddress(), cart.GetCartItemsAsShipmentPackages(shipmentPackagingStrategy), this.ShippingRate.ServiceType); if (rate != null) { this.ShippingRate = rate; } } } else { this.ShippingRate.Rate = 0; } // Coupons ReApplyAllCoupons(); // Tax Amount string taxCountry = BillingAddress.Country; string taxRegion = BillingAddress.Region; bool taxShipping = true; if (store != null) { if (store.GetSetting(StoreSettingNames.SalesTaxAddressType) == "Shipping") { taxCountry = ShippingAddress.Country; taxRegion = ShippingAddress.Region; } taxShipping = WA.Parser.ToBool(store.GetSetting(StoreSettingNames.TaxShipping)).GetValueOrDefault(true); } decimal taxRate = TaxRegion.GetTaxRate(cart.StoreId.GetValueOrDefault(-1), taxCountry, taxRegion); if (taxShipping) { TaxAmount = ((Math.Max(0, taxableSubTotal - DiscountAmount) + ShippingRate.Rate) * taxRate).RoundForMoney(); } else { TaxAmount = ((Math.Max(0, taxableSubTotal - DiscountAmount)) * taxRate).RoundForMoney(); } // Total Total = (SubTotal + ShippingRate.Rate - DiscountAmount + TaxAmount).RoundForMoney(); }