Пример #1
0
 /// <summary>
 /// Lấy danh sách tất cả WorkDay
 /// </summary>
 /// <returns></returns>
 public void SubmitWorkDay(List<Guid> ids)
 {
     using (var context = new VnrHrmDataContext())
     {
         var lstWorkday = new List<Att_Workday>();
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Att_WorkDayRepository(unitOfWork);
         lstWorkday = repo.FindBy(m => ids.Contains(m.ID)).ToList();
         foreach (var workday in lstWorkday)
         {
             workday.Status = AttendanceDataStatus.E_SUBMIT.ToString();
             repo.SaveChanges();
         }
     }
 }
Пример #2
0
        public DataTable ReportMealTimeDetailNoEat(List<Guid?> lstWorkPlace, String status, String codeEmp, Boolean isCludeEmpQuit,
            DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            List<Can_ReportMealTimeDetailNoEatEntity> lstreportMealTimeDetailNoEatEntity = new List<Can_ReportMealTimeDetailNoEatEntity>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);

                var repomealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                var mealRecordMissings = repomealRecordMissing.FindBy(s => s.ProfileID != null && s.WorkDate != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd
                                         && s.MealAllowanceTypeSettingID == null)
                                         .Select(s => new { s.ProfileID, s.WorkDate, s.Status, s.MealAllowanceTypeSettingID, s.OrgStructureID }).ToList();
                DataTable table = GetSchemaRptMealTimeDetailNoEat();
                if (mealRecordMissings == null && mealRecordMissings.Count < 1)
                {
                    return table;
                }
                var profileIds = mealRecordMissings.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(s => profileIds.Contains(s.ID)).ToList();

                if (orgIDs != null && orgIDs[0] != null)
                {
                    profiles = profiles.Where(hr => hr.OrgStructureID != null && orgIDs.Contains(hr.OrgStructureID)).ToList();
                }
                if (lstWorkPlace[0] != Guid.Empty)
                {
                    profiles = profiles.Where(wp => wp.WorkPlaceID != null && lstWorkPlace.Contains(wp.WorkPlaceID.Value)).ToList();
                }
                if (isCludeEmpQuit != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).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();
                    }
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecordMissings = mealRecordMissings.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                //trạng thái
                if (status != null)
                {
                    mealRecordMissings = mealRecordMissings.Where(meal => status.Contains(meal.Status)).ToList();
                }

                //workday
                var repAttWorkday = new Att_WorkDayRepository(unitOfWork);
                var lstWorkday = repAttWorkday.FindBy(wd => wd.WorkDate >= dateStart && wd.WorkDate <= dateEnd && profileIds.Contains(wd.ProfileID))
                                 .Select(wd => new {wd.ProfileID, wd.InTime1, wd.OutTime1, wd.WorkDate }).ToList();

                //danh mục leaveday type
                var repLeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leadayHLDID = repLeaveDayType.FindBy(ld => ld.Code == "HLD").Select(ld => ld.ID).FirstOrDefault();

                //att_leaveday
                var repAttLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                var lstLeaveday = repAttLeaveDay.FindBy(ld => ld.LeaveDayTypeID != leadayHLDID && (profileIds.Contains(ld.ProfileID))
                                && ld.Status == E_APPROVED && dateStart <= ld.DateEnd && ld.DateStart <= dateEnd)
                                .Select(ld => new { ld.ProfileID, ld.DateStart, ld.DateEnd }).ToList();

                //can_line
                var repHDTjob = new Can_LineRepository(unitOfWork);
                var lstHDTjobID = repHDTjob.FindBy(hdt => hdt.IsHDTJOB == true).Select(hdt => hdt.ID).ToList();
                
                //Can_mealRecord
                var repMealRecord = new Can_MealRecordRepository(unitOfWork);
                var lstMealRecord = repMealRecord.FindBy(meal => meal.LineID != null && !lstHDTjobID.Contains(meal.LineID.Value) && meal.ProfileID.HasValue && profileIds.Contains(meal.ProfileID.Value)
                                    && dateStart <= meal.WorkDay && meal.WorkDay <= dateEnd)
                                  .Select(meal => new { meal.ProfileID, meal.WorkDay }).ToList();

                //Allowance type setting
                var repAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var lstAllowanceTypeSetting = repAllowanceTypeSetting.GetAll().Select(al => new {al.ID, al.MealAllowanceTypeSettingName }).ToList();


                var repoOrgType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var listOrgType = repoOrgType.FindBy(s => s.IsDelete == null).ToList();

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

                //var repoLine = new Can_LineRepository(unitOfWork);
                //var repoCatering = new Can_CateringRepository(unitOfWork);
                //var repoCanteen = new Can_CanteenRepository(unitOfWork);

                foreach (var mealRecordMissing in mealRecordMissings)
                {
                    // neu co quet the an thi ko tinh
                    var meadRecord = lstMealRecord.FirstOrDefault(s => s.ProfileID == mealRecordMissing.ProfileID && s.WorkDay.Value.Date == mealRecordMissing.WorkDate.Value.Date);
                    if (meadRecord != null)
                    {
                        continue;
                    }
                    // neu ngay do dk nghi thi ko tinh
                    var leaveday = lstLeaveday.FirstOrDefault(s => s.ProfileID == mealRecordMissing.ProfileID && s.DateStart <= mealRecordMissing.WorkDate && mealRecordMissing.WorkDate <= s.DateEnd);
                    if (leaveday != null)
                    {
                        continue;
                    }
                    // neu ngay do ko di lam thi ko tinh
                    var workday = lstWorkday.FirstOrDefault(s => s.ProfileID == mealRecordMissing.ProfileID && s.WorkDate.Date == mealRecordMissing.WorkDate.Value.Date);
                    if (workday == null)
                    {
                        continue;
                    }
                    DataRow row = table.NewRow();
                    if (workday != null && workday.InTime1 != null)
                    {
                        row["TimeIn"] = workday.InTime1;
                    }
                    if (workday != null && workday.OutTime1 != null)
                    {
                        row["TimeOut"] = workday.OutTime1;
                    }
                    var profile = profiles.FirstOrDefault(s => s.ID == mealRecordMissing.ProfileID);
                    if (profile != null)
                    {
                        var type = lstAllowanceTypeSetting.FirstOrDefault(s => s.ID == mealRecordMissing.MealAllowanceTypeSettingID);
                        var org = listOrgAll.FirstOrDefault(s => profile != null && s.ID == mealRecordMissing.OrgStructureID);
                        var orgBranch = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_BRANCH, listOrgAll, listOrgType);
                        var orgOrg = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_DEPARTMENT, listOrgAll, listOrgType);
                        var orgTeam = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_TEAM, listOrgAll, listOrgType);
                        var orgSection = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_SECTION, listOrgAll, listOrgType);

                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            
                        row[Can_ReportCardByLocationEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                        row[Can_ReportCardByLocationEntity.FieldNames.ProfileName] = profile.ProfileName;
                        row[Can_ReportCardByLocationEntity.FieldNames.Date] = mealRecordMissing.WorkDate;
                        row[Can_ReportCardByLocationEntity.FieldNames.DateFrom] = dateStart;
                        row[Can_ReportCardByLocationEntity.FieldNames.DateTo] = dateEnd;

                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.DateExport] = DateTime.Now;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.MealAllowanceName] = type != null ? type.MealAllowanceTypeSettingName : string.Empty;
                        table.Rows.Add(row);
                    }

                }
                return table;
            }
        }
Пример #3
0
        public void ComputeMealRecordMissing(List<Guid> lstProfileIds, DateTime dateFrom, DateTime dateToSearch, List<Guid> TamScanReasonMissID, string Status, List<Guid?> lstAllowanceTypeIDs)
        {
            List<Can_MealRecordMissingEntity> lstMealRecord = new List<Can_MealRecordMissingEntity>();
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateTo = DateTime.Now;
                if (dateToSearch != null && dateToSearch != SqlDateTime.MaxValue.Value)
                {
                     dateTo = dateToSearch.AddDays(1).AddMinutes(-1);
                }
                if(lstProfileIds == null)
                {
                    return;
                }
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                string statusAllowance = StatusMealAllowanceToMoney.E_APPROVED.ToString();
                var repoMealAllowance = new Can_MealAllowanceToMoneyRepository(unitOfWork);
                var mealAllowanceProfies = repoMealAllowance.FindBy(s => s.Status == statusAllowance && dateFrom <= s.DateTo && s.DateFrom <= dateTo)
                    .Select(s => new { s.ProfileID, s.MealAllowanceTypeID, s.DateFrom, s.DateTo }).ToList();

                var repoMissReason = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var resons = repoMissReason.FindBy(s => s.IsForCMS == true).Select(s => new { s.ID, s.IsFullPay }).ToList();

                var repoWorkday = new Att_WorkDayRepository(unitOfWork);
                var workDays = repoWorkday.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateFrom <= s.WorkDate && s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID))
               .Select(s => new { s.ProfileID, s.WorkDate, s.MissInOutReason, s.Status, s.FirstInTime, s.LastOutTime }).ToList();

                var repoMealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecordProfiles = repoMealRecord.FindBy(s => s.WorkDay != null && s.ProfileID != null
                && dateFrom <= s.WorkDay && s.WorkDay <= dateTo && lstProfileIds.Contains(s.ProfileID.Value))
                .Select(s => new { s.ProfileID, s.TimeLog, s.WorkDay }).ToList();

                var statusLeaveDay = AttendanceDataStatus.E_APPROVED.ToString();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leaveDayProfiles = repoLeaveDay.FindBy(s => s.Status == statusLeaveDay && dateFrom <= s.DateEnd && s.DateStart <= dateTo)
               .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                var tamSanResons = repoMissReason.GetAll().ToList();
                var repoMealAllowanceTypeSettings = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealSesttings = repoMealAllowanceTypeSettings.GetAll().Select(s => new { s.ID, s.Amount, s.MealAllowanceTypeSettingName }).ToList();
                if (TamScanReasonMissID != null && TamScanReasonMissID[0] != Guid.Empty)
                {
                    workDays = workDays.Where(s => s.MissInOutReason != null && TamScanReasonMissID.Contains(s.MissInOutReason.Value)).ToList();
                }
                if (Status != null)
                {
                    workDays = workDays.Where(s => s.Status != null && Status == s.Status).ToList();
                }
                var repoRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                List<Can_MealRecordMissing> mealRecordMissings = repoRecordMissing.FindBy(s => dateFrom <= s.WorkDate && s.WorkDate <= dateTo && s.ProfileID != null
                    && lstProfileIds.Contains(s.ProfileID.Value)).ToList();
                var workDayProfies = repoWorkday.FindBy(s => (s.InTime1 != null || s.OutTime1 != null) && dateFrom <= s.WorkDate
                   && s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate, s.ShiftID }).ToList();
                var profileIDs = workDayProfies.Select(s => s.ProfileID).Distinct().ToList();
                var lstmeal = new List<Can_MealRecordMissing>();
                foreach (var profileID in profileIDs)
                {
                    for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
                    {
                        var recordProfileIDs = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var leavedayProfileIDs = leaveDayProfiles.Where(s => s.DateStart != null && s.DateEnd != null && s.DateStart.Date <= date.Date
                            && date.Date <= s.DateEnd.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date.Date && s.ProfileID == profileID && !recordProfileIDs.Contains(s.ProfileID) && !leavedayProfileIDs.Contains(s.ProfileID)).ToList();
                        foreach (var workDay in workDayProfiles)
                        {
                            var meal = mealRecordMissings.FirstOrDefault(s => s.ProfileID == workDay.ProfileID && s.WorkDate.Value.Date == workDay.WorkDate.Date);
                            if (meal == null)
                            {
                                meal = new Can_MealRecordMissing();
                                meal.ID = Guid.Empty;
                                lstmeal.Add(meal);
                            }
                            meal.ProfileID = workDay.ProfileID;
                            meal.WorkDate = workDay.WorkDate;
                            if (meal.TamScanReasonMissID == Guid.Empty)
                            {
                                if (workDay.MissInOutReason != Guid.Empty)
                                {
                                    meal.TamScanReasonMissID = workDay.MissInOutReason;
                                    var tamScan = tamSanResons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                    if (tamScan != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = tamScan.MealAllowanceTypeSettingID;
                                        meal.TamScanReasonMissID = tamScan.ID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == tamScan.MealAllowanceTypeSettingID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }
                                else
                                {
                                    var allownce = mealAllowanceProfies.FirstOrDefault(s => s.ProfileID == workDay.ProfileID &&
                                        s.DateFrom <= date && date <= s.DateTo);
                                    if (allownce != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = allownce.MealAllowanceTypeID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == allownce.MealAllowanceTypeID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }

                            }
                            if (meal.MealAllowanceTypeSettingID != Guid.Empty)
                            {
                                meal.Status = MealRecord_Status.E_APPROVED.ToString();
                            }
                            else
                            {
                                meal.Status = MealRecord_Status.E_SUBMIT.ToString();
                            }
                            meal.Type = WorkdaySrcType.E_MANUAL.ToString();
                            if (workDay.FirstInTime == null && workDay.LastOutTime == null && workDay.MissInOutReason != Guid.Empty)
                            {
                                var tamSanReson = resons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                if (tamSanReson != null)
                                {
                                    meal.IsFullPay = tamSanReson.IsFullPay;
                                }
                            }
                        }
                    }
                }

                 repoRecordMissing.Add(lstmeal);
                repoMissReason.SaveChanges();
            }
        }
Пример #4
0
        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();
        }
Пример #5
0
        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;

            }
        }
Пример #6
0
        public DataTable ReportMultiSlideCard(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime dateStart, DateTime dateEnd, List<int> lstProfileIds)
        {
            List<Can_ReportMultiSlideCardEntity> lstReportMultiSlideCard = new List<Can_ReportMultiSlideCardEntity>();
            DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEnd);
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var mealRecords = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var repo = new Can_MealRecordRepository(unitOfWork);
                mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
                        .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var lstcateringids = mealRecords.Select(m =>m.CateringID).ToList();
                var lstcanteenids = mealRecords.Select(m =>m.CanteenID).ToList();
                var lstlineids = mealRecords.Select(m => m.LineID).ToList();

                var workDays = new List<Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                workDays = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                    .Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                
                var Cardcode = mealRecords.Select(s => s.CardCode).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => Cardcode.Contains(m.CodeAttendance) && lstProfileIds.Contains(m.Id)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList();

                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoOrg.FindBy(m => m.Code != null).ToList();

                var catering = new List<Can_Catering>().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                if(CarteringIDs != null && CarteringIDs.Count >0)
                {
                    catering = repocatering.FindBy(m => CarteringIDs.Contains(m.Id)).ToList();
                }
                else
                    catering = repocatering.GetAll().ToList();


                var canteen = new List<Can_Canteen>().ToList();
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null && CanteenIDS.Count > 0)
                {
                    canteen = repocanteen.FindBy(m => CanteenIDS.Contains(m.Id)).ToList();
                }
                else
                    canteen = repocanteen.GetAll().ToList();

                var line = new List<Can_Line>().ToList();
                var repoline = new Can_LineRepository(unitOfWork);
                if (LineIDS != null && LineIDS.Count > 0)
                {
                    line = repoline.FindBy(m => LineIDS.Contains(m.Id)).ToList();
                }
                else
                    line = repoline.GetAll().ToList();

                Can_ReportMultiSlideCardEntity ReportMultiSlideCardEntity = new Can_ReportMultiSlideCardEntity();
                foreach (var profile in profiles)
                {
                    DataRow row = datatable.NewRow();
                    var orgbyprofile = orgs.Where(m => m.Id == profile.OrgStructureID).FirstOrDefault();
                    var cateringbyprofile = catering.Where(m => lstcateringids.Contains(m.Id)).FirstOrDefault();
                    var lineprofile = line.Where(m => lstlineids.Contains(m.Id)).FirstOrDefault();
                    var canteenbyprofile = canteen.Where(m =>  lstcanteenids.Contains(m.Id)).FirstOrDefault();
                    row[Can_ReportMultiSlideCardEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.OrgStructureName] = orgbyprofile.OrgStructureName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Cartering] = cateringbyprofile.CateringName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Canteen] = canteenbyprofile.CanteenName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Line] = lineprofile.LineName;
                    var mealRecordProfiles = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).ToList();
                    var workDayProfiles = workDays.Where(s => s.ProfileID == profile.Id).ToList();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date);
                        if (meal != null)
                        {
                            row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value;
                            //row["SumCardMore" + date.Day] = mealRecordProfiles.Count(s => s.TimeLog == date) - workDayProfiles.Count(s => s.WorkDate == date);
                        }
                    }
                    datatable.Rows.Add(row);
                }
            }
            return datatable;
        }
