diff --git a/fe-admin/src/components/pe/PeDetailTabs.tsx b/fe-admin/src/components/pe/PeDetailTabs.tsx index bad9a6b..e0ec9c6 100644 --- a/fe-admin/src/components/pe/PeDetailTabs.tsx +++ b/fe-admin/src/components/pe/PeDetailTabs.tsx @@ -15,6 +15,7 @@ import { Select } from '@/components/ui/Select' import { api } from '@/lib/api' import { getErrorMessage } from '@/lib/apiError' import { cn } from '@/lib/cn' +import { useAuth } from '@/contexts/AuthContext' import { PeAttachmentPurpose, PeAttachmentPurposeLabel, @@ -100,17 +101,33 @@ export function PeDetailTabs({ const canEditPhase = isEditablePhase(evaluation.phase) const opinionsReadOnly = readOnly || mode === 'workspace' + // Mig 28 (S21 t4) — F3: Approver edit Section 2 (Hạng mục + NCC + Báo giá). + const { user: currentUser } = useAuth() + const isAdmin = currentUser?.roles?.includes('Admin') ?? false + const v2Approvers = evaluation.currentApproval?.approvers ?? [] + const actorMatchesLevel = isAdmin + || (currentUser?.id != null && v2Approvers.some(a => a.userId === currentUser.id)) + const approverEditMode = evaluation.phase === PurchaseEvaluationPhase.ChoDuyet + && (evaluation.workflowOptions?.allowApproverEditDetails ?? false) + && actorMatchesLevel + const itemsReadOnly = readOnly && !approverEditMode + // "Lưu & Gửi Duyệt" workspace mode (user 2026-05-07): trigger transition // sang phase tiếp theo (= Đã gửi duyệt). nextPhases[0] thường là ChoPurchasing // (skip TuChoi). Sau success → toast + invalidate + onBack đóng workspace. + // Mig 28 (S21 t4) — F2: Drafter skip thẳng Cấp cuối. Workflow phải bật flag. + const [skipToFinal, setSkipToFinal] = useState(false) + const allowSkipToFinal = evaluation.workflowOptions?.allowDrafterSkipToFinal ?? false + const submitForApproval = useMutation({ - mutationFn: async () => { + mutationFn: async (opts: { skipToFinal: boolean }) => { const next = evaluation.workflow.nextPhases.find(p => p !== PurchaseEvaluationPhase.TuChoi && p !== PurchaseEvaluationPhase.TraLai) if (!next) throw new Error('Không có phase tiếp theo để gửi duyệt') return api.post(`/purchase-evaluations/${evaluation.id}/transitions`, { targetPhase: next, decision: 1, comment: null, + skipToFinal: opts.skipToFinal, }) }, onSuccess: () => { @@ -192,7 +209,14 @@ export function PeDetailTabs({
- + {/* Mig 28 (S21 t4) — F3: itemsReadOnly cho phép approver edit Section 2 */} + {approverEditMode && readOnly && ( +
+ ⓘ Bạn được phép chỉnh sửa Hạng mục / NCC / Báo giá (workflow bật mode Approver edit). + Mọi thay đổi sẽ được ghi vào Lịch sử chỉnh sửa. +
+ )} +
@@ -251,18 +275,33 @@ export function PeDetailTabs({ > Lưu + {/* Mig 28 (S21 t4) — F2: Drafter skip checkbox */} + {allowSkipToFinal && canSubmitForApproval && ( + + )} diff --git a/fe-admin/src/components/pe/PeWorkflowPanel.tsx b/fe-admin/src/components/pe/PeWorkflowPanel.tsx index 09bf34e..35a73e1 100644 --- a/fe-admin/src/components/pe/PeWorkflowPanel.tsx +++ b/fe-admin/src/components/pe/PeWorkflowPanel.tsx @@ -18,6 +18,7 @@ import { PurchaseEvaluationPhase, PurchaseEvaluationPhaseColor, PurchaseEvaluationPhaseLabel, + WorkflowReturnMode, type PeDepartmentApproval, type PeDetailBundle, } from '@/types/purchaseEvaluation' @@ -33,10 +34,20 @@ export function PeWorkflowPanel({ }) { const [target, setTarget] = useState(null) const [comment, setComment] = useState('') + // Mig 28 (S21 t4) — F1 mode Trả lại. Default Drafter (backward compat S17). + const [returnMode, setReturnMode] = useState(WorkflowReturnMode.Drafter) + const [returnTargetUserId, setReturnTargetUserId] = useState(null) const qc = useQueryClient() const { user: currentUser } = useAuth() const isAdmin = currentUser?.roles?.includes('Admin') ?? false + // Mig 28 — F1 workflow options. Null nếu V1 legacy → fallback chỉ "Trả về Drafter". + const wfOptions = evaluation.workflowOptions + // List approvers đã ký (cho mode Assignee dropdown pick) + const signedApprovers = (evaluation.levelOpinions ?? []) + .map(o => ({ userId: o.approverUserId, fullName: o.approverFullName ?? 'NV' })) + .filter((v, i, arr) => arr.findIndex(x => x.userId === v.userId) === i) + // Mig 24 — V2 schema chỉ cho phép approver trong CurrentApproval.approvers // duyệt cấp hiện tại. Nếu actor không khớp → disable nút "Duyệt forward" // (Trả lại / Từ chối vẫn enabled vì Service không kiểm Bước/Cấp với 2 @@ -75,10 +86,16 @@ export function PeWorkflowPanel({ && evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao) || (target === PurchaseEvaluationPhase.TraLai && evaluation.phase !== PurchaseEvaluationPhase.TraLai) + // Mig 28 (S21 t4) — F1: chỉ gửi returnMode khi target=TraLai + mode != null + const isTraLaiAction = target === PurchaseEvaluationPhase.TraLai + && evaluation.phase !== PurchaseEvaluationPhase.TraLai return api.post(`/purchase-evaluations/${evaluation.id}/transitions`, { targetPhase: target, decision: isReject ? 2 : 1, comment: comment || null, + returnMode: isTraLaiAction ? returnMode : null, + returnTargetUserId: isTraLaiAction && returnMode === WorkflowReturnMode.Assignee + ? returnTargetUserId : null, }) }, onSuccess: () => { @@ -88,6 +105,8 @@ export function PeWorkflowPanel({ qc.invalidateQueries({ queryKey: ['pe-dept-approvals', evaluation.id] }) setTarget(null) setComment('') + setReturnMode(WorkflowReturnMode.Drafter) + setReturnTargetUserId(null) }, onError: e => toast.error(getErrorMessage(e)), }) @@ -285,9 +304,96 @@ export function PeWorkflowPanel({ )} {isSendBack && ( -
- Phiếu sẽ về “Đang soạn thảo”. Drafter có thể sửa rồi trình lại — workflow tự jump tới phase này. -
+ <> + {/* Mig 28 (S21 t4) — F1 mode picker khi Trả lại. Show modes + enabled per workflow.options. Default Drafter (S17 fallback). */} + {(wfOptions?.allowReturnOneLevel + || wfOptions?.allowReturnOneStep + || wfOptions?.allowReturnToAssignee + || wfOptions?.allowReturnToDrafter + || !wfOptions) && ( +
+ +
+ {(wfOptions?.allowReturnOneLevel) && ( + + )} + {(wfOptions?.allowReturnOneStep) && ( + + )} + {(wfOptions?.allowReturnToAssignee) && ( + + )} + {(wfOptions?.allowReturnToDrafter !== false) && ( + + )} +
+
+ )} +
+ {returnMode === WorkflowReturnMode.Drafter + ? 'Phiếu sẽ về "Trả lại". Drafter có thể sửa rồi trình lại từ Cấp 1 Bước 1.' + : returnMode === WorkflowReturnMode.Assignee + ? 'Phiếu sẽ về Cấp/Bước của NV đã chọn (vẫn "Đã gửi duyệt"). NV nhận lại để duyệt tiếp.' + : 'Phiếu sẽ lùi pointer (vẫn "Đã gửi duyệt"). NV trước nhận lại để duyệt tiếp.'} +
+ )}