Exemple #1
0
        /// <summary>
        /// Lấy Dữ Liệu BC Thống Kê Ngày Nghỉ Ốm Năm
        /// </summary>
        /// <returns></returns>
        //public List<Att_ReportSummaryLeaveYearSickEntity> GetReportSummaryLeaveYearSick(DateTime dateYear, List<Guid> lstProfileIDs)
        public DataTable GetReportSummaryLeaveYearSick(int year, List<Hre_ProfileEntity> profiles, Guid[] leavedayTypeIds, bool isNotAllowZero, string userExport)
        {
            using (var context = new VnrHrmDataContext())
            {
                DataTable table = CreateReportSummaryLeaveYearSick();

                bool isIncludeQuitEmp = false;
                // leavedayTypeIds = leavedayTypeIds.Where(p => p != null).ToArray();
                List<Att_ReportSummaryLeaveYearSickEntity> listReportSummaryLeaveYearSick = new List<Att_ReportSummaryLeaveYearSickEntity>();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                DateTime dateStart = new DateTime(year, 1, 1);
                DateTime dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
                string key = OverTimeStatus.E_APPROVED.ToString();
                var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork);

                var leavedayTypes = repoCat_LeaveDayType
                    .FindBy(s => s.CodeStatistic == "P" || s.CodeStatistic == "SC" && s.IsDelete == null)
                    .Select(s => new { s.ID, s.CodeStatistic, s.PaidRate })
                    .Distinct()
                    .ToList();
                var leadayTypeIDs = leavedayTypes.Select(s => s.ID).ToList();
                var leaveDays = new List<Att_LeaveDay>().Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();

                leaveDays = repoAtt_LeaveDay.FindBy(s => s.IsDelete == null && leadayTypeIDs.Contains(s.LeaveDayTypeID)
                    && s.LeaveHours > 0 && dateStart <= s.DateEnd && s.DateStart <= dateEnd)
                    .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
                var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList();
                //if (lstProfileIDs != null && lstProfileIDs.Count > 0)
                //{
                //    leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd && lstProfileIDs.Contains(s.ProfileID))
                //        .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
                //}
                //else
                //{
                //    leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd)
                //        .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
                //}

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

                string E_ANNUAL_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
                string E_SICK_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_SICK_LEAVE.ToString();
                var repoAtt_AnnualLeaveDetail = new Att_AnnualLeaveDetailRepository(unitOfWork);
                var anualLeaves = repoAtt_AnnualLeaveDetail.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value)
                    && (s.Type == E_ANNUAL_LEAVE || s.Type == E_SICK_LEAVE) && s.Year == year)
                    .Select(s => new { s.ProfileID, s.Month3, s.Type }).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();
                List<Att_ReportSummaryLeaveYearSickEntity> lstReportSummaryLeaveYearSickEntity = new List<Att_ReportSummaryLeaveYearSickEntity>();
                Att_ReportSummaryLeaveYearSickEntity reportSummaryLeaveYearSickEntity = null;


                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 > dateStart).ToList();
                }
                if (isNotAllowZero)
                {
                    var profileIDs = leaveDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIDs.Contains(s.ID)).ToList();
                }

                foreach (var profile in profiles)
                {
                    DataRow row = table.NewRow();
                    reportSummaryLeaveYearSickEntity = new Att_ReportSummaryLeaveYearSickEntity();

                    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_ReportSummaryLeaveYearSickEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.ProfileName] = profile.ProfileName;

                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;

                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;

                    //reportSummaryLeaveYearSickEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                    //reportSummaryLeaveYearSickEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                    //reportSummaryLeaveYearSickEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                    //reportSummaryLeaveYearSickEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                    //reportSummaryLeaveYearSickEntity.ProfileName = profile.ProfileName;
                    //reportSummaryLeaveYearSickEntity.CodeEmp = profile.CodeEmp;
                    var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                    var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.UserExport] = userExport;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.DateExport] = DateTime.Today;
                    //reportSummaryLeaveYearSickEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
                    //reportSummaryLeaveYearSickEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                    //reportSummaryLeaveYearSickEntity.DateExport = DateTime.Now;

                    var anual = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_ANNUAL_LEAVE);
                    var anualSick = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_SICK_LEAVE);
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.TotalAllowYear] = anual != null ? anual.Month3 : 0;
                    row[Att_ReportSummaryLeaveYearSickEntity.FieldNames.TotalAllowSick] = anualSick != null ? anualSick.Month3 : 0;

                    //reportSummaryLeaveYearSickEntity.TotalAllowYear = anual != null ? anual.Month3 : 0;
                    //reportSummaryLeaveYearSickEntity.TotalAllowSick = anualSick != null ? anualSick.Month3 : 0;
                    for (int i = 1; i <= 12; i++)
                    {
                        dateStart = new DateTime(year, i, 1);
                        dateEnd = new DateTime(year, i, DateTime.DaysInMonth(year, i));
                        reportSummaryLeaveYearSickEntity.DateFrom = dateStart;
                        reportSummaryLeaveYearSickEntity.DateTo = dateEnd;
                        foreach (var leaday in leavedayTypes)
                        {
                            // Dictionary<string, double> leavedayKeyValue = new Dictionary<string, double>();
                            // var strCodeStatistic = leaday.CodeStatistic + i;
                            //  double leaveDayHours = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID).Sum(s => s.LeaveHours / 8);
                            var sum = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID && s.LeaveHours.HasValue).Sum(s => s.LeaveHours.Value / 8);
                            //if (leaday != null && !string.IsNullOrEmpty(leaday.CodeStatistic) && table.Columns.Contains(strCodeStatistic))
                            //{
                            //row[leaday.CodeStatistic + i] = leaveDayHours > 0 ? leaveDayHours : (double?)null;
                            row[leaday.CodeStatistic + i] = sum > 0 ? (object)sum : (double?)null;
                            //}
                            //    reportSummaryLeaveYearSickEntity.P  = leaveDayHours > 0 ? leaveDayHours : 0;

                        }
                    }
                    table.Rows.Add(row);
                    //listReportSummaryLeaveYearSick.Add(reportSummaryLeaveYearSickEntity);
                }
                var configs = new Dictionary<string, Dictionary<string, object>>();
                var config = new Dictionary<string, object>();
                var confighidden = new Dictionary<string, object>();
                var config90 = new Dictionary<string, object>();
                config90.Add("width", 90);

                var config110 = new Dictionary<string, object>();
                config110.Add("width", 110);
                configs.Add("CodeEmp", config90);
                configs.Add("BranchCode", config90);
                configs.Add("DepartmentCode", config90);
                configs.Add("TeamCode", config90);
                configs.Add("SectionCode", config90);
                configs.Add("BranchName", config110);
                configs.Add("OrgName", config110);
                configs.Add("TeamName", config110);
                configs.Add("SectionName", config110);
                configs.Add("PositionName", config110);
                configs.Add("JobTitleName", config110);

                confighidden.Add("hidden", true);
                configs.Add("UserExport", confighidden);
                configs.Add("DateExport", confighidden);
                config.Add("Width", 200);
                //for (int i = 1; i <= 12; i++)
                //{
                //    config = new Dictionary<string, object>();
                //    configs.Add("P" + i, confighidden);
                //    configs.Add("SC" + i, confighidden);
                //    config.Add("Width", 30);
                //}
                config.Add("locked", true);
                configs.Add("WorkDay", config);
                return table.ConfigTable(configs);
            }



            #region code cũ
            //using (var context = new VnrHrmDataContext())
            //{
            //    List<Att_ReportSummaryLeaveYearSickEntity> listReportSummaryLeaveYearSick = new List<Att_ReportSummaryLeaveYearSickEntity>();
            //    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
            //    //int year = dateYear.Year;
            //    DateTime dateStart = new DateTime(year, 1, 1);
            //    DateTime dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
            //    string key = OverTimeStatus.E_APPROVED.ToString();
            //    var repoCat_LeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
            //    var leavedayTypes = repoCat_LeaveDayType
            //        .FindBy(s => s.CodeStatistic == "P" || s.CodeStatistic == "SC")
            //        .Select(s => new { s.ID, s.CodeStatistic, s.PaidRate })
            //        .Distinct()
            //        .ToList();
            //    var leadayTypeIDs = leavedayTypes.Select(s => s.ID).ToList();
            //    var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork);
            //    var leaveDays = new List<Att_LeaveDay>().Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
            //    if (lstProfileIDs != null && lstProfileIDs.Count > 0)
            //    {
            //        leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd && lstProfileIDs.Contains(s.ProfileID))
            //            .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
            //    }
            //    else
            //    {
            //        leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd)
            //            .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
            //    }
            //    var profileIds = leaveDays.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();
            //    string E_ANNUAL_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
            //    string E_SICK_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_SICK_LEAVE.ToString();
            //    var repoAtt_AnnualLeaveDetail = new Att_AnnualLeaveDetailRepository(unitOfWork);
            //    var anualLeaves = repoAtt_AnnualLeaveDetail.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && (s.Type == E_ANNUAL_LEAVE || s.Type == E_SICK_LEAVE) && s.Year == year)
            //                    .Select(s => new { s.ProfileID, s.Month3, s.Type }).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();
            //    List<Att_ReportSummaryLeaveYearSickEntity> lstReportSummaryLeaveYearSickEntity = new List<Att_ReportSummaryLeaveYearSickEntity>();
            //    Att_ReportSummaryLeaveYearSickEntity reportSummaryLeaveYearSickEntity = null;

            //    foreach (var profile in profiles)
            //    {
            //        reportSummaryLeaveYearSickEntity = new Att_ReportSummaryLeaveYearSickEntity();
            //        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);
            //        reportSummaryLeaveYearSickEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
            //        reportSummaryLeaveYearSickEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
            //        reportSummaryLeaveYearSickEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
            //        reportSummaryLeaveYearSickEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
            //        var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
            //        var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
            //        reportSummaryLeaveYearSickEntity.ProfileName = profile.ProfileName;
            //        reportSummaryLeaveYearSickEntity.CodeEmp = profile.CodeEmp;
            //        reportSummaryLeaveYearSickEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
            //        reportSummaryLeaveYearSickEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
            //        reportSummaryLeaveYearSickEntity.DateExport = DateTime.Now;
            //        var anual = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_ANNUAL_LEAVE);
            //        var anualSick = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_SICK_LEAVE);
            //        reportSummaryLeaveYearSickEntity.TotalAllowYear = anual != null ? anual.Month3 : 0;
            //        reportSummaryLeaveYearSickEntity.TotalAllowSick = anualSick != null ? anualSick.Month3 : 0;
            //        for (int i = 1; i <= 12; i++)
            //        {
            //            dateStart = new DateTime(year, i, 1);
            //            dateEnd = new DateTime(year, i, DateTime.DaysInMonth(year, i));
            //            reportSummaryLeaveYearSickEntity.DateFrom = dateStart;
            //            reportSummaryLeaveYearSickEntity.DateTo = dateEnd;
            //            foreach (var leaday in leavedayTypes)
            //            {
            //                Dictionary<string, double> leavedayKeyValue = new Dictionary<string, double>();
            //                double leaveDayHours = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID).Sum(s => s.LeaveHours / 8);

            //            }
            //        }
            //        listReportSummaryLeaveYearSick.Add(reportSummaryLeaveYearSickEntity);
            //    }

            //    return listReportSummaryLeaveYearSick;
            //}
            #endregion
        }
