Esempio n. 1
0
        public static double GetPayrollResponse(List <Models.TaxRole> taxRoles, PayrollCalculateInput payrollCalculateInput, out double taxesDeductions)
        {
            double grossSalary = payrollCalculateInput.HourlyRate * payrollCalculateInput.HoursWorked;

            taxesDeductions = 0;

            foreach (TaxRole taxRole in taxRoles.OrderBy(i => i.MinSalary).ToList( ))
            {
                if (taxRole.MaxSalary == 0 && taxRole.MinSalary == 0)
                {
                    taxesDeductions += grossSalary * taxRole.TaxPercent / 100;
                    continue;
                }
                if (
                    (grossSalary > taxRole.MinSalary && grossSalary <= taxRole.MaxSalary) ||
                    (grossSalary > taxRole.MinSalary && taxRole.MaxSalary == 0)
                    )
                {
                    taxesDeductions += (grossSalary - taxRole.MinSalary) * taxRole.TaxPercent / 100;
                    continue;
                }
                else if (grossSalary > taxRole.MaxSalary && taxRole.MaxSalary != 0)
                {
                    taxesDeductions += (taxRole.MaxSalary - taxRole.MinSalary) * taxRole.TaxPercent / 100;
                }
            }
            return(grossSalary);
        }
Esempio n. 2
0
        public static async Task <PayrollResponse> GetPayroll(PayrollServiceContext _payrollServiceContext, Server.PayrollService _payrollService, PayrollCalculateInput payrollCalculateInput)
        {
            PayrollResponse payrollResponse = new PayrollResponse( );

            Country        country  = CountryServer.Get(_payrollServiceContext, _payrollService, payrollCalculateInput.CountryCode);
            List <TaxRole> taxRoles = new List <TaxRole>( );

            if (country != null)
            {
                taxRoles = await _payrollServiceContext.TaxRoles.Where(i => i.CountryId == country.Id).ToListAsync( );

                double taxesDeductions = 0;
                if (payrollCalculateInput.HourlyRate <= 0 || payrollCalculateInput.HoursWorked <= 0)
                {
                    payrollResponse.Message = "Data is not valid";
                    return(payrollResponse);
                }
                double grossSalary = Server.PayrollService.GetPayrollResponse(taxRoles, payrollCalculateInput, out taxesDeductions);
                if (taxesDeductions == 0)
                {
                    payrollResponse.Message = "Tax Role Not Found";
                    return(payrollResponse);
                }
                payrollResponse.CountryCode     = payrollCalculateInput.CountryCode = country.Code;
                payrollResponse.GrossSalary     = grossSalary;
                payrollResponse.NetSalary       = grossSalary - taxesDeductions;
                payrollResponse.TaxesDeductions = taxesDeductions;
                payrollResponse.Message         = "true";
            }
            else
            {
                payrollResponse.Message = "Country Code is not exists...";
            }

            return(payrollResponse);
        }
        public async Task <IHttpActionResult> GetTaxRole(PayrollCalculateInput payrollCalculateInput)
        {
            PayrollResponse payrollResponse = await Middle.Payroll.GetPayroll(_payrollServiceContext, _payrollService, payrollCalculateInput);

            return(Ok(payrollResponse));
        }