private async Task <ChamCongVMList> FeedSomeDataToIndexAction(int month, int year) { var employees = await userManager.Users.ToListAsync(); var chamCongVMList = mapper.Map <List <ChamCongVM> >(employees); foreach (var employee in chamCongVMList) { employee.ChucVu = mapper.Map <ChucVusVM>(await chucVuRepo.FindById(employee.MaChucVu)); employee.ChuyenMon = mapper.Map <ChuyenMonsVM>(await chuyenMonRepo.FindById(employee.MaChuyenMon)); employee.PhongBan = mapper.Map <PhongBansVM>(await phongBanRepo.FindById(employee.MaPhongBan)); var MaVaiTroTrenHeThong = await userRoleRepository.FindRoleIdByUserID(employee.Id); employee.VaiTroTrenHeThong = await roleRepository.FindById(MaVaiTroTrenHeThong); //Tiền lương đã tích lũy = lương cơ bản /(6 ngày * 4 tuần *24 giờ* 60 phút)*hệ số lương * số phút của lịch biểu employee.TongTienLuongCoBanDaTichLuyTrongThang = TinhTongLuongCoBanTichLuyTrongThang(nhatKylamViecRepository, employee.Id, year, month); employee.TongTienThuongDaTichLuyTrongThang = TinhTongTienThuongDaTichLuyTrongThang(nhatKylamViecRepository, employee.Id, year, month); int tongSoPhut = TinhTongSoPhutLamDaTichLuyTrongThang(nhatKylamViecRepository, employee.Id, year, month); employee.TongSoGio.SoGio = tongSoPhut / 60; employee.TongSoGio.SoPhut = tongSoPhut % 60; employee.TongTienLuong = employee.TongTienLuongCoBanDaTichLuyTrongThang + employee.TongTienThuongDaTichLuyTrongThang; employee.TrangThaiXuatLuong = (await phieuChi_NKLVRepository.DaXuatPhieuChiHayChua(employee.Id, month, year)); } var model = new ChamCongVMList { ChamCongList = chamCongVMList, ViewForm = new ChamCongVMListViewForm { CurrentMonth = month.ToString(), CurrentYear = year.ToString() } }; model = FeedSomeDataToChamCongVMList(model); return(model); }
public async Task <ActionResult> Create(CreateEditLichSuChamCongVM model) { try { model = await FeedSomeDataToCreateEditVM(model); model.ThoiGianBatDau = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, int.Parse(model.StartHour), int.Parse(model.StartMinute), 0); model.ThoiGianKetThuc = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, int.Parse(model.EndHour), int.Parse(model.EndMinute), 0); if (!ModelState.IsValid) { return(View(model)); } if (model.ThoiGianBatDau.CompareTo(model.ThoiGianKetThuc) >= 0) { ModelState.AddModelError("", "Thời gian kết thúc phải lớn hơn thời gian bắt đầu"); return(View(model)); } if (model.ThoiGianKetThuc.Date.CompareTo(DateTime.Now) > 0) { ModelState.AddModelError("", "Bạn chỉ có thể chấm công trong ngày hôm nay và các ngày đã qua"); return(View(model)); } var LichSuChamCongList = await nhatKylamViecRepository.FindByMaNhanVien(model.NhanVien.Id); foreach (var item in LichSuChamCongList) { if (model.ThoiGianBatDau.CompareTo(item.ThoiGianBatDau) >= 0 && model.ThoiGianBatDau.CompareTo(item.ThoiGianKetThuc) < 0 || model.ThoiGianKetThuc.CompareTo(item.ThoiGianBatDau) > 0 && model.ThoiGianKetThuc.CompareTo(item.ThoiGianKetThuc) <= 0) { ModelState.AddModelError("", "Khoảng thời gian được chọn bị trùng với lịch biểu trước đó" + "\n Khoảng thời gian được chọn: " + model.ThoiGianBatDau + " => " + model.ThoiGianKetThuc + "\n Lịch biểu bị trùng: " + item.ThoiGianBatDau + " => " + item.ThoiGianKetThuc); return(View(model)); } } var approvedLeaveRequests = (await leaveRequestRepository.FindAll()) .Where(q => q.Approved == true && q.RequestingEmployeeId == model.MaNhanVien); foreach (var item in approvedLeaveRequests) { if (model.ThoiGianBatDau.Date.CompareTo(item.StartDate) >= 0 && model.ThoiGianBatDau.Date.CompareTo(item.EndDate) <= 0) { ModelState.AddModelError("", "Khoảng thời gian được chọn bị trùng với yêu cầu nghỉ phép được thực thi" + "\n Khoảng thời gian được chọn: " + model.ThoiGianBatDau + " => " + model.ThoiGianKetThuc + "\n Nghỉ phép được thực thi: " + item.StartDate + " => " + item.EndDate); return(View(model)); } } var IsThangDaXuatLuong = await phieuChi_NKLVRepository.DaXuatPhieuChiHayChua(model.MaNhanVien, model.Date.Month, model.Date.Year); if (IsThangDaXuatLuong) { ModelState.AddModelError("", $"Không thể chấm công vì tháng {model.Date.Month} năm {model.Date.Year} của nhân viên {model.NhanVien.LastName} {model.NhanVien.MiddleName} {model.NhanVien.FirstName} đã được xuất lương."); return(View(model)); } var nhatKyLamViecRecord = mapper.Map <NhatKyLamViec>(model); nhatKyLamViecRecord.NgayThemVaoHeThong = DateTime.Now; nhatKyLamViecRecord.MucLuongCoBan = model.NhanVien.MucLuongCoBan; nhatKyLamViecRecord.HeSoLuongCoBan = (await loaiLichBieuRepository.FindById(model.MaLoaiLichBieu)).HeSoLuongCoBan; nhatKyLamViecRecord.MaNhanVienThemVaoHeThong = (await userManager.GetUserAsync(User)).Id; nhatKyLamViecRecord.NhanVien = null; var isSuccess = await nhatKylamViecRepository.Create(nhatKyLamViecRecord); if (!isSuccess) { model.NhanVien = mapper.Map <EmployeeVM>(await userManager.FindByIdAsync(model.MaNhanVien)); ModelState.AddModelError("", "Lỗi xảy ra khi thêm record vào CSDL"); return(View(model)); } return(RedirectToAction(nameof(LichSuChamCongList), new { employeeId = model.MaNhanVien })); } catch (Exception ex) { model.NhanVien = mapper.Map <EmployeeVM>(await userManager.FindByIdAsync(model.MaNhanVien)); ModelState.AddModelError("", "Lỗi xảy ra khi cập nhật CSDL"); return(View(model)); } }