/// <summary> /// Lấy bản ghi có id /// </summary> /// <returns></returns> public Sys_AllSetting GetById(Guid id) { using (var context = new VnrHrmDataContext()) { IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); Sys_AllSettingRepository repo = new Sys_AllSettingRepository(unitOfWork); Sys_AllSetting model = new Sys_AllSetting(); model = repo.GetById(id); return model; } }
public string SaveOvertimePermitConfig(OvertimePermitEntity entity, string userLogin) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoSys_AllSetting = new CustomBaseRepository<Sys_AllSetting>(unitOfWork); Sys_AllSetting sys = new Sys_AllSetting(); string HRM_ATT_OT_OTPERMIT_ = AppConfig.HRM_ATT_OT_OTPERMIT_.ToString(); string status = string.Empty; List<object> lstO = new List<object>(); lstO.Add(HRM_ATT_OT_OTPERMIT_); lstO.Add(null); lstO.Add(null); var config = GetData<Sys_AllSetting>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status); if (config != null) { if (entity.limitHour_ByDay.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByDay.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByDay.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY.ToString(); objConfig.Value1 = entity.limitHour_ByDay.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByDay_Lev1.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByDay_Lev1.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByDay_Lev1.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV1.ToString(); objConfig.Value1 = entity.limitHour_ByDay_Lev1.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByDay_Lev2.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByDay_Lev2.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByDay_Lev2.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYDAY_LEV2.ToString(); objConfig.Value1 = entity.limitHour_ByDay_Lev2.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByWeek.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByWeek.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByWeek.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK.ToString(); objConfig.Value1 = entity.limitHour_ByWeek.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByWeek_Lev1.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByWeek_Lev1.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByWeek_Lev1.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV1.ToString(); objConfig.Value1 = entity.limitHour_ByWeek_Lev1.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByWeek_Lev2.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByWeek_Lev2.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByWeek_Lev2.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYWEEK_LEV2.ToString(); objConfig.Value1 = entity.limitHour_ByWeek_Lev2.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByMonth.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByMonth.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByMonth.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH.ToString(); objConfig.Value1 = entity.limitHour_ByMonth.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByMonth_Lev1.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByMonth_Lev1.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByMonth_Lev1.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV1.ToString(); objConfig.Value1 = entity.limitHour_ByMonth_Lev1.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByMonth_Lev2.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByMonth_Lev2.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByMonth_Lev2.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYMONTH_LEV2.ToString(); objConfig.Value1 = entity.limitHour_ByMonth_Lev2.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByYear.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByYear.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByYear.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR.ToString(); objConfig.Value1 = entity.limitHour_ByYear.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByYear_Lev1.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByYear_Lev1.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByYear_Lev1.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV1.ToString(); objConfig.Value1 = entity.limitHour_ByYear_Lev1.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.limitHour_ByYear_Lev2.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitHour_ByYear_Lev2.Value.ToString()) { objConfig.Value1 = entity.limitHour_ByYear_Lev2.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITHOUR_BYYEAR_LEV2.ToString(); objConfig.Value1 = entity.limitHour_ByYear_Lev2.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (!string.IsNullOrEmpty(entity.limitColor)) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitColor) { objConfig.Value1 = entity.limitColor; repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR.ToString(); objConfig.Value1 = entity.limitColor; repoSys_AllSetting.Add(objConfig); } } if (!string.IsNullOrEmpty(entity.limitColor_Lev1)) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitColor_Lev1) { objConfig.Value1 = entity.limitColor_Lev1; repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV1.ToString(); objConfig.Value1 = entity.limitColor_Lev1; repoSys_AllSetting.Add(objConfig); } } if (!string.IsNullOrEmpty(entity.limitColor_Lev2)) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.limitColor_Lev2) { objConfig.Value1 = entity.limitColor_Lev2; repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_LIMITCOLOR_LEV2.ToString(); objConfig.Value1 = entity.limitColor_Lev2; repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowOverLimit_Normal.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowOverLimit_Normal.Value.ToString()) { objConfig.Value1 = entity.IsAllowOverLimit_Normal.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL.ToString(); objConfig.Value1 = entity.IsAllowOverLimit_Normal.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowOverLimit_Normal_Lev1.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowOverLimit_Normal_Lev1.Value.ToString()) { objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev1.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV1.ToString(); objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev1.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowOverLimit_Normal_Lev2.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowOverLimit_Normal_Lev2.Value.ToString()) { objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev2.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_NORMAL_LEV2.ToString(); objConfig.Value1 = entity.IsAllowOverLimit_Normal_Lev2.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowOverLimit_AllowOver.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowOverLimit_AllowOver.Value.ToString()) { objConfig.Value1 = entity.IsAllowOverLimit_AllowOver.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER.ToString(); objConfig.Value1 = entity.IsAllowOverLimit_AllowOver.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowOverLimit_AllowOver_Lev1.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV1.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowOverLimit_AllowOver_Lev1.Value.ToString()) { objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev1.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV1.ToString(); objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev1.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowOverLimit_AllowOver_Lev2.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV2.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowOverLimit_AllowOver_Lev2.Value.ToString()) { objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev2.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWOVERLIMIT_ALLOWOVER_LEV2.ToString(); objConfig.Value1 = entity.IsAllowOverLimit_AllowOver_Lev2.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } if (entity.IsAllowSplit.HasValue) { var objConfig = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWSPLIT.ToString()).FirstOrDefault(); if (objConfig != null) { if (objConfig.Value1 != entity.IsAllowSplit.Value.ToString()) { objConfig.Value1 = entity.IsAllowSplit.Value.ToString(); repoSys_AllSetting.Edit(objConfig); } } else { objConfig.ID = Guid.NewGuid(); objConfig.Name = AppConfig.HRM_ATT_OT_OTPERMIT_ISALLOWSPLIT.ToString(); objConfig.Value1 = entity.IsAllowSplit.Value.ToString(); repoSys_AllSetting.Add(objConfig); } } } repoSys_AllSetting.SaveChanges(); return "0"; } }
public List<Can_MealRecordEntity> GetMealRecordSummary(string _line, string _catering, string _canteen, DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> lstProfileIDs, string UserLogin) { dateStart = dateStart.Date; dateEnd = dateEnd.Date.AddDays(1).AddMilliseconds(-1); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoCan_MealRecord = new CustomBaseRepository<Can_MealRecord>(unitOfWork); var repoCan_TamScanLog = new CustomBaseRepository<Can_TamScanLogCMS>(unitOfWork); var repoCan_Line = new CustomBaseRepository<Can_Line>(unitOfWork); var repoCan_Canteen = new CustomBaseRepository<Can_Canteen>(unitOfWork); var repoCan_Catering = new CustomBaseRepository<Can_Catering>(unitOfWork); var repoSys_AllSetting = new CustomBaseRepository<Sys_AllSetting>(unitOfWork); string status = string.Empty; //string strIDs = string.Join(",", lstProfileIDs.ToArray()); #region xử lý cấu hình giờ kết thúc ăn - DateStart & DateEnd DateTime dateConfig = DateTime.MinValue; var rsTimeConfig = GetData<Sys_AllSettingEntity>(AppConfig.HRM_CAN_MEALRECORD_EATEND_CONFIG.ToString(), ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).FirstOrDefault(); if (rsTimeConfig != null && rsTimeConfig.Value1 != null) { dateConfig = DateTimeHelper.ConvertStringToDateTime(rsTimeConfig.Value1, ConstantFormat.HRM_Format_YearMonthDay_HoursMinSecond_ffffff.ToString()); } double hourConfig = dateConfig.Hour + (((double)dateConfig.Minute) / 60); dateStart = dateStart.Date.AddHours(hourConfig); dateEnd = dateEnd.Date.AddDays(1).AddHours(hourConfig).AddMilliseconds(-1); #endregion #region cấu hình số phút xử lý trùng int rsScanMulti = 0; var rsScanMultiConfig = GetData<Sys_AllSettingEntity>(AppConfig.HRM_CAN_MEALRECORD_SCANMULTI_CONFIG.ToString(), ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).FirstOrDefault(); if (rsScanMultiConfig != null) { rsScanMulti = rsScanMultiConfig.Value1 != null ? int.Parse(rsScanMultiConfig.Value1.ToString()) : 0; } #endregion var tamScanLogs = repoCan_TamScanLog .FindBy(s => dateStart <= s.TimeLog && s.TimeLog <= dateEnd) .Select(s => new { s.MachineCode, s.CardCode, s.TimeLog, s.ID }) .ToList(); var cardCodes = tamScanLogs.Select(s => s.CardCode).ToList(); //strIDs = Common.DotNetToOracle(strIDs); //var profiles = GetData<Hre_ProfileEntity>(strIDs, ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status) // .Where(s => cardCodes.Contains(s.CodeAttendance) && lstProfileIDs.Contains(s.ID)) var profiles = lstProfileIDs .Where(s => cardCodes.Contains(s.CodeAttendance)) .Select(s => new { s.ID, s.CodeAttendance, s.CodeEmp, s.ProfileName, s.OrgStructureName }).ToList(); tamScanLogs = tamScanLogs.Where(s => profiles.Select(p => p.CodeAttendance).Contains(s.CardCode)).OrderBy(s => s.CardCode).ThenBy(s=>s.TimeLog).ToList(); var lines = repoCan_Line.FindBy(s => s.IsDelete == null).ToList(); var canteens = repoCan_Canteen.FindBy(s => s.IsDelete == null).ToList(); var caterings = repoCan_Catering.FindBy(s => s.IsDelete == null).ToList(); if (_line != null) { List<Guid> lstLine = _line.Split(',').Select(Guid.Parse).ToList(); lines = lines.Where(s => lstLine.Contains(s.ID)).ToList(); } if (_canteen != null) { List<Guid> lstcanteen = _canteen.Split(',').Select(Guid.Parse).ToList(); canteens = canteens.Where(s => lstcanteen.Contains(s.ID)).ToList(); } if (_catering != null) { List<Guid> lstcatering = _catering.Split(',').Select(Guid.Parse).ToList(); caterings = caterings.Where(s => lstcatering.Contains(s.ID)).ToList(); } List<object> lstObj = new List<object>(); lstObj.Add(dateStart); lstObj.Add(dateEnd); List<Can_MealRecordCheckEntity> mealRecordCheckList = GetData<Can_MealRecordCheckEntity>(lstObj, ConstantSql.hrm_can_sp_get_MealRecord_ByDateFromDateTo, UserLogin, ref status); Can_MealRecordEntity record = new Can_MealRecordEntity(); List<Can_MealRecordEntity> lstRecord = new List<Can_MealRecordEntity>(); List<Can_MealRecord> lstEdit = new List<Can_MealRecord>(); List<Can_MealRecord> lstAdd = new List<Can_MealRecord>(); List<Guid> lstDuplicateTamScan = new List<Guid>(); foreach (var tamScanLog in tamScanLogs) { if (lstDuplicateTamScan.Contains(tamScanLog.ID)) continue; record = new Can_MealRecordEntity(); var profile = profiles.FirstOrDefault(s => s.CodeAttendance == tamScanLog.CardCode); var line = lines.FirstOrDefault(s => tamScanLog.MachineCode == s.MachineCode); if (profile != null && line != null) { #region xử lý quẹt thẻ trùng theo HRM_CAN_MEALRECORD_SCANMULTI_CONFIG var tamScanLogProfiles = tamScanLogs .Where(s => s.CardCode == tamScanLog.CardCode && s.TimeLog.Value.Date == tamScanLog.TimeLog.Value.Date && s.MachineCode == tamScanLog.MachineCode) .OrderBy(s => s.TimeLog) .ToList(); if (tamScanLogProfiles.Count > 1 && rsScanMulti > 0) { for (int i = 0; i < tamScanLogProfiles.Count; i++) { var tamsanFirst = tamScanLogProfiles[i]; int j = i + 1; if (j > tamScanLogProfiles.Count - 1) { j = i; } var tamsanNear = tamScanLogProfiles[j]; if (tamsanNear.TimeLog.Value.Subtract(tamsanFirst.TimeLog.Value).TotalMinutes < rsScanMulti && tamsanFirst.ID != tamsanNear.ID ) { if (tamsanFirst.MachineCode == tamsanNear.MachineCode) { lstDuplicateTamScan.Add(tamsanNear.ID); break; } } } } #endregion #region xử lý add record record.TimeLog = tamScanLog.TimeLog.HasValue ? tamScanLog.TimeLog.Value : DateTime.MinValue; if (record.TimeLog < record.TimeLog.Value.Date.AddHours(hourConfig)) { record.WorkDay = record.TimeLog.Value.AddDays(-1); } else { record.WorkDay = record.TimeLog; } if (tamScanLog.MachineCode != null) { record.MachineCode = tamScanLog.MachineCode; if (line != null) { record.LineName = line.LineName; record.LineID = line.ID; record.Amount = (decimal)line.Amount; if (line.CanteenID != null) { var cant = canteens.Where(c => c.ID == line.CanteenID).FirstOrDefault(); record.CanteenName = cant.CanteenName; record.CanteenID = line.CanteenID; } if (line.CateringID != null) { var cater = caterings.Where(c => c.ID == line.CateringID).FirstOrDefault(); record.CateringName = cater.CateringName; record.CateringID = line.CateringID; } } } record.ProfileName = profile.ProfileName; record.CodeEmp = profile.CodeEmp; record.OrgStructureName = profile.OrgStructureName; record.CodeAttendance = profile.CodeAttendance; record.DateCreate = DateTime.Now; var recordAdd = record.CopyData<Can_MealRecord>(); recordAdd.ProfileID = profile.ID; var CheckList = mealRecordCheckList.Where(s => s.ProfileID == profile.ID && s.TimeLog == tamScanLog.TimeLog).ToList(); if (CheckList != null) { if (CheckList.Count() > 0) { var idUpdate = CheckList.FirstOrDefault(); recordAdd.ID = idUpdate.ID; //lstEdit.Add(recordAdd); repoCan_MealRecord.Edit(recordAdd); } else { recordAdd.ID = Guid.NewGuid(); repoCan_MealRecord.Add(recordAdd); //lstAdd.Add(recordAdd); } } record.ID = tamScanLog.ID; lstRecord.Add(record); #endregion } } repoCan_MealRecord.SaveChanges(); if (lstRecord.Count > 0) { Sys_AllSetting sys = new Sys_AllSetting(); Sys_AllSetting rs = GetData<Sys_AllSetting>(AppConfig.HRM_CAN_MEALRECORD_SUMMARY.ToString(), ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).FirstOrDefault(); sys.Value1 = dateStart.ToString(ConstantFormat.HRM_Format_YearMonthDay_HoursMinSecond.ToString()); sys.Value2 = dateEnd.ToString(ConstantFormat.HRM_Format_YearMonthDay_HoursMinSecond.ToString()); sys.Name = AppConfig.HRM_CAN_MEALRECORD_SUMMARY.ToString(); if (rs != null) { sys.ID = rs.ID; repoSys_AllSetting.Edit(sys); } else { sys.ID = Guid.NewGuid(); repoSys_AllSetting.Add(sys); } repoSys_AllSetting.SaveChanges(); } //lstRecord.Where().(s => s.MealAllowanceTypeName = ConstantDisplay.HRM_Enum_Submit.TranslateString()).ToList(); return lstRecord; } }
/// <summary> /// hàm Validate những nhân viên trong giai đoạn thử việc sẽ không được phép đăng ký một số loại ngày nghỉ /// </summary> /// <param name="gradeCfg"></param> /// <param name="lstLeaveDay"></param> /// <returns></returns> public string ValidateLeaveTypeByNewEmployee(Sys_AllSetting AppConfig, List<Att_LeaveDay> lstLeaveDay) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); if (AppConfig == null || string.IsNullOrEmpty(AppConfig.Value1)) return string.Empty; Guid GuidContex = Guid.NewGuid(); char[] ex = new char[] { ',' }; List<string> leaveTypeCode = AppConfig.Value1.Split(ex, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); List<Guid> lstLeaveTypeIDs = repoCat_LeaveDayType.FindBy(m => leaveTypeCode.Contains(m.Code)).Select(m => m.ID).ToList<Guid>(); List<Att_LeaveDay> lstLeaveDayValidate = lstLeaveDay.Where(m => lstLeaveTypeIDs.Contains(m.LeaveDayTypeID)).ToList(); if (lstLeaveDayValidate.Count == 0) return string.Empty; List<Guid> lstProfileID = lstLeaveDayValidate.Select(m => m.ProfileID).Distinct().ToList<Guid>(); var lstProfile = repoHre_Profile.FindBy(m => lstProfileID.Contains(m.ID)).Select(m => new { m.ID, m.CodeEmp, m.ProfileName, m.DateEndProbation }); string ErrMess = string.Empty; foreach (var item in lstLeaveDayValidate) { var profile = lstProfile.Where(m => m.ID == item.ProfileID).FirstOrDefault(); DateTime dateStart = item.DateStart; if (profile != null && profile.DateEndProbation != null && profile.DateEndProbation.Value > dateStart.Date) { ErrMess += profile.ProfileName + "[" + profile.CodeEmp + "]; "; } } if (ErrMess != string.Empty) { ErrMess = ErrMess.Substring(0, ErrMess.Length - 2); //ErrMess = string.Format(Messages.EmpCantRegisterLeaveTypeWithProbation.TranslateString(), ErrMess); } return ErrMess; } }
public void CheckData(Guid LoginUserID, List<ImportRosterModel> listRoster, out List<ImportRosterModel> ListRosterCorrect, out List<ImportRosterModel> ListRosterError) { int pageSize = 2500; int skipRows = 0; var listShiftInfo = new List<Cat_Shift>(); var check12Hour = new Sys_AllSetting(); List<string> listProfileCode= listRoster.Select(m=>m.CodeEmp).Distinct().ToList(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); listShiftInfo = unitOfWork.CreateQueryable<Cat_Shift>().ToList(); var ValidateLess12Hour = AppConfig.HRM_ATT_VALIDATE_ROSTER_NON_CONTINUE_12HOUR.ToString(); check12Hour = unitOfWork.CreateQueryable<Sys_AllSetting>(m => m.Name == ValidateLess12Hour).FirstOrDefault(); } var isAllowEditFutureRoster = (new SecurityService()).CheckPermission(LoginUserID, VnResource.Helper.Security.PrivilegeType.View, ConstantMessages.Att_EditFutureRoster); var isAllowEditPastRoster = (new SecurityService()).CheckPermission(LoginUserID, VnResource.Helper.Security.PrivilegeType.View, ConstantMessages.Att_EditPastRoster); ListRosterCorrect = new List<ImportRosterModel>(); ListRosterError = new List<ImportRosterModel>(); while (skipRows < listProfileCode.Count()) { //Vinhtran - 20140718: Chia theo pagesize để không bị quá tải ram var listProfileSplit = listProfileCode.Skip(skipRows).Take(pageSize).ToList(); var listRosterSplit = listRoster.Where(d => listProfileSplit.Contains(d.CodeEmp)).OrderBy(d => d.DateStart).ToList(); CheckData(listRosterSplit, (check12Hour != null && check12Hour.Value1 == bool.TrueString), isAllowEditFutureRoster, isAllowEditPastRoster, listProfileSplit, listShiftInfo, ref ListRosterCorrect, ref ListRosterError); skipRows += pageSize; } }
private int ComputeAttendance(IUnitOfWork unitOfWork, Guid userID, DateTime monthYear, Guid cutOffDurationID, DateTime attendanceFrom, DateTime attendanceTo, Hre_ProfileEntity profile, Cat_GradeAttendance gradeCfg, List<Cat_Shift> listShift, List<Att_AnnualDetail> listAnnualDetailByProfile, List<Hre_HDTJob> listHDTJobByProfile, List<Att_LeaveDayEntity> listLeaveDayByProfile, List<Cat_LeaveDayType> listLeaveDayType, List<Att_OvertimeEntity> listOvertimeByProfile, List<Cat_OvertimeType> listOvertimeType, List<Att_PregnancyEntity> listPregnancyByProfile, List<Cat_LateEarlyRule> listLateEarlyRule, List<Att_Workday> listWorkDayByProfile, List<Att_AttendanceTableEntity> listPreAttendanceTableByProfile, List<Att_TimeOffInLieuEntity> listTimeOffInLieuByProfile, Sys_AllSetting notAutoRegHolidayLeave, Sys_AllSetting otholidayscompute400, Sys_AllSetting missTAM_LeaveType, Dictionary<DateTime, List<Guid?>> listMonthShiftID, List<Cat_DayOff> listHoliday) { Guid profileID = profile.ID; if (gradeCfg == null || profile == null) { return 0; } DateTime midCutOffDate = attendanceTo; bool isMidCutOffDay = false; #region Tạo Att_AttendanceTable theo khoảng thời gian Att_AttendanceTable attendanceTable = new Att_AttendanceTable(); unitOfWork.AddObject(typeof(Att_AttendanceTable), attendanceTable); attendanceTable.Status = AttendanceTableStatus.E_WAITING.ToString(); attendanceTable.ID = Guid.NewGuid(); attendanceTable.ProfileID = profileID; attendanceTable.MonthYear = monthYear; attendanceTable.DateStart = attendanceFrom; attendanceTable.DateEnd = attendanceTo; double anlDayTaken = 0D; double sickDayTaken = 0D; double coBeginPeriod = 0D; double coEndPeriod = 0D; if (cutOffDurationID != Guid.Empty) { attendanceTable.CutOffDurationID = cutOffDurationID; } //Tính công đến ngày cấu hình trong grade, những ngày sau mặc định full công - Khách hàng CPG if (gradeCfg != null && gradeCfg.IsMonthlyMidCutOff == true && gradeCfg.MidCutOffDay > 0) { if (!profile.DateQuit.HasValue || profile.DateQuit > attendanceTo) { midCutOffDate = new DateTime(monthYear.Year, monthYear.Month, gradeCfg.MidCutOffDay.Value); //Luôn tạo một dòng Ứng công lúc tính công, kô cần biết có nghỉ không Att_AdvanceTableItem advanceTableItem = new Att_AdvanceTableItem(); advanceTableItem.Att_AttendanceTable = attendanceTable; advanceTableItem.DateFrom = midCutOffDate.AddDays(1); advanceTableItem.DateTo = attendanceTo; isMidCutOffDay = true; } } #endregion #region Tạo Att_AttendanceTableItem theo khoảng thời gian List<Att_AttendanceTableItem> listAttendanceTableItemByProfile = new List<Att_AttendanceTableItem>(); for (DateTime date = attendanceFrom.Date; date <= attendanceTo; date = date.AddDays(1)) { var workdayByProfile = listWorkDayByProfile.Where(d => d.WorkDate.Date == date).FirstOrDefault(); Guid? shiftID1 = Guid.Empty; Guid? shiftID2 = Guid.Empty; var shiftByDate = listMonthShiftID.Where(d => d.Key.Date == date).Select(d => d.Value).FirstOrDefault(); if (shiftByDate != null) { if (shiftByDate.Count() > 0) { shiftID1 = shiftByDate[0]; } if (shiftByDate.Count() > 1) { shiftID2 = shiftByDate[1]; } } if (workdayByProfile == null && gradeCfg.EDType == PayrollComputeMethod.E_SUBTRACT.ToString()) { if (shiftID1.HasValue && shiftID1 != Guid.Empty) { workdayByProfile = new Att_Workday { ShiftID = shiftID1, ShiftApprove = shiftID1, ShiftActual = shiftID1, WorkDate = date }; if (shiftID2.HasValue && shiftID2 != Guid.Empty) { workdayByProfile.Shift2ID = shiftID2; workdayByProfile.ShiftApprove2 = shiftID2; workdayByProfile.ShiftActual2 = shiftID2; } if (listHoliday.Any(d => d.DateOff.Date == date)) { workdayByProfile.Type = WorkdayType.E_HOLIDAY.ToString(); } } } Att_AttendanceTableItem attendanceTableItem = new Att_AttendanceTableItem(); listAttendanceTableItemByProfile.Add(attendanceTableItem); attendanceTableItem.ID = Guid.NewGuid(); attendanceTableItem.Att_AttendanceTable = attendanceTable; attendanceTableItem.DutyCode = DutyCode.E_OFF.ToString(); attendanceTableItem.WorkDate = date; double nightDuration = 0F; double workDuration = 0F; attendanceTableItem.WorkPaidHours = 0; attendanceTableItem.PaidLeaveHours = 0; attendanceTableItem.UnpaidLeaveHours = 0; attendanceTableItem.LateEarlyMinutes = 0; attendanceTableItem.LateInMinutes = 0; attendanceTableItem.EarlyOutMinutes = 0; attendanceTableItem.LeaveHours = 0; attendanceTableItem.LeaveDays = 0; attendanceTableItem.WorkHourFirstHaftShift = 0; attendanceTableItem.WorkHourLastHaftShift = 0; if (workdayByProfile != null) { attendanceTableItem.MissInOutReasonID = workdayByProfile.MissInOutReason; attendanceTableItem.FirstInTime = workdayByProfile.FirstInTime; attendanceTableItem.LastOutTime = workdayByProfile.LastOutTime; attendanceTableItem.RootInTime = workdayByProfile.FirstInTime; attendanceTableItem.RootOutTime = workdayByProfile.LastOutTime; attendanceTableItem.ShiftID = workdayByProfile.ShiftID; attendanceTableItem.Shift2ID = workdayByProfile.Shift2ID; List<DateTime?> listInTime = new List<DateTime?>(); List<DateTime?> listOutTime = new List<DateTime?>(); listInTime.Add(workdayByProfile.InTime1); listInTime.Add(workdayByProfile.InTime2); listInTime.Add(workdayByProfile.InTime3); listInTime.Add(workdayByProfile.InTime4); listOutTime.Add(workdayByProfile.OutTime1); listOutTime.Add(workdayByProfile.OutTime2); listOutTime.Add(workdayByProfile.OutTime3); listOutTime.Add(workdayByProfile.OutTime4); attendanceTableItem.FirstInTime = listInTime.Where(d => d.HasValue).OrderBy(d => d).FirstOrDefault(); attendanceTableItem.LastOutTime = listOutTime.Where(d => d.HasValue).OrderBy(d => d).LastOrDefault(); if (workdayByProfile.ShiftApprove.HasValue) { attendanceTableItem.ShiftID = workdayByProfile.ShiftApprove.Value; } if (workdayByProfile.ShiftApprove2.HasValue) { attendanceTableItem.Shift2ID = workdayByProfile.ShiftApprove2.Value; } if (gradeCfg.AttendanceMethod == AttendanceMethod.E_FULL.ToString()) { if (listMonthShiftID.Any(d => d.Key.Date == date)) { //Bao.Tran: khi không kiểm tra vào ra thì ưu tiên ca đã tạo trong lịch làm việc if (shiftID1 != Guid.Empty) { attendanceTableItem.ShiftID = shiftID1; } if (shiftID2 != Guid.Empty) { attendanceTableItem.Shift2ID = shiftID2; } } //Bao.Tran: yêu cầu nếu công ko kiểm tra in/out thì không lấy in/out attendanceTableItem.FirstInTime = null; attendanceTableItem.LastOutTime = null; //comment code này do ảnh hưởng task 0046036 : ko tính được ngày nghỉ lễ ////Bao.Tran: do khi THNC cũ, Nếu ko bỏ type thì nó sẽ tính ngày công trên là holiday (attendanceTableItem.IsHoliday = true;) //workdayByProfile.Type = WorkdayType.E_NORMAL.ToString(); } //kiểm tra ngày làm việc có Lịch làm việc hay ko? if (attendanceTableItem.ShiftID != null && workdayByProfile.FirstInTime != null && workdayByProfile.LastOutTime != null) { #region Kiểm tra HDTJob var listHDTJobByProfileByDate = listHDTJobByProfile.Where(d => (d.DateFrom.Value.Date <= date && d.DateTo == null) || (d.DateTo != null && d.DateFrom.Value.Date <= date && d.DateTo.Value.Date >= date)).ToList(); foreach (var HDTJobByProfile in listHDTJobByProfileByDate) { if (HDTJobByProfile != null) { attendanceTableItem.HDTJobType = HDTJobByProfile.Type; } } #endregion } } var shiftByProfile1 = listShift.Where(d => d.ID == attendanceTableItem.ShiftID).FirstOrDefault(); var shiftByProfile2 = listShift.Where(d => d.ID == attendanceTableItem.Shift2ID).FirstOrDefault(); if (shiftByProfile1 != null) { attendanceTableItem.Cat_Shift = shiftByProfile1; attendanceTableItem.AvailableHours = shiftByProfile1.udAvailableHours; } if (shiftByProfile2 != null) { attendanceTableItem.Cat_Shift1 = shiftByProfile2; } if ((workdayByProfile != null && workdayByProfile.Type == WorkdayType.E_HOLIDAY.ToString()) || (attendanceTableItem.ShiftID.HasValue && attendanceTableItem.ShiftID != Guid.Empty)) { //Ngày đang xét là ngày làm việc bình thường attendanceTableItem.DutyCode = DutyCode.E_ON.ToString(); if (workdayByProfile.Type == WorkdayType.E_HOLIDAY.ToString()) { attendanceTableItem.IsHoliday = true; } } else { //Ngày đang xét không phải là ngày làm việc bình thường attendanceTableItem.DutyCode = DutyCode.E_OFF.ToString(); } #region Kiểm tra ngày nghỉ - leaveday if (attendanceTableItem.DutyCode != DutyCode.E_OFF.ToString()) { var listLeaveDayByProfileByDate = listLeaveDayByProfile.Where(d => d.DateStart.Date <= date && d.DateEnd.Date >= date).ToList(); foreach (var leaveDayByProfile in listLeaveDayByProfileByDate) { if (leaveDayByProfile != null) { double leaveHours = 0D; double leaveDays = 0D; var leaveDayType = listLeaveDayType.Where(d => d.ID == leaveDayByProfile.LeaveDayTypeID).FirstOrDefault(); var standardWorkHours = attendanceTableItem.AvailableHours; if (leaveDayByProfile.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString()) { //Lấy giờ nghỉ của ngày đang xét dựa vào ca làm việc leaveHours = standardWorkHours; leaveDays = 1;//Nghỉ full shift } else { leaveHours = leaveDayByProfile.LeaveHours.GetDouble(); leaveDays = leaveDayByProfile.LeaveDays.GetDouble(); } leaveHours = leaveHours > standardWorkHours ? standardWorkHours : leaveHours; leaveDays = leaveDays > 1 ? 1 : leaveDays;//Tối đa là nghỉ 1 ngày if (!attendanceTableItem.LeaveTypeID.HasValue) { attendanceTableItem.LeaveTypeID = leaveDayByProfile.LeaveDayTypeID; attendanceTableItem.Cat_LeaveDayType = leaveDayType; attendanceTableItem.LeaveHours = leaveHours; attendanceTableItem.LeaveDays = leaveDays; } else if (!attendanceTableItem.ExtraLeaveTypeID.HasValue) { attendanceTableItem.ExtraLeaveTypeID = leaveDayByProfile.LeaveDayTypeID; attendanceTableItem.Cat_LeaveDayType1 = leaveDayType; attendanceTableItem.ExtraLeaveHours = leaveHours; attendanceTableItem.ExtraLeaveDays = leaveDays; } if (leaveDayType != null && leaveDays > 0) { if (leaveDayType.Code == LeavedayTypeCode.ANL.ToString()) { anlDayTaken += leaveDays; } if (leaveDayType.Code == LeavedayTypeCode.SICK.ToString()) { sickDayTaken += leaveDays; } } } } } #endregion #region Kiểm tra làm thêm - overtime if (gradeCfg != null && gradeCfg.IsReceiveOvertimeBonus.Get_Boolean()) { var listOvertimeByProfileByDate = listOvertimeByProfile.Where(d => d.WorkDate.Date == date).ToList(); foreach (var overtime in listOvertimeByProfileByDate) { if (overtime != null) { double overtimeHours = overtime.ConfirmHours; string overTimeStatus = OverTimeStatus.E_APPROVED.ToString(); if (overTimeStatus == OverTimeStatus.E_APPROVED.ToString()) { overtimeHours = overtime.ApproveHours.GetDouble(); } else if (overTimeStatus == OverTimeStatus.E_CONFIRM.ToString()) { overtimeHours = overtime.ConfirmHours; } if (!attendanceTableItem.OvertimeTypeID.HasValue) { attendanceTableItem.OvertimeTypeID = overtime.OvertimeTypeID; attendanceTableItem.Cat_OvertimeType = listOvertimeType.Where(s => s.ID == overtime.OvertimeTypeID).FirstOrDefault(); attendanceTableItem.OvertimeDurationType = overtime.DurationType; attendanceTableItem.OvertimeRegisterHours = overtime.RegisterHours; attendanceTableItem.OvertimeHours = overtimeHours; } else if (!attendanceTableItem.ExtraOvertimeTypeID.HasValue) { attendanceTableItem.ExtraOvertimeTypeID = overtime.OvertimeTypeID; attendanceTableItem.Cat_OvertimeType1 = listOvertimeType.Where(s => s.ID == overtime.OvertimeTypeID).FirstOrDefault(); attendanceTableItem.ExtraOvertimeDurationType = overtime.DurationType; attendanceTableItem.ExtraOvertimeRegisterHours = overtime.RegisterHours; attendanceTableItem.ExtraOvertimeHours = overtimeHours; } else if (!attendanceTableItem.ExtraOvertimeType2ID.HasValue) { attendanceTableItem.ExtraOvertimeType2ID = overtime.OvertimeTypeID; attendanceTableItem.Cat_OvertimeType2 = listOvertimeType.Where(s => s.ID == overtime.OvertimeTypeID).FirstOrDefault(); attendanceTableItem.ExtraOvertimeDurationType2 = overtime.DurationType; attendanceTableItem.ExtraOvertimeRegisterHours2 = overtime.RegisterHours; attendanceTableItem.ExtraOvertimeHours2 = overtimeHours; } else if (!attendanceTableItem.ExtraOvertimeType3ID.HasValue) { attendanceTableItem.ExtraOvertimeType3ID = overtime.OvertimeTypeID; attendanceTableItem.Cat_OvertimeType3 = listOvertimeType.Where(s => s.ID == overtime.OvertimeTypeID).FirstOrDefault(); attendanceTableItem.ExtraOvertimeDurationType3 = overtime.DurationType; attendanceTableItem.ExtraOvertimeRegisterHours3 = overtime.RegisterHours; attendanceTableItem.ExtraOvertimeHours3 = overtimeHours; } } } } #endregion #region Kiểm tra có thai sản không var pregnancyByProfile = listPregnancyByProfile.Where(d => date >= d.DateStart && date <= d.DateEnd).FirstOrDefault(); if (pregnancyByProfile != null) { attendanceTableItem.IsHavingPregTreatment = true; } #endregion #region Nhân viên đã nghỉ hoặc chưa đi làm if ((profile.DateQuit.HasValue && profile.DateQuit.Value.Date <= date.Date) || (profile.DateHire.HasValue && profile.DateHire.Value.Date > date.Date)) { if (attendanceTableItem.DutyCode == DutyCode.E_ON.ToString()) { if (profile.DateHire.HasValue && profile.DateHire.Value.Date > date.Date) { if (shiftByProfile1 != null) { attendanceTableItem.udNotHiredHours = shiftByProfile1.WorkHours.GetDouble(); } else { attendanceTableItem.udNotHiredHours = attendanceTableItem.udStandardWorkHours; } if (shiftByProfile2 != null) { attendanceTableItem.udNotHiredHours += shiftByProfile2.WorkHours.GetDouble(); } } if (profile.DateQuit.HasValue && profile.DateQuit.Value.Date <= date.Date) { if (shiftByProfile1 != null) { attendanceTableItem.udTerminatedHours = shiftByProfile1.WorkHours.GetDouble(); } else { attendanceTableItem.udTerminatedHours = attendanceTableItem.udStandardWorkHours; } if (shiftByProfile2 != null) { attendanceTableItem.udTerminatedHours += shiftByProfile2.WorkHours.GetDouble(); } } } attendanceTableItem.Cat_LeaveDayType = null; continue; } #endregion #region Loại ngày nghỉ là ngày làm việc if (attendanceTableItem.Cat_LeaveDayType != null) { //Trường hợp ngày nghỉ tính như ngày đi làm => không tính nghỉ if (attendanceTableItem.Cat_LeaveDayType.IsWorkDay) { attendanceTableItem.WorkHours += attendanceTableItem.LeaveHours; attendanceTableItem.WorkPaidHours += attendanceTableItem.LeaveHours; attendanceTableItem.LeaveWorkDayHour = attendanceTableItem.LeaveHours; attendanceTableItem.LeaveWorkDayDays = attendanceTableItem.LeaveHours / attendanceTableItem.udStandardWorkHours; attendanceTableItem.Cat_LeaveDayType2 = attendanceTableItem.Cat_LeaveDayType; attendanceTableItem.Cat_LeaveDayType = null; attendanceTableItem.LeaveHours = 0; attendanceTableItem.LeaveDays = 0; } else { attendanceTableItem.PaidLeaveHours += attendanceTableItem.LeaveHours * attendanceTableItem.Cat_LeaveDayType.PaidRate; attendanceTableItem.UnpaidLeaveHours += attendanceTableItem.LeaveHours * (1 - attendanceTableItem.Cat_LeaveDayType.PaidRate); attendanceTableItem.PaidLeaveDays = attendanceTableItem.PaidLeaveHours / attendanceTableItem.udStandardWorkHours; attendanceTableItem.UnpaidLeaveDays = attendanceTableItem.UnpaidLeaveHours / attendanceTableItem.udStandardWorkHours; } } if (attendanceTableItem.Cat_LeaveDayType1 != null) { if (attendanceTableItem.Cat_LeaveDayType1.IsWorkDay) { attendanceTableItem.WorkHours += attendanceTableItem.ExtraLeaveHours; attendanceTableItem.WorkPaidHours += attendanceTableItem.ExtraLeaveHours; attendanceTableItem.Cat_LeaveDayType1 = null; attendanceTableItem.ExtraLeaveHours = 0; } else { attendanceTableItem.PaidLeaveHours += attendanceTableItem.ExtraLeaveHours * attendanceTableItem.Cat_LeaveDayType1.PaidRate; attendanceTableItem.UnpaidLeaveHours += attendanceTableItem.ExtraLeaveHours * (1 - attendanceTableItem.Cat_LeaveDayType1.PaidRate); } } #endregion if (attendanceTableItem.DutyCode == DutyCode.E_ON.ToString()) { #region IsHavingPregTreatment if (attendanceTableItem.IsHavingPregTreatment) { if ((attendanceTableItem.WorkPaidHours + attendanceTableItem.PaidLeaveHours) > attendanceTableItem.AvailableHours) { attendanceTableItem.WorkPaidHours = attendanceTableItem.AvailableHours - attendanceTableItem.PaidLeaveHours; } else { attendanceTableItem.WorkPaidHours = attendanceTableItem.WorkPaidHours; } } #endregion #region LateEarlyMinutes attendanceTableItem.LateEarlyMinutes = (int)workdayByProfile.LateEarlyDuration.GetDouble(); attendanceTableItem.RealLateEarlyMinutes = attendanceTableItem.LateEarlyMinutes; #endregion #region Tính số giờ đi làm if (workdayByProfile != null && shiftByProfile1 != null) { DateTime timeShiftStart1 = workdayByProfile.WorkDate.Date.Add(shiftByProfile1.InTime.TimeOfDay); DateTime timeShiftEnd1 = timeShiftStart1.AddHours(shiftByProfile1.CoOut); //Thời gian bắt đầu và kết thúc nghỉ giữa ca - dùng cho tính toán DateTime timeShiftBreakIn1 = timeShiftStart1.AddHours(shiftByProfile1.CoBreakIn); DateTime timeShiftBreakOut1 = timeShiftStart1.AddHours(shiftByProfile1.CoBreakOut); workDuration = GetDuration(workdayByProfile, timeShiftStart1, timeShiftEnd1, timeShiftBreakIn1, timeShiftBreakOut1, shiftByProfile1.InOutDynamic); #region Tính số giờ làm ca đêm if (shiftByProfile1.IsNightShift) { DateTime nightTimeStart = workdayByProfile.WorkDate.Date.AddHours(22); DateTime nightTimeEnd = workdayByProfile.WorkDate.Date.AddDays(1).AddHours(6); nightTimeStart = workdayByProfile.WorkDate.Date.Add(shiftByProfile1.NightTimeStart.Value.TimeOfDay); nightTimeEnd = workdayByProfile.WorkDate.Date.Add(shiftByProfile1.NightTimeEnd.Value.TimeOfDay); nightTimeEnd = nightTimeStart > nightTimeEnd ? nightTimeEnd.AddDays(1) : nightTimeEnd; //Truong hop nghi giua ca nam trong khoang bat dau ca dem nightDuration = GetDuration(workdayByProfile, nightTimeStart, nightTimeEnd, timeShiftBreakIn1, timeShiftBreakOut1, shiftByProfile1.InOutDynamic); } #endregion } if (workdayByProfile != null && shiftByProfile2 != null) { DateTime timeShiftStart2 = workdayByProfile.WorkDate.Date.Add(shiftByProfile2.InTime.TimeOfDay); DateTime timeShiftEnd2 = timeShiftStart2.AddHours(shiftByProfile2.CoOut); //Thời gian bắt đầu và kết thúc nghỉ giữa ca - dùng cho tính toán DateTime timeShiftBreakIn2 = timeShiftStart2.AddHours(shiftByProfile2.CoBreakIn); DateTime timeShiftBreakOut2 = timeShiftStart2.AddHours(shiftByProfile2.CoBreakOut); workDuration += GetDuration(workdayByProfile, timeShiftStart2, timeShiftEnd2, timeShiftBreakIn2, timeShiftBreakOut2, shiftByProfile2.InOutDynamic); #region Tính số giờ làm ca đêm if (shiftByProfile2.IsNightShift) { DateTime nightTimeStart = workdayByProfile.WorkDate.Date.AddHours(22); DateTime nightTimeEnd = workdayByProfile.WorkDate.Date.AddDays(1).AddHours(6); nightTimeStart = workdayByProfile.WorkDate.Date.Add(shiftByProfile2.NightTimeStart.Value.TimeOfDay); nightTimeEnd = workdayByProfile.WorkDate.Date.Add(shiftByProfile2.NightTimeEnd.Value.TimeOfDay); nightTimeEnd = nightTimeStart > nightTimeEnd ? nightTimeEnd.AddDays(1) : nightTimeEnd; //Truong hop nghi giua ca nam trong khoang bat dau ca dem nightDuration = GetDuration(workdayByProfile, nightTimeStart, nightTimeEnd, timeShiftBreakIn2, timeShiftBreakOut2, shiftByProfile2.InOutDynamic); } #endregion } attendanceTableItem.NightShiftHours = (nightDuration / 60);//lưu số giờ attendanceTableItem.WorkPaidHours = (workDuration / 60);//lưu số giờ attendanceTableItem.WorkHours = (workDuration / 60);//lưu số giờ attendanceTableItem.WorkPaidHours = attendanceTableItem.WorkPaidHours < 0 ? 0 : attendanceTableItem.WorkPaidHours; attendanceTableItem.WorkPaidHours = attendanceTableItem.WorkPaidHours > attendanceTableItem.AvailableHours ? attendanceTableItem.AvailableHours : attendanceTableItem.WorkPaidHours; #endregion if (gradeCfg.AttendanceMethod == AttendanceMethod.E_FULL.ToString()) { #region gradeCfg.AttendanceMethod = E_FULL if (shiftByProfile1 != null && shiftByProfile1.IsNightShift == true) { if (shiftByProfile1.NightTimeEnd != null && shiftByProfile1.NightTimeStart != null) { DateTime dateStartNightShift = shiftByProfile1.NightTimeStart.Value; DateTime dateEndNightShift = shiftByProfile1.NightTimeEnd.Value; if (dateStartNightShift > dateEndNightShift) { dateEndNightShift = dateEndNightShift.AddDays(1); } attendanceTableItem.NightShiftHours = dateEndNightShift.Subtract(dateStartNightShift).TotalHours; } else { attendanceTableItem.NightShiftHours = shiftByProfile1.WorkHours ?? 0; } } else if (shiftByProfile2 != null && shiftByProfile2.IsNightShift == true) { if (shiftByProfile2.NightTimeEnd != null && shiftByProfile2.NightTimeStart != null) { DateTime dateStartNightShift = shiftByProfile2.NightTimeStart.Value; DateTime dateEndNightShift = shiftByProfile2.NightTimeEnd.Value; if (dateStartNightShift > dateEndNightShift) { dateEndNightShift = dateEndNightShift.AddDays(1); } attendanceTableItem.NightShiftHours = dateEndNightShift.Subtract(dateStartNightShift).TotalHours; } else { attendanceTableItem.NightShiftHours = shiftByProfile2.WorkHours ?? 0; } } if ((shiftByProfile1 != null && shiftByProfile1.IsNightShift == true) || shiftByProfile2 != null && shiftByProfile2.IsNightShift == true) { if (attendanceTableItem.Cat_LeaveDayType != null) { double hourLeave = attendanceTableItem.LeaveHours + attendanceTableItem.PaidLeaveHours + attendanceTableItem.ExtraLeaveHours; attendanceTableItem.NightShiftHours = attendanceTableItem.NightShiftHours - hourLeave; if (attendanceTableItem.NightShiftHours < 0) { attendanceTableItem.NightShiftHours = 0; } } } if (attendanceTableItem.IsHoliday) { attendanceTableItem.LeaveHours = attendanceTableItem.PaidLeaveHours = 0; attendanceTableItem.WorkPaidHours = attendanceTableItem.LateEarlyMinutes = 0; attendanceTableItem.UnpaidLeaveHours = attendanceTableItem.AvailableHours; bool isNoLongerWorking = false; if ((profile.DateHire.HasValue && attendanceTableItem.WorkDate < profile.DateHire.Value) || (profile.DateQuit.HasValue && attendanceTableItem.WorkDate >= profile.DateQuit.Value)) { isNoLongerWorking = true; } if (!attendanceTableItem.IsHavingPregTreatment && !isNoLongerWorking && (notAutoRegHolidayLeave == null || notAutoRegHolidayLeave.Value1 != bool.TrueString)) { attendanceTableItem.WorkPaidHours = 0; attendanceTableItem.LateEarlyMinutes = 0; attendanceTableItem.UnpaidLeaveHours = 0; attendanceTableItem.LeaveHours = attendanceTableItem.AvailableHours; attendanceTableItem.PaidLeaveHours = attendanceTableItem.AvailableHours; attendanceTableItem.Cat_LeaveDayType = listLeaveDayType.Where(d => d.Code == LeavedayTypeCode.HLD.ToString()).FirstOrDefault(); } } attendanceTableItem.WorkHours = 0;//Thời gian làm việc = 0 attendanceTableItem.WorkPaidHours = attendanceTableItem.AvailableHours - attendanceTableItem.UnpaidLeaveHours - attendanceTableItem.PaidLeaveHours; #endregion } #region Trường hợp tăng ca trong ngày lễ if (attendanceTableItem.Cat_LeaveDayType != null && attendanceTableItem.Cat_LeaveDayType.Code == LeavedayTypeCode.HLD.ToString() && (otholidayscompute400 == null || otholidayscompute400.Value1 != bool.TrueString) && attendanceTableItem.Cat_OvertimeType != null) { var totalOvertimeHours = attendanceTableItem.OvertimeHours + attendanceTableItem.ExtraOvertimeHours + attendanceTableItem.ExtraOvertimeHours2 + attendanceTableItem.ExtraOvertimeHours3; if (gradeCfg.EDType == PayrollComputeMethod.E_SUBTRACT.ToString()) { if (attendanceTableItem.AvailableHours > totalOvertimeHours) { attendanceTableItem.LeaveHours = attendanceTableItem.AvailableHours - totalOvertimeHours; attendanceTableItem.ExtraLeaveHours = totalOvertimeHours; attendanceTableItem.PaidLeaveHours = attendanceTableItem.LeaveHours; attendanceTableItem.Cat_LeaveDayType1 = null; } else { attendanceTableItem.Cat_LeaveDayType = null; attendanceTableItem.LeaveHours = attendanceTableItem.AvailableHours; attendanceTableItem.PaidLeaveHours = 0; } } else { if (attendanceTableItem.AvailableHours >= totalOvertimeHours) { attendanceTableItem.LeaveHours = attendanceTableItem.PaidLeaveHours = attendanceTableItem.AvailableHours - totalOvertimeHours; } else { attendanceTableItem.LeaveHours = attendanceTableItem.PaidLeaveHours = 0; } } attendanceTableItem.WorkPaidHours = 0; } #endregion } unitOfWork.AddObject(typeof(Att_AttendanceTableItem), attendanceTableItem); } #endregion #region Tính toán lại phép năm và phép ốm trong kỳ var annualLeaveDetail = listAnnualDetailByProfile.Where(d => d.Type == AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString()).FirstOrDefault(); var sickLeaveDetail = listAnnualDetailByProfile.Where(d => d.Type == AnnualLeaveDetailType.E_SICK_LEAVE.ToString()).FirstOrDefault(); var preAttendanceTable = listPreAttendanceTableByProfile.Where(d => d.ProfileID == profileID).FirstOrDefault(); attendanceTable.AnlDayTaken = anlDayTaken; attendanceTable.SickDayTaken = sickDayTaken; if (preAttendanceTable != null) { if (annualLeaveDetail != null && annualLeaveDetail.MonthYear.HasValue && annualLeaveDetail.MonthYear.Value.Date == monthYear.Date) { attendanceTable.AnlDayAdjacent = anlDayTaken; } else { //VinhTran - 0030581 - AnlDayAdjacent là số ngày đã nghỉ tính tới đầu tháng đang tính công attendanceTable.AnlDayAdjacent = preAttendanceTable.AnlDayAdjacent.GetDouble() + anlDayTaken; } if (sickLeaveDetail != null && sickLeaveDetail.MonthYear.HasValue && sickLeaveDetail.MonthYear.Value.Date == monthYear.Date) { attendanceTable.SickDayAdjacent = sickDayTaken; } else { //VinhTran - 0030581 - AnlDayAdjacent là số ngày đã nghỉ tính tới đầu tháng đang tính công attendanceTable.SickDayAdjacent = preAttendanceTable.SickDayAdjacent.GetDouble() + sickDayTaken; } } else { attendanceTable.AnlDayAdjacent = anlDayTaken; attendanceTable.SickDayAdjacent = sickDayTaken; } if (annualLeaveDetail != null && annualLeaveDetail.MonthYear.HasValue) { attendanceTable.TotalAnlDayAvailable = annualLeaveDetail.Available.Get_Double(); attendanceTable.AnlDayAvailable = attendanceTable.TotalAnlDayAvailable.GetDouble() - attendanceTable.AnlDayAdjacent.GetDouble(); } else if (preAttendanceTable != null) { attendanceTable.AnlDayAvailable = preAttendanceTable.AnlDayAvailable - attendanceTable.AnlDayTaken; } if (sickLeaveDetail != null && sickLeaveDetail.MonthYear.HasValue) { attendanceTable.TotalSickDayAvailable = sickLeaveDetail.Available.Get_Double(); attendanceTable.SickDayAvailable = attendanceTable.TotalSickDayAvailable.GetDouble() - attendanceTable.SickDayAdjacent.GetDouble(); } else if (preAttendanceTable != null) { //tháng 7: còn 13, liền kề 1, hiện tại 1 => tháng 8: liền kề 2, hiện tại 1, còn 12 attendanceTable.SickDayAvailable = preAttendanceTable.SickDayAvailable.GetDouble() - attendanceTable.SickDayTaken.GetDouble(); } #endregion #region Tính toán lại phép bù trong kỳ foreach (var leaveDayByProfile in listLeaveDayByProfile) { if (leaveDayByProfile != null) { var dateStart = leaveDayByProfile.DateStart; var dateEnd = leaveDayByProfile.DateEnd; if (leaveDayByProfile.DateOvertimeOff.HasValue) { dateStart = leaveDayByProfile.DateOvertimeOff.Value; dateEnd = leaveDayByProfile.DateOvertimeOff.Value; } for (DateTime date = dateStart.Date; date <= dateEnd; date = date.AddDays(1)) { double leaveHours = 0D; double leaveDays = 0D; double standardWorkHours = 0; var leaveDayType = listLeaveDayType.Where(d => d.ID == leaveDayByProfile.LeaveDayTypeID).FirstOrDefault(); var attendanceTableItem = attendanceTable.Att_AttendanceTableItem.Where(d => d.WorkDate == date).FirstOrDefault(); if (attendanceTableItem!=null) standardWorkHours = attendanceTableItem.udStandardWorkHours; if (leaveDayByProfile.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString()) { //Lấy giờ nghỉ của ngày đang xét dựa vào ca làm việc leaveHours = standardWorkHours; leaveDays = 1;//Nghỉ full shift } else { leaveHours = leaveDayByProfile.LeaveHours.GetDouble(); leaveDays = leaveDayByProfile.LeaveDays.GetDouble(); } leaveHours = leaveHours > standardWorkHours ? standardWorkHours : leaveHours; leaveDays = leaveDays > 1 ? 1 : leaveDays;//Tối đa là nghỉ 1 ngày if (leaveDayType != null && leaveDays > 0) { if (leaveDayType.Code == LeavedayTypeCode.CPS.ToString() || leaveDayType.Code == LeavedayTypeCode.OCPS.ToString()) { if ((leaveDayByProfile.DateOvertimeOff.HasValue && leaveDayByProfile.DateStart > attendanceTo) || date > attendanceTo) { //Nghỉ CO tháng sau => coEndPeriod coEndPeriod += leaveDays; } else if (date >= attendanceFrom && date <= attendanceTo) { //Nghỉ CO trong tháng => coBeginPeriod coBeginPeriod += leaveDays; } } } } } } attendanceTable.COBeginPeriod = coBeginPeriod; attendanceTable.COEndPeriod = coEndPeriod; #endregion #region Cập nhật Att_AttendanceTable sau khi tính xong #region Sum type HDTJob var _type4 = attendanceTable.Att_AttendanceTableItem.Where(d => d.HDTJobType == EnumDropDown.HDTJobType.E_TYPE4.ToString()); var _type5 = attendanceTable.Att_AttendanceTableItem.Where(d => d.HDTJobType == EnumDropDown.HDTJobType.E_TYPE5.ToString()); attendanceTable.HDTJobType1 = EnumDropDown.HDTJobType.E_TYPE4.ToString(); attendanceTable.HDTJobType2 = EnumDropDown.HDTJobType.E_TYPE5.ToString(); attendanceTable.HDTJobDayCount1 = _type4 != null ? _type4.Count() : 0; attendanceTable.HDTJobDayCount2 = _type5 != null ? _type5.Count() : 0; #endregion attendanceTable.RealWorkDayCount = attendanceTable.Att_AttendanceTableItem.Where(d => d.udWorkHours > 0).Sum(d => (d.WorkPaidHours + d.LateEarlyMinutes / 60.0) / (d.udStandardWorkHours * d.udStandardWorkHours / d.udWorkHours)); attendanceTable.NightShiftHours = attendanceTable.Att_AttendanceTableItem.Where(d => d.DutyCode == DutyCode.E_ON.ToString()).Sum(d => d.NightShiftHours); attendanceTable.OTNightShiftHours = attendanceTable.Att_AttendanceTableItem.Where(d => d.DutyCode == DutyCode.E_ON.ToString()).Sum(d => d.OTNightShiftHours.GetDouble()); attendanceTable.LateEarlyDeductionHours += attendanceTable.Att_AttendanceTableItem.Sum(d => d.LateEarlyMinutes) / 60.0; attendanceTable.UnPaidLeave = attendanceTable.Att_AttendanceTableItem.Sum(d => d.UnpaidLeaveDays.GetDouble()); attendanceTable.PaidLeaveDays = attendanceTable.Att_AttendanceTableItem.Sum(d => d.PaidLeaveDays.GetDouble()); //Tính nghỉ bù attendanceTable.COBeginPeriod = coBeginPeriod; attendanceTable.COEndPeriod = coEndPeriod; //Tính số ngày công chuẩn int weekendDaysCount = attendanceTable.Att_AttendanceTableItem.Where(d => d.IsHoliday).Count(); attendanceTable.StdWorkDayCount = GetStandardWorkDays(gradeCfg, listHoliday, listShift, listMonthShiftID, monthYear, attendanceFrom, attendanceTo); attendanceTable.StdWorkDayOTCount = GetOTStandardWorkDays(weekendDaysCount, gradeCfg, listHoliday, listShift, listMonthShiftID, monthYear, attendanceFrom, attendanceTo); //Tổng số ngày được trả lương của nhân viên đang xét => ngày thực tế attendanceTable.PaidWorkDayCount = attendanceTable.RealWorkDayCount; if (gradeCfg.EDType == PayrollComputeMethod.E_SUBTRACT.ToString()) { //Số ngày công thực tế + số ngày nghỉ hưởng lương Double workAndPaidLeaveDays = attendanceTable.RealWorkDayCount; double unHiredDays = 0; double terminatedDays = 0; if (attendanceTable.Att_AttendanceTableItem.Count() > 0) { workAndPaidLeaveDays += attendanceTable.Att_AttendanceTableItem.Sum(d => d.PaidLeaveHours / d.udStandardWorkHours); } //Nếu nhân viên không vào làm hoặc nghỉ việc trong tháng và số ngày công thực tế + số ngày nghỉ hưởng lương > số ngày công tối thiểu if (((profile.DateHire.HasValue && profile.DateHire.Value.Date < attendanceFrom) || workAndPaidLeaveDays > attendanceTable.StdWorkDayCount) && ((!profile.DateQuit.HasValue || profile.DateQuit.Value.Date > attendanceTo) || workAndPaidLeaveDays > attendanceTable.StdWorkDayCount) && workAndPaidLeaveDays >= gradeCfg.MinWorkDay.Value) { //Tổng số ngày nghỉ loại 1 và loại 2 khi có trường hợp 1 ngày mà nghỉ 2 loại Double totalLeaveDays = attendanceTable.Att_AttendanceTableItem.Sum(d => (d.LeaveHours + d.ExtraLeaveHours) / d.udStandardWorkHours); if (isMidCutOffDay) { totalLeaveDays = attendanceTable.Att_AttendanceTableItem.Where(d => d.WorkDate <= midCutOffDate) .Sum(d => d.LeaveHours + d.ExtraLeaveHours / d.udStandardWorkHours);//Số ngày nghỉ không ứng công } //Cộng thêm số ngày chưa làm việc - trường hợp làm nửa ca totalLeaveDays += attendanceTable.Att_AttendanceTableItem.Sum(d => d.udNotHiredHours / d.udStandardWorkHours); if (profile.DateQuit.HasValue) { //Cộng thêm số ngày đã nghỉ việc totalLeaveDays += attendanceTable.Att_AttendanceTableItem.Sum(d => d.udTerminatedHours / d.udStandardWorkHours); } //Tính số ngày công tính lương = số ngày công chuẩn - tổng số ngày nghỉ attendanceTable.PaidWorkDayCount = attendanceTable.StdWorkDayCount - totalLeaveDays; if (attendanceTable.PaidWorkDayCount < 0) { attendanceTable.PaidWorkDayCount = 0; } } else if ((gradeCfg.IsApplySubSalaryNewQuitEmp.GetBoolean() && workAndPaidLeaveDays >= gradeCfg.MinWorkDayNewQuitEmp.GetDouble()) && ((profile.DateHire.HasValue && profile.DateHire.Value.Date >= attendanceFrom) || (profile.DateQuit.HasValue && profile.DateQuit.Value.Date <= attendanceTo))) { Double totalLeaveDays = attendanceTable.Att_AttendanceTableItem.Sum(it => (it.LeaveHours + it.ExtraLeaveHours) / it.udStandardWorkHours); Double DayNonShiftInUnEmployeeTime = 0;//Thời gian của nhân viên không có lịch làm việc trước khi vào công ty hoặc là sau khi ra khỏi công ty trong tháng if (profile.DateHire.HasValue && profile.DateHire.Value > attendanceFrom) { unHiredDays = profile.DateHire.Value.Subtract(attendanceFrom).Days; for (DateTime DateCheck = attendanceFrom; DateCheck < profile.DateHire.Value; DateCheck = DateCheck.AddDays(1)) { if (listMonthShiftID == null || !listMonthShiftID.Any(d => d.Key.Date == DateCheck.Date && d.Value != null)) { DayNonShiftInUnEmployeeTime++; } } } if (profile.DateQuit.HasValue && profile.DateQuit.Value < attendanceTo) { terminatedDays = attendanceTo.Subtract(profile.DateQuit.Value).Days + 1; for (DateTime DateCheck = profile.DateQuit.Value; DateCheck < attendanceTo; DateCheck = DateCheck.AddDays(1)) { if (listMonthShiftID == null || !listMonthShiftID.Any(d => d.Key.Date == DateCheck.Date && d.Value != null)) { DayNonShiftInUnEmployeeTime++; } } } Double paidWorkDay = attendanceTable.StdWorkDayCount - totalLeaveDays; paidWorkDay = paidWorkDay - (unHiredDays + terminatedDays - DayNonShiftInUnEmployeeTime) * gradeCfg.RateUneven.GetDouble(); attendanceTable.PaidWorkDayCount = paidWorkDay; } } #region Tính tổng thời gian theo từng loại ngày nghỉ và loại làm thêm TotalGroupByLeaveDayType(attendanceTable, attendanceTo); TotalGroupByOvertimeType(attendanceTable, attendanceTo); #endregion #region Tính tổng thời gian và làm tròn attendanceTable.TotalPaidWorkDayCount = attendanceTable.PaidWorkDayCount; attendanceTable.TotalRealWorkDayCount = attendanceTable.RealWorkDayCount; //Cấu hình làm tròng trễ sớm theo tháng if (gradeCfg != null && gradeCfg.IsLateEarlyFirstLastShiftRound == true) { attendanceTable.LateEarlyDeductionHours = Att_AttendanceLib.RoundLateEarlyMinutes(listLateEarlyRule.Where(d => d.GradeCfgID == gradeCfg.ID).ToList(), Convert.ToInt32(attendanceTable.LateEarlyDeductionHours * 60)) / 60; } #endregion #endregion return attendanceTable != null ? 1 : 0; }
public static void GetSalaryDateRange(Cat_GradeAttendance gradeCfg, Sys_AllSetting objAppConfig, List<Att_CutOffDuration> lstCutOff, DateTime monthYear , out DateTime from, out DateTime to) { DateTime fromDate = new DateTime(monthYear.Year, monthYear.Month, 1); DateTime toDate = fromDate.AddMonths(1).AddMinutes(-1); if (gradeCfg != null) Att_AttendanceServices.GetSalaryDateRange(gradeCfg, lstCutOff, monthYear, out fromDate, out toDate); else { if (objAppConfig != null) Att_AttendanceServices.GetSalaryDateRange(objAppConfig, monthYear, out fromDate, out toDate); } from = fromDate; to = toDate; }
/// <summary> /// Xac dinh ngay bat dau, ket thuc thang luong dua vao Cau hinh chung /// </summary> /// <param name="grade"></param> /// <param name="monthYear"></param> /// <param name="from"></param> /// <param name="to"></param> private static void GetSalaryDateRange(Sys_AllSetting appConfig, DateTime monthYear , out DateTime from, out DateTime to) { if (appConfig != null) { int day = Convert.ToInt32(appConfig.Value1); if (appConfig.Value3 == EnumDropDown.SalaryTimeType.E_LASTMONTH.ToString()) { from = new DateTime(monthYear.AddMonths(-1).Year, monthYear.AddMonths(-1).Month, day); } else //same month { from = new DateTime(monthYear.Year, monthYear.Month, day); } to = from.AddMonths(1).AddMinutes(-1); } else { GetSalaryMonthRange(monthYear, out from, out to); } }
/// <summary> /// Lấy tất cả các bản ghi /// Get by key /// </summary> /// <returns></returns> public void SaveConfig(List<Dictionary<string,string>> lstModel) { using (var context = new VnrHrmDataContext()) { IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new CustomBaseRepository<Sys_AllSetting>(unitOfWork); string status = string.Empty; List<Dictionary<Guid, string>> lstUpdate = new List<Dictionary<Guid, string>>(); var valueTemp = new Sys_AllSetting(); var modelTemp = new Sys_AllSetting(); List<Guid> lstConfigIds = new List<Guid>(); List<Sys_AllSetting> lstAdd = new List<Sys_AllSetting>(); List<Sys_AllSetting> lstEdit = new List<Sys_AllSetting>(); List<Sys_AllSetting> lstDel = new List<Sys_AllSetting>(); var getdata = repo.FindBy(s => s.IsDelete == null).ToList(); if (lstModel[0].FirstOrDefault().Value.Length > 0) { var lstStr = lstModel.FirstOrDefault()["lstConfigIds"].Split(','); lstConfigIds = lstStr.Select(Guid.Parse).ToList(); } foreach (var item in lstConfigIds) { modelTemp = GetById<Sys_AllSetting>(item, ref status); lstUpdate.Add(new Dictionary<Guid, string>() { { modelTemp.ID, modelTemp.Name } }); } for (int i = 1; i < lstModel.Count; i++) { var lstEntity = getdata.Where(s => s.Name == lstModel[i].FirstOrDefault().Key).ToList(); if (lstEntity.Count == 0) { valueTemp = new Sys_AllSetting(); valueTemp.ID = Guid.NewGuid(); valueTemp.Name = lstModel[i].FirstOrDefault().Key; valueTemp.Value1 = lstModel[i].FirstOrDefault().Value; lstAdd.Add(valueTemp); continue; } if (lstEntity.Count > 0) { valueTemp = new Sys_AllSetting(); foreach (var item in lstEntity) { item.IsDelete = true; lstDel.Add(item); //repo.Edit(item); } var isUpdate = lstUpdate.Where(s => s.FirstOrDefault().Value == lstModel[i].FirstOrDefault().Key).FirstOrDefault(); if (isUpdate != null) { valueTemp.ID = lstEntity.FirstOrDefault().ID; valueTemp.Name = lstModel[i].FirstOrDefault().Key; valueTemp.Value1 = lstModel[i].FirstOrDefault().Value; valueTemp.IsDelete = null; lstEdit.Add(valueTemp); } else { valueTemp.ID = Guid.NewGuid(); valueTemp.Name = lstModel[i].FirstOrDefault().Key; valueTemp.Value1 = lstModel[i].FirstOrDefault().Value; lstAdd.Add(valueTemp); } } } repo.Edit(lstDel); repo.Add(lstAdd); repo.Edit(lstEdit); repo.SaveChanges(); } }
/// <summary> /// [Hieu.van] Tổng Hợp giặt là /// </summary> /// <param name="dateStart"></param> /// <param name="dateEnd"></param> /// <param name="lstProfileIDs"></param> /// <returns></returns> public List<LMS_LaundryRecordEntity> GetLaundryRecordSummary(string _line, string _locker, string _marker, DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> lstProfileIDs,string UserLogin) { dateStart = dateStart.Date; dateEnd = dateEnd.Date.AddDays(1).AddMilliseconds(-1); string status = string.Empty; //string strIDs = string.Join(",", lstProfileIDs.ToArray()); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoLau_TamScanLog = new CustomBaseRepository<LMS_TamScanLogLMS>(unitOfWork); var repoLau_Line = new CustomBaseRepository<LMS_LineLMS>(unitOfWork); var repoLau_Locker = new CustomBaseRepository<LMS_LockerLMS>(unitOfWork); var repoLau_Marker = new CustomBaseRepository<LMS_Marker>(unitOfWork); var repoLau_LaundryRecord = new CustomBaseRepository<LMS_LaundryRecord>(unitOfWork); var repoSys_AllSetting = new CustomBaseRepository<Sys_AllSetting>(unitOfWork); #region cấu hình số phút xử lý trùng int rsScanMulti = 0; var rsScanMultiConfig = GetData<Sys_AllSetting>(AppConfig.HRM_LAU_LAUNDRYRECORD_SCANMULTI_CONFIG.ToString(), ConstantSql.hrm_sys_sp_get_AllSettingByKey,UserLogin, ref status).FirstOrDefault(); if (rsScanMultiConfig != null) { rsScanMulti = rsScanMultiConfig.Value1 != null ? int.Parse(rsScanMultiConfig.Value1.ToString()) : 0; dateStart = dateStart.Date.AddHours(rsScanMulti); dateEnd = dateEnd.Date.AddDays(1).AddHours(rsScanMulti).AddMilliseconds(-1); } #endregion var tamScanLogs = repoLau_TamScanLog .FindBy(s => dateStart <= s.TimeLog && s.TimeLog <= dateEnd) .Select(s => new { s.Code, s.TimeLog, s.ID, s.MachineCode }) //.Select(s => new { s.MachineCode, s.CardCode, s.TimeLog, s.Id }) .ToList(); var cardCodes = tamScanLogs.Select(s => s.Code).ToList(); //strIDs = Common.DotNetToOracle(strIDs); //var profiles = GetData<Hre_ProfileEntity>(strIDs, ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status) // .Where(s => cardCodes.Contains(s.CodeAttendance) && lstProfileIDs.Contains(s.ID)) var profiles = lstProfileIDs .Where(s => cardCodes.Contains(s.CodeAttendance)) .Select(s => new { s.ID, s.CodeAttendance, s.CodeEmp, s.ProfileName, s.OrgStructureName }).ToList(); tamScanLogs = tamScanLogs .Where(s => profiles.Select(p => p.CodeAttendance).Contains(s.Code)) .OrderBy(s => s.Code) .ThenBy(s => s.TimeLog) .ToList(); #region lấy line-locker-marker và xử lý khi tìm kiếm var lines = repoLau_Line.FindBy(s => s.IsDelete == null).ToList(); var Lockers = repoLau_Locker.FindBy(s => s.IsDelete == null).ToList(); var Markers = repoLau_Marker.FindBy(s => s.IsDelete == null).ToList(); if (_line != null) { List<Guid> lstLine = _line.Split(',').Select(Guid.Parse).ToList(); lines = lines.Where(s => lstLine.Contains(s.ID)).ToList(); } if (_locker != null) { List<Guid> lstLocker = _locker.Split(',').Select(Guid.Parse).ToList(); Lockers = Lockers.Where(s => lstLocker.Contains(s.ID)).ToList(); } if (_marker != null) { List<Guid> lstMarker = _marker.Split(',').Select(Guid.Parse).ToList(); Markers = Markers.Where(s => lstMarker.Contains(s.ID)).ToList(); } #endregion List<object> lstObj = new List<object>(); lstObj.Add(dateStart); lstObj.Add(dateEnd); List<Lau_LaundryRecordCheckEntity> laundryCheckList = GetData<Lau_LaundryRecordCheckEntity>(lstObj, ConstantSql.hrm_lau_sp_get_LaundryRecord_ByDateFromDateTo, UserLogin, ref status); LMS_LaundryRecordEntity laundry = new LMS_LaundryRecordEntity(); List<LMS_LaundryRecordEntity> lstRecord = new List<LMS_LaundryRecordEntity>(); List<LMS_LaundryRecord> lstAdd = new List<LMS_LaundryRecord>(); List<LMS_LaundryRecord> lstEdit = new List<LMS_LaundryRecord>(); List<Guid> lstDuplicateTamScan = new List<Guid>(); foreach (var tamScanLog in tamScanLogs) { if (lstDuplicateTamScan.Contains(tamScanLog.ID)) continue; laundry = new LMS_LaundryRecordEntity(); var profile = profiles.FirstOrDefault(s => s.CodeAttendance == tamScanLog.Code); var line = lines.FirstOrDefault(s => tamScanLog.MachineCode == s.MachineCode); if (profile != null && line != null) { #region xử lý bản ghi trùng var tamScanLogProfiles = tamScanLogs .Where(s => s.Code == tamScanLog.Code && s.TimeLog.Value.Date == tamScanLog.TimeLog.Value.Date && s.MachineCode == tamScanLog.MachineCode) .OrderBy(s => s.TimeLog) .ToList(); if (tamScanLogProfiles.Count > 1 && rsScanMulti > 0) { for (int i = 0; i < tamScanLogProfiles.Count; i++) { var tamsanFirst = tamScanLogProfiles[i]; int j = i + 1; if (j > tamScanLogProfiles.Count - 1) { j = i; } var tamsanNear = tamScanLogProfiles[j]; if (tamsanNear.TimeLog.Value.Subtract(tamsanFirst.TimeLog.Value).TotalMinutes < rsScanMulti && tamsanFirst.ID != tamsanNear.ID) { if (tamsanFirst.MachineCode == tamsanNear.MachineCode) { lstDuplicateTamScan.Add(tamsanNear.ID); break; } } } } #endregion #region xử lý add record laundry.ProfileID = profile.ID; laundry.ProfileName = profile.ProfileName; laundry.CodeAttendance = profile.CodeAttendance; laundry.TimeLog = tamScanLog.TimeLog; laundry.Status = HRM.Infrastructure.Utilities.LaundryRecordStatus.E_SUBMIT.ToString(); laundry.Type = LaundryRecordType.E_AUTO.ToString(); if (tamScanLog.MachineCode != null) { laundry.MachineCode = tamScanLog.MachineCode; if (line != null) { laundry.LineLMSName = line.LineLMSName; laundry.LineID = line.ID; laundry.Amount = (decimal)line.Amount; if (line.LockerID != null) { var locker = Lockers.Where(c => c.ID == line.LockerID).FirstOrDefault(); laundry.LockerLMSName = locker.LockerLMSName; laundry.LockerID = locker.ID; } if (line.MarkerID != null) { var marker = Markers.Where(c => c.ID == line.MarkerID).FirstOrDefault(); laundry.MarkerName = marker.MarkerName; laundry.MarkerID = marker.ID; } } } laundry.DateCreate = DateTime.Now; var recordAdd = laundry.CopyData<LMS_LaundryRecord>(); var CheckList = laundryCheckList.Where(s => s.ProfileID == laundry.ProfileID.Value && s.TimeLog == laundry.TimeLog).ToList(); if (CheckList != null) { if (CheckList.Count() > 0) { var idUpdate = CheckList.FirstOrDefault(); recordAdd.ID = idUpdate.ID; repoLau_LaundryRecord.Edit(recordAdd); //lstEdit.Add(recordAdd); } else { recordAdd.ID = Guid.NewGuid(); repoLau_LaundryRecord.Add(recordAdd); //lstAdd.Add(recordAdd); } } laundry.ID = tamScanLog.ID; lstRecord.Add(laundry); #endregion } } repoLau_LaundryRecord.SaveChanges(); //if (lstAdd.Any()) //{ // repoLau_LaundryRecord.Add(lstAdd); // repoLau_LaundryRecord.SaveChanges(); //} //if (lstEdit.Any()) //{ // repoLau_LaundryRecord.Edit(lstEdit); // repoLau_LaundryRecord.SaveChanges(); //} if (lstRecord.Count > 0) { Sys_AllSetting sys = new Sys_AllSetting(); Sys_AllSetting rs = GetData<Sys_AllSetting>(AppConfig.HRM_LAU_LAUNDRYRECORD_SUMMARY.ToString(), ConstantSql.hrm_sys_sp_get_AllSettingByKey,UserLogin, ref status).FirstOrDefault(); sys.Value1 = dateStart.ToString(ConstantFormat.HRM_Format_YearMonthDay_HoursMinSecond.ToString()); sys.Value2 = dateEnd.ToString(ConstantFormat.HRM_Format_YearMonthDay_HoursMinSecond.ToString()); sys.Name = AppConfig.HRM_LAU_LAUNDRYRECORD_SUMMARY.ToString(); if (rs != null) { sys.ID = rs.ID; repoSys_AllSetting.Edit(sys); } else { sys.ID = Guid.NewGuid(); repoSys_AllSetting.Add(sys); } repoSys_AllSetting.SaveChanges(); } return lstRecord; } }