Files
solution-erp/docs/changelog/migration-todos.md
pqhuy1987 3c4931687a
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m15s
[CLAUDE] App+Api+Docs: Chunk E1 — List endpoint + Bypass-review + Notify TPB + chốt session 8
3 endpoint mới + Notify TPB + Docs update để chốt session 8.

Application:
- PurchaseEvaluationDepartmentApprovalFeatures.cs (NEW):
  * ListPeDepartmentApprovalsQuery + DTO PeDepartmentApprovalDto
  * Join Departments (lấy Name) + lookup Users.FullName denorm cho FE timeline
- UserFeatures.cs: SetUserBypassReviewCommand + Handler dùng UserManager.UpdateAsync
- IApplicationDbContext: thêm DbSet<User> Users + DbSet<Role> Roles (cần cho lookup)

Api:
- PurchaseEvaluationsController: GET /api/purchase-evaluations/{id}/department-approvals
- UsersController: PATCH /api/users/{id}/bypass-review (Authorize Users.Update)

Infra:
- PurchaseEvaluationWorkflowService: notify TPB cùng dept khi NV review.
  Query db.Users.Where(DeptId match + IsActive) → UserManager.GetRolesAsync
  filter DeptManager → notifications.NotifyAsync. Best effort fail non-critical.

Docs:
- STATUS.md: Recently Done thêm row session 8 + Phase header update
  count 52→55 tables, 15→16 migrations, 128→131 endpoints
- HANDOFF.md: TL;DR session 8 + 8 cảnh báo session 9 (FE chưa làm,
  test flow anh Kiệt, smart reject test, lock edit test, ...)
- migration-todos.md: Phase 9 done section đầy đủ 3 ràng buộc + pending Chunk E-bis
- CLAUDE.md: count 52→55 + migration 16 description
- session log: 2026-05-04-1230-chot-session-8-2-stage-dept-approval.md (full report)

Verify final:
- Build pass 0 warning 0 error
- 77 unit test pass (54 Domain + 23 Infra)
- Migration 16 applied LocalDB OK + schema verified

Total session 8 cumulative: 5 commit per-chunk:
- 5fe61cc (A: Migration 16 schema)
- 14f3c9f (B: Lock edit guards 17 handler)
- 9747f8c (C: Smart reject + Resume 3 module)
- a532ba6 (D: PE 2-stage logic)
- (current E1: List + Notify + Bypass + Docs)

Pending Chunk E-bis (defer cho session 9 sau UAT PE):
- FE Workflow Panel hiển thị 2-stage timeline
- FE UserManager toggle CanBypassReview
- HĐ + Budget 2-stage extension
- Tests Phase 3 mini cho 2-stage Service-layer logic

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 12:42:47 +07:00

16 KiB
Raw Blame History

Migration To-dos — Atomic Roadmap

Tick [x] khi xong. Phase 0-8 đã DONE — collapsed. Detail xem session logs trong docs/changelog/sessions/. Active work: Phase 9 (UAT + Ops + carry over PE PDF export + Tests Phase 3-5).

Phase 0-5 + Tier 3 — Done (2026-04-21..22)

Phase Focus Trạng thái
0 Draft Scaffold .NET 10 + 2 Vite + parse FORM/QT + docs
1 Alpha Core Auth + 12 role + Permission Matrix + 3 master CRUD + Contract draft
2 Form Engine OpenXml + ClosedXML render + LibreOffice PDF + DynamicForm
3 Workflow State machine 9 phase + RG-001 code gen + SLA job + attachments + SignalR realtime
4 Reporting Dashboard KPI + Excel export + MyDashboard role-aware + brand identity #1F7DC1
5 Production CI/CD Gitea Actions + 3 IIS site + Let's Encrypt + Security headers + Users CRUD
Tier 3 Versioned workflow + 3-panel layout + 4-bảng overhaul + 4 master catalogs + 16 demo users + RolesPage CRUD + 7 demo HĐ varied

Detail chi tiết: docs/changelog/sessions/2026-04-21-*.md + 2026-04-22-0300-tier3-feature-complete.md + 2026-04-23-*.md.

Phase 6 — Module Duyệt NCC (tiền-HĐ) — Done

