public Guid GetProfileIDByTravelRequests(Guid TravelRequestID) { Guid rs = Guid.Empty; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoTravelRequest = new CustomBaseRepository<FIN_TravelRequest>(unitOfWork); var TravelRequest = repoTravelRequest.GetById(TravelRequestID); rs = TravelRequest.ProfileID.Value; } return rs; }
public bool CheckLeader(Guid LeaderID, Guid ProfileID) { bool rs = false; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoProfile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var Profile = repoProfile.GetById(ProfileID); if (Profile.SupervisorID == LeaderID || Profile.HighSupervisorID == LeaderID) rs = true; } return rs; }
/// <summary> /// [Chuc.Nguyen] - Lấy dữ liệu của một đối tượng bất kỳ theo Id dùng Entity /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="id"></param> /// <param name="status"></param> /// <returns></returns> public TEntity GetById <TEntity>(Guid id, ref string status) where TEntity : class { TEntity entity = null; using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repo = new CustomBaseRepository <TEntity>(unitOfWork); try { entity = repo.GetById(id); status = NotificationType.Success.ToString(); } catch (Exception ex) { status = NotificationType.Error + "," + ex.Message; } } return(entity); }
public void ComputeDepartment(Guid departmentID) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (UnitOfWork)(new UnitOfWork(context)); var repoSal_SalaryDepartment = new CustomBaseRepository<Sal_SalaryDepartment>(unitOfWork); var repoSal_SalaryDepartmentItem = new CustomBaseRepository<Sal_SalaryDepartmentItem>(unitOfWork); var repoAtt_CutOffDuration = new CustomBaseRepository<Att_CutOffDurationEntity>(unitOfWork); Sal_SalaryDepartment item = new Sal_SalaryDepartment(); item = repoSal_SalaryDepartment.GetById(departmentID); //xóa các item nếu đã tính trước đó List<Sal_SalaryDepartmentItem> listDepartmentItem = new List<Sal_SalaryDepartmentItem>(); listDepartmentItem = repoSal_SalaryDepartmentItem.GetAll().Where(m => m.SalaryDepartmentID == departmentID).ToList(); repoSal_SalaryDepartmentItem.Delete(listDepartmentItem); unitOfWork.SaveChanges(); //nếu chọn theo cutoff thì lấy datefrom dateto của cutoff if (item.CutOffDurationID != null) { var cutoff= repoAtt_CutOffDuration.GetById((Guid)item.CutOffDurationID); item.MonthYear = cutoff.MonthYear; item.DateFrom = cutoff.DateStart; item.DateTo = cutoff.DateEnd; } Hashtable hasTable = new Hashtable(); List<Sal_SalaryDepartment> listSalaryDepartment = new List<Sal_SalaryDepartment>(); listSalaryDepartment.Add(item); ComputeSalaryDepartment(item.MonthYear, (DateTime)item.DateFrom, (DateTime)item.DateTo, listSalaryDepartment, ref hasTable); } }
public string Set_RejectRoster_ByModuleApprove(string host, List<Guid> lstRoster, Guid UserLoginID, string userLogin) { using (var context = new VnrHrmDataContext()) { string status = string.Empty; string statusSendMail = DataErrorCode.Error.ToString(); BaseService service = new BaseService(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoAtt_Roster = new CustomBaseRepository<Att_Roster>(unitOfWork); #region getdata List<object> lstParamUser = new List<object>(); lstParamUser.AddRange(new object[4]); lstParamUser[3] = Int32.MaxValue; var lstUserAll = service.GetData<Sys_UserInfo>(lstParamUser, ConstantSql.hrm_sys_sp_get_users, userLogin, ref status); var lstUser = lstUserAll.Where(m => !string.IsNullOrEmpty(m.Email)).Select(m => new { m.ID, m.Email }).ToList(); #endregion #region process string E_REJECTED = RosterStatus.E_REJECTED.ToString(); List<Att_Roster> lstRosterSendMail = new List<Att_Roster>(); foreach (var rosID in lstRoster) { var Roster = repoAtt_Roster.GetById(rosID); lstRosterSendMail.Add(Roster); Roster.Status = E_REJECTED; } var stt = repoAtt_Roster.SaveChanges(); #endregion if (stt == DataErrorCode.Success) { #region getdata List<Hre_ProfileEntity> lstProfile = new List<Hre_ProfileEntity>(); List<Sys_TemplateSendMail> template = new List<Sys_TemplateSendMail>(); Sys_TemplateSendMail tempApprove = new Sys_TemplateSendMail(); Sys_TemplateSendMail tempReturn = new Sys_TemplateSendMail(); string[] strsParaKey = null; string bodyContent = null; string titleMail = null; string[] strsParaValues = null; string[] strsParaValues_Return = null; string _typeTemplate = EnumDropDown.EmailType.E_APPROVED_ROSTER.ToString(); string _typeTemplate_return = EnumDropDown.EmailType.E_APPROVED_ROSTER_RETURN.ToString(); var repoSys_TemplateSendMail = new CustomBaseRepository<Sys_TemplateSendMail>(unitOfWork); template = repoSys_TemplateSendMail.FindBy(s => s.Type == _typeTemplate || s.Type == _typeTemplate_return).ToList(); if (template.Count < 2) return DataErrorCode.Error_NoTemplateMail.ToString(); tempApprove = template.Where(s => s.Type == _typeTemplate).FirstOrDefault(); tempReturn = template.Where(s => s.Type == _typeTemplate_return).FirstOrDefault(); string proIDS = string.Join(",", lstRosterSendMail.Select(s => s.ProfileID.ToString()).Distinct().ToList()); proIDS = Common.DotNetToOracle(proIDS); lstProfile = GetData<Hre_ProfileEntity>(proIDS, ConstantSql.hrm_hr_sp_get_ProfileByIds, userLogin, ref status); strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_ROSTER.E_UserName.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_ProfileName.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_CodeEmp.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_DateStart.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_DateEnd.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_Status.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_Type.ToString(), EnumDropDown.EmailType_APPROVED_ROSTER.E_LinkContent.ToString(), }; #endregion foreach (var Roster in lstRosterSendMail) { List<Guid> lstDelegateApproveUserID = new List<Guid>(); var UserRegister = lstUserAll.Where(m => m.ProfileID == Roster.ProfileID).FirstOrDefault(); if (UserRegister != null) { lstDelegateApproveUserID.Add(UserRegister.ID); } lstDelegateApproveUserID = lstDelegateApproveUserID.Distinct().ToList(); var lstUserInfoCanView = lstUser.Where(m => lstDelegateApproveUserID.Contains(m.ID)).ToList(); List<Att_EmailRequireEntity> lstEmailRequire = new List<Att_EmailRequireEntity>(); foreach (var UserInfoCanView in lstUserInfoCanView) { if (UserInfoCanView.Email == null) continue; Att_EmailRequireEntity EmailRequireEntity = new Att_EmailRequireEntity(); EmailRequireEntity.IdObject = Roster.ID; EmailRequireEntity.EmailUserApprove = UserInfoCanView.Email; EmailRequireEntity.IdUserApprove = UserInfoCanView.ID; if (UserRegister != null && UserInfoCanView.ID == UserRegister.ID) { EmailRequireEntity.IsRegister = true; } lstEmailRequire.Add(EmailRequireEntity); } if (lstEmailRequire.Count > 0) { Guid ID = Roster.ID; var lstEmailToSend_ByOT = lstEmailRequire.Where(m => m.IdObject == ID).ToList(); var profile = lstProfile.Where(s => s.ID == Roster.ProfileID).FirstOrDefault(); var userApproved1 = lstUserAll.Where(s => s.ID == Roster.UserApproveID).FirstOrDefault(); var userApproved2 = lstUserAll.Where(s => s.ID == Roster.UserApproveID2).FirstOrDefault(); foreach (var mail in lstEmailRequire) { bodyContent = string.Empty; if (mail.IsRegister == true) { #region Send Cho nguoi đăng ký titleMail = tempReturn.Subject; strsParaValues_Return = new string[]{ profile.ProfileName, profile.ProfileName, profile.CodeEmp, Roster.DateStart.ToString("dd/MM/yyyy"), Roster.DateEnd.ToString("dd/MM/yyyy"), Roster.Status, Roster.Type, string.Empty, }; bodyContent = LibraryService.ReplaceContentFile(tempReturn.Content, strsParaKey, strsParaValues_Return); #endregion } else { #region Send cho ngươi duyệt string UserNameNext = lstUserAll.Where(m => m.ID == mail.IdUserApprove).Select(m => m.UserInfoName).FirstOrDefault(); titleMail = tempApprove.Subject; string linkcontent = "<br/> <a href='" + host + "Att_ApprovedOvertime/ProcessApprovedPage?loginID=" + mail.IdUserApprove + "&recordID=" + Roster.ID + "'>Click this link to approve<a/><br /><br />"; linkcontent += "<br/> <a href='" + host + "Att_ApprovedOvertime/ProcessRejectPage?loginID=" + mail.IdUserApprove + "&recordID=" + Roster.ID + "'>Click this link to Reject<a/><br /><br />"; strsParaValues_Return = new string[]{ UserNameNext, profile.ProfileName, profile.CodeEmp, Roster.DateStart.ToString("dd/MM/yyyy"), Roster.DateEnd.ToString("dd/MM/yyyy"), Roster.Status, Roster.Type, string.Empty, }; bodyContent = LibraryService.ReplaceContentFile(tempApprove.Content, strsParaKey, strsParaValues); #endregion } var sta = service.SendMail(titleMail, mail.EmailUserApprove, bodyContent, null); if (sta == true) { statusSendMail = DataErrorCode.Success.ToString(); } } } } } return statusSendMail; } }
public string Set_ApproveLeaveDay_ByModuleApprove(string host, List<Guid> lstLeaveDay, Guid UserLoginID, string userLogin) { using (var context = new VnrHrmDataContext()) { string status = string.Empty; string statusSendMail = DataErrorCode.Error.ToString(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); BaseService service = new BaseService(); var repoAtt_LeaveDay = new CustomBaseRepository<Att_LeaveDay>(unitOfWork); #region getdata List<object> lstParamUser = new List<object>(); lstParamUser.AddRange(new object[4]); lstParamUser[3] = Int32.MaxValue; var lstUserAll = service.GetData<Sys_UserInfo>(lstParamUser, ConstantSql.hrm_sys_sp_get_users, userLogin, ref status); var lstUser = lstUserAll.Where(m => !string.IsNullOrEmpty(m.Email)).Select(m => new { m.ID, m.Email }).ToList(); //Step1 : Check 1 Approve or 2 approve DateTime today = DateTime.Today; string E_LEAVEDAY = DelegateApproveType.E_LEAVE_DAY.ToString(); List<object> lstParam = new List<object>(); lstParam.AddRange(new object[10]); var lstDelegateApproveAll = service.GetData<Sys_DelegateApprove>(lstParam, ConstantSql.hrm_sys_sp_get_DelegateApprove, userLogin, ref status); var lstDelegateApprove = lstDelegateApproveAll.Where(m => m.UserID != null && m.UserDelegateID != null && m.DataTypeDelegate == E_LEAVEDAY && m.DateFrom <= today && m.DateTo >= today).ToList(); List<Guid> lstUserCanView = lstDelegateApprove.Where(m => m.UserDelegateID == UserLoginID).Select(m => m.UserID.Value).ToList(); lstUserCanView.Add(UserLoginID); #endregion #region process string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString(); string E_FIRST_APPROVED = LeaveDayStatus.E_FIRST_APPROVED.ToString(); List<Att_LeaveDay> lstLeaveDaySendMail = new List<Att_LeaveDay>(); foreach (var leaID in lstLeaveDay) { var LeaveDay = repoAtt_LeaveDay.GetById(leaID); lstLeaveDaySendMail.Add(LeaveDay); if (LeaveDay.UserApproveID2 != null && lstUserCanView.Contains(LeaveDay.UserApproveID2.Value)) { LeaveDay.Status = E_APPROVED; } if (LeaveDay.UserApproveID != null && lstUserCanView.Contains(LeaveDay.UserApproveID.Value)) { LeaveDay.Status = E_FIRST_APPROVED; } } var stt = repoAtt_LeaveDay.SaveChanges(); #endregion if (stt == DataErrorCode.Success) { #region getdata List<Hre_ProfileEntity> lstProfile = new List<Hre_ProfileEntity>(); List<Sys_TemplateSendMail> template = new List<Sys_TemplateSendMail>(); Sys_TemplateSendMail tempApprove = new Sys_TemplateSendMail(); Sys_TemplateSendMail tempReturn = new Sys_TemplateSendMail(); List<Cat_LeaveDayType> lstLeaveDayType = new List<Cat_LeaveDayType>(); string[] strsParaKey = null; string bodyContent = null; string titleMail = null; string[] strsParaValues = null; string[] strsParaValues_Return = null; string _typeTemplate = EnumDropDown.EmailType.E_APPROVED_LEAVEDAY.ToString(); string _typeTemplate_return = EnumDropDown.EmailType.E_APPROVED_LEAVEDAY_RETURN.ToString(); var repoSys_TemplateSendMail = new CustomBaseRepository<Sys_TemplateSendMail>(unitOfWork); template = repoSys_TemplateSendMail.FindBy(s => s.Type == _typeTemplate || s.Type == _typeTemplate_return).ToList(); if (template.Count < 2) return DataErrorCode.Error_NoTemplateMail.ToString(); var repoCat_LeaveDayType = new CustomBaseRepository<Cat_LeaveDayType>(unitOfWork); lstLeaveDayType = repoCat_LeaveDayType.FindBy(s => s.IsDelete == null).ToList(); tempApprove = template.Where(s => s.Type == _typeTemplate).FirstOrDefault(); tempReturn = template.Where(s => s.Type == _typeTemplate_return).FirstOrDefault(); string proIDS = string.Join(",", lstLeaveDaySendMail.Select(s => s.ProfileID.ToString()).Distinct().ToList()); proIDS = Common.DotNetToOracle(proIDS); lstProfile = GetData<Hre_ProfileEntity>(proIDS, ConstantSql.hrm_hr_sp_get_ProfileByIds, userLogin, ref status); strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_UserName.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_ProfileName.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_CodeEmp.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_DateStart.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_DateEnd.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_Status.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_LeaveDayTypeName.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_LeaveHours.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_LeaveDays.ToString(), EnumDropDown.EmailType_APPROVED_LEAVEDAY.E_LinkContent.ToString(), }; #endregion foreach (var Leaveday in lstLeaveDaySendMail) { Guid? UserNextApprove = null; if (Leaveday.Status == E_FIRST_APPROVED) { UserNextApprove = Leaveday.UserApproveID2; } string LeaveDayType = string.Empty; var leavedayTypeObject = lstLeaveDayType.Where(m=>m.ID==Leaveday.ID).FirstOrDefault(); if(leavedayTypeObject!= null) { LeaveDayType = leavedayTypeObject.LeaveDayTypeName; } List<Guid> lstDelegateApproveUserID = new List<Guid>(); if (UserNextApprove != null) { lstDelegateApproveUserID = lstDelegateApprove.Where(m => m.UserID == UserNextApprove).Select(m => m.UserDelegateID.Value).ToList(); lstDelegateApproveUserID.Add(UserNextApprove.Value); } var UserRegister = lstUserAll.Where(m => m.ProfileID == Leaveday.ProfileID).FirstOrDefault(); if (UserRegister != null) { lstDelegateApproveUserID.Add(UserRegister.ID); } lstDelegateApproveUserID = lstDelegateApproveUserID.Distinct().ToList(); var lstUserInfoCanView = lstUser.Where(m => lstDelegateApproveUserID.Contains(m.ID)).ToList(); List<Att_EmailRequireEntity> lstEmailRequire = new List<Att_EmailRequireEntity>(); foreach (var UserInfoCanView in lstUserInfoCanView) { if (UserInfoCanView.Email == null) continue; Att_EmailRequireEntity EmailRequireEntity = new Att_EmailRequireEntity(); EmailRequireEntity.IdObject = Leaveday.ID; EmailRequireEntity.EmailUserApprove = UserInfoCanView.Email; EmailRequireEntity.IdUserApprove = UserInfoCanView.ID; if (UserRegister != null && UserInfoCanView.ID == UserRegister.ID) { EmailRequireEntity.IsRegister = true; } lstEmailRequire.Add(EmailRequireEntity); } if (lstEmailRequire.Count > 0) { Guid ID = Leaveday.ID; var lstEmailToSend_ByOT = lstEmailRequire.Where(m => m.IdObject == ID).ToList(); var profile = lstProfile.Where(s => s.ID == Leaveday.ProfileID).FirstOrDefault(); var userApproved1 = lstUserAll.Where(s => s.ID == Leaveday.UserApproveID).FirstOrDefault(); var userApproved2 = lstUserAll.Where(s => s.ID == Leaveday.UserApproveID2).FirstOrDefault(); foreach (var mail in lstEmailRequire) { bodyContent = string.Empty; if (mail.IsRegister == true) { #region Send Cho nguoi đăng ký titleMail = tempReturn.Subject; strsParaValues_Return = new string[]{ profile.ProfileName, profile.ProfileName, profile.CodeEmp, Leaveday.DateStart.ToString("dd/MM/yyyy"), Leaveday.DateEnd.ToString("dd/MM/yyyy"), Leaveday.Status, LeaveDayType, (Leaveday.LeaveHours??0).ToString(), (Leaveday.LeaveDays??0).ToString(), string.Empty, }; bodyContent = LibraryService.ReplaceContentFile(tempReturn.Content, strsParaKey, strsParaValues_Return); #endregion } else { #region Send cho ngươi duyệt titleMail = tempApprove.Subject; string UserName = lstUserAll.Where(m => m.ID == mail.IdUserApprove).Select(m => m.UserInfoName).FirstOrDefault(); string linkcontent = "<br/> <a href='" + host + "Att_ApprovedLeaveday/ProcessApprovedPage?loginID=" + mail.IdUserApprove + "&recordID=" + Leaveday.ID + "'>Click this link to approve<a/><br /><br />"; linkcontent += "<br/> <a href='" + host + "Att_ApprovedLeaveday/ProcessRejectPage?loginID=" + mail.IdUserApprove + "&recordID=" + Leaveday.ID + "'>Click this link to Reject<a/><br /><br />"; strsParaValues = new string[]{ UserName, profile.ProfileName, profile.CodeEmp, Leaveday.DateStart.ToString("dd/MM/yyyy"), Leaveday.DateEnd.ToString("dd/MM/yyyy"), Leaveday.Status, LeaveDayType, (Leaveday.LeaveHours??0).ToString(), (Leaveday.LeaveDays??0).ToString(), linkcontent }; bodyContent = LibraryService.ReplaceContentFile(tempApprove.Content, strsParaKey, strsParaValues); #endregion } var sta = service.SendMail(titleMail, mail.EmailUserApprove, bodyContent, null); if (sta == true) { statusSendMail = DataErrorCode.Success.ToString(); } } } } } return statusSendMail; } }
public void ComputeBonusUnusualAllowance_Progress(Guid AsynTaskID, Sal_UnusualAllowanceEntity model, bool AllowanceEvaluationYear = false) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork) new UnitOfWork(context); var repoSys_AsynTask = new CustomBaseRepository <Sys_AsynTask>(unitOfWork); var repoCat_Element = new CustomBaseRepository <Cat_Element>(unitOfWork); var repoCat_UnusualAllowanceCfg = new CustomBaseRepository <Cat_UnusualAllowanceCfg>(unitOfWork); var repoUnusualAllowance = new CustomBaseRepository <Sal_UnusualAllowance>(unitOfWork); Sys_AsynTask asynTask = repoSys_AsynTask.GetById(AsynTaskID); Sal_ComputePayrollServices CumputePayrollServices = new Sal_ComputePayrollServices(); List <object> listModel = new List <object>(); string status = string.Empty; Sal_ComputePayrollServices Services = new Sal_ComputePayrollServices(); List <Sal_UnusualAllowanceEntity> ListResult = new List <Sal_UnusualAllowanceEntity>(); List <ElementFormula> listElementFormula = new List <ElementFormula>(); Sal_UnusualAllowanceServices UnusualAllowanceServices = new Sal_UnusualAllowanceServices(); Att_CutOffDurationEntity CutOffDuration = new Att_CutOffDurationEntity(); if (model.MonthEnd != null) { CutOffDuration.MonthYear = model.MonthStart.Value; CutOffDuration.DateStart = model.MonthStart.Value; CutOffDuration.DateEnd = model.MonthEnd.Value; } else { CutOffDuration.MonthYear = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateStart = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateEnd = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1).AddMonths(1).AddDays(-1); } List <Hre_ProfileEntity> ListProfile = new List <Hre_ProfileEntity>(); if (model.OrgStructureIDs != null && model.OrgStructureIDs != string.Empty) { listModel = new List <object>(); listModel.AddRange(new object[18]); listModel[2] = model.OrgStructureIDs; listModel[16] = 1; listModel[17] = Int32.MaxValue - 1; ListProfile = GetData <Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, ref status); if (model.ExProfileIDs != null) { string[] ExProfile = model.ExProfileIDs.Split(','); ListProfile = ListProfile.Where(m => ExProfile.Contains(m.ID.ToString())).ToList(); } } else if (model.ProfileIDs != null && model.ProfileIDs != string.Empty) { ListProfile = GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status); } //lọc profile theo workplace if (model.WorkingPlaceID != null) { string[] listWorkPlare = model.WorkingPlaceID.Split(','); ListProfile = ListProfile.Where(m => listWorkPlare.Contains(m.WorkPlaceID.ToString())).ToList(); } List <Cat_UnusualAllowanceCfg> listUnusualAllowanceCfg = new List <Cat_UnusualAllowanceCfg>(); listUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); #region Delete các phụ cấp trong năm đã có List <Sal_UnusualAllowance> listUnusualAllowance = repoUnusualAllowance.FindBy(m => m.IsDelete != true && m.MonthStart != null && model.MonthStart != null && m.MonthStart.Value.Year == model.MonthStart.Value.Year && m.Status != WorkHistoryStatus.E_APPROVED.ToString()).ToList(); //nếu là tính phép năm sức khỏe tốt thì delete thêm loại GoodHealth if (AllowanceEvaluationYear) { var _tmp = listUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); listUnusualAllowance = listUnusualAllowance.Where(m => (m.UnusualEDTypeID == model.UnusualEDTypeID || m.UnusualEDTypeID == _tmp.ID) && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } else { listUnusualAllowance = listUnusualAllowance.Where(m => m.UnusualEDTypeID == model.UnusualEDTypeID && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } //update isdelete is true listUnusualAllowance.ForEach(m => m.IsDelete = true); #endregion //Cat_ElementEntity ElementItem = repoCat_Element.GetById((Guid)model.Element).Copy<Cat_ElementEntity>(); Cat_ElementEntity ElementItem = repoCat_Element.FindBy(m => m.ID == (Guid)model.Element).FirstOrDefault().Copy <Cat_ElementEntity>(); ComputePayrollDataModel TotalData = Services.GetDataForComputeSalary(CutOffDuration); List <Cat_ElementEntity> listElementAll = new List <Cat_ElementEntity>(); listElementAll = TotalData.listElement_All; #region Xử lý cho tính phép năm, sức khỏe tốt List <Cat_UnusualAllowanceCfg> ListUnusualAllowanceCfg = new List <Cat_UnusualAllowanceCfg>(); Cat_UnusualAllowanceCfg PaidLeave = null; Cat_UnusualAllowanceCfg GoodHealth = null; ElementFormula FormulaValue = new ElementFormula(); if (AllowanceEvaluationYear) { ListUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); PaidLeave = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "PaidLeave"); GoodHealth = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); } #endregion foreach (var profile in ListProfile) { if (AllowanceEvaluationYear) { #region Tính Công Thức try { listElementFormula = new List <ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate <Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary <Guid, ValueCount>()); } catch { listElementFormula = null; continue; } #endregion if (PaidLeave != null) { //lưu phần tử TienBuPhepNam Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = PaidLeave.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienPhepNam").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } if (GoodHealth != null) { //lưu phần tử TienSucKhoe Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = GoodHealth.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienSucKhoe").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } } else { Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = model.UnusualEDTypeID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; try { listElementFormula = new List <ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate <Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary <Guid, ValueCount>()); FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == ElementItem.ElementCode.ReplaceSpace()).FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); } catch { UnusualAllowance.Amount = 0; UnusualAllowance.Notes = "Không tính được công thức - Lỗi: " + TotalData.Status; } repoUnusualAllowance.Add(UnusualAllowance); } if (ListProfile.IndexOf(profile) % 10 == 0) { asynTask.PercentComplete = (double)(ListProfile.IndexOf(profile) + 1) / (double)ListProfile.Count; unitOfWork.SaveChanges(); } } asynTask.PercentComplete = 1; unitOfWork.SaveChanges(); } }
public DataTable ReportAmountOTandUnpadLeave(string lstOrgstructureID, string profileIds, Guid cutOffDurationID, string ElementCode, Guid? workingPlaceID, string statusSyn, string UserLogin) { using (var context = new VnrHrmDataContext()) { DateTime monthyear = new DateTime(); DateTime from = new DateTime(); DateTime to = new DateTime(); #region Get Data var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var reposOrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork); var reposAttCutoffDuration = new CustomBaseRepository<Att_CutOffDuration>(unitOfWork); List<string> lstElementCode = new List<string>(); if (ElementCode != null && ElementCode != string.Empty) { lstElementCode = ElementCode.Split(',').ToList(); } var repoElement = new CustomBaseRepository<Cat_Element>(unitOfWork); //ds phần tử string statusEl = string.Empty; var lstObjElement = new List<object>(); lstObjElement.Add(null); lstObjElement.Add(null); lstObjElement.Add(null); lstObjElement.Add(null); lstObjElement.Add(null); lstObjElement.Add(1); lstObjElement.Add(int.MaxValue - 1); List<Cat_ElementEntity> lstElement = GetData<Cat_ElementEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_Element, UserLogin, ref statusEl); lstElement = lstElement.Where(m => lstElementCode.Contains(m.ElementCode)).ToList(); DataTable tb = getSchemaTableReportAmountOTandUPLeave(lstElement); //Ds nhân viên #region MyRegion string status = string.Empty; List<Hre_ProfileEntity> lstProfile = new List<Hre_ProfileEntity>(); List<Hre_ProfileEntity> listProfileByIds = new List<Hre_ProfileEntity>(); //Lọc theo phòng ban if ((lstOrgstructureID != null && lstOrgstructureID != string.Empty) || (lstOrgstructureID == null && profileIds == null)) { List<object> listObj = new List<object>(); listObj.Add(lstOrgstructureID); listObj.Add(string.Empty); listObj.Add(string.Empty); lstProfile = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status); } //lọc theo nhân viên List<object> lstModel = new List<object>(); if (profileIds != null && profileIds != string.Empty) { lstModel.AddRange(new object[16]); lstModel[14] = 1; lstModel[15] = Int32.MaxValue - 1; listProfileByIds = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(profileIds), ConstantSql.hrm_hr_sp_get_ProfileByIds, UserLogin, ref status).ToList(); } //kết 2 list nhân viên lại if (listProfileByIds != null && listProfileByIds.Count > 0) { foreach (var profile in listProfileByIds) { if (!lstProfile.Any(m => m.ID == profile.ID)) { lstProfile.Add(profile); } } } #endregion //string status = string.Empty; //List<object> listModel = new List<object>(); //listModel = new List<object>(); //listModel.AddRange(new object[16]); //listModel[2] = lstOrgstructureID; //listModel[14] = 1; //listModel[15] = Int32.MaxValue - 1; //List<Hre_ProfileEntity> lstProfile = GetData<Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, UserLogin,ref status); if (workingPlaceID != null) { lstProfile = lstProfile.Where(s => s.WorkPlaceID != null && workingPlaceID.Value == s.WorkPlaceID).ToList(); } if (!string.IsNullOrEmpty(statusSyn)) { lstProfile = lstProfile.Where(s => s.StatusSyn != null && s.StatusSyn == statusSyn).ToList(); } var lstProfileID = lstProfile.Select(hr => hr.ID).ToList(); //kỳ lương if (cutOffDurationID != Guid.Empty) { var cutoff = reposAttCutoffDuration.GetById(cutOffDurationID); if (cutoff != null) { monthyear = cutoff.MonthYear; from = cutoff.DateStart; to = cutoff.DateEnd; } } //Bảng lương string statusTb = string.Empty; List<object> listModelprtb = new List<object>(); listModelprtb = new List<object>(); listModelprtb.AddRange(new object[6]); listModelprtb[2] = from; listModelprtb[3] = to; listModelprtb[4] = 1; listModelprtb[5] = Int32.MaxValue - 1; List<Sal_PayrollTableEntity> lstPayrollTable = GetData<Sal_PayrollTableEntity>(listModelprtb, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin, ref statusTb); string statusTbit = string.Empty; List<object> listModelprtbit = new List<object>(); listModelprtbit = new List<object>(); listModelprtbit.AddRange(new object[9]); listModelprtbit[2] = from; listModelprtbit[3] = to; listModelprtbit[7] = 1; listModelprtbit[8] = Int32.MaxValue - 1; List<Sal_PayrollTableItemEntity> lstPayrollTableItem = GetData<Sal_PayrollTableItemEntity>(listModelprtbit, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin, ref statusTbit); lstPayrollTableItem = lstPayrollTableItem.Where(it => it.Value != null && it.Value != string.Empty).ToList(); //Ds phòng ban var lstOrgStructure = reposOrgStructure.GetAll().Where(org => org.IsDelete == null).Select(org => new { org.ID, org.Code, org.OrgStructureName }).ToList(); #endregion #region Process foreach (var profile in lstProfile) { if (profile == null) { continue; } DataRow dr = tb.NewRow(); dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeEmp] = profile.CodeEmp; dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.ProfileName] = profile.ProfileName; dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.StatusSyn] = profile.StatusSyn; if (profile.DateQuit != null) { dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateQuit] = profile.DateQuit; } if (profile.StatusSyn != null) { dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.StatusSyn] = profile.StatusSyn; } if (profile.DateStop != null) { dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateStop] = profile.DateStop; } dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.CostCentreName; var orgStructure = lstOrgStructure.Where(org => org.ID == profile.OrgStructureID).FirstOrDefault(); dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.E_UNIT] = profile.E_UNIT; dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.E_DIVISION] = profile.E_DIVISION; dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.E_DEPARTMENT] = profile.E_DEPARTMENT; dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.E_TEAM] = profile.E_TEAM; dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.E_SECTION] = profile.E_SECTION; //Bảng lương của profile var payrollTbID_Profile = lstPayrollTable.Where(sal => sal.ProfileID == profile.ID).Select(sal => sal.ID).FirstOrDefault(); var lstpayrollTbItem_Profile = lstPayrollTableItem.Where(salit => salit.PayrollTableID == payrollTbID_Profile).ToList(); if (lstpayrollTbItem_Profile != null && lstpayrollTbItem_Profile.Count > 0) { foreach (var element in lstElementCode) { var prItem = lstpayrollTbItem_Profile.Where(salIt => salIt.Code == element).FirstOrDefault(); if (prItem != null) { if (prItem.ValueType != null && prItem.ValueType.ToUpper() == typeof(Double).Name.ToUpper()) { dr[element] = Convert.ToDouble(prItem.Value); } else if (prItem.ValueType != null && prItem.ValueType.ToUpper() == typeof(DateTime).Name.ToUpper()) { dr[element] = Convert.ToDateTime(prItem.Value); } else dr[element] = prItem.Value; } } tb.Rows.Add(dr); } } #endregion return tb; } }
public void ComputeBonusUnusualAllowance_Progress(Guid AsynTaskID, Sal_UnusualAllowanceEntity model, bool AllowanceEvaluationYear = false) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)new UnitOfWork(context); var repoSys_AsynTask = new CustomBaseRepository<Sys_AsynTask>(unitOfWork); var repoCat_Element = new CustomBaseRepository<Cat_Element>(unitOfWork); var repoCat_UnusualAllowanceCfg = new CustomBaseRepository<Cat_UnusualAllowanceCfg>(unitOfWork); var repoUnusualAllowance = new CustomBaseRepository<Sal_UnusualAllowance>(unitOfWork); Sys_AsynTask asynTask = repoSys_AsynTask.GetById(AsynTaskID); Sal_ComputePayrollServices CumputePayrollServices = new Sal_ComputePayrollServices(); List<object> listModel = new List<object>(); string status = string.Empty; Sal_ComputePayrollServices Services = new Sal_ComputePayrollServices(); List<Sal_UnusualAllowanceEntity> ListResult = new List<Sal_UnusualAllowanceEntity>(); List<ElementFormula> listElementFormula = new List<ElementFormula>(); Sal_UnusualAllowanceServices UnusualAllowanceServices = new Sal_UnusualAllowanceServices(); Att_CutOffDurationEntity CutOffDuration = new Att_CutOffDurationEntity(); if (model.MonthEnd != null) { CutOffDuration.MonthYear = model.MonthStart.Value; CutOffDuration.DateStart = model.MonthStart.Value; CutOffDuration.DateEnd = model.MonthEnd.Value; } else { CutOffDuration.MonthYear = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateStart = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateEnd = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1).AddMonths(1).AddDays(-1); } List<Hre_ProfileEntity> ListProfile = new List<Hre_ProfileEntity>(); if (model.OrgStructureIDs != null && model.OrgStructureIDs != string.Empty) { listModel = new List<object>(); listModel.AddRange(new object[18]); listModel[2] = model.OrgStructureIDs; listModel[16] = 1; listModel[17] = Int32.MaxValue - 1; ListProfile = GetData<Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, ref status); if (model.ExProfileIDs != null) { string[] ExProfile = model.ExProfileIDs.Split(','); ListProfile = ListProfile.Where(m => ExProfile.Contains(m.ID.ToString())).ToList(); } } else if (model.ProfileIDs != null && model.ProfileIDs != string.Empty) { ListProfile = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status); } //lọc profile theo workplace if (model.WorkingPlaceID != null) { string[] listWorkPlare = model.WorkingPlaceID.Split(','); ListProfile = ListProfile.Where(m => listWorkPlare.Contains(m.WorkPlaceID.ToString())).ToList(); } List<Cat_UnusualAllowanceCfg> listUnusualAllowanceCfg = new List<Cat_UnusualAllowanceCfg>(); listUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); #region Delete các phụ cấp trong năm đã có List<Sal_UnusualAllowance> listUnusualAllowance = repoUnusualAllowance.FindBy(m => m.IsDelete != true && m.MonthStart != null && model.MonthStart != null && m.MonthStart.Value.Year == model.MonthStart.Value.Year && m.Status != WorkHistoryStatus.E_APPROVED.ToString()).ToList(); //nếu là tính phép năm sức khỏe tốt thì delete thêm loại GoodHealth if (AllowanceEvaluationYear) { var _tmp = listUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); listUnusualAllowance = listUnusualAllowance.Where(m => (m.UnusualEDTypeID == model.UnusualEDTypeID || m.UnusualEDTypeID == _tmp.ID) && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } else { listUnusualAllowance = listUnusualAllowance.Where(m => m.UnusualEDTypeID == model.UnusualEDTypeID && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } //update isdelete is true listUnusualAllowance.ForEach(m => m.IsDelete = true); #endregion //Cat_ElementEntity ElementItem = repoCat_Element.GetById((Guid)model.Element).Copy<Cat_ElementEntity>(); Cat_ElementEntity ElementItem = repoCat_Element.FindBy(m => m.ID == (Guid)model.Element).FirstOrDefault().Copy<Cat_ElementEntity>(); ComputePayrollDataModel TotalData = Services.GetDataForComputeSalary(CutOffDuration); List<Cat_ElementEntity> listElementAll = new List<Cat_ElementEntity>(); listElementAll = TotalData.listElement_All; #region Xử lý cho tính phép năm, sức khỏe tốt List<Cat_UnusualAllowanceCfg> ListUnusualAllowanceCfg = new List<Cat_UnusualAllowanceCfg>(); Cat_UnusualAllowanceCfg PaidLeave = null; Cat_UnusualAllowanceCfg GoodHealth = null; ElementFormula FormulaValue = new ElementFormula(); if (AllowanceEvaluationYear) { ListUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); PaidLeave = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "PaidLeave"); GoodHealth = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); } #endregion foreach (var profile in ListProfile) { if (AllowanceEvaluationYear) { #region Tính Công Thức try { listElementFormula = new List<ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate<Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary<Guid, ValueCount>()); } catch { listElementFormula = null; continue; } #endregion if (PaidLeave != null) { //lưu phần tử TienBuPhepNam Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = PaidLeave.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienPhepNam").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } if (GoodHealth != null) { //lưu phần tử TienSucKhoe Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = GoodHealth.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienSucKhoe").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } } else { Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = model.UnusualEDTypeID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; try { listElementFormula = new List<ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate<Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary<Guid, ValueCount>()); FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == ElementItem.ElementCode.ReplaceSpace()).FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); } catch { UnusualAllowance.Amount = 0; UnusualAllowance.Notes = "Không tính được công thức - Lỗi: " + TotalData.Status; } repoUnusualAllowance.Add(UnusualAllowance); } if (ListProfile.IndexOf(profile) % 10 == 0) { asynTask.PercentComplete = (double)(ListProfile.IndexOf(profile) + 1) / (double)ListProfile.Count; unitOfWork.SaveChanges(); } } asynTask.PercentComplete = 1; unitOfWork.SaveChanges(); } }