Пример #7
0
        /// <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;
            }
        }
Пример #8
0
        public DataTable GetReportDetailOvertime(string userExport, DateTime dateStart, DateTime dateEndSearch, string ProfileName, string CodeEmp, string OrgIDString, List<Guid?> lstovertimeTypeIds, bool noDisplay0Data, bool isIncludeQuitEmp)
        {
            DataTable table = CreateReportDetailOvertimeSchema();
            DateTime dateEnd = dateEndSearch.AddDays(1).AddMinutes(-1);

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



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

                }

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

                        if (shift != null)
                        {

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


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

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

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

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

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

                configtime.Add("width", 80);
                configtime.Add("format", "{0:HH:mm:ss}");
                configs.Add("udOutTime", configtime);
                configs.Add("udInTime", configtime);
                // return table.ConfigDatatable();
                return table.ConfigTable(configs);
            }
        }
Пример #9
0
        public DataTable ReportMealTimeDetail(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                DataTable datatable = CreateReportMealTimeDetailSchema(dateStart, dateEnd);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoMealRecord = new Can_MealRecordRepository(unitOfWork);
                var repoLine = new Can_LineRepository(unitOfWork);
                var lineHDTJobIDs = repoLine.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList();
                var mealRecords = repoMealRecord.FindBy(s => s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)
                    && s.ProfileID != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).ToList();
                if (mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var workDayProfies = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate
                  && s.WorkDate <= dateEnd && profileIds.Contains(s.ProfileID)).ToList();

                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(s => profileIds.Contains(s.ID)).ToList();

                var repoLeaveday = new Att_LeavedayRepository(unitOfWork);
                var leavedays = repoLeaveday.FindBy(s => dateStart <= s.DateEnd
                 && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID)).
                 Select(s => new { s.ProfileID, s.DateStart, s.DateEnd, s.LeaveDayTypeID }).ToList();

                var repoleaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leaveDayTypes = repoleaveDayType.GetAll().Select(s => new { s.ID, s.LeaveDayTypeName }).ToList();

                List<Cat_OrgStructure> orgs = new List<Cat_OrgStructure>();
                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                orgs = repoOrg.FindBy(s => s.Code != null).ToList();
                if (orgIDs != null && orgIDs.Count > 0)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                if (CanteenIDS != null && CanteenIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList();
                }
                if (CarteringIDs != null && CarteringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList();
                }
                if (LineIDS != null && LineIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList();
                }
                if (mealRecords.Count < 1)
                {
                    return datatable;
                }
                profileIds = mealRecords.Select(s => s.ProfileID.Value).ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                var orgTypes = new List<Cat_OrgStructureType>();

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

                var repoCanteen = new Can_CanteenRepository(unitOfWork);
                var repoCatering = new Can_CateringRepository(unitOfWork);
                var canteens = repoCanteen.GetAll().ToList();
                var caterings = repoCatering.GetAll().ToList();
                var lines = repoLine.GetAll().ToList();
                #region Code Cũ
                //foreach (var profile in profiles)
                //{
                //    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.Id).Select(s => s.WorkDate.Date).ToList();
                //    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                //    {
                //        var record = mealRecords.FirstOrDefault(s => s.ProfileID == profile.Id && date == s.TimeLog.Date && !workdayProfileDates.Contains(date.Date));
                //        if (record != null)
                //        {
                //            DataRow row = datatable.NewRow();
                //            int? 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[Can_ReportMealTimeDetailEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.ProfileName] = profile.ProfileName;
                //            var line = repoLine.FindBy(m => record.LineID == m.Id).FirstOrDefault();
                //            var canteen = repoCanteen.FindBy(m => record.CanteenID == m.Id).FirstOrDefault();
                //            var catering = repoCatering.FindBy(m => record.CateringID == m.Id).FirstOrDefault();
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.CateringName] = catering != null ? catering.CateringName : null;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.CanteenName] = canteen != null ? canteen.CanteenName : null;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.LineName] = line != null ? line.LineName : null;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DateFrom] = dateStart;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DateTo] = dateEnd;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DatePrint] = DateTime.Now;
                //            if (record.TimeLog != null)
                //            {
                //                row["Data" + date.Day] = record.TimeLog.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                //            }
                //            datatable.Rows.Add(row);
                //        }
                //    }
                //} 
                #endregion
                foreach (var profile in profiles)
                {
                    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID && (s.FirstInTime != null || s.LastOutTime != null)).Select(s => s.WorkDate.Date).ToList();
                    var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaday = leavedays.FirstOrDefault(s => s.DateStart != null && s.DateEnd != null && s.ProfileID == profile.ID && s.DateStart.Date <= date.Date && date.Date <= s.DateEnd.Date);
                        var record = mealRecordProfiles.FirstOrDefault(s => date.Date == s.WorkDay.Value.Date && (!workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null));
                        if (record != null)
                        {
                            DataRow row = datatable.NewRow();
                            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);
                            row[Can_ReportMealTimeDetailEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.ProfileName] = profile.ProfileName;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.Date] = record.WorkDay;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DateFrom] = dateStart;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DateTo] = dateEnd;
                            var cate = caterings.FirstOrDefault(s => s.ID == record.CateringID);
                            var cateen = canteens.FirstOrDefault(s => s.ID == record.CanteenID);
                            var line = lines.FirstOrDefault(s => s.ID == record.LineID);
                            row[Can_ReportMealTimeDetailEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                            if (record.TimeLog != null)
                            {
                                row["Data" + record.WorkDay.Value.Day] = record.TimeLog == null ? null : (object)record.TimeLog.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime) ?? DBNull.Value;
                            }
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DatePrint] = DateTime.Now;
                            if (leaday != null)
                            {
                                var leadayType = leaveDayTypes.FirstOrDefault(s => s.ID == leaday.LeaveDayTypeID);
                                row[Can_ReportMealTimeDetailEntity.FieldNames.LeaveDayTypeName] = leadayType != null ? leadayType.LeaveDayTypeName : string.Empty;
                            }
                            datatable.Rows.Add(row);
                        }
                    }
                }
                return datatable;
            }
        }
Пример #10
0
        public DataTable ReportCardNotStand(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEndSearch);
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecords = repoCan_MealRecord.FindBy(s => s.ProfileID != null && s.WorkDay != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd)
               .Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.WorkDay }).ToList();
                if (mealRecords.Count < 1)
                {
                    return datatable;
                }
                var Profileids = mealRecords.Select(s => s.ProfileID).ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(s => Profileids.Contains(s.ID)).ToList();

                var profileIdsByMealrecords = mealRecords.Where(m => m.ProfileID != null).Select(s => s.ProfileID.Value).ToList();
                var amountByMealrecords = mealRecords.Select(m => m.Amount).Distinct().ToList();

                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var workDayProfies = repoWorkDay.FindBy(s => s.ProfileID != null && s.WorkDate != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd &&
                    profileIdsByMealrecords.Contains(s.ProfileID)).ToList();

                var repoAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealAllowanceTypeStandard = repoAllowanceType.FindBy(s => s.Standard == true).FirstOrDefault();
                var amountStandar = mealAllowanceTypeStandard != null ? mealAllowanceTypeStandard.Amount : null;

                var repoline = new Can_LineRepository(unitOfWork);
                var lineHDTJobIDs = repoline.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList();
                var linIdNotAmoutStardands = repoline.FindBy(s => s.Amount != amountStandar).Select(s => s.ID).ToList();

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

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

                if (canteenIDs != null && canteenIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList();
                }
                if (cateringIDs != null && cateringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList();
                }
                if (lineIDs != null && lineIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList();
                }
                if (linIdNotAmoutStardands.Count > 0)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && linIdNotAmoutStardands.Contains(s.LineID.Value)).ToList();
                }
                if (lineHDTJobIDs.Count > 0)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList();
                }
                if (mealRecords.Count < 1)
                {
                    return datatable;
                }
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                var canteens = repocanteen.GetAll().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                var caterings = repocatering.GetAll().ToList();
                var lines = repoline.GetAll().ToList();
                var orgTypes = new List<Cat_OrgStructureType>();
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();

                var approve = LeaveDayStatus.E_APPROVED.ToString();
                var repoleavedays = new Att_LeavedayRepository(unitOfWork);
                var leavedays = repoleavedays.FindBy(s => s.Status == approve && dateStart <= s.DateEnd
                     && s.DateStart <= dateEnd && profileIdsByMealrecords.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();

                foreach (var profile in profiles)
                {
                    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                    var dateLeveDays = new List<DateTime>();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        if (leaveDay != null)
                        {
                            dateLeveDays.Add(date.Date);
                        }
                    }
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        var meal = mealRecords.FirstOrDefault(s => s.ProfileID == profile.ID && s.TimeLog != null && s.WorkDay != null
                            && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(s.WorkDay.Value.Date) && leaveDay == null);
                        if (meal != null)
                        {
                            DataRow row = datatable.NewRow();
                            Guid? orgId = profile != null ? profile.OrgStructureID : null;
                            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);
                            row[Can_ReportCardNotStandEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Can_ReportCardNotStandEntity.FieldNames.ProfileName] = profile.ProfileName;
                            row[Can_ReportCardNotStandEntity.FieldNames.DateFrom] = dateStart;
                            row[Can_ReportCardNotStandEntity.FieldNames.DateTo] = dateEnd;
                            row[Can_ReportCardNotStandEntity.FieldNames.DatePrint] = DateTime.Now;
                            var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID);
                            var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID);
                            var line = lines.FirstOrDefault(s => s.ID == meal.LineID);
                            if (meal.WorkDay != null)
                            {
                                row["Data" + date.Day] = meal.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                            }
                            row[Can_ReportCardNotStandEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                            row[Can_ReportCardNotStandEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                            row[Can_ReportCardNotStandEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                            var countcard = mealRecords.Count(s => s.WorkDay != null && s.ProfileID == profile.ID && workdayProfileDates.Contains(s.WorkDay.Value.Date)
                                && !dateLeveDays.Contains(s.WorkDay.Value.Date));
                            if (countcard != null)
                            {
                                row[Can_ReportCardNotStandEntity.FieldNames.CountCard] = countcard;
                                var SumAmount = mealRecords.Where(s => s.WorkDay != null && s.ProfileID == profile.ID && workdayProfileDates.Contains(s.WorkDay.Value.Date) &&
                                    !dateLeveDays.Contains(s.WorkDay.Value.Date)).Sum(s => s.Amount) - countcard * amountStandar;
                                row[Can_ReportCardNotStandEntity.FieldNames.SumAmount] = SumAmount;
                            }
                            datatable.Rows.Add(row);
                        }
                    }
                }
                return datatable;
            }
        }
Пример #11
0
        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;
        }
Пример #12
0
        public DataTable ReportHDTJobCardMore(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEnd, List<Guid> lstProfileIds,  Boolean isCludeEmpQuit)
        {
            DataTable datatable = CreateReportHDTJobCardMoreSchema();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var repo = new Can_MealRecordRepository(unitOfWork);

                var mealRecords = repo.FindBy(s => s.ProfileID != null && s.WorkDay != null && s.TimeLog != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).ToList();
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => profileIds.Contains(m.ID)).ToList();

                var repoCan_Location = new Can_LocationRepository(unitOfWork);
                var lstLocation = repoCan_Location.FindBy(s => s.IsDelete == null).ToList();

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

                if (isCludeEmpQuit != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                var lstcateringids = mealRecords.Select(m => m.CateringID).ToList();
                var lstcanteenids = mealRecords.Select(m => m.CanteenID).ToList();
                var Cardcode = mealRecords.Select(s => s.ProfileID).Distinct().ToList();

                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoOrg.FindBy(m => m.Code != null).ToList();

                if (CarteringIDs != null && CarteringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CateringID != null && CarteringIDs.Contains(m.CateringID)).ToList();
                }

                if (CanteenIDS != null && CanteenIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CanteenID != null && CanteenIDS.Contains(m.CanteenID)).ToList();
                }

                if (LineIDS != null && LineIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.LineID != null && LineIDS.Contains(m.LineID)).ToList();
                }

                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }

                var repoWorkLocation = new Cat_WorkPlaceRepository(unitOfWork);
                var lstWorkPlace = repoWorkLocation.GetAll().ToList();

                var repocatering = new Can_CateringRepository(unitOfWork);
                var caterings = repocatering.GetAll().ToList();

                var repocanteen = new Can_CanteenRepository(unitOfWork);
                var canteens = repocanteen.GetAll().ToList();

                var repoline = new Can_LineRepository(unitOfWork);
                var lines = repoline.GetAll().ToList();

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

                var repoAttWorkday = new Att_WorkDayRepository(unitOfWork);
                var wordDayProfiles = repoAttWorkday.FindBy(wd => dateStart <= wd.WorkDate && wd.WorkDate <= dateEnd)
                                .Select(wd => new { wd.ProfileID, wd.ShiftID, wd.WorkDate, wd.InTime1, wd.OutTime1 }).ToList();

                var approve = LeaveDayStatus.E_APPROVED.ToString();
                var repoAttLeaveday = new Att_LeavedayRepository(unitOfWork);
                var leavedays = repoAttLeaveday.FindBy(ld => ld.Status == approve && dateStart <= ld.DateEnd
                                && ld.DateStart <= dateEnd && profileIds.Contains(ld.ProfileID)).Select(ld => new { ld.ProfileID, ld.DateStart, ld.DateEnd }).ToList();

                var repoHDTjob = new Hre_HDTJobRepository(unitOfWork);
                var hdtJobs = repoHDTjob.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) 
                                && dateStart <= s.DateTo && s.DateFrom <= dateEnd).Select(s => new { s.DateFrom, s.ProfileID, s.DateTo, s.Type }).ToList();

                for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                {
                    if (!datatable.Columns.Contains("Data" + date.Day))
                    {
                        datatable.Columns.Add("Data" + date.Day, typeof(double));
                    }
                }

                foreach (var profile in profiles)
                {
                    List<DateTime> leaveDayDates = new List<DateTime>();
                    var leaveDayProfiles = leavedays.Where(s => s.ProfileID == profile.ID).ToList();
                    foreach (var leaveDayProfile in leaveDayProfiles)
                    {
                        for (DateTime date = leaveDayProfile.DateStart; date <= leaveDayProfile.DateEnd; date = date.AddDays(1))
                        {
                            leaveDayDates.Add(date.Date);
                        }
                    }
                    var workDayDates = wordDayProfiles.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                    workDayDates = workDayDates.Where(s => !leaveDayDates.Contains(s.Date)).ToList();

                    var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID && workDayDates.Contains(s.WorkDay.Value.Date)).ToList();
                    if (mealRecordProfiles.Count > 0)
                    {
                        var dateend = mealRecordProfiles[mealRecordProfiles.Count - 1].WorkDay;
                        for (DateTime date = mealRecordProfiles[0].WorkDay.Value; date <= dateend; date = date.AddDays(1))
                        {
                            if (mealRecordProfiles.Count(s => s.WorkDay.Value.Date == date.Date) > 1)
                            {
                                var mealDoubles = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date).ToList();
                                if (mealDoubles.Count > 1)
                                {
                                    var hdtType = hdtJobs.FirstOrDefault(s => s.DateFrom <= date && date <= s.DateTo && s.ProfileID == profile.ID);
                                    foreach (var meal in mealDoubles)
                                    {
                                        DataRow row = datatable.NewRow();

                                        var orgId = orgs.Where(og => og.ID == mealRecordProfiles[0].OrgStructureID).Select(og => og.ID).FirstOrDefault();
                                        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);

                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.ProfileName] = profile.ProfileName;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateFrom] = dateStart;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateTo] = dateEnd;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateExport] = DateTime.Now;
                                        if (meal.TimeLog != null)
                                        {
                                            row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateCard] = meal.WorkDay;
                                            row[Can_ReportHDTJobCardMoreEntity.FieldNames.Hour] = meal.TimeLog.Value.ToString("HH:mm:ss");
                                        }
                                        var count1 = 0;
                                        for (DateTime date1 = dateStart; date1 <= dateEnd; date1 = date1.AddDays(1))
                                        {
                                            int countDay = mealRecordProfiles.Count(s => s.WorkDay.Value.Date == date1.Date && !leaveDayDates.Contains(date1.Date));
                                            if (countDay > 1)
                                            {
                                                count1 += countDay - 1;
                                            }
                                        }
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.Total] = count1;
                                        row["Data" + date.Day] = mealDoubles.Sum(s => s.Amount);
                                        var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID);
                                        var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID);
                                        var line = lines.FirstOrDefault(s => s.ID == meal.LineID);
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                                        if (hdtType != null)
                                        {
                                            var hdttype = lines.FirstOrDefault(s => s.HDTJ == hdtType.Type);
                                            if (hdttype != null)
                                            {
                                                row[Can_ReportHDTJobCardMoreEntity.FieldNames.PriceStardand] = (object)hdttype.Amount ?? DBNull.Value;
                                            }
                                        }
                                        datatable.Rows.Add(row);
                                    }
                                }
                            }
                        }
                    }

                }
            }
            return datatable;
        }
