public DataErrorCode SendMaToNextApproved(string host, Guid recordID, Guid userApprovedID) { using (var context = new VnrHrmDataContext()) { string statusMess = string.Empty; var Services = new BaseService(); string status = string.Empty; var UserLogin = string.Empty; string typeApprover = FinApproverType.Fin_CashAdvance.ToString(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoSys_UserApprove = new CustomBaseRepository<Sys_UserApprove>(unitOfWork); var repoFin_Approver = new CustomBaseRepository<FIN_ApproverECLAIM>(unitOfWork); var lstApprover = repoFin_Approver.GetAll().Where(s => s.IsDelete == null).ToList(); var repoSys_UserInfo = new CustomBaseRepository<Sys_UserInfo>(unitOfWork); var repoSys_ConfigProcessApprove = new CustomBaseRepository<Sys_ConfigProcessApprove>(unitOfWork); var repoSys_TemplateSendMail = new CustomBaseRepository<Sys_TemplateSendMail>(unitOfWork); var repo_JobTitle = new CustomBaseRepository<Cat_JobTitle>(unitOfWork); var lstJobTitle = repo_JobTitle.GetAll().Where(s => s.IsDelete == null).ToList(); var repoOrg = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork); var lstOrg = repoOrg.GetAll().Where(s => s.IsDelete == null).ToList(); var repoProfile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var lstProfile = repoProfile.GetAll().Where(s => s.IsDelete == null).ToList(); var repoCashItem = new CustomBaseRepository<Fin_CashAdvanceItem>(unitOfWork); var totalItem = repoCashItem.GetAll().Where(s => s.CashAdvanceID == recordID && s.Status.Contains("E_APPROVED")).Sum(s => s.Amount); var repoFIN_TravelRequest = new CustomBaseRepository<Fin_CashAdvance>(unitOfWork); var record = repoFIN_TravelRequest.FindBy(s => s.ID == recordID).FirstOrDefault(); string _typeTemplate = EnumDropDown.EmailType.E_REQUEST_CASHADVANCE.ToString(); var template = repoSys_TemplateSendMail.FindBy(s => s.Type == _typeTemplate).FirstOrDefault(); if (template == null) return DataErrorCode.Error_NoTemplateMail; #region KT nếu là nguoi duyet cuoi thì gui email lại cho người yêu cầu duyệt if (userApprovedID == Guid.Empty) { if (record != null) { string _typeTemplateApproved = EnumDropDown.EmailType.E_APPROVED_CASHADVANCE.ToString(); var typeTemplateApproved = repoSys_TemplateSendMail.FindBy(s => s.Type == _typeTemplateApproved).FirstOrDefault(); if (typeTemplateApproved == null) { return DataErrorCode.Error_NoTemplateMail; } var lastApprover = lstApprover.Where(s => s.ProfileID == record.ProfileID && s.ApprovedID != null).OrderByDescending(s => s.OrderNo).FirstOrDefault(); var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == lastApprover.ApprovedID.Value).FirstOrDefault(); var lastProfileEntity = lstProfile.Where(s => userInfo != null && userInfo.ProfileID.Value == s.ID).FirstOrDefault(); var profileEntity = lstProfile.Where(s => record.ProfileID != null && record.ProfileID.Value == s.ID).FirstOrDefault(); if (profileEntity != null) { var jobTitleEntity = lstJobTitle.Where(s => profileEntity.JobTitleID != null && s.ID == profileEntity.JobTitleID.Value).FirstOrDefault(); var orgEntity = lstOrg.Where(s => profileEntity.OrgStructureID != null && s.ID == profileEntity.OrgStructureID.Value).FirstOrDefault(); if (template != null) { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_SendMailApprovedCashAdvance/DetailTravelRequest/" + recordID + "#NewTab"; try { #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCECODE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_TOTALADVANCE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_REJECTLINK.ToString(), }; strsParaValues = new string[] { lastProfileEntity != null? lastProfileEntity.ProfileName : string.Empty, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileEntity.ProfileName, record.CashAdvanceName, record.Code != null ? record.Code:"" , totalItem.ToString(), "Đã được duyệt.", "", "" }; string body = LibraryService.ReplaceContentFile(typeTemplateApproved.Content, strsParaKey, strsParaValues); #endregion string titleMail = typeTemplateApproved.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { throw; } } } } return DataErrorCode.Success; } #endregion var approverEntity = repoFin_Approver.GetAll().Where(s => s.IsDelete == null && s.ID == userApprovedID).FirstOrDefault(); if (approverEntity != null && approverEntity.OrderNo != null) { var profileInfoEntity = lstProfile.Where(s => s.ID == approverEntity.ProfileID.Value).FirstOrDefault(); var jobTitleEntity = lstJobTitle.Where(s => profileInfoEntity.JobTitleID != null && s.ID == profileInfoEntity.JobTitleID.Value).FirstOrDefault(); var orgEntity = lstOrg.Where(s => profileInfoEntity.OrgStructureID != null && s.ID == profileInfoEntity.OrgStructureID.Value).FirstOrDefault(); var lastApprover = lstApprover.Where(s => s.ProfileID == approverEntity.ProfileID && s.ApprovedType == typeApprover && s.ApprovedID != null).OrderByDescending(s => s.OrderNo).FirstOrDefault(); var lstApproverByClaim = lstApprover.Where(s => s.ProfileID == approverEntity.ProfileID && s.ApprovedType == typeApprover && s.ApprovedID != null && s.OrderNo > approverEntity.OrderNo).OrderBy(s => s.OrderNo).ToList(); var nextApprover = new FIN_ApproverECLAIM(); foreach (var item in lstApproverByClaim) { if (approverEntity.OrderNo == item.OrderNo) { continue; } nextApprover = item; break; } #region Nguoi duyet cuoi if (lastApprover != null && lastApprover.OrderNo != null && lastApprover.OrderNo == approverEntity.OrderNo) { var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == approverEntity.ApprovedID.Value).FirstOrDefault(); if (userInfo != null) { var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); var profileRequester = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(approverEntity.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if (template != null) { try { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_SendMailApprovedCashAdvance/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessApprovedPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + Guid.Empty + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessRejectPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + approverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCECODE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_TOTALADVANCE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_REJECTLINK.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileInfoEntity != null ? profileInfoEntity.ProfileName : string.Empty, record.CashAdvanceName, record.Code, totalItem.ToString(), "", linkcontent, linkcontentReject }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { throw; } } } } #endregion // var nextApprover = repoFin_Approver.GetAll().Where(s => s.IsDelete == null && s.ProfileID == approverEntity.ProfileID && s.ApprovedType == typeApprover && s.OrderNo == approverEntity.OrderNo + 1).FirstOrDefault(); if (nextApprover != null) { var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == approverEntity.ApprovedID.Value).FirstOrDefault(); var nextUserInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == nextApprover.ApprovedID.Value).FirstOrDefault(); if (userInfo != null) { var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); var profileEntityForRecord = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(nextUserInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if (profileEntity != null) { if (template != null) { try { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_SendMailApprovedCashAdvance/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; var name = nextUserInfo != null ? nextUserInfo.UserInfoName : nextUserInfo.UserLogin; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessApprovedPage" + "?loginID=" + nextApprover.ApprovedID + "&userApprovedID=" + nextApprover.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessRejectPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + approverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCECODE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_TOTALADVANCE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_REJECTLINK.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileInfoEntity != null ? profileInfoEntity.ProfileName : string.Empty, record.CashAdvanceName, record.Code, totalItem.ToString(), "", linkcontent , linkcontentReject }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { return DataErrorCode.Error_NoConfigMail; } } } } } else { var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == approverEntity.ApprovedID.Value).FirstOrDefault(); if(userInfo != null) { var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if (profileEntity != null) { if(template != null) { try { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_SendMailApprovedCashAdvance/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessApprovedPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + Guid.Empty + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessRejectPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + approverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCECODE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_TOTALADVANCE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_REJECTLINK.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileInfoEntity != null ? profileInfoEntity.ProfileName : string.Empty, record.CashAdvanceName, record.Code, totalItem.ToString(), "", linkcontent , linkcontentReject }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { return DataErrorCode.Error_NoConfigMail; } } } } } } return DataErrorCode.Error; } }
public string ProcessSendMailForFirstApprove(string host, Guid userId, Guid recordID) { DataErrorCode status = DataErrorCode.Success; using (var context = new VnrHrmDataContext()) { var Services = new BaseService(); var UserLogin = string.Empty; string statusMess = string.Empty; string type = ApproveType.E_FIN_CashAdvance.ToString(); string typeApprover = FinApproverType.Fin_CashAdvance.ToString(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoSys_UserApprove = new CustomBaseRepository<Sys_UserApprove>(unitOfWork); var repoSys_UserInfo = new CustomBaseRepository<Sys_UserInfo>(unitOfWork); var lstUserInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null).ToList(); var userInfoEntity = lstUserInfo.Where(s => userId == s.ID).FirstOrDefault(); var repo_JobTitle = new CustomBaseRepository<Cat_JobTitle>(unitOfWork); var lstJobTitle = repo_JobTitle.GetAll().Where(s => s.IsDelete == null).ToList(); var repoOrg = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork); var lstOrg = repoOrg.GetAll().Where(s => s.IsDelete == null).ToList(); var repoProfile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var lstProfile = repoProfile.GetAll().Where(s => s.IsDelete == null).ToList(); var repoFIN_TravelRequest = new CustomBaseRepository<Fin_CashAdvance>(unitOfWork); var record = repoFIN_TravelRequest.FindBy(s => s.ID == recordID).FirstOrDefault(); if (record != null) { List<Guid> lstIds = new List<Guid>(); lstIds.Add(record.ID); ActionApprovedAll(lstIds, "E_REQUEST", userId); } var repoCashItem = new CustomBaseRepository<Fin_CashAdvanceItem>(unitOfWork); var totalItem = repoCashItem.GetAll().Where(s => s.IsDelete == null && s.CashAdvanceID != null && s.CashAdvanceID.Value == recordID).Sum(s => s.Amount); var repoFin_Approver = new CustomBaseRepository<FIN_ApproverECLAIM>(unitOfWork); var lstApprover = repoFin_Approver.GetAll().Where(s => s.IsDelete == null).ToList(); var repoSys_TemplateSendMail = new CustomBaseRepository<Sys_TemplateSendMail>(unitOfWork); string _typeTemplate = EnumDropDown.EmailType.E_REQUEST_CASHADVANCE.ToString(); var template = repoSys_TemplateSendMail.FindBy(s => s.Type == _typeTemplate).FirstOrDefault(); if (userInfoEntity != null) { var profileInfoEntity = lstProfile.Where(s => s.ID == userInfoEntity.ProfileID.Value).FirstOrDefault(); var jobTitleEntity = lstJobTitle.Where(s => profileInfoEntity.JobTitleID != null && s.ID == profileInfoEntity.JobTitleID.Value).FirstOrDefault(); var orgEntity = lstOrg.Where(s => profileInfoEntity.OrgStructureID != null && s.ID == profileInfoEntity.OrgStructureID.Value).FirstOrDefault(); var lstApproverByClaim = lstApprover.Where(s => s.ProfileID == userInfoEntity.ProfileID && s.ApprovedType == typeApprover && s.ApprovedID != null).OrderBy(s => s.OrderNo).ToList(); var approvedEntity = new FIN_ApproverECLAIM(); // var firstApprover = lstApprover.Where(s => s.ProfileID == userInfoEntity.ProfileID && s.ApprovedType == typeApprover).OrderBy(s => s.OrderNo).FirstOrDefault(); var firstApprover = lstApproverByClaim.FirstOrDefault(); foreach (var item in lstApproverByClaim) { if (firstApprover.OrderNo == item.OrderNo) { continue; } approvedEntity = item; break; } // var userIdSecondApprover = lstApprover.Where(s => s.ProfileID == userInfoEntity.ProfileID && s.ApprovedType == typeApprover && s.OrderNo == 2).FirstOrDefault(); var userIdSecondApprover = lstApprover.Where(s => s.ID == approvedEntity.ID).FirstOrDefault(); if (firstApprover != null) { var userEnityByProfileID = lstUserInfo.Where(s => s.ID == firstApprover.ApprovedID.Value).FirstOrDefault(); var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userEnityByProfileID.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if (profileEntity != null) { if (userIdSecondApprover != null) { if (template != null) { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_SendMailApprovedCashAdvance/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; var temp = lstUserInfo.Where(s => s.ID == userIdSecondApprover.ApprovedID.Value).FirstOrDefault(); var name = temp.UserInfoName != null ? temp.UserInfoName : temp.UserLogin; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessApprovedPage" + "?loginID=" + firstApprover.ApprovedID + "&userApprovedID=" + userIdSecondApprover.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_SendMailApprovedCashAdvance/ProcessRejectPage" + "?loginID=" + firstApprover.ApprovedID + "&userApprovedID=" + userIdSecondApprover.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCENAME.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_CASHADVANCECODE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_TOTALADVANCE.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_CASHADVANCE.E_REJECTLINK.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, userInfoEntity.UserInfoName, record.CashAdvanceName, record.Code, totalItem.ToString(), "", linkcontent, linkcontentReject }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); } } } } } return status.ToString(); } }
public DataErrorCode SendMaToNextApproved(string host, Guid recordID, Guid userApprovedID) { using (var context = new VnrHrmDataContext()) { string statusMess = string.Empty; var UserLogin = string.Empty; var Services = new BaseService(); string status = string.Empty; string typeApprover = FinApproverType.FIN_TravelRequest_Domestic.ToString(); // string typeApprover2 = FinApproverType.FIN_TravelRequest_External.ToString(); var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoSys_UserApprove = new CustomBaseRepository<Sys_UserApprove>(unitOfWork); var repoFin_Approver = new CustomBaseRepository<FIN_ApproverECLAIM>(unitOfWork); var lstApprover = repoFin_Approver.GetAll().Where(s => s.IsDelete == null).ToList(); var repo_JobTitle = new CustomBaseRepository<Cat_JobTitle>(unitOfWork); var lstJobTitle = repo_JobTitle.GetAll().Where(s => s.IsDelete == null).ToList(); var repoOrg = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork); var lstOrg = repoOrg.GetAll().Where(s => s.IsDelete == null).ToList(); var repoProfile = new CustomBaseRepository<Hre_Profile>(unitOfWork); var lstProfile = repoProfile.GetAll().Where(s => s.IsDelete == null).ToList(); var repoSys_UserInfo = new CustomBaseRepository<Sys_UserInfo>(unitOfWork); var repoSys_ConfigProcessApprove = new CustomBaseRepository<Sys_ConfigProcessApprove>(unitOfWork); var repoSys_TemplateSendMail = new CustomBaseRepository<Sys_TemplateSendMail>(unitOfWork); var repoFIN_TravelRequest = new CustomBaseRepository<FIN_TravelRequest>(unitOfWork); var record = repoFIN_TravelRequest.FindBy(s => s.ID == recordID).FirstOrDefault(); var repoFin_TravelRequestItem = new CustomBaseRepository<FIN_TravelRequestItem>(unitOfWork); var totalItem = repoFin_TravelRequestItem.FindBy(s => s.IsDelete == null && s.Description2.Contains("E_APPROVED") && s.TravelRequestID != null && s.TravelRequestID.Value == recordID).ToList(); string _typeTemplate = EnumDropDown.EmailType.E_REQUEST_TRAVELREQUEST.ToString(); var template = repoSys_TemplateSendMail.FindBy(s => s.Type == _typeTemplate).FirstOrDefault(); if (template == null) return DataErrorCode.Error_NoTemplateMail; #region KT nếu là nguoi duyet cuoi thì gui email lại cho người yêu cầu duyệt if (userApprovedID == Guid.Empty) { var flag = false; var des = string.Empty; foreach (var item in totalItem) { if(item.IsBookingHotel != null && item.IsBookingHotel == true) { flag = true; des = item.Description; } } if (record != null) { string _typeTemplateApproved = EnumDropDown.EmailType.E_APPROVED_TRAVELREQUEST.ToString(); var typeTemplateApproved = repoSys_TemplateSendMail.FindBy(s => s.IsDelete == null && s.Type == _typeTemplateApproved).FirstOrDefault(); if (typeTemplateApproved == null) { return DataErrorCode.Error_NoTemplateMail; } var lastApprover = lstApprover.Where(s => record.Type != null && s.ProfileID == record.ProfileID && s.ApprovedType == record.Type && s.ApprovedID != null).OrderByDescending(s => s.OrderNo).FirstOrDefault(); var userInfo = repoSys_UserInfo.FindBy(s => s.IsDelete == null && s.ID == lastApprover.ApprovedID.Value).FirstOrDefault(); var lastProfileEntity = lstProfile.Where(s => userInfo != null && userInfo.ProfileID.Value == s.ID).FirstOrDefault(); var profileEntity = lstProfile.Where(s => record.ProfileID != null && record.ProfileID.Value == s.ID).FirstOrDefault(); if (profileEntity != null) { var jobTitleEntity = lstJobTitle.Where(s => profileEntity.JobTitleID != null && s.ID == profileEntity.JobTitleID.Value).FirstOrDefault(); var orgEntity = lstOrg.Where(s => profileEntity.OrgStructureID != null && s.ID == profileEntity.OrgStructureID.Value).FirstOrDefault(); if(template != null) { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_ApprovedTravelRequest/DetailTravelRequest/" + recordID + "#NewTab"; try { #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTNAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTCODE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_REJECTLINK.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_ISBOOKINGHOTEL.ToString(), }; strsParaValues = new string[] { lastProfileEntity != null ? lastProfileEntity.ProfileName : string.Empty, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileEntity.ProfileName, record.TravelRequestName, record.TravelRequestCode != null ? record.TravelRequestCode:"" , "Đã được duyệt.", "", "", "Ghi chú: chuyến đi có yêu cầu đặt khách sạn " + des + "<br/>" + "Note: hotel booking is requested " + des }; string body = LibraryService.ReplaceContentFile(typeTemplateApproved.Content, strsParaKey, strsParaValues); #endregion string titleMail = typeTemplateApproved.Subject; if (flag == true) { List<string> CCMail = new List<string>(); CCMail.Add("*****@*****.**"); bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty, CCMail); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } else { bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } } catch (Exception ex) { throw; } } } } return DataErrorCode.Success; } #endregion var approverEntity = repoFin_Approver.GetAll().Where(s => s.IsDelete == null && s.ID == userApprovedID).FirstOrDefault(); if (approverEntity != null && approverEntity.OrderNo != null) { var profileInfoEntity = lstProfile.Where(s => s.ID == approverEntity.ProfileID.Value).FirstOrDefault(); var jobTitleEntity = lstJobTitle.Where(s => profileInfoEntity.JobTitleID != null && s.ID == profileInfoEntity.JobTitleID.Value).FirstOrDefault(); var orgEntity = lstOrg.Where(s => profileInfoEntity.OrgStructureID != null && s.ID == profileInfoEntity.OrgStructureID.Value).FirstOrDefault(); var lastApprover = lstApprover.Where(s => record.Type != null && s.ProfileID == approverEntity.ProfileID && s.ApprovedType == record.Type && s.ApprovedID != null).OrderByDescending(s => s.OrderNo).FirstOrDefault(); var lstApproverByClaim = lstApprover.Where(s => record.Type != null && s.ProfileID == approverEntity.ProfileID && s.ApprovedType == record.Type && s.ApprovedID != null && s.OrderNo > approverEntity.OrderNo).OrderBy(s => s.OrderNo).ToList(); var nextApproverEntity = new FIN_ApproverECLAIM(); foreach (var item in lstApproverByClaim) { if (approverEntity.OrderNo == item.OrderNo) { continue; } nextApproverEntity = item; break; } #region Nguoi duyet cuoi if (lastApprover != null && lastApprover.OrderNo != null && lastApprover.OrderNo == approverEntity.OrderNo) { var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == approverEntity.ApprovedID.Value).FirstOrDefault(); if (userInfo != null) { var des = string.Empty; foreach (var item in totalItem) { if (item.IsBookingHotel != null && item.IsBookingHotel == true) { des = item.Description; } } var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); var profileRequester = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(approverEntity.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if (template != null) { try { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_ApprovedTravelRequest/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessApprovedPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + Guid.Empty + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessRejectPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + approverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTNAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTCODE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_REJECTLINK.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_ISBOOKINGHOTEL.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileInfoEntity != null ? profileInfoEntity.ProfileName : string.Empty, record.TravelRequestName, record.TravelRequestCode, "", linkcontent, linkcontentReject, "Ghi chú: chuyến đi có yêu cầu đặt khách sạn " + des + "</br>" + "Note: hotel booking is requested" + des }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { throw; } } } } #endregion // var nextApprover = repoFin_Approver.GetAll().Where(s => s.IsDelete == null && s.ProfileID == approverEntity.ProfileID && (s.ApprovedType == typeApprover1 || s.ApprovedType == typeApprover2) && s.OrderNo == approverEntity.OrderNo + 1).FirstOrDefault(); var preApprover = repoFin_Approver.GetAll().Where(s => record.Type != null && s.IsDelete == null && s.ProfileID == approverEntity.ProfileID && s.ApprovedType == record.Type && s.OrderNo == approverEntity.OrderNo - 1).FirstOrDefault(); if (nextApproverEntity != null) { var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == approverEntity.ApprovedID.Value).FirstOrDefault(); var nextUserInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == nextApproverEntity.ApprovedID.Value).FirstOrDefault(); if (userInfo != null) { var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); var profileEntityForRecord = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(nextUserInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if (profileEntity != null) { if (template != null) { try { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_ApprovedTravelRequest/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; var name = nextUserInfo != null ? nextUserInfo.UserInfoName : nextUserInfo.UserLogin; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessApprovedPage" + "?loginID=" + nextApproverEntity.ApprovedID + "&userApprovedID=" + nextApproverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessRejectPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + approverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTNAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTCODE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_REJECTLINK.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_ISBOOKINGHOTEL.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileInfoEntity != null ? profileInfoEntity.ProfileName : string.Empty, record.TravelRequestName, record.TravelRequestCode, "", linkcontent, linkcontentReject, "" }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { return DataErrorCode.Error_NoConfigMail; } } } } } else { var userInfo = repoSys_UserInfo.GetAll().Where(s => s.IsDelete == null && s.ID == approverEntity.ApprovedID.Value).FirstOrDefault(); if (userInfo != null) { var profileEntity = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(userInfo.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref statusMess).FirstOrDefault(); if(profileEntity != null) { if(template != null) { try { string MailTo = profileEntity.Email; string urlClickHere = host + "#Hrm_Main_Web/Fin_ApprovedTravelRequest/DetailTravelRequest/" + recordID + "#NewTab"; string linkcontent = string.Empty; string linkcontentReject = string.Empty; linkcontent += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessApprovedPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + Guid.Empty + "&recordID=" + recordID + "'>đây" + "<a/>" + " để đồng ý."; linkcontentReject += "Nhấn vào " + "<a href='" + host + "Fin_ApprovedTravelRequest/ProcessRejectPage" + "?loginID=" + approverEntity.ApprovedID + "&userApprovedID=" + approverEntity.ID + "&recordID=" + recordID + "'>đây" + "<a/>" + " để từ chối."; #region magreData string[] strsParaKey = null; string[] strsParaValues = null; strsParaKey = new string[] { EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_PROFILENAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_JOBTITLE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_AREA.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_USERINFONAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTNAME.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_TRAVELREQUESTCODE.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_DENIES.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_LINKCONTENT.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_REJECTLINK.ToString(), EnumDropDown.EmailType_APPROVED_TRAVELREQUEST.E_ISBOOKINGHOTEL.ToString(), }; strsParaValues = new string[] { profileEntity.ProfileName, jobTitleEntity != null ? jobTitleEntity.JobTitleName : string.Empty, orgEntity != null ? orgEntity.OrgStructureName : string.Empty, profileInfoEntity != null ? profileInfoEntity.ProfileName : string.Empty, record.TravelRequestName, record.TravelRequestCode, "", linkcontent, linkcontentReject, "" }; string body = LibraryService.ReplaceContentFile(template.Content, strsParaKey, strsParaValues); #endregion string titleMail = template.Subject; bool isSuccess = Services.SendMail(titleMail, MailTo, body, string.Empty); if (isSuccess) return DataErrorCode.Success; else return DataErrorCode.Error; } catch (Exception ex) { return DataErrorCode.Error_NoConfigMail; } } } } } } return DataErrorCode.Success; } }