Skip to main content

Project Registration

Revision 1.3 (2026-01-20) - Added Follow-Up Workflows feature, simplified ReviewPreWorkProceduresForm commands Revision 1.2 (2026-01-17) - Added Command Confirmation Assignee Auto-Selection Revision 1.1 (2026-01-16) - Added Two-Step Dialog for task creation Revision 1.0 (2026-01-14) - Complete documentation with workflow integration

Feature Summary

Project Registration (การลงทะเบียนโครงการ) is a workflow feature that manages the approval process for new projects. It coordinates between Work Owner, Purchasing, and Contractor roles to complete project setup before work permits can be issued.

Key Capabilities:

  • Create and track project registration tasks
  • Multi-role workflow: Work Owner → Purchasing → Contractor → Approval
  • Document form management (Project Registration Form, Pre-Work Procedures Form)
  • Form edit permissions based on workflow state
  • Task assignment with email notifications
  • Workflow history and audit trail
  • Optional command support (planned) - Skip Purchasing if project has PO No.

Workflow Relationship:

Project Registration is the first workflow in the Safety App process:

  1. Work Owner creates registration task via Two-Step Dialog:
    • Has PR No.: Search and select existing project
    • No PR No.: Enter project name to create new project
  2. Workflow progresses through 8 states (see Workflow Documentation)
  3. Upon approval, project can proceed to Work Permit Workflow

Prerequisites:

  • For existing projects: Project must exist in Project Settings with PR.No assigned
  • For new projects: Work Owner can create project directly via Two-Step Dialog
  • Contractor must be configured with coordinator and supervisor

Two-Step Dialog for Task Creation

Added in Revision 1.1 (2026-01-16)

When Work Owner creates a Project Registration task, a two-step dialog guides them through project selection or creation.

Problem Solved

Original behavior created orphaned projects:

IssueOriginalNew (Two-Step Dialog)
When project createdImmediately on dialog openOnly after user submits
Project nameEmpty string ""User-provided (required)
Orphan riskHigh - user can abandonNone - no project until submit

User Flow

WO clicks "สร้างงาน" → Selects "ขึ้นทะเบียนโครงการ"

Dialog: "คุณมีเลขที่ใบขอซื้อ (PR No.) หรือไม่?"

├─ [มี PR No.] → Search by PR No. → Select project → Create task

└─ [ไม่มี PR No.] → Enter project name (required)
+ description (optional) → Create task + project

Two Scenarios

ScenarioHas PR No.?ActionResult
Case 1YesSearch existing project by PR No.Task linked to existing project
Case 2NoEnter project name + descriptionNew project created with task

Benefits Over Alternatives

Rejected OptionWhy Not Used
Lazy Project CreationMajor backend refactor, FK constraint issues, high risk
Scheduled Cleanup JobStill creates orphans temporarily, magic cleanup rules
Draft Status for ProjectsAdds project status complexity, requires updating all queries

Why Two-Step Dialog is Best:

  1. No orphaned projects - Project only created on explicit submission
  2. Clear user intent - User explicitly chooses their path
  3. Better data quality - Projects always have meaningful names
  4. Minimal risk - Frontend-focused change, backend receives optional params
  5. No cleanup needed - Unlike scheduled jobs, no delayed deletion logic

Implementation Details

Frontend:

FileChange
select-project-for-pr-dialog.component.tsNew dialog with 3 steps
my-tasks.component.tsRoutes PR task to new dialog
my-tasks.contract.tsAdded newProjectData to request

Backend:

FileChange
CreateTaskEndpoint.csAccepts optional NewProjectData
TaskLifecycleService.csUses provided name/description

i18n Keys

KeyThaiEnglish
tasks.pr.dialogTitleขึ้นทะเบียนโครงการProject Registration
tasks.pr.hasPrNoคุณมีเลขที่ใบขอซื้อ (PR No.) หรือไม่?Do you have a PR No.?
tasks.pr.searchExistingมี PR No. - ค้นหาโครงการHas PR No. - Search project
tasks.pr.createNewไม่มี PR No. - สร้างโครงการใหม่No PR No. - Create new project

