Example #1
0
        private static string SalaryToString(SalaryDto salary)
        {
            if (salary?.From == null && salary?.To == null)
            {
                return("None");
            }
            var sb = new StringBuilder();

            if (salary.From.HasValue)
            {
                sb.Append($" from {salary.From}");
            }
            if (salary.To.HasValue)
            {
                sb.Append($" to {salary.To}");
            }
            if (salary.Currency != null)
            {
                sb.Append($" {salary.Currency ?? "RUR"}");
            }
            if (salary.Gross == true)
            {
                sb.Append(" (Gross)");
            }
            return(sb.ToString());
        }
Example #2
0
        public async Task <Response <SalaryDto> > Update(Guid id, SalaryDto entityDto)
        {
            Salary salary = await _context.Salaries.FindAsync(id);

            if (salary == null)
            {
                throw new RestException(HttpStatusCode.NotFound, new { Salary = "Not found" });
            }

            salary.Month      = entityDto.Month;
            salary.Amount     = (double)entityDto.Amount;
            salary.EmployeeId = Guid.Parse(entityDto.EmployeeId);
            salary.UpdatedAt  = DateTime.Now;

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                var salaryDto = _mapper.Map <Salary, SalaryDto>(salary);

                return(new Response <SalaryDto>
                {
                    Data = salaryDto,
                    Message = "Salary is updated ",
                    Time = DateTime.Now,
                    IsSuccess = true
                });
            }
            ;

            throw new Exception("Problem on saving salary");
        }
Example #3
0
        public IList <SalaryDto> ListSalary()
        {
            IList <SalaryDto> salaryDtoList = new List <SalaryDto>();
            var salaries = _db2.Salaries.ToList();

            if (salaries == null)
            {
                return(null);
            }
            foreach (var item in salaries)
            {
                var salary = new SalaryDto()
                {
                    Amount    = item.TotalAmount.ToString(),
                    Employee  = item.Employee.AspNetUser.FirstName,
                    Employer  = item.Employer.AspNetUser.FirstName,
                    EndDate   = item.EndDate.ToString(),
                    SalaryId  = item.SalaryId,
                    StartDate = item.StartDate.ToString()
                };

                salaryDtoList.Add(salary);
            }

            return(salaryDtoList);
        }
        public SalaryDto CalculateSalary(decimal annualSalary, decimal superPercantage)
        {
            SalaryDto salary             = new SalaryDto();
            var       grossMonthlySalary = Math.Round(annualSalary / 12, MidpointRounding.AwayFromZero);

            salary.IncomeTax = _taxCalaculator.CalculateTax(grossMonthlySalary);
            var netIncome = grossMonthlySalary - salary.IncomeTax;

            salary.Super       = _superCalaculator.CalculateSuper(netIncome, superPercantage);
            salary.NetIncome   = Math.Round(netIncome, MidpointRounding.AwayFromZero);
            salary.GrossSalary = grossMonthlySalary;
            return(salary);
        }
Example #5
0
        public async Task <IActionResult> CalculateSalary(int id, SalaryDto salaryDto)
        {
            var result = await Execute(async() => await _hrService.CalculateSalary(id, salaryDto));

            if (result.Failed)
            {
                return(View(salaryDto));
            }

            ViewData["TotalSalary"] = result.Output;

            return(View(salaryDto));
        }
Example #6
0
        public async Task <Response <SalaryDto> > Create(SalaryDto entityDto)
        {
            var check = _context.Salaries
                        .Any(s => s.EmployeeId.ToString() == entityDto.EmployeeId &&
                             s.Month == entityDto.Month &&
                             s.Year == entityDto.Year)
            ;

            if (check)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { Salary = "Salary is already paid" });
            }

            try
            {
                Salary salary = new Salary
                {
                    Amount     = entityDto.Amount,
                    Month      = entityDto.Month,
                    Year       = entityDto.Year,
                    EmployeeId = Guid.Parse(entityDto.EmployeeId),
                    SalaryDate = DateTime.Now,
                    CreatedAt  = DateTime.Now,
                    UpdatedAt  = DateTime.Now
                };
                await _context.Salaries.AddAsync(salary);

                await _context.SaveChangesAsync();

                return(new Response <SalaryDto>
                {
                    Data = entityDto,
                    Message = "Salary saved",
                    Time = DateTime.Now,
                    IsSuccess = true
                });
            }
            catch (Exception e)
            {
                return(new Response <SalaryDto>
                {
                    Data = null,
                    Message = e.StackTrace,
                    Time = DateTime.Now,
                    IsSuccess = false
                });
            }
        }
