示例#1
0
        /// <summary>
        /// invoke calculate NI method within the NI Calculator class. assign returned value into Inherited Total NI Amount property.
        /// </summary>
        /// <param name="payee"></param>
        public override void CalculateNationalInsuranceDeduction(Payee payee)
        {
            var niCalculator = new NationalInsuranceCalculator(); //create new instance of Type NICalculator.

            niCalculator.CalculateNIContribution(payee);
            TotalNationalInsuranceAmount = Math.Round(niCalculator.TotalNIAnnualContribution, 2); //rounding the result into 2 decimal places.
        }
示例#2
0
        /* need to calculate the weekly income (annual gross / 52).
         * using that figure to logically place the person category of NI contribution rate.
         * take annual gross minus the first-free £183 to move on to calculate the next NI contribution rate which is 12%, and so on...*/

        //Method to calculate NI contribution with object of Type Payee passed-in.
        public void CalculateNIContribution(Payee payee)
        {
            var grossAnnualIncome = payee.GrossAnnualSalary;
            var grossWeeklyIncome = CalculateWeeklyIncome(grossAnnualIncome);

            //List<decimal> remainingValueOfWeeklySalary = new List<decimal> { grossWeeklyIncome };

            if (grossWeeklyIncome < niLowerPrimaryWeeklyThreshold)
            {
                TotalNIAnnualContribution = 0.00m;
                System.Console.WriteLine("***** There is no contribution to be paid with your current earning *****");
            }
            else if (grossWeeklyIncome >= niLowerPrimaryWeeklyThreshold && grossWeeklyIncome <= niUpperPrimaryWeeklyThreshold)
            {
                var niWeeklyDeduction = (grossWeeklyIncome - niLowerPrimaryWeeklyThreshold) * 0.12m;
                TotalNIAnnualContribution = CalculateNIAnnualDeduction(niWeeklyDeduction);
            }
            else if (grossWeeklyIncome > niUpperPrimaryWeeklyThreshold)
            {
                var niWeeklyDeduction = (grossWeeklyIncome - niLowerPrimaryWeeklyThreshold) * 0.02m;
                TotalNIAnnualContribution = CalculateNIAnnualDeduction(niWeeklyDeduction);
            }
        }
 public abstract void CalculateNationalInsuranceDeduction(Payee payee);
 public abstract void CalculateTax(Payee payee);
示例#5
0
        /// <summary>
        /// invoke calculate tax method within the taxCalculator class. assign returned value into Inherited TotalTaxAmount property.
        /// </summary>
        /// <param name="payee"></param>
        public override void CalculateTax(Payee payee)
        {
            var taxCalculator = new TaxCalculator();                           //create new instance of Type TaxCalculator.

            TotalTaxAmount = Math.Round(taxCalculator.CalculateTax(payee), 2); //rounding the result into 2 decimal places.
        }
示例#6
0
        public decimal CalculateTax(Payee payee)
        {
            /*another way to create calculation of tax using anonymous/undefined type - but to be investigated - basically you can use foreach loop to start the calculation method.*/

            //var taxBands = new[]
            //{
            //    new { Lower = 0m, Upper = 10999m, Rate = 0.0m },
            //    new { Lower = 11000m, Upper = 43000m, Rate = 0.2m },
            //    new { Lower = 43001m, Upper = 150000m, Rate = 0.4m },
            //    new { Lower = 150001m, Upper = decimal.MaxValue, Rate = 0.45m }
            //};
            //Console.WriteLine(taxBands[0].Lower);


            decimal totalTaxDeduction = 0.00m;                                                                 //variable to contain the addition of total tax deduction. initialised with 0.00.

            decimal[]      taxMinThresholdRate    = { 0.00m, 12501m, 14586m, 25159m, 43431m, 150001m };        //array to hold the min thresholds value for each 6 bands of tax rate.
            decimal[]      taxMaxThresholdRate    = { 12500m, 14585m, 25158m, 43430m, 150000m, 150000000.0m }; //array to hold the max thresholds value for each 6 bands of tax rate.
            decimal[]      taxPercentsRate        = { 0.00m, 0.19m, 0.20m, 0.21m, 0.41m, 0.46m };              //array to hold the tax rate value for each 6 bands of tax rate.
            List <decimal> remainingValueOfSalary = new List <decimal> {
                payee.GrossAnnualSalary
            };                                                                                    //list (with initial of annual salary) withhold remaining salary for each tax bands calculation.

            //iterate through (& calculate tax due) each tax bands and calculate total tax owned at the end.
            for (int i = 0; i < taxPercentsRate.Length; i++)
            {
                //if users income within personal allowance then return 0 for the total tax deduction.
                if (payee.GrossAnnualSalary >= 0 && payee.GrossAnnualSalary <= 12500)
                {
                    Console.WriteLine("¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬");
                    Console.WriteLine($"Your income is within '20-'21 personal allowance. 0% tax will be applied");
                    Console.WriteLine("¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬");
                    return(totalTaxDeduction);
                }
                //if users income outwith personal allowance then calculate tax due & return the total tax deduction.
                else if (payee.GrossAnnualSalary > 12500.00m)
                {
                    decimal taxDeduction;

                    //as long the amount in the remaining salary if higher then the taxable amount in the next tax rate, calculate those taxes
                    if (remainingValueOfSalary[i] > taxMaxThresholdRate[i] - taxMinThresholdRate[i])
                    {
                        //calculate the current tax bracket from min & max thresholds multiply with current tax bracket rate. result in tax deduction for the current bracket.
                        taxDeduction = (taxMaxThresholdRate[i] - taxMinThresholdRate[i]) * taxPercentsRate[i];
                        Console.WriteLine($"Tax deduction for your earning between £{taxMinThresholdRate[i]} - £{taxMaxThresholdRate[i]} is £{taxDeduction}.");
                        //increment the value of current tax bracket tax deduction to the total tax deduction.
                        totalTaxDeduction += taxDeduction;
                        //get remaining value of salary (then add to remaining salary List to have value for next loop) before moving on to the next tax bracket.
                        remainingValueOfSalary.Add(remainingValueOfSalary[i] - (taxMaxThresholdRate[i] - taxMinThresholdRate[i]));
                    }
                    //else calculate the remaining salary after deduction with the last tax rate. add result to total tax deduction.
                    else if (remainingValueOfSalary[i] < taxMaxThresholdRate[i] - taxMinThresholdRate[i])
                    {
                        if (remainingValueOfSalary[i] == 0)
                        {
                            Console.WriteLine("¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬");
                            break;
                        }
                        else
                        {
                            decimal taxOnLastRemainingSalary;
                            taxOnLastRemainingSalary = remainingValueOfSalary[i] * taxPercentsRate[i];
                            totalTaxDeduction       += taxOnLastRemainingSalary;
                            Console.WriteLine($"Tax deduction for your last remainder salary of £{remainingValueOfSalary[i]} is £{taxOnLastRemainingSalary}.");
                            remainingValueOfSalary.Add(0); //last remaining salary should be zero.
                        }
                    }
                }
            }
            return(totalTaxDeduction);
        }