Iter 1 (2026-04-23)

  • Migration 12 AddPurchaseEvaluations — 10 bảng (Header/Suppliers/Details/Quotes/Approvals/Changelogs/Attachments/WorkflowDefinitions/Steps/StepApprovers)
  • Domain — 2 enum (Type A/B, Phase 7-state) + Policy record + Registry + FromDefinition builder
  • Seed — 13 menu Pe_/PeWf_ + 2 WorkflowDefinition v01 (QT-DN-A 3-step, QT-DN-B 5-step)
  • Application CQRS ~900 LOC — Create/Update/Transition/List/Inbox/Get/Delete + Supplier CRUD + Detail CRUD + Quote Upsert + SelectWinner + Changelog
  • PurchaseEvaluationWorkflowService — policy guard + approval + notification + changelog
  • PurchaseEvaluationsController — 17 endpoint REST
  • FE 2 app — Types + PurchaseEvaluationsListPage 3-panel + Create page + PeDetailTabs + PeWorkflowPanel + Menu resolver Pe_*
  • Kế thừa HĐ — CreateContractFromEvaluationCommand (guard DaDuyet + SelectedSupplier + !ContractId) → Contract draft. FE CreateContractDialog pick ContractType.
  • Migration 13 AddPurchaseEvaluationCodeSequences — atomic MaPhieu sequence PE/{YYYY}/{A|B}/{Seq:D3}
  • Demo PE seed — 4 phiếu varied phase (A-001/A-002/A-003/B-001) + Pe_* permission defaults 7 role × 9 menu key

Session log: 2026-04-23-2300-purchase-evaluations.md + 2026-04-24-1030-pe-polish-demo-maphieu-perms.md.

Iter 2 — UX polish (2026-04-24)

  • Rename menu "Phương Án" → "Giải pháp" + backfill DB (zero breaking change)
  • Menu tree inheritance extend Pe_/PeWf_ (GetMyMenuTreeQuery + 4 root)
  • Accordion mutex Pe_* groups + sidebar w-72 + label nowrap
  • NavLink active check query string (queryMatches helper) — fix 2 leaf cùng highlight
  • PE detail flat layout: Panel 2 = 4 section (Thông tin/NCC/Hạng mục/Bảng so sánh), Panel 3 += Approvals + Changelog
  • Upload file đính kèm per-NCC (SupplierAttachmentsCell) + Bảng so sánh tổng (GeneralAttachmentsSection, supplierRowId=null) + enum ComparisonTable=4
  • readOnly mode menu "Duyệt" (pendingMe=1) — hide Sửa/Xóa/Thêm/Edit/Upload/Delete, giữ download + transition + comment
  • Contract: move Lịch sử điều chỉnh Panel 2 → Panel 3 (Chi tiết HĐ full-width)
  • Demo email rebrand @solutionerp.local@solutions.com.vn + BackfillUserEmailDomainAsync (idempotent rename 4 field Email/NormalizedEmail/UserName/NormalizedUserName)

Session log: 2026-04-24-chot-session-3-pe-polish.md.