Example #7
0
 public OutputBase SaveSalary(SalaryDto salary)
 {
     if (
         _salaryRepository.Query(
             q =>
             q.Any(s => s.SalaryComponentId == salary.SalaryComponentId && s.EmployeeId == salary.EmployeeId && s.Id != salary.Id)))
     {
         return(new OutputBase {
             Message = "You have already made an entry for this salary conpunent", Success = false
         });
     }
     _salaryRepository.InsertOrUpdate(Mapper.Map <Salary>(salary));
     return(new OutputBase {
         Message = "Conpunent saved", Success = true
     });
 }
Example #8
0
        public async Task <IActionResult> CalculateSalary(int id)
        {
            var result = await Execute(async() => await _employeeService.GetEmployeeById(id));

            if (!result.Failed)
            {
                var model = new SalaryDto
                {
                    EmployeeType = result.Output.EmployeeType
                };

                return(View(model));
            }

            TempData["ErrorMessage"] = result.Message;

            return(RedirectToAction(nameof(Index)));
        }
Example #9
0
        public SalaryDto CalculateSalary(decimal annualSalary, decimal superPercantage)
        {
            //gross income = 60,050 / 12 = 5,004.16666667(round down) = 5,004
            //income tax = (3, 572 + (60, 050 - 37, 000) x 0.325) / 12 = 921.9375(round up) = 922
            //net income = 5,004 - 922 = 4,082
            //super = 5,004 x 9 % = 450.36(round down) = 450

            SalaryDto salary = new SalaryDto();

            //gross income
            var grossMonthlySalary = Math.Round(annualSalary / 12, MidpointRounding.AwayFromZero);

            salary.GrossSalary = grossMonthlySalary;

            //income tax
            //TaxCalculator tc = new TaxCalculator();

            salary.IncomeTax = _taxCalculator.CalculateTax(annualSalary);

            //salary.IncomeTax= _taxCalculator.CalculateTax(annualSalary);
            //salary.IncomeTax = _taxCalculator.CalculateTax(annualSalary);

            //salary.IncomeTax = 922;



            //Net income
            var netIncome = grossMonthlySalary - salary.IncomeTax;

            salary.NetIncome = Math.Round(netIncome, MidpointRounding.AwayFromZero);

            //Super
            var superAmount = netIncome * (superPercantage / 100);

            salary.Super = Math.Round(superAmount, MidpointRounding.AwayFromZero);

            return(salary);
        }
        public async Task <PartialViewResult> CreateOrEditSalaryCompunentModal(int?id, int employeeId)
        {
            var output = new SalaryDto();

            if (id != null)
            {
                output = _employeeService.GetSalary(new GetSalaryInput {
                    SalaryId = id.Value
                });
            }
            var viewModel = new CreateOrEditSalaryModel(output, id == null || id == 0);

            ViewBag.EmployeeId = employeeId;

            ViewBag.SalaryComponentId = new SelectList(_configurationService.GetSalaryCompunents().Items, "Id", "Name",
                                                       output.SalaryComponentId);
            ViewBag.PayGradeId     = new SelectList(_jobConfigurationService.GetPayGrades().Items, "Id", "Name", output.PayGradeId);
            ViewBag.PayFrequencyId = new SelectList(_configurationService.GetPayFrequencies().Items, "Id", "Name",
                                                    output.PayFrequencyId);
            ViewBag.CurrencyId = new SelectList(_configurationService.GetCurrencies().Items, "Id", "Name",
                                                output.CurrencyId);
            return(PartialView("EmployeeDetail/Salary/_CreateOrEditSalaryModal", viewModel));
        }
Example #11
0
 public CreateOrEditSalaryModel(SalaryDto input, bool isNew)
 {
     IsEditMode = !isNew;
     Salary     = input;
 }
Example #12
0
        public async Task <ActionResult> Edit(Guid id, [FromBody] SalaryDto salaryDto)
        {
            var result = await _repo.Update(id, salaryDto);

            return(Ok(result));
        }
Example #13
0
        public async Task <ActionResult> Create([FromBody] SalaryDto salaryDto)
        {
            var result = await _repo.Create(salaryDto);

            return(Ok(result));
        }