コード例 #1
0
ファイル: Cat_ShiftServices.cs プロジェクト: radtek/vnr
 /// <summary>
 /// Lấy tất cả dữ liệu
 /// </summary>
 /// <returns></returns>
 public IQueryable <Cat_Shift> GetAll()
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork         unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo       = new Cat_ShiftRepository(unitOfWork);
         return(repo.GetAllCatShift().Where(i => i.IsDelete == null));
     }
 }
コード例 #2
0
ファイル: Cat_ShiftServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Lấy tất cả dữ liệu
        /// </summary>
        /// <returns></returns>
        public IQueryable<Cat_Shift> GetAll()
        {
            using (var context = new VnrAttendanceDataContext())
            {
                IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                Cat_ShiftRepository repo = new Cat_ShiftRepository(unitOfWork);
                return repo.GetAllCatShift().Where(i => i.IsDelete == null);

            }
        }
コード例 #3
0
ファイル: Cat_ShiftServices.cs プロジェクト: dtafe/vnr
 /// <summary>
 /// Lấy dữ liệu theo Id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Cat_Shift GetById(int id)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo = new Cat_ShiftRepository(unitOfWork);
         var catshift= repo.GetById(id);
         if (catshift.IsDelete == true) catshift = null;
         return catshift;
     }
 }
コード例 #4
0
ファイル: Cat_ShiftServices.cs プロジェクト: radtek/vnr
 /// <summary>
 /// Lấy dữ liệu theo Id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Cat_Shift GetById(int id)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork         unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo       = new Cat_ShiftRepository(unitOfWork);
         var catshift = repo.GetById(id);
         if (catshift.IsDelete == true)
         {
             catshift = null;
         }
         return(catshift);
     }
 }
コード例 #5
0
ファイル: Cat_ShiftServices.cs プロジェクト: dtafe/vnr
 /// <summary>
 /// Thêm mới một record
 /// </summary>
 /// <param name="cat"></param>
 /// <returns></returns>
 public bool Add(Cat_Shift cat)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo = new Cat_ShiftRepository(unitOfWork);
         try
         {
             repo.Add(cat);
             repo.SaveChanges();
             return true;
         }
         catch
         {
             return false;
         }
     }
 }
コード例 #6
0
ファイル: Cat_ShiftServices.cs プロジェクト: radtek/vnr
 /// <summary>
 /// Edit một record
 /// </summary>
 /// <param name="cat"></param>
 /// <returns></returns>
 public bool Edit(Cat_Shift cat)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork         unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo       = new Cat_ShiftRepository(unitOfWork);
         try
         {
             repo.Edit(cat);
             repo.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
コード例 #7
0
ファイル: Cat_ShiftServices.cs プロジェクト: radtek/vnr
 /// <summary>
 /// Remove 1 record là chuyển trạng thái IsDelete=true
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool Remove(int id)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork         unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo       = new Cat_ShiftRepository(unitOfWork);
         var cat = repo.GetById(id);
         try
         {
             repo.Remove(cat);
             repo.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
コード例 #8
0
        /// <summary>
        /// Hàm tính toán Phép năm dành cho từng nhân viên
        /// </summary>
        /// <param name="Profile">Nhân Viên</param>
        /// <param name="lstGradeCfg">Ds Chế Độ lương</param>
        /// <param name="lstGrade">Ds Grade của Nhân viên</param>
        /// <param name="BeginYear">Ngày bắt đầu của năm</param>
        /// <param name="EndYear">Ngày Kết Thúc Của Năm</param>
        /// <param name="lstLeaveAnl">Ds nghỉ phép năm</param>
        /// <param name="lstAnnualDetailInDB">Ds AnnualDetail trong DB</param>
        /// <param name="AnnualLeave">AnnualLeave</param>
        /// <param name="lstRosterInYear">Ds Roster</param>
        /// <param name="lstRosterGroup">Ds RosterGroup</param>
        /// <param name="lstWorkHistory">Ds WorkingHistory</param>
        /// <param name="lstDayOff">Ds Ngày Nghỉ Lễ </param>
        /// <returns></returns>
        private List <Att_AnnualDetail> AnalyzeAnnualDetailPerProfile(Hre_ProfileMultiField Profile, List <Cat_GradeAttendance>
                                                                      lstGradeCfg, List <Att_Grade> lstGrade, DateTime BeginYear, DateTime EndYear, List <Att_LeaveDayInfo> lstLeaveAnl,
                                                                      List <Att_AnnualDetail> lstAnnualDetailInDB, Att_AnnualLeave AnnualLeave, List <Att_RosterInfo> lstRosterInYearIn,
                                                                      List <Att_RosterGroup> lstRosterGroup, List <Cat_DayOff> lstDayOff,
                                                                      bool IsFrom1To31, Cat_Position Position, List <Sys_AllSetting> lstAllSetting, List <Hre_HDTJob> lstHDTJob, out List <Att_AnnualDetail> AnalyzeAnnualDetailPerProfile_Update, string userLogin)
        {
            AnalyzeAnnualDetailPerProfile_Update = new List <Att_AnnualDetail>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork     = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Roster = new CustomBaseRepository <Att_Roster>(unitOfWork);
                var repoCat_Shift  = new Cat_ShiftRepository(unitOfWork);
                var shifts         = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();

                var lstRosterID     = lstRosterInYearIn.Select(s => s.ID).ToList();
                var lstRosterInYear = repoAtt_Roster.FindBy(s => lstRosterID.Contains(s.ID)).ToList();

                List <Att_AnnualDetail> lstResult            = new List <Att_AnnualDetail>();
                double            leaveBeginYearToMonth      = 0;
                double            leaveBeginYearToMonth_Init = 0;
                string            E_ROSTERGROUP       = RosterType.E_ROSTERGROUP.ToString();
                List <Att_Roster> lstRoster_byProfile = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type != E_ROSTERGROUP).ToList();
                List <Att_Roster> lstRosterTypeGroup  = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type == E_ROSTERGROUP).ToList();

                for (DateTime Month = BeginYear; Month <= EndYear; Month = Month.AddMonths(1))
                {
                    var gradeByProfileByTime = lstGrade.Where(m => m.ProfileID == Profile.ID && m.MonthStart <= Month).OrderByDescending(m => m.MonthStart).FirstOrDefault();
                    if (gradeByProfileByTime == null)
                    {
                        continue;
                    }
                    var GradeCfg = lstGradeCfg.Where(m => m.ID == gradeByProfileByTime.GradeAttendanceID).FirstOrDefault();
                    if (GradeCfg == null)
                    {
                        continue;
                    }

                    DateTime BeginMonth = Month;
                    DateTime EndMonth   = BeginMonth.AddMonths(1).AddMinutes(-1);
                    if (!IsFrom1To31)
                    {
                        Att_AttendanceServices.GetRangeMaxMinGrade(new List <Cat_GradeAttendance>()
                        {
                            GradeCfg
                        }, Month, out BeginMonth, out EndMonth);
                    }

                    int    AnnualLeaveMonthStart   = AnnualLeave != null ? AnnualLeave.MonthStart : 1;
                    double AnnualLeaveInitAnlValue = AnnualLeave != null ? AnnualLeave.InitAnlValue : 0;

                    double Availale = Att_AttendanceLib.GetAnnualLeaveReceive(BeginYear.Year, Month, GradeCfg, Profile.DateHire,
                                                                              Profile.DateEndProbation, Profile.DateQuit, AnnualLeaveMonthStart, AnnualLeaveInitAnlValue, Position, Profile,
                                                                              lstLeaveAnl, lstAllSetting, lstHDTJob, lstDayOff.Select(m => m.DateOff).ToList(), lstLeaveAnl, userLogin);
                    double LeaveInMonth = 0;
                    List <Att_LeaveDayInfo> lstAnlInMonth = lstLeaveAnl.Where(m => m.ProfileID == Profile.ID && m.DateStart <= EndMonth && m.DateEnd >= BeginMonth).ToList();
                    foreach (var item in lstAnlInMonth)
                    {
                        var listRosterEntity = lstRoster_byProfile.Select(d => new Att_RosterEntity
                        {
                            ID              = d.ID,
                            ProfileID       = d.ProfileID,
                            RosterGroupName = d.RosterGroupName,
                            Type            = d.Type,
                            Status          = d.Status,
                            DateEnd         = d.DateEnd,
                            DateStart       = d.DateStart,
                            MonShiftID      = d.MonShiftID,
                            TueShiftID      = d.TueShiftID,
                            WedShiftID      = d.WedShiftID,
                            ThuShiftID      = d.ThuShiftID,
                            FriShiftID      = d.FriShiftID,
                            SatShiftID      = d.SatShiftID,
                            SunShiftID      = d.SunShiftID,
                            MonShift2ID     = d.MonShiftID,
                            TueShift2ID     = d.TueShift2ID,
                            WedShift2ID     = d.WedShift2ID,
                            ThuShift2ID     = d.ThuShift2ID,
                            FriShift2ID     = d.FriShift2ID,
                            SatShift2ID     = d.SatShift2ID,
                            SunShift2ID     = d.SunShift2ID
                        }).ToList();

                        var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity
                        {
                            ID              = d.ID,
                            DateEnd         = d.DateEnd,
                            DateStart       = d.DateStart,
                            MonShiftID      = d.MonShiftID,
                            TueShiftID      = d.TueShiftID,
                            WedShiftID      = d.WedShiftID,
                            ThuShiftID      = d.ThuShiftID,
                            FriShiftID      = d.FriShiftID,
                            SatShiftID      = d.SatShiftID,
                            SunShiftID      = d.SunShiftID,
                            RosterGroupName = d.RosterGroupName
                        }).ToList();

                        if (item.DateStart >= BeginMonth && item.DateEnd <= EndMonth)
                        {
                            //Chi cần lấy TotalDuration hoặc lấy giờ rồi lấy ca
                            if (item.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString())
                            {
                                LeaveInMonth += item.LeaveDays ?? 0;
                            }
                            else
                            {
                                //Lấy ra ca làm việc
                                DateTime DateBeginLeave = item.DateStart.Date;
                                DateTime DateEndLeave   = item.DateEnd.Date;

                                Dictionary <DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBeginLeave, DateEndLeave, listRosterEntity, listRosterGroupEntity, shifts);

                                if (dicShift != null && dicShift.ContainsKey(DateBeginLeave))
                                {
                                    Cat_Shift shift = dicShift[DateBeginLeave];
                                    if (shift != null)
                                    {
                                        double HourWorkday = shift.udStandardWorkHours > 0 ? shift.udStandardWorkHours : 8.0;

                                        LeaveInMonth += item.LeaveHours.Value / HourWorkday;
                                    }
                                }
                            }
                        }
                        else
                        {
                            DateTime DateBegin = BeginMonth > item.DateStart ? BeginMonth : item.DateStart;
                            DateTime DateEnd   = EndMonth < item.DateEnd ? BeginMonth : item.DateEnd;
                            Dictionary <DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBegin, DateEnd, listRosterEntity, listRosterGroupEntity, shifts);
                            for (DateTime dateCheck = DateBegin; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1))
                            {
                                if (Att_WorkDayHelper.IsWorkDay(dateCheck, GradeCfg, dicShift, lstDayOff) && !lstDayOff.Any(m => m.DateOff == dateCheck))
                                {
                                    LeaveInMonth++;
                                }
                            }
                        }
                    }
                    Att_AnnualDetail AnnualDetail = lstAnnualDetailInDB.Where(m => m.ProfileID == Profile.ID && m.MonthYear == Month).FirstOrDefault();
                    bool             isNew        = false;
                    if (AnnualDetail == null)
                    {
                        isNew        = true;
                        AnnualDetail = new Att_AnnualDetail();
                    }
                    else
                    {
                        AnalyzeAnnualDetailPerProfile_Update.Add(AnnualDetail);
                    }


                    if (Profile.DateQuit != null)
                    {
                        DateTime MonthQuit = Profile.DateQuit.Value.Day >= 15 ? Profile.DateQuit.Value.AddMonths(1) : Profile.DateQuit.Value;
                        MonthQuit = new DateTime(MonthQuit.Year, MonthQuit.Month, 1);
                        if (Month >= MonthQuit)
                        {
                            AnnualDetail.IsDelete = true;
                        }
                    }
                    AnnualDetail.Available     = Availale;
                    AnnualDetail.InitAvailable = AnnualLeave == null ? 0 : AnnualLeave.InitAnlValue;
                    AnnualDetail.ProfileID     = Profile.ID;
                    //AnnualDetail.Hre_Profile = Profile.CopyData<Hre_Profile>();
                    AnnualDetail.Year             = BeginYear.Year;
                    AnnualDetail.MonthYear        = Month;
                    AnnualDetail.MonthBeginInYear = MonthStartAnl; //todo: Phần tử này để trong cấu hình chung
                    if (AnnualLeave != null && AnnualLeave.MonthResetAnlOfBeforeYear != null)
                    {
                        AnnualDetail.MonthResetInitAvailable = AnnualLeave.MonthResetAnlOfBeforeYear.Value;//todo: MonthReset Này để trong chế độ lương
                    }
                    else
                    {
                        AnnualDetail.MonthResetInitAvailable = 12;//todo: MonthReset Này để trong chế độ lương
                    }
                    AnnualDetail.MonthStartProfile = AnnualLeave == null ? 1 : AnnualLeave.MonthStart;
                    if (AnnualDetail.MonthResetInitAvailable != null && AnnualDetail.MonthResetInitAvailable != 12 && AnnualDetail.Year != null)
                    {
                        DateTime MonthReset = new DateTime(AnnualDetail.Year.Value, AnnualDetail.MonthResetInitAvailable.Value, 1);
                        AnnualDetail.IsHaveResetInitAvailable = true;
                        if (Month <= MonthReset) //Trong những tháng có
                        {
                            double delta = leaveBeginYearToMonth_Init + LeaveInMonth - AnnualDetail.InitAvailable.Value;
                            if (delta > 0)
                            {
                                AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                                AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth - delta;
                                AnnualDetail.LeaveInMonth   = delta;
                                AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                                leaveBeginYearToMonth      += delta;
                                leaveBeginYearToMonth_Init += LeaveInMonth - delta;
                            }
                            else
                            {
                                AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                                AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth;
                                AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                                AnnualDetail.LeaveInMonth   = 0;
                                leaveBeginYearToMonth_Init += LeaveInMonth;
                            }
                        }
                        else //sau những tháng kho có
                        {
                            AnnualDetail.InitAvailable = 0;
                            AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                            AnnualDetail.LeaveInMonth  = LeaveInMonth;
                            leaveBeginYearToMonth     += LeaveInMonth;
                        }
                    }
                    else //Bình thường
                    {
                        AnnualDetail.IsHaveResetInitAvailable = false;
                        AnnualDetail.TotalLeaveBef            = leaveBeginYearToMonth;
                        AnnualDetail.LeaveInMonth             = LeaveInMonth;
                        leaveBeginYearToMonth += LeaveInMonth;
                    }
                    double remain = (AnnualDetail.Available ?? 0) + (AnnualDetail.InitAvailable ?? 0) - (AnnualDetail.TotalLeaveBefFromInitAvailable ?? 0) - (AnnualDetail.LeaveInMonthFromInitAvailable ?? 0) - (AnnualDetail.TotalLeaveBef ?? 0) - (AnnualDetail.LeaveInMonth ?? 0);
                    AnnualDetail.Remain = remain;
                    AnnualDetail.Type   = AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
                    if (isNew)
                    {
                        lstResult.Add(AnnualDetail);
                    }
                }
                return(lstResult);
            }
        }
コード例 #9
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Lấy Dữ Liệu BC Thống Kê Đi Muộn Về Sớm
        /// </summary>
        /// <returns></returns>
        public List<Att_ReportSummaryLateInOutEntity> GetReportSummaryLateInOut(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> profiles, Guid[] shiftIDs, bool isIncludeQuitEmp, string codeEmp, string userExport)
        {
            using (var context = new VnrHrmDataContext())
            {
                List<Guid> lstProfileIDs = profiles.Select(s => s.ID).ToList();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoAtt_WorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoShift = new Cat_ShiftRepository(unitOfWork);
                var repoCat_TAMReasonmiss = new Cat_TAMScanReasonMissRepository(unitOfWork);

                string E_LATE_EARLY = WorkdayType.E_LATE_EARLY.ToString();
                string E_APPROVED = WorkdayStatus.E_APPROVED.ToString();
                var workDays = new List<Att_Workday>().Select(s => new { s.ProfileID, s.WorkDate, s.LateEarlyDuration, s.ShiftID, s.InTime1, s.OutTime1, s.MissInOutReason, s.LateDuration1, s.EarlyDuration1 }).ToList();

                workDays = repoAtt_WorkDay.FindBy(s => s.IsDelete == null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && s.Type == E_LATE_EARLY && !(s.Status == E_APPROVED && s.LateEarlyDuration == 0))
                    .Select(s => new { s.ProfileID, s.WorkDate, s.LateEarlyDuration, s.ShiftID, s.InTime1, s.OutTime1, s.MissInOutReason, s.LateDuration1, s.EarlyDuration1 }).ToList();

                var profileIds = workDays.Select(s => s.ProfileID).Distinct().ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                #region MyRegion
                var repoCat_Position = new Cat_PositionRepository(unitOfWork);
                var positions = repoCat_Position.FindBy(s => 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.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();
                #endregion
                var reasons = repoCat_TAMReasonmiss.FindBy(s => s.IsDelete == null);
                var shifts = repoShift.FindBy(s => s.IsDelete == null);
                if (shiftIDs != null)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && shiftIDs.Contains(s.ShiftID.Value)).ToList();
                    profileIds = workDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }

                if (!isIncludeQuitEmp)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateStart).ToList();
                }
                if (!string.IsNullOrEmpty(codeEmp))
                {
                    profiles = profiles.Where(s => s.CodeEmp == codeEmp).ToList();
                }

                var key = LeaveDayStatus.E_APPROVED.ToString();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leaveDays = repoLeaveDay.FindBy(s => s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd);
                List<Guid> guids = profiles.Select(s => s.ID).ToList();
                workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList();
                profiles = profiles.Where(s => guids.Contains(s.ID)).ToList();
                List<Att_ReportSummaryLateInOutEntity> lstReportSummaryLateInOutEntity = new List<Att_ReportSummaryLateInOutEntity>();
                Att_ReportSummaryLateInOutEntity reportSummaryLateInOutEntityEntity = null;
                foreach (var profile in profiles)
                {
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var workDayProfiles = workDays.Where(s => s.ProfileID == profile.ID && s.WorkDate.Date == date).ToList();
                        var leveDay = leaveDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        if (workDayProfiles.Count > 0 && leveDay == null)
                        {
                            var workDay = workDayProfiles.FirstOrDefault(s => s.WorkDate.Date == date);
                            if (workDay != null)
                            {
                                reportSummaryLateInOutEntityEntity = new Att_ReportSummaryLateInOutEntity();
                                Guid? orgId = profile.OrgStructureID;
                                var reason = reasons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                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);

                                reportSummaryLateInOutEntityEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;

                                reportSummaryLateInOutEntityEntity.BranchName = orgBranch != null ? orgOrg.OrgStructureName : string.Empty;
                                reportSummaryLateInOutEntityEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                reportSummaryLateInOutEntityEntity.TeamName = orgTeam != null ? orgOrg.OrgStructureName : string.Empty;
                                reportSummaryLateInOutEntityEntity.SectionName = orgSection != null ? orgOrg.OrgStructureName : string.Empty;

                                #region MyRegion
                                var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                                var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                                #endregion
                                var shift = shifts.FirstOrDefault(s => s.ID == workDay.ShiftID);
                                reportSummaryLateInOutEntityEntity.ProfileName = profile.ProfileName;
                                reportSummaryLateInOutEntityEntity.CodeEmp = profile.CodeEmp;
                                #region MyRegion
                                reportSummaryLateInOutEntityEntity.PositionCode = positon != null ? positon.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.JobtitleCode = jobtitle != null ? jobtitle.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
                                reportSummaryLateInOutEntityEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                                #endregion
                                reportSummaryLateInOutEntityEntity.DateFrom = dateStart;
                                reportSummaryLateInOutEntityEntity.Date = date;
                                reportSummaryLateInOutEntityEntity.DateTo = dateEnd;
                                reportSummaryLateInOutEntityEntity.DateExport = DateTime.Now;
                                reportSummaryLateInOutEntityEntity.UserExport = userExport;
                                reportSummaryLateInOutEntityEntity.udTAMScanReasonMiss = reason == null ? string.Empty : reason.TAMScanReasonMissName;
                                reportSummaryLateInOutEntityEntity.ShiftName = shift == null ? string.Empty : shift.ShiftName;
                                reportSummaryLateInOutEntityEntity.udInTime = workDay.InTime1 != null ? workDay.InTime1.Value : DateTime.MinValue;
                                reportSummaryLateInOutEntityEntity.udOutTime = workDay.OutTime1 != null ? workDay.OutTime1.Value : DateTime.MinValue;
                                if (workDay.LateEarlyDuration >= 120)
                                {
                                    reportSummaryLateInOutEntityEntity.EarlyDurationMore2 = "X";
                                }
                                else
                                {
                                    reportSummaryLateInOutEntityEntity.EarlyDurationLess2 = "X";
                                }

                                if (workDay.LateDuration1 != null && workDay.LateDuration1 > 0)
                                {
                                    reportSummaryLateInOutEntityEntity.LateForWork = "X";
                                }
                                if (workDay.EarlyDuration1 != null && workDay.EarlyDuration1 > 0)
                                {
                                    reportSummaryLateInOutEntityEntity.EarlyGoHome = "X";
                                }

                                lstReportSummaryLateInOutEntity.Add(reportSummaryLateInOutEntityEntity);
                            }
                        }
                    }
                    #region MyRegion
                    //Guid? orgId = profile.OrgStructureID;
                    //var attendanceProfiles = attendanceTables.Where(s => s.ProfileID == profile.ID).ToList();
                    //var attendaceProfileIDs = attendanceProfiles.Select(s => s.ID).ToList();
                    //var attendanceItemProfiles = attendanceItems.Where(s => attendaceProfileIDs.Contains(s.AttendanceTableID)).ToList();                    
                    //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);
                    //reportSummaryLateInOutEntityEntity.LateMinutes = attendanceItemProfiles.Sum(s => s.LateInMinutes);
                    //reportSummaryLateInOutEntityEntity.EarlyMinutes = attendanceItemProfiles.Sum(s => s.EarlyOutMinutes);
                    //reportSummaryLateInOutEntityEntity.NumTimeLate = attendanceItemProfiles.Count(s => s.LateInMinutes > 0);
                    //reportSummaryLateInOutEntityEntity.NumTimeEarly = attendanceItemProfiles.Count(s => s.EarlyOutMinutes > 0);
                    //lstReportSummaryLateInOutEntity.Add(reportSummaryLateInOutEntityEntity);
                    #endregion
                }
                return lstReportSummaryLateInOutEntity;
            }
        }
