示例#1
0
        public ActionResult Delete(string title)
        {
            try
            {
                var deleteObjs = new TaxRule().GetObjectsValueFromExpression(x => x.RuleName.Equals(title));
                if (deleteObjs != null && deleteObjs.Count > 0)
                {
                    foreach (var obj in deleteObjs)
                    {
                        obj.Delete();
                    }
                }

                return(new JsonResult()
                {
                    Data = ResultModel.SuccessResult()
                });
            }
            catch
            {
                return(new JsonResult()
                {
                    Data = ResultModel.FailResult()
                });
            }
        }
示例#2
0
        private static LSDecimal CalculateTax(TaxRule taxRule, LSDecimal price)
        {
            // DETERMINE TAX FOR TOTAL PRICE
            LSDecimal tempTax = ((price * taxRule.TaxRate) / 100);

            return(TaxHelper.Round((decimal)tempTax, 2, taxRule.RoundingRule));
        }
示例#3
0
        /// <summary>
        /// Calculates tax
        /// </summary>
        /// <param name="taxRule">The tax rule to process</param>
        /// <param name="order">The order being processed</param>
        /// <param name="shipmentId">The shipment ID to calculate tax for; pass 0 for unshippable or -1 to ignore shipments</param>
        /// <returns>A basket item for the tax entry, or null if no tax is charged.</returns>
        public static OrderItem Calculate(TaxRule taxRule, Order order, int shipmentId)
        {
            //THIS SHIPMENT QUALIFIES, GET TOTAL OF ALL APPLICABLE BASKET ITEMS
            LSDecimal totalPrice = 0;

            foreach (OrderItem oi in order.Items)
            {
                //CHECK IF THE ITEM IS PART OF THE SHIPMENT
                if (oi.OrderShipmentId == shipmentId || shipmentId < 0)
                {
                    //CHECK WHETHER THE TAX CODE IS AFFECTED BY THIS Tax RULE
                    if (taxRule.AppliesToTaxCode(oi.TaxCodeId))
                    {
                        totalPrice += oi.ExtendedPrice;
                    }
                }
            }
            // GENERATE ITEM AND RETURN IF VALID
            OrderItem taxItem = GenerateOrderItem(order.OrderId, shipmentId, taxRule, totalPrice);

            if (taxItem.ExtendedPrice > 0)
            {
                return(taxItem);
            }
            return(null);
        }
        public void Tax_item_creation_success()
        {
            //Arrange
            var TaxFreeThrashHold = 18200;
            var year                   = 2017;
            var Tier1Limit             = 0;
            var Tier1MarginalRate      = 0;
            var Tier1MinFixedTaxAmount = 0;
            var Tier2Limit             = 0;
            var Tier2MarginalRate      = 0;
            var Tier2MinFixedTaxAmount = 0;
            var Tier3Limit             = 0;
            var Tier3MarginalRate      = 0;
            var Tier3MinFixedTaxAmount = 0;

            var HighestMinFixedTaxAmount = 0;
            var HighestMarginalRate      = 0;

            //Act
            var taxRule = new TaxRule(year, TaxFreeThrashHold,
                                      Tier1Limit, Tier1MarginalRate, Tier1MinFixedTaxAmount,
                                      Tier2Limit, Tier2MarginalRate, Tier2MinFixedTaxAmount,
                                      Tier3Limit, Tier3MarginalRate, Tier3MinFixedTaxAmount,
                                      HighestMinFixedTaxAmount, HighestMarginalRate
                                      );
            var tax = new Tax(year, taxRule, null);

            //Assert
            Assert.IsNotNull(tax);
        }
示例#5
0
 public ActionResult Edit(List <TaxRule> objs)
 {
     try
     {
         if (objs != null && objs.Count > 0)
         {
             //Delete them all
             var title      = objs.FirstOrDefault().RuleName;
             var deleteObjs = new TaxRule().GetObjectsValueFromExpression(x => x.RuleName.Equals(title));
             if (deleteObjs != null && deleteObjs.Count > 0)
             {
                 foreach (var obj in deleteObjs)
                 {
                     obj.Delete();
                 }
             }
             //Then add new one(faster than modified the old one because the id was unknown
             foreach (var obj in objs)
             {
                 obj.Insert();
             }
         }
         return(new JsonResult()
         {
             Data = ResultModel.SuccessResult()
         });
     }
     catch
     {
         return(new JsonResult()
         {
             Data = ResultModel.FailResult()
         });
     }
 }
