PCRB follow up client side logic
This commit is contained in:
@ -34,36 +34,39 @@ public partial class PCRBSingle {
|
||||
private IEnumerable<PCRBAttachment> attachments = new List<PCRBAttachment>();
|
||||
private IEnumerable<PCRBActionItem> actionItems = new List<PCRBActionItem>();
|
||||
private IEnumerable<PCR3Document> pcr3Documents = new List<PCR3Document>();
|
||||
private IEnumerable<PCRBFollowUpComment> followUpComments = new List<PCRBFollowUpComment>();
|
||||
|
||||
private DateTime? followUpDate;
|
||||
|
||||
private IEnumerable<int> qualityApproverUserIds = new List<int>();
|
||||
|
||||
private IEnumerable<User> allActiveUsers = new List<User>();
|
||||
private User selectedOwner = null;
|
||||
|
||||
private bool userIsQA = false;
|
||||
|
||||
private bool processing = false;
|
||||
private bool saveInProcess = false;
|
||||
private bool deleteInProcess = false;
|
||||
private bool submitInProcess = false;
|
||||
private bool approvalInProcess = false;
|
||||
private bool denialInProcess = false;
|
||||
private bool recallInProcess = false;
|
||||
private bool attachmentUploadInProcess = false;
|
||||
private bool updateAttachmentInProcess = false;
|
||||
private bool deleteAttachmentInProcess = false;
|
||||
private bool addActionItemInProcess = false;
|
||||
|
||||
private string attachmentSearchString = "";
|
||||
|
||||
private string actionItemSearchString = "";
|
||||
private bool followUpSubmitInProcess = false;
|
||||
private bool followUpApproveInProcess = false;
|
||||
private bool followUpDenyInProcess = false;
|
||||
|
||||
protected override async Task OnParametersSetAsync() {
|
||||
processing = true;
|
||||
try {
|
||||
cache.Set("redirectUrl", $"pcrb/{planNumber}");
|
||||
|
||||
allActiveUsers = await userService.GetAllActiveUsers();
|
||||
|
||||
if (qualityApproverUserIds.Count() == 0)
|
||||
qualityApproverUserIds = await GetQualityApproverUserIds();
|
||||
|
||||
userIsQA = qualityApproverUserIds.Contains(authStateProvider.CurrentUser?.UserID ?? -1);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(planNumber) && Int32.TryParse(planNumber, out planNumberInt)) {
|
||||
pcrb = await pcrbService.GetPCRBByPlanNumber(planNumberInt, false);
|
||||
approvals = await approvalService.GetApprovalsForIssueId(planNumberInt, false);
|
||||
@ -71,6 +74,10 @@ public partial class PCRBSingle {
|
||||
attachments = await pcrbService.GetAttachmentsByPlanNumber(planNumberInt, false);
|
||||
actionItems = await pcrbService.GetActionItemsForPlanNumber(planNumberInt, false);
|
||||
pcr3Documents = await pcrbService.GetPCR3DocumentsForPlanNumber(planNumberInt, false);
|
||||
followUpComments = await pcrbService.GetFollowUpCommentsByPlanNumber(planNumberInt, false);
|
||||
|
||||
if (followUpDate is null)
|
||||
followUpDate = pcrb.FollowUps.Count() > 0 ? pcrb.FollowUps.First().FollowUpDate : DateTimeUtilities.MAX_DT;
|
||||
|
||||
List<Task> createPCR3DocumentTasks = new();
|
||||
if (pcr3Documents.Count() <= 0) {
|
||||
@ -117,9 +124,9 @@ public partial class PCRBSingle {
|
||||
|
||||
if (pcrb.OwnerID > 0) selectedOwner = await userService.GetUserByUserId(pcrb.OwnerID);
|
||||
|
||||
if (pcrb.CurrentStep > 0 && pcrb.CurrentStep < 4) {
|
||||
if (pcrb.CurrentStep > (int)PCRB.StagesEnum.Draft && pcrb.CurrentStep < (int)PCRB.StagesEnum.Complete) {
|
||||
bool stageHasAdvanced = false;
|
||||
for (int stage = pcrb.CurrentStep; stage < 4; stage++) {
|
||||
for (int stage = pcrb.CurrentStep; stage < (int)PCRB.StagesEnum.Complete; stage++) {
|
||||
int current_stage = stage;
|
||||
if (pcrb.CurrentStep == current_stage) {
|
||||
IEnumerable<Approval> currentStageApprovals = approvals.Where(a => a.Step == current_stage);
|
||||
@ -128,7 +135,7 @@ public partial class PCRBSingle {
|
||||
bool currentStageApproved = currentStageApprovedApprovalsCount >= 3 && currentStagePendingApprovalsCount == 0;
|
||||
|
||||
if (currentStageApproved) {
|
||||
if (pcrb.CurrentStep == 3) {
|
||||
if (pcrb.CurrentStep == (int)PCRB.StagesEnum.PCR3) {
|
||||
int openActionItemCount = actionItems.Where(a => a.ClosedByID == 0).Count();
|
||||
int openAffectedDocumentsCount = pcr3Documents.Where(d => d.CompletedByID == 0).Count();
|
||||
|
||||
@ -145,7 +152,7 @@ public partial class PCRBSingle {
|
||||
}
|
||||
|
||||
if (stageHasAdvanced) {
|
||||
if (pcrb.CurrentStep == 4) {
|
||||
if (pcrb.CurrentStep == (int)PCRB.StagesEnum.Complete) {
|
||||
pcrb.ClosedDate = DateTime.Now;
|
||||
|
||||
string message = $"PCRB# {pcrb.PlanNumber} - {pcrb.Title} is complete";
|
||||
@ -165,6 +172,34 @@ public partial class PCRBSingle {
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
}
|
||||
|
||||
if (pcrb.CurrentStep == (int)PCRB.StagesEnum.Complete && pcrb.FollowUps.Count() == 0) {
|
||||
PCRBFollowUp followUp = new() {
|
||||
PlanNumber = pcrb.PlanNumber,
|
||||
Step = (int)PCRB.StagesEnum.FollowUp,
|
||||
FollowUpDate = pcrb.ClosedDate.AddMonths(6)
|
||||
};
|
||||
|
||||
await pcrbService.CreateFollowUp(followUp);
|
||||
|
||||
pcrb = await pcrbService.GetPCRBByPlanNumber(pcrb.PlanNumber, true);
|
||||
|
||||
if (pcrb.FollowUps.Count() == 0)
|
||||
throw new Exception("unable to create follow up");
|
||||
|
||||
StateHasChanged();
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
|
||||
if (pcrb.CurrentStep == (int)PCRB.StagesEnum.Complete && pcrb.FollowUps.Count() > 0 &&
|
||||
DateTime.Now >= pcrb.FollowUps.First().FollowUpDate.AddDays(-15)) {
|
||||
pcrb.CurrentStep = (int)PCRB.StagesEnum.FollowUp;
|
||||
await pcrbService.UpdatePCRB(pcrb);
|
||||
pcrb = await pcrbService.GetPCRBByPlanNumber(pcrb.PlanNumber, true);
|
||||
|
||||
StateHasChanged();
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
} else {
|
||||
int ownerID = 0;
|
||||
string ownerName = string.Empty;
|
||||
@ -177,7 +212,7 @@ public partial class PCRBSingle {
|
||||
pcrb = new() {
|
||||
OwnerID = ownerID,
|
||||
OwnerName = ownerName,
|
||||
CurrentStep = 0
|
||||
CurrentStep = (int)PCRB.StagesEnum.Draft
|
||||
};
|
||||
}
|
||||
|
||||
@ -215,7 +250,7 @@ public partial class PCRBSingle {
|
||||
private bool PCRBReadyToSubmit(int step) {
|
||||
bool readyToSubmit = GetIncompleteFields().Count() <= 0;
|
||||
|
||||
readyToSubmit = readyToSubmit && pcrb.CurrentStep > 0;
|
||||
readyToSubmit = readyToSubmit && pcrb.CurrentStep > (int)PCRB.StagesEnum.Draft;
|
||||
|
||||
readyToSubmit = readyToSubmit && attachments.Where(a => a.Step == step).Count() > 0;
|
||||
|
||||
@ -241,7 +276,7 @@ public partial class PCRBSingle {
|
||||
pcrb.OwnerID = selectedOwner.UserID;
|
||||
pcrb.OwnerName = selectedOwner.GetFullName();
|
||||
|
||||
if (pcrb.CurrentStep == 0 && GetIncompleteFields().Count() <= 0)
|
||||
if (pcrb.CurrentStep == (int)PCRB.StagesEnum.Draft && GetIncompleteFields().Count() <= 0)
|
||||
pcrb.CurrentStep++;
|
||||
|
||||
if (initialPlanNumber <= 0) {
|
||||
@ -300,34 +335,54 @@ public partial class PCRBSingle {
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<int>> GetQualityApproverUserIds() {
|
||||
List<int> qualityApproverUserIds = new();
|
||||
|
||||
try {
|
||||
int roleId = await approvalService.GetRoleIdForRoleName("Module Manager");
|
||||
HashSet<int>? qualityApproverUserIds = cache.Get<HashSet<int>>("qualityApproverUserIds");
|
||||
|
||||
if (roleId <= 0) throw new Exception($"could not find Module Manager role ID");
|
||||
if (qualityApproverUserIds is null || qualityApproverUserIds.Count() == 0) {
|
||||
qualityApproverUserIds = new();
|
||||
|
||||
IEnumerable<SubRole> subRoles = await approvalService.GetSubRolesForSubRoleName("MMSubRole", roleId);
|
||||
int roleId = await approvalService.GetRoleIdForRoleName("Module Manager");
|
||||
|
||||
foreach (SubRole subRole in subRoles) {
|
||||
if (subRole.SubRoleCategoryItem.Equals("Quality", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (roleId <= 0) throw new Exception($"could not find Module Manager role ID");
|
||||
|
||||
IEnumerable<SubRole> subRoles = await approvalService.GetSubRolesForSubRoleName("MMSubRole", roleId);
|
||||
|
||||
foreach (SubRole subRole in subRoles) {
|
||||
if (subRole.SubRoleCategoryItem.Equals("Quality", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
IEnumerable<User> subRoleMembers = await approvalService.GetApprovalGroupMembers(subRole.SubRoleID);
|
||||
foreach (User user in subRoleMembers) qualityApproverUserIds.Add(user.UserID);
|
||||
}
|
||||
}
|
||||
|
||||
string roleName = "QA_PRE_APPROVAL";
|
||||
string subRoleName = "QA_PRE_APPROVAL";
|
||||
|
||||
roleId = await approvalService.GetRoleIdForRoleName(roleName);
|
||||
|
||||
if (roleId <= 0) throw new Exception($"could not find {roleName} role ID");
|
||||
|
||||
subRoles = await approvalService.GetSubRolesForSubRoleName(subRoleName, roleId);
|
||||
|
||||
foreach (SubRole subRole in subRoles) {
|
||||
IEnumerable<User> subRoleMembers = await approvalService.GetApprovalGroupMembers(subRole.SubRoleID);
|
||||
foreach (User user in subRoleMembers) qualityApproverUserIds.Add(user.UserID);
|
||||
}
|
||||
}
|
||||
|
||||
string roleName = "QA_PRE_APPROVAL";
|
||||
string subRoleName = "QA_PRE_APPROVAL";
|
||||
roleName = "QA_FINAL_APPROVAL";
|
||||
subRoleName = "QA_FINAL_APPROVAL";
|
||||
|
||||
roleId = await approvalService.GetRoleIdForRoleName(roleName);
|
||||
roleId = await approvalService.GetRoleIdForRoleName(roleName);
|
||||
|
||||
if (roleId <= 0) throw new Exception($"could not find {roleName} role ID");
|
||||
if (roleId <= 0) throw new Exception($"could not find {roleName} role ID");
|
||||
|
||||
subRoles = await approvalService.GetSubRolesForSubRoleName(subRoleName, roleId);
|
||||
subRoles = await approvalService.GetSubRolesForSubRoleName(subRoleName, roleId);
|
||||
|
||||
foreach (SubRole subRole in subRoles) {
|
||||
IEnumerable<User> subRoleMembers = await approvalService.GetApprovalGroupMembers(subRole.SubRoleID);
|
||||
foreach (User user in subRoleMembers) qualityApproverUserIds.Add(user.UserID);
|
||||
foreach (SubRole subRole in subRoles) {
|
||||
IEnumerable<User> subRoleMembers = await approvalService.GetApprovalGroupMembers(subRole.SubRoleID);
|
||||
foreach (User user in subRoleMembers) qualityApproverUserIds.Add(user.UserID);
|
||||
}
|
||||
|
||||
cache.Set("qualityApproverUserIds", qualityApproverUserIds);
|
||||
}
|
||||
|
||||
return qualityApproverUserIds;
|
||||
@ -445,9 +500,7 @@ public partial class PCRBSingle {
|
||||
Approval? latestQaPreApproval = currentStageApprovals
|
||||
.Where(a => a.SubRoleCategoryItem.Equals("QA Pre Approver"))
|
||||
.OrderByDescending(a => a.AssignedDate)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (latestQaPreApproval is null) throw new Exception("QA pre approval not found");
|
||||
.FirstOrDefault() ?? throw new Exception("QA pre approval not found");
|
||||
|
||||
bool qaPreApprovalDenied = latestQaPreApproval.ItemStatus == -1;
|
||||
if (qaPreApprovalDenied && currentStageUnsubmittedApprovalCount >= 3) {
|
||||
@ -493,9 +546,8 @@ public partial class PCRBSingle {
|
||||
await Task.WhenAll(createCopiedApprovalsTasks);
|
||||
} else {
|
||||
Approval? unassignedQaPreApproval = currentStageApprovals.Where(a => a.SubRoleCategoryItem.Equals("QA Pre Approver") &&
|
||||
a.AssignedDate <= DateTimeUtilities.MIN_DT).FirstOrDefault();
|
||||
|
||||
if (unassignedQaPreApproval is null) throw new Exception("unassigned QA pre approval not found");
|
||||
a.AssignedDate <= DateTimeUtilities.MIN_DT).FirstOrDefault() ??
|
||||
throw new Exception("unassigned QA pre approval not found");
|
||||
|
||||
unassignedQaPreApproval.AssignedDate = DateTime.Now;
|
||||
await approvalService.UpdateApproval(unassignedQaPreApproval);
|
||||
@ -505,7 +557,7 @@ public partial class PCRBSingle {
|
||||
|
||||
await pcrbService.NotifyNewApprovals(pcrb);
|
||||
|
||||
if (pcrb.CurrentStep == 1) {
|
||||
if (pcrb.CurrentStep == (int)PCRB.StagesEnum.PCR1) {
|
||||
pcrb.InsertTimeStamp = DateTime.Now;
|
||||
await pcrbService.UpdatePCRB(pcrb);
|
||||
|
||||
@ -525,23 +577,6 @@ public partial class PCRBSingle {
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetUserForApproval(Approval approval, User user) {
|
||||
if (approval is null) throw new ArgumentNullException("approval cannot be null");
|
||||
if (user is null) throw new ArgumentNullException("user cannot be null");
|
||||
|
||||
if (approval.CompletedDate < DateTimeUtilities.MAX_DT || approval.ItemStatus != 0)
|
||||
throw new ArgumentException("cannot reassign a complete approval");
|
||||
|
||||
approval.UserID = user.UserID;
|
||||
approval.User = user;
|
||||
approval.NotifyDate = DateTimeUtilities.MIN_DT;
|
||||
|
||||
await approvalService.UpdateApproval(approval);
|
||||
await approvalService.GetApprovalsForIssueId(approval.IssueID, true);
|
||||
|
||||
await pcrbService.NotifyNewApprovals(pcrb);
|
||||
}
|
||||
|
||||
private async Task ApprovePCR(int step) {
|
||||
if (!processing) {
|
||||
try {
|
||||
@ -1136,4 +1171,328 @@ public partial class PCRBSingle {
|
||||
if (itemStatus > 0) return "Approved";
|
||||
return "Pending";
|
||||
}
|
||||
|
||||
private async Task UpdateFollowUpDate(DateTime? newFollowUpDate) {
|
||||
if (followUpDate is not null || followUpDate <= DateTimeUtilities.MAX_DT) {
|
||||
try {
|
||||
if (newFollowUpDate is null)
|
||||
throw new Exception("follow up date cannot be null");
|
||||
|
||||
if (authStateProvider.CurrentUser is null) {
|
||||
snackbar.Add("You must log in to change the follow up date", Severity.Error);
|
||||
await authStateProvider.Logout();
|
||||
return;
|
||||
}
|
||||
|
||||
DateTime oldFollowUpDate = pcrb.FollowUps.First().FollowUpDate;
|
||||
|
||||
followUpDate = newFollowUpDate;
|
||||
pcrb.FollowUps.First().FollowUpDate = (DateTime)newFollowUpDate;
|
||||
await pcrbService.UpdateFollowUp(pcrb.FollowUps.First());
|
||||
|
||||
pcrb = await pcrbService.GetPCRBByPlanNumber(pcrb.PlanNumber, true);
|
||||
|
||||
string comments = "";
|
||||
|
||||
DialogParameters<Comments> parameters = new DialogParameters<Comments> { { x => x.comments, comments } };
|
||||
var dialog = await dialogService.ShowAsync<Comments>($"Follow Up Date Change Comment", parameters);
|
||||
|
||||
DialogResult? result = await dialog.Result;
|
||||
|
||||
if (result is null || result.Canceled || result.Data is null || string.IsNullOrWhiteSpace(result.Data?.ToString())) {
|
||||
followUpDate = oldFollowUpDate;
|
||||
pcrb.FollowUps.First().FollowUpDate = oldFollowUpDate;
|
||||
await pcrbService.UpdateFollowUp(pcrb.FollowUps.First());
|
||||
|
||||
pcrb = await pcrbService.GetPCRBByPlanNumber(pcrb.PlanNumber, true);
|
||||
|
||||
throw new Exception("you must provide a comment");
|
||||
}
|
||||
|
||||
comments = result.Data?.ToString() ?? string.Empty;
|
||||
|
||||
comments = comments.Trim();
|
||||
|
||||
StringBuilder commentBuilder = new();
|
||||
|
||||
commentBuilder.Append($"Changing follow up date from {oldFollowUpDate.ToString("MM/dd/yyyy")} ");
|
||||
commentBuilder.Append($"to {pcrb.FollowUps.First().FollowUpDate.ToString("MM/dd/yyyy")}. Comments: {comments}");
|
||||
|
||||
PCRBFollowUpComment comment = new() {
|
||||
PlanNumber = pcrb.FollowUps.First().PlanNumber,
|
||||
FollowUpID = pcrb.FollowUps.First().ID,
|
||||
Comment = commentBuilder.ToString(),
|
||||
UserID = authStateProvider.CurrentUser.UserID
|
||||
};
|
||||
|
||||
await pcrbService.CreateFollowUpComment(comment);
|
||||
|
||||
DateTime fifteenDaysFromNow = DateTime.Now.AddDays(15);
|
||||
|
||||
if (pcrb.FollowUps.First().FollowUpDate > fifteenDaysFromNow) {
|
||||
IEnumerable<Approval> step5Approvals = approvals.Where(a => a.Step == 5 && a.ItemStatus == 0);
|
||||
foreach (Approval approval in step5Approvals) {
|
||||
await approvalService.DeleteApproval(approval.ApprovalID);
|
||||
await approvalService.GetApprovalsForUserId(approval.UserID, true);
|
||||
}
|
||||
|
||||
approvals = await approvalService.GetApprovalsForIssueId(pcrb.PlanNumber, true);
|
||||
} else if (approvals.Where(a => a.Step == 5 && a.ItemStatus == 0).Count() == 0) {
|
||||
Approval newApproval = new Approval {
|
||||
IssueID = pcrb.PlanNumber,
|
||||
RoleName = "PCRB Owner Follow Up",
|
||||
SubRole = "PCRBOwnerFollowUp",
|
||||
SubRoleCategoryItem = "PCRB Owner Follow Up",
|
||||
UserID = pcrb.OwnerID,
|
||||
SubRoleID = 999,
|
||||
AssignedDate = DateTime.Now,
|
||||
TaskID = pcrb.FollowUps.First().ID,
|
||||
Step = 5,
|
||||
NotifyDate = DateTime.Now
|
||||
};
|
||||
|
||||
await approvalService.CreateApproval(newApproval);
|
||||
}
|
||||
|
||||
commentBuilder.Clear();
|
||||
commentBuilder.Append($"Effectiveness review date for PCRB# {pcrb.PlanNumber} - {pcrb.Title} has been changed to ");
|
||||
commentBuilder.Append($"{pcrb.FollowUps.First().FollowUpDate.ToString("MM/dd/yyyy")}. ");
|
||||
|
||||
PCRBNotification notification = new() {
|
||||
Message = commentBuilder.ToString(),
|
||||
Subject = $"[PCRB Effectiveness Review Date Change] {pcrb.PlanNumber} - {pcrb.Title}",
|
||||
PCRB = pcrb,
|
||||
NotifyQaPreApprover = true
|
||||
};
|
||||
|
||||
await pcrbService.NotifyOriginator(notification);
|
||||
} catch (Exception ex) {
|
||||
snackbar.Add($"Unable to update follow up date, because {ex.Message}", Severity.Error);
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SubmitFollowUpForApproval() {
|
||||
if (!followUpSubmitInProcess) {
|
||||
try {
|
||||
followUpSubmitInProcess = true;
|
||||
|
||||
if (pcrb.FollowUps.Count() > 0) {
|
||||
PCRBFollowUp followUp = pcrb.FollowUps.First();
|
||||
followUp.IsPendingApproval = true;
|
||||
await pcrbService.UpdateFollowUp(followUp);
|
||||
|
||||
List<SubRole> allSubRoles = new();
|
||||
|
||||
int roleId = await approvalService.GetRoleIdForRoleName("Module Manager");
|
||||
|
||||
if (roleId <= 0) throw new Exception($"could not find Module Manager role ID");
|
||||
|
||||
List<SubRole> qualityMMSubRoles = (await approvalService.GetSubRolesForSubRoleName("MMSubRole", roleId)).ToList();
|
||||
|
||||
foreach (SubRole subRole in qualityMMSubRoles) {
|
||||
if (subRole.SubRoleCategoryItem.Equals("Quality"))
|
||||
allSubRoles.Add(subRole);
|
||||
}
|
||||
|
||||
roleId = await approvalService.GetRoleIdForRoleName("QA_FINAL_APPROVAL");
|
||||
|
||||
if (roleId <= 0) throw new Exception($"could not find QA Final Approval role ID");
|
||||
|
||||
IEnumerable<SubRole> qaFinalApprovalSubRoles =
|
||||
(await approvalService.GetSubRolesForSubRoleName("QA_FINAL_APPROVAL", roleId)).ToList();
|
||||
|
||||
foreach (SubRole subRole in qaFinalApprovalSubRoles)
|
||||
allSubRoles.Add(subRole);
|
||||
|
||||
foreach (SubRole subRole in allSubRoles) {
|
||||
IEnumerable<User> subRoleMembers = await approvalService.GetApprovalGroupMembers(subRole.SubRoleID);
|
||||
|
||||
foreach (User member in subRoleMembers) {
|
||||
Approval approval = new() {
|
||||
IssueID = pcrb.PlanNumber,
|
||||
RoleName = subRole.SubRoleCategoryItem,
|
||||
SubRole = subRole.SubRoleName,
|
||||
UserID = member.UserID,
|
||||
SubRoleID = subRole.SubRoleID,
|
||||
AssignedDate = DateTime.Now,
|
||||
Step = followUp.Step,
|
||||
TaskID = followUp.ID
|
||||
};
|
||||
|
||||
await approvalService.CreateApproval(approval);
|
||||
|
||||
approvals = await approvalService.GetApprovalsForIssueId(pcrb.PlanNumber, true);
|
||||
|
||||
approval = approvals.Where(a => a.TaskID == followUp.ID &&
|
||||
a.RoleName.Equals(subRole.SubRoleCategoryItem) &&
|
||||
a.UserID == member.UserID &&
|
||||
a.Step == followUp.Step).First();
|
||||
|
||||
PCRBNotification notification = new() {
|
||||
PCRB = pcrb,
|
||||
Subject = $"[PCRB Follow Up] {pcrb.PlanNumber} - {pcrb.Title}",
|
||||
Message = $"Follow up for PCRB# {pcrb.PlanNumber} - {pcrb.Title} has been submitted for closure.",
|
||||
Approval = approval
|
||||
};
|
||||
|
||||
await pcrbService.NotifyApprover(notification);
|
||||
}
|
||||
}
|
||||
|
||||
string comments = "Submitted for closure";
|
||||
|
||||
PCRBFollowUpComment comment = new() {
|
||||
PlanNumber = followUp.PlanNumber,
|
||||
FollowUpID = followUp.ID,
|
||||
Comment = comments,
|
||||
UserID = authStateProvider.CurrentUser.UserID
|
||||
};
|
||||
|
||||
await pcrbService.CreateFollowUpComment(comment);
|
||||
|
||||
snackbar.Add("Follow up submitted for closure", Severity.Success);
|
||||
} else {
|
||||
throw new Exception("no follow ups available to mark as pending closure");
|
||||
}
|
||||
|
||||
followUpSubmitInProcess = false;
|
||||
} catch (Exception ex) {
|
||||
followUpSubmitInProcess = false;
|
||||
snackbar.Add($"Unable to submit follow up for closure, because {ex.Message}", Severity.Error);
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApproveFollowUp() {
|
||||
if (!followUpApproveInProcess) {
|
||||
try {
|
||||
followUpApproveInProcess = true;
|
||||
|
||||
IEnumerable<Approval> step5Approvals = approvals.Where(a => a.Step == 5 && a.ItemStatus == 0);
|
||||
foreach (Approval approval in step5Approvals) {
|
||||
approval.ItemStatus = 1;
|
||||
approval.Comments = "Follow up complete";
|
||||
approval.CompletedDate = DateTime.Now;
|
||||
await approvalService.UpdateApproval(approval);
|
||||
}
|
||||
|
||||
foreach (PCRBFollowUp? followUp in pcrb.FollowUps.Where(f => !f.IsComplete)) {
|
||||
followUp.IsComplete = true;
|
||||
followUp.IsPendingApproval = false;
|
||||
followUp.CompletedDate = DateTime.Now;
|
||||
await pcrbService.UpdateFollowUp(followUp);
|
||||
}
|
||||
|
||||
pcrb.CurrentStep = (int)PCRB.StagesEnum.Closed;
|
||||
await pcrbService.UpdatePCRB(pcrb);
|
||||
|
||||
string comments = "Follow up complete";
|
||||
|
||||
PCRBFollowUpComment comment = new() {
|
||||
PlanNumber = pcrb.PlanNumber,
|
||||
FollowUpID = pcrb.FollowUps.First().ID,
|
||||
Comment = comments,
|
||||
UserID = authStateProvider.CurrentUser.UserID
|
||||
};
|
||||
|
||||
await pcrbService.CreateFollowUpComment(comment);
|
||||
|
||||
PCRBNotification notification = new() {
|
||||
PCRB = pcrb,
|
||||
Message = $"Follow up for PCRB# {pcrb.PlanNumber} - {pcrb.Title} has been closed."
|
||||
};
|
||||
|
||||
await pcrbService.NotifyOriginator(notification);
|
||||
|
||||
followUpApproveInProcess = false;
|
||||
|
||||
snackbar.Add("Follow up successfully approved", Severity.Success);
|
||||
} catch (Exception ex) {
|
||||
followUpApproveInProcess = false;
|
||||
snackbar.Add($"Unable to approve follow up, because {ex.Message}", Severity.Error);
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DenyFollowUp(string action) {
|
||||
if (!followUpDenyInProcess) {
|
||||
try {
|
||||
string pastAction = action.ToLower().Equals("recall") ? "recalled" : "rejected";
|
||||
|
||||
followUpDenyInProcess = true;
|
||||
|
||||
string comments = "";
|
||||
|
||||
DialogParameters<Comments> parameters = new DialogParameters<Comments> { { x => x.comments, comments } };
|
||||
var dialog = await dialogService.ShowAsync<Comments>($"Follow Up {action} Comment", parameters);
|
||||
|
||||
DialogResult? result = await dialog.Result;
|
||||
|
||||
if (result is null || result.Canceled || result.Data is null || string.IsNullOrWhiteSpace(result.Data?.ToString())) {
|
||||
throw new Exception("you must provide a comment");
|
||||
}
|
||||
|
||||
comments = result.Data?.ToString() ?? string.Empty;
|
||||
|
||||
comments = comments.Trim();
|
||||
|
||||
IEnumerable<Approval> step5Approvals = approvals.Where(a => a.Step == 5 &&
|
||||
a.ItemStatus == 0 &&
|
||||
a.UserID != pcrb.OwnerID);
|
||||
foreach (Approval approval in step5Approvals) {
|
||||
approval.ItemStatus = -1;
|
||||
approval.CompletedDate = DateTime.Now;
|
||||
approval.Comments = comments is null ? string.Empty : comments;
|
||||
await approvalService.UpdateApproval(approval);
|
||||
}
|
||||
|
||||
foreach (var followUp in pcrb.FollowUps.Where(f => f.IsPendingApproval)) {
|
||||
followUp.IsPendingApproval = false;
|
||||
await pcrbService.UpdateFollowUp(followUp);
|
||||
}
|
||||
|
||||
StringBuilder messageBuilder = new();
|
||||
messageBuilder.Append($"Follow up for PCRB# {pcrb.PlanNumber} - {pcrb.Title} has been {pastAction}. ");
|
||||
messageBuilder.Append($"Please review the comments and make the necessary revisions. Comments: {comments}");
|
||||
|
||||
PCRBNotification notification = new() {
|
||||
PCRB = pcrb,
|
||||
Message = messageBuilder.ToString()
|
||||
};
|
||||
|
||||
await pcrbService.NotifyOriginator(notification);
|
||||
|
||||
comments = $"Follow up {pastAction}. Comments: {comments}";
|
||||
|
||||
PCRBFollowUpComment comment = new() {
|
||||
PlanNumber = pcrb.PlanNumber,
|
||||
FollowUpID = pcrb.FollowUps.First().ID,
|
||||
Comment = comments,
|
||||
UserID = authStateProvider.CurrentUser.UserID
|
||||
};
|
||||
|
||||
await pcrbService.CreateFollowUpComment(comment);
|
||||
|
||||
followUpDenyInProcess = false;
|
||||
|
||||
snackbar.Add($"Follow up successfully {pastAction}", Severity.Success);
|
||||
} catch (Exception ex) {
|
||||
followUpDenyInProcess = false;
|
||||
snackbar.Add($"Unable to {action.ToLower()} follow up, because {ex.Message}", Severity.Error);
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
await OnParametersSetAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user