コード例 #10
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Lấy Dữ Liệu BC Báo cáo tổng số lần đi muộn về sớm trong tháng
        /// </summary>
        /// <param name="DateFrom">Ngày bắt đầu</param>
        /// <param name="DateTo">Ngày kết thúc (Cuối ngày 23:59:59)</param>
        /// <param name="lstProfileIDs">Ds ProfileIDs</param>
        /// <returns></returns>

        public List<Att_ReportSumaryLateInOutEntity> GetReportSumaryLateInOut(DateTime DateFrom, DateTime DateTo, List<Hre_ProfileEntity> profiles, Guid[] ShiftIDs, bool isIncludeQuitEmp, bool noDisplay0Data, string userExport)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                List<Att_ReportSumaryLateInOutEntity> lstReportSumaryLateInOut = new List<Att_ReportSumaryLateInOutEntity>();
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.GetAll().ToList();
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => 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.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.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();
                if (!isIncludeQuitEmp)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > DateTo).ToList();
                }
                var workDays = repoAtt_Workday.FindBy(s =>
                  DateFrom <= s.WorkDate && s.WorkDate <= DateTo
                  && s.LateEarlyDuration > 0 && s.IsDelete == null)
                  .Select(m => new { m.ID, m.ProfileID, m.LateDuration1, m.EarlyDuration1, m.LateEarlyDuration, m.ShiftID }).ToList();
                if (ShiftIDs != null)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && ShiftIDs.Contains(s.ShiftID.Value)).ToList();
                }
                //var lstWorkday = workDays.Select(m => new { m.ID, m.ProfileID, m.LateDuration1, m.EarlyDuration1, m.LateEarlyDuration }).ToList();
                if (noDisplay0Data)
                {
                    var profileIDs = workDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIDs.Contains(s.ID)).ToList();
                }
                foreach (var profile in profiles)
                {
                    Att_ReportSumaryLateInOutEntity rptSumaryLateInOut = new Att_ReportSumaryLateInOutEntity();

                    Guid? orgId = 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);
                    rptSumaryLateInOut.GroupCode = orgBranch != null ? orgBranch.Code : string.Empty;
                    rptSumaryLateInOut.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                    rptSumaryLateInOut.Division = orgTeam != null ? orgTeam.Code : string.Empty; ;
                    rptSumaryLateInOut.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                    rptSumaryLateInOut.CodeEmp = profile.CodeEmp;
                    rptSumaryLateInOut.ProfileName = profile.ProfileName;
                    var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                    rptSumaryLateInOut.PositionCode = positon != null ? positon.Code : string.Empty;
                    //  var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                    rptSumaryLateInOut.DateFrom = DateFrom;
                    rptSumaryLateInOut.DateTo = DateTo;
                    rptSumaryLateInOut.DateExport = DateTime.Today;
                    rptSumaryLateInOut.UserExport = userExport;
                    var lstWorkday_ByProfile = workDays.Where(m => m.ProfileID == profile.ID).ToList();
                    if (lstWorkday_ByProfile != null && lstWorkday_ByProfile.Count > 0)
                    {
                        var sumEarly = lstWorkday_ByProfile.Sum(s => s.EarlyDuration1);
                        var SumLateMinute = lstWorkday_ByProfile.Sum(s => s.LateDuration1);
                        var CountLate = lstWorkday_ByProfile.Count(m => m.LateDuration1 > 0);
                        var CountEarly = lstWorkday_ByProfile.Count(m => m.EarlyDuration1 > 0);
                        rptSumaryLateInOut.EarlyMinutes = sumEarly > 0 ? sumEarly : null;
                        rptSumaryLateInOut.LateMinutes = SumLateMinute > 0 ? SumLateMinute : null;
                        rptSumaryLateInOut.NumTimeEarly = CountEarly > 0 ? (int?)CountEarly : null;
                        rptSumaryLateInOut.NumTimeLate = CountLate > 0 ? (int?)CountLate : null;
                    }
                    lstReportSumaryLateInOut.Add(rptSumaryLateInOut);
                }
                return lstReportSumaryLateInOut;

            }
        }
コード例 #11
0
ファイル: Att_AnnualDetailServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Hàm tính toán Phép năm dành cho từng nhân viên
        /// </summary>
        /// <param name="Profile">Nhân Viên</param>
        /// <param name="lstGradeCfg">Ds Chế Độ lương</param>
        /// <param name="lstGrade">Ds Grade của Nhân viên</param>
        /// <param name="BeginYear">Ngày bắt đầu của năm</param>
        /// <param name="EndYear">Ngày Kết Thúc Của Năm</param>
        /// <param name="lstLeaveAnl">Ds nghỉ phép năm</param>
        /// <param name="lstAnnualDetailInDB">Ds AnnualDetail trong DB</param>
        /// <param name="AnnualLeave">AnnualLeave</param>
        /// <param name="lstRosterInYear">Ds Roster</param>
        /// <param name="lstRosterGroup">Ds RosterGroup</param>
        /// <param name="lstWorkHistory">Ds WorkingHistory</param>
        /// <param name="lstDayOff">Ds Ngày Nghỉ Lễ </param>
        /// <returns></returns>
        private List<Att_AnnualDetail> AnalyzeAnnualDetailPerProfile(Hre_ProfileMultiField Profile, List<Cat_GradeAttendance>
            lstGradeCfg, List<Att_Grade> lstGrade, DateTime BeginYear, DateTime EndYear, List<Att_LeaveDayInfo> lstLeaveAnl,
            List<Att_AnnualDetail> lstAnnualDetailInDB, Att_AnnualLeave AnnualLeave, List<Att_RosterInfo> lstRosterInYearIn,
            List<Att_RosterGroup> lstRosterGroup, List<Cat_DayOff> lstDayOff,
            bool IsFrom1To31, Cat_Position Position, List<Sys_AllSetting> lstAllSetting, List<Hre_HDTJob> lstHDTJob, out List<Att_AnnualDetail> AnalyzeAnnualDetailPerProfile_Update, string userLogin)
        {
            AnalyzeAnnualDetailPerProfile_Update = new List<Att_AnnualDetail>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Roster = new CustomBaseRepository<Att_Roster>(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();

                var lstRosterID = lstRosterInYearIn.Select(s => s.ID).ToList();
                var lstRosterInYear = repoAtt_Roster.FindBy(s => lstRosterID.Contains(s.ID)).ToList();

                List<Att_AnnualDetail> lstResult = new List<Att_AnnualDetail>();
                double leaveBeginYearToMonth = 0;
                double leaveBeginYearToMonth_Init = 0;
                string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString();
                List<Att_Roster> lstRoster_byProfile = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type != E_ROSTERGROUP).ToList();
                List<Att_Roster> lstRosterTypeGroup = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type == E_ROSTERGROUP).ToList();

                for (DateTime Month = BeginYear; Month <= EndYear; Month = Month.AddMonths(1))
                {
                    var gradeByProfileByTime = lstGrade.Where(m => m.ProfileID == Profile.ID && m.MonthStart <= Month).OrderByDescending(m => m.MonthStart).FirstOrDefault();
                    if (gradeByProfileByTime == null)
                        continue;
                    var GradeCfg = lstGradeCfg.Where(m => m.ID == gradeByProfileByTime.GradeAttendanceID).FirstOrDefault();
                    if (GradeCfg == null)
                        continue;

                    DateTime BeginMonth = Month;
                    DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1);
                    if (!IsFrom1To31)
                    {
                        Att_AttendanceServices.GetRangeMaxMinGrade(new List<Cat_GradeAttendance>() { GradeCfg }, Month, out BeginMonth, out EndMonth);
                    }

                    int AnnualLeaveMonthStart = AnnualLeave != null ? AnnualLeave.MonthStart : 1;
                    double AnnualLeaveInitAnlValue = AnnualLeave != null ? AnnualLeave.InitAnlValue : 0;

                    double Availale = Att_AttendanceLib.GetAnnualLeaveReceive(BeginYear.Year, Month, GradeCfg, Profile.DateHire,
                        Profile.DateEndProbation, Profile.DateQuit, AnnualLeaveMonthStart, AnnualLeaveInitAnlValue, Position, Profile,
                        lstLeaveAnl, lstAllSetting, lstHDTJob, lstDayOff.Select(m => m.DateOff).ToList(), lstLeaveAnl, userLogin);
                    double LeaveInMonth = 0;
                    List<Att_LeaveDayInfo> lstAnlInMonth = lstLeaveAnl.Where(m => m.ProfileID == Profile.ID && m.DateStart <= EndMonth && m.DateEnd >= BeginMonth).ToList();
                    foreach (var item in lstAnlInMonth)
                    {
                        var listRosterEntity = lstRoster_byProfile.Select(d => new Att_RosterEntity
                        {
                            ID = d.ID,
                            ProfileID = d.ProfileID,
                            RosterGroupName = d.RosterGroupName,
                            Type = d.Type,
                            Status = d.Status,
                            DateEnd = d.DateEnd,
                            DateStart = d.DateStart,
                            MonShiftID = d.MonShiftID,
                            TueShiftID = d.TueShiftID,
                            WedShiftID = d.WedShiftID,
                            ThuShiftID = d.ThuShiftID,
                            FriShiftID = d.FriShiftID,
                            SatShiftID = d.SatShiftID,
                            SunShiftID = d.SunShiftID,
                            MonShift2ID = d.MonShiftID,
                            TueShift2ID = d.TueShift2ID,
                            WedShift2ID = d.WedShift2ID,
                            ThuShift2ID = d.ThuShift2ID,
                            FriShift2ID = d.FriShift2ID,
                            SatShift2ID = d.SatShift2ID,
                            SunShift2ID = d.SunShift2ID
                        }).ToList();

                        var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity
                        {
                            ID = d.ID,
                            DateEnd = d.DateEnd,
                            DateStart = d.DateStart,
                            MonShiftID = d.MonShiftID,
                            TueShiftID = d.TueShiftID,
                            WedShiftID = d.WedShiftID,
                            ThuShiftID = d.ThuShiftID,
                            FriShiftID = d.FriShiftID,
                            SatShiftID = d.SatShiftID,
                            SunShiftID = d.SunShiftID,
                            RosterGroupName = d.RosterGroupName
                        }).ToList();

                        if (item.DateStart >= BeginMonth && item.DateEnd <= EndMonth)
                        {
                            //Chi cần lấy TotalDuration hoặc lấy giờ rồi lấy ca
                            if (item.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString())
                            {
                                LeaveInMonth += item.LeaveDays ?? 0;
                            }
                            else
                            {
                                //Lấy ra ca làm việc 
                                DateTime DateBeginLeave = item.DateStart.Date;
                                DateTime DateEndLeave = item.DateEnd.Date;

                                Dictionary<DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBeginLeave, DateEndLeave, listRosterEntity, listRosterGroupEntity, shifts);

                                if (dicShift != null && dicShift.ContainsKey(DateBeginLeave))
                                {
                                    Cat_Shift shift = dicShift[DateBeginLeave];
                                    if (shift != null)
                                    {
                                        double HourWorkday = shift.udStandardWorkHours > 0 ? shift.udStandardWorkHours : 8.0;

                                        LeaveInMonth += item.LeaveHours.Value / HourWorkday;
                                    }
                                }
                            }
                        }
                        else
                        {
                            DateTime DateBegin = BeginMonth > item.DateStart ? BeginMonth : item.DateStart;
                            DateTime DateEnd = EndMonth < item.DateEnd ? BeginMonth : item.DateEnd;
                            Dictionary<DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBegin, DateEnd, listRosterEntity, listRosterGroupEntity, shifts);
                            for (DateTime dateCheck = DateBegin; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1))
                            {
                                if (Att_WorkDayHelper.IsWorkDay(dateCheck, GradeCfg, dicShift, lstDayOff) && !lstDayOff.Any(m => m.DateOff == dateCheck))
                                {
                                    LeaveInMonth++;
                                }
                            }
                        }
                    }
                    Att_AnnualDetail AnnualDetail = lstAnnualDetailInDB.Where(m => m.ProfileID == Profile.ID && m.MonthYear == Month).FirstOrDefault();
                    bool isNew = false;
                    if (AnnualDetail == null)
                    {
                        isNew = true;
                        AnnualDetail = new Att_AnnualDetail();
                    }
                    else
                    {
                        AnalyzeAnnualDetailPerProfile_Update.Add(AnnualDetail);
                    }


                    if (Profile.DateQuit != null)
                    {
                        DateTime MonthQuit = Profile.DateQuit.Value.Day >= 15 ? Profile.DateQuit.Value.AddMonths(1) : Profile.DateQuit.Value;
                        MonthQuit = new DateTime(MonthQuit.Year, MonthQuit.Month, 1);
                        if (Month >= MonthQuit)
                        {
                            AnnualDetail.IsDelete = true;
                        }
                    }
                    AnnualDetail.Available = Availale;
                    AnnualDetail.InitAvailable = AnnualLeave == null ? 0 : AnnualLeave.InitAnlValue;
                    AnnualDetail.ProfileID = Profile.ID;
                    //AnnualDetail.Hre_Profile = Profile.CopyData<Hre_Profile>();
                    AnnualDetail.Year = BeginYear.Year;
                    AnnualDetail.MonthYear = Month;
                    AnnualDetail.MonthBeginInYear = MonthStartAnl; //todo: Phần tử này để trong cấu hình chung
                    if (AnnualLeave != null && AnnualLeave.MonthResetAnlOfBeforeYear != null)
                    {
                        AnnualDetail.MonthResetInitAvailable = AnnualLeave.MonthResetAnlOfBeforeYear.Value;//todo: MonthReset Này để trong chế độ lương
                    }
                    else
                    {
                        AnnualDetail.MonthResetInitAvailable = 12;//todo: MonthReset Này để trong chế độ lương
                    }
                    AnnualDetail.MonthStartProfile = AnnualLeave == null ? 1 : AnnualLeave.MonthStart;
                    if (AnnualDetail.MonthResetInitAvailable != null && AnnualDetail.MonthResetInitAvailable != 12 && AnnualDetail.Year != null)
                    {
                        DateTime MonthReset = new DateTime(AnnualDetail.Year.Value, AnnualDetail.MonthResetInitAvailable.Value, 1);
                        AnnualDetail.IsHaveResetInitAvailable = true;
                        if (Month <= MonthReset) //Trong những tháng có
                        {
                            double delta = leaveBeginYearToMonth_Init + LeaveInMonth - AnnualDetail.InitAvailable.Value;
                            if (delta > 0)
                            {
                                AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                                AnnualDetail.LeaveInMonthFromInitAvailable = LeaveInMonth - delta;
                                AnnualDetail.LeaveInMonth = delta;
                                AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                                leaveBeginYearToMonth += delta;
                                leaveBeginYearToMonth_Init += LeaveInMonth - delta;
                            }
                            else
                            {
                                AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                                AnnualDetail.LeaveInMonthFromInitAvailable = LeaveInMonth;
                                AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                                AnnualDetail.LeaveInMonth = 0;
                                leaveBeginYearToMonth_Init += LeaveInMonth;
                            }
                        }
                        else //sau những tháng kho có
                        {
                            AnnualDetail.InitAvailable = 0;
                            AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                            AnnualDetail.LeaveInMonth = LeaveInMonth;
                            leaveBeginYearToMonth += LeaveInMonth;
                        }
                    }
                    else //Bình thường
                    {
                        AnnualDetail.IsHaveResetInitAvailable = false;
                        AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                        AnnualDetail.LeaveInMonth = LeaveInMonth;
                        leaveBeginYearToMonth += LeaveInMonth;
                    }
                    double remain = (AnnualDetail.Available ?? 0) + (AnnualDetail.InitAvailable ?? 0) - (AnnualDetail.TotalLeaveBefFromInitAvailable ?? 0) - (AnnualDetail.LeaveInMonthFromInitAvailable ?? 0) - (AnnualDetail.TotalLeaveBef ?? 0) - (AnnualDetail.LeaveInMonth ?? 0);
                    AnnualDetail.Remain = remain;
                    AnnualDetail.Type = AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
                    if (isNew)
                    {
                        lstResult.Add(AnnualDetail);
                    }
                }
                return lstResult;
            }
        }
コード例 #12
0
ファイル: Att_LeavedayServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// [Hieu.Van] 05/06/2014
        /// Phân Tích Nghỉ Phép Và Trễ Sớm
        /// </summary>
        /// <returns></returns>
        public List<Att_WorkdayEntity> ComputeLeaveLateEarly(DateTime? DateS, DateTime? DateE, List<Hre_ProfileEntity> lstProfileIDsFull, string udType)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                List<Att_WorkdayEntity> lstEntity = new List<Att_WorkdayEntity>();
                List<Guid> lstProfileIDs = lstProfileIDsFull.Select(s => s.ID).ToList();

                if (DateS == null || DateE == null)
                    return lstEntity;
                DateTime DateStart = DateS.Value;
                DateTime DateEnd = DateE.Value.Date.AddDays(1).AddMilliseconds(-1);
                string E_LATE_EARLY = WorkdayType.E_LATE_EARLY.ToString();
                string E_MISS_IN = WorkdayType.E_MISS_IN.ToString();
                string E_MISS_OUT = WorkdayType.E_MISS_OUT.ToString();
                string E_MISS_IN_OUT = WorkdayType.E_MISS_IN_OUT.ToString();
                var repoWorkday = new CustomBaseRepository<Att_Workday>(unitOfWork);

                var lstWorkday = repoWorkday
                    .FindBy(m => m.IsDelete == null
                        && ((m.Type == E_LATE_EARLY && m.LateEarlyDuration != null
                        && m.LateEarlyDuration > 0) || m.InTime1 == null || m.OutTime1 == null)
                        && m.WorkDate >= DateStart && m.WorkDate < DateEnd && lstProfileIDs.Contains(m.ProfileID))
                    .OrderBy(s => s.WorkDate)
                    .ToList().Translate<Att_WorkdayEntity>();

                SetStatusLeaveOnWorkday(lstWorkday);
                List<string> lstTypeData = null;
                if (udType != null)
                {
                    lstTypeData = udType.Split(',').ToList();
                }
                if (lstTypeData != null)
                {
                    if (!lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_LEAVE.ToString()))
                    {
                        lstWorkday = lstWorkday.Where(m => (m.udLeavedayCode1 == null || m.udLeavedayCode1 == string.Empty) && (m.udLeavedayCode2 == null || m.udLeavedayCode2 == string.Empty)).ToList();
                    }
                    if (!lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_NON_LEAVE.ToString()))
                    {
                        lstWorkday = lstWorkday.Where(m => m.udLeavedayCode1 != null || m.udLeavedayCode2 != null).ToList();
                    }
                }


                var repoShift = new Cat_ShiftRepository(unitOfWork);
                var lstShift = repoShift.FindBy(s => s.IsDelete == null).ToList();
                Att_WorkdayEntity entity = null;
                foreach (var workDay in lstWorkday)
                {
                    entity = new Att_WorkdayEntity();
                    if (workDay.ShiftID != null)
                    {
                        var shiftApprove = lstShift.FirstOrDefault(s => s.ID == workDay.ShiftID);
                        entity.ShiftApproveName = shiftApprove != null ? shiftApprove.ShiftName : string.Empty;
                        entity.ShiftName = shiftApprove != null ? shiftApprove.ShiftName : string.Empty;
                        entity.ShiftCode = shiftApprove != null ? shiftApprove.Code : string.Empty;
                    }
                    if (workDay.ProfileID != null)
                    {
                        var profile = lstProfileIDsFull.FirstOrDefault(s => s.ID == workDay.ProfileID);
                        entity.ProfileName = profile != null ? profile.ProfileName : string.Empty;
                        entity.CodeEmp = profile != null ? profile.CodeEmp : string.Empty;
                    }
                    entity.ID = workDay.ID;
                    entity.TotalRow = lstWorkday.Count;
                    entity.WorkDate = workDay.WorkDate;
                    entity.EarlyDuration1 = workDay.EarlyDuration1 ?? 0;
                    entity.EarlyDuration2 = workDay.EarlyDuration2 ?? 0;
                    entity.EarlyDuration3 = workDay.EarlyDuration3 ?? 0;
                    entity.EarlyDuration4 = workDay.EarlyDuration4 ?? 0;
                    entity.FirstInTime = workDay.FirstInTime;
                    entity.InTime1 = workDay.InTime1;
                    entity.InTime2 = workDay.InTime2;
                    entity.InTime3 = workDay.InTime3;
                    entity.InTime4 = workDay.InTime4;
                    entity.LastOutTime = workDay.LastOutTime;
                    entity.LateDuration1 = workDay.LateDuration1 ?? 0;
                    entity.LateDuration2 = workDay.LateDuration2 ?? 0;
                    entity.LateDuration3 = workDay.LateDuration3 ?? 0;
                    entity.LateDuration4 = workDay.LateDuration4 ?? 0;
                    entity.LateEarlyDuration = workDay.LateEarlyDuration ?? 0;
                    entity.OutTime1 = workDay.OutTime1;
                    entity.OutTime2 = workDay.OutTime2;
                    entity.OutTime3 = workDay.OutTime3;
                    entity.OutTime4 = workDay.OutTime4;
                    entity.ProfileID = workDay.ProfileID;
                    entity.ShiftActual = workDay.ShiftActual;
                    entity.ShiftApprove = workDay.ShiftApprove;
                    entity.ShiftID = workDay.ShiftID;
                    // entity.ShiftName = workDay.ShiftName;
                    entity.SrcType = workDay.SrcType;
                    entity.Status = workDay.Status;
                    entity.Type = workDay.Type;
                    entity.UserUpdate = workDay.UserUpdate;
                    entity.DateUpdate = workDay.DateUpdate;
                    entity.WorkDuration = workDay.WorkDuration;

                    entity.udLeavedayCode1 = workDay.udLeavedayCode1;
                    entity.udLeavedayCode2 = workDay.udLeavedayCode2;
                    entity.udLeavedayStatus1 = workDay.udLeavedayStatus1;
                    entity.udLeavedayStatus2 = workDay.udLeavedayStatus2;

                    lstEntity.Add(entity);
                }

                return lstEntity;
            }
        }