示例#6
0
        protected string GetZoneNames(object dataItem)
        {
            TaxRule rule = (TaxRule)dataItem;

            if (rule.ShipZones.Count == 0)
            {
                return("No filter");
            }
            List <string> zones = new List <string>();

            foreach (ShipZone zoneAssn in rule.ShipZones)
            {
                zones.Add(zoneAssn.Name);
            }
            string zoneList = string.Join(", ", zones.ToArray());

            if ((zoneList.Length > 100))
            {
                zoneList = (zoneList.Substring(0, 100) + "...");
            }
            if (rule.UseBillingAddress)
            {
                return("Billing address in: " + zoneList);
            }
            else
            {
                return("Shipping address in: " + zoneList);
            }
        }
示例#7
0
        protected string GetGroupNames(object dataItem)
        {
            TaxRule rule = (TaxRule)dataItem;

            if (rule.GroupRule == FilterRule.All)
            {
                return("No filter");
            }
            List <string> groups = new List <string>();

            foreach (Group grpAssn in rule.Groups)
            {
                groups.Add(grpAssn.Name);
            }
            string grpList = string.Join(", ", groups.ToArray());

            if ((grpList.Length > 100))
            {
                grpList = (grpList.Substring(0, 100) + "...");
            }
            if (rule.GroupRule == FilterRule.ExcludeSelected)
            {
                grpList = "Exclude: " + grpList;
            }
            else
            {
                grpList = "Include: " + grpList;
            }
            return(grpList);
        }
 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);
 }
        public async Task <Guid> AddTaxRuleAsync(Guid municipalityId, TaxRule rule)
        {
            rule.MunicipalityId = municipalityId;
            var id = _taxRuleRepository.Add(rule);

            await _unitOfWork.CommitAsync();

            return(id);
        }
示例#10
0
    /// <summary>
    /// Bind data to the fields in edit mode
    /// </summary>
    protected void BindEditData()
    {
        TaxRuleAdmin taxAdmin = new TaxRuleAdmin();
        TaxRule taxRule = new TaxRule();

        if (ItemId > 0)
        {
            taxRule = taxAdmin.GetTaxRule(ItemId);

            // Destination CountryCode
            if (taxRule.DestinationCountryCode != null)
            {
                lstCountries.SelectedValue = taxRule.DestinationCountryCode;

                if (lstCountries.SelectedValue != null)
                {
                    BindStates();
                }
            }

            // Destination StateCode
            if (taxRule.DestinationStateCode != null)
            {
                lstStateOption.SelectedValue = taxRule.DestinationStateCode;

                if (lstStateOption.SelectedValue != null)
                {
                    BindCounty();
                }
            }

            // CountyFIPS
            if (taxRule.CountyFIPS != null)
            {
                lstCounty.SelectedValue = taxRule.CountyFIPS;
            }

            // Tax Rates
            txtSalesTax.Text = taxRule.SalesTax.ToString();
            txtVAT.Text = taxRule.VAT.ToString();
            txtGST.Text = taxRule.GST.ToString();
            txtPST.Text = taxRule.PST.ToString();
            txtHST.Text = taxRule.HST.ToString();

            // Tax Preferences
            txtPrecedence.Text = taxRule.Precedence.ToString();

            chkTaxInclusiveInd.Checked = taxRule.InclusiveInd;

            ddlRuleTypes.SelectedValue = taxRule.TaxRuleTypeID.GetValueOrDefault().ToString();
        }
        else
        {
           //nothing to do here
        }
    }
        public void Tax_item_creation_fail()
        {
            //Arrange
            var     year = 2017;
            TaxRule rule = null;

            //Act - Assert
            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
                                                                 new Tax(year, rule, null));
        }