Пример #13
0
        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;
        }
Пример #14
0
        public DataTable GetReportSumaryReturnMoneyEat(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, List<Guid?> workPlaceIds,
            DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs, String codeEmp, Boolean IsIncludeQuitEmp)
        {
            DataTable datatable = CreateReportSumaryReturnMoneyEatSchema();
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecords = repoCan_MealRecord.FindBy(s => s.ProfileID != null && s.WorkDay != null &&
                dateStart <= s.WorkDay && s.WorkDay <= dateEnd).Select(
                s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay, s.WorkDay }).ToList();

                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var workDayProfies = repoWorkDay.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateStart <= s.WorkDate
                 && s.WorkDate <= dateEnd && profileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(m => profileIds.Contains(m.ID)).ToList();
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                var repoHre_HDTJob = new Hre_HDTJobRepository(unitOfWork);
                var profileHDTJIDs = repoHre_HDTJob.FindBy(s => s.DateTo >= dateStart && s.DateFrom <= dateEnd).Select(s => s.ProfileID).ToList();
                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var lineHDTJIDs = repoCan_Line.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList();
                var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var amountStardand = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount).FirstOrDefault();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);

                var leavedays = repoLeaveDay.FindBy(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID))
                    .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                if (orgIDs != null && orgIDs[0] != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                if (workPlaceIds != null && workPlaceIds[0] != null)
                {
                    profiles = profiles.Where(s => workPlaceIds.Contains(s.WorkPlaceID)).ToList();
                }

                if (IsIncludeQuitEmp != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                    //profileIds = profiles.Select(s => s.ID).ToList();
                    //mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).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();
                    }
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                if (canteenIDs != null && canteenIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList();
                }
                if (cateringIDs != null && cateringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList();
                }
                if (lineIDs != null && lineIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList();
                }
                var codeAttendaceByProfile = profiles.Select(m => m.ID).ToList();
                if (codeAttendaceByProfile != null && codeAttendaceByProfile.Count > 0)
                {
                    mealRecords = mealRecords.Where(m => m.ProfileID != null && codeAttendaceByProfile.Contains(m.ProfileID.Value)).ToList();
                }
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value)).ToList();

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

                var repoLine = new Can_LineRepository(unitOfWork);
                var lines = repoLine.FindBy(s => s.Amount != null && s.HDTJ == null && s.Amount != amountStardand).Select(s => new { s.Amount.Value, s.ID }).Distinct().ToList();

                foreach (var profile in profiles)
                {
                    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                    var mealProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList();
                    DataRow row = datatable.NewRow();
                    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);
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateFrom] = dateStart;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateTo] = dateEnd;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DatePrint] = DateTime.Now;
                    bool isAdd = false;
                    var amounts = lines.Select(s => s.Value).Distinct().ToList();
                    foreach (var amount in amounts)
                    {
                        var countCareing = 0;
                        double sumCareing = 0;
                        var line1IDs = lines.Where(s => s.Value == amount).Select(s => s.ID).ToList();
                        for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                        {
                            var leaday = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                            countCareing += mealProfiles.Count(s => line1IDs.Contains(s.LineID.Value) && s.WorkDay.Value.Date == date.Date && (workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null));
                            var sumAmount = mealProfiles.Where(s => line1IDs.Contains(s.LineID.Value) && s.WorkDay.Value.Date == date.Date && (workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null)).Sum(s => s.Amount);
                            if (sumAmount > 0)
                            {
                                sumCareing += (double)(sumAmount.Value - amountStardand.Value);
                            }

                        }
                        if (countCareing > 0)
                        {
                            isAdd = true;
                            row[amount.ToString()] = countCareing;
                            row["Số Tiền " + amount] = sumCareing;
                        }
                    }

                    var countSard = mealProfiles.Where(hr => hr.WorkDay != null).Count(hr => hr.Amount == amountStardand && workdayProfileDates.Contains(hr.WorkDay.Value.Date));
                    var countWorkDay = workDayProfies.Where(wd => wd.WorkDate != null).Count(wd => workdayProfileDates.Contains(wd.WorkDate.Date));
                    if (countSard > 0)
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountSandard] = countSard;
                    if (countWorkDay > 0)
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountWorkDay] = countWorkDay;

                    var countCardMore1 = 0;
                    double sumAmountNotStardand = 0;// tong so tien quet the ko dat chuan
                    double? sumAmountHDTJOB = 0;// tong so tien cua nhan vien ko phai HDTJOb ma an o cua an HDTJOB
                    sumAmountHDTJOB = (double?)mealProfiles.Where(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJIDs.Contains(s.LineID.Value) && !profileHDTJIDs.Contains(s.ProfileID.Value)).Sum(s => s.Amount);
                    double sumAmountNotWorkHasEat = 0;// tong so tien ko di lam ma co an
                    var countNotWorkButHasEat = 0;
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaday = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        if (mealProfiles.Count(s => s.WorkDay.Value.Date == date.Date) > 1)
                        {
                            countCardMore1++;
                        }
                        var amount = mealProfiles.FirstOrDefault(s => s.WorkDay.Value.Date == date.Date);
                        if (amount != null)
                        {
                            sumAmountNotStardand += (double)(amount.Amount.Value - amountStardand.Value);
                        }
                        var meal = mealProfiles.FirstOrDefault(s => date.Date == s.WorkDay.Value.Date && (!workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null));
                        if (meal != null)
                        {
                            countNotWorkButHasEat++;
                            sumAmountNotWorkHasEat += (double)meal.Amount.Value;
                        }
                    }

                    if (countCardMore1 > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountCardMore] = countCardMore1;
                        isAdd = true;
                    }
                    var sumCardMore = countCardMore1 * amountStardand.Value;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountCardMore] = sumCardMore;
                    if (countNotWorkButHasEat > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountNotWorkButHasEat] = countNotWorkButHasEat;
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumNotWorkButHasEat] = sumAmountNotWorkHasEat;
                        isAdd = true;
                    }
                    var sum = Math.Round((sumAmountNotWorkHasEat + sumAmountNotStardand + (double)sumCardMore), 0);
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountMustSubtract] = sum == 0 ? (object)DBNull.Value : sum;
                    sum = Math.Round(sumAmountHDTJOB.Value, 0);
                    if (sum > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.MoneyMustSubtractHDT] = sum;
                        isAdd = true;
                    }

                    sum = Math.Round((sumAmountNotWorkHasEat + sumAmountNotStardand + sumAmountHDTJOB.Value + (double)sumCardMore), 0);
                    if (sum > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumMoneyMustSubtract] = sum;
                        isAdd = true;
                    }
                    if (isAdd)
                        datatable.Rows.Add(row);
                }
                return datatable;
            }
        }
Пример #15
0
        public DataTable ReportMultiSlideCard(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, List<Guid?> lstWorkPlaceID,
            DateTime dateStart, DateTime dateEndSearch, List<Guid> lstProfileIds, Boolean IsIncludeQuitEmp)
        {
            DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEndSearch);
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

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

                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var wordDayProfiles = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                    .Select(s => new { s.ProfileID, s.WorkDate, s.FirstInTime, s.LastOutTime }).ToList();

                var repo = new Can_MealRecordRepository(unitOfWork);
                var mealRecords = repo.FindBy(s => s.LineID != null && s.WorkDay != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID != null
                    && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.WorkDay }).ToList();
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => profileIds.Contains(m.ID)).ToList();
                if (lstProfileIds != null && lstProfileIds.Count >= 1)
                {
                    profiles = profiles.Where(s => lstProfileIds.Contains(s.ID)).ToList();
                }
                if (lstWorkPlaceID[0] != Guid.Empty)
                {
                    profiles = profiles.Where(hr => hr.WorkPlaceID != null && lstWorkPlaceID.Contains(hr.WorkPlaceID.Value)).ToList();
                }
                //Kiểm tra ko nghỉ việc
                if (IsIncludeQuitEmp != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                var Cardcode = mealRecords.Select(s => s.ProfileID).Distinct().ToList();
                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoOrg.FindBy(m => m.Code != null).ToList();
                var catering = new List<Can_Catering>().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                if (CarteringIDs != null && CarteringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CateringID != null && CarteringIDs.Contains(m.CateringID)).ToList();
                }
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null && CanteenIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CanteenID != null && CanteenIDS.Contains(m.CanteenID)).ToList();
                }
                if (LineIDS != null && LineIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.LineID != null && LineIDS.Contains(m.LineID)).ToList();
                }
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var orgTypes = new List<Cat_OrgStructureType>();
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                var repoCan_Catering = new Can_CateringRepository(unitOfWork);
                var repoCan_Canteen = new Can_CanteenRepository(unitOfWork);
                var repoline = new Can_LineRepository(unitOfWork);
                var canteens = repoCan_Canteen.GetAll().ToList();
                var caterings = repoCan_Catering.GetAll().ToList();
                var lines = repoCan_Line.GetAll().ToList();

                var approve = LeaveDayStatus.E_APPROVED.ToString();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leavedays = repoLeaveDay.FindBy(s => s.Status == approve && dateStart <= s.DateEnd
                     && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();

                foreach (var profile in profiles)
                {
                    var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        var workDayDates = wordDayProfiles.Where(s => s.ProfileID == profile.ID && (s.FirstInTime != null || s.LastOutTime != null)).Select(s => s.WorkDate.Date).ToList();
                        var mealDoubles = mealRecordProfiles.Where(s => s.TimeLog != null && s.TimeLog.Value.Date == date.Date).ToList();
                        if (mealDoubles.Count > 1)
                        {
                            foreach (var meal in mealDoubles)
                            {
                                DataRow row = datatable.NewRow();
                                Guid? orgId = profile != null ? profile.OrgStructureID : Guid.Empty;
                                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);
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.ProfileName] = profile.ProfileName;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DateFrom] = dateStart;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DateTo] = dateEnd;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DatePrint] = DateTime.Now;
                                if (meal.TimeLog != null)
                                {
                                    row["Data" + date.Day] = meal.TimeLog.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                                }
                                var count1 = 0;
                                for (DateTime date1 = dateStart; date1 <= dateEnd; date1 = date1.AddDays(1))
                                {
                                    int countDay = mealRecordProfiles.Count(s => s.TimeLog != null && s.TimeLog.Value.Date == date1.Date && leaveDay == null);
                                    if (countDay > 1)
                                    {
                                        count1 += countDay - 1;
                                    }
                                }
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.SumCardMore] = count1;
                                var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID);
                                var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID);
                                var line = lines.FirstOrDefault(s => s.ID == meal.LineID);
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                                datatable.Rows.Add(row);
                            }
                        }
                    }
                }
                return datatable;
            }
        }