コード例 #13
0
ファイル: Att_LeavedayServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Hàm cập nhật lại TotalDuration cho nhân viên
        /// </summary>
        /// <param name="lstLeaveIDs"></param>
        public string UpdateTotalDuration(List<Guid> lstLeaveIDs)
        {
            string message = "";

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Leaveday = new CustomBaseRepository<Att_LeaveDay>(unitOfWork);
                var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork);
                var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork);
                var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork);
                var repoCat_GradeAttendance = new CustomBaseRepository<Cat_GradeAttendance>(unitOfWork);
                var repoHre_WorkHistory = new CustomBaseRepository<Hre_WorkHistory>(unitOfWork);
                var repoCat_DayOff = new CustomBaseRepository<Cat_DayOff>(unitOfWork);
                var repoAtt_Roster = new CustomBaseRepository<Att_Roster>(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();

                List<Att_LeaveDay> lstLeaveDay = repoAtt_Leaveday.FindBy(m => lstLeaveIDs.Contains(m.ID)).ToList<Att_LeaveDay>();
                if (lstLeaveDay == null || lstLeaveDay.Count == 0)
                {
                    message = ConstantMessages.LeavedayIsNotExist.TranslateString();
                    return message;
                }
                foreach (var item in lstLeaveDay)
                {
                    if (item.Status == AttendanceDataStatus.E_FIRST_APPROVED.ToString() || item.Status == AttendanceDataStatus.E_APPROVED.ToString())
                    {
                        message = ConstantMessages.StatusApproveCannotEdit.TranslateString();
                        return message;
                    }
                    if (item.Status == AttendanceDataStatus.E_REJECTED.ToString())
                    {
                        message = ConstantMessages.StatusRejectcannotEdit.TranslateString();
                        return message;
                    }
                }
                List<Cat_LeaveDayType> lstLeaveDayType = repoCat_LeaveDayType.GetAll().ToList<Cat_LeaveDayType>();
                List<Guid> lstProfileIDs = lstLeaveDay.Select(m => m.ProfileID).Distinct().ToList<Guid>();
                List<Hre_Profile> lstProfile = repoHre_Profile.FindBy(m => lstProfileIDs.Contains(m.ID)).ToList<Hre_Profile>();
                DateTime dateMin = lstLeaveDay.Min(m => m.DateStart).Date;
                DateTime dateMax = lstLeaveDay.Max(m => m.DateEnd);
                List<Att_Roster> lstRosterTypeGroup = new List<Att_Roster>();
                List<Att_RosterGroup> lstRosterGroup = new List<Att_RosterGroup>();
                var lstGrade = repoAtt_Grade.FindBy(m => lstProfileIDs.Contains((Guid)m.ProfileID))
                    .Select(m => new { m.ID, m.ProfileID, m.MonthStart, m.GradeAttendanceID })
                    .OrderByDescending(m => m.MonthStart)
                    .ToList();


                List<Cat_GradeAttendance> lstGradeCfg = repoCat_GradeAttendance.GetAll().ToList<Cat_GradeAttendance>();
                List<Hre_WorkHistory> listWorkHistory = repoHre_WorkHistory.FindBy(m => m.DateEffective <= dateMax && lstProfileIDs.Contains(m.ProfileID)).OrderByDescending(m => m.DateEffective).ToList<Hre_WorkHistory>();
                GetRosterGroup(lstProfileIDs, dateMin, dateMax, out lstRosterTypeGroup, out lstRosterGroup);
                List<Cat_DayOff> lstHoliday = repoCat_DayOff.GetAll().ToList<Cat_DayOff>();
                string E_APPROVED = RosterStatus.E_APPROVED.ToString();
                string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString();
                List<Att_Roster> lstRoster = repoAtt_Roster.FindBy(m => m.Status == E_APPROVED && m.DateStart <= dateMax && m.DateEnd >= dateMin && lstProfileIDs.Contains(m.ProfileID)).ToList<Att_Roster>();
                List<DateTime> lstHolidayType = lstHoliday.Select(m => m.DateOff).ToList<DateTime>();
                foreach (var item in lstLeaveDay)
                {
                    if (item.DurationType == null)
                        continue;
                    Cat_LeaveDayType leaveDayType = lstLeaveDayType.Where(m => m.ID == item.LeaveDayTypeID).FirstOrDefault();
                    if (leaveDayType == null)
                        continue;
                    Hre_Profile profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault();
                    if (profile == null)
                        continue;

                    DateTime dateFrom = item.DateStart;
                    DateTime dateTo = item.DateEnd;
                    //dateTo = dateTo.AddDays(1).AddMinutes(-1);



                    Guid? GradeCfgID = lstGrade.Where(m => m.ProfileID == profile.ID && m.MonthStart <= dateTo).Select(m => m.GradeAttendanceID).FirstOrDefault();
                    Cat_GradeAttendance gradeCfg = lstGradeCfg.Where(m => m.ID == GradeCfgID).FirstOrDefault();
                    List<Att_Roster> lstRosterByProfile = lstRoster.Where(m => m.ProfileID == profile.ID).ToList();
                    List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(m => m.ProfileID == profile.ID && m.DateEffective < dateTo).ToList();
                    List<Att_Roster> lstRosterByProfileTypeGroup = lstRosterByProfile.Where(m => m.Type == E_ROSTERGROUP).ToList();

                    AnalyseTotalLeaveDaysAndHours(item, leaveDayType, profile, gradeCfg, lstRosterByProfile, lstRosterGroup, listWorkHistoryByProfile, lstHoliday, shifts);
                    string LeaveDayTypeCode = leaveDayType.Code;

                    if (item.DurationType == null)
                    {
                        item.DurationType = LeaveDayDurationType.E_FULLSHIFT.ToString();
                    }
                    double Totalduration = 0;
                    bool isSetFullLeaveDay = false;
                    for (DateTime idx = dateFrom.Date; idx <= dateTo.Date; idx = idx.AddDays(1))
                    {
                        if (!string.IsNullOrEmpty(LeaveDayTypeCode) && (LeaveDayTypeCode == "SICK"
                                        || LeaveDayTypeCode == "PRG"
                                        || LeaveDayTypeCode == "SU"
                                        || LeaveDayTypeCode == "SD"
                                        || LeaveDayTypeCode == "D"
                                        || LeaveDayTypeCode == "DP"
                                        || LeaveDayTypeCode == "PSN"
                                        || LeaveDayTypeCode == "M"
                                        || LeaveDayTypeCode == "DSP"))
                        {
                            if (!lstHolidayType.Any(m => m == idx))
                            {
                                Totalduration += 1;
                            }
                            isSetFullLeaveDay = true;
                        }

                    }
                    if (isSetFullLeaveDay == false)
                    {
                        if (gradeCfg == null)
                        {
                            message = ConstantMessages.GradeAttendanceIsNotExist.TranslateString();
                            return message;
                        }

                        var listRosterEntity = lstRosterByProfile.Select(d => new Att_RosterEntity
                        {
                            ID = d.ID,
                            ProfileID = d.ProfileID,
                            RosterGroupName = d.RosterGroupName,
                            Type = d.Type,
                            Status = d.Status,
                            DateEnd = d.DateEnd,
                            DateStart = d.DateStart,
                            MonShiftID = d.MonShiftID,
                            TueShiftID = d.TueShiftID,
                            WedShiftID = d.WedShiftID,
                            ThuShiftID = d.ThuShiftID,
                            FriShiftID = d.FriShiftID,
                            SatShiftID = d.SatShiftID,
                            SunShiftID = d.SunShiftID,
                            MonShift2ID = d.MonShiftID,
                            TueShift2ID = d.TueShift2ID,
                            WedShift2ID = d.WedShift2ID,
                            ThuShift2ID = d.ThuShift2ID,
                            FriShift2ID = d.FriShift2ID,
                            SatShift2ID = d.SatShift2ID,
                            SunShift2ID = d.SunShift2ID
                        }).ToList();

                        var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity
                        {
                            ID = d.ID,
                            DateEnd = d.DateEnd,
                            DateStart = d.DateStart,
                            MonShiftID = d.MonShiftID,
                            TueShiftID = d.TueShiftID,
                            WedShiftID = d.WedShiftID,
                            ThuShiftID = d.ThuShiftID,
                            FriShiftID = d.FriShiftID,
                            SatShiftID = d.SatShiftID,
                            SunShiftID = d.SunShiftID,
                            RosterGroupName = d.RosterGroupName
                        }).ToList();

                        Dictionary<DateTime, Cat_Shift> listMonthShifts = Att_AttendanceLib.GetDailyShifts(profile != null ? profile.ID : Guid.Empty, dateFrom, dateTo, listRosterEntity, listRosterGroupEntity, shifts);
                        for (DateTime idx = dateFrom.Date; idx <= dateTo.Date; idx = idx.AddDays(1))
                        {
                            if (gradeCfg != null && Att_WorkDayHelper.IsWorkDay(idx, gradeCfg, listMonthShifts, lstHoliday))
                            {
                                Totalduration += 1;
                            }
                        }
                    }

                    if (item.LeaveDays.HasChanged(Totalduration))
                    {
                        item.LeaveDays = Totalduration;
                        item.LeaveHours = 8;
                    }

                }

                unitOfWork.SaveChanges();
                message = ConstantMessages.Succeed.TranslateString();
                return message;
            }


















        }
コード例 #14
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
                }
            }
        }
コード例 #15
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        public DataTable GetReportDetailedMonthlyStay(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> profiles, string orgStructureID, bool isIncludeQuitEmp, Guid[] leaveDayTypeIDs, string codeEmp, bool isNotAllowZero, string userExport, bool IsCreateTemplate, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var baseservice = new BaseService();
                string key = OverTimeStatus.E_APPROVED.ToString();
                DataTable table = CreateReportDetailedMonthlyStaySchema(leaveDayTypeIDs, dateStart, dateEnd);
                if (IsCreateTemplate)
                {
                    return table.ConfigTable();
                }
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork);
                var repoAtt_Roster = new Att_RosterRepository(unitOfWork);
                var repoCat_LeaveDayTypeRepository = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork);
                var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var repoCat_GradeAtt = new Cat_GradeAttendanceRepository(unitOfWork);
                var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork);
                var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork);


                List<Guid> lstProfileIDs = profiles.Select(s => s.ID).ToList();
                List<Att_LeaveDayEntity> leaveDays = new List<Att_LeaveDayEntity>();
                List<Cat_LeaveDayType> leavedaytypes = new List<Cat_LeaveDayType>();
                string status = string.Empty;
                List<object> para = new List<object>();
                para.AddRange(new object[3]);
                para[0] = (object)orgStructureID;
                para[1] = dateStart;
                para[2] = dateEnd;
                if (lstProfileIDs != null && lstProfileIDs.Count > 0)
                {
                    leaveDays = baseservice.GetData<Att_LeaveDayEntity>(para, ConstantSql.hrm_att_getdata_LeaveDay, UserLogin, ref status).Where(s => s.Status == key).ToList();
                }
                else
                {
                    return table.ConfigTable();

                }

                //[Tho.Bui] Get LeavedayR=type
                if (leaveDays != null && leaveDays.Count > 0)
                {
                    List<Guid> lstLDTinLD = leaveDays.Select(s => s.LeaveDayTypeID).Distinct().ToList();
                    leavedaytypes = repoCat_LeaveDayTypeRepository.FindBy(s => s.IsDelete == null && lstLDTinLD.Contains(s.ID)).ToList();
                    List<Guid> leavedayguid = leaveDays.Select(s => s.LeaveDayTypeID).ToList();
                    leavedaytypes = leavedaytypes.Where(s => leavedayguid.Contains(s.ID)).ToList();
                }
                var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList();

                var rosterStatus = RosterStatus.E_APPROVED.ToString();
                var _rosters = new List<Att_Roster>();
                foreach (var tempProfileIds in lstProfileIDs.Chunk(1000))
                {
                    _rosters.AddRange(unitOfWork.CreateQueryable<Att_Roster>(Guid.Empty, d => tempProfileIds.Contains(d.ProfileID) && d.Status == rosterStatus && d.DateStart <= dateEnd && d.DateEnd >= dateStart).ToList());
                }
                var rosters = new List<Att_RosterEntity>();
                if (_rosters.Count > 0)
                    rosters = _rosters.Translate<Att_RosterEntity>();
                var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.Code, s.ID, s.PaidRate, s.LeaveDayTypeName }).ToList();
                var leavdayPadidIDs = leavedayTypes.Where(s => s.PaidRate > 0).Select(s => s.ID).ToList();
                List<Guid> guids = profiles.Select(s => s.ID).ToList();
                leaveDays = leaveDays.Where(s => guids.Contains(s.ProfileID)).ToList();

                if (leaveDayTypeIDs != null)
                {
                    leaveDays = leaveDays.Where(s => leaveDayTypeIDs.Contains(s.LeaveDayTypeID)).ToList();
                    profileIds = leaveDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }
                if (!isIncludeQuitEmp)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                //var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();
                var shifts = unitOfWork.CreateQueryable<Cat_Shift>(Guid.Empty).ToList().Translate<Cat_ShiftEntity>();

                List<string> codeRejects = new List<string>();
                codeRejects.Add("SICK");
                codeRejects.Add("SU");
                codeRejects.Add("SD");
                codeRejects.Add("D");
                codeRejects.Add("DP");
                codeRejects.Add("PSN");
                codeRejects.Add("DSP");
                codeRejects.Add("M");
                List<Guid> leaveDayTypeRejectIDs = leavedayTypes.Where(s => codeRejects.Contains(s.Code)).Select(s => s.ID).ToList();

                if (isNotAllowZero)
                {
                    var profileIDs = leaveDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIDs.Contains(s.ID)).ToList();
                }
                #region sai xong xóa
                string CodeEmpTest = string.Empty;
                if (CodeEmpTest != string.Empty)
                {
                    char[] ext = new char[] { ';', ',' };
                    List<string> lstCodeEmpTest = CodeEmpTest.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
                    profiles = profiles.Where(m => lstCodeEmpTest.Contains(m.CodeEmp)).ToList();
                }
                #endregion

                var leveDayIDs = leaveDays.Select(s => s.LeaveDayTypeID).ToList();
                leavedayTypes = leavedayTypes.Where(s => leveDayIDs.Contains(s.ID)).ToList();
                var holidayDates = repoCat_DayOff.FindBy(hol => hol.DateOff >= dateStart && hol.DateOff <= dateEnd).Select(s => s.DateOff).ToList();
                holidayDates = holidayDates.Select(s => s.Date).ToList();

                var lstRosterGroup = unitOfWork.CreateQueryable<Att_RosterGroup>(Guid.Empty, s => s.DateStart != null && s.DateStart >= dateStart && s.DateEnd != null && s.DateEnd <= dateEnd).ToList().Translate<Att_RosterGroupEntity>();

                foreach (var profile in profiles)
                {
                    var rosterProfiles = rosters.Where(s => s.ProfileID == profile.ID).ToList();
                    List<DateTime> workDayDates = new List<DateTime>();
                    foreach (var roster in rosterProfiles)
                    {
                        for (DateTime date = roster.DateStart; date <= roster.DateEnd; date = date.AddDays(1))
                        {
                            workDayDates.Add(date.Date);
                        }
                    }
                    workDayDates = workDayDates.Where(s => !holidayDates.Contains(s.Date)).ToList();

                    DataRow row = table.NewRow();
                    var leaveDay = leaveDays.FirstOrDefault(s => s.ProfileID == profile.ID);
                    var LeaveDayType = leavedaytypes.FirstOrDefault(s => s.ID != Guid.Empty && leaveDay != null && s.ID == leaveDay.LeaveDayTypeID);

                    row[Att_ReportDetailedMonthlyStayEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Att_ReportDetailedMonthlyStayEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    if (profile.E_COMPANY != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_COMPANY] = profile.E_COMPANY;
                    if (profile.E_BRANCH != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_BRANCH] = profile.E_BRANCH;
                    if (profile.E_UNIT != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_UNIT] = profile.E_UNIT;
                    if (profile.E_DIVISION != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_DIVISION] = profile.E_DIVISION;
                    if (profile.E_DEPARTMENT != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_DEPARTMENT] = profile.E_DEPARTMENT;
                    if (profile.E_TEAM != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_TEAM] = profile.E_TEAM;
                    if (profile.E_SECTION != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.E_SECTION] = profile.E_SECTION;

                    if (profile.JobTitleName != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.JobTitleName] = profile.JobTitleName;
                    if (profile.PositionName != null)
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.PositionName] = profile.PositionName;

                    row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateFrom] = dateStart;
                    row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateTo] = dateEnd;
                    row[Att_ReportDetailedMonthlyStayEntity.FieldNames.UserExport] = userExport;
                    row[Att_ReportDetailedMonthlyStayEntity.FieldNames.DateExport] = DateTime.Today;
                    var leadayProfiles = leaveDays.Where(s => s.ProfileID == profile.ID).ToList();
                    var ledayeTyepIDs = leadayProfiles.Select(s => s.LeaveDayTypeID).ToList();
                    double sumPaid = 0;
                    foreach (var leadayType in leavedayTypes.Where(s => ledayeTyepIDs.Contains(s.ID)).ToList())
                    {
                        double sum = 0;
                        var leavdayProfiles = leadayProfiles.Where(s => s.LeaveDayTypeID == leadayType.ID).ToList();
                        foreach (var leavdayProfile in leavdayProfiles)
                        {
                            var DateEnd = leavdayProfile.DateEnd;
                            if (DateEnd > dateEnd)
                            {
                                DateEnd = dateEnd;
                            }
                            for (DateTime date = leavdayProfile.DateStart; date <= DateEnd; date = date.AddDays(1))
                            {
                                bool isWorkDay = workDayDates.Contains(date);
                                if (!isWorkDay)// neu ngay do ko phai ngay di lam
                                {
                                    if (leaveDayTypeRejectIDs.Contains(leavdayProfile.LeaveDayTypeID))// neu ngay do la ngay nghi dc xem la ko xem ca or ngay nghi
                                    {
                                        isWorkDay = true;
                                    }
                                }
                                if (isWorkDay)
                                {
                                    if (leavdayProfile.Duration > 0)
                                    {
                                        //sum++; 
                                        sum += leavdayProfile.Duration;
                                    }
                                    if (leavdayPadidIDs.Contains(leavdayProfile.LeaveDayTypeID))
                                    {
                                        sumPaid += leadayType.PaidRate;
                                        //sumPaid++;
                                    }
                                }
                            }
                        }
                        row[leadayType.Code] = sum > 0 ? (object)sum : DBNull.Value;
                        row[Att_ReportDetailedMonthlyStayEntity.FieldNames.Paid] = sumPaid > 0 ? (object)sumPaid : DBNull.Value;
                    }
                    #region tinh so gio nghi tung ngay cua nhan vien
                    var leavdayByProfile = leadayProfiles.Where(s => s.ProfileID == profile.ID).ToList();
                    Dictionary<DateTime, List<Guid?>> tempShiftByDate = new Dictionary<DateTime, List<Guid?>>();
                    tempShiftByDate = Att_AttendanceLib.GetDailyShifts(dateStart, dateEnd, profile.ID, rosterProfiles, lstRosterGroup);
                    foreach (var leavdayProfile in leavdayByProfile)
                    {
                        for (DateTime date = dateStart; date < dateEnd; date = date.AddDays(1))
                        {
                            bool isWorkDay = workDayDates.Contains(date);
                            if (isWorkDay)
                            {
                                //lay ca lam viec cua nhan vien
                                if (tempShiftByDate != null)
                                {
                                    var lstShiftID = tempShiftByDate.Where(s => s.Key == date).SelectMany(s => s.Value).ToList();
                                    if (lstShiftID.Count > 0)
                                    {
                                        var lstShiftProfileByDate = shifts.Where(s => s.WorkHours != null && lstShiftID.Contains(s.ID)).ToList();
                                        double? _tempWorkHour = 0;
                                        _tempWorkHour = lstShiftProfileByDate.Sum(s => s.WorkHours);
                                        if (_tempWorkHour > 0)
                                        {
                                            row["Day" + date.Day.ToString()] = _tempWorkHour;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    table.Rows.Add(row);
                }
                var configs = new Dictionary<string, Dictionary<string, object>>();
                var config = new Dictionary<string, object>();
                var confighidden = new Dictionary<string, object>();
                confighidden.Add("hidden", true);
                //var configdate = new Dictionary<string, object>();
                //configdate.Add("format", "{0:dd/MM/yyyy}");
                config.Add("width", 100);
                //config.Add("locked", true);
                if (!configs.ContainsKey("CodeEmp"))
                    configs.Add("CodeEmp", config);
                if (!configs.ContainsKey("DepartmentCode"))
                    configs.Add("DepartmentCode", config);
                if (!configs.ContainsKey("PositionName"))
                    configs.Add("PositionName", config);
                if (!configs.ContainsKey("JobTitleName"))
                    configs.Add("JobTitleName", config);
                if (!configs.ContainsKey("Paid"))
                    configs.Add("Paid", config);
                if (!configs.ContainsKey("BranchCode"))
                    configs.Add("BranchCode", config);
                if (!configs.ContainsKey("TeamCode"))
                    configs.Add("TeamCode", config);
                if (!configs.ContainsKey("SectionCode"))
                    configs.Add("SectionCode", config);
                if (!configs.ContainsKey("OrgName"))
                    configs.Add("OrgName", config);
                if (!configs.ContainsKey("TeamName"))
                    configs.Add("TeamName", config);
                if (!configs.ContainsKey("SectionName"))
                    configs.Add("SectionName", config);
                if (!configs.ContainsKey("BranchName"))
                    configs.Add("BranchName", config);
                if (!configs.ContainsKey("DateFrom"))
                    configs.Add("DateFrom", confighidden);
                if (!configs.ContainsKey("DateTo"))
                    configs.Add("DateTo", confighidden);
                if (!configs.ContainsKey("UserExport"))
                    configs.Add("UserExport", confighidden);
                if (!configs.ContainsKey("DateExport"))
                    configs.Add("DateExport", confighidden);

                foreach (var leavdayType in leavedayTypes)
                {
                    if (!configs.ContainsKey(leavdayType.Code))
                        configs.Add(leavdayType.Code, config);
                }

                return table.ConfigTable(configs);
            }

        }
コード例 #16
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        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);
            }
        }
