Esempio n. 1
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            TaxRateViewModel trvm = sender as TaxRateViewModel;

            if (trvm != null)
            {
                ReCalculateTaxes(trvm);
            }
        }
Esempio n. 2
0
        private TaxRateViewModel FindApplicableTaxRate(decimal value)
        {
            TaxRateViewModel result = null;

            foreach (var taxBracket in TaxSchedule)
            {
                if (value > taxBracket.RangeStart && value <= taxBracket.RangeEnd)
                {
                    result = taxBracket;
                    break;
                }
            }
            if (result == null)
            {
                throw new InvalidOperationException("Could not find applicable tax bracket");
            }
            return(result);
        }
Esempio n. 3
0
        private void ReCalculateTaxes(TaxRateViewModel updatedRate)
        {
            try
            {
                List <TaxReturnViewModel> affected = new List <TaxReturnViewModel>();
                foreach (var item in TaxReturns)
                {
                    TaxRateViewModel newRate = null;
                    try
                    {
                        newRate = FindApplicableTaxRate(item.PreTaxEarnings);
                    }
                    catch (InvalidOperationException)
                    {
                        item.TaxLiability    = decimal.Zero;
                        item.MarginalTaxRate = 0;
                    }
                    if (newRate == updatedRate)
                    {
                        affected.Add(item);
                    }
                }
                //var affected = from e in Earnings
                //               where FindApplicableTaxRate(e) == updatedRate
                //               let taxReturn = from r in TaxReturns
                //                               where r.PreTaxEarnings == e
                //                               select r
                //               select taxReturn;

                foreach (var item in affected)
                {
                    var newTax = CalculateTaxLiability(item.PreTaxEarnings, updatedRate);
                    item.TaxLiability    = newTax;
                    item.MarginalTaxRate = updatedRate.MarginalTaxRate;
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
 public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket)
 {
     return(taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor));
 }
        private void ReCalculateTaxes(TaxRateViewModel updatedRate)
        {
            try
            {
                List<TaxReturnViewModel> affected = new List<TaxReturnViewModel>();
                foreach (var item in TaxReturns)
                {
                    TaxRateViewModel newRate = null;
                    try
                    {
                        newRate = FindApplicableTaxRate(item.PreTaxEarnings);
                    }
                    catch (InvalidOperationException)
                    {
                        item.TaxLiability = decimal.Zero;
                        item.MarginalTaxRate = 0;
                    }
                    if (newRate == updatedRate)
                    {
                        affected.Add(item);
                    }
                }
                //var affected = from e in Earnings
                //               where FindApplicableTaxRate(e) == updatedRate
                //               let taxReturn = from r in TaxReturns
                //                               where r.PreTaxEarnings == e
                //                               select r
                //               select taxReturn;

                foreach (var item in affected)
                {
                    var newTax = CalculateTaxLiability(item.PreTaxEarnings, updatedRate);
                    item.TaxLiability = newTax;
                    item.MarginalTaxRate = updatedRate.MarginalTaxRate;
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
 public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket)
 {
     return taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor);
 }