Пример #16
0
        public DataTable GetReportMonthlyHourFlightLocal(Guid CutOffDurationID, string strOrgStructure, Guid[] shiftIDs, Guid[] payrollIDs, Guid[] workPlaceIDs, string codeEmp, bool isIncludeQuitEmp, bool isNotAllowZero, bool isCreateTemplate, string userExport, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                DataTable table = CreateReportMonthlyHourFlightLocalchema(UserLogin);
                if (isCreateTemplate)
                {
                    return table.ConfigDatatable();
                }
                string status = string.Empty;
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                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 repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoTimeSheet = new Att_TimeSheetRepository(unitOfWork);
                var repoJobtype = new Cat_JobTypeRepository(unitOfWork);
                var repoAtt_AttendencaTable = new CustomBaseRepository<Att_AttendanceTable>(unitOfWork);
                var repoAtt_AttendanceTableItem = new CustomBaseRepository<Att_AttendanceTableItem>(unitOfWork);
                var repoAtt_CutOffDuration = new CustomBaseRepository<Att_CutOffDuration>(unitOfWork);

                var roleServices = new Cat_RoleServices();
                var lstRole = new List<object>();
                lstRole.Add(null);
                lstRole.Add(null);
                lstRole.Add(1);
                lstRole.Add(100000000);
                var listRole = roleServices.GetData<Cat_RoleEntity>(lstRole, ConstantSql.hrm_cat_sp_get_Role, UserLogin, ref status).Where(s => s.Code != null).Select(m => new { m.ID, m.Code }).ToList();

                var jobTypeServices = new Cat_JobTypeServices();
                var lstjobType = new List<object>();
                lstjobType.Add(null);
                lstjobType.Add(null);
                lstjobType.Add(1);
                lstjobType.Add(100000000);
                var listjobType = jobTypeServices.GetData<Cat_JobTypeEntity>(lstjobType, ConstantSql.hrm_cat_sp_get_JobType, UserLogin, ref status).Where(s => s.Code != null).Select(m => m.Code).ToList();


                List<object> lstOrgIDs = new List<object>();
                lstOrgIDs.AddRange(new object[3]);
                lstOrgIDs[0] = (object)strOrgStructure;
                lstOrgIDs[1] = null;
                lstOrgIDs[2] = codeEmp;
                List<Hre_ProfileEntity> profiles = GetData<Hre_ProfileEntity>(lstOrgIDs, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();
                var cutoffInfo = repoAtt_CutOffDuration.FindBy(s => s.ID == CutOffDurationID).FirstOrDefault();
                var leavedayTypes = repoCat_LeaveDayType.FindBy(s => s.Code != null && s.IsDelete == null).Select(s => new { s.Code, s.ID, s.PaidRate, s.LeaveDayTypeName }).ToList();


                DateTime dateStart = cutoffInfo.DateStart;
                DateTime dateEnd = cutoffInfo.DateEnd;


                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();

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

                var timesheets = repoTimeSheet.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) && s.Date != null && dateStart <= s.Date && s.Date <= dateEnd
                    && s.IsDelete == null).Select(s => new { s.ProfileID, s.JobTypeID, s.RoleID, s.Date, s.NoHour, s.ID, s.Note }).ToList();

                var jobtypes = repoJobtype.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.Code, s.RoleID }).ToList();

                var workDays = repoWorkDay.FindBy(s => profileIds.Contains(s.ProfileID) && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && s.IsDelete == null).Select(s => new { s.ProfileID, s.ShiftID, s.Status }).ToList();

                if (payrollIDs != null)
                {
                    profiles = profiles.Where(s => s.PayrollGroupID != null && payrollIDs.Contains(s.PayrollGroupID.Value)).ToList();
                }
                if (workPlaceIDs != null)
                {
                    profiles = profiles.Where(s => s.WorkPlaceID != null && workPlaceIDs.Contains(s.WorkPlaceID.Value)).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 > dateStart).ToList();
                }
                profileIds = profiles.Select(s => s.ID).ToList();

                var attendanceTables = repoAtt_AttendencaTable
                    .FindBy(s => s.IsDelete == null && s.CutOffDurationID == CutOffDurationID && profileIds.Contains(s.ProfileID))
                    .ToList();

                List<Guid> attendanceTablesID = attendanceTables.Select(s => s.ID).ToList();

                var attendanceTableItem = repoAtt_AttendanceTableItem
                    .FindBy(s => s.IsDelete == null && attendanceTablesID.Contains(s.AttendanceTableID))
                    .ToList();
                if (isNotAllowZero)
                {
                    profileIds = attendanceTables.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }
                profileIds = attendanceTables.Select(s => s.ProfileID).ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();

                foreach (var profile in profiles)
                {
                    var attendanceTableProfile = attendanceTables.FirstOrDefault(s => s.ProfileID == profile.ID);
                    var timeSheetByProfile = timesheets.Where(s => s.ProfileID == profile.ID).ToList();

                    if (timeSheetByProfile == null)
                    {
                        continue;
                    }
                    var lstjobtypebytimesheetpro = timeSheetByProfile.Select(s => s.JobTypeID).ToList();
                    var lstJobTypeCodeByTimeSheet = jobtypes.Where(s => lstjobtypebytimesheetpro.Contains(s.ID)).Select(s => new { s.ID, s.Code, s.RoleID }).ToList();
                    if (attendanceTableProfile == null)
                    {
                        continue;
                    }
                    var attendanceTableItemProfile = attendanceTableItem.Where(s => s.AttendanceTableID == attendanceTableProfile.ID).ToList();
                    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 positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                    var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

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

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

                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                    if (profile.DateHire != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.StartingDate] = profile.DateHire.Value;
                    if (profile.DateQuit != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.ResignedDate] = profile.DateQuit.Value;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateFrom] = dateStart;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateTo] = dateEnd;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.UserExport] = userExport;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateExport] = DateTime.Today;

                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.StdWorkDayCount] = attendanceTableProfile.StdWorkDayCount > 0 ? attendanceTableProfile.StdWorkDayCount : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.RealWorkDayCount] = attendanceTableProfile.RealWorkDayCount > 0 ? attendanceTableProfile.RealWorkDayCount : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.PaidWorkDayCount] = attendanceTableProfile.PaidWorkDayCount > 0 ? attendanceTableProfile.PaidWorkDayCount : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.AnlDayAvailable] = attendanceTableProfile.AnlDayAvailable > 0 ? attendanceTableProfile.AnlDayAvailable : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.NightShiftHours] = attendanceTableProfile.NightShiftHours > 0 ? attendanceTableProfile.NightShiftHours : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.LateEarlyDeductionHours] = attendanceTableProfile.LateEarlyDeductionHours > 0 ? attendanceTableProfile.LateEarlyDeductionHours : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.AnlDayTaken] = attendanceTableProfile.AnlDayTaken > 0 ? attendanceTableProfile.AnlDayTaken : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Note] = attendanceTableProfile.Note != null ? attendanceTableProfile.Note : string.Empty;

                    foreach (var item in attendanceTableItemProfile)
                    {
                        if (item.LeaveTypeID != null)
                        {
                            row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + item.WorkDate.Day.ToString()] = leavedayTypes.Where(s => s.ID == item.LeaveTypeID).FirstOrDefault().Code;
                        }
                    }



                    foreach (var roleEntity in listRole)
                    {
                        var lstJobTypeByRoleID = lstJobTypeCodeByTimeSheet.Where(s => s.RoleID == roleEntity.ID).ToList();
                        foreach (var jobcode in lstJobTypeByRoleID)
                        {
                            var CodeRoleAndJobType = roleEntity.Code + "_" + jobcode.Code;
                            if (table.Columns.Contains(CodeRoleAndJobType))
                            {
                                double? nohourByPro = timeSheetByProfile.Where(s => s.JobTypeID == jobcode.ID && s.RoleID == roleEntity.ID).Sum(s => s.NoHour);
                                row[CodeRoleAndJobType] = nohourByPro;
                            }
                        }
                    }

                    table.Rows.Add(row);
                }
                return table.ConfigTable();
            }

        }
Пример #17
0
        /// <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
        /// <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;
            }
        }
Пример #19
0
        public DataTable GetReportLateEarlyTotal(Att_ReportLateEarlyTotalEntity model, string userLogin)
        {
            DataTable tblData = getSchema();
            var service = new Att_ReportLateEarlyTotalServices();
            var hrService = new Hre_ProfileServices();
            DateTime DateFrom = DateTime.Now;
            DateTime DateTo = DateTime.Now;
            List<Guid?> OrgIds = new List<Guid?>();
            if (model.SDateFrom != null)
            {
                DateFrom = model.SDateFrom.Value;
            }
            if (model.SDateTo != null)
            {
                DateTo = model.SDateTo.Value;
            }
            var From = DateFrom;
            var To = DateTo;

            string strOrgIDs = null;
            if (!string.IsNullOrEmpty(model.OrgStructureID))
            {
                strOrgIDs = model.OrgStructureID;
            }
            List<object> listObj = new List<object>();
            listObj.Add(strOrgIDs);
            listObj.Add(string.Empty);
            listObj.Add(string.Empty);


            string status = string.Empty;
           
            var result = new DataTable();
            var lstprofile = hrService.GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).ToList();
            if (lstprofile == null || lstprofile.Count == 0)
            {
            return null;
            }
            List<Guid> lstProfileIDs = lstprofile.Select(x => x.ID).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var repoOrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoOrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoTAMScanReasonMiss = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                //var lstprofile=repoProfile.FindBy(x=>lstProfileIDs.Contains(x.ID)).ToList();
                var orgs = repoOrgStructure.FindBy(s => s.Code != null).ToList();
                var orgTypes = repoOrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                Guid ForgetTams = repoTAMScanReasonMiss.FindBy(x => x.Code.Equals("FC")).Select(x => x.ID).FirstOrDefault();
                var lstWorkdayQuery = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && (m.LateEarlyDuration > 0 || m.Type == WorkdayType.E_LATE_EARLY.ToString()) && !(m.Status == WorkdayStatus.E_APPROVED.ToString() && m.LateEarlyDuration == 0)).ToList();
                var lstWorkdayFogetTamsQuery = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && m.MissInOutReason == ForgetTams).ToList();
                // var listProfile = repoProfile.FindBy(x => lstProfileIDs.Contains(x.ID)).ToList();
                if (lstProfileIDs != null && lstProfileIDs.Count != 0)
                {
                    lstWorkdayQuery = lstWorkdayQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                    lstWorkdayFogetTamsQuery = lstWorkdayFogetTamsQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                }
                var lstWorkday = lstWorkdayQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate, m.LateEarlyDuration }).ToList();
                var lstWorkdayFogetTams = lstWorkdayFogetTamsQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate }).ToList();
                foreach (var item in lstprofile)
                {
                    DataRow row = tblData.NewRow();
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.CodeEmp] = item.CodeEmp;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.ProfileName] = item.ProfileName;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateFrom] = From;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateTo] = To;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.UserExport] = model.UserExport;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateExport] = DateTime.Today;
                    if (item.OrgStructureID.HasValue)
                    {
                        Cat_OrgStructure objOrgStructure = orgs.Where(x => x.ID == item.OrgStructureID).FirstOrDefault();
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.OrgStructureName] = objOrgStructure.OrgStructureName;
                        Guid? orgId = item.OrgStructureID;
                        var orgBrand = 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_ReportLateEarlyTotalEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchCode] = orgBrand != null ? orgBrand.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchName] = orgBrand != null ? orgBrand.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    }
                    for (DateTime MonthCheck = From; MonthCheck <= To; MonthCheck = MonthCheck.AddMonths(1))
                    {
                        DateTime BeginMonth = new DateTime(MonthCheck.Year, MonthCheck.Month, 1);
                        DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1);
                        double Less2Hour = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration < 2).ToList().Count;
                        double Over2Hour = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration >= 2).ToList().Count;
                        double TotalLateEarly = Less2Hour + Over2Hour;
                        double ForgetTamscan = lstWorkdayFogetTams.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth).ToList().Count;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Less2Hour + BeginMonth.Month] = Less2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Over2Hour + BeginMonth.Month] = Over2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TotalLateEarly + BeginMonth.Month] = TotalLateEarly;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.ForgetTamscan + BeginMonth.Month] = ForgetTamscan;
                    }
                    tblData.Rows.Add(row);
                }

            }
            var configs = new Dictionary<string, Dictionary<string, object>>();
            var confighidden = new Dictionary<string, object>();
            var configCodeEmp = new Dictionary<string, object>();
            configCodeEmp.Add("width", 90);
            var configProfileName = new Dictionary<string, object>();
            configProfileName.Add("width", 125);
            var configOrgStructureName = new Dictionary<string, object>();
            configOrgStructureName.Add("width", 80);
            var configDepartmentCode = new Dictionary<string, object>();
            configDepartmentCode.Add("width", 98);
            var configSectionCode = new Dictionary<string, object>();
            configSectionCode.Add("width", 50);
            var configBranchCode = new Dictionary<string, object>();
            configBranchCode.Add("width", 90);
            var configBranchName = new Dictionary<string, object>();
            configBranchName.Add("width", 77);
            confighidden.Add("hidden", true);
            configs.Add("CodeEmp", configCodeEmp);
            configs.Add("ProfileName", configProfileName);
            configs.Add("OrgStructureName", configOrgStructureName);
            configs.Add("DepartmentCode", configDepartmentCode);
            configs.Add("SectionCode", configSectionCode);
            configs.Add("BranchCode", configBranchCode);
            configs.Add("DepartmentName", configOrgStructureName);
            configs.Add("SectionName", configSectionCode);
            configs.Add("BranchName", configBranchName);
            configs.Add("TeamName", configSectionCode);
            configs.Add("DateFrom", confighidden);
            configs.Add("DateTo", confighidden);
            configs.Add("UserExport", confighidden);
            configs.Add("DateExport", confighidden);
            return tblData.ConfigTable(configs);
        }