Command Confirmation Assignee Auto-Selection

Added in Revision 1.2 (2026-01-17)

When executing workflow commands that require assigning to another user, the assignee dropdown now intelligently pre-selects based on Project data.

How It Works

Target RoleAuto-Selection LogicFallback
Work Ownerproject.workOwnerUserIdFirst user in list
Safety Officerproject.safetyOfficerUserIdFirst user in list
Workspace Ownerproject.workspaceOwnerUserIdFirst user in list
Other roles-First user in list

Command Types

TypeUse CaseAuto-Selection
AssigneeRequiredSingle assignee (e.g., Send to Purchasing)One dropdown
AllRequiredParallel approval (e.g., SO + WO review)Multiple dropdowns

Implementation Details

File: review-task-execute-command.component.ts

The dialog reads task.project to match user IDs:

  • For WO/SO/WAO: Pre-selects the user assigned to the project
  • For other roles: Defaults to first available user

Benefits

  1. Faster workflow - Correct assignee pre-selected
  2. Fewer errors - Users don't accidentally pick wrong person
  3. Respects project setup - Uses actual project team assignments

Follow-Up Workflow Creation

Added in Revision 1.3 (2026-01-20)

After final approval, optional follow-up workflows can be automatically created:

Follow-UpDefaultAssigned ToPurpose
JSA Preparation✅ CheckedContractor SupervisorRisk assessment for job site
Tool List Preparation✅ CheckedContractor SupervisorEquipment and tool inventory

How It Works

  1. Work Owner clicks Approve on ReviewPreWorkProceduresForm
  2. Confirmation dialog shows checkboxes for follow-up workflows
  3. Both workflows are checked by default
  4. User can uncheck to skip creation
  5. Selected workflows are created and assigned to Contractor Supervisor

Workflow Chaining

Implementation Details

Configuration is defined via FollowUpWorkflowConfig in the workflow definition.

Developer Reference

See .claude/rules/workflow-implementation.md in the repository root for the full pattern documentation.


Role Matrix

Revision 1.0 (2026-01-14) - Initial version

Feature-Level Access

ActionAdminPurchasingWork OwnerSafety OfficerWorkspace OwnerContractor
View all tasksOwn onlyAssigned only
Create task
Execute commandsOwn onlyOwn onlyOwn only
View task historyOwn onlyOwn onlyOwn only
Add notesOwn onlyOwn onlyOwn only
Delete taskOwn only

Workflow State Access

StateWho Can ActAvailable Commands
FillInProjectInfoWork OwnerSend to Purchasing, Cancel
FillInPurchasingInfoPurchasingSubmit Back
ReviewPurchasingInfoWork OwnerSend to Purchasing, Send to Contractor, Cancel
FillInPreWorkProceduresFormContractorAcknowledge Procedures
ReviewPreWorkProceduresFormWork OwnerApprove, Cancel

Note: ReviewPreWorkProceduresForm was simplified from 4 commands to 2 (Revision 1.3). "Send Back" commands removed because form validation and digital signature verification prevent incomplete approvals.

Form Edit Permissions by State

StateProjectRegistrationFormPreWorkProceduresForm
FillInProjectInfo✅ WorkOwner-
FillInPurchasingInfo✅ Purchasing-
ReviewPurchasingInfo✅ WorkOwner-
FillInPreWorkProceduresForm🔒 Locked✅ Contractor
ReviewPreWorkProceduresForm🔒 Locked🔒 Locked
Approved/Canceled🔒 Locked🔒 Locked

Legend:

  • ✅ = Can edit
  • 🔒 = Read-only (locked)
  • Own only = Can only access tasks where user is current assignee
  • Assigned only = Can only see tasks assigned to them

Backend Test Report

Location: backend/tests/http/project-registration/ (planned) Status: Test files to be created in Phase 6

