@page "/pcrb/{planNumber}"
@page "/pcrb/new"
@using System.Text
PCRB @planNumber
PCRB @planNumber
@if (pcrb is not null) {
@for (int i = 0; i < PCRB.Stages.Length; i++) {
Color color;
if (pcrb.CurrentStep > i || pcrb.CurrentStep == (PCRB.Stages.Length - 1)) {
color = Color.Success;
} else if (pcrb.CurrentStep == i) {
color = Color.Info;
} else {
color = Color.Dark;
}
string stageName = PCRB.Stages[i];
@stageName
}
bool pcrbIsSubmitted = pcrb.CurrentStep > 0 && pcrb.InsertTimeStamp > DateTimeUtilities.MIN_DT;
bool pcrbIsComplete = pcrb.ClosedDate < DateTimeUtilities.MAX_DT && pcrb.CurrentStep == (PCRB.Stages.Length - 1);
bool userIsOriginator = pcrb.OwnerID == authStateProvider.CurrentUser?.UserID;
bool userIsAdmin = authStateProvider.CurrentUser is null ? false : authStateProvider.CurrentUser.IsAdmin;
bool userIsApprover = UserIsApprover();
@if ((!pcrbIsSubmitted && !string.IsNullOrWhiteSpace(pcrb.Title) && (userIsOriginator || userIsAdmin)) ||
(!pcrbIsSubmitted && pcrb.PlanNumber > 0 && (userIsOriginator || userIsAdmin))) {
@if (!pcrbIsSubmitted && !string.IsNullOrWhiteSpace(pcrb.Title) && (userIsOriginator || userIsAdmin)) {
@if (saveInProcess) {
Processing
} else {
Save
}
}
@if (!pcrbIsSubmitted && pcrb.PlanNumber > 0 && (userIsOriginator || userIsAdmin)) {
@if (deleteInProcess) {
Processing
} else {
Delete
}
}
}
@if (!pcrbIsSubmitted && GetIncompleteFields().Count() > 0) {
IEnumerable incompleteFields = GetIncompleteFields();
StringBuilder errorBuilder = new();
errorBuilder.Append($"Incomplete fields: {incompleteFields.First()}");
for (int i = 1; i < incompleteFields.Count(); i++) {
errorBuilder.Append($", {incompleteFields.ElementAt(i)}");
}
@errorBuilder.ToString()
}
@foreach (User user in allActiveUsers.OrderBy(u => u.LastName)) {
}
@if (pcrb.PlanNumber > 0 && pcrb.CurrentStep > 0) {
@for (int i = 1; i < 4; i++) {
int current_i = i;
bool previousStageSubmitted = current_i == 1;
IEnumerable previousStageApprovals = approvals.Where(a => a.Step == (current_i - 1));
int previousStageUnsubmittedApprovalCount = previousStageApprovals.Where(a => a.AssignedDate <= DateTimeUtilities.MIN_DT).Count();
int previousStagePendingApprovalCount = previousStageApprovals.Where(a => a.ItemStatus == 0 && a.AssignedDate > DateTimeUtilities.MIN_DT).Count();
int previousStageApprovedApprovalCount = previousStageApprovals.Where(a => a.ItemStatus == 1).Count();
int previousStageDeniedApprovalCount = previousStageApprovals.Where(a => a.ItemStatus == -1).Count();
bool previousStageApproved = current_i == 1;
if (!previousStageApproved) {
if (previousStageApprovals.Count() > 0 && previousStageUnsubmittedApprovalCount == 0 &&
previousStagePendingApprovalCount == 0 && previousStageApprovedApprovalCount >= 4)
previousStageApproved = true;
}
if (!previousStageSubmitted) {
if (((previousStagePendingApprovalCount > 0 || previousStageApprovedApprovalCount >= 4) &&
previousStageDeniedApprovalCount < previousStageApprovals.Count()) || previousStageApproved)
previousStageSubmitted = true;
}
IEnumerable currentStageApprovals = approvals.Where(a => a.Step == current_i);
int currentStageUnsubmittedApprovalCount = currentStageApprovals.Where(a => a.AssignedDate <= DateTimeUtilities.MIN_DT).Count();
int currentStagePendingApprovalsCount = currentStageApprovals.Where(a => a.ItemStatus == 0 && a.AssignedDate > DateTimeUtilities.MIN_DT).Count();
int currentStageApprovedApprovalsCount = currentStageApprovals.Where(a => a.ItemStatus == 1).Count();
int currentStageDeniedApprovalsCount = currentStageApprovals.Where(a => a.ItemStatus == -1).Count();
bool currentStageApproved = currentStageApprovedApprovalsCount >= 4 && currentStageUnsubmittedApprovalCount == 0 &&
currentStagePendingApprovalsCount == 0;
bool currentStageSubmitted = (currentStageApprovals.Count() > 0 && currentStagePendingApprovalsCount > 0 &&
currentStageDeniedApprovalsCount < currentStageApprovals.Count()) || currentStageApproved;
IEnumerable currentStageAttachments = attachments.Where(a => a.Step == current_i);
bool previousStageHasOpenGatedActionItems = actionItems.Where(a => a.Step == (current_i - 1) &&
a.ClosedStatus == false &&
a.Gating == true).Count() > 0;
IEnumerable currentStageActionItems = actionItems.Where(a => a.Step == current_i);
int currentStagePendingActionItemCount = currentStageActionItems.Where(a => a.ClosedStatus == false).Count();
bool allActionItemsComplete = current_i < 3 || actionItems.Where(a => a.ClosedStatus == false).Count() == 0;
bool actionItemsAreComplete = actionItems.Where(a => a.ClosedStatus == false).Count() == 0;
bool attachmentsMissing = currentStageAttachments.Count() == 0;
bool actionItemsIncomplete = current_i < 3 && currentStagePendingActionItemCount > 0;
bool affectedDocumentsIncomplete = current_i == 3 && pcr3Documents.Where(d => d.CompletedByID <= 0).Count() > 0;
bool approvalsIncomplete = currentStageApprovals.Count() > 0 && currentStagePendingApprovalsCount > 0;
IEnumerable currentStageAttendees = attendees.Where(a => a.Step == current_i);
bool atLeastOneAttendeeAttended = currentStageAttendees.Where(a => a.Attended == true).Count() > 0;
@($"PCR {current_i}")
@if (previousStageSubmitted && (attachmentsMissing || actionItemsIncomplete ||
affectedDocumentsIncomplete || approvalsIncomplete)) {
StringBuilder sb = new();
int missingSectionCount = 0;
sb.Append("Incomplete sections: ");
if (attachmentsMissing) {
missingSectionCount++;
sb.Append("upload PCRB");
}
if (actionItemsIncomplete) {
if (missingSectionCount > 0) sb.Append(", ");
missingSectionCount++;
sb.Append("action items incomplete");
}
if (affectedDocumentsIncomplete) {
if (missingSectionCount > 0) sb.Append(", ");
missingSectionCount++;
sb.Append("affected documents not closed");
}
if (approvalsIncomplete) {
if (missingSectionCount > 0) sb.Append(", ");
sb.Append("approvals still pending");
}
@sb.ToString()
}
@if (actionItemsIncomplete) {
All actions must be completed before PCR3 is submitted for approval
}
@if (previousStageHasOpenGatedActionItems) {
This stage cannot be submitted for approval until previous stage's gated action items are closed
}
Supporting Documents
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && previousStageSubmitted && !currentStageSubmitted) {
@if (current_i == 1) {
Download PCRB Template
}
@if (attachmentUploadInProcess) {
Processing
} else {
Upload Document
}
}
File Name
Uploaded By
Uploaded Date
@context.FileName
@(context.UploadedBy is null ? string.Empty : context.UploadedBy.GetFullName())
@context.UploadDateTime.ToString("yyyy-MM-dd HH:mm")
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && previousStageSubmitted && !currentStageSubmitted) {
@if (deleteAttachmentInProcess) {
Deleting
} else {
Delete
}
}
@if (current_i < 3) {
Action Items
@if (!currentStageSubmitted && actionItems.Where(a => a.Step == current_i).Count() == 0) {
Add action items if applicable
}
@if (previousStageSubmitted && !currentStageSubmitted) {
New Action Item
}
@if (currentStagePendingActionItemCount > 0) {
Complete All Actions
}
Action
Responsible Person
Gating
Closed Date
@context.Name
@(context.ResponsiblePerson is null ? string.Empty : context.ResponsiblePerson.GetFullName())
@(context.Gating ? "Yes" : "No")
@DateTimeUtilities.GetDateAsStringMaxDefault(context.ClosedDate)
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && context.ClosedByID == 0) {
Update
@if (!currentStageSubmitted) {
Delete
}
}
} else {
int openPCR3Documents = pcr3Documents.Where(d => d.CompletedByID <= 0).Count();
Affected Documents
Document Type
Document Numbers
Comments
ECN#
Closed Date
Closed By
@context.DocType
@context.DocNumbers
@context.Comment
@if (string.IsNullOrWhiteSpace(context.GetEcnNumberString())) {
context.GetEcnNumberString();
} else {
@context.GetEcnNumberString()
}
@(DateTimeUtilities.GetDateAsStringMaxDefault(context.CompletedDate))
@(context.CompletedBy is null ? string.Empty : context.CompletedBy.GetFullName())
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && !currentStageSubmitted) {
Update
}
}
Attendees
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && !currentStageSubmitted) {
Add Attendee
Mark All Attended
}
Attendee Name
Attended?
@(context.Attendee is null ? string.Empty : context.Attendee.GetFullName())
Approvers
@if (!actionItemsAreComplete && current_i == 3) {
All actions must be completed before PCR3 is submitted for approval
}
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && previousStageApproved) {
@if (!currentStageSubmitted) {
Add Approver
}
@if (previousStageSubmitted && !currentStageSubmitted && currentStageAttachments.Count() > 0 &&
!affectedDocumentsIncomplete && allActionItemsComplete &&
!previousStageHasOpenGatedActionItems && atLeastOneAttendeeAttended) {
@if (submitInProcess) {
Submitting
} else {
Submit For Approval
}
}
}
Approver Name
Job Title
Status
Assigned Date
Disposition Date
Comments
@(context.User is null ? string.Empty : context.User.GetFullName())
@SubRoleCategoryItemToJobTitleConverter(context.SubRoleCategoryItem)
@GetApprovalStatus(context.ItemStatus)
@DateTimeUtilities.GetDateAsStringMinDefault(context.AssignedDate)
@DateTimeUtilities.GetDateAsStringMaxDefault(context.CompletedDate)
@context.Comments
@if (pcrb.ClosedDate >= DateTimeUtilities.MAX_DT && (currentStageUnsubmittedApprovalCount > 0 ||
currentStagePendingApprovalsCount > 0)) {
@if (context.ItemStatus == 0 && userIsAdmin) {
Update
}
@if ((current_i < 3 || pcr3Documents.Where(d=>d.CompletedByID == 0).Count() == 0) &&
(authStateProvider.CurrentUser is not null && context.UserID == authStateProvider.CurrentUser.UserID) &&
context.ItemStatus == 0 && context.AssignedDate > DateTimeUtilities.MIN_DT) {
Approve
Deny
}
}
}
}
}