Files
solution-erp/docs/changelog/sessions/2026-04-24-1030-pe-polish-demo-maphieu-perms.md
pqhuy1987 c48ac2116d [CLAUDE] PurchaseEvaluation: demo seed 4 phieu + MaPhieu atomic sequence + Pe_* perm defaults
Polish session tiep cua PE module skeleton (commit 2c6f0ca..3990066):
3 task A (MISSING in MVP) khac STATUS.md In Progress:

1. Demo PE data seed (SeedDemoPurchaseEvaluationsAsync)
   - 4 phieu varied A/B x phase: A-001 DangSoanThao (mo), A-002
     ChoCEODuyetNCC (winner+9 quotes), A-003 DaDuyet (chua tao HD,
     PaymentTerms JSON), B-001 ChoDuAn (5-step giua chung).
   - Idempotent: skip-if-[DEMO]-exists.
   - Approval history dung policy A (3-step) hoac B (5-step).

2. MaPhieu atomic sequence — Migration 13
   - Format PE/{YYYY}/{TypeLetter}/{Seq:D3} (vd PE/2026/A/001).
   - PurchaseEvaluationCodeSequence entity (Prefix PK).
   - IPurchaseEvaluationCodeGenerator + impl SERIALIZABLE
     transaction (mirror ContractCodeGenerator 1:1).
   - Replace Random.Shared trong CreatePurchaseEvaluationCommandHandler.
   - Migration AddPurchaseEvaluationCodeSequences (1 bang).

3. Pe_* permission defaults
   - SeedPurchaseEvaluationPermissionDefaultsAsync — 7 role business x 9 menu key.
   - Drafter/DeptManager/Procurement: R+C+U; CostControl/PM/Director/AuthorizedSigner: R+U.
   - DeptManager them Delete (xoa nhap).
   - Idempotent per-(roleId x menuKey).

Build: 0 error, 2 warning (pre-existing DocxRenderer).

Files: 4 new + 8 modified (1 migration + entity + generator + DI + 2 ctx + 2 features).

Resolves: STATUS.md In Progress §A — 3 item PE MISSING.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 10:41:17 +07:00

