public async Task <IActionResult> CreditUpdate(BangLuongViewModel viewModel) { #region Authorization var login = User.Identity.Name; var loginUserName = User.Claims.Where(m => m.Type.Equals("UserName")).FirstOrDefault().Value; ViewData["LoginUserName"] = loginUserName; var loginInformation = dbContext.Employees.Find(m => m.Leave.Equals(false) && m.Id.Equals(login)).FirstOrDefault(); if (loginInformation == null) { #region snippet1 await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); #endregion return(RedirectToAction("login", "account")); } if (!(loginUserName == Constants.System.account ? true : Utility.IsRight(login, "nhan-su", (int)ERights.View))) { return(RedirectToAction("AccessDenied", "Account")); } #endregion foreach (var item in viewModel.Credits) { var builder = Builders <CreditEmployee> .Filter; var filter = builder.Eq(m => m.Id, item.Id); var update = Builders <CreditEmployee> .Update .Set(m => m.MucThanhToanHangThang, item.MucThanhToanHangThang) .Set(m => m.Status, item.Status) .Set(m => m.UpdatedOn, DateTime.Now); dbContext.CreditEmployees.UpdateOne(filter, update); } return(Json(new { result = true, source = "update", message = "Thành công" })); }
public async Task <IActionResult> BangLuong(string Thang, string Id, string SapXep, string ThuTu) { #region Authorization var login = User.Identity.Name; var loginUserName = User.Claims.Where(m => m.Type.Equals("UserName")).FirstOrDefault().Value; ViewData["LoginUserName"] = loginUserName; var loginInformation = dbContext.Employees.Find(m => m.Leave.Equals(false) && m.Id.Equals(login)).FirstOrDefault(); if (loginInformation == null) { #region snippet1 await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); #endregion return(RedirectToAction("login", "account")); } if (!(loginUserName == Constants.System.account ? true : Utility.IsRight(login, "nhan-su", (int)ERights.View))) { return(RedirectToAction("AccessDenied", "Account")); } #endregion var linkCurrent = string.Empty; #region DDL var sortTimes = Utility.DllMonths(); var employees = dbContext.Employees.Find(m => m.Enable.Equals(true) && m.Leave.Equals(false) && m.LuongBHXH > 0).SortBy(m => m.FullName).ToList(); #endregion #region Times var toDate = Utility.GetSalaryToDate(Thang); var fromDate = toDate.AddMonths(-1).AddDays(1); var year = toDate.Year; var month = toDate.Month; Thang = string.IsNullOrEmpty(Thang) ? month + "-" + year : Thang; linkCurrent += !string.IsNullOrEmpty(linkCurrent) ? "&" : "?"; linkCurrent += "Thang=" + Thang; #endregion var mucluongvung = Utility.SalaryMucLuongVung(month, year); #region Filter var builder = Builders <SalaryEmployeeMonth> .Filter; var filter = builder.Eq(m => m.Enable, true) & builder.Eq(m => m.Month, month) & builder.Eq(m => m.Year, year) & builder.Gt(m => m.LuongThamGiaBHXH, 0); if (!string.IsNullOrEmpty(Id)) { filter = filter & builder.Eq(m => m.EmployeeId, Id); linkCurrent += !string.IsNullOrEmpty(linkCurrent) ? "&" : "?"; linkCurrent += "Id=" + Id; } #endregion #region Sort var sortBuilder = Builders <SalaryEmployeeMonth> .Sort.Ascending(m => m.EmployeeCode); SapXep = string.IsNullOrEmpty(SapXep) ? "code" : SapXep; ThuTu = string.IsNullOrEmpty(ThuTu) ? "asc" : ThuTu; switch (SapXep) { case "ten": sortBuilder = ThuTu == "asc" ? Builders <SalaryEmployeeMonth> .Sort.Ascending(m => m.EmployeeFullName) : Builders <SalaryEmployeeMonth> .Sort.Descending(m => m.EmployeeFullName); break; case "luong": sortBuilder = ThuTu == "asc" ? Builders <SalaryEmployeeMonth> .Sort.Ascending(m => m.LuongThamGiaBHXH) : Builders <SalaryEmployeeMonth> .Sort.Descending(m => m.LuongThamGiaBHXH); break; default: sortBuilder = ThuTu == "asc" ? Builders <SalaryEmployeeMonth> .Sort.Ascending(m => m.EmployeeCode) : Builders <SalaryEmployeeMonth> .Sort.Descending(m => m.EmployeeCode); break; } #endregion var records = dbContext.SalaryEmployeeMonths.CountDocuments(filter); var list = new List <SalaryEmployeeMonth>(); list = dbContext.SalaryEmployeeMonths.Find(filter).Sort(sortBuilder).ToList(); var viewModel = new BangLuongViewModel() { Salaries = list, Employees = employees, SalaryMucLuongVung = mucluongvung, MonthYears = sortTimes, Id = Id, Thang = Thang, LinkCurrent = linkCurrent, ThuTu = ThuTu, SapXep = SapXep, Records = (int)records }; return(View(viewModel)); }
public async Task <IActionResult> Credit(string thang, string khoi, string id) { #region Authorization var login = User.Identity.Name; var loginUserName = User.Claims.Where(m => m.Type.Equals("UserName")).FirstOrDefault().Value; ViewData["LoginUserName"] = loginUserName; var loginInformation = dbContext.Employees.Find(m => m.Leave.Equals(false) && m.Id.Equals(login)).FirstOrDefault(); if (loginInformation == null) { #region snippet1 await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); #endregion return(RedirectToAction("login", "account")); } if (!(loginUserName == Constants.System.account ? true : Utility.IsRight(login, "nhan-su", (int)ERights.View))) { return(RedirectToAction("AccessDenied", "Account")); } #endregion #region DDL var sortTimes = Utility.DllMonths(); #endregion #region Times var toDate = Utility.GetToDate(thang); var fromDate = toDate.AddMonths(-1).AddDays(1); var year = toDate.Year; var month = toDate.Month; #endregion #region Filter var builder = Builders <CreditEmployee> .Filter; var filter = builder.Eq(m => m.Enable, true); if (!string.IsNullOrEmpty(thang)) { filter = filter & builder.Eq(m => m.Month, month) & builder.Eq(m => m.Year, year); } if (!string.IsNullOrEmpty(id)) { filter = filter & builder.Eq(x => x.EmployeeId, id.Trim()); } if (!string.IsNullOrEmpty(khoi)) { var intKhoi = (int)EKhoiLamViec.VP; switch (khoi) { case "SX": intKhoi = (int)EKhoiLamViec.SX; break; case "NM": intKhoi = (int)EKhoiLamViec.NM; break; } filter = filter & builder.Eq(x => x.EmployeeKhoi, intKhoi); } #endregion #region Sort var sortBuilder = Builders <CreditEmployee> .Sort.Ascending(m => m.UpdatedOn); #endregion var credits = await dbContext.CreditEmployees.Find(filter).Sort(sortBuilder).ToListAsync(); var viewModel = new BangLuongViewModel { Credits = credits, MonthYears = sortTimes, Thang = thang }; return(View(viewModel)); }
public async Task <IActionResult> CreditUpdate() { #region Authorization var login = User.Identity.Name; var loginUserName = User.Claims.Where(m => m.Type.Equals("UserName")).FirstOrDefault().Value; ViewData["LoginUserName"] = loginUserName; var loginInformation = dbContext.Employees.Find(m => m.Leave.Equals(false) && m.Id.Equals(login)).FirstOrDefault(); if (loginInformation == null) { #region snippet1 await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); #endregion return(RedirectToAction("login", "account")); } if (!(loginUserName == Constants.System.account ? true : Utility.IsRight(login, "nhan-su", (int)ERights.View))) { return(RedirectToAction("AccessDenied", "Account")); } #endregion var credits = new List <CreditEmployee>(); var employees = await dbContext.Employees.Find(m => m.Enable.Equals(true)& !m.UserName.Equals(Constants.System.account)).ToListAsync(); foreach (var employee in employees) { decimal mucthanhtoanhangthang = 0; var credit = await dbContext.CreditEmployees.Find(m => m.EmployeeId.Equals(employee.Id)).FirstOrDefaultAsync(); if (credit != null) { mucthanhtoanhangthang = credit.MucThanhToanHangThang; credits.Add(new CreditEmployee { Id = credit.Id, EmployeeId = employee.Id, EmployeeCode = employee.CodeOld, FullName = employee.FullName, EmployeeTitle = employee.SalaryChucVu, MucThanhToanHangThang = mucthanhtoanhangthang }); } else { var creditItem = new CreditEmployee { EmployeeId = employee.Id, EmployeeCode = employee.CodeOld, FullName = employee.FullName, EmployeeTitle = employee.SalaryChucVu, MucThanhToanHangThang = mucthanhtoanhangthang }; credits.Add(creditItem); dbContext.CreditEmployees.InsertOne(creditItem); } } var viewModel = new BangLuongViewModel { Credits = credits }; return(View(viewModel)); }