Ejemplo n.º 1
0
        public ActionResult Assign(int?Id)
        {
            var model           = new TimekeepingListViewModel();
            var timekeepingList = timekeepingListRepository.GetvwTimekeepingListById(Id.Value);

            AutoMapper.Mapper.Map(timekeepingList, model);
            var user    = userRepository.GetUserById(WebSecurity.CurrentUserId);
            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").AsEnumerable().ToList();

            ViewBag.DayOff = DayOff;
            var ShiftsList = shiftsRepository.GetAllShifts().Where(x => x.CategoryShifts == timekeepingList.CategoryShifts).AsEnumerable();

            ViewBag.ShiftsList = ShiftsList;
            return(View(model));
        }
Ejemplo n.º 2
0
        public ViewResult Index(string txtSearch)
        {
            IQueryable <ShiftsViewModel> q = ShiftsRepository.GetAllShifts()
                                             .Select(item => new ShiftsViewModel
            {
                Id            = item.Id,
                CreatedUserId = item.CreatedUserId,
                //CreatedUserName = item.CreatedUserName,
                CreatedDate    = item.CreatedDate,
                ModifiedUserId = item.ModifiedUserId,
                //ModifiedUserName = item.ModifiedUserName,
                ModifiedDate   = item.ModifiedDate,
                Name           = item.Name,
                StartTime      = item.StartTime,
                EndTime        = item.EndTime,
                Code           = item.Code,
                NightShifts    = item.NightShifts,
                EndTimeIn      = item.EndTimeIn,
                StartTimeOut   = item.StartTimeOut,
                CategoryShifts = item.CategoryShifts,
                EndTimeOut     = item.EndTimeOut,
                StartTimeIn    = item.StartTimeIn,
                MinuteEarly    = item.MinuteEarly,
                MinuteLate     = item.MinuteLate
            }).OrderByDescending(m => m.ModifiedDate);

            ViewBag.SuccessMessage = TempData["SuccessMessage"];
            ViewBag.FailedMessage  = TempData["FailedMessage"];
            ViewBag.AlertMessage   = TempData["AlertMessage"];
            return(View(q));
        }
Ejemplo n.º 3
0
        public ActionResult Create(TimekeepingListViewModel model)
        {
            if (ModelState.IsValid)
            {
                var TimekeepingList = new TimekeepingList();
                AutoMapper.Mapper.Map(model, TimekeepingList);
                TimekeepingList.IsDeleted      = false;
                TimekeepingList.CreatedUserId  = WebSecurity.CurrentUserId;
                TimekeepingList.ModifiedUserId = WebSecurity.CurrentUserId;
                TimekeepingList.AssignedUserId = WebSecurity.CurrentUserId;
                TimekeepingList.CreatedDate    = DateTime.Now;
                TimekeepingList.ModifiedDate   = DateTime.Now;
                TimekeepingList.CheckSalary    = false;
                if (model.Sale_BranchId != null)
                {
                    if (model.DepartmentId != null)
                    {
                        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;
                    }
                    else
                    {
                        var branch = branchRepository.GetBranchById(model.Sale_BranchId.Value);
                        TimekeepingList.Name = "Danh sách chấm công tháng " + model.Month + " năm " + model.Year + " - " + branch.Name;
                    }
                }
                else
                {
                    TimekeepingList.Name = "Danh sách chấm công tháng " + model.Month + " năm " + model.Year + " - Tất cả chi nhánh";
                }

                //mặc định khởi tạo danh sách thì trạng thái là pending... nếu có thêm phân công tự động thì là assigned
                if (model.CategoryShifts == "Full-time")
                {
                    TimekeepingList.Status = "timekeeping";
                }
                else
                {
                    TimekeepingList.Status = "assign";
                }
                TimekeepingListRepository.InsertTimekeepingList(TimekeepingList);
                var prefix2 = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_timekeepingList");
                TimekeepingList.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix2, TimekeepingList.Id);
                TimekeepingListRepository.UpdateTimekeepingList(TimekeepingList);
                //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.
                    List <vwStaffs> list_staff_insert = new List <vwStaffs>();
                    var             staff             = StaffsRepository.GetvwAllStaffs().Where(x => !string.IsNullOrEmpty(x.BranchName) && x.IsWorking == true);
                    if (model.Sale_BranchId != null)
                    {
                        if (model.DepartmentId != null)
                        {
                            list_staff_insert = staff.Where(x => x.BranchDepartmentId == model.DepartmentId).ToList();
                        }
                        else
                        {
                            list_staff_insert = staff.Where(x => x.Sale_BranchId == model.Sale_BranchId).ToList();
                        }
                    }
                    else
                    {
                        list_staff_insert = staff.OrderBy(x => x.Id).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 list_staff_insert)
                            {
                                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);
                            }
                        }
                    }
                }
                //TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("Detail", "TimekeepingList", new { area = "Staff", Id = TimekeepingList.Id }));
            }
            return(View(model));
        }