Пример #20
0
        /// <summary>
        /// [Kiet.Chung] 4/11/2014
        /// BC In Out Đã Bị Điều Chỉnh
        /// </summary>
        public List<Att_ReportInOutAdjustmentEntity> GetReportInOutAdjustment(DateTime dateStart, DateTime dateEnd, String TAMScanReasonMissIDs, String OrgStructureIDs, String CodeEmp, String PayrollGroupIDs, string userPrint)
        {
            using (var context = new VnrHrmDataContext())
            {
                var baseService = new BaseService();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoCat_TAMScanReasonMiss = new CustomBaseRepository<Cat_TAMScanReasonMiss>(unitOfWork);
                var repoCat_Shift = new CustomBaseRepository<Cat_Shift>(unitOfWork);

                List<Cat_OrgStructure> lstOrgAll = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();

                //var LstProfileQuery = repoHre_Profile.FindBy(s => s.IsDelete == null);


                //List<Guid> lstprofileIDs = LstProfileQuery.Select(m => m.ID).ToList<Guid>();
                string E_APPROVED = WorkdayStatus.E_APPROVED.ToString();

                var lstWorkdayQuery = repoAtt_Workday.FindBy(m => m.Status == E_APPROVED
                    && m.WorkDate >= dateStart
                    && m.WorkDate <= dateEnd
                    && (m.InTime1 != m.InTimeRoot
                        || m.OutTime1 != m.OutTimeRoot
                        || (m.InTime1 != null && m.InTimeRoot == null)
                        || (m.OutTime1 != null && m.OutTimeRoot == null)));
                //int? NumLimitContains = Common.NumLimitContains;
                //if (NumLimitContains == null || lstprofileIDs.Count < NumLimitContains.Value)
                //{
                if (!string.IsNullOrEmpty(OrgStructureIDs))
                {
                    var lstOrderNumber = OrgStructureIDs.Split(',').Select(s => int.Parse(s)).Distinct().ToList();
                    List<Guid> lstOrgS = lstOrgAll.Where(s => lstOrderNumber.Contains(s.OrderNumber)).Select(s => s.ID).ToList();
                    lstWorkdayQuery = lstWorkdayQuery.Where(m => m.OrgStructureID != null && lstOrgS.Contains(m.OrgStructureID.Value));
                }
                if (!string.IsNullOrEmpty(PayrollGroupIDs))
                {
                    var lstPayroll = PayrollGroupIDs.Split(',').Select(s => Guid.Parse(s)).ToList();
                    lstWorkdayQuery = lstWorkdayQuery.Where(m => m.Hre_Profile.PayrollGroupID != null && lstPayroll.Contains(m.Hre_Profile.PayrollGroupID.Value));
                }

                if (!string.IsNullOrEmpty(CodeEmp))
                {
                    lstWorkdayQuery = lstWorkdayQuery.Where(s => s.Hre_Profile.CodeEmp.Contains(CodeEmp));
                }
                //lstWorkdayQuery = lstWorkdayQuery.Where(m => lstprofileIDs.Contains(m.ProfileID));
                List<Att_Workday> lstWorkday = lstWorkdayQuery.ToList<Att_Workday>();
                if (!string.IsNullOrEmpty(TAMScanReasonMissIDs))
                {
                    var lstReasonMiss = TAMScanReasonMissIDs.Split(',').Select(s => Guid.Parse(s)).ToList();
                    lstWorkday = lstWorkday.Where(s => s.MissInOutReason.HasValue && lstReasonMiss.Contains(s.MissInOutReason.Value)).ToList();
                }


                #region ConvertToExportData

                #endregion

                List<Att_ReportInOutAdjustmentEntity> dt = new List<Att_ReportInOutAdjustmentEntity>();
                if (lstWorkday == null || lstWorkday.Count == 0)
                {
                    return dt;
                }

                List<Guid> lstProfileId = lstWorkday.Select(m => m.ProfileID).Distinct().ToList();
                var lstProfile = repoHre_Profile.FindBy(m => lstProfileId.Contains(m.ID)).Select(m => new { m.ID, m.ProfileName, m.CodeEmp, m.OrgStructureID, m.Cat_Position.Code, m.Cat_Position.PositionName }).ToList();
                //string UserLogin = EntityService.CreateQueryable<Sys_UserInfo>(false, GuidContext, Guid.Empty, m => m.ID == LoginUserID).Select(m => m.UserLogin).FirstOrDefault();
                var lstShift = repoCat_Shift.FindBy(s => s.Code != null).Select(m => new { m.ID, m.ShiftName, m.Code }).ToList();

                List<Guid> lstOrgID = lstWorkday.Where(m => m.OrgStructureID != null).Select(m => m.OrgStructureID.Value).Distinct().ToList<Guid>();
                Dictionary<Guid, OrgNameClass> DicOrgFull = (new Hre_ProfileServices()).GetOrgFullLink(lstOrgID, lstOrgAll);
                var lstReasonMissInout = repoCat_TAMScanReasonMiss.FindBy(s => s.Code != null).Select(m => new { m.ID, m.TAMScanReasonMissName }).ToList();
                foreach (var item in lstWorkday)
                {
                    Att_ReportInOutAdjustmentEntity dr = new Att_ReportInOutAdjustmentEntity();
                    var Profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault();
                    if (Profile != null)
                    {
                        dr.ProfileName = Profile.ProfileName;
                        dr.CodeEmp = Profile.CodeEmp;

                        if (item.OrgStructureID != null)
                        {
                            var Org = lstOrgAll.Where(m => m.ID == item.OrgStructureID).FirstOrDefault();
                            if (Org != null)
                            {
                                dr.ProfileOrgCode = Org.Code;
                                dr.ProfileOrgName = Org.OrgStructureName;
                            }

                            if (DicOrgFull.ContainsKey(item.OrgStructureID.Value))
                            {
                                OrgNameClass OrgName = DicOrgFull[item.OrgStructureID.Value];
                                if (OrgName != null)
                                {
                                    dr.DepartmentCode = OrgName.DepartmentCode;
                                    dr.SectionCode = OrgName.SectionCode;
                                    dr.BrandCode = OrgName.BrandCode;
                                    dr.TeamCode = OrgName.TeamCode;
                                    dr.DepartmentName = OrgName.DepartmentName;
                                    dr.SectionName = OrgName.SectionName;
                                    dr.BrandName = OrgName.BrandName;
                                    dr.TeamName = OrgName.TeamName;
                                }
                            }
                        }
                        dr.PositionCode = Profile.Code;
                        dr.PositionName = Profile.PositionName;
                    }

                    var shift = lstShift.Where(m => m.ID == item.ShiftID).FirstOrDefault();
                    if (shift != null)
                    {
                        dr.ShiftName = shift.ShiftName;
                    }
                    var shiftActual = lstShift.Where(m => m.ID == item.ShiftActual).FirstOrDefault();
                    if (shiftActual != null)
                    {
                        dr.ShiftNameActual = shiftActual.ShiftName;
                    }
                    if (item.WorkDate != null)
                    {
                        dr.WorkDate = item.WorkDate;
                    }
                    var shiftApprove = lstShift.Where(m => m.ID == item.ShiftApprove).FirstOrDefault();
                    if (shiftApprove != null)
                    {
                        dr.ShiftNameApprove = shiftApprove.ShiftName;
                    }
                    if (item.InTime1 != null)
                    {
                        dr.InTime1 = item.InTime1;
                    }
                    if (item.OutTime1 != null)
                    {
                        dr.OutTime1 = item.OutTime1;
                    }
                    dr.Type = item.Type;
                    dr.SrcType = item.SrcType;
                    dr.Status = item.Status;
                    dr.Note = item.Note;
                    if (item.LateDuration1 != null)
                    {
                        dr.LateDuration1 = item.LateDuration1;
                    }
                    if (item.EarlyDuration1 != null)
                    {
                        dr.EarlyDuration1 = item.EarlyDuration1;
                    }
                    if (item.LateEarlyDuration != null)
                    {
                        dr.LateEarlyDuration = item.LateEarlyDuration;
                    }
                    if (item.LateEarlyRoot != null)
                    {
                        dr.LateEarlyRoot = item.LateEarlyRoot;
                    }
                    if (item.MissInOutReason != null)
                    {
                        var reason = lstReasonMissInout.Where(m => m.ID == item.MissInOutReason.Value).FirstOrDefault();
                        if (reason != null)
                        {
                            dr.MissInOutReason = reason.TAMScanReasonMissName;
                        }
                    }

                    dr.LateEarlyReason = item.LateEarlyReason;
                    if (userPrint != null)
                    {
                        dr.UserExport = userPrint;
                    }
                    dr.DateExport = DateTime.Today;
                    if (item.InTimeRoot != null)
                        dr.InTimeRoot = item.InTimeRoot.Value;
                    if (item.OutTimeRoot != null)
                        dr.OutTimeRoot = item.OutTimeRoot.Value;
                    if (item.LateEarlyDuration != null)
                    {
                        if (item.LateEarlyDuration.Value < 120)
                        {
                            dr.EarlyLateLess2h = "X";
                        }
                        else
                        {
                            dr.EarlyLateOver2h = "X";
                        }
                    }
                    else
                    {
                        dr.EarlyLateLess2h = "X";
                    }

                    dr.DateFrom = dateStart;
                    dr.DateTo = dateEnd;
                    dt.Add(dr);
                }
                return dt;

                //var lstWorkdayQuery = repoAtt_Workday.FindBy(x => x.Status == WorkdayStatus.E_APPROVED.ToString() && x.WorkDate >= DateFrom && x.WorkDate <= DateTo &&
                //    (x.InTime1 != x.InTimeRoot || x.OutTime1 != x.OutTimeRoot || (x.InTime1 != null && x.InTimeRoot == null) || (x.OutTime1 != null && x.OutTimeRoot == null)));
                //List<Guid> lstprofileIDs = new List<Guid>();
                //if (!string.IsNullOrEmpty(OrgStructureIDs) || !string.IsNullOrEmpty(PayrollGroupIDs) || !string.IsNullOrEmpty(CodeEmp))
                //{
                //    if (PayrollGroupIDs == null)
                //        PayrollGroupIDs = "";
                //    var LstProfileQuery = repoHre_Profile.FindBy(x => x.PayrollGroupID.HasValue && PayrollGroupIDs.Contains(x.PayrollGroupID.Value.ToString()));
                //    if (!string.IsNullOrEmpty(OrgStructureIDs))
                //        LstProfileQuery = repoHre_Profile.FindBy(x => x.OrgStructureID.HasValue && OrgStructureIDs.Contains(x.OrgStructureID.Value.ToString()));
                //    if (!string.IsNullOrEmpty(CodeEmp))
                //        LstProfileQuery = repoHre_Profile.FindBy(x => x.CodeEmp == CodeEmp);
                //    lstprofileIDs = LstProfileQuery.Select(m => m.ID).ToList<Guid>();
                //}
                //if (lstWorkdayQuery != null && lstprofileIDs.Count > 0)
                //    lstWorkdayQuery = repoAtt_Workday.FindBy(x => lstprofileIDs.Contains(x.ProfileID));
                //List<Att_Workday> lstWorkday = lstWorkdayQuery.ToList();
                ////if (lstWorkday == null)
                ////    return null;
                ////return lstWorkday.Translate<Att_WorkdayEntity>();

                //if (lstWorkday == null)
                //    return null;

                //var profileIds = lstWorkday.Select(s => s.ProfileID).Distinct().ToList();
                //string strIDs = string.Join(",", profileIds.ToArray());
                //List<object> lstObj = new List<object>();
                //lstObj.Add(strIDs);
                //string status = "";
                //var lstProfile = baseService.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(String.Join(",", profileIds)), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status);
                //lstObj = new List<object>(4);
                //List<object> paracatshift = new List<object>();
                //paracatshift.AddRange(new object[4]);
                //paracatshift[2] = 1;
                //paracatshift[3] = 10000000;
                ////var lstShift = baseService.GetData<Cat_ShiftEntity>(lstObj, ConstantSql.hrm_cat_sp_get_Shift, ref status);
                //var lstShift = baseService.GetData<Cat_ShiftEntity>(paracatshift, ConstantSql.hrm_cat_sp_get_Shift, ref status);
                //var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                //var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                //List<Att_ReportInOutAdjustmentEntity> lstResult = new List<Att_ReportInOutAdjustmentEntity>();
                //var lstReasonMissInout = repoCat_TAMScanReasonMiss.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.TAMScanReasonMissName }).ToList();
                //foreach (var item in lstWorkday)
                //{
                //    Att_ReportInOutAdjustmentEntity objResult = new Att_ReportInOutAdjustmentEntity();
                //    var Profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault();
                //    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);

                //    objResult.CodeEmp = Profile.CodeEmp;
                //    objResult.ProfileName = Profile.ProfileName;
                //    if (lstShift != null)
                //    {
                //        var shift = lstShift.Where(m => m.ID == item.ShiftID).FirstOrDefault();
                //        if (shift != null)
                //            objResult.ShiftName = shift.ShiftName;
                //        var shiftActual = lstShift.Where(m => m.ID == item.ShiftActual).FirstOrDefault();
                //        if (shiftActual != null)
                //            objResult.ShiftNameActual = shiftActual.ShiftName;
                //        if (item.WorkDate != null)
                //            objResult.WorkDate = item.WorkDate;
                //        var shiftApprove = lstShift.Where(m => m.ID == item.ShiftApprove).FirstOrDefault();
                //        if (shiftApprove != null)
                //            objResult.ShiftNameApprove = shiftApprove.ShiftName;
                //    }
                //    if (item.InTime1 != null)
                //        objResult.InTime1 = item.InTime1;
                //    if (item.OutTime1 != null)
                //        objResult.OutTime1 = item.OutTime1;
                //    objResult.InTimeRoot = item.InTimeRoot;
                //    objResult.OutTimeRoot = item.OutTimeRoot;
                //    objResult.WorkDate = item.WorkDate;
                //    objResult.Type = item.Type;
                //    objResult.SrcType = item.SrcType;
                //    objResult.Status = item.Status;
                //    objResult.Note = item.Note;
                //    objResult.LateDuration1 = item.LateDuration1;
                //    objResult.EarlyDuration1 = item.EarlyDuration1;
                //    objResult.LateEarlyDuration = item.LateEarlyDuration;
                //    objResult.LateEarlyRoot = item.LateEarlyRoot;
                //    objResult.LateEarlyReason = item.LateEarlyReason;

                //    objResult.BrandCode = orgBranch != null ? orgBranch.Code : string.Empty;
                //    objResult.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                //    objResult.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                //    objResult.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                //    var Org = orgs.Where(d => d.ID == Profile.OrgStructureID).FirstOrDefault();
                //    if (Org != null)
                //    {
                //        objResult.ProfileOrgCode = Org.Code;
                //    }
                //    if (item.LateEarlyDuration != null)
                //    {
                //        if (item.LateEarlyDuration.Value < 2)
                //        {
                //            objResult.EarlyLateLess2h = "X";
                //        }
                //        else
                //        {
                //            objResult.EarlyLateOver2h = "X";
                //        }
                //    }
                //    else
                //    {
                //        objResult.EarlyLateLess2h = "X";
                //    }
                //    if (item.MissInOutReason != null)
                //    {
                //        var reason = lstReasonMissInout.Where(m => m.ID == item.MissInOutReason.Value).FirstOrDefault();
                //        if (reason != null)
                //        {
                //            objResult.MissInOutReason = reason.TAMScanReasonMissName;
                //        }
                //    }
                //    objResult.DateFrom = DateFrom;
                //    objResult.DateTo = DateTo;
                //    objResult.DatePrint = DateTime.Today;
                //    objResult.UserPrint = userPrint;
                //    lstResult.Add(objResult);
                //}
                //return lstResult;
            }
        }
Пример #21
0
 public List<Can_ReportMealTimeDetailNoEatEntity> ReportMealTimeDetailNoEat(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime dateStart, DateTime dateEnd, List<int?> orgIDs)
 {
     var mealRecords = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Can_MealRecordRepository(unitOfWork);
         if (LineIDS != null)
         {
             mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
             .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID })
             .ToList();
         }
         else mealRecords = repo.GetAll().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
     }
     var workDays = new List<Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Att_WorkDayRepository(unitOfWork);
         workDays = repo.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
         .Select(s => new { s.ProfileID, s.WorkDate }).ToList();
     }
     var lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
     var lstProfile = new List<Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance }).ToList();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Hre_ProfileRepository(unitOfWork);
         lstProfile = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance))
         .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance }).ToList();
     }
     List<Cat_OrgStructure> orgs = new List<Cat_OrgStructure>();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Cat_OrgStructureRepository(unitOfWork);
         orgs = repo.FindBy(s => s.Code != null).ToList();
     }
     lstProfile = lstProfile.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
     //if (!isIncludeQuitEmp)
     //{
     //    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
     //    profileIds = profiles.Select(s => s.ID).ToList();
     //    mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();
     //}
     if (CanteenIDS != null)
     {
         mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList();
     }
     if (CarteringIDs != null)
     {
         mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList();
     }
     if (LineIDS != null)
     {
         mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList();
     }
     lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
     List<Hre_Profile> profiles = new List<Hre_Profile>();
     var lstProfileId = new List<int>();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Hre_ProfileRepository(unitOfWork);
         profiles = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)).ToList();
         lstProfileId = profiles.Select(s => s.Id).ToList();
     }
     workDays = workDays.Where(s => lstProfileId.Contains(s.ProfileID)).ToList();
     var orgTypes = new List<Cat_OrgStructureType>();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Cat_OrgStructureTypeRepository(unitOfWork);
         orgTypes = repo.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
     }
     Can_ReportMealTimeDetailNoEatEntity reportMealTimeDetailNoEatEntity = null;
     List<Can_ReportMealTimeDetailNoEatEntity> lstreportMealTimeDetailNoEatEntity = new List<Can_ReportMealTimeDetailNoEatEntity>();
     foreach (var workDay in workDays)
     {
         var profile = profiles.FirstOrDefault(s => s.Id == workDay.ProfileID);
         if (profile != null)
         {
             int? 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);
             reportMealTimeDetailNoEatEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
             reportMealTimeDetailNoEatEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
             reportMealTimeDetailNoEatEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
             reportMealTimeDetailNoEatEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
             reportMealTimeDetailNoEatEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
             reportMealTimeDetailNoEatEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
             reportMealTimeDetailNoEatEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
             reportMealTimeDetailNoEatEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
             reportMealTimeDetailNoEatEntity.CodeEmp = profile.CodeEmp;
             reportMealTimeDetailNoEatEntity.ProfileName = profile.ProfileName;
             reportMealTimeDetailNoEatEntity.Date = workDay.WorkDate;
         }
         lstreportMealTimeDetailNoEatEntity.Add(reportMealTimeDetailNoEatEntity);
     }
     return lstreportMealTimeDetailNoEatEntity;
 }