示例#12
0
        public ActionResult TaxRuleDetailView(string title)
        {
            var objs = new TaxRule().GetObjectsValueFromExpression(x => x.RuleName.Equals(title));

            if (objs != null && objs.Count > 0)
            {
                return(PartialView(objs));
            }
            return(PartialView(new List <TaxRule>()));
        }
        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;
            }
        }
        public async Task GetWithDetails_SelectingTasRule_WillIncludePeriosAsync()
        {
            // Arrange
            var fackDatabaseBuilder = new FackDataBaseBuildHelper();
            var context             = new DansBankDbContext(fackDatabaseBuilder);

            context.Database.EnsureCreated();

            var municipalityName = "Copenhagen";



            var id   = Guid.NewGuid();
            var trId = Guid.NewGuid();

            using (var db = new DansBankDbContext(fackDatabaseBuilder))
            {
                var m = new Municipality {
                    Id = id, Name = municipalityName, TaxRules = new List <TaxRule>()
                };
                db.Municipalities.Add(m);
                db.SaveChanges();

                var tr = new TaxRule {
                    Id = trId, Name = "Yearly", Percentage = 0.2F, Priority = 1, MunicipalityId = m.Id
                };
                var periods = new List <Period>
                {
                    new Period {
                        From = DateTime.Today, To = DateTime.Today.AddDays(1)
                    },
                    new Period {
                        From = DateTime.Today.AddDays(2), To = DateTime.Today.AddDays(5)
                    }
                };
                tr.Periods = periods;

                db.TaxRules.Add(tr);

                db.SaveChanges();
            }

            var taxRuleRepository = new TaxRuleRepository(new DansBankDbContext(fackDatabaseBuilder));

            // Act
            var taxRule = await taxRuleRepository.GetWithDetailsAsync(trId);

            // Assert
            taxRule.Should().NotBeNull();
            taxRule.MunicipalityId.Should().Be(id);
            taxRule.Periods.Should().NotBeNullOrEmpty();
            taxRule.Periods.Should().HaveCount(2);
            taxRule.Periods.Select(p => p.TaxRuleId).Should().AllBeEquivalentTo(trId);
        }
示例#15
0
        protected string GetTaxCodeName(object dataItem)
        {
            TaxRule rule = (TaxRule)dataItem;
            TaxCode code = rule.TaxCode;

            if (code == null)
            {
                return(string.Empty);
            }
            return(code.Name);
        }
示例#16
0
        protected string GetTaxCodes(object dataItem)
        {
            TaxRule       taxRule  = (TaxRule)dataItem;
            List <string> taxCodes = new List <string>();

            foreach (TaxCode tc in taxRule.TaxCodes)
            {
                taxCodes.Add(tc.Name);
            }
            return(string.Join(", ", taxCodes.ToArray()));
        }
示例#17
0
        public double ComputeTotalAmount()
        {
            var totalAmount = 0.0;

            // BUG: There was a bug with the following line of code
            // totalAmount = PurchasedBooks.Sum(book => book.TotalPrice);

            // FIX: The above bug was fixed by the following line of code
            totalAmount = PurchasedBooks.Sum(book => book.TotalPrice * TaxRule.GetApplicableRate(Country, book.Book));

            return(totalAmount);
        }
示例#18
0
        public SaleOperations(Sale entity, ITaxService taxService, TaxRule taxRule, IEventService bus, ICustomerService customerService)
        {
            Entity           = entity;
            _taxService      = taxService;
            _taxRule         = taxRule;
            _bus             = bus;
            _customerService = customerService;

            var subscription = _bus.Subscribe <TaxCalculatedEvent>(OnTaxCalculate);

            _subscriptions.Add(subscription);
        }
        public async Task GetWithDetails_IncludeDetails()
        {
            // Arrange
            var fackDatabaseBuilder = new FackDataBaseBuildHelper();
            var context             = new DansBankDbContext(fackDatabaseBuilder);

            context.Database.EnsureCreated();

            var municipalityName = "Copenhagen";



            using (var db = new DansBankDbContext(fackDatabaseBuilder))
            {
                var id = Guid.NewGuid();
                var m  = new Municipality {
                    Id = id, Name = municipalityName, TaxRules = new List <TaxRule>()
                };
                var tr = new TaxRule {
                    Name = "Yearly", Percentage = 0.2F, Priority = 1
                };
                var periods = new List <Period>
                {
                    new Period {
                        From = DateTime.Today, To = DateTime.Today.AddDays(1)
                    },
                    new Period {
                        From = DateTime.Today.AddDays(2), To = DateTime.Today.AddDays(5)
                    }
                };
                tr.Periods = periods;
                m.TaxRules.Add(tr);

                db.Municipalities.Add(m);

                db.SaveChanges();
            }

            var municipalityRepository = new MunicipalityRepository(new DansBankDbContext(fackDatabaseBuilder));

            // Act
            var municipality = await municipalityRepository.GetWithDetails("Copenhagen");

            // Assert
            municipality.Should().NotBeNull();
            municipality.TaxRules.Should().NotBeNullOrEmpty();
            municipality.TaxRules.Should().HaveCount(1);
            var taxRule = municipality.TaxRules.First();

            taxRule.Periods.Should().NotBeNullOrEmpty();
            taxRule.Periods.Should().HaveCount(2);
        }
        /*Can make all calculations in one method*/
        private Payslip CalculateIncome(Employee employee, TaxRule rule)
        {
            Payslip ps = new Payslip();

            ps.Name        = $"{employee.FirstName} {employee.LastName}";
            ps.PayPeriod   = $"{employee.StartDate.Value.ToShortDateString()}={employee.EndDate.Value.ToShortDateString()}";
            ps.GrossIncome = SalaryRound(employee.Salary / MonthsInAYear);
            ps.Super       = SalaryRound(ps.GrossIncome * employee.SuperRate.Value / 100);
            ps.IncomeTax   = SalaryRound((rule.BaseTaxAmount + (employee.Salary - rule.TaxBracketMin) * rule.ExcessAmount) /
                                         MonthsInAYear);
            ps.NetIncome = ps.GrossIncome - ps.IncomeTax;
            return(ps);
        }
        public void GetTax_ShouldReturnValue_WhenAboveLimit(double value, double expectedTax)
        {
            // Arrange
            var config = new ConfigEntity()
            {
                MinTaxAmount = 100, TaxPercentage = 0.1
            };
            var sut = new TaxRule(config);

            // Act
            var tax = sut.GetTax(value);

            // Assert
            Assert.AreEqual(expectedTax, tax);
        }
        public void GetTax_ShouldReturn0_WhenUnderLimit(double value)
        {
            // Arrange
            var config = new ConfigEntity()
            {
                MinTaxAmount = 100
            };
            var sut = new TaxRule(config);

            // Act
            var tax = sut.GetTax(value);

            // Assert
            Assert.AreEqual(0, tax);
        }
