public ActionResult AddWorkSchedules(int?shifts, string DayWork, int?StaffId)
        {
            var workSchedules            = WorkSchedulesRepository.GetAllWorkSchedules().AsEnumerable().Where(x => x.ShiftsId == shifts && x.Day.Value == Convert.ToDateTime(DayWork) && x.StaffId == StaffId);
            vwTimekeepingViewModel model = new vwTimekeepingViewModel();
            WorkSchedules          work  = new WorkSchedules();

            if (workSchedules.Count() <= 0)
            {
                work.IsDeleted    = false;
                work.CreatedDate  = DateTime.Now;
                work.ModifiedDate = DateTime.Now;
                work.StaffId      = StaffId;
                work.ShiftsId     = shifts;
                work.Day          = Convert.ToDateTime(DayWork);
                WorkSchedulesRepository.InsertWorkSchedules(work);
                var q = timekeepingRepository.GetvwTimekeepingByWorkSchedulesId(work.Id);
                AutoMapper.Mapper.Map(q, model);
            }
            else
            {
                var q = timekeepingRepository.GetvwTimekeepingByWorkSchedulesId(workSchedules.FirstOrDefault().Id);
                AutoMapper.Mapper.Map(q, model);
            }

            if (string.IsNullOrEmpty(model.HoursIn.ToString()) && string.IsNullOrEmpty(model.HoursOut.ToString()))
            {
                var dayoff = dayoffRepository.GetAllvwDayOff().Where(x => x.StaffId == model.StaffId && x.DayStart <= model.DayWork && model.DayWork <= x.DayEnd);
                foreach (var i in dayoff)
                {
                    //model.Pay = i.Pay;
                    model.DayOff     = "P";
                    model.IdDayOff   = i.Id;
                    model.DayOffName = i.NameSymbol;
                    model.DayOffCode = i.CodeSymbol;
                }

                if (model.DayWork.Value.ToString("dd/MM/yyyy") == DateTime.Now.ToString("dd/MM/yyyy") && string.IsNullOrEmpty(model.DayOff))
                {
                    model.DayOff = "DL";
                    //  model.DayOffTooltip = "Đang làm";
                }
                if (model.DayWork < DateTime.Now && string.IsNullOrEmpty(model.DayOff))
                {
                    model.DayOff = "KP";
                    // model.DayOffTooltip = "Nghỉ không phép";
                }
                if (model.DayWork > DateTime.Now && string.IsNullOrEmpty(model.DayOff))
                {
                    model.DayOff = "CL";
                    //  model.DayOffTooltip = "Chưa làm";
                }
            }

            return(View(model));
        }
Exemple #2
0
        public ViewResult Index(string Name, string Code, int?TypeDayOff, int?branchId, int?DepartmentId, string start_date, string end_date)
        {
            var user = userRepository.GetUserById(WebSecurity.CurrentUserId);
            IEnumerable <DayOffViewModel> q = DayOffRepository.GetAllvwDayOff()
                                              .Select(item => new DayOffViewModel
            {
                Id            = item.Id,
                CreatedUserId = item.CreatedUserId,
                //CreatedUserName = item.CreatedUserName,
                CreatedDate    = item.CreatedDate,
                ModifiedUserId = item.ModifiedUserId,
                //ModifiedUserName = item.ModifiedUserName,
                ModifiedDate       = item.ModifiedDate,
                DayEnd             = item.DayEnd,
                DayStart           = item.DayStart,
                Quantity           = item.Quantity,
                QuantityNotUsed    = item.QuantityNotUsed,
                StaffId            = item.StaffId,
                TypeDayOffId       = item.TypeDayOffId,
                NameSymbol         = item.NameSymbol,
                BranchName         = item.BranchName,
                DepartmentName     = item.DepartmentName,
                CodeStaff          = item.CodeStaff,
                NameStaff          = item.NameStaff,
                TypeDayOffQuantity = item.TypeDayOffQuantity,
                Code               = item.Code,
                ProfileImage       = item.ProfileImage,
                CodeSymbol         = item.CodeSymbol,
                BranchDepartmentId = item.BranchDepartmentId,
                Sale_BranchId      = item.Sale_BranchId
            });

            if (!string.IsNullOrEmpty(Code))
            {
                q = q.Where(item => Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(item.CodeStaff).ToLower().Contains(Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(Code).ToLower()));
            }

            if (!string.IsNullOrEmpty(Name))
            {
                q = q.Where(item => Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(item.NameStaff).ToLower().Contains(Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(Name).ToLower()));
            }
            if (TypeDayOff != null && TypeDayOff.Value > 0)
            {
                q = q.Where(item => item.TypeDayOffId == TypeDayOff);
            }
            if (branchId != null && branchId.Value > 0)
            {
                q = q.Where(item => item.Sale_BranchId == branchId);
            }
            if (DepartmentId != null && DepartmentId.Value > 0)
            {
                q = q.Where(item => item.BranchDepartmentId == DepartmentId);
            }
            if (!string.IsNullOrEmpty(start_date) && !string.IsNullOrEmpty(end_date))
            {
                DateTime start_d;
                if (DateTime.TryParseExact(start_date, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out start_d))
                {
                    DateTime end_d;
                    if (DateTime.TryParseExact(end_date, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out end_d))
                    {
                        end_d = end_d.AddHours(23);
                        q     = q.Where(x => start_d <= x.DayStart && x.DayEnd <= end_d);
                    }
                }
            }
            if (user.UserTypeId == 1)
            {
                q = q.OrderByDescending(m => m.CreatedDate);
            }
            else
            {
                q = q.Where(x => x.Sale_BranchId == user.BranchId).OrderByDescending(m => m.CreatedDate);
            }
            return(View(q));
        }