コード例 #17
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Lấy Dữ Liệu BC GetReportDetailForgetCard
        /// </summary>
        /// <returns></returns>
        public DataTable GetReportDetailForgetCard(DateTime? DateFrom, DateTime? DateTo, List<Guid> lstProfileIDs, List<Guid?> ShiftIDs, string userExport)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                DataTable table = CreateReportDetailForgetCardSchema();
                List<string> lstType = new List<string> { 
                WorkdayType.E_MISS_IN.ToString(),
                WorkdayType.E_MISS_IN_OUT.ToString(),
                WorkdayType.E_MISS_OUT.ToString()
                };

                var workDays = repoAtt_Workday.FindBy(s =>
                  DateFrom <= s.WorkDate && s.WorkDate <= DateTo
                  && lstType.Contains(s.Type))
                  .Select(s => new { s.ProfileID, s.ShiftID, s.WorkDate, s.FirstInTime, s.LastOutTime, s.Type, s.InTime1, s.OutTime1 }).ToList();
                if (lstProfileIDs != null)
                {
                    workDays = workDays.Where(s => lstProfileIDs.Contains(s.ProfileID)).ToList();
                }

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

                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(s => (s.DateQuit == null || s.DateQuit > DateTo) && 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.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.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.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();

                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.GetAll().ToList();

                if (ShiftIDs[0] != null)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && ShiftIDs.Contains(s.ShiftID.Value)).ToList();
                }

                List<Guid> guids = profiles.Select(s => s.ID).ToList();

                if (guids.Count > 0)
                {
                    workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList();
                }

                foreach (var profile in profiles)
                {
                    for (DateTime date = DateFrom.Value.Date; date <= DateTo; date = date.AddDays(1))
                    {
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date && s.ProfileID == profile.ID).ToList();
                        if (workDayProfiles.Count > 0)
                        {
                            DataRow row = table.NewRow();

                            //var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                            //var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

                            Guid? orgId = 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_ReportDetailForgetCardEntity.FieldNames.GroupCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.Code : string.Empty;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.Division] = orgTeam != null ? orgTeam.Code : string.Empty;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;


                            row[Att_ReportDetailForgetCardEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.ProfileName] = profile.ProfileName;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.DateFrom] = DateFrom;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.DateTo] = DateTo;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.DateExport] = DateTime.Today;
                            row[Att_ReportDetailForgetCardEntity.FieldNames.UserExport] = userExport;

                            var workDay1 = workDayProfiles.FirstOrDefault();
                            row[Att_ReportDetailForgetCardEntity.FieldNames.Date] = date;

                            if (workDay1.ShiftID != null)
                            {
                                var shift = shifts.Where(m => m.ID == workDay1.ShiftID).FirstOrDefault();
                                row[Att_ReportDetailForgetCardEntity.FieldNames.ShiftName] = shift != null ? shift.ShiftName : string.Empty;
                            }
                            if (workDay1.Type == WorkdayType.E_MISS_IN.ToString())
                            {
                                row[Att_ReportDetailForgetCardEntity.FieldNames.OutTime] = workDay1.LastOutTime != null ? workDay1.LastOutTime.Value : DateTime.MinValue;

                            }
                            else if (workDay1.Type == WorkdayType.E_MISS_OUT.ToString())
                            {
                                row[Att_ReportDetailForgetCardEntity.FieldNames.InTime] = workDay1.FirstInTime != null ? workDay1.FirstInTime.Value : DateTime.MaxValue;
                            }


                            row[Att_ReportDetailForgetCardEntity.FieldNames.ScanType] = workDay1.Type;
                            table.Rows.Add(row);

                        }
                    }
                }


                return table;
            }

            #region Code Cũ
            //#region logic hien tai
            ////1. Chi tinh dc workday thieu in thieu out hoac thieu in out
            ////2. khong tinh dc nhưng quẹt thẻ da them bang tay boi vi khi them bang tay thì workday da du inout hok len dc bc
            //#endregion
            //List<Att_ReportDetailForgetCardEntity> lstReportDetailForgetCardEntity = new List<Att_ReportDetailForgetCardEntity>();
            //string E_MISS_IN = WorkdayType.E_MISS_IN.ToString();
            //string E_MISS_OUT = WorkdayType.E_MISS_OUT.ToString();
            //string E_MISS_IN_OUT = WorkdayType.E_MISS_IN_OUT.ToString();
            //#region getData
            //var lstWorkday = new List<Att_Workday>().Select(m => new { m.ProfileID, m.WorkDate, m.ShiftID, m.Type, m.FirstInTime, m.LastOutTime }).ToList();
            //using (var context = new VnrHrmDataContext())
            //{
            //    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
            //    var repo = new Att_WorkDayRepository(unitOfWork);
            //    if (lstProfileIDs != null && lstProfileIDs.Count > 0)
            //    {
            //        lstWorkday = repo.FindBy(m => m.WorkDate >= DateFrom && m.WorkDate < DateTo
            //        && m.ProfileID != null && lstProfileIDs.Contains(m.ProfileID)
            //        && (m.Type == E_MISS_IN || m.Type == E_MISS_OUT || m.Type == E_MISS_IN_OUT))
            //            .Select(m => new { m.ProfileID, m.WorkDate, m.ShiftID, m.Type, m.FirstInTime, m.LastOutTime }).ToList();
            //    }
            //    else
            //    {
            //        lstWorkday = repo.FindBy(m => (m.WorkDate >= DateFrom && m.WorkDate < DateTo)
            //       && (m.Type == E_MISS_IN || m.Type == E_MISS_OUT || m.Type == E_MISS_IN_OUT))
            //           .Select(m => new { m.ProfileID, m.WorkDate, m.ShiftID, m.Type, m.FirstInTime, m.LastOutTime }).ToList();
            //    }
            //}
            //List<Guid> lstprofilebyworkday = lstWorkday.Select(m => m.ProfileID).ToList();
            //var lstProfile = new List<Hre_Profile>().Select(m => new { m.ID, m.OrgStructureID, m.CodeEmp, m.ProfileName });
            //using (var context = new VnrHrmDataContext())
            //{
            //    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
            //    var repo = new Hre_ProfileRepository(unitOfWork);
            //    if (lstprofilebyworkday != null && lstprofilebyworkday.Count > 0)
            //    {
            //        lstProfile = repo.FindBy(m => lstprofilebyworkday.Contains(m.ID)).Select(m => new { m.ID, m.OrgStructureID, m.CodeEmp, m.ProfileName }).ToList();
            //    }
            //}

            //var lstShift = new List<Cat_Shift>().Select(m => new { m.ID, m.ShiftName, m.InTime, m.CoOut }).ToList();
            //using (var context = new VnrHrmDataContext())
            //{
            //    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
            //    var repo = new Cat_ShiftRepository(unitOfWork);
            //    lstShift = repo.GetAll().Select(m => new { m.ID, m.ShiftName, m.InTime, m.CoOut }).ToList();
            //}

            //#endregion
            //#region get org nhieu cap
            //List<OrgTiny> lstOrgAll = new List<OrgTiny>();
            //using (var context = new VnrHrmDataContext())
            //{
            //    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
            //    var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
            //    lstOrgAll = repoOrg.FindBy(s => s.IsDelete == null).Select(m => new OrgTiny { ID = m.ID, OrgCode = m.Code, OrgName = m.OrgStructureName, ParentID = m.ParentID, TypeID = m.TypeID }).ToList();
            //}
            //List<Guid?> lstOrgIDs = lstProfile.Select(m => m.OrgStructureID).Distinct().ToList();
            //Dictionary<Guid?, OrgLevelTypeName> OrgNameAllLevel = Cat_OrgStructureServices.GetFullLinkOrg(lstOrgIDs, lstOrgAll);
            //#endregion
            //foreach (var ProfileID in lstprofilebyworkday)
            //{
            //    if (ProfileID == null)
            //        continue;
            //    var lstWorkdayByProfile = lstWorkday.Where(m => m.ProfileID == ProfileID).ToList();
            //    foreach (var WorkdayByProfile in lstWorkdayByProfile)
            //    {
            //        if (WorkdayByProfile.WorkDate == null)
            //        {
            //            continue;
            //        }
            //        Att_ReportDetailForgetCardEntity ReportDetailForgetCardEntity = new Att_ReportDetailForgetCardEntity();
            //        var profileInfomation = lstProfile.Where(m => m.ID == ProfileID).FirstOrDefault();
            //        #region thông tin chung
            //        ReportDetailForgetCardEntity.DateFrom = DateFrom;
            //        ReportDetailForgetCardEntity.DateTo = DateTo;
            //        #endregion
            //        #region thông tin Profile
            //        if (profileInfomation != null)
            //        {
            //            ReportDetailForgetCardEntity.ProfileName = profileInfomation.ProfileName;
            //            ReportDetailForgetCardEntity.CodeEmp = profileInfomation.CodeEmp;
            //        }
            //        #endregion
            //        #region thông tin Phòng ban
            //        Guid? orgID = null;
            //        if (profileInfomation != null)
            //        {
            //            orgID = profileInfomation.OrgStructureID;
            //        }
            //        if (orgID != null)
            //        {
            //            var orgByProfile = lstOrgAll.Where(m => m.ID == orgID).FirstOrDefault();
            //            if (orgByProfile != null)
            //            {
            //                ReportDetailForgetCardEntity.DepartmentName = orgByProfile.OrgName;
            //                ReportDetailForgetCardEntity.Division = orgByProfile.OrgCode;
            //            }

            //        }
            //        if (orgID != null && OrgNameAllLevel.ContainsKey(orgID))
            //        {
            //            var OrgNameFull = OrgNameAllLevel[orgID];
            //            if (OrgNameFull != null)
            //            {
            //                ReportDetailForgetCardEntity.SectionCode = OrgNameFull.SectionCode;
            //                ReportDetailForgetCardEntity.GroupCode = OrgNameFull.TeamCode;
            //            }
            //        }
            //        #endregion
            //        #region thông tin chấm công
            //        ReportDetailForgetCardEntity.Date = WorkdayByProfile.WorkDate;
            //        if (WorkdayByProfile.ShiftID != null)
            //        {
            //            var Shift = lstShift.Where(m => m.ID == WorkdayByProfile.ShiftID).FirstOrDefault();
            //            if (Shift != null)
            //            {
            //                ReportDetailForgetCardEntity.ShiftName = Shift.ShiftName;
            //            }
            //        }
            //        #endregion
            //        #region thoi gian vao ra
            //        if (WorkdayByProfile.Type == E_MISS_IN)
            //        {
            //            ReportDetailForgetCardEntity.OutTime = WorkdayByProfile.LastOutTime;
            //        }
            //        else if (WorkdayByProfile.Type == E_MISS_OUT)
            //        {
            //            ReportDetailForgetCardEntity.InTime = WorkdayByProfile.FirstInTime;
            //        }
            //        ReportDetailForgetCardEntity.ScanType = WorkdayByProfile.Type;
            //        #endregion

            //        lstReportDetailForgetCardEntity.Add(ReportDetailForgetCardEntity);
            //    }
            //}

            //return lstReportDetailForgetCardEntity;
            #endregion

        }
コード例 #18
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        public DataTable GetReportGeneralMonthlyAttendance(DateTime? dateStart, DateTime DateTo, string strOrgStructure, List<Hre_ProfileEntity> profiles, Guid[] shiftIDs, Guid[] payrollIDs, string employeeStatus, string groupByType, bool ExcludeIfWorkingDayIsZero, bool isShowOTHourRow, string userExport, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var basesevise = new BaseService();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var repoAtt_Att_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork);
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoCat_Position = new Cat_PositionRepository(unitOfWork);
                var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork);
                var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork);
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork);
                var repoAtt_AttendencaTable = new Att_AttendanceTableRepository(unitOfWork);
                var repoAtt_AttendanceItem = new Att_AttendanceTableItemRepository(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var repoAtt_CutOffDuration = new Att_CutOffDurationRepository(unitOfWork);



                //  var monthDuration = dateStart.ToString();
                DataTable table = CreateReportGeneralMonthlyAttendanceSchema(UserLogin);
                dateStart = new DateTime(dateStart.Value.Year, dateStart.Value.Month, 1);
                // Guid? durationID = monthDuration != null ? (Guid?)(object)monthDuration : null;
                DateTime monthEnd = new DateTime(dateStart.Value.Year, dateStart.Value.Month, DateTime.DaysInMonth(dateStart.Value.Year, dateStart.Value.Month));


                // profiles = profiles.Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID, s.PayrollGroupID }).ToList();
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList();
                var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();
                var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.Code, s.ID, s.PaidRate, s.LeaveDayTypeName }).ToList();
                var overtimTypes = repoCat_OvertimeType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.ID, s.Code, s.OvertimeTypeName }).ToList();
                List<Guid> profileIds = profiles.Select(s => s.ID).ToList();
                DateTime dateFrom = dateStart.Value.Date.AddDays(1 - dateStart.Value.Day);
                DateTime dateTo = dateFrom.Date.AddDays(1 - dateFrom.Day).AddMonths(1).AddSeconds(-1);
                string status = string.Empty;
                List<object> para = new List<object>();
                para.AddRange(new object[3]);
                para[0] = strOrgStructure;
                para[1] = dateFrom;
                para[2] = dateTo;
                var workDays = basesevise.GetData<Att_WorkdayEntity>(para, ConstantSql.hrm_att_getdata_Workday, UserLogin, ref status).ToList();
                string groupBy = groupByType != null ? groupByType.ToString() : string.Empty;

                #region DataInfo
                List<object> paratables = new List<object>();
                paratables.AddRange(new object[7]);
                paratables[3] = dateFrom;
                paratables[4] = dateTo;
                paratables[5] = 1;
                paratables[6] = Int32.MaxValue - 1;
                var tableQueryable = basesevise.GetData<Att_AttendanceTableEntity>(paratables, ConstantSql.hrm_att_sp_get_AttendanceTable, UserLogin, ref status).ToList();
                List<object> paratable = new List<object>();
                paratable.AddRange(new object[4]);
                paratable[0] = dateFrom;
                paratable[1] = dateTo;
                paratable[2] = 1;
                paratable[3] = Int32.MaxValue - 1;
                var itemQueryable = basesevise.GetData<Att_AttendanceTableItemEntity>(paratable, ConstantSql.hrm_att_sp_getdata_AttendanceTableItem, UserLogin, ref status).ToList();

                #region durationID
                //if (durationID != null && durationID != Guid.Empty)
                //{
                //    var cutOffDuration = repoAtt_CutOffDuration.FindBy(
                //        d => d.ID == durationID).Select(d => new { d.DateStart, d.DateEnd }).FirstOrDefault();

                //    if (cutOffDuration != null)
                //    {
                //        dateFrom = cutOffDuration.DateStart;
                //        dateTo = cutOffDuration.DateEnd;
                //    }

                //    tableQueryable = tableQueryable.Where(d => d.CutOffDurationID == durationID).ToList();
                //}
                //else
                //{
                // tableQueryable = tableQueryable.Where(d => d.MonthYear == dateFrom).ToList();
                //  }
                #endregion

                tableQueryable = tableQueryable.Where(d => d.MonthYear == dateFrom).ToList();
                #endregion

                if (payrollIDs != null)
                {
                    profiles = profiles.Where(s => s.PayrollGroupID != null && payrollIDs.Contains(s.PayrollGroupID.Value)).ToList();
                }
                if (employeeStatus != null)
                {
                    if (employeeStatus == StatusEmployee.E_WORKING.ToString())
                    {
                        profiles = profiles.Where(pro => (pro.DateQuit == null || pro.DateQuit >= dateTo) && pro.DateHire < dateFrom).ToList();
                    }
                    else if (employeeStatus == StatusEmployee.E_NEWEMPLOYEE.ToString())
                    {
                        profiles = profiles.Where(pro => pro.DateHire <= dateTo && pro.DateHire >= dateFrom).ToList();
                    }
                    else if (employeeStatus == StatusEmployee.E_STOPWORKING.ToString())
                    {
                        profiles = profiles.Where(pro => pro.DateQuit != null && pro.DateQuit.Value <= dateTo && pro.DateQuit.Value >= dateFrom).ToList();
                    }
                    else if (employeeStatus == StatusEmployee.E_WORKINGANDNEW.ToString())
                    {
                        profiles = profiles.Where(pro => pro.DateQuit == null || pro.DateQuit >= dateTo).ToList();
                    }
                }

                profileIds = profiles.Select(d => d.ID).ToList<Guid>();
                tableQueryable = tableQueryable.Where(d => profileIds.Contains(d.ProfileID)).ToList();
                var listAttendanceTable = tableQueryable
                    .Select(d => new
                    {
                        d.ID,
                        d.ProfileID,
                        d.AnlDayAvailable,
                        d.StdWorkDayCount,
                        d.RealWorkDayCount,
                        d.LateEarlyDeductionHours,
                        d.PaidWorkDayCount,
                        d.AnlDayTaken,
                        d.Overtime1Hours,
                        d.Overtime2Hours,
                        d.Overtime3Hours,
                        d.Overtime4Hours,
                        d.Overtime5Hours,
                        d.Overtime6Hours,
                        d.Overtime1Type,
                        d.Overtime2Type,
                        d.Overtime3Type,
                        d.Overtime4Type,
                        d.Overtime5Type,
                        d.Overtime6Type,
                        d.LeaveDay1Hours,
                        d.LeaveDay2Hours,
                        d.LeaveDay3Hours,
                        d.LeaveDay4Hours,
                        d.NightShiftHours,
                        d.LeaveDay1Type,
                        d.LeaveDay2Type,
                        d.LeaveDay3Type,
                        d.LeaveDay4Type,
                    }).ToList();
                profileIds = listAttendanceTable.Select(s => s.ProfileID).ToList();
                List<Guid> listAttendanceTableID = listAttendanceTable.Select(d => d.ID).ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                var listProfileInfo = profiles.Select(d => new
                {
                    d.ID,
                    d.CodeEmp,
                    d.ProfileName,
                    d.DateHire,
                    d.DateQuit,
                    d.LaborType,
                    d.WorkingPlace,
                    d.OrgStructureID,
                    d.WorkPlaceName,
                    d.PositionName,
                    d.JobTitleName,
                    d.EmployeeTypeName,
                    d.OrgStructureName,
                }).ToList();

                itemQueryable = itemQueryable.Where(d => listAttendanceTableID.Contains(d.AttendanceTableID)
                   && d.WorkDate >= dateFrom && d.WorkDate <= dateTo).ToList();

                var listAttendanceTableItem = itemQueryable.Select(d => new
                {
                    d.AttendanceTableID,
                    d.WorkDate,
                    d.OvertimeHours,
                    d.ExtraOvertimeHours,
                    d.ExtraOvertimeHours2,
                    d.ExtraOvertimeHours3,
                    d.WorkPaidHours,
                    d.NightShiftHours,
                    d.ShiftID,
                    d.WorkHourFirstHaftShift,
                    d.WorkHourLastHaftShift,
                    d.LeaveTypeID,
                    d.AvailableHours,

                }).ToList();

                var listLeaveDay = repoAtt_Att_LeaveDay.FindBy(d => profileIds.Contains(d.ProfileID)
                  && dateFrom <= d.DateStart && d.DateEnd <= dateTo).Select(d => new { d.ProfileID, d.Comment }).ToList();
                var listGrade = repoAtt_Grade.FindBy(d => profileIds.Contains(d.ProfileID.Value) && d.IsDelete == null).OrderByDescending(d => d.MonthStart).Select(d =>
                        new { d.ProfileID, d.MonthStart, d.Cat_GradeAttendance.HourOnWorkDate }).ToList();
                var lstShift = repoCat_Shift.FindBy(s => s.IsDelete == null).Select(d => new { d.ID, d.IsDoubleShift, d.Code, d.FirstShiftID, d.LastShiftID }).ToList();
                DataTable table_lstResult = new DataTable();

                #region bang 7 dung store ben sql
                table_lstResult.Columns.Add("ProfileID");
                for (int i = 1; i <= 31; i++)
                {
                    table_lstResult.Columns.Add("Data" + i);
                }
                //lay du lieu bang cat_shift
                //  var lst_CatShift = repoCat_Shift.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.IsDoubleShift, s.Code, s.FirstShiftID, s.LastShiftID }).ToList();
                var lst_CatShift = lstShift.ToList();
                //var lstAttendanceTable = repoAtt_AttendencaTable.FindBy(s => s.IsDelete == null && s.MonthYear == dateFrom && profileIds.Contains(s.ProfileID)).Select(s => new { s.ID, s.ProfileID }).ToList();
                var lstAttendanceTable = listAttendanceTable.ToList();
                var lstAttendanceTableID = lstAttendanceTable.Select(s => s.ID).Distinct().ToList();
                //var lstAttendanceTableItem = repoAtt_AttendanceItem.FindBy(s => s.IsDelete == null && lstAttendanceTableID.Contains(s.AttendanceTableID))
                //    .Select(s => new {s.ID,s.AttendanceTableID,s.LeaveTypeID,s.WorkPaidHours,s.AvailableHours,s.ShiftID,s.WorkHourFirstHaftShift,s.WorkHourLastHaftShift,s.WorkDate }).ToList();
                var lstAttendanceTableItem = listAttendanceTableItem.ToList();
                int countId = lstAttendanceTableID.Count;
                //  DataRow rowlstResult = table_lstResult.NewRow();
                var lstCat_LeaDayType = repoCat_LeaveDayType.FindBy(s => s.IsDelete == null).ToList();
                //while(countId >0)
                //{
                for (int i = countId; i > 0; i--)
                {

                    // }
                    var AttendanceID = lstAttendanceTable.Select(s => s.ID).FirstOrDefault();
                    var ProfileID = lstAttendanceTable.Select(s => s.ProfileID).FirstOrDefault();
                    lstAttendanceTable = lstAttendanceTable.Where(s => s.ID != AttendanceID).ToList();
                    DataRow rowlstResult = table_lstResult.NewRow();
                    rowlstResult["ProfileID"] = ProfileID;
                    //int Numday = 1;
                    //while(Numday <=31)
                    //{
                    for (int Numday = 1; Numday <= 31; Numday++)
                    {

                        // }
                        var tab_AttendanceTableItem = lstAttendanceTableItem.Where(s => s.AttendanceTableID == AttendanceID && s.WorkDate.Day == Numday)
                            .Select(s => new { s.LeaveTypeID, s.WorkPaidHours, s.AvailableHours, s.ShiftID, s.WorkHourFirstHaftShift, s.WorkHourLastHaftShift }).ToList();
                        var leaveTypeID = tab_AttendanceTableItem.Select(s => s.LeaveTypeID).FirstOrDefault();
                        double workPaidHour = tab_AttendanceTableItem.Select(s => s.WorkPaidHours).FirstOrDefault();
                        double available = tab_AttendanceTableItem.Select(s => s.AvailableHours).FirstOrDefault();
                        available = 8;
                        var shiftID = tab_AttendanceTableItem.Select(s => s.ShiftID).FirstOrDefault();
                        var isDoubleShift = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.IsDoubleShift).FirstOrDefault();
                        double? workHourFirstHaftShift = tab_AttendanceTableItem.Select(s => s.WorkHourFirstHaftShift).FirstOrDefault();
                        double? workHourLastHaftShift = tab_AttendanceTableItem.Select(s => s.WorkHourLastHaftShift).FirstOrDefault();
                        string result = string.Empty;
                        if (leaveTypeID != null)
                        {
                            result = lstCat_LeaDayType.Where(s => s.ID == leaveTypeID).Select(s => s.CodeStatistic).ToString();
                        }
                        else
                        {
                            if (isDoubleShift == true)
                            {
                                if (available == workHourFirstHaftShift)
                                {
                                    var firstShiftID = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.FirstShiftID).FirstOrDefault();
                                    result = lst_CatShift.Where(s => s.ID == firstShiftID).Select(s => s.Code).FirstOrDefault();
                                }
                                else
                                {
                                    result = workHourFirstHaftShift.ToString();
                                }
                                if (available == workHourLastHaftShift)
                                {
                                    var lastShiftID = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.LastShiftID).FirstOrDefault();
                                    result = result + "-" + lst_CatShift.Where(s => s.ID == lastShiftID).Select(s => s.Code).FirstOrDefault();
                                }
                                else
                                {
                                    result = result + "-" + workHourLastHaftShift.ToString();
                                }
                            }
                            else
                            {
                                if (available == workPaidHour)
                                {
                                    result = lst_CatShift.Where(s => s.ID == shiftID).Select(s => s.Code).FirstOrDefault();
                                }
                                else
                                {
                                    result = workPaidHour.ToString();
                                }
                            }
                        }
                        rowlstResult["Data" + Numday] = result;
                        //Numday++;
                    }
                    table_lstResult.Rows.Add(rowlstResult);
                    //countId--;
                }
                #endregion
                DateTime DateMin = DateTime.MinValue;
                DateTime DateMax = DateTime.MinValue;
                DateTime? DateS = tableQueryable.Select(m => m.DateStart).FirstOrDefault();
                DateTime? DateE = tableQueryable.Select(m => m.DateEnd).FirstOrDefault();
                if (DateS != null)
                    DateMin = DateS.Value;
                if (DateE != null)
                    DateMax = DateE.Value;
                foreach (var profile in profiles)
                {
                    DataRow row = table.NewRow();
                    var attendanceTable = listAttendanceTable.Where(s => s.ProfileID == profile.ID).FirstOrDefault();
                    Guid? orgId = profile.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);

                    var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                    var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.CodeEmp] = profile.CodeEmp;

                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                    //row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty;
                    //    row[Att_ReportMonthlyTimeSheetEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;

                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty;


                    if (profile.DateHire != null)
                    {
                        row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DateHire] = profile.DateHire.Value;
                    }

                    if (profile.DateQuit != null)
                    {
                        row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DateQuit] = profile.DateQuit.Value;
                    }
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.UserExport] = userExport;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.DateExport] = DateTime.Today;
                    var gradeByProfile = listGrade.Where(d => d.ProfileID == attendanceTable.ProfileID).OrderByDescending(d => d.MonthStart).FirstOrDefault();
                    var listAttendanceTableItemByTable = listAttendanceTableItem.Where(d => d.AttendanceTableID == attendanceTable.ID).ToList();
                    var listLeaveDayByProfile = listLeaveDay.Where(d => d.ProfileID == attendanceTable.ProfileID).ToList();
                    double hourOnWorkDate = gradeByProfile != null ? double.Parse(gradeByProfile.HourOnWorkDate.ToString()) : 1;
                    #region Att_AttendanceTable
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.PaidWorkDayCount] = attendanceTable.PaidWorkDayCount;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.LateEarlyDeductionHours] = attendanceTable.LateEarlyDeductionHours;
                    row[Att_ReportMonthlyTimeSheetEntity.FieldNames.LateEarlyDeductionDays] = attendanceTable.LateEarlyDeductionHours / hourOnWorkDate;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.NightShiftHours] = attendanceTable.NightShiftHours;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.AnlDayAvailable] = attendanceTable.AnlDayAvailable;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.StandardWorkDays] = attendanceTable.StdWorkDayCount;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.RealWorkingDays] = attendanceTable.RealWorkDayCount;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.StandardWorkDaysFormula] = attendanceTable.RealWorkDayCount;
                    row[Att_ReportMonthlyTimeSheetEntity.FieldNames.DateFrom] = DateMin;
                    row[Att_ReportMonthlyTimeSheetEntity.FieldNames.DateTo] = DateMax;
                    if (attendanceTable.AnlDayTaken > 0)
                    {
                        row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.ANL] = attendanceTable.AnlDayTaken;
                    }
                    #endregion
                    #region table_lstResult Att_AttendanceTableItem_Symbol
                    var dtRow = table_lstResult.Rows.OfType<DataRow>().Where(d => d["ProfileID"].GetString() == profile.ID.ToString()).FirstOrDefault();
                    if (dtRow != null)
                    {
                        for (DateTime dateCheck = DateMin; dateCheck < DateMax; dateCheck = dateCheck.AddDays(1))
                        {
                            string Result = string.Empty;
                            switch (dateCheck.Day)
                            {
                                case 1:
                                    Result = dtRow["Data1"].ToString();
                                    break;
                                case 2:
                                    Result = dtRow["Data2"].ToString();
                                    break;
                                case 3:
                                    Result = dtRow["Data3"].ToString();
                                    break;
                                case 4:
                                    Result = dtRow["Data4"].ToString();
                                    break;
                                case 5:
                                    Result = dtRow["Data5"].ToString();
                                    break;
                                case 6:
                                    Result = dtRow["Data6"].ToString();
                                    break;
                                case 7:
                                    Result = dtRow["Data7"].ToString();
                                    break;
                                case 8:
                                    Result = dtRow["Data8"].ToString();
                                    break;
                                case 9:
                                    Result = dtRow["Data9"].ToString();
                                    break;
                                case 10:
                                    Result = dtRow["Data10"].ToString();
                                    break;
                                case 11:
                                    Result = dtRow["Data11"].ToString();
                                    break;
                                case 12:
                                    Result = dtRow["Data12"].ToString();
                                    break;
                                case 13:
                                    Result = dtRow["Data13"].ToString();
                                    break;
                                case 14:
                                    Result = dtRow["Data14"].ToString();
                                    break;
                                case 15:
                                    Result = dtRow["Data15"].ToString();
                                    break;
                                case 16:
                                    Result = dtRow["Data16"].ToString();
                                    break;
                                case 17:
                                    Result = dtRow["Data17"].ToString();
                                    break;
                                case 18:
                                    Result = dtRow["Data18"].ToString();
                                    break;
                                case 19:
                                    Result = dtRow["Data19"].ToString();
                                    break;
                                case 20:
                                    Result = dtRow["Data20"].ToString();
                                    break;
                                case 21:
                                    Result = dtRow["Data21"].ToString();
                                    break;
                                case 22:
                                    Result = dtRow["Data22"].ToString();
                                    break;
                                case 23:
                                    Result = dtRow["Data23"].ToString();
                                    break;
                                case 24:
                                    Result = dtRow["Data24"].ToString();
                                    break;
                                case 25:
                                    Result = dtRow["Data25"].ToString();
                                    break;
                                case 26:
                                    Result = dtRow["Data26"].ToString();
                                    break;
                                case 27:
                                    Result = dtRow["Data27"].ToString();
                                    break;
                                case 28:
                                    Result = dtRow["Data28"].ToString();
                                    break;
                                case 29:
                                    Result = dtRow["Data29"].ToString();
                                    break;
                                case 30:
                                    Result = dtRow["Data30"].ToString();
                                    break;
                                case 31:
                                    Result = dtRow["Data31"].ToString();
                                    break;
                            }
                            //row["Data" + dateCheck.Day] = Result;
                            string day = dateCheck.Day.ToString();
                            row[day] = Result;
                        }
                    }
                    #endregion

                    #region att_AttendanceTableItem
                    int WorkPaidHourOver8 = 0;
                    int NightShiftOver6 = 0;
                    double WorkPaidHours = 0;
                    foreach (var attendanceTableItem in listAttendanceTableItemByTable)
                    {
                        var shift = lstShift.Where(m => m.ID == attendanceTableItem.ShiftID).FirstOrDefault();
                        if (shift != null && shift.IsDoubleShift == true)
                        {
                            if (attendanceTableItem.WorkHourFirstHaftShift >= 8)
                            {
                                WorkPaidHourOver8++;
                            }
                            if (attendanceTableItem.WorkHourLastHaftShift >= 8)
                            {
                                WorkPaidHourOver8++;
                            }
                        }
                        else if (attendanceTableItem.WorkPaidHours >= 8)
                        {
                            WorkPaidHourOver8++;
                        }
                        if (attendanceTableItem.NightShiftHours >= 6)
                        {
                            NightShiftOver6++;
                        }
                        WorkPaidHours += attendanceTableItem.WorkPaidHours;
                    }
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.WorkPaidHourOver8] = WorkPaidHourOver8;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.NightHourOver6] = NightShiftOver6;
                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.WorkPaidHours] = WorkPaidHours;


                    #endregion
                    #region LeaveDayComment

                    string leaveDayComment = string.Empty;

                    foreach (var leaveDay in listLeaveDayByProfile)
                    {
                        if (!string.IsNullOrWhiteSpace(leaveDayComment))
                        {
                            leaveDayComment += ", ";
                        }

                        leaveDayComment += leaveDay.Comment;
                    }

                    row[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.Comment] = leaveDayComment;

                    #endregion
                    #region LeaveDay1Hours
                    //  string LeaveDayTypeCode1 = string.Empty;
                    var LeaveDayTypeCode1 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay1Type).Select(s => s.Code).FirstOrDefault();


                    string leaveDayTypeCode = LeaveDayTypeCode1;
                    var LeaveDayTypeCodeStatistic1 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay1Type).Select(s => s.CodeStatistic).FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic1))
                    {
                        leaveDayTypeCode = LeaveDayTypeCodeStatistic1;
                    }

                    leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_');
                    if (!string.IsNullOrWhiteSpace(leaveDayTypeCode))
                    {
                        if (table.Columns.Contains(leaveDayTypeCode))
                        {
                            row[leaveDayTypeCode] = attendanceTable.LeaveDay1Hours / hourOnWorkDate;
                        }

                        if (table.Columns.Contains("h" + leaveDayTypeCode))
                        {
                            row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay1Hours;
                        }
                    }

                    #endregion
                    #region LeaveDay2Hours

                    leaveDayTypeCode = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay2Type).Select(s => s.Code).FirstOrDefault();

                    var LeaveDayTypeCodeStatistic2 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay2Type).Select(s => s.CodeStatistic).FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic2))
                    {
                        leaveDayTypeCode = LeaveDayTypeCodeStatistic2;
                    }

                    leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_');
                    if (!string.IsNullOrWhiteSpace(leaveDayTypeCode))
                    {
                        if (table.Columns.Contains(leaveDayTypeCode))
                        {
                            row[leaveDayTypeCode] = attendanceTable.LeaveDay2Hours / hourOnWorkDate;
                        }

                        if (table.Columns.Contains("h" + leaveDayTypeCode))
                        {
                            row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay2Hours;
                        }
                    }

                    #endregion
                    #region LeaveDay3Hours

                    leaveDayTypeCode = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay3Type).Select(s => s.Code).FirstOrDefault();
                    var LeaveDayTypeCodeStatistic3 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay3Type).Select(s => s.CodeStatistic).FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic3))
                    {
                        leaveDayTypeCode = LeaveDayTypeCodeStatistic3;
                    }

                    leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_');
                    if (!string.IsNullOrWhiteSpace(leaveDayTypeCode))
                    {
                        if (table.Columns.Contains(leaveDayTypeCode))
                        {
                            row[leaveDayTypeCode] = attendanceTable.LeaveDay3Hours / hourOnWorkDate;
                        }

                        if (table.Columns.Contains("h" + leaveDayTypeCode))
                        {
                            row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay3Hours;
                        }
                    }

                    #endregion
                    #region LeaveDay4Hours

                    leaveDayTypeCode = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay4Type).Select(s => s.Code).FirstOrDefault();
                    var LeaveDayTypeCodeStatistic4 = lstCat_LeaDayType.Where(s => s.ID == attendanceTable.LeaveDay4Type).Select(s => s.CodeStatistic).FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(LeaveDayTypeCodeStatistic4))
                    {
                        leaveDayTypeCode = LeaveDayTypeCodeStatistic4;
                    }

                    leaveDayTypeCode = leaveDayTypeCode.GetString().Replace('.', '_');
                    if (!string.IsNullOrWhiteSpace(leaveDayTypeCode))
                    {
                        if (table.Columns.Contains(leaveDayTypeCode))
                        {
                            row[leaveDayTypeCode] = attendanceTable.LeaveDay4Hours / hourOnWorkDate;
                        }

                        if (table.Columns.Contains("h" + leaveDayTypeCode))
                        {
                            row["h" + leaveDayTypeCode] = attendanceTable.LeaveDay4Hours;
                        }
                    }

                    #endregion
                    #region Cat_Overtime
                    var OvertimeTypeCode1 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime1Type).Select(s => s.Code).FirstOrDefault();
                    string overtimeTypeCode = OvertimeTypeCode1;
                    overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_');

                    if (!string.IsNullOrWhiteSpace(overtimeTypeCode))
                    {
                        if (table.Columns.Contains(overtimeTypeCode))
                        {
                            row[overtimeTypeCode] = attendanceTable.Overtime1Hours;
                        }
                    }
                    var OvertimeTypeCode2 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime2Type).Select(s => s.Code).FirstOrDefault();
                    overtimeTypeCode = OvertimeTypeCode2;
                    overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_');

                    if (!string.IsNullOrWhiteSpace(overtimeTypeCode))
                    {
                        if (table.Columns.Contains(overtimeTypeCode))
                        {
                            row[overtimeTypeCode] = attendanceTable.Overtime2Hours;
                        }
                    }
                    var OvertimeTypeCode3 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime3Type).Select(s => s.Code).FirstOrDefault();
                    overtimeTypeCode = OvertimeTypeCode3;
                    overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_');

                    if (!string.IsNullOrWhiteSpace(overtimeTypeCode))
                    {
                        if (table.Columns.Contains(overtimeTypeCode))
                        {
                            row[overtimeTypeCode] = attendanceTable.Overtime3Hours;
                        }
                    }
                    var OvertimeTypeCode4 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime4Type).Select(s => s.Code).FirstOrDefault();
                    overtimeTypeCode = OvertimeTypeCode4;
                    overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_');

                    if (!string.IsNullOrWhiteSpace(overtimeTypeCode))
                    {
                        if (table.Columns.Contains(overtimeTypeCode))
                        {
                            row[overtimeTypeCode] = attendanceTable.Overtime4Hours;
                        }
                    }
                    var OvertimeTypeCode5 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime5Type).Select(s => s.Code).FirstOrDefault();
                    overtimeTypeCode = OvertimeTypeCode5;
                    overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_');

                    if (!string.IsNullOrWhiteSpace(overtimeTypeCode))
                    {
                        if (table.Columns.Contains(overtimeTypeCode))
                        {
                            row[overtimeTypeCode] = attendanceTable.Overtime5Hours;
                        }
                    }
                    var OvertimeTypeCode6 = overtimTypes.Where(s => s.ID == attendanceTable.Overtime6Type).Select(s => s.Code).FirstOrDefault();
                    overtimeTypeCode = OvertimeTypeCode6;
                    overtimeTypeCode = overtimeTypeCode.GetString().Replace('.', '_');

                    if (!string.IsNullOrWhiteSpace(overtimeTypeCode))
                    {
                        if (table.Columns.Contains(overtimeTypeCode))
                        {
                            row[overtimeTypeCode] = attendanceTable.Overtime6Hours;
                        }
                    }

                    #endregion

                    table.Rows.Add(row);

                    #region second Row (OT HOUR)
                    if (isShowOTHourRow)
                    {
                        DataRow dr_OT_Hour = table.NewRow();

                        foreach (var attendanceTableItem in listAttendanceTableItemByTable)
                        {
                            int date = attendanceTableItem.WorkDate.Day;
                            double totalHourOT = attendanceTableItem.OvertimeHours;
                            totalHourOT += attendanceTableItem.ExtraOvertimeHours;
                            totalHourOT += attendanceTableItem.ExtraOvertimeHours2;
                            totalHourOT += attendanceTableItem.ExtraOvertimeHours3;
                            dr_OT_Hour[Att_ReportGeneralMonthlyAttendanceEntity.FieldNames.Data + date] = totalHourOT;
                        }
                        table.Rows.Add(dr_OT_Hour);
                    }

                    #endregion
                }
                #region Code cu
                #endregion
                var configs = new Dictionary<string, Dictionary<string, object>>();
                var config = new Dictionary<string, object>();
                var configdouble = new Dictionary<string, object>();
                var config90 = new Dictionary<string, object>();
                var config95 = new Dictionary<string, object>();
                var config110 = new Dictionary<string, object>();
                var config81 = new Dictionary<string, object>();
                config81.Add("width", 81);
                for (int i = 1; i <= 31; i++)
                {

                    if (!configs.ContainsKey("_" + i.ToString()))
                        configs.Add("_" + i.ToString(), config81);
                }
                config95.Add("width", 95);
                if (!configs.ContainsKey("DateQuit"))
                    configs.Add("DateQuit", config95);
                config90.Add("width", 90);
                if (!configs.ContainsKey("DateHire"))
                    configs.Add("DateHire", config90);
                if (!configs.ContainsKey("CodeEmp"))
                    configs.Add("CodeEmp", config90);
                if (!configs.ContainsKey("DepartmentCode"))
                    configs.Add("DepartmentCode", config90);
                if (!configs.ContainsKey("BranchCode"))
                    configs.Add("BranchCode", config90);
                if (!configs.ContainsKey("TeamCode"))
                    configs.Add("TeamCode", config90);
                if (!configs.ContainsKey("SectionCode"))
                    configs.Add("SectionCode", config90);
                config110.Add("width", 110);
                if (!configs.ContainsKey("BranchName"))
                    configs.Add("BranchName", config110);
                if (!configs.ContainsKey("TeamName"))
                    configs.Add("TeamName", config110);
                if (!configs.ContainsKey("SectionName"))
                    configs.Add("SectionName", config110);
                if (!configs.ContainsKey("PositionName"))
                    configs.Add("PositionName", config110);
                if (!configs.ContainsKey("JobTitleName"))
                    configs.Add("JobTitleName", config110);

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

                configdouble.Add("format", "{0:n2}");
                if (!configs.ContainsKey("RealWorkingDays"))
                    configs.Add("RealWorkingDays", configdouble);
                if (!configs.ContainsKey("StandardWorkDaysFormula"))
                    configs.Add("StandardWorkDaysFormula", configdouble);
                return table.ConfigTable(configs);

            }

        }