Пример #22
0
        /// <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;
            }
        }
Пример #23
0
        public DataTable GetReportLateEarlyTotal(Att_ReportLateEarlyTotalEntity model, string userLogin)
        {
            DataTable    tblData   = getSchema();
            var          service   = new Att_ReportLateEarlyTotalServices();
            var          hrService = new Hre_ProfileServices();
            DateTime     DateFrom  = DateTime.Now;
            DateTime     DateTo    = DateTime.Now;
            List <Guid?> OrgIds    = new List <Guid?>();

            if (model.SDateFrom != null)
            {
                DateFrom = model.SDateFrom.Value;
            }
            if (model.SDateTo != null)
            {
                DateTo = model.SDateTo.Value;
            }
            var From = DateFrom;
            var To   = DateTo;

            string strOrgIDs = null;

            if (!string.IsNullOrEmpty(model.OrgStructureID))
            {
                strOrgIDs = model.OrgStructureID;
            }
            List <object> listObj = new List <object>();

            listObj.Add(strOrgIDs);
            listObj.Add(string.Empty);
            listObj.Add(string.Empty);


            string status = string.Empty;

            var result     = new DataTable();
            var lstprofile = hrService.GetData <Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).ToList();

            if (lstprofile == null || lstprofile.Count == 0)
            {
                return(null);
            }
            List <Guid> lstProfileIDs = lstprofile.Select(x => x.ID).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork            = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile           = new Hre_ProfileRepository(unitOfWork);
                var repoOrgStructure      = new Cat_OrgStructureRepository(unitOfWork);
                var repoOrgStructureType  = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoTAMScanReasonMiss = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var repoAtt_Workday       = new Att_WorkDayRepository(unitOfWork);
                //var lstprofile=repoProfile.FindBy(x=>lstProfileIDs.Contains(x.ID)).ToList();
                var  orgs                     = repoOrgStructure.FindBy(s => s.Code != null).ToList();
                var  orgTypes                 = repoOrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                Guid ForgetTams               = repoTAMScanReasonMiss.FindBy(x => x.Code.Equals("FC")).Select(x => x.ID).FirstOrDefault();
                var  lstWorkdayQuery          = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && (m.LateEarlyDuration > 0 || m.Type == WorkdayType.E_LATE_EARLY.ToString()) && !(m.Status == WorkdayStatus.E_APPROVED.ToString() && m.LateEarlyDuration == 0)).ToList();
                var  lstWorkdayFogetTamsQuery = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && m.MissInOutReason == ForgetTams).ToList();
                // var listProfile = repoProfile.FindBy(x => lstProfileIDs.Contains(x.ID)).ToList();
                if (lstProfileIDs != null && lstProfileIDs.Count != 0)
                {
                    lstWorkdayQuery          = lstWorkdayQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                    lstWorkdayFogetTamsQuery = lstWorkdayFogetTamsQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                }
                var lstWorkday          = lstWorkdayQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate, m.LateEarlyDuration }).ToList();
                var lstWorkdayFogetTams = lstWorkdayFogetTamsQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate }).ToList();
                foreach (var item in lstprofile)
                {
                    DataRow row = tblData.NewRow();
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.CodeEmp]     = item.CodeEmp;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.ProfileName] = item.ProfileName;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateFrom]    = From;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateTo]      = To;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.UserExport]  = model.UserExport;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateExport]  = DateTime.Today;
                    if (item.OrgStructureID.HasValue)
                    {
                        Cat_OrgStructure objOrgStructure = orgs.Where(x => x.ID == item.OrgStructureID).FirstOrDefault();
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.OrgStructureName] = objOrgStructure.OrgStructureName;
                        Guid?orgId      = item.OrgStructureID;
                        var  orgBrand   = 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_ReportLateEarlyTotalEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchCode]     = orgBrand != null ? orgBrand.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamCode]       = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionCode]    = orgSection != null ? orgSection.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchName]     = orgBrand != null ? orgBrand.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamName]       = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionName]    = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    }
                    for (DateTime MonthCheck = From; MonthCheck <= To; MonthCheck = MonthCheck.AddMonths(1))
                    {
                        DateTime BeginMonth     = new DateTime(MonthCheck.Year, MonthCheck.Month, 1);
                        DateTime EndMonth       = BeginMonth.AddMonths(1).AddMinutes(-1);
                        double   Less2Hour      = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration < 2).ToList().Count;
                        double   Over2Hour      = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration >= 2).ToList().Count;
                        double   TotalLateEarly = Less2Hour + Over2Hour;
                        double   ForgetTamscan  = lstWorkdayFogetTams.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth).ToList().Count;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Less2Hour + BeginMonth.Month]      = Less2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Over2Hour + BeginMonth.Month]      = Over2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TotalLateEarly + BeginMonth.Month] = TotalLateEarly;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.ForgetTamscan + BeginMonth.Month]  = ForgetTamscan;
                    }
                    tblData.Rows.Add(row);
                }
            }
            var configs       = new Dictionary <string, Dictionary <string, object> >();
            var confighidden  = new Dictionary <string, object>();
            var configCodeEmp = new Dictionary <string, object>();

            configCodeEmp.Add("width", 90);
            var configProfileName = new Dictionary <string, object>();

            configProfileName.Add("width", 125);
            var configOrgStructureName = new Dictionary <string, object>();

            configOrgStructureName.Add("width", 80);
            var configDepartmentCode = new Dictionary <string, object>();

            configDepartmentCode.Add("width", 98);
            var configSectionCode = new Dictionary <string, object>();

            configSectionCode.Add("width", 50);
            var configBranchCode = new Dictionary <string, object>();

            configBranchCode.Add("width", 90);
            var configBranchName = new Dictionary <string, object>();

            configBranchName.Add("width", 77);
            confighidden.Add("hidden", true);
            configs.Add("CodeEmp", configCodeEmp);
            configs.Add("ProfileName", configProfileName);
            configs.Add("OrgStructureName", configOrgStructureName);
            configs.Add("DepartmentCode", configDepartmentCode);
            configs.Add("SectionCode", configSectionCode);
            configs.Add("BranchCode", configBranchCode);
            configs.Add("DepartmentName", configOrgStructureName);
            configs.Add("SectionName", configSectionCode);
            configs.Add("BranchName", configBranchName);
            configs.Add("TeamName", configSectionCode);
            configs.Add("DateFrom", confighidden);
            configs.Add("DateTo", confighidden);
            configs.Add("UserExport", confighidden);
            configs.Add("DateExport", confighidden);
            return(tblData.ConfigTable(configs));
        }
Пример #24
0
        /// <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;

            }
        }
Пример #25
0
        public DataTable ReportMultiSlideCard(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime dateStart, DateTime dateEnd, List <int> lstProfileIds)
        {
            List <Can_ReportMultiSlideCardEntity> lstReportMultiSlideCard = new List <Can_ReportMultiSlideCardEntity>();
            DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEnd);

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork  = (IUnitOfWork)(new UnitOfWork(context));
                var mealRecords = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var repo        = new Can_MealRecordRepository(unitOfWork);
                mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
                              .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var lstcateringids = mealRecords.Select(m => m.CateringID).ToList();
                var lstcanteenids  = mealRecords.Select(m => m.CanteenID).ToList();
                var lstlineids     = mealRecords.Select(m => m.LineID).ToList();

                var workDays    = new List <Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                workDays = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                           .Select(s => new { s.ProfileID, s.WorkDate }).ToList();

                var Cardcode    = mealRecords.Select(s => s.CardCode).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles    = repoProfile.FindBy(m => Cardcode.Contains(m.CodeAttendance) && lstProfileIds.Contains(m.Id)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList();

                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs    = repoOrg.FindBy(m => m.Code != null).ToList();

                var catering     = new List <Can_Catering>().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                if (CarteringIDs != null && CarteringIDs.Count > 0)
                {
                    catering = repocatering.FindBy(m => CarteringIDs.Contains(m.Id)).ToList();
                }
                else
                {
                    catering = repocatering.GetAll().ToList();
                }


                var canteen     = new List <Can_Canteen>().ToList();
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null && CanteenIDS.Count > 0)
                {
                    canteen = repocanteen.FindBy(m => CanteenIDS.Contains(m.Id)).ToList();
                }
                else
                {
                    canteen = repocanteen.GetAll().ToList();
                }

                var line     = new List <Can_Line>().ToList();
                var repoline = new Can_LineRepository(unitOfWork);
                if (LineIDS != null && LineIDS.Count > 0)
                {
                    line = repoline.FindBy(m => LineIDS.Contains(m.Id)).ToList();
                }
                else
                {
                    line = repoline.GetAll().ToList();
                }

                Can_ReportMultiSlideCardEntity ReportMultiSlideCardEntity = new Can_ReportMultiSlideCardEntity();
                foreach (var profile in profiles)
                {
                    DataRow row               = datatable.NewRow();
                    var     orgbyprofile      = orgs.Where(m => m.Id == profile.OrgStructureID).FirstOrDefault();
                    var     cateringbyprofile = catering.Where(m => lstcateringids.Contains(m.Id)).FirstOrDefault();
                    var     lineprofile       = line.Where(m => lstlineids.Contains(m.Id)).FirstOrDefault();
                    var     canteenbyprofile  = canteen.Where(m => lstcanteenids.Contains(m.Id)).FirstOrDefault();
                    row[Can_ReportMultiSlideCardEntity.FieldNames.CodeEmp]          = profile.CodeEmp;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.ProfileName]      = profile.ProfileName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.OrgStructureName] = orgbyprofile.OrgStructureName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Cartering]        = cateringbyprofile.CateringName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Canteen]          = canteenbyprofile.CanteenName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Line]             = lineprofile.LineName;
                    var mealRecordProfiles = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).ToList();
                    var workDayProfiles    = workDays.Where(s => s.ProfileID == profile.Id).ToList();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date);
                        if (meal != null)
                        {
                            row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value;
                            //row["SumCardMore" + date.Day] = mealRecordProfiles.Count(s => s.TimeLog == date) - workDayProfiles.Count(s => s.WorkDate == date);
                        }
                    }
                    datatable.Rows.Add(row);
                }
            }
            return(datatable);
        }
Пример #26
0
        /// <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;
            }
        }
Пример #27
0
        public DataTable GetReportRecieveObjectByTime(string orgStructureIDs, DateTime dateFrom, DateTime dateTo, bool IsCreateTemplate, string userLogin)
        {
            DataTable table = GetSchemaReportRecieveObjectByTime(userLogin);
            if (IsCreateTemplate)
            {
                return table.ConfigTable();
            }
            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] = orgStructureIDs;
                listObjHDTJob[6] = dateFrom;
                listObjHDTJob[7] = dateTo;
                listObjHDTJob[12] = 1;
                listObjHDTJob[13] = Int32.MaxValue - 1;
                var lstHDTJob = hdtJobServices.GetData<Hre_HDTJobEntity>(listObjHDTJob, ConstantSql.hrm_hr_sp_get_RptRecieveObjectByTime, userLogin, ref status).ToList();
                if (lstHDTJob.Count == 0)
                {
                    return table;
                }

                var lstProfileIDByHDTJob = lstHDTJob.Select(s => s.ProfileID).Distinct().ToList();

                #region Lấy WorkDay
                var workDayRepository = new Att_WorkDayRepository(unitOfWork);
                var lstworkDays = new List<Att_Workday>().Select(d => new
                {
                    d.ProfileID,
                    d.WorkDate,
                    d.FirstInTime,
                    d.LastOutTime
                }).ToList();

                foreach (var item in lstProfileIDByHDTJob.Chunk(1000))
                {
                    lstworkDays.AddRange(workDayRepository.FindBy(s => s.IsDelete == null && s.WorkDate >= dateFrom
                        && s.WorkDate <= dateTo && item.Contains(s.ProfileID)).Select(d => new
                        {
                            d.ProfileID,
                            d.WorkDate,
                            d.FirstInTime,
                            d.LastOutTime
                        }).ToList());
                }

                if (lstworkDays.Count == 0)
                {
                    return table;
                }
                #endregion

                #region Lấy MealRecord
                var mealRecordRepository = new Can_MealRecordRepository(unitOfWork);
                var lstmeadrecored = new List<Can_MealRecord>().Select(d => new
                {
                    d.ProfileID,
                    d.WorkDay,
                    d.Amount
                }).ToList();

                foreach (var item in lstProfileIDByHDTJob.Chunk(1000))
                {
                    lstmeadrecored.AddRange(mealRecordRepository.FindBy(s => s.IsDelete == null && s.WorkDay >= dateFrom
                        && s.WorkDay <= dateTo && item.Contains(s.ProfileID)).Select(d => new
                        {
                            d.ProfileID,
                            d.WorkDay,
                            d.Amount
                        }).ToList());
                }
                #endregion

                List<object> listObjPrice = new List<object>();
                listObjPrice.Add(null);
                listObjPrice.Add(null);
                listObjPrice.Add(null);
                listObjPrice.Add(1);
                listObjPrice.Add(Int32.MaxValue - 1);
                var lstHDTJobTypePrice = basevices.GetData<Cat_HDTJobTypePriceEntity>(listObjPrice, ConstantSql.hrm_cat_sp_get_HDTJobTypePrice, userLogin, ref status).Where(s => s.Price != null).Distinct().ToList();
                var profileServices = new Hre_ProfileServices();
                var listResult = profileServices.getHDTJobByPrice(lstHDTJob, dateFrom, dateTo);

                var ListProfileID = listResult.Select(m => m.ProfileID).Distinct().ToList();

                foreach (var profileID in ListProfileID)
                {
                    var firstProfile = listResult.Where(m => m.ProfileID == profileID).FirstOrDefault();
                    var lstWorkDaysByProfile = lstworkDays.Where(m => m.ProfileID == profileID && (m.FirstInTime != null || m.LastOutTime != null)).ToList();
                    var lstmeadlbypro = lstmeadrecored.Where(s => s.ProfileID == profileID).ToList();
                    if (firstProfile != null && lstWorkDaysByProfile.Count != 0)
                    {
                        bool isAdd = false;
                        DataRow row = table.NewRow();
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.ProfileName] = firstProfile.ProfileName;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.CodeEmp] = firstProfile.CodeEmp;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_DEPARTMENT] = firstProfile.E_DEPARTMENT;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_DIVISION] = firstProfile.E_DIVISION;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_SECTION] = firstProfile.E_SECTION;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_TEAM] = firstProfile.E_TEAM;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_UNIT] = firstProfile.E_UNIT;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Dept] = firstProfile.Dept;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Unit] = firstProfile.Unit;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Part] = firstProfile.Part;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Line] = firstProfile.Line;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Session] = firstProfile.Session;
                        var hdtjobbyprofile = lstHDTJob.Where(s => s.ProfileID == profileID).ToList();
                        var workdaybyProfile = lstworkDays.Where(s => s.ProfileID == profileID).ToList();
                        foreach (var item in lstHDTJobTypePrice)
                        {
                            var resultByPrice = listResult.Where(m => m.ProfileID == profileID && m.Price == item.Price).ToList();

                            if (resultByPrice.Count == 0)
                            {
                                continue;
                            }
                            int? count = 0;

                            foreach (var Price in resultByPrice)
                            {
                                if (Price.DateTo == null)
                                {
                                    Price.DateTo = dateTo;
                                }
                                for (DateTime date = Price.DateFrom.Value; date <= Price.DateTo; date = date.AddDays(1))
                                {
                                    var workdaybyprice = workdaybyProfile.Where(s => s.WorkDate != null && s.WorkDate.Date == date.Date && s.FirstInTime != null && s.LastOutTime != null).FirstOrDefault();
                                    var mealbyprice = lstmeadlbypro.Where(s => s.Amount != null && s.WorkDay != null && s.WorkDay.Value.Date == date.Date && (double)s.Amount == Price.Price).FirstOrDefault();

                                    if (workdaybyprice != null && mealbyprice != null)
                                    {
                                        count++;
                                    }
                                    row[item.Price.ToString()] = count != 0 ? count : null;
                                    if (count != null && count != 0)
                                    {
                                        isAdd = true;
                                    }
                                }

                            }
                        }
                        if (isAdd == true)
                        {
                            table.Rows.Add(row);
                        }
                    }
                }
            }
            return table.ConfigTable();
        }
