protected void SaveButton_Click(object sender, EventArgs e) { _TaxCode.TaxRules.Clear(); foreach (GridViewRow gvr in TaxRuleGrid.Rows) { int taxRuleId = (int)TaxRuleGrid.DataKeys[gvr.DataItemIndex].Value; TaxRule taxRule = TaxRuleDataSource.Load(taxRuleId); CheckBox Linked = gvr.FindControl("Linked") as CheckBox; if (Linked.Checked) { if (taxRule.TaxCodes.IndexOf(_TaxCode) < 0) { taxRule.TaxCodes.Add(_TaxCode); taxRule.Save(); } _TaxCode.TaxRules.Add(taxRule); } else { if (taxRule.TaxCodes.IndexOf(_TaxCode) > -1) { taxRule.TaxCodes.Remove(_TaxCode); taxRule.Save(); } } } SavedMessage.Visible = true; SavedMessage.Text = string.Format(SavedMessage.Text, LocaleHelper.LocalNow); }
protected void Page_Load(object sender, EventArgs e) { if (!TaxesEnabled) { int taxRuleCount = TaxRuleDataSource.CountAll(); TaxesDisabledPanel.Visible = (taxRuleCount > 0); } }
protected void Page_PreRender(object sender, EventArgs e) { if (!_TaxProvider.Enabled) { int taxRuleCount = TaxRuleDataSource.CountAll(); TaxesDisabledPanel.Visible = (taxRuleCount > 0); } IncludeAnonPanel.Visible = (ShoppingDisplay.SelectedIndex != 0 && EnabledCheckBox.Checked); }
protected void Page_Load(object sender, EventArgs e) { _TaxRuleId = AlwaysConvert.ToInt(Request.QueryString["TaxRuleId"]); _TaxRule = TaxRuleDataSource.Load(_TaxRuleId); if (_TaxRule == null) { Response.Redirect("TaxRules.aspx"); } Caption.Text = string.Format(Caption.Text, _TaxRule.Name); if (!Page.IsPostBack) { Name.Text = _TaxRule.Name; foreach (ListItem taxCodeItem in this.TaxCodes.Items) { TaxCode taxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(taxCodeItem.Value)); taxCodeItem.Selected = (_TaxRule.TaxCodes.IndexOf(taxCode) > -1); } TaxRate.Text = string.Format("{0:0.00##}", _TaxRule.TaxRate); ZoneRule.SelectedIndex = (_TaxRule.ShipZones.Count == 0) ? 0 : 1; foreach (ShipZone item in _TaxRule.ShipZones) { ListItem listItem = ZoneList.Items.FindByValue(item.Id.ToString()); if (listItem != null) { listItem.Selected = true; } } UseBillingAddress.SelectedIndex = _TaxRule.UseBillingAddress ? 1 : 0; GroupRule.SelectedIndex = _TaxRule.GroupRuleId; foreach (Group item in _TaxRule.Groups) { ListItem listItem = GroupList.Items.FindByValue(item.Id.ToString()); if (listItem != null) { listItem.Selected = true; } } ListItem selectedCode = TaxCode.Items.FindByValue(_TaxRule.TaxCodeId.ToString()); if (selectedCode != null) { selectedCode.Selected = true; } Priority.Text = _TaxRule.Priority.ToString(); ListItem roundingRuleItem = RoundingRule.Items.FindByValue(_TaxRule.RoundingRuleId.ToString()); if (roundingRuleItem != null) { RoundingRule.SelectedItem.Selected = false; roundingRuleItem.Selected = true; } PerUnitCalculation.Checked = _TaxRule.UsePerItemTax; } }
/// <summary> /// Gets the tax rules that may apply /// </summary> /// <param name="taxCodeIds">The tax code of the taxable item(s)</param> /// <param name="billingAddress">The billing address for the item(s)</param> /// <param name="shippingAddresses">The shipping addresses for the item(s)</param> /// <param name="user">The user shopping for the item(s)</param> /// <returns>A List of TaxRule records that may apply</returns> public static List <TaxRule> GetPotentialTaxRules(int[] taxCodeIds, TaxAddress billingAddress, List <TaxAddress> shippingAddresses, User user) { // BUILD THE KEY String cacheKey = GetTaxCodesKey(taxCodeIds) + "~" + GetAddressKey(billingAddress) + "~" + GetAddressKey(shippingAddresses) + "~" + user.UserId; Dictionary <string, List <TaxRule> > taxRulesDic = null; // CHECK THE HTTP CONTEXT FOR EXISTING RULES if (HttpContext.Current != null) { taxRulesDic = HttpContext.Current.Items["PotentialTaxRules"] as Dictionary <string, List <TaxRule> >; if (taxRulesDic != null) { if (taxRulesDic.ContainsKey(cacheKey)) { return(taxRulesDic[cacheKey]); } } else { taxRulesDic = new Dictionary <string, List <TaxRule> >(); } } List <TaxRule> allRules = new List <TaxRule>(); TaxRuleCollection countryRules = TaxRuleDataSource.LoadForTaxCodes(taxCodeIds, billingAddress, user); foreach (TaxRule rule in countryRules) { allRules.Add(rule); } foreach (TaxAddress shippingAddress in shippingAddresses) { countryRules = TaxRuleDataSource.LoadForTaxCodes(taxCodeIds, shippingAddress, user); foreach (TaxRule rule in countryRules) { if (!ListContainsTaxRule(allRules, rule.TaxRuleId)) { allRules.Add(rule); } } } // IF CONTEXT IS AVAILABLE STORE THE RESULTS if (HttpContext.Current != null) { taxRulesDic[cacheKey] = allRules; HttpContext.Current.Items["PotentialTaxRules"] = taxRulesDic; } return(allRules); }
public static int GetOrderItemTaxPriority(OrderItem oi) { if (oi.OrderItemType == OrderItemType.Tax) { //THIS IS A TAX, RETURN THE TAX RULE PRIORITY //SKU OF ITEM SHOULD BE TAX RULE ID int taxRuleId = AlwaysConvert.ToInt(oi.Sku); TaxRule rule = TaxRuleDataSource.Load(taxRuleId); if (rule != null) { return(rule.Priority); } } return(-1); }
protected void SaveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { // DUPLICATE TAX RULE NAMES SHOULD NOT BE ALLOWED int taxRuleId = TaxRuleDataSource.GetTaxRuleIdByName(Name.Text); if (taxRuleId > 0) { // TAX RULE(S) WITH SAME NAME ALREADY EXIST CustomValidator customNameValidator = new CustomValidator(); customNameValidator.ControlToValidate = "Name"; customNameValidator.Text = "*"; customNameValidator.ErrorMessage = "A Tax Rule with the same name already exists."; customNameValidator.IsValid = false; phNameValidator.Controls.Add(customNameValidator); return; } //SAVE TAX RULE TaxRule taxRule = new TaxRule(); taxRule.Name = Name.Text; taxRule.TaxRate = AlwaysConvert.ToDecimal(TaxRate.Text); taxRule.UseBillingAddress = AlwaysConvert.ToBool(UseBillingAddress.SelectedValue.Equals("1"), false); taxRule.TaxCodeId = AlwaysConvert.ToInt(TaxCode.SelectedValue); taxRule.Priority = AlwaysConvert.ToInt16(Priority.Text); taxRule.UsePerItemTax = PerUnitCalculation.Checked; taxRule.Save(); //UPDATE TAX CODES taxRule.TaxCodes.Clear(); taxRule.Save(); foreach (ListItem listItem in TaxCodes.Items) { if (listItem.Selected) { TaxCode taxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(listItem.Value)); taxRule.TaxCodes.Add(taxCode); listItem.Selected = false; } } //UPDATE ZONES taxRule.ShipZones.Clear(); if (ZoneRule.SelectedIndex > 0) { foreach (ListItem item in ZoneList.Items) { ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { taxRule.ShipZones.Add(shipZone); } } } //UPDATE GROUP FILTER taxRule.Groups.Clear(); taxRule.GroupRule = (FilterRule)GroupRule.SelectedIndex; if (taxRule.GroupRule != FilterRule.All) { foreach (ListItem item in GroupList.Items) { Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { taxRule.Groups.Add(group); } } } //IF NO GROUPS ARE SELECTED, APPLY TO ALL GROUPS if (taxRule.Groups.Count == 0) { taxRule.GroupRule = FilterRule.All; } // UPDATE ROUNDING RULE taxRule.RoundingRuleId = AlwaysConvert.ToByte(RoundingRule.SelectedValue); taxRule.Save(); //UPDATE THE ADD MESSAGE Response.Redirect("TaxRules.aspx"); } }