[CLAUDE] Workflow: State machine 5 trạng thái — Trả lại = Phase riêng
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m17s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m17s
Session 17 spec: chốt 5 trạng thái phiếu PE/HĐ/Budget theo state diagram:
Nháp ─trình──► Đã gửi duyệt ─approve cấp cuối──► Đã duyệt (terminal)
├─ Trả lại ────────► Trả lại
└─ Từ chối ────────► Từ chối (terminal)
Trả lại ──Drafter sửa+gửi lại──► Đã gửi duyệt (chạy LẠI từ đầu)
Khác Mig 21 (Session 16): bỏ smart-reject jump-back. Trả lại = Phase
RIÊNG (TraLai=98), không revert về DangSoanThao + không jump-back step.
Drafter từ TraLai gửi lại như case Nháp — workflow chạy lại từ Cấp 1
Bước 1 (Option A diagram chốt với user).
BE Domain:
- ContractPhase + TraLai = 98
- BudgetPhase + TraLai = 98
- PurchaseEvaluationPhase: TraLai=98 đổi từ [LEGACY deprecated] thành
primary state. Comment update enum docs cho cả 3.
BE Policy (PE/HĐ/Budget):
- Reject transitions trỏ về TraLai (thay DangSoanThao)
- Mirror entry transitions: TraLai → next phase (cho Drafter resubmit)
- ActivePhases thêm TraLai
- FromDefinition mirror: TraLai → step.Phase + reject → TraLai
- DefaultSla cho TraLai = same as DangSoanThao
BE Service (PE + Contract):
- Reject branch: target=TuChoi giữ; else set Phase=TraLai, clear
CurrentWorkflowStepIndex=null
- Bỏ ResumeAfterReject branch + RejectedAtStepIndex/RejectedFromPhase
assignment (DB column giữ deprecated cho data cũ)
- Drafter trình branch: từ DangSoanThao HOẶC TraLai → ChoDuyet, init
CurrentWorkflowStepIndex=0 (cùng entry point, chạy lại từ đầu)
- Notification: TraLai when fromPhase=ChoDuyet → "bị trả lại"
- Budget Handler: simplify reject → TraLai, bỏ smart-reject + isResuming
BE Tests update:
- WorkflowPolicyTests: Standard_RejectFromCCM → TraLai (rename + assert)
+ Standard_TraLai_To_DangGopY_Allowed_For_Drafter (new)
- PurchaseEvaluationPolicyTests: BothPolicies_RejectFromCCM → TraLai
+ BothPolicies_TraLai_To_ChoPurchasing_AllowedForDrafter (new theory)
- BudgetPolicyTests: Default_CostControl_ChoCCM_To_TraLai (rename)
+ ActivePhases All6States (was All5) + NextPhasesFrom_TraLai (new)
+ NextPhasesFrom_ChoCEO_Includes_DaDuyet_And_TraLai (rename)
- 77 → 81 test pass (+4 tests TraLai entry point)
FE rename "Bản nháp" → "Nháp" (cả 2 app + types):
- types/purchaseEvaluation.ts: PurchaseEvaluationPhaseLabel 1=Nháp,
10=Đã gửi duyệt. PeDisplayStatus.BanNhap → Nhap (key + value).
PhaseLabel/Color cho TraLai update active.
- types/contracts.ts: +ChoDuyet=10, +TraLai=98 const + label/color.
Phase 2 'Đang soạn thảo' → 'Nháp'.
- types/budget.ts: +TraLai=98 const + label/color. Phase 1 → 'Nháp'.
- PeListPanel + PurchaseEvaluationsListPage filter dropdown: Nhap +
TraLai map đúng phase value.
BE label maps update consistent:
- ContractExcelExporter PhaseLabel: DangSoanThao → "Nháp" + add ChoDuyet/
TraLai entries.
- PeWorkflowAdminFeatures + WorkflowAdminFeatures PhaseLabels: same.
Verify: dotnet test 81 pass · npm build × 2 app pass · BE 0 error.
Field RejectedAtStepIndex/RejectedFromPhase giữ DB column (nullable,
không set value mới). Cleanup migration sau.
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
namespace SolutionErp.Domain.Contracts;
|
||||
|
||||
// State machine HĐ — Session 16 drastic refactor (Mig 21):
|
||||
// DangSoanThao → ChoDuyet (Drafter trình, init CurrentWorkflowStepIndex=0)
|
||||
// ChoDuyet → ChoDuyet (advance step pointer per approve)
|
||||
// ChoDuyet → DaPhatHanh (last step done — terminal)
|
||||
// ChoDuyet → DangSoanThao (Trả lại — save RejectedAtStepIndex, Drafter sửa)
|
||||
// ChoDuyet → TuChoi (Từ chối — terminal khoá)
|
||||
// State machine HĐ — Session 17 spec mới (5 trạng thái):
|
||||
// DangSoanThao (Nháp) ──Drafter trình──► ChoDuyet
|
||||
// TraLai (Trả lại) ──Drafter sửa+gửi lại──► ChoDuyet (chạy lại từ Cấp 1 Bước 1)
|
||||
// ChoDuyet (Đã gửi duyệt) ──advance step pointer──► ChoDuyet
|
||||
// ──last step done──────────► DaPhatHanh (terminal + gen mã HĐ)
|
||||
// ──Approver Trả lại────────► TraLai
|
||||
// ──Approver Từ chối────────► TuChoi (terminal)
|
||||
//
|
||||
// LEGACY values (DangChon, DangGopY, DangDamPhan, DangInKy, DangKiemTraCCM,
|
||||
// DangTrinhKy, DangDongDau) deprecated post-Mig 21 — giữ enum cho data cũ.
|
||||
// TraLai=98: Session 17 thêm mới — Trả lại là Phase RIÊNG (mirror PE).
|
||||
public enum ContractPhase
|
||||
{
|
||||
DangChon = 1, // [LEGACY]
|
||||
DangSoanThao = 2,
|
||||
DangSoanThao = 2, // Nháp
|
||||
DangGopY = 3, // [LEGACY]
|
||||
DangDamPhan = 4, // [LEGACY]
|
||||
DangInKy = 5, // [LEGACY]
|
||||
DangKiemTraCCM = 6, // [LEGACY]
|
||||
DangTrinhKy = 7, // [LEGACY]
|
||||
DangDongDau = 8, // [LEGACY]
|
||||
DaPhatHanh = 9, // terminal thành công (= DaDuyet cho HĐ)
|
||||
ChoDuyet = 10, // [Mig 21] generic intermediate, dùng CurrentWorkflowStepIndex tracking
|
||||
TuChoi = 99, // terminal khoá
|
||||
DaPhatHanh = 9, // Đã duyệt (cho HĐ — gen mã + phát hành) — terminal thành công
|
||||
ChoDuyet = 10, // Đã gửi duyệt — generic intermediate, CurrentWorkflowStepIndex tracking
|
||||
TraLai = 98, // Trả lại — Phase riêng, Drafter sửa rồi gửi lại chạy từ đầu
|
||||
TuChoi = 99, // Từ chối — terminal khoá
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ public static class WorkflowPolicies
|
||||
private static readonly Dictionary<ContractPhase, TimeSpan?> DefaultSla = new()
|
||||
{
|
||||
[ContractPhase.DangSoanThao] = TimeSpan.FromDays(7),
|
||||
[ContractPhase.TraLai] = TimeSpan.FromDays(7),
|
||||
[ContractPhase.DangGopY] = TimeSpan.FromDays(7),
|
||||
[ContractPhase.DangDamPhan] = TimeSpan.FromDays(7),
|
||||
[ContractPhase.DangInKy] = TimeSpan.FromDays(1),
|
||||
@ -65,6 +66,8 @@ public static class WorkflowPolicies
|
||||
|
||||
// ===== STANDARD: 9-phase formal workflow =====
|
||||
// Per QT-TP-NCC.docx: Thầu phụ / NCC / Tổ đội — full CCM review required.
|
||||
// Session 17: Reject = về TraLai (Phase riêng). Drafter từ TraLai gửi lại
|
||||
// = entry point thứ 2 (mirror DangSoanThao → DangGopY).
|
||||
public static readonly WorkflowPolicy Standard = new(
|
||||
Name: "Standard",
|
||||
Description: "Quy trình đầy đủ 8 phase — CCM kiểm tra + BOD duyệt. Áp dụng HĐ Thầu phụ / NCC / Giao khoán.",
|
||||
@ -72,26 +75,28 @@ public static class WorkflowPolicies
|
||||
{
|
||||
[(ContractPhase.DangSoanThao, ContractPhase.DangGopY)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.DangSoanThao, ContractPhase.TuChoi)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.TraLai, ContractPhase.DangGopY)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.TraLai, ContractPhase.TuChoi)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
|
||||
[(ContractPhase.DangGopY, ContractPhase.DangDamPhan)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.DangGopY, ContractPhase.DangSoanThao)] = [AppRoles.ProjectManager, AppRoles.Procurement, AppRoles.CostControl, AppRoles.Finance, AppRoles.Accounting, AppRoles.Equipment],
|
||||
[(ContractPhase.DangGopY, ContractPhase.TraLai)] = [AppRoles.ProjectManager, AppRoles.Procurement, AppRoles.CostControl, AppRoles.Finance, AppRoles.Accounting, AppRoles.Equipment],
|
||||
|
||||
[(ContractPhase.DangDamPhan, ContractPhase.DangInKy)] = [AppRoles.Drafter, AppRoles.DeptManager, AppRoles.ProjectManager],
|
||||
|
||||
[(ContractPhase.DangInKy, ContractPhase.DangKiemTraCCM)] = [AppRoles.Drafter, AppRoles.DeptManager, AppRoles.ProjectManager],
|
||||
|
||||
[(ContractPhase.DangKiemTraCCM, ContractPhase.DangTrinhKy)] = [AppRoles.CostControl],
|
||||
[(ContractPhase.DangKiemTraCCM, ContractPhase.DangSoanThao)] = [AppRoles.CostControl],
|
||||
[(ContractPhase.DangKiemTraCCM, ContractPhase.TraLai)] = [AppRoles.CostControl],
|
||||
|
||||
[(ContractPhase.DangTrinhKy, ContractPhase.DangDongDau)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(ContractPhase.DangTrinhKy, ContractPhase.DangSoanThao)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(ContractPhase.DangTrinhKy, ContractPhase.TraLai)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
|
||||
[(ContractPhase.DangDongDau, ContractPhase.DaPhatHanh)] = [AppRoles.HrAdmin],
|
||||
},
|
||||
PhaseSla: DefaultSla,
|
||||
ActivePhases:
|
||||
[
|
||||
ContractPhase.DangSoanThao, ContractPhase.DangGopY, ContractPhase.DangDamPhan,
|
||||
ContractPhase.DangSoanThao, ContractPhase.TraLai, ContractPhase.DangGopY, ContractPhase.DangDamPhan,
|
||||
ContractPhase.DangInKy, ContractPhase.DangKiemTraCCM, ContractPhase.DangTrinhKy,
|
||||
ContractPhase.DangDongDau, ContractPhase.DaPhatHanh, ContractPhase.TuChoi,
|
||||
]);
|
||||
@ -106,9 +111,11 @@ public static class WorkflowPolicies
|
||||
{
|
||||
[(ContractPhase.DangSoanThao, ContractPhase.DangGopY)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.DangSoanThao, ContractPhase.TuChoi)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.TraLai, ContractPhase.DangGopY)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.TraLai, ContractPhase.TuChoi)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
|
||||
[(ContractPhase.DangGopY, ContractPhase.DangDamPhan)] = [AppRoles.Drafter, AppRoles.DeptManager],
|
||||
[(ContractPhase.DangGopY, ContractPhase.DangSoanThao)] = [AppRoles.ProjectManager, AppRoles.Procurement, AppRoles.CostControl, AppRoles.Finance, AppRoles.Accounting, AppRoles.Equipment],
|
||||
[(ContractPhase.DangGopY, ContractPhase.TraLai)] = [AppRoles.ProjectManager, AppRoles.Procurement, AppRoles.CostControl, AppRoles.Finance, AppRoles.Accounting, AppRoles.Equipment],
|
||||
|
||||
[(ContractPhase.DangDamPhan, ContractPhase.DangInKy)] = [AppRoles.Drafter, AppRoles.DeptManager, AppRoles.ProjectManager],
|
||||
|
||||
@ -116,14 +123,14 @@ public static class WorkflowPolicies
|
||||
[(ContractPhase.DangInKy, ContractPhase.DangTrinhKy)] = [AppRoles.Drafter, AppRoles.DeptManager, AppRoles.ProjectManager],
|
||||
|
||||
[(ContractPhase.DangTrinhKy, ContractPhase.DangDongDau)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(ContractPhase.DangTrinhKy, ContractPhase.DangSoanThao)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
[(ContractPhase.DangTrinhKy, ContractPhase.TraLai)] = [AppRoles.Director, AppRoles.AuthorizedSigner],
|
||||
|
||||
[(ContractPhase.DangDongDau, ContractPhase.DaPhatHanh)] = [AppRoles.HrAdmin],
|
||||
},
|
||||
PhaseSla: DefaultSla,
|
||||
ActivePhases:
|
||||
[
|
||||
ContractPhase.DangSoanThao, ContractPhase.DangGopY, ContractPhase.DangDamPhan,
|
||||
ContractPhase.DangSoanThao, ContractPhase.TraLai, ContractPhase.DangGopY, ContractPhase.DangDamPhan,
|
||||
ContractPhase.DangInKy, ContractPhase.DangTrinhKy,
|
||||
ContractPhase.DangDongDau, ContractPhase.DaPhatHanh, ContractPhase.TuChoi,
|
||||
]);
|
||||
@ -213,22 +220,35 @@ public static class WorkflowPolicyRegistry
|
||||
transitions[(prev.Value, s.Phase)] = roles;
|
||||
if (userIds.Length > 0) userTransitions[(prev.Value, s.Phase)] = userIds;
|
||||
|
||||
// Reject path back to Drafter (common pattern QT docx)
|
||||
// Mirror: TraLai → s.Phase (Drafter resubmit từ Trả lại = entry point thứ 2)
|
||||
if (prev.Value == ContractPhase.DangSoanThao)
|
||||
{
|
||||
transitions.TryAdd((ContractPhase.TraLai, s.Phase), roles);
|
||||
if (userIds.Length > 0)
|
||||
userTransitions.TryAdd((ContractPhase.TraLai, s.Phase), userIds);
|
||||
}
|
||||
|
||||
// Reject path → TraLai (Phase riêng, không revert DangSoanThao)
|
||||
if (prev.Value != ContractPhase.DangSoanThao && s.Phase != ContractPhase.DangSoanThao)
|
||||
{
|
||||
transitions.TryAdd((s.Phase, ContractPhase.DangSoanThao), roles);
|
||||
transitions.TryAdd((s.Phase, ContractPhase.TraLai), roles);
|
||||
if (userIds.Length > 0)
|
||||
userTransitions.TryAdd((s.Phase, ContractPhase.DangSoanThao), userIds);
|
||||
userTransitions.TryAdd((s.Phase, ContractPhase.TraLai), userIds);
|
||||
}
|
||||
}
|
||||
prev = s.Phase;
|
||||
}
|
||||
// First step có thể reject to TuChoi
|
||||
// First step có thể reject to TuChoi (cả Nháp + Trả lại)
|
||||
if (steps.Count > 0)
|
||||
{
|
||||
transitions.TryAdd((steps[0].Phase, ContractPhase.TuChoi),
|
||||
[AppRoles.Drafter, AppRoles.DeptManager]);
|
||||
transitions.TryAdd((ContractPhase.TraLai, ContractPhase.TuChoi),
|
||||
[AppRoles.Drafter, AppRoles.DeptManager]);
|
||||
}
|
||||
|
||||
if (!activePhases.Contains(ContractPhase.TuChoi)) activePhases.Add(ContractPhase.TuChoi);
|
||||
if (!activePhases.Contains(ContractPhase.TraLai)) activePhases.Add(ContractPhase.TraLai);
|
||||
|
||||
return new WorkflowPolicy(
|
||||
Name: $"{def.Code}-v{def.Version:D2}",
|
||||
|
||||
Reference in New Issue
Block a user