Ejemplo n.º 1
0
        public ActionResult CreateUpdatePermanentEmployeeSalary(PermanentEmployeeSalaryModel empModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var empSalary = new PermanentEmployeeSalary();

            if (empModel.Id > 0)
            {
                empSalary = FarmManagementEntities.PermanentEmployeeSalaries.Single(x => x.Id == empModel.Id);
            }

            empSalary.Year             = empModel.Year;
            empSalary.Month            = empModel.Month;
            empSalary.Date             = empModel.Date;
            empSalary.UserId           = empModel.EmployeeId;
            empSalary.BasicSalary      = empModel.BasicSalary;
            empSalary.MedicalAllowance = Convert.ToDecimal(empModel.MedicalAllowance);
            empSalary.TA_DA            = Convert.ToDecimal(empModel.TA_DA);
            empSalary.HouseRent        = Convert.ToDecimal(empModel.HouseRent);
            empSalary.UtilityAllowance = Convert.ToDecimal(empModel.UtilityAllowance);
            empSalary.ProvidentFund    = Convert.ToDecimal(empModel.ProvidentFund);
            empSalary.Bonus            = Convert.ToDecimal(empModel.Bonus);
            empSalary.Penality         = empModel.Penality;
            empSalary.IsAllowFund      = empModel.IsAllowFund;

            if (empModel.Id == 0)
            {
                empSalary.InsertDate = DateTime.Now;
                FarmManagementEntities.PermanentEmployeeSalaries.Add(empSalary);
            }
            else
            {
                empSalary.UpdateDate = DateTime.Now;
            }

            var user = FarmManagementEntities.Users.FirstOrDefault(u => u.Id == empModel.EmployeeId);

            if (user != null)
            {
                user.Salary = empModel.BasicSalary.ToString();
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, empModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Ejemplo n.º 2
0
        public ActionResult CreateUpdatePermanentEmployeeSalary(Int32 id)
        {
            var empSalaryModel = new PermanentEmployeeSalaryModel();

            if (id > 0)
            {
                var empSalary = FarmManagementEntities.PermanentEmployeeSalaries.Single(x => x.Id == id);
                empSalaryModel = empSalary.ToType <PermanentEmployeeSalary, PermanentEmployeeSalaryModel>();

                var basicSalaryFromEmployeeTable = FarmManagementEntities.Users.Where(u => u.Id == empSalary.UserId).Select(u => u.Salary).FirstOrDefault();
                if (basicSalaryFromEmployeeTable != null)
                {
                    decimal numericSalary;

                    if (Decimal.TryParse(basicSalaryFromEmployeeTable, out numericSalary))
                    {
                        empSalaryModel.BasicSalary = numericSalary;
                    }
                }

                var loanReceived =
                    FarmManagementEntities.LoanManagements.Where(lm => lm.UserId == empSalary.UserId)
                    .Sum(lm => lm.LoanAmount);

                empSalaryModel.LoanReceived = loanReceived;

                var loanReturned =
                    FarmManagementEntities.ReturnLoans.Where(lm => lm.UserId == empSalary.UserId)
                    .Sum(lm => lm.InstallmentAmount);

                empSalaryModel.LoanReturned = loanReturned;

                empSalaryModel.LoanRemaining = loanReceived - loanReturned;

                empSalaryModel.EmployeeId = empSalary.UserId;
            }

            return(PartialView("PermanentEmployeeSalaryPartial", empSalaryModel));
        }