public void AnalyzeCompensation(int Year, List<Guid> lstProfileIDTotal)
        {
            //Lấy cấu hình
            //lấy ngày nghỉ (Bù)
            //Lấy tăng ca (Bù)
            //Lấy Ca Làm Việc (Bù)
            //Hệ Số Tăng Ca (Loại Tăng Ca)
            foreach (var lstProfileID in lstProfileIDTotal.Chunk(500))
            {
                using (var context = new VnrHrmDataContext())
                {
                    #region Khai báo
                    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                    var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                    var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork);
                    var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                    var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                    var repoAtt_Roster = new Att_RosterRepository(unitOfWork);
                    var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork);
                    var repoAtt_CompensationConfig = new Att_CompensationConfigRepository(unitOfWork);
                    var repoAtt_CompensationDetail = new Att_CompensationDetailRepository(unitOfWork);


                    #endregion
                    #region Lấy Dữ Liệu
                    //   var profileByCodeEmp = repoHre_Profile.FindBy(p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault();

                    var lstProfile = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.DateHire }).ToList();
                    var lstCompensationConfig = repoAtt_CompensationConfig
                        .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value))
                        .Select(m => new CompensationConfigModel() { ID = m.ID, ProfileID = m.ProfileID, Year = m.Year, InitAvailable = m.InitAvailable, MonthBeginInYear = m.MonthBeginInYear, MonthResetInitAvailable = m.MonthResetInitAvailable, MonthStartProfile = m.MonthStartProfile })
                        .ToList();
                    int MonthBeginYear = 1;
                    if (lstCompensationConfig != null && lstCompensationConfig.Count>0)
                    {
                        MonthBeginYear = lstCompensationConfig.FirstOrDefault().MonthBeginInYear ?? 1;
                    }
                    DateTime BeginYear = new DateTime(Year, MonthBeginYear, 1);
                    DateTime EndYear = BeginYear.AddYears(1).AddMinutes(-1);
                    string E_APPROVED_Leave = LeaveDayStatus.E_APPROVED.ToString();
                    var lstLeaveDayCompensationTypeID = repoCat_LeaveDayType
                        .FindBy(m => m.IsTimeOffInLieu == true)
                        .Select(m => m.ID)
                        .ToList();
                    var lstLeaveday = repoAtt_Leaveday
                       .FindBy(m => m.Status == E_APPROVED_Leave && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstLeaveDayCompensationTypeID.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID))
                       .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.DurationType })
                       .ToList();

                    string E_TIMEOFF = MethodOption.E_TIMEOFF.ToString();
                    string E_APPROVED_Overtime = OverTimeStatus.E_APPROVED.ToString();
                    string E_CONFIRM_Overtime = OverTimeStatus.E_CONFIRM.ToString();
                    var lstOvertime = repoAtt_Overtime
                        .FindBy(m => m.WorkDateRoot >= BeginYear && m.WorkDateRoot <= EndYear && m.MethodPayment == E_TIMEOFF && (m.Status == E_APPROVED_Overtime || m.Status == E_CONFIRM_Overtime) && lstProfileID.Contains(m.ProfileID))
                        .Select(m => new { m.ID, m.ProfileID, m.WorkDateRoot, m.ApproveHours, m.ConfirmHours, m.Status }).ToList();

                    string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString();
                    var lstRoster = repoAtt_Roster
                       .FindBy(m => m.Status == E_APPROVED_Roster && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstProfileID.Contains(m.ProfileID))
                       .Select(m => new RosterModel
                       {
                           ID = m.ID,
                           ProfileID = m.ProfileID,
                           DateStart = m.DateStart,
                           DateEnd = m.DateEnd,
                           Type = m.Type,
                           MonShiftID = m.MonShiftID,
                           TueShiftID = m.TueShiftID,
                           WedShiftID = m.WedShiftID,
                           ThuShiftID = m.ThuShiftID,
                           FriShiftID = m.FriShiftID,
                           SatShiftID = m.SatShiftID,
                           SunShiftID = m.SunShiftID
                       })
                       .ToList();

                    var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours, m.StdWorkHours }).ToList();


                    List<Att_CompensationDetail> detailInDB = repoAtt_CompensationDetail
                        .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value))
                        .ToList();
                    List<Att_CompensationDetail> detailNew = new List<Att_CompensationDetail>();

                    foreach (var ProfileID in lstProfileID)
                    {
                        double TotalLeaveHourBeforeMonth = 0;
                        double TotalOvertimeHourBeforeMonth = 0;
                        var Profile = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault();
                        int MonthHire = 1;
                        if (Profile.DateHire != null && Profile.DateHire >= BeginYear && Profile.DateHire <= EndYear)
                        {
                            if (Profile.DateHire.Value.Day >= 15)
                            {
                                MonthHire = Profile.DateHire.Value.AddMonths(1).Month;
                            }
                            else
                            {
                                MonthHire = Profile.DateHire.Value.Month;
                            }
                        }
                        for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1))
                        {
                            if (MonthHire > Month.Month)
                                continue;

                            DateTime BeginMonth = Month;
                            DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1);

                            double TotalLeaveHourInMonth = 0;
                            double TotalOvertimeHourInMonth = 0;
                            #region Tăng Ca
                            var lstOvertimeByProfileByMonth = lstOvertime.Where(m => m.ProfileID == ProfileID && m.WorkDateRoot >= BeginMonth && m.WorkDateRoot <= EndMonth).ToList();
                            TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_CONFIRM_Overtime).Sum(m => m.ConfirmHours);
                            TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_APPROVED_Overtime).Sum(m => m.ApproveHours ?? 0);
                            #endregion
                            #region Ngày Nghỉ
                            var lstLeavedayByProfileByMonth = lstLeaveday.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList();
                            var lstRosterByProfileByMonth = lstRoster.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList();
                            foreach (var Leaveday in lstLeavedayByProfileByMonth)
                            {
                                DateTime dateStart = Leaveday.DateStart < BeginMonth ? BeginMonth : Leaveday.DateStart;
                                DateTime dateEnd = Leaveday.DateEnd > EndMonth ? EndMonth : Leaveday.DateEnd;
                                for (DateTime dateCheck = dateStart; dateCheck <= dateEnd; dateCheck = dateCheck.AddDays(1))
                                {
                                    if (Leaveday.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) // Trong Ca
                                    {
                                        TotalLeaveHourInMonth += Leaveday.LeaveHours ?? 0;
                                    }
                                    else //Toàn Ca
                                    {
                                        //Check xem có Ca làm việc không
                                        Guid? ShiftID = null;
                                        var E_TIME_OFF = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_TIME_OFF.ToString()).FirstOrDefault();
                                        var E_CHANGE_SHIFT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_CHANGE_SHIFT.ToString()).FirstOrDefault();
                                        var E_DEFAULT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_DEFAULT.ToString()).FirstOrDefault();
                                        var E_ROSTERGROUP = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_ROSTERGROUP.ToString()).FirstOrDefault();
                                        if (E_TIME_OFF != null)
                                        {
                                        }
                                        else if (E_CHANGE_SHIFT != null)
                                        {
                                            ShiftID = GetShiftRoster(dateCheck, E_CHANGE_SHIFT);
                                        }
                                        else if (E_DEFAULT != null)
                                        {
                                            ShiftID = GetShiftRoster(dateCheck, E_DEFAULT);
                                        }
                                        else if (E_ROSTERGROUP != null)
                                        {
                                            //Chưa hỗ trợ đăng ký ca theo nhóm
                                        }

                                        if (ShiftID != null)
                                        {
                                            var Shift = lstShift.Where(m => m.ID == ShiftID.Value).FirstOrDefault();
                                            if (Shift != null)
                                            {
                                                TotalLeaveHourInMonth += Shift.StdWorkHours ?? (Shift.WorkHours ?? 0);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                            #region Gán Dữ Liệu
                            CompensationConfigModel Config = lstCompensationConfig.Where(m => m.ProfileID == ProfileID).FirstOrDefault();
                            Att_CompensationDetail detail = detailInDB.Where(m => m.MonthYear == Month && m.ProfileID == ProfileID).FirstOrDefault();
                            if (detail == null)
                            {
                                detail = new Att_CompensationDetail();
                                detail.ID = Guid.NewGuid();
                                detailNew.Add(detail);
                            }

                            if (Config != null)
                            {
                                if (Config.MonthResetInitAvailable != null && Config.MonthResetInitAvailable.Value <= Month.Month)
                                {
                                }
                                else
                                {
                                    detail.InitAvailable = Config.InitAvailable;
                                }
                                detail.MonthBeginInYear = Config.MonthBeginInYear ?? 1;
                                detail.MonthResetInitAvailable = Config.MonthResetInitAvailable;

                            }
                            detail.ProfileID = ProfileID;
                            detail.Year = Year;
                            detail.MonthYear = Month;
                            detail.MonthStartProfile = MonthHire;
                            detail.LeaveInMonth = TotalLeaveHourInMonth;
                            detail.TotalLeaveBef = TotalLeaveHourBeforeMonth;
                            detail.OvertimeInMonth = TotalOvertimeHourInMonth;
                            detail.TotalOvertimeBef = TotalOvertimeHourBeforeMonth;
                            detail.Remain = ((detail.InitAvailable ?? 0) + TotalOvertimeHourBeforeMonth + TotalOvertimeHourInMonth) - (TotalLeaveHourBeforeMonth + TotalLeaveHourInMonth);

                            TotalOvertimeHourBeforeMonth += TotalOvertimeHourInMonth;
                            TotalLeaveHourBeforeMonth += TotalLeaveHourInMonth;
                            #endregion
                        }
                    }
                    repoAtt_CompensationDetail.Add(detailNew);
                    repoAtt_CompensationDetail.SaveChanges();
                    #endregion
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Lưu xác nhận tăng ca
 /// </summary>
 /// <param name="cat"></param>
 /// <returns></returns>
 public string SaveOvertimeConfirm(IEnumerable<Att_OvertimeEntity> listOT)
 {
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Att_OvertimeRepository(unitOfWork);
         try
         {
             foreach (var item in listOT)
             {
                 repo.SaveOvertimeConfirm(item.ID, item.ConfirmHours);
             }
             repo.SaveChanges();
             return "0";
         }
         catch (Exception ex)
         {
             return ex.Message;
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// chuyển thành trạng thái Sumit
 /// </summary>
 /// <returns></returns>
 public void SubmitOvertime(List<Guid> ids)
 {
     using (var context = new VnrHrmDataContext())
     {
         var lstWorkday = new List<Att_OvertimeEntity>();
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Att_OvertimeRepository(unitOfWork);
         lstWorkday = repo.FindBy(m => ids.Contains(m.ID)).ToList().Translate<Att_OvertimeEntity>();
         foreach (var workday in lstWorkday)
         {
             workday.Status = AttendanceDataStatus.E_SUBMIT.ToString();
             repo.SaveChanges();
         }
     }
 }
Beispiel #4
0
        public void AnalyzeCompensation(int Year, List <Guid> lstProfileIDTotal)
        {
            //Lấy cấu hình
            //lấy ngày nghỉ (Bù)
            //Lấy tăng ca (Bù)
            //Lấy Ca Làm Việc (Bù)
            //Hệ Số Tăng Ca (Loại Tăng Ca)
            foreach (var lstProfileID in lstProfileIDTotal.Chunk(500))
            {
                using (var context = new VnrHrmDataContext())
                {
                    #region Khai báo
                    var unitOfWork                 = (IUnitOfWork)(new UnitOfWork(context));
                    var repoHre_Profile            = new Hre_ProfileRepository(unitOfWork);
                    var repoAtt_Leaveday           = new Att_LeavedayRepository(unitOfWork);
                    var repoCat_LeaveDayType       = new Cat_LeaveDayTypeRepository(unitOfWork);
                    var repoCat_Shift              = new Cat_ShiftRepository(unitOfWork);
                    var repoAtt_Roster             = new Att_RosterRepository(unitOfWork);
                    var repoAtt_Overtime           = new Att_OvertimeRepository(unitOfWork);
                    var repoAtt_CompensationConfig = new Att_CompensationConfigRepository(unitOfWork);
                    var repoAtt_CompensationDetail = new Att_CompensationDetailRepository(unitOfWork);


                    #endregion
                    #region Lấy Dữ Liệu
                    //   var profileByCodeEmp = repoHre_Profile.FindBy(p => p.IsDelete == null && p.CodeEmp == codeEmp).FirstOrDefault();

                    var lstProfile            = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.DateHire }).ToList();
                    var lstCompensationConfig = repoAtt_CompensationConfig
                                                .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value))
                                                .Select(m => new CompensationConfigModel()
                    {
                        ID = m.ID, ProfileID = m.ProfileID, Year = m.Year, InitAvailable = m.InitAvailable, MonthBeginInYear = m.MonthBeginInYear, MonthResetInitAvailable = m.MonthResetInitAvailable, MonthStartProfile = m.MonthStartProfile
                    })
                                                .ToList();
                    int MonthBeginYear = 1;
                    if (lstCompensationConfig != null && lstCompensationConfig.Count > 0)
                    {
                        MonthBeginYear = lstCompensationConfig.FirstOrDefault().MonthBeginInYear ?? 1;
                    }
                    DateTime BeginYear        = new DateTime(Year, MonthBeginYear, 1);
                    DateTime EndYear          = BeginYear.AddYears(1).AddMinutes(-1);
                    string   E_APPROVED_Leave = LeaveDayStatus.E_APPROVED.ToString();
                    var      lstLeaveDayCompensationTypeID = repoCat_LeaveDayType
                                                             .FindBy(m => m.IsTimeOffInLieu == true)
                                                             .Select(m => m.ID)
                                                             .ToList();
                    var lstLeaveday = repoAtt_Leaveday
                                      .FindBy(m => m.Status == E_APPROVED_Leave && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstLeaveDayCompensationTypeID.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID))
                                      .Select(m => new { m.ID, m.ProfileID, m.DateStart, m.DateEnd, m.LeaveHours, m.DurationType })
                                      .ToList();

                    string E_TIMEOFF           = MethodOption.E_TIMEOFF.ToString();
                    string E_APPROVED_Overtime = OverTimeStatus.E_APPROVED.ToString();
                    string E_CONFIRM_Overtime  = OverTimeStatus.E_CONFIRM.ToString();
                    var    lstOvertime         = repoAtt_Overtime
                                                 .FindBy(m => m.WorkDateRoot >= BeginYear && m.WorkDateRoot <= EndYear && m.MethodPayment == E_TIMEOFF && (m.Status == E_APPROVED_Overtime || m.Status == E_CONFIRM_Overtime) && lstProfileID.Contains(m.ProfileID))
                                                 .Select(m => new { m.ID, m.ProfileID, m.WorkDateRoot, m.ApproveHours, m.ConfirmHours, m.Status }).ToList();

                    string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString();
                    var    lstRoster         = repoAtt_Roster
                                               .FindBy(m => m.Status == E_APPROVED_Roster && m.DateStart <= EndYear && m.DateEnd >= BeginYear && lstProfileID.Contains(m.ProfileID))
                                               .Select(m => new RosterModel
                    {
                        ID         = m.ID,
                        ProfileID  = m.ProfileID,
                        DateStart  = m.DateStart,
                        DateEnd    = m.DateEnd,
                        Type       = m.Type,
                        MonShiftID = m.MonShiftID,
                        TueShiftID = m.TueShiftID,
                        WedShiftID = m.WedShiftID,
                        ThuShiftID = m.ThuShiftID,
                        FriShiftID = m.FriShiftID,
                        SatShiftID = m.SatShiftID,
                        SunShiftID = m.SunShiftID
                    })
                                               .ToList();

                    var lstShift = repoCat_Shift.GetAll().Select(m => new { m.ID, m.WorkHours, m.StdWorkHours }).ToList();


                    List <Att_CompensationDetail> detailInDB = repoAtt_CompensationDetail
                                                               .FindBy(m => m.Year == Year && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value))
                                                               .ToList();
                    List <Att_CompensationDetail> detailNew = new List <Att_CompensationDetail>();

                    foreach (var ProfileID in lstProfileID)
                    {
                        double TotalLeaveHourBeforeMonth    = 0;
                        double TotalOvertimeHourBeforeMonth = 0;
                        var    Profile   = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault();
                        int    MonthHire = 1;
                        if (Profile.DateHire != null && Profile.DateHire >= BeginYear && Profile.DateHire <= EndYear)
                        {
                            if (Profile.DateHire.Value.Day >= 15)
                            {
                                MonthHire = Profile.DateHire.Value.AddMonths(1).Month;
                            }
                            else
                            {
                                MonthHire = Profile.DateHire.Value.Month;
                            }
                        }
                        for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1))
                        {
                            if (MonthHire > Month.Month)
                            {
                                continue;
                            }

                            DateTime BeginMonth = Month;
                            DateTime EndMonth   = BeginMonth.AddMonths(1).AddMinutes(-1);

                            double TotalLeaveHourInMonth    = 0;
                            double TotalOvertimeHourInMonth = 0;
                            #region Tăng Ca
                            var lstOvertimeByProfileByMonth = lstOvertime.Where(m => m.ProfileID == ProfileID && m.WorkDateRoot >= BeginMonth && m.WorkDateRoot <= EndMonth).ToList();
                            TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_CONFIRM_Overtime).Sum(m => m.ConfirmHours);
                            TotalOvertimeHourInMonth += lstOvertimeByProfileByMonth.Where(m => m.Status == E_APPROVED_Overtime).Sum(m => m.ApproveHours ?? 0);
                            #endregion
                            #region Ngày Nghỉ
                            var lstLeavedayByProfileByMonth = lstLeaveday.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList();
                            var lstRosterByProfileByMonth   = lstRoster.Where(m => m.DateStart <= EndMonth && m.DateEnd >= BeginMonth && m.ProfileID == ProfileID).ToList();
                            foreach (var Leaveday in lstLeavedayByProfileByMonth)
                            {
                                DateTime dateStart = Leaveday.DateStart < BeginMonth ? BeginMonth : Leaveday.DateStart;
                                DateTime dateEnd   = Leaveday.DateEnd > EndMonth ? EndMonth : Leaveday.DateEnd;
                                for (DateTime dateCheck = dateStart; dateCheck <= dateEnd; dateCheck = dateCheck.AddDays(1))
                                {
                                    if (Leaveday.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()) // Trong Ca
                                    {
                                        TotalLeaveHourInMonth += Leaveday.LeaveHours ?? 0;
                                    }
                                    else //Toàn Ca
                                    {
                                        //Check xem có Ca làm việc không
                                        Guid?ShiftID        = null;
                                        var  E_TIME_OFF     = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_TIME_OFF.ToString()).FirstOrDefault();
                                        var  E_CHANGE_SHIFT = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_CHANGE_SHIFT.ToString()).FirstOrDefault();
                                        var  E_DEFAULT      = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_DEFAULT.ToString()).FirstOrDefault();
                                        var  E_ROSTERGROUP  = lstRosterByProfileByMonth.Where(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.Type == RosterType.E_ROSTERGROUP.ToString()).FirstOrDefault();
                                        if (E_TIME_OFF != null)
                                        {
                                        }
                                        else if (E_CHANGE_SHIFT != null)
                                        {
                                            ShiftID = GetShiftRoster(dateCheck, E_CHANGE_SHIFT);
                                        }
                                        else if (E_DEFAULT != null)
                                        {
                                            ShiftID = GetShiftRoster(dateCheck, E_DEFAULT);
                                        }
                                        else if (E_ROSTERGROUP != null)
                                        {
                                            //Chưa hỗ trợ đăng ký ca theo nhóm
                                        }

                                        if (ShiftID != null)
                                        {
                                            var Shift = lstShift.Where(m => m.ID == ShiftID.Value).FirstOrDefault();
                                            if (Shift != null)
                                            {
                                                TotalLeaveHourInMonth += Shift.StdWorkHours ?? (Shift.WorkHours ?? 0);
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                            #region Gán Dữ Liệu
                            CompensationConfigModel Config = lstCompensationConfig.Where(m => m.ProfileID == ProfileID).FirstOrDefault();
                            Att_CompensationDetail  detail = detailInDB.Where(m => m.MonthYear == Month && m.ProfileID == ProfileID).FirstOrDefault();
                            if (detail == null)
                            {
                                detail    = new Att_CompensationDetail();
                                detail.ID = Guid.NewGuid();
                                detailNew.Add(detail);
                            }

                            if (Config != null)
                            {
                                if (Config.MonthResetInitAvailable != null && Config.MonthResetInitAvailable.Value <= Month.Month)
                                {
                                }
                                else
                                {
                                    detail.InitAvailable = Config.InitAvailable;
                                }
                                detail.MonthBeginInYear        = Config.MonthBeginInYear ?? 1;
                                detail.MonthResetInitAvailable = Config.MonthResetInitAvailable;
                            }
                            detail.ProfileID         = ProfileID;
                            detail.Year              = Year;
                            detail.MonthYear         = Month;
                            detail.MonthStartProfile = MonthHire;
                            detail.LeaveInMonth      = TotalLeaveHourInMonth;
                            detail.TotalLeaveBef     = TotalLeaveHourBeforeMonth;
                            detail.OvertimeInMonth   = TotalOvertimeHourInMonth;
                            detail.TotalOvertimeBef  = TotalOvertimeHourBeforeMonth;
                            detail.Remain            = ((detail.InitAvailable ?? 0) + TotalOvertimeHourBeforeMonth + TotalOvertimeHourInMonth) - (TotalLeaveHourBeforeMonth + TotalLeaveHourInMonth);

                            TotalOvertimeHourBeforeMonth += TotalOvertimeHourInMonth;
                            TotalLeaveHourBeforeMonth    += TotalLeaveHourInMonth;
                            #endregion
                        }
                    }
                    repoAtt_CompensationDetail.Add(detailNew);
                    repoAtt_CompensationDetail.SaveChanges();
                    #endregion
                }
            }
        }