Exemple #2
0
        /// <summary>
        /// Lấy Dữ Liệu BC Chi Tiết Nghỉ Phép Ốm của nhân viên
        /// </summary>
        /// <returns></returns>
        /// 
        public DataTable GetReportLeaveYear(int dateYear, List<Guid?> leaveDayTypeIDs, List<Guid> lstProfileIDs, string userExport, string codeEmp)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                int year = dateYear;
                DateTime dateStart = new DateTime(year, 1, 1);
                DateTime dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
                string key = OverTimeStatus.E_APPROVED.ToString();
                var repoCat_Leaveday = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leavedayTypes = repoCat_Leaveday.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PaidRate }).Distinct().ToList();
                var leadayTypeIDs = leavedayTypes.Select(s => s.ID).ToList();
                var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leaveDays = new List<Att_LeaveDay>().Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd, s.LeaveDays }).ToList();
                leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd)
                        .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd, s.LeaveDays }).ToList();
                leaveDays = leaveDays.Where(s => leaveDayTypeIDs.Contains(s.ProfileID)).ToList();

                if (leaveDayTypeIDs[0] != null)
                {
                    leaveDays = leaveDays.Where(s => leaveDayTypeIDs.Contains(s.LeaveDayTypeID)).ToList();
                }
                var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList();
                lstProfileIDs.AddRange(profileIds);
                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();

                profiles = profiles.Where(s => lstProfileIDs.Contains(s.ID)).ToList();
                if (!string.IsNullOrEmpty(codeEmp))
                {
                    char[] ext = new char[] { ';', ',' };
                    List<string> codeEmpSeachs = codeEmp.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
                    if (codeEmpSeachs.Count == 1)
                    {
                        string codeEmpSearch = codeEmpSeachs[0];
                        profiles = profiles.Where(hr => hr.CodeEmp == codeEmpSearch).ToList();
                    }
                    else
                    {
                        profiles = profiles.Where(hr => codeEmpSeachs.Contains(hr.CodeEmp)).ToList();
                    }
                }

                string E_ANNUAL_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
                string E_SICK_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_SICK_LEAVE.ToString();
                var repoAtt_AnnualLeaveDetail = new Att_AnnualLeaveDetailRepository(unitOfWork);

                var anualLeaves = repoAtt_AnnualLeaveDetail.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && (s.Type == E_ANNUAL_LEAVE || s.Type == E_SICK_LEAVE) && s.Year == year)
                   .Select(s => new { s.ProfileID, s.Month3, s.Type }).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 repoAtt_Pregnancy = new Att_PregnancyRepository(unitOfWork);
                var pregnancys = repoAtt_Pregnancy.FindBy(s => s.DateStart != null && s.DateEnd != null && dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID))
                                .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();

                Dictionary<string, string> dicSchemma = new Dictionary<string, string>();
                DataTable tb = GetSchema(dateStart, dateEnd, out dicSchemma);
                int stt = 0;
                foreach (var profile in profiles)
                {
                    stt++;
                    DataRow dr = tb.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);
                    dr[Att_ReportSickLeaveEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                    dr[Att_ReportSickLeaveEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                    dr[Att_ReportSickLeaveEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                    dr[Att_ReportSickLeaveEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                    dr[Att_ReportSickLeaveEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    dr[Att_ReportSickLeaveEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    dr[Att_ReportSickLeaveEntity.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);
                    dr[Att_ReportSickLeaveEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    dr[Att_ReportSickLeaveEntity.FieldNames.ProfileName] = profile.ProfileName;
                    dr[Att_ReportSickLeaveEntity.FieldNames.CodePosition] = positon != null ? positon.Code : string.Empty;
                    dr[Att_ReportSickLeaveEntity.FieldNames.CodeJobtitle] = jobtitle != null ? jobtitle.Code : string.Empty;
                    var anual = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_ANNUAL_LEAVE);
                    var anualSick = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_SICK_LEAVE);
                    if (dicSchemma.ContainsKey(Att_ReportSickLeaveEntity.FieldNames.SumANL))
                    {
                        dr[dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumANL]] = anual != null ? (object)anual.Month3 : DBNull.Value;
                        string SttOfData = dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumANL].Substring(4, dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumANL].Length - 4);
                        if (stt == 1)
                        {
                            dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total P";
                        }
                        else if (stt == 2)
                        {
                            dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total SC";
                        }
                    }
                    if (dicSchemma.ContainsKey(Att_ReportSickLeaveEntity.FieldNames.SumSICK))
                    {
                        dr[dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumSICK]] = anualSick != null ? (object)anualSick.Month3 : DBNull.Value;

                        string SttOfData = dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumSICK].Substring(4, dicSchemma[Att_ReportSickLeaveEntity.FieldNames.SumSICK].Length - 4);
                        if (stt == 1)
                        {
                            dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total P";
                        }
                        else if (stt == 2)
                        {
                            dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = "Total SC";
                        }
                    }
                    //var pregnancyProfiles = pregnancys.Where(s => s.ProfileID == profile.ID).ToList();
                    //for (DateTime DateCheck = dateStart; DateCheck <= dateEnd; DateCheck = DateCheck.AddMonths(1))
                    //{
                    //    int dayPregancy = 0;
                    //    foreach (var pregnancyProfile in pregnancyProfiles)
                    //    {
                    //        for (DateTime date = pregnancyProfile.DateStart.Value; date < pregnancyProfile.DateEnd.Value; date = date.AddDays(1))
                    //        {
                    //            dayPregancy += 1;
                    //        }
                    //    }

                    //    foreach (var leaday in leavedayTypes)
                    //    {
                    //        if (dicSchemma.ContainsKey(leaday.Code + DateCheck.Month))
                    //        {
                    //            var sum = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID).Sum(s => s.TotalDuration);
                    //            dr[dicSchemma[leaday.CodeStatistic + DateCheck.Month]] = sum > 0 ? (object)(sum - dayPregancy) : DBNull.Value;
                    //            string SttOfData = dicSchemma[leaday.CodeStatistic + DateCheck.Month].Substring(4, dicSchemma[leaday.CodeStatistic + DateCheck.Month].Length - 4);
                    //            if (stt == 1)
                    //            {
                    //                dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = DateCheck.ToString("MMM-yyyy");
                    //            }
                    //            else if (stt == 2)
                    //            {
                    //                dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = leaday.CodeStatistic;
                    //            }
                    //        }
                    //    }
                    //}
                    //dr[Att_ReportSickLeaveEntity.FieldNames.DateFrom] = dateStart;
                    //dr[Att_ReportSickLeaveEntity.FieldNames.DateTo] = dateEnd;
                    //tb.Rows.Add(dr);
                    var pregnancyProfiles = pregnancys.Where(s => s.ProfileID == profile.ID).ToList();

                    for (DateTime DateCheck = dateStart; DateCheck <= dateEnd; DateCheck = DateCheck.AddMonths(1))
                    {
                        int dayPregancy = 0;
                        foreach (var pregnancyProfile in pregnancyProfiles)
                        {
                            for (DateTime date = pregnancyProfile.DateStart.Value; date < pregnancyProfile.DateEnd.Value; date = date.AddDays(1))
                            {
                                dayPregancy += 1;
                            }
                        }

                        foreach (var leaday in leavedayTypes)
                        {
                            if (dicSchemma.ContainsKey(leaday.Code + DateCheck.Month))
                            {
                                var sum = leaveDays.Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID).Sum(s => s.LeaveDays);
                                dr[dicSchemma[leaday.Code + DateCheck.Month]] = sum > 0 ? (object)(sum - dayPregancy) : DBNull.Value;
                                string SttOfData = dicSchemma[leaday.Code + DateCheck.Month].Substring(4, dicSchemma[leaday.Code + DateCheck.Month].Length - 4);
                                if (stt == 1)
                                {
                                    dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = DateCheck.ToString("MMM-yyyy");
                                }
                                else if (stt == 2)
                                {
                                    dr[Att_ReportSickLeaveEntity.FieldNames.DataHeader + SttOfData] = leaday.Code;
                                }
                            }
                        }
                    }
                    dr[Att_ReportSickLeaveEntity.FieldNames.DateFrom] = dateStart;
                    dr[Att_ReportSickLeaveEntity.FieldNames.DateTo] = dateEnd;
                    dr[Att_ReportSickLeaveEntity.FieldNames.UserExport] = userExport;
                    dr[Att_ReportSickLeaveEntity.FieldNames.DateExport] = DateTime.Today;
                    tb.Rows.Add(dr);
                }


                return tb;
            }
        }