コード例 #19
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// [Hieu.Van] 01/06/2014
        /// Lấy ds tất cả báo cáo Sai ca
        /// </summary>
        /// <returns></returns>
        public List<Att_ReportWrongShiftEntity> GetReportWrongShift(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> lstProfileAll, Guid[] ShiftIDs, bool isIncludeQuitEmp, string userExport)
        {
            using (var context = new VnrHrmDataContext())
            {

                List<Guid> lstProfileIDs = lstProfileAll.Select(s => s.ID).ToList();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoCat_Position = new Cat_PositionRepository(unitOfWork);
                var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                #region MyRegion
                //var workDays = repoAtt_Workday.FindBy(s => s.ShiftID != null && lstProfileIDs.Contains(s.ProfileID) && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && s.IsDelete == null)
                //    .Select(s => new { s.ProfileID, s.WorkDate, s.ShiftID, s.InTime1, s.OutTime1, s.ShiftActual, s.ShiftApprove, s.Status }).ToList();
                #endregion
                var workDays = repoAtt_Workday.FindBy(s => s.ShiftID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && s.IsDelete == null)
                  .Select(s => new { s.ProfileID, s.WorkDate, s.ShiftID, s.InTime1, s.OutTime1, s.ShiftActual, s.ShiftApprove, s.Status }).ToList();
                //var profileIds = workDays.Where(s => lstProfileIDs.Contains(s.ProfileID)).Select(s => s.ProfileID).Distinct().ToList();
                var profileIds = workDays.Select(s => s.ProfileID).Distinct().ToList();
                var profiles = lstProfileAll.Where(s => profileIds.Contains(s.ID))
                    .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
                var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null && s.Code != null).ToList();
                #region
                // var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                //var positions = repoCat_Position.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList();
                //var jobtitles = repoCat_JobTitle.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();
                #endregion

                var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();
                if (ShiftIDs != null)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && ShiftIDs.Contains(s.ShiftID.Value)).ToList();
                    profileIds = workDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }
                if (!isIncludeQuitEmp)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                #region
                //if (!string.IsNullOrEmpty(CodeEmp))
                //{
                //    lstProfileIDs = repoHre_Profile.FindBy(s => s.CodeEmp == CodeEmp).Select(p => p.ID).ToList();
                //}
                #endregion
                List<Guid> guids = profiles.Select(s => s.ID).ToList();
                // workDays = workDays.Where(s => s.ProfileID != null && guids.Contains(s.ProfileID)).ToList();
                workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList();
                profiles = profiles.Where(s => guids.Contains(s.ID)).ToList();
                List<Att_ReportWrongShiftEntity> lstReportWrongShiftEntity = new List<Att_ReportWrongShiftEntity>();
                Att_ReportWrongShiftEntity reportWrongShiftEntity = null;
                #region lay danh sach phong ban theo profiles
                ////  var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                //var lstDepartments = new List<Cat_OrgStructure>();
                ////   var orgTeam = new Cat_OrgStructure();
                ////   var orgSection = new Cat_OrgStructure();
                //var lstDivisions = new List<Cat_OrgStructure>();
                //var orgIds = new List<Guid>();
                //if (profiles.Any())
                //{
                //    orgIds = profiles.Select(p => p.OrgStructureID ?? Guid.Empty).ToList();
                //}

                //foreach (var orgId in orgIds)
                //{
                //    var department = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                //    var division = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);

                //    if (department != null)
                //    {
                //        lstDepartments.Add(department);
                //    }
                //    if (division != null)
                //    {
                //        lstDivisions.Add(division);
                //    }
                //}

                #endregion
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                var positions = repoCat_Position.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList();
                var jobtitles = repoCat_JobTitle.FindBy(s => s.IsDelete == null && s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();

                foreach (var profile in profiles)
                {
                    for (DateTime date = dateStart.Date; date <= dateEnd.Date; date = date.AddDays(1))
                    {
                        var workDay = workDays.FirstOrDefault(s => s.WorkDate.Date == date.Date && s.ProfileID == profile.ID);
                        if (workDay != null && workDay.ShiftActual != workDay.ShiftID)
                        {
                            reportWrongShiftEntity = new Att_ReportWrongShiftEntity();
                            //DataRow row = table.NewRow();
                            Guid? orgId = profile.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);
                            var orGroup = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes);
                            var orgDivision = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);

                            reportWrongShiftEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                            reportWrongShiftEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                            reportWrongShiftEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                            reportWrongShiftEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            reportWrongShiftEntity.GroupCode = orGroup != null ? orGroup.Code : string.Empty;
                            reportWrongShiftEntity.GroupName = orGroup != null ? orGroup.OrgStructureName : string.Empty;
                            reportWrongShiftEntity.Division = orgDivision != null ? orgDivision.Code : string.Empty;
                            reportWrongShiftEntity.DivisionName = orgDivision != null ? orgDivision.OrgStructureName : string.Empty;
                            reportWrongShiftEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                            reportWrongShiftEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;

                            var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                            var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                            var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID);
                            var shiftActual = shifts.FirstOrDefault(s => s.ID == workDay.ShiftActual);
                            var shiftApprove = shifts.FirstOrDefault(s => s.ID == workDay.ShiftApprove);
                            reportWrongShiftEntity.ProfileName = profile.ProfileName;
                            reportWrongShiftEntity.CodeEmp = profile.CodeEmp;

                            reportWrongShiftEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                            reportWrongShiftEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                            reportWrongShiftEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
                            reportWrongShiftEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;

                            reportWrongShiftEntity.OrgCode = org != null ? org.Code : string.Empty;
                            reportWrongShiftEntity.Date = date;
                            reportWrongShiftEntity.DateFrom = dateStart;
                            reportWrongShiftEntity.DateTo = dateEnd;
                            reportWrongShiftEntity.DateExport = DateTime.Now;
                            reportWrongShiftEntity.UserExport = userExport;
                            //reportWrongShiftEntity.UserExport = Session[SessionObjects.UserLogin];

                            reportWrongShiftEntity.ShiftName = shift != null ? shift.ShiftName : string.Empty;
                            reportWrongShiftEntity.ScheduleShift = shift != null ? shift.ShiftName : string.Empty;
                            reportWrongShiftEntity.ActualShift = shiftActual != null ? shiftActual.ShiftName : string.Empty;
                            reportWrongShiftEntity.ApprovedShift = shiftApprove != null ? shiftApprove.ShiftName : string.Empty;

                            reportWrongShiftEntity.Status = workDay.Status;
                            reportWrongShiftEntity.TimeIn = workDay.InTime1 != null ? workDay.InTime1 : null; ;
                            reportWrongShiftEntity.TimeOut = workDay.OutTime1 != null ? workDay.OutTime1 : null;
                            lstReportWrongShiftEntity.Add(reportWrongShiftEntity);
                        }
                    }

                }

                #region Code Cũ
                //foreach (var profile in profiles)
                //{

                //    for (DateTime date = dateStart.Date; date <= dateEnd.Date; date = date.AddDays(1))
                //    {
                //        var workDay = workDays.FirstOrDefault(s => s.WorkDate.Date == date.Date && s.ProfileID == profile.ID);
                //        if (workDay != null && workDay.ShiftActual != workDay.ShiftID)
                //        {
                //            reportWrongShiftEntity = new Att_ReportWrongShiftEntity();
                //            Guid? orgId = profile.OrgStructureID;
                //            #region
                //            // var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date);
                //           // var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID);
                //            // var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                //            #endregion
                //            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);
                //            #region
                //            var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                //            var orGroup = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes);
                //            var orgDivision = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);

                //            reportWrongShiftEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                //            reportWrongShiftEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                //            reportWrongShiftEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                //            reportWrongShiftEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                //            reportWrongShiftEntity.GroupCode = orGroup != null ? orGroup.Code : string.Empty;
                //             reportWrongShiftEntity.GroupName = orGroup != null ? orGroup.OrgStructureName : string.Empty;
                //            reportWrongShiftEntity.Division = orgDivision != null ? orgDivision.Code : string.Empty;
                //            reportWrongShiftEntity.DivisionName = orgDivision != null ? orgDivision.OrgStructureName : string.Empty;
                //             reportWrongShiftEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                //            reportWrongShiftEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                //            #endregion

                //            reportWrongShiftEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                //            reportWrongShiftEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                //            var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                //            var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

                //             reportWrongShiftEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
                //             reportWrongShiftEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                //            var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID);
                //            var shiftActual = shifts.FirstOrDefault(s => s.ID == workDay.ShiftActual);
                //            var shiftApprove = shifts.FirstOrDefault(s => s.ID == workDay.ShiftApprove);


                //            reportWrongShiftEntity.ProfileName = profile.ProfileName;
                //            reportWrongShiftEntity.CodeEmp = profile.CodeEmp;
                //            reportWrongShiftEntity.Date = date;
                //            reportWrongShiftEntity.DateFrom = dateStart;
                //            reportWrongShiftEntity.DateTo = dateEnd;
                //            reportWrongShiftEntity.DateExport = DateTime.Now;

                //            reportWrongShiftEntity.ShiftName = shift != null ? shift.ShiftName : string.Empty;
                //            reportWrongShiftEntity.ScheduleShift = shift != null ? shift.ShiftName : string.Empty;
                //            reportWrongShiftEntity.ActualShift = shiftActual != null ? shiftActual.ShiftName : string.Empty;
                //            reportWrongShiftEntity.ApprovedShift = shiftApprove != null ? shiftApprove.ShiftName : string.Empty;

                //            reportWrongShiftEntity.Status = workDay.Status;
                //            reportWrongShiftEntity.TimeIn = workDay.InTime1 != null ? workDay.InTime1 : null; ;
                //            reportWrongShiftEntity.TimeOut = workDay.OutTime1 != null ? workDay.OutTime1 : null;
                //            lstReportWrongShiftEntity.Add(reportWrongShiftEntity);
                //        }
                //    }

                //}
                #endregion
                return lstReportWrongShiftEntity;
            }
        }