示例#23
0
 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);
 }
        public async Task <string> EditTaxRuleAsync(Guid taxRuleId, TaxRule rule)
        {
            var databaseRule = await _taxRuleRepository.GetAsNoTrackingAsync(taxRuleId);

            if (databaseRule == null)
            {
                return(Messages.TaxRuleDoesNotExist);
            }

            rule.Id             = taxRuleId;
            rule.MunicipalityId = databaseRule.MunicipalityId;

            _taxRuleRepository.Edit(rule);

            await _unitOfWork.CommitAsync();

            return(null);
        }
示例#25
0
        /// <summary>
        /// Generates a line item for the tax
        /// </summary>
        /// <param name="basketId">The basket id</param>
        /// <param name="shipmentId">The shipment id</param>
        /// <param name="taxRule">The tax rule</param>
        /// <param name="totalPrice">The total price being taxed</param>
        /// <returns>A line item representing the calculated tax</returns>
        private static BasketItem GenerateBasketItem(int basketId, int shipmentId, TaxRule taxRule, LSDecimal totalPrice)
        {
            BasketItem taxLineItem = new BasketItem();

            taxLineItem.BasketId      = basketId;
            taxLineItem.OrderItemType = OrderItemType.Tax;
            if (shipmentId < 0)
            {
                shipmentId = 0;
            }
            taxLineItem.BasketShipmentId = shipmentId;
            taxLineItem.ParentItemId     = 0;
            taxLineItem.Name             = taxRule.Name;
            taxLineItem.Sku       = taxRule.TaxRuleId.ToString();
            taxLineItem.Price     = CalculateTax(taxRule, totalPrice);
            taxLineItem.Quantity  = 1;
            taxLineItem.TaxCodeId = taxRule.TaxCodeId;
            return(taxLineItem);
        }
示例#26
0
        public async Task <GetTaxRuleForEditOutput> GetTaxRuleForEdit(NullableIdInput <long> input)
        {
            TaxRuleEditDto taxRuleEditDto;

            if (!input.Id.HasValue)
            {
                taxRuleEditDto = new TaxRuleEditDto();
            }
            else
            {
                IRepository <TaxRule, long> repository = this._taxRuleRepository;
                TaxRule async = await repository.GetAsync(input.Id.Value);

                taxRuleEditDto = async.MapTo <TaxRuleEditDto>();
            }
            return(new GetTaxRuleForEditOutput()
            {
                TaxRule = taxRuleEditDto
            });
        }
