예제 #1
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            TaxRateViewModel trvm = sender as TaxRateViewModel;

            if (trvm != null)
            {
                ReCalculateTaxes(trvm);
            }
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #4
0
 public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket)
 {
     return(taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor));
 }
예제 #5
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);
            }
        }
예제 #6
0
 public decimal CalculateTaxLiability(decimal pretaxEarning, TaxRateViewModel taxBracket)
 {
     return taxBracket.BaseTaxAmount + (decimal)taxBracket.MarginalTaxRate * (pretaxEarning - taxBracket.MarginalRateFloor);
 }