API Endpoints

MethodEndpointDescriptionAuthorization
POST/api/tasks/searchSearch tasks by type, statusRealmBasic
GET/api/tasks/get/{id}Get task details with workflow stateRealmBasic
POST/api/tasks/createTaskCreate new workflow taskRealmBasic
POST/api/tasks/preExecuteCommandValidate and prepare commandRealmBasic
POST/api/tasks/executeCommandExecute workflow state transitionRealmBasic
POST/api/tasks/upload/formAttachmentUpload form attachmentRealmBasic
POST/api/tasks/remove/formAttachmentRemove form attachmentRealmBasic
POST/api/tasks/saveDocumentFormAuto-save form dataRealmBasic
POST/api/tasks/notes/createCreate task noteRealmBasic
PUT/api/tasks/notes/{noteId}Update task noteRealmBasic
DELETE/api/tasks/notes/{noteId}Delete task noteRealmBasic
POST/api/tasks/removeDelete task (Admin/Owner only)RealmBasic

Workflow-Specific Endpoints

MethodEndpointDescriptionAuthorization
GET/api/projects/searchByPrNoSearch project by PR.No for task creationProjectMgmt

Test Coverage (Planned)

PartSectionTestsDescription
ATask Creation6Create task with project link
ATask Get4Retrieve task with workflow state
BStandard Path8Full workflow: WO → Purchasing → WO → Contractor → WO → Approve
BSkip Path6Optional: WO → Contractor (skip Purchasing)
CCommands12All 6 commands with role validation
DForm Attachments4Upload/download/remove attachments
ENotes4Create/update/delete notes

Frontend Test Report

Location: frontend/e2e/features/project-registration/ (planned) Status: E2E tests to be created in Phase 6

Components

ComponentTypeDescription
review-task.component.tsSmartMain container component
review-task.service.tsServiceState management (to be migrated to rxResource)
review-task-toolbar.component.tsDumbCommand buttons and actions
review-task-form.component.tsDumbForm wrapper with tabs
review-task-workflow.component.tsDumbWorkflow visualization (stepper + diagram)
review-task-stepper.component.tsDumbHorizontal workflow stepper
review-task-transaction.component.tsDumbTask history/log table
review-task-note.component.tsDumbNotes section
workflow-svg-viewer.component.tsDumbSVG diagram viewer

Workflow Visualization Components

ComponentPurpose
StepperShows workflow progress with circular step indicators
Full DiagramSVG visualization of complete workflow
State Info CardsCurrent state and branch target information

E2E Test Plan (Phase 6)

Test IDDescription
TC-PR-E2E-001Work Owner creates task from project
TC-PR-E2E-002Work Owner sends to Purchasing
TC-PR-E2E-003Purchasing fills PO info and submits
TC-PR-E2E-004Work Owner reviews and sends to Contractor
TC-PR-E2E-005Contractor acknowledges procedures
TC-PR-E2E-006Work Owner approves registration
TC-PR-E2E-007Work Owner skips Purchasing (when has PO No.)
TC-PR-E2E-008Stepper shows correct state transitions
TC-PR-E2E-009Optional step shows dashed border
TC-PR-E2E-010Transaction log shows all state changes

Manual Test Cases

For comprehensive manual testing documentation, see: Project Registration Test Cases

Test Summary:

  • Standard Workflow Path (31 test cases)
  • Optional Path - Skip Purchasing (9 test cases)
  • Total: 40 test cases

Workflow States Reference

For complete workflow documentation including:

  • All 9 workflow states with Thai names
  • State transition diagram
  • Document form mappings
  • Form edit permissions matrix

See: Project Registration Workflow


Labels verified against:

  • review-task-toolbar.component.ts (command button labels)
  • review-task-stepper.component.ts (step labels)
  • review-task-transaction.component.ts (log table headers)
  • review-task-note.component.ts (notes section)
  • project-registration-state-metadata.config.ts (state names)