示例#27
0
    /// <summary>
    /// Submit button click event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        TaxRuleAdmin taxAdmin = new TaxRuleAdmin();
        TaxRule taxRule = new TaxRule();

        taxRule.PortalID = ZNodeConfigManager.SiteConfig.PortalID;

        // If edit mode then retrieve data first
        if (ItemId > 0)
        {
            taxRule = taxAdmin.GetTaxRule(ItemId);
        }

        // TaxClassID
        taxRule.TaxClassID = taxId;
        // Destination Country
        if (lstCountries.SelectedValue.Equals("*"))
            taxRule.DestinationCountryCode = null;
        else
            taxRule.DestinationCountryCode = lstCountries.SelectedValue;

        // Destination State
        if (lstStateOption.SelectedValue != "0")
            taxRule.DestinationStateCode = lstStateOption.SelectedValue;
        else
            taxRule.DestinationStateCode = null;

        // CountyFIPS
        if (lstCounty.SelectedValue != "0")
            taxRule.CountyFIPS = lstCounty.SelectedValue;
        else
            taxRule.CountyFIPS = null;

        // Tax Rates
        taxRule.SalesTax = Convert.ToDecimal(txtSalesTax.Text);
        taxRule.VAT = Convert.ToDecimal(txtVAT.Text);
        taxRule.GST = Convert.ToDecimal(txtGST.Text);
        taxRule.PST = Convert.ToDecimal(txtPST.Text);
        taxRule.HST = Convert.ToDecimal(txtHST.Text);

        // Tax Preferences

        taxRule.InclusiveInd = chkTaxInclusiveInd.Checked;
        taxRule.Precedence = int.Parse(txtPrecedence.Text);

        if (ddlRuleTypes.SelectedIndex != -1)
        {
            taxRule.TaxRuleTypeID = int.Parse(ddlRuleTypes.SelectedValue);
        }

        bool retval = false;

        if (ItemId > 0)
        {
            retval = taxAdmin.UpdateTaxRule(taxRule);
        }
        else
        {
            retval = taxAdmin.AddTaxRule(taxRule);
        }

        if (retval)
        {
            System.Web.HttpContext.Current.Cache.Remove("InclusiveTaxRules");

            //redirect to view page
            Response.Redirect("~/admin/secure/settings/taxes/view.aspx?taxId=" + taxId);
        }
        else
        {
            //display error message
            lblMsg.Text = "An error occurred while updating. Please try again.";
        }
    }
示例#28
0
    /// <summary>
    /// Event triggered when a command button is clicked on the grid
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void uxGrid_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "page")
        {
        }
        else
        {
            // Convert the row index stored in the CommandArgument
            // property to an Integer.
            int index = Convert.ToInt32(e.CommandArgument);

            // Get the values from the appropriate
            // cell in the GridView control.
            GridViewRow selectedRow = uxGrid.Rows[index];

            TableCell Idcell = selectedRow.Cells[0];
            string Id = Idcell.Text;

            if (e.CommandName == "Edit")
            {
                EditRuleLink = EditRuleLink + "?itemid=" + Id + "&taxId=" + taxId;
                Response.Redirect(EditRuleLink);
            }
            else if (e.CommandName == "Delete")
            {
                TaxRuleAdmin taxAdmin = new TaxRuleAdmin();
                TaxRule taxRule = new TaxRule();

                taxRule.TaxRuleID = int.Parse(Id);
                bool status = taxAdmin.DeleteTaxRule(taxRule);

                if(status)
                    System.Web.HttpContext.Current.Cache.Remove("InclusiveTaxRules");

            }
        }
    }
        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");
            }
        }
 //Provide constructor chaining to allow for the Default constructor to load the static rules
 public DefaultPayslipCalculatorImpl() : this(TaxRule.LoadRules())
 {
 }
        protected bool IsLinked(object dataItem)
        {
            TaxRule rule = (TaxRule)dataItem;

            return(rule.TaxCodes.IndexOf(_TaxCode) > -1);
        }
示例#32
0
 // GET: TaxRule/Details/5
 public ActionResult Details(int id)
 {
     return(View(TaxRule.GetById(id)));
 }
示例#33
0
 /// <summary>
 /// Determines the nexus for the tax rule
 /// </summary>
 /// <param name="taxRule">The tax rule to check</param>
 /// <returns>The nexus for the tax rule</returns>
 public static TaxNexus GetNexus(TaxRule taxRule)
 {
     return(taxRule.UseBillingAddress ? TaxNexus.PointOfBilling : TaxNexus.PointOfDelivery);
 }