128 lines
5.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Session 2026-04-24 sáng — PE polish: Demo seed + MaPhieu atomic + Pe_* perm defaults
**Context:** Tiếp nối session "[Roles+Demo+Pending cleanup]" (commit a667665) — user yêu cầu
"Chốt lại toàn bộ MD: 'rules, architech, gotcha, skill, daily, hand-off, DB,
luồng DB ...' và làm tiếp đi nhé." → continue PE polish theo STATUS.md §🔥 In
Progress nhóm A (chức năng MISSING trong MVP).
## Tasks completed (4)
### 1. Demo PE data seed — 4 phiếu varied
**File:** `src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs`
`SeedDemoPurchaseEvaluationsAsync` — pattern mirror `SeedDemoContractsAsync`:
| Phiếu | Type | Phase | Đặc điểm | Quotes |
|---|---|---|---|---|
| `[DEMO]-A-001` | DuyetNcc | DangSoanThao | Drafter mới mở, chưa nhập giá | 0 |
| `[DEMO]-A-002` | DuyetNcc | ChoCEODuyetNCC | Winner đề xuất + 9 quotes 3×3 grid | 9 |
| `[DEMO]-A-003` | DuyetNcc | DaDuyet | Chưa tạo HĐ — showcase kế thừa + PaymentTerms JSON | 4 |
| `[DEMO]-B-001` | DuyetNccPhuongAn | ChoDuAn | 5-step giữa chừng (Procurement đã chuyển) | 9 |
**Idempotent:** skip nếu MaPhieu prefix `[DEMO]` exists. Approval history seed
đúng theo policy A (3-step Procurement→CCM→CEO) hoặc B (5-step
Procurement→PM→CCM→CEO PA→CEO NCC). ApproverUserId mapping đúng role.
**Resolves:** STATUS.md §🔥 A — "Demo PE data seed".
### 2. MaPhieu atomic sequence — Migration 13
**Files mới:**
- `src/Backend/SolutionErp.Domain/PurchaseEvaluations/PurchaseEvaluationCodeSequence.cs` — Prefix PK + LastSeq + UpdatedAt
- `src/Backend/SolutionErp.Application/PurchaseEvaluations/Services/IPurchaseEvaluationWorkflowService.cs` — thêm `IPurchaseEvaluationCodeGenerator` interface
- `src/Backend/SolutionErp.Infrastructure/Services/PurchaseEvaluationCodeGenerator.cs` — impl SERIALIZABLE transaction
- `src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/20260424033449_AddPurchaseEvaluationCodeSequences.cs` — 1 bảng (Prefix nvarchar(100) PK)
**Files modified:**
- `IApplicationDbContext` + `ApplicationDbContext` thêm `PurchaseEvaluationCodeSequences` DbSet
- `PurchaseEvaluationConfiguration` thêm `PurchaseEvaluationCodeSequenceConfiguration` (Prefix max 100)
- `DependencyInjection` register Scoped `IPurchaseEvaluationCodeGenerator → PurchaseEvaluationCodeGenerator`
- `PurchaseEvaluationFeatures` `CreatePurchaseEvaluationCommandHandler` constructor inject codeGen, replace `Random.Shared` với `await codeGen.GenerateAsync(entity, ct)`
**Format:** `PE/{YYYY}/{TypeLetter}/{Seq:D3}` — VD `PE/2026/A/001`, `PE/2026/B/001`.
TypeLetter = `A` (DuyetNcc) | `B` (DuyetNccPhuongAn).
**Pattern mirror:** `ContractCodeGenerator` 1:1 — SERIALIZABLE transaction +
UPDATE-or-INSERT seq row + commit. Race-safe trên multi-instance.
**Resolves:** STATUS.md §🔥 A — "MaPhieu format chính thức".
### 3. Pe_* permission defaults — 7 role × 9 menu key
**File:** `src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs`
`SeedPurchaseEvaluationPermissionDefaultsAsync` — call cuối
`SeedAdminPermissionsAsync`. Strategy:
| Role | Read | Create | Update | Delete |
|---|---|---|---|---|
| Drafter, DeptManager, Procurement | ✓ | ✓ | ✓ | (chỉ DeptManager) |
| CostControl, ProjectManager, Director, AuthorizedSigner | ✓ | — | ✓ | — |
9 menu key per role: `PurchaseEvaluations` (root) + 2 group (`Pe_DuyetNcc`,
`Pe_DuyetNccPhuongAn`) + 6 leaf (List/Create/Pending × 2). Total ~63 row insert.
**Idempotent:** skip per-(roleId × menuKey) đã có row. Admin tinh chỉnh thêm
qua `/system/permissions`.
**Resolves:** STATUS.md §🔥 B — "Permission grant Pe_*".
### 4. Docs updates
- `docs/STATUS.md` — Phase line 7 "47 DB tables", "13 migrations". Tick `Demo PE data seed`, `MaPhieu format chính thức`, `Permission grant Pe_*`. Add Recently Done row.
- `docs/HANDOFF.md` — TL;DR update, gạch các item ✅ DONE, "47 DB tables" "13 migrations".
- `docs/changelog/migration-todos.md` — Tick 3 task PE.A.
## Build status
```
dotnet build SolutionErp.slnx --nologo -v minimal
→ Build succeeded. 2 Warning(s) (pre-existing DocxRenderer), 0 Error(s).
```
## Files touched (12)
**New (4):**
- `src/Backend/SolutionErp.Domain/PurchaseEvaluations/PurchaseEvaluationCodeSequence.cs`
- `src/Backend/SolutionErp.Infrastructure/Services/PurchaseEvaluationCodeGenerator.cs`
- `src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/20260424033449_AddPurchaseEvaluationCodeSequences.cs` + `.Designer.cs`
**Modified (8):**
- `src/Backend/SolutionErp.Application/Common/Interfaces/IApplicationDbContext.cs`
- `src/Backend/SolutionErp.Application/PurchaseEvaluations/Services/IPurchaseEvaluationWorkflowService.cs`
- `src/Backend/SolutionErp.Application/PurchaseEvaluations/PurchaseEvaluationFeatures.cs`
- `src/Backend/SolutionErp.Infrastructure/DependencyInjection.cs`
- `src/Backend/SolutionErp.Infrastructure/Persistence/ApplicationDbContext.cs`
- `src/Backend/SolutionErp.Infrastructure/Persistence/Configurations/PurchaseEvaluationConfiguration.cs`
- `src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs`
- `src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/ApplicationDbContextModelSnapshot.cs`
## Pending after this session (xem STATUS.md §🔥 In Progress)
### A. Còn MISSING
- PE Workflow admin designer UI (`/system/pe-workflows/:typeCode`)
- PE Attachments upload (entity + enum sẵn)
- Auto-map PE Details → Contract 7 per-type Details khi gen HĐ
- Section "Ý kiến phòng ban" trong PE form
### B. UX
- Payment terms tách field (JSON → 6 field)
- Matrix Quotes bulk paste từ Excel
- Export PDF/Excel
- fe-user Inbox PE section
- Sidebar accordion fe-user PE
### C. Edge case
- Reject path E2E
- Delete với linked contract
- Workflow v02 invariant pin v01
### D. Deploy
- win-acme task fix
- Remove huypham.vn old binding sau verify stable
## Commit
`[CLAUDE] PurchaseEvaluation: demo seed 4 phiếu + MaPhieu atomic sequence + Pe_* perm defaults`