public ActionResult Create([Bind(Include = "DueDate,Recipient, Taxes")] Invoice invoice) { try { if (ModelState.IsValid) { ComposeTaxCalculator(); invoice.CreationDate = DateTime.Now; invoice.TotalCost = invoice.invoiceTotalCost(); invoice.TotalCostWithTax = calculator.CalculateTax(invoice.Taxes, invoice.TotalCost); db.Invoices.Add(invoice); db.SaveChanges(); return(RedirectToAction("Edit", new { id = invoice.Id })); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(invoice)); }
public void CalculateProgressiveFrom7441PostalCodeAsProgressiveSalary1000() { var taxAmount = _taxCalculator.CalculateTax(1000, "7441"); _mockDb.Setup(db => db.AddCalculatedResult("7441", 1000, TaxCalculationType.Progressive, 100)); _mockDb.Verify(); Assert.AreEqual(100, taxAmount); }
public void CalculateTaxTest() { Initialize(); decimal totalProductTax = taxCal.CalculateTax(12.49M, 0, false); Assert.AreEqual(0, 0); }
public void T009_CalculateTotalPersonalTax() { // Given int receivedMoney = 100000; // int taxCredit = 8000; kwota wolna od podatku // int taxLevel = 85528; zmiana progu podatkowego // Once again, you may add a TotalPersonalTaxCalculator class and // swap old PersonalTax with this new one in the factory. // You may note for previous tests it will work like first level tax, but it will let you // CHAIN two calculators. Look at Expected and split money appropriately. // If you don't know what I want from you, call me when you get here. ITaxCalculator calculator = TaxCalculatorFactory.Create(CustomerType.Personal); // Expected // Money up to 85528: calculated like T002, so: 13955.04. But we have int, so 13955. // Money above 85528: 32%. In this case, 4631.04. But we have int, so 4631. // TOTAL: 18586 int expectedTax = 4631; // When int actualTax = calculator.CalculateTax(receivedMoney); // Then Assert.AreEqual(expectedTax, actualTax); }
public void T011_BusinessHasSubstractions() { // Given int companyMoney = 23000; List <Goods> goods = new List <Goods>() { new Goods(1000, "keyboard"), new Goods(2000, "mouse") }; // Expected // Right. So, 23000 - 3000 from 'costs of generating the profits' = 20000 // Thus, total tax = 0.19 * 20000 = 3800 int expectedTax = 3800; // Yes, you will have to deal with a new method. You will have to pass appropriate parameters // to the calculator using the CONSTRUCTOR, because you have no other way of // passing without changing the interface of the method - the contract. ITaxCalculator calculator = TaxCalculatorFactory.Create(CustomerType.BusinessLinear, goods); // When int actualTax = calculator.CalculateTax(companyMoney); // Then Assert.AreEqual(expectedTax, actualTax); }
static void CalculateTax() { ITaxCalculator calculator = GetCalculator(); decimal salary = 20000M; decimal tax = calculator.CalculateTax(salary); Console.WriteLine(tax); }
public void Run() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); _taxCalculator.CalculateTax("test1"); stopwatch.Stop(); Console.WriteLine($"Calculation wihtou realproxy is: {stopwatch.ElapsedMilliseconds} ms"); }
public void CalculateTax(ShoppingCart shoppingCart) { if (_taxCalculator == null) { //First set the _taxCalulator CreateTaxCalculator(_state); } _taxCalculator.CalculateTax(shoppingCart); }
public decimal Apply(decimal taxableIncome) { if (taxableIncome <= 0) { return(0); } ITaxCalculator calculator = Injector.Instance.Inject <ITaxCalculator>("GermanySolidaritySurchargeCalculator"); return(calculator.CalculateTax(taxableIncome)); }
public decimal Apply(decimal taxableIncome) { if (taxableIncome <= 0) { return(0); } ITaxCalculator calculator = Injector.Instance.Inject <ITaxCalculator>("NewZealandSocialSecurityAndHealthContribTaxCalculator"); return(calculator.CalculateTax(taxableIncome)); }
public decimal Apply(decimal taxableIncome) { if (taxableIncome <= 0) { return(0); } ITaxCalculator calculator = Injector.Instance.Inject <ITaxCalculator>("NewZealandIncomeTaxCalculator"); return(calculator.CalculateTax(taxableIncome)); }
public decimal Apply(decimal taxableIncome) { if (taxableIncome <= 0) { return(0); } ITaxCalculator calculator = Injector.Instance.Inject <ITaxCalculator>("AustraliaMedicareLevyCalculator"); return(calculator.CalculateTax(taxableIncome)); }
public RejectInvalidStateAbbreviation() { IMock mock = new DynamicMock(typeof(ITaxCalculator)); mock.ExpectAndReturn("CalculateTax", 7.25, 100, "TX"); mock.ExpectAndReturn("CalculateTax", 7.00, 100, "NC"); mock.ExpectAndThrow("CalculateTax", new ArgumentException(), 100, "XX"); ITaxCalculator calc = mock.Object as ITaxCalculator; Assert.That( calc.CalculateTax(100, "TX"), Is.EqualTo(7.25) ); Assert.That( calc.CalculateTax(100, "NC"), Is.EqualTo(7.00)); calc.CalculateTax(100, "XX"); }
public void CalcSalesTax(List <Product> productList) { foreach (Product p in productList) { double productTax = taxCalculator.CalculateTax( p.PAttributes.Price, p.PAttributes.IsImported, p.GetTaxValue()); p.PAttributes.SalesTax = Truncate(productTax); double totalProductPrice = (p.PAttributes.Price + p.PAttributes.SalesTax) * p.PAttributes.Quantity; p.PAttributes.TotalProductPrice = Truncate(totalProductPrice); } }
public void T005_CustomerAsksForPersonalTax() { // Here, you will have to build a second method of a Factory // Given Customer customer = new Customer(20000, CustomerType.Personal); ITaxCalculator calculator = TaxCalculatorFactory.Create(customer.Type); // When int owed = calculator.CalculateTax(customer.Money); // Then Assert.AreEqual(2160, owed); }
public async Task <IActionResult> Get(string muncipalityName, string date) { _logger.LogInformation($"Get End point Called for {muncipalityName} | date:{date}"); var result = await _taxCalculator.CalculateTax(muncipalityName, date); if (result == 0.0) { return(BadRequest("Not Able to match details")); } else { return(Ok(result)); } }
public double CalculateTaxForEmployees() { var employees = _provider.GetEmployees(); double total = 0; var rate = _rateProvider.GetRate(); foreach (var employee in employees) { var tax = _taxCalculator.CalculateTax(employee, rate); total = total + tax; } return(total); }
public decimal[] CalculateTotals(Guid invoiceId) { var result = new decimal[] { 0, 0 }; var currentInvoice = db.Invoices.FirstOrDefault(x => x.Id == invoiceId); if (db.InvoiceItems.Any(x => x.InvoiceId == invoiceId) && currentInvoice != null) { var totalWithoutTaxItem = db.InvoiceItems.Where(x => x.InvoiceId == invoiceId) .Sum(x => (x.Amount * x.PriceWithoutTax)); result[0] = totalWithoutTaxItem; result[1] = _taxCalculator.CalculateTax(totalWithoutTaxItem, currentInvoice.TaxPercentage); } return(result); }
public IPayslip GeneratePayslip(IEmployee employee) { var taxSlab = _taxSlabService.GetTaxSlab(employee.AnnualSalary, employee.SalaryPeriod.FinancialYear); var annualTax = _taxCalculator.CalculateTax(employee.AnnualSalary, taxSlab); var payslip = new Payslip { Name = string.Concat(employee.FirstName, ' ', employee.LastName), GrossIncome = Math.Round(employee.AnnualSalary / 12, MidpointRounding.AwayFromZero), IncomeTax = Math.Round(annualTax / 12, MidpointRounding.AwayFromZero), SalaryPeriod = employee.SalaryPeriod }; payslip.SuperAmount = Math.Round((payslip.GrossIncome * employee.SuperRate) / 100, MidpointRounding.AwayFromZero); payslip.NetIncome = payslip.GrossIncome - payslip.IncomeTax; return(payslip); }
public void T008_CalculatePersonalTaxAbove85528() { // Given int receivedMoney = 100000; // Note: you have to build a NEW ITaxCalculator member - add a new class ITaxCalculator calculator = TaxCalculatorFactory.Create("personal second tax level"); // Expected // Money above 85528: 32%, as this is the second tax level. Forget about tax credit this time. // TOTAL: 32000 int expectedTax = 32000; // When int actualTax = calculator.CalculateTax(receivedMoney); // Then Assert.AreEqual(expectedTax, actualTax); }
public void GenerateInvoiceWithInterface(Order order, ITaxCalculator taxCalculator) { double total = 0.0; foreach (var product in order.Products) { double price = product.Units * product.Price; total += price; Console.WriteLine($"{product.Name} (price: {product.Price}, amount: {product.Units}, total:{price}"); } Console.WriteLine("----------------------------------------------"); var tax = taxCalculator.CalculateTax(order); Console.WriteLine($"Total Before Tax: {total}"); Console.WriteLine($"Tax: {tax}"); Console.WriteLine("----------------------------------------------"); Console.WriteLine($"Total: {total + tax}"); }
public void T012_BusinessHasAmortyzacja() { // Given int companyMoney = 20000; List <Goods> goods = new List <Goods>() { new Goods(10001, "laptop") }; int expectedTax = 3325; ITaxCalculator calculator = TaxCalculatorFactory.Create(CustomerType.BusinessLinear, goods); // When int actualTax = calculator.CalculateTax(companyMoney); // Then Assert.AreEqual(expectedTax, actualTax); }
public SalarySlip GenerateFor(Employee employee) { if (employee == null) { throw new ArgumentNullException(nameof(employee)); } var grossSalary = _grossSalaryCalculator.CalculateGrossSalary(employee.AnnualGrossSalary); var nationalInsurance = _nationalInsurance.CalculateNationalInsurance(employee.AnnualGrossSalary); var tax = _taxCalculator.CalculateTax(employee.AnnualGrossSalary); var salarySlip = new SalarySlip( employee.Id, employee.Name, grossSalary, nationalInsurance, tax.TaxFree, tax.TaxableIncome, tax.TaxPayable); return(salarySlip); }
public SalaryDto CalculateSalary(decimal annualSalary, decimal superPercantage) { //gross income = 60,050 / 12 = 5,004.16666667(round down) = 5,004 //income tax = (3, 572 + (60, 050 - 37, 000) x 0.325) / 12 = 921.9375(round up) = 922 //net income = 5,004 - 922 = 4,082 //super = 5,004 x 9 % = 450.36(round down) = 450 SalaryDto salary = new SalaryDto(); //gross income var grossMonthlySalary = Math.Round(annualSalary / 12, MidpointRounding.AwayFromZero); salary.GrossSalary = grossMonthlySalary; //income tax //TaxCalculator tc = new TaxCalculator(); salary.IncomeTax = _taxCalculator.CalculateTax(annualSalary); //salary.IncomeTax= _taxCalculator.CalculateTax(annualSalary); //salary.IncomeTax = _taxCalculator.CalculateTax(annualSalary); //salary.IncomeTax = 922; //Net income var netIncome = grossMonthlySalary - salary.IncomeTax; salary.NetIncome = Math.Round(netIncome, MidpointRounding.AwayFromZero); //Super var superAmount = netIncome * (superPercantage / 100); salary.Super = Math.Round(superAmount, MidpointRounding.AwayFromZero); return(salary); }
public decimal CalculateTax(decimal taxableIncome) { var baseTax = _decoratedCalculator.CalculateTax(taxableIncome); decimal lowIncomeTaxOffset = 0; if (taxableIncome < 66667) { if (taxableIncome <= 37000) { lowIncomeTaxOffset = 445; } else { lowIncomeTaxOffset = (decimal)(445 - ((taxableIncome - 37000) * (decimal)0.0015)); } if ((baseTax - lowIncomeTaxOffset) < 0) { return(0); } } return(Math.Round((baseTax - lowIncomeTaxOffset), MidpointRounding.AwayFromZero)); }
public double CalculateTax(double price, double tax, bool imported) { double totalProductTax = taxCalculator.CalculateTax(price, tax, imported); return(totalProductTax); }
public Decimal CalculatePrice(IEnumerable <IItem> items) { return(items.Sum(item => item.Price + _taxCalc.CalculateTax(item.Price))); }
public decimal CalculateTax(decimal price, decimal tax) { decimal totalProductTax = _taxCalculator.CalculateTax(price, tax); return(totalProductTax); }
public decimal accept(ITaxCalculator taxCalculator) { return(taxCalculator.CalculateTax(this)); }
public ActionResult <decimal> Calculate(decimal salary, string postalCode) { return(_taxCalculator.CalculateTax(salary, postalCode)); }