Beispiel #5
0
        public DataTable GetReportDetailOvertime(string userExport, DateTime dateStart, DateTime dateEndSearch, string ProfileName, string CodeEmp, string OrgIDString, List<Guid?> lstovertimeTypeIds, bool noDisplay0Data, bool isIncludeQuitEmp)
        {
            DataTable table = CreateReportDetailOvertimeSchema();
            DateTime dateEnd = dateEndSearch.AddDays(1).AddMinutes(-1);

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork);
                string key = OverTimeStatus.E_APPROVED.ToString();
                string E_CASHOUT = MethodOption.E_CASHOUT.ToString();



                var overtimesQuery = unitOfWork.CreateQueryable<Att_Overtime>(s => s.IsDelete == null &&
                    (s.RegisterHours > 0 || s.ApproveHours > 0) && s.Status == key && dateStart <= s.WorkDate
                    && s.WorkDate <= dateEnd && (s.MethodPayment == null || s.MethodPayment == E_CASHOUT));
                if (!string.IsNullOrEmpty(OrgIDString))
                {
                    List<Guid> OrgIDs = new List<Guid>();
                    List<string> OrgIDsArr = OrgIDString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
                    foreach (var item in OrgIDsArr)
                    {
                        Guid OrgID = Guid.Empty;
                        Guid.TryParse(item, out OrgID);
                        if (OrgID != Guid.Empty)
                        {
                            OrgIDs.Add(OrgID);
                        }
                    }
                    overtimesQuery = overtimesQuery.Where(m => m.OrgStructureID != null && OrgIDs.Contains(m.OrgStructureID.Value));
                }
                if (!string.IsNullOrEmpty(ProfileName))
                {
                    List<string> lstProfileName = ProfileName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
                    if (lstProfileName.Count > 1)
                    {
                        overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && lstProfileName.Contains(m.Hre_Profile.ProfileName));
                    }
                    else
                    {
                        overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && m.Hre_Profile.ProfileName != null && (m.Hre_Profile.ProfileName.Contains(ProfileName)));
                    }

                }

                if (!string.IsNullOrEmpty(CodeEmp))
                {
                    List<string> lstCodeEmp = CodeEmp.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
                    if (lstCodeEmp.Count > 1)
                    {
                        overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && lstCodeEmp.Contains(m.Hre_Profile.CodeEmp));
                    }
                    else
                    {
                        overtimesQuery = overtimesQuery.Where(m => m.Hre_Profile != null && m.Hre_Profile.CodeEmp != null && (m.Hre_Profile.CodeEmp.Contains(CodeEmp)));
                    }
                }
                if (noDisplay0Data)
                {
                    overtimesQuery = overtimesQuery.Where(s => s.ApproveHours > 0);
                }
                if (lstovertimeTypeIds != null && lstovertimeTypeIds[0] != null && lstovertimeTypeIds[0] != Guid.Empty)
                {
                    overtimesQuery = overtimesQuery.Where(s => lstovertimeTypeIds.Contains(s.OvertimeTypeID));
                }
                var overtimes = overtimesQuery.Select(s => new { s.ProfileID, s.WorkDate, s.OvertimeTypeID, s.ApproveHours, s.RegisterHours, s.AnalyseHour, s.ConfirmHours, s.OrgStructureID, s.ReasonOT }).ToList();

                var profileIds = overtimes.Select(s => s.ProfileID).Distinct().ToList();

                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                var workDays = repoAtt_Workday.FindBy(s => s.IsDelete == null & dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
             .Select(s => new { s.ProfileID, s.ShiftID, s.InTime1, s.OutTime1, s.WorkDate }).ToList();

                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(s => s.IsDelete == null && profileIds.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();

                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null && s.Code != null).ToList();

                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();

                var repoCat_Position = new Cat_PositionRepository(unitOfWork);
                var positions = repoCat_Position.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList();

                var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork);
                var jobtitles = repoCat_JobTitle.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();

                var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork);
                var overtimeTypes = repoCat_OvertimeType.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code }).ToList();

                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();

                if (!isIncludeQuitEmp)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }

                foreach (var profile in profiles)
                {
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var overtimeProfiles = overtimes.Where(s => s.WorkDate.Date == date.Date && s.ProfileID == profile.ID).ToList();
                        if (overtimeProfiles.Count == 0)
                            continue;

                        var lastOvertimeByProfile = overtimeProfiles.OrderByDescending(m => m.WorkDate).FirstOrDefault();


                        DataRow row = table.NewRow();
                        Guid? orgId = profile.OrgStructureID;
                        if (lastOvertimeByProfile != null)
                            orgId = lastOvertimeByProfile.OrgStructureID;

                        var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID);
                        var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                        var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                        var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes);
                        var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.ProfileName] = profile.ProfileName;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.DateExport] = DateTime.Now;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.ReasonOT] = lastOvertimeByProfile.ReasonOT;
                        var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                        var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                        var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate == date);
                        var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID);
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.DateFrom] = dateStart;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.DateTo] = dateEnd;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.DateExport] = DateTime.Now;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.UserExport] = userExport;
                        row[Att_ReportDetailOvertimeEntity.FieldNames.udSubmitApproveHour] = overtimeProfiles.Where(m => m.AnalyseHour != null).Sum(m => m.AnalyseHour);

                        row[Att_ReportDetailOvertimeEntity.FieldNames.DateOvertime] = date;
                        if (workDay != null && workDay.InTime1 != null)
                        {
                            //row[Att_ReportDetailOvertimeEntity.FieldNames.udInTime] = workDay.InTime1.Value.ToString("HH:mm:ss");
                            row[Att_ReportDetailOvertimeEntity.FieldNames.udInTime] = workDay.InTime1.Value;
                        }
                        if (workDay != null && workDay.OutTime1 != null)
                        {
                            //row[Att_ReportDetailOvertimeEntity.FieldNames.udOutTime] = workDay.OutTime1.Value.ToString("HH:mm:ss");
                            row[Att_ReportDetailOvertimeEntity.FieldNames.udOutTime] = workDay.OutTime1.Value;
                        }

                        if (shift != null)
                        {

                            row[Att_ReportDetailOvertimeEntity.FieldNames.ShiftName] = shift.ShiftName;
                        }
                        foreach (var item in overtimeTypes)
                        {
                            var sum = overtimeProfiles.Where(s => s.OvertimeTypeID == item.ID).Sum(s => s.RegisterHours);
                            row[item.Code] = sum > 0 ? (object)sum : DBNull.Value;
                            sum = overtimeProfiles.Where(s => s.OvertimeTypeID == item.ID && s.ApproveHours > 0).Sum(s => s.ApproveHours.Value);
                            row[item.Code + "_Approve"] = sum > 0 ? (object)sum : DBNull.Value;
                            sum = overtimeProfiles.Where(s => s.OvertimeTypeID == item.ID && s.ConfirmHours != null && s.ConfirmHours > 0).Sum(s => s.ConfirmHours);
                            row[item.Code + "_Confirm"] = sum > 0 ? (object)sum : DBNull.Value;
                        }
                        table.Rows.Add(row);
                    }
                }
                var configs = new Dictionary<string, Dictionary<string, object>>();
                var config = new Dictionary<string, object>();
                var configtime = new Dictionary<string, object>();
                var configwidthCode = new Dictionary<string, object>();
                var configwidthName = new Dictionary<string, object>();
                var configwidthshift = new Dictionary<string, object>();
                var configwidthudSubmitApproveHour = new Dictionary<string, object>();


                configwidthCode.Add("width", 80);
                configs.Add("CodeBranch", configwidthCode);
                configs.Add("CodeOrg", configwidthCode);
                configs.Add("CodeTeam", configwidthCode);
                configs.Add("CodeSection", configwidthCode);
                configs.Add("CodeJobtitle", configwidthCode);
                configs.Add("CodePosition", configwidthCode);

                configwidthName.Add("width", 110);
                configs.Add("BranchName", configwidthName);
                configs.Add("OrgName", configwidthName);
                configs.Add("TeamName", configwidthName);
                configs.Add("SectionName", configwidthName);

                configwidthudSubmitApproveHour.Add("width", 120);
                configs.Add("udSubmitApproveHour", configwidthudSubmitApproveHour);

                configwidthshift.Add("width", 90);
                configs.Add("DateOvertime", configwidthshift);
                configs.Add("ShiftName", configwidthshift);

                config.Add("hidden", true);
                configs.Add("DateFrom", config);
                configs.Add("DateTo", config);
                configs.Add("UserExport", config);
                configs.Add("DateExport", config);

                configtime.Add("width", 80);
                configtime.Add("format", "{0:HH:mm:ss}");
                configs.Add("udOutTime", configtime);
                configs.Add("udInTime", configtime);
                // return table.ConfigDatatable();
                return table.ConfigTable(configs);
            }
        }
