コード例 #1
0
        public async Task <IActionResult> Create(PaymentRecordCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_employeeService.GetById(model.EmployeeId) != null)
                {
                    var overtimeHours       = _paymentService.OvertimeHours(model.HoursWorked, model.ContractualHours);
                    var overtimeEarnings    = _paymentService.OvertimeEarnings(_paymentService.OvertimeRate(model.HourlyRate), overtimeHours);
                    var contractualEarnings = _paymentService.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate);
                    var totalEarnings       = _paymentService.TotalEarnings(overtimeEarnings, contractualEarnings);

                    var tax      = _taxService.TaxAmount(totalEarnings);
                    var nIC      = _contributionService.NIContribution(totalEarnings);
                    var sLC      = _employeeService.StudentLoanRepaymentAmount(model.EmployeeId, totalEarnings);
                    var unionFee = _employeeService.UnionFees(model.EmployeeId);

                    var totalDeduction = _paymentService.TotalDeduction(tax, nIC, sLC, unionFee);
                    var netPayment     = _paymentService.NetPay(totalEarnings, totalDeduction);

                    var paymentRecord = new PaymentRecord()
                    {
                        Id                  = model.Id,
                        EmployeeId          = model.EmployeeId,
                        FullName            = _employeeService.GetById(model.EmployeeId).FullName,
                        NINO                = _employeeService.GetById(model.EmployeeId).NationalInsuranceNumber,
                        PayDate             = model.PayDate,
                        PayMonth            = model.PayMonth,
                        ContractualHours    = model.ContractualHours,
                        ContractualEarnings = contractualEarnings,
                        OvertimeHours       = overtimeHours,
                        OvertimeEarnings    = overtimeEarnings,
                        Tax                 = tax,
                        TaxYearId           = model.TaxYearId,
                        TaxCode             = model.TaxCode,
                        TaxYear             = model.TaxYear,
                        SLC                 = sLC,
                        UnionFee            = unionFee,
                        NIC                 = nIC,
                        HourlyRate          = model.HourlyRate,
                        HoursWorked         = model.HoursWorked,
                        TotalDeductions     = totalDeduction,
                        TotalEarnings       = totalEarnings,
                        NetPayment          = netPayment
                    };

                    await _paymentService.CreateAsync(paymentRecord);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            PopulateDataFieldsTaxYearsAndEmployees(model);
            return(View());
        }
コード例 #2
0
ファイル: PayController.cs プロジェクト: kimgyver/paycompute
        public async Task <IActionResult> Create(PaymentRecordCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                decimal overtimeHours       = _payComputationService.OvertimeHours(model.HoursWorked, model.ContractualHours);
                decimal contractualEarnings = _payComputationService.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate);
                decimal overtimeEarnings    = _payComputationService.OvertimeEarnings(_payComputationService.OvertimeRate(model.HourlyRate), overtimeHours);
                decimal totalEarnings       = _payComputationService.TotalEarnings(overtimeEarnings, contractualEarnings);
                decimal tax            = _taxService.TaxAmount(totalEarnings);
                decimal unionFee       = _employeeService.UnionFees(model.EmployeeId);
                decimal sLC            = _employeeService.StudentLoanRepaymentAmount(model.EmployeeId, totalEarnings);
                decimal nIC            = _nationalInsuranceContributionService.NIContribution(totalEarnings);
                decimal totalDeduction = _payComputationService.TotalDeduction(tax, nIC, sLC, unionFee);

                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       = overtimeHours,
                    ContractualEarnings = contractualEarnings,
                    OvertimeEarnings    = overtimeEarnings,
                    TotalEarnings       = totalEarnings,
                    Tax                 = tax,
                    UnionFee            = unionFee,
                    SLC                 = sLC,
                    NIC                 = nIC,
                    TotalDeduction      = totalDeduction,
                    NetPayment          = _payComputationService.NetPay(totalEarnings, totalDeduction)
                };
                await _payComputationService.CreateAsync(payrecord);

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.employees = _employeeService.GetAllEmployeesForPayroll();
            ViewBag.taxYears  = _payComputationService.GetAllTaxYear();
            return(View());
        }
コード例 #3
0
        // [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());
        }
コード例 #4
0
ファイル: PayController.cs プロジェクト: cShark-dev/Payway3
        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());
        }
コード例 #5
0
        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());
        }
コード例 #6
0
ファイル: PayController.cs プロジェクト: katsuxD/Paycompute
        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());
        }
コード例 #7
0
        public async Task <IActionResult> Create(PaymentRecordCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var payrecord = new PaymentRecord()
                {
                    Id                  = model.Id,
                    EmployeeId          = model.EmployeeId,
                    FullName            = _employeeServices.GetById(model.EmployeeId).FullName,
                    NiNo                = _employeeServices.GetById(model.EmployeeId).NationalInsuranceNo,
                    PayDate             = model.PayDate,
                    PayMonth            = model.PayMonth,
                    TaxYearId           = model.TaxYearId,
                    TaxCode             = model.TaxCode,
                    HourlyRate          = model.HourlyRate,
                    HoursWorkd          = model.HoursWorked,
                    ContractualHours    = model.ContractualHours,
                    OverTimeHours       = overtimeHrs = _paycompuatuationServices.OvertimeHours(model.HoursWorked, model.ContractualHours),
                    ContractualEarnings = ContractualEarnings = _paycompuatuationServices.ContractualEarnings(model.ContractualHours, model.HoursWorked, model.HourlyRate),
                    OvertimeEarnings    = OvertimeEarnings = _paycompuatuationServices.OvertimeEarnings(_paycompuatuationServices.OvertimeRate(model.HourlyRate), overtimeHrs),
                    TotalEarnings       = totalEarnings = _paycompuatuationServices.TotalEarnings(OvertimeEarnings, ContractualEarnings),
                    Tax                 = tax = _taxservices.TaxAmount(totalEarnings),
                    UnionFee            = unionFee = _employeeServices.UnionFees(model.EmployeeId),
                    SLC                 = studentloan = _employeeServices.StudentLoadRepaymentAmount(model.EmployeeId, totalEarnings),
                    NIC                 = nationalinsurance = _nationalInsuranceContributionService.NIContribution(totalEarnings),
                    TotalDeduction      = totalDeduction = _paycompuatuationServices.TotalDeduction(tax, nationalinsurance, studentloan, unionFee),
                    NetPayment          = _paycompuatuationServices.NetPay(totalEarnings, totalDeduction)
                };
                await _paycompuatuationServices.CreateAsync(payrecord);

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.employees = _employeeServices.GetAllEmployeeforPayroll();
            ViewBag.taxYears  = _paycompuatuationServices.GetAllTaxYear();
            return(View());
        }