Esempio n. 1
0
        public async Task <IActionResult> Create(PaymentRecordCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var paymentRecord = new PaymentRecord()
                {
                    Id                  = model.Id,
                    EmployeeId          = model.EmployeeId,
                    FullName            = _employeeService.GetEmployeeById(model.EmployeeId).FullName,
                    NiNo                = _employeeService.GetEmployeeById(model.EmployeeId).SSN,
                    PayDate             = model.PayDate,
                    PayMonth            = model.PayMonth,
                    TaxYearId           = model.TaxYearId,
                    TaxCode             = model.TaxCode,
                    HourlyRate          = model.HourlyRate,
                    HourWorked          = model.HourWorked,
                    ContractualHours    = model.ContractualHours,
                    OvertimeHours       = overtimeHrs = _payComputationService.OvertimeHours(model.HourWorked, model.ContractualHours),
                    ContractualEarnings = contractualEarnings = _payComputationService.ContractualEarnings(model.ContractualHours, model.HourWorked, 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.INContribution(totalEarnings),
                    TotalDeducation     = totalDeducation = _payComputationService.TotalDeduction(tax, nationalInsurance, studentLoan, unionFee),
                    NetPayment          = _payComputationService.NetPayment(totalEarnings, totalDeducation)
                };
                await _payComputationService.CreatePaymentRecordAsync(paymentRecord);

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.employees = _employeeService.GetAllEmployeesForPayroll();
            ViewBag.taxYears  = _payComputationService.GetAllTaxYears();
            return(View());
        }