Esempio n. 1
0
        /// <summary>
        /// [Hien.Nguyen] - Chức năng tính tăng ca - màng hình Phân Tích Tăng Ca
        /// </summary>
        /// <param name="lstOvertimeEntity"></param>
        public void CalAllowOvertime(List<Att_OvertimeEntity> lstOvertime, string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_workday = new CustomBaseRepository<Att_Workday>(unitOfWork);
                var repoAtt_NoneOvertime = new CustomBaseRepository<Att_NonOverTime>(unitOfWork);
                if (lstOvertime.Count == 0 || lstOvertime.Where(m => m.WorkDateRoot != null).Count() == 0)
                {
                    return;
                }

                DateTime minDate = lstOvertime.Min(m => m.WorkDateRoot.Value);
                DateTime maxDate = lstOvertime.Max(m => m.WorkDateRoot.Value);
                List<Guid> lstProfileID = lstOvertime.Select(m => m.ProfileID).Distinct().ToList();

                List<ProfileDateTime> lstWorkdayCanBeOT = new List<ProfileDateTime>();

                foreach (var item in lstOvertime)
                {
                    if (item.WorkDateRoot == null)
                        continue;
                    if (item.IsNonOvertime == null)
                        continue;

                    ProfileDateTime workdayNotOt = new ProfileDateTime();
                    workdayNotOt.ProfileID = item.ProfileID;
                    workdayNotOt.WorkDate = item.WorkDateRoot.Value;
                    lstWorkdayCanBeOT.Add(workdayNotOt);
                }



                List<Att_OvertimeEntity> lstOvertimeInCache = lstOvertimeCache;
                List<Att_OvertimeEntity> lstOvertimeInCache_Profile = lstOvertimeInCache.Where(m => lstProfileID.Contains(m.ProfileID)).ToList();

                var _tmp = lstOvertimeInCache_Profile;
                for (int i = 0; i < _tmp.Count(); i++)
                    lstOvertimeInCache.Remove(lstOvertimeInCache_Profile[i]);

                List<Att_OvertimeEntity> lstOvertimeNonBe_Delete = new List<Att_OvertimeEntity>();
                foreach (var item in lstOvertimeInCache_Profile)
                {
                    if (lstWorkdayCanBeOT.Any(m => m.ProfileID == item.ProfileID && m.WorkDate == item.WorkDateRoot))
                    {
                        item.IsNonOvertime = null;
                        lstOvertimeNonBe_Delete.Add(item);
                    }
                }
                //Để tính lại lũy kế sau khi xong
                OvertimePermitEntity overtimePermit = getOvertimePermit(userLogin);
                //List<Att_WorkdayEntity> lstWorkday = repoAtt_workday.FindBy(m => m.WorkDate >= minDate && m.WorkDate <= maxDate && lstProfileID.Contains(m.ProfileID)).ToList().Translate<Att_WorkdayEntity>();
                List<WorkdayCustom> lstWorkday = new List<WorkdayCustom>();
                if (lstProfileID.Count < 2000)
                {
                    lstWorkday = repoAtt_workday
                        .FindBy(m => m.IsDelete == null && m.WorkDate >= minDate && m.WorkDate <= maxDate && lstProfileID.Contains(m.ProfileID))
                        .Select(m => new WorkdayCustom() { ID = m.ID, ProfileID = m.ProfileID, ShiftID = m.ShiftID, ShiftApprove = m.ShiftApprove, WorkDate = m.WorkDate, Status = m.Status, InTime1 = m.InTime1, InTime2 = m.InTime2, OutTime1 = m.OutTime1, OutTime2 = m.OutTime2 })
                        .ToList<WorkdayCustom>();
                }
                else
                {
                    lstWorkday = repoAtt_workday
                        .FindBy(m => m.IsDelete == null && m.WorkDate >= minDate && m.WorkDate <= maxDate)
                         .Select(m => new WorkdayCustom() { ID = m.ID, ProfileID = m.ProfileID, ShiftID = m.ShiftID, ShiftApprove = m.ShiftApprove, WorkDate = m.WorkDate, Status = m.Status, InTime1 = m.InTime1, InTime2 = m.InTime2, OutTime1 = m.OutTime1, OutTime2 = m.OutTime2 })
                         .ToList<WorkdayCustom>();
                }

                FillterAllowOvertime(context, lstOvertimeInCache_Profile, overtimePermit, lstWorkday);
                lstOvertimeInCache.AddRange(lstOvertimeInCache_Profile);
                lstOvertimeInCache = lstOvertimeInCache.OrderBy(m => m.WorkDate.Date).ThenBy(m => m.ProfileID).ToList();
                lstOvertimeCache = lstOvertimeInCache;

                //List<Att_NonOverTime> LstNonOTSelect = repoAtt_NoneOvertime.FindBy(m => m.WorkDay >= minDate && m.WorkDay <= maxDate && lstProfileID.Contains(m.ProfileID.Value)).ToList<Att_NonOverTime>();
                List<Att_NonOverTime> LstNonOTSelect = new List<Att_NonOverTime>();
                if (lstProfileID.Count < 2000)
                {
                    LstNonOTSelect = repoAtt_workday
                        .FindBy(m => m.IsDelete == null && m.WorkDate >= minDate && m.WorkDate <= maxDate && lstProfileID.Contains(m.ProfileID)).ToList().Translate<Att_NonOverTime>();
                }
                else
                {
                    LstNonOTSelect = repoAtt_workday
                        .FindBy(m => m.IsDelete == null && m.WorkDate >= minDate && m.WorkDate <= maxDate).ToList().Translate<Att_NonOverTime>();
                }

                foreach (var item in lstOvertimeNonBe_Delete)
                {
                    Att_NonOverTime NonOT = LstNonOTSelect.Where(m => m.ProfileID == item.ProfileID && m.OvertimeTypeID == item.OvertimeTypeID && m.WorkDay == item.WorkDateRoot && m.Type == item.udTypeBeginOTWithShift).FirstOrDefault();
                    if (NonOT != null)
                    {
                        NonOT.IsDelete = true;
                    }
                }
                if (LstNonOTSelect.Count > 0)
                {
                    repoAtt_NoneOvertime.Edit(LstNonOTSelect);
                    unitOfWork.SaveChanges();
                }
                //BindToGrid(lstOvertimeCache);
            }
        }