Exemple #3
0
        /// <summary>
        /// Lay du lieu bao cao tong hop nghi om
        /// </summary>
        /// <param name="dateYear"></param>
        /// <param name="lstProfileIDs"></param>
        /// <returns></returns>
        public List<Att_ReportSickLeaveEntity> GetReportSickLeave(DateTime dateYear, List<Guid> lstProfileIDs)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                int year = dateYear.Year;
                DateTime dateStart = new DateTime(year, 1, 1);
                DateTime dateEnd = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
                string key = OverTimeStatus.E_APPROVED.ToString();
                var repoCat_Leaveday = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leavedayTypes = repoCat_Leaveday.FindBy(s => s.CodeStatistic == "P" || s.CodeStatistic == "SC").Select(s => new { s.ID, s.CodeStatistic, s.PaidRate }).Distinct().ToList();
                var leadayTypeIDs = leavedayTypes.Select(s => s.ID).ToList();
                var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leaveDays = new List<Att_LeaveDay>().Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
                if (lstProfileIDs != null && lstProfileIDs.Count > 0)
                {
                    leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd && lstProfileIDs.Contains(s.ProfileID))
                        .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
                }
                else
                {
                    leaveDays = repoAtt_LeaveDay.FindBy(s => leadayTypeIDs.Contains(s.LeaveDayTypeID) && s.LeaveHours > 0 && s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd)
                        .Select(s => new { s.ProfileID, s.LeaveDayTypeID, s.LeaveHours, s.DateStart, s.DateEnd }).ToList();
                }
                var profileIds = leaveDays.Select(s => s.ProfileID).Distinct().ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);

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

                string E_ANNUAL_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
                string E_SICK_LEAVE = HRM.Infrastructure.Utilities.EnumDropDown.AnnualLeaveDetailType.E_SICK_LEAVE.ToString();
                var repoAtt_AnnualLeaveDetail = new Att_AnnualLeaveDetailRepository(unitOfWork);
                var anualLeaves = repoAtt_AnnualLeaveDetail.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && (s.Type == E_ANNUAL_LEAVE || s.Type == E_SICK_LEAVE) && s.Year == year)
                .Select(s => new { s.ProfileID, s.Month3, s.Type }).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();
                List<Att_ReportSickLeaveEntity> lstReportSickLeaveEntity = new List<Att_ReportSickLeaveEntity>();
                Att_ReportSickLeaveEntity reportSickLeaveEntity = null;
                foreach (var profile in profiles)
                {
                    reportSickLeaveEntity = new Att_ReportSickLeaveEntity();
                    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);
                    reportSickLeaveEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                    reportSickLeaveEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                    reportSickLeaveEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                    reportSickLeaveEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                    var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                    var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                    reportSickLeaveEntity.ProfileName = profile.ProfileName;
                    reportSickLeaveEntity.CodeEmp = profile.CodeEmp;
                    reportSickLeaveEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
                    reportSickLeaveEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                    reportSickLeaveEntity.DateExport = DateTime.Now;
                    var anual = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_ANNUAL_LEAVE);
                    var anualSick = anualLeaves.FirstOrDefault(s => s.ProfileID == profile.ID && s.Type == E_SICK_LEAVE);
                    reportSickLeaveEntity.TotalP = anual != null ? anual.Month3 : 0;
                    reportSickLeaveEntity.TotalSC = anualSick != null ? anualSick.Month3 : 0;
                    //reportSickLeaveEntity.BugetYearP = anualSick != null ? anualSick.Month3 : 0;
                    //reportSickLeaveEntity.BalanceSC = anualSick != null ? anualSick.Month3 : 0;

                    for (int i = 1; i <= 12; i++)
                    {
                        dateStart = new DateTime(year, i, 1);
                        dateEnd = new DateTime(year, i, DateTime.DaysInMonth(year, i));
                        reportSickLeaveEntity.DateFrom = dateStart;
                        reportSickLeaveEntity.DateTo = dateEnd;

                        foreach (var leaday in leavedayTypes)
                        {
                            Dictionary<string, double> leavedayKeyValue = new Dictionary<string, double>();
                            double leaveDayHours = leaveDays
                                .Where(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && s.ProfileID == profile.ID && s.LeaveDayTypeID == leaday.ID)
                                .Sum(s => s.LeaveHours.Value / 8);
                        }
                    }
                    lstReportSickLeaveEntity.Add(reportSickLeaveEntity);
                }
                return lstReportSickLeaveEntity;
            }

        }