Beispiel #6
0
        public List<Att_OvertimeEntity> GetExceptionOvertimeList(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> lstProfileIDsAll, string UserLogin)
        {
            List<Guid> lstProfileIDs = lstProfileIDsAll.Select(s => s.ID).ToList();

            var lstAtt_Overtime = new List<Att_OvertimeEntity>();
            using (var context = new VnrHrmDataContext())
            {
                var baseService = new BaseService();
                var _status = string.Empty;
                ListQueryModel lqm = new ListQueryModel();

                #region [tại thời  chưa có giải pháp tốt nên để code củ chuối]
                List<object> lstObj = new List<object>();
                lstObj.Add(1);
                lstObj.Add(1000000);
                #endregion

                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                if (lstProfileIDs != null)
                {
                    string waitStatus = ProfileStatusSyn.E_WAITING.ToString();
                }
                string status = OverTimeStatus.E_REJECTED.ToString();
                var repoAtt_Overtime = new Att_OvertimeRepository(unitOfWork);

                List<Att_OvertimeEntity> lstOvertimeAll = baseService.GetData<Att_OvertimeEntity>(lstObj, ConstantSql.hrm_att_sp_get_OT, UserLogin, ref _status).Where(s => dateStart <= s.WorkDate
                    && s.WorkDate <= dateEnd && s.Status != status).Select(d => new Att_OvertimeEntity
                    {
                        ID = d.ID,
                        WorkDate = d.WorkDate,
                        RegisterHours = d.RegisterHours,
                        ApproveHours = d.ApproveHours,
                        ProfileID = d.ProfileID,
                        Status = d.Status,
                        MethodPayment = d.MethodPayment,
                        ReasonOT = d.ReasonOT,
                        ShiftName = d.ShiftName,
                        ProfileName = d.ProfileName,
                        CodeEmp = d.CodeEmp,
                        OvertimeTypeName = d.OvertimeTypeName,
                        UserApproveName1 = d.UserApproveName1,
                        UserApproveName2 = d.UserApproveName2,
                        OrgStructureName = d.OrgStructureName
                    }).ToList<Att_OvertimeEntity>();
                if (lstProfileIDs.Count > 0)
                    lstOvertimeAll = lstOvertimeAll.Where(s => lstProfileIDs.Contains(s.ProfileID)).ToList();
                List<Guid> listDuple = new List<Guid>();
                IList<IGrouping<Guid, Att_OvertimeEntity>> ilGroupProfileID = lstOvertimeAll.GroupBy(d => d.ProfileID).ToList();
                foreach (Att_OvertimeEntity attOvertime in lstOvertimeAll)
                {
                    Guid profileID = attOvertime.ProfileID;
                    DateTime workDate = attOvertime.WorkDate.AddHours(attOvertime.RegisterHours);

                    if (lstOvertimeAll.Where(s => s.ProfileID == profileID && s.WorkDate < workDate && s.WorkDate.AddHours(s.RegisterHours) > attOvertime.WorkDate).Count() > 1)
                        listDuple.Add(attOvertime.ID);
                }
                lstAtt_Overtime = lstOvertimeAll.Where(s => listDuple.Contains(s.ID)).OrderBy(ls => ls.ProfileID)
                    .ThenBy(ls => ls.WorkDate).ToList();
            }
            return lstAtt_Overtime;
        }