From ff5e35f279da266824d1c511720a441c1e7a3146 Mon Sep 17 00:00:00 2001 From: pqhuy1987 Date: Thu, 23 Apr 2026 14:39:48 +0700 Subject: [PATCH] =?UTF-8?q?[CLAUDE]=20Docs:=20ch=E1=BB=91t=20session=20202?= =?UTF-8?q?6-04-23=20chi=E1=BB=81u=20=E2=80=94=20toolkit=20+=204-b?= =?UTF-8?q?=E1=BA=A3ng=20+=20master=20+=20roles=20VN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 11 commit feature work (b75448e → ae59cfe) → docs sync. ## STATUS.md - Last updated 2026-04-23 16:00 - Phase header: Tier 3 + 4-bảng + master catalogs + roles VN - 7 Recently Done row mới (3-panel layout, 4-bảng overhaul, Thao tác 2-panel, Mã HĐ gen Create, master catalogs, roles VN demo users) - Cumulative table thêm cột "+Toolkit/Catalogs/Roles" (DB 36, endpoints ~80, migrations 11, commits ~47) - Session log link mới - Skill list count = 13 file ## HANDOFF.md - TL;DR cập nhật: 36 tables, 80 endpoints, 11 migrations - Phase table thêm 5 row Done (3-panel, 4-bảng, mã HĐ, master, roles) - Git state 18 commit gần nhất - Credentials block thêm 13 demo user (User@123456) — warn rotate trước UAT ## migration-todos.md Section "Session 2026-04-23 (chiều)" với 14 ticked checkbox + commit refs. ## schema-diagram.md - Header: 24 → 36 bảng - Migration table thêm row 9-11 (highlighted) - Section 8bis mới: chi tiết 7 Details + ContractChangelogs + 4 Catalogs + Role.ShortName + User.DepartmentId/Position ## Session log mới `docs/changelog/sessions/2026-04-23-1500-toolkit-data-roles.md` (~270 dòng) — outcome A→I, stats cumulative, 6 architectural decisions, next session priority. Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/HANDOFF.md | 51 +++- docs/STATUS.md | 40 +-- docs/changelog/migration-todos.md | 17 ++ .../2026-04-23-1500-toolkit-data-roles.md | 256 ++++++++++++++++++ docs/database/schema-diagram.md | 63 ++++- 5 files changed, 399 insertions(+), 28 deletions(-) create mode 100644 docs/changelog/sessions/2026-04-23-1500-toolkit-data-roles.md diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index 3d39325..fac721f 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -1,10 +1,10 @@ # HANDOFF — Brief 5 phút cho session tiếp theo -**Last updated:** 2026-04-23 09:30 (post-skill-governance + cron audit định kỳ) +**Last updated:** 2026-04-23 16:00 (post-toolkit + 4-bảng overhaul + master data + roles VN) ## TL;DR -Tier 3 ERP feature-complete (prod 3 domain live). **Skill governance setup xong** — 6 skill project-level (3 domain + 3 ops) + cron audit 1/tháng (next 2026-05-01). **Còn lại chủ yếu là UAT + SMTP + rotate creds**, không còn module kỹ thuật lớn nào chưa làm. +Tier 3 ERP + **4-bảng overhaul** (Header/Details/Workflow/Changelog) + **4 master catalogs** (Units/Materials/Services/WorkItems) + **Roles VN labels (ShortName)** + 13 demo users. Prod 3 domain live, 36 DB tables, ~80 endpoints, 11 migrations. **Còn lại chủ yếu là UAT + SMTP + rotate creds**. ## ⭐ Skills (.claude/skills/) — PHẢI dùng khi task khớp @@ -31,6 +31,11 @@ Tier 3 ERP feature-complete (prod 3 domain live). **Skill governance setup xong* | **5 Deploy prod** (3 domain HTTPS live) | ✅ Done | | **Tier 3 (Attach + Realtime + Form builder + PDF + Versioned WF + Nested menu + Permission 3-panel)** | ✅ Done | | **Skill governance** (6 skill project-level + audit cron 1/tháng) | ✅ Done | +| **3-panel List/Inbox/Thao tác + sidebar accordion + UserDashboard** | ✅ Done | +| **4-bảng data model** (Header + 7 Details + Workflow + Changelog audit) | ✅ Done | +| **Mã HĐ gen tại Create + backfill legacy** | ✅ Done | +| **4 master catalogs** (Units/Materials/Services/WorkItems) + datalist autocomplete | ✅ Done | +| **Roles VN labels (ShortName)** + Users dept/position + 13 demo users | ✅ Done | | 6+ Post-launch (E-signature, Bravo/SAP, Mobile, AI) | 📝 Future | ## Run nhanh @@ -264,13 +269,24 @@ SOLUTION_ERP/ ``` HEAD → main -b904a25 — Skill: governance + audit định kỳ hàng tháng (LATEST) -661f859 — Skill: thêm 3 skill ops project-specific -fbca832 — Docs: chốt session Tier 3 feature-complete + versioned workflow -91b2da1 — FE-Admin: PermissionsPage 3-panel layout -f216169 — FE-Admin+Domain+Infra+App: Workflows tab → sidebar menu items -355bbe3 — Fix Dialog size TS (xl → lg) -e7e5f2d — Versioned workflow entities + migration + designer +ae59cfe — FE-Admin: UsersPage dept/position + RoleShortName VN (LATEST) +330d529 — Domain+App+Infra: Role ShortName + User Dept/Position + 13 demo users (migration 11) +39031ca — FE: ContractDetailsPreview cho create mode +16e24ed — FE: Admin CatalogsPage CRUD + Details datalist autocomplete +e27c547 — Domain+App+Api: 4 master catalogs cho Details (migration 10) +51449d6 — App+Infra: Mã HĐ gen ngay tại CreateContract + backfill legacy +7f26ff9 — Edit/Xóa luôn hiện, mờ khi != DangSoanThao +8c4b4da — 2-panel layout cho Thao tác +ad0652d — Bỏ tabs, Chi tiết+Lịch sử 7/3 grid +b3762af — Panel 2 tabs (Tổng quan/Chi tiết/Lịch sử) +e684455 — App+Api: 7 Details CRUD endpoints + Changelogs query +71c035d — App+Infra: IChangelogService +70810e1 — Domain+Infra: 7 Details + ContractChangelog (migration 9) +d326e80 — FE-User: tách Tổng quan thành /dashboard riêng +89c7e88 — FE-User: 3-panel InboxPage +b75448e — 3-panel layout cho danh sách HĐ +7ea3957 — Sidebar accordion menu loại HĐ +d43d2c0 — Docs: chốt session 2026-04-23 — skill governance Branch: main (tracking origin/main) Remote: https://git.baocaogiaoduc.vn/vietreport-admin/solution-erp.git @@ -279,7 +295,22 @@ Remote: https://git.baocaogiaoduc.vn/vietreport-admin/solution-erp.git ## Credentials + URLs ``` -admin@solutionerp.local / Admin@123456 +admin@solutionerp.local / Admin@123456 ← Admin (QTV) + +Demo users (User@123456): + bod.huynh@solutionerp.local Tổng GĐ (BOD) + bod.le@solutionerp.local Phó GĐ NĐUQ + pm.nguyen@solutionerp.local GĐ Dự án FLOCK 01 (PM) + ccm.tran@solutionerp.local TPB Kiểm soát chi phí (CCM + TPB) + pro.pham@solutionerp.local TPB Cung ứng (PRO + TPB) + fin.do@solutionerp.local TPB Tài chính (FIN + TPB) + act.vu@solutionerp.local Kế toán trưởng (ACT + TPB) + equ.bui@solutionerp.local TPB Thiết bị (EQU + TPB) + hra.dang@solutionerp.local TPB HRA (HRA + TPB) + qs.hoang, qs.ngo QS công trường (NV.PB) + nv.cao, nv.dinh NV Cung ứng/Tài chính (NV.PB) + +⚠ Rotate ALL passwords trước UAT thật ``` - API prod: https://api.huypham.vn — `/health/live`, `/health/ready` diff --git a/docs/STATUS.md b/docs/STATUS.md index 23dc0ae..be751b7 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -2,9 +2,9 @@ > **Update rule:** trước khi bắt đầu 1 task → ghi row vào `🔥 In Progress`. Xong → chuyển sang `✅ Recently Done`. -**Last updated:** 2026-04-23 09:30 (post-skill-governance + cron audit định kỳ) +**Last updated:** 2026-04-23 16:00 (post-toolkit + 4-bảng overhaul + master data + roles VN) -## 📍 Phase hiện tại: **Tier 3 feature-complete + skill governance** — Prod live, 6 skill project-level + audit cron 1/tháng. Còn: UAT thật + Email outbox (chờ SMTP) + rotate creds. +## 📍 Phase hiện tại: **Tier 3 + 4-bảng data model + master catalogs + roles VN** — Prod live, 36 DB tables, ~80 endpoints, 11 migrations. Còn: UAT thật + Email outbox (chờ SMTP) + rotate creds. ### 🌐 Production URLs @@ -22,6 +22,13 @@ _(không có — Tier 3 + skill governance đóng gói xong, chờ UAT + chờ c | Ngày | Ai | Task | Commit | |---|---|---|---| +| 2026-04-23 | Claude | **Roles VN labels (ShortName) + Users dept/position + 13 demo users** — Migration 11 `AddRoleShortNameAndUserDepartment`. Role thêm ShortName max 50 (QTV/BOD/CCM/PRO/FIN/...) + Description full VN. User thêm DepartmentId FK Restrict + Position. Idempotent backfill 12 roles VN labels. Seed 13 demo users (bod/pm/ccm/pro/fin/act/equ/hra TPB + 4 Drafter), pwd `User@123456`. FE UsersPage column Phòng ban + Chức vụ + edit dialog mới + roles checkbox "ShortName — Full". PermissionsPage Panel 1 2-line per role. | `330d529` + `ae59cfe` | +| 2026-04-23 | Claude | **4 master catalogs cho Details + datalist autocomplete** — Migration 10 `AddMasterCatalogs`: UnitsOfMeasure (20 seed) + MaterialItems (15) + ServiceItems (10) + WorkItems (15). CQRS CRUD 13 endpoint, Admin role POST/PUT/DELETE. Menu mới `Catalogs` group + 4 leaves dưới Master. FE Admin CatalogsPage generic 4-tab CRUD `/master/catalogs/:kind`. FE Details Add form HTML5 `` per field + smart-fill (pick code → autofill name + defaultUnit). DB 32→36 bảng. | `e27c547` + `16e24ed` | +| 2026-04-23 | Claude | **Mã HĐ gen ngay tại CreateContract + backfill HĐ legacy** — `CreateContractCommandHandler` call `codeGenerator.GenerateAsync` trước `db.Contracts.Add`. TransitionAsync giữ defensive `if MaHopDong null gen` cho legacy. `BackfillContractCodesAsync` trong DbInitializer chạy startup, idempotent (NULL count → skip nếu 0). Trade-off: gap sequence khi reject nhưng user có mã ngay đầu để reference giấy tờ. | `51449d6` | +| 2026-04-23 | Claude | **"Thao tác" 2-panel + Edit/Xóa hover + Detail preview** — `ContractCreatePage` rewrite: Panel 1 List HĐ theo type + button "+ Thêm mới" cuối. Panel 2 ContractHeaderForm (new) hoặc ContractEditForm (edit) + Chi tiết section. URL state ?type/?id/?mode=new. Action buttons row Panel 1: Edit ✏ + Xóa 🗑 luôn hiện, mờ + disabled khi Phase != DangSoanThao. ContractDetailsPreview cho create mode show table headers + lock icon. | `8c4b4da` + `ec0c983` + `501b4de` + `7f26ff9` + `39031ca` | +| 2026-04-23 | Claude | **Panel 2 layout: tabs → 7/3 grid (UX iter 2)** — Bỏ tabs Tổng quan/Chi tiết/Lịch sử. Render flat: Tổng quan (Info+Comments+Attachments) ở trên, dưới grid lg:grid-cols-10 (Chi tiết 7 cột + Lịch sử Changelog 3 cột). | `b3762af` (tabs) → `ad0652d` (grid) | +| 2026-04-23 | Claude | **4-bảng data model overhaul (Header+Details+Workflow+Changelog)** — Migration 9 `AddContractDetailsAndChangelog`: 7 ContractType-specific Details bảng + 1 ContractChangelog unified audit log. IChangelogService 5 method, wired vào CreateContract+UpdateDraft+AddComment+Upload/Delete/Transition. CQRS 9 endpoint mới (GetBundle+7 Add+Delete+ListChangelogs). FE ContractDetailsTab + ContractChangelogsTab. DB 24→32 bảng. | `70810e1` + `71c035d` + `e684455` | +| 2026-04-23 | Claude | **3-panel layout HĐ (List/Detail/Workflow) + Inbox + sidebar accordion + UserDashboard fix** — MyContractsPage + ContractsListPage + InboxPage 3-panel `lg:grid-cols-[320px_1fr_360px]`, `?id=` URL state, mobile fallback fullpage. Sidebar accordion qua AccordionContext (chỉ 1 Ct_ expand). Tách "Tổng quan" → /dashboard riêng (fix bug trùng /inbox), UserDashboardPage 5-card "Của tôi" + recent contracts. | `b75448e` + `89c7e88` + `7ea3957` + `d326e80` | | 2026-04-23 | Claude | **Skill governance + audit định kỳ** — `docs/rules.md §9` mới (6 skill bảng, nguyên tắc tạo project-specific, format SKILL.md bắt buộc, workflow audit 7 bước, 4 anti-patterns). Cron task `solution-erp-skill-audit-monthly` fire 9:00 AM ngày 1 mỗi tháng (next 2026-05-01) — self-contained prompt cold-start, auto-refresh stale nhỏ + đề xuất add/archive cho human approve, log vào `docs/changelog/skill-audit-{YYYY-MM}.md`, ABORT nếu repo dirty. Touch-points: CLAUDE.md callout + HANDOFF A1 + migration-todos checkbox + skill scope commit | `b904a25` | | 2026-04-23 | Claude | **3 skill ops project-specific** — Khảo sát alirezarezvani/claude-skills, quyết định KHÔNG bulk-clone (skill global đã cover phần generic, repo còn lại doc-dump không có when-to-use). Viết 3 skill mới encode SOLUTION_ERP-only: `dependency-audit-erp` (npm/dotnet CVE scan respect MediatR 12.4.1 + Swashbuckle 6.9.0 pin), `ef-core-migration` (8 migration history + 3-file rule + DesignTimeDbContextFactory + 6 pitfalls cụ thể), `iis-deploy-runbook` (3 IIS site + win-acme + NSSM gitea-runner + LibreOffice + debug playbook 500/502/SignalR). Total skill project-level = 6 (3 domain + 3 ops) | `661f859` | | 2026-04-22 | Claude | **PermissionsPage 3-panel layout** — Grid `lg:grid-cols-[280px_1fr_300px]`: Panel 1 Role list click-to-select (active ring-brand), Panel 2 Menu×CRUD matrix sticky thead + search + column bulk-toggle + brand-tinted hover, Panel 3 Granted progress bar + CRUD breakdown color badges (slate/emerald/amber/red) + Tip | `91b2da1` | @@ -54,7 +61,7 @@ _(không có — Tier 3 + skill governance đóng gói xong, chờ UAT + chờ c | 2026-04-21 | Claude | **Phase 1 foundation** + Docs addition | `702411f` + `49a5f57` | | 2026-04-21 | Claude | **Phase 0** | `25dad7f` | -Session logs: [P0](changelog/sessions/2026-04-21-1045-phase0-scaffold.md) · [P1f](changelog/sessions/2026-04-21-1100-phase1-foundation.md) · [P1.2](changelog/sessions/2026-04-21-1130-phase1-cruds-permission.md) · [P2](changelog/sessions/2026-04-21-1200-phase2-form-engine.md) · [P3](changelog/sessions/2026-04-21-1330-phase3-workflow.md) · [P4](changelog/sessions/2026-04-21-1430-phase4-report.md) · [P5prep](changelog/sessions/2026-04-21-1530-phase5-prep.md) · [Tier 3](changelog/sessions/2026-04-22-0300-tier3-feature-complete.md) · [**Skill gov**](changelog/sessions/2026-04-23-0900-skill-governance.md) +Session logs: [P0](changelog/sessions/2026-04-21-1045-phase0-scaffold.md) · [P1f](changelog/sessions/2026-04-21-1100-phase1-foundation.md) · [P1.2](changelog/sessions/2026-04-21-1130-phase1-cruds-permission.md) · [P2](changelog/sessions/2026-04-21-1200-phase2-form-engine.md) · [P3](changelog/sessions/2026-04-21-1330-phase3-workflow.md) · [P4](changelog/sessions/2026-04-21-1430-phase4-report.md) · [P5prep](changelog/sessions/2026-04-21-1530-phase5-prep.md) · [Tier 3](changelog/sessions/2026-04-22-0300-tier3-feature-complete.md) · [Skill gov](changelog/sessions/2026-04-23-0900-skill-governance.md) · [**Toolkit+4-bảng+Roles VN**](changelog/sessions/2026-04-23-1500-toolkit-data-roles.md) **Docs entry points:** @@ -62,8 +69,8 @@ Session logs: [P0](changelog/sessions/2026-04-21-1045-phase0-scaffold.md) · [P1 - [`workflow-contract.md`](workflow-contract.md) · [`forms-spec.md`](forms-spec.md) - [`database/database-guide.md`](database/database-guide.md) · [`database/schema-diagram.md`](database/schema-diagram.md) - [`flows/`](flows/) (7 file) · [`guides/`](guides/) (4 file) · [`gotchas.md`](gotchas.md) -- [`changelog/migration-todos.md`](changelog/migration-todos.md) · [`changelog/sessions/`](changelog/sessions/) (12 file) -- [`.claude/skills/README.md`](../.claude/skills/README.md) — 6 skill (3 domain + 3 ops) · audit định kỳ 1/tháng (cron `solution-erp-skill-audit-monthly`) +- [`changelog/migration-todos.md`](changelog/migration-todos.md) · [`changelog/sessions/`](changelog/sessions/) (13 file) +- [`.claude/skills/README.md`](../.claude/skills/README.md) — 6 skill (3 domain + 3 ops) · audit định kỳ 1/tháng (cron `solution-erp-skill-audit-monthly` next 2026-05-01) ## 🎯 Next up @@ -99,17 +106,18 @@ Session logs: [P0](changelog/sessions/2026-04-21-1045-phase0-scaffold.md) · [P1 ## 📊 Thông số cumulative -| | P0 | P1f | P1.2 | P2 | P3 | P4 | P5prep | **Tier3** | -|---|---:|---:|---:|---:|---:|---:|---:|---:| -| BE LOC | 0 | ~400 | ~1500 | ~1900 | ~2700 | ~3100 | ~3300 | **~4800** | -| DB tables | 0 | 7 | 12 | 14 | 19 | 19 | 19 | **24** (+Notifications, +WorkflowTypeAssignments, +WorkflowDefinitions, +WorkflowSteps, +WorkflowStepApprovers) | -| API endpoints | 0 | 4 | 20 | 23 | 31 | 33 | 35 | **~50** (+notifications, +attachments, +forms CRUD, +pdf export, +workflows admin, +my-dashboard) | -| Migrations | 0 | 1 | 3 | 4 | 5 | 5 | 5 | **8** (+AddNotifications, +AddWorkflowTypeAssignments, +AddVersionedWorkflows) | -| FE pages | 0 | 2 | 6 | 7 | 14 | 16 | 16 | **~20** (admin Users/Workflows per-type + user nested menu) | -| Scripts PS | 0 | 0 | 0 | 1 | 1 | 1 | 3 | **4** (+install-libreoffice) | -| CI/CD workflow | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | -| Docs | 10 | 13 | 14 | 24 | 26 | 30 | 35 | **~40** (+session log + updated MDs) | -| Commits | 1 | 2 | 3 | 5 | 6 | 7 | 8 | **~25** | +| | P0 | P1f | P1.2 | P2 | P3 | P4 | P5prep | Tier3 | **+Toolkit/Catalogs/Roles** | +|---|---:|---:|---:|---:|---:|---:|---:|---:|---:| +| BE LOC | 0 | ~400 | ~1500 | ~1900 | ~2700 | ~3100 | ~3300 | ~4800 | **~7800** | +| DB tables | 0 | 7 | 12 | 14 | 19 | 19 | 19 | 24 | **36** (+7 Details +1 Changelog +4 Catalogs) | +| API endpoints | 0 | 4 | 20 | 23 | 31 | 33 | 35 | ~50 | **~80** (+9 Details/Changelogs +13 Catalogs CRUD) | +| Migrations | 0 | 1 | 3 | 4 | 5 | 5 | 5 | 8 | **11** (+AddContractDetailsAndChangelog +AddMasterCatalogs +AddRoleShortNameAndUserDepartment) | +| FE pages | 0 | 2 | 6 | 7 | 14 | 16 | 16 | ~20 | **~22** (+UserDashboard +CatalogsPage) | +| FE components | — | — | — | — | — | — | — | many | +ContractDetailContent +WorkflowHistoryPanel +ContractDetailsTab +ContractChangelogsTab +ContractDetailsPreview | +| Scripts PS | 0 | 0 | 0 | 1 | 1 | 1 | 3 | 4 | 4 | +| CI/CD workflow | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | +| Docs | 10 | 13 | 14 | 24 | 26 | 30 | 35 | ~40 | **~42** (+session log toolkit) | +| Commits | 1 | 2 | 3 | 5 | 6 | 7 | 8 | ~25 | **~47** | ## 🚨 Blockers / risks diff --git a/docs/changelog/migration-todos.md b/docs/changelog/migration-todos.md index 79a7988..22d7c5c 100644 --- a/docs/changelog/migration-todos.md +++ b/docs/changelog/migration-todos.md @@ -253,6 +253,23 @@ - [ ] **Audit 2026-07-01** - [ ] (lập lại mỗi tháng đầu) +## Session 2026-04-23 (chiều) — Toolkit + 4-bảng + Master Catalogs + Roles VN + +- [x] **3-panel layout HĐ list/inbox/thao tác** (commits b75448e/89c7e88/8c4b4da) +- [x] **Sidebar accordion** menu loại HĐ (`7ea3957`) +- [x] **Tách Tổng quan → /dashboard riêng** fix bug trùng /inbox (`d326e80`) +- [x] **4-bảng overhaul** Header/7 Details/Workflow/Changelog (Migration 9, `70810e1`) +- [x] **IChangelogService** + integrate vào CRUD/Workflow handlers (`71c035d`) +- [x] **Details CRUD endpoints + Changelogs query** (`e684455`) +- [x] **FE Panel 2 7/3 grid** (Chi tiết + Lịch sử inline, `ad0652d`) +- [x] **Edit/Xóa hover row Panel 1 Thao tác** (mờ khi != DangSoanThao, `7f26ff9`) +- [x] **Mã HĐ gen ngay tại Create + backfill legacy** (`51449d6`) +- [x] **4 master catalogs** Units/Materials/Services/WorkItems (Migration 10, `e27c547`) +- [x] **Admin CatalogsPage** + datalist autocomplete trong Details form (`16e24ed`) +- [x] **Roles VN labels** ShortName + Description backfill (Migration 11, `330d529`) +- [x] **Users +DepartmentId/Position** + 13 demo users seed (`330d529`) +- [x] **FE UsersPage** dept dropdown + position field + role badge ShortName (`ae59cfe`) + ## Tier 3 ERP (Session 2026-04-22) — feature-complete - [x] **Attachment upload E2E** — IFileStorage + CQRS + FE drag-drop (gotcha path-traversal) — `c8d0070` diff --git a/docs/changelog/sessions/2026-04-23-1500-toolkit-data-roles.md b/docs/changelog/sessions/2026-04-23-1500-toolkit-data-roles.md new file mode 100644 index 0000000..1ea9a4c --- /dev/null +++ b/docs/changelog/sessions/2026-04-23-1500-toolkit-data-roles.md @@ -0,0 +1,256 @@ +# Session 2026-04-23 ~15:00 — Toolkit + 4-bảng overhaul + master data + roles VN + +**Focus:** Sang phiên 2 trong ngày — UX redesign toàn bộ surface HĐ +(3-panel List/Detail/Workflow + Inbox + Thao tác), data model overhaul +4-bảng (Header/Details/Workflow/Changelog), master catalogs cho Details, +chi tiết Users/Departments/Roles VN. + +11 commit (b75448e → ae59cfe), 2 migration (9 + 10 + 11), DB 24→36 bảng. + +## Outcomes + +### A. 3-panel layout cho List/Inbox (UX) ✓ + +- `MyContractsPage` (fe-user): `lg:grid-cols-[320px_1fr_360px]` — + Panel 1 List + search + filter | Panel 2 Detail content | + Panel 3 Workflow + Lịch sử duyệt +- `ContractsListPage` (fe-admin): same pattern + Pagination compact +- `InboxPage` (fe-user): same + 4 StatPill inline (Cần xử lý / Sắp QH / + Quá hạn / Giá trị) + vai trò amber banner +- URL state `?id=` selected — bookmarkable, refresh giữ +- Mobile fallback (` expand cùng lúc (accordion) +- Auto-expand theo URL `?type=X` qua useEffect + AccordionContext +- Highlight active group: bg-slate-50 + text-slate-900 +- Commit: 7ea3957 + +### C. Tách "Tổng quan" → `/dashboard` riêng (fix bug trùng /inbox) ✓ + +- `UserDashboardPage` mới: 5-card "Của tôi" (DraftsInProgress / Pending / + DueSoon / Overdue / TotalValue) + section HĐ gần đây +- Layout resolvePath: Dashboard → /dashboard (không trùng Hộp thư) +- App route: / redirect → /dashboard +- Commit: d326e80 + +### D. Data model 4-bảng overhaul (Tier 3 follow-up) ✓ + +User decision Option B: bảng riêng cho mỗi loại HĐ. + +**Migration 9 — `AddContractDetailsAndChangelog`:** +- 7 Details bảng: ThauPhuDetails, GiaoKhoanDetails, NhaCungCapDetails, + DichVuDetails, MuaBanDetails, NguyenTacNccDetails, NguyenTacDvDetails + - Common base: ContractId FK Cascade, Order, ThanhTien decimal(18,2), + GhiChu, audit fields + - Schema chuyên biệt per loại HĐ (vd MuaBan có ThueVAT, NguyenTac có + DonGiaToiThieu/ToiDa) +- 1 ContractChangelogs bảng — unified audit log: + - EntityType enum: Contract | Detail | Workflow | Comment | Attachment + - Action enum: Insert | Update | Delete | Transition + - PhaseAtChange + UserName denormalize + FieldChangesJson + ContextNote +- DB 24 → 32 bảng + +**IChangelogService (App + Infra):** +- 5 method: LogContractChange / LogDetailChange / LogWorkflowTransition / + LogCommentAdded / LogAttachment +- Wired vào: CreateContract + UpdateContractDraft (with diff) + + AddComment + Upload/Delete Attachment + ContractWorkflowService.Transition + +**CQRS + API:** +- GetContractDetailsQuery dispatch theo Type → bundle 7 lists +- 7 typed AddXxxDetailCommand handler (Insert + log changelog) +- DeleteContractDetailCommand generic (dispatch theo Type) +- ListContractChangelogsQuery (read-only, desc CreatedAt, top 200) +- 9 endpoints mới ContractsController + +Commits: 70810e1, 71c035d, e684455 + +### E. FE Panel 2 — tabs → 7/3 grid layout (UX iter 2) ✓ + +**Iter 1 (b3762af):** Tabs Tổng quan / Chi tiết / Lịch sử +**Iter 2 (ad0652d):** Bỏ tabs, hiển thị flat: +- Tổng quan content (Info + Comments + Attachments) ở trên +- Bên dưới grid 7-3: [Chi tiết Tab] [Lịch sử Changelog Tab] + +`ContractDetailsTab`: +- 7 table renderers per type (HEADERS_BY_TYPE + DeleteBtn) +- AddRowForm với FIELDS_BY_TYPE (5-7 field per type) +- buildPayload auto compute thanhTien (SL × DonGia × (1+VAT/100) cho MuaBan) +- canEdit chỉ khi Phase=DangSoanThao + +`ContractChangelogsTab`: +- Render unified timeline desc CreatedAt +- Icon + tone color theo EntityType +- Expandable detail row hiển thị FieldChangesJson (Cũ → Mới) + +### F. "Thao tác" — 2-panel + Edit/Xóa hover + Mở fullpage ✓ + +`ContractCreatePage` rewrite: +- 2-panel: Panel 1 List HĐ theo type + button "+ Thêm mới" cuối | + Panel 2 Header form (new/edit) + Chi tiết section +- URL state: ?type / ?id / ?mode=new +- Empty state khi chưa chọn +- Action buttons hover row: Edit ✏ + Xóa 🗑 (luôn hiện, mờ khi + Phase != DangSoanThao + tooltip "Chỉ sửa được khi Đang soạn thảo") +- ContractDetailsPreview cho create mode — show table headers + lock + icon + disabled add button (user thấy structure trước khi tạo Header) + +Commits: 8c4b4da, ec0c983, 501b4de, 7f26ff9, 39031ca + +### G. Mã HĐ gen ngay tại Create + backfill ✓ + +User feedback: HĐ phải có mã ngay khi tạo, không đợi DangDongDau. + +- `CreateContractCommandHandler`: gen mã trước khi `db.Contracts.Add` — + GenerateAsync chạy SERIALIZABLE riêng, entity chưa tracked nên không + bị save kèm +- TransitionAsync giữ defensive `if (MaHopDong is null) gen` cho legacy +- `BackfillContractCodesAsync` trong DbInitializer — chạy 1 lần + startup, idempotent (count NULL → skip nếu 0), log success/failed + +Commit: 51449d6 + +### H. 4 master catalogs cho Details (migration 10) ✓ + +User feedback: thêm Master Data cho phần Chi tiết. + +**Domain entities (4 mới):** +- `UnitOfMeasure` (UnitsOfMeasure) — m2, kg, ngc, ... +- `MaterialItem` (MaterialItems) — Code, Name, Category (NhomSP), + DefaultUnit, Specification, OriginCountry, IsActive +- `ServiceItem` (ServiceItems) — vận chuyển, bảo trì, tư vấn, ... +- `WorkItem` (WorkItems) — đào móng, đổ bê tông, xây tường, ... + +Common pattern: AuditableEntity, Code unique, Category index, IsActive. + +**Migration 10 — `AddMasterCatalogs`:** DB 32 → 36 bảng. + +**Seed defaults idempotent:** +- 20 UnitsOfMeasure (m2/m3/kg/tan/l/cai/bo/goi/ngc/h/ca/...) +- 15 MaterialItems demo (xi măng PCB40, cát vàng, đá 1x2, thép D10, ...) +- 10 ServiceItems demo (vận chuyển, bảo trì, tư vấn, kiểm định, ...) +- 15 WorkItems demo (đào móng, đổ bê tông, xây tường, lát gạch, ...) + +**CQRS:** CatalogsFeatures.cs (~290 dòng) — 4 catalog × 5 handlers +(List + Create + Update + Delete + unique code guard). + +**Controller:** 13 endpoints — GET open cho mọi role (autocomplete); +POST/PUT/DELETE Admin role only. + +**Menu mới (5):** +- Catalogs group "Danh mục chi tiết" dưới Master +- 4 leaves: Đơn vị tính / Vật tư SP / Dịch vụ / Hạng mục công việc + +**FE Admin CatalogsPage:** 1 page generic, URL `/master/catalogs/:kind`, +4 sub-tabs (units/materials/services/work-items), per-kind FIELDS config, +form Dialog với input/textarea/checkbox. + +**FE Details Add form datalist autocomplete:** +- Fetch 4 catalogs qua TanStack Query (cache 'catalogs') +- HTML5 `` per relevant field (donViTinh/maSP/tenSP/hangMuc/...) +- Smart-fill: user pick code → autofill name + defaultUnit (sibling + fields) qua handleFieldChange + +Commits: e27c547, 16e24ed + +### I. Roles VN labels + Users dept/position + 13 demo users (migration 11) ✓ + +**Entity changes:** +- `Role` + `ShortName` (max 50) — Mã viết tắt VN +- `User` + `DepartmentId` Guid? FK Departments (Restrict) + `Position` + +**Migration 11 — `AddRoleShortNameAndUserDepartment`:** thêm cột, không +table mới. DB vẫn 36 bảng. + +**12 roles VN labels** (idempotent backfill nếu existing role thiếu): +| Code | Short | Description | +|---|---|---| +| Admin | QTV | Quản trị viên hệ thống | +| Drafter | NV.PB | Nhân viên phòng ban (soạn HĐ) | +| DeptManager | TPB | Trưởng phòng ban | +| ProjectManager | PM | Giám đốc dự án | +| Procurement | PRO | Phòng Cung ứng | +| CostControl | CCM | Phòng Kiểm soát chi phí | +| Finance | FIN | Phòng Tài chính | +| Accounting | ACT | Phòng Kế toán | +| Equipment | EQU | Phòng Thiết bị | +| Director | BOD | Ban Giám đốc | +| AuthorizedSigner | NĐUQ | Người được Ủy quyền ký HĐ | +| HrAdmin | HRA | Phòng Nhân sự - Hành chính | + +**Identity Name = code English giữ nguyên** (FK + [Authorize] attr). +Chỉ thêm 2 cột display VN. + +**13 Demo users seed (password `User@123456`):** +- bod.huynh + bod.le (BOD) +- pm.nguyen (PM) +- TPB cho CCM/PRO/FIN/ACT/EQU/HRA (6 user) +- qs.hoang + qs.ngo (QS Drafter) +- nv.cao + nv.dinh (PRO/FIN Drafter) + +**FE Admin updates:** +- `types/users.ts`: RoleShortName + RoleLabel + roleDisplayName helper +- `UsersPage`: column Phòng ban + Chức vụ, badge Vai trò = ShortName + (tooltip full label), Edit dialog mới (dept/position/active), + Create dialog 2-col grid + dropdown Phòng ban, Roles checkbox + "ShortName — Full Label" +- `PermissionsPage` Panel 1: 2-line per role (ShortName semibold + + Description small) + +Commits: 330d529, ae59cfe + +## Stats cumulative + +| | Trước session | Sau session | Δ | +|---|---|---|---| +| BE LOC | ~4800 | ~7800 | +3000 | +| DB tables | 24 | **36** | +12 (7 details + 1 changelog + 4 catalogs) | +| Migrations | 8 | **11** | +3 (Migration 9/10/11) | +| API endpoints | ~50 | **~80** | +30 (details CRUD + catalogs CRUD + changelogs) | +| FE pages | ~20 | **~22** | +2 (UserDashboardPage + CatalogsPage) | +| FE components | many | many+ | +ContractDetailContent/WorkflowHistoryPanel/ContractDetailsTab/ContractChangelogsTab/ContractDetailsPreview | +| Commits session này | — | **22** | b75448e → ae59cfe | + +## Architectural decisions + +1. **Option B per-type Details** (vs single bảng + JSON): chuẩn schema, + strict typing, TS strict mode FE bắt typo. Trade-off: 7 bảng riêng + + nhiều handler lặp pattern. Worth. + +2. **ContractChangelogs unified** — 1 bảng audit cho mọi entity HĐ + (Contract/Detail/Workflow/Comment/Attachment), KHÁC ContractApprovals + (workflow-only, dùng cho guard). View layer cho user đọc lịch sử. + +3. **Mã HĐ gen tại Create** (vs DangDongDau) — trade-off: gap trong + sequence khi reject, nhưng user có mã ngay từ đầu để reference. + +4. **Datalist HTML5 native autocomplete** (vs library combobox) — đủ + cho MVP, không add dependency, smart-fill qua handleFieldChange. + +5. **Identity Name English giữ nguyên + thêm ShortName/Description VN** + — không break FK, không cần data migration; FE/BE display layer + convert qua dict mapping. + +6. **Per-type bảng Details không có User-level approver runtime guard + yet** — data model `WorkflowStepApprover.Kind=User` đã có, nhưng + transition guard v1 chỉ check Role-kind. Iter sau enable. + +## Next session priority + +1. **UAT 2-3 user thật** — hard requirement +2. Email outbox (chờ SMTP config) +3. Rotate creds (SA/vrapp/JWT/admin) +4. SQL backup Task Scheduler +5. Roles CRUD admin (custom role ngoài 12 hardcoded) +6. User-kind approver runtime guard +7. PermissionsPage: grant Workflows.Read non-admin → Wf_* visible +8. Update docs (sẽ làm trong commit chốt session này) + +## Cron audit fire 2026-05-01 + +Cron task `solution-erp-skill-audit-monthly` sẽ chạy tự động đầu tháng +sau — log vào `docs/changelog/skill-audit-2026-05.md` + commit auto. diff --git a/docs/database/schema-diagram.md b/docs/database/schema-diagram.md index 873a21a..a48bf20 100644 --- a/docs/database/schema-diagram.md +++ b/docs/database/schema-diagram.md @@ -1,6 +1,6 @@ # Schema Diagram — Luồng DB SOLUTION_ERP -> ERD đầy đủ + mối quan hệ **24 table** sau Tier 3 (Notifications + Versioned workflows). Mermaid render ở VS Code / GitHub / Gitea. +> ERD đầy đủ + mối quan hệ **36 table** sau Migration 11 (Tier 3 + 4-bảng overhaul + 4 master catalogs + Role/User VN). Mermaid render ở VS Code / GitHub / Gitea. ## 1. Full ERD @@ -477,8 +477,67 @@ COMMIT; | 6 | `AddNotifications` | Notifications | | 7 | `AddWorkflowTypeAssignments` | WorkflowTypeAssignments (admin override legacy) | | 8 | `AddVersionedWorkflows` | WorkflowDefinitions, WorkflowSteps, WorkflowStepApprovers + Contracts.WorkflowDefinitionId FK | +| **9** | **`AddContractDetailsAndChangelog`** | **7 ContractType-specific Details + ContractChangelogs (unified audit log)** | +| **10** | **`AddMasterCatalogs`** | **UnitsOfMeasure, MaterialItems, ServiceItems, WorkItems** | +| **11** | **`AddRoleShortNameAndUserDepartment`** | **+Role.ShortName + User.DepartmentId/Position (cột thêm, không bảng mới)** | -Tổng: **24 bảng** (+ `__EFMigrationsHistory` hệ thống). +Tổng: **36 bảng** (+ `__EFMigrationsHistory` hệ thống). + +## 8bis. Bảng mới sau Migration 9-11 + +### Per-type Details (7 bảng — Migration 9) + +Mỗi loại HĐ có bảng riêng. Common base: `Id`, `ContractId` FK Cascade, +`Order` int, `ThanhTien` decimal(18,2), `GhiChu` nvarchar(1000) + +`AuditableEntity` (CreatedAt/By/UpdatedAt/By). + +| Bảng | Loại HĐ (Type) | Field đặc trưng | +|---|---|---| +| `ThauPhuDetails` | 1 | HangMuc, DonViTinh, KhoiLuong, DonGia, ThoiGianHoanThanh | +| `GiaoKhoanDetails` | 2 | MaCongViec, TenCongViec, KhoiLuong, DonGia, YeuCauKyThuat | +| `NhaCungCapDetails` | 3 | MaSP, TenSP, ThongSoKyThuat, SoLuong, DonGia, ThoiGianGiao, XuatXu | +| `DichVuDetails` | 4 | MaDichVu, TenDichVu, ThoiGian, DonGia, TuNgay/DenNgay | +| `MuaBanDetails` | 5 | MaSP, TenSP, SoLuong, DonGia, **ThueVAT** decimal(5,2), XuatXu | +| `NguyenTacNccDetails` | 6 | NhomSP, TenSP, **DonGiaToiThieu/ToiDa** (range), DieuKien | +| `NguyenTacDvDetails` | 7 | LoaiDichVu, TenDichVu, DonGiaToiThieu/ToiDa, PhamViDichVu, SLA | + +### ContractChangelogs (Migration 9) + +Unified audit log cho mọi entity HĐ: +- `Id`, `ContractId` FK Cascade +- `EntityType` int enum: 1=Contract, 2=Detail, 3=Workflow, 4=Comment, 5=Attachment +- `EntityId` Guid? (PK của child entity, null nếu là Header) +- `Action` int enum: 1=Insert, 2=Update, 3=Delete, 4=Transition +- `PhaseAtChange` int? (snapshot Phase tại thời điểm change) +- `UserId` Guid? + `UserName` nvarchar(200) (denormalize cho readable) +- `Summary` nvarchar(500), `FieldChangesJson` nvarchar(max), `ContextNote` nvarchar(2000) +- Indexes: (ContractId, CreatedAt), (ContractId, EntityType) + +### 4 Master Catalogs (Migration 10) + +Phục vụ autocomplete trong Details add form (FE HTML5 datalist). + +| Bảng | Field | Dùng cho HĐ Detail | +|---|---|---| +| `UnitsOfMeasure` | Code, Name, Description | Tất cả 7 type (donViTinh) | +| `MaterialItems` | Code, Name, Category, DefaultUnit, Specification, OriginCountry, IsActive | NCC + Mua bán + Nguyên tắc NCC | +| `ServiceItems` | Code, Name, Category, DefaultUnit, Description, IsActive | Dịch vụ + Nguyên tắc DV | +| `WorkItems` | Code, Name, Category, DefaultUnit, Description, IsActive | Thầu phụ + Giao khoán | + +Common: `AuditableEntity`, `IX__Code` UNIQUE filtered `IsDeleted=0`, +`IX_
_Category`, `HasQueryFilter !IsDeleted`. + +### Identity columns thêm (Migration 11) + +**Role:** +- `ShortName` nvarchar(50) — Mã viết tắt VN (QTV/BOD/CCM/PRO/FIN/...) +- `Description` đã có — full Vietnamese label + +**User:** +- `DepartmentId` Guid? FK Departments **OnDelete Restrict** (không xóa + dept nếu còn user reference) +- `Position` nvarchar(200) — chức vụ free text +- `IX_Users_DepartmentId` ## 9. Versioned workflow invariants