Esempio n. 1
0
        public void Calculate(decimal grossPackage, char payFrequencyUserInput)
        {
            //1. Find the taxation year
            var taxYear = DateTime.Now.Year;

            // read file into a string and deserialize JSON to a type
            var taxFile = GetTaxFile.RetrieveTaxFile(_logger);

            try
            {
                //Locate the tax data from tax file based on the current year and load the tax slabs

                if (taxFile == null)
                {
                    _logger.Log("no data in tax file.");
                    return;
                }

                var currentTaxRate = taxFile.TaxRates != null && taxFile.TaxRates.Any() ? taxFile.TaxRates.Find(x => x.Year == taxYear) : null;

                if (currentTaxRate == null)
                {
                    _logger.Log("no tax data found for the current year in tax file.");
                    return;
                }

                //2. find the percentage of Super
                var superPercentage = currentTaxRate.SuperRate;

                //3. Calculate Super component

                var taxableIncome = grossPackage / ((100 + superPercentage) / 100);

                var super = taxableIncome * (superPercentage / 100);

                //4. Do deductions

                //4.1. Tax

                decimal incomeTax = new IncomeTax().Calculate(currentTaxRate, taxableIncome);

                //4.2. Medicare Levy

                decimal medicareLevy = new MedicareLevy().Calculate(currentTaxRate, taxableIncome);

                //4.3. Budget Repair Levy

                decimal budgetRepairLevy = new BudgetRepairLevy().Calculate(currentTaxRate, taxableIncome);

                //5. Find Net Pay

                var netIncome = grossPackage - super - incomeTax - medicareLevy - budgetRepairLevy;

                //6. Net pay per passed frequency .i.e., Monthly, Weekly or fortnightly
                Frequency frequency;
                decimal   netPay = 0;

                frequency = CalculateNetPayAndFrequency(payFrequencyUserInput, netIncome, ref netPay);

                //7. Build and return the result
                var salary = new Salary()
                {
                    Super            = super,
                    TaxableIncome    = taxableIncome,
                    NetIncome        = netIncome,
                    BudgetRepairLevy = budgetRepairLevy,
                    MedicareLevy     = medicareLevy,
                    IncomeTax        = incomeTax,
                    Frequency        = frequency,
                    NetPay           = netPay,
                    Gross            = grossPackage
                };
                DisplayOutput(grossPackage, salary);
            }
            catch (Exception ex)
            {
                _logger.Log("Error occurred during Calculate.. {0}", ex.Message);
            }
        }