Пример #28
0
        public DataTable GetReportMonthlyTimeSheetV2(string WorkHourType, Guid? GradeAttendanceID, Guid CutOffDurationID, 
            string strProfile, string strOrgStructure, string codeEmp, bool isIncludeQuitEmp, bool isNotAllowZero,
            bool isCreateTemplate, string userExport, string UserLogin, Guid? jobtitleID, Guid? positionID)
        {
            bool IsPaidHour = WorkHourType == EnumDropDown.WorkHourType.E_PAIDHOUR.ToString() ? true : false;
            using (var context = new VnrHrmDataContext())
            {
                DataTable table = CreateReportMonthlyTimeSheetV2Schema(UserLogin);
                if (isCreateTemplate)
                {
                    return table.ConfigDatatable();
                }
                string status = string.Empty;
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                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 repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoTimeSheet = new Att_TimeSheetRepository(unitOfWork);
                var repoJobtype = new Cat_JobTypeRepository(unitOfWork);
                var repoAtt_AttendencaTable = new CustomBaseRepository<Att_AttendanceTable>(unitOfWork);
                var repoAtt_AttendanceTableItem = new CustomBaseRepository<Att_AttendanceTableItem>(unitOfWork);
                var repoAtt_CutOffDuration = new CustomBaseRepository<Att_CutOffDuration>(unitOfWork);

                var orgsService = new Cat_OrgStructureServices();
                List<object> objorgs = new List<object>();
                var lstallorgs = orgsService.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, UserLogin, ref status).ToList();

                var orgTypeService = new Cat_OrgStructureTypeServices();
                var lstObjOrgType = new List<object>();
                lstObjOrgType.Add(null);
                lstObjOrgType.Add(null);
                lstObjOrgType.Add(1);
                lstObjOrgType.Add(int.MaxValue - 1);
                var lstOrgType = orgTypeService.GetData<Cat_OrgStructureType>(lstObjOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, UserLogin, ref status);

                var jobTypeServices = new Cat_JobTypeServices();
                var lstjobType = new List<object>();
                lstjobType.Add(null);
                lstjobType.Add(null);
                lstjobType.Add(1);
                lstjobType.Add(Int32.MaxValue - 1);
                var listjobType = jobTypeServices.GetData<Cat_JobTypeEntity>(lstjobType, ConstantSql.hrm_cat_sp_get_JobType, UserLogin, ref status).Where(s => s.Code != null).Select(m => new { m.ID, m.Code }).ToList();

                var lstObjOrgByOrderNumberCount = new List<object>();
                lstObjOrgByOrderNumberCount.Add(strOrgStructure);
                var lstOrgByOrderNumberCount = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumberCount, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).ToList();

                List<Hre_ProfileEntity> profiles = new List<Hre_ProfileEntity>();
                List<object> lstParamHR = new List<object>();
                lstParamHR.Add(strOrgStructure);
                lstParamHR.Add(null);
                lstParamHR.Add(null);
                if (strProfile != null)
                {
                    List<Hre_ProfileEntity> _profileIDs = new List<Hre_ProfileEntity>();
                    var lst = strProfile.Split(',').Select(s => Guid.Parse(s)).ToList();

                    if (strOrgStructure != null)
                    {
                        profiles = GetData<Hre_ProfileEntity>(strOrgStructure, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();
                        _profileIDs = profiles.Where(m => !lst.Contains(m.ID)).ToList();
                        profiles.AddRange(_profileIDs);
                    }
                    else
                    {
                        string selectedIds = Common.DotNetToOracle(strProfile);
                        profiles = GetData<Hre_ProfileEntity>(selectedIds, ConstantSql.hrm_hr_sp_get_ProfileByIds, UserLogin, ref status).ToList();
                    }
                }
                else
                {
                    profiles = GetData<Hre_ProfileEntity>(lstParamHR, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();
                }

                if (GradeAttendanceID != null && GradeAttendanceID != Guid.Empty)
                {
                    var lstObjAttGrade = new List<object>();
                    lstObjAttGrade.AddRange(new object[6]);
                    lstObjAttGrade[1] = Common.DotNetToOracle(GradeAttendanceID.Value.ToString());
                    lstObjAttGrade[4] = 1;
                    lstObjAttGrade[5] = int.MaxValue - 1;
                    var lstAttGrade = GetData<Att_GradeEntity>(lstObjAttGrade, ConstantSql.hrm_att_sp_get_Att_Grade, UserLogin, ref status).ToList();

                    List<Guid> lstProOfGrade = lstAttGrade.Select(s => s.ProfileID.Value).Distinct().ToList();

                    profiles = profiles.Where(s => lstProOfGrade.Contains(s.ID)).ToList();
                }
                var cutoffInfo = repoAtt_CutOffDuration.FindBy(s => s.ID == CutOffDurationID).FirstOrDefault();
                var leavedayTypes = unitOfWork.CreateQueryable<Cat_LeaveDayType>(Guid.Empty, s => s.CodeStatistic != null).Select(s => new { s.Code, s.CodeStatistic, s.ID, s.PaidRate, s.LeaveDayTypeName }).ToList();
                var overtimeTypes = unitOfWork.CreateQueryable<Cat_OvertimeType>(Guid.Empty, s => s.CodeStatistic != null).ToList();
                DateTime dateStart = cutoffInfo.DateStart;
                DateTime dateEnd = cutoffInfo.DateEnd;

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

                if(jobtitleID != null)
                {
                    profiles = profiles.Where(s => s.JobTitleID == jobtitleID).ToList();
                }

                if (positionID != null)
                {
                    profiles = profiles.Where(s => s.PositionID == positionID).ToList();
                }

                List<Guid> profileIds = profiles.Select(s => s.ID).ToList();
                var timesheets = new List<Att_TimeSheet>().Select(s => new
                {
                    s.ProfileID,
                    s.JobTypeID,
                    s.RoleID,
                    s.Date,
                    s.NoHour,
                    s.ID,
                    s.Note,
                    s.Sector
                }).ToList();

                var workDays = new List<Att_Workday>().Select(s => new
                {
                    s.ProfileID,
                    s.ShiftID,
                    s.Status
                }).ToList();

                var attendanceTables = new List<Att_AttendanceTable>();
                var attendanceTableItems = new List<Att_AttendanceTableItem>();

                foreach (var item in profileIds.Chunk(1000))
                {
                    timesheets.AddRange(repoTimeSheet.FindBy(s => s.ProfileID != null && item.Contains(s.ProfileID.Value)
                        && s.Date != null && dateStart <= s.Date && s.Date <= dateEnd && s.IsDelete == null).Select(s => new
                        {
                            s.ProfileID,
                            s.JobTypeID,
                            s.RoleID,
                            s.Date,
                            s.NoHour,
                            s.ID,
                            s.Note,
                            s.Sector
                        }).ToList());

                    workDays.AddRange(repoWorkDay.FindBy(s => item.Contains(s.ProfileID) && dateStart <= s.WorkDate
                        && s.WorkDate <= dateEnd && s.IsDelete == null).Select(s => new
                        {
                            s.ProfileID,
                            s.ShiftID,
                            s.Status
                        }).ToList());

                    attendanceTables.AddRange(repoAtt_AttendencaTable.FindBy(s => s.IsDelete == null
                        && s.CutOffDurationID == CutOffDurationID && item.Contains(s.ProfileID)).ToList());
                }

                var jobtypes = repoJobtype.FindBy(s => s.IsDelete == null).Select(s => new { s.ID, s.Code }).ToList();
                List<Guid> attendanceTablesID = attendanceTables.Select(s => s.ID).ToList();

                foreach (var item in attendanceTablesID.Chunk(1000))
                {
                    attendanceTableItems.AddRange(unitOfWork.CreateQueryable<Att_AttendanceTableItem>(s =>
                        s.IsDelete == null && item.Contains(s.AttendanceTableID)).ToList());
                }

                if (isNotAllowZero)
                {
                    profileIds = attendanceTables.Where(x => x.StdWorkDayCount > 0).Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }

                profileIds = attendanceTables.Select(s => s.ProfileID).ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();

                int p = 0;
                foreach (var profile in profiles)
                {
                    p += 1;
                    var attendanceTableProfile = attendanceTables.FirstOrDefault(s => s.ProfileID == profile.ID);
                    var timeSheetByProfile = timesheets.Where(s => s.ProfileID == profile.ID).ToList();

                    //if (timeSheetByProfile == null)
                    //{
                    //    continue;
                    //}
                    var lstjobtypebytimesheetpro = timeSheetByProfile.Select(s => s.JobTypeID).ToList();
                    var lstJobTypeCodeByTimeSheet = jobtypes.Where(s => lstjobtypebytimesheetpro.Contains(s.ID)).Select(s => new { s.ID, s.Code }).ToList();
                    if (attendanceTableProfile == null)
                    {
                        continue;
                    }
                    var attendanceTableItemProfile = attendanceTableItems.Where(s => s.AttendanceTableID == attendanceTableProfile.ID).ToList();
                    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 positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                    //var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);

                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DepartmentName] = profile.OrgStructureName;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DepartmentCode] = profile.OrgStructureCode;

                    if (profile.DateHire.HasValue)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateHire] = profile.DateHire.Value;
                    if (profile.DateEndProbation.HasValue)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateEndProbation] = profile.DateEndProbation.Value;
                    if (profile.E_COMPANY != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_COMPANY] = profile.E_COMPANY;
                    if (profile.E_BRANCH != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_BRANCH] = profile.E_BRANCH;
                    if (profile.E_UNIT != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_UNIT] = profile.E_UNIT;
                    if (profile.E_DIVISION != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_DIVISION] = profile.E_DIVISION;
                    if (profile.E_DEPARTMENT != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_DEPARTMENT] = profile.E_DEPARTMENT;
                    if (profile.E_TEAM != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_TEAM] = profile.E_TEAM;
                    if (profile.E_SECTION != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_SECTION] = profile.E_SECTION;



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



                    #region Lấy Tên Phòng ban cho BDF
                    var orgName = GetParentOrg(lstallorgs, lstOrgType, profile.OrgStructureID);
                    if (orgName.Count != 0)
                    {
                        if (orgName.Count < 3)
                        {
                            orgName.Insert(0, string.Empty);
                            if (orgName.Count < 3)
                            {
                                orgName.Insert(0, string.Empty);
                            }
                        }
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Channel] = orgName[2];
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Region] = orgName[1];
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Area] = orgName[0];
                    }
                    #endregion

                    #region Lấy phòng ban cho VietNam EASport

                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_COMPANY] = profile.E_COMPANY;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_BRANCH] = profile.E_BRANCH;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_UNIT] = profile.E_UNIT;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_DIVISION] = profile.E_DIVISION;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_DEPARTMENT] = profile.E_DEPARTMENT;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_TEAM] = profile.E_TEAM;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.E_SECTION] = profile.E_SECTION;

                    #endregion

                    //row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.PositionName] = positon != null ? positon.PositionName : string.Empty;
                    //row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                    if (profile.DateHire != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.StartingDate] = profile.DateHire.Value;
                    if (profile.DateQuit != null)
                        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.ResignedDate] = profile.DateQuit.Value;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateFrom] = dateStart;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateTo] = dateEnd;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.DateExport] = DateTime.Today;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.UserExport] = userExport;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.StdWorkDayCount] = attendanceTableProfile.StdWorkDayCount > 0 ? attendanceTableProfile.StdWorkDayCount : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.RealWorkDayCount] = attendanceTableProfile.RealWorkDayCount > 0 ? attendanceTableProfile.RealWorkDayCount : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.PaidWorkDayCount] = attendanceTableProfile.PaidWorkDayCount > 0 ? attendanceTableProfile.PaidWorkDayCount : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.HourPerDay] = attendanceTableProfile.HourPerDay > 0 ? attendanceTableProfile.HourPerDay : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.AnlDayAvailable] = attendanceTableProfile.AnlDayAvailable > 0 ? attendanceTableProfile.AnlDayAvailable : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.NightShiftHours] = attendanceTableProfile.NightShiftHours > 0 ? attendanceTableProfile.NightShiftHours : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.LateEarlyDeductionHours] = attendanceTableProfile.LateEarlyDeductionHours > 0 ? attendanceTableProfile.LateEarlyDeductionHours : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Note] = attendanceTableProfile.Note != null ? attendanceTableProfile.Note : string.Empty;

                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.UnPaidLeave] = attendanceTableProfile.UnPaidLeave > 0 ? attendanceTableProfile.UnPaidLeave : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.AnlDayTaken] = attendanceTableProfile.AnlDayTaken > 0 ? attendanceTableProfile.AnlDayTaken : 0.0;
                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.SickDayTaken] = attendanceTableProfile.SickDayTaken > 0 ? attendanceTableProfile.SickDayTaken : 0.0;

                    double preg = 0.0;

                    #region code cũ xử lý đổ (Data + Day)
                    //foreach (var item in attendanceTableItemProfile)
                    //{
                    //    if (item.IsHavingPregTreatment)
                    //    {
                    //        preg += 1;
                    //    }

                    //    if (item.LeaveTypeID != null)
                    //    {
                    //        row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + item.WorkDate.Day.ToString()] = leavedayTypes.Where(s => s.ID == item.LeaveTypeID).FirstOrDefault().Code;
                    //    }
                    //    else
                    //    {
                    //        if (IsPaidHour)
                    //        {
                    //            row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + item.WorkDate.Day.ToString()] = item.WorkPaidHours;
                    //        }
                    //        else
                    //        {
                    //            row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + item.WorkDate.Day.ToString()] = item.WorkHours;
                    //        }
                    //    }
                    //} 
                    #endregion

                    attendanceTableItemProfile = attendanceTableItemProfile.OrderBy(s => s.WorkDate).ToList();
                    Dictionary<string, double> leave_Hour = new Dictionary<string, double>();
                    for (int i = 0; i < attendanceTableItemProfile.Count; i++)
                    {
                        int stt = i + 1;

                        if (attendanceTableItemProfile[i].IsHavingPregTreatment)
                        {
                            preg += 1;
                        }

                        if (attendanceTableItemProfile[i].LeaveTypeID != null)
                        {
                            var leave = leavedayTypes.Where(s => s.ID == attendanceTableItemProfile[i].LeaveTypeID).FirstOrDefault();
                            if (attendanceTableItemProfile[i].LeaveDays == 0.5)
                            {
                                row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + stt] = leave.CodeStatistic + "/2";
                            }
                            else
                            {
                                row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + stt] = leave.CodeStatistic;
                            }

                            if (leave.CodeStatistic == null)
                                continue;
                            if (leave_Hour.ContainsKey(leave.CodeStatistic))
                                leave_Hour[leave.CodeStatistic] += attendanceTableItemProfile[i].LeaveHours;
                            else
                                leave_Hour[leave.CodeStatistic] = attendanceTableItemProfile[i].LeaveHours;
                        }
                        else
                        {
                            if (IsPaidHour)
                            {
                                row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + stt] = attendanceTableItemProfile[i].WorkPaidHours;
                            }
                            else
                            {
                                row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.Data + stt] = attendanceTableItemProfile[i].WorkHours;
                            }
                        }
                    }

                    foreach (var leave in leavedayTypes)
                    {
                        if (leave.CodeStatistic == null)
                            continue;
                        if (leave_Hour.ContainsKey(leave.CodeStatistic))
                        {
                            row[leave.CodeStatistic] = leave_Hour[leave.CodeStatistic];
                        }
                    }

                    #region Tăng Ca

                    if (attendanceTableProfile.Overtime1Type != null)
                    {
                        var overtime = overtimeTypes.Where(s => s.ID == attendanceTableProfile.Overtime1Type).FirstOrDefault();
                        if (overtime != null)
                            row[overtime.CodeStatistic] = attendanceTableProfile.Overtime1Hours;
                    }
                    if (attendanceTableProfile.Overtime2Type != null)
                    {
                        var overtime = overtimeTypes.Where(s => s.ID == attendanceTableProfile.Overtime2Type).FirstOrDefault();
                        if (overtime != null)
                            row[overtime.CodeStatistic] = attendanceTableProfile.Overtime2Hours;
                    }
                    if (attendanceTableProfile.Overtime3Type != null)
                    {
                        var overtime = overtimeTypes.Where(s => s.ID == attendanceTableProfile.Overtime3Type).FirstOrDefault();
                        if (overtime != null)
                            row[overtime.CodeStatistic] = attendanceTableProfile.Overtime3Hours;
                    }
                    if (attendanceTableProfile.Overtime4Type != null)
                    {
                        var overtime = overtimeTypes.Where(s => s.ID == attendanceTableProfile.Overtime4Type).FirstOrDefault();
                        if (overtime != null)
                            row[overtime.CodeStatistic] = attendanceTableProfile.Overtime4Hours;
                    }
                    if (attendanceTableProfile.Overtime5Type != null)
                    {
                        var overtime = overtimeTypes.Where(s => s.ID == attendanceTableProfile.Overtime5Type).FirstOrDefault();
                        if (overtime != null)
                            row[overtime.CodeStatistic] = attendanceTableProfile.Overtime5Hours;
                    }
                    if (attendanceTableProfile.Overtime6Type != null)
                    {
                        var overtime = overtimeTypes.Where(s => s.ID == attendanceTableProfile.Overtime6Type).FirstOrDefault();
                        if (overtime != null)
                            row[overtime.CodeStatistic] = attendanceTableProfile.Overtime6Hours;
                    }

                    #endregion


                    row[Att_ReportMonthlyTimeSheetV2Entity.FieldNames.TotalPregnancy] = preg;
                    foreach (var jobcode in listjobType)
                    {
                        if (table.Columns.Contains(jobcode.Code))
                        {
                            double? nohourByPro = timeSheetByProfile.Where(s => s.JobTypeID == jobcode.ID).Sum(s => s.NoHour);
                            double? sectorByPro = timeSheetByProfile.Where(s => s.JobTypeID == jobcode.ID).Sum(s => s.Sector);
                            row[jobcode.Code] = nohourByPro == null ? 0 : nohourByPro.Value;
                            row[jobcode.Code + "_Sector"] = sectorByPro == null ? 0 : sectorByPro.Value;
                        }
                    }
                    table.Rows.Add(row);
                }
                var configs = new Dictionary<string, Dictionary<string, object>>();
                var config = new Dictionary<string, object>();
                config.Add("format", "{0:dd/mm/yyyy}");
                configs.Add("DateFrom", config);
                return table.ConfigTable();
            }

        }