Domain rebrand .huypham.vn.solutions.com.vn (2026-04-24)

  • 18 file repo (FE env + scripts + CI/CD + docs + skill + code comments)
  • scripts/migrate-domains.ps1 (ASCII-only #30) — 3 IIS binding + 3 cert Let's Encrypt + auto HTTPS + redirect
  • CI/CD auto rebuild BE CORS + FE bundle VITE_API_BASE_URL
  • E2E verified 3 domain live + preflight OK

Sub: api.solutions.com.vn · admin.solutions.com.vn · eoffice.solutions.com.vn. Old .huypham.vn vẫn fallback (chưa remove — Phase 9 Ops).

📝 Phase 7 — PE feature gap + Budget BE (Session 4 partial done)

A. PE feature gap (3 task — phần lớn đóng ở Phase 8 S5)

  • PE Workflow admin designer UI /system/pe-workflows/:typeCode — done S5 (5d94bb4)
    • BE Application/PurchaseEvaluations/PeWorkflowAdminFeatures.cs (mirror WorkflowAdminFeatures.cs)
    • Api/Controllers/PeWorkflowsController.cs
    • FE fe-admin/src/pages/system/PeWorkflowsPage.tsx + PeWorkflowDesigner.tsx
    • Route /system/pe-workflows/:typeCode (menu PeWf_* + resolver đã sẵn)
  • Ý kiến 4 phòng ban (Phê duyệt / P.CCM / P.MuaHàng / SM-PM) ở tab Thông tin — done S5 (5d94bb4, Migration 15)
    • Option A: 4 text field + signoff date + UserId vào header
    • Option B: dùng PurchaseEvaluationApprovals với roleKind extra field
    • Chốt: dùng Migration 15 AddPurchaseEvaluationDepartmentOpinions (separate table UNIQUE PEId+Kind, 4 box sign-off 2x2 grid OpinionBox như Excel mẫu) — tốt hơn Option A/B vì audit qua Changelog + Upsert preserve chữ ký cũ khi text-only edit.
  • Export phiếu PDF/Excel — tái dùng IDocumentConverter + template PE-TrinhDuyet.docx → carry over Phase 9 (user pending — không quan trọng lắm)

B. Optional polish (carry over Phase 9 — làm khi UAT phát sinh)

  • Auto-map PE Details → Contract per-type Details khi gen HĐ (phức tạp vì 7 schema khác nhau)
  • Payment terms tách field từ JSON → 6 column (Tạm ứng/TT tạm/Quyết toán/Bảo hành/Hạn mức/Đánh giá)
  • Matrix Quotes bulk paste từ Excel
  • fe-user Inbox thêm section "Phiếu Duyệt NCC chờ tôi"

C. Ops (carry over Phase 9 — Hard blockers)

  • Remove binding cũ .huypham.vn sau verify stable: ssh vietreport-vps ; cd C:\solution-erp\scripts ; .\migrate-domains.ps1 -RemoveOld -SkipCert
  • win-acme scheduled task fix unhealthy (cert expire 2026-06-18)
  • UAT thật 1 tuần với 2-3 user (30 demo user — 16 sample + 14 Solutions thật)
  • SMTP config → Email outbox
  • Rotate credentials (admin + 30 demo + SA + vrapp + JWT)
  • Schedule SQL backup Task Scheduler

D. Module Ngân sách (Budget) — Session 4 partial done

  • Migration 14 AddBudgets — 4 bảng (Budgets/BudgetDetails/BudgetApprovals/BudgetChangelogs) + index BudgetId nullable trên Contract & PurchaseEvaluation
  • Domain — Budget (Header) + BudgetDetail (flat row) + BudgetApproval + BudgetChangelog + enum BudgetPhase 5-state + BudgetEntityType Header/Detail/Workflow
  • BudgetPolicy.Default hardcoded simple 3-step (Drafter→CCM→CEO + Reject từ ChoCCM/ChoCEO về DangSoanThao)
  • Application CQRS ~340 LOC — Create + UpdateDraft + Transition + List + GetDetail + Delete (only DangSoanThao/TuChoi) + Detail CRUD (auto-recompute TongNganSach) + ListChangelogs
  • BudgetsController 11 endpoint REST
  • Menu seed Budgets root + 3 leaf (Bg_List/Bg_Create/Bg_Pending) order=27 icon Wallet
  • 14 demo user Solutions thật — PRO 5 + CCM 7 + ISO 1 + CEO 1 (pwd User@123456). Reconcile pattern (gotcha #38 4-field rename). Tổng 30 user (16 sample cũ + 14 Solutions thật mới).

Session log: 2026-04-28-chot-session-4-budget.md.

E. Pending migrations

  • AddPePaymentTermFields (nếu chốt UX tách field — JSON blob → 6 column)
  • AddPurchaseEvaluationDepartmentOpinions migration 15 (S5)
  • AddBudgetCodeSequences (nếu chốt format MaNganSach atomic — hiện Random.Shared)
  • AddBudgetVersionedWorkflow (nếu user cần admin config UI thay vì hardcoded BudgetPolicy.Default)

Phase 8 — Budget FE + PE/HD integration (Session 5 done)

A. FE Budget pages — done

  • fe-admin/src/types/budget.ts (BudgetPhase 5-state enum + DTO types)
  • fe-admin/src/pages/budgets/BudgetsListPage.tsx (3-panel [340px_1fr_360px] + filter Phase/Năm + ?phase=Pending alias + readOnly mode + BudgetDetailPage fullpage mobile)
  • fe-admin/src/pages/budgets/BudgetCreatePage.tsx (form Header — Tên/Năm/Dự án/Phòng ban/Mô tả)
  • fe-admin/src/components/budgets/BudgetDetailTabs.tsx (Section Thông tin Header + Section Hạng mục table CRUD inline auto-compute ThanhTien=KL×ĐG)
  • fe-admin/src/components/budgets/BudgetWorkflowPanel.tsx (Panel 3 timeline activePhases + nextPhases buttons + Dialog comment + Approvals/Changelog)
  • Mirror tất cả sang fe-user/
  • App.tsx routes /budgets, /budgets/new, /budgets/:id cả 2 app
  • Menu resolver Bg_* (Bg_List → /budgets, Bg_Pending → /budgets?phase=Pending, Bg_Create → /budgets/new)

B. PE/Contract → Budget integration — done

  • PE form + Select "Ngân sách" filter Phase=DaDuyet, ProjectId match, BE validate
  • Contract form (Header + Edit) tương tự, EditForm read-only link card khi !isDraft
  • PE Detail Hạng mục thêm cột "NS link · Δ" — match per-row qua groupCode|itemCode + footer aggregate (xanh dưới / đỏ vượt / xám khớp)
  • PE Detail UI restructure 4 section đánh số match form spec PHIẾU TRÌNH KÝ
  • BE: BudgetSummaryDto shared + Create/Update PE+Contract commands + BudgetId? + GetQueries load Budget
  • CreateContractFromEvaluation carry forward pe.BudgetId → contract.BudgetId

C. PE Workflow Designer admin UI — done

  • BE PeWorkflowAdminFeatures.cs ~250 LOC mirror Contract pattern
  • BE PeWorkflowsController 2 endpoint reuse policy Workflows.*
  • FE PeWorkflowsPage.tsx ~500 LOC + designer dialog (clone/edit/+Role/+User)
  • App.tsx route /system/pe-workflows/:typeCode

D. Ý kiến 4 phòng ban — done

  • Migration 15 AddPurchaseEvaluationDepartmentOpinions (UNIQUE PEId+Kind)
  • Domain entity + enum PeDepartmentKind (PheDuyet/Ccm/MuaHang/SmPm)
  • BE Upsert (sign=true → set SignedAt+UserId, sign=false giữ chữ ký cũ) + Delete + 2 endpoint
  • FE Section "5. Ý kiến 4 phòng ban (sign-off)" 2x2 grid OpinionBox

E. Tests Phase 1-2-3mini + CI optimize — done

  • Phase 1tests/SolutionErp.Domain.Tests/ (xUnit + FluentAssertions 7.2): 54 test policy state machine (Contract WF + PE WF + Budget) + Registry + FromDefinition versioned + UserKindApprover
  • Phase 2tests/SolutionErp.Infrastructure.Tests/ (EF SQLite + TestApplicationDbContext override nvarchar(max) → TEXT): 17 test code generator format + sequence + year boundary + persistence verify
  • Phase 3 minitests/.../Application/PeWorkflowAdminTests.cs: 6 test CreatePeWorkflowDefinitionCommand versioning (auto-increment + deactivate cũ + EvaluationType independence + steps/approvers persistence)
  • CI gate .gitea/workflows/deploy.yml — 2 step dotnet test trước build, fail → no deploy
  • Total 77 test pass / ~3s
  • CI manual checkout bypass github.com — fix gotcha #39 (act_runner TCP timeout 21s)
  • CI path filter docs-only skip — gotcha #41 (paths-ignore behavior)
  • Tests Phase 3 full — Opinion Upsert + Budget link validation (cần Identity UserManager setup helper)
  • npm junction cache CI optimize (rollback ở a21790d — gotcha #40 chưa debug)

📝 Phase 9 — UAT + Ops + carry over (Session 6+ active)

Session 8 done (2026-05-04) — Migration 16: 2-stage dept approval + smart reject + lock edit

Bối cảnh: Anh Kiệt (FDC) báo bug PE workflow: NV.PRO tạo phiếu → duyệt được hết phase. Phân quyền sai vì policy chỉ check role, không check Stage 2-cấp.

3 ràng buộc gộp 1 migration:

  • Lock edit khi Phase != DangSoanThao — 17 handler thêm guard (Contract Detail × 15 qua helper EnsureContractType, PE Detail × 5 qua helper mới PurchaseEvaluationDraftGuard, Budget Detail × 3 inline). KHÔNG lock Comment + Attachment + Opinion (workflow design intent).

  • Smart reject + ResumeDecision=Rejectentity.RejectedFromPhase = currentPhase + force targetPhase=DangSoanThao. Resume: Drafter trình từ DangSoanThao + RejectedFromPhase != null → jump tới phase đã reject + clear field. Bypass policy guard ở resume.

  • 2-stage dept approval (PE only v1) — User.DepartmentId != null + role guard:

    • DeptManager (TPB) → Stage=Confirm trực tiếp
    • User.CanBypassReview=true → Stage=Confirm + IsBypassed=true
    • Else (NV) → Stage=Review only, BLOCK transition cho đến khi TPB confirm
    • Schema: 3 bảng *DepartmentApprovals UNIQUE (TargetId, Phase, Dept, Stage)
  • Migration 16 AddTwoStageDeptApprovalAndSmartReject — 4 ALTER + 3 CREATE TABLE + 12 indexes + FK Cascade

  • Endpoint mới: GET /api/purchase-evaluations/{id}/department-approvals (List), PATCH /api/users/{id}/bypass-review (toggle)

  • Notify TPB cùng dept khi NV review (best effort, fail non-critical)

  • Verify: Build pass + 77 test pass + Migration applied LocalDB OK + schema verified qua sqlcmd

  • 5 commit per-chunk: 5fe61cc (A) · 14f3c9f (B) · 9747f8c (C) · a532ba6 (D) · current (E1)

Session log: 2026-05-04-1230-chot-session-8-2-stage-dept-approval.md.

Pending Chunk E-bis (defer):

  • FE Workflow Panel hiển thị progress 2-stage timeline
  • FE UserManager toggle CanBypassReview checkbox
  • HĐ 2-stage mở rộng (ContractWorkflowService thêm 2-stage logic + endpoint List)
  • Budget 2-stage mở rộng (low priority)
  • Tests 2-stage logic Service-layer (cần UserManager DI helper)

Session 6 done (2026-04-30 — pure docs work)

  • MD audit + compact — STATUS -27%, HANDOFF -32%, migration-todos -35%, archive 51 row Phase 0-7 cũ
  • 3 skill refreshform-engine Phase 2 MVP → Tier 3 feature-complete, permission-matrix 12 menu → ~60 + inheritance roots, ef-core-migration 24 DbSet → 52 bảng
  • Rule mới rules.md §7 — Khi nào viết test (timing rule 5-row table)
  • Rule mới rules.md §6.4 — Audit + compact MD định kỳ (cadence + checklist + anti-pattern)
  • rules.md §9.4 — Mở rộng skill audit cross-ref §6.4

A. Hard blockers (chờ user / ops)

  • UAT thật 1 tuần với 2-3 user (30 demo: 16 sample + 14 Solutions thật)
  • SMTP config → Email outbox (BLOCKED chờ user cấp host/user/pass)
  • Rotate credentials (admin + 30 demo + SA + vrapp + JWT secret + Gitea runner token)
  • Schedule SQL backup daily Task Scheduler

B. PE feature gap còn lại

  • Export phiếu PDF/Excel — IDocumentConverter + template PE-TrinhDuyet.docx (user pending — không quan trọng lắm)

C. Optional polish (làm khi UAT phát sinh)

  • Budget MaNganSach atomic sequence + migration AddBudgetCodeSequences
  • Budget versioned workflow + migration AddBudgetVersionedWorkflow
  • Payment terms PE tách field (JSON → 6 column)
  • Auto-map PE Details → Contract Details khi gen HĐ
  • Matrix Quotes bulk paste từ Excel
  • fe-user Inbox thêm section "Phiếu Duyệt NCC chờ tôi"

D. Tests Phase 3-5 (làm khi gặp bug recurring để justify ROI)

  • Phase 3 — Application handler tests (CQRS + EF InMemory) ~15 test
  • Phase 4 — API smoke tests (WebApplicationFactory) ~7 test
  • Phase 5 — FE Vitest cho lib utility (queryMatches, fmtMoney) ~10 test

E. Ops chưa xong

  • Remove binding cũ .huypham.vn sau verify stable
  • win-acme scheduled task fix unhealthy (cert expire 2026-06-18)

🔁 Skill governance (recurring)

Quy tắc: docs/rules.md §9. Audit định kỳ mỗi đầu tháng — workflow §9.4.

  • Setup ban đầu — 6 skill (3 domain + 3 ops), rules §9 ← 661f859
  • Audit 2026-05-01 — log docs/changelog/skill-audit-2026-05.md
  • Audit 2026-06-01
  • Audit 2026-07-01

Cron task solution-erp-skill-audit-monthly fire 9:00 AM ngày 1 mỗi tháng.

📦 Post-launch (Phase 10+ — future)

  • Email outbox (MailKit + SMTP) — blocked chờ SMTP config
  • E-signature integration (VNPT CA hoặc FPT CA)
  • Tích hợp Bravo / SAP ERP import NCC
  • Mobile app (React Native?) cho BOD duyệt ngoài giờ
  • AI: gợi ý điền form dựa HĐ cũ, OCR scan HĐ đối tác
  • Multi-tenant nếu có công ty thứ 2