コード例 #1
0
        // GET: Admin/Salary/PayslipPrintPreview
        public ActionResult PayslipPrintPreview(string id = "")
        {
            try
            {
                PaySlipInfo _paySlip = null;
                int         _temp;

                if (!int.TryParse(id, out _temp))
                {
                    return(RedirectToAction("Details", "Salary"));
                }

                using (PaySlipRepository Repo = new PaySlipRepository())
                {
                    _paySlip = Repo.GetPayslipById(int.Parse(id));
                }

                if (_paySlip == null)
                {
                    return(RedirectToAction("Details", "Salary"));
                }

                return(PartialView("_PayslipPrintPreview", _paySlip));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Salary", "PayslipPrintPreview")));
            }
        }
コード例 #2
0
        public void SavePayslip(PaySlipInfo paySlipInfo)
        {
            Data.PaySlip payslip = ConvertToDb(paySlipInfo);

            _context.PaySlips.Add(payslip);
            _context.SaveChanges();
        }
コード例 #3
0
        public ActionResult DeletePayslip(string PayslipId = "")
        {
            try
            {
                int         _id;
                PaySlipInfo _paySlip      = null;
                string      previousMonth = DateTime.Now.AddMonths(-1).ToString("MMMM - yyyy");
                string      currentMonth  = DateTime.Now.ToString("MMMM - yyyy");
                string      nextMonth     = DateTime.Now.AddMonths(1).ToString("MMMM - yyyy");

                if (!int.TryParse(PayslipId, out _id))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                    return(RedirectToAction("Details", "Salary"));
                }

                using (PaySlipRepository Repo = new PaySlipRepository())
                {
                    _paySlip = Repo.GetPayslipById(_id);

                    if (_paySlip == null)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Payslip does not exist.");

                        return(RedirectToAction("Details", "Salary"));
                    }

                    if (_paySlip.SalaryDate.ToString("MMMM - yyyy") != previousMonth && _paySlip.SalaryDate.ToString("MMMM - yyyy") != currentMonth && _paySlip.SalaryDate.ToString("MMMM - yyyy") != nextMonth)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Selected payslip cannot be deleted.");

                        return(RedirectToAction("Details", "Salary", new { id = _paySlip.EmployeeInfoId }));
                    }

                    Repo.DeletePayslip(_id);

                    TempData["Msg"] = AlertMessageProvider.SuccessMessage("Payslip deleted successfully.");
                }

                return(RedirectToAction("Details", "Salary", new { id = _paySlip.EmployeeInfoId }));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Salary", "DeletePayslip")));
            }
        }
コード例 #4
0
 public Data.PaySlip ConvertToDb(PaySlipInfo paySlipInfo)
 {
     return(new Data.PaySlip
     {
         Id = paySlipInfo.Id,
         NumberOfDaysWorked = paySlipInfo.NumberOfDaysWorked,
         TotalSalary = paySlipInfo.TotalSalary,
         BasicSalary = paySlipInfo.BasicSalary,
         HouseRent = paySlipInfo.HouseRent,
         MedicalAllowance = paySlipInfo.MedicalAllowance,
         IncomTax = paySlipInfo.IncomTax,
         LoanDeduction = paySlipInfo.LoanDeduction,
         OtherDeductions = paySlipInfo.OtherDeductions,
         SalaryDate = paySlipInfo.SalaryDate,
         EmployeeInfoId = paySlipInfo.EmployeeInfoId,
         CreatedDate = paySlipInfo.CreatedDate,
         CreatedByAccountId = paySlipInfo.CreatedByAccountId,
         ModifiedDate = paySlipInfo.ModifiedDate,
         ModifiedByAccountId = paySlipInfo.ModifiedByAccountId
     });
 }
コード例 #5
0
        public ActionResult CreateSalariesHistory(string employeesIdList = "", string SalaryDate = "")
        {
            try
            {
                string previousMonth = DateTime.Now.AddMonths(-1).ToString("MMMM - yyyy");
                string currentMonth  = DateTime.Now.ToString("MMMM - yyyy");
                string nextMonth     = DateTime.Now.AddMonths(1).ToString("MMMM - yyyy");

                if (string.IsNullOrEmpty(employeesIdList) || string.IsNullOrEmpty(SalaryDate))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! please try again later.");

                    return(View());
                }

                DateTime dt;

                if (!DateTime.TryParse(SalaryDate, out dt))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid date, please select valid date.");

                    return(View());
                }

                if (dt.ToString("MMMM - yyyy") != previousMonth && dt.ToString("MMMM - yyyy") != currentMonth && dt.ToString("MMMM - yyyy") != nextMonth)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Salary cannot be created other than previous, current and next month.");

                    return(View());
                }

                var  _empIdsList  = employeesIdList.Split(',').Select(int.Parse).ToList();
                var  _paySlipInfo = new PaySlipInfo();
                bool isSucceed    = false;

                _paySlipInfo.CreatedDate        = DateTime.Now;
                _paySlipInfo.SalaryDate         = dt;
                _paySlipInfo.NumberOfDaysWorked = DateTime.DaysInMonth(dt.Year, dt.Month);
                _paySlipInfo.CreatedByAccountId = CurrentUser.AccountId;

                using (var transaction = new System.Transactions.TransactionScope())
                {
                    using (SalaryRepository SalaryRepo = new SalaryRepository())
                    {
                        using (PaySlipRepository PaySlipRepo = new PaySlipRepository())
                        {
                            foreach (var empId in _empIdsList)
                            {
                                SalaryInfo salary = null;
                                salary = SalaryRepo.GetSalaryByEmployeeId(empId);

                                if (salary != null)
                                {
                                    if (PaySlipRepo.IsPayslipCreated((int)salary.EmployeeInfoId, SalaryDate) == true)
                                    {
                                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Selected employee(s) salary of selected month has already created.");

                                        return(RedirectToAction("Manage", "Salary"));
                                    }

                                    if (salary.TotalSalary > 0)
                                    {
                                        _paySlipInfo.TotalSalary      = salary.TotalSalary;
                                        _paySlipInfo.BasicSalary      = salary.BasicSalary;
                                        _paySlipInfo.HouseRent        = salary.HouseRent;
                                        _paySlipInfo.MedicalAllowance = salary.MedicalAllowance;
                                        _paySlipInfo.IncomTax         = salary.IncomTax;
                                        _paySlipInfo.LoanDeduction    = salary.LoanDeduction;
                                        _paySlipInfo.OtherDeductions  = salary.OtherDeductions;
                                        _paySlipInfo.EmployeeInfoId   = (int)salary.EmployeeInfoId;

                                        PaySlipRepo.SavePayslip(_paySlipInfo);

                                        salary.LoanDeduction   = 0;
                                        salary.OtherDeductions = 0;

                                        SalaryRepo.UpdateSalary(salary);
                                        isSucceed = true;
                                    }
                                }
                            }
                        }
                    }

                    transaction.Complete();
                }

                if (isSucceed == true)
                {
                    TempData["Msg"] = AlertMessageProvider.SuccessMessage("Salaries created successfully.");
                }
                else
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Selected employee(s) salary amount is zero.");
                }

                return(RedirectToAction("Manage", "Salary"));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Salary", "CreateSalariesHistory")));
            }
        }