Пример #29
0
        /// <summary>
        /// [Tam.Le] - 20140725 - Lấy dữ liệu BC Chi Tiết Nhân Viên Có Chấm Công Nhưng Không Ăn
        /// </summary>
        /// <param name="CarteringIDs"></param>
        /// <param name="CanteenIDS"></param>
        /// <param name="LineIDS"></param>
        /// <param name="DateFrom"></param>
        /// <param name="DateTo"></param>
        /// <returns></returns>
        public List <Can_ReportMealTimeDetailNoEatEntity> ReportMealTimeDetailNoEat(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime dateStart, DateTime dateEnd, List <int?> orgIDs)
        {
            var mealRecords = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_MealRecordRepository(unitOfWork);
                if (LineIDS != null)
                {
                    mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
                                  .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID })
                                  .ToList();
                }
                else
                {
                    mealRecords = repo.GetAll().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                }
            }
            var workDays = new List <Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Att_WorkDayRepository(unitOfWork);
                workDays = repo.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                           .Select(s => new { s.ProfileID, s.WorkDate }).ToList();
            }
            var lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
            var lstProfile        = new List <Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Hre_ProfileRepository(unitOfWork);
                lstProfile = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance))
                             .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList();
            }
            List <Cat_OrgStructure> orgs = new List <Cat_OrgStructure>();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Cat_OrgStructureRepository(unitOfWork);
                orgs = repo.FindBy(s => s.Code != null).ToList();
            }
            lstProfile = lstProfile.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
            //if (!isIncludeQuitEmp)
            //{
            //    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
            //    profileIds = profiles.Select(s => s.ID).ToList();
            //    mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();
            //}
            if (CanteenIDS[0] != null)
            {
                mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList();
            }
            if (CarteringIDs[0] != null)
            {
                mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList();
            }
            if (LineIDS[0] != null)
            {
                mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList();
            }
            lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
            List <Hre_Profile> profiles = new List <Hre_Profile>();
            var lstProfileId            = new List <int>();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Hre_ProfileRepository(unitOfWork);
                profiles     = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)).ToList();
                lstProfileId = profiles.Select(s => s.Id).ToList();
            }
            workDays = workDays.Where(s => lstProfileId.Contains(s.ProfileID)).ToList();
            var orgTypes = new List <Cat_OrgStructureType>();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repo.FindBy(s => s.IsDelete == null).ToList <Cat_OrgStructureType>();
            }
            Can_ReportMealTimeDetailNoEatEntity        reportMealTimeDetailNoEatEntity    = null;
            List <Can_ReportMealTimeDetailNoEatEntity> lstreportMealTimeDetailNoEatEntity = new List <Can_ReportMealTimeDetailNoEatEntity>();

            foreach (var workDay in workDays)
            {
                var profile = profiles.FirstOrDefault(s => s.Id == workDay.ProfileID);
                if (profile != null)
                {
                    int?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);
                    reportMealTimeDetailNoEatEntity.BranchCode  = orgBranch != null ? orgBranch.Code : string.Empty;
                    reportMealTimeDetailNoEatEntity.OrgCode     = orgOrg != null ? orgOrg.Code : string.Empty;
                    reportMealTimeDetailNoEatEntity.TeamCode    = orgTeam != null ? orgTeam.Code : string.Empty;
                    reportMealTimeDetailNoEatEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                    reportMealTimeDetailNoEatEntity.BranchName  = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    reportMealTimeDetailNoEatEntity.OrgName     = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    reportMealTimeDetailNoEatEntity.TeamName    = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    reportMealTimeDetailNoEatEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    reportMealTimeDetailNoEatEntity.CodeEmp     = profile.CodeEmp;
                    reportMealTimeDetailNoEatEntity.ProfileName = profile.ProfileName;
                    reportMealTimeDetailNoEatEntity.Date        = workDay.WorkDate;
                }
                lstreportMealTimeDetailNoEatEntity.Add(reportMealTimeDetailNoEatEntity);
            }
            return(lstreportMealTimeDetailNoEatEntity);
        }
Пример #30
0
        public void ComputeMealRecordMissing(List <Guid> lstProfileIds, DateTime dateFrom, DateTime dateToSearch, List <Guid> TamScanReasonMissID, string Status, List <Guid?> lstAllowanceTypeIDs)
        {
            List <Can_MealRecordMissingEntity> lstMealRecord = new List <Can_MealRecordMissingEntity>();

            using (var context = new VnrHrmDataContext())
            {
                DateTime dateTo = DateTime.Now;
                if (dateToSearch != null && dateToSearch != SqlDateTime.MaxValue.Value)
                {
                    dateTo = dateToSearch.AddDays(1).AddMinutes(-1);
                }
                if (lstProfileIds == null)
                {
                    return;
                }
                var    unitOfWork           = (IUnitOfWork)(new UnitOfWork(context));
                var    repoProfile          = new Hre_ProfileRepository(unitOfWork);
                string statusAllowance      = StatusMealAllowanceToMoney.E_APPROVED.ToString();
                var    repoMealAllowance    = new Can_MealAllowanceToMoneyRepository(unitOfWork);
                var    mealAllowanceProfies = repoMealAllowance.FindBy(s => s.Status == statusAllowance && dateFrom <= s.DateTo && s.DateFrom <= dateTo)
                                              .Select(s => new { s.ProfileID, s.MealAllowanceTypeID, s.DateFrom, s.DateTo }).ToList();

                var repoMissReason = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var resons         = repoMissReason.FindBy(s => s.IsForCMS == true).Select(s => new { s.ID, s.IsFullPay }).ToList();

                var repoWorkday = new Att_WorkDayRepository(unitOfWork);
                var workDays    = repoWorkday.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateFrom <= s.WorkDate && s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID))
                                  .Select(s => new { s.ProfileID, s.WorkDate, s.MissInOutReason, s.Status, s.FirstInTime, s.LastOutTime }).ToList();

                var repoMealRecord     = new Can_MealRecordRepository(unitOfWork);
                var mealRecordProfiles = repoMealRecord.FindBy(s => s.WorkDay != null && s.ProfileID != null &&
                                                               dateFrom <= s.WorkDay && s.WorkDay <= dateTo && lstProfileIds.Contains(s.ProfileID.Value))
                                         .Select(s => new { s.ProfileID, s.TimeLog, s.WorkDay }).ToList();

                var statusLeaveDay   = AttendanceDataStatus.E_APPROVED.ToString();
                var repoLeaveDay     = new Att_LeavedayRepository(unitOfWork);
                var leaveDayProfiles = repoLeaveDay.FindBy(s => s.Status == statusLeaveDay && dateFrom <= s.DateEnd && s.DateStart <= dateTo)
                                       .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                var tamSanResons = repoMissReason.GetAll().ToList();
                var repoMealAllowanceTypeSettings = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealSesttings = repoMealAllowanceTypeSettings.GetAll().Select(s => new { s.ID, s.Amount, s.MealAllowanceTypeSettingName }).ToList();
                if (TamScanReasonMissID != null && TamScanReasonMissID[0] != Guid.Empty)
                {
                    workDays = workDays.Where(s => s.MissInOutReason != null && TamScanReasonMissID.Contains(s.MissInOutReason.Value)).ToList();
                }
                if (Status != null)
                {
                    workDays = workDays.Where(s => s.Status != null && Status == s.Status).ToList();
                }
                var repoRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                List <Can_MealRecordMissing> mealRecordMissings = repoRecordMissing.FindBy(s => dateFrom <= s.WorkDate && s.WorkDate <= dateTo && s.ProfileID != null &&
                                                                                           lstProfileIds.Contains(s.ProfileID.Value)).ToList();
                var workDayProfies = repoWorkday.FindBy(s => (s.InTime1 != null || s.OutTime1 != null) && dateFrom <= s.WorkDate &&
                                                        s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate, s.ShiftID }).ToList();
                var profileIDs = workDayProfies.Select(s => s.ProfileID).Distinct().ToList();
                var lstmeal    = new List <Can_MealRecordMissing>();
                foreach (var profileID in profileIDs)
                {
                    for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
                    {
                        var recordProfileIDs   = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var leavedayProfileIDs = leaveDayProfiles.Where(s => s.DateStart != null && s.DateEnd != null && s.DateStart.Date <= date.Date &&
                                                                        date.Date <= s.DateEnd.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date.Date && s.ProfileID == profileID && !recordProfileIDs.Contains(s.ProfileID) && !leavedayProfileIDs.Contains(s.ProfileID)).ToList();
                        foreach (var workDay in workDayProfiles)
                        {
                            var meal = mealRecordMissings.FirstOrDefault(s => s.ProfileID == workDay.ProfileID && s.WorkDate.Value.Date == workDay.WorkDate.Date);
                            if (meal == null)
                            {
                                meal    = new Can_MealRecordMissing();
                                meal.ID = Guid.Empty;
                                lstmeal.Add(meal);
                            }
                            meal.ProfileID = workDay.ProfileID;
                            meal.WorkDate  = workDay.WorkDate;
                            if (meal.TamScanReasonMissID == Guid.Empty)
                            {
                                if (workDay.MissInOutReason != Guid.Empty)
                                {
                                    meal.TamScanReasonMissID = workDay.MissInOutReason;
                                    var tamScan = tamSanResons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                    if (tamScan != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = tamScan.MealAllowanceTypeSettingID;
                                        meal.TamScanReasonMissID        = tamScan.ID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == tamScan.MealAllowanceTypeSettingID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }
                                else
                                {
                                    var allownce = mealAllowanceProfies.FirstOrDefault(s => s.ProfileID == workDay.ProfileID &&
                                                                                       s.DateFrom <= date && date <= s.DateTo);
                                    if (allownce != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = allownce.MealAllowanceTypeID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == allownce.MealAllowanceTypeID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }
                            }
                            if (meal.MealAllowanceTypeSettingID != Guid.Empty)
                            {
                                meal.Status = MealRecord_Status.E_APPROVED.ToString();
                            }
                            else
                            {
                                meal.Status = MealRecord_Status.E_SUBMIT.ToString();
                            }
                            meal.Type = WorkdaySrcType.E_MANUAL.ToString();
                            if (workDay.FirstInTime == null && workDay.LastOutTime == null && workDay.MissInOutReason != Guid.Empty)
                            {
                                var tamSanReson = resons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                if (tamSanReson != null)
                                {
                                    meal.IsFullPay = tamSanReson.IsFullPay;
                                }
                            }
                        }
                    }
                }

                repoRecordMissing.Add(lstmeal);
                repoMissReason.SaveChanges();
            }
        }