コード例 #20
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Lấy Dữ Liệu BC Chi Tiết Ca Làm Việc
        /// </summary>
        /// <returns></returns>
        public DataTable GetReportDetailShift(DateTime DateFrom, DateTime DateTo, List<Hre_ProfileEntity> profiles, string userExport, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                if (DateTo != null)
                    DateTo = DateTo.AddDays(1).AddMilliseconds(-1);
                DataTable table = CreateReportDetailShiftSchema();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                List<Guid> ProfileIDs = profiles.Select(s => s.ID).ToList();
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                var basevice = new BaseService();
                //var workDays = repoAtt_Workday.FindBy(s => s.IsDelete == null &&
                //  DateFrom <= s.WorkDate && s.WorkDate <= DateTo
                //  && s.ProfileID != null && ProfileIDs.Contains(s.ProfileID))
                //  .Select(s => new { s.ProfileID, s.ShiftID, s.ShiftApprove, s.WorkDate, s.InTime1, s.OutTime1,s.Note }).ToList();
                string status = string.Empty;
                List<object> para = new List<object>();
                para.AddRange(new object[3]);
                para[1] = DateFrom;
                para[2] = DateTo;

                var workDays = basevice.GetData<Att_WorkdayEntity>(para, ConstantSql.hrm_att_sp_getdata_reportWorDay, UserLogin, ref status).Where(s => ProfileIDs.Contains(s.ProfileID)).ToList();
                var profileIds = workDays.Select(s => s.ProfileID).Distinct().ToList();


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

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

                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.GetAll().ToList();

                List<Guid> guids = profiles.Select(s => s.ID).ToList();
                workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList();

                foreach (var profile in profiles)
                {
                    for (DateTime date = DateFrom.Date; date <= DateTo; date = date.AddDays(1))
                    {
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date && s.ProfileID == profile.ID).ToList();
                        if (workDayProfiles.Count > 0)
                        {
                            DataRow row = table.NewRow();
                            Guid? orgId = 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_ReportDetailShiftEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                            row[Att_ReportDetailShiftEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.Code : string.Empty;
                            row[Att_ReportDetailShiftEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                            row[Att_ReportDetailShiftEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                            row[Att_ReportDetailShiftEntity.FieldNames.PositionName] = profile.PositionName;
                            row[Att_ReportDetailShiftEntity.FieldNames.JobtitleName] = profile.JobTitleName;
                            row[Att_ReportDetailShiftEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Att_ReportDetailShiftEntity.FieldNames.ProfileName] = profile.ProfileName;


                            var workDay1 = workDayProfiles.FirstOrDefault();
                            row[Att_ReportDetailShiftEntity.FieldNames.Date] = date;
                            row[Att_ReportDetailShiftEntity.FieldNames.DateFrom] = DateFrom.Date;
                            row[Att_ReportDetailShiftEntity.FieldNames.DateTo] = DateTo;
                            row[Att_ReportDetailShiftEntity.FieldNames.DateExport] = DateTime.Now;
                            row[Att_ReportDetailShiftEntity.FieldNames.UserExport] = userExport;
                            //    row[Att_ReportSumaryInOutEntity.FieldNames.UserExport] = Session[SessionObjects.UserLogin];
                            if (workDay1 != null)
                            {
                                Guid? ShiftID = workDay1.ShiftApprove ?? workDay1.ShiftID;
                                var shift = shifts.FirstOrDefault(s => s.ID == ShiftID);
                                row[Att_ReportDetailShiftEntity.FieldNames.ShiftName] = shift != null ? shift.ShiftName : string.Empty;
                                if (workDay1.InTime1 != null)
                                    row[Att_ReportDetailShiftEntity.FieldNames.InTime] = workDay1.InTime1.Value;
                                if (workDay1.OutTime1 != null)
                                    row[Att_ReportDetailShiftEntity.FieldNames.OutTime] = workDay1.OutTime1.Value;
                                row[Att_ReportDetailShiftEntity.FieldNames.WorkDate] = workDay1.WorkDate != null ? (DateTime?)workDay1.WorkDate : null;
                            }
                            row[Att_ReportDetailShiftEntity.FieldNames.Remark] = workDay1.Note;
                            table.Rows.Add(row);
                        }
                    }
                }

                return table;

            }
        }
コード例 #21
0
ファイル: Att_LeavedayServices.cs プロジェクト: dtafe/vnr
        public string ValidateLeaveDayTimeOff(List<Guid> lstProfileId, List<Att_LeaveDay> listleaveDayInsert)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_TimeOffInLieu = new Att_TimeOffInLieuRepository(unitOfWork);
                var repoAtt_Roster = new Att_RosterRepository(unitOfWork);
                var repoAtt_RosterGroup = new Att_RosterGroupRepository(unitOfWork);
                var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork);
                var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork);
                var repoAtt_TimeOffInLieuMonth = new CustomBaseRepository<Att_TimeOffInLieuMonth>(unitOfWork);
                var repoCat_GradeAttendance = new CustomBaseRepository<Cat_GradeAttendance>(unitOfWork);
                var repoAtt_Grade = new CustomBaseRepository<Att_Grade>(unitOfWork);
                var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();
                string ErrorResult = string.Empty;
                Guid GuidContext = Guid.NewGuid();
                DateTime dateMin = listleaveDayInsert.Min(m => m.DateStart);
                DateTime Datemax = listleaveDayInsert.Min(m => m.DateEnd);
                DateTime BeginMonthOfMin = new DateTime(dateMin.Year, dateMin.Month, 1);
                DateTime EndMonthOfMax = new DateTime(Datemax.Year, Datemax.Month, 1);
                EndMonthOfMax = EndMonthOfMax.AddMonths(1).AddMinutes(-1);
                DateTime Month4Ago = BeginMonthOfMin.AddMonths(-4);
                List<Att_TimeOffInLieu> lstTimeOffInLieu = repoAtt_TimeOffInLieu.FindBy(m => m.Date >= Month4Ago && m.Date < EndMonthOfMax && lstProfileId.Contains(m.ProfileID)).ToList<Att_TimeOffInLieu>();
                List<Att_TimeOffInLieuMonth> lstTimeOffInLieu_Month = repoAtt_TimeOffInLieuMonth.FindBy(m => m.Month >= Month4Ago && m.Month < EndMonthOfMax && lstProfileId.Contains(m.ProfileID)).ToList<Att_TimeOffInLieuMonth>();

                List<Cat_GradeAttendance> lstGradeCfg = repoCat_GradeAttendance.GetAll().ToList<Cat_GradeAttendance>();
                var lstGrade = repoAtt_Grade.FindBy(m => lstProfileId.Contains((Guid)m.ProfileID) && m.MonthStart <= dateMin).Select(m => new { m.ProfileID, m.MonthStart, m.GradeAttendanceID }).OrderByDescending(m => m.MonthStart);
                string E_APPROVED_Roster = RosterStatus.E_APPROVED.ToString();
                List<Att_Roster> lstRoster = repoAtt_Roster.FindBy(m => m.Status == E_APPROVED_Roster && m.DateEnd >= dateMin && m.DateStart <= Datemax && lstProfileId.Contains(m.ProfileID)).ToList<Att_Roster>();
                List<Att_RosterGroup> lstRosterGroup = repoAtt_RosterGroup.FindBy(m => m.DateEnd >= dateMin && m.DateStart <= Datemax).ToList<Att_RosterGroup>();
                string E_ROSTERGROUP = RosterType.E_ROSTERGROUP.ToString();
                List<Att_Roster> lstRosterTypeGroup = lstRoster.Where(m => m.Type == E_ROSTERGROUP).ToList();
                List<Hre_WorkHistory> lstWorkHistory = repoHre_WorkHistory.FindBy(m => lstProfileId.Contains(m.ProfileID)).ToList<Hre_WorkHistory>();
                List<DateTime> lstDayOff = repoCat_DayOff.GetAll().Select(m => m.DateOff).ToList<DateTime>();


                //Tạo ra một list giả dữ liệu
                List<LeaveDayValidate> lstLeaveDayValidate = new List<LeaveDayValidate>();
                List<LeaveDayValidate> lstLeaveDayValidate1 = new List<LeaveDayValidate>();
                foreach (var item in listleaveDayInsert)
                {
                    LeaveDayValidate LeaveDayValid = new LeaveDayValidate();
                    LeaveDayValid.ProfileID = item.ProfileID;
                    LeaveDayValid.DateStart = item.DateStart;
                    LeaveDayValid.DateEnd = item.DateEnd;
                    LeaveDayValid.Duration = item.LeaveHours.Value;
                    LeaveDayValid.TotalDuration = item.LeaveDays ?? 1;
                    lstLeaveDayValidate1.Add(LeaveDayValid);
                }

                foreach (var item in lstLeaveDayValidate1)
                {
                    if (item.DateEnd.Date > item.DateStart.Date)
                    {
                        Dictionary<DateTime, DateTime> dicTime = new Dictionary<DateTime, DateTime>();
                        DateTime DateMinBeginMonth = new DateTime(item.DateStart.Year, item.DateStart.Month, 1);
                        DateTime DateMaxBeginMonth = new DateTime(item.DateEnd.Year, item.DateEnd.Month, 1);
                        if (DateMinBeginMonth < DateMaxBeginMonth)
                        {
                            Guid GradeID = Guid.Empty;
                            var gradeByProfile = lstGrade.Where(m => m.ProfileID == item.ProfileID).FirstOrDefault();
                            if (gradeByProfile != null)
                            {
                                GradeID = (Guid)gradeByProfile.GradeAttendanceID;
                            }
                            Cat_GradeAttendance gradeCfg = lstGradeCfg.Where(m => m.ID == GradeID).FirstOrDefault();
                            if (gradeCfg == null)
                                continue;
                            List<Att_Roster> listRosterByProfile = lstRoster.Where(m => m.ProfileID == item.ProfileID).ToList();
                            List<Hre_WorkHistory> listWorkHistoryByProfile = lstWorkHistory.Where(m => m.ProfileID == item.ProfileID).ToList();
                            List<Att_Roster> lstRosterTypeGroupByProfile = lstRosterTypeGroup.Where(m => m.ProfileID == item.ProfileID).ToList();

                            var listRosterEntity = listRosterByProfile.Select(d => new Att_RosterEntity
                            {
                                ID = d.ID,
                                ProfileID = d.ProfileID,
                                RosterGroupName = d.RosterGroupName,
                                Type = d.Type,
                                Status = d.Status,
                                DateEnd = d.DateEnd,
                                DateStart = d.DateStart,
                                MonShiftID = d.MonShiftID,
                                TueShiftID = d.TueShiftID,
                                WedShiftID = d.WedShiftID,
                                ThuShiftID = d.ThuShiftID,
                                FriShiftID = d.FriShiftID,
                                SatShiftID = d.SatShiftID,
                                SunShiftID = d.SunShiftID,
                                MonShift2ID = d.MonShiftID,
                                TueShift2ID = d.TueShift2ID,
                                WedShift2ID = d.WedShift2ID,
                                ThuShift2ID = d.ThuShift2ID,
                                FriShift2ID = d.FriShift2ID,
                                SatShift2ID = d.SatShift2ID,
                                SunShift2ID = d.SunShift2ID
                            }).ToList();

                            var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity
                            {
                                ID = d.ID,
                                DateEnd = d.DateEnd,
                                DateStart = d.DateStart,
                                MonShiftID = d.MonShiftID,
                                TueShiftID = d.TueShiftID,
                                WedShiftID = d.WedShiftID,
                                ThuShiftID = d.ThuShiftID,
                                FriShiftID = d.FriShiftID,
                                SatShiftID = d.SatShiftID,
                                SunShiftID = d.SunShiftID,
                                RosterGroupName = d.RosterGroupName
                            }).ToList();

                            Dictionary<DateTime, Cat_Shift> dailyShifts = Att_AttendanceLib.GetDailyShifts(item.ProfileID,
                                item.DateStart, item.DateEnd, listRosterEntity, listRosterGroupEntity, shifts);

                            for (DateTime DateCheck = DateMinBeginMonth; DateCheck <= DateMaxBeginMonth; DateCheck = DateCheck.AddMonths(1))
                            {
                                DateTime beginMonth = DateCheck;
                                DateTime endMonth = beginMonth.AddMonths(1).AddMinutes(-1);
                                if (DateCheck == DateMinBeginMonth)
                                {
                                    dicTime.Add(item.DateStart, endMonth);
                                }
                                else if (DateCheck == DateMaxBeginMonth)
                                {
                                    dicTime.Add(beginMonth, item.DateEnd);
                                }
                                else
                                {
                                    dicTime.Add(beginMonth, endMonth);
                                }
                            }
                            foreach (var dicTimeKey in dicTime.Keys)
                            {
                                DateTime DateS = dicTimeKey;
                                DateTime DateE = dicTime[dicTimeKey];

                                double TotalDuration = 0;
                                for (DateTime dateC = DateS; dateC <= DateE; dateC = dateC.AddDays(1))
                                {
                                    if (!lstDayOff.Contains(dateC) && dailyShifts.ContainsKey(dateC))
                                    {
                                        if (dailyShifts[dateC] != null)
                                        {
                                            TotalDuration++;
                                        }
                                    }
                                }
                                LeaveDayValidate LeaveDayValid = new LeaveDayValidate();
                                LeaveDayValid.ProfileID = item.ProfileID;
                                LeaveDayValid.DateStart = DateS;
                                LeaveDayValid.DateEnd = DateE;
                                LeaveDayValid.Duration = item.Duration;
                                LeaveDayValid.TotalDuration = TotalDuration;
                                lstLeaveDayValidate1.Add(LeaveDayValid);
                            }
                        }
                        else
                        {
                            lstLeaveDayValidate.Add(item);
                        }
                    }
                    else
                    {
                        lstLeaveDayValidate.Add(item);
                    }
                }

                List<Guid> LstProfileIDs_Error_MissImport = new List<Guid>();
                List<Guid> LstProfileIDs_Error_NotValid = new List<Guid>();

                foreach (var item in lstLeaveDayValidate)
                {
                    DateTime monthYear = new DateTime(item.DateStart.Year, item.DateStart.Month, 1);
                    List<Att_TimeOffInLieu> lstTimeOffInlieu_ByProfile = lstTimeOffInLieu.Where(m => m.ProfileID == item.ProfileID).ToList();
                    List<Att_TimeOffInLieuMonth> lstTimeOffInlieuMonth_ByProfile = lstTimeOffInLieu_Month.Where(m => m.ProfileID == item.ProfileID).ToList();
                    double? NumAvailable = CalculateTotalHourTimeOff(item.ProfileID, lstTimeOffInlieu_ByProfile, lstTimeOffInlieuMonth_ByProfile, monthYear, 1);

                    if (NumAvailable == null)
                    {
                        LstProfileIDs_Error_MissImport.Add(item.ProfileID);
                    }
                    else if ((item.Duration * item.TotalDuration) > NumAvailable.Value)
                    {
                        LstProfileIDs_Error_NotValid.Add(item.ProfileID);
                    }
                }
                if (LstProfileIDs_Error_MissImport.Count > 0)
                {
                    var profile = repoHre_Profile.FindBy(m => LstProfileIDs_Error_MissImport.Contains(m.ID)).Select(m => new { m.CodeEmp, m.ProfileName });

                    foreach (var item in profile)
                    {
                        ErrorResult += item.ProfileName + "[" + item.CodeEmp + "]; ";
                    }
                    if (ErrorResult.Length > 0)
                    {
                        ErrorResult = ErrorResult.Substring(0, ErrorResult.Length - 2);
                    }
                    ErrorResult = ConstantMessages.EmpDoNotConfigTimeOffBegin.TranslateString();
                    //ErrorResult = "EmpDoNotConfigTimeOffBegin";

                }
                else if (LstProfileIDs_Error_NotValid.Count > 0)
                {
                    var profile = repoHre_Profile.FindBy(m => LstProfileIDs_Error_NotValid.Contains(m.ID)).Select(m => new { m.CodeEmp, m.ProfileName });

                    foreach (var item in profile)
                    {
                        ErrorResult += item.ProfileName + "[" + item.CodeEmp + "]; ";
                    }
                    if (ErrorResult.Length > 0)
                    {
                        ErrorResult = ErrorResult.Substring(0, ErrorResult.Length - 2);
                    }
                    ErrorResult = ConstantMessages.DataNotEnoughToMakeLeave.TranslateString();
                    //ErrorResult = "EmpDoNotEnoughTimeOff";
                }
                return ErrorResult;
            }
        }
コード例 #22
0
ファイル: Hre_ReportServices.cs プロジェクト: dtafe/vnr
        public DataTable GetReportProfileHDTInMonth(DateTime Month, string lstOrgOrderNumber, List<string> lstUnit, List<string> lstDept, List<string> lstPart, bool IsCreateTemplate, string userLogin)
        {
            DataTable table = CreateReportProfileHDTInMonthSchema();
            if (IsCreateTemplate)
            {
                return table.ConfigTable();
            }
            DateTime monthStart = new DateTime(Month.Year, Month.Month, 1);
            DateTime monthEnd = monthStart.AddMonths(1).AddMilliseconds(-1);
            string status = string.Empty;
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var basevices = new BaseService();
                var hdtJobServices = new Hre_HDTJobServices();
                List<object> listObjHDTJob = new List<object>();
                listObjHDTJob.AddRange(new object[14]);
                listObjHDTJob[5] = lstOrgOrderNumber;
                listObjHDTJob[12] = 1;
                listObjHDTJob[13] = Int32.MaxValue - 1;
                var lstHDTJob = hdtJobServices.GetData<Hre_HDTJobEntity>(listObjHDTJob, ConstantSql.hrm_hr_sp_get_HDTJob, userLogin, ref status).ToList();
                //Hieu.Van: HungLe yêu cầu thêm nghiệp vụ này idTask: 19234
                //Chỉ xuất những người còn làm HDTJob trong tháng

                lstHDTJob = lstHDTJob.Where(s => s.DateFrom != null && s.DateFrom.Value.Month == Month.Month).ToList();
               
                if (lstUnit.Count() > 0)
                {
                    lstHDTJob = lstHDTJob.Where(s => lstUnit.Contains(s.Unit)).ToList();
                }
                if (lstDept.Count() > 0)
                {
                    lstHDTJob = lstHDTJob.Where(s => lstDept.Contains(s.Dept)).ToList();
                }
                if (lstPart.Count() > 0)
                {
                    lstHDTJob = lstHDTJob.Where(s => lstPart.Contains(s.Part)).ToList();
                }
                if (lstHDTJob.Count == 0)
                {
                    return table;
                }
                var lstProfileIDsByHDTJob = lstHDTJob.Select(s => s.ProfileID).ToList();
                #region DS ngày công Theo ProfileIds
                var workDayRepository = new Att_WorkDayRepository(unitOfWork);
                var lstWorkDay = new List<Att_Workday>().Select(s => new
                {
                    s.ID,
                    s.ProfileID,
                    s.WorkDate,
                    s.ShiftActual
                }).ToList();

                lstWorkDay.AddRange(workDayRepository.FindBy(s => s.IsDelete == null && s.FirstInTime != null && s.LastOutTime != null && s.WorkDate.Month == Month.Month 
                    && lstProfileIDsByHDTJob.Contains(s.ProfileID)).Select(s => new
                {
                    s.ID,
                    s.ProfileID,
                    s.WorkDate,
                    s.ShiftActual
                }).ToList());
                #endregion
                #region DS ngày nghỉ Theo ProfileIds
                var leavedayRepository = new Att_LeavedayRepository(unitOfWork);
                var lstleaveday = new List<Att_LeaveDay>().Select(s => new
                {
                    s.ID,
                    s.ProfileID,
                    s.DateStart,
                    s.DateEnd
                }).ToList();

                lstleaveday.AddRange(leavedayRepository.FindBy(s => s.IsDelete == null
                    && s.DateStart.Month <= Month.Month && s.DateEnd.Month >= Month.Month
                    && lstProfileIDsByHDTJob.Contains(s.ProfileID) && s.Status == LeaveDayStatus.E_APPROVED.ToString()).Select(s => new
                    {
                        s.ID,
                        s.ProfileID,
                        s.DateStart,
                        s.DateEnd
                    }).ToList());
                #endregion
                #region DS ca làm việc
                var shiftRepository = new Cat_ShiftRepository(unitOfWork);
                var lstShift = new List<Cat_Shift>().Select(s => new
                {
                    s.ID,
                    s.Code
                }).ToList();

                lstShift.AddRange(shiftRepository.FindBy(s => s.IsDelete == null ).Select(s => new
                    {
                        s.ID,
                        s.Code
                    }).ToList());
                #endregion
                Hre_ProfileServices hreService = new Hre_ProfileServices();
                lstHDTJob = hreService.getHDTJobByPrice(lstHDTJob, monthStart, monthEnd);
                foreach (var HDTJob in lstHDTJob)
                {
                    DataRow row = table.NewRow();
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.ProfileName] = HDTJob.ProfileName;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.CodeEmp] = HDTJob.CodeEmp;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.E_DEPARTMENT] = HDTJob.E_DEPARTMENT;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.E_DIVISION] = HDTJob.E_DIVISION;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.E_SECTION] = HDTJob.E_SECTION;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.E_TEAM] = HDTJob.E_TEAM;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.E_UNIT] = HDTJob.E_UNIT;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Unit] = HDTJob.Unit;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Dept] = HDTJob.Dept;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Part] = HDTJob.Part;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Line] = HDTJob.Line;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Price] = HDTJob.Price != null ? HDTJob.Price : 0;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Session] = HDTJob.Session;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.HDTJobTypeName] = HDTJob.HDTJobTypeName;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.HDTJobTypeNameHVN] = HDTJob.HDTJobTypeNameHVN;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.StandardElement] = HDTJob.StandardElement;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.EncryptJob] = HDTJob.EncryptJob;
                    row[Hre_ReportProfileHDTInMonthEntity.FieldNames.HDTJobGroupName] = HDTJob.HDTJobGroupName;
                    var workdaybypro = lstWorkDay.Where(s => s.ProfileID == HDTJob.ProfileID).ToList();
                    if (workdaybypro.Count  == 0)
                    {
                        continue;
                    }
                    for (int i = 1; i <= 31; i++)
                    {
                        var workdaybydate = workdaybypro.Where(s => s.WorkDate != null && s.WorkDate.Day == i).FirstOrDefault();
                        if (workdaybydate == null)
                        {
                            continue;
                        }
                        else
                        {
                            var leavedaybydate = lstleaveday.Where(s => s.DateStart.Day <= i && s.DateEnd.Day >= i).FirstOrDefault();
                            if (leavedaybydate != null)
                            {
                                continue;
                            }
                            else
                            {
                                var shiftbydate = lstShift.Where(s => s.ID == workdaybydate.ShiftActual).FirstOrDefault();
                                row[Hre_ReportProfileHDTInMonthEntity.FieldNames.Data + i] = shiftbydate != null ? shiftbydate.Code : null;
                            }
                        }
                    }
                    table.Rows.Add(row);
                }
            }
            return table.ConfigTable();
        }
