//[Authorize(Roles = "Admin")] public async Task <IActionResult> Create(PaymentRecordCreateViewModel model) { if (ModelState.IsValid) { var payRecord = new PaymentRecord() { Id = model.Id, EmployeeId = model.EmployeeId, FullName = _employeeService.GetById(model.EmployeeId).FullName, //Full name comes from selected employee from the dropdown list NiNo = _employeeService.GetById(model.EmployeeId).NationalInsuranceNo, PayDate = model.PayDate, PayMonth = model.PayMonth, TaxYearId = model.TaxYearId, TaxCode = model.TaxCode, HourlyRate = model.HourlyRate, HoursWorked = model.HoursWorked, ContractualHours = model.ContractualHours, //multi asignment expressions below. //these methods take arguments, also new feilds were declared to store values and make it easier to pass to methods. OvertimeHours = overtimeHrs = _payComputationService.OvertimeHours(model.HoursWorked, model.ContractualHours), ContractualEarnings = contractualEarnings = _payComputationService.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate), OvertimeEarnings = overtimeEarnings = _payComputationService.OvertimeEarnings(_payComputationService.OvertimeRate(model.HourlyRate), overtimeHrs), TotalEarnings = totalEarnings = _payComputationService.TotalEarnings(overtimeEarnings, contractualEarnings), Tax = tax = _taxService.TaxAmount(totalEarnings), UnionFee = unionFee = _employeeService.UnionFees(model.EmployeeId), SLC = studentLoan = _employeeService.StudentLoanRepaymentAmount(model.EmployeeId, totalEarnings), NIC = nationalInsurance = _nationalInsuranceContributionService.NIContribution(totalEarnings), TotalDeduction = totalDeduction = _payComputationService.TotalDeduction(tax, nationalInsurance, studentLoan, unionFee), NetPayment = _payComputationService.NetPay(totalEarnings, totalDeduction) }; await _payComputationService.CreateAsync(payRecord); return(RedirectToAction(nameof(Index))); } ViewBag.employees = _employeeService.GetAllEmployeesForPayroll(); ViewBag.taxYears = _payComputationService.GetAllTaxYear(); return(View()); }
public async Task <IActionResult> Create(PaymentRecordCreateViewModel model) { if (ModelState.IsValid) { var payRecord = new PaymentRecord() { Id = model.Id, EmployeeId = model.EmployeeId, FullName = _employeeService.GetById(model.EmployeeId).FullName, Nino = _employeeService.GetById(model.EmployeeId).NationalInsuranceNo, PayDate = model.PayDate, PayMonth = model.PayMonth, TaxYearId = model.TaxYearId, TaxCode = model.TaxCode, HourlyRate = model.HourlyRate, HoursWorked = model.HoursWorked, ContractualHours = model.ContractualHours, OvertimeHours = overTimeHrs = _payRoleService.OvertimeHours(model.HoursWorked, model.ContractualHours), ContractualEarnings = contractualEarnungs = _payRoleService.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate), Overtimearnings = overTimeEarning = _payRoleService.OvertimeEarnings(_payRoleService.OvertimeRate(model.HourlyRate), overTimeHrs), TotalEarnings = totalEarning = _payRoleService.TotalEarnings(overTimeEarning, contractualEarnungs), Tax = tax = _taxService.TaxAmount(totalEarning), UnionFee = unionFee = _employeeService.UnionFees(model.EmployeeId), SLC = studentLoad = _employeeService.StudentLoadRepaymentAmount(model.EmployeeId, totalEarning), NIC = nationalInsurance = _nationalInsuranceContributionService.NIContribution(totalEarning), TotalDeductions = totalDeduction = _payRoleService.TotalDeduction(tax, nationalInsurance, studentLoad, unionFee), NetPayment = _payRoleService.NetPay(totalEarning, totalDeduction) }; await _payRoleService.CreatAsync(payRecord); return(RedirectToAction(nameof(Index))); } ViewBag.emplyees = _employeeService.GetAllEmployeesForPayroll(); ViewBag.taxYears = _payRoleService.GetAllTaxYear(); return(View()); }
public async Task <IActionResult> Create(PaymentRecordCreateViewModel model) { if (ModelState.IsValid) //First we need to check if the model state is valid, if it's valid we can create a new payment record { var payrecord = new PaymentRecord() { Id = model.Id, //Then we need to a our mapping EmployeeId = model.EmployeeId, FullName = _employeeService.GetById(model.EmployeeId).FullName, NiNo = _employeeService.GetById(model.EmployeeId).NationalInsuranceNo, PayDate = model.PayDate, PayMonth = model.PayMonth, TaxYearId = model.TaxYearId, TaxCode = model.TaxCode, HourlyRate = model.HourlyRate, HoursWorked = model.HoursWorked, ContractualHours = model.ContractualHours, OvertimeHours = overtimeHrs = _payComputationService.OvertimeHours(model.HoursWorked, model.ContractualHours), //We have a method to compute the overtime hours, this method takes 2 args ContractualEarnings = contractualEarnings = _payComputationService.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate), OvertimeEarnings = overtimeEarnings = _payComputationService.OvertimeEarnings(_payComputationService.OvertimeRate(model.HourlyRate), overtimeHrs), //This method takes 2 args, the first arg is passed in using a method TotalEarnings = totalEarnings = _payComputationService.TotalEarnings(overtimeEarnings, contractualEarnings), Tax = tax = _taxService.TaxAmount(totalEarnings), //The tax comes from the tax service so we need to inject that interface into the constructor UnionFee = unionFee = _employeeService.UnionFees(model.EmployeeId), SLC = studentLoan = _employeeService.StudentLoanRepaymentAmount(model.EmployeeId, totalEarnings), //This method takes in 2 args, the id and total amount earned NIC = nationalInsurance = _nationalInsuranceContributionService.NIContribution(totalEarnings), //We have a service for the NIC, let's inject the interface within the controller TotalDeduction = totalDeduction = _payComputationService.TotalDeduction(tax, nationalInsurance, studentLoan, unionFee), //Total deduction method takes 4 args NetPayment = _payComputationService.NetPay(totalEarnings, totalDeduction) }; await _payComputationService.CreateAsync(payrecord); //We are now ready to create a payment, and then we need to pass in payrecord, return(RedirectToAction(nameof(Index))); //once we create this we are going to return to index, redirecttoAction } ViewBag.employees = _employeeService.GetallEmployeesForPayroll(); //IF the model state fails, we still want the drop down list of all employees, This will render a selectable drop down list of all employees, we need to return the collection of employees as a select list item type ViewBag.taxYears = _payComputationService.GetAllTaxYear(); //AND all the tax years together with the view, this create is async so the method Iactionresult needs to be async return(View()); }
public async Task <IActionResult> Create(PaymentRecordCreateViewModel viewModel) { if (ModelState.IsValid) { var payRecord = new PaymentRecord { Id = viewModel.Id, EmployeeId = viewModel.EmployeeId, FullName = _employeeService.GetById(viewModel.Id).FullName, NiNo = viewModel.NiNo, PayDate = viewModel.PayDate, PayMonth = viewModel.PayMonth, TaxYearId = viewModel.TaxYearId, TaxCode = viewModel.TaxCode, HourlyRate = viewModel.HourlyRate, HoursWorked = viewModel.HoursWorked, ContractualHours = viewModel.ContractualHours, OvertimeHours = _overTimeHours = _payComputationServie.OvertimeHours(viewModel.HoursWorked, viewModel.ContractualHours), ContractualEarnings = _contractualEarnings = _payComputationServie.ContractualEarning(viewModel.ContractualHours, viewModel.HoursWorked, viewModel.HourlyRate), OvertimeEarnings = _overtimeEarnings = _payComputationServie.OvertimeEarnings(_payComputationServie.OvertimeRate(viewModel.HourlyRate), _overTimeHours), TotalEarnings = _totalEarnings = _payComputationServie.TotalEarnings(_overtimeEarnings, _contractualEarnings), Tax = _tax = _taxService.TaxAmount(_totalEarnings), UnionFee = _unionFee = _employeeService.UnionFees(viewModel.Id), SLC = _slc = _employeeService.StudentLoanRepaymentAmount(viewModel.Id, _totalEarnings), NIC = _nic = _nationalInsuranceContributionService.NIContribution(_totalEarnings), TotalDeduction = _totalDeduction = _payComputationServie.TotalDeduction(_tax, _nic, _slc, _unionFee), NetPayment = _payComputationServie.NetPay(_totalEarnings, _totalDeduction) }; await _payComputationServie.CreateAsync(payRecord); return(RedirectToAction(nameof(Index))); } ViewBag.employees = _employeeService.GetAllEmployeesForPayRoll(); ViewBag.taxYears = _payComputationServie.GetAllTaxYear(); return(View()); }
public async Task <IActionResult> Create(PaymentRecordCreateViewModel model) { if (ModelState.IsValid) { var payrecord = new PaymentRecord() { Id = model.Id, EmployeeId = model.EmployeeId, FullName = _employeeService.GetById(model.EmployeeId).Fullname, NiNo = _employeeService.GetById(model.EmployeeId).NationalInsuranceNo, PayDate = model.PayDate, PayMonth = model.PayMonth, TaxYearId = model.TaxYearId, TaxCode = model.TaxCode, HourlyRate = model.HourlyRate, HoursWorked = model.HoursWorked, ContractualHours = model.ContractualHours, OvertimeHours = overtimeHrs = _payComputationService.OvertimeHours(model.HoursWorked, model.ContractualHours), ContractualEarnings = contractualEarnings = _payComputationService.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate), OvertimeEarnings = overtimeEarnings = _payComputationService.OvertimeEarnings(_payComputationService.OvertimeRate(model.HourlyRate), overtimeHrs), TotalEarnings = totalEarnings = _payComputationService.TotalEarnings(overtimeEarnings, contractualEarnings), Tax = tax = _taxService.TaxAmount(totalEarnings), UnionFee = unionFee = _employeeService.UnionFees(model.EmployeeId), SLC = studentLoan = _employeeService.StudentLoanRepaymentAmount(model.EmployeeId, totalEarnings), NIC = nationalInsurance = _nationalInsuranceContributionService.NIContribution(totalEarnings), TotalDeduction = totalDeduction = _payComputationService.TotalDeduction(tax, nationalInsurance, studentLoan, unionFee), NetPayment = _payComputationService.NetPay(totalEarnings, totalDeduction) }; await _payComputationService.CreateAsync(payrecord); return(RedirectToAction(nameof(Index))); } //if the model state fails, the dropdown list of all the employee still present and all the taxyear -together with the view ViewBag.employees = _employeeService.GetAllEmployeesForPayroll(); ViewBag.taxYears = _payComputationService.GetAllTaxYear(); return(View()); }
private void PopulateDataFieldsTaxYearsAndEmployees(PaymentRecordCreateViewModel model) { model.AllTaxYears = _paymentService.GetAllTaxYear(); model.AllEmployeesForPayrollProcessing = _employeeService.GetAllEmployeesForPayrollProcessing(); }