/// <summary> /// Builds line by line money values of the paycheck /// </summary> /// <param name="person"></param> /// <returns></returns> private PaycheckPeopleViewModel BuildPaycheckModel(PaycheckPerson person) { var discount = _paycheck.Round(_paycheck.CalculateLetterADiscount(person.FirstName, person.LastName, DeductionContstants.Discount)); var benefitCost = person.EmpType == Constants.EmployeeType ? DeductionContstants.EmployeeDeduction : DeductionContstants.DependentDeduction; var discountAmount = _paycheck.Round(_paycheck.CalculateDiscountedDeduction(benefitCost, discount)); var vm = new PaycheckPeopleViewModel { PersonType = person.EmpType, FirstName = person.FirstName, LastName = person.LastName, Deduction = _paycheck.Round(_paycheck.CalculatePayPeriodValue(benefitCost, DeductionContstants.NumberOfPayPeriods)), Discount = _paycheck.Round(_paycheck.CalculatePayPeriodValue(discountAmount, DeductionContstants.NumberOfPayPeriods)), SubTotal = _paycheck.Round(_paycheck.CalculatePayPeriodValue(_paycheck.CalculateSubTotal(benefitCost, discountAmount), DeductionContstants.NumberOfPayPeriods)) }; return(vm); }
/// <summary> /// Iterates through the db result set and builds a paycheck view /// </summary> /// <param name="emp">List query result</param> /// <returns></returns> private PaycheckViewModel BuildPaycheck(List <PaycheckQuery> emp) { var people = new List <PaycheckPeopleViewModel>(); var paycheckView = new PaycheckViewModel(); try { //if any exceptions occur, they will result from settings not being pulled from Deductions table correctly, or are missing var person = new PaycheckPerson { FirstName = emp[0].FirstName, LastName = emp[0].LastName, Salary = emp[0].Salary, EmpType = Constants.EmployeeType }; var employee = BuildPaycheckModel(person); people.Add(employee); if (emp.Count > 1) { foreach (var d in emp) { person = new PaycheckPerson { FirstName = d.DependentFirstName, LastName = d.LastName, Salary = 0, EmpType = Constants.DependentType }; var dependent = BuildPaycheckModel(person); people.Add(dependent); } } paycheckView = BuildPaycheckView(people, _paycheck.CalculatePayPeriodValue(emp[0].Salary, DeductionContstants.NumberOfPayPeriods)); paycheckView.People = people; } catch (Exception) { //LOG to the database or other means throw; } return(paycheckView); }