コード例 #23
0
ファイル: Att_LeavedayServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// [Tam.Le] - 2014/08/08
        /// Hàm xử lý load dữ liệu
        /// </summary>
        /// <param name="request"></param>
        /// <param name="otModel"></param>
        /// <returns></returns>
        public DataTable LoadData(DateTime dateStart, DateTime dateEnd, List<Guid> orgIDs, string ProfileName, string CodeEmp, Guid LeavedayType, out string ErrorMessages)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                ErrorMessages = string.Empty;
                //bool isIncludeQuitEmp = true;
                List<Guid> leavedayTypeIds = new List<Guid>();
                if (LeavedayType != null)
                    leavedayTypeIds.Add(LeavedayType);

                List<Guid> shiftIDs = new List<Guid>();
                string E_WAIT_APPROVED = LeaveDayStatus.E_WAIT_APPROVED.ToString();
                string E_SUBMIT = LeaveDayStatus.E_SUBMIT.ToString();
                var repoAtt_Leaveday = new Att_LeavedayRepository(unitOfWork);
                List<Att_LeaveDay> leaveDays = repoAtt_Leaveday.FindBy(s => s.LeaveDays > 0
                    && (s.Status == E_WAIT_APPROVED || s.Status == E_SUBMIT) && dateStart <= s.DateEnd && s.DateStart <= dateEnd).ToList<Att_LeaveDay>();
                foreach (var item in leaveDays)
                {
                    item.Status = E_WAIT_APPROVED;
                }

                var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList();
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                var workDays = repoAtt_Workday.FindBy(s => profileIds.Contains(s.ProfileID) && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                .Select(s => new { s.ProfileID, s.ShiftID, s.WorkDate, s.InTime1, s.OutTime1 }).ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(s => 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.Code != null).ToList();
                var repoCat_Position = new Cat_PositionRepository(unitOfWork);
                var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList();
                var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork);
                var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code }).ToList();
                var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PaidRate }).Distinct().ToList();
                var ledvedayPaidIds = leavedayTypes.Where(s => s.PaidRate > 0).Select(s => s.ID).ToList();
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.GetAll().ToList();
                if (orgIDs != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                if (shiftIDs.Count > 0)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && shiftIDs.Contains(s.ShiftID.Value)).ToList();
                    profileIds = workDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }
                if (leavedayTypeIds.Count > 0)
                {
                    leaveDays = leaveDays.Where(s => leavedayTypeIds.Contains(s.LeaveDayTypeID)).ToList();
                    profileIds = leaveDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }
                //if (!isIncludeQuitEmp)
                //{
                //    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateStart).ToList();
                //}
                var startYear = new DateTime(dateStart.Year, 1, 1);
                var endYear = new DateTime(dateStart.Year, 12, DateTime.DaysInMonth(dateStart.Year, 12));
                var rosterStatus = RosterStatus.E_APPROVED.ToString();
                var repoAtt_Roster = new Att_RosterRepository(unitOfWork);
                List<Att_Roster> listRoster = repoAtt_Roster.FindBy(d =>
                        d.Status == rosterStatus && profileIds.Contains(d.ProfileID) && d.DateStart <= dateEnd && d.DateEnd >= startYear).ToList<Att_Roster>();
                var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork);
                List<Cat_DayOff> listHoliday = repoCat_DayOff.FindBy(hol => hol.DateOff >= startYear && hol.DateOff <= endYear).ToList<Cat_DayOff>();
                var repoAtt_Grade = new Att_GradeRepository(unitOfWork);
                var listGrade = repoAtt_Grade.FindBy(d => d.MonthStart != null && d.MonthStart <= dateEnd
                && profileIds.Contains((Guid)d.ProfileID)).Select(d => new { d.ProfileID, d.MonthStart, d.GradeAttendanceID }).ToList();
                List<Guid?> listGradeID = listGrade.Select(d => d.GradeAttendanceID).ToList();
                var repoCat_Grade = new Cat_GradeAttendanceRepository(unitOfWork);
                List<Cat_GradeAttendance> listGradeCfg = repoCat_Grade.FindBy(d => listGradeID.Contains(d.ID)).ToList<Cat_GradeAttendance>();
                List<Att_Roster> lstRosterTypeGroup = new List<Att_Roster>();
                List<Att_RosterGroup> lstRosterGroup = new List<Att_RosterGroup>();
                GetRosterGroup(profileIds, startYear, dateEnd, out lstRosterTypeGroup, out lstRosterGroup);
                var repoHre_WorkHistory = new Hre_WorkHistoryRepository(unitOfWork);
                List<Hre_WorkHistory> listWorkHistory = repoHre_WorkHistory.FindBy(d => profileIds.Contains(d.ProfileID) && d.DateEffective <= dateEnd).ToList<Hre_WorkHistory>();
                var orgTypes = new List<Cat_OrgStructureType>();
                var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                DataTable table = GetSchema();
                List<string> codeRejects = new List<string>();
                codeRejects.Add("SICK");
                codeRejects.Add("SU");
                codeRejects.Add("SD");
                codeRejects.Add("D");
                codeRejects.Add("D");
                codeRejects.Add("DP");
                codeRejects.Add("PSN");
                codeRejects.Add("DSP");
                codeRejects.Add("M");
                List<Guid> leaveDayTypeRejectIDs = leavedayTypes.Where(s => codeRejects.Contains(s.Code)).Select(s => s.ID).ToList();
                foreach (var profile in profiles)
                {
                    var grade = listGrade.Where(d => d.ProfileID == profile.ID && d.MonthStart <= dateEnd).OrderByDescending(d => d.MonthStart).FirstOrDefault();
                    Cat_GradeAttendance gradeCfg = listGradeCfg.FirstOrDefault(d => grade != null && d.ID == grade.GradeAttendanceID);
                    List<Hre_WorkHistory> listWorkHistoryByProfile = listWorkHistory.Where(d => d.ProfileID == profile.ID).ToList();
                    List<Att_Roster> listRosterByProfile = listRoster.Where(d => d.ProfileID == profile.ID && d.DateStart <= dateEnd && d.DateEnd >= dateStart).ToList();

                    var listRosterEntity = listRosterByProfile.Select(d => new Att_RosterEntity
                    {
                        ID = d.ID,
                        ProfileID = d.ProfileID,
                        RosterGroupName = d.RosterGroupName,
                        Type = d.Type,
                        Status = d.Status,
                        DateEnd = d.DateEnd,
                        DateStart = d.DateStart,
                        MonShiftID = d.MonShiftID,
                        TueShiftID = d.TueShiftID,
                        WedShiftID = d.WedShiftID,
                        ThuShiftID = d.ThuShiftID,
                        FriShiftID = d.FriShiftID,
                        SatShiftID = d.SatShiftID,
                        SunShiftID = d.SunShiftID,
                        MonShift2ID = d.MonShiftID,
                        TueShift2ID = d.TueShift2ID,
                        WedShift2ID = d.WedShift2ID,
                        ThuShift2ID = d.ThuShift2ID,
                        FriShift2ID = d.FriShift2ID,
                        SatShift2ID = d.SatShift2ID,
                        SunShift2ID = d.SunShift2ID
                    }).ToList();

                    var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity
                    {
                        ID = d.ID,
                        DateEnd = d.DateEnd,
                        DateStart = d.DateStart,
                        MonShiftID = d.MonShiftID,
                        TueShiftID = d.TueShiftID,
                        WedShiftID = d.WedShiftID,
                        ThuShiftID = d.ThuShiftID,
                        FriShiftID = d.FriShiftID,
                        SatShiftID = d.SatShiftID,
                        SunShiftID = d.SunShiftID,
                        RosterGroupName = d.RosterGroupName
                    }).ToList();

                    Dictionary<DateTime, Cat_Shift> listMonthShifts = Att_AttendanceLib.GetDailyShifts(profile.ID, dateStart, dateEnd, listRosterEntity, listRosterGroupEntity, shifts);
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {

                        var leavdayProfiles = leaveDays.Where(s => s.DateStart.Date <= date.Date && date.Date <= s.DateEnd.Date && s.ProfileID == profile.ID).ToList();
                        if (leavdayProfiles.Count > 0)
                        {
                            bool isWorkDay = gradeCfg != null && Att_WorkDayHelper.IsWorkDay(date, gradeCfg, listMonthShifts, listHoliday);
                            var leaveday = leavdayProfiles.FirstOrDefault(s => ledvedayPaidIds.Contains(s.LeaveDayTypeID));
                            if (!isWorkDay)// neu ngay do ko phai ngay di lam
                            {
                                if (leaveday != null && leaveDayTypeRejectIDs.Contains(leaveday.LeaveDayTypeID) || listHoliday.Exists(s => s.DateOff == date))// neu ngay do la ngay nghi dc xem la ko xem ca or ngay nghi
                                {
                                    isWorkDay = true;
                                }
                            }
                            if (isWorkDay)
                            {
                                var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date);
                                DataRow row = table.NewRow();
                                Guid? orgId = profile.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_LeaveDayEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.CodeOrg] = orgOrg != null ? orgOrg.Code : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                                var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                                var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                                row[Att_LeaveDayEntity.FieldNames.ProfileName] = profile.ProfileName;
                                row[Att_LeaveDayEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                                row[Att_LeaveDayEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty;
                                row[Att_LeaveDayEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty;
                                var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID);
                                row[Att_LeaveDayEntity.FieldNames.Date] = date;
                                row[Att_LeaveDayEntity.FieldNames.DateFrom] = dateStart;
                                row[Att_LeaveDayEntity.FieldNames.DateTo] = dateEnd;
                                row[Att_LeaveDayEntity.FieldNames.DateExport] = DateTime.Now;
                                //row[Att_LeavedayEntity.FieldNames.UserExport] = Session[SessionObjects.UserLogin];
                                if (leaveday != null && leaveday.LeaveDays > 0)
                                {
                                    row["Paid"] = "X";
                                }
                                if (workDay != null)
                                {
                                    row[Att_LeaveDayEntity.FieldNames.Cat_Shift] = shift.ShiftName;
                                    row[Att_LeaveDayEntity.FieldNames.udInTime] = workDay.InTime1 != null ? workDay.InTime1.Value.ToString("HH:mm") : string.Empty;
                                    row[Att_LeaveDayEntity.FieldNames.udOutTime] = workDay.OutTime1 != null ? workDay.OutTime1.Value.ToString("HH:mm") : string.Empty;
                                }
                                foreach (var leaday in leavedayTypes)
                                {
                                    var leaday1 = leavdayProfiles.FirstOrDefault(s => s.LeaveDayTypeID == leaday.ID);
                                    if (leaday1 != null && leaday1.LeaveDays > 0)
                                    {
                                        row[leaday.Code] = "X";
                                    }
                                }

                                if (leaveday != null)
                                {
                                    row[Att_LeaveDayEntity.FieldNames.Status] = leaveday.Status;
                                }

                                table.Rows.Add(row);
                            }
                        }

                    }


                }
                //EntityService.SubmitChanges(GuidContext, LoginUserID.Value);
                context.SaveChanges();
                return table;
            }
        }
コード例 #24
0
ファイル: Can_ReportServices.cs プロジェクト: dtafe/vnr
        public bool SaveSumryMealRecord(Guid CutOffDurationID, List<Guid> lstProfileIDs)
        {
            using (var context = new VnrHrmDataContext())
            {
                try
                {
                    #region GetData
                    List<Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List<Can_ReportAdjustmentMealAllowancePaymentEntity>();
            
                    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                    var repoMealRecord = new Can_MealRecordRepository(unitOfWork);
                    var cutoffdurationRepository = new Att_CutOffDurationRepository(unitOfWork);
                    var Cutoffduration = cutoffdurationRepository.FindBy(m => m.ID == CutOffDurationID && m.IsDelete != true).FirstOrDefault();
                    DateTime DateFrom = new DateTime();
                    DateTime DateTo = new DateTime();
                    if (Cutoffduration != null)
                    {
                        DateFrom = Cutoffduration.DateStart;
                        DateTo = Cutoffduration.DateEnd.AddDays(1).AddMilliseconds(-1);
                    }
                    var sumryMealRecordRepository = new Can_SumryMealRecordRepository(unitOfWork);
                    var lstMealRecord = repoMealRecord.FindBy(m => m.WorkDay != null && m.WorkDay >= DateFrom && m.WorkDay <= DateTo && m.ProfileID != null)
                        .Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay }).ToList();

                    if (lstMealRecord.Count < 0)
                    {
                        return true;
                    }

                    var status = StatusMealAllowanceToMoney.E_APPROVED.ToString();
                    #region Dư ko dùng
                    //var repoAllowanceToMoney = new Can_MealAllowanceToMoneyRepository(unitOfWork);
                    //var mealAllowncaToMoneyProfileIDs = repoAllowanceToMoney.FindBy(s => s.Status == status && s.ProfileID != null && DateFrom <= s.DateTo && s.DateFrom <= DateTo).ToList();
                    #endregion

                    var lstProfileIdsByMeal = lstMealRecord.Select(s => s.ProfileID).Distinct().ToList();
                    var repoprofiles = new Hre_ProfileRepository(unitOfWork);
                    var profiles = repoprofiles.FindBy(s => lstProfileIdsByMeal.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
                    if (lstProfileIDs != null && lstProfileIDs.Count > 0)
                    {
                        profiles = profiles.Where(m => lstProfileIDs.Contains(m.ID)).ToList();
                    }

                    var repomealAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                    var mealAllowanceTypeSantandIDs = repomealAllowanceType.FindBy(s => s.Standard == true).Select(m => m.ID).ToList();
                    var mealAllowanceTypes = repomealAllowanceType.FindBy(s => s.IsDelete == null).ToList();
                    var amountStardand = repomealAllowanceType.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount.Value).FirstOrDefault();

                    var repoLineHDTJob = new Can_LineRepository(unitOfWork);
                    var lineHDTJobIDs = repoLineHDTJob.FindBy(s => s.HDTJ != null).Select(m => m.ID).ToList();

                    var repoHDTJob = new Hre_HDTJobRepository(unitOfWork);
                    var profileHDTJs = repoHDTJob.FindBy(s => DateFrom <= s.DateTo && s.DateFrom <= DateTo)
                        .Select(s => new { s.ProfileID, s.Type, s.DateFrom, s.DateTo }).ToList(); 
                    var profileHDTJIDs = profileHDTJs.Select(s => s.ProfileID).Distinct().ToList();

                    string approveKey = MealRecord_Status.E_APPROVED.ToString();
                    var repo_MealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                    var mealRecordMissings = repo_MealRecordMissing.FindBy(s => s.Status == approveKey && DateFrom <= s.WorkDate && s.WorkDate <= DateTo)
                        .Select(s => new { s.ProfileID, s.WorkDate, s.MealAllowanceTypeSettingID, s.TamScanReasonMissID, s.Amount }).ToList();

                    var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                    var dateStart1 = DateFrom.AddDays(-1);
                    var workDays = repoWorkDay.FindBy(s => dateStart1 <= s.WorkDate && s.WorkDate <= DateTo).Select(s => new { s.ProfileID, s.FirstInTime, s.LastOutTime, s.ShiftID, s.WorkDate }).ToList();
                    var workDayProfies = workDays.Where(s => s.FirstInTime != null || s.LastOutTime != null).ToList();

                    var repotamScan = new Cat_TAMScanReasonMissRepository(unitOfWork);
                    var tamSans = repotamScan.GetAll().ToList();
                    var tamScanNotFullPayIDs = tamSans.Where(s => s.IsFullPay == null || s.IsFullPay == false).Select(s => s.ID).ToList();

                    var reposhift = new Cat_ShiftRepository(unitOfWork);
                    var shifts = reposhift.GetAll().ToList();

                    var lines = new List<Can_Line>().ToList();
                    var repolines = new Can_LineRepository(unitOfWork);
                    lines = repolines.GetAll().ToList();

                    var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                    var orgs = repoOrg.GetAll().ToList();

                    var orgTypes = new List<Cat_OrgStructureType>();
                    var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork);
                    orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                    #endregion

                    foreach (var profile in profiles)
                    {
                      
                        var mealProfiles = lstMealRecord.Where(s => s.ProfileID == profile.ID).ToList();
                        #region Dư ko dùng
                        //var mealAllownProfiles = mealAllowncaToMoneyProfileIDs.Where(s => s.ProfileID == profile.ID).ToList();
                        //var mealNotStardands = lstMealRecord.Where(s => s.ProfileID == profile.ID && s.Amount > amountStardand).ToList();
                        #endregion
                        Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity();
                        Guid? orgId = profile.OrgStructureID;
                        var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID);
                        var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);
                        var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                        var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                        var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes);
                        ReportAdjustmentMealAllowancePayment.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp;
                        ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName;
                        ReportAdjustmentMealAllowancePayment.DateFrom = DateFrom;
                        ReportAdjustmentMealAllowancePayment.DateTo = DateTo;
                        ReportAdjustmentMealAllowancePayment.DatePrint = DateTime.Now;
                        var countCard = 0;
                        var sumCard = 0.0;
                        int countCardMore1 = 0;
                        var countNotWorkButHasEat = 0;
                        var sumNotWorkButHasEat = 0.0;
                        var countmealNotStardand = 0;
                        var amountmealNotStardand = 0.0;
                        var countHDTJ = 0;
                        var amountHDTJ = 0.0;
                        var countNotStandHDTJ = 0;
                        var amountNotStandHDTJ = 0.0;
                        int amount3OnMonth = 0;
                        var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                        for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1))
                        {
                            var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date);
                            var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID);
                            var missing = mealRecordMissings.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Value.Date == date.Date);
                            if (missing != null)
                            {
                                if (missing.MealAllowanceTypeSettingID != null && missing.TamScanReasonMissID == null)
                                {
                                    countCard++;
                                    sumCard += (double)(missing.Amount != null ? missing.Amount.Value : 0);
                                }
                                else if (missing.TamScanReasonMissID != null)
                                {
                                    var tamscan = tamSans.FirstOrDefault(s => s.ID == missing.TamScanReasonMissID);
                                    if (tamscan != null)
                                    {
                                        if (tamscan.IsFullPay == true)
                                        {
                                            countCard++;
                                            sumCard += (double)amountStardand;
                                        }
                                        else
                                        {
                                            amount3OnMonth++;
                                        }
                                    }
                                }
                            }
                            if (mealProfiles.Count(s => s.TimeLog != null && s.TimeLog.Value.Date == date.Date) > 1)
                            {
                                countCardMore1++;
                            }
                            var record = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)
                                && s.ProfileID == profile.ID && date.Date == s.TimeLog.Value.Date && !workdayProfileDates.Contains(date.Date));
                            if (record != null)
                            {
                                countNotWorkButHasEat++;
                                sumNotWorkButHasEat += (double)(record.Amount != null ? record.Amount.Value : 0);
                            }
                            var meal = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.Amount > amountStardand && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)
                                && s.ProfileID == profile.ID && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(date.Date));
                            if (meal != null)
                            {
                                countmealNotStardand++;
                                amountmealNotStardand += (double)(meal.Amount != null ? meal.Amount.Value : 0);
                            }
                            var mealHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && s.TimeLog != null && 
                                s.TimeLog.Value.Date == date.Date && (!profileHDTJIDs.Contains(s.ProfileID.Value) || (profileHDTJIDs.Contains(s.ProfileID.Value) && !workdayProfileDates.Contains(date.Date))));
                            if (mealHDT != null)
                            {
                                countHDTJ++;
                                amountHDTJ += (double)(mealHDT.Amount != null ? mealHDT.Amount.Value : 0);
                            }
                            var mealNotStandandHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID != null && s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && 
                                s.TimeLog != null && s.TimeLog.Value.Date == date.Date && profileHDTJIDs.Contains(s.ProfileID.Value) && workdayProfileDates.Contains(date.Date));
                            if (mealNotStandandHDT != null && mealNotStandandHDT.LineID != null)
                            {
                                var line = lines.FirstOrDefault(s => s.ID == mealNotStandandHDT.LineID);
                                var hdtjob = profileHDTJs.FirstOrDefault(s => s.Type != null && s.ProfileID == profile.ID && s.DateFrom.Value.Date <= date.Date && date.Date <= s.DateTo.Value.Date);
                                if (line != null && line.HDTJ != null && hdtjob.Type != line.HDTJ)
                                {
                                    var lineHDT = lines.FirstOrDefault(s => s.HDTJ == hdtjob.Type);
                                    if (lineHDT != null && lineHDT.Amount != null && lineHDT.Amount < line.Amount)
                                    {
                                        countNotStandHDTJ++;
                                        var lineAmount = line.Amount != null ? line.Amount.Value : 0;
                                        var lineAmountHDT = lineHDT.Amount != null ? lineHDT.Amount.Value : 0;
                                        amountNotStandHDTJ += (double)(lineAmount - lineAmountHDT);
                                    }
                                }
                            }
                            double countMiss = mealRecordMissings.Count(s => s.ProfileID == profile.ID && s.TamScanReasonMissID != null && tamScanNotFullPayIDs.Contains(s.TamScanReasonMissID.Value));
                            countMiss = GetCountAmount((int)countMiss);
                            if (countCard > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.TotalMealAllowance = countCard + countMiss;
                            }
                            if (sumCard > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.SumAmount = (double)(sumCard + countMiss * (double)amountStardand);
                            }
                            if (countmealNotStardand > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountEatNotStandar = countmealNotStardand;
                                ReportAdjustmentMealAllowancePayment.AmountEatNotStandar = amountmealNotStardand - (double)(amountStardand * countmealNotStardand);
                            }
                            if (countCardMore1 > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountCardMore = countCardMore1;
                                ReportAdjustmentMealAllowancePayment.SumCardMore = (double)Math.Round(countCardMore1 * amountStardand, 2);
                            }
                            if (countNotWorkButHasEat > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat = countNotWorkButHasEat;
                                ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat = sumNotWorkButHasEat;
                            }
                            amount3OnMonth = amount3OnMonth - (int)GetCountAmount(amount3OnMonth);
                            if (amount3OnMonth > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.Amount3OnMonth = amount3OnMonth;
                            }
                            if (countHDTJ > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountHDTJob = countHDTJ;
                                ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob = amountHDTJ;
                            }
                            if (countNotStandHDTJ > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountCardWorngStandar = countNotStandHDTJ;
                                ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandar = amountNotStandHDTJ;
                            }
                        }
                        Can_SumryMealRecord sumryMealRecordNew = new Can_SumryMealRecord();
                        sumryMealRecordNew.ProfileID = profile.ID;
                        sumryMealRecordNew.DateFrom = Cutoffduration.DateStart;
                        sumryMealRecordNew.DateTo = Cutoffduration.DateEnd;
                        sumryMealRecordNew.TotalMealAllowance = ReportAdjustmentMealAllowancePayment.TotalMealAllowance;
                        sumryMealRecordNew.SumAmount = ReportAdjustmentMealAllowancePayment.SumAmount;
                        sumryMealRecordNew.CountEatNotStandar = ReportAdjustmentMealAllowancePayment.CountEatNotStandar;
                        sumryMealRecordNew.AmountEatNotStandar = ReportAdjustmentMealAllowancePayment.AmountEatNotStandar;
                        sumryMealRecordNew.CountCardMore = ReportAdjustmentMealAllowancePayment.CountCardMore;
                        sumryMealRecordNew.SumAmountCardMore = ReportAdjustmentMealAllowancePayment.SumCardMore;
                        sumryMealRecordNew.CountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat;
                        sumryMealRecordNew.AmountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat;
                        sumryMealRecordNew.Amount3OnMonth = ReportAdjustmentMealAllowancePayment.Amount3OnMonth;
                        sumryMealRecordNew.CountHDTJob = ReportAdjustmentMealAllowancePayment.CountHDTJob;
                        sumryMealRecordNew.AmountHDTJob = ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob;
                        sumryMealRecordNew.AmountNotWorkButHasHDT = ReportAdjustmentMealAllowancePayment.AmountNotWorkButHasHDT;
                        sumryMealRecordNew.CountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.CountSubtractWorngStandarHDT;
                        sumryMealRecordNew.AmountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandarHDT;
                        sumryMealRecordRepository.Add(sumryMealRecordNew);
                        lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment);

                        if (profiles.IndexOf(profile) % 1000 == 0)
                        {
                            sumryMealRecordRepository.SaveChanges();
                        }
                    }
                    sumryMealRecordRepository.SaveChanges();
                }
                catch (Exception)
                {
                    return false;
                }
            }
            return true;
        }