Esempio n. 2
0
        private string ValidateOT_DoNotAllow(List<Att_OvertimeEntity> lstOvertime, List<Hre_ProfileEntity> lstHre_Profile)
        {

            string result = string.Empty;
            List<Att_OvertimeEntity> lstOvertimeCanNot = lstOvertime.Where(m => m.IsNonOvertime == true).ToList();
            List<Guid> lstProfileID = lstOvertimeCanNot.Select(m => m.ProfileID).Distinct().ToList();
            var lstProfile = lstHre_Profile.Where(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.ProfileName, m.CodeEmp });

            List<ProfileDateTime> lstProfileAlready = new List<ProfileDateTime>();


            foreach (var item in lstOvertimeCanNot)
            {
                if (lstProfileAlready.Any(m => m.ProfileID == item.ProfileID && m.WorkDate == item.WorkDateRoot))
                {
                    continue;
                }
                else
                {
                    var Profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault();
                    result += Profile.ProfileName + "[" + Profile.CodeEmp + "] - " + item.WorkDateRoot.Value.ToShortDateString() + "; ";

                    ProfileDateTime ProfileAlready = new ProfileDateTime();
                    ProfileAlready.ProfileID = item.ProfileID;
                    ProfileAlready.WorkDate = item.WorkDateRoot.Value;
                    lstProfileAlready.Add(ProfileAlready);
                }
            }

            if (result != string.Empty)
            {
                result = result.Substring(0, result.Length - 2);
                //result = string.Format(Messages.EmpDoNotRegisterOvertime.TranslateString(), result);
            }
            return result;
        }