/// <summary> /// Generate the PaySlip for a customer to be outputted /// </summary> /// <param name="processCust"></param> /// <param name="frequency"></param> /// <returns>PaySlipVm</returns> public PaySlipVm GenerateSalarySlip(Customer processCust, TimeFrequency frequency) { if (processCust.PayPeriod != null) { //Gross Income var grossIncome = processCust.PayPeriod.Package.AnnualGrossSalary / Convert.ToDecimal(frequency); //Income Tax decimal? incomeTax = _taxService.IncomeTaxCalculation(processCust.PayPeriod.Month, processCust.PayPeriod.Package.AnnualGrossSalary, frequency); if (!incomeTax.HasValue) return null; //Net Income var netIncome = grossIncome - incomeTax; //SuperAnnuation Rate var superRate = processCust.PayPeriod.Package.SuperAnnuationRate; var superAnnuation = grossIncome * superRate; // Generate PaySlipVm for the view return new PaySlipVm { GrossSalary = "" + grossIncome.RoundToNearestWhole(), CustomerFullName = processCust.GetFullName(), IncomeTax = "" + incomeTax.Value.RoundToNearestWhole(), NetIncome = "" + netIncome.Value.RoundToNearestWhole(), Period = processCust.PayPeriod.GetPayPeriodWithHypen(), SuperAnnuation = "" + superAnnuation.RoundToNearestWhole() }; } return null; }
private TimeEntry CreateTimeEntry(DateTime fromDate, DateTime throughDate, TimeFrequency frequency, WorkEffort workEffort, RateType rateType) => new TimeEntryBuilder(this.Session) .WithRateType(rateType) .WithFromDate(fromDate) .WithThroughDate(throughDate) .WithTimeFrequency(frequency) .WithWorkEffort(workEffort) .Build();
/// <summary> /// Calculates the income tax on the income based on date and frequency /// </summary> /// <param name="date"></param> /// <param name="income"></param> /// <param name="timeFrequency"></param> /// <returns>decimal?</returns> public decimal? IncomeTaxCalculation(DateTime date, decimal income, TimeFrequency timeFrequency) { var taxBracket = AllocatedTaxRate(date, income); if (taxBracket != null) { return (taxBracket.BaseTax + (income - taxBracket.MinSalaryValue.RoundValueToNearest100()) * taxBracket.BaseRate) / Convert.ToDecimal(timeFrequency); } return null; }
public static TimeEntry CreateTimeEntry(this WorkEffort @this, DateTime fromDate, DateTime throughDate, TimeFrequency frequency, RateType rateType) => new TimeEntryBuilder(@this.Session()) .WithRateType(rateType) .WithFromDate(fromDate) .WithThroughDate(throughDate) .WithTimeFrequency(frequency) .WithWorkEffort(@this) .Build();
void TaxServices_Calculate_Tax(decimal income, TimeFrequency timeFrequency, int year, int month, int day, [Frozen] Mock<IRateDatasSource> taxRates, TaxCalculationService sut) { // Assign DateTime date = (new DateTime(year, month, day)); taxRates.Setup(x => x.GetRates(date)).Returns(TestStubs.TaxBrackets()); decimal expected = 921.9375m; //Act var actual = sut.IncomeTaxCalculation(date, income, timeFrequency); // Assert getRates is called. taxRates.Verify(x => x.GetRates(It.IsAny<DateTime>()), Times.Once()); // Assert tax to verify it works Assert.Equal(expected, actual); }
void SalarySlipService_GenerateSalarySlip(TimeFrequency frequency, [Frozen] Mock<ITaxService> taxService, MonthlySalarySlipService sut) { // Assign Customer cust = TestStubs.GetCustomer(); PaySlipVm expected = TestStubs.GetPaySlipVm(cust.GetFullName(), cust.PayPeriod.GetPayPeriodWithHypen()); taxService.Setup(x => x.IncomeTaxCalculation(cust.PayPeriod.Month, cust.PayPeriod.Package.AnnualGrossSalary, frequency)).Returns(Convert.ToDecimal(expected.IncomeTax)); // Act PaySlipVm actual = sut.GenerateSalarySlip(cust, frequency); CompareLogic compareLogic = new CompareLogic(); ComparisonResult result = compareLogic.Compare(expected, actual); // Assert income tax calculation is called. taxService.Verify(x => x.IncomeTaxCalculation(It.IsAny<DateTime>(), It.IsAny<Decimal>(), It.IsAny<TimeFrequency>()), Times.Once()); //Assertions for Objects Assert.True(result.AreEqual); }