コード例 #25
0
ファイル: Att_LeavedayServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// [Son.Vo] 05/06/2014
        /// Phân Tích Nghỉ Phép Và Trễ Sớm
        /// </summary>
        /// <returns></returns>
        public List<Att_AnalysysLeaveAndLateEarlyEntity> AnalysisLeaveAndLate(DateTime DateS, DateTime DateE, List<Guid> lstProfileIDs)
        {
            using (var context = new VnrHrmDataContext())
            {
                if (DateS == null || DateE == null)
                    return null;
                DateTime DateStart = DateS;
                DateTime DateEnd = DateE;
                string E_LATE_EARLY = WorkdayType.E_LATE_EARLY.ToString();
                var lstWorkday = new List<Att_WorkdayEntity>();

                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

                var repo = new CustomBaseRepository<Att_Workday>(unitOfWork);
                lstWorkday = repo
                    .FindBy(m => m.IsDelete == null && ((m.Type == E_LATE_EARLY && m.LateEarlyDuration != null && m.LateEarlyDuration > 0) || m.InTime1 == null || m.OutTime1 == null)
                    && m.WorkDate >= DateStart && m.WorkDate < DateEnd && lstProfileIDs.Contains(m.ProfileID))
                    .ToList()
                    .Translate<Att_WorkdayEntity>();
                SetStatusLeaveOnWorkday(lstWorkday);
                var profileIds = lstWorkday.Select(s => s.ProfileID).Distinct().ToList();

                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(s => profileIds.Contains(s.ID))
                 .Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
                List<Guid?> shiftids = lstWorkday.Select(m => m.ShiftID).ToList();

                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.FindBy(s => shiftids.Contains(s.ID))
                 .Select(s => new { s.ID, s.ShiftName }).ToList();

                List<Att_AnalysysLeaveAndLateEarlyEntity> lstAnalysysLeaveAndLateEarly = new List<Att_AnalysysLeaveAndLateEarlyEntity>();
                foreach (var item in profiles)
                {
                    var lstWorkdayByProfile = lstWorkday.Where(m => m.ProfileID == item.ID).ToList();
                    foreach (var WorkdayByProfile in lstWorkdayByProfile)
                    {
                        Att_AnalysysLeaveAndLateEarlyEntity analysysLeaveAndLateEarly = new Att_AnalysysLeaveAndLateEarlyEntity();
                        var profileshifts = shifts.Where(m => m.ID == WorkdayByProfile.ShiftID).FirstOrDefault();
                        analysysLeaveAndLateEarly.ProfileName = item.ProfileName;
                        analysysLeaveAndLateEarly.CodeEmp = item.CodeEmp;
                        analysysLeaveAndLateEarly.WorkDate = WorkdayByProfile.WorkDate;
                        if (profileshifts != null)
                        {
                            analysysLeaveAndLateEarly.ShiftName = profileshifts.ShiftName;
                        }
                        analysysLeaveAndLateEarly.InTime = WorkdayByProfile.FirstInTime;
                        analysysLeaveAndLateEarly.OutTime = WorkdayByProfile.LastOutTime;
                        analysysLeaveAndLateEarly.udLeavedayCode1 = WorkdayByProfile.udLeavedayCode1;
                        analysysLeaveAndLateEarly.udLeavedayStatus1 = WorkdayByProfile.udLeavedayStatus1;
                        analysysLeaveAndLateEarly.Late = WorkdayByProfile.LateDuration1;
                        analysysLeaveAndLateEarly.Early = WorkdayByProfile.EarlyDuration1;
                        analysysLeaveAndLateEarly.LateEarly = WorkdayByProfile.LateEarlyDuration;

                        lstAnalysysLeaveAndLateEarly.Add(analysysLeaveAndLateEarly);
                    }
                }
                return lstAnalysysLeaveAndLateEarly;
            }
        }
コード例 #26
0
ファイル: Cat_ShiftServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Remove 1 record là chuyển trạng thái IsDelete=true
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Remove(int id)
        {
            using (var context = new VnrAttendanceDataContext())
            {
                IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                Cat_ShiftRepository repo = new Cat_ShiftRepository(unitOfWork);
                var cat = repo.GetById(id);
                try
                {
                    repo.Remove(cat);
                    repo.SaveChanges();
                    return true;
                }
                catch
                {
                    return false;
                }

            }
        }
コード例 #27
0
ファイル: Att_OvertimeServices.cs プロジェクト: dtafe/vnr
        public DataTable LoadDataAnalyzeOvertime_DataLimit(string strOrgStructure, DateTime DateStart, DateTime DateEnd, List<Hre_ProfileEntity> lstProfile, List<string> lstTypeData, Att_OvertimeInfoFillterAnalyze _OvertimeInfoFillterAnalyzeEntity, string userLogin)
        {
            DataTable table = GetSchemaExportExcel();
            string status = string.Empty;

            DateStart = DateStart.Date;
            DateEnd = DateEnd.Date.AddDays(1).AddMilliseconds(-1);
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_WorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var repoCat_ShiftItem = new Cat_ShiftItemRepository(unitOfWork);
                var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork);
                var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork);
                var repoCat_OrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork);
                var repoCat_OrgStructureType = new CustomBaseRepository<Cat_OrgStructureType>(unitOfWork);

                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null && s.Code != null).ToList();

                List<WorkdayCustom> lstWorkday = new List<WorkdayCustom>();
                List<Guid> lstProfileId = lstProfile.Select(s => s.ID).ToList();

                List<object> lst3ParamSE = new List<object>();
                lst3ParamSE.Add(strOrgStructure);
                lst3ParamSE.Add(DateStart);
                lst3ParamSE.Add(DateEnd);
                if (lstProfile.Count > 0 && strOrgStructure == null)
                {
                    var lstWD = repoAtt_WorkDay.FindBy(s => s.IsDelete == null && s.WorkDate >= DateStart && s.WorkDate <= DateEnd && lstProfileId.Contains(s.ProfileID)).ToList();
                    if (lstWD.Count > 0)
                    {
                        lstWorkday = lstWD.Translate<WorkdayCustom>();
                    }
                }
                else
                {
                    lstWorkday = GetData<WorkdayCustom>(lst3ParamSE, ConstantSql.hrm_att_getdata_Workday, userLogin, ref status).ToList();
                }
                //var lstWorkdayQuery = repoAtt_WorkDay.FindBy(m => m.IsDelete == null && m.WorkDate >= DateStart && m.WorkDate <= DateEnd);
                //if (lstProfileId.Count > 0)
                //{
                //    lstWorkdayQuery = lstWorkdayQuery.Where(m => lstProfileId.Contains(m.ProfileID));
                //}
                //lstWorkday = lstWorkdayQuery.ToList().Translate<Att_WorkdayEntity>();

                List<Cat_ShiftEntity> lstShift = repoCat_Shift
                    .FindBy(s => s.IsDelete == null)
                    .ToList()
                    .Translate<Cat_ShiftEntity>();
                List<Cat_ShiftItemEntity> lstShiftItem = repoCat_ShiftItem
                    .FindBy(s => s.IsDelete == null)
                    .ToList()
                    .Translate<Cat_ShiftItemEntity>();
                List<Cat_DayOffEntity> LstDayOff = repoCat_DayOff
                    .FindBy(m => m.IsDelete == null && m.DateOff >= DateStart && m.DateOff < DateEnd)
                    .ToList()
                    .Translate<Cat_DayOffEntity>();
                List<Cat_OvertimeTypeEntity> lstOvertimeType = repoCat_OvertimeType
                    .FindBy(s => s.IsDelete == null).ToList()
                    .Translate<Cat_OvertimeTypeEntity>();

                string E_CANCEL = OverTimeStatus.E_CANCEL.ToString();
                string E_REJECTED = OverTimeStatus.E_REJECTED.ToString();
                DateTime beforeDateStart = DateStart.Date.AddDays(-1);
                DateTime afterDateEnd = DateEnd.Date.AddDays(2).AddMinutes(-1);
                // string E_HOLIDAY_HLD = HolidayType.E_HOLIDAY_HLD.ToString();
                List<DateTime> lstHoliday = repoCat_DayOff
                    .FindBy(s => s.IsDelete == null)
                    .Select(m => m.DateOff).ToList<DateTime>();
                //lstWorkday = filterData_NonAllowOT_inGrade(lstWorkday);
                List<Att_OvertimeEntity> lstOvertimeCal = AnalyzeOvertime(lstWorkday, lstShift, lstShiftItem, LstDayOff, lstOvertimeType, _OvertimeInfoFillterAnalyzeEntity, userLogin);
                if (lstOvertimeCal.Count == 0)
                {
                    lstOvertimeCache = lstOvertimeCal;
                    return table;
                }
                OvertimePermitEntity overtimePermit = getOvertimePermit(userLogin);
                FilterNonOvertimeByGradeConfig(lstOvertimeCal);
                SetNonOT(lstOvertimeCal);
                SetStatusOvertimeOnWorkday(lstOvertimeCal);
                FilterOvertimeByMaxHourPerDay(lstOvertimeCal, overtimePermit, _OvertimeInfoFillterAnalyzeEntity.MaximumOvertimeHour);
                RoundOT(lstOvertimeCal, userLogin);
                FillterAllowOvertime(context, lstOvertimeCal, overtimePermit, lstWorkday);
                RoundOT(lstOvertimeCal, userLogin);
                lstOvertimeCal = lstOvertimeCal.Where(m => m.RegisterHours != null && m.RegisterHours > 0).ToList();
                SetStatusLeaveOnWorkday(lstOvertimeCal);//Set loại ngày nghỉ cho OT

                if (lstTypeData.Count > 0)
                {
                    Expression<Func<Att_OvertimeEntity, bool>> predicate = VnResource.Helper.Linq.PredicateBuilder.False<Att_OvertimeEntity>();
                    if (lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_LEAVE.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate1 = m => m.udLeaveTypeCode != null || m.udLeaveTypeCode2 != null;
                        predicate = predicate.Or(predicate1);
                        //lstOvertimeCal = lstOvertimeCal.Where(m => (m.udLeaveTypeCode == null || m.udLeaveTypeCode == string.Empty) && (m.udLeaveTypeCode2 == null || m.udLeaveTypeCode2 == string.Empty)).ToList();
                    }
                    if (lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_NON_LEAVE.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => (m.udLeaveTypeCode == null || m.udLeaveTypeCode == string.Empty) && (m.udLeaveTypeCode2 == null || m.udLeaveTypeCode2 == string.Empty);
                        predicate = predicate.Or(predicate2);
                        //lstOvertimeCal = lstOvertimeCal.Where(m => m.udLeaveTypeCode != null || m.udLeaveTypeCode2 != null).ToList();
                    }
                    if (lstTypeData.Any(m => m == ComputeOvertimeType.E_DATA_OT.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => m.udOvertimeStatus != null;
                        predicate = predicate.Or(predicate2);
                    }
                    if (lstTypeData.Any(m => m == ComputeOvertimeType.E_DATA_NON_OT.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => m.udOvertimeStatus == null;
                        predicate = predicate.Or(predicate2);
                    }
                    lstOvertimeCal = lstOvertimeCal.AsQueryable().Where(predicate).ToList();
                }

                //lstOvertimeCal = lstOvertimeCal.OrderBy(m => m.WorkDate.Date).ThenBy(m => m.ProfileID).ToList();
                //lstOvertimeCache = lstOvertimeCal;
                //BindToGrid(lstOvertimeCache);
                lstOvertimeCal = lstOvertimeCal
                    .Where(m => m.udIsLimitHour == true || m.udIsLimitHourLv1 == true || m.udIsLimitHourLv2 == true)
                    .OrderBy(m => m.WorkDate.Date)
                    .ThenBy(m => m.ProfileID)
                    .ToList();

                //lstOvertimeCal.ForEach(s => s.IsValid = false);

                #region process return table

                foreach (var item in lstOvertimeCal)
                {
                    DataRow row = table.NewRow();
                    Guid? orgId = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault().OrgStructureID;
                    var org = orgs.FirstOrDefault(s => s.ID == orgId);
                    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_OvertimeEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.OrgStructureCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;

                    row[Att_OvertimeEntity.FieldNames.WorkDate] = item.WorkDate;
                    row[Att_OvertimeEntity.FieldNames.InTime] = item.InTime;
                    row[Att_OvertimeEntity.FieldNames.OutTime] = item.OutTime;

                    if (item.udIsLimitHour == null || item.udIsLimitHour == false)
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = "Level1";
                    }
                    else if (item.udIsLimitHourLv1 == null || item.udIsLimitHourLv1 == false)
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = "Level2";
                    }
                    else if (item.udIsLimitHourLv2 == null || item.udIsLimitHourLv2 == false)
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = "Level3";
                    }
                    else
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = string.Empty;
                    }

                    if (item.OvertimeTypeID != Guid.Empty)
                    {
                        var OTType = lstOvertimeType.Where(s => s.ID == item.OvertimeTypeID).FirstOrDefault();
                        row[Att_OvertimeEntity.FieldNames.OvertimeTypeID] = item.OvertimeTypeID;
                        row[Att_OvertimeEntity.FieldNames.OvertimeTypeName] = OTType.OvertimeTypeName;

                        row[OTType.Code] = item.RegisterHours;
                        row[OTType.Code + "Confirm"] = item.ApproveHours ?? 0.0;
                    }
                    if (item.ShiftID != Guid.Empty)
                    {
                        var _shift = lstShift.Where(s => s.ID == item.ShiftID).FirstOrDefault();
                        row[Att_OvertimeEntity.FieldNames.ShiftID] = item.ShiftID;
                        row[Att_OvertimeEntity.FieldNames.ShiftName] = _shift.ShiftName;
                    }
                    if (item.ProfileID != Guid.Empty)
                    {
                        var temp = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();
                        row[Att_OvertimeEntity.FieldNames.ProfileID] = item.ProfileID;
                        row[Att_OvertimeEntity.FieldNames.ProfileName] = temp.ProfileName;
                        row[Att_OvertimeEntity.FieldNames.CodeEmp] = temp.CodeEmp;
                        //row[Att_ReportDetailOvertimeEntity.FieldNames.OrgStructureName] = temp.OrgStructureName;
                    }
                    row[Att_OvertimeEntity.FieldNames.TotalRow] = lstOvertimeCal.Count;
                    row[Att_OvertimeEntity.FieldNames.DateExport] = DateTime.Now;
                    row[Att_OvertimeEntity.FieldNames.AnalyseHour] = item.AnalyseHour;
                    row[Att_OvertimeEntity.FieldNames.udHourByDate] = item.udHourByDate;
                    row[Att_OvertimeEntity.FieldNames.udHourByWeek] = item.udHourByWeek;
                    row[Att_OvertimeEntity.FieldNames.udHourByMonth] = item.udHourByMonth;
                    row[Att_OvertimeEntity.FieldNames.udHourByYear] = item.udHourByYear;
                    row[Att_OvertimeEntity.FieldNames.udLeaveTypeCode] = item.udLeaveTypeCode;
                    row[Att_OvertimeEntity.FieldNames.udOvertimeStatus] = item.udOvertimeStatus;
                    row[Att_OvertimeEntity.FieldNames.RegisterHours] = item.RegisterHours;
                    row[Att_OvertimeEntity.FieldNames.ApproveHours] = item.RegisterHours;
                    table.Rows.Add(row);
                }
                #endregion
                return table;

            }
        }
コード例 #28
0
ファイル: Att_ReportServices.cs プロジェクト: dtafe/vnr
        /// <summary>
        /// Lấy Dữ Liệu BC Báo cáo chi tiết giờ vào giờ ra
        /// </summary>
        /// <param name="DateFrom">Ngày bắt đầu</param>
        /// <param name="DateTo">Ngày kết thúc (Cuối ngày 23:59:59)</param>
        /// <param name="lstProfileIDs">Ds ProfileIDs</param>
        /// <returns></returns>
        public DataTable GetReportSumaryInOut(DateTime DateFrom, DateTime DateTo, List<Hre_ProfileEntity> profiles, Guid[] ShiftIDs, string CodeEmp, bool isIncludeQuitEmp, string userExport, string UserLogin)
        {
            List<Guid> lstProfileIDs = profiles.Select(s => s.ID).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);

                var workDays = repoAtt_Workday.FindBy(s => s.IsDelete == null &&
                    DateFrom <= s.WorkDate && s.WorkDate <= DateTo
                    && (s.InTime1 != null || s.OutTime1 != null))
                    .Select(s => new { s.ProfileID, s.ShiftID, s.ShiftApprove, s.WorkDate, s.InTime1, s.OutTime1 }).ToList();
                //if(lstProfileIDs != null){
                //    workDays = workDays.Where(s => lstProfileIDs.Contains(s.ProfileID)).ToList();
                //}
                if (ShiftIDs != null)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && ShiftIDs.Contains(s.ShiftID.Value)).ToList();
                }

                var profileIds = workDays.Select(s => s.ProfileID).Distinct().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();
                profiles = profiles.Where(s => s.IsDelete == null && profileIds.Contains(s.ID)).ToList();
                // .Select(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.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.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.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();

                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var shifts = repoCat_Shift.GetAll().ToList();

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

                if (!string.IsNullOrEmpty(CodeEmp))
                {
                    profiles = profiles.Where(s => s.CodeEmp == CodeEmp).ToList();
                }
                List<Guid> guids = profiles.Select(s => s.ID).ToList();
                workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList();
                string E_FULLSHIFT = LeaveDayDurationType.E_FULLSHIFT.ToString();
                string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();

                var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leavedayProfiles = repoAtt_LeaveDay.FindBy(s => s.DurationType == E_FULLSHIFT
                     & s.Status == E_APPROVED && DateFrom <= s.DateEnd && s.DateStart <= DateTo).Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                //if (isNotAllowZero)
                //{
                //    profileIds = workDays.Select(s => s.ProfileID).ToList();
                //    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                //}
                DataTable table = CreateReportSummaryInOutSchema();
                foreach (var profile in profiles)
                {
                    for (DateTime date = DateFrom.Date; date <= DateTo; date = date.AddDays(1))
                    {
                        var leaday = leavedayProfiles.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date && s.ProfileID == profile.ID).ToList();
                        if (workDayProfiles.Count > 0 && leaday == null)
                        {
                            DataRow row = table.NewRow();

                            var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                            var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

                            Guid? orgId = profile.OrgStructureID;
                            var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                            var orgGroup = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, 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);
                            var orgDivision = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);


                            row[Att_ReportSumaryInOutEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.GroupCode] = orgGroup != null ? orgGroup.Code : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.GroupName] = orgGroup != null ? orgGroup.OrgStructureName : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.Division] = orgDivision != null ? orgDivision.Code : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.DivisionName] = orgDivision != null ? orgDivision.OrgStructureName : string.Empty;


                            row[Att_ReportSumaryInOutEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Att_ReportSumaryInOutEntity.FieldNames.ProfileName] = profile.ProfileName;

                            row[Att_ReportSumaryInOutEntity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty;
                            row[Att_ReportSumaryInOutEntity.FieldNames.JobtitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                            var workDay1 = workDayProfiles.FirstOrDefault();
                            row[Att_ReportSumaryInOutEntity.FieldNames.Date] = date;
                            row[Att_ReportSumaryInOutEntity.FieldNames.DateFrom] = DateFrom.Date;
                            row[Att_ReportSumaryInOutEntity.FieldNames.DateTo] = DateTo;
                            row[Att_ReportSumaryInOutEntity.FieldNames.DateExport] = DateTime.Now;
                            row[Att_ReportSumaryInOutEntity.FieldNames.UserExport] = userExport;
                            //    row[Att_ReportSumaryInOutEntity.FieldNames.UserExport] = Session[SessionObjects.UserLogin];
                            if (workDay1 != null)
                            {
                                //Guid? ShiftID = workDay1.ShiftApprove ?? workDay1.ShiftID;
                                var shift = shifts.FirstOrDefault(s => s.ID == workDay1.ShiftID);
                                row[Att_ReportSumaryInOutEntity.FieldNames.ShiftName] = shift != null ? shift.ShiftName : string.Empty;
                                row[Att_ReportSumaryInOutEntity.FieldNames.udTimeIn] = workDay1.InTime1 != null ? workDay1.InTime1.Value : DateTime.MinValue;
                                if (workDay1.OutTime1 != null)
                                    row[Att_ReportSumaryInOutEntity.FieldNames.udTimeOut] = workDay1.OutTime1 != null ? workDay1.OutTime1.Value : DateTime.MinValue;
                                if (workDay1.ShiftApprove != Guid.Empty)
                                {
                                    shift = shifts.FirstOrDefault(s => s.ID == workDay1.ShiftApprove);
                                    row[Att_ReportSumaryInOutEntity.FieldNames.ApprovedShift] = shift != null ? shift.ShiftName : string.Empty;
                                }

                            }
                            table.Rows.Add(row);
                        }
                    }
                }
                return table;
            }
        }
コード例 #29
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
                }
            }
        }
コード例 #30
0
ファイル: Can_ReportServices.cs プロジェクト: dtafe/vnr
        public DataTable ReportMealAllowanceOfEmployee(List<Guid?> lstMealAllowanceTypeSettingID, DateTime dateStart, DateTime dateEnd, 
            List<Guid> lstProfileIds, List<Guid?> workPlaceIds, Boolean isCludeEmpQuit)
        {
            DataTable datatable = CreateReportMealAllowanceOfEmployeeSchema();
            using (var context = new VnrHrmDataContext())
            {
                //DateTime dateEnd = dateEnd.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

                string typeApprove = MealRecordMissingStatus.E_APPROVED.ToString(); 
                string typeWaitApprove = MealRecordMissingStatus.E_WAIT_APPROVED.ToString();

                var repoMealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);

                var lstMealRecordMiss = repoMealRecordMissing.FindBy(m => lstProfileIds.Contains(m.ProfileID.Value) &&
                                            (m.Status == typeApprove || m.Status == typeWaitApprove) &&
                                             m.WorkDate >= dateStart && m.WorkDate <= dateEnd).OrderBy(m => m.ProfileID).ThenBy(m => m.WorkDate).ToList();

                var profileIDs = lstMealRecordMiss.Select(hre => hre.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => profileIDs.Contains(m.ID)).ToList();

                //tất cả phòng ban và loại trợ cấp
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var lstOrgAll = repoCat_OrgStructure.FindBy(og => og.IsDelete == null).ToList();

                var repoTypeMealAllSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var lstTypeMealAllSetting = repoTypeMealAllSetting.GetAll().ToList();

                //ds Att_Workday và ca làm việc
                var repoAttWorkday = new Att_WorkDayRepository(unitOfWork);
                var workDays = repoAttWorkday.FindBy(wd => dateStart <= wd.WorkDate && wd.WorkDate <= dateEnd && profileIDs.Contains(wd.ProfileID))
                                .Select(wd => new { wd.ProfileID, wd.ShiftID, wd.WorkDate, wd.InTime1, wd.OutTime1, wd.ShiftActual, wd.ShiftApprove }).ToList();

                var repoShift = new Cat_ShiftRepository(unitOfWork);
                var lstShiftAll = repoShift.GetAll().ToList();

                if (lstProfileIds != null && lstProfileIds.Count >= 1)
                {
                    profiles = profiles.Where(s => lstProfileIds.Contains(s.ID)).ToList();
                }

                if (workPlaceIds != null && workPlaceIds[0] != null)
                {
                    profiles = profiles.Where(s => workPlaceIds.Contains(s.WorkPlaceID)).ToList();
                }

                if (isCludeEmpQuit != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                lstProfileIds = profiles.Select(s => s.ID).ToList();

                //ds ko quẹt thẻ theo loại trợ cấp
                if (lstMealAllowanceTypeSettingID[0] != Guid.Empty)
                {
                    lstMealRecordMiss = lstMealRecordMiss.Where(m => m.MealAllowanceTypeSettingID != null && lstMealAllowanceTypeSettingID.Contains(m.MealAllowanceTypeSettingID.Value)).ToList();
                }

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

                foreach (var recordmiss in lstMealRecordMiss)
                {
                    if (recordmiss == null)
                        continue;
                    var profile = profiles.FirstOrDefault(s => s.ID == recordmiss.ProfileID);
                    if (profile == null) continue;
                    DataRow row = datatable.NewRow();

                    var orgId = lstOrgAll.Where(s => s.ID == recordmiss.OrgStructureID).Select(og => og.ID).FirstOrDefault();

                    var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, lstOrgAll, orgTypes);
                    var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, lstOrgAll, orgTypes);
                    var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, lstOrgAll, orgTypes);
                    var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, lstOrgAll, orgTypes);

                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;

                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateExport] = DateTime.Now;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateFrom] = dateStart;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateTo] = dateEnd;

                    var mealAllowance = lstTypeMealAllSetting.FirstOrDefault(m => m.ID == recordmiss.MealAllowanceTypeSettingID);
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.MealAllowance] = mealAllowance != null ? mealAllowance.MealAllowanceTypeSettingName : string.Empty;

                    var attworkday = workDays.FirstOrDefault(at => at.ProfileID == profile.ID && at.WorkDate == recordmiss.WorkDate);
                    if (attworkday != null)
                    {
                        var shiftActual = lstShiftAll.FirstOrDefault(sf => sf.ID == attworkday.ShiftActual);
                        row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ShiftActual] = shiftActual != null ? shiftActual.ShiftName : string.Empty;

                        var shiftApprove = lstShiftAll.FirstOrDefault(sf => sf.ID == attworkday.ShiftApprove);
                        row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ShiftApprove] = shiftApprove != null ? shiftApprove.ShiftName : string.Empty;
                    }
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.Date] = recordmiss.WorkDate;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.Status] = recordmiss.Status;

                    datatable.Rows.Add(row);
                }

            }
            return datatable;
        }