public ViewResult Calender(int?TimekeepingListId, int BranchId) { //var user = userRepository.GetUserById(WebSecurity.CurrentUserId); //List<string> ListBranchId = new List<string>(); //var Branch_id = 0; //if (!string.IsNullOrEmpty(BranchId)) //{ // ListBranchId = BranchId.Split(',').ToList(); // Branch_id = Convert.ToInt32(ListBranchId.FirstOrDefault().ToString()); //} var timekeepingList = timekeepingListRepository.GetTimekeepingListById(TimekeepingListId.Value); DateTime aDateTime = new DateTime(); aDateTime = new DateTime(timekeepingList.Year.Value, timekeepingList.Month.Value, 1); var dataChamCong = Erp.Domain.Helper.SqlHelper.QuerySP <WorkSchedulesViewModel>("spDanhSachChamCong", new { TimekeepingListId = TimekeepingListId, BranchId = BranchId }).ToList(); var dataNhanVien = Erp.Domain.Helper.SqlHelper.QuerySP <WorkSchedulesViewModel>("spDanhSachNhanVienChamCong", new { TimekeepingListId = TimekeepingListId, BranchId = BranchId }).ToList(); var resource = dataNhanVien.Select(e => new { id = e.StaffId, title = e.Name, branch_id = e.BranchName }).ToList(); var dataEvent = dataChamCong.Select(e => new { id = e.Id, resourceId = e.StaffId, title = e.DayOffCode, start = (e.HoursIn == null ? Convert.ToDateTime(e.Day.Value.ToString("dd/MM/yyyy") + " " + e.StartTime).ToString("yyyy-MM-ddTHH:mm:ssZ") : e.HoursIn.Value.ToString("yyyy-MM-ddTHH:mm:ssZ")), end = (e.HoursOut == null ? Convert.ToDateTime(e.Day.Value.ToString("dd/MM/yyyy") + " " + e.EndTime).ToString("yyyy-MM-ddTHH:mm:ssZ") : e.HoursOut.Value.ToString("yyyy-MM-ddTHH:mm:ssZ")), //allDay = false, className = (e.Color), url = e.Id, backgroundColor = e.Color, tooltip = e.DayOffName }).ToList(); ViewBag.dataEvent = new JavaScriptSerializer().Serialize(dataEvent); ViewBag.resource = new JavaScriptSerializer().Serialize(resource); ViewBag.aDateTime = aDateTime.ToString("yyyy-MM-dd"); return(View()); }
public ActionResult Assign(FormCollection fc) { var model = new TimekeepingListViewModel(); var Id = Request["timekeepingListId"]; var timekeepingList = timekeepingListRepository.GetTimekeepingListById(Convert.ToInt32(Id)); var holiday = holidayRepository.GetAllHolidays().AsEnumerable().ToList(); var staff = StaffsRepository.GetvwAllStaffs().Where(x => x.BranchDepartmentId == timekeepingList.DepartmentId); ViewBag.staffList = staff; ViewBag.DayHoliday = holiday; DateTime aDateTime = new DateTime(timekeepingList.Year.Value, timekeepingList.Month.Value, 1); // Cộng thêm 1 tháng và trừ đi một ngày. DateTime retDateTime = aDateTime.AddMonths(1).AddDays(-1); ViewBag.aDateTime = aDateTime; ViewBag.retDateTime = retDateTime; var DayOff = categoryRepository.GetCategoryByCode("DayOffDefault").Where(x => x.Value == "True").AsEnumerable().ToList(); ViewBag.DayOff = DayOff; var ShiftsList = shiftsRepository.GetAllShifts().Where(x => x.CategoryShifts == timekeepingList.CategoryShifts).AsEnumerable(); ViewBag.ShiftsList = ShiftsList; var user = userRepository.GetUserById(WebSecurity.CurrentUserId); List <string> listIdShifts = new List <string>(); if (Request["shifts_id"] != null) { listIdShifts = Request["shifts_id"].Split(',').ToList(); } List <string> ListWorkSchedules = new List <string>(); foreach (var item in staff) { List <string> listIdCurrent = WorkSchedulesRepository.GetAllWorkSchedules().AsEnumerable().Where(x => aDateTime <= x.Day && x.Day <= retDateTime && x.ShiftsId != null && x.StaffId == item.Id).Select(x => x.ShiftsId.ToString().Replace(x.ShiftsId.ToString(), x.StaffId + "-" + x.Day.Value.ToString("dd/MM/yyyy") + "-" + x.ShiftsId)).ToList(); ListWorkSchedules = ListWorkSchedules.Union(listIdCurrent).ToList(); } // query id new to insert (not in database) List <string> listIdNew = listIdShifts.Where(id1 => !ListWorkSchedules.Any(id2 => id2 == id1)).ToList(); //query id to delete not listIdFromRequest List <string> listIdToDelete = ListWorkSchedules.Where(id1 => !listIdShifts.Any(id2 => id2 == id1)).ToList(); foreach (var id in listIdNew) { var item = new WorkSchedules(); item.CreatedUserId = WebSecurity.CurrentUserId; item.ModifiedUserId = WebSecurity.CurrentUserId; item.CreatedDate = DateTime.Now; item.ModifiedDate = DateTime.Now; item.IsDeleted = false; string[] arrVal = id.Split('-'); item.StaffId = int.Parse(arrVal[0], CultureInfo.InstalledUICulture); item.Day = DateTime.ParseExact(arrVal[1], "dd/MM/yyyy", CultureInfo.InvariantCulture); item.ShiftsId = int.Parse(arrVal[2], CultureInfo.InvariantCulture); item.TimekeepingListId = Convert.ToInt32(Id); WorkSchedulesRepository.InsertWorkSchedules(item); } foreach (var id in listIdToDelete) { string[] arrVal = id.Split('-'); int StaffId = int.Parse(arrVal[0], CultureInfo.InstalledUICulture); string Day = arrVal[1]; int ShiftsId = int.Parse(arrVal[2], CultureInfo.InvariantCulture); WorkSchedulesRepository.Delete(Day, StaffId, ShiftsId); } timekeepingList.Status = "timekeeping"; timekeepingListRepository.UpdateTimekeepingList(timekeepingList); // TempData[Globals.SuccessMessageKey] = "Lưu phân công ca làm việc thành công"; return(RedirectToAction("Detail", "TimekeepingList", new { area = "Staff", Id = Convert.ToInt32(Id) })); }
public ActionResult Edit(TimekeepingListViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var TimekeepingList = TimekeepingListRepository.GetTimekeepingListById(model.Id); //nếu danh sách chấm công sửa từ part-time sang full-time thì tự động phân công ca làm việc. if (TimekeepingList.CategoryShifts == "Part-time" && model.CategoryShifts == "Full-time") { //nếu danh sách khởi tạo chấm công là Toàn thời gian thì tự động tạo phân công cho tất cả nhân viên trong phòng ban if (model.CategoryShifts == "Full-time") { //chuẩn bị dữ liệu ngày nghỉ để duyệt ngày nghỉ thì không phân công. var DayOff = categoryRepository.GetCategoryByCode("DayOffDefault").Where(x => x.Value == "True").AsEnumerable().ToList(); //lấy ca làm việc toàn thời gian ra. var shift = shiftsRepository.GetAllShifts().Where(x => x.CategoryShifts == "Full-time").OrderByDescending(x => x.CreatedDate).FirstOrDefault(); //lấy danh sách nhân viên của phòng ban để phân công. var staff = StaffsRepository.GetAllStaffs().Where(x => x.BranchDepartmentId == TimekeepingList.DepartmentId).ToList(); //dựa vào tháng năm của danh sách khởi tạo ở trên, tạo ra list ngày trong tháng. DateTime aDateTime = new DateTime(TimekeepingList.Year.Value, TimekeepingList.Month.Value, 1); // Cộng thêm 1 tháng và trừ đi một ngày. DateTime retDateTime = aDateTime.AddMonths(1).AddDays(-1); //phần duyệt ngày trong tháng để thêm phân công cho từng nhân viên. for (DateTime dt = aDateTime; dt <= retDateTime; dt = dt.AddDays(1)) { if (DayOff.Where(x => Convert.ToInt32(x.OrderNo) == (int)dt.DayOfWeek && x.Value == "True").Count() <= 0) { foreach (var i in staff) { var item = new WorkSchedules(); item.CreatedUserId = WebSecurity.CurrentUserId; item.ModifiedUserId = WebSecurity.CurrentUserId; item.CreatedDate = DateTime.Now; item.ModifiedDate = DateTime.Now; item.IsDeleted = false; item.StaffId = i.Id; item.Day = dt; item.ShiftsId = shift.Id; item.TimekeepingListId = TimekeepingList.Id; WorkSchedulesRepository.InsertWorkSchedules(item); } } } } } AutoMapper.Mapper.Map(model, TimekeepingList); TimekeepingList.ModifiedUserId = WebSecurity.CurrentUserId; TimekeepingList.ModifiedDate = DateTime.Now; //if (model.CategoryShifts == "Full-time") //{ // TimekeepingList.Status = "assigned"; //} var department = departmentRepository.GetvwBranchDepartmentById(model.DepartmentId.Value); TimekeepingList.Name = "Danh sách chấm công tháng " + model.Month + " năm " + model.Year + " - " + department.Staff_DepartmentId + " - " + department.BranchName; TimekeepingListRepository.UpdateTimekeepingList(TimekeepingList); TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }